From cf5414c9d0db2a388159f2407428c107f1a5a51e Mon Sep 17 00:00:00 2001 From: OhThomas Date: Thu, 1 Dec 2022 03:08:31 -0600 Subject: [PATCH 1/8] In game settings --- src/api/frontend.c | 2 + src/device/r4300/interrupt.c | 7 ++++ src/device/r4300/r4300_core.c | 4 ++ src/device/rcp/vi/vi_controller.c | 14 +++++++ src/main/main.c | 61 +++++++++++++++++++++++++++++-- src/main/main.h | 5 +++ 6 files changed, 89 insertions(+), 4 deletions(-) diff --git a/src/api/frontend.c b/src/api/frontend.c index 0f8c344aa..1a006cb39 100644 --- a/src/api/frontend.c +++ b/src/api/frontend.c @@ -69,6 +69,8 @@ EXPORT m64p_error CALL CoreStartup(int APIVersion, const char *ConfigPath, const SetDebugCallback(DebugCallback, Context); SetStateCallback(StateCallback, Context2); + g_EmuModeInitiated = 0; + /* check front-end's API version */ if ((APIVersion & 0xffff0000) != (FRONTEND_API_VERSION & 0xffff0000)) { diff --git a/src/device/r4300/interrupt.c b/src/device/r4300/interrupt.c index dd37e6c74..00f67dfe9 100644 --- a/src/device/r4300/interrupt.c +++ b/src/device/r4300/interrupt.c @@ -553,6 +553,13 @@ void gen_interrupt(struct r4300_core* r4300) if (savestates_get_job() == savestates_job_load) { savestates_load(); + + // Doing this because the interpreter doesn't get initiated properly after resetting from + // the in game settings menu (no instructions seem to get executed) + if(g_ResolutionReset != 0 && get_r4300_emumode(&g_dev.r4300) == 1 && g_LoadOnce == 0){ + main_state_load_latest_auto_save(); + g_LoadOnce++; + } return; } diff --git a/src/device/r4300/r4300_core.c b/src/device/r4300/r4300_core.c index 865f9865b..36a48c890 100644 --- a/src/device/r4300/r4300_core.c +++ b/src/device/r4300/r4300_core.c @@ -141,6 +141,7 @@ void run_r4300(struct r4300_core* r4300) { DebugMessage(M64MSG_INFO, "Starting R4300 emulator: Pure Interpreter"); r4300->emumode = EMUMODE_PURE_INTERPRETER; + g_EmuModeInitiated = 1; run_pure_interpreter(r4300); } #if defined(DYNAREC) @@ -151,6 +152,7 @@ void run_r4300(struct r4300_core* r4300) init_blocks(&r4300->cached_interp); #ifdef NEW_DYNAREC new_dynarec_init(); + g_EmuModeInitiated = 1; new_dyna_start(); new_dynarec_cleanup(); #else @@ -192,6 +194,8 @@ void run_r4300(struct r4300_core* r4300) r4300->cp0.last_addr = *r4300_pc(r4300); + g_EmuModeInitiated = 1; + run_cached_interpreter(r4300); free_blocks(&r4300->cached_interp); diff --git a/src/device/rcp/vi/vi_controller.c b/src/device/rcp/vi/vi_controller.c index d83f32001..8490e2a3f 100644 --- a/src/device/rcp/vi/vi_controller.c +++ b/src/device/rcp/vi/vi_controller.c @@ -170,6 +170,17 @@ void write_vi_regs(void* opaque, uint32_t address, uint32_t value, uint32_t mask masked_write(&vi->regs[reg], value, mask); } +void settings_reset_check() +{ + /* Making sure to pause once the core has started up; + sometimes the graphics plugin finishes first */ + if(g_EmulatorRunning && !g_rom_pause && g_ResolutionReset != 0 && g_ResolutionResetCoreCounter >= 12){ + main_toggle_pause(); + g_ResolutionResetCoreCounter = -6; + g_ResolutionReset = 0; + } +} + void vi_vertical_interrupt_event(void* opaque) { struct vi_controller* vi = (struct vi_controller*)opaque; @@ -184,6 +195,9 @@ void vi_vertical_interrupt_event(void* opaque) /* toggle vi field if in interlaced mode */ vi->field ^= (vi->regs[VI_STATUS_REG] >> 6) & 0x1; + /* make sure we aren't resetting from changing settings in game */ + settings_reset_check(); + /* schedule next vertical interrupt */ uint32_t next_vi = *get_event(&vi->mi->r4300->cp0.q, VI_INT) + vi->delay; remove_interrupt_event(&vi->mi->r4300->cp0); diff --git a/src/main/main.c b/src/main/main.c index 643c5854b..5d4426b2e 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -97,6 +97,10 @@ m64p_frame_callback g_FrameCallback = NULL; int g_RomWordsLittleEndian = 0; // after loading, ROM words are in native N64 byte order (big endian). We will swap them on x86 int g_EmulatorRunning = 0; // need separate boolean to tell if emulator is running, since --nogui doesn't use a thread +int g_EmuModeInitiated = 0; // we use this to help the plugin wait before initializing when resetting from in game settings +int g_ResolutionReset = 0; // used to check if the game needs to pause before starting because of in game settings being changed +int g_ResolutionResetCoreCounter = 0;// counts frames to make sure the video plugin is showing when resetting via resolution reset +int g_LoadOnce = 0; // used to prevent the interpreter from loading multiple times int g_rom_pause; @@ -117,6 +121,8 @@ m64p_media_loader g_media_loader; int g_gs_vi_counter = 0; +char * l_FileName = NULL; // holds the latest auto save file name to use if we reset from in game settings + /** static (local) variables **/ static int l_CurrentFrame = 0; // frame counter static int l_TakeScreenshot = 0; // Tell OSD Rendering callback to take a screenshot just before drawing the OSD @@ -308,6 +314,14 @@ static void main_check_inputs(void) SDL_PumpEvents(); } +void free_current_save(void) +{ + if(l_FileName != NULL) { + free(l_FileName); + l_FileName = NULL; + } +} + /********************************************************************************************************* * global functions, for adjusting the core emulator behavior */ @@ -561,8 +575,21 @@ void main_state_inc_slot(void) savestates_inc_slot(); } +void main_state_load_latest_auto_save() +{ + if (netplay_is_init() || l_FileName == NULL) + return; + savestates_set_job(savestates_job_load, savestates_type_unknown, l_FileName); +} + void main_state_load(const char *filename) { + if(filename != NULL) { + free_current_save(); + l_FileName = malloc(strlen(filename) + 1); + strcpy(l_FileName, filename); + } + if (netplay_is_init()) return; @@ -588,6 +615,10 @@ m64p_error main_core_state_query(m64p_core_param param, int *rval) switch (param) { case M64CORE_EMU_STATE: + if (g_EmuModeInitiated != 1) { + *rval = -2; + break; + } if (!g_EmulatorRunning) *rval = M64EMU_STOPPED; else if (g_rom_pause) @@ -623,8 +654,6 @@ m64p_error main_core_state_query(m64p_core_param param, int *rval) } case M64CORE_AUDIO_VOLUME: { - if (!g_EmulatorRunning) - return M64ERR_INVALID_STATE; return main_volume_get_level(rval); } case M64CORE_AUDIO_MUTE: @@ -669,6 +698,10 @@ m64p_error main_core_state_set(m64p_core_param param, int val) main_toggle_pause(); return M64ERR_SUCCESS; } + else if (val == 5) { + free_current_save(); + return M64ERR_SUCCESS; + } return M64ERR_INPUT_INVALID; case M64CORE_VIDEO_MODE: if (!g_EmulatorRunning) @@ -703,6 +736,10 @@ m64p_error main_core_state_set(m64p_core_param param, int val) { // the front-end app is telling us that the user has resized the video output frame, and so // we should try to update the video plugin accordingly. First, check state + if (val <= 0){ + g_ResolutionReset = val; + return M64ERR_SUCCESS; + } int width, height; if (!g_EmulatorRunning) return M64ERR_INVALID_STATE; @@ -716,7 +753,9 @@ m64p_error main_core_state_set(m64p_core_param param, int val) case M64CORE_AUDIO_VOLUME: if (!g_EmulatorRunning) return M64ERR_INVALID_STATE; - if (val < 0 || val > 100) + if (val == -2) + return M64ERR_SUCCESS; + else if (val < 0 || val > 100) return M64ERR_INPUT_INVALID; return main_volume_set_level(val); case M64CORE_AUDIO_MUTE: @@ -851,6 +890,9 @@ void new_frame(void) /* advance the current frame */ l_CurrentFrame++; + if(g_ResolutionReset != 0 && g_EmuModeInitiated == 1) + g_ResolutionResetCoreCounter++; + if (l_FrameAdvance) { g_rom_pause = 1; l_FrameAdvance = 0; @@ -949,7 +991,15 @@ static void pause_loop(void) if(g_rom_pause) { osd_render(); // draw Paused message in case gfx.updateScreen didn't do it - VidExt_GL_SwapBuffers(); + + // using estimated frame skip settings with gfx plugin causes black screen + if(g_ResolutionReset == 0 && g_ResolutionResetCoreCounter != 0){ + if(g_ResolutionResetCoreCounter == -6) + g_ResolutionResetCoreCounter = -5; + else + VidExt_GL_SwapBuffers(); + } + while(g_rom_pause) { SDL_Delay(10); @@ -1869,6 +1919,7 @@ m64p_error main_run(void) osd_new_message(OSD_MIDDLE_CENTER, "Mupen64Plus Started..."); g_EmulatorRunning = 1; + g_ResolutionResetCoreCounter = -5; StateChanged(M64CORE_EMU_STATE, M64EMU_RUNNING); poweron_device(&g_dev); @@ -1917,6 +1968,8 @@ m64p_error main_run(void) // clean up g_EmulatorRunning = 0; + g_EmuModeInitiated = 0; + free_current_save(); StateChanged(M64CORE_EMU_STATE, M64EMU_STOPPED); return M64ERR_SUCCESS; diff --git a/src/main/main.h b/src/main/main.h index 2700cefeb..600faaa2a 100644 --- a/src/main/main.h +++ b/src/main/main.h @@ -42,6 +42,10 @@ extern m64p_handle g_CoreConfig; extern int g_RomWordsLittleEndian; extern int g_EmulatorRunning; +extern int g_EmuModeInitiated; +extern int g_ResolutionReset; +extern int g_ResolutionResetCoreCounter; +extern int g_LoadOnce; extern int g_rom_pause; extern struct cheat_ctx g_cheat_ctx; @@ -84,6 +88,7 @@ void main_take_next_screenshot(void); void main_state_set_slot(int slot); void main_state_inc_slot(void); +void main_state_load_latest_auto_save(void); void main_state_load(const char *filename); void main_state_save(int format, const char *filename); From 6bd41fed7a8a6636cbb6a1bf68047d84906fb835 Mon Sep 17 00:00:00 2001 From: OhThomas Date: Thu, 1 Dec 2022 05:14:08 -0600 Subject: [PATCH 2/8] Making reset counter local --- src/device/rcp/vi/vi_controller.c | 14 -------------- src/main/main.c | 27 ++++++++++++++++++++------- src/main/main.h | 1 - 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/device/rcp/vi/vi_controller.c b/src/device/rcp/vi/vi_controller.c index 8490e2a3f..d83f32001 100644 --- a/src/device/rcp/vi/vi_controller.c +++ b/src/device/rcp/vi/vi_controller.c @@ -170,17 +170,6 @@ void write_vi_regs(void* opaque, uint32_t address, uint32_t value, uint32_t mask masked_write(&vi->regs[reg], value, mask); } -void settings_reset_check() -{ - /* Making sure to pause once the core has started up; - sometimes the graphics plugin finishes first */ - if(g_EmulatorRunning && !g_rom_pause && g_ResolutionReset != 0 && g_ResolutionResetCoreCounter >= 12){ - main_toggle_pause(); - g_ResolutionResetCoreCounter = -6; - g_ResolutionReset = 0; - } -} - void vi_vertical_interrupt_event(void* opaque) { struct vi_controller* vi = (struct vi_controller*)opaque; @@ -195,9 +184,6 @@ void vi_vertical_interrupt_event(void* opaque) /* toggle vi field if in interlaced mode */ vi->field ^= (vi->regs[VI_STATUS_REG] >> 6) & 0x1; - /* make sure we aren't resetting from changing settings in game */ - settings_reset_check(); - /* schedule next vertical interrupt */ uint32_t next_vi = *get_event(&vi->mi->r4300->cp0.q, VI_INT) + vi->delay; remove_interrupt_event(&vi->mi->r4300->cp0); diff --git a/src/main/main.c b/src/main/main.c index 5d4426b2e..cc12fa7ff 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -99,7 +99,6 @@ int g_RomWordsLittleEndian = 0; // after loading, ROM words are in nativ int g_EmulatorRunning = 0; // need separate boolean to tell if emulator is running, since --nogui doesn't use a thread int g_EmuModeInitiated = 0; // we use this to help the plugin wait before initializing when resetting from in game settings int g_ResolutionReset = 0; // used to check if the game needs to pause before starting because of in game settings being changed -int g_ResolutionResetCoreCounter = 0;// counts frames to make sure the video plugin is showing when resetting via resolution reset int g_LoadOnce = 0; // used to prevent the interpreter from loading multiple times @@ -129,6 +128,7 @@ static int l_TakeScreenshot = 0; // Tell OSD Rendering callback to take static int l_SpeedFactor = 100; // percentage of nominal game speed at which emulator is running static int l_FrameAdvance = 0; // variable to check if we pause on next frame static int l_MainSpeedLimit = 1; // insert delay during vi_interrupt to keep speed at real-time +static int l_ResolutionResetCoreCounter = 0;// counts frames to make sure the video plugin is showing when resetting via resolution reset static osd_message_t *l_msgVol = NULL; static osd_message_t *l_msgFF = NULL; @@ -314,7 +314,7 @@ static void main_check_inputs(void) SDL_PumpEvents(); } -void free_current_save(void) +static void free_current_save(void) { if(l_FileName != NULL) { free(l_FileName); @@ -891,7 +891,7 @@ void new_frame(void) l_CurrentFrame++; if(g_ResolutionReset != 0 && g_EmuModeInitiated == 1) - g_ResolutionResetCoreCounter++; + l_ResolutionResetCoreCounter++; if (l_FrameAdvance) { g_rom_pause = 1; @@ -993,9 +993,9 @@ static void pause_loop(void) osd_render(); // draw Paused message in case gfx.updateScreen didn't do it // using estimated frame skip settings with gfx plugin causes black screen - if(g_ResolutionReset == 0 && g_ResolutionResetCoreCounter != 0){ - if(g_ResolutionResetCoreCounter == -6) - g_ResolutionResetCoreCounter = -5; + if(g_ResolutionReset == 0 && l_ResolutionResetCoreCounter != 0){ + if(l_ResolutionResetCoreCounter == -6) + l_ResolutionResetCoreCounter = -5; else VidExt_GL_SwapBuffers(); } @@ -1008,6 +1008,17 @@ static void pause_loop(void) } } +/* Making sure to pause once the core has started up if resetting from settings; + * sometimes the graphics plugin finishes first */ +static void settings_reset_check(void) +{ + if(g_EmulatorRunning && !g_rom_pause && g_ResolutionReset != 0 && l_ResolutionResetCoreCounter >= 12){ + main_toggle_pause(); + l_ResolutionResetCoreCounter = -6; + g_ResolutionReset = 0; + } +} + /* called on vertical interrupt. * Allow the core to perform various things */ void new_vi(void) @@ -1024,6 +1035,8 @@ void new_vi(void) pause_loop(); netplay_check_sync(&g_dev.r4300.cp0); + + settings_reset_check(); } static void main_switch_pak(int control_id) @@ -1919,7 +1932,7 @@ m64p_error main_run(void) osd_new_message(OSD_MIDDLE_CENTER, "Mupen64Plus Started..."); g_EmulatorRunning = 1; - g_ResolutionResetCoreCounter = -5; + l_ResolutionResetCoreCounter = -5; StateChanged(M64CORE_EMU_STATE, M64EMU_RUNNING); poweron_device(&g_dev); diff --git a/src/main/main.h b/src/main/main.h index 600faaa2a..1a1292f9b 100644 --- a/src/main/main.h +++ b/src/main/main.h @@ -44,7 +44,6 @@ extern int g_RomWordsLittleEndian; extern int g_EmulatorRunning; extern int g_EmuModeInitiated; extern int g_ResolutionReset; -extern int g_ResolutionResetCoreCounter; extern int g_LoadOnce; extern int g_rom_pause; From e382f91b60a8bbdbb900aa54ba1fdda8517133f8 Mon Sep 17 00:00:00 2001 From: OhThomas Date: Thu, 1 Dec 2022 19:47:56 -0600 Subject: [PATCH 3/8] Making variables local --- src/device/r4300/interrupt.c | 5 +---- src/main/main.c | 32 +++++++++++++++++--------------- src/main/main.h | 5 ++--- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/device/r4300/interrupt.c b/src/device/r4300/interrupt.c index 00f67dfe9..9741e0617 100644 --- a/src/device/r4300/interrupt.c +++ b/src/device/r4300/interrupt.c @@ -556,10 +556,7 @@ void gen_interrupt(struct r4300_core* r4300) // Doing this because the interpreter doesn't get initiated properly after resetting from // the in game settings menu (no instructions seem to get executed) - if(g_ResolutionReset != 0 && get_r4300_emumode(&g_dev.r4300) == 1 && g_LoadOnce == 0){ - main_state_load_latest_auto_save(); - g_LoadOnce++; - } + main_interpreter_reload(); return; } diff --git a/src/main/main.c b/src/main/main.c index cc12fa7ff..191a38d16 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -97,9 +97,7 @@ m64p_frame_callback g_FrameCallback = NULL; int g_RomWordsLittleEndian = 0; // after loading, ROM words are in native N64 byte order (big endian). We will swap them on x86 int g_EmulatorRunning = 0; // need separate boolean to tell if emulator is running, since --nogui doesn't use a thread -int g_EmuModeInitiated = 0; // we use this to help the plugin wait before initializing when resetting from in game settings -int g_ResolutionReset = 0; // used to check if the game needs to pause before starting because of in game settings being changed -int g_LoadOnce = 0; // used to prevent the interpreter from loading multiple times +int g_EmuModeInitiated = 0; // helps the plugin wait before initializing when resetting from in game settings int g_rom_pause; @@ -128,7 +126,9 @@ static int l_TakeScreenshot = 0; // Tell OSD Rendering callback to take static int l_SpeedFactor = 100; // percentage of nominal game speed at which emulator is running static int l_FrameAdvance = 0; // variable to check if we pause on next frame static int l_MainSpeedLimit = 1; // insert delay during vi_interrupt to keep speed at real-time +static int l_ResolutionReset = 0; // checks if the game needs to pause before starting because of in game settings being changed static int l_ResolutionResetCoreCounter = 0;// counts frames to make sure the video plugin is showing when resetting via resolution reset +static int l_LoadOnce = 0; // prevents the interpreter from loading multiple times static osd_message_t *l_msgVol = NULL; static osd_message_t *l_msgFF = NULL; @@ -575,13 +575,6 @@ void main_state_inc_slot(void) savestates_inc_slot(); } -void main_state_load_latest_auto_save() -{ - if (netplay_is_init() || l_FileName == NULL) - return; - savestates_set_job(savestates_job_load, savestates_type_unknown, l_FileName); -} - void main_state_load(const char *filename) { if(filename != NULL) { @@ -737,7 +730,7 @@ m64p_error main_core_state_set(m64p_core_param param, int val) // the front-end app is telling us that the user has resized the video output frame, and so // we should try to update the video plugin accordingly. First, check state if (val <= 0){ - g_ResolutionReset = val; + l_ResolutionReset = val; return M64ERR_SUCCESS; } int width, height; @@ -890,7 +883,7 @@ void new_frame(void) /* advance the current frame */ l_CurrentFrame++; - if(g_ResolutionReset != 0 && g_EmuModeInitiated == 1) + if(l_ResolutionReset != 0 && g_EmuModeInitiated == 1) l_ResolutionResetCoreCounter++; if (l_FrameAdvance) { @@ -993,7 +986,7 @@ static void pause_loop(void) osd_render(); // draw Paused message in case gfx.updateScreen didn't do it // using estimated frame skip settings with gfx plugin causes black screen - if(g_ResolutionReset == 0 && l_ResolutionResetCoreCounter != 0){ + if(l_ResolutionReset == 0 && l_ResolutionResetCoreCounter != 0){ if(l_ResolutionResetCoreCounter == -6) l_ResolutionResetCoreCounter = -5; else @@ -1012,10 +1005,10 @@ static void pause_loop(void) * sometimes the graphics plugin finishes first */ static void settings_reset_check(void) { - if(g_EmulatorRunning && !g_rom_pause && g_ResolutionReset != 0 && l_ResolutionResetCoreCounter >= 12){ + if(g_EmulatorRunning && !g_rom_pause && l_ResolutionReset != 0 && l_ResolutionResetCoreCounter >= 12){ main_toggle_pause(); l_ResolutionResetCoreCounter = -6; - g_ResolutionReset = 0; + l_ResolutionReset = 0; } } @@ -2082,3 +2075,12 @@ m64p_error open_pif(const unsigned char* pifimage, unsigned int size) g_start_address = UINT32_C(0xbfc00000); return M64ERR_SUCCESS; } + +void main_interpreter_reload() +{ + if (netplay_is_init() || l_FileName == NULL || + !(l_ResolutionReset != 0 && get_r4300_emumode(&g_dev.r4300) == 1 && l_LoadOnce == 0)) + return; + l_LoadOnce++; + savestates_set_job(savestates_job_load, savestates_type_unknown, l_FileName); +} diff --git a/src/main/main.h b/src/main/main.h index 1a1292f9b..e2e2bbb0a 100644 --- a/src/main/main.h +++ b/src/main/main.h @@ -43,8 +43,6 @@ extern m64p_handle g_CoreConfig; extern int g_RomWordsLittleEndian; extern int g_EmulatorRunning; extern int g_EmuModeInitiated; -extern int g_ResolutionReset; -extern int g_LoadOnce; extern int g_rom_pause; extern struct cheat_ctx g_cheat_ctx; @@ -87,7 +85,6 @@ void main_take_next_screenshot(void); void main_state_set_slot(int slot); void main_state_inc_slot(void); -void main_state_load_latest_auto_save(void); void main_state_load(const char *filename); void main_state_save(int format, const char *filename); @@ -108,5 +105,7 @@ m64p_error main_reset(int do_hard_reset); m64p_error open_pif(const unsigned char* pifimage, unsigned int size); +void main_interpreter_reload(void); + #endif /* __MAIN_H__ */ From 07893a21828d4dd9b6561b7a5df9209aa6f0acf5 Mon Sep 17 00:00:00 2001 From: OhThomas Date: Sat, 3 Dec 2022 00:34:05 -0600 Subject: [PATCH 4/8] Renaming for settings reset --- src/main/main.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/main.c b/src/main/main.c index 191a38d16..e42cb8c16 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -126,8 +126,8 @@ static int l_TakeScreenshot = 0; // Tell OSD Rendering callback to take static int l_SpeedFactor = 100; // percentage of nominal game speed at which emulator is running static int l_FrameAdvance = 0; // variable to check if we pause on next frame static int l_MainSpeedLimit = 1; // insert delay during vi_interrupt to keep speed at real-time -static int l_ResolutionReset = 0; // checks if the game needs to pause before starting because of in game settings being changed -static int l_ResolutionResetCoreCounter = 0;// counts frames to make sure the video plugin is showing when resetting via resolution reset +static int l_SettingsReset = 0; // checks if the game needs to pause before starting because of in game settings being changed +static int l_SettingsResetCoreCounter = 0;// counts frames to make sure the video plugin is showing when resetting via settings reset static int l_LoadOnce = 0; // prevents the interpreter from loading multiple times static osd_message_t *l_msgVol = NULL; @@ -730,7 +730,7 @@ m64p_error main_core_state_set(m64p_core_param param, int val) // the front-end app is telling us that the user has resized the video output frame, and so // we should try to update the video plugin accordingly. First, check state if (val <= 0){ - l_ResolutionReset = val; + l_SettingsReset = val; return M64ERR_SUCCESS; } int width, height; @@ -883,8 +883,8 @@ void new_frame(void) /* advance the current frame */ l_CurrentFrame++; - if(l_ResolutionReset != 0 && g_EmuModeInitiated == 1) - l_ResolutionResetCoreCounter++; + if(l_SettingsReset != 0 && g_EmuModeInitiated == 1) + l_SettingsResetCoreCounter++; if (l_FrameAdvance) { g_rom_pause = 1; @@ -986,9 +986,9 @@ static void pause_loop(void) osd_render(); // draw Paused message in case gfx.updateScreen didn't do it // using estimated frame skip settings with gfx plugin causes black screen - if(l_ResolutionReset == 0 && l_ResolutionResetCoreCounter != 0){ - if(l_ResolutionResetCoreCounter == -6) - l_ResolutionResetCoreCounter = -5; + if(l_SettingsReset == 0 && l_SettingsResetCoreCounter != 0){ + if(l_SettingsResetCoreCounter == -6) + l_SettingsResetCoreCounter = -5; else VidExt_GL_SwapBuffers(); } @@ -1005,10 +1005,10 @@ static void pause_loop(void) * sometimes the graphics plugin finishes first */ static void settings_reset_check(void) { - if(g_EmulatorRunning && !g_rom_pause && l_ResolutionReset != 0 && l_ResolutionResetCoreCounter >= 12){ + if(g_EmulatorRunning && !g_rom_pause && l_SettingsReset != 0 && l_SettingsResetCoreCounter >= 12){ main_toggle_pause(); - l_ResolutionResetCoreCounter = -6; - l_ResolutionReset = 0; + l_SettingsResetCoreCounter = -6; + l_SettingsReset = 0; } } @@ -1925,7 +1925,7 @@ m64p_error main_run(void) osd_new_message(OSD_MIDDLE_CENTER, "Mupen64Plus Started..."); g_EmulatorRunning = 1; - l_ResolutionResetCoreCounter = -5; + l_SettingsResetCoreCounter = -5; StateChanged(M64CORE_EMU_STATE, M64EMU_RUNNING); poweron_device(&g_dev); @@ -2079,7 +2079,7 @@ m64p_error open_pif(const unsigned char* pifimage, unsigned int size) void main_interpreter_reload() { if (netplay_is_init() || l_FileName == NULL || - !(l_ResolutionReset != 0 && get_r4300_emumode(&g_dev.r4300) == 1 && l_LoadOnce == 0)) + !(l_SettingsReset != 0 && get_r4300_emumode(&g_dev.r4300) == 1 && l_LoadOnce == 0)) return; l_LoadOnce++; savestates_set_job(savestates_job_load, savestates_type_unknown, l_FileName); From 131e52b8121aa054af395ade744986a61c42d107 Mon Sep 17 00:00:00 2001 From: OhThomas Date: Sat, 3 Dec 2022 01:06:07 -0600 Subject: [PATCH 5/8] Making l_FileName static --- src/main/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/main.c b/src/main/main.c index e42cb8c16..dbfde99b1 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -118,18 +118,18 @@ m64p_media_loader g_media_loader; int g_gs_vi_counter = 0; -char * l_FileName = NULL; // holds the latest auto save file name to use if we reset from in game settings - /** static (local) variables **/ static int l_CurrentFrame = 0; // frame counter static int l_TakeScreenshot = 0; // Tell OSD Rendering callback to take a screenshot just before drawing the OSD static int l_SpeedFactor = 100; // percentage of nominal game speed at which emulator is running static int l_FrameAdvance = 0; // variable to check if we pause on next frame static int l_MainSpeedLimit = 1; // insert delay during vi_interrupt to keep speed at real-time -static int l_SettingsReset = 0; // checks if the game needs to pause before starting because of in game settings being changed +static int l_SettingsReset = 0; // checks if the game needs to pause before starting because of in game settings being changed static int l_SettingsResetCoreCounter = 0;// counts frames to make sure the video plugin is showing when resetting via settings reset static int l_LoadOnce = 0; // prevents the interpreter from loading multiple times +static char * l_FileName = NULL; // holds the latest auto save file name to use if we reset from in game settings + static osd_message_t *l_msgVol = NULL; static osd_message_t *l_msgFF = NULL; static osd_message_t *l_msgPause = NULL; From f26d6cc298d1b349a6e1f2582598ba4bbaac061f Mon Sep 17 00:00:00 2001 From: OhThomas Date: Sat, 3 Dec 2022 18:06:11 -0600 Subject: [PATCH 6/8] Frame counter renamed --- src/main/main.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/main.c b/src/main/main.c index dbfde99b1..65789aa89 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -125,7 +125,7 @@ static int l_SpeedFactor = 100; // percentage of nominal game speed at static int l_FrameAdvance = 0; // variable to check if we pause on next frame static int l_MainSpeedLimit = 1; // insert delay during vi_interrupt to keep speed at real-time static int l_SettingsReset = 0; // checks if the game needs to pause before starting because of in game settings being changed -static int l_SettingsResetCoreCounter = 0;// counts frames to make sure the video plugin is showing when resetting via settings reset +static int l_SettingsFrameCounter = 0; // counts frames to make sure the video plugin is showing when resetting via settings reset static int l_LoadOnce = 0; // prevents the interpreter from loading multiple times static char * l_FileName = NULL; // holds the latest auto save file name to use if we reset from in game settings @@ -884,7 +884,7 @@ void new_frame(void) l_CurrentFrame++; if(l_SettingsReset != 0 && g_EmuModeInitiated == 1) - l_SettingsResetCoreCounter++; + l_SettingsFrameCounter++; if (l_FrameAdvance) { g_rom_pause = 1; @@ -986,12 +986,10 @@ static void pause_loop(void) osd_render(); // draw Paused message in case gfx.updateScreen didn't do it // using estimated frame skip settings with gfx plugin causes black screen - if(l_SettingsReset == 0 && l_SettingsResetCoreCounter != 0){ - if(l_SettingsResetCoreCounter == -6) - l_SettingsResetCoreCounter = -5; - else - VidExt_GL_SwapBuffers(); - } + if(l_SettingsReset == 0 && l_SettingsFrameCounter == -1) + l_SettingsFrameCounter = 0; + else + VidExt_GL_SwapBuffers(); while(g_rom_pause) { @@ -1005,9 +1003,9 @@ static void pause_loop(void) * sometimes the graphics plugin finishes first */ static void settings_reset_check(void) { - if(g_EmulatorRunning && !g_rom_pause && l_SettingsReset != 0 && l_SettingsResetCoreCounter >= 12){ + if(g_EmulatorRunning && !g_rom_pause && l_SettingsReset != 0 && l_SettingsFrameCounter >= 17){ main_toggle_pause(); - l_SettingsResetCoreCounter = -6; + l_SettingsFrameCounter = -1; // set to -1 to avoid swap buffer in case of frame skip settings l_SettingsReset = 0; } } @@ -1925,7 +1923,7 @@ m64p_error main_run(void) osd_new_message(OSD_MIDDLE_CENTER, "Mupen64Plus Started..."); g_EmulatorRunning = 1; - l_SettingsResetCoreCounter = -5; + l_SettingsFrameCounter = 0; StateChanged(M64CORE_EMU_STATE, M64EMU_RUNNING); poweron_device(&g_dev); From 99cddac006b653e365b5dba45e059b06ab914963 Mon Sep 17 00:00:00 2001 From: OhThomas Date: Fri, 9 Dec 2022 19:21:48 -0600 Subject: [PATCH 7/8] Removing l_LoadOnce --- src/main/main.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/main.c b/src/main/main.c index 65789aa89..50831d514 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -126,7 +126,6 @@ static int l_FrameAdvance = 0; // variable to check if we pause on nex static int l_MainSpeedLimit = 1; // insert delay during vi_interrupt to keep speed at real-time static int l_SettingsReset = 0; // checks if the game needs to pause before starting because of in game settings being changed static int l_SettingsFrameCounter = 0; // counts frames to make sure the video plugin is showing when resetting via settings reset -static int l_LoadOnce = 0; // prevents the interpreter from loading multiple times static char * l_FileName = NULL; // holds the latest auto save file name to use if we reset from in game settings @@ -2076,9 +2075,9 @@ m64p_error open_pif(const unsigned char* pifimage, unsigned int size) void main_interpreter_reload() { - if (netplay_is_init() || l_FileName == NULL || - !(l_SettingsReset != 0 && get_r4300_emumode(&g_dev.r4300) == 1 && l_LoadOnce == 0)) - return; - l_LoadOnce++; - savestates_set_job(savestates_job_load, savestates_type_unknown, l_FileName); + if (!netplay_is_init() && l_FileName != NULL && + l_SettingsReset != 0 && get_r4300_emumode(&g_dev.r4300) == 1) { + savestates_set_job(savestates_job_load, savestates_type_unknown, l_FileName); + free_current_save(); + } } From 46966b34f086640fecf1e2d7c4cc5cdf8f9165d8 Mon Sep 17 00:00:00 2001 From: OhThomas Date: Mon, 12 Dec 2022 18:30:46 -0600 Subject: [PATCH 8/8] Removing l_FileName --- src/device/r4300/interrupt.c | 4 ---- src/main/main.c | 30 ------------------------------ src/main/main.h | 2 -- 3 files changed, 36 deletions(-) diff --git a/src/device/r4300/interrupt.c b/src/device/r4300/interrupt.c index 9741e0617..dd37e6c74 100644 --- a/src/device/r4300/interrupt.c +++ b/src/device/r4300/interrupt.c @@ -553,10 +553,6 @@ void gen_interrupt(struct r4300_core* r4300) if (savestates_get_job() == savestates_job_load) { savestates_load(); - - // Doing this because the interpreter doesn't get initiated properly after resetting from - // the in game settings menu (no instructions seem to get executed) - main_interpreter_reload(); return; } diff --git a/src/main/main.c b/src/main/main.c index 50831d514..20324e2db 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -127,8 +127,6 @@ static int l_MainSpeedLimit = 1; // insert delay during vi_interrupt to static int l_SettingsReset = 0; // checks if the game needs to pause before starting because of in game settings being changed static int l_SettingsFrameCounter = 0; // counts frames to make sure the video plugin is showing when resetting via settings reset -static char * l_FileName = NULL; // holds the latest auto save file name to use if we reset from in game settings - static osd_message_t *l_msgVol = NULL; static osd_message_t *l_msgFF = NULL; static osd_message_t *l_msgPause = NULL; @@ -313,14 +311,6 @@ static void main_check_inputs(void) SDL_PumpEvents(); } -static void free_current_save(void) -{ - if(l_FileName != NULL) { - free(l_FileName); - l_FileName = NULL; - } -} - /********************************************************************************************************* * global functions, for adjusting the core emulator behavior */ @@ -576,12 +566,6 @@ void main_state_inc_slot(void) void main_state_load(const char *filename) { - if(filename != NULL) { - free_current_save(); - l_FileName = malloc(strlen(filename) + 1); - strcpy(l_FileName, filename); - } - if (netplay_is_init()) return; @@ -690,10 +674,6 @@ m64p_error main_core_state_set(m64p_core_param param, int val) main_toggle_pause(); return M64ERR_SUCCESS; } - else if (val == 5) { - free_current_save(); - return M64ERR_SUCCESS; - } return M64ERR_INPUT_INVALID; case M64CORE_VIDEO_MODE: if (!g_EmulatorRunning) @@ -1972,7 +1952,6 @@ m64p_error main_run(void) // clean up g_EmulatorRunning = 0; g_EmuModeInitiated = 0; - free_current_save(); StateChanged(M64CORE_EMU_STATE, M64EMU_STOPPED); return M64ERR_SUCCESS; @@ -2072,12 +2051,3 @@ m64p_error open_pif(const unsigned char* pifimage, unsigned int size) g_start_address = UINT32_C(0xbfc00000); return M64ERR_SUCCESS; } - -void main_interpreter_reload() -{ - if (!netplay_is_init() && l_FileName != NULL && - l_SettingsReset != 0 && get_r4300_emumode(&g_dev.r4300) == 1) { - savestates_set_job(savestates_job_load, savestates_type_unknown, l_FileName); - free_current_save(); - } -} diff --git a/src/main/main.h b/src/main/main.h index e2e2bbb0a..6890549fb 100644 --- a/src/main/main.h +++ b/src/main/main.h @@ -105,7 +105,5 @@ m64p_error main_reset(int do_hard_reset); m64p_error open_pif(const unsigned char* pifimage, unsigned int size); -void main_interpreter_reload(void); - #endif /* __MAIN_H__ */