X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fgp2x%2Femu.c;h=ce056b3e33d68d9f1d785b47c154c931020589bc;hb=48e8482fc2d74c9b96e581241390bade986acb22;hp=3d6cd3a2ca94d1959a1ab500b549a9e5eaec985c;hpb=83bd0b76aba19ff62368cfee76089e15579e3b7c;p=picodrive.git diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index 3d6cd3a..ce056b3 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -393,6 +393,8 @@ int emu_ReloadRom(void) } +static void emu_msg_cb(const char *msg); + void emu_Init(void) { // make temp buffer for alt renderer @@ -409,6 +411,7 @@ void emu_Init(void) mkdir("cfg", 0777); PicoInit(); + PicoMessage = emu_msg_cb; // logf = fopen("log.txt", "w"); } @@ -496,6 +499,7 @@ int emu_ReadConfig(int game) currentConfig.KeyBinds[23] = 1<<29; // vol up currentConfig.KeyBinds[22] = 1<<30; // vol down currentConfig.gamma = 100; + currentConfig.PicoCDBuffers = 64; strncpy(cfg, PicoConfigFile, 511); cfg[511] = 0; } else { @@ -517,6 +521,7 @@ int emu_ReadConfig(int game) PsndRate = currentConfig.PsndRate; PicoRegionOverride = currentConfig.PicoRegion; PicoAutoRgnOrder = currentConfig.PicoAutoRgnOrder; + PicoCDBuffers = currentConfig.PicoCDBuffers; if (PicoOpt & 0x20) { actionNames[ 8] = "Z"; actionNames[ 9] = "Y"; actionNames[10] = "X"; actionNames[11] = "MODE"; @@ -545,7 +550,7 @@ int emu_WriteConfig(int game) strncpy(cfg, PicoConfigFile, 511); cfg[511] = 0; } else { - romfname_ext(cfg, "cfg", ".pbcfg"); + romfname_ext(cfg, "cfg/", ".pbcfg"); } printf("emu_WriteConfig: %s ", cfg); @@ -555,6 +560,7 @@ int emu_WriteConfig(int game) currentConfig.PsndRate = PsndRate; currentConfig.PicoRegion = PicoRegionOverride; currentConfig.PicoAutoRgnOrder = PicoAutoRgnOrder; + currentConfig.PicoCDBuffers = PicoCDBuffers; bwrite = fwrite(¤tConfig, 1, sizeof(currentConfig), f); fflush(f); fclose(f); @@ -768,6 +774,23 @@ static void vidResetMode(void) } +static void emu_msg_cb(const char *msg) +{ + if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { + // 8-bit renderers + gp2x_memset_all_buffers(320*232, 0xe0, 320*8); + osd_text(4, 232, msg); + gp2x_memcpy_all_buffers((char *)gp2x_screen+320*232, 320*232, 320*8); + } else { + // 16bit accurate renderer + gp2x_memset_all_buffers(320*232*2, 0, 320*8*2); + osd_text(4, 232, msg); + gp2x_memcpy_all_buffers((char *)gp2x_screen+320*232*2, 320*232*2, 320*8*2); + } + gettimeofday(¬iceMsgTime, 0); + noticeMsgTime.tv_sec -= 2; +} + static void emu_state_cb(const char *str) { clearArea(0); @@ -950,21 +973,11 @@ static void updateSound(int len) } -static void SkipFrame(int do_sound) +static void SkipFrame(void) { - void *sndbuff_tmp = 0; - if (PsndOut && !do_sound) { - sndbuff_tmp = PsndOut; - PsndOut = 0; - } - PicoSkipFrame=1; PicoFrame(); PicoSkipFrame=0; - - if (sndbuff_tmp && !do_sound) { - PsndOut = sndbuff_tmp; - } } @@ -974,7 +987,6 @@ void emu_forced_frame(void) PicoOpt |= 0x10; PicoFrameFull(); - PicoOpt = po_old; if (!(Pico.video.reg[12]&1)) { vidCpyM2 = vidCpyM2_32col; @@ -984,6 +996,8 @@ void emu_forced_frame(void) vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8); vidConvCpyRGB32(localPal, Pico.cram, 0x40); gp2x_video_setpalette(localPal, 0x40); + + PicoOpt = po_old; } static void simpleWait(int thissec, int lim_time) @@ -1068,6 +1082,9 @@ void emu_Loop(void) PsndOut = 0; } + // prepare CD buffer + if (PicoMCD & 1) PicoCDBufferInit(); + // loop? while (engineState == PGS_Running) { @@ -1140,7 +1157,7 @@ void emu_Loop(void) // when second changes, but we don't want buffer to starve. if(PsndOut && frames_done < target_fps && frames_done > target_fps-5) { updateKeys(); - SkipFrame(1); frames_done++; + SkipFrame(); frames_done++; } frames_done -= target_fps; if (frames_done < 0) frames_done = 0; @@ -1153,7 +1170,7 @@ void emu_Loop(void) if(currentConfig.Frameskip >= 0) { // frameskip enabled for(i = 0; i < currentConfig.Frameskip; i++) { updateKeys(); - SkipFrame(1); frames_done++; + SkipFrame(); frames_done++; if (PsndOut) { // do framelimitting if sound is enabled gettimeofday(&tval, 0); if(thissec != tval.tv_sec) tval.tv_usec+=1000000; @@ -1165,8 +1182,14 @@ void emu_Loop(void) } } else if(tval.tv_usec > lim_time) { // auto frameskip // no time left for this frame - skip + if (tval.tv_usec - lim_time >= 0x300000) { + /* something caused a slowdown for us (disk access? cache flush?) + * try to recover by resetting timing... */ + reset_timing = 1; + continue; + } updateKeys(); - SkipFrame(tval.tv_usec < lim_time+target_frametime); frames_done++; + SkipFrame(/*tval.tv_usec < lim_time+target_frametime*/); frames_done++; continue; } @@ -1233,14 +1256,14 @@ if (Pico.m.frame_count == 31563) { // check time gettimeofday(&tval, 0); - if(thissec != tval.tv_sec) tval.tv_usec+=1000000; + if (thissec != tval.tv_sec) tval.tv_usec+=1000000; - // sleep if we are still too fast - if(PsndOut != 0 || currentConfig.Frameskip < 0) + if (currentConfig.Frameskip < 0 && tval.tv_usec - lim_time >= 0x300000) // slowdown detection + reset_timing = 1; + else if (PsndOut != NULL || currentConfig.Frameskip < 0) { + // sleep if we are still too fast // usleep sleeps for ~20ms minimum, so it is not a solution here - gettimeofday(&tval, 0); - if(thissec != tval.tv_sec) tval.tv_usec+=1000000; if(tval.tv_usec < lim_time) { // we are too fast @@ -1253,6 +1276,9 @@ if (Pico.m.frame_count == 31563) { frames_done++; frames_shown++; } + + if (PicoMCD & 1) PicoCDBufferFree(); + // save SRAM if((currentConfig.EmuOpt & 1) && SRam.changed) { osd_text(4, 232, "Writing SRAM/BRAM..");