Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.30 KB | None | 0 0
  1. ; Functions dealing with rendering and interacting with maps.
  2.  
  3. CheckTriggers:: ; 211b
  4. ; Checks wCurrentMapTriggerPointer. If it's empty, returns -1 in a. Otherwise, returns the active trigger ID in a.
  5. push hl
  6. ld hl, wCurrentMapTriggerPointer
  7. ld a, [hli]
  8. ld h, [hl]
  9. ld l, a
  10. or h
  11. ld a, [hl]
  12. jr nz, .triggerexists
  13. ld a, -1
  14.  
  15. .triggerexists
  16. pop hl
  17. ret
  18. ; 212a
  19.  
  20. GetCurrentMapTrigger:: ; 212a
  21. ; Grabs the wram map trigger pointer for the current map and loads it into wCurrentMapTriggerPointer.
  22. ; If there are no triggers, both bytes of wCurrentMapTriggerPointer are wiped clean.
  23. ; Copy the current map group and number into bc. This is needed for GetMapTrigger.
  24. ld a, [wMapGroup]
  25. ld b, a
  26. ld a, [wMapNumber]
  27. ld c, a
  28. ; Blank out wCurrentMapTriggerPointer; this is the default scenario.
  29. xor a
  30. ld [wCurrentMapTriggerPointer], a
  31. ld [wCurrentMapTriggerPointer + 1], a
  32. call GetMapTrigger
  33. ret c ; The map is not in the trigger table
  34. ; Load the trigger table pointer from de into wCurrentMapTriggerPointer
  35. ld a, e
  36. ld [wCurrentMapTriggerPointer], a
  37. ld a, d
  38. ld [wCurrentMapTriggerPointer + 1], a
  39. xor a
  40. ret
  41. ; 2147
  42.  
  43. GetMapTrigger::
  44. ; Searches the trigger table for the map group and number loaded in bc, and returns the wram pointer in de.
  45. ; If the map is not in the trigger table, returns carry.
  46. anonbankpush MapTriggers
  47.  
  48. .Function:
  49. ld hl, MapTriggers
  50. ld de, 4
  51. jr .handleLoop
  52. .loop
  53. pop hl
  54. add hl, de
  55. .handleLoop
  56. push hl
  57. ld a, [hli] ; map group, or terminator
  58. cp -1
  59. jr z, .end ; the current map is not in the trigger table
  60. cp b
  61. jr nz, .loop ; map group did not match
  62. ld a, [hli] ; map number
  63. cp c
  64. jr nz, .loop ; map number did not match
  65. ld a, [hli]
  66. ld d, [hl]
  67. ld e, a
  68. jr .done
  69. .end
  70. scf
  71. .done
  72. pop hl
  73. ret
  74.  
  75. LoadMapPart:: ; 217a
  76. farjp _LoadMapPart
  77.  
  78. ReturnToMapFromSubmenu::
  79. ld a, MAPSETUP_SUBMENU
  80. ld [hMapEntryMethod], a
  81. farcall RunMapSetupScript
  82. xor a
  83. ld [hMapEntryMethod], a
  84. ret
  85.  
  86. CheckWarpTile::
  87. call GetDestinationWarpNumber
  88. ret nc
  89.  
  90. push bc
  91. farcall CheckDirectionalWarp
  92. pop bc
  93. ret nc
  94.  
  95. call CopyWarpData
  96. scf
  97. ret
  98.  
  99. WarpCheck::
  100. call GetDestinationWarpNumber
  101. ret nc
  102. jp CopyWarpData
  103.  
  104. GetDestinationWarpNumber:: ; 2252
  105. farcall CheckWarpCollision
  106. ret nc
  107.  
  108. ld a, [hROMBank]
  109. push af
  110.  
  111. call SwitchToMapScriptHeaderBank
  112. call .GetDestinationWarpNumber
  113.  
  114. pop de
  115. ld a, d
  116. rst Bankswitch
  117. ret
  118. ; 2266
  119.  
  120. .GetDestinationWarpNumber: ; 2266
  121. ld a, [wPlayerStandingMapY]
  122. sub $4
  123. ld e, a
  124. ld a, [wPlayerStandingMapX]
  125. sub $4
  126. ld d, a
  127. ld a, [wCurrMapWarpCount]
  128. and a
  129. ret z
  130.  
  131. ld c, a
  132. ld hl, wCurrMapWarpHeaderPointer
  133. ld a, [hli]
  134. ld h, [hl]
  135. ld l, a
  136. .loop
  137. push hl
  138. ld a, [hli]
  139. cp e
  140. jr nz, .next
  141. ld a, [hli]
  142. cp d
  143. jr nz, .next
  144. jr .found_warp
  145.  
  146. .next
  147. pop hl
  148. ld a, 5
  149. add l
  150. ld l, a
  151. jr nc, .okay
  152. inc h
  153.  
  154. .okay
  155. dec c
  156. jr nz, .loop
  157. xor a
  158. ret
  159.  
  160. .found_warp
  161. pop hl
  162. inc hl
  163. inc hl
  164.  
  165. ld a, [wCurrMapWarpCount]
  166. inc a
  167. sub c
  168. ld c, a
  169. scf
  170. ret
  171.  
  172. CopyWarpData:: ; 22a7
  173. ld a, [hROMBank]
  174. push af
  175.  
  176. call SwitchToMapScriptHeaderBank
  177. call .CopyWarpData
  178.  
  179. pop af
  180. rst Bankswitch
  181. scf
  182. ret
  183. ; 22b4
  184.  
  185. .CopyWarpData: ; 22b4
  186. push bc
  187. ld hl, wCurrMapWarpHeaderPointer
  188. ld a, [hli]
  189. ld h, [hl]
  190. ld l, a
  191. ld a, c
  192. dec a
  193. ld bc, 5 ; warp size
  194. rst AddNTimes
  195. ld bc, 2 ; warp number
  196. add hl, bc
  197. ld a, [hli]
  198. cp $ff
  199. jr nz, .skip
  200. ld hl, wBackupWarpNumber
  201. ld a, [hli]
  202.  
  203. .skip
  204. pop bc
  205. ld [wNextWarp], a
  206. ld a, [hli]
  207. ld [wNextMapGroup], a
  208. ld a, [hli]
  209. ld [wNextMapNumber], a
  210.  
  211. ld a, c
  212. ld [wPrevWarp], a
  213. ld a, [wMapGroup]
  214. ld [wPrevMapGroup], a
  215. ld a, [wMapNumber]
  216. ld [wPrevMapNumber], a
  217. scf
  218. ret
  219. ; 22ee
  220.  
  221. CheckOutdoorMapOrPerm5::
  222. cp PERM_5
  223. ret z
  224. CheckOutdoorMap:: ; 22ee
  225. cp ROUTE
  226. ret z
  227. cp TOWN
  228. ret
  229. ; 22f4
  230.  
  231. CheckIndoorMap:: ; 22f4
  232. cp INDOOR
  233. ret z
  234. cp CAVE
  235. ret z
  236. cp DUNGEON
  237. ret z
  238. cp GATE
  239. ret
  240. ; 2300
  241.  
  242. LoadMapAttributes:: ; 2309
  243. call CopyMapHeaders
  244. call SwitchToMapScriptHeaderBank
  245. xor a ; FALSE
  246. jr ReadMapScripts
  247. ; 2317
  248.  
  249. LoadMapAttributes_SkipPeople:: ; 2317
  250. call CopyMapHeaders
  251. call SwitchToMapScriptHeaderBank
  252. ld a, TRUE
  253. ; fallthrough
  254. ReadMapScripts:: ; 234f
  255. push af
  256. ld hl, wMapScriptHeaderPointer
  257. ld a, [hli]
  258. ld h, [hl]
  259. ld l, a
  260. call ReadMapTriggers
  261. call ReadMapCallbacks
  262. call ReadWarps
  263. call ReadCoordEvents
  264. call ReadSignposts
  265. pop af
  266. and a
  267. ret nz
  268. ; fallthrough
  269. ReadObjectEvents:: ; 241f
  270. push hl
  271. call ClearObjectStructs
  272. pop de
  273. ld hl, wMap1Object
  274. ld a, [de]
  275. inc de
  276. ld [wCurrentMapPersonEventCount], a
  277. ld a, e
  278. ld [wCurrentMapPersonEventHeaderPointer], a
  279. ld a, d
  280. ld [wCurrentMapPersonEventHeaderPointer + 1], a
  281.  
  282. ld a, [wCurrentMapPersonEventCount]
  283. call CopyMapObjectHeaders
  284.  
  285. ; get NUM_OBJECTS - 1 - [wCurrentMapPersonEventCount]
  286. ld a, [wCurrentMapPersonEventCount]
  287. ld c, a
  288. ld a, NUM_OBJECTS - 1
  289. sub c
  290. jr z, .skip
  291. jr c, .skip
  292. inc hl
  293. ; Fill the remaining sprite IDs and y coords with 0 and -1, respectively.
  294. ld bc, OBJECT_LENGTH
  295. .loop
  296. ld [hl], 0
  297. inc hl
  298. ld [hl], -1
  299. dec hl
  300. add hl, bc
  301. dec a
  302. jr nz, .loop
  303.  
  304. .skip
  305. ld h, d
  306. ld l, e
  307. ret
  308. ; 2457
  309.  
  310.  
  311. CopySecondMapHeader:: ; 235c
  312. ld de, wMapHeader
  313. ld c, 10 ; size of the second map header
  314. .loop
  315. ld a, [hli]
  316. ld [de], a
  317. inc de
  318. dec c
  319. jr nz, .loop
  320. ret
  321. ; 2368
  322.  
  323. CopyMapHeaders:: ; 2326
  324. call PartiallyCopyMapHeader
  325. call SwitchToMapBank
  326. call GetSecondaryMapHeaderPointer
  327. call CopySecondMapHeader
  328. ; fallthrough
  329. GetMapConnections:: ; 2368
  330. ld a, $ff
  331. ld [wNorthConnectedMapGroup], a
  332. ld [wSouthConnectedMapGroup], a
  333. ld [wWestConnectedMapGroup], a
  334. ld [wEastConnectedMapGroup], a
  335.  
  336. ld a, [wMapConnections]
  337. ld b, a
  338.  
  339. bit NORTH_F, b
  340. jr z, .no_north
  341. ld de, wNorthMapConnection
  342. call GetMapConnection
  343. .no_north
  344.  
  345. bit SOUTH_F, b
  346. jr z, .no_south
  347. ld de, wSouthMapConnection
  348. call GetMapConnection
  349. .no_south
  350.  
  351. bit WEST_F, b
  352. jr z, .no_west
  353. ld de, wWestMapConnection
  354. call GetMapConnection
  355. .no_west
  356.  
  357. bit EAST_F, b
  358. ret z
  359. ld de, wEastMapConnection
  360. ; fallthrough
  361.  
  362. GetMapConnection:: ; 23a3
  363. ; Load map connection struct at hl into de.
  364. ld c, wSouthMapConnection - wNorthMapConnection
  365. .loop
  366. ld a, [hli]
  367. ld [de], a
  368. inc de
  369. dec c
  370. jr nz, .loop
  371. ret
  372. ; 23ac
  373.  
  374. ReadMapTriggers:: ; 23ac
  375. ld a, [hli] ; trigger count
  376. ld c, a
  377. ld [wCurrMapTriggerCount], a ; current map trigger count
  378. ld a, l
  379. ld [wCurrMapTriggerHeaderPointer], a ; map trigger pointer
  380. ld a, h
  381. ld [wCurrMapTriggerHeaderPointer + 1], a
  382. ld a, c
  383. and a
  384. ret z
  385.  
  386. ld bc, 2 ; size of a map trigger header entry
  387. rst AddNTimes
  388. ret
  389. ; 23c3
  390.  
  391. ReadMapCallbacks:: ; 23c3
  392. ld a, [hli]
  393. ld c, a
  394. ld [wCurrMapCallbackCount], a
  395. ld a, l
  396. ld [wCurrMapCallbackHeaderPointer], a
  397. ld a, h
  398. ld [wCurrMapCallbackHeaderPointer + 1], a
  399. ld a, c
  400. and a
  401. ret z
  402.  
  403. ld bc, 3
  404. rst AddNTimes
  405. ret
  406. ; 23da
  407.  
  408. ReadWarps:: ; 23da
  409. ld a, [hli]
  410. ld c, a
  411. ld [wCurrMapWarpCount], a
  412. ld a, l
  413. ld [wCurrMapWarpHeaderPointer], a
  414. ld a, h
  415. ld [wCurrMapWarpHeaderPointer + 1], a
  416. ld a, c
  417. and a
  418. ret z
  419. ld bc, 5
  420. rst AddNTimes
  421. ret
  422. ; 23f1
  423.  
  424. ReadCoordEvents:: ; 23f1
  425. ld a, [hli]
  426. ld c, a
  427. ld [wCurrentMapXYTriggerCount], a
  428. ld a, l
  429. ld [wCurrentMapXYTriggerHeaderPointer], a
  430. ld a, h
  431. ld [wCurrentMapXYTriggerHeaderPointer + 1], a
  432.  
  433. ld a, c
  434. and a
  435. ret z
  436.  
  437. ld bc, 5
  438. rst AddNTimes
  439. ret
  440. ; 2408
  441.  
  442. ReadSignposts:: ; 2408
  443. ld a, [hli]
  444. ld c, a
  445. ld [wCurrentMapSignpostCount], a
  446. ld a, l
  447. ld [wCurrentMapSignpostHeaderPointer], a
  448. ld a, h
  449. ld [wCurrentMapSignpostHeaderPointer + 1], a
  450.  
  451. ld a, c
  452. and a
  453. ret z
  454.  
  455. ld bc, 5
  456. rst AddNTimes
  457. ret
  458. ; 241f
  459.  
  460. CopyMapObjectHeaders:: ; 2457
  461. and a
  462. ret z
  463.  
  464. ld c, a
  465. .loop
  466. push bc
  467. push hl
  468. ld a, $ff
  469. ld [hli], a
  470. ld b, MAPOBJECT_FLAG_HI - MAPOBJECT_SPRITE + 1 ; size of person_event
  471. .loop2
  472. ld a, [de]
  473. inc de
  474. ld [hli], a
  475. dec b
  476. jr nz, .loop2
  477.  
  478. pop hl
  479. ld bc, OBJECT_LENGTH
  480. add hl, bc
  481. pop bc
  482. dec c
  483. jr nz, .loop
  484. ret
  485. ; 2471
  486.  
  487. ClearObjectStructs:: ; 2471
  488. ld hl, wObject1Struct
  489. ld bc, OBJECT_STRUCT_LENGTH * (NUM_OBJECT_STRUCTS - 1)
  490. xor a
  491. jp ByteFill
  492. ; 248a
  493.  
  494. RestoreFacingAfterWarp:: ; 248a
  495. call SwitchToMapScriptHeaderBank
  496.  
  497. ld hl, wMapScriptHeaderPointer
  498. ld a, [hli]
  499. ld h, [hl]
  500. ld l, a
  501.  
  502. ; get to the warp coords
  503. ld a, [hli] ; get map trigger count
  504. ld bc, 2 ; size of an entry in the map trigger table
  505. rst AddNTimes
  506. ld a, [hli] ; get callback count
  507. ld bc, 3 ; size of an entry in the callback table
  508. rst AddNTimes
  509. inc hl ; skip warp count
  510. ld a, [wWarpNumber]
  511. dec a
  512. ld bc, 5 ; size of an entry in the warps table
  513. rst AddNTimes
  514.  
  515. ld a, [hli]
  516. ld [wYCoord], a
  517. ld a, [hli]
  518. ld [wXCoord], a
  519. ld a, [hli]
  520. cp -1
  521. jr nz, .skip
  522.  
  523. ld a, [wPrevWarp]
  524. ld [wBackupWarpNumber], a
  525. ld a, [wPrevMapGroup]
  526. ld [wBackupMapGroup], a
  527. ld a, [wPrevMapNumber]
  528. ld [wBackupMapNumber], a
  529.  
  530. .skip
  531. farjp GetCoordOfUpperLeftCorner
  532. ; 24ba
  533.  
  534. LoadBlockData:: ; 24cd
  535. ld a, [hVBlank]
  536. push af
  537. ld a, 2
  538. ld [hVBlank], a
  539. ld hl, wOverworldMap
  540. ld bc, wOverworldMapEnd - wOverworldMap
  541. xor a
  542. call ByteFill
  543. call ChangeMap
  544. call FillMapConnections
  545. ld a, MAPCALLBACK_TILES
  546. call RunMapCallback
  547. pop af
  548. ld [hVBlank], a
  549. ret
  550.  
  551. ChangeMap:: ; 24e4
  552. ld a, [wMapBlockDataBank]
  553. ld b, a
  554. ld a, [wMapBlockDataPointer]
  555. ld l, a
  556. ld a, [wMapBlockDataPointer+1]
  557. ld h, a
  558. ld a, [wMapWidth]
  559. ld d, a
  560. ld a, [wMapHeight]
  561. ld e, a
  562.  
  563. call RunFunctionInWRA6
  564.  
  565. .Function:
  566. push de
  567. call FarDecompressAtB_D000
  568. pop de
  569.  
  570. ld a, d
  571. ld [hConnectedMapWidth], a
  572. add $6
  573. ld [hConnectionStripLength], a
  574. ld hl, wOverworldMap
  575.  
  576. ld c, a
  577. ld b, 0
  578. add hl, bc
  579. add hl, bc
  580. add hl, bc
  581. ld c, 3
  582. add hl, bc
  583.  
  584. ld b, e
  585. ld de, wDecompressScratch
  586. .row
  587. push hl
  588. ld a, [hConnectedMapWidth]
  589. ld c, a
  590. .col
  591. ld a, [de]
  592. inc de
  593. ld [hli], a
  594. dec c
  595. jr nz, .col
  596. pop hl
  597. ld a, [hConnectionStripLength]
  598. add l
  599. ld l, a
  600. jr nc, .okay
  601. inc h
  602. .okay
  603. dec b
  604. jr nz, .row
  605. ret
  606. ; 2524
  607.  
  608. DecompressConnectionMap:
  609. ld a, [rSVBK]
  610. push af
  611. ld a, BANK(wDecompressScratch)
  612. ld [rSVBK], a
  613. push de
  614. push bc
  615. ld de, wDecompressScratch
  616. call Decompress
  617. pop bc
  618. pop de
  619. pop af
  620. ld [rSVBK], a
  621. ret
  622.  
  623. FillMapConnections:: ; 2524
  624.  
  625. ; North
  626. ld a, [wNorthConnectedMapGroup]
  627. cp $ff
  628. jr z, .South
  629. ld b, a
  630. ld a, [wNorthConnectedMapNumber]
  631. ld c, a
  632. call GetAnyMapBlockdataBankPointer
  633. call DecompressConnectionMap
  634.  
  635. ld a, [wNorthConnectionStripPointer]
  636. ld l, a
  637. ld a, [wNorthConnectionStripPointer + 1]
  638. ld h, a
  639.  
  640. ld a, [wNorthConnectionStripLocation]
  641. ld e, a
  642. ld a, [wNorthConnectionStripLocation + 1]
  643. ld d, a
  644. ld a, [wNorthConnectionStripLength]
  645. ld [hConnectionStripLength], a
  646. ld a, [wNorthConnectedMapWidth]
  647. ld [hConnectedMapWidth], a
  648. call FillNorthConnectionStrip
  649.  
  650. .South
  651. ld a, [wSouthConnectedMapGroup]
  652. cp $ff
  653. jr z, .West
  654. ld b, a
  655. ld a, [wSouthConnectedMapNumber]
  656. ld c, a
  657. call GetAnyMapBlockdataBankPointer
  658. call DecompressConnectionMap
  659.  
  660. ld a, [wSouthConnectionStripPointer]
  661. ld l, a
  662. ld a, [wSouthConnectionStripPointer + 1]
  663. ld h, a
  664. ld a, [wSouthConnectionStripLocation]
  665. ld e, a
  666. ld a, [wSouthConnectionStripLocation + 1]
  667. ld d, a
  668. ld a, [wSouthConnectionStripLength]
  669. ld [hConnectionStripLength], a
  670. ld a, [wSouthConnectedMapWidth]
  671. ld [hConnectedMapWidth], a
  672. call FillSouthConnectionStrip
  673.  
  674. .West
  675. ld a, [wWestConnectedMapGroup]
  676. cp $ff
  677. jr z, .East
  678. ld b, a
  679. ld a, [wWestConnectedMapNumber]
  680. ld c, a
  681. call GetAnyMapBlockdataBankPointer
  682. call DecompressConnectionMap
  683.  
  684. ld a, [wWestConnectionStripPointer]
  685. ld l, a
  686. ld a, [wWestConnectionStripPointer + 1]
  687. ld h, a
  688. ld a, [wWestConnectionStripLocation]
  689. ld e, a
  690. ld a, [wWestConnectionStripLocation + 1]
  691. ld d, a
  692. ld a, [wWestConnectionStripLength]
  693. ld b, a
  694. ld a, [wWestConnectedMapWidth]
  695. ld [hConnectionStripLength], a
  696. call FillWestConnectionStrip
  697.  
  698. .East
  699. ld a, [wEastConnectedMapGroup]
  700. cp $ff
  701. ret z
  702. ld b, a
  703. ld a, [wEastConnectedMapNumber]
  704. ld c, a
  705. call GetAnyMapBlockdataBankPointer
  706. call DecompressConnectionMap
  707.  
  708. ld a, [wEastConnectionStripPointer]
  709. ld l, a
  710. ld a, [wEastConnectionStripPointer + 1]
  711. ld h, a
  712. ld a, [wEastConnectionStripLocation]
  713. ld e, a
  714. ld a, [wEastConnectionStripLocation + 1]
  715. ld d, a
  716. ld a, [wEastConnectionStripLength]
  717. ld b, a
  718. ld a, [wEastConnectedMapWidth]
  719. ld [hConnectionStripLength], a
  720.  
  721. ; fallthrough
  722. FillWestConnectionStrip::
  723. FillEastConnectionStrip:: ; 25f6
  724. ld a, [wMapWidth]
  725. add 6
  726. ld [hConnectedMapWidth], a
  727.  
  728. ld a, [rSVBK]
  729. push af
  730. ld a, BANK(wDecompressScratch)
  731. ld [rSVBK], a
  732. .loop
  733. push de
  734.  
  735. push hl
  736. ld a, [hli]
  737. ld [de], a
  738. inc de
  739. ld a, [hli]
  740. ld [de], a
  741. inc de
  742. ld a, [hli]
  743. ld [de], a
  744. inc de
  745. pop hl
  746.  
  747. ld a, [hConnectionStripLength]
  748. ld e, a
  749. ld d, 0
  750. add hl, de
  751. pop de
  752.  
  753. ld a, [hConnectedMapWidth]
  754. add e
  755. ld e, a
  756. jr nc, .okay
  757. inc d
  758. .okay
  759. dec b
  760. jr nz, .loop
  761. pop af
  762. ld [rSVBK], a
  763. ret
  764. ; 261b
  765.  
  766. FillNorthConnectionStrip::
  767. FillSouthConnectionStrip:: ; 25d3
  768. ld a, [wMapWidth]
  769. add 6
  770. ld [hMapWidthPlus6], a
  771. ld a, [rSVBK]
  772. push af
  773. ld a, BANK(wDecompressScratch)
  774. ld [rSVBK], a
  775.  
  776. ld c, 3
  777. .y
  778. push de
  779.  
  780. push hl
  781. ld a, [hConnectionStripLength]
  782. ld b, a
  783. .x
  784. ld a, [hli]
  785. ld [de], a
  786. inc de
  787. dec b
  788. jr nz, .x
  789. pop hl
  790.  
  791. ld a, [hConnectedMapWidth]
  792. ld e, a
  793. ld d, 0
  794. add hl, de
  795. pop de
  796.  
  797. ld a, [hMapWidthPlus6]
  798. add e
  799. ld e, a
  800. jr nc, .okay
  801. inc d
  802. .okay
  803. dec c
  804. jr nz, .y
  805. pop af
  806. ld [rSVBK], a
  807. ret
  808. ; 25f6
  809.  
  810. LoadMapStatus:: ; 261b
  811. ld [wMapStatus], a
  812. ret
  813. ; 261f
  814.  
  815. CallScript:: ; 261f
  816. ; Call a script at a:hl.
  817.  
  818. ld [wScriptBank], a
  819. ld a, l
  820. ld [wScriptPos], a
  821. ld a, h
  822. ld [wScriptPos + 1], a
  823.  
  824. ld a, PLAYEREVENT_MAPSCRIPT
  825. ld [wScriptRunning], a
  826.  
  827. scf
  828. ret
  829. ; 2631
  830.  
  831. CallMapScript:: ; 2631
  832. ; Call a script at hl in the current bank if there isn't already a script running
  833. ld a, [wScriptRunning]
  834. and a
  835. ret nz
  836. ld a, [wMapScriptHeaderBank]
  837. jr CallScript
  838. ; 263b
  839.  
  840. RunMapCallback:: ; 263b
  841. ; Will run the first callback found in the map header with execution index equal to a.
  842. ld b, a
  843. ld a, [hROMBank]
  844. push af
  845. call SwitchToMapScriptHeaderBank
  846. call .FindCallback
  847. jr nc, .done
  848.  
  849. ld a, [wMapScriptHeaderBank]
  850. ld b, a
  851. ld d, h
  852. ld e, l
  853. call ExecuteCallbackScript
  854.  
  855. .done
  856. pop af
  857. rst Bankswitch
  858. ret
  859. ; 2653
  860.  
  861. .FindCallback: ; 2653
  862. ld a, [wCurrMapCallbackCount]
  863. ld c, a
  864. and a
  865. ret z
  866. ld hl, wCurrMapCallbackHeaderPointer
  867. ld a, [hli]
  868. ld h, [hl]
  869. ld l, a
  870. or h
  871. ret z
  872. ld de, 3
  873. .loop
  874. ld a, [hl]
  875. cp b
  876. jr z, .found
  877. add hl, de
  878. dec c
  879. jr nz, .loop
  880. xor a
  881. ret
  882.  
  883. .found
  884. inc hl
  885. ld a, [hli]
  886. ld h, [hl]
  887. ld l, a
  888. scf
  889. ret
  890. ; 2674
  891.  
  892. ExecuteCallbackScript:: ; 2674
  893. ; Do map callback de and return to script bank b.
  894. farcall CallCallback
  895. ld a, [wScriptMode]
  896. push af
  897. ld hl, wScriptFlags
  898. ld a, [hl]
  899. push af
  900. set 1, [hl]
  901. farcall EnableScriptMode
  902. farcall ScriptEvents
  903. pop af
  904. ld [wScriptFlags], a
  905. pop af
  906. ld [wScriptMode], a
  907. ret
  908. ; 269a
  909.  
  910. MapTextbox:: ; 269a
  911. ld a, [hROMBank]
  912. push af
  913.  
  914. ld a, b
  915. rst Bankswitch
  916.  
  917. push hl
  918. call SpeechTextBox
  919. call SafeUpdateSprites
  920. ld a, 1
  921. ld [hOAMUpdate], a
  922. call ApplyTilemap
  923. pop hl
  924. call PrintTextBoxText
  925. xor a
  926. ld [hOAMUpdate], a
  927.  
  928. pop af
  929. rst Bankswitch
  930. ret
  931. ; 26b7
  932.  
  933. Call_a_de:: ; 26b7
  934. ; Call a:de.
  935.  
  936. ld [hBuffer], a
  937. ld a, [hROMBank]
  938. push af
  939. ld a, [hBuffer]
  940. rst Bankswitch
  941.  
  942. call .de
  943.  
  944. pop af
  945. rst Bankswitch
  946. ret
  947.  
  948. .de
  949. push de
  950. ret
  951. ; 26c7
  952.  
  953. GetMovementData:: ; 26c7
  954. ; Initialize the movement data for person c at b:hl
  955. ld a, [hROMBank]
  956. push af
  957. ld a, b
  958. rst Bankswitch
  959.  
  960. ld a, c
  961. call LoadMovementDataPointer
  962.  
  963. pop hl
  964. ld a, h
  965. rst Bankswitch
  966. ret
  967. ; 26d4
  968.  
  969. GetScriptByte:: ; 0x26d4
  970. ; Return byte at wScriptBank:wScriptPos in a.
  971.  
  972. push hl
  973. push bc
  974. ld a, [hROMBank]
  975. push af
  976. ld a, [wScriptBank]
  977. rst Bankswitch
  978.  
  979. ld hl, wScriptPos
  980. ld c, [hl]
  981. inc hl
  982. ld b, [hl]
  983.  
  984. ld a, [bc]
  985.  
  986. inc bc
  987. ld [hl], b
  988. dec hl
  989. ld [hl], c
  990.  
  991. ld b, a
  992. pop af
  993. rst Bankswitch
  994. ld a, b
  995. pop bc
  996. pop hl
  997. ret
  998. ; 0x26ef
  999.  
  1000. ObjectEvent:: ; 0x26ef
  1001. jumptextfaceplayer ObjectEventText
  1002. ; 0x26f2
  1003.  
  1004. ObjectEventText::
  1005. text_jump _ObjectEventText
  1006. db "@"
  1007. ; 0x26f7
  1008.  
  1009. EndEvent::
  1010. end
  1011.  
  1012. CheckObjectMask:: ; 2707
  1013. ld a, [hMapObjectIndexBuffer]
  1014. ld e, a
  1015. ld d, $0
  1016. ld hl, wObjectMasks
  1017. add hl, de
  1018. ld a, [hl]
  1019. ret
  1020. ; 2712
  1021.  
  1022. MaskObject:: ; 2712
  1023. ld a, [hMapObjectIndexBuffer]
  1024. ld e, a
  1025. ld d, $0
  1026. ld hl, wObjectMasks
  1027. add hl, de
  1028. ld [hl], -1 ; , masked
  1029. ret
  1030. ; 271e
  1031.  
  1032. UnmaskObject:: ; 271e
  1033. ld a, [hMapObjectIndexBuffer]
  1034. ld e, a
  1035. ld d, $0
  1036. ld hl, wObjectMasks
  1037. add hl, de
  1038. ld [hl], 0 ; unmasked
  1039. ret
  1040. ; 272a
  1041.  
  1042. ScrollMapDown:: ; 272a
  1043. hlcoord 0, 0
  1044. ld de, wBGMapBuffer
  1045. call BackupBGMapRow
  1046. hlcoord 0, 0, wAttrMap
  1047. ld de, wBGMapPalBuffer
  1048. call BackupBGMapRow
  1049. ld a, [wBGMapAnchor]
  1050. ld e, a
  1051. ld a, [wBGMapAnchor + 1]
  1052. ld d, a
  1053. call UpdateBGMapRow
  1054. ld a, $1
  1055. ld [hBGMapUpdate], a
  1056. ret
  1057. ; 2748
  1058.  
  1059. ScrollMapUp:: ; 2748
  1060. hlcoord 0, SCREEN_HEIGHT - 2
  1061. ld de, wBGMapBuffer
  1062. call BackupBGMapRow
  1063. hlcoord 0, SCREEN_HEIGHT - 2, wAttrMap
  1064. ld de, wBGMapPalBuffer
  1065. call BackupBGMapRow
  1066. ld a, [wBGMapAnchor]
  1067. ld l, a
  1068. ld a, [wBGMapAnchor + 1]
  1069. ld h, a
  1070. ld bc, $0200
  1071. add hl, bc
  1072. ; cap d at VBGMap1 / $100
  1073. ld a, h
  1074. and %00000011
  1075. or VBGMap0 / $100
  1076. ld e, l
  1077. ld d, a
  1078. call UpdateBGMapRow
  1079. ld a, $1
  1080. ld [hBGMapUpdate], a
  1081. ret
  1082. ; 2771
  1083.  
  1084. ScrollMapRight:: ; 2771
  1085. hlcoord 0, 0
  1086. ld de, wBGMapBuffer
  1087. call BackupBGMapColumn
  1088. hlcoord 0, 0, wAttrMap
  1089. ld de, wBGMapPalBuffer
  1090. call BackupBGMapColumn
  1091. ld a, [wBGMapAnchor]
  1092. ld e, a
  1093. ld a, [wBGMapAnchor + 1]
  1094. ld d, a
  1095. call UpdateBGMapColumn
  1096. ld a, $1
  1097. ld [hBGMapUpdate], a
  1098. ret
  1099. ; 278f
  1100.  
  1101. ScrollMapLeft:: ; 278f
  1102. hlcoord SCREEN_WIDTH - 2, 0
  1103. ld de, wBGMapBuffer
  1104. call BackupBGMapColumn
  1105. hlcoord SCREEN_WIDTH - 2, 0, wAttrMap
  1106. ld de, wBGMapPalBuffer
  1107. call BackupBGMapColumn
  1108. ld a, [wBGMapAnchor]
  1109. ld e, a
  1110. and %11100000
  1111. ld b, a
  1112. ld a, e
  1113. add SCREEN_HEIGHT
  1114. and %00011111
  1115. or b
  1116. ld e, a
  1117. ld a, [wBGMapAnchor + 1]
  1118. ld d, a
  1119. call UpdateBGMapColumn
  1120. ld a, $1
  1121. ld [hBGMapUpdate], a
  1122. ret
  1123. ; 27b7
  1124.  
  1125. BackupBGMapRow:: ; 27b7
  1126. ld c, 2 * SCREEN_WIDTH
  1127. .loop
  1128. ld a, [hli]
  1129. ld [de], a
  1130. inc de
  1131. dec c
  1132. jr nz, .loop
  1133. ret
  1134. ; 27c0
  1135.  
  1136. BackupBGMapColumn:: ; 27c0
  1137. ld c, SCREEN_HEIGHT
  1138. .loop
  1139. ld a, [hli]
  1140. ld [de], a
  1141. inc de
  1142. ld a, [hl]
  1143. ld [de], a
  1144. inc de
  1145. ld a, SCREEN_WIDTH - 1
  1146. add l
  1147. ld l, a
  1148. jr nc, .skip
  1149. inc h
  1150.  
  1151. .skip
  1152. dec c
  1153. jr nz, .loop
  1154. ret
  1155. ; 27d3
  1156.  
  1157. UpdateBGMapRow:: ; 27d3
  1158. ld hl, wBGMapBufferPtrs
  1159. push de
  1160. call .iteration
  1161. pop de
  1162. ld a, $20
  1163. add e
  1164. ld e, a
  1165.  
  1166. .iteration
  1167. ld c, 10
  1168. .loop
  1169. ld a, e
  1170. ld [hli], a
  1171. ld a, d
  1172. ld [hli], a
  1173. ld a, e
  1174. inc a
  1175. inc a
  1176. and $1f
  1177. ld b, a
  1178. ld a, e
  1179. and $e0
  1180. or b
  1181. ld e, a
  1182. dec c
  1183. jr nz, .loop
  1184. ld a, SCREEN_WIDTH
  1185. ld [hBGMapTileCount], a
  1186. ret
  1187. ; 27f8
  1188.  
  1189. UpdateBGMapColumn:: ; 27f8
  1190. ld hl, wBGMapBufferPtrs
  1191. ld c, SCREEN_HEIGHT
  1192. .loop
  1193. ld a, e
  1194. ld [hli], a
  1195. ld a, d
  1196. ld [hli], a
  1197. ld a, $20
  1198. add e
  1199. ld e, a
  1200. jr nc, .skip
  1201. inc d
  1202. ; cap d at VBGMap1 / $100
  1203. ld a, d
  1204. and $3
  1205. or VBGMap0 / $100
  1206. ld d, a
  1207.  
  1208. .skip
  1209. dec c
  1210. jr nz, .loop
  1211. ld a, SCREEN_HEIGHT
  1212. ld [hBGMapTileCount], a
  1213. ret
  1214. ; 2816
  1215.  
  1216. LoadTileset:: ; 2821
  1217. ld hl, wTilesetGFXAddress
  1218. ld a, [hli]
  1219. ld h, [hl]
  1220. ld l, a
  1221. ld a, [wTilesetGFXBank]
  1222. ld [hTilesetGFXBank], a
  1223.  
  1224. ld a, BANK(wDecompressScratch)
  1225. ld [rSVBK], a
  1226.  
  1227. ld a, [hTilesetGFXBank]
  1228. ld de, wDecompressScratch
  1229. call FarDecompress
  1230.  
  1231. ld hl, wDecompressScratch
  1232. ld de, VTiles2
  1233. ld bc, $7f tiles
  1234. rst CopyBytes
  1235.  
  1236. ld a, $1
  1237. ld [rVBK], a
  1238.  
  1239. ld hl, wDecompressScratch + $80 tiles
  1240. ld de, VTiles5
  1241. ld bc, $80 tiles
  1242. rst CopyBytes
  1243.  
  1244. ld a, $1
  1245. ld [rSVBK], a
  1246.  
  1247. ld hl, wTilesetGFX2Address
  1248. ld a, [hli]
  1249. and a
  1250. jr z, .no_gfx2
  1251. ld h, [hl]
  1252. ld l, a
  1253.  
  1254. ld a, BANK(wDecompressScratch)
  1255. ld [rSVBK], a
  1256.  
  1257. ld a, [hTilesetGFXBank]
  1258. ld de, wDecompressScratch
  1259. call FarDecompress
  1260.  
  1261. ld hl, wDecompressScratch
  1262. ld de, VTiles4
  1263. ld bc, $80 tiles
  1264. rst CopyBytes
  1265.  
  1266. .no_gfx2
  1267. xor a
  1268. ld [rVBK], a
  1269.  
  1270. inc a
  1271. ld [rSVBK], a
  1272.  
  1273. ld a, [wTileset]
  1274. cp TILESET_GLINT
  1275. jr z, .load_roof
  1276. cp TILESET_SPOOKY
  1277. jr z, .load_roof
  1278. jr .skip_roof
  1279.  
  1280. .load_roof
  1281. farcall LoadMapGroupRoof
  1282.  
  1283. .skip_roof
  1284. xor a
  1285. ld [hTileAnimFrame], a
  1286. ret
  1287. ; 2879
  1288.  
  1289. BufferScreen:: ; 2879
  1290. ld hl, wOverworldMapAnchor
  1291. ld a, [hli]
  1292. ld h, [hl]
  1293. ld l, a
  1294. ld de, wScreenSave
  1295. lb bc, $6, $5
  1296. .row
  1297. push bc
  1298. push hl
  1299. .col
  1300. ld a, [hli]
  1301. ld [de], a
  1302. inc de
  1303. dec b
  1304. jr nz, .col
  1305. pop hl
  1306. ld a, [wMapWidth]
  1307. add $6
  1308. ld c, a
  1309. ld b, $0
  1310. add hl, bc
  1311. pop bc
  1312. dec c
  1313. jr nz, .row
  1314. ret
  1315. ; 289d
  1316.  
  1317. SaveScreen:: ; 289d
  1318. ld hl, wOverworldMapAnchor
  1319. ld a, [hli]
  1320. ld h, [hl]
  1321. ld l, a
  1322. ld de, wScreenSave
  1323. ld a, [wMapWidth]
  1324. add 6
  1325. ld [hMapObjectIndexBuffer], a
  1326. ld a, [wPlayerStepDirection]
  1327. and a
  1328. jr z, .down
  1329. cp UP
  1330. jr z, .up
  1331. cp LEFT
  1332. jr z, .left
  1333. cp RIGHT
  1334. jr z, .right
  1335. ret
  1336.  
  1337. .up
  1338. ld de, wScreenSave + 6
  1339. ld a, [hMapObjectIndexBuffer]
  1340. ld c, a
  1341. ld b, $0
  1342. add hl, bc
  1343. jr .vertical
  1344.  
  1345. .down
  1346. ld de, wScreenSave
  1347. .vertical
  1348. lb bc, 6, 4
  1349. jr SaveScreen_LoadNeighbor
  1350.  
  1351. .left
  1352. ld de, wScreenSave + 1
  1353. inc hl
  1354. jr .horizontal
  1355.  
  1356. .right
  1357. ld de, wScreenSave
  1358. .horizontal
  1359. lb bc, 5, 5
  1360. jr SaveScreen_LoadNeighbor
  1361.  
  1362. LoadNeighboringBlockData:: ; 28e3
  1363. ld hl, wOverworldMapAnchor
  1364. ld a, [hli]
  1365. ld h, [hl]
  1366. ld l, a
  1367. ld a, [wMapWidth]
  1368. add 6
  1369. ld [hConnectionStripLength], a
  1370. ld de, wScreenSave
  1371. lb bc, 6, 5
  1372.  
  1373. SaveScreen_LoadNeighbor:: ; 28f7
  1374. .row
  1375. push bc
  1376. push hl
  1377. push de
  1378. .col
  1379. ld a, [de]
  1380. inc de
  1381. ld [hli], a
  1382. dec b
  1383. jr nz, .col
  1384. pop de
  1385. ld a, e
  1386. add 6
  1387. ld e, a
  1388. jr nc, .okay
  1389. inc d
  1390.  
  1391. .okay
  1392. pop hl
  1393. ld a, [hConnectionStripLength]
  1394. ld c, a
  1395. ld b, 0
  1396. add hl, bc
  1397. pop bc
  1398. dec c
  1399. jr nz, .row
  1400. ret
  1401. ; 2914
  1402.  
  1403. GetMovementPermissions:: ; 2914
  1404. xor a
  1405. ld [wTilePermissions], a
  1406. call .LeftRight
  1407. call .UpDown
  1408. ; get coords of current tile
  1409. ld a, [wPlayerStandingMapX]
  1410. ld d, a
  1411. ld a, [wPlayerStandingMapY]
  1412. ld e, a
  1413. call GetCoordTile
  1414. ld [wPlayerStandingTile], a
  1415. call .CheckHiNybble
  1416. ret nz
  1417.  
  1418. ld a, [wPlayerStandingTile]
  1419. and 7
  1420. ld hl, .MovementPermissionsData
  1421. add l
  1422. ld l, a
  1423. ld a, 0 ; not xor a; preserve carry flag
  1424. adc h
  1425. ld h, a
  1426. ld a, [hl]
  1427. ld hl, wTilePermissions
  1428. or [hl]
  1429. ld [hl], a
  1430. ret
  1431. ; 2945
  1432.  
  1433. .MovementPermissionsData: ; 2945
  1434. db 1 << DOWN
  1435. db 1 << UP
  1436. db 1 << LEFT
  1437. db 1 << RIGHT
  1438. db (1 << DOWN) | (1 << RIGHT)
  1439. db (1 << UP) | (1 << RIGHT)
  1440. db (1 << DOWN) | (1 << LEFT)
  1441. db (1 << UP) | (1 << LEFT)
  1442. ; 294d
  1443.  
  1444. .UpDown:
  1445. ld a, [wPlayerStandingMapX]
  1446. ld d, a
  1447. ld a, [wPlayerStandingMapY]
  1448. ld e, a
  1449.  
  1450. push de
  1451. inc e
  1452. call GetCoordTile
  1453. ld [wTileDown], a
  1454. call .Down
  1455.  
  1456. pop de
  1457. dec e
  1458. call GetCoordTile
  1459. ld [wTileUp], a
  1460. jp .Up
  1461. ; 296c
  1462.  
  1463. .LeftRight:
  1464. ld a, [wPlayerStandingMapX]
  1465. ld d, a
  1466. ld a, [wPlayerStandingMapY]
  1467. ld e, a
  1468.  
  1469. push de
  1470. dec d
  1471. call GetCoordTile
  1472. ld [wTileLeft], a
  1473. call .Left
  1474.  
  1475. pop de
  1476. inc d
  1477. call GetCoordTile
  1478. ld [wTileRight], a
  1479. jp .Right
  1480. ; 298b
  1481.  
  1482. .Down:
  1483. call .CheckHiNybble
  1484. ret nz
  1485. ld a, [wTileDown]
  1486. and 7
  1487. cp $2
  1488. jr z, .ok_down
  1489. cp $6
  1490. jr z, .ok_down
  1491. cp $7
  1492. ret nz
  1493.  
  1494. .ok_down
  1495. ld a, [wTilePermissions]
  1496. or FACE_DOWN
  1497. ld [wTilePermissions], a
  1498. ret
  1499. ; 29a8
  1500.  
  1501. .Up:
  1502. call .CheckHiNybble
  1503. ret nz
  1504. ld a, [wTileUp]
  1505. and 7
  1506. cp $3
  1507. jr z, .ok_up
  1508. cp $4
  1509. jr z, .ok_up
  1510. cp $5
  1511. ret nz
  1512.  
  1513. .ok_up
  1514. ld a, [wTilePermissions]
  1515. or FACE_UP
  1516. ld [wTilePermissions], a
  1517. ret
  1518. ; 29c5
  1519.  
  1520. .Right:
  1521. call .CheckHiNybble
  1522. ret nz
  1523. ld a, [wTileRight]
  1524. and 7
  1525. cp $1
  1526. jr z, .ok_right
  1527. cp $5
  1528. jr z, .ok_right
  1529. cp $7
  1530. ret nz
  1531.  
  1532. .ok_right
  1533. ld a, [wTilePermissions]
  1534. or FACE_RIGHT
  1535. ld [wTilePermissions], a
  1536. ret
  1537. ; 29e2
  1538.  
  1539. .Left:
  1540. call .CheckHiNybble
  1541. ret nz
  1542. ld a, [wTileLeft]
  1543. and 7
  1544. cp $0
  1545. jr z, .ok_left
  1546. cp $4
  1547. jr z, .ok_left
  1548. cp $6
  1549. ret nz
  1550.  
  1551. .ok_left
  1552. ld a, [wTilePermissions]
  1553. or FACE_LEFT
  1554. ld [wTilePermissions], a
  1555. ret
  1556. ; 29ff
  1557.  
  1558. .CheckHiNybble:
  1559. and $f0
  1560. cp $b0
  1561. ret z
  1562. cp $c0
  1563. ret
  1564. ; 2a07
  1565.  
  1566. GetFacingTileCoord:: ; 2a07
  1567. ; Return map coordinates in (d, e) and tile id in a
  1568. ; of the tile the player is facing.
  1569.  
  1570. ld a, [wPlayerDirection]
  1571. and %1100
  1572. srl a
  1573. srl a
  1574. ld l, a
  1575. ld h, 0
  1576. add hl, hl
  1577. add hl, hl
  1578. ld de, .Directions
  1579. add hl, de
  1580.  
  1581. ld d, [hl]
  1582. inc hl
  1583. ld e, [hl]
  1584. inc hl
  1585.  
  1586. ld a, [hli]
  1587. ld h, [hl]
  1588. ld l, a
  1589.  
  1590. ld a, [wPlayerStandingMapX]
  1591. add d
  1592. ld d, a
  1593. ld a, [wPlayerStandingMapY]
  1594. add e
  1595. ld e, a
  1596. ld a, [hl]
  1597. ret
  1598.  
  1599. .Directions:
  1600. ; x, y
  1601. db 0, 1
  1602. dw wTileDown
  1603. db 0, -1
  1604. dw wTileUp
  1605. db -1, 0
  1606. dw wTileLeft
  1607. db 1, 0
  1608. dw wTileRight
  1609. ; 2a3c
  1610.  
  1611. GetCoordTile:: ; 2a3c
  1612. ; Get the collision byte for tile d, e
  1613. call GetBlockLocation
  1614. ld a, [hl]
  1615. and a
  1616. jr z, .nope
  1617. ld l, a
  1618. ld h, $0
  1619. add hl, hl
  1620. add hl, hl
  1621. ld a, [wTilesetCollisionAddress]
  1622. ld c, a
  1623. ld a, [wTilesetCollisionAddress + 1]
  1624. ld b, a
  1625. add hl, bc
  1626. rr d
  1627. jr nc, .nocarry
  1628. inc hl
  1629.  
  1630. .nocarry
  1631. rr e
  1632. jr nc, .nocarry2
  1633. inc hl
  1634. inc hl
  1635.  
  1636. .nocarry2
  1637. ld a, [wTilesetCollisionBank]
  1638. jp GetFarByte
  1639.  
  1640. .nope
  1641. ld a, -1
  1642. ret
  1643. ; 2a66
  1644.  
  1645. GetBlockLocation:: ; 2a66
  1646. ld a, [wMapWidth]
  1647. add 6
  1648. ld c, a
  1649. ld b, 0
  1650. ld hl, wOverworldMap + 1
  1651. add hl, bc
  1652. ld a, e
  1653. srl a
  1654. jr z, .nope
  1655. and a
  1656. .loop
  1657. srl a
  1658. jr nc, .ok
  1659. add hl, bc
  1660.  
  1661. .ok
  1662. sla c
  1663. rl b
  1664. and a
  1665. jr nz, .loop
  1666.  
  1667. .nope
  1668. ld c, d
  1669. srl c
  1670. ld b, 0
  1671. add hl, bc
  1672. ret
  1673. ; 2a8b
  1674.  
  1675. CheckFacingSign:: ; 2a8b
  1676. call GetFacingTileCoord
  1677. ; Load facing into b.
  1678. ld b, a
  1679. ; Convert the coordinates at de to within-boundaries coordinates.
  1680. ld a, d
  1681. sub 4
  1682. ld d, a
  1683. ld a, e
  1684. sub 4
  1685. ld e, a
  1686. ; If there are no signposts, we don't need to be here.
  1687. ld a, [wCurrentMapSignpostCount]
  1688. and a
  1689. ret z
  1690.  
  1691. ld c, a
  1692. ld a, [hROMBank]
  1693. push af
  1694. call SwitchToMapScriptHeaderBank
  1695. call CheckIfFacingTileCoordIsSign
  1696. pop hl
  1697. ld a, h
  1698. rst Bankswitch
  1699. ret
  1700. ; 2aaa
  1701.  
  1702. CheckIfFacingTileCoordIsSign:: ; 2aaa
  1703. ; Checks to see if you are facing a signpost. If so, copies it into wEngineBuffer1 and sets carry.
  1704. ld hl, wCurrentMapSignpostHeaderPointer
  1705. ld a, [hli]
  1706. ld h, [hl]
  1707. ld l, a
  1708. .loop
  1709. push hl
  1710. ld a, [hli]
  1711. cp e
  1712. jr nz, .next
  1713. ld a, [hli]
  1714. cp d
  1715. jr nz, .next
  1716. jr .copysign
  1717.  
  1718. .next
  1719. pop hl
  1720. ld a, 5 ; signpost event length
  1721. add l
  1722. ld l, a
  1723. jr nc, .nocarry
  1724. inc h
  1725.  
  1726. .nocarry
  1727. dec c
  1728. jr nz, .loop
  1729. xor a
  1730. ret
  1731.  
  1732. .copysign
  1733. pop hl
  1734. ld de, wCurSignpostYCoord
  1735. ld bc, 5 ; signpost event length
  1736. rst CopyBytes
  1737. scf
  1738. ret
  1739. ; 2ad4
  1740.  
  1741. CheckCurrentMapXYTriggers:: ; 2ad4
  1742. ; If there are no xy triggers, we don't need to be here.
  1743. ld a, [wCurrentMapXYTriggerCount]
  1744. and a
  1745. ret z
  1746. ; Copy the trigger count into c.
  1747. ld c, a
  1748. ld a, [hROMBank]
  1749. push af
  1750. call SwitchToMapScriptHeaderBank
  1751. call .TriggerCheck
  1752. pop hl
  1753. ld a, h
  1754. rst Bankswitch
  1755. ret
  1756.  
  1757. .TriggerCheck:
  1758. ; Checks to see if you are standing on an xy-trigger. If yes, copies the trigger to wEngineBuffer1 and sets carry.
  1759. ld hl, wCurrentMapXYTriggerHeaderPointer
  1760. ld a, [hli]
  1761. ld h, [hl]
  1762. ld l, a
  1763. ; Load the active trigger ID into b
  1764. call CheckTriggers
  1765. ld b, a
  1766. ; Load your current coordinates into de. This will be used to check if your position is in the xy-trigger table for the current map.
  1767. ld a, [wPlayerStandingMapX]
  1768. sub 4
  1769. ld d, a
  1770. ld a, [wPlayerStandingMapY]
  1771. sub 4
  1772. ld e, a
  1773.  
  1774. .loop
  1775. push hl
  1776. ld a, [hli]
  1777. cp b
  1778. jr z, .got_id
  1779. cp -1
  1780. jr nz, .next
  1781.  
  1782. .got_id
  1783. ld a, [hli]
  1784. cp e
  1785. jr nz, .next
  1786. ld a, [hli]
  1787. cp d
  1788. jr nz, .next
  1789. jr .copytrigger
  1790.  
  1791. .next
  1792. pop hl
  1793. ld a, $5 ; xy-trigger size
  1794. add l
  1795. ld l, a
  1796. jr nc, .nocarry
  1797. inc h
  1798.  
  1799. .nocarry
  1800. dec c
  1801. jr nz, .loop
  1802. xor a
  1803. ret
  1804.  
  1805. .copytrigger
  1806. pop hl
  1807. ld de, wCurCoordEventTriggerID
  1808. ld bc, 5 ; xy-trigger size
  1809. rst CopyBytes
  1810. scf
  1811. ret
  1812. ; 2b29
  1813.  
  1814. FadeToMenu:: ; 2b29
  1815. xor a
  1816. ld [hBGMapMode], a
  1817. call LoadStandardMenuDataHeader
  1818. farcall FadeOutPalettes
  1819. call ClearSprites
  1820. jp DisableSpriteUpdates
  1821. ; 2b3c
  1822.  
  1823. CloseSubmenu:: ; 2b3c
  1824. call ClearBGPalettes
  1825. call ReloadTilesetAndPalettes
  1826. call UpdateSprites
  1827. call ExitMenu
  1828. jr FinishExitMenu
  1829. ; 2b4d
  1830.  
  1831. ExitAllMenus:: ; 2b4d
  1832. call ClearBGPalettes
  1833. call ExitMenu
  1834. call ReloadTilesetAndPalettes
  1835. call UpdateSprites
  1836. FinishExitMenu:: ; 2b5c
  1837. ld b, CGB_MAPPALS
  1838. call GetCGBLayout
  1839. farcall LoadBlindingFlashPalette
  1840. call ApplyAttrAndTilemapInVBlank
  1841. farcall FadeInPalettes
  1842. jp EnableSpriteUpdates
  1843. ; 2b74
  1844.  
  1845. ReturnToMapWithSpeechTextbox:: ; 0x2b74
  1846. push af
  1847. ld a, $1
  1848. ld [wSpriteUpdatesEnabled], a
  1849. call ClearBGPalettes
  1850. call ClearSprites
  1851. call ReloadTilesetAndPalettes
  1852. hlcoord 0, 12
  1853. lb bc, 4, 18
  1854. call TextBox
  1855. ld hl, wVramState
  1856. set 0, [hl]
  1857. call UpdateSprites
  1858. call ApplyAttrAndTilemapInVBlank
  1859. ld b, CGB_MAPPALS
  1860. call GetCGBLayout
  1861. farcall LoadBlindingFlashPalette
  1862. call UpdateTimePals
  1863. call DelayFrame
  1864. ld a, $1
  1865. ld [hMapAnims], a
  1866. pop af
  1867. ret
  1868. ; 0x2bae
  1869.  
  1870. ReloadTilesetAndPalettes:: ; 2bae
  1871. call DisableLCD
  1872. call ClearSprites
  1873. farcall ReloadVisibleSprites
  1874. call LoadStandardFont
  1875. call LoadFontsExtra
  1876. ld a, [hROMBank]
  1877. push af
  1878. ld a, [wMapGroup]
  1879. ld b, a
  1880. ld a, [wMapNumber]
  1881. ld c, a
  1882. call SwitchToAnyMapBank
  1883. farcall UpdateTimeOfDayPal
  1884. call LoadMapPart
  1885. call LoadTileset
  1886. ld a, 9
  1887. call SkipMusic
  1888. pop af
  1889. rst Bankswitch
  1890.  
  1891. jp EnableLCD
  1892. ; 2be5
  1893.  
  1894. GetMapHeaderPointer:: ; 2be5
  1895. ld a, [wMapGroup]
  1896. ld b, a
  1897. ld a, [wMapNumber]
  1898. ld c, a
  1899. GetAnyMapHeaderPointer:: ; 0x2bed
  1900. ; Prior to calling this function, you must have switched banks so that
  1901. ; MapGroupPointers is visible.
  1902.  
  1903. ; inputs:
  1904. ; b = map group, c = map number
  1905.  
  1906. ; outputs:
  1907. ; hl points to the map header
  1908. push bc ; save map number for later
  1909.  
  1910. ; get pointer to map group
  1911. dec b
  1912. ld c, b
  1913. ld b, 0
  1914. ld hl, MapGroupPointers
  1915. add hl, bc
  1916. add hl, bc
  1917.  
  1918. ld a, [hli]
  1919. ld h, [hl]
  1920. ld l, a
  1921. pop bc ; restore map number
  1922.  
  1923. ; find the cth map header
  1924. dec c
  1925. ld b, 0
  1926. ld a, 9
  1927. rst AddNTimes
  1928. ret
  1929. ; 0x2c04
  1930.  
  1931. GetMapHeaderMember:: ; 0x2c04
  1932. ; Extract data from the current map's header.
  1933.  
  1934. ; inputs:
  1935. ; de = offset of desired data within the mapheader
  1936.  
  1937. ; outputs:
  1938. ; bc = data from the current map's header
  1939. ; (e.g., de = $0003 would return a pointer to the secondary map header)
  1940.  
  1941. ld a, [wMapGroup]
  1942. ld b, a
  1943. ld a, [wMapNumber]
  1944. ld c, a
  1945. GetAnyMapHeaderMember:: ; 0x2c0c
  1946. ; bankswitch
  1947. ld a, [hROMBank]
  1948. push af
  1949. ld a, BANK(MapGroupPointers)
  1950. rst Bankswitch
  1951.  
  1952. call GetAnyMapHeaderPointer
  1953. add hl, de
  1954. ld c, [hl]
  1955. inc hl
  1956. ld b, [hl]
  1957.  
  1958. ; bankswitch back
  1959. pop af
  1960. rst Bankswitch
  1961. ret
  1962. ; 0x2c1c
  1963.  
  1964. SwitchToMapBank:: ; 2c1c
  1965. ld a, [wMapGroup]
  1966. ld b, a
  1967. ld a, [wMapNumber]
  1968. ld c, a
  1969. SwitchToAnyMapBank:: ; 2c24
  1970. call GetAnyMapBank
  1971. rst Bankswitch
  1972. ret
  1973. ; 2c29
  1974.  
  1975. GetAnyMapBank:: ; 2c31
  1976. push hl
  1977. push de
  1978. ld de, 0
  1979. call GetAnyMapHeaderMember
  1980. ld a, c
  1981. pop de
  1982. pop hl
  1983. ret
  1984. ; 2c3d
  1985.  
  1986. PartiallyCopyMapHeader:: ; 2c3d
  1987. ; Copy second map header bank, tileset, permission, and second map header address
  1988. ; from the current map's map header.
  1989. ld a, [hROMBank]
  1990. push af
  1991. ld a, BANK(MapGroupPointers)
  1992. rst Bankswitch
  1993.  
  1994. call GetMapHeaderPointer
  1995. ld de, wSecondMapHeaderBank
  1996. ld bc, wMapHeader - wSecondMapHeaderBank
  1997. rst CopyBytes
  1998.  
  1999. pop af
  2000. rst Bankswitch
  2001. ret
  2002. ; 2c52
  2003.  
  2004. SwitchToMapScriptHeaderBank:: ; 2c52
  2005. ld a, [wMapScriptHeaderBank]
  2006. rst Bankswitch
  2007. ret
  2008. ; 2c57
  2009.  
  2010. GetAnyMapBlockdataBankPointer:: ; 2c5b
  2011. ; Return the blockdata bank for group b map c.
  2012. push de
  2013. push bc
  2014.  
  2015. push bc
  2016. ld de, 3 ; second map header pointer
  2017. call GetAnyMapHeaderMember
  2018. ld l, c
  2019. ld h, b
  2020. pop bc
  2021.  
  2022. push hl
  2023. ld de, 0 ; second map header bank
  2024. call GetAnyMapHeaderMember
  2025. pop hl
  2026.  
  2027. inc hl
  2028. inc hl
  2029. inc hl
  2030. ld a, c
  2031. rst Bankswitch
  2032. ld a, [hli]
  2033. ld c, a
  2034. ld a, [hli]
  2035. ld h, [hl]
  2036. ld l, a
  2037. ld a, c
  2038. rst Bankswitch
  2039.  
  2040. pop bc
  2041. pop de
  2042. ret
  2043. ; 2c7d
  2044.  
  2045. GetSecondaryMapHeaderPointer:: ; 0x2c7d
  2046. ; returns the current map's secondary map header pointer in hl.
  2047. push bc
  2048. push de
  2049. ld de, 3 ; secondary map header pointer (offset within header)
  2050. call GetMapHeaderMember
  2051. ld l, c
  2052. ld h, b
  2053. pop de
  2054. pop bc
  2055. ret
  2056. ; 2c8a
  2057.  
  2058. GetMapPermission:: ; 2c8a
  2059. push hl
  2060. push de
  2061. push bc
  2062. ld de, 2 ; permission
  2063. call GetMapHeaderMember
  2064. ld a, c
  2065. pop bc
  2066. pop de
  2067. pop hl
  2068. ret
  2069. ; 2c98
  2070.  
  2071. GetAnyMapPermission:: ; 2c99
  2072. push hl
  2073. push de
  2074. push bc
  2075. ld de, 2 ; permission
  2076. call GetAnyMapHeaderMember
  2077. ld a, c
  2078. pop bc
  2079. pop de
  2080. pop hl
  2081. ret
  2082. ; 2ca7
  2083.  
  2084. GetAnyMapTileset:: ; 2ca7
  2085. ld de, 1 ; tileset
  2086. call GetAnyMapHeaderMember
  2087. ld a, c
  2088. ret
  2089. ; 2caf
  2090.  
  2091. GetWorldMapLocation:: ; 0x2caf
  2092. eventflagcheck EVENT_ON_DODRIO_RANCH
  2093. jr z, .DodrioRanch
  2094. ; given a map group/id in bc, return its location on the Pokégear map.
  2095. push hl
  2096. push de
  2097. push bc
  2098.  
  2099. ld de, 5 ; landmark
  2100. call GetAnyMapHeaderMember
  2101. ld a, c
  2102.  
  2103. pop bc
  2104. pop de
  2105. pop hl
  2106. ret
  2107. ; 0x2cbd
  2108.  
  2109. .DodrioRanch:
  2110. ld a, DODRIO_RANCH
  2111. ld [wCurrentLandmark], a
  2112. ret
  2113.  
  2114. GetCurrentLandmark::
  2115. ld a, [wMapGroup]
  2116. ld b, a
  2117. ld a, [wMapNumber]
  2118. ld c, a
  2119. call GetWorldMapLocation
  2120. and a ; cp SPECIAL_MAP
  2121. ret nz
  2122.  
  2123. ; In a special map, get the backup map group / map id
  2124. GetBackupLandmark::
  2125. ld a, [wBackupMapGroup]
  2126. ld b, a
  2127. ld a, [wBackupMapNumber]
  2128. ld c, a
  2129. jp GetWorldMapLocation
  2130.  
  2131. RegionCheck::
  2132. ; Checks if the player is in Kanto or Johto.
  2133. ; If in Johto, returns 0 in e.
  2134. ; If in Kanto, returns 1 in e.
  2135. ; If on Shamouti Island, returns 2 in e.
  2136. call GetCurrentLandmark
  2137. ld e, ORANGE_REGION
  2138. cp SHAMOUTI_LANDMARK
  2139. ret nc
  2140. dec e ; KANTO_REGION
  2141. cp KANTO_LANDMARK
  2142. ret nc
  2143. dec e ; JOHTO_REGION
  2144. ret
  2145.  
  2146. GetMapHeaderMusic:: ; 2cbd
  2147. push hl
  2148. push bc
  2149. ld de, 6 ; music
  2150. call GetMapHeaderMember
  2151. ld a, c
  2152. cp MUSIC_STARGLOW
  2153. jr z, .starglow
  2154. call Function8b342
  2155. ld e, c
  2156. ld d, 0
  2157. .done
  2158. pop bc
  2159. pop hl
  2160. ret
  2161.  
  2162. .starglow
  2163. ld a, [wSnareFlags]
  2164. bit 0, a ; ENGINE_ROCKETS_IN_RADIO_TOWER
  2165. jr z, .clearedstarglow
  2166. ld de, MUSIC_SNARE_INVASION
  2167. jr .done
  2168.  
  2169. .clearedstarglow
  2170. ld de, MUSIC_STARGLOW_VALLEY
  2171. jr .done
  2172. ; 2cff
  2173.  
  2174. Function8b342: ; 8b342
  2175. call GetSecondaryMapHeaderPointer
  2176. ld d, h
  2177. ld e, l
  2178. ret
  2179. ; 8b35d
  2180.  
  2181. GetMapHeaderTimeOfDayNybble:: ; 2cff
  2182. call GetPhoneServiceTimeOfDayByte
  2183. and $f
  2184. ret
  2185. ; 2d05
  2186.  
  2187. GetMapHeaderPhoneServiceNybble:: ; 2d05
  2188. call GetPhoneServiceTimeOfDayByte
  2189. and $f0
  2190. swap a
  2191. ret
  2192. ; 2d0d
  2193.  
  2194. GetPhoneServiceTimeOfDayByte:: ; 2d0d
  2195. push hl
  2196. push bc
  2197.  
  2198. ld de, 7 ; phone service and time of day
  2199. call GetMapHeaderMember
  2200. ld a, c
  2201.  
  2202. pop bc
  2203. pop hl
  2204. ret
  2205. ; 2d19
  2206.  
  2207. GetFishingGroup:: ; 2d19
  2208. push de
  2209. push hl
  2210. push bc
  2211.  
  2212. ld de, 8 ; fishing group
  2213. call GetMapHeaderMember
  2214. ld a, c
  2215.  
  2216. pop bc
  2217. pop hl
  2218. pop de
  2219. ret
  2220. ; 2d27
  2221.  
  2222. LoadTilesetHeader:: ; 2d27
  2223. push hl
  2224. push bc
  2225.  
  2226. ld hl, Tilesets
  2227. ld bc, wTilesetHeaderEnd - wTilesetHeader
  2228. ld a, [wTileset]
  2229. dec a
  2230. rst AddNTimes
  2231.  
  2232. ld de, wTilesetHeader
  2233. ld bc, wTilesetHeaderEnd - wTilesetHeader
  2234.  
  2235. ld a, BANK(Tilesets)
  2236. call FarCopyBytes
  2237.  
  2238. pop bc
  2239. pop hl
  2240. ret
  2241. ; 2d43
  2242.  
  2243. GetOvercastIndex::
  2244. ; Some maps are overcast, depending on certain conditions
  2245. ; ld a, [wMapGroup]
  2246. ; cp GROUP_AZALEA_TOWN ; GROUP_ROUTE_33
  2247. ; jr z, .azalea_route_33
  2248. ; cp GROUP_LAKE_OF_RAGE ; GROUP_ROUTE_43
  2249. ; jr z, .lake_of_rage_route_43
  2250. ; cp GROUP_STORMY_BEACH ; GROUP_GOLDENROD_CITY, GROUP_ROUTE_34, GROUP_ROUTE_34_COAST
  2251. ; jr z, .stormy_beach
  2252. ;.not_overcast:
  2253. ; xor a ; NOT_OVERCAST
  2254. ; ret
  2255.  
  2256. ;.azalea_route_33:
  2257. ; Azalea Town and Route 33
  2258. ; ld a, [wMapNumber]
  2259. ; cp MAP_AZALEA_TOWN
  2260. ; jr z, .azalea_town
  2261. ; cp MAP_ROUTE_33
  2262. ; jr nz, .not_overcast
  2263. ;.azalea_town
  2264. ; Not overcast until Slowpokes appear (Team Rocket beaten)
  2265. ; eventflagcheck EVENT_AZALEA_TOWN_SLOWPOKES
  2266. ; jr nz, .not_overcast
  2267. ; Overcast on Sunday, Tuesday, Thursday, and Saturday
  2268. ; call GetWeekday
  2269. ; cp MONDAY
  2270. ; jr z, .not_overcast
  2271. ; cp WEDNESDAY
  2272. ; jr z, .not_overcast
  2273. ; cp FRIDAY
  2274. ; jr z, .not_overcast
  2275. ; ld a, AZALEA_OVERCAST
  2276. ; ret
  2277.  
  2278. ;.lake_of_rage_route_43:
  2279. ; Lake of Rage and Route 43
  2280. ; ld a, [wMapNumber]
  2281. ; cp MAP_LAKE_OF_RAGE
  2282. ; jr z, .lake_of_rage
  2283. ; cp MAP_ROUTE_43
  2284. ; jr nz, .not_overcast
  2285. ;.lake_of_rage
  2286. ; Always overcast until civilians appear (Team Rocket beaten)
  2287. ; eventflagcheck EVENT_LAKE_OF_RAGE_CIVILIANS
  2288. ; jr nz, .overcast_lake_of_rage
  2289. ; Overcast on Monday, Wednesday, and Friday
  2290. ; call GetWeekday
  2291. ; cp MONDAY
  2292. ; jr z, .overcast_lake_of_rage
  2293. ; cp WEDNESDAY
  2294. ; jr z, .overcast_lake_of_rage
  2295. ; cp FRIDAY
  2296. ; jr nz, .not_overcast
  2297. ;.overcast_lake_of_rage
  2298. ; ld a, LAKE_OF_RAGE_OVERCAST
  2299. ; ret
  2300.  
  2301. ;.stormy_beach:
  2302. ; Stormy Beach or Goldenrod City, Route 34, and ROute 34 Coast
  2303. ; ld a, [wMapNumber]
  2304. ; Stormy Beach is always overcast
  2305. ; cp MAP_STORMY_BEACH
  2306. ; jr z, .overcast_stormy_beach
  2307. ; cp MAP_ROUTE_34_COAST
  2308. ; jr z, .maybe_stormy_beach
  2309. ; cp MAP_ROUTE_34
  2310. ; jr z, .maybe_stormy_beach
  2311. ; cp MAP_GOLDENROD_CITY
  2312. ; jr nz, .not_overcast
  2313. ; Only overcast while Team Rocket is present
  2314. ;.maybe_stormy_beach
  2315. ; eventflagcheck EVENT_GOLDENROD_CITY_ROCKET_TAKEOVER
  2316. ; jr nz, .not_overcast
  2317. ;.overcast_stormy_beach
  2318. ; ld a, STORMY_BEACH_OVERCAST
  2319. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement