pandora: handle custom size fb for menu layer
[picodrive.git] / platform / gizmondo / emu.c
... / ...
CommitLineData
1#include <windows.h>
2#include <string.h>
3
4#include <sys/stat.h> // mkdir
5#include <sys/types.h>
6
7#include "kgsdk/Framework.h"
8#include "kgsdk/Framework2D.h"
9#include "kgsdk/FrameworkAudio.h"
10#include "../common/emu.h"
11#include "../common/lprintf.h"
12#include "../common/arm_utils.h"
13#include "../common/config.h"
14#include "emu.h"
15#include "menu.h"
16#include "giz.h"
17#include "asm_utils.h"
18
19#include <pico/pico_int.h>
20
21#ifdef BENCHMARK
22#define OSD_FPS_X 220
23#else
24#define OSD_FPS_X 260
25#endif
26
27// main 300K gfx-related buffer. Used by menu and renderers.
28unsigned char gfx_buffer[321*240*2*2];
29unsigned char *PicoDraw2FB = gfx_buffer; // temporary buffer for alt renderer ( (8+320)*(8+240+8) )
30
31static short *snd_cbuff = NULL;
32static int snd_cbuf_samples = 0, snd_all_samples = 0;
33
34
35static void blit(const char *fps, const char *notice);
36static void clearArea(int full);
37
38int plat_get_root_dir(char *dst, int len)
39{
40 if (len > 0) *dst = 0;
41
42 return 0;
43}
44
45static void emu_msg_cb(const char *msg)
46{
47 if (giz_screen != NULL) fb_unlock();
48 giz_screen = fb_lock(1);
49
50 memset32((int *)((char *)giz_screen + 321*232*2), 0, 321*8*2/4);
51 emu_text_out16(4, 232, msg);
52 noticeMsgTime = GetTickCount() - 2000;
53
54 /* assumption: emu_msg_cb gets called only when something slow is about to happen */
55 reset_timing = 1;
56
57 fb_unlock();
58 giz_screen = fb_lock((currentConfig.EmuOpt&0x8000) ? 0 : 1);
59}
60
61void emu_stateCb(const char *str)
62{
63 if (giz_screen != NULL) fb_unlock();
64 giz_screen = fb_lock(1);
65
66 clearArea(0);
67 blit("", str);
68
69 fb_unlock();
70 giz_screen = NULL;
71
72 Sleep(0); /* yield the CPU, the system may need it */
73}
74
75void pemu_prep_defconfig(void)
76{
77 defaultConfig.s_PsndRate = 22050;
78 defaultConfig.s_PicoCDBuffers = 0;
79 defaultConfig.KeyBinds[ 2] = 1<<0; // SACB RLDU
80 defaultConfig.KeyBinds[ 3] = 1<<1;
81 defaultConfig.KeyBinds[ 0] = 1<<2;
82 defaultConfig.KeyBinds[ 1] = 1<<3;
83 defaultConfig.KeyBinds[ 5] = 1<<4;
84 defaultConfig.KeyBinds[ 6] = 1<<5;
85 defaultConfig.KeyBinds[ 7] = 1<<6;
86 defaultConfig.KeyBinds[ 4] = 1<<7;
87 defaultConfig.KeyBinds[13] = 1<<26; // switch rend
88 defaultConfig.KeyBinds[ 8] = 1<<27; // save state
89 defaultConfig.KeyBinds[ 9] = 1<<28; // load state
90 defaultConfig.KeyBinds[12] = 1<<29; // vol up
91 defaultConfig.KeyBinds[11] = 1<<30; // vol down
92 defaultConfig.scaling = 0;
93}
94
95
96static int EmuScanBegin16(unsigned int num)
97{
98 DrawLineDest = (unsigned short *) giz_screen + 321 * num;
99
100 if ((currentConfig.EmuOpt&0x4000) && (num&1) == 0) // (Pico.m.frame_count&1))
101 return 1; // skip next line
102
103 return 0;
104}
105
106static int EmuScanBegin8(unsigned int num)
107{
108 // draw like the fast renderer
109 HighCol = gfx_buffer + 328 * num;
110
111 return 0;
112}
113
114static void osd_text(int x, int y, const char *text)
115{
116 int len = strlen(text) * 8 / 2;
117 int *p, h;
118 for (h = 0; h < 8; h++) {
119 p = (int *) ((unsigned short *) giz_screen+x+321*(y+h));
120 p = (int *) ((int)p & ~3); // align
121 memset32(p, 0, len);
122 }
123 emu_text_out16(x, y, text);
124}
125
126/*
127void log1(void *p1, void *p2)
128{
129 lprintf("%p %p %p\n", p1, p2, DrawLineDest);
130}
131*/
132
133static void cd_leds(void)
134{
135 static int old_reg = 0;
136 unsigned int col_g, col_r, *p;
137
138 if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change
139 old_reg = Pico_mcd->s68k_regs[0];
140
141 p = (unsigned int *)((short *)giz_screen + 321*2+4+2);
142 col_g = (old_reg & 2) ? 0x06000600 : 0;
143 col_r = (old_reg & 1) ? 0xc000c000 : 0;
144 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 321/2 - 12/2 + 1;
145 *p++ = col_g; p+=3; *p++ = col_r; p += 321/2 - 10/2;
146 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r;
147}
148
149
150static short localPal[0x100];
151
152static void blit(const char *fps, const char *notice)
153{
154 int emu_opt = currentConfig.EmuOpt;
155
156 if (PicoOpt&0x10)
157 {
158 int lines_flags = 224;
159 // 8bit fast renderer
160 if (Pico.m.dirtyPal) {
161 Pico.m.dirtyPal = 0;
162 vidConvCpyRGB565(localPal, Pico.cram, 0x40);
163 }
164 // a hack for VR
165 if (PicoAHW & PAHW_SVP)
166 memset32((int *)(PicoDraw2FB+328*8+328*223), 0xe0e0e0e0, 328);
167 if (!(Pico.video.reg[12]&1)) lines_flags|=0x10000;
168 if (currentConfig.EmuOpt&0x4000)
169 lines_flags|=0x40000; // (Pico.m.frame_count&1)?0x20000:0x40000;
170 vidCpy8to16((unsigned short *)giz_screen+321*8, PicoDraw2FB+328*8, localPal, lines_flags);
171 }
172 else if (!(emu_opt&0x80))
173 {
174 int lines_flags;
175 // 8bit accurate renderer
176 if (Pico.m.dirtyPal) {
177 Pico.m.dirtyPal = 0;
178 vidConvCpyRGB565(localPal, Pico.cram, 0x40);
179 if (Pico.video.reg[0xC]&8) { // shadow/hilight mode
180 //vidConvCpyRGB32sh(localPal+0x40, Pico.cram, 0x40);
181 //vidConvCpyRGB32hi(localPal+0x80, Pico.cram, 0x40); // TODO?
182 memcpy32((void *)(localPal+0xc0), (void *)(localPal+0x40), 0x40*2/4);
183 localPal[0xc0] = 0x0600;
184 localPal[0xd0] = 0xc000;
185 localPal[0xe0] = 0x0000; // reserved pixels for OSD
186 localPal[0xf0] = 0xffff;
187 }
188 /* no support
189 else if (rendstatus & 0x20) { // mid-frame palette changes
190 vidConvCpyRGB565(localPal+0x40, HighPal, 0x40);
191 vidConvCpyRGB565(localPal+0x80, HighPal+0x40, 0x40);
192 } */
193 }
194 lines_flags = (Pico.video.reg[1]&8) ? 240 : 224;
195 if (!(Pico.video.reg[12]&1)) lines_flags|=0x10000;
196 if (currentConfig.EmuOpt&0x4000)
197 lines_flags|=0x40000; // (Pico.m.frame_count&1)?0x20000:0x40000;
198 vidCpy8to16((unsigned short *)giz_screen+321*8, PicoDraw2FB+328*8, localPal, lines_flags);
199 }
200
201 if (notice || (emu_opt & 2)) {
202 int h = 232;
203 if (notice) osd_text(4, h, notice);
204 if (emu_opt & 2) osd_text(OSD_FPS_X, h, fps);
205 }
206
207 if ((emu_opt & 0x400) && (PicoAHW & PAHW_MCD))
208 cd_leds();
209}
210
211// clears whole screen or just the notice area (in all buffers)
212static void clearArea(int full)
213{
214 if (giz_screen == NULL)
215 giz_screen = fb_lock(1);
216 if (full) memset32(giz_screen, 0, 320*240*2/4);
217 else memset32((int *)((char *)giz_screen + 321*232*2), 0, 321*8*2/4);
218
219 if (currentConfig.EmuOpt&0x8000) {
220 fb_unlock();
221 giz_screen = fb_lock(0);
222 if (full) memset32(giz_screen, 0, 320*240*2/4);
223 else memset32((int *)((char *)giz_screen + 321*232*2), 0, 321*8*2/4);
224 }
225}
226
227static void vidResetMode(void)
228{
229 giz_screen = fb_lock(1);
230
231 if (PicoOpt&0x10) {
232 } else if (currentConfig.EmuOpt&0x80) {
233 PicoDrawSetOutFormat(PDF_RGB555, 0);
234 PicoDrawSetCallbacks(EmuScanBegin16, NULL);
235 } else {
236 PicoDrawSetOutFormat(PDF_NONE, 0);
237 PicoDrawSetCallbacks(EmuScanBegin8, NULL);
238 }
239 if ((PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80)) {
240 // setup pal for 8-bit modes
241 localPal[0xc0] = 0x0600;
242 localPal[0xd0] = 0xc000;
243 localPal[0xe0] = 0x0000; // reserved pixels for OSD
244 localPal[0xf0] = 0xffff;
245 }
246 Pico.m.dirtyPal = 1;
247
248 memset32(giz_screen, 0, 321*240*2/4);
249 if (currentConfig.EmuOpt&0x8000) {
250 fb_unlock();
251 giz_screen = fb_lock(0);
252 memset32(giz_screen, 0, 321*240*2/4);
253 }
254 fb_unlock();
255 giz_screen = NULL;
256}
257
258/*
259#include <stdarg.h>
260static void stdbg(const char *fmt, ...)
261{
262 static int cnt = 0;
263 va_list vl;
264
265 sprintf(noticeMsg, "%x ", cnt++);
266 va_start(vl, fmt);
267 vsnprintf(noticeMsg+strlen(noticeMsg), sizeof(noticeMsg)-strlen(noticeMsg), fmt, vl);
268 va_end(vl);
269
270 noticeMsgTime = GetTickCount();
271}
272*/
273
274static void updateSound(int len)
275{
276 if (PicoOpt&8) len<<=1;
277
278 snd_all_samples += len;
279 PsndOut += len;
280 if (PsndOut - snd_cbuff >= snd_cbuf_samples)
281 {
282 //if (PsndOut - snd_cbuff != snd_cbuf_samples)
283 // stdbg("snd diff is %i, not %i", PsndOut - snd_cbuff, snd_cbuf_samples);
284 PsndOut = snd_cbuff;
285 }
286}
287
288
289static void SkipFrame(void)
290{
291 PicoSkipFrame=1;
292 PicoFrame();
293 PicoSkipFrame=0;
294}
295
296/* forced frame to front buffer */
297void pemu_forced_frame(int no_scale, int do_emu)
298{
299 int po_old = PicoOpt;
300 int eo_old = currentConfig.EmuOpt;
301
302 PicoOpt &= ~0x10;
303 PicoOpt |= POPT_ACC_SPRITES;
304 if (!no_scale)
305 PicoOpt |= POPT_EN_SOFTSCALE;
306 currentConfig.EmuOpt |= 0x80;
307
308 if (giz_screen == NULL)
309 giz_screen = fb_lock(1);
310
311 PicoDrawSetOutFormat(PDF_RGB555, 0);
312 PicoDrawSetCallbacks(EmuScanBegin16, NULL);
313 Pico.m.dirtyPal = 1;
314 PicoFrameDrawOnly();
315
316 fb_unlock();
317 giz_screen = NULL;
318
319 PicoOpt = po_old;
320 currentConfig.EmuOpt = eo_old;
321}
322
323
324static void RunEvents(unsigned int which)
325{
326 if (which & 0x1800) // save or load (but not both)
327 {
328 int do_it = 1;
329
330 if (PsndOut != NULL)
331 FrameworkAudio_SetPause(1);
332 if (giz_screen == NULL)
333 giz_screen = fb_lock(1);
334 if ( emu_check_save_file(state_slot) &&
335 (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) || // load
336 (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) // save
337 {
338 int keys;
339 blit("", (which & 0x1000) ? "LOAD STATE? (PLAY=yes, STOP=no)" : "OVERWRITE SAVE? (PLAY=yes, STOP=no)");
340 while( !((keys = Framework_PollGetButtons()) & (PBTN_PLAY|PBTN_STOP)) )
341 Sleep(50);
342 if (keys & PBTN_STOP) do_it = 0;
343 while( ((keys = Framework_PollGetButtons()) & (PBTN_PLAY|PBTN_STOP)) ) // wait for release
344 Sleep(50);
345 clearArea(0);
346 }
347
348 if (do_it)
349 {
350 osd_text(4, 232, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME");
351 PicoStateProgressCB = emu_stateCb;
352 emu_save_load_game((which & 0x1000) >> 12, 0);
353 PicoStateProgressCB = NULL;
354 Sleep(0);
355 }
356
357 if (PsndOut != NULL)
358 FrameworkAudio_SetPause(0);
359 reset_timing = 1;
360 }
361 if (which & 0x0400) // switch renderer
362 {
363 if (PicoOpt&0x10) { PicoOpt&=~0x10; currentConfig.EmuOpt |= 0x80; }
364 else { PicoOpt|= 0x10; currentConfig.EmuOpt &= ~0x80; }
365
366 vidResetMode();
367
368 if (PicoOpt&0x10) {
369 strcpy(noticeMsg, " 8bit fast renderer");
370 } else if (currentConfig.EmuOpt&0x80) {
371 strcpy(noticeMsg, "16bit accurate renderer");
372 } else {
373 strcpy(noticeMsg, " 8bit accurate renderer");
374 }
375
376 noticeMsgTime = GetTickCount();
377 }
378 if (which & 0x0300)
379 {
380 if(which&0x0200) {
381 state_slot -= 1;
382 if(state_slot < 0) state_slot = 9;
383 } else {
384 state_slot += 1;
385 if(state_slot > 9) state_slot = 0;
386 }
387 sprintf(noticeMsg, "SAVE SLOT %i [%s]", state_slot, emu_check_save_file(state_slot) ? "USED" : "FREE");
388 noticeMsgTime = GetTickCount();
389 }
390}
391
392static void updateKeys(void)
393{
394 unsigned int keys, allActions[2] = { 0, 0 }, events;
395 static unsigned int prevEvents = 0;
396 int i;
397
398 /* FIXME: port to input fw, merge with emu.c:emu_update_input() */
399 keys = Framework_PollGetButtons();
400 if (keys & PBTN_HOME)
401 engineState = PGS_Menu;
402
403 keys &= CONFIGURABLE_KEYS;
404
405 PicoPad[0] = allActions[0] & 0xfff;
406 PicoPad[1] = allActions[1] & 0xfff;
407
408 if (allActions[0] & 0x7000) emu_DoTurbo(&PicoPad[0], allActions[0]);
409 if (allActions[1] & 0x7000) emu_DoTurbo(&PicoPad[1], allActions[1]);
410
411 events = (allActions[0] | allActions[1]) >> 16;
412
413 // volume is treated in special way and triggered every frame
414 if ((events & 0x6000) && PsndOut != NULL)
415 {
416 int vol = currentConfig.volume;
417 if (events & 0x2000) {
418 if (vol < 100) vol++;
419 } else {
420 if (vol > 0) vol--;
421 }
422 FrameworkAudio_SetVolume(vol, vol);
423 sprintf(noticeMsg, "VOL: %02i ", vol);
424 noticeMsgTime = GetTickCount();
425 currentConfig.volume = vol;
426 }
427
428 events &= ~prevEvents;
429 if (events) RunEvents(events);
430 if (movie_data) emu_updateMovie();
431
432 prevEvents = (allActions[0] | allActions[1]) >> 16;
433}
434
435void plat_debug_cat(char *str)
436{
437}
438
439static void simpleWait(DWORD until)
440{
441 DWORD tval;
442 int diff;
443
444 tval = GetTickCount();
445 diff = (int)until - (int)tval;
446 if (diff >= 2)
447 Sleep(diff - 1);
448
449 while ((tval = GetTickCount()) < until && until - tval < 512) // some simple overflow detection
450 spend_cycles(1024*2);
451}
452
453void pemu_loop(void)
454{
455 static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;
456 char fpsbuff[24]; // fps count c string
457 DWORD tval, tval_prev = 0, tval_thissec = 0; // timing
458 int frames_done = 0, frames_shown = 0, oldmodes = 0, sec_ms = 1000;
459 int target_fps, target_frametime, lim_time, tval_diff, i;
460 char *notice = NULL;
461
462 lprintf("entered emu_Loop()\n");
463
464 fpsbuff[0] = 0;
465
466 // make sure we are in correct mode
467 vidResetMode();
468 if (currentConfig.scaling) PicoOpt|=0x4000;
469 else PicoOpt&=~0x4000;
470 Pico.m.dirtyPal = 1;
471 oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc;
472
473 // pal/ntsc might have changed, reset related stuff
474 target_fps = Pico.m.pal ? 50 : 60;
475 target_frametime = Pico.m.pal ? (1000<<8)/50 : (1000<<8)/60+1;
476 reset_timing = 1;
477
478 // prepare CD buffer
479 if (PicoAHW & PAHW_MCD) PicoCDBufferInit();
480
481 // prepare sound stuff
482 PsndOut = NULL;
483 if (currentConfig.EmuOpt & 4)
484 {
485 int ret, snd_excess_add, stereo;
486 if (PsndRate != PsndRate_old || (PicoOpt&0x0b) != (PicoOpt_old&0x0b) || Pico.m.pal != pal_old) {
487 PsndRerate(Pico.m.frame_count ? 1 : 0);
488 }
489 stereo=(PicoOpt&8)>>3;
490 snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;
491 snd_cbuf_samples = (PsndRate<<stereo) * 16 / target_fps;
492 lprintf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",
493 PsndRate, PsndLen, snd_excess_add, stereo, Pico.m.pal);
494 ret = FrameworkAudio_Init(PsndRate, snd_cbuf_samples, stereo);
495 if (ret != 0) {
496 lprintf("FrameworkAudio_Init() failed: %i\n", ret);
497 sprintf(noticeMsg, "sound init failed (%i), snd disabled", ret);
498 noticeMsgTime = GetTickCount();
499 currentConfig.EmuOpt &= ~4;
500 } else {
501 FrameworkAudio_SetVolume(currentConfig.volume, currentConfig.volume);
502 PicoWriteSound = updateSound;
503 snd_cbuff = FrameworkAudio_56448Buffer();
504 PsndOut = snd_cbuff + snd_cbuf_samples / 2; // start writing at the middle
505 snd_all_samples = 0;
506 PsndRate_old = PsndRate;
507 PicoOpt_old = PicoOpt;
508 pal_old = Pico.m.pal;
509 }
510 }
511
512 // loop?
513 while (engineState == PGS_Running)
514 {
515 int modes;
516
517 tval = GetTickCount();
518 if (reset_timing || tval < tval_prev) {
519 //stdbg("timing reset");
520 reset_timing = 0;
521 tval_thissec = tval;
522 frames_shown = frames_done = 0;
523 }
524
525 // show notice message?
526 if (noticeMsgTime) {
527 static int noticeMsgSum;
528 if (tval - noticeMsgTime > 2000) { // > 2.0 sec
529 noticeMsgTime = 0;
530 clearArea(0);
531 notice = 0;
532 } else {
533 int sum = noticeMsg[0]+noticeMsg[1]+noticeMsg[2];
534 if (sum != noticeMsgSum) { clearArea(0); noticeMsgSum = sum; }
535 notice = noticeMsg;
536 }
537 }
538
539 // check for mode changes
540 modes = ((Pico.video.reg[12]&1)<<2)|(Pico.video.reg[1]&8);
541 if (modes != oldmodes) {
542 oldmodes = modes;
543 clearArea(1);
544 }
545
546 // second passed?
547 if (tval - tval_thissec >= sec_ms)
548 {
549#ifdef BENCHMARK
550 static int bench = 0, bench_fps = 0, bench_fps_s = 0, bfp = 0, bf[4];
551 if(++bench == 10) {
552 bench = 0;
553 bench_fps_s = bench_fps;
554 bf[bfp++ & 3] = bench_fps;
555 bench_fps = 0;
556 }
557 bench_fps += frames_shown;
558 sprintf(fpsbuff, "%02i/%02i/%02i", frames_shown, bench_fps_s, (bf[0]+bf[1]+bf[2]+bf[3])>>2);
559#else
560 if(currentConfig.EmuOpt & 2)
561 sprintf(fpsbuff, "%02i/%02i", frames_shown, frames_done);
562#endif
563 //tval_thissec += 1000;
564 tval_thissec += sec_ms;
565
566 if (PsndOut != NULL)
567 {
568 /* some code which tries to sync things to audio clock, the dirty way */
569 static int audio_skew_prev = 0;
570 int audio_skew, adj, co = 9, shift = 7;
571 audio_skew = snd_all_samples*2 - FrameworkAudio_BufferPos();
572 if (PsndRate == 22050) co = 10;
573 if (PsndRate > 22050) co = 11;
574 if (PicoOpt&8) shift++;
575 if (audio_skew < 0) {
576 adj = -((-audio_skew) >> shift);
577 if (audio_skew > -(6<<co)) adj>>=1;
578 if (audio_skew > -(4<<co)) adj>>=1;
579 if (audio_skew > -(2<<co)) adj>>=1;
580 if (audio_skew > audio_skew_prev) adj>>=2; // going up already
581 } else {
582 adj = audio_skew >> shift;
583 if (audio_skew < (6<<co)) adj>>=1;
584 if (audio_skew < (4<<co)) adj>>=1;
585 if (audio_skew < (2<<co)) adj>>=1;
586 if (audio_skew < audio_skew_prev) adj>>=2;
587 }
588 audio_skew_prev = audio_skew;
589 target_frametime += adj;
590 sec_ms = (target_frametime * target_fps) >> 8;
591 //stdbg("%i %i %i", audio_skew, adj, sec_ms);
592 frames_done = frames_shown = 0;
593 }
594 else if (currentConfig.Frameskip < 0) {
595 frames_done -= target_fps; if (frames_done < 0) frames_done = 0;
596 frames_shown -= target_fps; if (frames_shown < 0) frames_shown = 0;
597 if (frames_shown > frames_done) frames_shown = frames_done;
598 } else {
599 frames_done = frames_shown = 0;
600 }
601 }
602#ifdef PFRAMES
603 sprintf(fpsbuff, "%i", Pico.m.frame_count);
604#endif
605
606 tval_prev = tval;
607 lim_time = (frames_done+1) * target_frametime;
608 if (currentConfig.Frameskip >= 0) // frameskip enabled
609 {
610 for (i = 0; i < currentConfig.Frameskip; i++) {
611 updateKeys();
612 SkipFrame(); frames_done++;
613 if (PsndOut) { // do framelimitting if sound is enabled
614 int tval_diff;
615 tval = GetTickCount();
616 tval_diff = (int)(tval - tval_thissec) << 8;
617 if (tval_diff < lim_time) // we are too fast
618 simpleWait(tval + ((lim_time - tval_diff)>>8));
619 }
620 lim_time += target_frametime;
621 }
622 }
623 else // auto frameskip
624 {
625 int tval_diff;
626 tval = GetTickCount();
627 tval_diff = (int)(tval - tval_thissec) << 8;
628 if (tval_diff > lim_time)
629 {
630 // no time left for this frame - skip
631 if (tval_diff - lim_time >= (300<<8)) {
632 /* something caused a slowdown for us (disk access? cache flush?)
633 * try to recover by resetting timing... */
634 reset_timing = 1;
635 continue;
636 }
637 updateKeys();
638 SkipFrame(); frames_done++;
639 continue;
640 }
641 }
642
643 updateKeys();
644
645 if (currentConfig.EmuOpt&0x80)
646 /* be sure correct framebuffer is locked */
647 giz_screen = fb_lock((currentConfig.EmuOpt&0x8000) ? 0 : 1);
648
649 PicoFrame();
650
651 if (giz_screen == NULL)
652 giz_screen = fb_lock((currentConfig.EmuOpt&0x8000) ? 0 : 1);
653
654 blit(fpsbuff, notice);
655
656 if (giz_screen != NULL) {
657 fb_unlock();
658 giz_screen = NULL;
659 }
660
661 if (currentConfig.EmuOpt&0x2000)
662 Framework2D_WaitVSync();
663
664 if (currentConfig.EmuOpt&0x8000)
665 fb_flip();
666
667 // check time
668 tval = GetTickCount();
669 tval_diff = (int)(tval - tval_thissec) << 8;
670
671 if (currentConfig.Frameskip < 0 && tval_diff - lim_time >= (300<<8)) // slowdown detection
672 reset_timing = 1;
673 else if (PsndOut != NULL || currentConfig.Frameskip < 0)
674 {
675 // sleep if we are still too fast
676 if (tval_diff < lim_time)
677 {
678 // we are too fast
679 simpleWait(tval + ((lim_time - tval_diff) >> 8));
680 }
681 }
682
683 frames_done++; frames_shown++;
684 }
685
686
687 if (PicoAHW & PAHW_MCD) PicoCDBufferFree();
688
689 if (PsndOut != NULL) {
690 PsndOut = snd_cbuff = NULL;
691 FrameworkAudio_Close();
692 }
693
694 // save SRAM
695 if ((currentConfig.EmuOpt & 1) && SRam.changed) {
696 emu_stateCb("Writing SRAM/BRAM..");
697 emu_save_load_game(0, 1);
698 SRam.changed = 0;
699 }
700}
701