static short sndBuffer[2*44100/50];\r
static char noticeMsg[64]; // notice msg to draw\r
static struct timeval noticeMsgTime = { 0, 0 }; // when started showing\r
-static int reset_timing, osd_fps_x;\r
+static int osd_fps_x;\r
static int combo_keys = 0, combo_acts = 0; // keys and actions which need button combos\r
static int gp2x_old_gamma = 100;\r
static unsigned char *movie_data = NULL;\r
static int movie_size = 0;\r
unsigned char *framebuff = 0; // temporary buffer for alt renderer\r
int state_slot = 0;\r
+int reset_timing = 0;\r
\r
-/*\r
-// tmp\r
-static FILE *logf = NULL;\r
\r
-void pprintf(char *texto, ...)\r
-{\r
- va_list args;\r
-\r
- va_start(args,texto);\r
- vfprintf(logf,texto,args);\r
- va_end(args);\r
- fflush(logf);\r
- sync();\r
-}\r
-*/\r
// utilities\r
static void strlwr(char* string)\r
{\r
}\r
\r
\r
+static void emu_msg_cb(const char *msg);\r
+\r
void emu_Init(void)\r
{\r
// make temp buffer for alt renderer\r
mkdir("cfg", 0777);\r
\r
PicoInit();\r
+ PicoMessage = emu_msg_cb;\r
\r
// logf = fopen("log.txt", "w");\r
}\r
}\r
\r
\r
+void scaling_update(void)\r
+{\r
+ PicoOpt &= ~0x4100;\r
+ switch (currentConfig.scaling) {\r
+ default: break; // off\r
+ case 1: // hw hor\r
+ case 2: PicoOpt |= 0x0100; break; // hw hor+vert\r
+ case 3: PicoOpt |= 0x4000; break; // sw hor\r
+ }\r
+}\r
+\r
+\r
int emu_ReadConfig(int game)\r
{\r
FILE *f;\r
currentConfig.KeyBinds[23] = 1<<29; // vol up\r
currentConfig.KeyBinds[22] = 1<<30; // vol down\r
currentConfig.gamma = 100;\r
+ currentConfig.PicoCDBuffers = 64;\r
+ currentConfig.scaling = 0;\r
strncpy(cfg, PicoConfigFile, 511);\r
cfg[511] = 0;\r
} else {\r
bread = fread(¤tConfig, 1, sizeof(currentConfig), f);\r
fclose(f);\r
}\r
- printf((bread == sizeof(currentConfig)) ? "(ok)\n" : "(failed)\n");\r
+ printf(bread > 0 ? "(ok)\n" : "(failed)\n");\r
\r
PicoOpt = currentConfig.PicoOpt;\r
PsndRate = currentConfig.PsndRate;\r
PicoRegionOverride = currentConfig.PicoRegion;\r
PicoAutoRgnOrder = currentConfig.PicoAutoRgnOrder;\r
+ PicoCDBuffers = currentConfig.PicoCDBuffers;\r
if (PicoOpt & 0x20) {\r
actionNames[ 8] = "Z"; actionNames[ 9] = "Y";\r
actionNames[10] = "X"; actionNames[11] = "MODE";\r
}\r
+ scaling_update();\r
// some sanity checks\r
if (currentConfig.CPUclock < 1 || currentConfig.CPUclock > 4096) currentConfig.CPUclock = 200;\r
if (currentConfig.gamma < 10 || currentConfig.gamma > 300) currentConfig.gamma = 100;\r
currentConfig.KeyBinds[22] = 1<<30; // vol down\r
}\r
\r
- return (bread == sizeof(currentConfig));\r
+ return (bread > 0); // == sizeof(currentConfig));\r
}\r
\r
\r
strncpy(cfg, PicoConfigFile, 511);\r
cfg[511] = 0;\r
} else {\r
- romfname_ext(cfg, "cfg", ".pbcfg");\r
+ romfname_ext(cfg, "cfg/", ".pbcfg");\r
}\r
\r
printf("emu_WriteConfig: %s ", cfg);\r
currentConfig.PsndRate = PsndRate;\r
currentConfig.PicoRegion = PicoRegionOverride;\r
currentConfig.PicoAutoRgnOrder = PicoAutoRgnOrder;\r
+ currentConfig.PicoCDBuffers = PicoCDBuffers;\r
bwrite = fwrite(¤tConfig, 1, sizeof(currentConfig), f);\r
fflush(f);\r
fclose(f);\r
+#ifndef NO_SYNC\r
sync();\r
+#endif\r
}\r
printf((bwrite == sizeof(currentConfig)) ? "(ok)\n" : "(failed)\n");\r
\r
SRam.changed = 0;\r
}\r
\r
- if (!(currentConfig.EmuOpt & 0x20))\r
- emu_WriteConfig(0);\r
+ if (!(currentConfig.EmuOpt & 0x20)) {\r
+ FILE *f = fopen(PicoConfigFile, "r+b");\r
+ if (!f) emu_WriteConfig(0);\r
+ else {\r
+ // if we already have config, reload it, except last ROM\r
+ fseek(f, sizeof(currentConfig.lastRomFile), SEEK_SET);\r
+ fread(¤tConfig.EmuOpt, 1, sizeof(currentConfig) - sizeof(currentConfig.lastRomFile), f);\r
+ fseek(f, 0, SEEK_SET);\r
+ fwrite(¤tConfig, 1, sizeof(currentConfig), f);\r
+ fflush(f);\r
+ fclose(f);\r
+#ifndef NO_SYNC\r
+ sync();\r
+#endif\r
+ }\r
+ }\r
+\r
free(framebuff);\r
\r
PicoExit();\r
}\r
}\r
\r
- if (notice) osd_text(4, 232, notice);\r
- if (emu_opt & 2)\r
- osd_text(osd_fps_x, 232, fps);\r
+ if (notice || (emu_opt & 2)) {\r
+ int h = 232;\r
+ if (currentConfig.scaling == 2 && !(Pico.video.reg[1]&8)) h -= 8;\r
+ if (notice) osd_text(4, h, notice);\r
+ if (emu_opt & 2)\r
+ osd_text(osd_fps_x, h, fps);\r
+ }\r
if ((emu_opt & 0x400) && (PicoMCD & 1))\r
cd_leds();\r
\r
}\r
Pico.m.dirtyPal = 1;\r
// reset scaling\r
- gp2x_video_RGB_setscaling((PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 240);\r
+ if (currentConfig.scaling == 2 && !(Pico.video.reg[1]&8))\r
+ gp2x_video_RGB_setscaling(8, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 224);\r
+ else gp2x_video_RGB_setscaling(0, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 240);\r
}\r
\r
\r
+static void emu_msg_cb(const char *msg)\r
+{\r
+ if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
+ // 8-bit renderers\r
+ gp2x_memset_all_buffers(320*232, 0xe0, 320*8);\r
+ osd_text(4, 232, msg);\r
+ gp2x_memcpy_all_buffers((char *)gp2x_screen+320*232, 320*232, 320*8);\r
+ } else {\r
+ // 16bit accurate renderer\r
+ gp2x_memset_all_buffers(320*232*2, 0, 320*8*2);\r
+ osd_text(4, 232, msg);\r
+ gp2x_memcpy_all_buffers((char *)gp2x_screen+320*232*2, 320*232*2, 320*8*2);\r
+ }\r
+ gettimeofday(¬iceMsgTime, 0);\r
+ noticeMsgTime.tv_sec -= 2;\r
+\r
+ /* assumption: emu_msg_cb gets called only when something slow is about to happen */\r
+ reset_timing = 1;\r
+}\r
+\r
static void emu_state_cb(const char *str)\r
{\r
clearArea(0);\r
{\r
if (PicoOpt&8) len<<=1;\r
\r
- gp2x_sound_write(PsndOut, len<<1);\r
+ /* avoid writing audio when lagging behind to prevent audio lag */\r
+ if (PicoSkipFrame != 2)\r
+ gp2x_sound_write(PsndOut, len<<1);\r
}\r
\r
\r
-static void SkipFrame(int do_sound)\r
+static void SkipFrame(int do_audio)\r
{\r
- void *sndbuff_tmp = 0;\r
- if (PsndOut && !do_sound) {\r
- sndbuff_tmp = PsndOut;\r
- PsndOut = 0;\r
- }\r
-\r
- PicoSkipFrame=1;\r
+ PicoSkipFrame=do_audio ? 1 : 2;\r
PicoFrame();\r
PicoSkipFrame=0;\r
-\r
- if (sndbuff_tmp && !do_sound) {\r
- PsndOut = sndbuff_tmp;\r
- }\r
}\r
\r
\r
\r
PicoOpt |= 0x10;\r
PicoFrameFull();\r
- PicoOpt = po_old;\r
\r
if (!(Pico.video.reg[12]&1)) {\r
vidCpyM2 = vidCpyM2_32col;\r
vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8);\r
vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
gp2x_video_setpalette(localPal, 0x40);\r
+\r
+ PicoOpt = po_old;\r
}\r
\r
static void simpleWait(int thissec, int lim_time)\r
PsndOut = 0;\r
}\r
\r
+ // prepare CD buffer\r
+ if (PicoMCD & 1) PicoCDBufferInit();\r
+\r
// loop?\r
while (engineState == PGS_Running)\r
{\r
vidCpyM2 = vidCpyM2_32col;\r
}\r
}\r
- gp2x_video_RGB_setscaling(scalex, 240);\r
+ if (currentConfig.scaling == 2 && !(modes&8)) // want vertical scaling and game is not in 240 line mode\r
+ gp2x_video_RGB_setscaling(8, scalex, 224);\r
+ else gp2x_video_RGB_setscaling(0, scalex, 240);\r
oldmodes = modes;\r
clearArea(1);\r
}\r
if (frames_shown > frames_done) frames_shown = frames_done;\r
}\r
}\r
-\r
+#if 1\r
+ sprintf(fpsbuff, "%05i", Pico.m.frame_count);\r
+#endif\r
lim_time = (frames_done+1) * target_frametime;\r
if(currentConfig.Frameskip >= 0) { // frameskip enabled\r
for(i = 0; i < currentConfig.Frameskip; i++) {\r
}\r
} else if(tval.tv_usec > lim_time) { // auto frameskip\r
// no time left for this frame - skip\r
+ if (tval.tv_usec - lim_time >= 0x300000) {\r
+ /* something caused a slowdown for us (disk access? cache flush?)\r
+ * try to recover by resetting timing... */\r
+ reset_timing = 1;\r
+ continue;\r
+ }\r
updateKeys();\r
- SkipFrame(tval.tv_usec < lim_time+target_frametime); frames_done++;\r
+ SkipFrame(tval.tv_usec < lim_time+target_frametime*2); frames_done++;\r
continue;\r
}\r
\r
\r
// check time\r
gettimeofday(&tval, 0);\r
- if(thissec != tval.tv_sec) tval.tv_usec+=1000000;\r
+ if (thissec != tval.tv_sec) tval.tv_usec+=1000000;\r
\r
- // sleep if we are still too fast\r
- if(PsndOut != 0 || currentConfig.Frameskip < 0)\r
+ if (currentConfig.Frameskip < 0 && tval.tv_usec - lim_time >= 0x300000) // slowdown detection\r
+ reset_timing = 1;\r
+ else if (PsndOut != NULL || currentConfig.Frameskip < 0)\r
{\r
+ // sleep if we are still too fast\r
// usleep sleeps for ~20ms minimum, so it is not a solution here\r
- gettimeofday(&tval, 0);\r
- if(thissec != tval.tv_sec) tval.tv_usec+=1000000;\r
if(tval.tv_usec < lim_time)\r
{\r
// we are too fast\r
frames_done++; frames_shown++;\r
}\r
\r
+\r
+ if (PicoMCD & 1) PicoCDBufferFree();\r
+\r
// save SRAM\r
if((currentConfig.EmuOpt & 1) && SRam.changed) {\r
osd_text(4, 232, "Writing SRAM/BRAM..");\r
ret = fwrite(sram_data, 1, sram_size, sramFile);\r
ret = (ret != sram_size) ? -1 : 0;\r
fclose(sramFile);\r
+#ifndef NO_SYNC\r
sync();\r
+#endif\r
}\r
}\r
return ret;\r
ret = PmovState(load ? 6 : 5, PmovFile);\r
areaClose(PmovFile);\r
PmovFile = 0;\r
- if (!load) sync();\r
- else Pico.m.dirtyPal=1;\r
+ if (load) Pico.m.dirtyPal=1;\r
+#ifndef NO_SYNC\r
+ else sync();\r
+#endif\r
}\r
else ret = -1;\r
if (!ret)\r