From 484383a5023d372948b5470d52b9a171a7797297 Mon Sep 17 00:00:00 2001 From: Vincent-FK Date: Sat, 17 Apr 2021 19:32:30 +0200 Subject: [PATCH 1/2] corrected pclose in init_menu_system_values --- platform/common/emu.c | 2 +- platform/common/main.c | 7 +++++++ platform/common/menu_pico.c | 22 +++++++++++----------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/platform/common/emu.c b/platform/common/emu.c index 88f0cb6f..168941f2 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -210,7 +210,7 @@ static const char *find_bios(int *region, const char *cd_fname) for (i = 0; i < count; i++) { emu_make_path(static_buff, files[i], sizeof(static_buff) - 4); - printf("static_buff: %s\n", static_buff); + //printf("bios name static_buff: %s\n", static_buff); strcat(static_buff, ".bin"); f = fopen(static_buff, "rb"); if (f) break; diff --git a/platform/common/main.c b/platform/common/main.c index 9b3852d4..2f2d6e12 100644 --- a/platform/common/main.c +++ b/platform/common/main.c @@ -245,6 +245,13 @@ int main(int argc, char *argv[]) for (;;) { + /** Debug */ + /*static int prev_engine_state = -1; + if(prev_engine_state != engineState){ + printf("current engine state: %d, prev = %d\n", engineState, prev_engine_state); + prev_engine_state = engineState; + }*/ + switch (engineState) { case PGS_Menu: diff --git a/platform/common/menu_pico.c b/platform/common/menu_pico.c index 53d0641a..61511881 100644 --- a/platform/common/menu_pico.c +++ b/platform/common/menu_pico.c @@ -443,8 +443,8 @@ void init_menu_system_values(){ volume_percentage = 50; ///wrong value: setting default to 50 } else{ - pclose(fp); fgets(res, sizeof(res)-1, fp); + pclose(fp); /// Check if Volume is a number (at least the first char) if(res[0] < '0' || res[0] > '9'){ @@ -464,8 +464,8 @@ void init_menu_system_values(){ brightness_percentage = 50; ///wrong value: setting default to 50 } else{ - pclose(fp); fgets(res, sizeof(res)-1, fp); + pclose(fp); /// Check if brightness is a number (at least the first char) if(res[0] < '0' || res[0] > '9'){ @@ -806,8 +806,8 @@ void run_menu_loop() if (fp == NULL) { MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd); } else { - pclose(fp); - } + pclose(fp); + } /// ------ Refresh screen ------ screen_refresh = 1; @@ -824,7 +824,7 @@ void run_menu_loop() if (fp == NULL) { MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd); } else { - pclose(fp); + pclose(fp); } /// ------ Refresh screen ------ screen_refresh = 1; @@ -882,7 +882,7 @@ void run_menu_loop() if (fp == NULL) { MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd); } else { - pclose(fp); + pclose(fp); } /// ------ Refresh screen ------ screen_refresh = 1; @@ -899,7 +899,7 @@ void run_menu_loop() if (fp == NULL) { MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd); } else { - pclose(fp); + pclose(fp); } /// ------ Refresh screen ------ screen_refresh = 1; @@ -966,8 +966,8 @@ void run_menu_loop() fp = popen(shell_cmd, "r"); if (fp == NULL) { MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd); - } else { - pclose(fp); + } else { + pclose(fp); } stop_menu_loop = 1; @@ -1013,8 +1013,8 @@ void run_menu_loop() fp = popen(shell_cmd, "r"); if (fp == NULL) { MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd); - } else { - pclose(fp); + } else { + pclose(fp); } /*snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "LOADED" : "FAIL!"); From b1a23f037d125d84cb74ffd6e391a55bcb2482bb Mon Sep 17 00:00:00 2001 From: Vincent-FK Date: Sat, 17 Apr 2021 20:22:29 +0200 Subject: [PATCH 2/2] corrected quick loads for Sega CD, fix for now --- platform/common/emu.c | 42 ++++++++++++++++++++++++++++++++++++---- platform/common/emu.h | 4 ++++ platform/common/main.c | 44 ++++++++++++++++++++++++++++-------------- 3 files changed, 71 insertions(+), 19 deletions(-) diff --git a/platform/common/emu.c b/platform/common/emu.c index 168941f2..39097f4c 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -1504,8 +1504,9 @@ void emu_cmn_forced_frame(int no_scale, int do_emu, void *buf) PicoIn.opt = po_old; } - - +int emu_is_segaCD(){ + return (PicoIn.AHW & PAHW_MCD); +} /* Quick save and turn off the console */ void quick_save_and_poweroff() @@ -1669,6 +1670,7 @@ static void emu_loop_prep(void) void emu_loop(void) { int frames_done, frames_shown; /* actual frames for fps counter */ + int frame_nb = 0; int target_frametime_x3; unsigned int timestamp_x3 = 0; unsigned int timestamp_aim_x3 = 0; @@ -1679,6 +1681,8 @@ void emu_loop(void) fpsbuff[0] = 0; + printf("%s ------------------ \n", __func__); + PicoLoopPrepare(); plat_video_loop_prepare(); @@ -1797,8 +1801,8 @@ void emu_loop(void) /* Quick save and poweroff */ if(mQuickSaveAndPoweroff){ - quick_save_and_poweroff(); - mQuickSaveAndPoweroff = 0; + quick_save_and_poweroff(); + mQuickSaveAndPoweroff = 0; } emu_update_input(); @@ -1842,6 +1846,36 @@ void emu_loop(void) if (!skip && flip_after_sync) plat_video_flip(); + + /* FOR SEGA CD */ + /* Leave some time for the bios to load before starting a quick load at boot */ + /* (Sega CD doesn't quick load at boot otherwise) */ + /* Should have a much cleaner implementation thant this fix */ + if((PicoIn.AHW & PAHW_MCD) && frame_nb >= 100){ + + /* Load slot */ + if(load_state_slot != -1){ + printf("LOADING FROM SLOT (SEGA CD) %d...\n", load_state_slot+1); + char fname[1024]; + emu_save_load_game(1, 0); + printf("LOADED FROM SLOT (SEGA CD) %d\n", load_state_slot+1); + load_state_slot = -1; + } + if(need_quick_load != -1){ + load_state_file = quick_save_file; + need_quick_load = -1; + } + /* Load file */ + if(load_state_file != NULL){ + printf("LOADING FROM FILE (SEGA CD) %s...\n", load_state_file); + emu_save_load_game_from_file(1, load_state_file); + printf("LOADED FROM SLOT (SEGA CD) %s\n", load_state_file); + load_state_file = NULL; + } + } + + frame_nb++; + pprof_end(main); } diff --git a/platform/common/emu.h b/platform/common/emu.h index f81ad157..f2e2fc30 100644 --- a/platform/common/emu.h +++ b/platform/common/emu.h @@ -90,6 +90,9 @@ extern int flip_after_sync; extern int show_fps_bypass; extern int need_screen_cleared; extern int mQuickSaveAndPoweroff; +extern char *load_state_file; +extern int load_state_slot; +extern int need_quick_load; extern char *prog_name; extern char *mRomName; @@ -150,6 +153,7 @@ void emu_update_input(void); void emu_get_game_name(char *str150); void emu_set_fastforward(int set_on); void emu_status_msg(const char *format, ...); +int emu_is_segaCD(); /* default sound code */ void emu_sound_start(void); diff --git a/platform/common/main.c b/platform/common/main.c index 2f2d6e12..861a8325 100644 --- a/platform/common/main.c +++ b/platform/common/main.c @@ -30,12 +30,13 @@ char **g_argv; char *prog_name; -static char *load_state_file = NULL; -static int load_state_slot = -1; +char *load_state_file = NULL; +int load_state_slot = -1; static char *quick_save_file_extension = "quicksave"; char *mRomName = NULL; char *mRomPath = NULL; char *quick_save_file = NULL; +int need_quick_load = -1; char *cfg_file_default = NULL; char *cfg_file_rom = NULL; static char *cfg_file_default_name = "default_config"; @@ -204,29 +205,42 @@ int main(int argc, char *argv[]) if (emu_reload_rom(rom_fname_reload)) { engineState = PGS_Running; - /* Load slot */ + /* Load slot (if NOT sega CD) */ if(load_state_slot != -1){ - printf("LOADING FROM SLOT %d...\n", load_state_slot+1); - char fname[1024]; - emu_save_load_game(1, 0); - printf("LOADED FROM SLOT %d\n", load_state_slot+1); - load_state_slot = -1; + + /* DO NOT put this if in the previous one, we need this here not to enter the next else */ + if(!emu_is_segaCD()){ + printf("LOADING FROM SLOT %d...\n", load_state_slot+1); + char fname[1024]; + emu_save_load_game(1, 0); + printf("LOADED FROM SLOT %d\n", load_state_slot+1); + load_state_slot = -1; + } } - /* Load file */ + /* Load file (if NOT sega CD) */ else if(load_state_file != NULL){ - printf("LOADING FROM FILE %s...\n", load_state_file); - emu_save_load_game_from_file(1, load_state_file); - printf("LOADED FROM SLOT %s\n", load_state_file); - load_state_file = NULL; + + /* DO NOT put this if in the previous one, we need this here not to enter the next else */ + if(!emu_is_segaCD()){ + printf("LOADING FROM FILE %s...\n", load_state_file); + emu_save_load_game_from_file(1, load_state_file); + printf("LOADED FROM SLOT %s\n", load_state_file); + load_state_file = NULL; + } } - /* Load quick save file */ + /* Load quick save file (if NOT sega CD) */ else if(access( quick_save_file, F_OK ) != -1){ printf("Found quick save file: %s\n", quick_save_file); int resume = launch_resume_menu_loop(); if(resume == RESUME_YES){ printf("Resume game from quick save file: %s\n", quick_save_file); - emu_save_load_game_from_file(1, quick_save_file); + if(emu_is_segaCD()){ + need_quick_load = 1; + } + else{ + emu_save_load_game_from_file(1, quick_save_file); + } } else{ printf("Reset game\n");