start_sub_menus.asm 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. StartMenu_Pokedex:
  2. predef ShowPokedexMenu
  3. call LoadScreenTilesFromBuffer2 ; restore saved screen
  4. call Delay3
  5. call LoadGBPal
  6. call UpdateSprites
  7. jp RedisplayStartMenu
  8. StartMenu_Pokemon:
  9. ld a, [wPartyCount]
  10. and a
  11. jp z, RedisplayStartMenu
  12. xor a
  13. ld [wMenuItemToSwap], a
  14. ld [wPartyMenuTypeOrMessageID], a
  15. ld [wUpdateSpritesEnabled], a
  16. call DisplayPartyMenu
  17. jr .checkIfPokemonChosen
  18. .loop
  19. xor a
  20. ld [wMenuItemToSwap], a
  21. ld [wPartyMenuTypeOrMessageID], a
  22. call GoBackToPartyMenu
  23. .checkIfPokemonChosen
  24. jr nc, .chosePokemon
  25. .exitMenu
  26. call GBPalWhiteOutWithDelay3
  27. call RestoreScreenTilesAndReloadTilePatterns
  28. call LoadGBPal
  29. jp RedisplayStartMenu
  30. .chosePokemon
  31. call SaveScreenTilesToBuffer1
  32. ld a, FIELD_MOVE_MON_MENU
  33. ld [wTextBoxID], a
  34. call DisplayTextBoxID ; display pokemon menu options
  35. ld hl, wFieldMoves
  36. lb bc, 2, 12 ; max menu item ID, top menu item Y
  37. ld e, 5
  38. .adjustMenuVariablesLoop
  39. dec e
  40. jr z, .storeMenuVariables
  41. ld a, [hli]
  42. and a ; end of field moves?
  43. jr z, .storeMenuVariables
  44. inc b
  45. dec c
  46. dec c
  47. jr .adjustMenuVariablesLoop
  48. .storeMenuVariables
  49. ld hl, wTopMenuItemY
  50. ld a, c
  51. ld [hli], a ; top menu item Y
  52. ld a, [hFieldMoveMonMenuTopMenuItemX]
  53. ld [hli], a ; top menu item X
  54. xor a
  55. ld [hli], a ; current menu item ID
  56. inc hl
  57. ld a, b
  58. ld [hli], a ; max menu item ID
  59. ld a, A_BUTTON | B_BUTTON
  60. ld [hli], a ; menu watched keys
  61. xor a
  62. ld [hl], a
  63. call HandleMenuInput
  64. push af
  65. call LoadScreenTilesFromBuffer1 ; restore saved screen
  66. pop af
  67. bit 1, a ; was the B button pressed?
  68. jp nz, .loop
  69. ; if the B button wasn't pressed
  70. ld a, [wMaxMenuItem]
  71. ld b, a
  72. ld a, [wCurrentMenuItem] ; menu selection
  73. cp b
  74. jp z, .exitMenu ; if the player chose Cancel
  75. dec b
  76. cp b
  77. jr z, .choseSwitch
  78. dec b
  79. cp b
  80. jp z, .choseStats
  81. ld c, a
  82. ld b, 0
  83. ld hl, wFieldMoves
  84. add hl, bc
  85. jp .choseOutOfBattleMove
  86. .choseSwitch
  87. ld a, [wPartyCount]
  88. cp 2 ; is there more than one pokemon in the party?
  89. jp c, StartMenu_Pokemon ; if not, no switching
  90. call SwitchPartyMon_InitVarOrSwapData ; init [wMenuItemToSwap]
  91. ld a, SWAP_MONS_PARTY_MENU
  92. ld [wPartyMenuTypeOrMessageID], a
  93. call GoBackToPartyMenu
  94. jp .checkIfPokemonChosen
  95. .choseStats
  96. call ClearSprites
  97. xor a ; PLAYER_PARTY_DATA
  98. ld [wMonDataLocation], a
  99. predef StatusScreen
  100. predef StatusScreen2
  101. call ReloadMapData
  102. jp StartMenu_Pokemon
  103. .choseOutOfBattleMove
  104. push hl
  105. ld a, [wWhichPokemon]
  106. ld hl, wPartyMonNicks
  107. call GetPartyMonName
  108. pop hl
  109. ld a, [hl]
  110. dec a
  111. add a
  112. ld b, 0
  113. ld c, a
  114. ld hl, .outOfBattleMovePointers
  115. add hl, bc
  116. ld a, [hli]
  117. ld h, [hl]
  118. ld l, a
  119. ld a, [wObtainedBadges] ; badges obtained
  120. jp hl
  121. .outOfBattleMovePointers
  122. dw .cut
  123. dw .fly
  124. dw .surf
  125. dw .surf
  126. dw .strength
  127. dw .flash
  128. dw .dig
  129. dw .teleport
  130. dw .softboiled
  131. .fly
  132. bit 2, a ; does the player have the Thunder Badge?
  133. jp z, .newBadgeRequired
  134. call CheckIfInOutsideMap
  135. jr z, .canFly
  136. ld a, [wWhichPokemon]
  137. ld hl, wPartyMonNicks
  138. call GetPartyMonName
  139. ld hl, .cannotFlyHereText
  140. call PrintText
  141. jp .loop
  142. .canFly
  143. call ChooseFlyDestination
  144. ld a, [wd732]
  145. bit 3, a ; did the player decide to fly?
  146. jp nz, .goBackToMap
  147. call LoadFontTilePatterns
  148. ld hl, wd72e
  149. set 1, [hl]
  150. jp StartMenu_Pokemon
  151. .cut
  152. bit 1, a ; does the player have the Cascade Badge?
  153. jp z, .newBadgeRequired
  154. predef UsedCut
  155. ld a, [wActionResultOrTookBattleTurn]
  156. and a
  157. jp z, .loop
  158. jp CloseTextDisplay
  159. .surf
  160. bit 4, a ; does the player have the Soul Badge?
  161. jp z, .newBadgeRequired
  162. callba IsSurfingAllowed
  163. ld hl, wd728
  164. bit 1, [hl]
  165. res 1, [hl]
  166. jp z, .loop
  167. ld a, SURFBOARD
  168. ld [wcf91], a
  169. ld [wPseudoItemID], a
  170. call UseItem
  171. ld a, [wActionResultOrTookBattleTurn]
  172. and a
  173. jp z, .loop
  174. call GBPalWhiteOutWithDelay3
  175. jp .goBackToMap
  176. .strength
  177. bit 3, a ; does the player have the Rainbow Badge?
  178. jp z, .newBadgeRequired
  179. predef PrintStrengthTxt
  180. call GBPalWhiteOutWithDelay3
  181. jp .goBackToMap
  182. .flash
  183. bit 0, a ; does the player have the Boulder Badge?
  184. jp z, .newBadgeRequired
  185. xor a
  186. ld [wMapPalOffset], a
  187. ld hl, .flashLightsAreaText
  188. call PrintText
  189. call GBPalWhiteOutWithDelay3
  190. jp .goBackToMap
  191. .flashLightsAreaText
  192. TX_FAR _FlashLightsAreaText
  193. db "@"
  194. .dig
  195. ld a, ESCAPE_ROPE
  196. ld [wcf91], a
  197. ld [wPseudoItemID], a
  198. call UseItem
  199. ld a, [wActionResultOrTookBattleTurn]
  200. and a
  201. jp z, .loop
  202. call GBPalWhiteOutWithDelay3
  203. jp .goBackToMap
  204. .teleport
  205. call CheckIfInOutsideMap
  206. jr z, .canTeleport
  207. ld a, [wWhichPokemon]
  208. ld hl, wPartyMonNicks
  209. call GetPartyMonName
  210. ld hl, .cannotUseTeleportNowText
  211. call PrintText
  212. jp .loop
  213. .canTeleport
  214. ld hl, .warpToLastPokemonCenterText
  215. call PrintText
  216. ld hl, wd732
  217. set 3, [hl]
  218. set 6, [hl]
  219. ld hl, wd72e
  220. set 1, [hl]
  221. res 4, [hl]
  222. ld c, 60
  223. call DelayFrames
  224. call GBPalWhiteOutWithDelay3
  225. jp .goBackToMap
  226. .warpToLastPokemonCenterText
  227. TX_FAR _WarpToLastPokemonCenterText
  228. db "@"
  229. .cannotUseTeleportNowText
  230. TX_FAR _CannotUseTeleportNowText
  231. db "@"
  232. .cannotFlyHereText
  233. TX_FAR _CannotFlyHereText
  234. db "@"
  235. .softboiled
  236. ld hl, wPartyMon1MaxHP
  237. ld a, [wWhichPokemon]
  238. ld bc, wPartyMon2 - wPartyMon1
  239. call AddNTimes
  240. ld a, [hli]
  241. ld [H_DIVIDEND], a
  242. ld a, [hl]
  243. ld [H_DIVIDEND + 1], a
  244. ld a, 5
  245. ld [H_DIVISOR], a
  246. ld b, 2 ; number of bytes
  247. call Divide
  248. ld bc, wPartyMon1HP - wPartyMon1MaxHP
  249. add hl, bc
  250. ld a, [hld]
  251. ld b, a
  252. ld a, [H_QUOTIENT + 3]
  253. sub b
  254. ld b, [hl]
  255. ld a, [H_QUOTIENT + 2]
  256. sbc b
  257. jp nc, .notHealthyEnough
  258. ld a, [wPartyAndBillsPCSavedMenuItem]
  259. push af
  260. ld a, POTION
  261. ld [wcf91], a
  262. ld [wPseudoItemID], a
  263. call UseItem
  264. pop af
  265. ld [wPartyAndBillsPCSavedMenuItem], a
  266. jp .loop
  267. .notHealthyEnough ; if current HP is less than 1/5 of max HP
  268. ld hl, .notHealthyEnoughText
  269. call PrintText
  270. jp .loop
  271. .notHealthyEnoughText
  272. TX_FAR _NotHealthyEnoughText
  273. db "@"
  274. .goBackToMap
  275. call RestoreScreenTilesAndReloadTilePatterns
  276. jp CloseTextDisplay
  277. .newBadgeRequired
  278. ld hl, .newBadgeRequiredText
  279. call PrintText
  280. jp .loop
  281. .newBadgeRequiredText
  282. TX_FAR _NewBadgeRequiredText
  283. db "@"
  284. ; writes a blank tile to all possible menu cursor positions on the party menu
  285. ErasePartyMenuCursors:
  286. coord hl, 0, 1
  287. ld bc, 2 * 20 ; menu cursor positions are 2 rows apart
  288. ld a, 6 ; 6 menu cursor positions
  289. .loop
  290. ld [hl], " "
  291. add hl, bc
  292. dec a
  293. jr nz, .loop
  294. ret
  295. ItemMenuLoop:
  296. call LoadScreenTilesFromBuffer2DisableBGTransfer ; restore saved screen
  297. call RunDefaultPaletteCommand
  298. StartMenu_Item:
  299. ld a, [wLinkState]
  300. dec a ; is the player in the Colosseum or Trade Centre?
  301. jr nz, .notInCableClubRoom
  302. ld hl, CannotUseItemsHereText
  303. call PrintText
  304. jr .exitMenu
  305. .notInCableClubRoom
  306. ld bc, wNumBagItems
  307. ld hl, wListPointer
  308. ld a, c
  309. ld [hli], a
  310. ld [hl], b ; store item bag pointer in wListPointer (for DisplayListMenuID)
  311. xor a
  312. ld [wPrintItemPrices], a
  313. ld a, ITEMLISTMENU
  314. ld [wListMenuID], a
  315. ld a, [wBagSavedMenuItem]
  316. ld [wCurrentMenuItem], a
  317. call DisplayListMenuID
  318. ld a, [wCurrentMenuItem]
  319. ld [wBagSavedMenuItem], a
  320. jr nc, .choseItem
  321. .exitMenu
  322. call LoadScreenTilesFromBuffer2 ; restore saved screen
  323. call LoadTextBoxTilePatterns
  324. call UpdateSprites
  325. jp RedisplayStartMenu
  326. .choseItem
  327. ; erase menu cursor (blank each tile in front of an item name)
  328. ld a, " "
  329. Coorda 5, 4
  330. Coorda 5, 6
  331. Coorda 5, 8
  332. Coorda 5, 10
  333. call PlaceUnfilledArrowMenuCursor
  334. xor a
  335. ld [wMenuItemToSwap], a
  336. ld a, [wcf91]
  337. cp BICYCLE
  338. jp z, .useOrTossItem
  339. .notBicycle1
  340. ld a, USE_TOSS_MENU_TEMPLATE
  341. ld [wTextBoxID], a
  342. call DisplayTextBoxID
  343. ld hl, wTopMenuItemY
  344. ld a, 11
  345. ld [hli], a ; top menu item Y
  346. ld a, 14
  347. ld [hli], a ; top menu item X
  348. xor a
  349. ld [hli], a ; current menu item ID
  350. inc hl
  351. inc a ; a = 1
  352. ld [hli], a ; max menu item ID
  353. ld a, A_BUTTON | B_BUTTON
  354. ld [hli], a ; menu watched keys
  355. xor a
  356. ld [hl], a ; old menu item id
  357. call HandleMenuInput
  358. call PlaceUnfilledArrowMenuCursor
  359. bit 1, a ; was the B button pressed?
  360. jr z, .useOrTossItem
  361. jp ItemMenuLoop
  362. .useOrTossItem ; if the player made the choice to use or toss the item
  363. ld a, [wcf91]
  364. ld [wd11e], a
  365. call GetItemName
  366. call CopyStringToCF4B ; copy name to wcf4b
  367. ld a, [wcf91]
  368. cp BICYCLE
  369. jr nz, .notBicycle2
  370. ld a, [wd732]
  371. bit 5, a
  372. jr z, .useItem_closeMenu
  373. ld hl, CannotGetOffHereText
  374. call PrintText
  375. jp ItemMenuLoop
  376. .notBicycle2
  377. ld a, [wCurrentMenuItem]
  378. and a
  379. jr nz, .tossItem
  380. ; use item
  381. ld [wPseudoItemID], a ; a must be 0 due to above conditional jump
  382. ld a, [wcf91]
  383. cp HM_01
  384. jr nc, .useItem_partyMenu
  385. ld hl, UsableItems_CloseMenu
  386. ld de, 1
  387. call IsInArray
  388. jr c, .useItem_closeMenu
  389. ld a, [wcf91]
  390. ld hl, UsableItems_PartyMenu
  391. ld de, 1
  392. call IsInArray
  393. jr c, .useItem_partyMenu
  394. call UseItem
  395. jp ItemMenuLoop
  396. .useItem_closeMenu
  397. xor a
  398. ld [wPseudoItemID], a
  399. call UseItem
  400. ld a, [wActionResultOrTookBattleTurn]
  401. and a
  402. jp z, ItemMenuLoop
  403. jp CloseStartMenu
  404. .useItem_partyMenu
  405. ld a, [wUpdateSpritesEnabled]
  406. push af
  407. call UseItem
  408. ld a, [wActionResultOrTookBattleTurn]
  409. cp $02
  410. jp z, .partyMenuNotDisplayed
  411. call GBPalWhiteOutWithDelay3
  412. call RestoreScreenTilesAndReloadTilePatterns
  413. pop af
  414. ld [wUpdateSpritesEnabled], a
  415. jp StartMenu_Item
  416. .partyMenuNotDisplayed
  417. pop af
  418. ld [wUpdateSpritesEnabled], a
  419. jp ItemMenuLoop
  420. .tossItem
  421. call IsKeyItem
  422. ld a, [wIsKeyItem]
  423. and a
  424. jr nz, .skipAskingQuantity
  425. ld a, [wcf91]
  426. call IsItemHM
  427. jr c, .skipAskingQuantity
  428. call DisplayChooseQuantityMenu
  429. inc a
  430. jr z, .tossZeroItems
  431. .skipAskingQuantity
  432. ld hl, wNumBagItems
  433. call TossItem
  434. .tossZeroItems
  435. jp ItemMenuLoop
  436. CannotUseItemsHereText:
  437. TX_FAR _CannotUseItemsHereText
  438. db "@"
  439. CannotGetOffHereText:
  440. TX_FAR _CannotGetOffHereText
  441. db "@"
  442. ; items which bring up the party menu when used
  443. UsableItems_PartyMenu:
  444. db MOON_STONE
  445. db ANTIDOTE
  446. db BURN_HEAL
  447. db ICE_HEAL
  448. db AWAKENING
  449. db PARLYZ_HEAL
  450. db FULL_RESTORE
  451. db MAX_POTION
  452. db HYPER_POTION
  453. db SUPER_POTION
  454. db POTION
  455. db FIRE_STONE
  456. db THUNDER_STONE
  457. db WATER_STONE
  458. db HP_UP
  459. db PROTEIN
  460. db IRON
  461. db CARBOS
  462. db CALCIUM
  463. db RARE_CANDY
  464. db LEAF_STONE
  465. db FULL_HEAL
  466. db REVIVE
  467. db MAX_REVIVE
  468. db FRESH_WATER
  469. db SODA_POP
  470. db LEMONADE
  471. db X_ATTACK
  472. db X_DEFEND
  473. db X_SPEED
  474. db X_SPECIAL
  475. db PP_UP
  476. db ETHER
  477. db MAX_ETHER
  478. db ELIXER
  479. db MAX_ELIXER
  480. db $ff
  481. ; items which close the item menu when used
  482. UsableItems_CloseMenu:
  483. db ESCAPE_ROPE
  484. db ITEMFINDER
  485. db POKE_FLUTE
  486. db OLD_ROD
  487. db GOOD_ROD
  488. db SUPER_ROD
  489. db $ff
  490. StartMenu_TrainerInfo:
  491. call GBPalWhiteOut
  492. call ClearScreen
  493. call UpdateSprites
  494. ld a, [hTilesetType]
  495. push af
  496. xor a
  497. ld [hTilesetType], a
  498. call DrawTrainerInfo
  499. predef DrawBadges ; draw badges
  500. ld b, SET_PAL_TRAINER_CARD
  501. call RunPaletteCommand
  502. call GBPalNormal
  503. call WaitForTextScrollButtonPress ; wait for button press
  504. call GBPalWhiteOut
  505. call LoadFontTilePatterns
  506. call LoadScreenTilesFromBuffer2 ; restore saved screen
  507. call RunDefaultPaletteCommand
  508. call ReloadMapData
  509. call LoadGBPal
  510. pop af
  511. ld [hTilesetType], a
  512. jp RedisplayStartMenu
  513. ; loads tile patterns and draws everything except for gym leader faces / badges
  514. DrawTrainerInfo:
  515. ld de, RedPicFront
  516. lb bc, BANK(RedPicFront), $01
  517. predef DisplayPicCenteredOrUpperRight
  518. call DisableLCD
  519. coord hl, 0, 2
  520. ld a, " "
  521. call TrainerInfo_DrawVerticalLine
  522. coord hl, 1, 2
  523. call TrainerInfo_DrawVerticalLine
  524. ld hl, vChars2 + $70
  525. ld de, vChars2
  526. ld bc, $70 * 4
  527. call CopyData
  528. ld hl, TrainerInfoTextBoxTileGraphics ; trainer info text box tile patterns
  529. ld de, vChars2 + $770
  530. ld bc, $0080
  531. push bc
  532. call TrainerInfo_FarCopyData
  533. ld hl, BlankLeaderNames
  534. ld de, vChars2 + $600
  535. ld bc, $0170
  536. call TrainerInfo_FarCopyData
  537. pop bc
  538. ld hl, BadgeNumbersTileGraphics ; badge number tile patterns
  539. ld de, vChars1 + $580
  540. call TrainerInfo_FarCopyData
  541. ld hl, GymLeaderFaceAndBadgeTileGraphics ; gym leader face and badge tile patterns
  542. ld de, vChars2 + $200
  543. ld bc, $0400
  544. ld a, $03
  545. call FarCopyData2
  546. ld hl, TextBoxGraphics
  547. ld de, $00d0
  548. add hl, de ; hl = colon tile pattern
  549. ld de, vChars1 + $560
  550. ld bc, $0010
  551. ld a, $04
  552. push bc
  553. call FarCopyData2
  554. pop bc
  555. ld hl, TrainerInfoTextBoxTileGraphics + $80 ; background tile pattern
  556. ld de, vChars1 + $570
  557. call TrainerInfo_FarCopyData
  558. call EnableLCD
  559. ld hl, wTrainerInfoTextBoxWidthPlus1
  560. ld a, 18 + 1
  561. ld [hli], a
  562. dec a
  563. ld [hli], a
  564. ld [hl], 1
  565. coord hl, 0, 0
  566. call TrainerInfo_DrawTextBox
  567. ld hl, wTrainerInfoTextBoxWidthPlus1
  568. ld a, 16 + 1
  569. ld [hli], a
  570. dec a
  571. ld [hli], a
  572. ld [hl], 3
  573. coord hl, 1, 10
  574. call TrainerInfo_DrawTextBox
  575. coord hl, 0, 10
  576. ld a, $d7
  577. call TrainerInfo_DrawVerticalLine
  578. coord hl, 19, 10
  579. call TrainerInfo_DrawVerticalLine
  580. coord hl, 6, 9
  581. ld de, TrainerInfo_BadgesText
  582. call PlaceString
  583. coord hl, 2, 2
  584. ld de, TrainerInfo_NameMoneyTimeText
  585. call PlaceString
  586. coord hl, 7, 2
  587. ld de, wPlayerName
  588. call PlaceString
  589. coord hl, 8, 4
  590. ld de, wPlayerMoney
  591. ld c, $e3
  592. call PrintBCDNumber
  593. coord hl, 9, 6
  594. ld de, wPlayTimeHours ; hours
  595. lb bc, LEFT_ALIGN | 1, 3
  596. call PrintNumber
  597. ld [hl], $d6 ; colon tile ID
  598. inc hl
  599. ld de, wPlayTimeMinutes ; minutes
  600. lb bc, LEADING_ZEROES | 1, 2
  601. jp PrintNumber
  602. TrainerInfo_FarCopyData:
  603. ld a, BANK(TrainerInfoTextBoxTileGraphics)
  604. jp FarCopyData2
  605. TrainerInfo_NameMoneyTimeText:
  606. db "NAME/"
  607. next "MONEY/"
  608. next "TIME/@"
  609. ; $76 is a circle tile
  610. TrainerInfo_BadgesText:
  611. db $76,"BADGES",$76,"@"
  612. ; draws a text box on the trainer info screen
  613. ; height is always 6
  614. ; INPUT:
  615. ; hl = destination address
  616. ; [wTrainerInfoTextBoxWidthPlus1] = width
  617. ; [wTrainerInfoTextBoxWidth] = width - 1
  618. ; [wTrainerInfoTextBoxNextRowOffset] = distance from the end of a text box row to the start of the next
  619. TrainerInfo_DrawTextBox:
  620. ld a, $79 ; upper left corner tile ID
  621. lb de, $7a, $7b ; top edge and upper right corner tile ID's
  622. call TrainerInfo_DrawHorizontalEdge ; draw top edge
  623. call TrainerInfo_NextTextBoxRow
  624. ld a, [wTrainerInfoTextBoxWidthPlus1]
  625. ld e, a
  626. ld d, 0
  627. ld c, 6 ; height of the text box
  628. .loop
  629. ld [hl], $7c ; left edge tile ID
  630. add hl, de
  631. ld [hl], $78 ; right edge tile ID
  632. call TrainerInfo_NextTextBoxRow
  633. dec c
  634. jr nz, .loop
  635. ld a, $7d ; lower left corner tile ID
  636. lb de, $77, $7e ; bottom edge and lower right corner tile ID's
  637. TrainerInfo_DrawHorizontalEdge:
  638. ld [hli], a ; place left corner tile
  639. ld a, [wTrainerInfoTextBoxWidth]
  640. ld c, a
  641. ld a, d
  642. .loop
  643. ld [hli], a ; place edge tile
  644. dec c
  645. jr nz, .loop
  646. ld a, e
  647. ld [hl], a ; place right corner tile
  648. ret
  649. TrainerInfo_NextTextBoxRow:
  650. ld a, [wTrainerInfoTextBoxNextRowOffset] ; distance to the start of the next row
  651. .loop
  652. inc hl
  653. dec a
  654. jr nz, .loop
  655. ret
  656. ; draws a vertical line
  657. ; INPUT:
  658. ; hl = address of top tile in the line
  659. ; a = tile ID
  660. TrainerInfo_DrawVerticalLine:
  661. ld de, SCREEN_WIDTH
  662. ld c, 8
  663. .loop
  664. ld [hl], a
  665. add hl, de
  666. dec c
  667. jr nz, .loop
  668. ret
  669. StartMenu_SaveReset:
  670. ld a, [wd72e]
  671. bit 6, a ; is the player using the link feature?
  672. jp nz, Init
  673. predef SaveSAV ; save the game
  674. call LoadScreenTilesFromBuffer2 ; restore saved screen
  675. jp HoldTextDisplayOpen
  676. StartMenu_Option:
  677. xor a
  678. ld [H_AUTOBGTRANSFERENABLED], a
  679. call ClearScreen
  680. call UpdateSprites
  681. callab DisplayOptionMenu
  682. call LoadScreenTilesFromBuffer2 ; restore saved screen
  683. call LoadTextBoxTilePatterns
  684. call UpdateSprites
  685. jp RedisplayStartMenu
  686. SwitchPartyMon:
  687. call SwitchPartyMon_InitVarOrSwapData ; swap data
  688. ld a, [wSwappedMenuItem]
  689. call SwitchPartyMon_ClearGfx
  690. ld a, [wCurrentMenuItem]
  691. call SwitchPartyMon_ClearGfx
  692. jp RedrawPartyMenu_
  693. SwitchPartyMon_ClearGfx:
  694. push af
  695. coord hl, 0, 0
  696. ld bc, SCREEN_WIDTH * 2
  697. call AddNTimes
  698. ld c, SCREEN_WIDTH * 2
  699. ld a, " "
  700. .clearMonBGLoop ; clear the mon's row in the party menu
  701. ld [hli], a
  702. dec c
  703. jr nz, .clearMonBGLoop
  704. pop af
  705. ld hl, wOAMBuffer
  706. ld bc, $10
  707. call AddNTimes
  708. ld de, $4
  709. ld c, e
  710. .clearMonOAMLoop
  711. ld [hl], $a0
  712. add hl, de
  713. dec c
  714. jr nz, .clearMonOAMLoop
  715. call WaitForSoundToFinish
  716. ld a, SFX_SWAP
  717. jp PlaySound
  718. SwitchPartyMon_InitVarOrSwapData:
  719. ; This is used to initialise [wMenuItemToSwap] and to actually swap the data.
  720. ld a, [wMenuItemToSwap]
  721. and a ; has [wMenuItemToSwap] been initialised yet?
  722. jr nz, .pickedMonsToSwap
  723. ; If not, initialise [wMenuItemToSwap] so that it matches the current mon.
  724. ld a, [wWhichPokemon]
  725. inc a ; [wMenuItemToSwap] counts from 1
  726. ld [wMenuItemToSwap], a
  727. ret
  728. .pickedMonsToSwap
  729. xor a
  730. ld [wPartyMenuTypeOrMessageID], a
  731. ld a, [wMenuItemToSwap]
  732. dec a
  733. ld b, a
  734. ld a, [wCurrentMenuItem]
  735. ld [wSwappedMenuItem], a
  736. cp b ; swapping a mon with itself?
  737. jr nz, .swappingDifferentMons
  738. ; can't swap a mon with itself
  739. xor a
  740. ld [wMenuItemToSwap], a
  741. ld [wPartyMenuTypeOrMessageID], a
  742. ret
  743. .swappingDifferentMons
  744. ld a, b
  745. ld [wMenuItemToSwap], a
  746. push hl
  747. push de
  748. ld hl, wPartySpecies
  749. ld d, h
  750. ld e, l
  751. ld a, [wCurrentMenuItem]
  752. add l
  753. ld l, a
  754. jr nc, .noCarry
  755. inc h
  756. .noCarry
  757. ld a, [wMenuItemToSwap]
  758. add e
  759. ld e, a
  760. jr nc, .noCarry2
  761. inc d
  762. .noCarry2
  763. ld a, [hl]
  764. ld [hSwapTemp], a
  765. ld a, [de]
  766. ld [hl], a
  767. ld a, [hSwapTemp]
  768. ld [de], a
  769. ld hl, wPartyMons
  770. ld bc, wPartyMon2 - wPartyMon1
  771. ld a, [wCurrentMenuItem]
  772. call AddNTimes
  773. push hl
  774. ld de, wSwitchPartyMonTempBuffer
  775. ld bc, wPartyMon2 - wPartyMon1
  776. call CopyData
  777. ld hl, wPartyMons
  778. ld bc, wPartyMon2 - wPartyMon1
  779. ld a, [wMenuItemToSwap]
  780. call AddNTimes
  781. pop de
  782. push hl
  783. ld bc, wPartyMon2 - wPartyMon1
  784. call CopyData
  785. pop de
  786. ld hl, wSwitchPartyMonTempBuffer
  787. ld bc, wPartyMon2 - wPartyMon1
  788. call CopyData
  789. ld hl, wPartyMonOT
  790. ld a, [wCurrentMenuItem]
  791. call SkipFixedLengthTextEntries
  792. push hl
  793. ld de, wSwitchPartyMonTempBuffer
  794. ld bc, NAME_LENGTH
  795. call CopyData
  796. ld hl, wPartyMonOT
  797. ld a, [wMenuItemToSwap]
  798. call SkipFixedLengthTextEntries
  799. pop de
  800. push hl
  801. ld bc, NAME_LENGTH
  802. call CopyData
  803. pop de
  804. ld hl, wSwitchPartyMonTempBuffer
  805. ld bc, NAME_LENGTH
  806. call CopyData
  807. ld hl, wPartyMonNicks
  808. ld a, [wCurrentMenuItem]
  809. call SkipFixedLengthTextEntries
  810. push hl
  811. ld de, wSwitchPartyMonTempBuffer
  812. ld bc, NAME_LENGTH
  813. call CopyData
  814. ld hl, wPartyMonNicks
  815. ld a, [wMenuItemToSwap]
  816. call SkipFixedLengthTextEntries
  817. pop de
  818. push hl
  819. ld bc, NAME_LENGTH
  820. call CopyData
  821. pop de
  822. ld hl, wSwitchPartyMonTempBuffer
  823. ld bc, NAME_LENGTH
  824. call CopyData
  825. ld a, [wMenuItemToSwap]
  826. ld [wSwappedMenuItem], a
  827. xor a
  828. ld [wMenuItemToSwap], a
  829. ld [wPartyMenuTypeOrMessageID], a
  830. pop de
  831. pop hl
  832. ret