jsgroth / jgenesis

Sega Genesis / Sega CD / SNES / Master System / Game Gear emulator
MIT License
56 stars 3 forks source link

Trouble Shooter (USA).md controls dont work properly #110

Closed benderscruffy closed 2 weeks ago

benderscruffy commented 3 months ago

C button doesnt work properly

jsgroth commented 3 months ago

It looks like it's reading C button presses as Start presses, and it's probably also reading B presses as A presses.

This game has strange code for reading controller inputs. For 3-button controllers, most games do something like this:

move.b #0x40, ($A10009)  ; set TH pin to output and all other pins to input
move.b #0x00, ($A10003)  ; set TH=low
nop                      ; wait for controller to update pins
nop
move.b ($A10003), d0     ; read A and Start
move.b #0x40, ($A10003)  ; set TH=high
nop
nop
move.b ($A10003), d1     ; read B, C, and directional inputs

This game does this (abridged a bit to skip irrelevant instructions):

move.b #0x00, ($A10003)  ; set TH=low
move.b #0x00, ($A10009)  ; set TH pin to input???
nop                      ; wait for controller to update pins
nop
move.b ($A10003), d0     ; ???
move.b #0x40, ($A10003)  ; set TH=high
move.b #0x40, ($A10009)  ; set TH to output
nop
nop
move.b ($A10003), d1     ; read B, C, and directional inputs

It seems to expect the first read to function as if TH is low, which should return the status of the A and Start buttons. Right now TH in input mode functions the same as TH high so it's reading the B/C/direction inputs twice.

Making TH in input mode function the same as TH=low fixes this, but I'm struggling to think of an explanation for why this works on actual hardware.

jsgroth commented 3 months ago

Fixed with a solution that mostly makes sense to me: