Dandaman955

SoR

Jun 14th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; =============== S U B R O U T I N E =======================================
  2. ; Subroutine to read the current controller state and update the button
  3. ; press values in RAM.
  4.  
  5. ReadJoypads:                ; DATA XREF: ROM:loc_1A07Ct
  6.         move.w  #$100,($A11100).l        ; Stop the Z80.
  7.         lea ($A10003).l,a1           ; Load data port A (controller 1) to a1.
  8.         lea ($FFFFFC04).w,a0         ; Load player 1's button RAM address output to a0.
  9.         lea ($FFFFFF2C).w,a2
  10.         bsr.s   Joypad_Read              ; Update the controller's state.
  11.         lea ($A10005).l,a1           ; Load data port B (controller 2) to a1.
  12.         addq.w  #2,a0                    ; Load player 2's button RAM address output to a0 ($FFFFFC07).
  13.         lea ($FFFFFF30).w,a2
  14.         bsr.s   Joypad_Read              ; Update the controller's state.
  15.         move.w  #0,($A11100).l           ; Start the Z80.
  16.         rts                              ; Return.
  17. ; End of function ReadJoypads
  18.  
  19.  
  20. ; =============== S U B R O U T I N E =======================================
  21. ; Routine to convert TODO - Write up.
  22. ;
  23. ; Key: X - Unused. T - /TH pin. S - Start. U - Up, D - Down, L - Left, R - Right.
  24. ; When /TH is low:
  25. ; $A10003 - XTSA --DU
  26. ; When /TH is high:
  27. ; $A10003 - XTCB RLDU
  28.  
  29. Joypad_Read:                ; CODE XREF: ReadJoypads+16p ReadJoypads+24p
  30.         move.b  #0,(a1)                  ; Set /TH pin low.
  31.         nop                              ; Delay...
  32.         nop                              ; ...
  33.         move.b  (a1),d0                  ; Get bit outputs XTSA --DU.
  34.         move.b  d0,d3                    ; Copy to d3.
  35.         lsl.b   #2,d0                    ; Discard the irrelevant bits (XT).
  36.         andi.b  #$C0,d0                  ; Get only Start and A (Down and Up are also covered when the /TH pin is high).
  37.         move.b  #$40,(a1)                ; Set /TH pin high.
  38.         nop                              ; Delay...
  39.         nop                              ; ...
  40.         move.b  (a1),d1                  ; Get bit outputs XTCB RLDU.
  41.         andi.b  #$3F,d1                  ; Discard the irrelevant bits (XT).
  42.         move.b  d1,d4                    ; Copy to d4.
  43.         or.b    d1,d0                    ; Combine the bits (SACB RLDU).
  44.         not.b   d0                       ; Reverse bit values (Values were 1 by default and set to 0 when a button was pressed. This reverses that).
  45.         move.b  d0,d1                    ; Copy to d1.
  46.         move.b  (a0),d2                  ; Load the last frame's stored controller state.
  47.         eor.b   d2,d0                    ; Ensure buttons pressed last frame cannot be pressed again.
  48.         tst.b   ($FFFFFF2A).w            ;
  49.         beq.s   loc_817E                 ;
  50.         movea.l (a2),a3
  51.         andi.b  #$80,d1
  52.         or.b    (a3)+,d1
  53.         andi.b  #$80,d0
  54.         or.b    (a3)+,d0
  55.         move.l  a3,(a2)
  56.  
  57. loc_817E:                        ; CODE XREF: Joypad_Read+30j
  58.         move.b  d1,(a0)+                 ; Write the held button output to a0.
  59.         and.b   d1,d0                    ; Unset any button bits that were held last frame.
  60.         move.b  d0,(a0)+                 ; Write the pressed button output to a0.
  61.         move.b  #0,(a0)                    0011 0011
  62.         cmp.b   d3,d4                    ; Are left and right being pressed at the same time (but nothing else, with the exception of up and down).
  63.         bne.s   locret_8190              ; If not, branch.
  64.         move.b  #1,(a0)                    0011 1111
  65.  
  66. locret_8190:                ; CODE XREF: Joypad_Read+4Ej
  67.         rts                              ; Return.
  68. ; End of function Joypad_Read
  69.  
  70.  
  71. &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  72.  
  73. loc_9128:               ; DATA XREF: ROM:off_3D2o
  74.         move.w  ($FFFFFF48).w,($C00004).l; Disable the display.
  75.         move    #$2500,sr                ; Enable interrupts.
  76.         jsr ClearVDPRAM(pc)          ; Clear VDP RAM.
  77.         jsr (loc_1260E).l            ;
  78.         jsr sub_10526(pc)
  79.         move.w  ($FFFFFF46).w,($C00004).l; Enable the display.
  80.         move    #$2700,sr                ; Disable interrupts.
  81.         addq.w  #2,($FFFFFF00).w         ; Load loc_9152 on next GameModeArray pass.
  82.  
  83. loc_9152:               ; DATA XREF: ROM:000003D6o
  84.         tst.w   ($FFFFFB06).w            ; Is there time left on the counter?
  85.         beq.s   loc_9168                 ; If there isn't, branch.
  86.         tst.b   ($FFFFFC06).w            ;
  87.         bne.s   locret_916E              ;
  88.         move.b  ($FFFFFC05).w,d0         ; Get player 1's button input.
  89.         or.b    ($FFFFFC09).w,d0         ; Get player 2's button input.
  90.         bpl.s   locret_916E              ; If none of them were pressing start, branch.
  91.  
  92. loc_9168:               ; CODE XREF: ROM:00009156j
  93.         move.w  #0,($FFFFFF00).w         ; Set the game mode to the Sega Screen.
  94.  
  95. locret_916E:                ; CODE XREF: ROM:0000915Cj
  96.                     ; ROM:00009166j
  97.         rts                              ; Return.
Advertisement
Add Comment
Please, Sign In to add comment