blargg_err_t Nes_Cart::load_ines( Auto_File_Reader in ) { RETURN_ERR( in.open() ); ines_header_t h; RETURN_ERR( in->read( &h, sizeof h ) ); if ( 0 != memcmp( h.signature, "NES\x1A", 4 ) ) return not_ines_file; if ( h.zero [7] ) // handle header defaced by a f*****g idiot's handle h.flags2 = 0; set_mapper( h.flags, h.flags2 ); if ( h.flags & 0x04 ) // skip trainer RETURN_ERR( in->skip( 512 ) ); RETURN_ERR( resize_prg( h.prg_count * 16 * 1024L ) ); RETURN_ERR( resize_chr( h.chr_count * 8 * 1024L ) ); RETURN_ERR( in->read( prg(), prg_size() ) ); RETURN_ERR( in->read( chr(), chr_size() ) ); return 0; }
blargg_err_t Nes_Cart::apply_ips_to_chr( Auto_File_Reader patch ) { RETURN_ERR( patch.open() ); long size = chr_size(); byte* chr_copy = (byte*) malloc( size ); CHECK_ALLOC( chr_copy ); memcpy( chr_copy, chr(), size ); const char* err = apply_ips_patch( *patch, &chr_copy, &size ); if ( !err ) { resize_chr( size ); memcpy( chr(), chr_copy, size ); } free( chr_copy ); return err; }
blargg_err_t Nes_Rom::load_ines_rom( Data_Reader& in ) { ines_header_t h; BLARGG_RETURN_ERR( in.read( &h, sizeof h ) ); if ( 0 != memcmp( h.signature, "NES\x1A", 4 ) ) return "Not a iNES ROM file"; if ( h.zero [7] ) // handle header defaced by a f*****g idiot's handle h.flags2 = 0; set_mapper( h.flags, h.flags2 ); if ( h.flags & 0x04 ) // skip trainer BLARGG_RETURN_ERR( in.skip( 512 ) ); BLARGG_RETURN_ERR( resize_prg( h.prg_count * 16 * 1024L ) ); BLARGG_RETURN_ERR( resize_chr( h.chr_count * 8 * 1024L ) ); BLARGG_RETURN_ERR( in.read( prg(), prg_size() ) ); BLARGG_RETURN_ERR( in.read( chr(), chr_size() ) ); return blargg_success; }