Advertisement
Guest User

custom sprite clipping patch

a guest
Apr 7th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.06 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;
  3. ;; Custom Sprite Clipping Patch, by imamelia
  4. ;;
  5. ;; This patch allows you to give a sprite any size interaction field you want. You simply have
  6. ;; to set the sprite clipping in the .cfg file to 3C, 3D, 3E, or 3F, depending on what you want
  7. ;; to do:
  8. ;;
  9. ;; - 3C will make the sprite use clipping values from tables in ROM.
  10. ;; - 3D will make the sprite use clipping values from tables in RAM.
  11. ;; - 3E is currently unused. Do not use.
  12. ;; - 3F is currently unused. Do not use.
  13. ;;
  14. ;; Instructions for use:
  15. ;;
  16. ;; If you want to set the clipping values in tables beforehand (in ROM)...
  17. ;;
  18. ;; 1) Set up the clipping values in the four tables below, if you choose to use them.
  19. ;; SprClipXDisp is for the X displacement of the clipping field, SprClipYDisp is for
  20. ;; the Y displacement, SprClipWidth is how wide the clipping field is, and SprClipHeight
  21. ;; is how tall it is. Each byte in a table represents one custom clipping value; the first
  22. ;; byte is for custom clipping 00, the second is for custom clipping 01, etc.
  23. ;; 2) Use a text editor or the .cfg editor (mikeyk's won't work; use Romi's) to set the sprite
  24. ;; clipping index to 3C. (The .cfg editor will tell you where this is.)
  25. ;; 3) Within the custom sprite code, store the custom clipping value to !RAM_CustSprClip,x.
  26. ;; For instance, if you want the sprite to use custom clipping value 05, put
  27. ;; LDA #$05
  28. ;; STA !RAM_CustSprClip
  29. ;; in the sprite's init routine. (Make sure you actually have that define in the sprite or in an
  30. ;; incsrc file, or you'll get assembling errors.)
  31. ;;
  32. ;; If you want to set the clipping values manually in the sprite code (in RAM)...
  33. ;;
  34. ;; 1) Use a text editor or Romi's .cfg editor to set the sprite's clipping index to 3D.
  35. ;; 2) In the sprite code (can be in the init routine if the values never change), set up the four
  36. ;; clipping variables. Store the X displacement of the clipping field to !RAM_SprClipXDisp,
  37. ;; the Y displacement to !RAM_SprClipYDisp, the width to !RAM_SprClipWidth, and the height
  38. ;; to !RAM_SprClipHeight. Note that you have to actually have these defines in the sprite code
  39. ;; (if you put them in as defines), or you will get assembling errors.
  40. ;;
  41. ;; A note about the default RAM addresses:
  42. ;;
  43. ;; You may or may not be wondering why I picked $7FAB70, $7FABAA, $7FABB6, $7FABC2,
  44. ;; and $7FABCE for the default addresses. Well, since all the RAM addresses mikeyk originally
  45. ;; used for custom sprites were in the $7FABxx range, I figured we should stick to the same area
  46. ;; when adding new custom sprite tables. I used to have plans for $7FAB40, $7FAB4C, $7FAB58,
  47. ;; and $7FAB64 already, so $7FAB70 was the next table. (I'd use $7FAB7C for custom object
  48. ;; clipping.) That's why the sprite clipping index is $7FAB70,x by default. The other four tables
  49. ;; follow a similar logic; $7FAB9E,x was the last chunk of $7FABxx RAM used for a sprite table,
  50. ;; so the next four would be $7FABAA,x, $7FABB6,x, $7FABC2,x, and $7FABCE,x.
  51. ;;
  52. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  53.  
  54. header
  55. lorom
  56.  
  57. !RAM_CustSprClip = $7FAB70 ; 12 bytes of free RAM used for the custom sprite clipping value
  58. !RAM_SprClipXDisp = $7FABAA ; 12 bytes of free RAM used for the X displacement of a custom sprite clipping field
  59. !RAM_SprClipYDisp = $7FABB6 ; 12 bytes of free RAM used for the Y displacement of a custom sprite clipping field
  60. !RAM_SprClipWidth = $7FABC2 ; 12 bytes of free RAM used for the width of a custom sprite clipping field
  61. !RAM_SprClipHeight = $7FABCE ; 12 bytes of free RAM used for the height of a custom sprite clipping field
  62. ; See below for SA-1 addresses.
  63.  
  64. !bank = $800000 ; do not change these
  65. !addr = $0000
  66. !E4 = $E4
  67. !14E0 = $14E0
  68. !D8 = $D8
  69. !14D4 = $14D4
  70.  
  71. if read1($00ffd5) == $23
  72. sa1rom
  73.  
  74. !RAM_CustSprClip = $6000 ; 22 bytes of free RAM used for the custom sprite clipping value
  75. !RAM_SprClipXDisp = $6099 ; 22 bytes of free RAM used for the X displacement of a custom sprite clipping field
  76. !RAM_SprClipYDisp = $60AF ; 22 bytes of free RAM used for the Y displacement of a custom sprite clipping field
  77. !RAM_SprClipWidth = $60C5 ; 22 bytes of free RAM used for the width of a custom sprite clipping field
  78. !RAM_SprClipHeight = $60F1 ; 22 bytes of free RAM used for the height of a custom sprite clipping field
  79.  
  80. !bank = $000000 ; do not change these
  81. !addr = $6000
  82. !E4 = $322C
  83. !14E0 = $326E
  84. !D8 = $3216
  85. !14D4 = $3258
  86.  
  87. endif
  88.  
  89. org $03B6AA
  90. autoclean JML SprClipHack1
  91.  
  92. org $03B6F0
  93. autoclean JML SprClipHack2
  94.  
  95. freecode
  96.  
  97. SprClipXDisp:
  98. db $03,$00,$00,$00,$00,$00,$00,$00 ; custom sprite clipping values 00-07
  99. db $00,$00,$00,$00,$00,$00,$00,$00 ; custom sprite clipping values 08-0F
  100. ; you can insert more here, up to FF
  101.  
  102. SprClipYDisp:
  103. db $03,$00,$00,$00,$00,$00,$00,$00 ; custom sprite clipping values 00-07
  104. db $00,$00,$00,$00,$00,$00,$00,$00 ; custom sprite clipping values 08-0F
  105. ; you can insert more here, up to FF
  106.  
  107. SprClipWidth:
  108. db $20,$00,$00,$00,$00,$00,$00,$00 ; custom sprite clipping values 00-07
  109. db $00,$00,$00,$00,$00,$00,$00,$00 ; custom sprite clipping values 08-0F
  110. ; you can insert more here, up to FF
  111.  
  112. SprClipHeight:
  113. db $35,$00,$00,$00,$00,$00,$00,$00 ; custom sprite clipping values 00-07
  114. db $00,$00,$00,$00,$00,$00,$00,$00 ; custom sprite clipping values 08-0F
  115. ; you can insert more here, up to FF
  116.  
  117. SprClipHack1:
  118.  
  119. CPX #$3C ; if the clipping index is 3C or greater...
  120. BCS CustomSprClip1 ; then use the custom clipping routines
  121. LDA $03B56C|!bank,x ; else, load the normal clipping table values
  122. JML $03B6AE|!bank ;
  123.  
  124. CustomSprClip1: ;
  125.  
  126. BEQ .UseROMTables ; if X = 3C, then use the ROM tables
  127. CPX #$3D ;
  128. BEQ .UseRAMTables ; if X = 3D, then use the RAM tables
  129.  
  130. LDA $03B56C|!bank,x ; else, load the normal clipping table values
  131. JML $03B6AE|!bank ;
  132.  
  133. .UseROMTables ;
  134. PHB ;
  135. PHK ;
  136. PLB ;
  137. LDX $15E9|!addr ; get the sprite index into X
  138. LDA !RAM_CustSprClip,x ;
  139. TAY ; and the clipping index into Y
  140. JSR GetCustSprClipA1 ;
  141. PLB ;
  142. PLX ;
  143. PLY ;
  144. RTL ;
  145.  
  146. .UseRAMTables ;
  147. PHB ;
  148. PHK ;
  149. PLB ;
  150. LDX $15E9|!addr ; get the sprite index into X
  151. JSR GetCustSprClipA2 ;
  152. PLB ;
  153. PLX ;
  154. PLY ;
  155. RTL ;
  156.  
  157. SprClipHack2:
  158.  
  159. CPX #$3C ; if the clipping index is 3C or greater...
  160. BCS CustomSprClip2 ; then use the custom clipping routines
  161. LDA $03B56C|!bank,x ; else, load the normal clipping table values
  162. JML $03B6F4|!bank ;
  163.  
  164. CustomSprClip2: ;
  165.  
  166. BEQ .UseROMTables ; if X = 3C, then use the ROM tables
  167. CPX #$3D ;
  168. BEQ .UseRAMTables ; if X = 3D, then use the RAM tables
  169.  
  170. LDA $03B56C|!bank,x ; else, load the normal clipping table values
  171. JML $03B6AE|!bank ;
  172.  
  173. .UseROMTables ;
  174. PHB ;
  175. PHK ;
  176. PLB ;
  177. LDX $15E9|!addr ; get the sprite index into X
  178. LDA !RAM_CustSprClip,x ;
  179. TAY ; and the clipping index into Y
  180. JSR GetCustSprClipB1 ;
  181. PLB ;
  182. PLX ;
  183. PLY ;
  184. RTL ;
  185.  
  186. .UseRAMTables ;
  187. PHB ;
  188. PHK ;
  189. PLB ;
  190. LDX $15E9|!addr ; get the sprite index into X
  191. JSR GetCustSprClipB2 ;
  192. PLB ;
  193. PLX ;
  194. PLY ;
  195. RTL ;
  196.  
  197. GetCustSprClipA1: ;
  198.  
  199. STZ $0F ;
  200. LDA.w SprClipXDisp,y ;
  201. BPL $02 ;
  202. DEC $0F ;
  203. CLC ;
  204. ADC !E4,x ;
  205. STA $04 ; $04 = sprite X position low byte + X displacement value
  206. LDA !14E0,x ;
  207. ADC $0F ;
  208. STA $0A ; $0A = sprite X position high byte + X displacement high byte (00 or FF)
  209. LDA.w SprClipWidth,y ;
  210. STA $06 ; $06 = sprite clipping width (a little less than 16 pixels)
  211. STZ $0F ;
  212. LDA.w SprClipYDisp,y ;
  213. BPL $02 ;
  214. DEC $0F ;
  215. CLC ;
  216. ADC !D8,x ;
  217. STA $05 ; $05 = sprite Y position low byte + Y displacement value
  218. LDA !14D4,x ;
  219. ADC $0F ;
  220. STA $0B ; $0B = sprite Y position high byte + Y displacement high byte (00 or FF)
  221. LDA.w SprClipHeight,y ;
  222. STA $07 ; $07 = sprite clipping height
  223. RTS ;
  224.  
  225. GetCustSprClipB1: ;
  226.  
  227. STZ $0F ;
  228. LDA.w SprClipXDisp,y ;
  229. BPL $02 ;
  230. DEC $0F ;
  231. CLC ;
  232. ADC !E4,x ;
  233. STA $00 ; $00 = sprite X position low byte + X displacement value
  234. LDA !14E0,x ;
  235. ADC $0F ;
  236. STA $08 ; $08 = sprite X position high byte + X displacement high byte (00 or FF)
  237. LDA.w SprClipWidth,y ;
  238. STA $02 ; $02 = sprite clipping width (a little less than 16 pixels)
  239. STZ $0F ;
  240. LDA.w SprClipYDisp,y ;
  241. BPL $02 ;
  242. DEC $0F ;
  243. CLC ;
  244. ADC !D8,x ;
  245. STA $01 ; $01 = sprite Y position low byte + Y displacement value
  246. LDA !14D4,x ;
  247. ADC $0F ;
  248. STA $09 ; $09 = sprite Y position high byte + Y displacement high byte (00 or FF)
  249. LDA.w SprClipHeight,y ;
  250. STA $03 ; $03 = sprite clipping height
  251. RTS ;
  252.  
  253. GetCustSprClipA2: ;
  254.  
  255. STZ $0F ;
  256. LDA !RAM_SprClipXDisp,x ;
  257. BPL $02 ;
  258. DEC $0F ;
  259. CLC ;
  260. ADC !E4,x ;
  261. STA $04 ; $04 = sprite X position low byte + X displacement value
  262. LDA !14E0,x ;
  263. ADC $0F ;
  264. STA $0A ; $0A = sprite X position high byte + X displacement high byte (00 or FF)
  265. LDA !RAM_SprClipWidth,x ;
  266. STA $06 ; $06 = sprite clipping width (a little less than 16 pixels)
  267. STZ $0F ;
  268. LDA !RAM_SprClipYDisp,x ;
  269. BPL $02 ;
  270. DEC $0F ;
  271. CLC ;
  272. ADC !D8,x ;
  273. STA $05 ; $05 = sprite Y position low byte + Y displacement value
  274. LDA !14D4,x ;
  275. ADC $0F ;
  276. STA $0B ; $0B = sprite Y position high byte + Y displacement high byte (00 or FF)
  277. LDA !RAM_SprClipHeight,x ;
  278. STA $07 ; $07 = sprite clipping height
  279. RTS ;
  280.  
  281. GetCustSprClipB2: ;
  282.  
  283. STZ $0F ;
  284. LDA !RAM_SprClipXDisp,x ;
  285. BPL $02 ;
  286. DEC $0F ;
  287. CLC ;
  288. ADC !E4,x ;
  289. STA $00 ; $00 = sprite X position low byte + X displacement value
  290. LDA !14E0,x ;
  291. ADC $0F ;
  292. STA $08 ; $08 = sprite X position high byte + X displacement high byte (00 or FF)
  293. LDA !RAM_SprClipWidth,x ;
  294. STA $02 ; $02 = sprite clipping width (a little less than 16 pixels)
  295. STZ $0F ;
  296. LDA !RAM_SprClipYDisp,x ;
  297. BPL $02 ;
  298. DEC $0F ;
  299. CLC ;
  300. ADC !D8,x ;
  301. STA $01 ; $01 = sprite Y position low byte + Y displacement value
  302. LDA !14D4,x ;
  303. ADC $0F ;
  304. STA $09 ; $09 = sprite Y position high byte + Y displacement high byte (00 or FF)
  305. LDA !RAM_SprClipHeight,x ;
  306. STA $03 ; $03 = sprite clipping height
  307. RTS ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement