Counting Button Presses

A place where you can keep others updated about your NES-related projects through screenshots, videos or information in general.

Moderator: Moderators

Post Reply
doubleH
Posts: 2
Joined: Fri Sep 09, 2022 2:21 pm

Counting Button Presses

Post by doubleH »

I'm working on some NES controller ideas and I'm looking for testing programs to help me out. I've found the Joystick test cartridge rom, which is a great help. Now I'm wondering is the any other controller testing tools out there that the homebrew community have made? Specifically I would like one that told me how many times per second I was pressing the A and B buttons. I'd like to test my own speed with different controllers and test different turbo controllers.

Bonus question...
Would the theoretical max button presses be 15 for the NES? I was thinking 30 fps with alternating high/low button states would make 15 max.
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: Counting Button Presses

Post by Fiskbit »

The console doesn't have a limit on the number of button presses per second, per se. It's convenient to read input once per frame, and so you normally have about 60 reads per second (and thus 30 presses (ie toggles) per second), but input could be read hundreds, perhaps thousands of times in a single frame, if desired. (At least on real hardware; emulators aren't able to get button state from controllers that frequently.)

The speed is limited by the particular controller hardware, the protocol for reading input, the particular inputs you care about, and the CPU's speed. The CPU gets data from the joypad by reading a joypad register, which tells the joypad it's being read and allows the joypad to respond. To give you an upper bound, reading that register takes 4 cycles, and the CPU runs at 1,789,773 cycles per second. The protocol for a standard controller requires 'strobing' the controller by doing a couple writes to lock the current input and then doing 8 reads, usually moving a bit from each of those reads into a variable for later use, which usually takes 100-200 cycles. That can be optimized, particularly if you just care about a particular button. In fact, if you just care about the A button, you an forego strobing entirely because if you do half a strobe, the controller will return the current state of the A button on every read, approaching that upper bound mentioned earlier (minus any overhead for processing a state change, which might make it something like 9 cycles instead of 4). That easily gets us to a rate of thousands of reads per frame and hundreds of thousands per second, way faster than the button could ever reasonably be pressed.

The specific controller does impact this, though. Some controllers take time to measure input or stabilize. Controllers like the Arkanoid controller or Family BASIC keyboard can only be read so fast.
Joe
Posts: 650
Joined: Mon Apr 01, 2013 11:17 pm

Re: Counting Button Presses

Post by Joe »

There's the theoretical maximum, and then there's the useful maximum. Most games read the controller once per frame, at either 60 FPS or 50 FPS depending on the TV system. That limits you to 30 or 25 presses per second no matter how fast you can actually press a button.

Some games do read the controller more than once per frame, but they're only doing it to work around a hardware glitch that sometimes corrupts the data received from the controller, so they still won't recognize more than 30 or 25 presses per second. A few of these games assume a human is pressing the button on the controller and will crash or otherwise misbehave if you feed them input at superhuman speed.
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: Counting Button Presses

Post by Fiskbit »

I guess one other detail to add is that sufficiently-fast button presses can be missed entirely. There is normally about 1 frame between joypad strobes, and any button state changes in the mean time won't get seen. So, if the button was pressed and released faster than 1 frame, which I'm pretty sure can be done by humans, it can land entirely between two reads and never be seen by the software.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Counting Button Presses

Post by rainwarrior »

Someone did make a small NES game to test your button mashing speed: https://www.shmupspeed.com/

There's various input tests on the wiki. I made one that logs input each frame to the screen.
Fiskbit wrote: Fri Sep 09, 2022 7:01 pmSo, if the button was pressed and released faster than 1 frame, which I'm pretty sure can be done by humans, it can land entirely between two reads and never be seen by the software.
It might be technically true, I'm not sure how practically true it is. You can definitely make the controller make contact and be in the 1-pollable state for less than a frame, but I'd debate whether that would ever feel like a "real" button press. Can you feel the characteristic flip of the rubber dome under your finger press and release in that time? In cases where a partial frame input can arise, I'm not sure the user could definitively say they'd actually "pressed" the button.

For repeated button mashing, the fastest people can press and release around 15-20 times per second (even at higher framrates). 60fps polling is quite sufficient, generally, for even extremely fash mashing. You could poll at 120fps and say the gloves were truly off, but I think that'd already be kind of overkill.
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: Counting Button Presses

Post by Fiskbit »

Indeed, a normal button press is probably almost always longer than a frame. For games with tricks that require one-frame taps, such as the 'screen scroll' glitch in Zelda where Link wraps from one side of the screen to the other, people usually come up with some unusual method of pressing to make it fairly reliable, such as using a fingernail on the edge of the button to allow a fast release.
Post Reply