X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pandora%2Femu.c;h=8bc76be6c7a2aa707ad3a5301a77a9bd63838f45;hb=13b692eb4ee66fd0c7d4d45bdead750a4defa90e;hp=2d873dfc843bb5968ed6fb92b77c856e294024a4;hpb=36f6fd5afec3bd982c715f6d39d5712dacb237cd;p=libpicofe.git diff --git a/pandora/emu.c b/pandora/emu.c index 2d873df..8bc76be 100644 --- a/pandora/emu.c +++ b/pandora/emu.c @@ -15,18 +15,20 @@ #include #include "../gp2x/emu.h" -#include "../gp2x/usbjoy.h" #include "../gp2x/menu.h" +#include "../gp2x/gp2x.h" #include "../common/arm_utils.h" #include "../common/fonts.h" #include "../common/emu.h" #include "../common/config.h" #include "../common/common.h" +#include "../common/input.h" +#include "../linux/sndout_oss.h" #include "asm_utils.h" -#include -#include -#include +#include +#include +#include #include //#define PFRAMES @@ -101,18 +103,6 @@ void emu_Init(void) } -static void scaling_update(void) -{ - PicoOpt &= ~0x4100; - switch (currentConfig.scaling) { - default: break; // off - case 1: // hw hor - case 2: PicoOpt |= 0x0100; break; // hw hor+vert - case 3: PicoOpt |= 0x4000; break; // sw hor - } -} - - void emu_Deinit(void) { // save SRAM @@ -139,7 +129,7 @@ void emu_prepareDefaultConfig(void) defaultConfig.EmuOpt = 0x8f | 0x00600; // | <- confirm_save, cd_leds defaultConfig.s_PicoOpt = 0x0f | POPT_EXT_FM|POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_SVP_DRC; defaultConfig.s_PicoOpt |= POPT_ACC_SPRITES|POPT_EN_MCD_GFX; - defaultConfig.s_PicoOpt &= ~POPT_EN_SVP_DRC; // crashes :( +// defaultConfig.s_PicoOpt &= ~POPT_EN_SVP_DRC; // crashes :( defaultConfig.EmuOpt &= ~8; // no save gzip defaultConfig.s_PsndRate = 44100; defaultConfig.s_PicoRegion = 0; @@ -294,8 +284,8 @@ static int EmuScanEnd16(unsigned int num) len = 256; } - if (!sh && (rendstatus & PDRAW_ACC_SPRITES)) - mask=0x3f; // accurate sprites, upper bits are priority stuff + if (!sh && (rendstatus & PDRAW_SPR_LO_ON_HI)) + mask=0x3f; // messed sprites, upper bits are priority stuff #if 1 clut_line(pd, ps, pal, (mask<<16) | len); @@ -350,7 +340,7 @@ static void blit(const char *fps, const char *notice) // 8bit accurate renderer if (Pico.m.dirtyPal) { - int pallen = 0x40; + int pallen = 0xc0; Pico.m.dirtyPal = 0; if (Pico.video.reg[0xC]&8) // shadow/hilight mode { @@ -360,13 +350,6 @@ static void blit(const char *fps, const char *notice) memcpy32(localPal+0xc0, localPal+0x40, 0x40); pallen = 0x100; } - else if (rendstatus & PDRAW_ACC_SPRITES) { - vidConvCpyRGB32(localPal, Pico.cram, 0x40); - memcpy32(localPal+0x40, localPal, 0x40); - memcpy32(localPal+0x80, localPal, 0x40); - memcpy32(localPal+0xc0, localPal, 0x40); - pallen = 0x100; - } else if (rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes vidConvCpyRGB32(localPal, Pico.cram, 0x40); vidConvCpyRGB32(localPal+0x40, HighPal, 0x40); @@ -375,6 +358,7 @@ static void blit(const char *fps, const char *notice) } else { vidConvCpyRGB32(localPal, Pico.cram, 0x40); + memcpy32(localPal+0x80, localPal, 0x40); } if (pallen > 0xc0) { localPal[0xc0] = 0x0000c000; @@ -492,6 +476,7 @@ static void emu_msg_tray_open(void) gettimeofday(¬iceMsgTime, 0); } +#if 0 static void RunEventsPico(unsigned int events, unsigned int gp2x_keys) { int ret, px, py, lim_x; @@ -543,6 +528,7 @@ static void RunEventsPico(unsigned int events, unsigned int gp2x_keys) PicoPicohw.pen_pos[0] += 0x3c; PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y); } +#endif static void update_volume(int has_changed, int is_up) { @@ -560,7 +546,7 @@ static void update_volume(int has_changed, int is_up) if (vol > 0) vol--; } wait_frames = 0; - gp2x_sound_volume(vol, vol); + sndout_oss_setvol(vol, vol); currentConfig.volume = vol; } sprintf(noticeMsg, "VOL: %02i", vol); @@ -586,6 +572,7 @@ static void RunEvents(unsigned int which) if ( emu_checkSaveFile(state_slot) && (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) || // load (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) { // save +#if 0 unsigned long keys; blit("", (which & 0x1000) ? "LOAD STATE? (Y=yes, X=no)" : "OVERWRITE SAVE? (Y=yes, X=no)"); while ( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) @@ -594,6 +581,7 @@ static void RunEvents(unsigned int which) while ( gp2x_joystick_read(1) & (GP2X_X|GP2X_Y) ) // wait for release usleep(50*1024); clearArea(0); +#endif } if (do_it) { osd_text(4, SCREEN_HEIGHT-16, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME"); @@ -642,63 +630,11 @@ static void RunEvents(unsigned int which) static void updateKeys(void) { - unsigned int keys, keys2, allActions[2] = { 0, 0 }, events; + unsigned int allActions[2] = { 0, 0 }, events; static unsigned int prevEvents = 0; - int joy, i; - - keys = gp2x_joystick_read(0); - if (keys & GP2X_SELECT) { - engineState = select_exits ? PGS_Quit : PGS_Menu; - // wait until select is released, so menu would not resume game - while (gp2x_joystick_read(1) & GP2X_SELECT) usleep(50*1000); - } - - keys &= CONFIGURABLE_KEYS; - keys2 = keys; - - for (i = 0; i < 32; i++) - { - if (keys2 & (1 << i)) - { - int pl, acts = currentConfig.KeyBinds[i]; - if (!acts) continue; - pl = (acts >> 16) & 1; - if (kb_combo_keys & (1 << i)) - { - int u = i+1, acts_c = acts & kb_combo_acts; - // let's try to find the other one - if (acts_c) { - for (; u < 32; u++) - if ( (keys2 & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) { - allActions[pl] |= acts_c & currentConfig.KeyBinds[u]; - keys2 &= ~((1 << i) | (1 << u)); - break; - } - } - // add non-combo actions if combo ones were not found - if (!acts_c || u == 32) - allActions[pl] |= acts & ~kb_combo_acts; - } else { - allActions[pl] |= acts; - } - } - } - // add joy inputs - if (num_of_joys > 0) - { - gp2x_usbjoy_update(); - for (joy = 0; joy < num_of_joys; joy++) { - int btns = gp2x_usbjoy_check2(joy); - for (i = 0; i < 32; i++) { - if (btns & (1 << i)) { - int acts = currentConfig.JoyBinds[joy][i]; - int pl = (acts >> 16) & 1; - allActions[pl] |= acts; - } - } - } - } + /* FIXME: combos, player2 */ + allActions[0] = in_update(); PicoPad[0] = allActions[0] & 0xfff; PicoPad[1] = allActions[1] & 0xfff; @@ -720,8 +656,10 @@ static void updateKeys(void) events &= ~prevEvents; +/* if (PicoAHW == PAHW_PICO) RunEventsPico(events, keys); +*/ if (events) RunEvents(events); if (movie_data) emu_updateMovie(); @@ -735,7 +673,7 @@ static void updateSound(int len) /* avoid writing audio when lagging behind to prevent audio lag */ if (PicoSkipFrame != 2) - gp2x_sound_write(PsndOut, len<<1); + sndout_oss_write(PsndOut, len<<1); } @@ -781,6 +719,11 @@ void emu_forcedFrame(int opts) currentConfig.EmuOpt = eo_old; } +void emu_platformDebugCat(char *str) +{ + // nothing +} + static void simpleWait(int thissec, int lim_time) { struct timeval tval; @@ -797,10 +740,46 @@ static void simpleWait(int thissec, int lim_time) } } +void emu_startSound(void) +{ + static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0; + int target_fps = Pico.m.pal ? 50 : 60; + + PsndOut = NULL; + + if (currentConfig.EmuOpt & 4) + { + int snd_excess_add; + if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old) + 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; + update_volume(0, 0); + memset(sndBuffer, 0, sizeof(sndBuffer)); + PsndOut = sndBuffer; + PsndRate_old = PsndRate; + PicoOpt_old = PicoOpt; + pal_old = Pico.m.pal; + } +} + +void emu_endSound(void) +{ +} + +/* wait until we can write more sound */ +void emu_waitSound(void) +{ + // don't need to do anything, writes will block by themselves +} void emu_Loop(void) { - static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0; char fpsbuff[24]; // fps count c string struct timeval tval; // timing int pframes_done, pframes_shown, pthissec; // "period" frames, used for sync @@ -814,7 +793,6 @@ void emu_Loop(void) // make sure we are in correct mode vidResetMode(); - scaling_update(); Pico.m.dirtyPal = 1; oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc; emu_findKeyBindCombos(); @@ -824,28 +802,7 @@ void emu_Loop(void) target_frametime = 1000000/target_fps; reset_timing = 1; - // prepare sound stuff - if (currentConfig.EmuOpt & 4) - { - int snd_excess_add; - if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old) - 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); - gp2x_start_sound(PsndRate, 16, (PicoOpt&8)>>3); - gp2x_sound_volume(currentConfig.volume, currentConfig.volume); - PicoWriteSound = updateSound; - update_volume(0, 0); - memset(sndBuffer, 0, sizeof(sndBuffer)); - PsndOut = sndBuffer; - PsndRate_old = PsndRate; - PicoOpt_old = PicoOpt; - pal_old = Pico.m.pal; - } else { - PsndOut = NULL; - } + emu_startSound(); // prepare CD buffer if (PicoAHW & PAHW_MCD) PicoCDBufferInit(); @@ -1002,7 +959,8 @@ void emu_Loop(void) if (currentConfig.Frameskip < 0 && tval.tv_usec - lim_time >= 300000) // slowdown detection reset_timing = 1; -/* else if (PsndOut != NULL || currentConfig.Frameskip < 0) +#if 1 + else if (PsndOut != NULL || currentConfig.Frameskip < 0) { // sleep or vsync if we are still too fast // usleep sleeps for ~20ms minimum, so it is not a solution here @@ -1018,7 +976,7 @@ void emu_Loop(void) } } } -*/ +#endif blit(fpsbuff, notice); pframes_done++; pframes_shown++;