aboutsummaryrefslogtreecommitdiff
path: root/source/ppu.cpp
diff options
context:
space:
mode:
authorNebuleon Fumika2012-12-21 03:50:10 -0500
committerNebuleon Fumika2012-12-21 03:50:10 -0500
commita0d0c5e7a5bdc396b4c370a750273b6e3b963bb0 (patch)
tree6bc433422db602b974a01dffbfc5ce5d84afc578 /source/ppu.cpp
parent3972512b2a5c25236ea3ba586621dba6e5b56361 (diff)
downloadsnes9x2005-a0d0c5e7a5bdc396b4c370a750273b6e3b963bb0.tar.gz
snes9x2005-a0d0c5e7a5bdc396b4c370a750273b6e3b963bb0.tar.bz2
snes9x2005-a0d0c5e7a5bdc396b4c370a750273b6e3b963bb0.zip
Eliminate the latency of button press recognition, which was bad enough to lose keys entirely sometimes, and could otherwise delay a button press or release by 200 ms.
This was the entire reason I created the fork, and I finally did it! It syncs the controls every scanline of a frame, which costs about 60,000 MIPS instructions per frame to deal with. Luckily, the processor runs at 396 MHz, which means the cost of checking the controls is 1% of the CPU's power.
Diffstat (limited to 'source/ppu.cpp')
-rw-r--r--source/ppu.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/source/ppu.cpp b/source/ppu.cpp
index 8ba7a5f..e0c6e24 100644
--- a/source/ppu.cpp
+++ b/source/ppu.cpp
@@ -3202,12 +3202,45 @@ void S9xUpdateJustifiers()
void S9xUpdateJoypads ()
{
- int i;
+ uint32 i;
+#ifdef SYNC_JOYPAD_AT_HBLANK
+ uint32 j, k, KeyValue;
+ bool8 StartedPressed;
+
+ // For each joypad
+ for (i = 0; i < 5; i++)
+ {
+ IPPU.Joypads [i] = 0;
+ // Sync each key
+ for (k = 1; k != 0x80000000; k <<= 1)
+ {
+ KeyValue = IPPU.JoypadsAtHBlanks[i][0] & k;
+ StartedPressed = KeyValue != 0;
+ // from each line.
+ // If, initially, the key is NOT pressed, one line of it being
+ // pressed means that the key MUST be pressed.
+ // Otherwise, the key MUST be pressed if it doesn't start as such.
+ for (j = 1; j < (Settings.PAL ? SNES_MAX_PAL_VCOUNTER : SNES_MAX_NTSC_VCOUNTER); j++)
+ {
+ if ((StartedPressed) && ((IPPU.JoypadsAtHBlanks[i][j] & k) == 0)) {
+ KeyValue = 0;
+ break;
+ }
+ else if ((!StartedPressed) && ((IPPU.JoypadsAtHBlanks[i][j] & k) != 0)) {
+ KeyValue = k;
+ break;
+ }
+ }
+ IPPU.Joypads [i] |= KeyValue;
+ }
+ }
+#else
for (i = 0; i < 5; i++)
{
IPPU.Joypads [i] = S9xReadJoypad (i);
}
+#endif
// S9xMovieUpdate();