nes_rom/
lib.rs

1//! # nes_rom
2//! 
3//! parses the most common NES rom file formats 
4
5
6#[macro_use]
7extern crate num_derive;
8
9#[macro_use]
10extern crate lazy_static;
11
12pub mod unif;
13pub mod ines;
14pub mod fds;
15mod crc32;
16
17use std::io;
18use std::error;
19use std::fmt;
20use std::convert::From;
21
22static INES_GUARD: [u8; 4] = [0x4e, 0x45, 0x53, 0x1a];
23static UNIF_GUARD: [u8; 4] = [0x55, 0x4e, 0x49, 0x46];
24static FDS_GUARD: [u8; 4] = [0x46, 0x44, 0x53, 0x1a];
25//static NSF_GUARD: [u8; 5] = [0x4e, 0x45, 0x53, 0x4d, 0x1a];
26
27#[derive(Debug, Copy, Clone, PartialEq)]
28pub enum RomError {
29    InvalidFormat,
30    InvalidRom,
31    InvalidConversion,
32    IOError,
33}
34
35impl error::Error for RomError {
36    fn description(&self) -> &str {
37        match *self {
38            RomError::InvalidFormat => "invalid rom file format",
39            RomError::InvalidRom => "rom file contained invalid or corrupted data",
40            RomError::InvalidConversion => "unable to process conversion",
41            RomError::IOError => "rom file io error",
42        }
43    }
44}
45
46impl fmt::Display for RomError {
47    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48        write!(f,"{}", self)
49    }
50}
51
52impl From<io::Error> for RomError {
53    fn from(_err: io::Error) -> Self {
54        RomError::IOError
55    }
56}
57
58