Guest User

Untitled

a guest
Jan 24th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. DrawTriangle:
  2. ;IN: x1,y1,u1,v1,x2,y2,u2,v2,x3,y3,u3,v3
  3. ;scherm = 96*64
  4.  
  5. ld hl, (y1)
  6. ld de, (y2)
  7. cpHLDE
  8. jr c, Y1SmallerThanY2
  9. ld (y1), de
  10. ld (y2), hl
  11. ld hl, (x1)
  12. ld de, (x2)
  13. ld (x1), de
  14. ld (x2), hl
  15. Y1SmallerThanY2:
  16. ld hl, (y1)
  17. ld de, (y3)
  18. cpHLDE
  19. jr c, Y1SmallerThanY3
  20. ld (y1), de
  21. ld (y3), hl
  22. ld hl, (x1)
  23. ld de, (x3)
  24. ld (x1), de
  25. ld (x3), hl
  26. Y1SmallerThanY3:
  27. ld hl, (y2)
  28. ld de, (y3)
  29. cpHLDE
  30. jr c, Y2SmallerThanY3
  31. ld (y2), de
  32. ld (y3), hl
  33. ld hl, (x2)
  34. ld de, (x3)
  35. ld (x2), de
  36. ld (x3), hl
  37. Y2SmallerThanY3:
  38.  
  39.  
  40. push IY
  41. pop hl
  42. ld (SaveIY), hl
  43. ld hl, TempFlags
  44. push hl
  45. pop IY
  46.  
  47. res 0, (IY) ;in bit 0, (IY) wordt opgeslagen bij welke helft het is. 0=eerste helft, 1= tweede helft
  48. res 1, (IY) ;bit 1, (IY) = interval texturen al berekend
  49.  
  50. ld hl, (y2)
  51. ld de, (y1)
  52. subFP ;hier gebruikt om 16-bit getallen af te trekken I.P.V. fixed-point getallen
  53. ld h, l
  54. ld l, 0
  55. push hl
  56. ld hl, (x2)
  57. ld de, (x1)
  58. subFP
  59. ld h, l
  60. ld l, 0
  61. pop de
  62. call DivFP
  63. ld (dx1), hl
  64. ld hl, (y3)
  65. ld de, (y2)
  66. subFP
  67. ld h, l
  68. ld l, 0
  69. push hl
  70. ld hl, (x3)
  71. ld de, (x2)
  72. subFP
  73. ld h, l
  74. ld l, 0
  75. pop de
  76. call DivFP
  77. ld (dx2), hl
  78. ld hl, (y3)
  79. ld de, (y1)
  80. subFP
  81. ld h, l
  82. ld l, 0
  83. push hl
  84. ld hl, (x3)
  85. ld de, (x1)
  86. subFP
  87. ld h, l
  88. ld l, 0
  89. pop de
  90. call DivFP
  91. ld (dx3), hl
  92.  
  93. ; ld hl, (dx1)
  94. ; ld de, (dx3)
  95. ; cpHLDE
  96. ; jr nc, TNoChange
  97. ; ld (dx1), de
  98. ; ld (dx3), hl
  99. ;TNoChange:
  100.  
  101.  
  102. ld hl, (x1)
  103. bit 7, h
  104. jr z, TPos1
  105. ld (tx1+1),hl \ ld a, $FF \ ld (tx1),a
  106. ld (tx2+1),hl \ ld a, $FF \ ld (tx2),a
  107. jr TEnd1
  108. TPos1:
  109. ld (tx1+1),hl \ xor a \ ld (tx1),a ;store the 16bit integer at hl into 16.8 fixed point number tx1
  110. ld (tx2+1),hl \ xor a \ ld (tx2),a
  111. TEnd1:
  112. ld hl, (y1)
  113. ld (_ty), hl
  114.  
  115. ld hl, (Y1)
  116. ld de, (y2)
  117. cpHLDE
  118. jp z, __TEndLoop
  119.  
  120. TDrawLoop:
  121.  
  122. ;(h,l) (d,e)
  123.  
  124. ; ld a, (tx1+1)
  125. ; ld h, a
  126. ; ld a, (_ty)
  127. ; ld l, a
  128. ; ld e, a
  129. ; ld a, (tx2+1)
  130. ; ld d, a
  131. ; call DrawLine
  132.  
  133. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Horizontal line drawing !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  134.  
  135. ld a, (_ty)
  136. ld l, a
  137. #comment
  138. ld hl, (tu1)
  139. ld (tmpu), hl
  140. ld hl, (tv1)
  141. ld (tmpv), hl
  142. ld hl, (tu2)
  143. ld (temp2), hl
  144. ld hl, (tv2)
  145. ld (temp3), hl
  146. #endcomment
  147. ld a, (tx2+1)
  148. ld (temp+1), a
  149. ld b, a
  150. ld a, (tx1+1)
  151. ld (temp), a
  152. cp b
  153. jr c, TOrdered
  154. #comment
  155. ld hl, (tu2)
  156. ld (tmpu), hl
  157. ld hl, (tv2)
  158. ld (tmpv), hl
  159. ld hl, (tu1)
  160. ld (temp2), hl
  161. ld hl, (tv1)
  162. ld (temp3), hl
  163. #endcomment
  164. ld a, (tx2+1)
  165. ld (temp), a
  166. ld a, (tx1+1)
  167. ld (temp+1), a
  168. TOrdered:
  169. ld a, (temp)
  170. call GetPixel
  171. ld (mask), a
  172. ld (pointer), hl
  173. ;#comment
  174. bit 1, (IY)
  175. jr nz, EndCalc
  176. ld hl, (tx1)
  177. ld de, (tx2)
  178. cpHLDE
  179. jr z, EndCalc
  180. ld a, (temp)
  181. ld h, a
  182. ld l, 0
  183. ld a, (temp+1)
  184. ld d, a
  185. ld e, 0
  186. subFP
  187. push hl
  188. ld hl, (tmpu)
  189. ld de, (temp2)
  190. subFP
  191. pop de
  192. call DivFP
  193. ld (tmpdu), hl
  194. ld a, (temp)
  195. ld h, a
  196. ld l, 0
  197. ld a, (temp+1)
  198. ld d, a
  199. ld e, 0
  200. subFP
  201. push hl
  202. ld hl, (tmpv)
  203. ld de, (temp3)
  204. subFP
  205. pop de
  206. call DivFP
  207. ld (tmpdv), hl
  208. EndCalc:
  209. ;#endcomment
  210. TPlotLoop:
  211. ld a, (mask)
  212. ld hl, (pointer)
  213. or (hl)
  214. ld (hl), a
  215.  
  216. ld hl, mask
  217. rrc (hl)
  218. jr nc, TNoCarry
  219. ld hl, (pointer)
  220. inc hl
  221. ld (pointer), hl
  222. TNoCarry:
  223.  
  224. ;#comment
  225. ld hl, (tmpu)
  226. ld de, (tmpdu)
  227. add hl, de
  228. ld (tmpu), hl
  229. ld hl, (tmpv)
  230. ld de, (tmpdv)
  231. add hl, de
  232. ld (tmpv), hl
  233. ;#endcomment
  234.  
  235. ld a, (temp+1)
  236. ld b, a
  237. ld a, (temp)
  238. ld hl, temp
  239. inc (hl)
  240. cp b
  241. jr nz, TPlotLoop
  242.  
  243. ; ld hl, (tx1)
  244. ; ld de, (dx1)
  245. ; add hl, de
  246. ; ld a, (tx1+2)
  247. ; bit 7, d
  248. ; jr z, TPos2
  249. ; adc a, $FF
  250. ; jr Tend2
  251. ;TPos2:
  252. ; adc a, 0
  253. ;TEnd2:
  254. ; ld (tx1), hl
  255. ; ld (tx1+2), a
  256.  
  257. ; ld hl,(tx1) \ ld de, (dx1) \ ld a, d \ rla \ sbc a,a \ add hl, de \ ld b, a \ ld a, (tx1+2) \ adc a, b \ ld (tx1+2), a \ ld (tx1), hl
  258.  
  259. ; ld hl, (tx1)
  260. ; ld de, (dx1)
  261. ; ld a,(tx1+2)
  262. ; bit 7, d
  263. ; jr nz, __Substract1
  264. ; add hl, de
  265. ; jr nc, __End1
  266. ; inc a
  267. ; ld (tx1+2), a
  268. ; jr __End1
  269. ;__Substract1:
  270. ; call NegDE
  271. ; or a
  272. ; sbc hl, de
  273. ; jr nc, __End1
  274. ; dec a
  275. ; ld (tx1+2), a
  276. ;__End1:
  277. ; ld (tx1), hl
  278.  
  279. ld hl,(tx1)
  280. ld de, (dx1)
  281. ld a, d
  282. rla
  283. sbc a, a
  284. ld b, a
  285. add hl, de
  286. ld (tx1), hl
  287. ld a, (tx1+2)
  288. adc a, b
  289. ld (tx1+2), a
  290.  
  291. ; ld hl, (tx2)
  292. ; ld de, (dx3)
  293. ; add hl, de
  294. ; ld a, (tx2+2)
  295. ; bit 7, d
  296. ; jr z, TPos3
  297. ; adc a, $FF
  298. ; jr Tend3
  299. ;TPos3:
  300. ; adc a, 0
  301. ;TEnd3:
  302. ; ld (tx2), hl
  303. ; ld (tx2+2), a
  304.  
  305. ; ld hl,(tx2) \ ld de, (dx3) \ ld a, d \ rla \ sbc a,a \ add hl, de \ ld b, a \ ld a, (tx2+2) \ adc a, b \ ld (tx2+2), a \ ld (tx2), hl
  306.  
  307. ; ld hl, (tx2)
  308. ; ld de, (dx3)
  309. ; ld a,(tx2+2)
  310. ; bit 7, d
  311. ; jr nz, __Substract2
  312. ; add hl, de
  313. ; jr nc, __End2
  314. ; inc a
  315. ; ld (tx2+2), a
  316. ; jr __End2
  317. ;__Substract2:
  318. ; call NegDE
  319. ; or a
  320. ; sbc hl, de
  321. ; jr nc, __End2
  322. ; dec a
  323. ; ld (tx2+2), a
  324. ;__End2:
  325. ; ld (tx2), hl
  326.  
  327. ld hl,(tx2)
  328. ld de, (dx3)
  329. ld a, d
  330. rla
  331. sbc a, a
  332. ld b, a
  333. add hl, de
  334. ld (tx2), hl
  335. ld a, (tx2+2)
  336. adc a, b
  337. ld (tx2+2), a
  338.  
  339.  
  340.  
  341. ld hl, (_ty)
  342. inc hl
  343. ld (_ty), hl
  344. ld de, (y2)
  345. cpHLDE
  346. jp c, TDrawLoop
  347.  
  348. bit 0, (IY)
  349. jr nz, _TEnd
  350. __TEndLoop:
  351.  
  352. ;Begin tweede keer tekenen:
  353.  
  354. ld hl, (y2)
  355. ld (_ty), hl
  356.  
  357. ld hl, (y3)
  358. ld (y2), hl
  359. ld hl, (dx2)
  360. ld (dx1), hl
  361.  
  362. ld hl, (x2)
  363. bit 7, h
  364. jr nz, TPos4
  365. ld (tx1+1),hl \ ld a, $FF \ ld (tx1),a
  366. jr TEnd4
  367. TPos4:
  368. ld (tx1+1),hl \ xor a \ ld (tx1),a
  369. Tend4:
  370.  
  371. set 0, (IY)
  372.  
  373. jp TDrawLoop
  374.  
  375. _TEnd:
  376.  
  377. ld hl, (SaveIY)
  378. push hl
  379. pop IY
  380.  
  381. ret
  382.  
  383.  
  384.  
  385. getPixel:
  386. ld h, 0
  387. ld d, h
  388. ld e, l
  389.  
  390. add hl, hl
  391. add hl, de
  392. add hl, hl
  393. add hl, hl
  394.  
  395. ld e, a
  396. srl e
  397. srl e
  398. srl e
  399. add hl, de
  400.  
  401. ld de, PlotSScreen
  402. add hl, de
  403.  
  404. and 7
  405. ld b, a
  406. ld a, $80
  407. ret z
  408.  
  409. rrca
  410. djnz $-1
  411. ret
Add Comment
Please, Sign In to add comment