Adding doRendering flag to disable audio/picture rendering for performance

This commit is contained in:
Sergio Martin 2024-01-13 11:10:42 +01:00
parent 86ffc7fce7
commit 52bb0987e3
7 changed files with 63 additions and 40 deletions

View File

@ -38,6 +38,7 @@ Nes_Core::Nes_Core() : ppu( this )
mapper = NULL;
memset( &nes, 0, sizeof nes );
memset( &joypad, 0, sizeof joypad );
_doRendering = true;
}
const char * Nes_Core::init()
@ -510,14 +511,17 @@ nes_time_t Nes_Core::emulate_frame()
clock_ = cpu_time_offset;
// TODO: clean this fucking mess up
impl->apu.run_until_( emulate_frame_() );
auto t0 = emulate_frame_();
if (_doRendering == true) impl->apu.run_until_( t0 );
clock_ = cpu_time_offset;
impl->apu.run_until_( cpu_time() );
auto t1 = cpu_time();
if (_doRendering == true) impl->apu.run_until_( t1 );
nes_time_t ppu_frame_length = ppu.frame_length();
nes_time_t length = cpu_time();
nes.timestamp = ppu.end_frame( length );
mapper->end_frame( length );
impl->apu.end_frame( ppu_frame_length );
disable_rendering();

View File

@ -20,6 +20,9 @@ public:
Nes_Core();
~Nes_Core();
// Flag to enable/disable rendering
bool _doRendering;
const char * init();
const char * open( Nes_Cart const* );
void reset( bool full_reset = true, bool erase_battery_ram = false );

View File

@ -140,47 +140,53 @@ const char * Nes_Emu::emulate_frame( int joypad1, int joypad2 )
emu.ppu.host_pixels = NULL;
unsigned changed_count = sound_buf->channels_changed_count();
bool new_enabled = (frame_ != NULL);
if ( sound_buf_changed_count != changed_count || sound_enabled != new_enabled )
if (emu._doRendering == true)
{
sound_buf_changed_count = changed_count;
sound_enabled = new_enabled;
enable_sound( sound_enabled );
}
unsigned changed_count = sound_buf->channels_changed_count();
bool new_enabled = (frame_ != NULL);
if ( sound_buf_changed_count != changed_count || sound_enabled != new_enabled )
{
sound_buf_changed_count = changed_count;
sound_enabled = new_enabled;
enable_sound( sound_enabled );
}
frame_t* f = frame_;
if ( f )
{
emu.ppu.max_palette_size = host_palette_size;
emu.ppu.host_palette = f->palette + emu.ppu.palette_begin;
// add black and white for emulator to use (unless emulator uses entire
// palette for frame)
f->palette [252] = 0x0F;
f->palette [254] = 0x30;
f->palette [255] = 0x0F;
if ( host_pixels )
emu.ppu.host_pixels = (uint8_t*) host_pixels +
emu.ppu.host_row_bytes * f->top;
frame_t* f = frame_;
if ( f )
{
emu.ppu.max_palette_size = host_palette_size;
emu.ppu.host_palette = f->palette + emu.ppu.palette_begin;
// add black and white for emulator to use (unless emulator uses entire
// palette for frame)
f->palette [252] = 0x0F;
f->palette [254] = 0x30;
f->palette [255] = 0x0F;
if ( host_pixels )
emu.ppu.host_pixels = (uint8_t*) host_pixels +
emu.ppu.host_row_bytes * f->top;
if ( sound_buf->samples_avail() )
clear_sound_buf();
if ( sound_buf->samples_avail() )
clear_sound_buf();
nes_time_t frame_len = emu.emulate_frame();
sound_buf->end_frame( frame_len, false );
nes_time_t frame_len = emu.emulate_frame();
sound_buf->end_frame( frame_len, false );
f = frame_;
f->sample_count = sound_buf->samples_avail();
f->chan_count = sound_buf->samples_per_frame();
f->palette_begin = emu.ppu.palette_begin;
f->palette_size = emu.ppu.palette_size;
f->joypad_read_count = emu.joypad_read_count;
f->burst_phase = emu.ppu.burst_phase;
f->pitch = emu.ppu.host_row_bytes;
if (emu.ppu.host_pixels != NULL)
f->pixels = emu.ppu.host_pixels + f->left;
else
f->pixels = NULL;
f = frame_;
f->sample_count = sound_buf->samples_avail();
f->chan_count = sound_buf->samples_per_frame();
f->palette_begin = emu.ppu.palette_begin;
f->palette_size = emu.ppu.palette_size;
f->joypad_read_count = emu.joypad_read_count;
f->burst_phase = emu.ppu.burst_phase;
f->pitch = emu.ppu.host_row_bytes;
f->pixels = emu.ppu.host_pixels + f->left;
}
else
{
emu.ppu.max_palette_size = 0;
emu.emulate_frame();
}
}
else
{

View File

@ -41,7 +41,10 @@ public:
enum { image_height = 240 };
const uint8_t* getHostPixels () const { return emu.ppu.host_pixels; }
void enableRendering() { emu._doRendering = true; }
void disableRendering() { emu._doRendering = false; }
// Basic emulation
// Emulate one video frame using joypad1 and joypad2 as input. Afterwards, image

View File

@ -64,6 +64,7 @@ int main(int argc, char *argv[])
// Printing provided parameters
printw("[] Rom File Path: '%s'\n", romFilePath.c_str());
printw("[] Sequence File Path: '%s'\n", sequenceFilePath.c_str());
printw("[] Sequence Length: %lu\n", sequence.size());
printw("[] State File Path: '%s'\n", stateFilePath.empty() ? "<Boot Start>" : stateFilePath.c_str());
printw("[] Generating Sequence...\n");

View File

@ -57,8 +57,11 @@ int main(int argc, char *argv[])
// Creating emulator instance
auto e = EmuInstance(romFilePath, initialStateFilePath);
// Disable rendering
e.getInternalEmulator()->disableRendering();
// Getting initial hash
auto initialHash = e.getStateHash();
printf("[] Initial State Hash: 0x%lX%lX\n", initialHash.first, initialHash.second);
// Getting state size
const auto stateSize = e.getStateSize();
@ -98,6 +101,7 @@ int main(int argc, char *argv[])
printf("[] Verification State File: '%s'\n", verificationStateFilePath.c_str());
printf("[] Sequence File: '%s'\n", sequenceFilePath.c_str());
printf("[] Sequence Length: %lu\n", sequenceLength);
printf("[] Initial State Hash: 0x%lX%lX\n", initialHash.first, initialHash.second);
printf("[] State Size: %lu bytes\n", stateSize);
printf("[] Running Test...\n");

View File

@ -1,5 +1,6 @@
nomalloc = environment({'MALLOC_PERTURB_': '0'})
subdir('arkanoid')
subdir('castlevania1')
subdir('superOffroad')
subdir('princeOfPersia')
@ -8,3 +9,4 @@ subdir('ninjaGaiden2')
subdir('ironSword')
subdir('solarJetman')
subdir('tennis')
subdir('nigelMansell')