bigsprite.z80 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. #define spritetmp 8000h
  2. sprite_width = spritetmp+0
  3. sprite_x = spritetmp+1
  4. sprite_mask0 = spritetmp+2
  5. sprite_mask1 = spritetmp+3
  6. sprite_method = spritetmp+4
  7. rshiftHA_7:
  8. rr h \ rra
  9. rr h \ rra
  10. rr h \ rra
  11. rr h \ rra
  12. rr h \ rra
  13. rr h \ rra
  14. rr h \ rra
  15. ex de,hl
  16. ld e,a
  17. ret
  18. spritemask:
  19. .db $00,$80,$C0,$E0,$F0,$F8,$FC,$FE
  20. call_ix:
  21. jp (ix)
  22. sprite:
  23. ;Inputs:
  24. ; A is the method:
  25. ; 0=Overwrite
  26. ; 1=AND
  27. ; 2=XOR
  28. ; 3=OR
  29. ; 5=Erase
  30. ; B is the X-coordinate
  31. ; C is the Y-Coordinate
  32. ; DE points to the sprite
  33. ; H is the height
  34. ; L is the width
  35. ; (gbuf_temp) is the buffer to which to draw
  36. ld (sprite_method),a
  37. ;First check if the sprite is on-screen in the horizontal direction
  38. ld a,c
  39. cp 64
  40. jr c,+_
  41. add a,h
  42. ret nc
  43. ld h,a
  44. push hl
  45. xor a
  46. ld h,a
  47. sub c
  48. ex de,hl
  49. add hl,de
  50. dec a
  51. jr nz,$-2
  52. ex de,hl
  53. pop hl
  54. xor a
  55. ld c,a
  56. _:
  57. ;Next check h+c<=64
  58. ld a,64
  59. sub c
  60. cp h
  61. jr nc,+_
  62. ld h,a
  63. _:
  64. ;Make sure the height is not now 0
  65. ld a,h
  66. or a
  67. ret z
  68. ;Save the width and height of the sprite
  69. push hl ;height,width
  70. ld h,b
  71. ld (sprite_width),hl ;x,width
  72. push de ;sprite pointer
  73. ;Set up a pointer to the routine for shifting the routine for shifting the sprite data
  74. ld ixh,rshiftHA_7>>8
  75. ld a,h
  76. cpl
  77. and 7
  78. ld l,a
  79. add a,a
  80. add a,l
  81. add a,rshiftHA_7&255
  82. ld ixl,a
  83. #if (rshiftHA_7&255)>234
  84. jr nc,$+4
  85. inc ixh
  86. #endif
  87. ld a,b
  88. and 7
  89. ld de,spritemask
  90. add a,e
  91. ld e,a
  92. #if spritemask&255>248
  93. jr nc,$+3
  94. inc d
  95. #endif
  96. ld a,(de)
  97. ld (sprite_mask0),a
  98. cpl
  99. ld (sprite_mask1),a
  100. ;
  101. ;
  102. ld a,c
  103. add a,a
  104. sbc a,a
  105. ld h,a
  106. ld a,b
  107. ld b,h
  108. ld l,c
  109. add hl,hl
  110. add hl,bc
  111. add hl,hl
  112. add hl,hl
  113. ld c,a
  114. add a,a
  115. sbc a,a
  116. ld b,a
  117. ld a,c
  118. sra c
  119. sra c
  120. sra c
  121. add hl,bc
  122. ld bc,(gbuf_temp)
  123. add hl,bc
  124. pop de
  125. pop bc
  126. ;B is height
  127. ;C is width
  128. ex de,hl
  129. _:
  130. push bc ;height,width
  131. push de ;gbuf ptr
  132. push hl ;sprite data pointer
  133. ld a,(sprite_x)
  134. ld c,a
  135. add a,8
  136. ld (sprite_x),a
  137. call spritemethod
  138. pop hl
  139. inc hl
  140. pop de
  141. inc de
  142. pop bc
  143. dec c
  144. jr nz,-_
  145. ret
  146. spritemethod:
  147. ld a,(sprite_method)
  148. dec a
  149. jp z,spriteloop_AND
  150. dec a
  151. jp z,spriteloop_XOR
  152. dec a
  153. jp z,spriteloop_OR
  154. sub 2
  155. jp z,spriteloop_Erase
  156. spriteloop_Overwrite:
  157. push bc
  158. push hl
  159. ld h,(hl)
  160. xor a
  161. call call_ix
  162. ld a,c
  163. cp 96
  164. jr nc,+_
  165. ld a,(sprite_mask0)
  166. and (hl)
  167. or d
  168. ld (hl),a
  169. ld a,c
  170. _:
  171. inc hl
  172. add a,8
  173. cp 96
  174. jr nc,+_
  175. ld a,(sprite_mask1)
  176. and (hl)
  177. or e
  178. ld (hl),a
  179. _:
  180. ld bc,11
  181. add hl,bc
  182. ex de,hl
  183. pop hl
  184. ld a,(sprite_width)
  185. ld c,a
  186. add hl,bc
  187. pop bc
  188. djnz spriteloop_Overwrite
  189. ret
  190. spriteloop_OR:
  191. push bc
  192. push hl
  193. ld h,(hl)
  194. xor a
  195. call call_ix
  196. ld a,c
  197. cp 96
  198. jr nc,+_
  199. ld a,(hl)
  200. or d
  201. ld (hl),a
  202. ld a,c
  203. _:
  204. inc hl
  205. add a,8
  206. cp 96
  207. jr nc,+_
  208. ld a,(sprite_mask1)
  209. ld a,(hl)
  210. or e
  211. ld (hl),a
  212. _:
  213. ld bc,11
  214. add hl,bc
  215. ex de,hl
  216. pop hl
  217. ld a,(sprite_width)
  218. ld c,a
  219. add hl,bc
  220. pop bc
  221. djnz spriteloop_OR
  222. ret
  223. spriteloop_XOR:
  224. push bc
  225. push hl
  226. ld h,(hl)
  227. xor a
  228. call call_ix
  229. ld a,c
  230. cp 96
  231. jr nc,+_
  232. ld a,(hl)
  233. xor d
  234. ld (hl),a
  235. ld a,c
  236. _:
  237. inc hl
  238. add a,8
  239. cp 96
  240. jr nc,+_
  241. ld a,(sprite_mask1)
  242. ld a,(hl)
  243. xor e
  244. ld (hl),a
  245. _:
  246. ld bc,11
  247. add hl,bc
  248. ex de,hl
  249. pop hl
  250. ld a,(sprite_width)
  251. ld c,a
  252. add hl,bc
  253. pop bc
  254. djnz spriteloop_XOR
  255. ret
  256. spriteloop_AND:
  257. push bc
  258. push hl
  259. ld h,(hl)
  260. scf \ sbc a,a
  261. call call_ix
  262. ld a,c
  263. cp 96
  264. jr nc,+_
  265. ld a,(hl)
  266. and d
  267. ld (hl),a
  268. ld a,c
  269. _:
  270. inc hl
  271. add a,8
  272. cp 96
  273. jr nc,+_
  274. ld a,(sprite_mask1)
  275. ld a,(hl)
  276. and e
  277. ld (hl),a
  278. _:
  279. ld bc,11
  280. add hl,bc
  281. ex de,hl
  282. pop hl
  283. ld a,(sprite_width)
  284. ld c,a
  285. add hl,bc
  286. pop bc
  287. djnz spriteloop_AND
  288. ret
  289. spriteloop_Erase:
  290. push bc
  291. push hl
  292. ld h,(hl)
  293. xor a
  294. call call_ix
  295. ld a,c
  296. cp 96
  297. jr nc,+_
  298. ld a,d
  299. cpl
  300. and (hl)
  301. ld (hl),a
  302. ld a,c
  303. _:
  304. inc hl
  305. add a,8
  306. cp 96
  307. jr nc,+_
  308. ld a,e
  309. cpl
  310. and (hl)
  311. ld (hl),a
  312. _:
  313. ld bc,11
  314. add hl,bc
  315. ex de,hl
  316. pop hl
  317. ld a,(sprite_width)
  318. ld c,a
  319. add hl,bc
  320. pop bc
  321. djnz spriteloop_Erase
  322. ret