X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=gp2x%2Femu.c;h=b1b314eeade50a8b88832a73a0acd3e621887f0e;hb=d2f29611d1379a249c8f3f955ed16a336f9290cd;hp=32450758ee014cc713586453f6d7e50fa6805280;hpb=f71361b521c9c64351ea99ed97627a606c642008;p=libpicofe.git diff --git a/gp2x/emu.c b/gp2x/emu.c index 3245075..b1b314e 100644 --- a/gp2x/emu.c +++ b/gp2x/emu.c @@ -33,28 +33,13 @@ extern int crashed_940; -static short __attribute__((aligned(4))) sndBuffer[2*44100/50]; +static short __attribute__((aligned(4))) sndBuffer[2*(44100+100)/50]; static unsigned char PicoDraw2FB_[(8+320) * (8+240+8)]; unsigned char *PicoDraw2FB = PicoDraw2FB_; -static int osd_fps_x; +static int osd_fps_x, osd_y; extern void *gp2x_screens[4]; -int plat_get_root_dir(char *dst, int len) -{ - extern char **g_argv; - int j; - - strncpy(dst, g_argv[0], len); - len -= 32; // reserve - if (len < 0) len = 0; - dst[len] = 0; - for (j = strlen(dst); j > 0; j--) - if (dst[j] == '/') { dst[j+1] = 0; break; } - - return j + 1; -} - static void scaling_update(void) { @@ -76,19 +61,7 @@ void pemu_prep_defconfig(void) { gp2x_soc_t soc; - memset(&defaultConfig, 0, sizeof(defaultConfig)); - defaultConfig.EmuOpt = 0x9d | EOPT_RAM_TIMINGS|EOPT_CONFIRM_SAVE|EOPT_EN_CD_LEDS; - defaultConfig.s_PicoOpt = 0x0f | POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_SVP_DRC|POPT_ACC_SPRITES; - defaultConfig.s_PsndRate = 44100; - defaultConfig.s_PicoRegion = 0; // auto - defaultConfig.s_PicoAutoRgnOrder = 0x184; // US, EU, JP - defaultConfig.s_PicoCDBuffers = 0; - defaultConfig.Frameskip = -1; // auto defaultConfig.CPUclock = default_cpu_clock; - defaultConfig.volume = 50; - defaultConfig.gamma = 100; - defaultConfig.scaling = 0; - defaultConfig.turbo_rate = 15; soc = soc_detect(); if (soc == SOCID_MMSP2) @@ -97,6 +70,23 @@ void pemu_prep_defconfig(void) defaultConfig.EmuOpt |= EOPT_WIZ_TEAR_FIX|EOPT_SHOW_RTC; } +void pemu_validate_config(void) +{ + gp2x_soc_t soc; + + soc = soc_detect(); + if (soc != SOCID_MMSP2) + PicoOpt &= ~POPT_EXT_FM; + if (soc != SOCID_POLLUX) + currentConfig.EmuOpt &= ~EOPT_WIZ_TEAR_FIX; + + if (currentConfig.gamma < 10 || currentConfig.gamma > 300) + currentConfig.gamma = 100; + + if (currentConfig.CPUclock < 10 || currentConfig.CPUclock > 1024) + currentConfig.CPUclock = default_cpu_clock; +} + static void (*osd_text)(int x, int y, const char *text); static void osd_text8(int x, int y, const char *text) @@ -205,7 +195,7 @@ static void draw_pico_ptr(void) if (!(Pico.video.reg[12]&1) && !(PicoOpt & POPT_DIS_32C_BORDER)) x += 32; - if (EOPT_WIZ_TEAR_FIX) { + if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) { pitch = 240; p += (319 - x) * pitch + y; } else @@ -220,7 +210,6 @@ static void draw_pico_ptr(void) static int EmuScanBegin16(unsigned int num) { - if (!(Pico.video.reg[1]&8)) num += 8; DrawLineDest = (unsigned short *) g_screen_ptr + g_screen_width * num; return 0; @@ -228,7 +217,6 @@ static int EmuScanBegin16(unsigned int num) static int EmuScanBegin8(unsigned int num) { - if (!(Pico.video.reg[1]&8)) num += 8; DrawLineDest = (unsigned char *) g_screen_ptr + g_screen_width * num; return 0; @@ -247,8 +235,6 @@ static int EmuScanEnd16_rot(unsigned int num) { if ((num & 3) != 3) return 0; - if (!(Pico.video.reg[1] & 8)) - num += 8; rotated_blit16(g_screen_ptr, rot_buff, num + 1, !(Pico.video.reg[12] & 1) && !(PicoOpt & POPT_EN_SOFTSCALE)); return 0; @@ -264,31 +250,74 @@ static int EmuScanEnd8_rot(unsigned int num) { if ((num & 3) != 3) return 0; - if (!(Pico.video.reg[1] & 8)) - num += 8; rotated_blit8(g_screen_ptr, rot_buff, num + 1, !(Pico.video.reg[12] & 1)); return 0; } -int localPal[0x100]; -static void (*vidcpyM2)(void *dest, void *src, int m32col, int with_32c_border) = NULL; +static int localPal[0x100]; +static void (*vidcpyM2)(void *dest, void *src, int m32col, int with_32c_border); +static int (*make_local_pal)(int fast_mode); + +static int make_local_pal_md(int fast_mode) +{ + int pallen = 0xc0; + + bgr444_to_rgb32(localPal, Pico.cram); + if (fast_mode) + return 0x40; + + if (Pico.video.reg[0xC] & 8) { // shadow/hilight mode + bgr444_to_rgb32_sh(localPal, Pico.cram); + localPal[0xc0] = 0x0000c000; + localPal[0xd0] = 0x00c00000; + localPal[0xe0] = 0x00000000; // reserved pixels for OSD + localPal[0xf0] = 0x00ffffff; + pallen = 0x100; + } + else if (rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes + bgr444_to_rgb32(localPal+0x40, HighPal); + bgr444_to_rgb32(localPal+0x80, HighPal+0x40); + } + else + memcpy32(localPal+0x80, localPal, 0x40); // for spr prio mess + + return pallen; +} + +static int make_local_pal_sms(int fast_mode) +{ + unsigned short *spal = Pico.cram; + unsigned int *dpal = (void *)localPal; + unsigned int i, t; + + for (i = 0x40; i > 0; i--) { + t = *spal++; + t = ((t & 0x0003) << 22) | ((t & 0x000c) << 12) | ((t & 0x0030) << 2); + t |= t >> 2; + t |= t >> 4; + *dpal++ = t; + } + + return 0x40; +} void pemu_update_display(const char *fps, const char *notice) { int emu_opt = currentConfig.EmuOpt; + int ret; if (PicoOpt & POPT_ALT_RENDERER) { // 8bit fast renderer if (Pico.m.dirtyPal) { Pico.m.dirtyPal = 0; - vidConvCpyRGB32(localPal, Pico.cram, 0x40); + ret = make_local_pal(1); // feed new palette to our device - gp2x_video_setpalette(localPal, 0x40); + gp2x_video_setpalette(localPal, ret); } // a hack for VR - if (PicoRead16Hook == PicoSVPRead16) + if (PicoAHW & PAHW_SVP) memset32((int *)(PicoDraw2FB+328*8+328*223), 0xe0e0e0e0, 328); // do actual copy vidcpyM2(g_screen_ptr, PicoDraw2FB+328*8, @@ -299,45 +328,19 @@ void pemu_update_display(const char *fps, const char *notice) // 8bit accurate renderer if (Pico.m.dirtyPal) { - int pallen = 0xc0; Pico.m.dirtyPal = 0; - if (Pico.video.reg[0xC]&8) // shadow/hilight mode - { - vidConvCpyRGB32(localPal, Pico.cram, 0x40); - vidConvCpyRGB32sh(localPal+0x40, Pico.cram, 0x40); - vidConvCpyRGB32hi(localPal+0x80, Pico.cram, 0x40); - memcpy32(localPal+0xc0, localPal+0x40, 0x40); - pallen = 0x100; - } - else if (rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes - vidConvCpyRGB32(localPal, Pico.cram, 0x40); - vidConvCpyRGB32(localPal+0x40, HighPal, 0x40); - vidConvCpyRGB32(localPal+0x80, HighPal+0x40, 0x40); - } - else { - vidConvCpyRGB32(localPal, Pico.cram, 0x40); - memcpy32(localPal+0x80, localPal, 0x40); // for spr prio mess - } - if (pallen > 0xc0) { - localPal[0xc0] = 0x0000c000; - localPal[0xd0] = 0x00c00000; - localPal[0xe0] = 0x00000000; // reserved pixels for OSD - localPal[0xf0] = 0x00ffffff; - } - gp2x_video_setpalette(localPal, pallen); + ret = make_local_pal(0); + gp2x_video_setpalette(localPal, ret); } } - if (notice || (emu_opt & 2)) { - int h = 232; - if (currentConfig.scaling == EOPT_SCALE_HW_HV && !(Pico.video.reg[1]&8)) - h -= 8; + if (notice || (emu_opt & EOPT_SHOW_FPS)) { if (notice) - osd_text(4, h, notice); + osd_text(4, osd_y, notice); if (emu_opt & 2) - osd_text(osd_fps_x, h, fps); + osd_text(osd_fps_x, osd_y, fps); } - if ((emu_opt & 0x400) && (PicoAHW & PAHW_MCD)) + if ((PicoAHW & PAHW_MCD) && (emu_opt & EOPT_EN_CD_LEDS)) draw_cd_leds(); if (PicoAHW & PAHW_PICO) draw_pico_ptr(); @@ -480,12 +483,19 @@ static void vidResetMode(void) if (currentConfig.scaling == EOPT_SCALE_HW_HV && !(Pico.video.reg[1]&8)) gp2x_video_RGB_setscaling(8, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 224); else gp2x_video_RGB_setscaling(0, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 240); + + // palette converters for 8bit modes + make_local_pal = (PicoAHW & PAHW_SMS) ? make_local_pal_sms : make_local_pal_md; } -void plat_video_toggle_renderer(int is_next, int is_menu) +void plat_video_toggle_renderer(int is_next, int force_16bpp, int is_menu) { + if (force_16bpp) { + PicoOpt &= ~POPT_ALT_RENDERER; + currentConfig.EmuOpt |= EOPT_16BPP; + } /* alt, 16bpp, 8bpp */ - if (PicoOpt & POPT_ALT_RENDERER) { + else if (PicoOpt & POPT_ALT_RENDERER) { PicoOpt &= ~POPT_ALT_RENDERER; if (is_next) currentConfig.EmuOpt |= EOPT_16BPP; @@ -504,6 +514,7 @@ void plat_video_toggle_renderer(int is_next, int is_menu) return; vidResetMode(); + rendstatus_old = -1; if (PicoOpt & POPT_ALT_RENDERER) { emu_status_msg(" 8bit fast renderer"); @@ -614,9 +625,19 @@ void pemu_sound_start(void) int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0; int target_fps = Pico.m.pal ? 50 : 60; int frame_samples, snd_excess_add; + int snd_rate_oss = PsndRate; gp2x_soc_t soc; soc = soc_detect(); + if (soc == SOCID_POLLUX) { + /* POLLUX pain: DPLL1 / mclk_div / bitclk_div / 4 */ + switch (PsndRate) { + case 44100: PsndRate = 44171; break; // 44170.673077 + case 22050: PsndRate = 22086; break; // 22085.336538 + case 11025: PsndRate = 11043; break; // 11042.668269 + default: break; + } + } #define SOUND_RERATE_FLAGS (POPT_EN_FM|POPT_EN_PSG|POPT_EN_STEREO|POPT_EXT_FM|POPT_EN_MCD_CDDA) if (PsndRate != PsndRate_old || Pico.m.pal != pal_old || ((PicoOpt & POPT_EXT_FM) && crashed_940) || @@ -642,7 +663,7 @@ void pemu_sound_start(void) printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n", PsndRate, PsndLen, snd_excess_add, is_stereo, Pico.m.pal); sndout_oss_setvol(currentConfig.volume, currentConfig.volume); - sndout_oss_start(PsndRate, frame_samples, is_stereo); + sndout_oss_start(snd_rate_oss, frame_samples, is_stereo); /* Wiz's sound hardware needs more prebuffer */ if (soc == SOCID_POLLUX) @@ -652,6 +673,13 @@ void pemu_sound_start(void) void pemu_sound_stop(void) { + /* get back from Wiz pain */ + switch (PsndRate) { + case 44171: PsndRate = 44100; break; + case 22086: PsndRate = 22050; break; + case 11043: PsndRate = 11025; break; + default: break; + } } void pemu_sound_wait(void) @@ -683,18 +711,21 @@ void plat_debug_cat(char *str) { } -void pemu_video_mode_change(int is_32col, int is_240_lines) +void emu_video_mode_change(int start_line, int line_count, int is_32cols) { int scalex = 320; osd_fps_x = OSD_FPS_X; - if (is_32col && (PicoOpt & POPT_DIS_32C_BORDER)) { + osd_y = 232; + if (is_32cols && (PicoOpt & POPT_DIS_32C_BORDER)) { scalex = 256; osd_fps_x = OSD_FPS_X - 64; } + /* want vertical scaling and game is not in 240 line mode */ - if (currentConfig.scaling == EOPT_SCALE_HW_HV && !is_240_lines) - gp2x_video_RGB_setscaling(8, scalex, 224); - else + if (currentConfig.scaling == EOPT_SCALE_HW_HV) { + gp2x_video_RGB_setscaling(start_line, scalex, line_count); + osd_y = start_line + line_count - 8; + } else gp2x_video_RGB_setscaling(0, scalex, 240); // clear whole screen in all buffers @@ -807,6 +838,9 @@ void pemu_loop_end(void) int po_old = PicoOpt; int eo_old = currentConfig.EmuOpt; + pemu_sound_stop(); + memset32(g_screen_ptr, 0, 320*240*2/4); + /* do one more frame for menu bg */ PicoOpt &= ~POPT_ALT_RENDERER; PicoOpt |= POPT_EN_SOFTSCALE|POPT_ACC_SPRITES;