Use the SNES/NES controllers: Difference between revisions
m (the trigger can be cleared right away) |
m (→Usage: code comments) |
||
| (9 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
== NES and SNES controllers == | == NES and SNES controllers == | ||
The F256 machines can use these controllers provided they are equipped with an optional | The F256 machines can use these controllers provided they are equipped with an optional FNX4N4S breakout adapter (website purchase link no longer active). | ||
The official gamepads of yesteryear work without issue with this and are plentiful in the used market. | The official gamepads of yesteryear work without issue with this and are plentiful in the used market. | ||
| Line 7: | Line 7: | ||
Super famicom gamepads work very well as substitute for regular SNES gamepads. | Super famicom gamepads work very well as substitute for regular SNES gamepads. | ||
If your FNX4N4S adapter box is not working reliably, go check how to resolve a potential issue in the [[Troubleshooting|Troubleshoot]] page. | |||
[[File:Full complement of gamepads.png|thumb|A fully populated FNX4N4S for the F256K2]] | |||
=== Registers === | === Registers === | ||
| Line 314: | Line 317: | ||
|R | |R | ||
|} | |} | ||
Notes: | |||
* L refers to the left shoulder button and R refers to the right shoulder button. | |||
* Buttons are active low! Bits are 1 when unpressed, 0 when pressed. | |||
=== Usage === | === Usage === | ||
| Line 321: | Line 327: | ||
<pre> | <pre> | ||
POKE(PAD_CTRL, 0b10000001); //trigger, nes mode, enabled | POKE(PAD_CTRL, 0b10000001); //trigger, nes mode, enabled | ||
ASM("NOP"); //one of these is necessary for the old 1x cores | |||
ASM("NOP"); //a second one is necessary for the first 2x cores; none of those 2 delays are necessary since September 2026+ 2x cores | |||
POKE(PAD_CTRL, 0b00000001); //clear trigger | POKE(PAD_CTRL, 0b00000001); //clear trigger | ||
while((PEEK(PAD_STAT) & 0x40) == 0) //loop while this bit is cleared | while((PEEK(PAD_STAT) & 0x40) == 0) //loop while this bit is cleared | ||
| Line 345: | Line 353: | ||
while((PEEK(PAD_STAT) & 0x40) == 0) //loop while this bit is cleared | while((PEEK(PAD_STAT) & 0x40) == 0) //loop while this bit is cleared | ||
; | ; | ||
//Insert section where reactions are made to the various NES presses | |||
//NES once more, with feeling. Check the gotchas section below | |||
POKE(PAD_CTRL, 0b10000001); //trigger, nes mode, enabled | |||
POKE(PAD_CTRL, 0b00000001); //clear trigger | |||
while((PEEK(PAD_STAT) & 0x40) == 0) //loop while this bit is cleared | |||
; | |||
//SNES section | //SNES section | ||
| Line 353: | Line 367: | ||
while((PEEK(PAD_STAT) & 0x40) == 0) //loop while this bit is cleared | while((PEEK(PAD_STAT) & 0x40) == 0) //loop while this bit is cleared | ||
; | ; | ||
//section where reactions are made to the various SNES presses | |||
//Insert section where reactions are made to the various SNES presses | |||
</pre> | </pre> | ||
=== Source code example in C: === | |||
Check out this simple example displaying the statuses of all 4 NES pads on screen, using hex: https://github.com/Mu0n/F256KsimpleCdoodles/tree/main/NES/src | |||
=== Gotchas === | |||
* In the "old days" prior to the revamped 2x cores from August/September 2026, the 2x core needed a bit of a delay before activating the trigger and clear it. We found out that adding one "NOP" command for 1x core and two "NOP" for 2x core was necessary or it wouldn't behave. It is no longer necessary for the current day 2x core (September 2026 and on). | |||
* Some bootleg SNES controllers out there in the market behave badly when you want to quickly poll both NES and SNES controllers in one game loop pass. User Michael Hill was the one to bring this to our attention. Here is his findings: | |||
<blockquote> | |||
It comes down to the fact that the clock and latch lines go to all the controllers regardless of which bank (nes or snes) you are reading. So what happens is the 8 clock pulses are fine for pulling the controller data for the nes controller. But it takes 16 clock pulses to read the snes. So when you are reading an nes controller you are actually clocking an 8-bit read on the snes also, but the data for those is ignored because you have it set to nes mode which prevents the data lines from being read. Setting to nes mode doesn't disable the clock and latch to the snes (or vice versa). | |||
Now on proper SNES controllers this isn't an issue. Their shift register resets when the latch pin is strobed. But the cheap clone controllers that are out there don't reset, so if you read a nes controller and then a clone snes controller, you get the second 8 bits first because it is out of sync. | |||
So what you can do to fix this (I can test if you want to verify it) read the NES controller again and just ignore it. | |||
So if your sample code you posted in your channel is how you are doing it currently. | |||
<pre> | |||
pollNES(); | |||
pad0 = padState(PEEK(PAD0)); | |||
pad1 = padState(PEEK(PAD1)); | |||
pad2 = padState(PEEK(PAD2)); | |||
pad3 = padState(PEEK(PAD3)); | |||
</pre> | |||
Just change it to this | |||
<pre> | |||
pollNES(); | |||
pad0 = padState(PEEK(PAD0)); | |||
pad1 = padState(PEEK(PAD1)); | |||
pad2 = padState(PEEK(PAD2)); | |||
pad3 = padState(PEEK(PAD3)); | |||
pollNES(); | |||
</pre> | |||
That will keep everything in sync. | |||
</blockquote> | |||
Latest revision as of 09:28, 23 November 2026
NES and SNES controllers
The F256 machines can use these controllers provided they are equipped with an optional FNX4N4S breakout adapter (website purchase link no longer active).
The official gamepads of yesteryear work without issue with this and are plentiful in the used market.
Third party modern recreations are sometimes flaky or not working at all. Share you discoveries in the discord!
Super famicom gamepads work very well as substitute for regular SNES gamepads.
If your FNX4N4S adapter box is not working reliably, go check how to resolve a potential issue in the Troubleshoot page.

Registers
| Register Name | R/W | Address | NES/SNES | Description |
|---|---|---|---|---|
| PAD_CTRL | W | 0xD880 | both | Used to trigger a reading and setting the NES/SNES mode |
| PAD_STAT | R | 0xD880 | both | Used to verify if the triggered polling of gamepad state is done yet |
| PAD0 | R | 0xD884 | both | Buttons statuses: if cleared, they are pressed. If set, they are unpressed. |
| PAD0_S | R | 0xD885 | SNES | Same deal; unused by NES. Consult button table below |
| PAD1 | R | 0xD886 | both | Buttons statuses: if cleared, they are pressed. If set, they are unpressed. |
| PAD1_S | R | 0xD887 | SNES | Same deal; unused by NES. Consult button table below |
| PAD2 | R | 0xD888 | both | Buttons statuses: if cleared, they are pressed. If set, they are unpressed. |
| PAD2_S | R | 0xD889 | SNES | Same deal; unused by NES. Consult button table below |
| PAD3 | R | 0xD88A | both | Buttons statuses: if cleared, they are pressed. If set, they are unpressed. |
| PAD3_S | R | 0xD88B | SNES | Same deal; unused by NES. Consult button table below |
Control register
| Register Name | R/W | Address | Bit7 | Bit6 | Bit5 | Bit4 | Bit3 | Bit2 | Bit1 | Bit0 |
|---|---|---|---|---|---|---|---|---|---|---|
| PAD_CTRL | W | 0xD880 | NES_TRIG | - | - | - | - | MODE | - | EN |
| PAD_STAT | R | 0xD880 | NES_TRIG | DONE | - | - | - | MODE | - | EN |
Control register bit states:
| Bit Name | If set to 1 | If cleared to 0 |
|---|---|---|
| NES_TRIG | Launches the polling of the states of all buttons | Stops polling the states of all buttons |
| DONE | The states of the buttons are ready to be read | The states of the buttons are not ready |
| MODE | SNES data will be used to populate the PAD registers | NES data will be used to populate the PAD registers |
| EN | Enables the gamepads | Disables the gamepads |
Button table
| MODE | NES/SNES | Address | Pad | Bit7 | Bit6 | Bit5 | Bit4 | Bit3 | Bit2 | Bit1 | Bit0 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | NES | 0xD884 | 0 | A | B | Select | Start | Up | Down | Left | Right |
| 0 | NES | 0xD886 | 1 | A | B | Select | Start | Up | Down | Left | Right |
| 0 | NES | 0xD888 | 2 | A | B | Select | Start | Up | Down | Left | Right |
| 0 | NES | 0xD88A | 3 | A | B | Select | Start | Up | Down | Left | Right |
| 1 | SNES | 0xD884 | 0 | B | Y | Select | Start | Up | Down | Left | Right |
| 1 | SNES | 0xD885 | 0 | A | X | L | R | ||||
| 1 | SNES | 0xD886 | 1 | B | Y | Select | Start | Up | Down | Left | Right |
| 1 | SNES | 0xD887 | 1 | A | X | L | R | ||||
| 1 | SNES | 0xD888 | 2 | B | Y | Select | Start | Up | Down | Left | Right |
| 1 | SNES | 0xD889 | 2 | A | X | L | R | ||||
| 1 | SNES | 0xD88A | 3 | B | Y | Select | Start | Up | Down | Left | Right |
| 1 | SNES | 0xD88B | 3 | A | X | L | R |
Notes:
- L refers to the left shoulder button and R refers to the right shoulder button.
- Buttons are active low! Bits are 1 when unpressed, 0 when pressed.
Usage
Example 1: polling a NES controller in PAD0 position and checking if A is pressed:
POKE(PAD_CTRL, 0b10000001); //trigger, nes mode, enabled
ASM("NOP"); //one of these is necessary for the old 1x cores
ASM("NOP"); //a second one is necessary for the first 2x cores; none of those 2 delays are necessary since September 2026+ 2x cores
POKE(PAD_CTRL, 0b00000001); //clear trigger
while((PEEK(PAD_STAT) & 0x40) == 0) //loop while this bit is cleared
;
if((PEEK(PAD0) & 0x80) == 0) reactToAPressed();
Example 2: polling a SNES controller in PAD2 position and checking if X is pressed:
POKE(PAD_CTRL, 0b10000101); //trigger, snes mode, enabled
POKE(PAD_CTRL, 0b00000101); //clear trigger
while((PEEK(PAD_STAT) & 0x40) == 0) //loop while this bit is cleared
;
if((PEEK(PAD2_S) & 0x04) == 0) reactToXPressed();
Example 3: polling both types of controller in rapid succession (allows the usage of all 8 controllers!)
//NES section
POKE(PAD_CTRL, 0b10000001); //trigger, nes mode, enabled
POKE(PAD_CTRL, 0b00000001); //clear trigger
while((PEEK(PAD_STAT) & 0x40) == 0) //loop while this bit is cleared
;
//Insert section where reactions are made to the various NES presses
//NES once more, with feeling. Check the gotchas section below
POKE(PAD_CTRL, 0b10000001); //trigger, nes mode, enabled
POKE(PAD_CTRL, 0b00000001); //clear trigger
while((PEEK(PAD_STAT) & 0x40) == 0) //loop while this bit is cleared
;
//SNES section
POKE(PAD_CTRL, 0b10000101); //trigger, snes mode, enabled
POKE(PAD_CTRL, 0b00000101); //clear trigger
while((PEEK(PAD_STAT) & 0x40) == 0) //loop while this bit is cleared
;
//Insert section where reactions are made to the various SNES presses
Source code example in C:
Check out this simple example displaying the statuses of all 4 NES pads on screen, using hex: https://github.com/Mu0n/F256KsimpleCdoodles/tree/main/NES/src
Gotchas
- In the "old days" prior to the revamped 2x cores from August/September 2026, the 2x core needed a bit of a delay before activating the trigger and clear it. We found out that adding one "NOP" command for 1x core and two "NOP" for 2x core was necessary or it wouldn't behave. It is no longer necessary for the current day 2x core (September 2026 and on).
- Some bootleg SNES controllers out there in the market behave badly when you want to quickly poll both NES and SNES controllers in one game loop pass. User Michael Hill was the one to bring this to our attention. Here is his findings:
It comes down to the fact that the clock and latch lines go to all the controllers regardless of which bank (nes or snes) you are reading. So what happens is the 8 clock pulses are fine for pulling the controller data for the nes controller. But it takes 16 clock pulses to read the snes. So when you are reading an nes controller you are actually clocking an 8-bit read on the snes also, but the data for those is ignored because you have it set to nes mode which prevents the data lines from being read. Setting to nes mode doesn't disable the clock and latch to the snes (or vice versa).
Now on proper SNES controllers this isn't an issue. Their shift register resets when the latch pin is strobed. But the cheap clone controllers that are out there don't reset, so if you read a nes controller and then a clone snes controller, you get the second 8 bits first because it is out of sync.
So what you can do to fix this (I can test if you want to verify it) read the NES controller again and just ignore it.
So if your sample code you posted in your channel is how you are doing it currently.
pollNES(); pad0 = padState(PEEK(PAD0)); pad1 = padState(PEEK(PAD1)); pad2 = padState(PEEK(PAD2)); pad3 = padState(PEEK(PAD3));Just change it to this
pollNES(); pad0 = padState(PEEK(PAD0)); pad1 = padState(PEEK(PAD1)); pad2 = padState(PEEK(PAD2)); pad3 = padState(PEEK(PAD3)); pollNES();That will keep everything in sync.