Advertisement
HitaxasTV

6-button ReadJoypads

May 11th, 2021
1,612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Ctrl_1_Ext_Logical =        ramaddr( $FFFFF608 ) ; 2 bytes
  2. Ctrl_1_Ext_Held_Logical =   ramaddr( $FFFFF608 ) ; 1 byte
  3. Ctrl_1_Ext_Press_Logical =  ramaddr( $FFFFF609 ) ; 1 byte
  4. Ctrl_1_Ext =                ramaddr( $FFFFF60A ) ; 2 bytes  ; ----MXYZ
  5. Ctrl_1_Ext_Held =           ramaddr( $FFFFF60A ) ; 1 byte
  6. Ctrl_1_Ext_Press =          ramaddr( $FFFFF60B ) ; 1 byte
  7.  
  8. Ctrl_2_Ext_Logical =        ramaddr( $FFFFF60C ) ; 2 bytes
  9. Ctrl_2_Ext_Held_Logical =   ramaddr( $FFFFF60C ) ; 1 byte
  10. Ctrl_2_Ext_Press_Logical =  ramaddr( $FFFFF60D ) ; 1 byte
  11. Ctrl_2_Ext =                ramaddr( $FFFFF60E ) ; 2 bytes  ; ----MXYZ
  12. Ctrl_2_Ext_Held =           ramaddr( $FFFFF60E ) ; 1 byte
  13. Ctrl_2_Ext_Press =          ramaddr( $FFFFF60F ) ; 1 byte
  14.  
  15. ; ---------------------------------------------------------------------------
  16. ; Subroutine to read joypad input, and send it to the RAM
  17. ; ---------------------------------------------------------------------------
  18. ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
  19.  
  20. ; sub_111C:
  21. ReadJoypads:
  22.     stopZ80
  23.     ; Read first player SACBRLDU buttons
  24.     lea (Z80_Port_1_Data+1).l,a1    ; first joypad port
  25.     lea (Ctrl_1).w,a0               ; address where joypad states are written
  26.     bsr.s   Joypad_Read
  27.  
  28.         ; Read first player MXYZ buttons
  29.         lea (Ctrl_1_Ext).w,a0
  30.         bsr.s   Joypad_Read_Ext
  31.  
  32.         ; Test for 3 button mode
  33.         btst    #7,(Ctrl_1_Ext).w
  34.         bne.s   +
  35.         clr.w   (Ctrl_1_Ext).w
  36. +
  37.     ; Read second player SACBRLDU buttons
  38.     addi.l  #2,a1           ; second joypad port
  39.     lea (Ctrl_2).w,a0       ; address where joypad states are written
  40.     bsr.s   Joypad_Read
  41.  
  42.     if SUPPORT_ARCADE_PAD == 1
  43.  
  44.         ; Read second player MXYZ buttons
  45.         lea (Ctrl_2_Ext).w,a0
  46.         bsr.s   Joypad_Read_Ext
  47.  
  48.         ; Test for 3 button mode
  49.         btst    #7,(Ctrl_2_Ext).w
  50.         bne.s   +
  51.         clr.w   (Ctrl_2_Ext).w
  52. +
  53.     endif
  54.  
  55.     startZ80
  56.     rts
  57. ; End of function ReadJoypads
  58.  
  59.  
  60. ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
  61.  
  62. ; sub_112A:
  63. Joypad_Read:    ; SACBLRDU
  64.     move.b  #0,(a1)
  65.     move.b  (a1),d0
  66.     lsl.b   #2,d0
  67.     andi.b  #$C0,d0
  68.     move.b  #$40,(a1)
  69.     move.b  (a1),d1
  70.     andi.b  #$3F,d1
  71.     or.b    d1,d0
  72.     not.b   d0
  73.     move.b  (a0),d1
  74.     eor.b   d0,d1
  75.     move.b  d0,(a0)+
  76.     and.b   d0,d1
  77.     move.b  d1,(a0)+
  78.     rts
  79.  
  80. Joypad_Read_Ext:    ; MXYZ
  81.     ; First cycle
  82.     move.b  #0,(a1)
  83.     move.b  (a1),d0
  84.     move.b  #$40,(a1)
  85.     move.b  (a1),d1
  86.  
  87.     ; Second cycle
  88.     move.b  #0,(a1)
  89.     move.b  (a1),d0
  90.     lsl.b   #4,d0
  91.     move.b  #$40,(a1)
  92.     move.b  (a1),d1
  93.  
  94.     ; Write button pushes
  95.     andi.b  #$F,d1
  96.     or.b    d1,d0
  97.     not.b   d0
  98.     move.b  (a0),d1
  99.     eor.b   d0,d1
  100.     move.b  d0,(a0)+
  101.     and.b   d0,d1
  102.     move.b  d1,(a0)+
  103.     rts
  104. ; End of function Joypad_Read
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement