aboutsummaryrefslogtreecommitdiff
path: root/source/nds/entry.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/nds/entry.cpp')
-rw-r--r--source/nds/entry.cpp162
1 files changed, 105 insertions, 57 deletions
diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp
index 727986e..14c6243 100644
--- a/source/nds/entry.cpp
+++ b/source/nds/entry.cpp
@@ -734,6 +734,14 @@ void S9xSyncSpeed ()
{
do {
S9xProcessSound (0);
+#ifdef ACCUMULATE_JOYPAD
+/*
+ * This call allows NDSSFC to synchronise the DS controller more often.
+ * If porting a later version of Snes9x into NDSSFC, it is essential to
+ * preserve it.
+ */
+ NDSSFCAccumulateJoypad ();
+#endif
syncdif = sync_next - getSysTime();
} while (syncdif > 0);
}
@@ -767,6 +775,14 @@ void S9xSyncSpeed ()
{
do {
S9xProcessSound (0);
+#ifdef ACCUMULATE_JOYPAD
+/*
+ * This call allows NDSSFC to synchronise the DS controller more often.
+ * If porting a later version of Snes9x into NDSSFC, it is essential to
+ * preserve it.
+ */
+ NDSSFCAccumulateJoypad ();
+#endif
syncdif = sync_next - getSysTime();
} while (syncdif > 0);
// After that little delay, what time is it?
@@ -968,17 +984,17 @@ void S9xProcessSound (unsigned int)
if (!game_enable_audio)
return;
- if(ds2_checkAudiobuff() > AUDIO_BUFFER_COUNT * 3/4)
- {
- LastSoundEmissionTime++;
- return;
- }
-
- unsigned short *audiobuff;
-
unsigned int Now = getSysTime();
if (Now - LastSoundEmissionTime >= SOUND_EMISSION_INTERVAL)
{
+ if(ds2_checkAudiobuff() > AUDIO_BUFFER_COUNT * 3/4)
+ {
+ LastSoundEmissionTime++;
+ return;
+ }
+
+ unsigned short *audiobuff;
+
if (Now - LastSoundEmissionTime >= 11719 /* 500 milliseconds */)
{
LastSoundEmissionTime = Now;
@@ -1003,9 +1019,14 @@ void S9xProcessSound (unsigned int)
}
#endif
- do {
+ audiobuff = (unsigned short*)ds2_getAudiobuff();
+ while (audiobuff == NULL) //There are audio queue in sending or wait to send
+ {
+#ifdef ACCUMULATE_JOYPAD
+ NDSSFCAccumulateJoypad ();
+#endif
audiobuff = (unsigned short*)ds2_getAudiobuff();
- } while (audiobuff == NULL); //There are audio queue in sending or wait to send
+ }
/* If we need more audio samples */
if (so.samples_mixed_so_far < sample_count)
@@ -1141,72 +1162,99 @@ const unsigned int keymap[12] = {
static bool8 SoundToggleWasHeld = FALSE;
-unsigned int S9xReadJoypad (int which1)
-{
- struct key_buf inputdata;
+#ifdef ACCUMULATE_JOYPAD
+// These are kept as DS key bitfields until it's time to send them to Snes9x.
+static uint32 PreviousControls = 0x00000000;
+static uint32 ControlsPressed = 0x00000000;
+static uint32 ControlsReleased = 0x00000000;
+void NDSSFCAccumulateJoypad ()
+{
+ struct key_buf inputdata;
ds2_getrawInput(&inputdata);
- if (inputdata.key & KEY_LID)
+ ControlsPressed |= inputdata.key & ~PreviousControls;
+ ControlsReleased |= PreviousControls & ~inputdata.key;
+}
+#endif // ACCUMULATE_JOYPAD
+
+uint32 S9xReadJoypad (int which1)
+{
+ if(which1 < 1)
{
- LowFrequencyCPU();
- ds2_setSupend();
- do {
+ uint32 Controls;
+#ifdef ACCUMULATE_JOYPAD
+ Controls = (PreviousControls | ControlsPressed) & ~ControlsReleased;
+ PreviousControls = Controls;
+ ControlsPressed = ControlsReleased = 0x00000000;
+#else
+ {
+ struct key_buf inputdata;
ds2_getrawInput(&inputdata);
- mdelay(1);
- } while (inputdata.key & KEY_LID);
- ds2_wakeup();
- // Before starting to emulate again, turn off the lower
- // screen's backlight.
- mdelay(100); // needed to avoid ds2_setBacklight crashing
- ds2_setBacklight(2);
- GameFrequencyCPU();
- }
- u32 HotkeyReturnToMenu = game_config.HotkeyReturnToMenu != 0 ? game_config.HotkeyReturnToMenu : emu_config.HotkeyReturnToMenu;
- u32 HotkeyTemporaryFastForward = game_config.HotkeyTemporaryFastForward != 0 ? game_config.HotkeyTemporaryFastForward : emu_config.HotkeyTemporaryFastForward;
- u32 HotkeyToggleSound = game_config.HotkeyToggleSound != 0 ? game_config.HotkeyToggleSound : emu_config.HotkeyToggleSound;
+ Controls = inputdata.key;
+ }
+#endif
- if(inputdata.key & KEY_TOUCH ||
- (HotkeyReturnToMenu && ((inputdata.key & HotkeyReturnToMenu) == HotkeyReturnToMenu))
- ) //Active menu
- Settings.Paused = 1;
+ if (Controls & KEY_LID)
+ {
+ LowFrequencyCPU();
+ ds2_setSupend();
+ struct key_buf inputdata;
+ do {
+ ds2_getrawInput(&inputdata);
+ mdelay(1);
+ } while (inputdata.key & KEY_LID);
+ ds2_wakeup();
+ // Before starting to emulate again, turn off the lower
+ // screen's backlight.
+ mdelay(100); // needed to avoid ds2_setBacklight crashing
+ ds2_setBacklight(2);
+ GameFrequencyCPU();
+ }
- temporary_fast_forward =
- (HotkeyTemporaryFastForward && ((inputdata.key & HotkeyTemporaryFastForward) == HotkeyTemporaryFastForward))
- ;
+ u32 HotkeyReturnToMenu = game_config.HotkeyReturnToMenu != 0 ? game_config.HotkeyReturnToMenu : emu_config.HotkeyReturnToMenu;
+ u32 HotkeyTemporaryFastForward = game_config.HotkeyTemporaryFastForward != 0 ? game_config.HotkeyTemporaryFastForward : emu_config.HotkeyTemporaryFastForward;
+ u32 HotkeyToggleSound = game_config.HotkeyToggleSound != 0 ? game_config.HotkeyToggleSound : emu_config.HotkeyToggleSound;
- bool8 SoundToggleIsHeld =
- (HotkeyToggleSound && ((inputdata.key & HotkeyToggleSound) == HotkeyToggleSound))
- ;
+ if(Controls & KEY_TOUCH ||
+ (HotkeyReturnToMenu && ((Controls & HotkeyReturnToMenu) == HotkeyReturnToMenu))
+ ) //Active menu
+ Settings.Paused = 1;
- if (SoundToggleIsHeld && !SoundToggleWasHeld)
- {
- game_enable_audio = !game_enable_audio;
- game_disableAudio();
- }
+ temporary_fast_forward =
+ (HotkeyTemporaryFastForward && ((Controls & HotkeyTemporaryFastForward) == HotkeyTemporaryFastForward))
+ ;
- SoundToggleWasHeld = SoundToggleIsHeld;
+ bool8 SoundToggleIsHeld =
+ (HotkeyToggleSound && ((Controls & HotkeyToggleSound) == HotkeyToggleSound))
+ ;
- if(which1 < 1)
- {
- unsigned int key;
+ if (SoundToggleIsHeld && !SoundToggleWasHeld)
+ {
+ game_enable_audio = !game_enable_audio;
+ game_disableAudio();
+ }
+
+ SoundToggleWasHeld = SoundToggleIsHeld;
+
+ uint32 key = 0x80000000; // Required by Snes9x
// DS -> SNES
- key = (inputdata.key & KEY_A ) << 7; // 0x0001 -> 0x0080
- key |= (inputdata.key & KEY_B ) << 14; // 0x0002 -> 0x8000
- key |= (inputdata.key & KEY_SELECT) << 11; // 0x0004 -> 0x2000
- key |= (inputdata.key & KEY_START ) << 9; // 0x0008 -> 0x1000
- key |= (inputdata.key & KEY_UP ) << 5; // 0x0040 -> 0x0800
+ key |= (Controls & KEY_A ) << 7; // 0x0001 -> 0x0080
+ key |= (Controls & KEY_B ) << 14; // 0x0002 -> 0x8000
+ key |= (Controls & KEY_SELECT) << 11; // 0x0004 -> 0x2000
+ key |= (Controls & KEY_START ) << 9; // 0x0008 -> 0x1000
+ key |= (Controls & KEY_UP ) << 5; // 0x0040 -> 0x0800
// 0x0010 -> 0x0100; 0x0020 -> 0x0200
// 0x0030 -> 0x0300
- key |= (inputdata.key & (KEY_RIGHT | KEY_LEFT)) << 4;
+ key |= (Controls & (KEY_RIGHT | KEY_LEFT)) << 4;
// 0x0100 -> 0x0010; 0x0200 -> 0x0020; 0x0400 -> 0x0040
// 0x0700 -> 0x0070
- key |= (inputdata.key & (KEY_R | KEY_L | KEY_X)) >> 4;
+ key |= (Controls & (KEY_R | KEY_L | KEY_X)) >> 4;
// 0x0080 -> 0x0400; 0x0800 -> 0x4000
// 0x0880 -> 0x4400
- key |= (inputdata.key & (KEY_DOWN | KEY_Y)) << 3;
+ key |= (Controls & (KEY_DOWN | KEY_Y)) << 3;
/*
for(i= 0; i < 12; i++) //remap key
{
@@ -1214,7 +1262,7 @@ unsigned int S9xReadJoypad (int which1)
}
*/
- return (key | 0x80000000);
+ return key;
}
else
return 0;