Adding no frills memcpy-based ines loader
This commit is contained in:
parent
5624f29ee6
commit
ad9858a564
|
@ -11,6 +11,5 @@ option('CPUFunctionAlignment',
|
||||||
value : 1024,
|
value : 1024,
|
||||||
description : '''Indicates the alignment for the main emulator CPU function.
|
description : '''Indicates the alignment for the main emulator CPU function.
|
||||||
This is a large function that may cross page boundaries, which impacts performance.
|
This is a large function that may cross page boundaries, which impacts performance.
|
||||||
We recommend setting this value for the architecture own page size.
|
|
||||||
This requires the GNU compiler to work.'''
|
This requires the GNU compiler to work.'''
|
||||||
)
|
)
|
|
@ -118,3 +118,24 @@ const char * Nes_Cart::load_ines( Auto_File_Reader in )
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char * Nes_Cart::load_ines( const uint8_t* buffer )
|
||||||
|
{
|
||||||
|
ines_header_t h;
|
||||||
|
|
||||||
|
size_t bufferPos = 0;
|
||||||
|
{ size_t copySize = sizeof(ines_header_t); memcpy(&h, &buffer[bufferPos], copySize); bufferPos += copySize; }
|
||||||
|
if ( h.zero [7] ) h.flags2 = 0;
|
||||||
|
set_mapper( h.flags, h.flags2 );
|
||||||
|
|
||||||
|
// skip trainer
|
||||||
|
if ( h.flags & 0x04 ) bufferPos += 512;
|
||||||
|
|
||||||
|
resize_prg( h.prg_count * 16 * 1024L );
|
||||||
|
resize_chr( h.chr_count * 8 * 1024L );
|
||||||
|
|
||||||
|
{ size_t copySize = prg_size(); memcpy(prg(), &buffer[bufferPos], copySize); bufferPos += copySize; }
|
||||||
|
{ size_t copySize = chr_size(); memcpy(chr(), &buffer[bufferPos], copySize); bufferPos += copySize; }
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ public:
|
||||||
~Nes_Cart();
|
~Nes_Cart();
|
||||||
|
|
||||||
// Load iNES file
|
// Load iNES file
|
||||||
|
const char * load_ines( const uint8_t* buffer );
|
||||||
const char * load_ines( Auto_File_Reader );
|
const char * load_ines( Auto_File_Reader );
|
||||||
static const char not_ines_file [];
|
static const char not_ines_file [];
|
||||||
|
|
||||||
|
|
|
@ -189,6 +189,13 @@ const char * Nes_Emu::emulate_frame( int joypad1, int joypad2 )
|
||||||
|
|
||||||
// Extras
|
// Extras
|
||||||
|
|
||||||
|
const char * Nes_Emu::load_ines( const uint8_t* buffer )
|
||||||
|
{
|
||||||
|
close();
|
||||||
|
private_cart.load_ines( buffer );
|
||||||
|
return set_cart( &private_cart );
|
||||||
|
}
|
||||||
|
|
||||||
const char * Nes_Emu::load_ines( Auto_File_Reader in )
|
const char * Nes_Emu::load_ines( Auto_File_Reader in )
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
|
|
|
@ -21,6 +21,7 @@ public:
|
||||||
|
|
||||||
// Load iNES file into emulator and clear recording
|
// Load iNES file into emulator and clear recording
|
||||||
const char * load_ines( Auto_File_Reader );
|
const char * load_ines( Auto_File_Reader );
|
||||||
|
const char * load_ines( const uint8_t* buffer );
|
||||||
|
|
||||||
// Set sample rate for sound generation
|
// Set sample rate for sound generation
|
||||||
const char * set_sample_rate( long );
|
const char * set_sample_rate( long );
|
||||||
|
|
|
@ -46,10 +46,16 @@ class EmuInstance
|
||||||
_romSHA1String = SHA1::GetHash((uint8_t*)romData.data(), romData.size());
|
_romSHA1String = SHA1::GetHash((uint8_t*)romData.data(), romData.size());
|
||||||
|
|
||||||
// Loading the rom into the emulator
|
// Loading the rom into the emulator
|
||||||
Mem_File_Reader romReader(romData.data(), (int)romData.size());
|
#ifdef USE_ORIGINAL_QUICKNES
|
||||||
Auto_File_Reader romFile(romReader);
|
Mem_File_Reader romReader(romData.data(), (int)romData.size());
|
||||||
auto result = _nes->load_ines(romFile);
|
Auto_File_Reader romFile(romReader);
|
||||||
if (result != 0) EXIT_WITH_ERROR("Could not initialize emulator with rom file: %s\n", romFilePath.c_str());
|
auto result = _nes->load_ines(romFile);
|
||||||
|
if (result != 0) EXIT_WITH_ERROR("Could not initialize emulator with rom file: %s\n", romFilePath.c_str());
|
||||||
|
#else
|
||||||
|
auto result = _nes->load_ines((const uint8_t*) romData.data());
|
||||||
|
if (result != 0) EXIT_WITH_ERROR("Could not initialize emulator with rom file: %s\n", romFilePath.c_str());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Getting state size to use
|
// Getting state size to use
|
||||||
_stateSize = getStateSizeImpl();
|
_stateSize = getStateSizeImpl();
|
||||||
|
|
Loading…
Reference in New Issue