town_map.asm 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. DisplayTownMap:
  2. call LoadTownMap
  3. ld hl, wUpdateSpritesEnabled
  4. ld a, [hl]
  5. push af
  6. ld [hl], $ff
  7. push hl
  8. ld a, $1
  9. ld [hJoy7], a
  10. ld a, [wCurMap]
  11. push af
  12. ld b, $0
  13. call DrawPlayerOrBirdSprite ; player sprite
  14. coord hl, 1, 0
  15. ld de, wcd6d
  16. call PlaceString
  17. ld hl, wOAMBuffer
  18. ld de, wTileMapBackup
  19. ld bc, $10
  20. call CopyData
  21. ld hl, vSprites + $40
  22. ld de, TownMapCursor
  23. lb bc, BANK(TownMapCursor), (TownMapCursorEnd - TownMapCursor) / $8
  24. call CopyVideoDataDouble
  25. xor a
  26. ld [wWhichTownMapLocation], a
  27. pop af
  28. jr .enterLoop
  29. .townMapLoop
  30. coord hl, 0, 0
  31. lb bc, 1, 20
  32. call ClearScreenArea
  33. ld hl, TownMapOrder
  34. ld a, [wWhichTownMapLocation]
  35. ld c, a
  36. ld b, 0
  37. add hl, bc
  38. ld a, [hl]
  39. .enterLoop
  40. ld de, wTownMapCoords
  41. call LoadTownMapEntry
  42. ld a, [de]
  43. push hl
  44. call TownMapCoordsToOAMCoords
  45. ld a, $4
  46. ld [wOAMBaseTile], a
  47. ld hl, wOAMBuffer + $10
  48. call WriteTownMapSpriteOAM ; town map cursor sprite
  49. pop hl
  50. ld de, wcd6d
  51. .copyMapName
  52. ld a, [hli]
  53. ld [de], a
  54. inc de
  55. cp $50
  56. jr nz, .copyMapName
  57. coord hl, 1, 0
  58. ld de, wcd6d
  59. call PlaceString
  60. ld hl, wOAMBuffer + $10
  61. ld de, wTileMapBackup + 16
  62. ld bc, $10
  63. call CopyData
  64. .inputLoop
  65. call TownMapSpriteBlinkingAnimation
  66. call JoypadLowSensitivity
  67. ld a, [hJoy5]
  68. ld b, a
  69. and A_BUTTON | B_BUTTON | D_UP | D_DOWN
  70. jr z, .inputLoop
  71. ld a, SFX_TINK
  72. call PlaySound
  73. bit 6, b
  74. jr nz, .pressedUp
  75. bit 7, b
  76. jr nz, .pressedDown
  77. xor a
  78. ld [wTownMapSpriteBlinkingEnabled], a
  79. ld [hJoy7], a
  80. ld [wAnimCounter], a
  81. call ExitTownMap
  82. pop hl
  83. pop af
  84. ld [hl], a
  85. ret
  86. .pressedUp
  87. ld a, [wWhichTownMapLocation]
  88. inc a
  89. cp TownMapOrderEnd - TownMapOrder ; number of list items + 1
  90. jr nz, .noOverflow
  91. xor a
  92. .noOverflow
  93. ld [wWhichTownMapLocation], a
  94. jp .townMapLoop
  95. .pressedDown
  96. ld a, [wWhichTownMapLocation]
  97. dec a
  98. cp -1
  99. jr nz, .noUnderflow
  100. ld a, TownMapOrderEnd - TownMapOrder - 1 ; number of list items
  101. .noUnderflow
  102. ld [wWhichTownMapLocation], a
  103. jp .townMapLoop
  104. INCLUDE "data/town_map_order.asm"
  105. TownMapCursor:
  106. INCBIN "gfx/town_map_cursor.1bpp"
  107. TownMapCursorEnd:
  108. LoadTownMap_Nest:
  109. call LoadTownMap
  110. ld hl, wUpdateSpritesEnabled
  111. ld a, [hl]
  112. push af
  113. ld [hl], $ff
  114. push hl
  115. call DisplayWildLocations
  116. call GetMonName
  117. coord hl, 1, 0
  118. call PlaceString
  119. ld h, b
  120. ld l, c
  121. ld de, MonsNestText
  122. call PlaceString
  123. call WaitForTextScrollButtonPress
  124. call ExitTownMap
  125. pop hl
  126. pop af
  127. ld [hl], a
  128. ret
  129. MonsNestText:
  130. db "'s NEST@"
  131. LoadTownMap_Fly:
  132. call ClearSprites
  133. call LoadTownMap
  134. call LoadPlayerSpriteGraphics
  135. call LoadFontTilePatterns
  136. ld de, BirdSprite
  137. ld hl, vSprites + $40
  138. lb bc, BANK(BirdSprite), $c
  139. call CopyVideoData
  140. ld de, TownMapUpArrow
  141. ld hl, vChars1 + $6d0
  142. lb bc, BANK(TownMapUpArrow), (TownMapUpArrowEnd - TownMapUpArrow) / $8
  143. call CopyVideoDataDouble
  144. call BuildFlyLocationsList
  145. ld hl, wUpdateSpritesEnabled
  146. ld a, [hl]
  147. push af
  148. ld [hl], $ff
  149. push hl
  150. coord hl, 0, 0
  151. ld de, ToText
  152. call PlaceString
  153. ld a, [wCurMap]
  154. ld b, $0
  155. call DrawPlayerOrBirdSprite
  156. ld hl, wFlyLocationsList
  157. coord de, 18, 0
  158. .townMapFlyLoop
  159. ld a, " "
  160. ld [de], a
  161. push hl
  162. push hl
  163. coord hl, 3, 0
  164. lb bc, 1, 15
  165. call ClearScreenArea
  166. pop hl
  167. ld a, [hl]
  168. ld b, $4
  169. call DrawPlayerOrBirdSprite ; draw bird sprite
  170. coord hl, 3, 0
  171. ld de, wcd6d
  172. call PlaceString
  173. ld c, 15
  174. call DelayFrames
  175. coord hl, 18, 0
  176. ld [hl], "▲"
  177. coord hl, 19, 0
  178. ld [hl], "▼"
  179. pop hl
  180. .inputLoop
  181. push hl
  182. call DelayFrame
  183. call JoypadLowSensitivity
  184. ld a, [hJoy5]
  185. ld b, a
  186. pop hl
  187. and A_BUTTON | B_BUTTON | D_UP | D_DOWN
  188. jr z, .inputLoop
  189. bit 0, b
  190. jr nz, .pressedA
  191. ld a, SFX_TINK
  192. call PlaySound
  193. bit 6, b
  194. jr nz, .pressedUp
  195. bit 7, b
  196. jr nz, .pressedDown
  197. jr .pressedB
  198. .pressedA
  199. ld a, SFX_HEAL_AILMENT
  200. call PlaySound
  201. ld a, [hl]
  202. ld [wDestinationMap], a
  203. ld hl, wd732
  204. set 3, [hl]
  205. inc hl
  206. set 7, [hl]
  207. .pressedB
  208. xor a
  209. ld [wTownMapSpriteBlinkingEnabled], a
  210. call GBPalWhiteOutWithDelay3
  211. pop hl
  212. pop af
  213. ld [hl], a
  214. ret
  215. .pressedUp
  216. coord de, 18, 0
  217. inc hl
  218. ld a, [hl]
  219. cp $ff
  220. jr z, .wrapToStartOfList
  221. cp $fe
  222. jr z, .pressedUp ; skip past unvisited towns
  223. jp .townMapFlyLoop
  224. .wrapToStartOfList
  225. ld hl, wFlyLocationsList
  226. jp .townMapFlyLoop
  227. .pressedDown
  228. coord de, 19, 0
  229. dec hl
  230. ld a, [hl]
  231. cp $ff
  232. jr z, .wrapToEndOfList
  233. cp $fe
  234. jr z, .pressedDown ; skip past unvisited towns
  235. jp .townMapFlyLoop
  236. .wrapToEndOfList
  237. ld hl, wFlyLocationsList + 11
  238. jr .pressedDown
  239. ToText:
  240. db "To@"
  241. BuildFlyLocationsList:
  242. ld hl, wFlyLocationsList - 1
  243. ld [hl], $ff
  244. inc hl
  245. ld a, [wTownVisitedFlag]
  246. ld e, a
  247. ld a, [wTownVisitedFlag + 1]
  248. ld d, a
  249. ld bc, SAFFRON_CITY + 1
  250. .loop
  251. srl d
  252. rr e
  253. ld a, $fe ; store $fe if the town hasn't been visited
  254. jr nc, .notVisited
  255. ld a, b ; store the map number of the town if it has been visited
  256. .notVisited
  257. ld [hl], a
  258. inc hl
  259. inc b
  260. dec c
  261. jr nz, .loop
  262. ld [hl], $ff
  263. ret
  264. TownMapUpArrow:
  265. INCBIN "gfx/up_arrow.1bpp"
  266. TownMapUpArrowEnd:
  267. LoadTownMap:
  268. call GBPalWhiteOutWithDelay3
  269. call ClearScreen
  270. call UpdateSprites
  271. coord hl, 0, 0
  272. ld b, $12
  273. ld c, $12
  274. call TextBoxBorder
  275. call DisableLCD
  276. ld hl, WorldMapTileGraphics
  277. ld de, vChars2 + $600
  278. ld bc, WorldMapTileGraphicsEnd - WorldMapTileGraphics
  279. ld a, BANK(WorldMapTileGraphics)
  280. call FarCopyData2
  281. ld hl, MonNestIcon
  282. ld de, vSprites + $40
  283. ld bc, MonNestIconEnd - MonNestIcon
  284. ld a, BANK(MonNestIcon)
  285. call FarCopyDataDouble
  286. coord hl, 0, 0
  287. ld de, CompressedMap
  288. .nextTile
  289. ld a, [de]
  290. and a
  291. jr z, .done
  292. ld b, a
  293. and $f
  294. ld c, a
  295. ld a, b
  296. swap a
  297. and $f
  298. add $60
  299. .writeRunLoop
  300. ld [hli], a
  301. dec c
  302. jr nz, .writeRunLoop
  303. inc de
  304. jr .nextTile
  305. .done
  306. call EnableLCD
  307. ld b, SET_PAL_TOWN_MAP
  308. call RunPaletteCommand
  309. call Delay3
  310. call GBPalNormal
  311. xor a
  312. ld [wAnimCounter], a
  313. inc a
  314. ld [wTownMapSpriteBlinkingEnabled], a
  315. ret
  316. CompressedMap:
  317. ; you can decompress this file with the redrle program in the extras/ dir
  318. INCBIN "gfx/town_map.rle"
  319. ExitTownMap:
  320. ; clear town map graphics data and load usual graphics data
  321. xor a
  322. ld [wTownMapSpriteBlinkingEnabled], a
  323. call GBPalWhiteOut
  324. call ClearScreen
  325. call ClearSprites
  326. call LoadPlayerSpriteGraphics
  327. call LoadFontTilePatterns
  328. call UpdateSprites
  329. jp RunDefaultPaletteCommand
  330. DrawPlayerOrBirdSprite:
  331. ; a = map number
  332. ; b = OAM base tile
  333. push af
  334. ld a, b
  335. ld [wOAMBaseTile], a
  336. pop af
  337. ld de, wTownMapCoords
  338. call LoadTownMapEntry
  339. ld a, [de]
  340. push hl
  341. call TownMapCoordsToOAMCoords
  342. call WritePlayerOrBirdSpriteOAM
  343. pop hl
  344. ld de, wcd6d
  345. .loop
  346. ld a, [hli]
  347. ld [de], a
  348. inc de
  349. cp "@"
  350. jr nz, .loop
  351. ld hl, wOAMBuffer
  352. ld de, wTileMapBackup
  353. ld bc, $a0
  354. jp CopyData
  355. DisplayWildLocations:
  356. callba FindWildLocationsOfMon
  357. call ZeroOutDuplicatesInList
  358. ld hl, wOAMBuffer
  359. ld de, wTownMapCoords
  360. .loop
  361. ld a, [de]
  362. cp $ff
  363. jr z, .exitLoop
  364. and a
  365. jr z, .nextEntry
  366. push hl
  367. call LoadTownMapEntry
  368. pop hl
  369. ld a, [de]
  370. cp $19 ; Cerulean Cave's coordinates
  371. jr z, .nextEntry ; skip Cerulean Cave
  372. call TownMapCoordsToOAMCoords
  373. ld a, $4 ; nest icon tile no.
  374. ld [hli], a
  375. xor a
  376. ld [hli], a
  377. .nextEntry
  378. inc de
  379. jr .loop
  380. .exitLoop
  381. ld a, l
  382. and a ; were any OAM entries written?
  383. jr nz, .drawPlayerSprite
  384. ; if no OAM entries were written, print area unknown text
  385. coord hl, 1, 7
  386. ld b, 2
  387. ld c, 15
  388. call TextBoxBorder
  389. coord hl, 2, 9
  390. ld de, AreaUnknownText
  391. call PlaceString
  392. jr .done
  393. .drawPlayerSprite
  394. ld a, [wCurMap]
  395. ld b, $0
  396. call DrawPlayerOrBirdSprite
  397. .done
  398. ld hl, wOAMBuffer
  399. ld de, wTileMapBackup
  400. ld bc, $a0
  401. jp CopyData
  402. AreaUnknownText:
  403. db " AREA UNKNOWN@"
  404. TownMapCoordsToOAMCoords:
  405. ; in: lower nybble of a = x, upper nybble of a = y
  406. ; out: b and [hl] = (y * 8) + 24, c and [hl+1] = (x * 8) + 24
  407. push af
  408. and $f0
  409. srl a
  410. add 24
  411. ld b, a
  412. ld [hli], a
  413. pop af
  414. and $f
  415. swap a
  416. srl a
  417. add 24
  418. ld c, a
  419. ld [hli], a
  420. ret
  421. WritePlayerOrBirdSpriteOAM:
  422. ld a, [wOAMBaseTile]
  423. and a
  424. ld hl, wOAMBuffer + $90 ; for player sprite
  425. jr z, WriteTownMapSpriteOAM
  426. ld hl, wOAMBuffer + $80 ; for bird sprite
  427. WriteTownMapSpriteOAM:
  428. push hl
  429. ; Subtract 4 from c (X coord) and 4 from b (Y coord). However, the carry from c
  430. ; is added to b, so the net result is that only 3 is subtracted from b.
  431. lb hl, -4, -4
  432. add hl, bc
  433. ld b, h
  434. ld c, l
  435. pop hl
  436. WriteAsymmetricMonPartySpriteOAM:
  437. ; Writes 4 OAM blocks for a helix mon party sprite, since it does not have
  438. ; a vertical line of symmetry.
  439. lb de, 2, 2
  440. .loop
  441. push de
  442. push bc
  443. .innerLoop
  444. ld a, b
  445. ld [hli], a
  446. ld a, c
  447. ld [hli], a
  448. ld a, [wOAMBaseTile]
  449. ld [hli], a
  450. inc a
  451. ld [wOAMBaseTile], a
  452. xor a
  453. ld [hli], a
  454. inc d
  455. ld a, 8
  456. add c
  457. ld c, a
  458. dec e
  459. jr nz, .innerLoop
  460. pop bc
  461. pop de
  462. ld a, 8
  463. add b
  464. ld b, a
  465. dec d
  466. jr nz, .loop
  467. ret
  468. WriteSymmetricMonPartySpriteOAM:
  469. ; Writes 4 OAM blocks for a mon party sprite other than a helix. All the
  470. ; sprites other than the helix one have a vertical line of symmetry which allows
  471. ; the X-flip OAM bit to be used so that only 2 rather than 4 tile patterns are
  472. ; needed.
  473. xor a
  474. ld [wSymmetricSpriteOAMAttributes], a
  475. lb de, 2, 2
  476. .loop
  477. push de
  478. push bc
  479. .innerLoop
  480. ld a, b
  481. ld [hli], a ; Y
  482. ld a, c
  483. ld [hli], a ; X
  484. ld a, [wOAMBaseTile]
  485. ld [hli], a ; tile
  486. ld a, [wSymmetricSpriteOAMAttributes]
  487. ld [hli], a ; attributes
  488. xor (1 << OAM_X_FLIP)
  489. ld [wSymmetricSpriteOAMAttributes], a
  490. inc d
  491. ld a, 8
  492. add c
  493. ld c, a
  494. dec e
  495. jr nz, .innerLoop
  496. pop bc
  497. pop de
  498. push hl
  499. ld hl, wOAMBaseTile
  500. inc [hl]
  501. inc [hl]
  502. pop hl
  503. ld a, 8
  504. add b
  505. ld b, a
  506. dec d
  507. jr nz, .loop
  508. ret
  509. ZeroOutDuplicatesInList:
  510. ; replace duplicate bytes in the list of wild pokemon locations with 0
  511. ld de, wBuffer
  512. .loop
  513. ld a, [de]
  514. inc de
  515. cp $ff
  516. ret z
  517. ld c, a
  518. ld l, e
  519. ld h, d
  520. .zeroDuplicatesLoop
  521. ld a, [hl]
  522. cp $ff
  523. jr z, .loop
  524. cp c
  525. jr nz, .skipZeroing
  526. xor a
  527. ld [hl], a
  528. .skipZeroing
  529. inc hl
  530. jr .zeroDuplicatesLoop
  531. LoadTownMapEntry:
  532. ; in: a = map number
  533. ; out: lower nybble of [de] = x, upper nybble of [de] = y, hl = address of name
  534. cp REDS_HOUSE_1F
  535. jr c, .external
  536. ld bc, 4
  537. ld hl, InternalMapEntries
  538. .loop
  539. cp [hl]
  540. jr c, .foundEntry
  541. add hl, bc
  542. jr .loop
  543. .foundEntry
  544. inc hl
  545. jr .readEntry
  546. .external
  547. ld hl, ExternalMapEntries
  548. ld c, a
  549. ld b, 0
  550. add hl, bc
  551. add hl, bc
  552. add hl, bc
  553. .readEntry
  554. ld a, [hli]
  555. ld [de], a
  556. ld a, [hli]
  557. ld h, [hl]
  558. ld l, a
  559. ret
  560. INCLUDE "data/town_map_entries.asm"
  561. INCLUDE "text/map_names.asm"
  562. MonNestIcon:
  563. INCBIN "gfx/mon_nest_icon.1bpp"
  564. MonNestIconEnd:
  565. TownMapSpriteBlinkingAnimation:
  566. ld a, [wAnimCounter]
  567. inc a
  568. cp 25
  569. jr z, .hideSprites
  570. cp 50
  571. jr nz, .done
  572. ; show sprites when the counter reaches 50
  573. ld hl, wTileMapBackup
  574. ld de, wOAMBuffer
  575. ld bc, $90
  576. call CopyData
  577. xor a
  578. jr .done
  579. .hideSprites
  580. ld hl, wOAMBuffer
  581. ld b, $24
  582. ld de, $4
  583. .hideSpritesLoop
  584. ld [hl], $a0
  585. add hl, de
  586. dec b
  587. jr nz, .hideSpritesLoop
  588. ld a, 25
  589. .done
  590. ld [wAnimCounter], a
  591. jp DelayFrame