From a0d0c5e7a5bdc396b4c370a750273b6e3b963bb0 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Fri, 21 Dec 2012 03:50:10 -0500 Subject: 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. --- source/ppu.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'source/ppu.cpp') 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(); -- cgit v1.2.3