Advertisement
LuigiBlood

SNES Mouse BIOS bass code

Dec 18th, 2016
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.77 KB | None | 0 0
  1. arch snes.cpu
  2.  
  3. //*****************************************************
  4. //*
  5. //* mouse.x65
  6. //* Super NES Mouse System file
  7. //* March 11, 1992
  8. //* (c) 1992 Nintendo of America
  9. //*
  10. //* mouse_v100_bass.asm
  11. //* December 18, 2016
  12. //* Modified by LuigiBlood for bass
  13. //*
  14. //*****************************************************
  15.  
  16. //*****************************************************
  17. //*****************************************************
  18. //* Mouse Driver Routine (Ver 1.00)
  19. //*****************************************************
  20. //*****************************************************
  21.  
  22. db "START OF MOUSE BIOS" //do not delete
  23.  
  24. //=====================================================
  25. //* RAM Definition
  26. //=====================================================
  27.  
  28. //Change this to the address you want
  29. define MouseVars $0000
  30.  
  31. define reg0 {MouseVars}+0
  32. define reg0l {reg0}+0 // Work registers
  33. define reg0h {reg0}+1 //
  34.  
  35. define mouse_con {MouseVars}+2
  36. define mouse_con0 {mouse_con}+0 // Mouse connection port D0=4016
  37. define mouse_con1 {mouse_con}+1 // Mouse connection port D0=4017
  38.  
  39. define mouse_sp_set {MouseVars}+4
  40. define mouse_sp_set0 {mouse_sp_set}+0 // Mouse speed setting (joy1)
  41. define mouse_sp_set1 {mouse_sp_set}+1 // Mouse speed setting (joy2)
  42.  
  43. define mouse_sp {MouseVars}+6
  44. define mouse_sp0 {mouse_sp}+0 // Mouse speed (joy1)
  45. define mouse_sp1 {mouse_sp}+1 // Mouse speed (joy2)
  46.  
  47. define mouse_y0 {MouseVars}+8 // Mouse Y direction (joy 1)
  48. define mouse_y1 {MouseVars}+9 // Mouse Y direction (joy 2)
  49. define mouse_x0 {MouseVars}+10 // Mouse X direction (joy 1)
  50. define mouse_x1 {MouseVars}+11 // Mouse X direction (joy 2)
  51.  
  52. define mouse_sw {MouseVars}+12
  53. define mouse_sw0 {mouse_sw}+0 // Mouse button turbo (joy1)
  54. define mouse_sw1 {mouse_sw}+1 // Mouse button turbo (joy2)
  55.  
  56. define mouse_swt {MouseVars}+14
  57. define mouse_swt0 {mouse_swt}+0 // Mouse button trigger (joy1)
  58. define mouse_swt1 {mouse_swt}+1 // Mouse button trigger (joy2)
  59.  
  60. define mouse_sb {MouseVars}+16 // Previous switch status
  61. define mouse_sb0 {mouse_sb}+0 //
  62. define mouse_sb1 {mouse_sb}+1
  63.  
  64. define connect_st0 {MouseVars}+18 // Mouse is connected? (joy1)
  65. define connect_st1 {MouseVars}+19 // Mouse is connected? (joy2)
  66.  
  67. define cursor_x0 {MouseVars}+20 //Cursor X position (joy1)
  68. define cursor_x1 {MouseVars}+22 //Cursor X position (joy2)
  69. define cursor_y0 {MouseVars}+24 //Cursor Y position (joy1)
  70. define cursor_y1 {MouseVars}+26 //Cursor Y position (joy2)
  71.  
  72. //*****************************************************
  73. //=====================================================
  74. //* mouse_read
  75. //=====================================================
  76. //* If this routine is called every frame, then the mouse status will be set to the
  77. //* appropriate registers.
  78. //* INPUT
  79. //* None (Mouse key read automatically)
  80. //* OUTPUT
  81. //* Connection status (mouse_con) D0=1 Mouse connected to Joy1
  82. //* D1=1 Mouse connected to Joy2
  83. //* Switch (mouse_sw0,1) D0=left switch turbo
  84. //* D1=right switch turbo
  85. //* Switch (mouse_swt0,1) D0=left switch trigger
  86. //* D1=right switch trigger
  87. //* Mouse movement (ball) value
  88. //* (mouse_x) D7=0 Positive turn, D7=1 Negative turn
  89. //* D6-D0 X movement value
  90. //* (mouse_y) D7=0 Positive turn, D7=1 Negative turn
  91. //* D6-D0 X movement value
  92. //*****************************************************
  93.  
  94. mouse_read:
  95. php
  96. sep #$30
  97. _10:
  98. lda $4212
  99. and.b #%00000001
  100. bne _10 // Automatic read ok?
  101.  
  102. ldx.b #$01 // Joy2
  103. lda $421a
  104. jsr mouse_data
  105.  
  106. lda {connect_st1}
  107. beq _20
  108.  
  109. jsr speed_change
  110. stz {connect_st1}
  111.  
  112. plp
  113. rts
  114. _20:
  115. dex
  116. lda $4218 // joy1
  117. jsr mouse_data
  118.  
  119. lda {connect_st0}
  120. beq _30
  121.  
  122. jsr speed_change
  123. stz {connect_st0}
  124. _30:
  125. plp
  126. rts
  127.  
  128. mouse_data:
  129. sta {reg0l} //(421a 4218 save to reg0)
  130. and.b #%00001111
  131. cmp.b #$01 // Is the mouse connected?
  132. beq _m10
  133.  
  134. stz {mouse_con0},x // No connection.
  135.  
  136. stz {mouse_x0},x
  137. stz {mouse_y0},x
  138. stz {mouse_sw0},x
  139. stz {mouse_swt0},x
  140. stz {mouse_sb0},x
  141.  
  142. rts
  143. _m10:
  144. lda {mouse_con0},x // When mouse is connected, speed will change.
  145. bne _m20 // Previous connection status
  146. // (mouse.com judged by lower 1 bit)
  147. lda.b #$01 // Connection check flag on
  148. sta {mouse_con0},x
  149. sta {connect_st0},x
  150. rts
  151. _m20:
  152. ldy.b #16 // Read 16 bit data.
  153. _m30:
  154. lda $4016,x
  155. lsr
  156. rol {mouse_x0},x
  157. rol {mouse_y0},x
  158. dey
  159. bne _m30
  160.  
  161. stz {mouse_sw0},x
  162.  
  163. rol {reg0l}
  164. rol {mouse_sw0},x
  165. rol {reg0l}
  166. rol {mouse_sw0},x // Switch turbo
  167.  
  168. lda {mouse_sw0},x
  169. eor {mouse_sb0},x // Get switch trigger
  170. bne _m40
  171.  
  172. stz {mouse_swt0},x
  173.  
  174. rts
  175. _m40:
  176. lda {mouse_sw0},x
  177. sta {mouse_swt0},x
  178. sta {mouse_sb0},x
  179.  
  180. rts
  181.  
  182. //*****************************************************
  183. //=====================================================
  184. //* speed_change
  185. //=====================================================
  186. //* Set speed to mouse_sp_set. Give mouse port the value of x and call this routine.
  187. //* If this routine is called without setting mouse_sp_set, then the previous speed will be assigned to the current speed.
  188. //* Normally, the mouse speed data will be saved to mouse_sp.
  189. //* If the mouse speed cannot be set, then the error code will be set to mouse_sp.
  190. //* INPUT
  191. //* X=connection port (X:0=joy1 1=joy2)
  192. //* MOUSE_SP_SET0= JOY1 setting speed
  193. //* MOUSE_SP_SET1= JOY2 setting speed
  194. //* OUTPUT
  195. //* MOUSE_SP0 = Joy1 Mouse speed
  196. //* (0=slow, 1=medium, 2=fast, $80=error code)
  197. //* MOUSE_SP1 = Joy2 Mouse speed
  198. //* (0=slow, 1=medium, 2=fast, $80=error code)
  199. //*****************************************************
  200.  
  201. speed_change:
  202. php
  203. sep #$30
  204.  
  205. lda {mouse_con},x
  206. beq _s25
  207.  
  208. lda.b #$10
  209. sta {reg0h}
  210. _s10:
  211. lda.b #$01
  212. sta $4016
  213. lda $4016,x // Speed change (1 step).
  214. stz $4016
  215.  
  216. lda.b #$01 // Read speed data.
  217. sta $4016 // Shift register clear.
  218. lda.b #$00
  219. sta $4016
  220.  
  221. sta {mouse_sp0},x // Speed register clear.
  222.  
  223. ldy.b #$0a // Shift register read has no meaning.
  224. _s20:
  225. lda $4016,x
  226. dey
  227. bne _s20
  228.  
  229. lda $4016,x // Read speed
  230. lsr
  231. rol {mouse_sp0},x
  232.  
  233. lda $4016,x
  234.  
  235. lsr
  236. rol {mouse_sp0},x
  237. lda {mouse_sp0},x
  238.  
  239. cmp {mouse_sp_set0},x //Set speed or not?
  240. beq _s30
  241.  
  242. dec {reg0h} // For error check
  243. bne _s10
  244. _s25:
  245. lda #$80 // Speed change error
  246. sta {mouse_sp0},x
  247. _s30:
  248. plp
  249. rts
  250.  
  251. //*****************************************************
  252. //=====================================================
  253. //* cursor_update
  254. //=====================================================
  255. //* Call this routine after mouse_read, calculates the cursor position.
  256. //* Use the position as cursor coordinates.
  257. //* Minimum and Maximum X and Y positions are set by min_x,y and max_x,y.
  258. //* Based on Sound Factory prototype mouse code.
  259. //* Destroys the data of A and Y.
  260. //*
  261. //* INPUT
  262. //* X=connection port (X:0=joy1 1=joy2)
  263. //* OUTPUT
  264. //* Cursor X Position (cursor_x0,1)
  265. //* Cursor Y Position (cursor_y0,1)
  266. //*****************************************************
  267.  
  268. define min_x #$0001 //Minimum X position
  269. define min_y #$0001 //Minimum Y position
  270. define max_x #$00F4 //Maximum X position
  271. define max_y #$00D6 //Maximum Y position
  272.  
  273. cursor_update:
  274. php
  275. sep #$30
  276. txa
  277. rol
  278. tay
  279.  
  280. _xcursor:
  281. sep #$20
  282. lda {mouse_x0},x
  283. bmi _xcursor_minus
  284. xba
  285. lda.b #$00
  286. bra _xcursor_check
  287. _xcursor_minus:
  288. eor.b #$7f
  289. inc
  290. xba
  291. lda.b #$ff
  292. _xcursor_check:
  293. xba
  294. rep #$20
  295. clc
  296. adc {cursor_x0},y
  297. bpl _xcursorpos_greater
  298. lda #$0000
  299. _xcursorpos_greater:
  300. cmp {max_x}
  301. bcc _xcursorpos_lower
  302. lda {max_x}-1
  303. _xcursorpos_lower:
  304. cmp {min_x}
  305. bcs _xcursor_update
  306. lda {min_x}+1
  307. _xcursor_update:
  308. sta {cursor_x0},y
  309.  
  310. _ycursor:
  311. sep #$20
  312. lda {mouse_y0},x
  313. bmi _ycursor_minus
  314. xba
  315. lda.b #$00
  316. bra _ycursor_check
  317. _ycursor_minus:
  318. eor.b #$7f
  319. inc
  320. xba
  321. lda.b #$ff
  322. _ycursor_check:
  323. xba
  324. rep #$20
  325. clc
  326. adc {cursor_y0},y
  327. bpl _ycursorpos_greater
  328. lda #$0000
  329. _ycursorpos_greater:
  330. cmp {max_y}
  331. bcc _ycursorpos_lower
  332. lda {max_y}-1
  333. _ycursorpos_lower:
  334. cmp {min_y}
  335. bcs _ycursor_update
  336. lda {min_y}+1
  337. _ycursor_update:
  338. sta {cursor_y0},y
  339.  
  340. plp
  341. rts
  342.  
  343.  
  344. //db "NINTENDO SNES MOUSE BIOS Ver1.00"
  345. db "BASS MODIFIED FROM SNES MOUSE BIOS Ver1.00"
  346.  
  347. //If user modifies program, then change to
  348. //"MODIFIED FROM SNES MOUSE BIOS Ver1.00"
  349. db "END OF MOUSE BIOS"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement