X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fgp2x%2Femu.c;h=c608f32f41766ebbef1390339b2ddadab6fa2251;hb=4010330cc00a358d301caccf8aac6dd02bf8cad5;hp=372ce56fe1d148c6412f6d0e82dc1998c225caca;hpb=b24e0f6ce6e8a59ba43597520709ca79fa36ff8e;p=picodrive.git diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index 372ce56..c608f32 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -33,7 +33,7 @@ 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; @@ -205,7 +205,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 @@ -409,6 +409,7 @@ void plat_status_msg_busy_next(const char *msg) { plat_status_msg_clear(); pemu_update_display("", msg); + emu_status_msg(""); /* assumption: msg_busy_next gets called only when * something slow is about to happen */ @@ -575,7 +576,7 @@ void plat_update_volume(int has_changed, int is_up) prev_frame = Pico.m.frame_count; } - if (need_low_volume) + if (!need_low_volume) return; /* set the right mixer func */ @@ -589,46 +590,85 @@ void plat_update_volume(int has_changed, int is_up) static void updateSound(int len) { + len <<= 1; if (PicoOpt & POPT_EN_STEREO) len <<= 1; + if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len)) + return; + /* avoid writing audio when lagging behind to prevent audio lag */ if (PicoSkipFrame != 2) - sndout_oss_write(PsndOut, len<<1); + sndout_oss_write(PsndOut, len); } void pemu_sound_start(void) { static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0; - int target_fps = Pico.m.pal ? 50 : 60; PsndOut = NULL; // prepare sound stuff - if (currentConfig.EmuOpt & 4) + if (currentConfig.EmuOpt & EOPT_EN_SOUND) { - int snd_excess_add; - if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old || - ((PicoOpt&0x200) && crashed_940)) { + 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) || + ((PicoOpt ^ PicoOpt_old) & SOUND_RERATE_FLAGS)) { PsndRerate(Pico.m.frame_count ? 1 : 0); } - snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps; - printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n", - PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal); - sndout_oss_start(PsndRate, 16, (PicoOpt&8)>>3); - sndout_oss_setvol(currentConfig.volume, currentConfig.volume); - PicoWriteSound = updateSound; - plat_update_volume(0, 0); + memset(sndBuffer, 0, sizeof(sndBuffer)); PsndOut = sndBuffer; + PicoWriteSound = updateSound; PsndRate_old = PsndRate; PicoOpt_old = PicoOpt; pal_old = Pico.m.pal; + plat_update_volume(0, 0); + + frame_samples = PsndLen; + snd_excess_add = ((PsndRate - PsndLen * target_fps)<<16) / target_fps; + if (snd_excess_add != 0) + frame_samples++; + if (soc == SOCID_POLLUX) + frame_samples *= 2; /* force larger buffer */ + + 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(snd_rate_oss, frame_samples, is_stereo); + + /* Wiz's sound hardware needs more prebuffer */ + if (soc == SOCID_POLLUX) + updateSound(frame_samples); } } 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) @@ -733,6 +773,9 @@ void pemu_loop_prep(void) { static int gp2x_old_clock = -1, EmuOpt_old = 0, pal_old = 0; static int gp2x_old_gamma = 100; + gp2x_soc_t soc; + + soc = soc_detect(); if ((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_RAM_TIMINGS) { if (currentConfig.EmuOpt & EOPT_RAM_TIMINGS) @@ -750,16 +793,16 @@ void pemu_loop_prep(void) printf(" done\n"); } - if (gp2x_old_gamma != currentConfig.gamma || (EmuOpt_old&0x1000) != (currentConfig.EmuOpt&0x1000)) { - set_lcd_gamma(currentConfig.gamma, !!(currentConfig.EmuOpt&0x1000)); + if (gp2x_old_gamma != currentConfig.gamma || ((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_A_SN_GAMMA)) { + set_lcd_gamma(currentConfig.gamma, !!(currentConfig.EmuOpt & EOPT_A_SN_GAMMA)); gp2x_old_gamma = currentConfig.gamma; printf("updated gamma to %i, A_SN's curve: %i\n", currentConfig.gamma, !!(currentConfig.EmuOpt&0x1000)); } - if (((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_PSYNC) || Pico.m.pal != pal_old) { - if (currentConfig.EmuOpt & EOPT_PSYNC) + if (((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_VSYNC) || Pico.m.pal != pal_old) { + if ((currentConfig.EmuOpt & EOPT_VSYNC) || soc == SOCID_POLLUX) set_lcd_custom_rate(Pico.m.pal); - else + else if (EmuOpt_old & EOPT_VSYNC) unset_lcd_custom_rate(); } @@ -778,6 +821,24 @@ void pemu_loop_prep(void) void pemu_loop_end(void) { + int po_old = PicoOpt; + int eo_old = currentConfig.EmuOpt; + + pemu_sound_stop(); + + /* do one more frame for menu bg */ + PicoOpt &= ~POPT_ALT_RENDERER; + PicoOpt |= POPT_EN_SOFTSCALE|POPT_ACC_SPRITES; + currentConfig.EmuOpt |= EOPT_16BPP; + + PicoScanBegin = EmuScanBegin16; + PicoScanEnd = NULL; + PicoDrawSetColorFormat(1); + Pico.m.dirtyPal = 1; + PicoFrame(); + + PicoOpt = po_old; + currentConfig.EmuOpt = eo_old; } const char *plat_get_credits(void)