rom_parse/
rom_parse.rs

1extern crate nes_rom;
2
3use std::fs::File;
4use nes_rom::{ines, unif, fds};
5
6fn main() {
7  
8    let ines_file = File::open("example_roms\\Super Mario Bros. + Duck Hunt (USA).nes").unwrap();
9    let ines = ines::Ines::from_rom(ines_file);
10
11    match ines {
12        Ok(ref ines) => {
13            println!(" ines rom =========================================================");
14            println!("\theader ver. {:?}", ines.header_version);
15            println!("\tmapper: {:?} submapper: {:?}", ines.mapper, ines.submapper);
16            println!("\tmirroring: {:?}", ines.nametable_mirroring);
17            println!("\tprg rom size: {:?} chr rom size: {:?}", ines.prg_rom_size, ines.chr_rom_size);
18            println!("\tprg rom crc: {:X} chr rom crc: {:X}", ines.prg_crc, ines.chr_crc);
19            // Nes 2.0 allows more detailed handling of ram types
20            match ines.ram {
21                ines::Ram::Ines(prg_ram) => println!("\tprg ram: {:?}", prg_ram),
22                ines::Ram::Nes2{prg_ram, prg_nvram, chr_ram, chr_nvram} =>
23                    println!("\tprg ram: {:?} chr ram: {:?} prg nvram: {:?} chr nvram: {:?}", prg_ram, chr_ram, prg_nvram, chr_nvram),
24            }
25        }
26        Err(ref e) => println!("{:?}", e),
27    }
28
29    let unif_file = File::open("example_roms\\EarthWorm Jim 2 (Unl) [U][!].unf").unwrap();
30    let unif = unif::Unif::from_rom(unif_file);
31
32    match unif {
33        Ok(ref unif) => {
34            println!(" unif rom =========================================================");
35            println!("\tname: {:?}", unif.name);
36            println!("\tread: {:?}", unif.read);
37            println!("\tmapr: {:?}", unif.mapr);
38            println!("\tmirr: {:?}", unif.mirr);
39            println!("\tprg rom size: {:?} chr rom size: {:?}", unif.prg_data.len(), unif.chr_data.len());
40            println!("\tprg rom crc: {:X} chr rom crc: {:X}", unif.prg_crc, unif.chr_crc);
41            println!("\tbatr: {:?}", unif.batr);
42        }
43        Err(ref e) => println!("{:?}", e),
44    }
45
46    assert_eq!(unif.is_ok(), true);
47    let ines_c  = unif.unwrap().into_ines();
48
49    match ines_c {
50         Ok(ref ines_c) => {
51            println!(" unif to ines coversion =============================================");
52            println!("\theader ver. {:?}", ines_c.header_version);
53            println!("\tmapper: {:?} submapper: {:?}", ines_c.mapper, ines_c.submapper);
54            println!("\tmirroring: {:?}", ines_c.nametable_mirroring);
55            println!("\tprg rom size: {:?} chr rom size: {:?}", ines_c.prg_rom_size, ines_c.chr_rom_size);
56            println!("\tprg rom crc: {:X} chr rom crc: {:X}", ines_c.prg_crc, ines_c.chr_crc);
57            // Nes 2.0 allows more detailed handling of ram types
58            match ines_c.ram {
59                ines::Ram::Ines(prg_ram) => println!("\tprg ram: {:?}", prg_ram),
60                ines::Ram::Nes2{prg_ram, prg_nvram, chr_ram, chr_nvram} =>
61                    println!("\tprg ram: {:?} chr ram: {:?} prg nvram: {:?} chr nvram: {:?}", prg_ram, chr_ram, prg_nvram, chr_nvram),
62            }
63        }
64        Err(ref e) => println!("{:?}", e),
65    }
66
67    let fds_file = File::open("example_roms\\Time Twist - Rekishi no Katasumi de (1991)(Nintendo).fds").unwrap();
68    let fds = fds::Fds::from_rom(fds_file);
69
70     match fds {
71        Ok(ref fds) => {
72            println!(" fds rom =========================================================");
73            println!(" \tfile -----------------------------------------------");
74
75            for f in &fds.disk_files {
76                let fname = unsafe { 
77                    String::from_utf8_unchecked(f.file_name.to_vec())
78                };
79                println!("\t\tdisk num: {:?} actual disk num: {:?}", f.disk_number, f.actual_disk_number);
80                println!("\t\tside num: {:?}", f.side_number);
81                println!("\t\tfile number: {:?}", f.file_number);
82                println!("\t\tfile id: {:?}", f.file_id);
83                println!("\t\tfile type: {:?}", f.file_type);
84                println!("\t\tfile address: {:X}", f.file_address);
85                println!("\t\tboot read file code: {:?}", f.boot_read_file_code);
86                println!("\t\tfile size: {:?}", f.file_size);
87                println!("\t\tfile name: {:?}", fname);
88                println!(" \tfile -----------------------------------------------");
89            }
90        },
91        Err(e) => println!("fds ERROR: {:?}", e),
92    }
93
94}