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