particle.z80 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. PToRy:
  2. call ParseFullArg
  3. cp 2Bh
  4. ld (PBufType),bc
  5. ld bc,%01100001
  6. jr nz,GetRuleNum+3
  7. inc hl
  8. ld a,(hl)
  9. sub 2Ah
  10. jr nz,GetRuleNum
  11. ld b,h
  12. ld c,l
  13. ld h,a
  14. ld l,a
  15. ConvRuleLoop:
  16. inc bc
  17. ld a,(bc)
  18. call EndOArg
  19. jr nz,more_rules
  20. cp 2Bh
  21. jr z,more_rule_args
  22. _:
  23. ld a,h \ and $F0
  24. jr nz,+_
  25. add hl,hl
  26. add hl,hl
  27. add hl,hl
  28. add hl,hl
  29. jr -_
  30. _:
  31. ld (PBufRule),hl
  32. ret
  33. more_rule_args:
  34. add hl,hl
  35. add hl,hl
  36. add hl,hl
  37. add hl,hl
  38. more_rules:
  39. cp 'U'
  40. jr nz,+_
  41. set 3,l
  42. _:
  43. cp 'R'
  44. jr nz,+_
  45. set 2,l
  46. _:
  47. cp 'L'
  48. jr nz,+_
  49. set 1,l
  50. _:
  51. cp 'D'
  52. jr nz,ConvRuleLoop
  53. set 0,l
  54. jr ConvRuleLoop
  55. GetRuleNum:
  56. call ParseNextFullArg
  57. ld a,b
  58. rlca \ rlca \ rlca \ rlca
  59. ld (PBufRule),a
  60. ld a,c
  61. rlca \ rlca \ rlca \ rlca
  62. ld (PBufRule+1),a
  63. ret
  64. RToPr:
  65. ld hl,(PBufPtr)
  66. inc hl \ inc hl
  67. ld (hl),0 \ inc hl
  68. ld (hl),0 \ inc hl
  69. ret
  70. ;===============================================================
  71. RToPTheta:
  72. ;===============================================================
  73. ;This executes one particle cycle
  74. ;===============================================================
  75. ld a,(hl)
  76. call EndOArg
  77. jr z,DefaultBuffer
  78. call ParseFullArg
  79. push bc
  80. cp $2b
  81. call ParseNextFullArg_Buffer
  82. pop bc
  83. g_ParticleCycle:
  84. ld (PBufPtr),bc
  85. DefaultBuffer:
  86. ld hl,(PBufPtr)
  87. ld a,(PBufType)
  88. ld de,(PBufRule)
  89. or a
  90. jr nz,+_
  91. ld de,%0001011000000000
  92. _:
  93. dec a
  94. jr nz,+_
  95. ld de,%0001011010000000
  96. _:
  97. ld (TempWord1),de
  98. ;RuleSet=DE
  99. inc hl
  100. inc hl
  101. ld (TempWord4),hl
  102. ld c,(hl)
  103. inc hl
  104. ld b,(hl)
  105. ld a,b
  106. or c
  107. ret z
  108. inc hl
  109. ;BC now is the number of particles
  110. ;HL now points to the particles
  111. ;(TempWord1) is the ruleset
  112. ld (TempWord2),bc
  113. add hl,bc
  114. add hl,bc
  115. dec hl
  116. ld (TempWord3),hl
  117. inc hl
  118. sbc hl,bc
  119. sbc hl,bc
  120. ;TempWord2 contains the number of particles left in the buffer
  121. ;TempWord3 points to the last particle
  122. ;TempWord4 points to the particle size bytes
  123. ParticleDrawLoop:
  124. push bc
  125. push hl
  126. call EraseParticle
  127. push hl
  128. pop ix
  129. ld hl,(TempWord1)
  130. push af
  131. ld a,(flags+ParticleFlag)
  132. and %11100000
  133. ld (flags+ParticleFlag),a
  134. ld a,b
  135. or a
  136. jr nz,PLeft
  137. set Xis0,(iy+ParticleFlag)
  138. jr PUpDown
  139. PLeft:
  140. sub 95
  141. jr c,PUpDown
  142. set Xis95,(iy+ParticleFlag)
  143. PUpDown:
  144. ld a,c
  145. or a
  146. jr nz,PDown
  147. set Yis0,(iy+ParticleFlag)
  148. jr PPPp
  149. PDown:
  150. sub 63
  151. jr c,PPPp
  152. set Yis63,(iy+ParticleFlag)
  153. PPPp:
  154. pop bc
  155. ld c,0
  156. ParticleTestLoop:
  157. add hl,hl
  158. jr nc,CheckPRight
  159. ld a,b
  160. and (ix-12)
  161. jr nz,CheckPRight
  162. ld c,8
  163. bit Yis0,(iy+ParticleFlag)
  164. jr z,CheckPRight
  165. set OffScrn,(iy+ParticleFlag)
  166. CheckPRight:
  167. add hl,hl
  168. jr nc,CheckPLeft
  169. ld a,b
  170. rrca
  171. jr c,$+7
  172. and (ix)
  173. jr +_
  174. and (ix+1)
  175. _:
  176. jr nz,CheckPLeft
  177. ld a,c
  178. or a
  179. jr z,$+8
  180. ld a,r
  181. bit 4,a
  182. jr nz,+_
  183. ld c,4
  184. _:
  185. bit Xis95,(iy+ParticleFlag)
  186. jr z,CheckPLeft
  187. set OffScrn,(iy+ParticleFlag)
  188. CheckPLeft:
  189. add hl,hl
  190. jr nc,CheckPDown
  191. ld a,b
  192. rlca
  193. jr c,$+7
  194. and (ix)
  195. jr +_
  196. and (ix-1)
  197. _:
  198. jr nz,CheckPDown
  199. ld a,c
  200. or a
  201. jr z,$+8
  202. ld a,r
  203. bit 4,a
  204. jr nz,+_
  205. ld c,2
  206. _:
  207. bit Xis0,(iy+ParticleFlag)
  208. jr z,CheckPDown
  209. set OffScrn,(iy+ParticleFlag)
  210. CheckPDown:
  211. add hl,hl
  212. jr nc,PChecked
  213. ld a,b
  214. and (ix+12)
  215. jr nz,PChecked
  216. ld a,c
  217. or a
  218. jr z,$+8
  219. ld a,r
  220. bit 4,a
  221. jr nz,+_
  222. ld c,1
  223. _:
  224. bit Yis63,(iy+ParticleFlag)
  225. jr z,PChecked
  226. set OffScrn,(iy+ParticleFlag)
  227. PChecked:
  228. ld a,c
  229. or a
  230. jr nz,MoveP
  231. ld a,h
  232. or l
  233. jp nz,ParticleTestLoop
  234. MoveP:
  235. pop hl
  236. ld a,c
  237. or a
  238. jr z,MovedP
  239. ld a,b
  240. cpl
  241. and (ix)
  242. ld (ix),a
  243. bit OffScrn,(iy+ParticleFlag)
  244. jr nz,RemoveParticle
  245. ld a,b
  246. rrc c
  247. jr nc,+_
  248. or (ix+12)
  249. ld (ix+12),a
  250. inc (hl)
  251. jr MovedP
  252. _:
  253. rrc c
  254. jr nc,$+23
  255. rlca
  256. jr nc,$+10
  257. or (ix-1)
  258. ld (ix-1),a
  259. jr $+8
  260. or (ix)
  261. ld (ix),a
  262. inc hl
  263. dec (hl)
  264. jr MovedP+1
  265. rrc c
  266. jr nc,$+23
  267. rrca
  268. jr nc,$+10
  269. or (ix+1)
  270. ld (ix+1),a
  271. jr +_
  272. or (ix)
  273. ld (ix),a
  274. _:
  275. inc hl
  276. inc (hl)
  277. jr MovedP+1
  278. or (ix-12)
  279. ld (ix-12),a
  280. dec (hl)
  281. MovedP:
  282. inc hl
  283. pop bc
  284. cpi
  285. jp pe,ParticleDrawLoop
  286. ret
  287. RemoveParticle:
  288. ;HL points to particle data
  289. ;TempWord2 contains the number of particles left in the buffer
  290. ;TempWord3 points to the last particle
  291. ;TempWord4 points to the particle size bytes
  292. res OffScrn,(iy+ParticleFlag)
  293. ld bc,(TempWord2)
  294. cpi
  295. ex de,hl
  296. push af
  297. ld hl,(TempWord3)
  298. ld (TempWord2),bc
  299. ldd
  300. ldd
  301. ld (TempWord3),hl
  302. ld hl,(TempWord4)
  303. inc bc
  304. inc bc
  305. ld (hl),c
  306. inc hl
  307. ld (hl),b
  308. ex de,hl
  309. pop af
  310. pop bc
  311. ret po
  312. cpi
  313. jp pe,ParticleDrawLoop
  314. ret
  315. ;===============================================================
  316. PBufInfoDef:
  317. ld hl,(PBufPtr)
  318. PBufInfo:
  319. ld c,(hl) \ inc hl
  320. ld b,(hl) \ inc hl
  321. ld e,(hl) \ inc hl
  322. ld d,(hl) \ inc hl
  323. ret
  324. NextParticle:
  325. sra b \ rr c \ dec bc
  326. ex de,hl
  327. sbc hl,bc \ ret z
  328. add hl,bc
  329. inc hl
  330. ex de,hl
  331. ld (TempWord1),hl
  332. dec hl \ ld (hl),d
  333. dec hl \ ld (hl),e
  334. ex de,hl
  335. add hl,hl
  336. add hl,de
  337. or 1
  338. ret
  339. PartConv:
  340. ; jr $
  341. push bc
  342. call ParseNextFullArg
  343. push bc
  344. call ParseNextFullArg
  345. ld a,c
  346. pop bc \ ld b,a
  347. push bc
  348. call ParseNextFullArg
  349. push bc
  350. call ParseNextFullArg
  351. cp $2b
  352. ld a,c
  353. push af
  354. call ParseNextFullArg_Buffer
  355. pop af
  356. pop bc \ ld b,a
  357. pop hl \ ld (TempWord3),hl
  358. add hl,bc \ dec h \ dec l
  359. ld (TempWord2),bc
  360. ;HL contains the lower-left coordinates
  361. PartConvLoop:
  362. push hl
  363. push bc
  364. ld (TempWord4),hl
  365. ld b,h \ ld c,l
  366. call GetPixelLoc
  367. jr nc,FinishPartAdd
  368. and (hl) \ jr z,FinishPartAdd
  369. call PBufInfoDef
  370. call NextParticle \ jr z,PConvComplete
  371. ld bc,(TempWord4)
  372. ld (hl),c \ inc hl \ ld (hl),b
  373. FinishPartAdd:
  374. pop bc \ pop hl
  375. ;TempWord2 is the size of the reqion
  376. ;TempWord3 is is the upper right coordinate
  377. dec h \ djnz PartConvLoop
  378. ld hl,(TempWord3)
  379. ld bc,(TempWord2) \ dec c
  380. add hl,bc
  381. jr nz,PartConvLoop-6
  382. pop bc \ ret
  383. PConvComplete:
  384. pop bc \ pop hl \ pop bc \ ret ;zuviel
  385. FillPart:
  386. ret
  387. PToRX:
  388. ld a,(hl) \ cp $AE
  389. jr z,PartConv
  390. cp 11 \ jr z,FillPart
  391. call PBufInfoDef
  392. ;BC=Max number of particles
  393. ;DE=Current number of particles
  394. ;HL=particle pointer
  395. call NextParticle
  396. ld de,(TempWord1)
  397. push de
  398. push hl
  399. ;HL points to where particle data gets written
  400. call ParseFullArg
  401. push bc
  402. call ParseNextFullArg
  403. ld a,c
  404. pop bc \ ld b,a
  405. pop hl \ pop de
  406. AddParticle:
  407. ld (hl),c \ inc hl
  408. ld (hl),b
  409. call GetPixelLoc
  410. or (hl) \ ld (hl),a
  411. ld b,d \ ld c,e
  412. ret