2
0

tilemap.z80 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. tilemap_new:
  2. dec a
  3. jp z,tilemap_init
  4. ld hl,(parsePtr)
  5. dec a
  6. jp z,tilemap_fullrender
  7. ld c,1
  8. dec a
  9. jr z,tmap_scroll_down
  10. dec a
  11. jr z,tmap_scroll_left
  12. dec a
  13. jr z,tmap_scroll_right
  14. dec a
  15. jr z,tmap_scroll_up
  16. dec a
  17. jr z,tmap_scroll
  18. dec a
  19. jp z,tmap_gettile
  20. dec a
  21. jp z,tmap_settile
  22. dec a
  23. jp z,tmap_gettile_pxl
  24. jp p1_errbadtoken
  25. tmap_scroll_left:
  26. ld a,(hl)
  27. cp $2B
  28. call z,p1_ParseNextFullArg
  29. inc c
  30. dec c
  31. ret z
  32. ld b,c
  33. tmap_scroll_left_loop:
  34. _:
  35. push bc
  36. call tilemap_scroll_left
  37. pop bc
  38. djnz -_
  39. ret
  40. tmap_scroll_right:
  41. ld a,(hl)
  42. cp $2B
  43. call z,p1_ParseNextFullArg
  44. inc c
  45. dec c
  46. ret z
  47. ld b,c
  48. tmap_scroll_right_loop:
  49. _:
  50. push bc
  51. call tilemap_scroll_right
  52. pop bc
  53. djnz -_
  54. ret
  55. tmap_scroll_down:
  56. ld a,(hl)
  57. cp $2B
  58. call z,p1_ParseNextFullArg
  59. inc c
  60. dec c
  61. ret z
  62. ld b,c
  63. tmap_scroll_down_loop:
  64. _:
  65. push bc
  66. call tilemap_scroll_down
  67. pop bc
  68. djnz -_
  69. ret
  70. tmap_scroll_up:
  71. ld a,(hl)
  72. cp $2B
  73. call z,p1_ParseNextFullArg
  74. inc c
  75. dec c
  76. ret z
  77. ld b,c
  78. tmap_scroll_up_loop:
  79. _:
  80. push bc
  81. call tilemap_scroll_up
  82. pop bc
  83. djnz -_
  84. ret
  85. tmap_scroll:
  86. call p1_ParseNextFullArg
  87. cp $2B
  88. ld a,c
  89. push af
  90. ld c,1
  91. call z,p1_ParseNextFullArg
  92. pop af
  93. inc c
  94. dec c
  95. ret z
  96. ld b,c
  97. rrca
  98. push af
  99. push bc
  100. call c,tmap_scroll_down_loop
  101. pop bc
  102. pop af
  103. rrca
  104. push af
  105. push bc
  106. call c,tmap_scroll_left_loop
  107. pop bc
  108. pop af
  109. rrca
  110. push af
  111. push bc
  112. call c,tmap_scroll_right_loop
  113. pop bc
  114. pop af
  115. rrca
  116. ret nc
  117. jp tmap_scroll_up_loop
  118. tmap_gettile_pxl:
  119. call p1_ParseNextFullArg
  120. ld a,(tilemap_sy)
  121. add a,c
  122. and %11111000
  123. rrca
  124. rrca
  125. rrca
  126. ld c,a
  127. ld a,(tilemap_y)
  128. add a,c
  129. ld c,a
  130. push bc
  131. call p1_ParseNextFullArg
  132. ld a,(tilemap_sx_mask)
  133. .db $FE
  134. _:
  135. inc c
  136. add a,a
  137. jr nc,-_
  138. ld a,c
  139. and %11111000
  140. rrca
  141. rrca
  142. rrca
  143. ld c,a
  144. ld a,(tilemap_x)
  145. add a,c
  146. pop de
  147. ld c,a
  148. jr +_
  149. tmap_gettile:
  150. ; This gets the tile number based on the map coordinates
  151. call p1_ParseNextFullArg
  152. push bc
  153. call p1_ParseNextFullArg
  154. pop de
  155. _:
  156. ld b,0
  157. ld hl,(tilemap_height)
  158. ld a,e
  159. cp l
  160. jr nc,setC_to_B
  161. ld a,d
  162. cp h
  163. jr nc,setC_to_B
  164. ;need tilemap_base+width*e+c
  165. ld hl,(tilemap_base)
  166. ld b,0
  167. add hl,bc
  168. ld d,b
  169. ld a,(tilemap_width)
  170. ld b,a
  171. or a
  172. jr z,+_
  173. add hl,de
  174. djnz $-1
  175. _:
  176. ld c,(hl)
  177. ld b,d
  178. ret
  179. setC_to_B:
  180. ld c,b
  181. ret
  182. tmap_settile:
  183. call p1_ParseNextFullArg
  184. push bc
  185. call p1_ParseNextFullArg
  186. pop de
  187. ;need tilemap_base+width*e+c
  188. ld b,0
  189. ld hl,(tilemap_height)
  190. ld a,e
  191. cp l
  192. jr nc,parse_return_0
  193. ld a,d
  194. cp h
  195. jr nc,parse_return_0
  196. ld hl,(tilemap_base)
  197. add hl,bc
  198. ld d,b
  199. ld a,(tilemap_width)
  200. ld b,a
  201. or a
  202. jr z,+_
  203. add hl,de
  204. djnz $-1
  205. _:
  206. push hl
  207. call p1_ParseNextFullArg
  208. pop hl
  209. ld a,(hl)
  210. ld (hl),c
  211. ld c,a
  212. ld b,0
  213. ret
  214. parse_return_0:
  215. call p1_ParseNextFullArg
  216. ld bc,0
  217. ret
  218. tilemap_init:
  219. ;Use this routine to initialize a tilemap
  220. ; (tilemap_base) points to the tilemap base
  221. ; (tilemap_height) is the height
  222. ; (tilemap_width) is the width
  223. ; (sprite_select) points to the routine for selecting the sprite
  224. ; (tilemap_buf) points to the buffer to draw on
  225. ; tilemap_flags
  226. ;Need to set
  227. ; (tilemap_sy) is the y-offset into the sprite
  228. ; (tilemap_y) is the y-offset into the tilemap
  229. ; (tilemap_sx_mask) is the column mask for the sprite
  230. ; (tilemap_x) is the x-offset into the tilemap
  231. ; (tilemap_top) is the pointer to the upper-left tile in view
  232. ; (tilemap_bottom) is the pointer to the bottom-left incoming row
  233. call p1_ParseNextFullArg
  234. ld (tilemap_base),bc
  235. call p1_ParseNextFullArg
  236. ld (spritesheet_ptr),bc
  237. call p1_ParseNextFullArg
  238. ld a,c
  239. ld (tilemap_height),a
  240. call p1_ParseNextFullArg
  241. cp $2B
  242. ld a,c
  243. ld (tilemap_width),a
  244. ld bc,(bufptr)
  245. call z,p1_ParseNextFullArg
  246. ld (tilemap_buf),bc
  247. ld hl,sprite_selector
  248. ld (sprite_select),hl
  249. xor a
  250. ld (tilemap_flags),a
  251. ;now generate the rest
  252. ld hl,0
  253. ld b,h ;for later
  254. ld (tilemap_sy),hl
  255. ld l,$80
  256. ld (tilemap_sx_mask),hl
  257. ld hl,(tilemap_base)
  258. ld (tilemap_top),hl
  259. ld a,(tilemap_width)
  260. add a,a \ rl b
  261. add a,a \ rl b
  262. add a,a \ rl b
  263. ld c,a
  264. add hl,bc
  265. ld (tilemap_bottom),hl
  266. ret
  267. tilemap_fullrender:
  268. ;Inputs:
  269. ; (D,E) is the offset into the map
  270. ;Set:
  271. ; (tilemap_sx_mask) is the column mask for the sprite
  272. ; (tilemap_x) is the x-offset into the tilemap
  273. ; (tilemap_sy) is the x-offset into the sprite
  274. ; (tilemap_y) is the y-offset into the tilemap
  275. ; (tilemap_top) is the pointer to the upper-left tile in view
  276. ; (tilemap_bottom) is the pointer to the bottom-left incoming row
  277. ld a,(hl)
  278. cp $2B
  279. ld c,0
  280. call z,p1_ParseNextFullArg
  281. push bc
  282. cp $2B
  283. ld c,0
  284. call z,p1_ParseNextFullArg
  285. pop de
  286. ld a,e
  287. ld (tilemap_y),a
  288. ld a,c
  289. ld (tilemap_x),a
  290. xor a
  291. ld d,a ;for later
  292. ld b,a ; for later
  293. ld (tilemap_sy),a
  294. ld a,$80
  295. ld (tilemap_sx_mask),a
  296. ld hl,(tilemap_base)
  297. ;top is x+y*w
  298. add hl,bc
  299. ld a,(tilemap_width)
  300. or a
  301. jr nc,+_
  302. ld b,a
  303. add hl,de
  304. djnz $-1
  305. _:
  306. ld (tilemap_top),hl
  307. ld a,(tilemap_width)
  308. ;now add width*8 to HL for tilemap_bottom
  309. ld e,a
  310. add a,a \ rl d
  311. add a,a \ rl d
  312. add a,a \ rl d
  313. ld e,a
  314. add hl,de
  315. ld (tilemap_bottom),hl
  316. ;Now we need to actually draw the tilemap
  317. ;I'm going to do this the slow and easy way
  318. ld hl,(tilemap_top)
  319. ld de,(tilemap_buf)
  320. ld ix,(sprite_select)
  321. ld c,0
  322. tilemap_y_loop:
  323. ld b,0
  324. push hl
  325. tilemap_x_loop:
  326. push hl
  327. push bc
  328. push de
  329. ld a,(hl)
  330. call tilemap_getsprite_at_BC
  331. pop hl
  332. push hl
  333. ;at HL, draw the tile from DE
  334. ld bc,12
  335. ld a,8
  336. _:
  337. ex de,hl
  338. ldi
  339. ex de,hl
  340. add hl,bc
  341. inc c
  342. dec a
  343. jr nz,-_
  344. pop de
  345. inc de
  346. pop bc
  347. pop hl
  348. inc hl
  349. inc b
  350. ld a,b
  351. cp 12
  352. jr nz,tilemap_x_loop
  353. ld hl,7*12
  354. add hl,de
  355. ex de,hl
  356. pop hl
  357. ;need to add width to HL
  358. ld a,(tilemap_width)
  359. add a,l
  360. ld l,a
  361. jr nc,$+3
  362. inc h
  363. inc c
  364. bit 3,c
  365. jr z,tilemap_y_loop
  366. ret
  367. tilemap_scroll_left:
  368. ld ix,(sprite_select)
  369. ld hl,(tilemap_top)
  370. ld bc,12
  371. add hl,bc
  372. ld (tempword2),hl ;tilemap pointer
  373. ld a,(tilemap_x)
  374. add a,12
  375. ld b,a
  376. ld a,(tilemap_y)
  377. ld c,a
  378. ld (tempword3),bc ;tilemap (x,y)
  379. ld a,(hl)
  380. call tilemap_getsprite
  381. ;DE points to the sprite data
  382. ld hl,(tilemap_buf)
  383. ld bc,11
  384. add hl,bc
  385. ld a,(tilemap_sy)
  386. cpl
  387. and 7
  388. inc a
  389. ld b,a
  390. ld a,(tilemap_sy)
  391. add a,e
  392. ld e,a
  393. jr nc,$+3
  394. inc d
  395. ld a,(tilemap_sx_mask)
  396. ld c,a
  397. tilemap_scroll_left_loop0:
  398. push bc
  399. ld a,(de)
  400. inc de
  401. and c
  402. add a,255
  403. ld b,12
  404. _:
  405. rl (hl)
  406. dec hl
  407. djnz -_
  408. ld c,24
  409. add hl,bc
  410. pop bc
  411. djnz tilemap_scroll_left_loop0
  412. ld b,7
  413. tilemap_scroll_left_loop1:
  414. ld a,(tempword3)
  415. inc a
  416. ld (tempword3),a
  417. push bc
  418. push hl
  419. ld hl,(tempword2)
  420. ld a,(tilemap_width)
  421. ld c,a
  422. ld b,0
  423. add hl,bc
  424. ld (tempword2),hl
  425. ld a,(hl)
  426. call tilemap_getsprite
  427. pop hl
  428. ld b,8
  429. ld a,(tilemap_sx_mask)
  430. ld c,a
  431. tilemap_scroll_left_loop2:
  432. push bc
  433. ld a,(de)
  434. inc de
  435. and c
  436. add a,255
  437. ld b,12
  438. _:
  439. rl (hl)
  440. dec hl
  441. djnz -_
  442. ld c,24
  443. add hl,bc
  444. pop bc
  445. djnz tilemap_scroll_left_loop2
  446. pop bc
  447. djnz tilemap_scroll_left_loop1
  448. ld a,(tempword3)
  449. inc a
  450. ld (tempword3),a
  451. ;final iteration
  452. push hl
  453. ld hl,(tempword2)
  454. ld a,(tilemap_width)
  455. ld c,a
  456. ld b,0
  457. add hl,bc
  458. ld (tempword2),hl
  459. ld a,(hl)
  460. call tilemap_getsprite
  461. pop hl
  462. ld a,(tilemap_sy)
  463. or a
  464. jr z,tilemap_scroll_left_end
  465. ld b,a
  466. ld a,(tilemap_sx_mask)
  467. ld c,a
  468. tilemap_scroll_left_loop3:
  469. push bc
  470. ld a,(de)
  471. inc de
  472. and c
  473. add a,255
  474. ld b,12
  475. _:
  476. rl (hl)
  477. dec hl
  478. djnz -_
  479. ld c,24
  480. add hl,bc
  481. pop bc
  482. djnz tilemap_scroll_left_loop3
  483. tilemap_scroll_left_end:
  484. ld hl,tilemap_sx_mask
  485. rrc (hl)
  486. ret nc
  487. inc hl
  488. inc (hl) ;tilemap_x
  489. ld hl,(tilemap_top)
  490. inc hl
  491. ld (tilemap_top),hl
  492. ld hl,(tilemap_bottom)
  493. inc hl
  494. ld (tilemap_bottom),hl
  495. ret
  496. tilemap_scroll_right:
  497. ld ix,(sprite_select)
  498. ld hl,tilemap_sx_mask
  499. rlc (hl)
  500. jr nc,+_
  501. inc hl
  502. dec (hl) ;tilemap_x
  503. ld hl,(tilemap_bottom)
  504. dec hl
  505. ld (tilemap_bottom),hl
  506. ld hl,(tilemap_top)
  507. dec hl
  508. ld (tilemap_top),hl
  509. _:
  510. ld hl,(tilemap_top)
  511. ld (tempword2),hl ;tilemap pointer
  512. ld a,(tilemap_x)
  513. ld b,a
  514. ld a,(tilemap_y)
  515. ld c,a
  516. ld (tempword3),bc ;tilemap (x,y)
  517. ld a,(hl)
  518. call tilemap_getsprite
  519. ;DE points to the sprite data
  520. ld hl,(tilemap_buf)
  521. ld a,(tilemap_sy)
  522. cpl
  523. and 7
  524. inc a
  525. ld b,a
  526. ld a,(tilemap_sy)
  527. add a,e
  528. ld e,a
  529. jr nc,$+3
  530. inc d
  531. ld a,(tilemap_sx_mask)
  532. ld c,a
  533. tilemap_scroll_right_loop0:
  534. push bc
  535. ld a,(de)
  536. inc de
  537. and c
  538. add a,255
  539. ld b,12
  540. _:
  541. rr (hl)
  542. inc hl
  543. djnz -_
  544. pop bc
  545. djnz tilemap_scroll_right_loop0
  546. ld b,7
  547. tilemap_scroll_right_loop1:
  548. ld a,(tempword3)
  549. inc a
  550. ld (tempword3),a
  551. push bc
  552. push hl
  553. ld hl,(tempword2)
  554. ld a,(tilemap_width)
  555. add a,l
  556. ld l,a
  557. jr nc,$+3
  558. inc h
  559. ld (tempword2),hl
  560. ld a,(hl)
  561. call tilemap_getsprite
  562. pop hl
  563. ld b,8
  564. ld a,(tilemap_sx_mask)
  565. ld c,a
  566. tilemap_scroll_right_loop2:
  567. push bc
  568. ld a,(de)
  569. inc de
  570. and c
  571. add a,255
  572. ld b,12
  573. _:
  574. rr (hl)
  575. inc hl
  576. djnz -_
  577. pop bc
  578. djnz tilemap_scroll_right_loop2
  579. pop bc
  580. djnz tilemap_scroll_right_loop1
  581. ld a,(tempword3)
  582. inc a
  583. ld (tempword3),a
  584. ;final iteration
  585. push hl
  586. ld hl,(tempword2)
  587. ld a,(tilemap_width)
  588. add a,l
  589. ld l,a
  590. jr nc,$+3
  591. inc h
  592. ld (tempword2),hl
  593. ld a,(hl)
  594. call tilemap_getsprite
  595. pop hl
  596. ld a,(tilemap_sy)
  597. or a
  598. ret z
  599. ld b,a
  600. ld a,(tilemap_sx_mask)
  601. ld c,a
  602. tilemap_scroll_right_loop3:
  603. push bc
  604. ld a,(de)
  605. inc de
  606. and c
  607. add a,255
  608. ld b,12
  609. _:
  610. rr (hl)
  611. inc hl
  612. djnz -_
  613. pop bc
  614. djnz tilemap_scroll_right_loop3
  615. ret
  616. tilemap_scroll_up:
  617. ld ix,(sprite_select)
  618. ld a,(tilemap_x)
  619. ld h,a
  620. ld a,(tilemap_y)
  621. add a,8
  622. ld l,a
  623. ld (tempword3),hl ;tilemap (x,y)
  624. ld de,(tilemap_buf)
  625. ld hl,12
  626. add hl,de
  627. ld bc,756
  628. ldir
  629. ;Now we need to populate the row of pixels
  630. ;first right the sprite data as if it is supposed to be aligned
  631. ld hl,(tilemap_bottom)
  632. ld b,12
  633. ;DE points to where to write the sprite data
  634. ;HL points to the tile
  635. ;B is the number of tiles to read
  636. tilemap_scroll_up_loop_0:
  637. push bc
  638. push hl
  639. push de
  640. ld a,(hl)
  641. call tilemap_getsprite
  642. ld a,(tilemap_sy)
  643. add a,e
  644. ld e,a
  645. jr nc,$+3
  646. inc d
  647. ld a,(de)
  648. pop de
  649. ld (de),a
  650. inc de
  651. pop hl
  652. inc hl
  653. ld a,(tempword3+1)
  654. inc a
  655. ld (tempword3+1),a
  656. pop bc
  657. djnz tilemap_scroll_up_loop_0
  658. ;now we need to shift the row left, shifting in the bits from the next tile
  659. push de
  660. ld a,(hl)
  661. call tilemap_getsprite
  662. ld a,(tilemap_sy)
  663. add a,e
  664. ld e,a
  665. jr nc,$+3
  666. inc d
  667. ld a,(de)
  668. pop hl
  669. ld c,a
  670. ld a,(tilemap_sx_mask)
  671. ;need to shift in C until A is $80
  672. ld de,12
  673. jr tilemap_scroll_up_loop_1_start
  674. tilemap_scroll_up_loop_1:
  675. ld b,e
  676. rlc c
  677. _:
  678. dec hl
  679. rl (hl)
  680. djnz -_
  681. add hl,de
  682. tilemap_scroll_up_loop_1_start:
  683. add a,a
  684. jr nc,tilemap_scroll_up_loop_1
  685. ld a,(tilemap_sy)
  686. inc a
  687. and 7
  688. ld (tilemap_sy),a
  689. ret nz
  690. ld a,(tilemap_y)
  691. inc a
  692. ld (tilemap_y),a
  693. ld a,(tilemap_width)
  694. ld c,a
  695. ld b,0
  696. ld hl,(tilemap_top)
  697. add hl,bc
  698. ld (tilemap_top),hl
  699. ld hl,(tilemap_bottom)
  700. add hl,bc
  701. ld (tilemap_bottom),hl
  702. ret
  703. tilemap_scroll_down:
  704. ld ix,(sprite_select)
  705. ld a,(tilemap_x)
  706. ld h,a
  707. ld a,(tilemap_y)
  708. ld l,a
  709. ld (tempword3),hl ;tilemap (x,y)
  710. ld de,(tilemap_buf)
  711. inc d
  712. inc d
  713. inc d
  714. dec de
  715. ld hl,-12
  716. add hl,de
  717. ld bc,756
  718. lddr
  719. ld a,(tilemap_sy)
  720. dec a
  721. ld (tilemap_sy),a
  722. jp p,+_
  723. and 7
  724. ld (tilemap_sy),a
  725. ld a,(tilemap_y)
  726. dec a
  727. ld (tilemap_y),a
  728. ld (tempword3),a
  729. ld a,(tilemap_width)
  730. neg
  731. ld c,a
  732. ld b,-1
  733. ld hl,(tilemap_top)
  734. add hl,bc
  735. ld (tilemap_top),hl
  736. ld hl,(tilemap_bottom)
  737. add hl,bc
  738. ld (tilemap_bottom),hl
  739. _:
  740. ;Now we need to populate the row of pixels
  741. ;first right the sprite data as if it is supposed to be aligned
  742. ld de,(tilemap_buf)
  743. ld hl,(tilemap_top)
  744. ld b,12
  745. ;DE points to where to write the sprite data
  746. ;HL points to the tile
  747. ;B is the number of tiles to read
  748. tilemap_scroll_down_loop_0:
  749. push bc
  750. push hl
  751. push de
  752. ld a,(hl)
  753. call tilemap_getsprite
  754. ld a,(tilemap_sy)
  755. add a,e
  756. ld e,a
  757. jr nc,$+3
  758. inc d
  759. ld a,(de)
  760. pop de
  761. ld (de),a
  762. inc de
  763. pop hl
  764. inc hl
  765. ld a,(tempword3+1)
  766. inc a
  767. ld (tempword3+1),a
  768. pop bc
  769. djnz tilemap_scroll_down_loop_0
  770. ;now we need to shift the row left, shifting in the bits from the next tile
  771. push de
  772. ld a,(hl)
  773. call tilemap_getsprite
  774. ld a,(tilemap_sy)
  775. add a,e
  776. ld e,a
  777. jr nc,$+3
  778. inc d
  779. ld a,(de)
  780. pop hl
  781. ld c,a
  782. ld a,(tilemap_sx_mask)
  783. ;need to shift in C until A is $80
  784. ld de,12
  785. jr tilemap_scroll_down_loop_1_start
  786. tilemap_scroll_down_loop_1:
  787. ld b,e
  788. rlc c
  789. _:
  790. dec hl
  791. rl (hl)
  792. djnz -_
  793. add hl,de
  794. tilemap_scroll_down_loop_1_start:
  795. add a,a
  796. jr nc,tilemap_scroll_down_loop_1
  797. ret
  798. tilemap_getsprite:
  799. ld bc,(tempword3)
  800. tilemap_getsprite_at_BC:
  801. ld hl,(tilemap_height)
  802. jp (ix)
  803. sprite_selector:
  804. ld e,a
  805. ld a,b
  806. cp h
  807. jr nc,+_
  808. ld a,c
  809. cp l
  810. ld a,e
  811. _:
  812. ld de,(spritesheet_ptr)
  813. ret nc
  814. ld l,a
  815. ld h,0
  816. add hl,hl
  817. add hl,hl
  818. add hl,hl
  819. add hl,de
  820. ex de,hl
  821. ret