#include "../common/arm_utils.h"\r
#include "../common/fonts.h"\r
#include "../common/emu.h"\r
+#include "../common/config.h"\r
#include "cpuctrl.h"\r
\r
#include <Pico/PicoInt.h>\r
#include <Pico/Patch.h>\r
+#include <Pico/sound/mix.h>\r
#include <zlib/zlib.h>\r
\r
//#define PFRAMES\r
\r
extern int crashed_940;\r
\r
-static short sndBuffer[2*44100/50];\r
+static short __attribute__((aligned(4))) sndBuffer[2*44100/50];\r
static struct timeval noticeMsgTime = { 0, 0 }; // when started showing\r
static int osd_fps_x;\r
-static int combo_keys = 0, combo_acts = 0; // keys and actions which need button combos\r
static int gp2x_old_gamma = 100;\r
char noticeMsg[64]; // notice msg to draw\r
unsigned char *PicoDraw2FB = NULL; // temporary buffer for alt renderer\r
}\r
\r
\r
-static void find_combos(void)\r
-{\r
- int act, u;\r
-\r
- // find out which keys and actions are combos\r
- combo_keys = combo_acts = 0;\r
- for (act = 0; act < 32; act++)\r
- {\r
- int keyc = 0, keyc2 = 0;\r
- if (act == 16 || act == 17) continue; // player2 flag\r
- if (act > 17)\r
- {\r
- for (u = 0; u < 32; u++)\r
- if (currentConfig.KeyBinds[u] & (1 << act)) keyc++;\r
- }\r
- else\r
- {\r
- for (u = 0; u < 32; u++)\r
- if ((currentConfig.KeyBinds[u] & 0x30000) == 0 && // pl. 1\r
- (currentConfig.KeyBinds[u] & (1 << act))) keyc++;\r
- for (u = 0; u < 32; u++)\r
- if ((currentConfig.KeyBinds[u] & 0x30000) == 1 && // pl. 2\r
- (currentConfig.KeyBinds[u] & (1 << act))) keyc2++;\r
- if (keyc2 > keyc) keyc = keyc2;\r
- }\r
- if (keyc > 1)\r
- {\r
- // loop again and mark those keys and actions as combo\r
- for (u = 0; u < 32; u++)\r
- {\r
- if (currentConfig.KeyBinds[u] & (1 << act)) {\r
- combo_keys |= 1 << u;\r
- combo_acts |= 1 << act;\r
- }\r
- }\r
- }\r
- }\r
-\r
- // printf("combo keys/acts: %08x %08x\n", combo_keys, combo_acts);\r
-}\r
-\r
-\r
static void scaling_update(void)\r
{\r
PicoOpt &= ~0x4100;\r
}\r
\r
if (!(currentConfig.EmuOpt & 0x20)) {\r
- FILE *f = fopen(PicoConfigFile, "r+b");\r
- if (!f) emu_WriteConfig(0);\r
- else {\r
- // if we already have config, reload it, except last ROM\r
- fseek(f, sizeof(currentConfig.lastRomFile), SEEK_SET);\r
- fread(¤tConfig.EmuOpt, 1, sizeof(currentConfig) - sizeof(currentConfig.lastRomFile), f);\r
- fseek(f, 0, SEEK_SET);\r
- fwrite(¤tConfig, 1, sizeof(currentConfig), f);\r
- fflush(f);\r
- fclose(f);\r
+ config_writelrom(PicoConfigFile);\r
#ifndef NO_SYNC\r
- sync();\r
+ sync();\r
#endif\r
- }\r
}\r
\r
free(PicoDraw2FB);\r
set_gamma(100, 0);\r
}\r
\r
+void emu_prepareDefaultConfig(void)\r
+{\r
+ memset(&defaultConfig, 0, sizeof(defaultConfig));\r
+ defaultConfig.EmuOpt = 0x1d | 0x00700; // | <- ram_tmng, confirm_save, cd_leds\r
+ defaultConfig.s_PicoOpt = 0x0f | 0x20e00; // | <- use_940, cd_pcm, cd_cdda, svp drc\r
+ defaultConfig.s_PsndRate = 44100;\r
+ defaultConfig.s_PicoRegion = 0; // auto\r
+ defaultConfig.s_PicoAutoRgnOrder = 0x184; // US, EU, JP\r
+ defaultConfig.s_PicoCDBuffers = 64;\r
+ defaultConfig.Frameskip = -1; // auto\r
+ defaultConfig.CPUclock = 200;\r
+ defaultConfig.volume = 50;\r
+ defaultConfig.KeyBinds[ 0] = 1<<0; // SACB RLDU\r
+ defaultConfig.KeyBinds[ 4] = 1<<1;\r
+ defaultConfig.KeyBinds[ 2] = 1<<2;\r
+ defaultConfig.KeyBinds[ 6] = 1<<3;\r
+ defaultConfig.KeyBinds[14] = 1<<4;\r
+ defaultConfig.KeyBinds[13] = 1<<5;\r
+ defaultConfig.KeyBinds[12] = 1<<6;\r
+ defaultConfig.KeyBinds[ 8] = 1<<7;\r
+ defaultConfig.KeyBinds[15] = 1<<26; // switch rend\r
+ defaultConfig.KeyBinds[10] = 1<<27; // save state\r
+ defaultConfig.KeyBinds[11] = 1<<28; // load state\r
+ defaultConfig.KeyBinds[23] = 1<<29; // vol up\r
+ defaultConfig.KeyBinds[22] = 1<<30; // vol down\r
+ defaultConfig.gamma = 100;\r
+ defaultConfig.scaling = 0;\r
+}\r
+\r
void emu_setDefaultConfig(void)\r
{\r
- memset(¤tConfig, 0, sizeof(currentConfig));\r
- currentConfig.lastRomFile[0] = 0;\r
- currentConfig.EmuOpt = 0x1f | 0x600; // | confirm_save, cd_leds\r
- currentConfig.PicoOpt = 0x0f | 0xe00; // | use_940, cd_pcm, cd_cdda\r
- currentConfig.PsndRate = 22050; // 44100;\r
- currentConfig.PicoRegion = 0; // auto\r
- currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP\r
- currentConfig.Frameskip = -1; // auto\r
- currentConfig.CPUclock = 200;\r
- currentConfig.volume = 50;\r
- currentConfig.KeyBinds[ 0] = 1<<0; // SACB RLDU\r
- currentConfig.KeyBinds[ 4] = 1<<1;\r
- currentConfig.KeyBinds[ 2] = 1<<2;\r
- currentConfig.KeyBinds[ 6] = 1<<3;\r
- currentConfig.KeyBinds[14] = 1<<4;\r
- currentConfig.KeyBinds[13] = 1<<5;\r
- currentConfig.KeyBinds[12] = 1<<6;\r
- currentConfig.KeyBinds[ 8] = 1<<7;\r
- currentConfig.KeyBinds[15] = 1<<26; // switch rend\r
- currentConfig.KeyBinds[10] = 1<<27; // save state\r
- currentConfig.KeyBinds[11] = 1<<28; // load state\r
- currentConfig.KeyBinds[23] = 1<<29; // vol up\r
- currentConfig.KeyBinds[22] = 1<<30; // vol down\r
- currentConfig.gamma = 100;\r
- currentConfig.PicoCDBuffers = 64;\r
- currentConfig.scaling = 0;\r
+ memcpy(¤tConfig, &defaultConfig, sizeof(currentConfig));\r
+ PicoOpt = currentConfig.s_PicoOpt;\r
+ PsndRate = currentConfig.s_PsndRate;\r
+ PicoRegionOverride = currentConfig.s_PicoRegion;\r
+ PicoAutoRgnOrder = currentConfig.s_PicoAutoRgnOrder;\r
+ PicoCDBuffers = currentConfig.s_PicoCDBuffers;\r
}\r
\r
void osd_text(int x, int y, const char *text)\r
{\r
int emu_opt = currentConfig.EmuOpt;\r
\r
- if (PicoOpt&0x10) {\r
+ if (PicoOpt&0x10)\r
+ {\r
// 8bit fast renderer\r
if (Pico.m.dirtyPal) {\r
Pico.m.dirtyPal = 0;\r
// feed new palette to our device\r
gp2x_video_setpalette(localPal, 0x40);\r
}\r
+ // a hack for VR\r
+ if (PicoRead16Hook == PicoSVPRead16)\r
+ memset32((int *)(PicoDraw2FB+328*8+328*223), 0xe0e0e0e0, 328);\r
+ // do actual copy\r
vidCpyM2((unsigned char *)gp2x_screen+320*8, PicoDraw2FB+328*8);\r
- } else if (!(emu_opt&0x80)) {\r
+ }\r
+ else if (!(emu_opt&0x80))\r
+ {\r
// 8bit accurate renderer\r
if (Pico.m.dirtyPal) {\r
Pico.m.dirtyPal = 0;\r
gettimeofday(¬iceMsgTime, 0);\r
}\r
\r
+static void update_volume(int has_changed, int is_up)\r
+{\r
+ static int prev_frame = 0, wait_frames = 0;\r
+ int vol = currentConfig.volume;\r
+\r
+ if (has_changed)\r
+ {\r
+ if (vol < 5 && (PicoOpt&8) && prev_frame == Pico.m.frame_count - 1 && wait_frames < 12)\r
+ wait_frames++;\r
+ else {\r
+ if (is_up) {\r
+ if (vol < 99) vol++;\r
+ } else {\r
+ if (vol > 0) vol--;\r
+ }\r
+ wait_frames = 0;\r
+ gp2x_sound_volume(vol, vol);\r
+ currentConfig.volume = vol;\r
+ }\r
+ sprintf(noticeMsg, "VOL: %02i", vol);\r
+ gettimeofday(¬iceMsgTime, 0);\r
+ prev_frame = Pico.m.frame_count;\r
+ }\r
+\r
+ // set the right mixer func\r
+ if (!(PicoOpt&8)) return; // just use defaults for mono\r
+ if (vol >= 5)\r
+ PsndMix_32_to_16l = mix_32_to_16l_stereo;\r
+ else {\r
+ mix_32_to_16l_level = 5 - vol;\r
+ PsndMix_32_to_16l = mix_32_to_16l_stereo_lvl;\r
+ }\r
+}\r
+\r
+static void change_fast_forward(int set_on)\r
+{\r
+ static void *set_PsndOut = NULL;\r
+ static int set_Frameskip, set_EmuOpt, is_on = 0;\r
+\r
+ if (set_on && !is_on) {\r
+ set_PsndOut = PsndOut;\r
+ set_Frameskip = currentConfig.Frameskip;\r
+ set_EmuOpt = currentConfig.EmuOpt;\r
+ PsndOut = NULL;\r
+ currentConfig.Frameskip = 8;\r
+ currentConfig.EmuOpt &= ~4;\r
+ is_on = 1;\r
+ }\r
+ else if (!set_on && is_on) {\r
+ PsndOut = set_PsndOut;\r
+ currentConfig.Frameskip = set_Frameskip;\r
+ currentConfig.EmuOpt = set_EmuOpt;\r
+ PsndRerate(1);\r
+ update_volume(0, 0);\r
+ reset_timing = 1;\r
+ is_on = 0;\r
+ }\r
+}\r
+\r
static void RunEvents(unsigned int which)\r
{\r
- if(which & 0x1800) { // save or load (but not both)\r
+ if (which & 0x1800) // save or load (but not both)\r
+ {\r
int do_it = 1;\r
if ( emu_checkSaveFile(state_slot) &&\r
(( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) || // load\r
\r
reset_timing = 1;\r
}\r
- if(which & 0x0400) { // switch renderer\r
+ if (which & 0x0400) // switch renderer\r
+ {\r
if ( PicoOpt&0x10) { PicoOpt&=~0x10; currentConfig.EmuOpt |= 0x80; }\r
else if (!(currentConfig.EmuOpt&0x80)) PicoOpt|= 0x10;\r
else currentConfig.EmuOpt &= ~0x80;\r
\r
gettimeofday(¬iceMsgTime, 0);\r
}\r
- if(which & 0x0300) {\r
+ if (which & 0x0300)\r
+ {\r
if(which&0x0200) {\r
state_slot -= 1;\r
if(state_slot < 0) state_slot = 9;\r
sprintf(noticeMsg, "SAVE SLOT %i [%s]", state_slot, emu_checkSaveFile(state_slot) ? "USED" : "FREE");\r
gettimeofday(¬iceMsgTime, 0);\r
}\r
- if(which & 0x0080) {\r
+ if (which & 0x0080) {\r
engineState = PGS_Menu;\r
}\r
}\r
\r
for (i = 0; i < 32; i++)\r
{\r
- if (keys & (1 << i)) {\r
+ if (keys & (1 << i))\r
+ {\r
int pl, acts = currentConfig.KeyBinds[i];\r
if (!acts) continue;\r
pl = (acts >> 16) & 1;\r
- if (combo_keys & (1 << i)) {\r
- int u = i+1, acts_c = acts & combo_acts;\r
+ if (kb_combo_keys & (1 << i))\r
+ {\r
+ int u, acts_c = acts & kb_combo_acts;\r
// let's try to find the other one\r
- if (acts_c)\r
- for (; u < 32; u++)\r
- if ( (currentConfig.KeyBinds[u] & acts_c) && (keys & (1 << u)) ) {\r
- allActions[pl] |= acts_c;\r
+ if (acts_c) {\r
+ for (u = i + 1; u < 32; u++)\r
+ if ( (keys & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) {\r
+ allActions[pl] |= acts_c & currentConfig.KeyBinds[u];\r
keys &= ~((1 << i) | (1 << u));\r
break;\r
}\r
+ }\r
// add non-combo actions if combo ones were not found\r
if (!acts_c || u == 32)\r
- allActions[pl] |= acts & ~combo_acts;\r
+ allActions[pl] |= acts & ~kb_combo_acts;\r
} else {\r
allActions[pl] |= acts;\r
}\r
events = (allActions[0] | allActions[1]) >> 16;\r
\r
// volume is treated in special way and triggered every frame\r
- if(events & 0x6000) {\r
- int vol = currentConfig.volume;\r
- if (events & 0x2000) {\r
- if (vol < 99) vol++;\r
- } else {\r
- if (vol > 0) vol--;\r
- }\r
- gp2x_sound_volume(vol, vol);\r
- sprintf(noticeMsg, "VOL: %02i", vol);\r
- gettimeofday(¬iceMsgTime, 0);\r
- currentConfig.volume = vol;\r
- }\r
+ if (events & 0x6000)\r
+ update_volume(1, events & 0x2000);\r
+\r
+ if ((events ^ prevEvents) & 0x40)\r
+ change_fast_forward(events & 0x40);\r
\r
events &= ~prevEvents;\r
if (events) RunEvents(events);\r
scaling_update();\r
Pico.m.dirtyPal = 1;\r
oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc;\r
- find_combos();\r
+ emu_findKeyBindCombos();\r
\r
// pal/ntsc might have changed, reset related stuff\r
target_fps = Pico.m.pal ? 50 : 60;\r
reset_timing = 1;\r
\r
// prepare sound stuff\r
- if(currentConfig.EmuOpt & 4) {\r
+ if (currentConfig.EmuOpt & 4)\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
- /* if 940 is turned off, we need it to be put back to sleep */\r
- if (!(PicoOpt&0x200) && ((PicoOpt^PicoOpt_old)&0x200)) {\r
- Reset940(1, 2);\r
- Pause940(1);\r
- }\r
PsndRerate(Pico.m.frame_count ? 1 : 0);\r
}\r
snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;\r
gp2x_start_sound(PsndRate, 16, (PicoOpt&8)>>3);\r
gp2x_sound_volume(currentConfig.volume, currentConfig.volume);\r
PicoWriteSound = updateSound;\r
+ update_volume(0, 0);\r
memset(sndBuffer, 0, sizeof(sndBuffer));\r
PsndOut = sndBuffer;\r
PsndRate_old = PsndRate;\r
PicoOpt_old = PicoOpt;\r
pal_old = Pico.m.pal;\r
} else {\r
- PsndOut = 0;\r
+ PsndOut = NULL;\r
}\r
\r
// prepare CD buffer\r
int modes;\r
\r
gettimeofday(&tval, 0);\r
- if(reset_timing) {\r
+ if (reset_timing) {\r
reset_timing = 0;\r
thissec = tval.tv_sec;\r
frames_shown = frames_done = tval.tv_usec/target_frametime;\r
}\r
\r
// show notice message?\r
- if(noticeMsgTime.tv_sec) {\r
+ if (noticeMsgTime.tv_sec)\r
+ {\r
static int noticeMsgSum;\r
if((tval.tv_sec*1000000+tval.tv_usec) - (noticeMsgTime.tv_sec*1000000+noticeMsgTime.tv_usec) > 2000000) { // > 2.0 sec\r
noticeMsgTime.tv_sec = noticeMsgTime.tv_usec = 0;\r
\r
// check for mode changes\r
modes = ((Pico.video.reg[12]&1)<<2)|(Pico.video.reg[1]&8);\r
- if (modes != oldmodes) {\r
+ if (modes != oldmodes)\r
+ {\r
int scalex = 320;\r
osd_fps_x = OSD_FPS_X;\r
if (modes & 4) {\r
}\r
\r
// second changed?\r
- if(thissec != tval.tv_sec) {\r
+ if (thissec != tval.tv_sec)\r
+ {\r
#ifdef BENCHMARK\r
static int bench = 0, bench_fps = 0, bench_fps_s = 0, bfp = 0, bf[4];\r
- if(++bench == 10) {\r
+ if (++bench == 10) {\r
bench = 0;\r
bench_fps_s = bench_fps;\r
bf[bfp++ & 3] = bench_fps;\r
bench_fps += frames_shown;\r
sprintf(fpsbuff, "%02i/%02i/%02i", frames_shown, bench_fps_s, (bf[0]+bf[1]+bf[2]+bf[3])>>2);\r
#else\r
- if(currentConfig.EmuOpt & 2)\r
+ if (currentConfig.EmuOpt & 2)\r
sprintf(fpsbuff, "%02i/%02i", frames_shown, frames_done);\r
+ if (fpsbuff[5] == 0) { fpsbuff[5] = fpsbuff[6] = ' '; fpsbuff[7] = 0; }\r
#endif\r
thissec = tval.tv_sec;\r
\r
- if(PsndOut == 0 && currentConfig.Frameskip >= 0) {\r
+ if (PsndOut == 0 && currentConfig.Frameskip >= 0) {\r
frames_done = frames_shown = 0;\r
} else {\r
// it is quite common for this implementation to leave 1 fame unfinished\r
for(i = 0; i < currentConfig.Frameskip; i++) {\r
updateKeys();\r
SkipFrame(1); frames_done++;\r
- if (PsndOut) { // do framelimitting if sound is enabled\r
+ if (PsndOut && !reset_timing) { // do framelimitting if sound is enabled\r
gettimeofday(&tval, 0);\r
if(thissec != tval.tv_sec) tval.tv_usec+=1000000;\r
if(tval.tv_usec < lim_time) { // we are too fast\r
{\r
// sleep or vsync if we are still too fast\r
// usleep sleeps for ~20ms minimum, so it is not a solution here\r
- if(tval.tv_usec < lim_time)\r
+ if (!reset_timing && tval.tv_usec < lim_time)\r
{\r
// we are too fast\r
if (vsync_offset) {\r
frames_done++; frames_shown++;\r
}\r
\r
+ change_fast_forward(0);\r
\r
if (PicoMCD & 1) PicoCDBufferFree();\r
\r