Verification of some controller information

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Verification of some controller information
by on (#109571)
I'm updating the wiki to add some missing information and clarify some stuff that confused me the first time I was reading it.

I'm currently looking at the http://wiki.nesdev.com/w/index.php/Standard_controller page and the way the controller strobe works in particular. Does the following sound right?

Quote:
Bits 2-0 of $4016/write are stored in internal latches in the 2A03/07. While $4016:0 (strobe) is high, the shift registers in the controllers are continuously reloaded from the button states, and reading $4016/$4017 will return the state of the first button (A) over and over. Once $4016:0 goes low, the reloading will stop. This is why a 1/0 write sequence is required to get the button states.


Edit: s/bottom/button/ :P
Re: Verification of some controller information
by on (#109576)
Quote:
I'm updating the wiki to add some missing information and clarify some stuff that confused me the first time I was reading it.

The best way to do it. Your rewrite sounds good and is clearer. One tweak:

"...and reading $4016/$4017 will keep returning the current state of the first button (A)."

The "over and over" somewhat implied that it would give the same reading each time, rather than the current state.
Re: Verification of some controller information
by on (#109578)
blargg wrote:
"...and reading $4016/$4017 will keep returning the current state of the first button (A)."

The "over and over" somewhat implied that it would give the same reading each time, rather than the current state.


Yeah, that's a clearer way of putting it.

I'll assume the three bits being latched internally is correct then (I remember discussing it on #nesdev earlier). Feel free to jump in if I'm lying. Updating the page... :)
Re: Verification of some controller information
by on (#109642)
So to clarify for the purposes of emulation;

1. Upon writing a xxxxxxx1 to 4016 (constantly) updates which buttons are being pressed.
2. All subsequent reads from 4016 will return the status of the A button.
3. Upon writing a xxxxxxx0 to 4016 the updating stops and all 8 buttons can be read.
4. The 9th read and onwards of 4016 will return 1.

Edit: 5. A write of xxxxxxx0 to 4016 will result in 1 being read back from 4016 onwards.

Edit: Sorry this post is a question. Is the above correct?
Re: Verification of some controller information
by on (#109650)
Above is correct, though buttons being pressed are updated continuously until you write xxxxxxx0 to 4016. That is, if you write xxxxxxx1 to 4016, then hold B while you write xxxxxxx0 to 4016, then release B and read back the button states, you'll see B held. And you could also write xxxxxxx0 to 4016 between each bit read without having any effect on anything (repeated writes of the same value have no effect).