\r
extern int crashed_940;\r
\r
-static short __attribute__((aligned(4))) sndBuffer[2*44100/50];\r
+static short __attribute__((aligned(4))) sndBuffer[2*(44100+100)/50];\r
static unsigned char PicoDraw2FB_[(8+320) * (8+240+8)];\r
unsigned char *PicoDraw2FB = PicoDraw2FB_;\r
-static int osd_fps_x;\r
+static int osd_fps_x, osd_y;\r
\r
extern void *gp2x_screens[4];\r
\r
if (!(Pico.video.reg[12]&1) && !(PicoOpt & POPT_DIS_32C_BORDER))\r
x += 32;\r
\r
- if (EOPT_WIZ_TEAR_FIX) {\r
+ if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {\r
pitch = 240;\r
p += (319 - x) * pitch + y;\r
} else\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 + g_screen_width * num;\r
\r
return 0;\r
\r
static int EmuScanBegin8(unsigned int num)\r
{\r
- if (!(Pico.video.reg[1]&8)) num += 8;\r
DrawLineDest = (unsigned char *) g_screen_ptr + g_screen_width * num;\r
\r
return 0;\r
{\r
if ((num & 3) != 3)\r
return 0;\r
- if (!(Pico.video.reg[1] & 8))\r
- num += 8;\r
rotated_blit16(g_screen_ptr, rot_buff, num + 1,\r
!(Pico.video.reg[12] & 1) && !(PicoOpt & POPT_EN_SOFTSCALE));\r
return 0;\r
{\r
if ((num & 3) != 3)\r
return 0;\r
- if (!(Pico.video.reg[1] & 8))\r
- num += 8;\r
rotated_blit8(g_screen_ptr, rot_buff, num + 1,\r
!(Pico.video.reg[12] & 1));\r
return 0;\r
}\r
\r
-int localPal[0x100];\r
-static void (*vidcpyM2)(void *dest, void *src, int m32col, int with_32c_border) = NULL;\r
+static int localPal[0x100];\r
+static void (*vidcpyM2)(void *dest, void *src, int m32col, int with_32c_border);\r
+static int (*make_local_pal)(int fast_mode);\r
+\r
+static int make_local_pal_md(int fast_mode)\r
+{\r
+ int pallen = 0xc0;\r
+\r
+ bgr444_to_rgb32(localPal, Pico.cram);\r
+ if (fast_mode)\r
+ return 0x40;\r
+\r
+ if (Pico.video.reg[0xC] & 8) { // shadow/hilight mode\r
+ bgr444_to_rgb32_sh(localPal, Pico.cram);\r
+ localPal[0xc0] = 0x0000c000;\r
+ localPal[0xd0] = 0x00c00000;\r
+ localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
+ localPal[0xf0] = 0x00ffffff;\r
+ pallen = 0x100;\r
+ }\r
+ else if (rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes\r
+ bgr444_to_rgb32(localPal+0x40, HighPal);\r
+ bgr444_to_rgb32(localPal+0x80, HighPal+0x40);\r
+ }\r
+ else\r
+ memcpy32(localPal+0x80, localPal, 0x40); // for spr prio mess\r
+\r
+ return pallen;\r
+}\r
+\r
+static int make_local_pal_sms(int fast_mode)\r
+{\r
+ unsigned short *spal = Pico.cram;\r
+ unsigned int *dpal = (void *)localPal;\r
+ unsigned int i, t;\r
+\r
+ for (i = 0x40; i > 0; i--) {\r
+ t = *spal++;\r
+ t = ((t & 0x0003) << 22) | ((t & 0x000c) << 12) | ((t & 0x0030) << 2);\r
+ t |= t >> 2;\r
+ t |= t >> 4;\r
+ *dpal++ = t;\r
+ }\r
+\r
+ return 0x40;\r
+}\r
\r
void pemu_update_display(const char *fps, const char *notice)\r
{\r
int emu_opt = currentConfig.EmuOpt;\r
+ int ret;\r
\r
if (PicoOpt & POPT_ALT_RENDERER)\r
{\r
// 8bit fast renderer\r
if (Pico.m.dirtyPal) {\r
Pico.m.dirtyPal = 0;\r
- vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
+ ret = make_local_pal(1);\r
// feed new palette to our device\r
- gp2x_video_setpalette(localPal, 0x40);\r
+ gp2x_video_setpalette(localPal, ret);\r
}\r
// a hack for VR\r
- if (PicoRead16Hook == PicoSVPRead16)\r
+ if (PicoAHW & PAHW_SVP)\r
memset32((int *)(PicoDraw2FB+328*8+328*223), 0xe0e0e0e0, 328);\r
// do actual copy\r
vidcpyM2(g_screen_ptr, PicoDraw2FB+328*8,\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
- }\r
- else {\r
- vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
- memcpy32(localPal+0x80, localPal, 0x40); // for spr prio mess\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
+ ret = make_local_pal(0);\r
+ gp2x_video_setpalette(localPal, ret);\r
}\r
}\r
\r
if (notice || (emu_opt & 2)) {\r
- int h = 232;\r
- if (currentConfig.scaling == EOPT_SCALE_HW_HV && !(Pico.video.reg[1]&8))\r
- h -= 8;\r
if (notice)\r
- osd_text(4, h, notice);\r
+ osd_text(4, osd_y, notice);\r
if (emu_opt & 2)\r
- osd_text(osd_fps_x, h, fps);\r
+ osd_text(osd_fps_x, osd_y, fps);\r
}\r
if ((emu_opt & 0x400) && (PicoAHW & PAHW_MCD))\r
draw_cd_leds();\r
{\r
plat_status_msg_clear();\r
pemu_update_display("", msg);\r
+ emu_status_msg("");\r
\r
/* assumption: msg_busy_next gets called only when\r
* something slow is about to happen */\r
if (currentConfig.scaling == EOPT_SCALE_HW_HV && !(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
+ // palette converters for 8bit modes\r
+ make_local_pal = (PicoAHW & PAHW_SMS) ? make_local_pal_sms : make_local_pal_md;\r
}\r
\r
-void plat_video_toggle_renderer(int is_next, int is_menu)\r
+void plat_video_toggle_renderer(int is_next, int force_16bpp, int is_menu)\r
{\r
+ if (force_16bpp) {\r
+ PicoOpt &= ~POPT_ALT_RENDERER;\r
+ currentConfig.EmuOpt |= EOPT_16BPP;\r
+ }\r
/* alt, 16bpp, 8bpp */\r
- if (PicoOpt & POPT_ALT_RENDERER) {\r
+ else if (PicoOpt & POPT_ALT_RENDERER) {\r
PicoOpt &= ~POPT_ALT_RENDERER;\r
if (is_next)\r
currentConfig.EmuOpt |= EOPT_16BPP;\r
return;\r
\r
vidResetMode();\r
+ rendstatus_old = -1;\r
\r
if (PicoOpt & POPT_ALT_RENDERER) {\r
emu_status_msg(" 8bit fast renderer");\r
prev_frame = Pico.m.frame_count;\r
}\r
\r
- if (need_low_volume)\r
+ if (!need_low_volume)\r
return;\r
\r
/* set the right mixer func */\r
\r
static void updateSound(int len)\r
{\r
+ len <<= 1;\r
if (PicoOpt & POPT_EN_STEREO)\r
len <<= 1;\r
\r
+ if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len))\r
+ return;\r
+\r
/* avoid writing audio when lagging behind to prevent audio lag */\r
if (PicoSkipFrame != 2)\r
- sndout_oss_write(PsndOut, len<<1);\r
+ sndout_oss_write(PsndOut, len);\r
}\r
\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
// prepare sound stuff\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
- ((PicoOpt&0x200) && crashed_940)) {\r
+ int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0;\r
+ int target_fps = Pico.m.pal ? 50 : 60;\r
+ int frame_samples, snd_excess_add;\r
+ int snd_rate_oss = PsndRate;\r
+ gp2x_soc_t soc;\r
+\r
+ soc = soc_detect();\r
+ if (soc == SOCID_POLLUX) {\r
+ /* POLLUX pain: DPLL1 / mclk_div / bitclk_div / 4 */\r
+ switch (PsndRate) {\r
+ case 44100: PsndRate = 44171; break; // 44170.673077\r
+ case 22050: PsndRate = 22086; break; // 22085.336538\r
+ case 11025: PsndRate = 11043; break; // 11042.668269\r
+ default: break;\r
+ }\r
+ }\r
+\r
+ #define SOUND_RERATE_FLAGS (POPT_EN_FM|POPT_EN_PSG|POPT_EN_STEREO|POPT_EXT_FM|POPT_EN_MCD_CDDA)\r
+ if (PsndRate != PsndRate_old || Pico.m.pal != pal_old || ((PicoOpt & POPT_EXT_FM) && crashed_940) ||\r
+ ((PicoOpt ^ PicoOpt_old) & SOUND_RERATE_FLAGS)) {\r
PsndRerate(Pico.m.frame_count ? 1 : 0);\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
- PicoWriteSound = updateSound;\r
- plat_update_volume(0, 0);\r
+\r
memset(sndBuffer, 0, sizeof(sndBuffer));\r
PsndOut = sndBuffer;\r
+ PicoWriteSound = updateSound;\r
PsndRate_old = PsndRate;\r
PicoOpt_old = PicoOpt;\r
pal_old = Pico.m.pal;\r
+ plat_update_volume(0, 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
+ if (soc == SOCID_POLLUX)\r
+ frame_samples *= 2; /* force larger buffer */\r
+\r
+ printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",\r
+ PsndRate, PsndLen, snd_excess_add, is_stereo, Pico.m.pal);\r
+ sndout_oss_setvol(currentConfig.volume, currentConfig.volume);\r
+ sndout_oss_start(snd_rate_oss, frame_samples, is_stereo);\r
+\r
+ /* Wiz's sound hardware needs more prebuffer */\r
+ if (soc == SOCID_POLLUX)\r
+ updateSound(frame_samples);\r
}\r
}\r
\r
void pemu_sound_stop(void)\r
{\r
+ /* get back from Wiz pain */\r
+ switch (PsndRate) {\r
+ case 44171: PsndRate = 44100; break;\r
+ case 22086: PsndRate = 22050; break;\r
+ case 11043: PsndRate = 11025; break;\r
+ default: break;\r
+ }\r
}\r
\r
void pemu_sound_wait(void)\r
{\r
}\r
\r
-void pemu_video_mode_change(int is_32col, int is_240_lines)\r
+void emu_video_mode_change(int start_line, int line_count, int is_32cols)\r
{\r
int scalex = 320;\r
osd_fps_x = OSD_FPS_X;\r
- if (is_32col && (PicoOpt & POPT_DIS_32C_BORDER)) {\r
+ osd_y = 232;\r
+ if (is_32cols && (PicoOpt & POPT_DIS_32C_BORDER)) {\r
scalex = 256;\r
osd_fps_x = OSD_FPS_X - 64;\r
}\r
+\r
/* want vertical scaling and game is not in 240 line mode */\r
- if (currentConfig.scaling == EOPT_SCALE_HW_HV && !is_240_lines)\r
- gp2x_video_RGB_setscaling(8, scalex, 224);\r
- else\r
+ if (currentConfig.scaling == EOPT_SCALE_HW_HV) {\r
+ gp2x_video_RGB_setscaling(start_line, scalex, line_count);\r
+ osd_y = start_line + line_count - 8;\r
+ } else\r
gp2x_video_RGB_setscaling(0, scalex, 240);\r
\r
// clear whole screen in all buffers\r
{\r
static int gp2x_old_clock = -1, EmuOpt_old = 0, pal_old = 0;\r
static int gp2x_old_gamma = 100;\r
+ gp2x_soc_t soc;\r
+\r
+ soc = soc_detect();\r
\r
if ((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_RAM_TIMINGS) {\r
if (currentConfig.EmuOpt & EOPT_RAM_TIMINGS)\r
printf(" done\n");\r
}\r
\r
- if (gp2x_old_gamma != currentConfig.gamma || (EmuOpt_old&0x1000) != (currentConfig.EmuOpt&0x1000)) {\r
- set_lcd_gamma(currentConfig.gamma, !!(currentConfig.EmuOpt&0x1000));\r
+ if (gp2x_old_gamma != currentConfig.gamma || ((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_A_SN_GAMMA)) {\r
+ set_lcd_gamma(currentConfig.gamma, !!(currentConfig.EmuOpt & EOPT_A_SN_GAMMA));\r
gp2x_old_gamma = currentConfig.gamma;\r
printf("updated gamma to %i, A_SN's curve: %i\n", currentConfig.gamma, !!(currentConfig.EmuOpt&0x1000));\r
}\r
\r
- if (((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_PSYNC) || Pico.m.pal != pal_old) {\r
- if (currentConfig.EmuOpt & EOPT_PSYNC)\r
+ if (((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_VSYNC) || Pico.m.pal != pal_old) {\r
+ if ((currentConfig.EmuOpt & EOPT_VSYNC) || soc == SOCID_POLLUX)\r
set_lcd_custom_rate(Pico.m.pal);\r
- else\r
+ else if (EmuOpt_old & EOPT_VSYNC)\r
unset_lcd_custom_rate();\r
}\r
\r
\r
void pemu_loop_end(void)\r
{\r
+ int po_old = PicoOpt;\r
+ int eo_old = currentConfig.EmuOpt;\r
+\r
+ pemu_sound_stop();\r
+ memset32(g_screen_ptr, 0, 320*240*2/4);\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
+ PicoScanBegin = EmuScanBegin16;\r
+ PicoScanEnd = NULL;\r
+ PicoDrawSetColorFormat(1);\r
+ Pico.m.dirtyPal = 1;\r
+ PicoFrame();\r
+\r
+ PicoOpt = po_old;\r
+ currentConfig.EmuOpt = eo_old;\r
}\r
\r
const char *plat_get_credits(void)\r