From 0174c2efe4fcd2309479878d20499b89021dd23e Mon Sep 17 00:00:00 2001 From: William Emfinger Date: Wed, 3 Jul 2024 21:38:17 -0500 Subject: [PATCH] replace static auto with simple get() for simplicity --- components/genesis/src/genesis.cpp | 17 +++++++---------- components/nes/src/video_audio.cpp | 14 +++++--------- components/sms/src/sms.cpp | 14 ++++++-------- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/components/genesis/src/genesis.cpp b/components/genesis/src/genesis.cpp index fd1a539..cfcf102 100644 --- a/components/genesis/src/genesis.cpp +++ b/components/genesis/src/genesis.cpp @@ -180,13 +180,10 @@ void init_genesis(uint8_t *romdata, size_t rom_data_size) { } void IRAM_ATTR run_genesis_rom() { - static auto& emu = BoxEmu::get(); - static auto& box = espp::EspBox::get(); - auto start = esp_timer_get_time(); // handle input here (see system.h and use input.pad and input.system) static GamepadState previous_state = {}; - auto state = emu.gamepad_state(); + auto state = BoxEmu::get().gamepad_state(); // set frameskip to be 3 if muted, 60 otherwise frameskip = 3; // hal::is_muted() ? 3 : 60; @@ -227,7 +224,7 @@ void IRAM_ATTR run_genesis_rom() { gwenesis_vdp_render_config(); - bool sound_enabled = !box.is_muted(); + bool sound_enabled = !espp::EspBox::get().is_muted(); /* Reset the difference clocks and audio index */ system_clock = 0; @@ -314,21 +311,21 @@ void IRAM_ATTR run_genesis_rom() { // copy the palette memcpy(palette, CRAM565, PALETTE_SIZE * sizeof(uint16_t)); // set the palette - emu.palette(palette, PALETTE_SIZE); + BoxEmu::get().palette(palette, PALETTE_SIZE); // push the frame buffer to the display task - emu.push_frame(frame_buffer); + BoxEmu::get().push_frame(frame_buffer); // ping pong the frame buffer frame_buffer_index = !frame_buffer_index; frame_buffer = frame_buffer_index - ? box.frame_buffer1() - : box.frame_buffer0(); + ? espp::EspBox::get().frame_buffer1() + : espp::EspBox::get().frame_buffer0(); gwenesis_vdp_set_buffer(frame_buffer); } if (sound_enabled) { // push the audio buffer to the audio task int audio_len = REG1_PAL ? GWENESIS_AUDIO_BUFFER_LENGTH_PAL : GWENESIS_AUDIO_BUFFER_LENGTH_NTSC; - box.play_audio((uint8_t*)gwenesis_ym2612_buffer, audio_len); + espp::EspBox::get().play_audio((uint8_t*)gwenesis_ym2612_buffer, audio_len); } // manage statistics diff --git a/components/nes/src/video_audio.cpp b/components/nes/src/video_audio.cpp index a2d085a..26d7798 100644 --- a/components/nes/src/video_audio.cpp +++ b/components/nes/src/video_audio.cpp @@ -40,13 +40,12 @@ static void (*audio_callback)(void *buffer, int length) = NULL; extern "C" void do_audio_frame() { if (audio_callback == NULL) return; - static auto& box = espp::EspBox::get(); static int num_channels = 2; - static int num_samples = box.audio_sample_rate() * num_channels / NES_REFRESH_RATE; + static int num_samples = espp::EspBox::get().audio_sample_rate() * num_channels / NES_REFRESH_RATE; static int num_bytes = num_samples * sizeof(int16_t); static int16_t *audio_frame = (int16_t*)heap_caps_malloc(num_bytes, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); audio_callback(audio_frame, num_samples); - box.play_audio((uint8_t*)audio_frame, num_bytes); + espp::EspBox::get().play_audio((uint8_t*)audio_frame, num_bytes); } extern "C" void osd_setsound(void (*playfunc)(void *buffer, int length)) @@ -173,15 +172,13 @@ static void free_write(int num_dirties, rect_t *dirty_rects) } static void custom_blit(const bitmap_t *bmp, int num_dirties, rect_t *dirty_rects) { - static auto& box = espp::EspBox::get(); - static auto& emu = BoxEmu::get(); - uint8_t *lcdfb = box.frame_buffer0(); + uint8_t *lcdfb = espp::EspBox::get().frame_buffer0(); if (bmp->line[0] != NULL) { memcpy(lcdfb, bmp->line[0], 256 * 224); void* arg = (void*)lcdfb; - emu.push_frame(arg); + BoxEmu::get().push_frame(arg); } } @@ -193,8 +190,7 @@ static int ConvertJoystickInput() { int result = 0; - static auto& emu = BoxEmu::get(); - auto state = emu.gamepad_state(); + auto state = BoxEmu::get().gamepad_state(); if (!state.a) result |= (1<<13); diff --git a/components/sms/src/sms.cpp b/components/sms/src/sms.cpp index 25b7c29..038249b 100644 --- a/components/sms/src/sms.cpp +++ b/components/sms/src/sms.cpp @@ -111,11 +111,9 @@ void init_gg(uint8_t *romdata, size_t rom_data_size) { } void run_sms_rom() { - static auto& emu = BoxEmu::get(); - static auto& box = espp::EspBox::get(); auto start = esp_timer_get_time(); // handle input here (see system.h and use input.pad and input.system) - auto state = emu.gamepad_state(); + auto state = BoxEmu::get().gamepad_state(); // pad[0] is player 0 input.pad[0] = 0; @@ -147,15 +145,15 @@ void run_sms_rom() { palette[i] = (rgb565 >> 8) | (rgb565 << 8); } // set the palette - emu.palette(palette, PALETTE_SIZE); + BoxEmu::get().palette(palette, PALETTE_SIZE); // render the frame - emu.push_frame((uint8_t*)bitmap.data + frame_buffer_offset); + BoxEmu::get().push_frame((uint8_t*)bitmap.data + frame_buffer_offset); // ping pong the frame buffer frame_buffer_index = !frame_buffer_index; bitmap.data = frame_buffer_index - ? (uint8_t*)box.frame_buffer1() - : (uint8_t*)box.frame_buffer0(); + ? (uint8_t*)espp::EspBox::get().frame_buffer1() + : (uint8_t*)espp::EspBox::get().frame_buffer0(); } else { system_frame(1); } @@ -180,7 +178,7 @@ void run_sms_rom() { auto sms_audio_buffer_len = sms_snd.sample_count - 1; // push the audio buffer to the audio task - box.play_audio((uint8_t*)sms_audio_buffer, sms_audio_buffer_len * 2 * 2); // 2 channels, 2 bytes per sample + espp::EspBox::get().play_audio((uint8_t*)sms_audio_buffer, sms_audio_buffer_len * 2 * 2); // 2 channels, 2 bytes per sample // update unlock based on x button static bool last_x = false;