Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; =============== S U B R O U T I N E =======================================
- ; Subroutine to read the current controller state and update the button
- ; press values in RAM.
- ReadJoypads: ; DATA XREF: ROM:loc_1A07Ct
- move.w #$100,($A11100).l ; Stop the Z80.
- lea ($A10003).l,a1 ; Load data port A (controller 1) to a1.
- lea ($FFFFFC04).w,a0 ; Load player 1's button RAM address output to a0.
- lea ($FFFFFF2C).w,a2
- bsr.s Joypad_Read ; Update the controller's state.
- lea ($A10005).l,a1 ; Load data port B (controller 2) to a1.
- addq.w #2,a0 ; Load player 2's button RAM address output to a0 ($FFFFFC07).
- lea ($FFFFFF30).w,a2
- bsr.s Joypad_Read ; Update the controller's state.
- move.w #0,($A11100).l ; Start the Z80.
- rts ; Return.
- ; End of function ReadJoypads
- ; =============== S U B R O U T I N E =======================================
- ; Routine to convert TODO - Write up.
- ;
- ; Key: X - Unused. T - /TH pin. S - Start. U - Up, D - Down, L - Left, R - Right.
- ; When /TH is low:
- ; $A10003 - XTSA --DU
- ; When /TH is high:
- ; $A10003 - XTCB RLDU
- Joypad_Read: ; CODE XREF: ReadJoypads+16p ReadJoypads+24p
- move.b #0,(a1) ; Set /TH pin low.
- nop ; Delay...
- nop ; ...
- move.b (a1),d0 ; Get bit outputs XTSA --DU.
- move.b d0,d3 ; Copy to d3.
- lsl.b #2,d0 ; Discard the irrelevant bits (XT).
- andi.b #$C0,d0 ; Get only Start and A (Down and Up are also covered when the /TH pin is high).
- move.b #$40,(a1) ; Set /TH pin high.
- nop ; Delay...
- nop ; ...
- move.b (a1),d1 ; Get bit outputs XTCB RLDU.
- andi.b #$3F,d1 ; Discard the irrelevant bits (XT).
- move.b d1,d4 ; Copy to d4.
- or.b d1,d0 ; Combine the bits (SACB RLDU).
- not.b d0 ; Reverse bit values (Values were 1 by default and set to 0 when a button was pressed. This reverses that).
- move.b d0,d1 ; Copy to d1.
- move.b (a0),d2 ; Load the last frame's stored controller state.
- eor.b d2,d0 ; Ensure buttons pressed last frame cannot be pressed again.
- tst.b ($FFFFFF2A).w ;
- beq.s loc_817E ;
- movea.l (a2),a3
- andi.b #$80,d1
- or.b (a3)+,d1
- andi.b #$80,d0
- or.b (a3)+,d0
- move.l a3,(a2)
- loc_817E: ; CODE XREF: Joypad_Read+30j
- move.b d1,(a0)+ ; Write the held button output to a0.
- and.b d1,d0 ; Unset any button bits that were held last frame.
- move.b d0,(a0)+ ; Write the pressed button output to a0.
- move.b #0,(a0) 0011 0011
- cmp.b d3,d4 ; Are left and right being pressed at the same time (but nothing else, with the exception of up and down).
- bne.s locret_8190 ; If not, branch.
- move.b #1,(a0) 0011 1111
- locret_8190: ; CODE XREF: Joypad_Read+4Ej
- rts ; Return.
- ; End of function Joypad_Read
- &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
- loc_9128: ; DATA XREF: ROM:off_3D2o
- move.w ($FFFFFF48).w,($C00004).l; Disable the display.
- move #$2500,sr ; Enable interrupts.
- jsr ClearVDPRAM(pc) ; Clear VDP RAM.
- jsr (loc_1260E).l ;
- jsr sub_10526(pc)
- move.w ($FFFFFF46).w,($C00004).l; Enable the display.
- move #$2700,sr ; Disable interrupts.
- addq.w #2,($FFFFFF00).w ; Load loc_9152 on next GameModeArray pass.
- loc_9152: ; DATA XREF: ROM:000003D6o
- tst.w ($FFFFFB06).w ; Is there time left on the counter?
- beq.s loc_9168 ; If there isn't, branch.
- tst.b ($FFFFFC06).w ;
- bne.s locret_916E ;
- move.b ($FFFFFC05).w,d0 ; Get player 1's button input.
- or.b ($FFFFFC09).w,d0 ; Get player 2's button input.
- bpl.s locret_916E ; If none of them were pressing start, branch.
- loc_9168: ; CODE XREF: ROM:00009156j
- move.w #0,($FFFFFF00).w ; Set the game mode to the Sega Screen.
- locret_916E: ; CODE XREF: ROM:0000915Cj
- ; ROM:00009166j
- rts ; Return.
Advertisement
Add Comment
Please, Sign In to add comment