Advertisement
Guest User

Untitled

a guest
Mar 9th, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. ;----------------------------------------------------------------------------
  2. ; @ReadSega [internal]
  3. ; Reads joypads with the Sega multitap
  4. ;----------------------------------------------------------------------------
  5. ; input d7.w ... Port ID (0 or 1)
  6. ;----------------------------------------------------------------------------
  7. ; breaks: d5, d6, d7, a4, a5, a6
  8. ;----------------------------------------------------------------------------
  9.  
  10. @ReadSega:
  11.  
  12. ;----------------------------------------------------------------------------
  13. ; @GetNibble [internal]
  14. ; Macro to get the next nibble from Sega's multitap
  15. ;----------------------------------------------------------------------------
  16. ; input d7.b .... TR of nibble to read
  17. ; input a6.l .... I/O port address
  18. ;----------------------------------------------------------------------------
  19. ; output d7.b ... TR of next nibble
  20. ; output d6.b ... Nibble being read
  21. ;----------------------------------------------------------------------------
  22. ; breaks: d5
  23. ;----------------------------------------------------------------------------
  24.  
  25. @GetNibble: macro
  26. move.b d7, (a6)
  27. moveq #$7F, d5
  28. @Wait\@:
  29. move.b (a6), d6
  30. add.b d6, d6
  31. eor.b d7, d6
  32. btst.l #5, d6
  33. beq.s @GotIt\@
  34. dbf d5, @Wait\@
  35. bra @Error
  36. @GotIt\@:
  37. bchg.l #5, d7
  38. lsr.b #1, d6
  39. and.b #$0F, d6
  40. endm
  41.  
  42. ;----------------------------------------------------------------------------
  43. ; The actual subroutine...
  44. ;----------------------------------------------------------------------------
  45.  
  46. movem.l d0-d4, -(sp) ; Save registers (UGH)
  47.  
  48. add.w d7, d7 ; Get port base address
  49. lea ($A10003), a6
  50. lea (a6,d7.w), a6
  51.  
  52. lea (Joy1Hold), a5 ; Where joypad status is stored
  53.  
  54. move.b #$20, (a6) ; Set TH low to start communication
  55. nop
  56. nop
  57. nop
  58.  
  59. moveq #$00, d7 ; First nibble has TR low
  60. @GetNibble ; Skip the first two nibbles
  61. @GetNibble
  62.  
  63. @GetNibble ; Get the IDs for the devices
  64. move.b d6, d0 ; connected to each port
  65. lsl.l #8, d0
  66. @GetNibble
  67. move.b d6, d0
  68. lsl.l #8, d0
  69. @GetNibble
  70. move.b d6, d0
  71. lsl.l #8, d0
  72. @GetNibble
  73. move.b d6, d0
  74.  
  75. moveq #4-1, d1 ; Go through all ports
  76. @DevLoop:
  77. rol.l #8, d0 ; Get device ID
  78. cmp.b #$01, d0 ; Is there a joypad?
  79. bhi.s @NoDevice
  80.  
  81. @GetNibble ; Read joypad buttons
  82. move.b d6, d2
  83. @GetNibble
  84. lsl.b #4, d6
  85. or.b d6, d2
  86. tst.b d0
  87. beq.s @No6Pad
  88. @GetNibble
  89. @No6Pad:
  90.  
  91. not.b d2 ; Make buttons high logic
  92.  
  93. move.b (a5), d3 ; Update joypad status
  94. move.b d2, (a5)+
  95. not.b d3
  96. and.b d2, d3
  97. move.b d3, (a5)+
  98. bra.s @DeviceParsed
  99.  
  100. @NoDevice:
  101. addq.w #2, a5 ; Skip this joypad
  102.  
  103. @DeviceParsed:
  104. dbf d1, @DevLoop ; Go for next port
  105.  
  106. move.b #$60, (a6) ; Done accessing multitap
  107. movem.l (sp)+, d0-d4 ; Restore registers
  108. rts ; End of subroutine
  109.  
  110. ;----------------------------------------------------------------------------
  111. ; Error handling (i.e. timeout)
  112. ;----------------------------------------------------------------------------
  113.  
  114. @Error:
  115. move.l #0, (Joy1Hold) ; Kill joypad status
  116. move.l #0, (Joy3Hold)
  117. move.b #$60, (a6) ; Done accessing multitap
  118. movem.l (sp)+, d0-d4 ; Restore registers
  119. rts ; End of subroutine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement