1 // (c) Copyright 2006-2009 notaz, All rights reserved.
\r
2 // Free for non-commercial use.
\r
4 // For commercial use, separate licencing terms must be obtained.
\r
8 #include <sys/time.h>
\r
11 #include "../common/arm_utils.h"
\r
12 #include "../common/fonts.h"
\r
13 #include "../common/emu.h"
\r
14 #include "../common/menu.h"
\r
15 #include "../common/config.h"
\r
16 #include "../common/input.h"
\r
17 #include "../linux/sndout_oss.h"
\r
18 #include "asm_utils.h"
\r
20 #include <pico/pico_int.h>
\r
21 #include <pico/patch.h>
\r
22 #include <pico/sound/mix.h>
\r
23 #include <zlib/zlib.h>
\r
27 //#define USE_320_SCREEN 1
\r
30 #define OSD_FPS_X (800-200)
\r
32 #define OSD_FPS_X (800-120)
\r
36 static short __attribute__((aligned(4))) sndBuffer[2*44100/50];
\r
37 static int osd_fps_x;
\r
38 unsigned char *PicoDraw2FB = NULL; // temporary buffer for alt renderer
\r
40 #define PICO_PEN_ADJUST_X 4
\r
41 #define PICO_PEN_ADJUST_Y 2
\r
42 static int pico_pen_x = 0, pico_pen_y = 240/2;
\r
45 int plat_get_root_dir(char *dst, int len)
\r
47 extern char **g_argv;
\r
50 strncpy(dst, g_argv[0], len);
\r
51 len -= 32; // reserve
\r
52 if (len < 0) len = 0;
\r
54 for (j = strlen(dst); j > 0; j--)
\r
55 if (dst[j] == '/') { dst[j+1] = 0; break; }
\r
60 void pemu_prep_defconfig(void)
\r
62 memset(&defaultConfig, 0, sizeof(defaultConfig));
\r
63 defaultConfig.EmuOpt = 0x8f | 0x00600; // | <- confirm_save, cd_leds
\r
64 defaultConfig.s_PicoOpt = 0x0f | POPT_EXT_FM|POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_SVP_DRC;
\r
65 defaultConfig.s_PicoOpt |= POPT_ACC_SPRITES|POPT_EN_MCD_GFX;
\r
66 defaultConfig.EmuOpt &= ~8; // no save gzip
\r
67 defaultConfig.s_PsndRate = 44100;
\r
68 defaultConfig.s_PicoRegion = 0;
\r
69 defaultConfig.s_PicoAutoRgnOrder = 0x184; // US, EU, JP
\r
70 defaultConfig.s_PicoCDBuffers = 0;
\r
71 defaultConfig.Frameskip = 0;
\r
72 defaultConfig.CPUclock = 200;
\r
73 defaultConfig.volume = 50;
\r
74 defaultConfig.scaling = 0;
\r
75 defaultConfig.turbo_rate = 15;
\r
78 static void textOut16(int x, int y, const char *text)
\r
80 int i,l,len=strlen(text);
\r
81 unsigned int *screen = (unsigned int *)((unsigned short *)g_screen_ptr + (x&~1) + y*g_screen_width);
\r
83 for (i = 0; i < len; i++)
\r
87 unsigned char fd = fontdata8x8[((text[i])*8)+l/2];
\r
88 unsigned int *d = &screen[l*g_screen_width/2];
\r
89 if (fd&0x80) d[0]=0xffffffff;
\r
90 if (fd&0x40) d[1]=0xffffffff;
\r
91 if (fd&0x20) d[2]=0xffffffff;
\r
92 if (fd&0x10) d[3]=0xffffffff;
\r
93 if (fd&0x08) d[4]=0xffffffff;
\r
94 if (fd&0x04) d[5]=0xffffffff;
\r
95 if (fd&0x02) d[6]=0xffffffff;
\r
96 if (fd&0x01) d[7]=0xffffffff;
\r
97 l++; d = &screen[l*g_screen_width/2];
\r
98 if (fd&0x80) d[0]=0xffffffff;
\r
99 if (fd&0x40) d[1]=0xffffffff;
\r
100 if (fd&0x20) d[2]=0xffffffff;
\r
101 if (fd&0x10) d[3]=0xffffffff;
\r
102 if (fd&0x08) d[4]=0xffffffff;
\r
103 if (fd&0x04) d[5]=0xffffffff;
\r
104 if (fd&0x02) d[6]=0xffffffff;
\r
105 if (fd&0x01) d[7]=0xffffffff;
\r
113 static void osd_text(int x, int y, const char *text)
\r
115 int len = strlen(text)*8;
\r
117 if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {
\r
119 x &= ~3; // align x
\r
120 len = (len+3) >> 2;
\r
121 for (h = 0; h < 8; h++) {
\r
122 p = (int *) ((unsigned char *) g_screen_ptr+x+g_screen_width*(y+h));
\r
123 for (i = len; i; i--, p++) *p = 0xe0e0e0e0;
\r
125 emu_text_out8(x, y, text);
\r
128 x &= ~1; // align x
\r
130 for (h = 0; h < 16; h++) {
\r
131 p = (int *) ((unsigned short *) g_screen_ptr+x+g_screen_width*(y+h));
\r
132 for (i = len; i; i--, p++) *p = 0;//(*p>>2)&0x39e7;
\r
134 text_out16(x, y, text);
\r
138 static void draw_cd_leds(void)
\r
142 // if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change // mmu hack problems?
\r
143 old_reg = Pico_mcd->s68k_regs[0];
\r
145 if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {
\r
147 unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;
\r
148 unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;
\r
149 *(unsigned int *)((char *)g_screen_ptr + g_screen_width*2+ 4) =
\r
150 *(unsigned int *)((char *)g_screen_ptr + g_screen_width*3+ 4) =
\r
151 *(unsigned int *)((char *)g_screen_ptr + g_screen_width*4+ 4) = col_g;
\r
152 *(unsigned int *)((char *)g_screen_ptr + g_screen_width*2+12) =
\r
153 *(unsigned int *)((char *)g_screen_ptr + g_screen_width*3+12) =
\r
154 *(unsigned int *)((char *)g_screen_ptr + g_screen_width*4+12) = col_r;
\r
157 unsigned int *p = (unsigned int *)((short *)g_screen_ptr + g_screen_width*2+4);
\r
158 unsigned int col_g = (old_reg & 2) ? 0x06000600 : 0;
\r
159 unsigned int col_r = (old_reg & 1) ? 0xc000c000 : 0;
\r
160 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2;
\r
161 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2;
\r
162 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r;
\r
166 static void draw_pico_ptr(void)
\r
168 unsigned short *p = (unsigned short *)g_screen_ptr;
\r
170 // only if pen enabled and for 16bit modes
\r
171 if (pico_inp_mode == 0 || (PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80)) return;
\r
173 if (!(Pico.video.reg[12]&1) && !(PicoOpt&POPT_DIS_32C_BORDER))
\r
176 p += g_screen_width * (pico_pen_y + PICO_PEN_ADJUST_Y);
\r
177 p += pico_pen_x + PICO_PEN_ADJUST_X;
\r
185 #ifdef USE_320_SCREEN
\r
187 static int EmuScanBegin16(unsigned int num)
\r
189 DrawLineDest = (unsigned short *)g_screen_ptr + num*800 + 800/2 - 320/2;
\r
190 //int w = (Pico.video.reg[12]&1) ? 320 : 256;
\r
191 //DrawLineDest = (unsigned short *)g_screen_ptr + num*w;
\r
196 #else // USE_320_SCREEN
\r
198 static int EmuScanEnd16(unsigned int num)
\r
200 unsigned char *ps=HighCol+8;
\r
201 unsigned short *pd;
\r
202 unsigned short *pal=HighPal;
\r
203 int sh = Pico.video.reg[0xC]&8;
\r
204 int len, mask = 0xff;
\r
206 pd=(unsigned short *)g_screen_ptr + num*800*2 + 800/2 - 320*2/2;
\r
208 if (Pico.m.dirtyPal)
\r
209 PicoDoHighPal555(sh);
\r
211 if (Pico.video.reg[12]&1) {
\r
218 if (!sh && (rendstatus & PDRAW_SPR_LO_ON_HI))
\r
219 mask=0x3f; // messed sprites, upper bits are priority stuff
\r
222 clut_line(pd, ps, pal, (mask<<16) | len);
\r
224 for (; len > 0; len--)
\r
226 unsigned int p = pal[*ps++ & mask];
\r
228 *(unsigned int *)pd = p;
\r
229 *(unsigned int *)(&pd[800]) = p;
\r
237 #endif // USE_320_SCREEN
\r
239 int localPal[0x100];
\r
240 static void (*vidCpyM2)(void *dest, void *src) = NULL;
\r
242 static void blit(const char *fps, const char *notice)
\r
244 int emu_opt = currentConfig.EmuOpt;
\r
248 // 8bit fast renderer
\r
249 if (Pico.m.dirtyPal) {
\r
250 Pico.m.dirtyPal = 0;
\r
251 vidConvCpyRGB32(localPal, Pico.cram, 0x40);
\r
252 // feed new palette to our device
\r
253 // gp2x_video_setpalette(localPal, 0x40);
\r
256 if (PicoAHW & PAHW_SVP)
\r
257 memset32((int *)(PicoDraw2FB+328*8+328*223), 0xe0e0e0e0, 328);
\r
259 vidCpyM2((unsigned char *)g_screen_ptr+g_screen_width*8, PicoDraw2FB+328*8);
\r
261 else if (!(emu_opt&0x80))
\r
263 // 8bit accurate renderer
\r
264 if (Pico.m.dirtyPal)
\r
267 Pico.m.dirtyPal = 0;
\r
268 if (Pico.video.reg[0xC]&8) // shadow/hilight mode
\r
270 vidConvCpyRGB32(localPal, Pico.cram, 0x40);
\r
271 vidConvCpyRGB32sh(localPal+0x40, Pico.cram, 0x40);
\r
272 vidConvCpyRGB32hi(localPal+0x80, Pico.cram, 0x40);
\r
273 memcpy32(localPal+0xc0, localPal+0x40, 0x40);
\r
276 else if (rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes
\r
277 vidConvCpyRGB32(localPal, Pico.cram, 0x40);
\r
278 vidConvCpyRGB32(localPal+0x40, HighPal, 0x40);
\r
279 vidConvCpyRGB32(localPal+0x80, HighPal+0x40, 0x40);
\r
283 vidConvCpyRGB32(localPal, Pico.cram, 0x40);
\r
284 memcpy32(localPal+0x80, localPal, 0x40);
\r
286 if (pallen > 0xc0) {
\r
287 localPal[0xc0] = 0x0000c000;
\r
288 localPal[0xd0] = 0x00c00000;
\r
289 localPal[0xe0] = 0x00000000; // reserved pixels for OSD
\r
290 localPal[0xf0] = 0x00ffffff;
\r
292 // gp2x_video_setpalette(localPal, pallen);
\r
296 if (notice || (emu_opt & 2)) {
\r
297 int h = g_screen_height-16;
\r
298 if (currentConfig.scaling == 2 && !(Pico.video.reg[1]&8)) h -= 16;
\r
299 if (notice) osd_text(4, h, notice);
\r
301 osd_text(osd_fps_x, h, fps);
\r
303 if ((emu_opt & 0x400) && (PicoAHW & PAHW_MCD))
\r
305 if (PicoAHW & PAHW_PICO)
\r
308 //gp2x_video_wait_vsync();
\r
309 // gp2x_video_flip();
\r
313 // clears whole screen or just the notice area (in all buffers)
\r
314 static void clearArea(int full)
\r
316 if (full) memset(g_screen_ptr, 0, g_screen_width*g_screen_height*2);
\r
317 else memset((short *)g_screen_ptr + g_screen_width * (g_screen_height - 16), 0,
\r
318 g_screen_width * 16 * 2);
\r
322 static void vidResetMode(void)
\r
325 if (PicoOpt&0x10) {
\r
326 gp2x_video_changemode(8);
\r
327 } else if (currentConfig.EmuOpt&0x80) {
\r
328 gp2x_video_changemode(16);
\r
329 #ifdef USE_320_SCREEN
\r
330 PicoDrawSetColorFormat(1);
\r
331 PicoScanBegin = EmuScanBegin16;
\r
333 PicoDrawSetColorFormat(-1);
\r
334 PicoScanEnd = EmuScanEnd16;
\r
337 gp2x_video_changemode(8);
\r
338 PicoDrawSetColorFormat(2);
\r
339 PicoScanBegin = EmuScanBegin8;
\r
341 if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {
\r
342 // setup pal for 8-bit modes
\r
343 localPal[0xc0] = 0x0000c000; // MCD LEDs
\r
344 localPal[0xd0] = 0x00c00000;
\r
345 localPal[0xe0] = 0x00000000; // reserved pixels for OSD
\r
346 localPal[0xf0] = 0x00ffffff;
\r
347 gp2x_video_setpalette(localPal, 0x100);
\r
348 gp2x_memset_all_buffers(0, 0xe0, 320*240);
\r
351 Pico.m.dirtyPal = 1;
\r
353 if (currentConfig.scaling == 2 && !(Pico.video.reg[1]&8))
\r
354 gp2x_video_RGB_setscaling(8, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 224);
\r
355 else gp2x_video_RGB_setscaling(0, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 240);
\r
357 #ifdef USE_320_SCREEN
\r
358 PicoDrawSetColorFormat(1);
\r
359 PicoScanBegin = EmuScanBegin16;
\r
361 PicoDrawSetColorFormat(-1);
\r
362 PicoScanEnd = EmuScanEnd16;
\r
368 static void update_volume(int has_changed, int is_up)
\r
370 static int prev_frame = 0, wait_frames = 0;
\r
371 int vol = currentConfig.volume;
\r
375 if (vol < 5 && (PicoOpt&8) && prev_frame == Pico.m.frame_count - 1 && wait_frames < 12)
\r
379 if (vol < 99) vol++;
\r
381 if (vol > 0) vol--;
\r
384 sndout_oss_setvol(vol, vol);
\r
385 currentConfig.volume = vol;
\r
387 sprintf(noticeMsg, "VOL: %02i", vol);
\r
388 gettimeofday(¬iceMsgTime, 0);
\r
389 prev_frame = Pico.m.frame_count;
\r
392 // set the right mixer func
\r
393 if (!(PicoOpt&8)) return; // just use defaults for mono
\r
395 PsndMix_32_to_16l = mix_32_to_16l_stereo;
\r
397 mix_32_to_16l_level = 5 - vol;
\r
398 PsndMix_32_to_16l = mix_32_to_16l_stereo_lvl;
\r
403 static void updateSound(int len)
\r
405 if (PicoOpt&8) len<<=1;
\r
407 /* avoid writing audio when lagging behind to prevent audio lag */
\r
408 if (PicoSkipFrame != 2)
\r
409 sndout_oss_write(PsndOut, len<<1);
\r
413 static void SkipFrame(int do_audio)
\r
415 PicoSkipFrame=do_audio ? 1 : 2;
\r
421 void pemu_forced_frame(int opts)
\r
423 int po_old = PicoOpt;
\r
424 int eo_old = currentConfig.EmuOpt;
\r
427 PicoOpt |= opts|POPT_ACC_SPRITES; // acc_sprites
\r
428 currentConfig.EmuOpt |= 0x80;
\r
431 #ifdef USE_320_SCREEN
\r
432 PicoDrawSetColorFormat(1);
\r
433 PicoScanBegin = EmuScanBegin16;
\r
435 PicoDrawSetColorFormat(-1);
\r
436 PicoScanEnd = EmuScanEnd16;
\r
438 Pico.m.dirtyPal = 1;
\r
439 PicoFrameDrawOnly();
\r
442 if (!(Pico.video.reg[12]&1)) {
\r
443 vidCpyM2 = vidCpyM2_32col;
\r
445 } else vidCpyM2 = vidCpyM2_40col;
\r
447 vidCpyM2((unsigned char *)g_screen_ptr+g_screen_width*8, PicoDraw2FB+328*8);
\r
448 vidConvCpyRGB32(localPal, Pico.cram, 0x40);
\r
449 gp2x_video_setpalette(localPal, 0x40);
\r
452 currentConfig.EmuOpt = eo_old;
\r
455 void plat_debug_cat(char *str)
\r
459 static void simpleWait(int thissec, int lim_time)
\r
461 struct timeval tval;
\r
463 spend_cycles(1024);
\r
464 gettimeofday(&tval, 0);
\r
465 if (thissec != tval.tv_sec) tval.tv_usec+=1000000;
\r
467 while (tval.tv_usec < lim_time)
\r
469 spend_cycles(1024);
\r
470 gettimeofday(&tval, 0);
\r
471 if (thissec != tval.tv_sec) tval.tv_usec+=1000000;
\r
475 void pemu_sound_start(void)
\r
477 static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;
\r
478 int target_fps = Pico.m.pal ? 50 : 60;
\r
482 if (currentConfig.EmuOpt & 4)
\r
484 int snd_excess_add;
\r
485 if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old)
\r
486 PsndRerate(Pico.m.frame_count ? 1 : 0);
\r
488 snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;
\r
489 printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",
\r
490 PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal);
\r
491 sndout_oss_start(PsndRate, 16, (PicoOpt&8)>>3);
\r
492 sndout_oss_setvol(currentConfig.volume, currentConfig.volume);
\r
493 PicoWriteSound = updateSound;
\r
494 update_volume(0, 0);
\r
495 memset(sndBuffer, 0, sizeof(sndBuffer));
\r
496 PsndOut = sndBuffer;
\r
497 PsndRate_old = PsndRate;
\r
498 PicoOpt_old = PicoOpt;
\r
499 pal_old = Pico.m.pal;
\r
503 void pemu_sound_stop(void)
\r
507 void pemu_sound_wait(void)
\r
509 // don't need to do anything, writes will block by themselves
\r
512 void pemu_loop(void)
\r
514 char fpsbuff[24]; // fps count c string
\r
515 struct timeval tval; // timing
\r
516 int pframes_done, pframes_shown, pthissec; // "period" frames, used for sync
\r
517 int frames_done, frames_shown, thissec; // actual frames
\r
518 int oldmodes = 0, target_fps, target_frametime, lim_time, vsync_offset, i;
\r
521 printf("entered emu_Loop()\n");
\r
525 // make sure we are in correct mode
\r
527 Pico.m.dirtyPal = 1;
\r
528 oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc;
\r
530 // pal/ntsc might have changed, reset related stuff
\r
531 target_fps = Pico.m.pal ? 50 : 60;
\r
532 target_frametime = 1000000/target_fps;
\r
535 pemu_sound_start();
\r
537 // prepare CD buffer
\r
538 if (PicoAHW & PAHW_MCD) PicoCDBufferInit();
\r
540 // calc vsync offset to sync timing code with vsync
\r
541 if (currentConfig.EmuOpt&0x2000) {
\r
542 gettimeofday(&tval, 0);
\r
543 //gp2x_video_wait_vsync();
\r
544 gettimeofday(&tval, 0);
\r
545 vsync_offset = tval.tv_usec;
\r
546 while (vsync_offset >= target_frametime)
\r
547 vsync_offset -= target_frametime;
\r
548 if (!vsync_offset) vsync_offset++;
\r
549 printf("vsync_offset: %i\n", vsync_offset);
\r
553 frames_done = frames_shown = thissec =
\r
554 pframes_done = pframes_shown = pthissec = 0;
\r
557 while (engineState == PGS_Running)
\r
561 gettimeofday(&tval, 0);
\r
562 if (reset_timing) {
\r
564 pthissec = tval.tv_sec;
\r
565 pframes_shown = pframes_done = tval.tv_usec/target_frametime;
\r
568 // show notice message?
\r
569 if (noticeMsgTime.tv_sec)
\r
571 static int noticeMsgSum;
\r
572 if((tval.tv_sec*1000000+tval.tv_usec) - (noticeMsgTime.tv_sec*1000000+noticeMsgTime.tv_usec) > 2000000) { // > 2.0 sec
\r
573 noticeMsgTime.tv_sec = noticeMsgTime.tv_usec = 0;
\r
577 int sum = noticeMsg[0]+noticeMsg[1]+noticeMsg[2];
\r
578 if (sum != noticeMsgSum) { clearArea(0); noticeMsgSum = sum; }
\r
579 notice = noticeMsg;
\r
583 // check for mode changes
\r
584 modes = ((Pico.video.reg[12]&1)<<2)|(Pico.video.reg[1]&8);
\r
585 if (modes != oldmodes)
\r
587 int scalex = g_screen_width;
\r
588 osd_fps_x = OSD_FPS_X;
\r
590 vidCpyM2 = vidCpyM2_40col;
\r
592 if (PicoOpt & 0x100) {
\r
593 vidCpyM2 = vidCpyM2_32col_nobord;
\r
595 osd_fps_x = OSD_FPS_X - 64;
\r
597 vidCpyM2 = vidCpyM2_32col;
\r
600 //if (currentConfig.scaling == 2 && !(modes&8)) // want vertical scaling and game is not in 240 line mode
\r
601 // gp2x_video_RGB_setscaling(8, scalex, 224);
\r
602 // else gp2x_video_RGB_setscaling(0, scalex, 240);
\r
608 if (thissec != tval.tv_sec)
\r
611 static int bench = 0, bench_fps = 0, bench_fps_s = 0, bfp = 0, bf[4];
\r
612 if (++bench == 4) {
\r
614 bench_fps_s = bench_fps / 4;
\r
615 bf[bfp++ & 3] = bench_fps / 4;
\r
618 bench_fps += frames_shown;
\r
619 sprintf(fpsbuff, "%3i/%3i/%3i", frames_shown, bench_fps_s, (bf[0]+bf[1]+bf[2]+bf[3])>>2);
\r
620 printf("%s\n", fpsbuff);
\r
622 if (currentConfig.EmuOpt & 2) {
\r
623 sprintf(fpsbuff, "%3i/%3i", frames_shown, frames_done);
\r
624 if (fpsbuff[5] == 0) { fpsbuff[5] = fpsbuff[6] = ' '; fpsbuff[7] = 0; }
\r
627 frames_shown = frames_done = 0;
\r
628 thissec = tval.tv_sec;
\r
631 sprintf(fpsbuff, "%i", Pico.m.frame_count);
\r
634 if (pthissec != tval.tv_sec)
\r
636 if (PsndOut == 0 && currentConfig.Frameskip >= 0) {
\r
637 pframes_done = pframes_shown = 0;
\r
639 // it is quite common for this implementation to leave 1 fame unfinished
\r
640 // when second changes, but we don't want buffer to starve.
\r
641 if(PsndOut && pframes_done < target_fps && pframes_done > target_fps-5) {
\r
642 emu_update_input();
\r
643 SkipFrame(1); pframes_done++;
\r
646 pframes_done -= target_fps; if (pframes_done < 0) pframes_done = 0;
\r
647 pframes_shown -= target_fps; if (pframes_shown < 0) pframes_shown = 0;
\r
648 if (pframes_shown > pframes_done) pframes_shown = pframes_done;
\r
650 pthissec = tval.tv_sec;
\r
653 lim_time = (pframes_done+1) * target_frametime + vsync_offset;
\r
654 if (currentConfig.Frameskip >= 0) // frameskip enabled
\r
656 for(i = 0; i < currentConfig.Frameskip; i++) {
\r
657 emu_update_input();
\r
658 SkipFrame(1); pframes_done++; frames_done++;
\r
659 if (PsndOut && !reset_timing) { // do framelimitting if sound is enabled
\r
660 gettimeofday(&tval, 0);
\r
661 if (pthissec != tval.tv_sec) tval.tv_usec+=1000000;
\r
662 if (tval.tv_usec < lim_time) { // we are too fast
\r
663 simpleWait(pthissec, lim_time);
\r
666 lim_time += target_frametime;
\r
669 else if (tval.tv_usec > lim_time) // auto frameskip
\r
671 // no time left for this frame - skip
\r
672 if (tval.tv_usec - lim_time >= 300000) {
\r
673 /* something caused a slowdown for us (disk access? cache flush?)
\r
674 * try to recover by resetting timing... */
\r
678 emu_update_input();
\r
679 SkipFrame(tval.tv_usec < lim_time+target_frametime*2); pframes_done++; frames_done++;
\r
683 emu_update_input();
\r
687 gettimeofday(&tval, 0);
\r
688 if (pthissec != tval.tv_sec) tval.tv_usec+=1000000;
\r
690 if (currentConfig.Frameskip < 0 && tval.tv_usec - lim_time >= 300000) // slowdown detection
\r
693 else if (PsndOut != NULL || currentConfig.Frameskip < 0)
\r
695 // sleep or vsync if we are still too fast
\r
696 // usleep sleeps for ~20ms minimum, so it is not a solution here
\r
697 if (!reset_timing && tval.tv_usec < lim_time)
\r
700 if (vsync_offset) {
\r
701 if (lim_time - tval.tv_usec > target_frametime/2)
\r
702 simpleWait(pthissec, lim_time - target_frametime/4);
\r
703 // gp2x_video_wait_vsync();
\r
705 simpleWait(pthissec, lim_time);
\r
710 blit(fpsbuff, notice);
\r
712 pframes_done++; pframes_shown++;
\r
713 frames_done++; frames_shown++;
\r
716 emu_set_fastforward(0);
\r
718 if (PicoAHW & PAHW_MCD) PicoCDBufferFree();
\r
721 if ((currentConfig.EmuOpt & EOPT_EN_SRAM) && SRam.changed) {
\r
722 /* FIXME: plat_status_msg_busy_first */
\r
723 emu_state_cb("Writing SRAM/BRAM..");
\r
724 emu_save_load_game(0, 1);
\r
728 // if in 8bit mode, generate 16bit image for menu background
\r
729 if ((PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80))
\r
730 pemu_forced_frame(POPT_EN_SOFTSCALE);
\r