rect.z80 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. ;Issues:
  2. ; For the ones with border and fill different, need to actually check the top and bottom border weren't clipped
  3. ; Status is stored at TempWord1+1, just not used yet.
  4. #define rightbordermask TempWord2
  5. #define leftbordermask TempWord2+1
  6. #define toprightmask TempWord3
  7. #define topleftmask TempWord3+1
  8. rect:
  9. ;Inputs:
  10. ; A is the type of rectangle to draw
  11. ; 0 =White
  12. ; 1 =Black
  13. ; 2 =XOR
  14. ; 3 =Black border
  15. ; 4 =White border
  16. ; 5 =XOR border
  17. ; 6 =Black border, white inside
  18. ; 7 =Black border, XOR inside
  19. ; 8 =White border, black inside
  20. ; 9 =White border, XOR inside
  21. ; 10=Shift Up
  22. ; 11=Shift Down
  23. ; B is the height
  24. ; C is the Y pixel coordinate
  25. ; D is the width in pixels
  26. ; E is is the X pixel coordinate
  27. ;Need to generate a top/bottom left and right mask
  28. ;Need to generate a left and right mask
  29. ld (TempWord1),a ;saving the method
  30. ld a,e
  31. and 7
  32. ld hl,spritemask
  33. add a,l
  34. ld l,a
  35. #if spritemask&255>248
  36. jr nc,$+3
  37. inc h
  38. #endif
  39. cpl
  40. ld (topleftmask),a
  41. ld l,a
  42. rra
  43. xor l
  44. ld (leftbordermask),a
  45. ld a,e
  46. add a,d
  47. cpl
  48. and 7
  49. #if spritemask&255>248
  50. ld hl,spritemask
  51. add a,l
  52. ld l,a
  53. jr nc,$+3
  54. inc h
  55. #else
  56. add a,spritemask&255
  57. ld l,a
  58. #endif
  59. ld (toprightmask),a
  60. ld l,a
  61. rra
  62. xor l
  63. ld (rightbordermask),a
  64. ;Now we make sure the rect is on-screen is on-screen in the horizontal direction
  65. sla l ;This will hold clipping info
  66. ld a,c
  67. cp 64
  68. jr c,+_
  69. add a,b
  70. ret nc
  71. ld c,0
  72. ld b,a
  73. inc l
  74. _:
  75. ;Next check b+c<=64 and b>0
  76. sla l
  77. ld a,64
  78. sub c
  79. ret z
  80. cp b
  81. jr nc,+_
  82. ld b,a
  83. inc l
  84. _:
  85. ;Next check if the rect is on-screen in the vertical direction
  86. ld a,e
  87. cp 96
  88. jr c,+_
  89. add a,d
  90. ret nc
  91. ld d,a
  92. xor a
  93. ld e,a
  94. ld (rightbordermask),a
  95. _:
  96. ;Next check d+e<=64
  97. ld a,96
  98. sub e
  99. cp d
  100. jr nc,+_
  101. ld d,a
  102. xor a
  103. ld (leftbordermask),a
  104. _:
  105. ;B is the height
  106. ;C is the Y pixel coordinate
  107. ;D is the width in pixels
  108. ;E is is the X pixel coordinate
  109. ;L is clipping flags:
  110. ; bit 0 means bottom-clipped
  111. ; bit 1 means top-clipped
  112. ld a,l
  113. ld (TempWord1+1),a ;Store clipping flags
  114. ;Now We calculate where to begin drawing.
  115. ;Note that this will always start on screen due to how we performed clipping
  116. ld a,b
  117. ld h,0
  118. ld b,h
  119. ld l,c
  120. add hl,hl
  121. add hl,bc
  122. add hl,hl
  123. add hl,hl
  124. ld c,e
  125. srl c
  126. srl c
  127. srl c
  128. add hl,bc
  129. ld bc,(gbuf_temp)
  130. add hl,bc
  131. ld b,a
  132. ;Need to calculate how many bytes spanned
  133. ld a,e
  134. and %11111000
  135. ld c,a
  136. ld a,e
  137. add a,d
  138. and %11111000
  139. sub c
  140. ld d,a
  141. inc d
  142. ;B is height
  143. ;HL points to where to start drawing
  144. ;D is bytes spanned
  145. ld a,(TempWord1)
  146. or a
  147. jp z,rect_wbwf
  148. dec a
  149. jp z,rect_bbbf
  150. dec a
  151. jp z,rect_xbxf
  152. dec a
  153. jp z,rect_bbcf
  154. dec a
  155. jp z,rect_wbcf
  156. dec a
  157. jp z,rect_xbcf
  158. dec a
  159. jp z,rect_bbwf
  160. dec a
  161. jp z,rect_bbxf
  162. dec a
  163. jp z,rect_wbbf
  164. dec a
  165. jp z,rect_wbxf
  166. dec a
  167. jp z,rect_shift_up
  168. dec a
  169. jp z,rect_shift_down
  170. dec a
  171. jp z,rect_shift_right
  172. dec a
  173. jp z,rect_shift_left
  174. dec a
  175. jp z,rect_xbbf
  176. dec a
  177. ret nz
  178. rect_xbwf:
  179. call horiz_xb
  180. dec b
  181. ret z
  182. dec b
  183. jp z,horiz_xb
  184. ;Here we need to fill with an inverted border, white fill
  185. dec d
  186. jr z,rect_xbwf_1byte
  187. rect_xbwf_loop:
  188. push de
  189. push hl
  190. ld a,(topleftmask)
  191. rra
  192. cpl
  193. and (hl)
  194. ld e,a
  195. ld a,(leftbordermask)
  196. xor e
  197. ld (hl),a
  198. inc hl
  199. dec d
  200. jr z,+_
  201. ld (hl),0
  202. inc hl
  203. dec d
  204. jr nz,$-4
  205. _:
  206. ld a,(toprightmask)
  207. rla
  208. cpl
  209. and (hl)
  210. ld e,a
  211. ld a,(rightbordermask)
  212. xor e
  213. ld (hl),a
  214. pop hl
  215. ld e,12
  216. add hl,de
  217. pop de
  218. djnz rect_xbwf_loop
  219. jp horiz_xb
  220. rect_xbwf_1byte:
  221. ld a,(topleftmask)
  222. ld e,a
  223. ld a,(toprightmask)
  224. and e
  225. ld e,a
  226. ld a,(leftbordermask)
  227. ld d,a
  228. ld a,(rightbordermask)
  229. or d
  230. and e
  231. ld d,a
  232. ld a,e
  233. cpl
  234. ld e,a
  235. _:
  236. ld a,(hl)
  237. and e
  238. xor d
  239. ld (hl),a
  240. inc hl
  241. djnz -_
  242. rect_wbwf:
  243. _:
  244. call horiz_wb
  245. djnz -_
  246. ret
  247. rect_bbbf:
  248. ;B is height
  249. ;HL points to where to start drawing
  250. ;D is bytes spanned
  251. _:
  252. call horiz_bb
  253. djnz -_
  254. ret
  255. rect_xbxf:
  256. _:
  257. call horiz_xb
  258. djnz -_
  259. ret
  260. rect_bbcf:
  261. call horiz_bb
  262. dec b
  263. ret z
  264. dec b
  265. jp z,horiz_bb
  266. ;Here we need to fill with a black border, clear fill
  267. ret
  268. rect_wbcf:
  269. call horiz_wb
  270. dec b
  271. ret z
  272. dec b
  273. jp z,horiz_wb
  274. ;Here we need to fill with a white border, clear fill
  275. ret
  276. rect_xbcf:
  277. call horiz_xb
  278. dec b
  279. ret z
  280. dec b
  281. jp z,horiz_xb
  282. ;Here we need to fill with a inverted border, clear fill
  283. ret
  284. rect_bbwf:
  285. call horiz_bb
  286. dec b
  287. ret z
  288. dec b
  289. jp z,horiz_bb
  290. ;Here we need to fill with a black border, white fill
  291. ret
  292. rect_bbxf:
  293. call horiz_bb
  294. dec b
  295. ret z
  296. dec b
  297. jp z,horiz_bb
  298. ;Here we need to fill with a black border, inverted fill
  299. ret
  300. rect_wbbf:
  301. call horiz_wb
  302. dec b
  303. ret z
  304. dec b
  305. jp z,horiz_wb
  306. ;Here we need to fill with a white border, black fill
  307. ret
  308. rect_wbxf:
  309. call horiz_wb
  310. dec b
  311. ret z
  312. dec b
  313. jp z,horiz_wb
  314. ;Here we need to fill with a white border, inverted fill
  315. ret
  316. rect_xbbf:
  317. call horiz_xb
  318. dec b
  319. ret z
  320. dec b
  321. jp z,horiz_xb
  322. ;Here we need to fill with a inverted border, black fill
  323. ret
  324. rect_shift_up:
  325. rect_shift_down:
  326. rect_shift_right:
  327. rect_shift_left:
  328. ret
  329. horiz_bb:
  330. push de
  331. dec d
  332. ld a,(topleftmask)
  333. jr nz,+_
  334. ld e,a
  335. ld a,(toprightmask)
  336. and e
  337. or (hl)
  338. ld (hl),a
  339. jr endhoriz_bb
  340. _:
  341. push hl
  342. or (hl)
  343. ld (hl),a
  344. inc hl
  345. dec d
  346. jr z,horizbb_lastiter
  347. _:
  348. ld (hl),-1
  349. inc hl
  350. dec d
  351. jr nz,-_
  352. horizbb_lastiter:
  353. ld a,(toprightmask)
  354. or (hl)
  355. ld (hl),a
  356. pop hl
  357. endhoriz_bb:
  358. ld e,12
  359. add hl,de
  360. pop de
  361. ret
  362. horiz_wb:
  363. push de
  364. dec d
  365. ld a,(topleftmask)
  366. cpl
  367. jr nz,+_
  368. ld e,a
  369. ld a,(toprightmask)
  370. cpl
  371. or e
  372. and (hl)
  373. ld (hl),a
  374. jr endhoriz_bb
  375. _:
  376. push hl
  377. and (hl)
  378. ld (hl),a
  379. inc hl
  380. dec d
  381. jr z,horizwb_lastiter
  382. _:
  383. ld (hl),0
  384. inc hl
  385. dec d
  386. jr nz,-_
  387. horizwb_lastiter:
  388. ld a,(toprightmask)
  389. cpl
  390. and (hl)
  391. ld (hl),a
  392. pop hl
  393. jp endhoriz_bb
  394. horiz_xb:
  395. push de
  396. dec d
  397. ld a,(topleftmask)
  398. jr nz,+_
  399. ld e,a
  400. ld a,(toprightmask)
  401. and e
  402. xor (hl)
  403. ld (hl),a
  404. jr endhoriz_bb
  405. _:
  406. push hl
  407. xor (hl)
  408. ld (hl),a
  409. inc hl
  410. dec d
  411. jr z,horizxb_lastiter
  412. _:
  413. ld a,(hl)
  414. cpl
  415. ld (hl),a
  416. inc hl
  417. dec d
  418. jr nz,-_
  419. horizxb_lastiter:
  420. ld a,(toprightmask)
  421. xor (hl)
  422. ld (hl),a
  423. pop hl
  424. jp endhoriz_bb
  425. .echo "rect: ",$-rect
  426. ;Need to beat 796 bytes