fn from_ines(buffer: &[u8]) -> Result<Cart, CartReadingError> {
        let prg_chunks = buffer[4] as usize;
        let chr_chunks = buffer[5] as usize;
        let flag6 = buffer[6];
        let flag7 = buffer[7];
        let trainer_offset = if flag6 & 0b100 > 0 { 512 } else { 0 };
        let prg_start = 16 + trainer_offset;
        let prg_end = prg_start + 0x4000 * prg_chunks;
        let chr_end = prg_end + 0x2000 * chr_chunks;
        let mapper = MapperID::try_from((flag6 >> 4) | (flag7 & 0xF0))?;
        let mirroring = if flag6 & 1 != 0 {
            Mirroring::Vertical
        } else {
            Mirroring::Horizontal
        };
        let chr = if chr_chunks == 0 {
            vec![0; 0x2000]
        } else {
            buffer[prg_end..chr_end].to_vec()
        };
        Ok(Cart {
            prg: buffer[prg_start..prg_end].to_vec(),
            chr,
            mapper,
            sram: [0; 0x2000],
            mirroring,
            has_battery: flag6 & 0b10 > 0,
        })
    }
/// Reads an INES formatted buffer, including the header
Reads an INES formatted buffer, including the header
Reads an INES formatted buffer including the header
fn from_ines(buffer: &[u8]) -> Result<Cart, CartReadingError> {
        let prg_chunks = buffer[4] as usize;
        let chr_chunks = buffer[5] as usize;
        let flag6 = buffer[6];
        let flag7 = buffer[7];
        let trainer_offset = if flag6 & 0b100 > 0 { 512 } else { 0 };
        let prg_start = 16 + trainer_offset;
        let prg_end = prg_start + 0x4000 * prg_chunks;
        let chr_end = prg_end + 0x2000 * chr_chunks;
        let mapper = MapperID::try_from((flag6 >> 4) | (flag7 & 0xF0))?;
        let mirroring = if flag6 & 1 != 0 {
            Mirroring::Vertical
        } else {
            Mirroring::Horizontal
        };
        let chr = if chr_chunks == 0 {
            vec![0; 0x2000]
        } else {
            buffer[prg_end..chr_end].to_vec()
        };
        Ok(Cart {
            prg: buffer[prg_start..prg_end].to_vec(),
            chr,
            mapper,
            sram: [0; 0x2000],
            mirroring,
            has_battery: flag6 & 0b10 > 0,
        })
    }
fn from_ines ( buffer : & [ u8 ] ) -> Result < Cart , CartReadingError > { let prg_chunks = buffer [ 4 ] as usize ; let chr_chunks = buffer [ 5 ] as usize ; let flag6 = buffer [ 6 ] ; let flag7 = buffer [ 7 ] ; let trainer_offset = if flag6 & 0b100 > 0 { 512 } else { 0 } ; let prg_start = 16 + trainer_offset ; let prg_end = prg_start + 0x4000 * prg_chunks ; let chr_end = prg_end + 0x2000 * chr_chunks ; let mapper = MapperID :: try_from ( ( flag6 >> 4 ) | ( flag7 & 0xF0 ) ) ? ; let mirroring = if flag6 & 1 != 0 { Mirroring :: Vertical } else { Mirroring :: Horizontal } ; let chr = if chr_chunks == 0 { vec ! [ 0 0x2000 ] } else { buffer [ prg_end .. chr_end ] . to_vec ( ) } ; Ok ( Cart { prg : buffer [ prg_start .. prg_end ] . to_vec ( ) , chr , mapper , sram : [ 0 ; 0x2000 ] , mirroring , has_battery : flag6 & 0b10 > 0 , } ) }
Reads an INES formatted buffer, including the header
Reads an INES formatted buffer including the header
buffer
&[u8]
buffer
&[u8]