pokedex.asm 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. ShowPokedexMenu:
  2. call GBPalWhiteOut
  3. call ClearScreen
  4. call UpdateSprites
  5. ld a, [wListScrollOffset]
  6. push af
  7. xor a
  8. ld [wCurrentMenuItem], a
  9. ld [wListScrollOffset], a
  10. ld [wLastMenuItem], a
  11. inc a
  12. ld [wd11e], a
  13. ld [hJoy7], a
  14. .setUpGraphics
  15. ld b, SET_PAL_GENERIC
  16. call RunPaletteCommand
  17. callab LoadPokedexTilePatterns
  18. .doPokemonListMenu
  19. ld hl, wTopMenuItemY
  20. ld a, 3
  21. ld [hli], a ; top menu item Y
  22. xor a
  23. ld [hli], a ; top menu item X
  24. inc a
  25. ld [wMenuWatchMovingOutOfBounds], a
  26. inc hl
  27. inc hl
  28. ld a, 6
  29. ld [hli], a ; max menu item ID
  30. ld [hl], D_LEFT | D_RIGHT | B_BUTTON | A_BUTTON
  31. call HandlePokedexListMenu
  32. jr c, .goToSideMenu ; if the player chose a pokemon from the list
  33. .exitPokedex
  34. xor a
  35. ld [wMenuWatchMovingOutOfBounds], a
  36. ld [wCurrentMenuItem], a
  37. ld [wLastMenuItem], a
  38. ld [hJoy7], a
  39. ld [wWastedByteCD3A], a
  40. ld [wOverrideSimulatedJoypadStatesMask], a
  41. pop af
  42. ld [wListScrollOffset], a
  43. call GBPalWhiteOutWithDelay3
  44. call RunDefaultPaletteCommand
  45. jp ReloadMapData
  46. .goToSideMenu
  47. call HandlePokedexSideMenu
  48. dec b
  49. jr z, .exitPokedex ; if the player chose Quit
  50. dec b
  51. jr z, .doPokemonListMenu ; if pokemon not seen or player pressed B button
  52. jp .setUpGraphics ; if pokemon data or area was shown
  53. ; handles the menu on the lower right in the pokedex screen
  54. ; OUTPUT:
  55. ; b = reason for exiting menu
  56. ; 00: showed pokemon data or area
  57. ; 01: the player chose Quit
  58. ; 02: the pokemon has not been seen yet or the player pressed the B button
  59. HandlePokedexSideMenu:
  60. call PlaceUnfilledArrowMenuCursor
  61. ld a, [wCurrentMenuItem]
  62. push af
  63. ld b, a
  64. ld a, [wLastMenuItem]
  65. push af
  66. ld a, [wListScrollOffset]
  67. push af
  68. add b
  69. inc a
  70. ld [wd11e], a
  71. ld a, [wd11e]
  72. push af
  73. ld a, [wDexMaxSeenMon]
  74. push af ; this doesn't need to be preserved
  75. ld hl, wPokedexSeen
  76. call IsPokemonBitSet
  77. ld b, 2
  78. jr z, .exitSideMenu
  79. call PokedexToIndex
  80. ld hl, wTopMenuItemY
  81. ld a, 10
  82. ld [hli], a ; top menu item Y
  83. ld a, 15
  84. ld [hli], a ; top menu item X
  85. xor a
  86. ld [hli], a ; current menu item ID
  87. inc hl
  88. ld a, 3
  89. ld [hli], a ; max menu item ID
  90. ;ld a, A_BUTTON | B_BUTTON
  91. ld [hli], a ; menu watched keys (A button and B button)
  92. xor a
  93. ld [hli], a ; old menu item ID
  94. ld [wMenuWatchMovingOutOfBounds], a
  95. .handleMenuInput
  96. call HandleMenuInput
  97. bit 1, a ; was the B button pressed?
  98. ld b, 2
  99. jr nz, .buttonBPressed
  100. ld a, [wCurrentMenuItem]
  101. and a
  102. jr z, .choseData
  103. dec a
  104. jr z, .choseCry
  105. dec a
  106. jr z, .choseArea
  107. .choseQuit
  108. ld b, 1
  109. .exitSideMenu
  110. pop af
  111. ld [wDexMaxSeenMon], a
  112. pop af
  113. ld [wd11e], a
  114. pop af
  115. ld [wListScrollOffset], a
  116. pop af
  117. ld [wLastMenuItem], a
  118. pop af
  119. ld [wCurrentMenuItem], a
  120. push bc
  121. coord hl, 0, 3
  122. ld de, 20
  123. lb bc, " ", 13
  124. call DrawTileLine ; cover up the menu cursor in the pokemon list
  125. pop bc
  126. ret
  127. .buttonBPressed
  128. push bc
  129. coord hl, 15, 10
  130. ld de, 20
  131. lb bc, " ", 7
  132. call DrawTileLine ; cover up the menu cursor in the side menu
  133. pop bc
  134. jr .exitSideMenu
  135. .choseData
  136. call ShowPokedexDataInternal
  137. ld b, 0
  138. jr .exitSideMenu
  139. ; play pokemon cry
  140. .choseCry
  141. ld a, [wd11e]
  142. call GetCryData
  143. call PlaySound
  144. jr .handleMenuInput
  145. .choseArea
  146. predef LoadTownMap_Nest ; display pokemon areas
  147. ld b, 0
  148. jr .exitSideMenu
  149. ; handles the list of pokemon on the left of the pokedex screen
  150. ; sets carry flag if player presses A, unsets carry flag if player presses B
  151. HandlePokedexListMenu:
  152. xor a
  153. ld [H_AUTOBGTRANSFERENABLED], a
  154. ; draw the horizontal line separating the seen and owned amounts from the menu
  155. coord hl, 15, 8
  156. ld a, "─"
  157. ld [hli], a
  158. ld [hli], a
  159. ld [hli], a
  160. ld [hli], a
  161. ld [hli], a
  162. coord hl, 14, 0
  163. ld [hl], $71 ; vertical line tile
  164. coord hl, 14, 1
  165. call DrawPokedexVerticalLine
  166. coord hl, 14, 9
  167. call DrawPokedexVerticalLine
  168. ld hl, wPokedexSeen
  169. ld b, wPokedexSeenEnd - wPokedexSeen
  170. call CountSetBits
  171. ld de, wNumSetBits
  172. coord hl, 16, 3
  173. lb bc, 1, 3
  174. call PrintNumber ; print number of seen pokemon
  175. ld hl, wPokedexOwned
  176. ld b, wPokedexOwnedEnd - wPokedexOwned
  177. call CountSetBits
  178. ld de, wNumSetBits
  179. coord hl, 16, 6
  180. lb bc, 1, 3
  181. call PrintNumber ; print number of owned pokemon
  182. coord hl, 16, 2
  183. ld de, PokedexSeenText
  184. call PlaceString
  185. coord hl, 16, 5
  186. ld de, PokedexOwnText
  187. call PlaceString
  188. coord hl, 1, 1
  189. ld de, PokedexContentsText
  190. call PlaceString
  191. coord hl, 16, 10
  192. ld de, PokedexMenuItemsText
  193. call PlaceString
  194. ; find the highest pokedex number among the pokemon the player has seen
  195. ld hl, wPokedexSeenEnd - 1
  196. ld b, (wPokedexSeenEnd - wPokedexSeen) * 8 + 1
  197. .maxSeenPokemonLoop
  198. ld a, [hld]
  199. ld c, 8
  200. .maxSeenPokemonInnerLoop
  201. dec b
  202. sla a
  203. jr c, .storeMaxSeenPokemon
  204. dec c
  205. jr nz, .maxSeenPokemonInnerLoop
  206. jr .maxSeenPokemonLoop
  207. .storeMaxSeenPokemon
  208. ld a, b
  209. ld [wDexMaxSeenMon], a
  210. .loop
  211. xor a
  212. ld [H_AUTOBGTRANSFERENABLED], a
  213. coord hl, 4, 2
  214. lb bc, 14, 10
  215. call ClearScreenArea
  216. coord hl, 1, 3
  217. ld a, [wListScrollOffset]
  218. ld [wd11e], a
  219. ld d, 7
  220. ld a, [wDexMaxSeenMon]
  221. cp 7
  222. jr nc, .printPokemonLoop
  223. ld d, a
  224. dec a
  225. ld [wMaxMenuItem], a
  226. ; loop to print pokemon pokedex numbers and names
  227. ; if the player has owned the pokemon, it puts a pokeball beside the name
  228. .printPokemonLoop
  229. ld a, [wd11e]
  230. inc a
  231. ld [wd11e], a
  232. push af
  233. push de
  234. push hl
  235. ld de, -SCREEN_WIDTH
  236. add hl, de
  237. ld de, wd11e
  238. lb bc, LEADING_ZEROES | 1, 3
  239. call PrintNumber ; print the pokedex number
  240. ld de, SCREEN_WIDTH
  241. add hl, de
  242. dec hl
  243. push hl
  244. ld hl, wPokedexOwned
  245. call IsPokemonBitSet
  246. pop hl
  247. ld a, " "
  248. jr z, .writeTile
  249. ld a, $72 ; pokeball tile
  250. .writeTile
  251. ld [hl], a ; put a pokeball next to pokemon that the player has owned
  252. push hl
  253. ld hl, wPokedexSeen
  254. call IsPokemonBitSet
  255. jr nz, .getPokemonName ; if the player has seen the pokemon
  256. ld de, .dashedLine ; print a dashed line in place of the name if the player hasn't seen the pokemon
  257. jr .skipGettingName
  258. .dashedLine ; for unseen pokemon in the list
  259. db "----------@"
  260. .getPokemonName
  261. call PokedexToIndex
  262. call GetMonName
  263. .skipGettingName
  264. pop hl
  265. inc hl
  266. call PlaceString
  267. pop hl
  268. ld bc, 2 * SCREEN_WIDTH
  269. add hl, bc
  270. pop de
  271. pop af
  272. ld [wd11e], a
  273. dec d
  274. jr nz, .printPokemonLoop
  275. ld a, 01
  276. ld [H_AUTOBGTRANSFERENABLED], a
  277. call Delay3
  278. call GBPalNormal
  279. call HandleMenuInput
  280. bit 1, a ; was the B button pressed?
  281. jp nz, .buttonBPressed
  282. .checkIfUpPressed
  283. bit 6, a ; was Up pressed?
  284. jr z, .checkIfDownPressed
  285. .upPressed ; scroll up one row
  286. ld a, [wListScrollOffset]
  287. and a
  288. jp z, .loop
  289. dec a
  290. ld [wListScrollOffset], a
  291. jp .loop
  292. .checkIfDownPressed
  293. bit 7, a ; was Down pressed?
  294. jr z, .checkIfRightPressed
  295. .downPressed ; scroll down one row
  296. ld a, [wDexMaxSeenMon]
  297. cp 7
  298. jp c, .loop ; can't if the list is shorter than 7
  299. sub 7
  300. ld b, a
  301. ld a, [wListScrollOffset]
  302. cp b
  303. jp z, .loop
  304. inc a
  305. ld [wListScrollOffset], a
  306. jp .loop
  307. .checkIfRightPressed
  308. bit 4, a ; was Right pressed?
  309. jr z, .checkIfLeftPressed
  310. .rightPressed ; scroll down 7 rows
  311. ld a, [wDexMaxSeenMon]
  312. cp 7
  313. jp c, .loop ; can't if the list is shorter than 7
  314. sub 6
  315. ld b, a
  316. ld a, [wListScrollOffset]
  317. add 7
  318. ld [wListScrollOffset], a
  319. cp b
  320. jp c, .loop
  321. dec b
  322. ld a, b
  323. ld [wListScrollOffset], a
  324. jp .loop
  325. .checkIfLeftPressed ; scroll up 7 rows
  326. bit 5, a ; was Left pressed?
  327. jr z, .buttonAPressed
  328. .leftPressed
  329. ld a, [wListScrollOffset]
  330. sub 7
  331. ld [wListScrollOffset], a
  332. jp nc, .loop
  333. xor a
  334. ld [wListScrollOffset], a
  335. jp .loop
  336. .buttonAPressed
  337. scf
  338. ret
  339. .buttonBPressed
  340. and a
  341. ret
  342. DrawPokedexVerticalLine:
  343. ld c, 9 ; height of line
  344. ld de, SCREEN_WIDTH
  345. ld a, $71 ; vertical line tile
  346. .loop
  347. ld [hl], a
  348. add hl, de
  349. xor 1 ; toggle between vertical line tile and box tile
  350. dec c
  351. jr nz, .loop
  352. ret
  353. PokedexSeenText:
  354. db "SEEN@"
  355. PokedexOwnText:
  356. db "OWN@"
  357. PokedexContentsText:
  358. db "CONTENTS@"
  359. PokedexMenuItemsText:
  360. db "DATA"
  361. next "CRY"
  362. next "AREA"
  363. next "QUIT@"
  364. ; tests if a pokemon's bit is set in the seen or owned pokemon bit fields
  365. ; INPUT:
  366. ; [wd11e] = pokedex number
  367. ; hl = address of bit field
  368. IsPokemonBitSet:
  369. ld a, [wd11e]
  370. dec a
  371. ld c, a
  372. ld b, FLAG_TEST
  373. predef FlagActionPredef
  374. ld a, c
  375. and a
  376. ret
  377. ; function to display pokedex data from outside the pokedex
  378. ShowPokedexData:
  379. call GBPalWhiteOutWithDelay3
  380. call ClearScreen
  381. call UpdateSprites
  382. callab LoadPokedexTilePatterns ; load pokedex tiles
  383. ; function to display pokedex data from inside the pokedex
  384. ShowPokedexDataInternal:
  385. ld hl, wd72c
  386. set 1, [hl]
  387. ld a, $33 ; 3/7 volume
  388. ld [rNR50], a
  389. call GBPalWhiteOut ; zero all palettes
  390. call ClearScreen
  391. ld a, [wd11e] ; pokemon ID
  392. ld [wcf91], a
  393. push af
  394. ld b, SET_PAL_POKEDEX
  395. call RunPaletteCommand
  396. pop af
  397. ld [wd11e], a
  398. ld a, [hTilesetType]
  399. push af
  400. xor a
  401. ld [hTilesetType], a
  402. coord hl, 0, 0
  403. ld de, 1
  404. lb bc, $64, SCREEN_WIDTH
  405. call DrawTileLine ; draw top border
  406. coord hl, 0, 17
  407. ld b, $6f
  408. call DrawTileLine ; draw bottom border
  409. coord hl, 0, 1
  410. ld de, 20
  411. lb bc, $66, $10
  412. call DrawTileLine ; draw left border
  413. coord hl, 19, 1
  414. ld b, $67
  415. call DrawTileLine ; draw right border
  416. ld a, $63 ; upper left corner tile
  417. Coorda 0, 0
  418. ld a, $65 ; upper right corner tile
  419. Coorda 19, 0
  420. ld a, $6c ; lower left corner tile
  421. Coorda 0, 17
  422. ld a, $6e ; lower right corner tile
  423. Coorda 19, 17
  424. coord hl, 0, 9
  425. ld de, PokedexDataDividerLine
  426. call PlaceString ; draw horizontal divider line
  427. coord hl, 9, 6
  428. ld de, HeightWeightText
  429. call PlaceString
  430. call GetMonName
  431. coord hl, 9, 2
  432. call PlaceString
  433. ld hl, PokedexEntryPointers
  434. ld a, [wd11e]
  435. dec a
  436. ld e, a
  437. ld d, 0
  438. add hl, de
  439. add hl, de
  440. ld a, [hli]
  441. ld e, a
  442. ld d, [hl] ; de = address of pokedex entry
  443. coord hl, 9, 4
  444. call PlaceString ; print species name
  445. ld h, b
  446. ld l, c
  447. push de
  448. ld a, [wd11e]
  449. push af
  450. call IndexToPokedex
  451. coord hl, 2, 8
  452. ld a, "№"
  453. ld [hli], a
  454. ld a, "⠄"
  455. ld [hli], a
  456. ld de, wd11e
  457. lb bc, LEADING_ZEROES | 1, 3
  458. call PrintNumber ; print pokedex number
  459. ld hl, wPokedexOwned
  460. call IsPokemonBitSet
  461. pop af
  462. ld [wd11e], a
  463. ld a, [wcf91]
  464. ld [wd0b5], a
  465. pop de
  466. push af
  467. push bc
  468. push de
  469. push hl
  470. call Delay3
  471. call GBPalNormal
  472. call GetMonHeader ; load pokemon picture location
  473. coord hl, 1, 1
  474. call LoadFlippedFrontSpriteByMonIndex ; draw pokemon picture
  475. ld a, [wcf91]
  476. call PlayCry ; play pokemon cry
  477. pop hl
  478. pop de
  479. pop bc
  480. pop af
  481. ld a, c
  482. and a
  483. jp z, .waitForButtonPress ; if the pokemon has not been owned, don't print the height, weight, or description
  484. inc de ; de = address of feet (height)
  485. ld a, [de] ; reads feet, but a is overwritten without being used
  486. coord hl, 12, 6
  487. lb bc, 1, 2
  488. call PrintNumber ; print feet (height)
  489. ld a, $60 ; feet symbol tile (one tick)
  490. ld [hl], a
  491. inc de
  492. inc de ; de = address of inches (height)
  493. coord hl, 15, 6
  494. lb bc, LEADING_ZEROES | 1, 2
  495. call PrintNumber ; print inches (height)
  496. ld a, $61 ; inches symbol tile (two ticks)
  497. ld [hl], a
  498. ; now print the weight (note that weight is stored in tenths of pounds internally)
  499. inc de
  500. inc de
  501. inc de ; de = address of upper byte of weight
  502. push de
  503. ; put weight in big-endian order at hDexWeight
  504. ld hl, hDexWeight
  505. ld a, [hl] ; save existing value of [hDexWeight]
  506. push af
  507. ld a, [de] ; a = upper byte of weight
  508. ld [hli], a ; store upper byte of weight in [hDexWeight]
  509. ld a, [hl] ; save existing value of [hDexWeight + 1]
  510. push af
  511. dec de
  512. ld a, [de] ; a = lower byte of weight
  513. ld [hl], a ; store lower byte of weight in [hDexWeight + 1]
  514. ld de, hDexWeight
  515. coord hl, 11, 8
  516. lb bc, 2, 5 ; 2 bytes, 5 digits
  517. call PrintNumber ; print weight
  518. coord hl, 14, 8
  519. ld a, [hDexWeight + 1]
  520. sub 10
  521. ld a, [hDexWeight]
  522. sbc 0
  523. jr nc, .next
  524. ld [hl], "0" ; if the weight is less than 10, put a 0 before the decimal point
  525. .next
  526. inc hl
  527. ld a, [hli]
  528. ld [hld], a ; make space for the decimal point by moving the last digit forward one tile
  529. ld [hl], "⠄" ; decimal point tile
  530. pop af
  531. ld [hDexWeight + 1], a ; restore original value of [hDexWeight + 1]
  532. pop af
  533. ld [hDexWeight], a ; restore original value of [hDexWeight]
  534. pop hl
  535. inc hl ; hl = address of pokedex description text
  536. coord bc, 1, 11
  537. ld a, 2
  538. ld [$fff4], a
  539. call TextCommandProcessor ; print pokedex description text
  540. xor a
  541. ld [$fff4], a
  542. .waitForButtonPress
  543. call JoypadLowSensitivity
  544. ld a, [hJoy5]
  545. and A_BUTTON | B_BUTTON
  546. jr z, .waitForButtonPress
  547. pop af
  548. ld [hTilesetType], a
  549. call GBPalWhiteOut
  550. call ClearScreen
  551. call RunDefaultPaletteCommand
  552. call LoadTextBoxTilePatterns
  553. call GBPalNormal
  554. ld hl, wd72c
  555. res 1, [hl]
  556. ld a, $77 ; max volume
  557. ld [rNR50], a
  558. ret
  559. HeightWeightText:
  560. db "HT ?",$60,"??",$61
  561. next "WT ???lb@"
  562. ; XXX does anything point to this?
  563. PokeText:
  564. db "#@"
  565. ; horizontal line that divides the pokedex text description from the rest of the data
  566. PokedexDataDividerLine:
  567. db $68,$69,$6B,$69,$6B
  568. db $69,$6B,$69,$6B,$6B
  569. db $6B,$6B,$69,$6B,$69
  570. db $6B,$69,$6B,$69,$6A
  571. db "@"
  572. ; draws a line of tiles
  573. ; INPUT:
  574. ; b = tile ID
  575. ; c = number of tile ID's to write
  576. ; de = amount to destination address after each tile (1 for horizontal, 20 for vertical)
  577. ; hl = destination address
  578. DrawTileLine:
  579. push bc
  580. push de
  581. .loop
  582. ld [hl], b
  583. add hl, de
  584. dec c
  585. jr nz, .loop
  586. pop de
  587. pop bc
  588. ret
  589. INCLUDE "data/pokedex_entries.asm"
  590. PokedexToIndex:
  591. ; converts the Pokédex number at wd11e to an index
  592. push bc
  593. push hl
  594. ld a, [wd11e]
  595. ld b, a
  596. ld c, 0
  597. ld hl, PokedexOrder
  598. .loop ; go through the list until we find an entry with a matching dex number
  599. inc c
  600. ld a, [hli]
  601. cp b
  602. jr nz, .loop
  603. ld a, c
  604. ld [wd11e], a
  605. pop hl
  606. pop bc
  607. ret
  608. IndexToPokedex:
  609. ; converts the index number at wd11e to a Pokédex number
  610. push bc
  611. push hl
  612. ld a, [wd11e]
  613. dec a
  614. ld hl, PokedexOrder
  615. ld b, 0
  616. ld c, a
  617. add hl, bc
  618. ld a, [hl]
  619. ld [wd11e], a
  620. pop hl
  621. pop bc
  622. ret
  623. INCLUDE "data/pokedex_order.asm"