\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
combo_keys = combo_acts = 0;\r
for (act = 0; act < 32; act++)\r
{\r
- int keyc = 0;\r
+ int keyc = 0, keyc2 = 0;\r
if (act == 16 || act == 17) continue; // player2 flag\r
- for (u = 0; u < 32; u++)\r
+ if (act > 17)\r
{\r
- if (currentConfig.KeyBinds[u] & (1 << act)) keyc++;\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
}\r
}\r
}\r
+\r
// printf("combo keys/acts: %08x %08x\n", combo_keys, combo_acts);\r
}\r
\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
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
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
- sound_rerate(Pico.m.frame_count ? 1 : 0);\r
+ PsndRerate(Pico.m.frame_count ? 1 : 0);\r
}\r
snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;\r
printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",\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