sprites.s 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. IFND NOLINK
  2. FUNC_SPRITES = 1
  3. ; include custom.i
  4. ; include myheader.i
  5. ; INCLUDE funcs.f
  6. ENDC
  7. *****************************************************************************
  8. * Both the blitter and the processor sprite *
  9. * routines use d0-d7 a0 & a1 *
  10. * the blitter version also uses a2 *
  11. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
  12. *****************************************************************************
  13. SPRITE_SCREEN_WIDTH = SCREEN_WIDTH
  14. *****************************************************************************
  15. xdef _s8_draw
  16. _s8_draw
  17. rts
  18. *****************************************************************************
  19. * d0 = x d1 = y d2 = height a0 = the screen a1 = source *
  20. *****************************************************************************
  21. xdef _s16_draw
  22. _s16_draw ;
  23. move.w d2,d7 *1 calculate the plane size
  24. add.w d7,d7 *2
  25. tst.w d1 is y less than 0
  26. bge.s .y_not_minus no, ok.
  27. ******************************************************************************
  28. * QY is negative
  29. neg.w d1
  30. sub.w d1,d2 do we see any of it ?
  31. ble .not_drawn no, dont draw the thing at all
  32. ; a 16 pixel wide sprite has 2 bytes a line, so we have to multiply by 2
  33. add.w d1,d1 *2
  34. adda.w d1,a1 move into the source the required no. of lines
  35. bra.s .y_clipped
  36. *********
  37. .y_not_minus
  38. move.w lines_high(pc),d6
  39. cmp.w d6,d1
  40. bge .not_drawn
  41. IFNE SCREEN_WIDTH-40
  42. fail 'sorry, SCREEN_WIDTH changed you gotta re-write this bit'
  43. ENDC
  44. move.w d1,d3
  45. add.w d3,d3 *2
  46. add.w d3,d3 *4
  47. add.w d1,d3 *5
  48. lsl.w #3,d3 *8*5 = *40
  49. adda.w d3,a0 move down the screen
  50. add.w d2,d1
  51. sub.w d6,d1
  52. blt.s .y_clipped
  53. sub.w d1,d2 adjust height of sprite to fit the fucker on
  54. .y_clipped
  55. *****************************************************************************
  56. * I suppose I better do the QX stuff now
  57. tst.w d0
  58. bge.s .x_not_minus x ok, well at least it isn't negative!
  59. cmpi.w #-16,d0
  60. ble.s .not_drawn it is off screen
  61. bra blit_left_16
  62. .x_not_minus
  63. move.w d0,d3
  64. andi.w #$f,d0 just the shift
  65. * we want . . . 0-15 ->0, 16-31->2 etc.........
  66. eor.w d0,d3 all but the shift
  67. lsr.w #3,d3 AMIGA
  68. move.w sprite_screen_width(pc),d6 """""
  69. cmp.w d6,d3 is it off the right side of the screen ?
  70. bge.s .not_drawn yes
  71. adda.w d3,a0 adjust destination
  72. subq.w #2,d6 AMIGA
  73. cmp.w d6,d3
  74. bne blit_mid_16
  75. * right hand only case
  76. moveq #0,d1
  77. bra blit_right_16
  78. .not_drawn
  79. rts
  80. ;left_gone BLTCON0 BLTCON1 BLTAFWM BLTALWM
  81. left16lu
  82. dc.w $0fca, $0000, $0000, $0000
  83. dc.w $1fca, $1000, $0001, $0000
  84. dc.w $2fca, $2000, $0003, $0000
  85. dc.w $3fca, $3000, $0007, $0000
  86. dc.w $4fca, $4000, $000f, $0000
  87. dc.w $5fca, $5000, $001f, $0000
  88. dc.w $6fca, $6000, $003f, $0000
  89. dc.w $7fca, $7000, $007f, $0000
  90. dc.w $8fca, $8000, $00ff, $0000
  91. dc.w $9fca, $9000, $01ff, $0000
  92. dc.w $afca, $a000, $03ff, $0000
  93. dc.w $bfca, $b000, $07ff, $0000
  94. dc.w $cfca, $c000, $0fff, $0000
  95. dc.w $dfca, $d000, $1fff, $0000
  96. dc.w $efca, $e000, $3fff, $0000
  97. dc.w $ffca, $f000, $7fff, $0000
  98. blit_left_16
  99. subq.l #2,a0
  100. andi.w #$f,d0
  101. lsl.w #3,d0 shifted for lookup
  102. lea left16lu,a2
  103. movem.l (a2,d0.w),d0/d1
  104. movem.l d0/d1,(BLTCON0).l
  105. move.w #-2,(BLTAMOD).l
  106. move.w #-2,(BLTBMOD).l
  107. move.w #SCREEN_WIDTH-4,(BLTCMOD).l
  108. move.w #SCREEN_WIDTH-4,(BLTDMOD).l
  109. lsl.w #6,d2
  110. addq.w #4/2,d2
  111. bra blit_sprite
  112. right_16_lu
  113. ;right_gone BLTCON0 BLTCON1 BLTAFWM BLTALWM 2 less on the width
  114. dc.w $0fca, $0000, $ffff, $ffff
  115. dc.w $1fca, $1000, $ffff, $fffe
  116. dc.w $2fca, $2000, $ffff, $fffc
  117. dc.w $3fca, $3000, $ffff, $fff8
  118. dc.w $4fca, $4000, $ffff, $fff0
  119. dc.w $5fca, $5000, $ffff, $ffe0
  120. dc.w $6fca, $6000, $ffff, $ffc0
  121. dc.w $7fca, $7000, $ffff, $ff80
  122. dc.w $8fca, $8000, $ffff, $ff00
  123. dc.w $9fca, $9000, $ffff, $fe00
  124. dc.w $afca, $a000, $ffff, $fc00
  125. dc.w $bfca, $b000, $ffff, $f800
  126. dc.w $cfca, $c000, $ffff, $f000
  127. dc.w $dfca, $d000, $ffff, $e000
  128. dc.w $efca, $e000, $ffff, $c000
  129. dc.w $ffca, $f000, $ffff, $8000
  130. blit_right_16
  131. andi.w #$f,d0
  132. lsl.w #3,d0 shifted for lookup
  133. lea right_16_lu,a2
  134. movem.l (a2,d0.w),d0/d1
  135. movem.l d0/d1,(BLTCON0).l
  136. move.w #0,(BLTAMOD).l
  137. move.w #0,(BLTBMOD).l
  138. move.w #SCREEN_WIDTH-2,(BLTCMOD).l
  139. move.w #SCREEN_WIDTH-2,(BLTDMOD).l
  140. lsl.w #6,d2
  141. addq.w #2/2,d2
  142. bra blit_sprite
  143. rts
  144. ;mid screen BLTCON0 BLTCON1 BLTAFWM BLTALWM
  145. mid16lu
  146. dc.w $0fca, $0000, $ffff, $0000
  147. dc.w $1fca, $1000, $ffff, $0000
  148. dc.w $2fca, $2000, $ffff, $0000
  149. dc.w $3fca, $3000, $ffff, $0000
  150. dc.w $4fca, $4000, $ffff, $0000
  151. dc.w $5fca, $5000, $ffff, $0000
  152. dc.w $6fca, $6000, $ffff, $0000
  153. dc.w $7fca, $7000, $ffff, $0000
  154. dc.w $8fca, $8000, $ffff, $0000
  155. dc.w $9fca, $9000, $ffff, $0000
  156. dc.w $afca, $a000, $ffff, $0000
  157. dc.w $bfca, $b000, $ffff, $0000
  158. dc.w $cfca, $c000, $ffff, $0000
  159. dc.w $dfca, $d000, $ffff, $0000
  160. dc.w $efca, $e000, $ffff, $0000
  161. dc.w $ffca, $f000, $ffff, $0000
  162. blit_mid_16
  163. lsl.w #3,d0 shifted for lookup
  164. lea mid16lu,a2
  165. movem.l (a2,d0.w),d0/d1
  166. movem.l d0/d1,(BLTCON0).l
  167. move.w #-2,(BLTAMOD).l
  168. move.w #-2,(BLTBMOD).l
  169. move.w #SCREEN_WIDTH-4,(BLTCMOD).l
  170. move.w #SCREEN_WIDTH-4,(BLTDMOD).l
  171. lsl.w #6,d2
  172. addq.w #4/2,d2
  173. bra blit_sprite
  174. *****************************************************************************
  175. xdef _s32_draw
  176. _s32_draw ;
  177. ; move.w #$707,(COLOR).l
  178. move.w d2,d7 *1 calculate the plane size
  179. add.w d7,d7 *2
  180. add.w d7,d7 *4
  181. tst.w d1 is y less than 0
  182. bge.s .y_not_minus no, ok.
  183. ******************************************************************************
  184. * QY is negative
  185. neg.w d1
  186. sub.w d1,d2 do we see any of it ?
  187. ble .not_drawn no, dont draw the thing at all
  188. ; a 32 pixel wide sprite has 4 bytes a line, so we have to multiply by 4
  189. add.w d1,d1 *2
  190. add.w d1,d1 *4
  191. adda.w d1,a1 move into the source the required no. of lines
  192. bra.s .y_clipped
  193. *********
  194. .y_not_minus
  195. move.w lines_high(pc),d6
  196. cmp.w d6,d1
  197. bge .not_drawn
  198. IFNE SCREEN_WIDTH-40
  199. fail 'sorry, SCREEN_WIDTH changed you gotta re-write this bit'
  200. ENDC
  201. move.w d1,d3
  202. add.w d3,d3 *2
  203. add.w d3,d3 *4
  204. add.w d1,d3 *5
  205. lsl.w #3,d3 *8*5 = *40
  206. adda.w d3,a0 move down the screen
  207. add.w d2,d1
  208. sub.w d6,d1
  209. blt.s .y_clipped
  210. sub.w d1,d2 adjust height of sprite to fit the fucker on
  211. .y_clipped
  212. *****************************************************************************
  213. * I suppose I better do the X stuff now
  214. tst.w d0
  215. bge.s .x_not_minus x ok, well at least it isn't negative!
  216. cmpi.w #-32,d0
  217. ble.s .not_drawn it is off screen
  218. cmpi.w #-16,d0
  219. blt blit_left_32_lt16
  220. bra blit_left_32_gt16
  221. .x_not_minus
  222. move.w d0,d3
  223. andi.w #$f,d0 just the shift
  224. * we want . . . 0-15 ->0, 16-31->2 etc.........
  225. eor.w d0,d3 all but the shift
  226. lsr.w #3,d3
  227. adda.w d3,a0 adjust destination
  228. move.w sprite_screen_width(pc),d6 """""
  229. subq.w #6,d6
  230. cmp.w d6,d3 is it definately on screen ?
  231. ble blit_mid_32 yes
  232. addq.w #2,d6
  233. cmp.w d6,d3 is it mostly on screen ?
  234. ble blit_right_32_gt16 yes
  235. addq.w #2,d6
  236. cmp.w d6,d3 is it partly on screen ?
  237. ble blit_right_32_lt16 yes
  238. .not_drawn
  239. rts
  240. blit_right_32_gt16
  241. andi.w #$f,d0
  242. lsl.w #3,d0 shifted for lookup
  243. lea right_16_lu,a2
  244. movem.l (a2,d0.w),d0/d1
  245. movem.l d0/d1,(BLTCON0).l
  246. move.w #0,(BLTAMOD).l
  247. move.w #0,(BLTBMOD).l
  248. move.w #SCREEN_WIDTH-4,(BLTCMOD).l
  249. move.w #SCREEN_WIDTH-4,(BLTDMOD).l
  250. lsl.w #6,d2
  251. addq.w #4/2,d2
  252. bra blit_sprite
  253. rts
  254. blit_right_32_lt16
  255. andi.w #$f,d0
  256. lsl.w #3,d0 shifted for lookup
  257. lea right_16_lu,a2
  258. movem.l (a2,d0.w),d0/d1
  259. movem.l d0/d1,(BLTCON0).l
  260. move.w #2,(BLTAMOD).l
  261. move.w #2,(BLTBMOD).l
  262. move.w #SCREEN_WIDTH-2,(BLTCMOD).l
  263. move.w #SCREEN_WIDTH-2,(BLTDMOD).l
  264. lsl.w #6,d2
  265. addq.w #2/2,d2
  266. bra blit_sprite
  267. rts
  268. blit_left_32_lt16
  269. subq.l #2,a0
  270. addq.l #2,a1
  271. andi.w #$f,d0
  272. lsl.w #3,d0 shifted for lookup
  273. lea left16lu,a2
  274. movem.l (a2,d0.w),d0/d1
  275. movem.l d0/d1,(BLTCON0).l
  276. move.w #0,(BLTAMOD).l
  277. move.w #0,(BLTBMOD).l
  278. move.w #SCREEN_WIDTH-4,(BLTCMOD).l
  279. move.w #SCREEN_WIDTH-4,(BLTDMOD).l
  280. lsl.w #6,d2
  281. addq.w #4/2,d2
  282. bra blit_sprite
  283. blit_left_32_gt16
  284. subq.l #2,a0
  285. andi.w #$f,d0
  286. lsl.w #3,d0 shifted for lookup
  287. lea left16lu,a2
  288. movem.l (a2,d0.w),d0/d1
  289. movem.l d0/d1,(BLTCON0).l
  290. move.w #-2,(BLTAMOD).l
  291. move.w #-2,(BLTBMOD).l
  292. move.w #SCREEN_WIDTH-6,(BLTCMOD).l
  293. move.w #SCREEN_WIDTH-6,(BLTDMOD).l
  294. lsl.w #6,d2
  295. addq.w #6/2,d2
  296. bra blit_sprite
  297. rts
  298. blit_mid_32
  299. lsl.w #3,d0 shifted for lookup
  300. lea mid16lu,a2
  301. movem.l (a2,d0.w),d0/d1
  302. movem.l d0/d1,(BLTCON0).l
  303. move.w #-2,(BLTAMOD).l
  304. move.w #-2,(BLTBMOD).l
  305. move.w #SCREEN_WIDTH-6,(BLTCMOD).l
  306. move.w #SCREEN_WIDTH-6,(BLTDMOD).l
  307. lsl.w #6,d2
  308. addq.w #6/2,d2
  309. blit_sprite *****************************************************************
  310. * a0-> screen address; a1-> sprite data; d2 = blitsize; d7 = planesize *
  311. * mods, cons & endmasks are set up *
  312. *****************************************************************************
  313. BLIT_NASTY
  314. ; move.w #$ff0,(COLOR).l
  315. lea (a1,d7.w),a2
  316. move.l a0,(BLTCPT).l dest as source
  317. move.l a0,(BLTDPT).l dest
  318. move.l a2,(BLTBPT).l source
  319. move.l a1,(BLTAPT).l template
  320. move.w d2,(BLTSIZE).l plane 0
  321. ; wait_blit
  322. add.w d7,a2 next plane of source
  323. lea PLANE_SIZE(a0),a0 next plane of screen
  324. move.l a0,(BLTCPT).l dest as source
  325. move.l a0,(BLTDPT).l dest
  326. move.l a2,(BLTBPT).l source
  327. move.l a1,(BLTAPT).l template
  328. move.w d2,(BLTSIZE).l plane 1
  329. ; wait_blit
  330. add.w d7,a2 next plane of source
  331. lea PLANE_SIZE(a0),a0 next plane of screen
  332. move.l a0,(BLTCPT).l dest as source
  333. move.l a0,(BLTDPT).l dest
  334. move.l a2,(BLTBPT).l source
  335. move.l a1,(BLTAPT).l template
  336. move.w d2,(BLTSIZE).l plane 2
  337. ; wait_blit
  338. add.w d7,a2 next plane of source
  339. lea PLANE_SIZE(a0),a0 next plane of screen
  340. move.l a0,(BLTCPT).l dest as source
  341. move.l a0,(BLTDPT).l dest
  342. move.l a2,(BLTBPT).l source
  343. move.l a1,(BLTAPT).l template
  344. move.w d2,(BLTSIZE).l plane 3
  345. ; wait_blit
  346. BLIT_NICE
  347. ; move.w #0,(COLOR).l
  348. rts
  349. *
  350. xdef lines_high
  351. lines_high dc.w 200
  352. xdef sprite_screen_width
  353. sprite_screen_width dc.w 40