Advertisement
luckytyphlosion

unrolled LoadMapPart

Dec 21st, 2017
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.10 KB | None | 0 0
  1. loadmapblock: MACRO
  2. ld a, [de]
  3. inc de
  4. and a
  5. jr nz, .notMapBorderBlock\@
  6. ld a, [hMapBorderBlock]
  7. .notMapBorderBlock\@
  8. ENDM
  9.  
  10. nocarry: MACRO
  11. jr nc, .noCarry\@
  12. dec h
  13. .noCarry\@
  14. ENDM
  15.  
  16. addmapwidthoffset: MACRO
  17. ld a, [hMapWidthPlus6]
  18. add e
  19. ld e, a
  20. jr nc, .noCarry\@
  21. inc d
  22. .noCarry\@
  23. ENDM
  24.  
  25. _LoadMapPart::
  26. ld a, [wOverworldMapAnchor]
  27. ld e, a
  28. ld a, [wOverworldMapAnchor + 1]
  29. ld d, a
  30. ld a, [wMapBorderBlock]
  31. ld [hMapBorderBlock], a
  32. ld a, [wMapWidth]
  33. inc a
  34. ld [hMapWidthPlus6], a
  35. ld a, [wMetatileStandingY]
  36. add a
  37. ld b, a
  38. ld a, [wMetatileStandingX]
  39. or b
  40. ld b, a
  41. ld a, [rSVBK]
  42. push af
  43. ld a, BANK(wDecompressedMetatiles)
  44. ld [rSVBK], a
  45. call .Function
  46. pop af
  47. ld [rSVBK], a
  48. ret
  49.  
  50. .Function:
  51. ld a, b
  52. and a
  53. jp z, .BlockY0BlockX0
  54. dec a
  55. jp z, .BlockY0BlockX1
  56. coord hl, 0, 0
  57. dec a
  58. jp z, .BlockY1BlockX0
  59. ; block y1, block x1
  60.  
  61. .BlockY1BlockX1:
  62. ; LoadOneQuarterBottomRightMetatile
  63. .LoadOneQuarterBottomRightMetatile:
  64. loadmapblock
  65. ld b, d
  66. ld c, e
  67. swap a
  68. ld d, a
  69. and $f0
  70. add 10
  71. call .LoadOneQuarterMetatile
  72. ld d, b
  73. ld e, c
  74.  
  75. coord hl, 2, 0
  76. ld bc, SCREEN_WIDTH - 4
  77. call .LoadOneRowOf4BottomHalfBlocks
  78. coord hl, 18, 0
  79. ; LoadOneQuarterBottomLeftMetatile
  80. loadmapblock
  81. ld b, d
  82. ld c, e
  83. swap a
  84. ld d, a
  85. and $f0
  86. add 8
  87. call .LoadOneQuarterMetatile
  88. ld d, b
  89. ld e, c
  90.  
  91. ld hl, hMapWidthPlus6
  92. dec [hl]
  93. addmapwidthoffset
  94.  
  95. coord hl, 0, 2
  96. ld bc, SCREEN_WIDTH - 1
  97. call .LoadOneRowOf5BlocksFromHalfRightMetatile
  98. coord hl, 0, 6
  99. call .LoadOneRowOf5BlocksFromHalfRightMetatile
  100. coord hl, 0, 10
  101. call .LoadOneRowOf5BlocksFromHalfRightMetatile
  102. coord hl, 0, 14
  103.  
  104. .LoadOneRowOf5BlocksFromHalfRightMetatile:
  105. loadmapblock
  106. push de
  107. swap a
  108. ld d, a
  109. and $f0
  110. inc a
  111. inc a
  112. ld e, a
  113. ld a, d
  114. and $f
  115. add (wDecompressedMetatiles >> 8)
  116. ld d, a
  117.  
  118. rept 3
  119. ld a, [de]
  120. inc e
  121. ld [hli], a
  122. ld a, [de]
  123. inc e
  124. inc e
  125. inc e
  126. ld [hl], a
  127. add hl, bc
  128. endr
  129.  
  130. ld a, [de]
  131. inc e
  132. ld [hli], a
  133. ld a, [de]
  134. ld [hl], a
  135. pop de
  136. ld a, l
  137. sub (SCREEN_WIDTH * 3) - 1
  138. ld l, a
  139. nocarry
  140. ; LoadOneRowOf4Blocks:
  141. ld c, SCREEN_WIDTH - 4
  142. loadmapblock
  143. push de
  144. swap a
  145. ld d, a
  146. and $f0
  147. ld e, a
  148. ld a, d
  149. and $f
  150. add (wDecompressedMetatiles >> 8)
  151. ld d, a
  152. ; copy the 4x4 metatile
  153.  
  154. ; rows 1 - 3
  155. rept 3
  156. rept 4
  157. ld a, [de]
  158. ld [hli], a
  159. inc e
  160. endr
  161. add hl, bc
  162. endr
  163. ; row 4
  164. rept 3
  165. ld a, [de]
  166. ld [hli], a
  167. inc e
  168. endr
  169. ld a, [de]
  170. ld [hl], a
  171. pop de
  172. ld a, l
  173. sub (SCREEN_WIDTH * 3) - 1
  174. ld l, a
  175. nocarry
  176. ; Next metatile
  177. loadmapblock
  178. push de
  179. swap a
  180. ld d, a
  181. and $f0
  182. ld e, a
  183. ld a, d
  184. and $f
  185. add (wDecompressedMetatiles >> 8)
  186. ld d, a
  187. ; copy the 4x4 metatile
  188.  
  189. ; rows 1 - 3
  190. rept 3
  191. rept 4
  192. ld a, [de]
  193. ld [hli], a
  194. inc e
  195. endr
  196. add hl, bc
  197. endr
  198. ; row 4
  199. rept 3
  200. ld a, [de]
  201. ld [hli], a
  202. inc e
  203. endr
  204. ld a, [de]
  205. ld [hl], a
  206. pop de
  207. ld a, l
  208. sub (SCREEN_WIDTH * 3) - 1
  209. ld l, a
  210. nocarry
  211. ; Next metatile
  212. loadmapblock
  213. push de
  214. swap a
  215. ld d, a
  216. and $f0
  217. ld e, a
  218. ld a, d
  219. and $f
  220. add (wDecompressedMetatiles >> 8)
  221. ld d, a
  222. ; copy the 4x4 metatile
  223.  
  224. ; rows 1 - 3
  225. rept 3
  226. rept 4
  227. ld a, [de]
  228. ld [hli], a
  229. inc e
  230. endr
  231. add hl, bc
  232. endr
  233. ; row 4
  234. rept 3
  235. ld a, [de]
  236. ld [hli], a
  237. inc e
  238. endr
  239. ld a, [de]
  240. ld [hl], a
  241. pop de
  242. ld a, l
  243. sub (SCREEN_WIDTH * 3) - 1
  244. ld l, a
  245. nocarry
  246. loadmapblock
  247. ; Next metatile
  248. push de
  249. swap a
  250. ld d, a
  251. and $f0
  252. ld e, a
  253. ld a, d
  254. and $f
  255. add (wDecompressedMetatiles >> 8)
  256. ld d, a
  257. ; copy the 4x4 metatile
  258.  
  259. ; rows 1 - 3
  260. rept 3
  261. rept 4
  262. ld a, [de]
  263. ld [hli], a
  264. inc e
  265. endr
  266. add hl, bc
  267. endr
  268. ; row 4
  269. rept 3
  270. ld a, [de]
  271. ld [hli], a
  272. inc e
  273. endr
  274. ld a, [de]
  275. ld [hl], a
  276. pop de
  277. ld a, l
  278. sub (SCREEN_WIDTH * 3) - 1
  279. ld l, a
  280. nocarry
  281. ; LoadOneHalfLeftMetatile
  282. loadmapblock
  283. ld c, SCREEN_WIDTH - 1
  284. push de
  285. swap a
  286. ld d, a
  287. and $f0
  288. ld e, a
  289. ld a, d
  290. and $f
  291. add (wDecompressedMetatiles >> 8)
  292. ld d, a
  293.  
  294. rept 3
  295. ld a, [de]
  296. inc e
  297. ld [hli], a
  298. ld a, [de]
  299. inc e
  300. inc e
  301. inc e
  302. ld [hl], a
  303. add hl, bc
  304. endr
  305.  
  306. ld a, [de]
  307. inc e
  308. ld [hli], a
  309. ld a, [de]
  310. ld [hl], a
  311. pop de
  312. ld a, [hMapWidthPlus6]
  313. add e
  314. ld e, a
  315. ret nc
  316. inc d
  317. ret
  318.  
  319. .BlockY0BlockX0:
  320. coord hl, 0, 0
  321. ld bc, SCREEN_WIDTH - 4
  322. call .LoadOneRowOf5Blocks
  323. coord hl, 0, 4
  324. call .LoadOneRowOf5Blocks
  325. coord hl, 0, 8
  326. call .LoadOneRowOf5Blocks
  327. coord hl, 0, 12
  328. call .LoadOneRowOf5Blocks
  329. coord hl, 0, 16
  330.  
  331. ; LoadOneRowOf5UpperHalfBlocks
  332. loadmapblock
  333. push de
  334. swap a
  335. ld d, a
  336. and $f0
  337. ld e, a
  338. ld a, d
  339. and $f
  340. add (wDecompressedMetatiles >> 8)
  341. ld d, a
  342. ; copy the 4x4 metatile
  343.  
  344. ; row 1
  345. rept 4
  346. ld a, [de]
  347. ld [hli], a
  348. inc e
  349. endr
  350. add hl, bc
  351. ; row 2
  352. rept 3
  353. ld a, [de]
  354. ld [hli], a
  355. inc e
  356. endr
  357. ld a, [de]
  358. ld [hl], a
  359. pop de
  360. ; Next metatile
  361. ld a, l
  362. sub (SCREEN_WIDTH * 1) - 1
  363. ld l, a
  364. nocarry
  365. .LoadOneRowOf4UpperHalfBlocks:
  366. loadmapblock
  367. push de
  368. swap a
  369. ld d, a
  370. and $f0
  371. ld e, a
  372. ld a, d
  373. and $f
  374. add (wDecompressedMetatiles >> 8)
  375. ld d, a
  376. ; copy the 4x4 metatile
  377.  
  378. ; row 1
  379. rept 4
  380. ld a, [de]
  381. ld [hli], a
  382. inc e
  383. endr
  384. add hl, bc
  385. ; row 2
  386. rept 3
  387. ld a, [de]
  388. ld [hli], a
  389. inc e
  390. endr
  391. ld a, [de]
  392. ld [hl], a
  393. pop de
  394. ; Next metatile
  395. ld a, l
  396. sub (SCREEN_WIDTH * 1) - 1
  397. ld l, a
  398. nocarry
  399. loadmapblock
  400. push de
  401. swap a
  402. ld d, a
  403. and $f0
  404. ld e, a
  405. ld a, d
  406. and $f
  407. add (wDecompressedMetatiles >> 8)
  408. ld d, a
  409. ; copy the 4x4 metatile
  410.  
  411. ; row 1
  412. rept 4
  413. ld a, [de]
  414. ld [hli], a
  415. inc e
  416. endr
  417. add hl, bc
  418. ; row 2
  419. rept 3
  420. ld a, [de]
  421. ld [hli], a
  422. inc e
  423. endr
  424. ld a, [de]
  425. ld [hl], a
  426. pop de
  427. ; Next metatile
  428. ld a, l
  429. sub (SCREEN_WIDTH * 1) - 1
  430. ld l, a
  431. nocarry
  432. loadmapblock
  433. push de
  434. swap a
  435. ld d, a
  436. and $f0
  437. ld e, a
  438. ld a, d
  439. and $f
  440. add (wDecompressedMetatiles >> 8)
  441. ld d, a
  442. ; copy the 4x4 metatile
  443.  
  444. ; row 1
  445. rept 4
  446. ld a, [de]
  447. ld [hli], a
  448. inc e
  449. endr
  450. add hl, bc
  451. ; row 2
  452. rept 3
  453. ld a, [de]
  454. ld [hli], a
  455. inc e
  456. endr
  457. ld a, [de]
  458. ld [hl], a
  459. pop de
  460. ; Next metatile
  461. ld a, l
  462. sub (SCREEN_WIDTH * 1) - 1
  463. ld l, a
  464. nocarry
  465. loadmapblock
  466. push de
  467. swap a
  468. ld d, a
  469. and $f0
  470. ld e, a
  471. ld a, d
  472. and $f
  473. add (wDecompressedMetatiles >> 8)
  474. ld d, a
  475. ; copy the 4x4 metatile
  476.  
  477. ; row 1
  478. rept 4
  479. ld a, [de]
  480. ld [hli], a
  481. inc e
  482. endr
  483. add hl, bc
  484. ; row 2
  485. rept 3
  486. ld a, [de]
  487. ld [hli], a
  488. inc e
  489. endr
  490. ld a, [de]
  491. ld [hl], a
  492. pop de
  493. ret
  494.  
  495. .BlockY1BlockX0:
  496. call .LoadOneHalfRowOf5LowerHalfBlocks
  497. addmapwidthoffset
  498. coord hl, 0, 2
  499. call .LoadOneRowOf5Blocks
  500. coord hl, 0, 6
  501. call .LoadOneRowOf5Blocks
  502. coord hl, 0, 10
  503. call .LoadOneRowOf5Blocks
  504. coord hl, 0, 14
  505.  
  506. ; fallthrough
  507. .LoadOneRowOf5Blocks:
  508. loadmapblock
  509. push de
  510. swap a
  511. ld d, a
  512. and $f0
  513. ld e, a
  514. ld a, d
  515. and $f
  516. add (wDecompressedMetatiles >> 8)
  517. ld d, a
  518. ; copy the 4x4 metatile
  519.  
  520. ; rows 1 - 3
  521. rept 3
  522. rept 4
  523. ld a, [de]
  524. ld [hli], a
  525. inc e
  526. endr
  527. add hl, bc
  528. endr
  529. ; row 4
  530. rept 3
  531. ld a, [de]
  532. ld [hli], a
  533. inc e
  534. endr
  535. ld a, [de]
  536. ld [hl], a
  537. pop de
  538. ld a, l
  539. sub (SCREEN_WIDTH * 3) - 1
  540. ld l, a
  541. nocarry
  542. ; .LoadOneRowOf4Blocks_Entrypoint:
  543. ; Next metatile
  544. loadmapblock
  545. push de
  546. swap a
  547. ld d, a
  548. and $f0
  549. ld e, a
  550. ld a, d
  551. and $f
  552. add (wDecompressedMetatiles >> 8)
  553. ld d, a
  554. ; copy the 4x4 metatile
  555.  
  556. ; rows 1 - 3
  557. rept 3
  558. rept 4
  559. ld a, [de]
  560. ld [hli], a
  561. inc e
  562. endr
  563. add hl, bc
  564. endr
  565. ; row 4
  566. rept 3
  567. ld a, [de]
  568. ld [hli], a
  569. inc e
  570. endr
  571. ld a, [de]
  572. ld [hl], a
  573. pop de
  574. ld a, l
  575. sub (SCREEN_WIDTH * 3) - 1
  576. ld l, a
  577. nocarry
  578. ; Next metatile
  579. loadmapblock
  580. push de
  581. swap a
  582. ld d, a
  583. and $f0
  584. ld e, a
  585. ld a, d
  586. and $f
  587. add (wDecompressedMetatiles >> 8)
  588. ld d, a
  589. ; copy the 4x4 metatile
  590.  
  591. ; rows 1 - 3
  592. rept 3
  593. rept 4
  594. ld a, [de]
  595. ld [hli], a
  596. inc e
  597. endr
  598. add hl, bc
  599. endr
  600. ; row 4
  601. rept 3
  602. ld a, [de]
  603. ld [hli], a
  604. inc e
  605. endr
  606. ld a, [de]
  607. ld [hl], a
  608. pop de
  609. ld a, l
  610. sub (SCREEN_WIDTH * 3) - 1
  611. ld l, a
  612. nocarry
  613. ; Next metatile
  614. loadmapblock
  615. push de
  616. swap a
  617. ld d, a
  618. and $f0
  619. ld e, a
  620. ld a, d
  621. and $f
  622. add (wDecompressedMetatiles >> 8)
  623. ld d, a
  624. ; copy the 4x4 metatile
  625.  
  626. ; rows 1 - 3
  627. rept 3
  628. rept 4
  629. ld a, [de]
  630. ld [hli], a
  631. inc e
  632. endr
  633. add hl, bc
  634. endr
  635. ; row 4
  636. rept 3
  637. ld a, [de]
  638. ld [hli], a
  639. inc e
  640. endr
  641. ld a, [de]
  642. ld [hl], a
  643. pop de
  644. ld a, l
  645. sub (SCREEN_WIDTH * 3) - 1
  646. ld l, a
  647. nocarry
  648. loadmapblock
  649. ; Next metatile
  650. push de
  651. swap a
  652. ld d, a
  653. and $f0
  654. ld e, a
  655. ld a, d
  656. and $f
  657. add (wDecompressedMetatiles >> 8)
  658. ld d, a
  659. ; copy the 4x4 metatile
  660.  
  661. ; rows 1 - 3
  662. rept 3
  663. rept 4
  664. ld a, [de]
  665. ld [hli], a
  666. inc e
  667. endr
  668. add hl, bc
  669. endr
  670. ; row 4
  671. rept 3
  672. ld a, [de]
  673. ld [hli], a
  674. inc e
  675. endr
  676. ld a, [de]
  677. ld [hl], a
  678. pop de
  679. ld a, [hMapWidthPlus6]
  680. add e
  681. ld e, a
  682. ret nc
  683. inc d
  684. ret
  685.  
  686. .LoadOneHalfRowOf5LowerHalfBlocks:
  687. ld bc, SCREEN_WIDTH - 4
  688. loadmapblock
  689. push de
  690. swap a
  691. ld d, a
  692. and $f0
  693. add 8
  694. ld e, a
  695. ld a, d
  696. and $f
  697. add (wDecompressedMetatiles >> 8)
  698. ld d, a
  699. ; copy the 4x4 metatile
  700.  
  701. ; row 1
  702. rept 4
  703. ld a, [de]
  704. ld [hli], a
  705. inc e
  706. endr
  707. add hl, bc
  708. ; row 2
  709. rept 3
  710. ld a, [de]
  711. ld [hli], a
  712. inc e
  713. endr
  714. ld a, [de]
  715. ld [hl], a
  716. pop de
  717. ; Next metatile
  718.  
  719. ld a, l
  720. sub (SCREEN_WIDTH * 1) - 1
  721. ld l, a
  722. nocarry
  723. .LoadOneRowOf4BottomHalfBlocks:
  724. loadmapblock
  725. push de
  726. swap a
  727. ld d, a
  728. and $f0
  729. add 8
  730. ld e, a
  731. ld a, d
  732. and $f
  733. add (wDecompressedMetatiles >> 8)
  734. ld d, a
  735. ; copy the 4x4 metatile
  736.  
  737. ; row 1
  738. rept 4
  739. ld a, [de]
  740. ld [hli], a
  741. inc e
  742. endr
  743. add hl, bc
  744. ; row 2
  745. rept 3
  746. ld a, [de]
  747. ld [hli], a
  748. inc e
  749. endr
  750. ld a, [de]
  751. ld [hl], a
  752. pop de
  753. ; Next metatile
  754.  
  755. ld a, l
  756. sub (SCREEN_WIDTH * 1) - 1
  757. ld l, a
  758. nocarry
  759. loadmapblock
  760. push de
  761. swap a
  762. ld d, a
  763. and $f0
  764. add 8
  765. ld e, a
  766. ld a, d
  767. and $f
  768. add (wDecompressedMetatiles >> 8)
  769. ld d, a
  770. ; copy the 4x4 metatile
  771.  
  772. ; row 1
  773. rept 4
  774. ld a, [de]
  775. ld [hli], a
  776. inc e
  777. endr
  778. add hl, bc
  779. ; row 2
  780. rept 3
  781. ld a, [de]
  782. ld [hli], a
  783. inc e
  784. endr
  785. ld a, [de]
  786. ld [hl], a
  787. pop de
  788. ; Next metatile
  789.  
  790. ld a, l
  791. sub (SCREEN_WIDTH * 1) - 1
  792. ld l, a
  793. nocarry
  794. loadmapblock
  795. push de
  796. swap a
  797. ld d, a
  798. and $f0
  799. add 8
  800. ld e, a
  801. ld a, d
  802. and $f
  803. add (wDecompressedMetatiles >> 8)
  804. ld d, a
  805. ; copy the 4x4 metatile
  806.  
  807. ; row 1
  808. rept 4
  809. ld a, [de]
  810. ld [hli], a
  811. inc e
  812. endr
  813. add hl, bc
  814. ; row 2
  815. rept 3
  816. ld a, [de]
  817. ld [hli], a
  818. inc e
  819. endr
  820. ld a, [de]
  821. ld [hl], a
  822. pop de
  823. ; Next metatile
  824.  
  825. ld a, l
  826. sub (SCREEN_WIDTH * 1) - 1
  827. ld l, a
  828. nocarry
  829. loadmapblock
  830. push de
  831. swap a
  832. ld d, a
  833. and $f0
  834. add 8
  835. ld e, a
  836. ld a, d
  837. and $f
  838. add (wDecompressedMetatiles >> 8)
  839. ld d, a
  840. ; copy the 4x4 metatile
  841.  
  842. ; row 1
  843. rept 4
  844. ld a, [de]
  845. ld [hli], a
  846. inc e
  847. endr
  848. add hl, bc
  849. ; row 2
  850. rept 3
  851. ld a, [de]
  852. ld [hli], a
  853. inc e
  854. endr
  855. ld a, [de]
  856. ld [hl], a
  857. pop de
  858. ; Next metatile
  859. ret
  860.  
  861. .BlockY0BlockX1:
  862. ld hl, hMapWidthPlus6
  863. dec [hl]
  864. coord hl, 0, 0
  865. ld bc, SCREEN_WIDTH - 1
  866. call .LoadOneRowOf5BlocksFromHalfRightMetatile
  867. coord hl, 0, 4
  868. call .LoadOneRowOf5BlocksFromHalfRightMetatile
  869. coord hl, 0, 8
  870. call .LoadOneRowOf5BlocksFromHalfRightMetatile
  871. coord hl, 0, 12
  872. call .LoadOneRowOf5BlocksFromHalfRightMetatile
  873.  
  874. ; LoadOneQuarterUpperRightMetatile
  875. coord hl, 0, 16
  876. loadmapblock
  877. ld b, d
  878. ld c, e
  879. swap a
  880. ld d, a
  881. and $f0
  882. inc a
  883. inc a
  884. call .LoadOneQuarterMetatile
  885. ld d, b
  886. ld e, c
  887.  
  888. coord hl, 2, 16
  889. ld bc, SCREEN_WIDTH - 4
  890. call .LoadOneRowOf4UpperHalfBlocks
  891. coord hl, 18, 16
  892.  
  893. ; LoadOneQuarterUpperLeftMetatile
  894. ld a, [de]
  895. and a
  896. jr nz, .notMapBorderBlock3
  897. ld a, [hMapBorderBlock]
  898. .notMapBorderBlock3
  899. swap a
  900. ld d, a
  901. and $f0
  902.  
  903. ; fallthrough
  904. .LoadOneQuarterMetatile:
  905. ld e, a
  906. ld a, d
  907. and $f
  908. add (wDecompressedMetatiles >> 8)
  909. ld d, a
  910.  
  911. ld a, [de]
  912. inc e
  913. ld [hli], a
  914. ld a, [de]
  915. inc e
  916. inc e
  917. inc e
  918. ld [hl], a
  919. ld a, SCREEN_WIDTH - 1
  920. add l
  921. ld l, a
  922. jr nc, .noCarry
  923. inc h
  924. .noCarry
  925. ld a, [de]
  926. inc e
  927. ld [hli], a
  928. ld a, [de]
  929. ld [hl], a
  930. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement