-// (c) Copyright 2006-2008 notaz, All rights reserved.\r
+// (c) Copyright 2006-2009 notaz, All rights reserved.\r
// Free for non-commercial use.\r
\r
// For commercial use, separate licencing terms must be obtained.\r
\r
#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <sys/time.h>\r
-#include <sys/stat.h>\r
-#include <sys/types.h>\r
-#include <linux/limits.h>\r
-#include <ctype.h>\r
#include <unistd.h>\r
\r
-#include <stdarg.h>\r
-\r
-#include "../common/arm_utils.h"\r
-#include "../common/fonts.h"\r
#include "../common/emu.h"\r
#include "../common/menu.h"\r
-#include "../common/config.h"\r
-#include "../common/common.h"\r
-#include "../common/input.h"\r
+#include "../common/plat.h"\r
+#include "../common/arm_utils.h"\r
#include "../linux/sndout_oss.h"\r
+#include "../linux/fbdev.h"\r
#include "asm_utils.h"\r
+#include "version.h"\r
\r
#include <pico/pico_int.h>\r
-#include <pico/patch.h>\r
-#include <pico/sound/mix.h>\r
-#include <zlib/zlib.h>\r
\r
-//#define PFRAMES\r
-#define BENCHMARK\r
//#define USE_320_SCREEN 1\r
\r
-#ifdef BENCHMARK\r
-#define OSD_FPS_X (800-200)\r
-#else\r
-#define OSD_FPS_X (800-120)\r
-#endif\r
-\r
-\r
-int select_exits = 0;\r
\r
static short __attribute__((aligned(4))) sndBuffer[2*44100/50];\r
-static struct timeval noticeMsgTime = { 0, 0 }; // when started showing\r
-static int osd_fps_x;\r
-unsigned char *PicoDraw2FB = NULL; // temporary buffer for alt renderer\r
-int reset_timing = 0;\r
-\r
-#define PICO_PEN_ADJUST_X 4\r
-#define PICO_PEN_ADJUST_Y 2\r
-static int pico_pen_x = 0, pico_pen_y = 240/2;\r
-\r
-static void emu_msg_cb(const char *msg);\r
-static void emu_msg_tray_open(void);\r
-\r
-\r
-void emu_noticeMsgUpdated(void)\r
-{\r
- gettimeofday(¬iceMsgTime, 0);\r
-}\r
-\r
-int emu_getMainDir(char *dst, int len)\r
-{\r
- extern char **g_argv;\r
- int j;\r
-\r
- strncpy(dst, g_argv[0], len);\r
- len -= 32; // reserve\r
- if (len < 0) len = 0;\r
- dst[len] = 0;\r
- for (j = strlen(dst); j > 0; j--)\r
- if (dst[j] == '/') { dst[j+1] = 0; break; }\r
+static unsigned char temp_frame[g_screen_width * g_screen_height * 2];\r
+unsigned char *PicoDraw2FB = temp_frame;\r
+char cpu_clk_name[] = "unused";\r
\r
- return j + 1;\r
-}\r
\r
-void emu_Init(void)\r
+void pemu_prep_defconfig(void)\r
{\r
- // make temp buffer for alt renderer\r
- PicoDraw2FB = malloc((8+320)*(8+240+8));\r
- if (!PicoDraw2FB)\r
- {\r
- printf("PicoDraw2FB == 0\n");\r
- }\r
-\r
- // make dirs for saves, cfgs, etc.\r
- mkdir("mds", 0777);\r
- mkdir("srm", 0777);\r
- mkdir("brm", 0777);\r
- mkdir("cfg", 0777);\r
+ // XXX: move elsewhere\r
+ g_menubg_ptr = temp_frame;\r
\r
- PicoInit();\r
- PicoMessage = emu_msg_cb;\r
- PicoMCDopenTray = emu_msg_tray_open;\r
- PicoMCDcloseTray = menu_loop_tray;\r
+ defaultConfig.EmuOpt |= EOPT_VSYNC;\r
}\r
\r
-\r
-void emu_Deinit(void)\r
+void pemu_validate_config(void)\r
{\r
- // save SRAM\r
- if((currentConfig.EmuOpt & 1) && SRam.changed) {\r
- emu_SaveLoadGame(0, 1);\r
- SRam.changed = 0;\r
- }\r
-\r
- if (!(currentConfig.EmuOpt & 0x20)) {\r
- config_writelrom(PicoConfigFile);\r
-#ifndef NO_SYNC\r
- sync();\r
-#endif\r
- }\r
-\r
- free(PicoDraw2FB);\r
-\r
- PicoExit();\r
}\r
\r
-void emu_prepareDefaultConfig(void)\r
-{\r
- memset(&defaultConfig, 0, sizeof(defaultConfig));\r
- defaultConfig.EmuOpt = 0x8f | 0x00600; // | <- confirm_save, cd_leds\r
- defaultConfig.s_PicoOpt = 0x0f | POPT_EXT_FM|POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_SVP_DRC;\r
- defaultConfig.s_PicoOpt |= POPT_ACC_SPRITES|POPT_EN_MCD_GFX;\r
- defaultConfig.EmuOpt &= ~8; // no save gzip\r
- defaultConfig.s_PsndRate = 44100;\r
- defaultConfig.s_PicoRegion = 0;\r
- defaultConfig.s_PicoAutoRgnOrder = 0x184; // US, EU, JP\r
- defaultConfig.s_PicoCDBuffers = 0;\r
- defaultConfig.Frameskip = 0;\r
- defaultConfig.CPUclock = 200;\r
- defaultConfig.volume = 50;\r
- defaultConfig.scaling = 0;\r
- defaultConfig.turbo_rate = 15;\r
-}\r
-\r
-static void textOut16(int x, int y, const char *text)\r
-{\r
- int i,l,len=strlen(text);\r
- unsigned int *screen = (unsigned int *)((unsigned short *)g_screen_ptr + (x&~1) + y*g_screen_width);\r
-\r
- for (i = 0; i < len; i++)\r
- {\r
- for (l=0;l<16;)\r
- {\r
- unsigned char fd = fontdata8x8[((text[i])*8)+l/2];\r
- unsigned int *d = &screen[l*g_screen_width/2];\r
- if (fd&0x80) d[0]=0xffffffff;\r
- if (fd&0x40) d[1]=0xffffffff;\r
- if (fd&0x20) d[2]=0xffffffff;\r
- if (fd&0x10) d[3]=0xffffffff;\r
- if (fd&0x08) d[4]=0xffffffff;\r
- if (fd&0x04) d[5]=0xffffffff;\r
- if (fd&0x02) d[6]=0xffffffff;\r
- if (fd&0x01) d[7]=0xffffffff;\r
- l++; d = &screen[l*g_screen_width/2];\r
- if (fd&0x80) d[0]=0xffffffff;\r
- if (fd&0x40) d[1]=0xffffffff;\r
- if (fd&0x20) d[2]=0xffffffff;\r
- if (fd&0x10) d[3]=0xffffffff;\r
- if (fd&0x08) d[4]=0xffffffff;\r
- if (fd&0x04) d[5]=0xffffffff;\r
- if (fd&0x02) d[6]=0xffffffff;\r
- if (fd&0x01) d[7]=0xffffffff;\r
- l++;\r
- }\r
- screen += 8;\r
- }\r
-}\r
-\r
-\r
-void osd_text(int x, int y, const char *text)\r
+// FIXME: cleanup\r
+static void osd_text(int x, int y, const char *text)\r
{\r
int len = strlen(text)*8;\r
\r
p = (int *) ((unsigned char *) g_screen_ptr+x+g_screen_width*(y+h));\r
for (i = len; i; i--, p++) *p = 0xe0e0e0e0;\r
}\r
- emu_textOut8(x, y, text);\r
+ emu_text_out8(x, y, text);\r
} else {\r
int *p, i, h;\r
x &= ~1; // align x\r
p = (int *) ((unsigned short *) g_screen_ptr+x+g_screen_width*(y+h));\r
for (i = len; i; i--, p++) *p = 0;//(*p>>2)&0x39e7;\r
}\r
- textOut16(x, y, text);\r
+ text_out16(x, y, text);\r
}\r
}\r
\r
}\r
}\r
\r
-static void draw_pico_ptr(void)\r
-{\r
- unsigned short *p = (unsigned short *)g_screen_ptr;\r
-\r
- // only if pen enabled and for 16bit modes\r
- if (pico_inp_mode == 0 || (PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80)) return;\r
-\r
- if (!(Pico.video.reg[12]&1) && !(PicoOpt&POPT_DIS_32C_BORDER))\r
- p += 32;\r
-\r
- p += g_screen_width * (pico_pen_y + PICO_PEN_ADJUST_Y);\r
- p += pico_pen_x + PICO_PEN_ADJUST_X;\r
- p[0] ^= 0xffff;\r
- p[319] ^= 0xffff;\r
- p[320] ^= 0xffff;\r
- p[321] ^= 0xffff;\r
- p[640] ^= 0xffff;\r
-}\r
-\r
#ifdef USE_320_SCREEN\r
\r
static int EmuScanBegin16(unsigned int num)\r
{\r
- if (!(Pico.video.reg[1]&8)) num += 8;\r
DrawLineDest = (unsigned short *)g_screen_ptr + num*800 + 800/2 - 320/2;\r
//int w = (Pico.video.reg[12]&1) ? 320 : 256;\r
//DrawLineDest = (unsigned short *)g_screen_ptr + num*w;\r
int sh = Pico.video.reg[0xC]&8;\r
int len, mask = 0xff;\r
\r
- if (!(Pico.video.reg[1]&8)) num += 8;\r
pd=(unsigned short *)g_screen_ptr + num*800*2 + 800/2 - 320*2/2;\r
\r
if (Pico.m.dirtyPal)\r
return 0;\r
}\r
\r
-#endif // USE_320_SCREEN\r
-\r
-int localPal[0x100];\r
-static void (*vidCpyM2)(void *dest, void *src) = NULL;\r
-\r
-static void blit(const char *fps, const char *notice)\r
+static int EmuScanEnd16_32x(unsigned int num)\r
{\r
- int emu_opt = currentConfig.EmuOpt;\r
-\r
- if (PicoOpt&0x10)\r
- {\r
- // 8bit fast renderer\r
- if (Pico.m.dirtyPal) {\r
- Pico.m.dirtyPal = 0;\r
- vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
- // feed new palette to our device\r
- // gp2x_video_setpalette(localPal, 0x40);\r
- }\r
- // a hack for VR\r
- if (PicoRead16Hook == PicoSVPRead16)\r
- memset32((int *)(PicoDraw2FB+328*8+328*223), 0xe0e0e0e0, 328);\r
- // do actual copy\r
- vidCpyM2((unsigned char *)g_screen_ptr+g_screen_width*8, PicoDraw2FB+328*8);\r
- }\r
- else if (!(emu_opt&0x80))\r
- {\r
- // 8bit accurate renderer\r
- if (Pico.m.dirtyPal)\r
- {\r
- int pallen = 0xc0;\r
- Pico.m.dirtyPal = 0;\r
- if (Pico.video.reg[0xC]&8) // shadow/hilight mode\r
- {\r
- vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
- vidConvCpyRGB32sh(localPal+0x40, Pico.cram, 0x40);\r
- vidConvCpyRGB32hi(localPal+0x80, Pico.cram, 0x40);\r
- memcpy32(localPal+0xc0, localPal+0x40, 0x40);\r
- pallen = 0x100;\r
- }\r
- else if (rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes\r
- vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
- vidConvCpyRGB32(localPal+0x40, HighPal, 0x40);\r
- vidConvCpyRGB32(localPal+0x80, HighPal+0x40, 0x40);\r
- pallen = 0xc0;\r
- }\r
- else {\r
- vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
- memcpy32(localPal+0x80, localPal, 0x40);\r
- }\r
- if (pallen > 0xc0) {\r
- localPal[0xc0] = 0x0000c000;\r
- localPal[0xd0] = 0x00c00000;\r
- localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
- localPal[0xf0] = 0x00ffffff;\r
- }\r
- // gp2x_video_setpalette(localPal, pallen);\r
- }\r
- }\r
-\r
- if (notice || (emu_opt & 2)) {\r
- int h = g_screen_height-16;\r
- if (currentConfig.scaling == 2 && !(Pico.video.reg[1]&8)) h -= 16;\r
- if (notice) osd_text(4, h, notice);\r
- if (emu_opt & 2)\r
- osd_text(osd_fps_x, h, fps);\r
+ unsigned int *ps;\r
+ unsigned int *pd;\r
+ int len;\r
+\r
+ ps = (unsigned int *)temp_frame;\r
+ pd = (unsigned int *)g_screen_ptr + (num*800*2 + 800/2 - 320*2/2) / 2;\r
+\r
+ for (len = 320/2; len > 0; len--, ps++) {\r
+ unsigned int p, p1;\r
+ p1 = *ps;\r
+ p = p1 << 16;\r
+ p |= p >> 16;\r
+ *pd = pd[800/2] = p;\r
+ pd++;\r
+\r
+ p = p1 >> 16;\r
+ p |= p << 16;\r
+ *pd = pd[800/2] = p;\r
+ pd++;\r
}\r
- if ((emu_opt & 0x400) && (PicoAHW & PAHW_MCD))\r
- draw_cd_leds();\r
- if (PicoAHW & PAHW_PICO)\r
- draw_pico_ptr();\r
\r
- //gp2x_video_wait_vsync();\r
- // gp2x_video_flip();\r
+ return 0;\r
}\r
+#endif // USE_320_SCREEN\r
\r
-\r
-// clears whole screen or just the notice area (in all buffers)\r
-static void clearArea(int full)\r
+void pemu_finalize_frame(const char *fps, const char *notice)\r
{\r
- if (full) memset(g_screen_ptr, 0, g_screen_width*g_screen_height*2);\r
- else memset((short *)g_screen_ptr + g_screen_width * (g_screen_height - 16), 0,\r
- g_screen_width * 16 * 2);\r
+ if (notice || (currentConfig.EmuOpt & EOPT_SHOW_FPS)) {\r
+ if (notice)\r
+ osd_text(4, 464, notice);\r
+ if (currentConfig.EmuOpt & EOPT_SHOW_FPS)\r
+ osd_text(640, 464, fps);\r
+ }\r
+ if ((PicoAHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS))\r
+ draw_cd_leds();\r
}\r
\r
-\r
-static void vidResetMode(void)\r
+void plat_video_toggle_renderer(int is_next, int force_16bpp, int is_menu)\r
{\r
-#if 0\r
- if (PicoOpt&0x10) {\r
- gp2x_video_changemode(8);\r
- } else if (currentConfig.EmuOpt&0x80) {\r
- gp2x_video_changemode(16);\r
-#ifdef USE_320_SCREEN\r
- PicoDrawSetColorFormat(1);\r
- PicoScanBegin = EmuScanBegin16;\r
-#else\r
- PicoDrawSetColorFormat(-1);\r
- PicoScanEnd = EmuScanEnd16;\r
-#endif\r
- } else {\r
- gp2x_video_changemode(8);\r
- PicoDrawSetColorFormat(2);\r
- PicoScanBegin = EmuScanBegin8;\r
- }\r
- if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
- // setup pal for 8-bit modes\r
- localPal[0xc0] = 0x0000c000; // MCD LEDs\r
- localPal[0xd0] = 0x00c00000;\r
- localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
- localPal[0xf0] = 0x00ffffff;\r
- gp2x_video_setpalette(localPal, 0x100);\r
- gp2x_memset_all_buffers(0, 0xe0, 320*240);\r
- gp2x_video_flip();\r
- }\r
- Pico.m.dirtyPal = 1;\r
- // reset scaling\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
-#else\r
-#ifdef USE_320_SCREEN\r
+ // this will auto-select SMS/32X renderers\r
PicoDrawSetColorFormat(1);\r
- PicoScanBegin = EmuScanBegin16;\r
-#else\r
- PicoDrawSetColorFormat(-1);\r
- PicoScanEnd = EmuScanEnd16;\r
-#endif\r
-#endif\r
}\r
\r
-\r
-static void emu_msg_cb(const char *msg)\r
+void plat_video_menu_enter(int is_rom_loaded)\r
{\r
-/*\r
- if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
- // 8-bit renderers\r
- gp2x_memset_all_buffers(g_screen_width*(g_screen_height-16), 0xe0, g_screen_width*16);\r
- osd_text(4, g_screen_height-16, msg);\r
- gp2x_memcpy_all_buffers((char *)g_screen_ptr+g_screen_width*(g_screen_height-16),\r
- g_screen_width*(g_screen_height-16), g_screen_width*16);\r
- } else {\r
- // 16bit accurate renderer\r
- gp2x_memset_all_buffers(g_screen_width*(g_screen_height-16)*2, 0, g_screen_width*16*2);\r
- osd_text(4, g_screen_height-16, msg);\r
- gp2x_memcpy_all_buffers((char *)g_screen_ptr+g_screen_width*(g_screen_height-16)*2,\r
- g_screen_width*(g_screen_height-16)*2, g_screen_width*16*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
+void plat_video_menu_begin(void)\r
{\r
- clearArea(0);\r
- blit("", str);\r
+ memcpy32(g_screen_ptr, g_menubg_ptr, g_screen_width * g_screen_height * 2 / 4);\r
}\r
\r
-static void emu_msg_tray_open(void)\r
+void plat_video_menu_end(void)\r
{\r
- strcpy(noticeMsg, "CD tray opened");\r
- gettimeofday(¬iceMsgTime, 0);\r
+ plat_video_flip();\r
}\r
\r
-#if 0\r
-static void RunEventsPico(unsigned int events, unsigned int gp2x_keys)\r
+void plat_status_msg_clear(void)\r
{\r
- int ret, px, py, lim_x;\r
- static int pdown_frames = 0;\r
+ int s = g_screen_width * g_screen_height * 2;\r
+ int l = g_screen_width * 16 * 2;\r
+ int i;\r
\r
- emu_RunEventsPico(events);\r
-\r
- if (pico_inp_mode == 0) return;\r
-\r
- // for F200\r
- ret = gp2x_touchpad_read(&px, &py);\r
- if (ret >= 0)\r
- {\r
- if (ret > 35000)\r
- {\r
- if (pdown_frames++ > 5)\r
- PicoPad[0] |= 0x20;\r
-\r
- pico_pen_x = px;\r
- pico_pen_y = py;\r
- if (!(Pico.video.reg[12]&1)) {\r
- pico_pen_x -= 32;\r
- if (pico_pen_x < 0) pico_pen_x = 0;\r
- if (pico_pen_x > 248) pico_pen_x = 248;\r
- }\r
- if (pico_pen_y > 224) pico_pen_y = 224;\r
- }\r
- else\r
- pdown_frames = 0;\r
+ for (i = 0; i < fbdev_buffer_count; i++)\r
+ memset32((int *)((char *)fbdev_buffers[i] + s - l), 0, l / 4);\r
+}\r
\r
- //if (ret == 0)\r
- // PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;\r
- }\r
+void plat_status_msg_busy_next(const char *msg)\r
+{\r
+ plat_status_msg_clear();\r
+ pemu_finalize_frame("", msg);\r
+ plat_video_flip();\r
+ emu_status_msg("");\r
+ reset_timing = 1;\r
+}\r
\r
- PicoPad[0] &= ~0x0f; // release UDLR\r
- if (gp2x_keys & GP2X_UP) pico_pen_y--;\r
- if (gp2x_keys & GP2X_DOWN) pico_pen_y++;\r
- if (gp2x_keys & GP2X_LEFT) pico_pen_x--;\r
- if (gp2x_keys & GP2X_RIGHT) pico_pen_x++;\r
-\r
- lim_x = (Pico.video.reg[12]&1) ? 319 : 255;\r
- if (pico_pen_y < 8) pico_pen_y = 8;\r
- if (pico_pen_y > 224-PICO_PEN_ADJUST_Y) pico_pen_y = 224-PICO_PEN_ADJUST_Y;\r
- if (pico_pen_x < 0) pico_pen_x = 0;\r
- if (pico_pen_x > lim_x-PICO_PEN_ADJUST_X) pico_pen_x = lim_x-PICO_PEN_ADJUST_X;\r
-\r
- PicoPicohw.pen_pos[0] = pico_pen_x;\r
- if (!(Pico.video.reg[12]&1)) PicoPicohw.pen_pos[0] += pico_pen_x/4;\r
- PicoPicohw.pen_pos[0] += 0x3c;\r
- PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);\r
+void plat_status_msg_busy_first(const char *msg)\r
+{\r
+// memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);\r
+ plat_status_msg_busy_next(msg);\r
}\r
-#endif\r
\r
-static void update_volume(int has_changed, int is_up)\r
+void plat_update_volume(int has_changed, int is_up)\r
{\r
static int prev_frame = 0, wait_frames = 0;\r
int vol = currentConfig.volume;\r
\r
if (has_changed)\r
{\r
- if (vol < 5 && (PicoOpt&8) && prev_frame == Pico.m.frame_count - 1 && wait_frames < 12)\r
- wait_frames++;\r
- else {\r
- if (is_up) {\r
- if (vol < 99) vol++;\r
- } else {\r
- if (vol > 0) vol--;\r
- }\r
- wait_frames = 0;\r
- sndout_oss_setvol(vol, vol);\r
- currentConfig.volume = vol;\r
- }\r
- sprintf(noticeMsg, "VOL: %02i", vol);\r
- gettimeofday(¬iceMsgTime, 0);\r
- prev_frame = Pico.m.frame_count;\r
- }\r
-\r
- // set the right mixer func\r
- if (!(PicoOpt&8)) return; // just use defaults for mono\r
- if (vol >= 5)\r
- PsndMix_32_to_16l = mix_32_to_16l_stereo;\r
- else {\r
- mix_32_to_16l_level = 5 - vol;\r
- PsndMix_32_to_16l = mix_32_to_16l_stereo_lvl;\r
- }\r
-}\r
-\r
-static void RunEvents(unsigned int which)\r
-{\r
- if (which & 0x1800) // save or load (but not both)\r
- {\r
- int do_it = 1;\r
- if ( emu_checkSaveFile(state_slot) &&\r
- (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) || // load\r
- (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) { // save\r
-#if 0\r
- unsigned long keys;\r
- blit("", (which & 0x1000) ? "LOAD STATE? (Y=yes, X=no)" : "OVERWRITE SAVE? (Y=yes, X=no)");\r
- while ( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) )\r
- usleep(50*1024);\r
- if (keys & GP2X_X) do_it = 0;\r
- while ( gp2x_joystick_read(1) & (GP2X_X|GP2X_Y) ) // wait for release\r
- usleep(50*1024);\r
- clearArea(0);\r
-#endif\r
- }\r
- if (do_it) {\r
- osd_text(4, g_screen_height-16, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME");\r
- PicoStateProgressCB = emu_state_cb;\r
- //gp2x_memcpy_all_buffers(g_screen_ptr, 0, g_screen_width*g_screen_height*2);\r
- emu_SaveLoadGame((which & 0x1000) >> 12, 0);\r
- PicoStateProgressCB = NULL;\r
- }\r
-\r
- reset_timing = 1;\r
- }\r
- if (which & 0x0400) // switch renderer\r
- {\r
- if ( PicoOpt&0x10) { PicoOpt&=~0x10; currentConfig.EmuOpt |= 0x80; }\r
- else if (!(currentConfig.EmuOpt&0x80)) PicoOpt|= 0x10;\r
- else currentConfig.EmuOpt &= ~0x80;\r
-\r
- vidResetMode();\r
-\r
- if (PicoOpt&0x10) {\r
- strcpy(noticeMsg, " 8bit fast renderer");\r
- } else if (currentConfig.EmuOpt&0x80) {\r
- strcpy(noticeMsg, "16bit accurate renderer");\r
- } else {\r
- strcpy(noticeMsg, " 8bit accurate renderer");\r
- }\r
-\r
- gettimeofday(¬iceMsgTime, 0);\r
- }\r
- if (which & 0x0300)\r
- {\r
- if(which&0x0200) {\r
- state_slot -= 1;\r
- if(state_slot < 0) state_slot = 9;\r
+ if (is_up) {\r
+ if (vol < 99) vol++;\r
} else {\r
- state_slot += 1;\r
- if(state_slot > 9) state_slot = 0;\r
+ if (vol > 0) vol--;\r
}\r
- sprintf(noticeMsg, "SAVE SLOT %i [%s]", state_slot, emu_checkSaveFile(state_slot) ? "USED" : "FREE");\r
- gettimeofday(¬iceMsgTime, 0);\r
- }\r
- if (which & 0x0080) {\r
- engineState = PGS_Menu;\r
+ wait_frames = 0;\r
+ sndout_oss_setvol(vol, vol);\r
+ currentConfig.volume = vol;\r
+ emu_status_msg("VOL: %02i", vol);\r
+ prev_frame = Pico.m.frame_count;\r
}\r
}\r
\r
-static void updateKeys(void)\r
-{\r
- unsigned int allActions[2] = { 0, 0 }, events;\r
- static unsigned int prevEvents = 0;\r
-\r
- /* FIXME: combos, player2 */\r
- allActions[0] = in_update();\r
-\r
- PicoPad[0] = allActions[0] & 0xfff;\r
- PicoPad[1] = allActions[1] & 0xfff;\r
-\r
- if (allActions[0] & 0x7000) emu_DoTurbo(&PicoPad[0], allActions[0]);\r
- if (allActions[1] & 0x7000) emu_DoTurbo(&PicoPad[1], allActions[1]);\r
-\r
- events = (allActions[0] | allActions[1]) >> 16;\r
-\r
- // volume is treated in special way and triggered every frame\r
- if (events & 0x6000)\r
- update_volume(1, events & 0x2000);\r
-\r
- if ((events ^ prevEvents) & 0x40) {\r
- emu_changeFastForward(events & 0x40);\r
- update_volume(0, 0);\r
- reset_timing = 1;\r
- }\r
-\r
- events &= ~prevEvents;\r
-\r
-/*\r
- if (PicoAHW == PAHW_PICO)\r
- RunEventsPico(events, keys);\r
-*/\r
- if (events) RunEvents(events);\r
- if (movie_data) emu_updateMovie();\r
-\r
- prevEvents = (allActions[0] | allActions[1]) >> 16;\r
-}\r
-\r
-\r
-static void updateSound(int len)\r
-{\r
- if (PicoOpt&8) len<<=1;\r
-\r
- /* avoid writing audio when lagging behind to prevent audio lag */\r
- if (PicoSkipFrame != 2)\r
- sndout_oss_write(PsndOut, len<<1);\r
-}\r
-\r
-\r
-static void SkipFrame(int do_audio)\r
-{\r
- PicoSkipFrame=do_audio ? 1 : 2;\r
- PicoFrame();\r
- PicoSkipFrame=0;\r
-}\r
-\r
-\r
-void emu_forcedFrame(int opts)\r
+void pemu_forced_frame(int opts)\r
{\r
int po_old = PicoOpt;\r
int eo_old = currentConfig.EmuOpt;\r
PicoOpt |= opts|POPT_ACC_SPRITES; // acc_sprites\r
currentConfig.EmuOpt |= 0x80;\r
\r
- //vidResetMode();\r
-#ifdef USE_320_SCREEN\r
- PicoDrawSetColorFormat(1);\r
- PicoScanBegin = EmuScanBegin16;\r
-#else\r
- PicoDrawSetColorFormat(-1);\r
- PicoScanEnd = EmuScanEnd16;\r
-#endif\r
Pico.m.dirtyPal = 1;\r
PicoFrameDrawOnly();\r
\r
-/*\r
- if (!(Pico.video.reg[12]&1)) {\r
- vidCpyM2 = vidCpyM2_32col;\r
- clearArea(1);\r
- } else vidCpyM2 = vidCpyM2_40col;\r
-\r
- vidCpyM2((unsigned char *)g_screen_ptr+g_screen_width*8, PicoDraw2FB+328*8);\r
- vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
- gp2x_video_setpalette(localPal, 0x40);\r
-*/\r
PicoOpt = po_old;\r
currentConfig.EmuOpt = eo_old;\r
}\r
\r
-void emu_platformDebugCat(char *str)\r
+static void updateSound(int len)\r
{\r
- // nothing\r
-}\r
+ unsigned int t;\r
\r
-static void simpleWait(int thissec, int lim_time)\r
-{\r
- struct timeval tval;\r
+ len <<= 1;\r
+ if (PicoOpt & POPT_EN_STEREO)\r
+ len <<= 1;\r
\r
- spend_cycles(1024);\r
- gettimeofday(&tval, 0);\r
- if (thissec != tval.tv_sec) tval.tv_usec+=1000000;\r
+ // sndout_oss_can_write() not reliable..\r
+ if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len))\r
+ return;\r
\r
- while (tval.tv_usec < lim_time)\r
- {\r
- spend_cycles(1024);\r
- gettimeofday(&tval, 0);\r
- if (thissec != tval.tv_sec) tval.tv_usec+=1000000;\r
- }\r
+ /* avoid writing audio when lagging behind to prevent audio lag */\r
+ if (PicoSkipFrame == 2)\r
+ return;\r
+\r
+ t = plat_get_ticks_ms();\r
+ sndout_oss_write(PsndOut, len);\r
+ t = plat_get_ticks_ms() - t;\r
+ if (t > 1)\r
+ printf("audio lag %u\n", t);\r
}\r
\r
-void emu_startSound(void)\r
+void pemu_sound_start(void)\r
{\r
- static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;\r
int target_fps = Pico.m.pal ? 50 : 60;\r
\r
PsndOut = NULL;\r
\r
- if (currentConfig.EmuOpt & 4)\r
+ if (currentConfig.EmuOpt & EOPT_EN_SOUND)\r
{\r
- int snd_excess_add;\r
- if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old)\r
- PsndRerate(Pico.m.frame_count ? 1 : 0);\r
+ int snd_excess_add, frame_samples;\r
+ int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0;\r
+\r
+ PsndRerate(Pico.m.frame_count ? 1 : 0);\r
+\r
+ frame_samples = PsndLen;\r
+ snd_excess_add = ((PsndRate - PsndLen * target_fps)<<16) / target_fps;\r
+ if (snd_excess_add != 0)\r
+ frame_samples++;\r
\r
- snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;\r
printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",\r
- PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal);\r
- sndout_oss_start(PsndRate, 16, (PicoOpt&8)>>3);\r
- sndout_oss_setvol(currentConfig.volume, currentConfig.volume);\r
+ PsndRate, PsndLen, snd_excess_add, is_stereo, Pico.m.pal);\r
+ sndout_oss_start(PsndRate, frame_samples * 2, is_stereo);\r
+ //sndout_oss_setvol(currentConfig.volume, currentConfig.volume);\r
PicoWriteSound = updateSound;\r
- update_volume(0, 0);\r
+ plat_update_volume(0, 0);\r
memset(sndBuffer, 0, sizeof(sndBuffer));\r
PsndOut = sndBuffer;\r
- PsndRate_old = PsndRate;\r
- PicoOpt_old = PicoOpt;\r
- pal_old = Pico.m.pal;\r
}\r
}\r
\r
-void emu_endSound(void)\r
+void pemu_sound_stop(void)\r
{\r
+ sndout_oss_stop();\r
}\r
\r
-/* wait until we can write more sound */\r
-void emu_waitSound(void)\r
+void pemu_sound_wait(void)\r
{\r
// don't need to do anything, writes will block by themselves\r
}\r
\r
-void emu_Loop(void)\r
+void plat_debug_cat(char *str)\r
{\r
- char fpsbuff[24]; // fps count c string\r
- struct timeval tval; // timing\r
- int pframes_done, pframes_shown, pthissec; // "period" frames, used for sync\r
- int frames_done, frames_shown, thissec; // actual frames\r
- int oldmodes = 0, target_fps, target_frametime, lim_time, vsync_offset, i;\r
- char *notice = 0;\r
-\r
- printf("entered emu_Loop()\n");\r
-\r
- fpsbuff[0] = 0;\r
-\r
- // make sure we are in correct mode\r
- vidResetMode();\r
- Pico.m.dirtyPal = 1;\r
- oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc;\r
-\r
- // pal/ntsc might have changed, reset related stuff\r
- target_fps = Pico.m.pal ? 50 : 60;\r
- target_frametime = 1000000/target_fps;\r
- reset_timing = 1;\r
-\r
- emu_startSound();\r
-\r
- // prepare CD buffer\r
- if (PicoAHW & PAHW_MCD) PicoCDBufferInit();\r
-\r
- // calc vsync offset to sync timing code with vsync\r
- if (currentConfig.EmuOpt&0x2000) {\r
- gettimeofday(&tval, 0);\r
- //gp2x_video_wait_vsync();\r
- gettimeofday(&tval, 0);\r
- vsync_offset = tval.tv_usec;\r
- while (vsync_offset >= target_frametime)\r
- vsync_offset -= target_frametime;\r
- if (!vsync_offset) vsync_offset++;\r
- printf("vsync_offset: %i\n", vsync_offset);\r
- } else\r
- vsync_offset = 0;\r
-\r
- frames_done = frames_shown = thissec =\r
- pframes_done = pframes_shown = pthissec = 0;\r
-\r
- // loop\r
- while (engineState == PGS_Running)\r
- {\r
- int modes;\r
-\r
- gettimeofday(&tval, 0);\r
- if (reset_timing) {\r
- reset_timing = 0;\r
- pthissec = tval.tv_sec;\r
- pframes_shown = pframes_done = tval.tv_usec/target_frametime;\r
- }\r
+}\r
\r
- // show notice message?\r
- if (noticeMsgTime.tv_sec)\r
- {\r
- static int noticeMsgSum;\r
- if((tval.tv_sec*1000000+tval.tv_usec) - (noticeMsgTime.tv_sec*1000000+noticeMsgTime.tv_usec) > 2000000) { // > 2.0 sec\r
- noticeMsgTime.tv_sec = noticeMsgTime.tv_usec = 0;\r
- clearArea(0);\r
- notice = 0;\r
- } else {\r
- int sum = noticeMsg[0]+noticeMsg[1]+noticeMsg[2];\r
- if (sum != noticeMsgSum) { clearArea(0); noticeMsgSum = sum; }\r
- notice = noticeMsg;\r
- }\r
- }\r
+void emu_video_mode_change(int start_line, int line_count, int is_32cols)\r
+{\r
+ int i;\r
\r
- // check for mode changes\r
- modes = ((Pico.video.reg[12]&1)<<2)|(Pico.video.reg[1]&8);\r
- if (modes != oldmodes)\r
- {\r
- int scalex = g_screen_width;\r
- osd_fps_x = OSD_FPS_X;\r
- if (modes & 4) {\r
- vidCpyM2 = vidCpyM2_40col;\r
- } else {\r
- if (PicoOpt & 0x100) {\r
- vidCpyM2 = vidCpyM2_32col_nobord;\r
- scalex = 256;\r
- osd_fps_x = OSD_FPS_X - 64;\r
- } else {\r
- vidCpyM2 = vidCpyM2_32col;\r
- }\r
- }\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
+ // clear whole screen in all buffers\r
+ for (i = 0; i < fbdev_buffer_count; i++)\r
+ memset32(fbdev_buffers[i], 0, g_screen_width * g_screen_height * 2 / 4);\r
\r
- // second changed?\r
- if (thissec != tval.tv_sec)\r
- {\r
-#ifdef BENCHMARK\r
- static int bench = 0, bench_fps = 0, bench_fps_s = 0, bfp = 0, bf[4];\r
- if (++bench == 4) {\r
- bench = 0;\r
- bench_fps_s = bench_fps / 4;\r
- bf[bfp++ & 3] = bench_fps / 4;\r
- bench_fps = 0;\r
- }\r
- bench_fps += frames_shown;\r
- sprintf(fpsbuff, "%3i/%3i/%3i", frames_shown, bench_fps_s, (bf[0]+bf[1]+bf[2]+bf[3])>>2);\r
- printf("%s\n", fpsbuff);\r
+#ifdef USE_320_SCREEN\r
+ PicoDrawSetColorFormat(1);\r
+ PicoScanBegin = EmuScanBegin16;\r
#else\r
- if (currentConfig.EmuOpt & 2) {\r
- sprintf(fpsbuff, "%3i/%3i", frames_shown, frames_done);\r
- if (fpsbuff[5] == 0) { fpsbuff[5] = fpsbuff[6] = ' '; fpsbuff[7] = 0; }\r
- }\r
-#endif\r
- frames_shown = frames_done = 0;\r
- thissec = tval.tv_sec;\r
- }\r
-#ifdef PFRAMES\r
- sprintf(fpsbuff, "%i", Pico.m.frame_count);\r
+ if (PicoAHW & PAHW_32X) {\r
+ DrawLineDest = (unsigned short *)temp_frame;\r
+ PicoDrawSetColorFormat(1);\r
+ PicoScanBegin = NULL;\r
+ PicoScanEnd = EmuScanEnd16_32x;\r
+ } else {\r
+ PicoDrawSetColorFormat(-1);\r
+ PicoScanBegin = NULL;\r
+ PicoScanEnd = EmuScanEnd16;\r
+ }\r
#endif\r
+}\r
\r
- if (pthissec != tval.tv_sec)\r
- {\r
- if (PsndOut == 0 && currentConfig.Frameskip >= 0) {\r
- pframes_done = pframes_shown = 0;\r
- } else {\r
- // it is quite common for this implementation to leave 1 fame unfinished\r
- // when second changes, but we don't want buffer to starve.\r
- if(PsndOut && pframes_done < target_fps && pframes_done > target_fps-5) {\r
- updateKeys();\r
- SkipFrame(1); pframes_done++;\r
- }\r
-\r
- pframes_done -= target_fps; if (pframes_done < 0) pframes_done = 0;\r
- pframes_shown -= target_fps; if (pframes_shown < 0) pframes_shown = 0;\r
- if (pframes_shown > pframes_done) pframes_shown = pframes_done;\r
- }\r
- pthissec = tval.tv_sec;\r
- }\r
-\r
- lim_time = (pframes_done+1) * target_frametime + vsync_offset;\r
- if (currentConfig.Frameskip >= 0) // frameskip enabled\r
- {\r
- for(i = 0; i < currentConfig.Frameskip; i++) {\r
- updateKeys();\r
- SkipFrame(1); pframes_done++; frames_done++;\r
- if (PsndOut && !reset_timing) { // do framelimitting if sound is enabled\r
- gettimeofday(&tval, 0);\r
- if (pthissec != tval.tv_sec) tval.tv_usec+=1000000;\r
- if (tval.tv_usec < lim_time) { // we are too fast\r
- simpleWait(pthissec, lim_time);\r
- }\r
- }\r
- lim_time += target_frametime;\r
- }\r
- }\r
- else if (tval.tv_usec > lim_time) // auto frameskip\r
- {\r
- // no time left for this frame - skip\r
- if (tval.tv_usec - lim_time >= 300000) {\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*2); pframes_done++; frames_done++;\r
- continue;\r
- }\r
-\r
- updateKeys();\r
- PicoFrame();\r
+void pemu_loop_prep(void)\r
+{\r
+ emu_video_mode_change(0, 0, 0);\r
+ pemu_sound_start();\r
+}\r
\r
- // check time\r
- gettimeofday(&tval, 0);\r
- if (pthissec != tval.tv_sec) tval.tv_usec+=1000000;\r
+void pemu_loop_end(void)\r
+{\r
+ int po_old = PicoOpt;\r
+ int eo_old = currentConfig.EmuOpt;\r
\r
- if (currentConfig.Frameskip < 0 && tval.tv_usec - lim_time >= 300000) // slowdown detection\r
- reset_timing = 1;\r
-#if 1\r
- else if (PsndOut != NULL || currentConfig.Frameskip < 0)\r
- {\r
- // sleep or vsync if we are still too fast\r
- // usleep sleeps for ~20ms minimum, so it is not a solution here\r
- if (!reset_timing && tval.tv_usec < lim_time)\r
- {\r
- // we are too fast\r
- if (vsync_offset) {\r
- if (lim_time - tval.tv_usec > target_frametime/2)\r
- simpleWait(pthissec, lim_time - target_frametime/4);\r
- // gp2x_video_wait_vsync();\r
- } else {\r
- simpleWait(pthissec, lim_time);\r
- }\r
- }\r
- }\r
-#endif\r
- blit(fpsbuff, notice);\r
+ pemu_sound_stop();\r
+ memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);\r
\r
- pframes_done++; pframes_shown++;\r
- frames_done++; frames_shown++;\r
- }\r
+ /* do one more frame for menu bg */\r
+ PicoOpt &= ~POPT_ALT_RENDERER;\r
+ PicoOpt |= POPT_EN_SOFTSCALE|POPT_ACC_SPRITES;\r
+ currentConfig.EmuOpt |= EOPT_16BPP;\r
\r
- emu_changeFastForward(0);\r
+ PicoDrawSetColorFormat(1);\r
+ Pico.m.dirtyPal = 1;\r
+ PicoFrame();\r
\r
- if (PicoAHW & PAHW_MCD) PicoCDBufferFree();\r
+ PicoOpt = po_old;\r
+ currentConfig.EmuOpt = eo_old;\r
+}\r
\r
- // save SRAM\r
- if((currentConfig.EmuOpt & 1) && SRam.changed) {\r
- emu_state_cb("Writing SRAM/BRAM..");\r
- emu_SaveLoadGame(0, 1);\r
- SRam.changed = 0;\r
+void plat_wait_till_us(unsigned int us_to)\r
+{\r
+ unsigned int now;\r
+ signed int diff;\r
+\r
+ now = plat_get_ticks_us();\r
+\r
+ // XXX: need to check NOHZ and djw kernel\r
+ diff = (signed int)(us_to - now);\r
+ if (diff > 10000) {\r
+ //printf("sleep %d\n", us_to - now);\r
+ usleep(diff * 15 / 16);\r
+ now = plat_get_ticks_us();\r
+ //printf(" wake %d\n", (signed)(us_to - now));\r
}\r
-\r
- // if in 8bit mode, generate 16bit image for menu background\r
- if ((PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80))\r
- emu_forcedFrame(POPT_EN_SOFTSCALE);\r
+/*\r
+ while ((signed int)(us_to - now) > 512) {\r
+ spend_cycles(1024);\r
+ now = plat_get_ticks_us();\r
+ }\r
+*/\r
}\r
\r
-\r
-void emu_ResetGame(void)\r
+const char *plat_get_credits(void)\r
{\r
- PicoReset();\r
- reset_timing = 1;\r
+ return "PicoDrive v" VERSION " (c) notaz, 2006-2009\n\n\n"\r
+ "Credits:\n"\r
+ "fDave: Cyclone 68000 core,\n"\r
+ " base code of PicoDrive\n"\r
+ "Reesy & FluBBa: DrZ80 core\n"\r
+ "MAME devs: YM2612 and SN76496 cores\n"\r
+ "rlyeh and others: minimal SDK\n"\r
+ "Squidge: mmuhack\n"\r
+ "Dzz: ARM940 sample\n"\r
+ "GnoStiC / Puck2099: USB joy code\n"\r
+ "craigix: GP2X hardware\n"\r
+ "ketchupgun: skin design\n"\r
+ "\n"\r
+ "special thanks (for docs, ideas):\n"\r
+ " Charles MacDonald, Haze,\n"\r
+ " Stephane Dallongeville,\n"\r
+ " Lordus, Exophase, Rokas,\n"\r
+ " Nemesis, Tasco Deluxe";\r
}\r
-\r