Example #1
0
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;
}
Example #2
0
blargg_err_t Nes_Cart::load_patched_ines( Auto_File_Reader in, Auto_File_Reader patch )
{
	RETURN_ERR( in.open() );
	RETURN_ERR( patch.open() );
	
	// read file into memory
	long size = in->remain();
	byte* ines = (byte*) malloc( size );
	CHECK_ALLOC( ines );
	const char* err = in->read( ines, size );
	
	// apply patch
	if ( !err )
		err = apply_ips_patch( *patch, &ines, &size );
	
	// load patched file
	if ( !err )
	{
		Mem_File_Reader patched( ines, size );
		err = load_ines( patched );
	}
	
	free( ines );
	
	return err;
}
Example #3
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;
}
Example #4
0
blargg_err_t Nes_Emu::load_battery_ram( Auto_File_Reader in )
{
    RETURN_ERR( in.open() );
    emu.sram_present = true;
    return in->read( emu.impl->sram, emu.impl->sram_size );
}