-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change SNES timings to specs #375
Change SNES timings to specs #375
Conversation
… old check of controller presence. Reduce time needed to detect if controller present. Clean up comments.
Committed some improvements. The scan now takes 1,746 cycles = 218 us (+34 us compared to current master). |
I attempted to adjust the timing so that it's closer to how I think SNES consoles do it. Durations measured with the emulator.
If both my understanding and measurements are correct, we should be very close to the standard. The joystick scan takes a total 1,769 cycles = 221 us (+37 us compared to the current master branch). The total duration measured from the start of the joystick scan method (before KVARS_START_TRASH_A_NZ) until the end of the method (after KVARS_END_TRASH_A_NZ). The code works on my hardware (OtterX + original SNES controllers). |
…,739 cycles = +33 us compared to current master
I made some further changes to improve joystick scanning performance without breaking SNES timing. In the latest code, The The emulated keyboard joystick wasn't changed. It still uses joy0+2 to track whether connected or not.
|
Attached is a capture of the SNES port on my system (OtterX + original controller), made with a cheap logic analyzer (24 MHz). Results, compared to the real SNES console as described here: https://gamesx.com/controldata/snesdat.htm
No button was pressed, and the first 16 bits are 1. The 17th bit is 0, which tells that a controller is attached. The Data line went low about 1 us after the raising edge of Clock, that is 11 us before we need it. |
I'm closing this PR as it is not clear it will actually support more SNES controllers. The subject was discussed in depth here: https://discord.com/channels/547559626024157184/548715649065811989/1311825434794659911 |
This is an attempt to follow SNES timing specs more closely.
In the current master branch, scanning the SNES controllers takes 1,473 clock cycles = 184 us.
This PR slows down the SNES controller latch and clock to about 12 us, according to specs. This increases the time needed to scan the controllers.
The SNES controller sends 16 bits of data. The current master branch reads another 8 bits, a total of 24 bits, where the last 8 bits are only used to check if a controller is present. This PR changes the controller detection by reading only one extra bit, reducing the duration of the scan.
After these two changes, scanning the SNES controllers takes 1,838 clock cycles = 230 us, i.e. 46 us more than the current master branch implementation.
It might be enough to get more SNES controller clones to work. If so, we need to decide if that is worth the extra 46 us.