X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=common%2Femu.c;h=1e836941176c40db7842fbee2a94b41722f71971;hb=9cfdd2d2e94daaeb85ab7f1675312dec80659ec3;hp=370242dc951feb4ef5c5ca02f192bd5fbe087636;hpb=6c026031a80434cda8499e2208538e0155466d6b;p=libpicofe.git diff --git a/common/emu.c b/common/emu.c index 370242d..1e83694 100644 --- a/common/emu.c +++ b/common/emu.c @@ -464,25 +464,25 @@ int emu_reload_rom(char *rom_fname) // check for both gmv and rom int dummy; FILE *movie_file = fopen(rom_fname, "rb"); - if(!movie_file) { + if (!movie_file) { me_update_msg("Failed to open movie."); return 0; } fseek(movie_file, 0, SEEK_END); movie_size = ftell(movie_file); fseek(movie_file, 0, SEEK_SET); - if(movie_size < 64+3) { + if (movie_size < 64+3) { me_update_msg("Invalid GMV file."); fclose(movie_file); return 0; } movie_data = malloc(movie_size); - if(movie_data == NULL) { + if (movie_data == NULL) { me_update_msg("low memory."); fclose(movie_file); return 0; } - fread(movie_data, 1, movie_size, movie_file); + dummy = fread(movie_data, 1, movie_size, movie_file); fclose(movie_file); if (strncmp((char *)movie_data, "Gens Movie TEST", 15) != 0) { me_update_msg("Invalid GMV file."); @@ -730,6 +730,27 @@ static void make_config_cfg(char *cfg_buff_512) cfg_buff_512[511] = 0; } +void emu_prep_defconfig(void) +{ + memset(&defaultConfig, 0, sizeof(defaultConfig)); + defaultConfig.EmuOpt = 0x9d | EOPT_RAM_TIMINGS|EOPT_CONFIRM_SAVE|EOPT_EN_CD_LEDS; + defaultConfig.s_PicoOpt = POPT_EN_STEREO|POPT_EN_FM|POPT_EN_PSG|POPT_EN_Z80 | + POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_SVP_DRC|POPT_ACC_SPRITES | + POPT_EN_32X|POPT_EN_PWM; + defaultConfig.s_PsndRate = 44100; + defaultConfig.s_PicoRegion = 0; // auto + defaultConfig.s_PicoAutoRgnOrder = 0x184; // US, EU, JP + defaultConfig.s_PicoCDBuffers = 0; + defaultConfig.Frameskip = -1; // auto + defaultConfig.volume = 50; + defaultConfig.gamma = 100; + defaultConfig.scaling = 0; + defaultConfig.turbo_rate = 15; + + // platform specific overrides + pemu_prep_defconfig(); +} + void emu_set_defconfig(void) { memcpy(¤tConfig, &defaultConfig, sizeof(currentConfig)); @@ -786,7 +807,7 @@ int emu_read_config(int game, int no_defaults) } } - plat_validate_config(); + pemu_validate_config(); // some sanity checks #ifdef PSP @@ -1008,13 +1029,16 @@ int emu_save_load_game(int load, int sram) sram_size = SRam.size; sram_data = SRam.data; } - if (!sram_data) return 0; // SRam forcefully disabled for this game + if (sram_data == NULL) + return 0; // SRam forcefully disabled for this game if (load) { sramFile = fopen(saveFname, "rb"); - if(!sramFile) return -1; - fread(sram_data, 1, sram_size, sramFile); + if (!sramFile) + return -1; + ret = fread(sram_data, 1, sram_size, sramFile); + ret = ret > 0 ? 0 : -1; fclose(sramFile); if ((PicoAHW & PAHW_MCD) && (PicoOpt&POPT_EN_MCD_RAMCART)) memcpy32((int *)Pico_mcd->bram, (int *)sram_data, 0x2000/4); @@ -1092,7 +1116,7 @@ static void emu_tray_close(void) void emu_32x_startup(void) { - plat_video_toggle_renderer(0, 1, 0); + plat_video_toggle_renderer(0, 0); system_announce(); } @@ -1223,9 +1247,9 @@ static void run_events_ui(unsigned int which) PicoStateProgressCB = NULL; } } - if ((which & PEV_SWITCH_RND) && !(PicoAHW & PAHW_32X)) + if (which & PEV_SWITCH_RND) { - plat_video_toggle_renderer(1, 0, 0); + plat_video_toggle_renderer(1, 0); } if (which & (PEV_SSLOT_PREV|PEV_SSLOT_NEXT)) { @@ -1323,6 +1347,8 @@ void emu_init(void) mkdir_path(path, pos, "srm"); mkdir_path(path, pos, "brm"); + pprof_init(); + make_config_cfg(path); config_readlrom(path); @@ -1349,6 +1375,8 @@ void emu_finish(void) #endif } + pprof_finish(); + PicoExit(); } @@ -1408,6 +1436,8 @@ void emu_loop(void) unsigned int timestamp; int diff, diff_lim; + pprof_start(main); + timestamp = get_ticks(); if (reset_timing) { reset_timing = 0; @@ -1446,6 +1476,7 @@ void emu_loop(void) } bench_fps += frames_shown; sprintf(fpsbuff, "%02i/%02i/%02i", frames_shown, bench_fps_s, (bf[0]+bf[1]+bf[2]+bf[3])>>2); + printf("%s\n", fpsbuff); #else if (currentConfig.EmuOpt & EOPT_SHOW_FPS) { sprintf(fpsbuff, "%02i/%02i", frames_shown, frames_done); @@ -1463,17 +1494,15 @@ void emu_loop(void) { 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; + if (pframes_done < -2) { + /* don't drag more than 2 frames behind */ + pframes_done = -2; + timestamp_base = timestamp - 2 * target_frametime; } - timestamp_base += ms_to_ticks(1000); + else + timestamp_base += ms_to_ticks(1000); } diff = timestamp - timestamp_base; @@ -1498,19 +1527,20 @@ void emu_loop(void) else if (diff > diff_lim) { /* no time left for this frame - skip */ - if (diff - diff_lim >= ms_to_ticks(200)) { - /* if too much behind, reset instead */ - reset_timing = 1; + /* limit auto frameskip to 8 */ + if (frames_done / 8 <= frames_shown) { + emu_update_input(); + skip_frame(diff < diff_lim + target_frametime * 16); + pframes_done++; frames_done++; continue; } - emu_update_input(); - skip_frame(diff < diff_lim + target_frametime * 2); - pframes_done++; frames_done++; - continue; } emu_update_input(); PicoFrame(); + pemu_finalize_frame(fpsbuff, notice_msg); + + // plat_video_flip(); /* frame limiter */ if (!reset_timing && !(currentConfig.EmuOpt & (EOPT_NO_FRMLIMIT|EOPT_EXT_FRMLIMIT))) @@ -1528,9 +1558,13 @@ void emu_loop(void) } } - pemu_update_display(fpsbuff, notice_msg); + // XXX: for some plats it might be better to flip before vsync + // (due to shadow registers in display hw) + plat_video_flip(); pframes_done++; frames_done++; frames_shown++; + + pprof_end(main); } emu_set_fastforward(0);