X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fcommon%2Femu.c;h=7de2aa99a2be211c505ee228b7b04453dd513498;hb=370d5805173cf2a3a3739b4245e6a27a47dd51d2;hp=5bd34e879c6d065396767b3958153015cde83287;hpb=b24e0f6ce6e8a59ba43597520709ca79fa36ff8e;p=picodrive.git diff --git a/platform/common/emu.c b/platform/common/emu.c index 5bd34e8..7de2aa9 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -25,6 +25,8 @@ #include +#define STATUS_MSG_TIMEOUT 2000 + void *g_screen_ptr; #if !SCREEN_SIZE_FIXED @@ -78,9 +80,9 @@ static int try_rfn_cut(char *fname) return 0; } -static void get_ext(char *file, char *ext) +static void get_ext(const char *file, char *ext) { - char *p; + const char *p; p = file + strlen(file) - 4; if (p < file) p = file; @@ -92,23 +94,29 @@ static void get_ext(char *file, char *ext) void emu_status_msg(const char *format, ...) { va_list vl; + int ret; va_start(vl, format); - vsnprintf(noticeMsg, sizeof(noticeMsg), format, vl); + ret = vsnprintf(noticeMsg, sizeof(noticeMsg), format, vl); va_end(vl); + /* be sure old text gets overwritten */ + for (; ret < 28; ret++) + noticeMsg[ret] = ' '; + noticeMsg[ret] = 0; + notice_msg_time = plat_get_ticks_ms(); } -static const char *biosfiles_us[] = { "us_scd1_9210", "us_scd2_9306", "SegaCDBIOS9303" }; -static const char *biosfiles_eu[] = { "eu_mcd1_9210", "eu_mcd2_9306", "eu_mcd2_9303" }; -static const char *biosfiles_jp[] = { "jp_mcd1_9112", "jp_mcd1_9111" }; +static const char * const biosfiles_us[] = { "us_scd1_9210", "us_scd2_9306", "SegaCDBIOS9303" }; +static const char * const biosfiles_eu[] = { "eu_mcd1_9210", "eu_mcd2_9306", "eu_mcd2_9303" }; +static const char * const biosfiles_jp[] = { "jp_mcd1_9112", "jp_mcd1_9111" }; static int find_bios(int region, char **bios_file) { static char bios_path[1024]; int i, count; - const char **files; + const char * const *files; FILE *f = NULL; if (region == 4) { // US @@ -169,12 +177,13 @@ static unsigned char id_header[0x100]; /* checks if fname points to valid MegaCD image * if so, checks for suitable BIOS */ -int emu_cd_check(int *pregion, char *fname_in) +static int emu_cd_check(int *pregion, const char *fname_in) { + const char *fname = fname_in; unsigned char buf[32]; pm_file *cd_f; int region = 4; // 1: Japan, 4: US, 8: Europe - char ext[5], *fname = fname_in; + char ext[5]; cue_track_type type = CT_UNKNOWN; cue_data_t *cue_data = NULL; @@ -523,6 +532,24 @@ fail: return 0; } +int emu_swap_cd(const char *fname) +{ + cd_img_type cd_type; + int ret = -1; + + cd_type = emu_cd_check(NULL, fname); + if (cd_type != CIT_NOT_CD) + ret = Insert_CD(fname, cd_type); + if (ret != 0) { + me_update_msg("Load failed, invalid CD image?"); + return 0; + } + + strncpy(rom_fname_loaded, fname, sizeof(rom_fname_loaded)-1); + rom_fname_loaded[sizeof(rom_fname_loaded)-1] = 0; + return 1; +} + static void romfname_ext(char *dst, const char *prefix, const char *ext) { char *p; @@ -924,7 +951,7 @@ int emu_save_load_game(int load, int sram) } else ret = -1; if (!ret) - emu_status_msg(load ? "GAME LOADED" : "GAME SAVED"); + emu_status_msg(load ? "STATE LOADED" : "STATE SAVED"); else { emu_status_msg(load ? "LOAD FAILED" : "SAVE FAILED"); @@ -1086,7 +1113,7 @@ static void run_events_ui(unsigned int which) in_set_blocking(0); } if (do_it) { - plat_status_msg_busy_first((which & PEV_STATE_LOAD) ? "LOADING GAME" : "SAVING GAME"); + plat_status_msg_busy_first((which & PEV_STATE_LOAD) ? "LOADING STATE" : "SAVING STATE"); PicoStateProgressCB = plat_status_msg_busy_next; emu_save_load_game((which & PEV_STATE_LOAD) ? 1 : 0, 0); PicoStateProgressCB = NULL; @@ -1276,7 +1303,7 @@ void emu_loop(void) if (notice_msg_time != 0) { static int noticeMsgSum; - if (timestamp - ms_to_ticks(notice_msg_time) > ms_to_ticks(2000)) { + if (timestamp - ms_to_ticks(notice_msg_time) > ms_to_ticks(STATUS_MSG_TIMEOUT)) { notice_msg_time = 0; plat_status_msg_clear(); notice_msg = NULL; @@ -1325,10 +1352,18 @@ void emu_loop(void) if (timestamp - timestamp_base >= ms_to_ticks(1000)) { - if (PsndOut == 0 && currentConfig.Frameskip >= 0) + if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && currentConfig.Frameskip >= 0) pframes_done = 0; - else + else { pframes_done -= target_fps; + /* don't allow it to drift during heavy slowdowns */ + if (pframes_done < -5) { + reset_timing = 1; + continue; + } + if (pframes_done < -2) + pframes_done = -2; + } timestamp_base += ms_to_ticks(1000); } @@ -1343,7 +1378,7 @@ void emu_loop(void) pframes_done++; frames_done++; diff_lim += target_frametime; - if (PsndOut && !reset_timing) { // do framelimitting if sound is enabled + if (!(currentConfig.EmuOpt & EOPT_NO_FRMLIMIT)) { timestamp = get_ticks(); diff = timestamp - timestamp_base; if (diff < diff_lim) // we are too fast @@ -1354,7 +1389,7 @@ void emu_loop(void) else if (diff > diff_lim) { /* no time left for this frame - skip */ - if (diff - diff_lim >= ms_to_ticks(300)) { + if (diff - diff_lim >= ms_to_ticks(200)) { /* if too much behind, reset instead */ reset_timing = 1; continue; @@ -1369,7 +1404,7 @@ void emu_loop(void) PicoFrame(); /* frame limiter */ - if (!reset_timing && (PsndOut != NULL || currentConfig.Frameskip < 0)) + if (!reset_timing && !(currentConfig.EmuOpt & EOPT_NO_FRMLIMIT)) { timestamp = get_ticks(); diff = timestamp - timestamp_base;