georgjz/snes-assembly-adventure-code

Incorrect interpretation of HBVJOY

Opened this issue · 0 comments

First of all, thanks for the incredible tutorial! I don't know how I would have gotten started without it.

However, I believe the article on reading input has an error. It claims that the LSB of HBVJOY is 1 when the controller is ready to read. As far as I can tell the opposite is true - the LSB of HBVJOY indicates that the controller auto-read is in progress: https://snes.nesdev.org/wiki/MMIO_registers#HVBJOY

So this code...

WaitForJoypad:
        lda HVBJOY                          ; get joypad status
        and #$01                            ; check whether joypad done reading...
        beq WaitForJoypad                   ; ...if not, wait a bit more

should actually be...

WaitForJoypad:
        lda HVBJOY                          ; get joypad status
        and #$01                            ; check whether joypad still reading...
        bne WaitForJoypad                   ; ...if so, wait a bit more

This would then match another tutorial I found: https://snes.nesdev.org/wiki/Controller_reading

I'm guessing your demo still works because the controller gets polled reliably once a frame, and your demo tends to be in the game loop at that point, and the controller read registers tend to be mostly correct, even during the update process. Kinda surprising that this code can work either way!

Thanks again!