Myself086 / Project-Nested

MIT License
508 stars 17 forks source link

Enable automatic joypad polling #24

Closed qwertymodo closed 2 years ago

qwertymodo commented 3 years ago

I was recently working with somebody on a similar but unrelated project porting an NES game to the SNES, and something they ran into was the fact that the hotkey hooks on the SD2SNES, such as in-game reset, didn't work. We ended up solving this by enabling automatic joypad polling (just set bit 0 on all writes to $4200). This does NOT mean you should actually use auto joypad polling by reading from $4218/19, as that will end up reading "stale" values and result in causing input latency. No changes to the original polling are necessary, just setting that one bit is enough to enable the SD2SNES hotkeys.

Myself086 commented 3 years ago

Interesting, I thought setting $4200.0 would ruin reading $4016 and $4017 if done at the wrong time. The timing on those reads isn't predictable because the game decides when to do it. Additionally, the option NMI mode "auto detect" can shift the timing in either direction during slowdowns.

Does SD2SNES rely on overriding NMI? Because I'm only using IRQ for now.

qwertymodo commented 3 years ago

That's a good question. I believe the SD2SNES might use NMI, so in that case it might still not work. Conflicting auto and manual joypad reads would be really unlikely, but if you were paranoid, you can avoid conflicts between manual and auto joypad polling if your JIT is able to detect a manual poll starting and insert a check like

-; lda $4212; bit #$01; bne -

before the manual poll starts. Either way, it's not a huge deal, but having just figured it out for that other project, I figured I'd bring it up here while it was fresh in my mind.

On Mon, Aug 23, 2021, 10:44 PM Myself086 @.***> wrote:

Interesting, I thought setting $4200.0 would ruin reading $4016 and $4017 if done at the wrong time. The timing on those reads isn't predictable because the game decides when to do it. Additionally, the option NMI mode "auto detect" can shift the timing in either direction during slowdowns.

Does SD2SNES rely on overriding NMI? Because I'm only using IRQ for now.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Myself086/Project-Nested/issues/24#issuecomment-904339536, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNWEBSLXTNX4W6ULQD7WU3T6MWSTANCNFSM5CVN4QRQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

Myself086 commented 3 years ago

Ah, that's one way of doing it!

I'll fix this at the same time I do input remap option. I've got a long list of things that I know how to do/fix.

Thanks for letting me know!

Myself086 commented 2 years ago

Added in v1.5