@ (c) Copyright 2007, Grazvydas "notaz" Ignotas
+.text
+.align 4
+
@ this assumes src is word aligned
.global mix_16h_to_32 @ int *dest, short *src, int count
ldmfd sp!, {r4-r8,lr}
bx lr
+
+
+.data
+.align 4
+
+.global mix_32_to_16l_level
+mix_32_to_16l_level:
+ .word 0
+
+.text
+.align 4
+
+@ same as mix_32_to_16l_stereo, but with additional shift
+.global mix_32_to_16l_stereo_lvl @ short *dest, int *src, int count
+
+mix_32_to_16l_stereo_lvl:
+ stmfd sp!, {r4-r9,lr}
+
+ ldr r9, =mix_32_to_16l_level
+ mov lr, #1
+ ldr r9, [r9]
+
+ mov r2, r2, lsl #1
+ subs r2, r2, #4
+ bmi m32_16l_st_l_end
+
+m32_16l_st_l_loop:
+ ldmia r0, {r8,r12}
+ ldmia r1!, {r4-r7}
+ mov r8, r8, lsl #16
+ mov r12,r12,lsl #16
+ add r4, r4, r8, asr #16
+ add r5, r5, r8, asr #16
+ add r6, r6, r12,asr #16
+ add r7, r7, r12,asr #16
+ mov r4, r4, asr r9
+ mov r5, r5, asr r9
+ mov r6, r6, asr r9
+ mov r7, r7, asr r9
+ Limitsh r4
+ Limitsh r5
+ Limitsh r6
+ Limitsh r7
+ subs r2, r2, #4
+ orr r4, r5, r4, lsr #16
+ orr r5, r7, r6, lsr #16
+ stmia r0!, {r4,r5}
+ bpl m32_16l_st_l_loop
+
+m32_16l_st_l_end:
+ @ check for remaining bytes to convert
+ tst r2, #2
+ beq m32_16l_st_l_no_unal2
+ ldrsh r6, [r0]
+ ldmia r1!,{r4,r5}
+ add r4, r4, r6
+ add r5, r5, r6
+ mov r4, r4, asr r9
+ mov r5, r5, asr r9
+ Limitsh r4
+ Limitsh r5
+ orr r4, r5, r4, lsr #16
+ str r4, [r0], #4
+
+m32_16l_st_l_no_unal2:
+ ldmfd sp!, {r4-r9,lr}
+ bx lr
+
+
\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
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
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