X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=gp2x%2Femu.c;h=0375a7ff99bc0780635a6511b3c167b21008fe87;hb=8e708f920ffd20b026aed616e58c8c8e94c8fb8d;hp=1fd76657e999aed617256bd9a041933ea322de06;hpb=b3818d1ea48c4eaebc60dbc335133ccf44f95f95;p=libpicofe.git diff --git a/gp2x/emu.c b/gp2x/emu.c index 1fd7665..0375a7f 100644 --- a/gp2x/emu.c +++ b/gp2x/emu.c @@ -21,6 +21,7 @@ #include "../common/arm_utils.h" #include "../common/fonts.h" #include "../common/emu.h" +#include "../common/config.h" #include "cpuctrl.h" #include @@ -47,7 +48,6 @@ extern int crashed_940; static short __attribute__((aligned(4))) sndBuffer[2*44100/50]; static struct timeval noticeMsgTime = { 0, 0 }; // when started showing static int osd_fps_x; -static int combo_keys = 0, combo_acts = 0; // keys and actions which need button combos static int gp2x_old_gamma = 100; char noticeMsg[64]; // notice msg to draw unsigned char *PicoDraw2FB = NULL; // temporary buffer for alt renderer @@ -97,48 +97,6 @@ void emu_Init(void) } -static void find_combos(void) -{ - int act, u; - - // find out which keys and actions are combos - combo_keys = combo_acts = 0; - for (act = 0; act < 32; act++) - { - int keyc = 0, keyc2 = 0; - if (act == 16 || act == 17) continue; // player2 flag - if (act > 17) - { - for (u = 0; u < 32; u++) - if (currentConfig.KeyBinds[u] & (1 << act)) keyc++; - } - else - { - for (u = 0; u < 32; u++) - if ((currentConfig.KeyBinds[u] & 0x30000) == 0 && // pl. 1 - (currentConfig.KeyBinds[u] & (1 << act))) keyc++; - for (u = 0; u < 32; u++) - if ((currentConfig.KeyBinds[u] & 0x30000) == 1 && // pl. 2 - (currentConfig.KeyBinds[u] & (1 << act))) keyc2++; - if (keyc2 > keyc) keyc = keyc2; - } - if (keyc > 1) - { - // loop again and mark those keys and actions as combo - for (u = 0; u < 32; u++) - { - if (currentConfig.KeyBinds[u] & (1 << act)) { - combo_keys |= 1 << u; - combo_acts |= 1 << act; - } - } - } - } - - // printf("combo keys/acts: %08x %08x\n", combo_keys, combo_acts); -} - - static void scaling_update(void) { PicoOpt &= ~0x4100; @@ -160,20 +118,10 @@ void emu_Deinit(void) } if (!(currentConfig.EmuOpt & 0x20)) { - FILE *f = fopen(PicoConfigFile, "r+b"); - if (!f) emu_WriteConfig(0); - else { - // if we already have config, reload it, except last ROM - fseek(f, sizeof(currentConfig.lastRomFile), SEEK_SET); - fread(¤tConfig.EmuOpt, 1, sizeof(currentConfig) - sizeof(currentConfig.lastRomFile), f); - fseek(f, 0, SEEK_SET); - fwrite(¤tConfig, 1, sizeof(currentConfig), f); - fflush(f); - fclose(f); + config_writelrom(PicoConfigFile); #ifndef NO_SYNC - sync(); + sync(); #endif - } } free(PicoDraw2FB); @@ -185,34 +133,43 @@ void emu_Deinit(void) set_gamma(100, 0); } +void emu_prepareDefaultConfig(void) +{ + memset(&defaultConfig, 0, sizeof(defaultConfig)); + defaultConfig.EmuOpt = 0x1d | 0x00700; // | <- ram_tmng, confirm_save, cd_leds + defaultConfig.s_PicoOpt = 0x0f | 0x20e00; // | <- use_940, cd_pcm, cd_cdda, svp drc + defaultConfig.s_PsndRate = 44100; + defaultConfig.s_PicoRegion = 0; // auto + defaultConfig.s_PicoAutoRgnOrder = 0x184; // US, EU, JP + defaultConfig.s_PicoCDBuffers = 64; + defaultConfig.Frameskip = -1; // auto + defaultConfig.CPUclock = 200; + defaultConfig.volume = 50; + defaultConfig.KeyBinds[ 0] = 1<<0; // SACB RLDU + defaultConfig.KeyBinds[ 4] = 1<<1; + defaultConfig.KeyBinds[ 2] = 1<<2; + defaultConfig.KeyBinds[ 6] = 1<<3; + defaultConfig.KeyBinds[14] = 1<<4; + defaultConfig.KeyBinds[13] = 1<<5; + defaultConfig.KeyBinds[12] = 1<<6; + defaultConfig.KeyBinds[ 8] = 1<<7; + defaultConfig.KeyBinds[15] = 1<<26; // switch rend + defaultConfig.KeyBinds[10] = 1<<27; // save state + defaultConfig.KeyBinds[11] = 1<<28; // load state + defaultConfig.KeyBinds[23] = 1<<29; // vol up + defaultConfig.KeyBinds[22] = 1<<30; // vol down + defaultConfig.gamma = 100; + defaultConfig.scaling = 0; +} + void emu_setDefaultConfig(void) { - memset(¤tConfig, 0, sizeof(currentConfig)); - currentConfig.lastRomFile[0] = 0; - currentConfig.EmuOpt = 0x1f | 0x600; // | confirm_save, cd_leds - currentConfig.PicoOpt = 0x0f | 0xe00; // | use_940, cd_pcm, cd_cdda - currentConfig.PsndRate = 22050; // 44100; - currentConfig.PicoRegion = 0; // auto - currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP - currentConfig.Frameskip = -1; // auto - currentConfig.CPUclock = 200; - currentConfig.volume = 50; - currentConfig.KeyBinds[ 0] = 1<<0; // SACB RLDU - currentConfig.KeyBinds[ 4] = 1<<1; - currentConfig.KeyBinds[ 2] = 1<<2; - currentConfig.KeyBinds[ 6] = 1<<3; - currentConfig.KeyBinds[14] = 1<<4; - currentConfig.KeyBinds[13] = 1<<5; - currentConfig.KeyBinds[12] = 1<<6; - currentConfig.KeyBinds[ 8] = 1<<7; - currentConfig.KeyBinds[15] = 1<<26; // switch rend - currentConfig.KeyBinds[10] = 1<<27; // save state - currentConfig.KeyBinds[11] = 1<<28; // load state - currentConfig.KeyBinds[23] = 1<<29; // vol up - currentConfig.KeyBinds[22] = 1<<30; // vol down - currentConfig.gamma = 100; - currentConfig.PicoCDBuffers = 64; - currentConfig.scaling = 0; + memcpy(¤tConfig, &defaultConfig, sizeof(currentConfig)); + PicoOpt = currentConfig.s_PicoOpt; + PsndRate = currentConfig.s_PsndRate; + PicoRegionOverride = currentConfig.s_PicoRegion; + PicoAutoRgnOrder = currentConfig.s_PicoAutoRgnOrder; + PicoCDBuffers = currentConfig.s_PicoCDBuffers; } void osd_text(int x, int y, const char *text) @@ -577,23 +534,26 @@ static void updateKeys(void) for (i = 0; i < 32; i++) { - if (keys & (1 << i)) { + if (keys & (1 << i)) + { int pl, acts = currentConfig.KeyBinds[i]; if (!acts) continue; pl = (acts >> 16) & 1; - if (combo_keys & (1 << i)) { - int u = i+1, acts_c = acts & combo_acts; + if (kb_combo_keys & (1 << i)) + { + int u, acts_c = acts & kb_combo_acts; // let's try to find the other one - if (acts_c) - for (; u < 32; u++) - if ( (currentConfig.KeyBinds[u] & acts_c) && (keys & (1 << u)) ) { - allActions[pl] |= acts_c; + if (acts_c) { + for (u = i + 1; u < 32; u++) + if ( (keys & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) { + allActions[pl] |= acts_c & currentConfig.KeyBinds[u]; keys &= ~((1 << i) | (1 << u)); break; } + } // add non-combo actions if combo ones were not found if (!acts_c || u == 32) - allActions[pl] |= acts & ~combo_acts; + allActions[pl] |= acts & ~kb_combo_acts; } else { allActions[pl] |= acts; } @@ -740,7 +700,7 @@ void emu_Loop(void) scaling_update(); Pico.m.dirtyPal = 1; oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc; - find_combos(); + emu_findKeyBindCombos(); // pal/ntsc might have changed, reset related stuff target_fps = Pico.m.pal ? 50 : 60;