Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;----------------------------------------------------------------------------
- ; @ReadSega [internal]
- ; Reads joypads with the Sega multitap
- ;----------------------------------------------------------------------------
- ; input d7.w ... Port ID (0 or 1)
- ;----------------------------------------------------------------------------
- ; breaks: d5, d6, d7, a4, a5, a6
- ;----------------------------------------------------------------------------
- @ReadSega:
- ;----------------------------------------------------------------------------
- ; @GetNibble [internal]
- ; Macro to get the next nibble from Sega's multitap
- ;----------------------------------------------------------------------------
- ; input d7.b .... TR of nibble to read
- ; input a6.l .... I/O port address
- ;----------------------------------------------------------------------------
- ; output d7.b ... TR of next nibble
- ; output d6.b ... Nibble being read
- ;----------------------------------------------------------------------------
- ; breaks: d5
- ;----------------------------------------------------------------------------
- @GetNibble: macro
- move.b d7, (a6)
- moveq #$7F, d5
- @Wait\@:
- move.b (a6), d6
- add.b d6, d6
- eor.b d7, d6
- btst.l #5, d6
- beq.s @GotIt\@
- dbf d5, @Wait\@
- bra @Error
- @GotIt\@:
- bchg.l #5, d7
- lsr.b #1, d6
- and.b #$0F, d6
- endm
- ;----------------------------------------------------------------------------
- ; The actual subroutine...
- ;----------------------------------------------------------------------------
- movem.l d0-d4, -(sp) ; Save registers (UGH)
- add.w d7, d7 ; Get port base address
- lea ($A10003), a6
- lea (a6,d7.w), a6
- lea (Joy1Hold), a5 ; Where joypad status is stored
- move.b #$20, (a6) ; Set TH low to start communication
- nop
- nop
- nop
- moveq #$00, d7 ; First nibble has TR low
- @GetNibble ; Skip the first two nibbles
- @GetNibble
- @GetNibble ; Get the IDs for the devices
- move.b d6, d0 ; connected to each port
- lsl.l #8, d0
- @GetNibble
- move.b d6, d0
- lsl.l #8, d0
- @GetNibble
- move.b d6, d0
- lsl.l #8, d0
- @GetNibble
- move.b d6, d0
- moveq #4-1, d1 ; Go through all ports
- @DevLoop:
- rol.l #8, d0 ; Get device ID
- cmp.b #$01, d0 ; Is there a joypad?
- bhi.s @NoDevice
- @GetNibble ; Read joypad buttons
- move.b d6, d2
- @GetNibble
- lsl.b #4, d6
- or.b d6, d2
- tst.b d0
- beq.s @No6Pad
- @GetNibble
- @No6Pad:
- not.b d2 ; Make buttons high logic
- move.b (a5), d3 ; Update joypad status
- move.b d2, (a5)+
- not.b d3
- and.b d2, d3
- move.b d3, (a5)+
- bra.s @DeviceParsed
- @NoDevice:
- addq.w #2, a5 ; Skip this joypad
- @DeviceParsed:
- dbf d1, @DevLoop ; Go for next port
- move.b #$60, (a6) ; Done accessing multitap
- movem.l (sp)+, d0-d4 ; Restore registers
- rts ; End of subroutine
- ;----------------------------------------------------------------------------
- ; Error handling (i.e. timeout)
- ;----------------------------------------------------------------------------
- @Error:
- move.l #0, (Joy1Hold) ; Kill joypad status
- move.l #0, (Joy3Hold)
- move.b #$60, (a6) ; Done accessing multitap
- movem.l (sp)+, d0-d4 ; Restore registers
- rts ; End of subroutine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement