633d027c9ed5fd165cc9f11afbf5c47cf76da774
[picodrive.git] / platform / pandora / emu.c
1 // (c) Copyright 2006-2008 notaz, All rights reserved.\r
2 // Free for non-commercial use.\r
3 \r
4 // For commercial use, separate licencing terms must be obtained.\r
5 \r
6 #include <stdio.h>\r
7 #include <stdlib.h>\r
8 #include <sys/time.h>\r
9 #include <sys/stat.h>\r
10 #include <sys/types.h>\r
11 #include <linux/limits.h>\r
12 #include <ctype.h>\r
13 #include <unistd.h>\r
14 \r
15 #include <stdarg.h>\r
16 \r
17 #include "../gp2x/emu.h"\r
18 #include "../gp2x/usbjoy.h"\r
19 #include "../gp2x/menu.h"\r
20 #include "../common/arm_utils.h"\r
21 #include "../common/fonts.h"\r
22 #include "../common/emu.h"\r
23 #include "../common/config.h"\r
24 #include "../common/common.h"\r
25 #include "asm_utils.h"\r
26 \r
27 #include <Pico/PicoInt.h>\r
28 #include <Pico/Patch.h>\r
29 #include <Pico/sound/mix.h>\r
30 #include <zlib/zlib.h>\r
31 \r
32 //#define PFRAMES\r
33 #define BENCHMARK\r
34 //#define USE_320_SCREEN 1\r
35 \r
36 #ifdef BENCHMARK\r
37 #define OSD_FPS_X (800-200)\r
38 #else\r
39 #define OSD_FPS_X (800-120)\r
40 #endif\r
41 \r
42 \r
43 int engineState;\r
44 int select_exits = 0;\r
45 \r
46 char romFileName[PATH_MAX];\r
47 \r
48 static short __attribute__((aligned(4))) sndBuffer[2*44100/50];\r
49 static struct timeval noticeMsgTime = { 0, 0 }; // when started showing\r
50 static int osd_fps_x;\r
51 char noticeMsg[64];                     // notice msg to draw\r
52 unsigned char *PicoDraw2FB = NULL;  // temporary buffer for alt renderer\r
53 int reset_timing = 0;\r
54 \r
55 #define PICO_PEN_ADJUST_X 4\r
56 #define PICO_PEN_ADJUST_Y 2\r
57 static int pico_pen_x = SCREEN_WIDTH/2, pico_pen_y = 240/2;\r
58 \r
59 static void emu_msg_cb(const char *msg);\r
60 static void emu_msg_tray_open(void);\r
61 \r
62 \r
63 void emu_noticeMsgUpdated(void)\r
64 {\r
65         gettimeofday(&noticeMsgTime, 0);\r
66 }\r
67 \r
68 void emu_getMainDir(char *dst, int len)\r
69 {\r
70         extern char **g_argv;\r
71         int j;\r
72 \r
73         strncpy(dst, g_argv[0], len);\r
74         len -= 32; // reserve\r
75         if (len < 0) len = 0;\r
76         dst[len] = 0;\r
77         for (j = strlen(dst); j > 0; j--)\r
78                 if (dst[j] == '/') { dst[j+1] = 0; break; }\r
79 }\r
80 \r
81 void emu_Init(void)\r
82 {\r
83         // make temp buffer for alt renderer\r
84         PicoDraw2FB = malloc((8+320)*(8+240+8));\r
85         if (!PicoDraw2FB)\r
86         {\r
87                 printf("PicoDraw2FB == 0\n");\r
88         }\r
89 \r
90         // make dirs for saves, cfgs, etc.\r
91         mkdir("mds", 0777);\r
92         mkdir("srm", 0777);\r
93         mkdir("brm", 0777);\r
94         mkdir("cfg", 0777);\r
95 \r
96         PicoInit();\r
97         PicoMessage = emu_msg_cb;\r
98         PicoMCDopenTray = emu_msg_tray_open;\r
99         PicoMCDcloseTray = menu_loop_tray;\r
100 }\r
101 \r
102 \r
103 static void scaling_update(void)\r
104 {\r
105         PicoOpt &= ~0x4100;\r
106         switch (currentConfig.scaling) {\r
107                 default: break; // off\r
108                 case 1:  // hw hor\r
109                 case 2:  PicoOpt |=  0x0100; break; // hw hor+vert\r
110                 case 3:  PicoOpt |=  0x4000; break; // sw hor\r
111         }\r
112 }\r
113 \r
114 \r
115 void emu_Deinit(void)\r
116 {\r
117         // save SRAM\r
118         if((currentConfig.EmuOpt & 1) && SRam.changed) {\r
119                 emu_SaveLoadGame(0, 1);\r
120                 SRam.changed = 0;\r
121         }\r
122 \r
123         if (!(currentConfig.EmuOpt & 0x20)) {\r
124                 config_writelrom(PicoConfigFile);\r
125 #ifndef NO_SYNC\r
126                 sync();\r
127 #endif\r
128         }\r
129 \r
130         free(PicoDraw2FB);\r
131 \r
132         PicoExit();\r
133 }\r
134 \r
135 void emu_prepareDefaultConfig(void)\r
136 {\r
137         memset(&defaultConfig, 0, sizeof(defaultConfig));\r
138         defaultConfig.EmuOpt    = 0x8f | 0x00600; // | <- confirm_save, cd_leds\r
139         defaultConfig.s_PicoOpt  = 0x0f | POPT_EXT_FM|POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_SVP_DRC;\r
140         defaultConfig.s_PicoOpt |= POPT_ACC_SPRITES|POPT_EN_MCD_GFX;\r
141         defaultConfig.s_PicoOpt &= ~POPT_EN_SVP_DRC; // crashes :(\r
142         defaultConfig.EmuOpt    &= ~8; // no save gzip\r
143         defaultConfig.s_PsndRate = 44100;\r
144         defaultConfig.s_PicoRegion = 0;\r
145         defaultConfig.s_PicoAutoRgnOrder = 0x184; // US, EU, JP\r
146         defaultConfig.s_PicoCDBuffers = 0;\r
147         defaultConfig.Frameskip = 0;\r
148         defaultConfig.CPUclock = 200;\r
149         defaultConfig.volume = 50;\r
150         defaultConfig.scaling = 0;\r
151         defaultConfig.turbo_rate = 15;\r
152 }\r
153 \r
154 void emu_setDefaultConfig(void)\r
155 {\r
156         memcpy(&currentConfig, &defaultConfig, sizeof(currentConfig));\r
157         PicoOpt = currentConfig.s_PicoOpt;\r
158         PsndRate = currentConfig.s_PsndRate;\r
159         PicoRegionOverride = currentConfig.s_PicoRegion;\r
160         PicoAutoRgnOrder = currentConfig.s_PicoAutoRgnOrder;\r
161         PicoCDBuffers = currentConfig.s_PicoCDBuffers;\r
162 }\r
163 \r
164 static void textOut16(int x, int y, const char *text)\r
165 {\r
166         int i,l,len=strlen(text);\r
167         unsigned int *screen = (unsigned int *)((unsigned short *)SCREEN_BUFFER + (x&~1) + y*SCREEN_WIDTH);\r
168 \r
169         for (i = 0; i < len; i++)\r
170         {\r
171                 for (l=0;l<16;)\r
172                 {\r
173                         unsigned char fd = fontdata8x8[((text[i])*8)+l/2];\r
174                         unsigned int *d = &screen[l*SCREEN_WIDTH/2];\r
175                         if (fd&0x80) d[0]=0xffffffff;\r
176                         if (fd&0x40) d[1]=0xffffffff;\r
177                         if (fd&0x20) d[2]=0xffffffff;\r
178                         if (fd&0x10) d[3]=0xffffffff;\r
179                         if (fd&0x08) d[4]=0xffffffff;\r
180                         if (fd&0x04) d[5]=0xffffffff;\r
181                         if (fd&0x02) d[6]=0xffffffff;\r
182                         if (fd&0x01) d[7]=0xffffffff;\r
183                         l++; d = &screen[l*SCREEN_WIDTH/2];\r
184                         if (fd&0x80) d[0]=0xffffffff;\r
185                         if (fd&0x40) d[1]=0xffffffff;\r
186                         if (fd&0x20) d[2]=0xffffffff;\r
187                         if (fd&0x10) d[3]=0xffffffff;\r
188                         if (fd&0x08) d[4]=0xffffffff;\r
189                         if (fd&0x04) d[5]=0xffffffff;\r
190                         if (fd&0x02) d[6]=0xffffffff;\r
191                         if (fd&0x01) d[7]=0xffffffff;\r
192                         l++;\r
193                 }\r
194                 screen += 8;\r
195         }\r
196 }\r
197 \r
198 \r
199 void osd_text(int x, int y, const char *text)\r
200 {\r
201         int len = strlen(text)*8;\r
202 \r
203         if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
204                 int *p, i, h;\r
205                 x &= ~3; // align x\r
206                 len = (len+3) >> 2;\r
207                 for (h = 0; h < 8; h++) {\r
208                         p = (int *) ((unsigned char *) gp2x_screen+x+SCREEN_WIDTH*(y+h));\r
209                         for (i = len; i; i--, p++) *p = 0xe0e0e0e0;\r
210                 }\r
211                 emu_textOut8(x, y, text);\r
212         } else {\r
213                 int *p, i, h;\r
214                 x &= ~1; // align x\r
215                 len++;\r
216                 for (h = 0; h < 16; h++) {\r
217                         p = (int *) ((unsigned short *) gp2x_screen+x+SCREEN_WIDTH*(y+h));\r
218                         for (i = len; i; i--, p++) *p = 0;//(*p>>2)&0x39e7;\r
219                 }\r
220                 textOut16(x, y, text);\r
221         }\r
222 }\r
223 \r
224 static void draw_cd_leds(void)\r
225 {\r
226 //      static\r
227         int old_reg;\r
228 //      if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change // mmu hack problems?\r
229         old_reg = Pico_mcd->s68k_regs[0];\r
230 \r
231         if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
232                 // 8-bit modes\r
233                 unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;\r
234                 unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;\r
235                 *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*2+ 4) =\r
236                 *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*3+ 4) =\r
237                 *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*4+ 4) = col_g;\r
238                 *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*2+12) =\r
239                 *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*3+12) =\r
240                 *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*4+12) = col_r;\r
241         } else {\r
242                 // 16-bit modes\r
243                 unsigned int *p = (unsigned int *)((short *)gp2x_screen + SCREEN_WIDTH*2+4);\r
244                 unsigned int col_g = (old_reg & 2) ? 0x06000600 : 0;\r
245                 unsigned int col_r = (old_reg & 1) ? 0xc000c000 : 0;\r
246                 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += SCREEN_WIDTH/2 - 12/2;\r
247                 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += SCREEN_WIDTH/2 - 12/2;\r
248                 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r;\r
249         }\r
250 }\r
251 \r
252 static void draw_pico_ptr(void)\r
253 {\r
254         unsigned short *p = (unsigned short *)gp2x_screen;\r
255 \r
256         // only if pen enabled and for 16bit modes\r
257         if (pico_inp_mode == 0 || (PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80)) return;\r
258 \r
259         if (!(Pico.video.reg[12]&1) && !(PicoOpt&POPT_DIS_32C_BORDER))\r
260                 p += 32;\r
261 \r
262         p += SCREEN_WIDTH * (pico_pen_y + PICO_PEN_ADJUST_Y);\r
263         p += pico_pen_x + PICO_PEN_ADJUST_X;\r
264         p[0]   ^= 0xffff;\r
265         p[319] ^= 0xffff;\r
266         p[320] ^= 0xffff;\r
267         p[321] ^= 0xffff;\r
268         p[640] ^= 0xffff;\r
269 }\r
270 \r
271 #ifdef USE_320_SCREEN\r
272 \r
273 static int EmuScanBegin16(unsigned int num)\r
274 {\r
275         if (!(Pico.video.reg[1]&8)) num += 8;\r
276         DrawLineDest = (unsigned short *)gp2x_screen + num*800 + 800/2 - 320/2;\r
277         //int w = (Pico.video.reg[12]&1) ? 320 : 256;\r
278         //DrawLineDest = (unsigned short *)gp2x_screen + num*w;\r
279 \r
280         return 0;\r
281 }\r
282 \r
283 #else // USE_320_SCREEN\r
284 \r
285 static int EmuScanEnd16(unsigned int num)\r
286 {\r
287         unsigned char  *ps=HighCol+8;\r
288         unsigned short *pd;\r
289         unsigned short *pal=HighPal;\r
290         int sh = Pico.video.reg[0xC]&8;\r
291         int len, mask = 0xff;\r
292 \r
293         if (!(Pico.video.reg[1]&8)) num += 8;\r
294         pd=(unsigned short *)gp2x_screen + num*800*2 + 800/2 - 320*2/2;\r
295 \r
296         if (Pico.m.dirtyPal)\r
297                 PicoDoHighPal555(sh);\r
298 \r
299         if (Pico.video.reg[12]&1) {\r
300                 len = 320;\r
301         } else {\r
302                 pd += 32*2;\r
303                 len = 256;\r
304         }\r
305 \r
306         if (!sh && (rendstatus & PDRAW_ACC_SPRITES))\r
307                 mask=0x3f; // accurate sprites, upper bits are priority stuff\r
308 \r
309 #if 1\r
310         clut_line(pd, ps, pal, (mask<<16) | len);\r
311 #else\r
312         for (; len > 0; len--)\r
313         {\r
314                 unsigned int p = pal[*ps++ & mask];\r
315                 p |= p << 16;\r
316                 *(unsigned int *)pd = p;\r
317                 *(unsigned int *)(&pd[800]) = p;\r
318                 pd += 2;\r
319         }\r
320 #endif\r
321 \r
322         return 0;\r
323 }\r
324 \r
325 #endif // USE_320_SCREEN\r
326 \r
327 static int EmuScanBegin8(unsigned int num)\r
328 {\r
329         if (!(Pico.video.reg[1]&8)) num += 8;\r
330         DrawLineDest = (unsigned char *)  gp2x_screen + SCREEN_WIDTH * num;\r
331 \r
332         return 0;\r
333 }\r
334 \r
335 int localPal[0x100];\r
336 static void (*vidCpyM2)(void *dest, void *src) = NULL;\r
337 \r
338 static void blit(const char *fps, const char *notice)\r
339 {\r
340         int emu_opt = currentConfig.EmuOpt;\r
341 \r
342         if (PicoOpt&0x10)\r
343         {\r
344                 // 8bit fast renderer\r
345                 if (Pico.m.dirtyPal) {\r
346                         Pico.m.dirtyPal = 0;\r
347                         vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
348                         // feed new palette to our device\r
349                         gp2x_video_setpalette(localPal, 0x40);\r
350                 }\r
351                 // a hack for VR\r
352                 if (PicoRead16Hook == PicoSVPRead16)\r
353                         memset32((int *)(PicoDraw2FB+328*8+328*223), 0xe0e0e0e0, 328);\r
354                 // do actual copy\r
355                 vidCpyM2((unsigned char *)gp2x_screen+SCREEN_WIDTH*8, PicoDraw2FB+328*8);\r
356         }\r
357         else if (!(emu_opt&0x80))\r
358         {\r
359                 // 8bit accurate renderer\r
360                 if (Pico.m.dirtyPal)\r
361                 {\r
362                         int pallen = 0x40;\r
363                         Pico.m.dirtyPal = 0;\r
364                         if (Pico.video.reg[0xC]&8) // shadow/hilight mode\r
365                         {\r
366                                 vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
367                                 vidConvCpyRGB32sh(localPal+0x40, Pico.cram, 0x40);\r
368                                 vidConvCpyRGB32hi(localPal+0x80, Pico.cram, 0x40);\r
369                                 memcpy32(localPal+0xc0, localPal+0x40, 0x40);\r
370                                 pallen = 0x100;\r
371                         }\r
372                         else if (rendstatus & PDRAW_ACC_SPRITES) {\r
373                                 vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
374                                 memcpy32(localPal+0x40, localPal, 0x40);\r
375                                 memcpy32(localPal+0x80, localPal, 0x40);\r
376                                 memcpy32(localPal+0xc0, localPal, 0x40);\r
377                                 pallen = 0x100;\r
378                         }\r
379                         else if (rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes\r
380                                 vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
381                                 vidConvCpyRGB32(localPal+0x40, HighPal, 0x40);\r
382                                 vidConvCpyRGB32(localPal+0x80, HighPal+0x40, 0x40);\r
383                                 pallen = 0xc0;\r
384                         }\r
385                         else {\r
386                                 vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
387                         }\r
388                         if (pallen > 0xc0) {\r
389                                 localPal[0xc0] = 0x0000c000;\r
390                                 localPal[0xd0] = 0x00c00000;\r
391                                 localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
392                                 localPal[0xf0] = 0x00ffffff;\r
393                         }\r
394                         gp2x_video_setpalette(localPal, pallen);\r
395                 }\r
396         }\r
397 \r
398         if (notice || (emu_opt & 2)) {\r
399                 int h = SCREEN_HEIGHT-16;\r
400                 if (currentConfig.scaling == 2 && !(Pico.video.reg[1]&8)) h -= 16;\r
401                 if (notice) osd_text(4, h, notice);\r
402                 if (emu_opt & 2)\r
403                         osd_text(osd_fps_x, h, fps);\r
404         }\r
405         if ((emu_opt & 0x400) && (PicoAHW & PAHW_MCD))\r
406                 draw_cd_leds();\r
407         if (PicoAHW & PAHW_PICO)\r
408                 draw_pico_ptr();\r
409 {\r
410 //static int u=0;\r
411 //memset((char *)gp2x_screen+800*471*2, (u++)>>1, 800*9*2);\r
412 }\r
413 \r
414         //gp2x_video_wait_vsync();\r
415         gp2x_video_flip();\r
416 }\r
417 \r
418 \r
419 // clears whole screen or just the notice area (in all buffers)\r
420 static void clearArea(int full)\r
421 {\r
422         if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
423                 // 8-bit renderers\r
424                 if (full) gp2x_memset_all_buffers(0, 0xe0, SCREEN_WIDTH*240);\r
425                 else      gp2x_memset_all_buffers(SCREEN_WIDTH*232, 0xe0, SCREEN_WIDTH*8);\r
426         } else {\r
427                 // 16bit accurate renderer\r
428                 if (full) gp2x_memset_all_buffers(0, 0, SCREEN_WIDTH*SCREEN_HEIGHT*2);\r
429                 else      gp2x_memset_all_buffers(SCREEN_WIDTH*(SCREEN_HEIGHT-16)*2, 0, SCREEN_WIDTH*16*2);\r
430         }\r
431 }\r
432 \r
433 \r
434 static void vidResetMode(void)\r
435 {\r
436         if (PicoOpt&0x10) {\r
437                 gp2x_video_changemode(8);\r
438         } else if (currentConfig.EmuOpt&0x80) {\r
439                 gp2x_video_changemode(16);\r
440 #ifdef USE_320_SCREEN\r
441                 PicoDrawSetColorFormat(1);\r
442                 PicoScanBegin = EmuScanBegin16;\r
443 #else\r
444                 PicoDrawSetColorFormat(-1);\r
445                 PicoScanEnd = EmuScanEnd16;\r
446 #endif\r
447         } else {\r
448                 gp2x_video_changemode(8);\r
449                 PicoDrawSetColorFormat(2);\r
450                 PicoScanBegin = EmuScanBegin8;\r
451         }\r
452         if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
453                 // setup pal for 8-bit modes\r
454                 localPal[0xc0] = 0x0000c000; // MCD LEDs\r
455                 localPal[0xd0] = 0x00c00000;\r
456                 localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
457                 localPal[0xf0] = 0x00ffffff;\r
458                 gp2x_video_setpalette(localPal, 0x100);\r
459                 gp2x_memset_all_buffers(0, 0xe0, 320*240);\r
460                 gp2x_video_flip();\r
461         }\r
462         Pico.m.dirtyPal = 1;\r
463         // reset scaling\r
464         if (currentConfig.scaling == 2 && !(Pico.video.reg[1]&8))\r
465              gp2x_video_RGB_setscaling(8, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 224);\r
466         else gp2x_video_RGB_setscaling(0, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 240);\r
467 }\r
468 \r
469 \r
470 static void emu_msg_cb(const char *msg)\r
471 {\r
472         if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
473                 // 8-bit renderers\r
474                 gp2x_memset_all_buffers(SCREEN_WIDTH*(SCREEN_HEIGHT-16), 0xe0, SCREEN_WIDTH*16);\r
475                 osd_text(4, SCREEN_HEIGHT-16, msg);\r
476                 gp2x_memcpy_all_buffers((char *)gp2x_screen+SCREEN_WIDTH*(SCREEN_HEIGHT-16),\r
477                         SCREEN_WIDTH*(SCREEN_HEIGHT-16), SCREEN_WIDTH*16);\r
478         } else {\r
479                 // 16bit accurate renderer\r
480                 gp2x_memset_all_buffers(SCREEN_WIDTH*(SCREEN_HEIGHT-16)*2, 0, SCREEN_WIDTH*16*2);\r
481                 osd_text(4, SCREEN_HEIGHT-16, msg);\r
482                 gp2x_memcpy_all_buffers((char *)gp2x_screen+SCREEN_WIDTH*(SCREEN_HEIGHT-16)*2,\r
483                         SCREEN_WIDTH*(SCREEN_HEIGHT-16)*2, SCREEN_WIDTH*16*2);\r
484         }\r
485         gettimeofday(&noticeMsgTime, 0);\r
486         noticeMsgTime.tv_sec -= 2;\r
487 \r
488         /* assumption: emu_msg_cb gets called only when something slow is about to happen */\r
489         reset_timing = 1;\r
490 }\r
491 \r
492 static void emu_state_cb(const char *str)\r
493 {\r
494         clearArea(0);\r
495         blit("", str);\r
496 }\r
497 \r
498 static void emu_msg_tray_open(void)\r
499 {\r
500         strcpy(noticeMsg, "CD tray opened");\r
501         gettimeofday(&noticeMsgTime, 0);\r
502 }\r
503 \r
504 static void RunEventsPico(unsigned int events, unsigned int gp2x_keys)\r
505 {\r
506         int ret, px, py, lim_x;\r
507         static int pdown_frames = 0;\r
508 \r
509         emu_RunEventsPico(events);\r
510 \r
511         if (pico_inp_mode == 0) return;\r
512 \r
513         // for F200\r
514         ret = gp2x_touchpad_read(&px, &py);\r
515         if (ret >= 0)\r
516         {\r
517                 if (ret > 35000)\r
518                 {\r
519                         if (pdown_frames++ > 5)\r
520                                 PicoPad[0] |= 0x20;\r
521 \r
522                         pico_pen_x = px;\r
523                         pico_pen_y = py;\r
524                         if (!(Pico.video.reg[12]&1)) {\r
525                                 pico_pen_x -= 32;\r
526                                 if (pico_pen_x <   0) pico_pen_x = 0;\r
527                                 if (pico_pen_x > 248) pico_pen_x = 248;\r
528                         }\r
529                         if (pico_pen_y > 224) pico_pen_y = 224;\r
530                 }\r
531                 else\r
532                         pdown_frames = 0;\r
533 \r
534                 //if (ret == 0)\r
535                 //      PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;\r
536         }\r
537 \r
538         PicoPad[0] &= ~0x0f; // release UDLR\r
539         if (gp2x_keys & GP2X_UP)    pico_pen_y--;\r
540         if (gp2x_keys & GP2X_DOWN)  pico_pen_y++;\r
541         if (gp2x_keys & GP2X_LEFT)  pico_pen_x--;\r
542         if (gp2x_keys & GP2X_RIGHT) pico_pen_x++;\r
543 \r
544         lim_x = (Pico.video.reg[12]&1) ? 319 : 255;\r
545         if (pico_pen_y < 8) pico_pen_y = 8;\r
546         if (pico_pen_y > 224-PICO_PEN_ADJUST_Y) pico_pen_y = 224-PICO_PEN_ADJUST_Y;\r
547         if (pico_pen_x < 0) pico_pen_x = 0;\r
548         if (pico_pen_x > lim_x-PICO_PEN_ADJUST_X) pico_pen_x = lim_x-PICO_PEN_ADJUST_X;\r
549 \r
550         PicoPicohw.pen_pos[0] = pico_pen_x;\r
551         if (!(Pico.video.reg[12]&1)) PicoPicohw.pen_pos[0] += pico_pen_x/4;\r
552         PicoPicohw.pen_pos[0] += 0x3c;\r
553         PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);\r
554 }\r
555 \r
556 static void update_volume(int has_changed, int is_up)\r
557 {\r
558         static int prev_frame = 0, wait_frames = 0;\r
559         int vol = currentConfig.volume;\r
560 \r
561         if (has_changed)\r
562         {\r
563                 if (vol < 5 && (PicoOpt&8) && prev_frame == Pico.m.frame_count - 1 && wait_frames < 12)\r
564                         wait_frames++;\r
565                 else {\r
566                         if (is_up) {\r
567                                 if (vol < 99) vol++;\r
568                         } else {\r
569                                 if (vol >  0) vol--;\r
570                         }\r
571                         wait_frames = 0;\r
572                         gp2x_sound_volume(vol, vol);\r
573                         currentConfig.volume = vol;\r
574                 }\r
575                 sprintf(noticeMsg, "VOL: %02i", vol);\r
576                 gettimeofday(&noticeMsgTime, 0);\r
577                 prev_frame = Pico.m.frame_count;\r
578         }\r
579 \r
580         // set the right mixer func\r
581         if (!(PicoOpt&8)) return; // just use defaults for mono\r
582         if (vol >= 5)\r
583                 PsndMix_32_to_16l = mix_32_to_16l_stereo;\r
584         else {\r
585                 mix_32_to_16l_level = 5 - vol;\r
586                 PsndMix_32_to_16l = mix_32_to_16l_stereo_lvl;\r
587         }\r
588 }\r
589 \r
590 static void RunEvents(unsigned int which)\r
591 {\r
592         if (which & 0x1800) // save or load (but not both)\r
593         {\r
594                 int do_it = 1;\r
595                 if ( emu_checkSaveFile(state_slot) &&\r
596                                 (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) ||   // load\r
597                                  (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) { // save\r
598                         unsigned long keys;\r
599                         blit("", (which & 0x1000) ? "LOAD STATE? (Y=yes, X=no)" : "OVERWRITE SAVE? (Y=yes, X=no)");\r
600                         while ( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) )\r
601                                 usleep(50*1024);\r
602                         if (keys & GP2X_X) do_it = 0;\r
603                         while ( gp2x_joystick_read(1) & (GP2X_X|GP2X_Y) ) // wait for release\r
604                                 usleep(50*1024);\r
605                         clearArea(0);\r
606                 }\r
607                 if (do_it) {\r
608                         osd_text(4, SCREEN_HEIGHT-16, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME");\r
609                         PicoStateProgressCB = emu_state_cb;\r
610                         gp2x_memcpy_all_buffers(gp2x_screen, 0, SCREEN_WIDTH*SCREEN_HEIGHT*2);\r
611                         emu_SaveLoadGame((which & 0x1000) >> 12, 0);\r
612                         PicoStateProgressCB = NULL;\r
613                 }\r
614 \r
615                 reset_timing = 1;\r
616         }\r
617         if (which & 0x0400) // switch renderer\r
618         {\r
619                 if      (  PicoOpt&0x10)             { PicoOpt&=~0x10; currentConfig.EmuOpt |= 0x80; }\r
620                 else if (!(currentConfig.EmuOpt&0x80)) PicoOpt|= 0x10;\r
621                 else   currentConfig.EmuOpt &= ~0x80;\r
622 \r
623                 vidResetMode();\r
624 \r
625                 if (PicoOpt&0x10) {\r
626                         strcpy(noticeMsg, " 8bit fast renderer");\r
627                 } else if (currentConfig.EmuOpt&0x80) {\r
628                         strcpy(noticeMsg, "16bit accurate renderer");\r
629                 } else {\r
630                         strcpy(noticeMsg, " 8bit accurate renderer");\r
631                 }\r
632 \r
633                 gettimeofday(&noticeMsgTime, 0);\r
634         }\r
635         if (which & 0x0300)\r
636         {\r
637                 if(which&0x0200) {\r
638                         state_slot -= 1;\r
639                         if(state_slot < 0) state_slot = 9;\r
640                 } else {\r
641                         state_slot += 1;\r
642                         if(state_slot > 9) state_slot = 0;\r
643                 }\r
644                 sprintf(noticeMsg, "SAVE SLOT %i [%s]", state_slot, emu_checkSaveFile(state_slot) ? "USED" : "FREE");\r
645                 gettimeofday(&noticeMsgTime, 0);\r
646         }\r
647         if (which & 0x0080) {\r
648                 engineState = PGS_Menu;\r
649         }\r
650 }\r
651 \r
652 static void updateKeys(void)\r
653 {\r
654         unsigned int keys, keys2, allActions[2] = { 0, 0 }, events;\r
655         static unsigned int prevEvents = 0;\r
656         int joy, i;\r
657 \r
658         keys = gp2x_joystick_read(0);\r
659         if (keys & GP2X_SELECT) {\r
660                 engineState = select_exits ? PGS_Quit : PGS_Menu;\r
661                 // wait until select is released, so menu would not resume game\r
662                 while (gp2x_joystick_read(1) & GP2X_SELECT) usleep(50*1000);\r
663         }\r
664 \r
665         keys &= CONFIGURABLE_KEYS;\r
666         keys2 = keys;\r
667 \r
668         for (i = 0; i < 32; i++)\r
669         {\r
670                 if (keys2 & (1 << i))\r
671                 {\r
672                         int pl, acts = currentConfig.KeyBinds[i];\r
673                         if (!acts) continue;\r
674                         pl = (acts >> 16) & 1;\r
675                         if (kb_combo_keys & (1 << i))\r
676                         {\r
677                                 int u = i+1, acts_c = acts & kb_combo_acts;\r
678                                 // let's try to find the other one\r
679                                 if (acts_c) {\r
680                                         for (; u < 32; u++)\r
681                                                 if ( (keys2 & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) {\r
682                                                         allActions[pl] |= acts_c & currentConfig.KeyBinds[u];\r
683                                                         keys2 &= ~((1 << i) | (1 << u));\r
684                                                         break;\r
685                                                 }\r
686                                 }\r
687                                 // add non-combo actions if combo ones were not found\r
688                                 if (!acts_c || u == 32)\r
689                                         allActions[pl] |= acts & ~kb_combo_acts;\r
690                         } else {\r
691                                 allActions[pl] |= acts;\r
692                         }\r
693                 }\r
694         }\r
695 \r
696         // add joy inputs\r
697         if (num_of_joys > 0)\r
698         {\r
699                 gp2x_usbjoy_update();\r
700                 for (joy = 0; joy < num_of_joys; joy++) {\r
701                         int btns = gp2x_usbjoy_check2(joy);\r
702                         for (i = 0; i < 32; i++) {\r
703                                 if (btns & (1 << i)) {\r
704                                         int acts = currentConfig.JoyBinds[joy][i];\r
705                                         int pl = (acts >> 16) & 1;\r
706                                         allActions[pl] |= acts;\r
707                                 }\r
708                         }\r
709                 }\r
710         }\r
711 \r
712         PicoPad[0] = allActions[0] & 0xfff;\r
713         PicoPad[1] = allActions[1] & 0xfff;\r
714 \r
715         if (allActions[0] & 0x7000) emu_DoTurbo(&PicoPad[0], allActions[0]);\r
716         if (allActions[1] & 0x7000) emu_DoTurbo(&PicoPad[1], allActions[1]);\r
717 \r
718         events = (allActions[0] | allActions[1]) >> 16;\r
719 \r
720         // volume is treated in special way and triggered every frame\r
721         if (events & 0x6000)\r
722                 update_volume(1, events & 0x2000);\r
723 \r
724         if ((events ^ prevEvents) & 0x40) {\r
725                 emu_changeFastForward(events & 0x40);\r
726                 update_volume(0, 0);\r
727                 reset_timing = 1;\r
728         }\r
729 \r
730         events &= ~prevEvents;\r
731 \r
732         if (PicoAHW == PAHW_PICO)\r
733                 RunEventsPico(events, keys);\r
734         if (events) RunEvents(events);\r
735         if (movie_data) emu_updateMovie();\r
736 \r
737         prevEvents = (allActions[0] | allActions[1]) >> 16;\r
738 }\r
739 \r
740 \r
741 static void updateSound(int len)\r
742 {\r
743         if (PicoOpt&8) len<<=1;\r
744 \r
745         /* avoid writing audio when lagging behind to prevent audio lag */\r
746         if (PicoSkipFrame != 2)\r
747                 gp2x_sound_write(PsndOut, len<<1);\r
748 }\r
749 \r
750 \r
751 static void SkipFrame(int do_audio)\r
752 {\r
753         PicoSkipFrame=do_audio ? 1 : 2;\r
754         PicoFrame();\r
755         PicoSkipFrame=0;\r
756 }\r
757 \r
758 \r
759 void emu_forcedFrame(int opts)\r
760 {\r
761         int po_old = PicoOpt;\r
762         int eo_old = currentConfig.EmuOpt;\r
763 \r
764         PicoOpt &= ~0x10;\r
765         PicoOpt |= opts|POPT_ACC_SPRITES; // acc_sprites\r
766         currentConfig.EmuOpt |= 0x80;\r
767 \r
768         //vidResetMode();\r
769 #ifdef USE_320_SCREEN\r
770         PicoDrawSetColorFormat(1);\r
771         PicoScanBegin = EmuScanBegin16;\r
772 #else\r
773         PicoDrawSetColorFormat(-1);\r
774         PicoScanEnd = EmuScanEnd16;\r
775 #endif\r
776         Pico.m.dirtyPal = 1;\r
777         PicoFrameDrawOnly();\r
778 \r
779 /*\r
780         if (!(Pico.video.reg[12]&1)) {\r
781                 vidCpyM2 = vidCpyM2_32col;\r
782                 clearArea(1);\r
783         } else  vidCpyM2 = vidCpyM2_40col;\r
784 \r
785         vidCpyM2((unsigned char *)gp2x_screen+SCREEN_WIDTH*8, PicoDraw2FB+328*8);\r
786         vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
787         gp2x_video_setpalette(localPal, 0x40);\r
788 */\r
789         PicoOpt = po_old;\r
790         currentConfig.EmuOpt = eo_old;\r
791 }\r
792 \r
793 static void simpleWait(int thissec, int lim_time)\r
794 {\r
795         struct timeval tval;\r
796 \r
797         spend_cycles(1024);\r
798         gettimeofday(&tval, 0);\r
799         if (thissec != tval.tv_sec) tval.tv_usec+=1000000;\r
800 \r
801         while (tval.tv_usec < lim_time)\r
802         {\r
803                 spend_cycles(1024);\r
804                 gettimeofday(&tval, 0);\r
805                 if (thissec != tval.tv_sec) tval.tv_usec+=1000000;\r
806         }\r
807 }\r
808 \r
809 \r
810 void emu_Loop(void)\r
811 {\r
812         static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;\r
813         char fpsbuff[24]; // fps count c string\r
814         struct timeval tval; // timing\r
815         int pframes_done, pframes_shown, pthissec; // "period" frames, used for sync\r
816         int  frames_done,  frames_shown,  thissec; // actual frames\r
817         int oldmodes = 0, target_fps, target_frametime, lim_time, vsync_offset, i;\r
818         char *notice = 0;\r
819 \r
820         printf("entered emu_Loop()\n");\r
821 \r
822         fpsbuff[0] = 0;\r
823 \r
824         // make sure we are in correct mode\r
825         vidResetMode();\r
826         scaling_update();\r
827         Pico.m.dirtyPal = 1;\r
828         oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc;\r
829         emu_findKeyBindCombos();\r
830 \r
831         // pal/ntsc might have changed, reset related stuff\r
832         target_fps = Pico.m.pal ? 50 : 60;\r
833         target_frametime = 1000000/target_fps;\r
834         reset_timing = 1;\r
835 \r
836         // prepare sound stuff\r
837         if (currentConfig.EmuOpt & 4)\r
838         {\r
839                 int snd_excess_add;\r
840                 if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old)\r
841                         PsndRerate(Pico.m.frame_count ? 1 : 0);\r
842 \r
843                 snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;\r
844                 printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",\r
845                         PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal);\r
846                 gp2x_start_sound(PsndRate, 16, (PicoOpt&8)>>3);\r
847                 gp2x_sound_volume(currentConfig.volume, currentConfig.volume);\r
848                 PicoWriteSound = updateSound;\r
849                 update_volume(0, 0);\r
850                 memset(sndBuffer, 0, sizeof(sndBuffer));\r
851                 PsndOut = sndBuffer;\r
852                 PsndRate_old = PsndRate;\r
853                 PicoOpt_old  = PicoOpt;\r
854                 pal_old = Pico.m.pal;\r
855         } else {\r
856                 PsndOut = NULL;\r
857         }\r
858 \r
859         // prepare CD buffer\r
860         if (PicoAHW & PAHW_MCD) PicoCDBufferInit();\r
861 \r
862         // calc vsync offset to sync timing code with vsync\r
863         if (currentConfig.EmuOpt&0x2000) {\r
864                 gettimeofday(&tval, 0);\r
865                 gp2x_video_wait_vsync();\r
866                 gettimeofday(&tval, 0);\r
867                 vsync_offset = tval.tv_usec;\r
868                 while (vsync_offset >= target_frametime)\r
869                         vsync_offset -= target_frametime;\r
870                 if (!vsync_offset) vsync_offset++;\r
871                 printf("vsync_offset: %i\n", vsync_offset);\r
872         } else\r
873                 vsync_offset = 0;\r
874 \r
875         frames_done = frames_shown = thissec =\r
876         pframes_done = pframes_shown = pthissec = 0;\r
877 \r
878         // loop\r
879         while (engineState == PGS_Running)\r
880         {\r
881                 int modes;\r
882 \r
883                 gettimeofday(&tval, 0);\r
884                 if (reset_timing) {\r
885                         reset_timing = 0;\r
886                         pthissec = tval.tv_sec;\r
887                         pframes_shown = pframes_done = tval.tv_usec/target_frametime;\r
888                 }\r
889 \r
890                 // show notice message?\r
891                 if (noticeMsgTime.tv_sec)\r
892                 {\r
893                         static int noticeMsgSum;\r
894                         if((tval.tv_sec*1000000+tval.tv_usec) - (noticeMsgTime.tv_sec*1000000+noticeMsgTime.tv_usec) > 2000000) { // > 2.0 sec\r
895                                 noticeMsgTime.tv_sec = noticeMsgTime.tv_usec = 0;\r
896                                 clearArea(0);\r
897                                 notice = 0;\r
898                         } else {\r
899                                 int sum = noticeMsg[0]+noticeMsg[1]+noticeMsg[2];\r
900                                 if (sum != noticeMsgSum) { clearArea(0); noticeMsgSum = sum; }\r
901                                 notice = noticeMsg;\r
902                         }\r
903                 }\r
904 \r
905                 // check for mode changes\r
906                 modes = ((Pico.video.reg[12]&1)<<2)|(Pico.video.reg[1]&8);\r
907                 if (modes != oldmodes)\r
908                 {\r
909                         int scalex = SCREEN_WIDTH;\r
910                         osd_fps_x = OSD_FPS_X;\r
911                         if (modes & 4) {\r
912                                 vidCpyM2 = vidCpyM2_40col;\r
913                         } else {\r
914                                 if (PicoOpt & 0x100) {\r
915                                         vidCpyM2 = vidCpyM2_32col_nobord;\r
916                                         scalex = 256;\r
917                                         osd_fps_x = OSD_FPS_X - 64;\r
918                                 } else {\r
919                                         vidCpyM2 = vidCpyM2_32col;\r
920                                 }\r
921                         }\r
922                         if (currentConfig.scaling == 2 && !(modes&8)) // want vertical scaling and game is not in 240 line mode\r
923                              gp2x_video_RGB_setscaling(8, scalex, 224);\r
924                         else gp2x_video_RGB_setscaling(0, scalex, 240);\r
925                         oldmodes = modes;\r
926                         clearArea(1);\r
927                 }\r
928 \r
929                 // second changed?\r
930                 if (thissec != tval.tv_sec)\r
931                 {\r
932 #ifdef BENCHMARK\r
933                         static int bench = 0, bench_fps = 0, bench_fps_s = 0, bfp = 0, bf[4];\r
934                         if (++bench == 4) {\r
935                                 bench = 0;\r
936                                 bench_fps_s = bench_fps / 4;\r
937                                 bf[bfp++ & 3] = bench_fps / 4;\r
938                                 bench_fps = 0;\r
939                         }\r
940                         bench_fps += frames_shown;\r
941                         sprintf(fpsbuff, "%3i/%3i/%3i", frames_shown, bench_fps_s, (bf[0]+bf[1]+bf[2]+bf[3])>>2);\r
942                         printf("%s\n", fpsbuff);\r
943 #else\r
944                         if (currentConfig.EmuOpt & 2) {\r
945                                 sprintf(fpsbuff, "%3i/%3i", frames_shown, frames_done);\r
946                                 if (fpsbuff[5] == 0) { fpsbuff[5] = fpsbuff[6] = ' '; fpsbuff[7] = 0; }\r
947                         }\r
948 #endif\r
949                         frames_shown = frames_done = 0;\r
950                         thissec = tval.tv_sec;\r
951                 }\r
952 #ifdef PFRAMES\r
953                 sprintf(fpsbuff, "%i", Pico.m.frame_count);\r
954 #endif\r
955 \r
956                 if (pthissec != tval.tv_sec)\r
957                 {\r
958                         if (PsndOut == 0 && currentConfig.Frameskip >= 0) {\r
959                                 pframes_done = pframes_shown = 0;\r
960                         } else {\r
961                                 // it is quite common for this implementation to leave 1 fame unfinished\r
962                                 // when second changes, but we don't want buffer to starve.\r
963                                 if(PsndOut && pframes_done < target_fps && pframes_done > target_fps-5) {\r
964                                         updateKeys();\r
965                                         SkipFrame(1); pframes_done++;\r
966                                 }\r
967 \r
968                                 pframes_done  -= target_fps; if (pframes_done  < 0) pframes_done  = 0;\r
969                                 pframes_shown -= target_fps; if (pframes_shown < 0) pframes_shown = 0;\r
970                                 if (pframes_shown > pframes_done) pframes_shown = pframes_done;\r
971                         }\r
972                         pthissec = tval.tv_sec;\r
973                 }\r
974 \r
975                 lim_time = (pframes_done+1) * target_frametime + vsync_offset;\r
976                 if (currentConfig.Frameskip >= 0) // frameskip enabled\r
977                 {\r
978                         for(i = 0; i < currentConfig.Frameskip; i++) {\r
979                                 updateKeys();\r
980                                 SkipFrame(1); pframes_done++; frames_done++;\r
981                                 if (PsndOut && !reset_timing) { // do framelimitting if sound is enabled\r
982                                         gettimeofday(&tval, 0);\r
983                                         if (pthissec != tval.tv_sec) tval.tv_usec+=1000000;\r
984                                         if (tval.tv_usec < lim_time) { // we are too fast\r
985                                                 simpleWait(pthissec, lim_time);\r
986                                         }\r
987                                 }\r
988                                 lim_time += target_frametime;\r
989                         }\r
990                 }\r
991                 else if (tval.tv_usec > lim_time) // auto frameskip\r
992                 {\r
993                         // no time left for this frame - skip\r
994                         if (tval.tv_usec - lim_time >= 300000) {\r
995                                 /* something caused a slowdown for us (disk access? cache flush?)\r
996                                  * try to recover by resetting timing... */\r
997                                 reset_timing = 1;\r
998                                 continue;\r
999                         }\r
1000                         updateKeys();\r
1001                         SkipFrame(tval.tv_usec < lim_time+target_frametime*2); pframes_done++; frames_done++;\r
1002                         continue;\r
1003                 }\r
1004 \r
1005                 updateKeys();\r
1006                 PicoFrame();\r
1007 \r
1008                 // check time\r
1009                 gettimeofday(&tval, 0);\r
1010                 if (pthissec != tval.tv_sec) tval.tv_usec+=1000000;\r
1011 \r
1012                 if (currentConfig.Frameskip < 0 && tval.tv_usec - lim_time >= 300000) // slowdown detection\r
1013                         reset_timing = 1;\r
1014 /*              else if (PsndOut != NULL || currentConfig.Frameskip < 0)\r
1015                 {\r
1016                         // sleep or vsync if we are still too fast\r
1017                         // usleep sleeps for ~20ms minimum, so it is not a solution here\r
1018                         if (!reset_timing && tval.tv_usec < lim_time)\r
1019                         {\r
1020                                 // we are too fast\r
1021                                 if (vsync_offset) {\r
1022                                         if (lim_time - tval.tv_usec > target_frametime/2)\r
1023                                                 simpleWait(pthissec, lim_time - target_frametime/4);\r
1024                                         gp2x_video_wait_vsync();\r
1025                                 } else {\r
1026                                         simpleWait(pthissec, lim_time);\r
1027                                 }\r
1028                         }\r
1029                 }\r
1030 */\r
1031                 blit(fpsbuff, notice);\r
1032 \r
1033                 pframes_done++; pframes_shown++;\r
1034                  frames_done++;  frames_shown++;\r
1035         }\r
1036 \r
1037         emu_changeFastForward(0);\r
1038 \r
1039         if (PicoAHW & PAHW_MCD) PicoCDBufferFree();\r
1040 \r
1041         // save SRAM\r
1042         if((currentConfig.EmuOpt & 1) && SRam.changed) {\r
1043                 emu_state_cb("Writing SRAM/BRAM..");\r
1044                 emu_SaveLoadGame(0, 1);\r
1045                 SRam.changed = 0;\r
1046         }\r
1047 \r
1048         // if in 8bit mode, generate 16bit image for menu background\r
1049         if ((PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80))\r
1050                 emu_forcedFrame(POPT_EN_SOFTSCALE);\r
1051 }\r
1052 \r
1053 \r
1054 void emu_ResetGame(void)\r
1055 {\r
1056         PicoReset();\r
1057         reset_timing = 1;\r
1058 }\r
1059 \r