3 #include <sys/syslimits.h> // PATH_MAX
5 #include <pspthreadman.h>
6 #include <pspdisplay.h>
13 #include "../common/emu.h"
14 #include "../common/lprintf.h"
15 #include "../../Pico/PicoInt.h"
23 char romFileName[PATH_MAX];
24 unsigned char *PicoDraw2FB = (unsigned char *)VRAM_CACHED_STUFF + 8; // +8 to be able to skip border with 1 quadword..
27 static int combo_keys = 0, combo_acts = 0; // keys and actions which need button combos
28 static unsigned int noticeMsgTime = 0;
29 int reset_timing = 0; // do we need this?
32 static void blit(const char *fps, const char *notice);
33 static void clearArea(int full);
35 void emu_noticeMsgUpdated(void)
37 noticeMsgTime = sceKernelGetSystemTimeLow();
40 void emu_getMainDir(char *dst, int len)
42 if (len > 0) *dst = 0;
45 static void emu_msg_cb(const char *msg)
47 void *fb = psp_video_get_active_fb();
49 memset32((int *)((char *)fb + 512*264*2), 0, 512*8*2/4);
50 emu_textOut16(4, 264, msg);
51 noticeMsgTime = sceKernelGetSystemTimeLow() - 2000000;
53 /* assumption: emu_msg_cb gets called only when something slow is about to happen */
57 void emu_stateCb(const char *str)
63 static void emu_msg_tray_open(void)
65 strcpy(noticeMsg, "CD tray opened");
66 noticeMsgTime = sceKernelGetSystemTimeLow();
72 // make dirs for saves, cfgs, etc.
79 PicoMessage = emu_msg_cb;
80 PicoMCDopenTray = emu_msg_tray_open;
81 PicoMCDcloseTray = menu_loop_tray;
87 if ((currentConfig.EmuOpt & 1) && SRam.changed) {
88 emu_SaveLoadGame(0, 1);
92 if (!(currentConfig.EmuOpt & 0x20)) {
93 FILE *f = fopen(PicoConfigFile, "r+b");
94 if (!f) emu_WriteConfig(0);
96 // if we already have config, reload it, except last ROM
97 fseek(f, sizeof(currentConfig.lastRomFile), SEEK_SET);
98 fread(¤tConfig.EmuOpt, 1, sizeof(currentConfig) - sizeof(currentConfig.lastRomFile), f);
99 fseek(f, 0, SEEK_SET);
100 fwrite(¤tConfig, 1, sizeof(currentConfig), f);
109 void emu_setDefaultConfig(void)
111 memset(¤tConfig, 0, sizeof(currentConfig));
112 currentConfig.lastRomFile[0] = 0;
113 currentConfig.EmuOpt = 0x1f | 0x680; // | confirm_save, cd_leds, 16bit rend
114 currentConfig.PicoOpt = 0x07 | 0xc00; // | cd_pcm, cd_cdda
115 currentConfig.PsndRate = 22050;
116 currentConfig.PicoRegion = 0; // auto
117 currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP
118 currentConfig.Frameskip = -1; // auto
119 currentConfig.volume = 50;
120 currentConfig.CPUclock = 222;
121 currentConfig.KeyBinds[ 4] = 1<<0; // SACB RLDU
122 currentConfig.KeyBinds[ 6] = 1<<1;
123 currentConfig.KeyBinds[ 7] = 1<<2;
124 currentConfig.KeyBinds[ 5] = 1<<3;
125 currentConfig.KeyBinds[14] = 1<<4;
126 currentConfig.KeyBinds[13] = 1<<5;
127 currentConfig.KeyBinds[15] = 1<<6;
128 currentConfig.KeyBinds[ 3] = 1<<7;
129 currentConfig.KeyBinds[23] = 1<<26; // switch rend
130 currentConfig.KeyBinds[ 8] = 1<<27; // save state
131 currentConfig.KeyBinds[ 9] = 1<<28; // load state
132 currentConfig.PicoCDBuffers = 0;
133 currentConfig.scaling = 0;
137 static unsigned short __attribute__((aligned(16))) localPal[0x100];
145 static void EmuScanPrepare(void)
147 HighCol = VRAM_STUFF;
150 sceGuSync(0,0); // sync with prev
151 sceGuStart(GU_DIRECT, guCmdList);
152 // sceGuDispBuffer(480, 272, psp_screen == VRAM_FB0 ? VRAMOFFS_FB1 : VRAMOFFS_FB0, 512);
153 sceGuDrawBuffer(GU_PSM_5650, psp_screen == VRAM_FB0 ? VRAMOFFS_FB0 : VRAMOFFS_FB1, 512); // point to back fb?
158 static int EmuScan16(unsigned int num, void *sdata)
160 // struct Vertex* vertices;
162 if (!(Pico.video.reg[1]&8)) num += 8;
163 //DrawLineDest = (unsigned short *) psp_screen + 512*(num+1);
164 HighCol = (unsigned char *)psp_screen + num*512;
167 sceGuSync(0,0); // sync with prev
168 sceGuStart(GU_DIRECT, guCmdList);
170 if (Pico.m.dirtyPal) {
171 int i, *dpal = (void *)localPal, *spal = (int *)Pico.cram;
173 for (i = 0x3f/2; i >= 0; i--)
174 dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4);
176 sceGuClutLoad((256/8), localPal); // upload 32*8 entries (256)
179 // setup CLUT texture
181 // sceGuClutMode(GU_PSM_5650,0,0xff,0);
182 // sceGuClutLoad((256/8), localPal); // upload 32*8 entries (256)
183 // sceGuTexMode(GU_PSM_T8,0,0,0); // 8-bit image
184 // sceGuTexImage(0,512,1/*512*/,512,VRAM_STUFF);
185 // sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB);
186 // sceGuTexFilter(GU_LINEAR,GU_LINEAR);
187 // sceGuTexScale(1.0f,1.0f);
188 // sceGuTexOffset(0.0f,0.0f);
189 // sceGuAmbientColor(0xffffffff);
193 // sceGuColor(0xffffffff);
194 vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex));
195 vertices[0].u = 0; vertices[0].v = 0;
196 vertices[0].x = 0; vertices[0].y = num; vertices[0].z = 0;
197 vertices[1].u = 320; vertices[1].v = 512;
198 vertices[1].x = 320; vertices[1].y = num+1; vertices[1].z = 0;
199 //sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices);
207 static void draw2_clut(void)
209 struct Vertex* vertices;
212 sceKernelDcacheWritebackAll(); // for PicoDraw2FB
214 sceGuSync(0,0); // sync with prev
215 sceGuStart(GU_DIRECT, guCmdList);
216 // sceGuDispBuffer(480, 272, psp_screen == VRAM_FB0 ? VRAMOFFS_FB1 : VRAMOFFS_FB0, 512);
217 sceGuDrawBuffer(GU_PSM_5650, psp_screen == VRAM_FB0 ? VRAMOFFS_FB0 : VRAMOFFS_FB1, 512); // point to back fb?
219 if (Pico.m.dirtyPal) {
220 int i, *dpal = (void *)localPal, *spal = (int *)Pico.cram;
222 for (i = 0x3f/2; i >= 0; i--)
223 dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4);
225 sceGuClutLoad((256/8), localPal); // upload 32*8 entries (256)
228 #define SLICE_WIDTH 32
230 for (x = 0; x < 320; x += SLICE_WIDTH)
233 vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex));
234 vertices[0].u = vertices[0].x = x;
235 vertices[0].v = vertices[0].y = 0;
237 vertices[1].u = vertices[1].x = x + SLICE_WIDTH;
238 vertices[1].v = vertices[1].y = 224;
240 sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices);
248 static int EmuScan8(unsigned int num, void *sdata)
250 // draw like the fast renderer
252 //if (!(Pico.video.reg[1]&8)) num += 8;
253 //HighCol = gfx_buffer + 328*(num+1);
258 static void osd_text(int x, const char *text)
260 int len = strlen(text) * 8 / 2;
262 for (h = 0; h < 8; h++) {
263 p = (int *) ((unsigned short *) psp_screen+x+512*(264+h));
264 p = (int *) ((int)p & ~3); // align
267 emu_textOut16(x, 264, text);
271 static void cd_leds(void)
273 static int old_reg = 0;
274 unsigned int col_g, col_r, *p;
276 if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change
277 old_reg = Pico_mcd->s68k_regs[0];
279 p = (unsigned int *)((short *)psp_screen + 512*2+4+2);
280 col_g = (old_reg & 2) ? 0x06000600 : 0;
281 col_r = (old_reg & 1) ? 0xc000c000 : 0;
282 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 512/2 - 12/2;
283 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 512/2 - 12/2;
284 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r;
288 static void blit(const char *fps, const char *notice)
290 int emu_opt = currentConfig.EmuOpt;
297 extern void amips_clut(unsigned short *dst, unsigned char *src, unsigned short *pal, int count);
298 int i; // , lines_flags = 224;
299 unsigned short *pd = psp_screen;
300 unsigned char *ps = PicoDraw2FB+328*8+8;
301 // 8bit fast renderer
302 if (Pico.m.dirtyPal) {
303 int *dpal = (void *)localPal;
304 int *spal = (int *)Pico.cram;
306 for (i = 0x3f/2; i >= 0; i--)
307 dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4);
309 // if (!(Pico.video.reg[12]&1)) lines_flags|=0x10000;
310 // if (currentConfig.EmuOpt&0x4000)
311 // lines_flags|=0x40000; // (Pico.m.frame_count&1)?0x20000:0x40000;
312 //vidCpy8to16((unsigned short *)giz_screen+321*8, PicoDraw2FB+328*8, localPal, lines_flags);
313 for (i = 224; i > 0; i--, pd+=512, ps+=328)
314 amips_clut(pd, ps, localPal, 320);
318 else if (!(emu_opt&0x80))
321 // 8bit accurate renderer
322 if (Pico.m.dirtyPal) {
324 vidConvCpyRGB565(localPal, Pico.cram, 0x40);
325 if (Pico.video.reg[0xC]&8) { // shadow/hilight mode
326 //vidConvCpyRGB32sh(localPal+0x40, Pico.cram, 0x40);
327 //vidConvCpyRGB32hi(localPal+0x80, Pico.cram, 0x40); // TODO?
328 blockcpy(localPal+0xc0, localPal+0x40, 0x40*2);
329 localPal[0xc0] = 0x0600;
330 localPal[0xd0] = 0xc000;
331 localPal[0xe0] = 0x0000; // reserved pixels for OSD
332 localPal[0xf0] = 0xffff;
335 else if (rendstatus & 0x20) { // mid-frame palette changes
336 vidConvCpyRGB565(localPal+0x40, HighPal, 0x40);
337 vidConvCpyRGB565(localPal+0x80, HighPal+0x40, 0x40);
340 lines_flags = (Pico.video.reg[1]&8) ? 240 : 224;
341 if (!(Pico.video.reg[12]&1)) lines_flags|=0x10000;
342 if (currentConfig.EmuOpt&0x4000)
343 lines_flags|=0x40000; // (Pico.m.frame_count&1)?0x20000:0x40000;
344 vidCpy8to16((unsigned short *)giz_screen+321*8, PicoDraw2FB+328*8, localPal, lines_flags);
348 if (notice || (emu_opt & 2)) {
349 if (notice) osd_text(4, notice);
350 if (emu_opt & 2) osd_text(OSD_FPS_X, fps);
353 if ((emu_opt & 0x400) && (PicoMCD & 1))
360 // clears whole screen or just the notice area (in all buffers)
361 static void clearArea(int full)
364 memset32(psp_screen, 0, 512*272*2/4);
366 memset32(psp_screen, 0, 512*272*2/4);
368 void *fb = psp_video_get_active_fb();
369 memset32((int *)((char *)psp_screen + 512*264*2), 0, 512*8*2/4);
370 memset32((int *)((char *)fb + 512*264*2), 0, 512*8*2/4);
374 static void vidResetMode(void)
377 sceGuSync(0,0); // sync with prev
378 sceGuStart(GU_DIRECT, guCmdList);
380 sceGuClutMode(GU_PSM_5650,0,0xff,0);
381 //sceGuClutLoad((256/8), localPal); // upload 32*8 entries (256)
382 sceGuTexMode(GU_PSM_T8,0,0,0); // 8-bit image
383 sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB);
384 sceGuTexFilter(GU_LINEAR,GU_LINEAR);
385 sceGuTexScale(1.0f,1.0f);
386 sceGuTexOffset(0.0f,0.0f);
387 sceGuAmbientColor(0xffffffff);
388 sceGuColor(0xffffffff);
392 sceGuTexImage(0,512,512,512,(char *)VRAM_STUFF + 8*512+16);
394 } else if (currentConfig.EmuOpt&0x80) {
395 PicoDrawSetColorFormat(/*1*/-1);
396 PicoScan = EmuScan16;
398 sceGuTexImage(0,512,1/*512*/,512,VRAM_STUFF);
401 PicoDrawSetColorFormat(-1);
404 if ((PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80)) {
405 // setup pal for 8-bit modes
406 localPal[0xc0] = 0x0600;
407 localPal[0xd0] = 0xc000;
408 localPal[0xe0] = 0x0000; // reserved pixels for OSD
409 localPal[0xf0] = 0xffff;
419 static void updateSound(int len)
421 if (PicoOpt&8) len<<=1;
427 static void SkipFrame(void)
434 void emu_forcedFrame(void)
436 int po_old = PicoOpt;
437 int eo_old = currentConfig.EmuOpt;
440 PicoOpt |= 0x4080; // soft_scale | acc_sprites
441 currentConfig.EmuOpt |= 0x80;
443 PicoDrawSetColorFormat(1);
444 PicoScan = EmuScan16;
450 currentConfig.EmuOpt = eo_old;
454 static void RunEvents(unsigned int which)
456 if (which & 0x1800) // save or load (but not both)
460 if ( emu_checkSaveFile(state_slot) &&
461 (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) || // load
462 (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) // save
465 blit("", (which & 0x1000) ? "LOAD STATE? (X=yes, O=no)" : "OVERWRITE SAVE? (X=yes, O=no)");
466 while( !((keys = psp_pad_read(1)) & (BTN_X|BTN_CIRCLE)) )
468 if (keys & BTN_CIRCLE) do_it = 0;
469 while( ((keys = psp_pad_read(1)) & (BTN_X|BTN_CIRCLE)) ) // wait for release
476 osd_text(4, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME");
477 PicoStateProgressCB = emu_stateCb;
478 emu_SaveLoadGame((which & 0x1000) >> 12, 0);
479 PicoStateProgressCB = NULL;
485 if (which & 0x0400) // switch renderer
487 if (PicoOpt&0x10) { PicoOpt&=~0x10; currentConfig.EmuOpt |= 0x80; }
488 else { PicoOpt|= 0x10; currentConfig.EmuOpt &= ~0x80; }
493 strcpy(noticeMsg, " 8bit fast renderer");
494 } else if (currentConfig.EmuOpt&0x80) {
495 strcpy(noticeMsg, "16bit accurate renderer");
497 strcpy(noticeMsg, " 8bit accurate renderer");
500 noticeMsgTime = sceKernelGetSystemTimeLow();
506 if(state_slot < 0) state_slot = 9;
509 if(state_slot > 9) state_slot = 0;
511 sprintf(noticeMsg, "SAVE SLOT %i [%s]", state_slot, emu_checkSaveFile(state_slot) ? "USED" : "FREE");
512 noticeMsgTime = sceKernelGetSystemTimeLow();
516 static void updateKeys(void)
518 unsigned int keys, allActions[2] = { 0, 0 }, events;
519 static unsigned int prevEvents = 0;
522 keys = psp_pad_read(0);
523 if (keys & PSP_CTRL_HOME)
524 sceDisplayWaitVblankStart();
526 if (keys & BTN_SELECT)
527 engineState = PGS_Menu;
529 keys &= CONFIGURABLE_KEYS;
531 for (i = 0; i < 32; i++)
535 int pl, acts = currentConfig.KeyBinds[i];
537 pl = (acts >> 16) & 1;
538 if (combo_keys & (1 << i))
540 int u = i+1, acts_c = acts & combo_acts;
541 // let's try to find the other one
544 if ( (currentConfig.KeyBinds[u] & acts_c) && (keys & (1 << u)) ) {
545 allActions[pl] |= acts_c;
546 keys &= ~((1 << i) | (1 << u));
549 // add non-combo actions if combo ones were not found
550 if (!acts_c || u == 32)
551 allActions[pl] |= acts & ~combo_acts;
553 allActions[pl] |= acts;
558 PicoPad[0] = (unsigned short) allActions[0];
559 PicoPad[1] = (unsigned short) allActions[1];
561 events = (allActions[0] | allActions[1]) >> 16;
563 // volume is treated in special way and triggered every frame
564 if ((events & 0x6000) && PsndOut != NULL)
566 int vol = currentConfig.volume;
567 if (events & 0x2000) {
568 if (vol < 100) vol++;
572 // FrameworkAudio_SetVolume(vol, vol); // TODO
573 sprintf(noticeMsg, "VOL: %02i ", vol);
574 noticeMsgTime = sceKernelGetSystemTimeLow();
575 currentConfig.volume = vol;
578 events &= ~prevEvents;
579 if (events) RunEvents(events);
580 if (movie_data) emu_updateMovie();
582 prevEvents = (allActions[0] | allActions[1]) >> 16;
585 static void find_combos(void)
589 // find out which keys and actions are combos
590 combo_keys = combo_acts = 0;
591 for (act = 0; act < 32; act++)
594 if (act == 16 || act == 17) continue; // player2 flag
595 for (u = 0; u < 32; u++)
597 if (currentConfig.KeyBinds[u] & (1 << act)) keyc++;
601 // loop again and mark those keys and actions as combo
602 for (u = 0; u < 32; u++)
604 if (currentConfig.KeyBinds[u] & (1 << act)) {
605 combo_keys |= 1 << u;
606 combo_acts |= 1 << act;
614 static void simpleWait(unsigned int until)
619 tval = sceKernelGetSystemTimeLow();
620 diff = (int)until - (int)tval;
621 if (diff >= 512 && diff < 100*1024)
622 sceKernelDelayThread(diff);
627 //static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;
628 char fpsbuff[24]; // fps count c string
629 unsigned int tval, tval_prev = 0, tval_thissec = 0; // timing
630 int frames_done = 0, frames_shown = 0, oldmodes = 0;
631 int target_fps, target_frametime, lim_time, tval_diff, i;
634 lprintf("entered emu_Loop()\n");
638 if (currentConfig.CPUclock != psp_get_cpu_clock()) {
639 lprintf("setting cpu clock to %iMHz... ", currentConfig.CPUclock);
640 i = psp_set_cpu_clock(currentConfig.CPUclock);
641 lprintf(i ? "failed\n" : "done\n");
642 currentConfig.CPUclock = psp_get_cpu_clock();
645 // make sure we are in correct mode
648 oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc;
651 // pal/ntsc might have changed, reset related stuff
652 target_fps = Pico.m.pal ? 50 : 60;
653 target_frametime = Pico.m.pal ? (1000000<<8)/50 : (1000000<<8)/60+1;
657 if (PicoMCD & 1) PicoCDBufferInit();
659 // prepare sound stuff
662 if (currentConfig.EmuOpt & 4)
664 int ret, snd_excess_add, stereo;
665 if (PsndRate != PsndRate_old || (PicoOpt&0x0b) != (PicoOpt_old&0x0b) || Pico.m.pal != pal_old) {
666 sound_rerate(Pico.m.frame_count ? 1 : 0);
668 stereo=(PicoOpt&8)>>3;
669 snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;
670 snd_cbuf_samples = (PsndRate<<stereo) * 16 / target_fps;
671 lprintf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",
672 PsndRate, PsndLen, snd_excess_add, stereo, Pico.m.pal);
673 ret = FrameworkAudio_Init(PsndRate, snd_cbuf_samples, stereo);
675 lprintf("FrameworkAudio_Init() failed: %i\n", ret);
676 sprintf(noticeMsg, "sound init failed (%i), snd disabled", ret);
677 noticeMsgTime = sceKernelGetSystemTimeLow();
678 currentConfig.EmuOpt &= ~4;
680 FrameworkAudio_SetVolume(currentConfig.volume, currentConfig.volume);
681 PicoWriteSound = updateSound;
682 snd_cbuff = FrameworkAudio_56448Buffer();
683 PsndOut = snd_cbuff + snd_cbuf_samples / 2; // start writing at the middle
685 PsndRate_old = PsndRate;
686 PicoOpt_old = PicoOpt;
687 pal_old = Pico.m.pal;
693 while (engineState == PGS_Running)
697 tval = sceKernelGetSystemTimeLow();
698 if (reset_timing || tval < tval_prev) {
699 //stdbg("timing reset");
702 frames_shown = frames_done = 0;
705 // show notice message?
707 static int noticeMsgSum;
708 if (tval - noticeMsgTime > 2000000) { // > 2.0 sec
713 int sum = noticeMsg[0]+noticeMsg[1]+noticeMsg[2];
714 if (sum != noticeMsgSum) { clearArea(0); noticeMsgSum = sum; }
719 // check for mode changes
720 modes = ((Pico.video.reg[12]&1)<<2)|(Pico.video.reg[1]&8);
721 if (modes != oldmodes) {
727 if (tval - tval_thissec >= 1000000)
730 static int bench = 0, bench_fps = 0, bench_fps_s = 0, bfp = 0, bf[4];
733 bench_fps_s = bench_fps;
734 bf[bfp++ & 3] = bench_fps;
737 bench_fps += frames_shown;
738 sprintf(fpsbuff, "%02i/%02i/%02i", frames_shown, bench_fps_s, (bf[0]+bf[1]+bf[2]+bf[3])>>2);
740 if(currentConfig.EmuOpt & 2)
741 sprintf(fpsbuff, "%02i/%02i", frames_shown, frames_done);
743 tval_thissec += 1000000;
745 if (currentConfig.Frameskip < 0) {
746 frames_done -= target_fps; if (frames_done < 0) frames_done = 0;
747 frames_shown -= target_fps; if (frames_shown < 0) frames_shown = 0;
748 if (frames_shown > frames_done) frames_shown = frames_done;
750 frames_done = frames_shown = 0;
754 sprintf(fpsbuff, "%i", Pico.m.frame_count);
758 lim_time = (frames_done+1) * target_frametime;
759 if (currentConfig.Frameskip >= 0) // frameskip enabled
761 for (i = 0; i < currentConfig.Frameskip; i++) {
763 SkipFrame(); frames_done++;
764 if (PsndOut) { // do framelimitting if sound is enabled
766 tval = sceKernelGetSystemTimeLow();
767 tval_diff = (int)(tval - tval_thissec) << 8;
768 if (tval_diff < lim_time) // we are too fast
769 simpleWait(tval + ((lim_time - tval_diff)>>8));
771 lim_time += target_frametime;
774 else // auto frameskip
777 tval = sceKernelGetSystemTimeLow();
778 tval_diff = (int)(tval - tval_thissec) << 8;
779 if (tval_diff > lim_time)
781 // no time left for this frame - skip
782 if (tval_diff - lim_time >= (300000<<8)) {
783 /* something caused a slowdown for us (disk access? cache flush?)
784 * try to recover by resetting timing... */
789 SkipFrame(); frames_done++;
801 blit(fpsbuff, notice);
804 tval = sceKernelGetSystemTimeLow();
805 tval_diff = (int)(tval - tval_thissec) << 8;
807 if (currentConfig.Frameskip < 0 && tval_diff - lim_time >= (300000<<8)) // slowdown detection
809 else if (PsndOut != NULL || currentConfig.Frameskip < 0)
811 // sleep if we are still too fast
812 if (tval_diff < lim_time)
815 simpleWait(tval + ((lim_time - tval_diff) >> 8));
819 frames_done++; frames_shown++;
823 if (PicoMCD & 1) PicoCDBufferFree();
825 if (PsndOut != NULL) {
826 PsndOut = snd_cbuff = NULL;
827 FrameworkAudio_Close();
831 if ((currentConfig.EmuOpt & 1) && SRam.changed) {
832 emu_stateCb("Writing SRAM/BRAM..");
833 emu_SaveLoadGame(0, 1);
839 void emu_ResetGame(void)