diff options
Diffstat (limited to 'home.asm')
-rw-r--r-- | home.asm | 1541 |
1 files changed, 945 insertions, 596 deletions
@@ -21,7 +21,7 @@ SECTION "rst 38", ROM0 [$38] SECTION "vblank", ROM0 [$40] jp VBlank SECTION "hblank", ROM0 [$48] - rst $38 + jp LCDC SECTION "timer", ROM0 [$50] jp Timer SECTION "serial", ROM0 [$58] @@ -87,7 +87,7 @@ INCLUDE "home/copy.asm" SECTION "Entry", ROM0 [$100] nop - jp Start + jp Start ; 01ab SECTION "Header", ROM0 [$104] @@ -101,24 +101,73 @@ SECTION "Header", ROM0 [$104] SECTION "Main", ROM0 +Func_150:: ; 0150 (0:0150) + ld a,[H_LOADEDROMBANK] + push af + ld a,b + call BankswitchCommon + ld a,[hli] + ld c,a + ld a,[hli] + ld b,a +.loop + ld a,[hli] + ld d,a + ld a,$3 +.unknownloop + dec a + jr nz,.unknownloop + + rept 7 + call Func_199 + call Func_1a5 + endr + + call Func_199 + dec bc + ld a,c + or b + jr nz,.loop + pop af + call BankswitchCommon + ret + +Func_199:: ; 0199 (0:0199) + ld a,d + and $80 + srl a + srl a + ld [rNR32],a + sla d + ret + +Func_1a5:: ; 01a5 (0:01a5) + ld a,$3 +.unknownloop2 + dec a + jr nz,.unknownloop2 + ret + Start:: cp GBC jr z, .gbc xor a jr .ok .gbc - ld a, 0 + ld a, $1 .ok - ld [wGBC], a + ld [hGBC], a jp Init +Joypad:: ; 01b9 + homecall_jump _Joypad -INCLUDE "home/joypad.asm" -INCLUDE "data/map_header_pointers.asm" +ReadJoypad:: ; 01c8 (0:01c8) + homecall_jump ReadJoypad_ + INCLUDE "home/overworld.asm" - -CheckForUserInterruption:: ; 12f8 (0:12f8) +CheckForUserInterruption:: ; 10ba (0:10ba) ; Return carry if Up+Select+B, Start or A are pressed in c frames. ; Used only in the intro and title screen. call DelayFrame @@ -148,7 +197,7 @@ CheckForUserInterruption:: ; 12f8 (0:12f8) ; function to load position data for destination warp when switching maps ; INPUT: ; a = ID of destination warp within destination map -LoadDestinationWarpPosition:: ; 1313 (0:1313) +LoadDestinationWarpPosition:: ; 10d5 (0:10d5) ld b,a ld a,[H_LOADEDROMBANK] push af @@ -170,14 +219,14 @@ LoadDestinationWarpPosition:: ; 1313 (0:1313) ret -DrawHPBar:: ; 1336 (0:1336) +DrawHPBar:: ; 10f8 (0:10f8) ; Draw an HP bar d tiles long, and fill it to e pixels. ; If c is nonzero, show at least a sliver regardless. ; The right end of the bar changes with [wHPBarType]. push hl push de - push bc + ;push bc ; Left ld a, $71 ; "HP:" @@ -233,7 +282,7 @@ DrawHPBar:: ; 1336 (0:1336) add e ld [hl], a .done - pop bc + ;pop bc pop de pop hl ret @@ -251,12 +300,11 @@ DrawHPBar:: ; 1336 (0:1336) ; OUTPUT: ; [wcf91] = pokemon ID ; wLoadedMon = base address of pokemon data -; W_MONHEADER = base address of base stats -LoadMonData:: ; 1372 (0:1372) +; W_MONHDEXNUM = base address of base stats +LoadMonData:: ; 1132 (0:1132) jpab LoadMonData_ - -OverwritewMoves:: ; 137a (0:137a) +OverwritewMoves:: ; 113a (0:113a) ; Write c to [wMoves + b]. Unused. ld hl, wMoves ld e, b @@ -266,11 +314,11 @@ OverwritewMoves:: ; 137a (0:137a) ld [hl], a ret -LoadFlippedFrontSpriteByMonIndex:: ; 1384 (0:1384) +LoadFlippedFrontSpriteByMonIndex:: ; 1144 (0:1144) ld a, 1 ld [W_SPRITEFLIPPED], a -LoadFrontSpriteByMonIndex:: ; 1389 (0:1389) +LoadFrontSpriteByMonIndex:: ; 1149 (0:1149) push hl ld a, [wd11e] push af @@ -297,27 +345,33 @@ LoadFrontSpriteByMonIndex:: ; 1389 (0:1389) pop hl ld a, [H_LOADEDROMBANK] push af - ld a, Bank(CopyUncompressedPicToHL) - ld [H_LOADEDROMBANK], a - ld [MBC1RomBank], a + switchbank CopyUncompressedPicToHL xor a ld [hStartTileID], a call CopyUncompressedPicToHL xor a ld [W_SPRITEFLIPPED], a pop af - ld [H_LOADEDROMBANK], a - ld [MBC1RomBank], a - ret - + jp BankswitchCommon -PlayCry:: ; 13d0 (0:13d0) +PlayCry:: ; 118b (0:118b) ; Play monster a's cry. + push bc + ld b,a + ld a,[wLowHealthAlarm] + push af + xor a + ld [wLowHealthAlarm],a + ld a,b call GetCryData call PlaySound - jp WaitForSoundToFinish + call WaitForSoundToFinish + pop af + ld [wLowHealthAlarm],a + pop bc + ret -GetCryData:: ; 13d9 (0:13d9) +GetCryData:: ; 11a5 (0:11a5) ; Load cry data for monster a. dec a ld c, a @@ -327,7 +381,7 @@ GetCryData:: ; 13d9 (0:13d9) add hl, bc add hl, bc - ld a, Bank(CryData) + ld a, BANK(CryData) call BankswitchHome ld a, [hli] ld b, a ; cry id @@ -347,8 +401,7 @@ GetCryData:: ; 13d9 (0:13d9) add c ret - -DisplayPartyMenu:: ; 13fc (0:13fc) +DisplayPartyMenu:: ; 11c8 (0:11c8) ld a,[hTilesetType] push af xor a @@ -358,8 +411,8 @@ DisplayPartyMenu:: ; 13fc (0:13fc) call PartyMenuInit call DrawPartyMenu jp HandlePartyMenuInput - -GoBackToPartyMenu:: ; 1411 (0:1411) + +GoBackToPartyMenu:: ; 11dd (0:11dd) ld a,[hTilesetType] push af xor a @@ -368,7 +421,7 @@ GoBackToPartyMenu:: ; 1411 (0:1411) call RedrawPartyMenu jp HandlePartyMenuInput -PartyMenuInit:: ; 1420 (0:1420) +PartyMenuInit:: ; 11ec (0:11ec) ld a, 1 ; hardcoded bank call BankswitchHome call LoadHpBarAndStatusTilePatterns @@ -407,24 +460,35 @@ PartyMenuInit:: ; 1420 (0:1420) ld [hl], a ; old menu item ID ret -HandlePartyMenuInput:: ; 145a (0:145a) +HandlePartyMenuInput:: ; 1226 (0:1226) ld a,1 ld [wMenuWrappingEnabled],a ld a,$40 ld [wPartyMenuAnimMonEnabled],a - call HandleMenuInput_ - call PlaceUnfilledArrowMenuCursor - ld b,a - xor a + call HandleMenuInputPokemonSelection + push af ; save hJoy5 OR wMenuWrapping enabled, if no inputs were selected within a certain period of time + bit 1,a ; was B button pressed? + ld a,$0 ld [wPartyMenuAnimMonEnabled],a ld a,[wCurrentMenuItem] ld [wPartyAndBillsPCSavedMenuItem],a + jr nz,.asm_1258 + ld a,[wCurrentMenuItem] + ld [wWhichPokemon],a + callab Func_fce18 ; 3f:4e18 + jr nc,.asm_1258 + call Func_154a + jr nz,.asm_128f +.asm_1258 + pop af + call PlaceUnfilledArrowMenuCursor + ld b,a ld hl,wd730 res 6,[hl] ; turn on letter printing delay ld a,[wMenuItemToSwap] and a jp nz,.swappingPokemon - pop af + pop af ; double pop af? ld [hTilesetType],a bit 1,b jr nz,.noPokemonChosen @@ -443,6 +507,14 @@ HandlePartyMenuInput:: ; 145a (0:145a) call BankswitchBack and a ret +.asm_128f + pop af + ld hl,PartyMenuText_12cc + call PrintText + xor a + ld [wMenuItemToSwap],a + pop af + ld [hTilesetType],a .noPokemonChosen call BankswitchBack scf @@ -451,26 +523,30 @@ HandlePartyMenuInput:: ; 145a (0:145a) bit 1,b ; was the B button pressed? jr z,.handleSwap ; if not, handle swapping the pokemon .cancelSwap ; if the B button was pressed - callba ErasePartyMenuCursors + callba ErasePartyMenuCursors ; 4:5e98 xor a ld [wMenuItemToSwap],a ld [wPartyMenuTypeOrMessageID],a call RedrawPartyMenu - jr HandlePartyMenuInput + jp HandlePartyMenuInput .handleSwap ld a,[wCurrentMenuItem] ld [wWhichPokemon],a - callba SwitchPartyMon - jr HandlePartyMenuInput + callba SwitchPartyMon ; 4:61c5 + jp HandlePartyMenuInput -DrawPartyMenu:: ; 14d4 (0:14d4) - ld hl, DrawPartyMenu_ +PartyMenuText_12cc:: ; 12cc (0:12cc) + TX_FAR _SleepingPikachuText1 ; 28:411b + db "@" + +DrawPartyMenu:: ; 12d1 (0:12d1) + ld hl, DrawPartyMenu_ ; 4:5875 jr DrawPartyMenuCommon -RedrawPartyMenu:: ; 14d9 (0:14d9) - ld hl, RedrawPartyMenu_ +RedrawPartyMenu:: ; 12d6 (0:12d6) + ld hl, RedrawPartyMenu_ ; 4:5886 -DrawPartyMenuCommon:: ; 14dc (0:14dc) +DrawPartyMenuCommon:: ; 12d9 (0:12d9) ld b, BANK(RedrawPartyMenu_) jp Bankswitch @@ -478,7 +554,7 @@ DrawPartyMenuCommon:: ; 14dc (0:14dc) ; INPUT: ; de = address of status condition ; hl = destination address -PrintStatusCondition:: ; 14e1 (0:14e1) +PrintStatusCondition:: ; 12de (0:12de) push de dec de dec de ; de = address of current HP @@ -497,24 +573,15 @@ PrintStatusCondition:: ; 14e1 (0:14e1) ld [hl],"T" and a ret -PrintStatusConditionNotFainted: ; 14f6 - ld a,[H_LOADEDROMBANK] - push af - ld a,BANK(PrintStatusAilment) - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a - call PrintStatusAilment ; print status condition - pop bc - ld a,b - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a - ret + +PrintStatusConditionNotFainted: ; 12f3 (0:12f3) + homecall_jump_sf PrintStatusAilment ; function to print pokemon level, leaving off the ":L" if the level is at least 100 ; INPUT: ; hl = destination address ; [wLoadedMonLevel] = level -PrintLevel:: ; 150b (0:150b) +PrintLevel:: ; 1303 (0:1303) ld a,$6e ; ":L" tile ID ld [hli],a ld c,2 ; number of digits @@ -530,19 +597,19 @@ PrintLevel:: ; 150b (0:150b) ; INPUT: ; hl = destination address ; [wLoadedMonLevel] = level -PrintLevelFull:: ; 151b (0:151b) +PrintLevelFull:: ; 1313 (0:1313) ld a,$6e ; ":L" tile ID ld [hli],a ld c,3 ; number of digits ld a,[wLoadedMonLevel] ; level -PrintLevelCommon:: ; 1523 (0:1523) +PrintLevelCommon:: ; 131b (0:131b) ld [wd11e],a ld de,wd11e ld b,LEFT_ALIGN | 1 ; 1 byte jp PrintNumber -GetwMoves:: ; 152e (0:152e) +GetwMoves:: ; 1326 (0:1326) ; Unused. Returns the move at index a from wMoves in a ld hl,wMoves ld c,a @@ -554,12 +621,10 @@ GetwMoves:: ; 152e (0:152e) ; copies the base stat data of a pokemon to W_MONHEADER ; INPUT: ; [wd0b5] = pokemon ID -GetMonHeader:: ; 1537 (0:1537) +GetMonHeader:: ; 132f (0:132f) ld a,[H_LOADEDROMBANK] push af - ld a,BANK(BaseStats) - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a + switchbank BaseStats push bc push de push hl @@ -578,8 +643,8 @@ GetMonHeader:: ; 1537 (0:1537) ld b,$77 ; size of Aerodactyl fossil sprite cp a,FOSSIL_AERODACTYL ; Aerodactyl fossil jr z,.specialID - cp a,MEW - jr z,.mew + ;cp a,MEW + ;jr z,.mew predef IndexToPokedex ; convert pokemon ID in [wd11e] to pokedex number ld a,[wd11e] dec a @@ -597,13 +662,6 @@ GetMonHeader:: ; 1537 (0:1537) ld [hl],e ; write front sprite pointer inc hl ld [hl],d - jr .done -.mew - ld hl,MewBaseStats - ld de,W_MONHEADER - ld bc,MonBaseStatsEnd - MonBaseStats - ld a,BANK(MewBaseStats) - call FarCopyData .done ld a,[wd0b5] ld [W_MONHINDEX],a @@ -613,17 +671,16 @@ GetMonHeader:: ; 1537 (0:1537) pop de pop bc pop af - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a + call BankswitchCommon ret ; copy party pokemon's name to wcd6d -GetPartyMonName2:: ; 15b4 (0:15b4) +GetPartyMonName2:: ; 1394 (0:1394) ld a,[wWhichPokemon] ; index within party ld hl,wPartyMonNicks ; this is called more often -GetPartyMonName:: ; 15ba (0:15ba) +GetPartyMonName:: ; 139a (0:139a) push hl push bc call SkipFixedLengthTextEntries ; add NAME_LENGTH to hl, a times @@ -649,7 +706,7 @@ GetPartyMonName:: ; 15ba (0:15ba) ; bits 0-4: length of BCD number in bytes ; Note that bits 5 and 7 are modified during execution. The above reflects ; their meaning at the beginning of the functions's execution. -PrintBCDNumber:: ; 15cd (0:15cd) +PrintBCDNumber:: ; 13ad (0:13ad) ld b,c ; save flags in b res 7,c res 6,c @@ -658,7 +715,7 @@ PrintBCDNumber:: ; 15cd (0:15cd) jr z,.loop bit 7,b jr nz,.loop - ld [hl],"¥" + ld [hl], "¥" inc hl .loop ld a,[de] @@ -678,7 +735,7 @@ PrintBCDNumber:: ; 15cd (0:15cd) .skipRightAlignmentAdjustment bit 5,b jr z,.skipCurrencySymbol - ld [hl],"¥" + ld [hl], "¥" inc hl .skipCurrencySymbol ld [hl],"0" @@ -687,7 +744,7 @@ PrintBCDNumber:: ; 15cd (0:15cd) .done ret -PrintBCDDigit:: ; 1604 (0:1604) +PrintBCDDigit:: ; 13e4 (0:13e4) and $f and a jr z,.zeroDigit @@ -697,7 +754,7 @@ PrintBCDDigit:: ; 1604 (0:1604) ; if bit 7 is set, then no numbers have been printed yet bit 5,b ; print the currency symbol? jr z,.skipCurrencySymbol - ld [hl],"¥" + ld [hl], "¥" inc hl res 5,b .skipCurrencySymbol @@ -717,7 +774,7 @@ PrintBCDDigit:: ; 1604 (0:1604) ; uncompresses the front or back sprite of the specified mon ; assumes the corresponding mon header is already loaded ; hl contains offset to sprite pointer ($b for front or $d for back) -UncompressMonSprite:: ; 1627 (0:1627) +UncompressMonSprite:: ; 1407 (0:1407) ld bc,W_MONHEADER add hl,bc ld a,[hli] @@ -734,10 +791,10 @@ UncompressMonSprite:: ; 1627 (0:1627) ; $99 ≤ index, bank $D ld a,[wcf91] ; XXX name for this ram location ld b,a - cp MEW - ld a,BANK(MewPicFront) - jr z,.GotBank - ld a,b + ;cp MEW + ;ld a,BANK(MewPicFront) + ;jr z,.GotBank + ;ld a,b cp FOSSIL_KABUTOPS ld a,BANK(FossilKabutopsPic) jr z,.GotBank @@ -759,10 +816,10 @@ UncompressMonSprite:: ; 1627 (0:1627) jr c,.GotBank ld a,BANK(VictreebelPicFront) .GotBank - jp UncompressSpriteData + jp UncompressSpriteData ; 23f8 ; de: destination location -LoadMonFrontSprite:: ; 1665 (0:1665) +LoadMonFrontSprite:: ; 143e (0:143e) push de ld hl, W_MONHFRONTSPRITE - W_MONHEADER call UncompressMonSprite @@ -808,8 +865,8 @@ LoadUncompressedSpriteData:: ; 1672 (0:1672) add a add a ; 8*(7*((8-w)/2) + 7-h) ; combined overall offset (in bytes) ld [H_SPRITEOFFSET], a - xor a - ld [$4000], a + ld a,$0 + call SwitchSRAMBankAndLatchClockData ld hl, S_SPRITEBUFFER0 call ZeroSpriteBuffer ; zero buffer 0 ld de, S_SPRITEBUFFER1 @@ -820,12 +877,13 @@ LoadUncompressedSpriteData:: ; 1672 (0:1672) ld de, S_SPRITEBUFFER2 ld hl, S_SPRITEBUFFER1 call AlignSpriteDataCentered ; copy and align buffer 2 to 1 (containing the LSB of the 2bpp sprite) + call PrepareRTCDataAndDisableSRAM pop de - jp InterlaceMergeSpriteBuffers + jp InterlaceMergeSpriteBuffers ; 14c7 ; copies and aligns the sprite data properly inside the sprite buffer ; sprite buffers are 7*7 tiles in size, the loaded sprite is centered within this area -AlignSpriteDataCentered:: ; 16c2 (0:16c2) +AlignSpriteDataCentered:: ; 149f (0:149f) ld a, [H_SPRITEOFFSET] ld b, $0 ld c, a @@ -851,7 +909,7 @@ AlignSpriteDataCentered:: ; 16c2 (0:16c2) ret ; fills the sprite buffer (pointed to in hl) with zeros -ZeroSpriteBuffer:: ; 16df (0:16df) +ZeroSpriteBuffer:: ; 14bc (0:14bc) ld bc, SPRITEBUFFERSIZE .nextByteLoop xor a @@ -865,9 +923,9 @@ ZeroSpriteBuffer:: ; 16df (0:16df) ; combines the (7*7 tiles, 1bpp) sprite chunks in buffer 0 and 1 into a 2bpp sprite located in buffer 1 through 2 ; in the resulting sprite, the rows of the two source sprites are interlaced ; de: output address -InterlaceMergeSpriteBuffers:: ; 16ea (0:16ea) - xor a - ld [$4000], a +InterlaceMergeSpriteBuffers:: ; 14c7 (0:14c7) + ld a,$0 + call SwitchSRAMBankAndLatchClockData push de ld hl, S_SPRITEBUFFER2 + (SPRITEBUFFERSIZE - 1) ; destination: end of buffer 2 ld de, S_SPRITEBUFFER1 + (SPRITEBUFFERSIZE - 1) ; source 2: end of buffer 1 @@ -909,66 +967,189 @@ InterlaceMergeSpriteBuffers:: ; 16ea (0:16ea) ld c, (2*SPRITEBUFFERSIZE)/16 ; $31, number of 16 byte chunks to be copied ld a, [H_LOADEDROMBANK] ld b, a - jp CopyVideoData + call CopyVideoData + jp PrepareRTCDataAndDisableSRAM + +Func_1510:: ; 1510 (0:1510) + push hl + ld hl,wd430 + set 7,[hl] + ld hl,wSpriteStateData1 + $f2 ; pikachu data? + ld [hl],$ff + pop hl + ret + +Func_151d:: ; 151d (0:151d) + push hl + ld hl,wd430 + res 7,[hl] + pop hl + ret + +Func_1525:: ; 1525 (0:1525) + push hl + ld hl,wd430 + res 3,[hl] + pop hl + ret + +Func_152d:: ; 152d (0:152d) + push hl + ld hl,wd430 + set 3,[hl] + ld hl,wSpriteStateData1 + $f2 ; pikachu data? + ld [hl],$ff + pop hl + ret + +Func_153a:: ; 153a (0:153a) + push hl + ld hl,wd430 + set 1,[hl] + pop hl + ret + +Func_1542:: ; 1542 (0:1542) + push hl + ld hl,wd430 + res 1,[hl] + pop hl + ret + +Func_154a:: ; 154a (0:154a) + push hl + ld hl,wd430 + bit 1,[hl] + pop hl + ret + +Func_1552:: ; 1552 (0:1552) + ld a,[hl] + dec a + swap a + ld [$ff93],a + homecall Func_fc6d5 ; 3f:46d5 + ret +Func_1568:: ; 1568 (0:1568) + ld b,$0 + ld c,a +.asm_156b + inc b + ld a,[hli] + cp $ff + jr z,.asm_1578 + cp c + jr nz,.asm_156b + dec b + dec hl + scf + ret +.asm_1578 + dec b + dec hl + and a + ret + +Func_157c:: ; 157c (0:157c) + push hl + push bc + ld a,[H_LOADEDROMBANK] + push af + ld a,[wd44a] + call BankswitchCommon + ld hl,wd44b + ld c,[hl] + inc hl + ld b,[hl] + ld a,[bc] + inc bc + ld [hl],b + dec hl + ld [hl],c + ld c,a + pop af + call BankswitchCommon + ld a,c + pop bc + pop hl + ret + +Func_159b:: ; 159b (0:159b) + ld a,[H_LOADEDROMBANK] + ld b,a + push af + callbs Func_fd2a1 + pop af + call BankswitchCommon + ret + +;INCLUDE "data/collision.asm" + +INCLUDE "home/lcdc.asm" + +IsTilePassable:: ; 15c3 (0:15c3) +; sets carry if tile is passable, resets carry otherwise + homecall_sf _IsTilePassable ; 1:4aaa + ret -INCLUDE "data/collision.asm" INCLUDE "home/copy2.asm" INCLUDE "home/text.asm" INCLUDE "home/vcopy.asm" INCLUDE "home/init.asm" INCLUDE "home/vblank.asm" INCLUDE "home/fade.asm" +INCLUDE "home/play_time.asm" INCLUDE "home/serial.asm" INCLUDE "home/timer.asm" INCLUDE "home/audio.asm" -UpdateSprites:: ; 2429 (0:2429) +UpdateSprites:: ; 231c (0:231c) ld a, [wUpdateSpritesEnabled] dec a ret nz ld a, [H_LOADEDROMBANK] push af - ld a, Bank(_UpdateSprites) - ld [H_LOADEDROMBANK], a - ld [MBC1RomBank], a - call _UpdateSprites + switchbank _UpdateSprites + ld a,$ff + ld [wUpdateSpritesEnabled],a + call _UpdateSprites ; 1:4bb7 + ld a,$1 + ld [wUpdateSpritesEnabled],a pop af - ld [H_LOADEDROMBANK], a - ld [MBC1RomBank], a + call BankswitchCommon ret INCLUDE "data/mart_inventories.asm" -TextScriptEndingChar:: ; 24d6 (0:24d6) +TextScriptEndingChar:: ; 23d1 (0:23d1) db "@" -TextScriptEnd:: ; 24d7 (0:24d7) +TextScriptEnd:: ; 23d2 (0:23d2) ld hl,TextScriptEndingChar ret -ExclamationText:: ; 24db (0:24db) +ExclamationText:: ; 23d6 (0:23d6) TX_FAR _ExclamationText db "@" -GroundRoseText:: ; 24e0 (0:24e0) +GroundRoseText:: ; 23db (0:23db) TX_FAR _GroundRoseText db "@" -BoulderText:: ; 24e5 (0:24e5) +BoulderText:: ; 23e0 (0:23e0) TX_FAR _BoulderText db "@" -MartSignText:: ; 24ea (0:24ea) +MartSignText:: ; 23e5 (0:23e5) TX_FAR _MartSignText db "@" -PokeCenterSignText:: ; 24ef (0:24ef) +PokeCenterSignText:: ; 23ea (0:23ea) TX_FAR _PokeCenterSignText db "@" -PickUpItemText:: ; 24f4 (0:24f4) -; XXX better label (what does predef $5C do?) +PickUpItemText:: ; 23ef (0:23ef) TX_ASM predef PickUpItem jp TextScriptEnd @@ -977,7 +1158,7 @@ PickUpItemText:: ; 24f4 (0:24f4) INCLUDE "home/pic.asm" -ResetPlayerSpriteData:: ; 28a6 (0:28a6) +ResetPlayerSpriteData:: ; 279c (0:279c) ld hl, wSpriteStateData1 call ResetPlayerSpriteData_ClearSpriteData ld hl, wSpriteStateData2 @@ -993,22 +1174,24 @@ ResetPlayerSpriteData:: ; 28a6 (0:28a6) ret ; overwrites sprite data with zeroes -ResetPlayerSpriteData_ClearSpriteData:: ; 28c4 (0:28c4) +ResetPlayerSpriteData_ClearSpriteData:: ; 27ba (0:27ba) ld bc, $10 xor a - jp FillMemory + call FillMemory ; XXX why replaced with call + ret? + ret + ;jp FillMemory -FadeOutAudio:: ; 28cb (0:28cb) +FadeOutAudio:: ; 27c2 (0:27c2) ld a, [wAudioFadeOutControl] and a - jr nz, .asm_28dc + jr nz, .asm_27d3 ld a, [wd72c] bit 1, a ret nz ld a, $77 ld [rNR50], a ret -.asm_28dc +.asm_27d3 ld a, [wAudioFadeOutCounter] and a jr z, .counterReachedZero @@ -1020,7 +1203,7 @@ FadeOutAudio:: ; 28cb (0:28cb) ld [wAudioFadeOutCounter], a ld a, [rNR50] and a - jr z, .asm_2903 + jr z, .asm_27fa ld b, a and $f dec a @@ -1033,23 +1216,25 @@ FadeOutAudio:: ; 28cb (0:28cb) or c ld [rNR50], a ret -.asm_2903 +.asm_27fa ld a, [wAudioFadeOutControl] ld b, a xor a ld [wAudioFadeOutControl], a - ld a, $ff - ld [wNewSoundID], a - call PlaySound + call StopAllMusic ld a, [wAudioSavedROMBank] ld [wAudioROMBank], a ld a, b ld [wNewSoundID], a jp PlaySound +UnknownText_2812:: ; 2812 (0:2812) + TX_FAR _PokemonText ; 2c:749a + db "@" + ; this function is used to display sign messages, sprite dialog, etc. ; INPUT: [hSpriteIndexOrTextID] = sprite ID or text ID -DisplayTextID:: ; 2920 (0:2920) +DisplayTextID:: ; 2817 (0:2817) ld a,[H_LOADEDROMBANK] push af callba DisplayTextIDInit ; initialization @@ -1071,6 +1256,8 @@ DisplayTextID:: ; 2920 (0:2920) ld [wSpriteIndex],a and a jp z,DisplayStartMenu + cp a,$d4 ; new yellow asm + jp z,DisplayUnknownText_29c6 cp a,TEXT_SAFARI_GAME_OVER jp z,DisplaySafariGameOverText cp a,TEXT_MON_FAINTED @@ -1088,20 +1275,18 @@ DisplayTextID:: ; 2920 (0:2920) .spriteHandling ; get the text ID of the sprite push hl - push de - push bc - callba UpdateSpriteFacingOffsetAndDelayMovement ; update the graphics of the sprite the player is talking to (to face the right direction) - pop bc - pop de + ;push de + ;push bc + ;callba UpdateSpriteFacingOffsetAndDelayMovement ; update the graphics of the sprite the player is talking to (to face the right direction) + ;pop bc + ;pop de ld hl,W_MAPSPRITEDATA ; NPC text entries ld a,[hSpriteIndexOrTextID] dec a add a - add l - ld l,a - jr nc,.noCarry - inc h -.noCarry + ld e,a + ld d,$0 + add hl,de inc hl ld a,[hl] ; a = text ID of the sprite pop hl @@ -1109,7 +1294,8 @@ DisplayTextID:: ; 2920 (0:2920) ; look up the address of the text in the map's text entries dec a ld e,a - sla e + ld d,$0 + add hl,de add hl,de ld a,[hli] ld h,[hl] @@ -1143,20 +1329,20 @@ DisplayTextID:: ; 2920 (0:2920) and a jr nz,HoldTextDisplayOpen -AfterDisplayingTextID:: ; 29d6 (0:29d6) +AfterDisplayingTextID:: ; 28c6 (0:28c6) ld a,[wEnteringCableClub] and a jr nz,HoldTextDisplayOpen call WaitForTextScrollButtonPress ; wait for a button press after displaying all the text ; loop to hold the dialogue box open as long as the player keeps holding down the A button -HoldTextDisplayOpen:: ; 29df (0:29df) +HoldTextDisplayOpen:: ; 28cf (0:28cf) call Joypad ld a,[hJoyHeld] bit 0,a ; is the A button being pressed? jr nz,HoldTextDisplayOpen -CloseTextDisplay:: ; 29e8 (0:29e8) +CloseTextDisplay:: ; 28d8 (0:28d8) ld a,[W_CURMAP] call SwitchToMapRomBank ld a,$90 @@ -1177,9 +1363,6 @@ CloseTextDisplay:: ; 29e8 (0:29e8) add hl,de dec c jr nz,.restoreSpriteFacingDirectionLoop - ld a,BANK(InitMapSprites) - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a call InitMapSprites ; reload sprite tile pattern data (since it was partially overwritten by text tile patterns) ld hl,wFontLoaded res 0,[hl] @@ -1188,11 +1371,10 @@ CloseTextDisplay:: ; 29e8 (0:29e8) call z,LoadPlayerSpriteGraphics call LoadCurrentMapView pop af - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a + call BankswitchCommon jp UpdateSprites -DisplayPokemartDialogue:: ; 2a2e (0:2a2e) +DisplayPokemartDialogue:: ; 2915 (0:2915) push hl ld hl,PokemartGreetingText call PrintText @@ -1200,23 +1382,15 @@ DisplayPokemartDialogue:: ; 2a2e (0:2a2e) inc hl call LoadItemList ld a,PRICEDITEMLISTMENU - ld [wListMenuID],a - ld a,[H_LOADEDROMBANK] - push af - ld a,Bank(DisplayPokemartDialogue_) - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a - call DisplayPokemartDialogue_ - pop af - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a + ld [wListMenuID],a ; selects between subtypes of menus + homecall DisplayPokemartDialogue_ jp AfterDisplayingTextID -PokemartGreetingText:: ; 2a55 (0:2a55) +PokemartGreetingText:: ; 2938 (0:2938) TX_FAR _PokemartGreetingText db "@" -LoadItemList:: ; 2a5a (0:2a5a) +LoadItemList:: ; 293d (0:293d) ld a,1 ld [wUpdateSpritesEnabled],a ld a,h @@ -1232,7 +1406,7 @@ LoadItemList:: ; 2a5a (0:2a5a) jr nz,.loop ret -DisplayPokemonCenterDialogue:: ; 2a72 (0:2a72) +DisplayPokemonCenterDialogue:: ; 2955 (0:2955) ; zeroing these doesn't appear to serve any purpose xor a ld [$ff8b],a @@ -1240,51 +1414,58 @@ DisplayPokemonCenterDialogue:: ; 2a72 (0:2a72) ld [$ff8d],a inc hl - ld a,[H_LOADEDROMBANK] - push af - ld a,Bank(DisplayPokemonCenterDialogue_) - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a - call DisplayPokemonCenterDialogue_ - pop af - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a + homecall DisplayPokemonCenterDialogue_ jp AfterDisplayingTextID -DisplaySafariGameOverText:: ; 2a90 (0:2a90) +DisplaySafariGameOverText:: ; 296f (0:296f) callab PrintSafariGameOverText jp AfterDisplayingTextID -DisplayPokemonFaintedText:: ; 2a9b (0:2a9b) +DisplayPokemonFaintedText:: ; 297a (0:297a) ld hl,PokemonFaintedText call PrintText jp AfterDisplayingTextID -PokemonFaintedText:: ; 2aa4 (0:2aa4) +PokemonFaintedText:: ; 2983 (0:2983) TX_FAR _PokemonFaintedText db "@" -DisplayPlayerBlackedOutText:: ; 2aa9 (0:2aa9) +DisplayPlayerBlackedOutText:: ; 2988 (0:2988) ld hl,PlayerBlackedOutText call PrintText ld a,[wd732] res 5,a ; reset forced to use bike bit ld [wd732],a + ld a,[wd790] + bit 7,a + jr z,.didnotblackoutinsafari + xor a + ld [W_NUMSAFARIBALLS],a + ld [wSafariSteps],a + ld [wSafariSteps+1],a + ld [wd790],a + ld [wcf0d],a + ld [W_SAFARIZONEENTRANCECURSCRIPT],a +.didnotblackoutinsafari jp HoldTextDisplayOpen -PlayerBlackedOutText:: ; 2aba (0:2aba) +PlayerBlackedOutText:: ; 29b3 (0:29b3) TX_FAR _PlayerBlackedOutText db "@" -DisplayRepelWoreOffText:: ; 2abf (0:2abf) +DisplayRepelWoreOffText:: ; 29b8 (0:29b8) ld hl,RepelWoreOffText call PrintText jp AfterDisplayingTextID -RepelWoreOffText:: ; 2ac8 (0:2ac8) +RepelWoreOffText:: ; 29c1 (0:29c1) TX_FAR _RepelWoreOffText db "@" +DisplayUnknownText_29c6:: ; 29c6 (0:29c6) + callab Func_fd004 ; 3f:5004 + jp CloseTextDisplay + INCLUDE "engine/menu/start_menu.asm" ; function to count how many bits are set in a string of bytes @@ -1293,7 +1474,7 @@ INCLUDE "engine/menu/start_menu.asm" ; b = length of string of bytes ; OUTPUT: ; [wNumSetBits] = number of set bits -CountSetBits:: ; 2b7f (0:2b7f) +CountSetBits:: ; 2a81 (0:2a81) ld c,0 .loop ld a,[hli] @@ -1314,11 +1495,11 @@ CountSetBits:: ; 2b7f (0:2b7f) ; subtracts the amount the player paid from their money ; sets carry flag if there is enough money and unsets carry flag if not -SubtractAmountPaidFromMoney:: ; 2b96 (0:2b96) +SubtractAmountPaidFromMoney:: ; 2a98 (0:2a98) jpba SubtractAmountPaidFromMoney_ ; adds the amount the player sold to their money -AddAmountSoldToMoney:: ; 2b9e (0:2b9e) +AddAmountSoldToMoney:: ; 2aa0 (0:2aa0) ld de,wPlayerMoney + 2 ld hl,$ffa1 ; total price of items ld c,3 ; length of money in bytes @@ -1326,6 +1507,9 @@ AddAmountSoldToMoney:: ; 2b9e (0:2b9e) ld a,MONEY_BOX ld [wTextBoxID],a call DisplayTextBoxID ; redraw money text box + ld a, $b2 ; SFX_PURCHASE + call PlaySoundWaitForCurrent ; play sound + jp WaitForSoundToFinish ; wait until sound is done playing ld a, SFX_PURCHASE call PlaySoundWaitForCurrent jp WaitForSoundToFinish @@ -1335,16 +1519,8 @@ AddAmountSoldToMoney:: ; 2b9e (0:2b9e) ; HL = address of inventory (either wNumBagItems or wNumBoxItems) ; [wWhichPokemon] = index (within the inventory) of the item to remove ; [wItemQuantity] = quantity to remove -RemoveItemFromInventory:: ; 2bbb (0:2bbb) - ld a,[H_LOADEDROMBANK] - push af - ld a,BANK(RemoveItemFromInventory_) - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a - call RemoveItemFromInventory_ - pop af - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a +RemoveItemFromInventory:: ; 2abd (0:2abd) + homecall RemoveItemFromInventory_ ret ; function to add an item (in varying quantities) to the player's bag or PC box @@ -1353,25 +1529,16 @@ RemoveItemFromInventory:: ; 2bbb (0:2bbb) ; [wcf91] = item ID ; [wItemQuantity] = item quantity ; sets carry flag if successful, unsets carry flag if unsuccessful -AddItemToInventory:: ; 2bcf (0:2bcf) +AddItemToInventory:: ; 2acd (0:2acd) push bc - ld a,[H_LOADEDROMBANK] - push af - ld a,BANK(AddItemToInventory_) - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a - call AddItemToInventory_ - pop bc - ld a,b - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a + homecall_sf AddItemToInventory_ pop bc ret ; INPUT: ; [wListMenuID] = list menu ID ; [wListPointer] = address of the list (2 bytes) -DisplayListMenuID:: ; 2be6 (0:2be6) +DisplayListMenuID:: ; 2ae0 (0:2ae0) xor a ld [H_AUTOBGTRANSFERENABLED],a ; disable auto-transfer ld a,1 @@ -1382,7 +1549,7 @@ DisplayListMenuID:: ; 2be6 (0:2be6) ld a,$01 ; hardcoded bank jr .bankswitch .specialBattleType ; Old Man battle - ld a, Bank(DisplayBattleMenu) + ld a, $f ; BANK(DisplayBattleMenu) .bankswitch call BankswitchHome ld hl,wd730 @@ -1425,7 +1592,7 @@ DisplayListMenuID:: ; 2be6 (0:2be6) ld c,10 call DelayFrames -DisplayListMenuIDLoop:: ; 2c53 (0:2c53) +DisplayListMenuIDLoop:: ; 2b4d (0:2b4d) xor a ld [H_AUTOBGTRANSFERENABLED],a ; disable transfer call PrintListMenuEntries @@ -1438,7 +1605,7 @@ DisplayListMenuIDLoop:: ; 2c53 (0:2c53) .oldManBattle ld a,"▶" Coorda 5, 4 ; place menu cursor in front of first menu entry - ld c,80 + ld c,20 call DelayFrames xor a ld [wCurrentMenuItem],a @@ -1562,16 +1729,16 @@ DisplayListMenuIDLoop:: ; 2c53 (0:2c53) dec [hl] jp DisplayListMenuIDLoop -DisplayChooseQuantityMenu:: ; 2d57 (0:2d57) +DisplayChooseQuantityMenu:: ; 2c51 (0:2c51) ; text box dimensions/coordinates for just quantity coord hl, 15, 9 - ld b,1 ; height - ld c,3 ; width + lb bc, 1, 3 ; height and width ld a,[wListMenuID] cp a,PRICEDITEMLISTMENU jr nz,.drawTextBox ; text box dimensions/coordinates for quantity and price coord hl, 7, 9 + lb bc, 1, 11 ; height and width ld b,1 ; height ld c,11 ; width .drawTextBox @@ -1681,13 +1848,13 @@ DisplayChooseQuantityMenu:: ; 2d57 (0:2d57) ld a,$ff ret -InitialQuantityText:: ; 2e30 (0:2e30) +InitialQuantityText:: ; 2d28 (0:2d28) db "×01@" -SpacesBetweenQuantityAndPriceText:: ; 2e34 (0:2e34) +SpacesBetweenQuantityAndPriceText:: ; 2d2c (0:2d2c) db " @" -ExitListMenu:: ; 2e3b (0:2e3b) +ExitListMenu:: ; 2d33 (0:2d33) ld a,[wCurrentMenuItem] ld [wChosenMenuItem],a ld a,CANCELLED_MENU @@ -1703,10 +1870,9 @@ ExitListMenu:: ; 2e3b (0:2e3b) scf ret -PrintListMenuEntries:: ; 2e5a (0:2e5a) +PrintListMenuEntries:: ; 2d52 (0:2d52) coord hl, 5, 3 - ld b,9 - ld c,14 + lb bc, 9, 14 call ClearScreenArea ld a,[wListPointer] ld e,a @@ -1721,7 +1887,7 @@ PrintListMenuEntries:: ; 2e5a (0:2e5a) jr nz,.skipMultiplying ; if it's an item menu ; item entries are 2 bytes long, so multiply by 2 - sla a + add a sla c .skipMultiplying add e @@ -1870,7 +2036,7 @@ PrintListMenuEntries:: ; 2e5a (0:2e5a) ld a,[wMenuItemToSwap] ; ID of item chosen for swapping (counts from 1) and a ; is an item being swapped? jr z,.nextListEntry - sla a + add a cp c ; is it this item? jr nz,.nextListEntry dec hl @@ -1892,19 +2058,19 @@ PrintListMenuEntries:: ; 2e5a (0:2e5a) ld de,ListMenuCancelText jp PlaceString -ListMenuCancelText:: ; 2f97 (0:2f97) +ListMenuCancelText:: ; 2e8c (0:2e8c) db "CANCEL@" -GetMonName:: ; 2f9e (0:2f9e) +GetMonName:: ; 2e93 (0:2e93) push hl ld a,[H_LOADEDROMBANK] push af - ld a,BANK(MonsterNames) + ld a,BANK(MonsterNames) ; 3a ld [H_LOADEDROMBANK],a ld [MBC1RomBank],a ld a,[wd11e] dec a - ld hl,MonsterNames + ld hl,MonsterNames ; 4000 ld c,10 ld b,0 call AddNTimes @@ -1921,7 +2087,7 @@ GetMonName:: ; 2f9e (0:2f9e) pop hl ret -GetItemName:: ; 2fcf (0:2fcf) +GetItemName:: ; 2ec4 (0:2ec4) ; given an item ID at [wd11e], store the name of the item into a string ; starting at wcd6d push hl @@ -1946,7 +2112,7 @@ GetItemName:: ; 2fcf (0:2fcf) pop hl ret -GetMachineName:: ; 2ff3 (0:2ff3) +GetMachineName:: ; 2ee8 (0:2ee8) ; copies the name of the TM/HM in [wd11e] to wcd6d push hl push de @@ -1991,7 +2157,6 @@ GetMachineName:: ; 2ff3 (0:2ff3) inc de ld a,"@" ld [de],a - pop af ld [wd11e],a pop bc @@ -1999,14 +2164,14 @@ GetMachineName:: ; 2ff3 (0:2ff3) pop hl ret -TechnicalPrefix:: ; 303c (0:303c) +TechnicalPrefix:: ; 2f31 (0:2f31) db "TM" -HiddenPrefix:: ; 303e (0:303e) +HiddenPrefix:: ; 2f33 (0:2f33) db "HM" ; sets carry if item is HM, clears carry if item is not HM ; Input: a = item ID -IsItemHM:: ; 3040 (0:3040) +IsItemHM:: ; 2f35 (0:2f35) cp a,HM_01 jr c,.notHM cp a,TM_01 @@ -2017,16 +2182,16 @@ IsItemHM:: ; 3040 (0:3040) ; sets carry if move is an HM, clears carry if move is not an HM ; Input: a = move ID -IsMoveHM:: ; 3049 (0:3049) +IsMoveHM:: ; 2f3e (0:2f3e) ld hl,HMMoves ld de,1 jp IsInArray -HMMoves:: ; 3052 (0:3052) +HMMoves:: ; 2f47 (0:2f47) db CUT,FLY,SURF,STRENGTH,FLASH db $ff ; terminator -GetMoveName:: ; 3058 (0:3058) +GetMoveName:: ; 2f4d (0:2f4d) push hl ld a,MOVE_NAME ld [wNameListType],a @@ -2040,7 +2205,7 @@ GetMoveName:: ; 3058 (0:3058) ret ; reloads text box tile patterns, current map view, and tileset tile patterns -ReloadMapData:: ; 3071 (0:3071) +ReloadMapData:: ; 2f66 (0:2f66) ld a,[H_LOADEDROMBANK] push af ld a,[W_CURMAP] @@ -2051,12 +2216,11 @@ ReloadMapData:: ; 3071 (0:3071) call LoadTilesetTilePatternData call EnableLCD pop af - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a + call BankswitchCommon ret ; reloads tileset tile patterns -ReloadTilesetTilePatterns:: ; 3090 (0:3090) +ReloadTilesetTilePatterns:: ; 2f83 (0:2f83) ld a,[H_LOADEDROMBANK] push af ld a,[W_CURMAP] @@ -2065,18 +2229,45 @@ ReloadTilesetTilePatterns:: ; 3090 (0:3090) call LoadTilesetTilePatternData call EnableLCD pop af - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a + call BankswitchCommon ret ; shows the town map and lets the player choose a destination to fly to -ChooseFlyDestination:: ; 30a9 (0:30a9) +ChooseFlyDestination:: ; 2f9a (0:2f9a) ld hl,wd72e res 4,[hl] jpba LoadTownMap_Fly +Func_2fa7:: ; 2fa7 (0:2fa7) + homecall Func_e8a5e + ret + +SerialFunction:: ; 2fb7 (0:2fb7) + ld a,[wUnknownSerialFlag_d49a] + bit 0,a + ret z + ld a,[wUnknownSerialFlag_d49b] + and a + ret nz + ld hl,wOverworldMap+650 + inc [hl] + ld a,[hl] + cp $6 + ret c + xor a + ld [hl],a + ld a,$0c + ld [wUnknownSerialFlag_d49b],a + ld a,$88 + ld [rSB],a + ld a,$1 + ld [rSC],a + ld a,START_TRANSFER_INTERNAL_CLOCK + ld [rSC],a + ret + ; causes the text box to close without waiting for a button press after displaying text -DisableWaitingAfterTextDisplay:: ; 30b6 (0:30b6) +DisableWaitingAfterTextDisplay:: ; 2fde (0:2fde) ld a,$01 ld [wDoNotWaitForButtonPressAfterDisplayingText],a ret @@ -2090,7 +2281,7 @@ DisableWaitingAfterTextDisplay:: ; 30b6 (0:30b6) ; 00: unsucessful ; 01: successful ; 02: not able to be used right now, no extra menu displayed (only certain items use this) -UseItem:: ; 30bc (0:30bc) +UseItem:: ; 2fe4 (0:2fe4) jpba UseItem_ ; confirms the item toss and then tosses the item @@ -2101,7 +2292,7 @@ UseItem:: ; 30bc (0:30bc) ; [wItemQuantity] = quantity to toss ; OUTPUT: ; clears carry flag if the item is tossed, sets carry flag if not -TossItem:: ; 30c4 (0:30c4) +TossItem:: ; 2fec (0:2fec) ld a,[H_LOADEDROMBANK] push af ld a,BANK(TossItem_) @@ -2121,7 +2312,7 @@ TossItem:: ; 30c4 (0:30c4) ; [wIsKeyItem] = result ; 00: item is not key item ; 01: item is key item -IsKeyItem:: ; 30d9 (0:30d9) +IsKeyItem:: ; 3000 (0:3000) push hl push de push bc @@ -2134,23 +2325,95 @@ IsKeyItem:: ; 30d9 (0:30d9) ; function to draw various text boxes ; INPUT: ; [wTextBoxID] = text box ID -; b, c = y, x cursor position (TWO_OPTION_MENU only) -DisplayTextBoxID:: ; 30e8 (0:30e8) - ld a,[H_LOADEDROMBANK] +DisplayTextBoxID:: ; 3010 (0:3010) + homecall_sf DisplayTextBoxID_ + ret + +Func_3021:: ; 3021 (0:3021) push af - ld a,BANK(DisplayTextBoxID_) - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a - call DisplayTextBoxID_ + ld a,[hGBC] + and a + jr z,.notgbc + push bc + push de + push hl + ld a,[rBGP] + ld b,a + ld a,[wdef2] + cp b + jr z,.asm_303b + callba Func_72524 ; 1c:6524 +.asm_303b + pop hl + pop de pop bc - ld a,b - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a +.notgbc + pop af + ret + +Func_3040:: ; 3040 (0:3040) + push af + ld a,[hGBC] + and a + jr z,.notgbc + push bc + push de + push hl + ld a,[rOBP0] + ld b,a + ld a,[wdef3] + cp b + jr z,.asm_305c + ld b,BANK(Func_7256c) ; 1c:656c + ld hl,Func_7256c + ld c,$1 + call Bankswitch +.asm_305c + pop hl + pop de + pop bc +.notgbc + pop af + ret + +Func_3061:: ; 3061 (0:3061) + push af + ld a,[hGBC] + and a + jr z,.notgbc + push bc + push de + push hl + ld a,[rOBP1] + ld b,a + ld a,[wdef4] + cp b + jr z,.asm_307d + ld b,BANK(Func_7256c) + ld hl,Func_7256c + ld c,$2 + call Bankswitch +.asm_307d + pop hl + pop de + pop bc +.notgbc + pop af + ret + +Func_3082:: ; 3082 (0:3082) + ld a,[H_LOADEDROMBANK] + push af + call Func_27c2 + callbs Music_DoLowHealthAlarm + callbs Music2_UpdateMusic + pop af + call BankswitchCommon ret ; not zero if an NPC movement script is running, the player character is ; automatically stepping down from a door, or joypad states are being simulated -IsPlayerCharacterBeingControlledByGame:: ; 30fd (0:30fd) +IsPlayerCharacterBeingControlledByGame:: ; 309d (0:309d) ld a, [wNPCMovementScriptPointerTableNum] and a ret nz @@ -2161,7 +2424,7 @@ IsPlayerCharacterBeingControlledByGame:: ; 30fd (0:30fd) and $80 ret -RunNPCMovementScript:: ; 310e (0:310e) +RunNPCMovementScript:: ; 30ae (0:30ae) ld hl, wd736 bit 0, [hl] res 0, [hl] @@ -2181,14 +2444,13 @@ RunNPCMovementScript:: ; 310e (0:310e) ld a, [H_LOADEDROMBANK] push af ld a, [wNPCMovementScriptBank] - ld [H_LOADEDROMBANK], a - ld [MBC1RomBank], a + call BankswitchCommon ld a, [wNPCMovementScriptFunctionNum] call CallFunctionInTable pop af - ld [H_LOADEDROMBANK], a - ld [MBC1RomBank], a + call BankswitchCommon ret + .NPCMovementScriptPointerTables dw PalletMovementScriptPointerTable dw PewterMuseumGuyMovementScriptPointerTable @@ -2196,14 +2458,14 @@ RunNPCMovementScript:: ; 310e (0:310e) .playerStepOutFromDoor jpba PlayerStepOutFromDoor -EndNPCMovementScript:: ; 314e (0:314e) +EndNPCMovementScript:: ; 30ea (0:30ea) jpba _EndNPCMovementScript -EmptyFunc2:: ; 3156 (0:3156) +EmptyFunc2:: ; 30f2 (0:30f2) ret ; stores hl in [W_TRAINERHEADERPTR] -StoreTrainerHeaderPointer:: ; 3157 (0:3157) +StoreTrainerHeaderPointer:: ; 30f3 (0:30f3) ld a, h ld [W_TRAINERHEADERPTR], a ld a, l @@ -2212,7 +2474,7 @@ StoreTrainerHeaderPointer:: ; 3157 (0:3157) ; executes the current map script from the function pointer array provided in hl. ; a: map script index to execute (unless overridden by [wd733] bit 4) -ExecuteCurMapScriptInTable:: ; 3160 (0:3160) +ExecuteCurMapScriptInTable:: ; 30fc (0:30fc) push af push de call StoreTrainerHeaderPointer @@ -2231,7 +2493,7 @@ ExecuteCurMapScriptInTable:: ; 3160 (0:3160) ld a, [W_CURMAPSCRIPT] ret -LoadGymLeaderAndCityName:: ; 317f (0:317f) +LoadGymLeaderAndCityName:: ; 311b (0:311b) push de ld de, wGymCityName ld bc, $11 @@ -2248,7 +2510,7 @@ LoadGymLeaderAndCityName:: ; 317f (0:317f) ; 4 -> before battle text (into hl) ; 6 -> after battle text (into hl) ; 8 -> end battle text (into hl) -ReadTrainerHeaderInfo:: ; 3193 (0:3193) +ReadTrainerHeaderInfo:: ; 312f (0:312f) push de push af ld d, $0 @@ -2287,10 +2549,10 @@ ReadTrainerHeaderInfo:: ; 3193 (0:3193) pop de ret -TrainerFlagAction:: +TrainerFlagAction:: ; 3163 (0:3163) predef_jump FlagActionPredef -TalkToTrainer:: ; 31cc (0:31cc) +TalkToTrainer:: ; 3168 (0:3168) call StoreTrainerHeaderPointer xor a call ReadTrainerHeaderInfo ; read flag's bit @@ -2329,7 +2591,7 @@ TalkToTrainer:: ; 31cc (0:31cc) jp StartTrainerBattle ; checks if any trainers are seeing the player and wanting to fight -CheckFightingMapTrainers:: ; 3219 (0:3219) +CheckFightingMapTrainers:: ; 31b5 (0:31b5) call CheckForEngagingTrainers ld a, [wSpriteIndex] cp $ff @@ -2355,7 +2617,7 @@ CheckFightingMapTrainers:: ; 3219 (0:3219) ret ; display the before battle text after the enemy trainer has walked up to the player's sprite -DisplayEnemyTrainerTextAndStartBattle:: ; 324c (0:324c) +DisplayEnemyTrainerTextAndStartBattle:: ; 31e8 (0:31e8) ld a, [wd730] and $1 ret nz ; return if the enemy trainer hasn't finished walking to the player's sprite @@ -2365,7 +2627,7 @@ DisplayEnemyTrainerTextAndStartBattle:: ; 324c (0:324c) call DisplayTextID ; fall through -StartTrainerBattle:: ; 325d (0:325d) +StartTrainerBattle:: ; 31f9 (0:31f9) xor a ld [wJoyIgnore], a call InitBattleEnemyParameters @@ -2378,7 +2640,7 @@ StartTrainerBattle:: ; 325d (0:325d) inc [hl] ; increment map script index (next script function is usually EndTrainerBattle) ret -EndTrainerBattle:: ; 3275 (0:3275) +EndTrainerBattle:: ; 3211 (0:3211) ld hl, wd126 set 5, [hl] set 6, [hl] @@ -2412,7 +2674,7 @@ EndTrainerBattle:: ; 3275 (0:3275) res 4, [hl] ret nz -ResetButtonPressedAndMapScript:: ; 32c1 (0:32c1) +ResetButtonPressedAndMapScript:: ; 325d (0:325d) xor a ld [wJoyIgnore], a ld [hJoyHeld], a @@ -2422,11 +2684,11 @@ ResetButtonPressedAndMapScript:: ; 32c1 (0:32c1) ret ; calls TrainerWalkUpToPlayer -TrainerWalkUpToPlayer_Bank0:: ; 32cf (0:32cf) +TrainerWalkUpToPlayer_Bank0:: ; 326b (0:326b) jpba TrainerWalkUpToPlayer ; sets opponent type and mon set/lvl based on the engaging trainer data -InitBattleEnemyParameters:: ; 32d7 (0:32d7) +InitBattleEnemyParameters:: ; 3273 (0:3273) ld a, [wEngagedTrainerClass] ld [W_CUROPPONENT], a ld [W_ENEMYMONORTRAINERCLASS], a @@ -2439,25 +2701,25 @@ InitBattleEnemyParameters:: ; 32d7 (0:32d7) ld [W_CURENEMYLVL], a ret -GetSpritePosition1:: ; 32ef (0:32ef) +GetSpritePosition1:: ; 328b (0:328b) ld hl, _GetSpritePosition1 jr SpritePositionBankswitch -GetSpritePosition2:: ; 32f4 (0:32f4) +GetSpritePosition2:: ; 3290 (0:3290) ld hl, _GetSpritePosition2 jr SpritePositionBankswitch -SetSpritePosition1:: ; 32f9 (0:32f9) +SetSpritePosition1:: ; 3295 (0:3295) ld hl, _SetSpritePosition1 jr SpritePositionBankswitch -SetSpritePosition2:: ; 32fe (0:32fe) +SetSpritePosition2:: ; 329a (0:329a) ld hl, _SetSpritePosition2 -SpritePositionBankswitch:: ; 3301 (0:3301) +SpritePositionBankswitch:: ; 329d (0:329d) ld b, BANK(_GetSpritePosition1) ; BANK(_GetSpritePosition2), BANK(_SetSpritePosition1), BANK(_SetSpritePosition2) jp Bankswitch ; indirect jump to one of the four functions -CheckForEngagingTrainers:: ; 3306 (0:3306) +CheckForEngagingTrainers:: ; 32a2 (0:32a2) xor a call ReadTrainerHeaderInfo ; read trainer flag's bit (unused) ld d, h ; store trainer header address in de @@ -2505,7 +2767,7 @@ CheckForEngagingTrainers:: ; 3306 (0:3306) ; hl = text if the player wins ; de = text if the player loses -SaveEndBattleTextPointers:: ; 3354 (0:3354) +SaveEndBattleTextPointers:: ; 32f0 (0:32f0) ld a, [H_LOADEDROMBANK] ld [wEndBattleTextRomBank], a ld a, h @@ -2520,7 +2782,7 @@ SaveEndBattleTextPointers:: ; 3354 (0:3354) ; loads data of some trainer on the current map and plays pre-battle music ; [wSpriteIndex]: sprite ID of trainer who is engaged -EngageMapTrainer:: ; 336a (0:336a) +EngageMapTrainer:: ; 3306 (0:3306) ld hl, W_MAPSPRITEEXTRADATA ld d, $0 ld a, [wSpriteIndex] @@ -2534,7 +2796,7 @@ EngageMapTrainer:: ; 336a (0:336a) ld [wEnemyMonAttackMod], a jp PlayTrainerMusic -PrintEndBattleText:: ; 3381 (0:3381) +PrintEndBattleText:: ; 331d (0:331d) push hl ld hl, wd72d bit 7, [hl] @@ -2557,7 +2819,7 @@ PrintEndBattleText:: ; 3381 (0:3381) callba FreezeEnemyTrainerSprite jp WaitForSoundToFinish -GetSavedEndBattleTextPointer:: ; 33b7 (0:33b7) +GetSavedEndBattleTextPointer:: ; 3353 (0:3353) ld a, [wBattleResult] and a ; won battle @@ -2574,25 +2836,14 @@ GetSavedEndBattleTextPointer:: ; 33b7 (0:33b7) ld l, a ret -TrainerEndBattleText:: ; 33cf (0:33cf) +TrainerEndBattleText:: ; 336b (0:336b) TX_FAR _TrainerNameText TX_ASM call GetSavedEndBattleTextPointer call TextCommandProcessor jp TextScriptEnd -; only engage withe trainer if the player is not already -; engaged with another trainer -; XXX unused? -CheckIfAlreadyEngaged:: ; 33dd (0:33dd) - ld a, [wFlags_0xcd60] - bit 0, a - ret nz - call EngageMapTrainer - xor a - ret - -PlayTrainerMusic:: ; 33e8 (0:33e8) +PlayTrainerMusic:: ; 3379 (0:3379) ld a, [wEngagedTrainerClass] cp OPP_SONY1 ret z @@ -2605,9 +2856,8 @@ PlayTrainerMusic:: ; 33e8 (0:33e8) ret nz xor a ld [wAudioFadeOutControl], a - ld a, $ff - call PlaySound - ld a, BANK(Music_MeetEvilTrainer) + call StopAllMusic ; stop music + ld a, $1f ; BANK(Music_MeetEvilTrainer) ld [wAudioROMBank], a ld [wAudioSavedROMBank], a ld a, [wEngagedTrainerClass] @@ -2619,7 +2869,7 @@ PlayTrainerMusic:: ; 33e8 (0:33e8) jr z, .noEvilTrainer cp b jr nz, .evilTrainerListLoop - ld a, MUSIC_MEET_EVIL_TRAINER + ld a, $f5 ; MUSIC_MEET_EVIL_TRAINER jr .PlaySound .noEvilTrainer ld hl, FemaleTrainerList @@ -2629,10 +2879,10 @@ PlayTrainerMusic:: ; 33e8 (0:33e8) jr z, .maleTrainer cp b jr nz, .femaleTrainerListLoop - ld a, MUSIC_MEET_FEMALE_TRAINER + ld a, $f8 ; MUSIC_MEET_FEMALE_TRAINER jr .PlaySound .maleTrainer - ld a, MUSIC_MEET_MALE_TRAINER + ld a, $fb ; MUSIC_MEET_MALE_TRAINER .PlaySound ld [wNewSoundID], a jp PlaySound @@ -2667,33 +2917,33 @@ DecodeArrowMovementRLE:: ; 3442 (0:3442) inc hl jr DecodeArrowMovementRLE -FuncTX_ItemStoragePC:: ; 3460 (0:3460) +FuncTX_ItemStoragePC:: ; 33ef (0:33ef) call SaveScreenTilesToBuffer2 ld b, BANK(PlayerPC) ld hl, PlayerPC jr bankswitchAndContinue -FuncTX_BillsPC:: ; 346a (0:346a) +FuncTX_BillsPC:: ; 33f9 (0:33f9) call SaveScreenTilesToBuffer2 ld b, BANK(BillsPC_) ld hl, BillsPC_ jr bankswitchAndContinue -FuncTX_SlotMachine:: ; 3474 (0:3474) +FuncTX_SlotMachine:: ; 3403 (0:3403) ; XXX find a better name for this function ; special_F7 ld b,BANK(CeladonPrizeMenu) ld hl,CeladonPrizeMenu -bankswitchAndContinue:: ; 3479 (0:3479) +bankswitchAndContinue:: ; 3408 (0:3408) call Bankswitch jp HoldTextDisplayOpen ; continue to main text-engine function -FuncTX_PokemonCenterPC:: ; 347f (0:347f) +FuncTX_PokemonCenterPC:: ; 340e (0:340e) ld b, BANK(ActivatePC) ld hl, ActivatePC jr bankswitchAndContinue -StartSimulatingJoypadStates:: ; 3486 (0:3486) +StartSimulatingJoypadStates:: ; 3415 (0:3415) xor a ld [wOverrideSimulatedJoypadStatesMask], a ld [wSpriteStateData2 + $06], a ; player's sprite movement byte 1 @@ -2701,7 +2951,7 @@ StartSimulatingJoypadStates:: ; 3486 (0:3486) set 7, [hl] ret -IsItemInBag:: ; 3493 (0:3493) +IsItemInBag:: ; 3422 (0:3422) ; given an item_id in b ; set zero flag if item isn't in player's bag ; else reset zero flag @@ -2710,17 +2960,71 @@ IsItemInBag:: ; 3493 (0:3493) ld a,b and a ret - -DisplayPokedex:: ; 349b (0:349b) + +IsSurfingPikachuInParty:: ; 342a (0:342a) +; set bit 6 of wd472 if true +; also calls Func_3467, which is a bankswitch to Func_fcdb8 + ld a,[wd472] + and $3f + ld [wd472],a + ld hl,wPartyMon1 + ld c,PARTY_LENGTH + ld b,SURF +.loop + ld a,[hl] + cp PIKACHU + jr nz,.notPikachu + push hl + ld de,$8 + add hl,de + ld a,[hli] + cp b ; does pikachu have surf as one of its moves + jr z,.hasSurf + ld a,[hli] + cp b + jr z,.hasSurf + ld a,[hli] + cp b + jr z,.hasSurf + ld a,[hli] + cp b + jr nz,.noSurf +.hasSurf + ld a,[wd472] + set 6,a + ld [wd472],a +.noSurf + pop hl +.notPikachu + ld de,wPartyMon2 - wPartyMon1 + add hl,de + dec c + jr nz,.loop + call Func_3467 + ret + +Func_3467:: ; 3467 (0:3467) + push hl + push bc + callab Func_fcdb8 + pop bc + pop hl + ret nc + ld a,[wd472] + set 7,a + ld [wd472],a + ret + +DisplayPokedex:: ; 347d (0:347d) ld [wd11e], a jpba _DisplayPokedex -SetSpriteFacingDirectionAndDelay:: ; 34a6 (0:34a6) +SetSpriteFacingDirectionAndDelay:: ; 3488 (0:3488) call SetSpriteFacingDirection ld c, 6 jp DelayFrames -SetSpriteFacingDirection:: ; 34ae (0:34ae) +SetSpriteFacingDirection:: ; 3490 (0:3490) ld a, $9 ld [H_SPRITEDATAOFFSET], a call GetPointerWithinSpriteStateData1 @@ -2728,26 +3032,46 @@ SetSpriteFacingDirection:: ; 34ae (0:34ae) ld [hl], a ret -SetSpriteImageIndexAfterSettingFacingDirection:: ; 34b9 (0:34b9) +SetSpriteImageIndexAfterSettingFacingDirection:: ; 349b (0:349b) ld de, -7 add hl, de ld [hl], a ret +SpriteFunc_34a1:: ; 34a1 (0:34a1) + ld a,[H_SPRITEINDEX] + swap a + add $e + ld l,a + ld h,$c2 + ld c,[hl] + dec c + swap c + ld a,[$ff8d] + add c + ld c,a + ld a,[$ff8c] + swap a + add $2 + ld l,a + dec h + ld [hl],c + ret + ; tests if the player's coordinates are in a specified array ; INPUT: ; hl = address of array ; OUTPUT: ; [wCoordIndex] = if there is match, the matching array index ; sets carry if the coordinates are in the array, clears carry if not -ArePlayerCoordsInArray:: ; 34bf (0:34bf) +ArePlayerCoordsInArray:: ; 34bc (0:34bc) ld a,[W_YCOORD] ld b,a ld a,[W_XCOORD] ld c,a ; fallthrough -CheckCoords:: ; 34c7 (0:34c7) +CheckCoords:: ; 34c4 (0:34c4) xor a ld [wCoordIndex],a .loop @@ -2781,7 +3105,7 @@ CheckCoords:: ; 34c7 (0:34c7) ; OUTPUT: ; [wCoordIndex] = if there is match, the matching array index ; sets carry if the coordinates are in the array, clears carry if not -CheckBoulderCoords:: ; 34e4 (0:34e4) +CheckBoulderCoords:: ; 34e1 (0:34e1) push hl ld hl, wSpriteStateData2 + $04 ld a, [H_SPRITEINDEX] @@ -2798,14 +3122,14 @@ CheckBoulderCoords:: ; 34e4 (0:34e4) pop hl jp CheckCoords -GetPointerWithinSpriteStateData1:: ; 34fc (0:34fc) +GetPointerWithinSpriteStateData1:: ; 34f9 (0:34f9) ld h, $c1 jr _GetPointerWithinSpriteStateData -GetPointerWithinSpriteStateData2:: ; 3500 (0:3500) +GetPointerWithinSpriteStateData2:: ; 34fd (0:34fd) ld h, $c2 -_GetPointerWithinSpriteStateData: +_GetPointerWithinSpriteStateData: ; 34ff (0:34ff) ld a, [H_SPRITEDATAOFFSET] ld b, a ld a, [H_SPRITEINDEX] @@ -2819,7 +3143,7 @@ _GetPointerWithinSpriteStateData: ; the final $ff will be replicated in the output list and a contains the number of bytes written ; de: input list ; hl: output list -DecodeRLEList:: ; 350c (0:350c) +DecodeRLEList:: ; 3509 (0:3509) xor a ld [wRLEByteCount], a ; count written bytes here .listLoop @@ -2846,7 +3170,7 @@ DecodeRLEList:: ; 350c (0:350c) ret ; sets movement byte 1 for sprite [H_SPRITEINDEX] to $FE and byte 2 to [hSpriteMovementByte2] -SetSpriteMovementBytesToFE:: ; 3533 (0:3533) +SetSpriteMovementBytesToFE:: ; 3530 (0:3530) push hl call GetSpriteMovementByte1Pointer ld [hl], $fe @@ -2857,7 +3181,7 @@ SetSpriteMovementBytesToFE:: ; 3533 (0:3533) ret ; sets both movement bytes for sprite [H_SPRITEINDEX] to $FF -SetSpriteMovementBytesToFF:: ; 3541 (0:3541) +SetSpriteMovementBytesToFF:: ; 353f (0:353f) push hl call GetSpriteMovementByte1Pointer ld [hl],$FF @@ -2867,7 +3191,7 @@ SetSpriteMovementBytesToFF:: ; 3541 (0:3541) ret ; returns the sprite movement byte 1 pointer for sprite [H_SPRITEINDEX] in hl -GetSpriteMovementByte1Pointer:: ; 354e (0:354e) +GetSpriteMovementByte1Pointer:: ; 354b (0:354b) ld h,$C2 ld a,[H_SPRITEINDEX] swap a @@ -2876,24 +3200,24 @@ GetSpriteMovementByte1Pointer:: ; 354e (0:354e) ret ; returns the sprite movement byte 2 pointer for sprite [H_SPRITEINDEX] in hl -GetSpriteMovementByte2Pointer:: ; 3558 (0:3558) +GetSpriteMovementByte2Pointer:: ; 3555 (0:3555) push de ld hl,W_MAPSPRITEDATA ld a,[H_SPRITEINDEX] dec a add a - ld d,0 ld e,a + ld d,0 add hl,de pop de ret -GetTrainerInformation:: ; 3566 (0:3566) +GetTrainerInformation:: ; 3563 (0:3563) call GetTrainerName ld a, [wLinkState] and a jr nz, .linkBattle - ld a, Bank(TrainerPicAndMoneyPointers) + ld a, BANK(TrainerPicAndMoneyPointers) call BankswitchHome ld a, [W_TRAINERCLASS] dec a @@ -2912,6 +3236,7 @@ GetTrainerInformation:: ; 3566 (0:3566) inc de ld a, [hli] ld [de], a + call IsFightingJessieJames jp BankswitchBack .linkBattle ld hl, wTrainerPicPointer @@ -2921,11 +3246,28 @@ GetTrainerInformation:: ; 3566 (0:3566) ld [hl], d ret -GetTrainerName:: ; 359e (0:359e) +IsFightingJessieJames:: ; 359e (0:359e) + ld a,[W_TRAINERCLASS] + cp ROCKET + ret nz + ld a,[W_TRAINERNO] + cp $2a + ret c + ld de,JessieJamesPic + cp $2e + jr c,.dummy + ld de,JessieJamesPic ; possibly meant to add another pic +.dummy + ld hl,wTrainerPicPointer + ld a,e + ld [hli],a + ld [hl],d + ret + +GetTrainerName:: ; 35bb (0:35bb) jpba GetTrainerName_ - -HasEnoughMoney:: +HasEnoughMoney:: ; 35c3 (0:35c3) ; Check if the player has at least as much ; money as the 3-byte BCD value at hMoney. ld de, wPlayerMoney @@ -2933,7 +3275,7 @@ HasEnoughMoney:: ld c, 3 jp StringCmp -HasEnoughCoins:: +HasEnoughCoins:: ; 35ce (0:35ce) ; Check if the player has at least as many ; coins as the 2-byte BCD value at hCoins. ld de, wPlayerCoins @@ -2942,22 +3284,20 @@ HasEnoughCoins:: jp StringCmp -BankswitchHome:: ; 35bc (0:35bc) +BankswitchHome:: ; 35d9 (0:35d9) ; switches to bank # in a ; Only use this when in the home bank! ld [wBankswitchHomeTemp],a ld a,[H_LOADEDROMBANK] ld [wBankswitchHomeSavedROMBank],a ld a,[wBankswitchHomeTemp] - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a + call BankswitchCommon ret -BankswitchBack:: ; 35cd (0:35cd) +BankswitchBack:: ; 35e8 (0:35e8) ; returns from BankswitchHome ld a,[wBankswitchHomeSavedROMBank] - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a + call BankswitchCommon ret Bankswitch:: ; 35d6 (0:35d6) @@ -2980,25 +3320,25 @@ Bankswitch:: ; 35d6 (0:35d6) ; displays yes/no choice ; yes -> set carry -YesNoChoice:: ; 35ec (0:35ec) +YesNoChoice:: ; 35ef (0:35ef) call SaveScreenTilesToBuffer1 call InitYesNoTextBoxParameters jr DisplayYesNoChoice -Func_35f4:: ; 35f4 (0:35f4) +Func_35f7:: ; 35f7 (0:35f7) ld a, TWO_OPTION_MENU ld [wTextBoxID], a call InitYesNoTextBoxParameters jp DisplayTextBoxID -InitYesNoTextBoxParameters:: ; 35ff (0:35ff) +InitYesNoTextBoxParameters:: ; 3602 (0:3602) xor a ; YES_NO_MENU ld [wTwoOptionMenuID], a coord hl, 14, 7 ld bc, $80f ret -YesNoChoicePokeCenter:: ; 360a (0:360a) +YesNoChoicePokeCenter:: ; 360d (0:360d) call SaveScreenTilesToBuffer1 ld a, HEAL_CANCEL_MENU ld [wTwoOptionMenuID], a @@ -3006,20 +3346,20 @@ YesNoChoicePokeCenter:: ; 360a (0:360a) lb bc, 8, 12 jr DisplayYesNoChoice -Func_361a:: ; 361a (0:361a) +Func_361d:: ; 361d (0:361d) call SaveScreenTilesToBuffer1 ld a, WIDE_YES_NO_MENU ld [wTwoOptionMenuID], a coord hl, 12, 7 lb bc, 8, 13 -DisplayYesNoChoice:: ; 3628 (0:3628) +DisplayYesNoChoice:: ; 362b (0:362b) ld a, TWO_OPTION_MENU ld [wTextBoxID], a call DisplayTextBoxID jp LoadScreenTilesFromBuffer1 ; calculates the difference |a-b|, setting carry flag if a<b -CalcDifference:: ; 3633 (0:3633) +CalcDifference:: ; 3636 (0:3636) sub b ret nc cpl @@ -3027,11 +3367,11 @@ CalcDifference:: ; 3633 (0:3633) scf ret -MoveSprite:: ; 363a (0:363a) +MoveSprite:: ; 363d (0:363d) ; move the sprite [H_SPRITEINDEX] with the movement pointed to by de ; actually only copies the movement data to wNPCMovementDirections for later call SetSpriteMovementBytesToFF -MoveSprite_:: ; 363d (0:363d) +MoveSprite_:: ; 3640 (0:3640) push hl push bc call GetSpriteMovementByte1Pointer @@ -3061,12 +3401,12 @@ MoveSprite_:: ; 363d (0:363d) dec a ld [wJoyIgnore],a ld [wWastedByteCD3A],a - ret + ret ; divides [hDividend2] by [hDivisor2] and stores the quotient in [hQuotient2] -DivideBytes:: ; 366b (0:366b) +DivideBytes:: ; 366e (0:366e) push hl - ld hl, $ffe7 + ld hl, hQuotient2 xor a ld [hld], a ld a, [hld] @@ -3085,7 +3425,7 @@ DivideBytes:: ; 366b (0:366b) ret -LoadFontTilePatterns:: +LoadFontTilePatterns:: ; 3683 (0:3683) ld a, [rLCDC] bit 7, a ; is the LCD enabled? jr nz, .on @@ -3101,7 +3441,7 @@ LoadFontTilePatterns:: lb bc, BANK(FontGraphics), (FontGraphicsEnd - FontGraphics) / $8 jp CopyVideoDataDouble ; if LCD is on, transfer during V-blank -LoadTextBoxTilePatterns:: +LoadTextBoxTilePatterns:: ; 36a3 (0:36a3) ld a, [rLCDC] bit 7, a ; is the LCD enabled? jr nz, .on @@ -3110,14 +3450,14 @@ LoadTextBoxTilePatterns:: ld de, vChars2 + $600 ld bc, TextBoxGraphicsEnd - TextBoxGraphics ld a, BANK(TextBoxGraphics) - jp FarCopyData2 ; if LCD is off, transfer all at once + jp FarCopyData ; if LCD is off, transfer all at once .on ld de, TextBoxGraphics ld hl, vChars2 + $600 lb bc, BANK(TextBoxGraphics), (TextBoxGraphicsEnd - TextBoxGraphics) / $10 jp CopyVideoData ; if LCD is on, transfer during V-blank -LoadHpBarAndStatusTilePatterns:: +LoadHpBarAndStatusTilePatterns:: ; 36c3 (0:36c3) ld a, [rLCDC] bit 7, a ; is the LCD enabled? jr nz, .on @@ -3126,30 +3466,14 @@ LoadHpBarAndStatusTilePatterns:: ld de, vChars2 + $620 ld bc, HpBarAndStatusGraphicsEnd - HpBarAndStatusGraphics ld a, BANK(HpBarAndStatusGraphics) - jp FarCopyData2 ; if LCD is off, transfer all at once + jp FarCopyData ; if LCD is off, transfer all at once .on ld de, HpBarAndStatusGraphics ld hl, vChars2 + $620 lb bc, BANK(HpBarAndStatusGraphics), (HpBarAndStatusGraphicsEnd - HpBarAndStatusGraphics) / $10 jp CopyVideoData ; if LCD is on, transfer during V-blank - -FillMemory:: -; Fill bc bytes at hl with a. - push de - ld d, a -.loop - ld a, d - ld [hli], a - dec bc - ld a, b - or c - jr nz, .loop - pop de - ret - - -UncompressSpriteFromDE:: ; 36eb (0:36eb) +UncompressSpriteFromDE:: ; 36e3 (0:36e3) ; Decompress pic at a:de. ld hl, W_SPRITEINPUTPTR ld [hl], e @@ -3157,37 +3481,34 @@ UncompressSpriteFromDE:: ; 36eb (0:36eb) ld [hl], d jp UncompressSpriteData - -SaveScreenTilesToBuffer2:: ; 36f4 (0:36f4) +SaveScreenTilesToBuffer2:: ; 36ec (0:36ec) coord hl, 0, 0 ld de, wTileMapBackup2 ld bc, SCREEN_WIDTH * SCREEN_HEIGHT - call CopyData - ret + jp CopyData -LoadScreenTilesFromBuffer2:: ; 3701 (0:3701) +LoadScreenTilesFromBuffer2:: ; 36f8 (0:36f8) call LoadScreenTilesFromBuffer2DisableBGTransfer ld a, $1 ld [H_AUTOBGTRANSFERENABLED], a ret ; loads screen tiles stored in wTileMapBackup2 but leaves H_AUTOBGTRANSFERENABLED disabled -LoadScreenTilesFromBuffer2DisableBGTransfer:: ; 3709 (0:3709) +LoadScreenTilesFromBuffer2DisableBGTransfer:: ; 3700 (0:3700) xor a ld [H_AUTOBGTRANSFERENABLED], a ld hl, wTileMapBackup2 coord de, 0, 0 ld bc, $168 - call CopyData - ret + jp CopyData -SaveScreenTilesToBuffer1:: ; 3719 (0:3719) +SaveScreenTilesToBuffer1:: ; 370f (0:370f) coord hl, 0, 0 ld de, wTileMapBackup ld bc, SCREEN_WIDTH * SCREEN_HEIGHT jp CopyData -LoadScreenTilesFromBuffer1:: ; 3725 (0:3725) +LoadScreenTilesFromBuffer1:: ; 371b (0:371b) xor a ld [H_AUTOBGTRANSFERENABLED], a ld hl, wTileMapBackup @@ -3198,21 +3519,21 @@ LoadScreenTilesFromBuffer1:: ; 3725 (0:3725) ld [H_AUTOBGTRANSFERENABLED], a ret -DelayFrames:: ; 3739 (0:3739) -; wait n frames, where n is the value in c +DelayFrames:: ; 372f (0:372f) +; wait c frames call DelayFrame dec c jr nz,DelayFrames ret -PlaySoundWaitForCurrent:: ; 3740 (0:3740) +PlaySoundWaitForCurrent:: ; 3736 (0:3736) push af call WaitForSoundToFinish pop af jp PlaySound ; Wait for sound to finish playing -WaitForSoundToFinish:: ; 3748 (0:3748) +WaitForSoundToFinish:: ; 373e (0:373e) ld a, [wLowHealthAlarm] and $80 ret nz @@ -3226,11 +3547,12 @@ WaitForSoundToFinish:: ; 3748 (0:3748) inc hl inc hl or [hl] + and a jr nz, .waitLoop pop hl ret -NamePointers:: ; 375d (0:375d) +NamePointers:: ; 3754 (0:3754) dw MonsterNames dw MoveNames dw UnusedNames @@ -3239,7 +3561,7 @@ NamePointers:: ; 375d (0:375d) dw wEnemyMonOT ; enemy's OT names list dw TrainerNames -GetName:: ; 376b (0:376b) +GetName:: ; 3762 (0:3762) ; arguments: ; [wd0b5] = which name ; [wNameListType] = which list @@ -3272,8 +3594,7 @@ GetName:: ; 376b (0:376b) .otherEntries ;2-7 = OTHER ENTRIES ld a,[wPredefBank] - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a + call BankswitchCommon ld a,[wNameListType] ;VariousNames' entryID dec a add a @@ -3320,23 +3641,21 @@ GetName:: ; 376b (0:376b) pop bc pop hl pop af - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a + call BankswitchCommon ret -GetItemPrice:: ; 37df (0:37df) +GetItemPrice:: ; 37d2 (0:37d2) ; Stores item's price as BCD at hItemPrice (3 bytes) ; Input: [wcf91] = item id ld a, [H_LOADEDROMBANK] push af ld a, [wListMenuID] cp MOVESLISTMENU - ld a, BANK(ItemPrices) - jr nz, .asm_37ed + ld a, $1 ; BANK(ItemPrices) + jr nz, .asm_37e0 ld a, $f ; hardcoded Bank -.asm_37ed - ld [H_LOADEDROMBANK], a - ld [MBC1RomBank], a +.asm_37e0 + call BankswitchCommon ld hl, wItemPrices ld a, [hli] ld h, [hl] @@ -3345,10 +3664,10 @@ GetItemPrice:: ; 37df (0:37df) cp HM_01 jr nc, .getTMPrice ld bc, $3 -.asm_3802 +.asm_37f3 add hl, bc dec a - jr nz, .asm_3802 + jr nz, .asm_37f3 dec hl ld a, [hld] ld [hItemPrice + 2], a @@ -3356,26 +3675,22 @@ GetItemPrice:: ; 37df (0:37df) ld [hItemPrice + 1], a ld a, [hl] ld [hItemPrice], a - jr .asm_381c + jr .asm_380b .getTMPrice - ld a, Bank(GetMachinePrice) - ld [H_LOADEDROMBANK], a - ld [MBC1RomBank], a - call GetMachinePrice -.asm_381c + callbs GetMachinePrice +.asm_380b ld de, hItemPrice pop af - ld [H_LOADEDROMBANK], a - ld [MBC1RomBank], a + call BankswitchCommon ret ; copies a string from [de] to [wcf4b] -CopyStringToCF4B:: ; 3826 (0:3826) +CopyStringToCF4B:: ; 3813 (0:3813) ld hl, wcf4b ; fall through ; copies a string from [de] to [hl] -CopyString:: ; 3829 (0:3829) +CopyString:: ; 3816 (0:3816) ld a, [de] inc de ld [hli], a @@ -3398,7 +3713,7 @@ CopyString:: ; 3829 (0:3829) ; report only one button press. ; 3. Same as 2, but report no buttons as pressed if A or B is held down. ; ([hJoy7] == 1, [hJoy6] == 0) -JoypadLowSensitivity:: ; 3831 (0:3831) +JoypadLowSensitivity:: ; 381e (0:381e) call Joypad ld a,[hJoy7] ; flag and a ; get all currently pressed buttons or only newly pressed buttons? @@ -3451,7 +3766,11 @@ WaitForTextScrollButtonPress:: ; 3865 (0:3865) ld a, [wTownMapSpriteBlinkingEnabled] and a jr z, .skipAnimation - call TownMapSpriteBlinkingAnimation + push de + push bc + callab TownMapSpriteBlinkingAnimation ; 1c:5753 + pop bc + pop de .skipAnimation coord hl, 18, 16 call HandleDownArrowBlinkTiming @@ -3468,12 +3787,13 @@ WaitForTextScrollButtonPress:: ; 3865 (0:3865) ret ; (unless in link battle) waits for A or B being pressed and outputs the scrolling sound effect -ManualTextScroll:: ; 3898 (0:3898) +ManualTextScroll:: ; 388e (0:388e) ld a, [wLinkState] cp LINK_STATE_BATTLING jr z, .inLinkBattle call WaitForTextScrollButtonPress - ld a, SFX_PRESS_AB + call WaitForSoundToFinish + ld a, $90 ; SFX_PRESS_AB jp PlaySound .inLinkBattle ld c, 65 @@ -3486,10 +3806,10 @@ ManualTextScroll:: ; 3898 (0:3898) ; FF99 = multiplier ; OUTPUT ; FF95-FF98 = product -Multiply:: ; 38ac (0:38ac) +Multiply:: ; 38a5 (0:38a5) push hl push bc - callab _Multiply + callab _Multiply ; 3d:660e pop bc pop hl ret @@ -3503,19 +3823,11 @@ Multiply:: ; 38ac (0:38ac) ; OUTPUT ; FF95-FF98 = quotient ; FF99 = remainder -Divide:: ; 38b9 (0:38b9) +Divide:: ; 38b2 (0:38b2) push hl push de push bc - ld a,[H_LOADEDROMBANK] - push af - ld a,Bank(_Divide) - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a - call _Divide - pop af - ld [H_LOADEDROMBANK],a - ld [MBC1RomBank],a + homecall _Divide pop bc pop de pop hl @@ -3524,7 +3836,7 @@ Divide:: ; 38b9 (0:38b9) ; This function is used to wait a short period after printing a letter to the ; screen unless the player presses the A/B button or the delay is turned off ; through the [wd730] or [wLetterPrintingDelayFlags] flags. -PrintLetterDelay:: ; 38d3 (0:38d3) +PrintLetterDelay:: ; 38c8 (0:38c8) ld a,[wd730] bit 6,a ret nz @@ -3570,7 +3882,7 @@ PrintLetterDelay:: ; 38d3 (0:38d3) ; Copies [hl, bc) to [de, bc - hl). ; In other words, the source data is from hl up to but not including bc, ; and the destination is de. -CopyDataUntil:: ; 3913 (0:3913) +CopyDataUntil:: ; 3908 (0:3908) ld a,[hli] ld [de],a inc de @@ -3586,10 +3898,10 @@ CopyDataUntil:: ; 3913 (0:3913) ; wWhichPokemon determines the pokemon. ; [wRemoveMonFromBox] == 0 specifies the party. ; [wRemoveMonFromBox] != 0 specifies the current box. -RemovePokemon:: ; 391f (0:391f) +RemovePokemon:: ; 3914 (0:3914) jpab _RemovePokemon -AddPartyMon:: ; 3927 (0:3927) +AddPartyMon:: ; 391c (0:391c) push hl push de push bc @@ -3600,7 +3912,7 @@ AddPartyMon:: ; 3927 (0:3927) ret ; calculates all 5 stats of current mon and writes them to [de] -CalcStats:: ; 3936 (0:3936) +CalcStats:: ; 392b (0:392b) ld c, $0 .statsLoop inc c @@ -3620,7 +3932,7 @@ CalcStats:: ; 3936 (0:3936) ; c: stat to calc (HP=1,Atk=2,Def=3,Spd=4,Spc=5) ; b: consider stat exp? ; hl: base ptr to stat exp values ([hl + 2*c - 1] and [hl + 2*c]) -CalcStat:: ; 394a (0:394a) +CalcStat:: ; 393f (0:393f) push hl push de push bc @@ -3799,35 +4111,17 @@ CalcStat:: ; 394a (0:394a) pop hl ret -AddEnemyMonToPlayerParty:: ; 3a53 (0:3a53) - ld a, [H_LOADEDROMBANK] - push af - ld a, BANK(_AddEnemyMonToPlayerParty) - ld [H_LOADEDROMBANK], a - ld [MBC1RomBank], a - call _AddEnemyMonToPlayerParty - pop bc - ld a, b - ld [H_LOADEDROMBANK], a - ld [MBC1RomBank], a +AddEnemyMonToPlayerParty:: ; 3a48 (0:3a48) + homecall_sf _AddEnemyMonToPlayerParty ret -MoveMon:: ; 3a68 (0:3a68) - ld a, [H_LOADEDROMBANK] - push af - ld a, BANK(_MoveMon) - ld [H_LOADEDROMBANK], a - ld [MBC1RomBank], a - call _MoveMon - pop bc - ld a, b - ld [H_LOADEDROMBANK], a - ld [MBC1RomBank], a +MoveMon:: ; 3a59 (0:3a59) + homecall_sf Func_f3a4 ret ; skips a text entries, each of size NAME_LENGTH (like trainer name, OT name, rival name, ...) ; hl: base pointer, will be incremented by NAME_LENGTH * a -SkipFixedLengthTextEntries:: ; 3a7d (0:3a7d) +SkipFixedLengthTextEntries:: ; 3a6a (0:3a6a) and a ret z ld bc, NAME_LENGTH @@ -3837,7 +4131,7 @@ SkipFixedLengthTextEntries:: ; 3a7d (0:3a7d) jr nz, .skipLoop ret -AddNTimes:: ; 3a87 (0:3a87) +AddNTimes:: ; 3a74 (0:3a74) ; add bc to hl a times and a ret z @@ -3849,7 +4143,7 @@ AddNTimes:: ; 3a87 (0:3a87) ; Compare strings, c bytes in length, at de and hl. ; Often used to compare big endian numbers in battle calculations. -StringCmp:: ; 3a8e (0:3a8e) +StringCmp:: ; 3a7b (0:3a7b) ld a,[de] cp [hl] ret nz @@ -3864,7 +4158,7 @@ StringCmp:: ; 3a8e (0:3a8e) ; b = Y coordinate of upper left corner of sprite ; c = X coordinate of upper left corner of sprite ; de = base address of 4 tile number and attribute pairs -WriteOAMBlock:: ; 3a97 (0:3a97) +WriteOAMBlock:: ; 3a84 (0:3a84) ld h,wOAMBuffer / $100 swap a ; multiply by 16 ld l,a @@ -3883,7 +4177,7 @@ WriteOAMBlock:: ; 3a97 (0:3a97) add c ld c,a ; lower right -.writeOneEntry +.writeOneEntry ; 3aa0 (0:3aa0) ld [hl],b ; Y coordinate inc hl ld [hl],c ; X coordinate @@ -3896,11 +4190,11 @@ WriteOAMBlock:: ; 3a97 (0:3a97) ld [hli],a ret -HandleMenuInput:: ; 3abe (0:3abe) +HandleMenuInput:: ; 3aab (0:3aab) xor a ld [wPartyMenuAnimMonEnabled],a -HandleMenuInput_:: ; 3ac2 (0:3ac2) +HandleMenuInputPokemonSelection:: ; 3aaf (0:3aaf) ld a,[H_DOWNARROWBLINKCNT1] push af ld a,[H_DOWNARROWBLINKCNT2] @@ -3919,7 +4213,7 @@ HandleMenuInput_:: ; 3ac2 (0:3ac2) ld a,[wPartyMenuAnimMonEnabled] and a ; is it a pokemon selection menu? jr z,.getJoypadState - callba AnimatePartyMon ; shake mini sprite of selected pokemon + callba AnimatePartyMon ; shake mini sprite of selected pokemon (1c:578c) .getJoypadState pop hl call JoypadLowSensitivity @@ -3948,6 +4242,8 @@ HandleMenuInput_:: ; 3ac2 (0:3ac2) ld [wCheckFor180DegreeTurn],a ld a,[hJoy5] ld b,a + bit 0,a ; pressed A key? + jr nz,.checkOtherKeys bit 6,a ; pressed Up key? jr z,.checkIfDownPressed .upPressed @@ -3997,8 +4293,8 @@ HandleMenuInput_:: ; 3ac2 (0:3ac2) bit 5,[hl] pop hl jr nz,.skipPlayingSound - ld a,SFX_PRESS_AB - call PlaySound + ld a, $90 ; SFX_PRESS_AB + call PlaySound ; play sound .skipPlayingSound pop af ld [H_DOWNARROWBLINKCNT2],a @@ -4014,7 +4310,7 @@ HandleMenuInput_:: ; 3ac2 (0:3ac2) jr z,.checkOtherKeys jr .checkIfAButtonOrBButtonPressed -PlaceMenuCursor:: ; 3b7c (0:3b7c) +PlaceMenuCursor:: ; 3b6d (0:3b6d) ld a,[wTopMenuItemY] and a ; is the y coordinate 0? jr z,.adjustForXCoord @@ -4033,15 +4329,13 @@ PlaceMenuCursor:: ; 3b7c (0:3b7c) ld a,[wLastMenuItem] and a ; was the previous menu id 0? jr z,.checkForArrow1 + ld bc,40 push af - ld a,[hFlags_0xFFF6] + ld a,[hFlags_0xFFFA] bit 1,a ; is the menu double spaced? jr z,.doubleSpaced1 ld bc,20 - jr .getOldMenuItemScreenPosition .doubleSpaced1 - ld bc,40 -.getOldMenuItemScreenPosition pop af .oldMenuItemLoop add hl,bc @@ -4059,15 +4353,13 @@ PlaceMenuCursor:: ; 3b7c (0:3b7c) ld a,[wCurrentMenuItem] and a jr z,.checkForArrow2 + ld bc,40 push af - ld a,[hFlags_0xFFF6] + ld a,[hFlags_0xFFFA] bit 1,a ; is the menu double spaced? jr z,.doubleSpaced2 ld bc,20 - jr .getCurrentMenuItemScreenPosition .doubleSpaced2 - ld bc,40 -.getCurrentMenuItemScreenPosition pop af .currentMenuItemLoop add hl,bc @@ -4093,7 +4385,7 @@ PlaceMenuCursor:: ; 3b7c (0:3b7c) ; manipulated. In the case of submenus, this is used to show the location of ; the menu cursor in the parent menu. In the case of swapping items in list, ; this is used to mark the item that was first chosen to be swapped. -PlaceUnfilledArrowMenuCursor:: ; 3bec (0:3bec) +PlaceUnfilledArrowMenuCursor:: ; 3bd9 (0:3bd9) ld b,a ld a,[wMenuCursorLocation] ld l,a @@ -4104,7 +4396,7 @@ PlaceUnfilledArrowMenuCursor:: ; 3bec (0:3bec) ret ; Replaces the menu cursor with a blank space. -EraseMenuCursor:: ; 3bf9 (0:3bf9) +EraseMenuCursor:: ; 3be6 (0:3be6) ld a,[wMenuCursorLocation] ld l,a ld a,[wMenuCursorLocation + 1] @@ -4120,7 +4412,7 @@ EraseMenuCursor:: ; 3bf9 (0:3bf9) ; initliazed with a down arrow, this function does nothing. ; That allows this to be called without worrying about if a down arrow should ; be blinking. -HandleDownArrowBlinkTiming:: ; 3c04 (0:3c04) +HandleDownArrowBlinkTiming:: ; 3bf1 (0:3bf1) ld a,[hl] ld b,a ld a,$ee ; down arrow @@ -4135,7 +4427,7 @@ HandleDownArrowBlinkTiming:: ; 3c04 (0:3c04) dec a ld [H_DOWNARROWBLINKCNT2],a ret nz - ld a," " + ld a," " ld [hl],a ld a,$ff ld [H_DOWNARROWBLINKCNT1],a @@ -4165,20 +4457,20 @@ HandleDownArrowBlinkTiming:: ; 3c04 (0:3c04) ; text boxes by DisplayTextID. Both functions cause DisplayTextID to wait ; for a button press after displaying text (unless [wEnteringCableClub] is set). -EnableAutoTextBoxDrawing:: ; 3c3c (0:3c3c) +EnableAutoTextBoxDrawing:: ; 3c29 (0:3c29) xor a jr AutoTextBoxDrawingCommon -DisableAutoTextBoxDrawing:: ; 3c3f (0:3c3f) +DisableAutoTextBoxDrawing:: ; 3c2c (0:3c2c) ld a,$01 -AutoTextBoxDrawingCommon:: ; 3c41 (0:3c41) +AutoTextBoxDrawingCommon:: ; 3c2e (0:3c2d) ld [wAutoTextBoxDrawingControl],a xor a ld [wDoNotWaitForButtonPressAfterDisplayingText],a ; make DisplayTextID wait for button press ret -PrintText:: ; 3c49 (0:3c49) +PrintText:: ; 3c36 (0:3c36) ; Print text hl at (1, 14). push hl ld a,MESSAGE_BOX @@ -4187,12 +4479,22 @@ PrintText:: ; 3c49 (0:3c49) call UpdateSprites call Delay3 pop hl -PrintText_NoCreatingTextBox:: ; 3c59 (0:3c59) +PrintText_NoCreatingTextBox:: ; 3c46 (0:3c46) coord bc, 1, 14 jp TextCommandProcessor - -PrintNumber:: ; 3c5f +FarPrintText:: ; 3c4c (0:3c4c) +; print text b:hl at (1, 14) + ld a,[H_LOADEDROMBANK] + push af + ld a,b + call BankswitchCommon + call PrintText + pop af + call BankswitchCommon + ret + +PrintNumber:: ; 3c5b (0:3c5b) ; Print the c-digit, b-byte value at de. ; Allows 2 to 7 digits. For 1-digit numbers, add ; the value to char "0" instead of calling PrintNumber. @@ -4314,7 +4616,7 @@ endm pop bc ret -.PrintDigit: +.PrintDigit: ; 3d21 (0:3d21) ; Divide by the current decimal place. ; Print the quotient, and keep the modulus. ld c, 0 @@ -4389,13 +4691,13 @@ endm ld [H_PASTLEADINGZEROES], a ret -.PrintLeadingZero: +.PrintLeadingZero: ; 3d7f (0:3d7f) bit BIT_LEADING_ZEROES, d ret z ld [hl], "0" ret -.NextDigit: +.NextDigit: ; 3d85 (0:3d85) ; Increment unless the number is left-aligned, ; leading zeroes are not printed, and no digits ; have been printed yet. @@ -4411,7 +4713,7 @@ endm ret -CallFunctionInTable:: +CallFunctionInTable:: ; 3d93 (0:3d93) JumpTable:: ; Call function a in jumptable hl. ; de is not preserved. @@ -4435,13 +4737,13 @@ JumpTable:: ret -IsInArray:: +IsInArray:: ; 3da7 (0:3da7) ; Search an array at hl for the value in a. ; Entry size is de bytes. ; Return count b and carry if found. ld b, 0 -IsInRestOfArray:: +IsInRestOfArray:: ; 3da9 (0:3da9) ld c, a .loop ld a, [hl] @@ -4461,8 +4763,12 @@ IsInRestOfArray:: scf ret +InitMapSprites:: ; 3dba (0:3dba) + ld hl, _InitMapSprites ; 1401b (5:401b) + ld b,BANK(_InitMapSprites) + jp Bankswitch -RestoreScreenTilesAndReloadTilePatterns:: ; 3dbe (0:3dbe) +RestoreScreenTilesAndReloadTilePatterns:: ; 3dc2 (0:3dc2) call ClearSprites ld a, $1 ld [wUpdateSpritesEnabled], a @@ -4473,41 +4779,47 @@ RestoreScreenTilesAndReloadTilePatterns:: ; 3dbe (0:3dbe) jr Delay3 -GBPalWhiteOutWithDelay3:: +GBPalWhiteOutWithDelay3:: ; 3dd8 (0:3dd8) call GBPalWhiteOut -Delay3:: +Delay3:: ; 3ddb (0:3ddb) ; The bg map is updated each frame in thirds. ; Wait three frames to let the bg map fully update. ld c, 3 jp DelayFrames -GBPalNormal:: +GBPalNormal:: ; 3de0 (0:3de0) ; Reset BGP and OBP0. ld a, %11100100 ; 3210 ld [rBGP], a ld a, %11010000 ; 3100 ld [rOBP0], a + call Func_3021 + call Func_3040 + call Func_3061 ret -GBPalWhiteOut:: +GBPalWhiteOut:: ; 3df2 (0:3df2) ; White out all palettes. xor a ld [rBGP],a ld [rOBP0],a ld [rOBP1],a + call Func_3021 + call Func_3040 + call Func_3061 ret -RunDefaultPaletteCommand:: ; 3ded (0:3ded) +RunDefaultPaletteCommand:: ; 3e03 (0:3e03) ld b,$ff -RunPaletteCommand:: ; 3def (0:3def) +RunPaletteCommand:: ; 3e05 (0:3e05) ld a,[wOnSGB] and a ret z predef_jump _RunPaletteCommand -GetHealthBarColor:: +GetHealthBarColor:: ; 3e0f (0:3e0f) ; Return at hl the palette of ; an HP bar e pixels long. ld a, e @@ -4524,7 +4836,7 @@ GetHealthBarColor:: ; Copy the current map's sprites' tile patterns to VRAM again after they have ; been overwritten by other tile patterns. -ReloadMapSpriteTilePatterns:: ; 3e08 (0:3e08) +ReloadMapSpriteTilePatterns:: ; 3e1e (0:3e1e) ld hl, wFontLoaded ld a, [hl] push af @@ -4533,7 +4845,7 @@ ReloadMapSpriteTilePatterns:: ; 3e08 (0:3e08) xor a ld [W_SPRITESETID], a call DisableLCD - callba InitMapSprites + call InitMapSprites call EnableLCD pop hl pop af @@ -4543,7 +4855,7 @@ ReloadMapSpriteTilePatterns:: ; 3e08 (0:3e08) jp UpdateSprites -GiveItem:: +GiveItem:: ; 3e3f (0:3e3f) ; Give player quantity c of item b, ; and copy the item's name to wcf4b. ; Return carry on success. @@ -4560,7 +4872,7 @@ GiveItem:: scf ret -GivePokemon:: +GivePokemon:: ; 3e59 (0:3e59) ; Give the player monster b at level c. ld a, b ld [wcf91], a @@ -4568,10 +4880,11 @@ GivePokemon:: ld [W_CURENEMYLVL], a xor a ; PLAYER_PARTY_DATA ld [wMonDataLocation], a - jpba _GivePokemon - + jpba _GivePokemon ; 3d:66fa + ld hl, _GivePokemon + jp Bankswitch -Random:: +Random:: ; 3e6d (0:3e6d) ; Return a random number in a. ; For battles, use BattleRandom. push hl @@ -4584,37 +4897,73 @@ Random:: pop hl ret +BankswitchCommon:: ; 3e7e (0:3e7e) + ld [H_LOADEDROMBANK],a + ld [$2000],a + ret + +Bankswitch:: ; 3e84 (0:3e84) +; self-contained bankswitch, use this when not in the home bank +; switches to the bank in b + ld a,[H_LOADEDROMBANK] + push af + ld a,b + ld [H_LOADEDROMBANK],a + ld [$2000],a + call JumpToAddress + pop bc + ld a,b + ld [H_LOADEDROMBANK],a + ld [$2000],a + ret +JumpToAddress:: ; 3e98 (0:3e98) + jp [hl] +SwitchSRAMBankAndLatchClockData:: ; 3e99 (0:3e99) + push af + ld a,$1 + ld [$6000],a + ld a,SRAM_ENABLE + ld [$0],a + pop af + ld [$4000],a + ret + +PrepareRTCDataAndDisableSRAM:: ; 3ea9 (0:3ea9) + push af + ld a,$0 + ld [$6000],a + ld [$0],a + pop af + ret + INCLUDE "home/predef.asm" +UpdateCinnabarGymGateTileBlocks:: ; 3ef0 (0:3ef0) + callba CinnabarGymQuiz_1eb0a + ret ; again? + ;jp Bankswitch -UpdateCinnabarGymGateTileBlocks:: ; 3ead (0:3ead) - jpba UpdateCinnabarGymGateTileBlocks_ - -CheckForHiddenObjectOrBookshelfOrCardKeyDoor:: ; 3eb5 (0:3eb5) +CheckForHiddenObjectOrBookshelfOrCardKeyDoor:: ; 3ef9 (0:3ef9) ld a, [H_LOADEDROMBANK] push af ld a, [hJoyHeld] bit 0, a ; A button jr z, .nothingFound ; A button is pressed - ld a, Bank(CheckForHiddenObject) - ld [MBC1RomBank], a - ld [H_LOADEDROMBANK], a - call CheckForHiddenObject + callbs CheckForHiddenObject ld a, [$ffee] and a jr nz, .hiddenObjectNotFound - ld a, [wHiddenObjectFunctionRomBank] - ld [MBC1RomBank], a - ld [H_LOADEDROMBANK], a - ld de, .returnAddress - push de - jp [hl] -.returnAddress xor a + ld [$ffeb],a + ld a, [wHiddenObjectFunctionRomBank] + call BankswitchCommon + call JumpToAddress + ld a,[$ffeb] jr .done .hiddenObjectNotFound + predef GetTileAndCoordsInFrontOfPlayer callba PrintBookshelfText ld a, [$ffdb] and a @@ -4624,19 +4973,18 @@ CheckForHiddenObjectOrBookshelfOrCardKeyDoor:: ; 3eb5 (0:3eb5) .done ld [$ffeb], a pop af - ld [MBC1RomBank], a - ld [H_LOADEDROMBANK], a + call BankswitchCommon ret -PrintPredefTextID:: ; 3ef5 (0:3ef5) - ld [hSpriteIndexOrTextID], a +PrintPredefTextID:: ; 3f3a (0:3f3a) + ld [hSpriteIndexOrTextID], a ; $ff8c ld hl, TextPredefs call SetMapTextPointer ld hl, wTextPredefFlag set 0, [hl] call DisplayTextID -RestoreMapTextPointer:: ; 3f05 (0:3f05) +RestoreMapTextPointer:: ; 3f4a (0:3f4a) ld hl, W_MAPTEXTPTR ld a, [$ffec] ld [hli], a @@ -4644,7 +4992,7 @@ RestoreMapTextPointer:: ; 3f05 (0:3f05) ld [hl], a ret -SetMapTextPointer:: ; 3f0f (0:3f0f) +SetMapTextPointer:: ; 3f54 (0:3f54) ld a, [W_MAPTEXTPTR] ld [$ffec], a ld a, [W_MAPTEXTPTR + 1] @@ -4655,70 +5003,71 @@ SetMapTextPointer:: ; 3f0f (0:3f0f) ld [W_MAPTEXTPTR + 1], a ret -TextPredefs:: - add_tx_pre CardKeySuccessText ; 01 - add_tx_pre CardKeyFailText ; 02 - add_tx_pre RedBedroomPCText ; 03 - add_tx_pre RedBedroomSNESText ; 04 - add_tx_pre PushStartText ; 05 - add_tx_pre SaveOptionText ; 06 - add_tx_pre StrengthsAndWeaknessesText ; 07 - add_tx_pre OakLabEmailText ; 08 - add_tx_pre AerodactylFossilText ; 09 - add_tx_pre Route15UpstairsBinocularsText ; 0A - add_tx_pre KabutopsFossilText ; 0B - add_tx_pre GymStatueText1 ; 0C - add_tx_pre GymStatueText2 ; 0D - add_tx_pre BookcaseText ; 0E - add_tx_pre ViridianCityPokecenterBenchGuyText ; 0F - add_tx_pre PewterCityPokecenterBenchGuyText ; 10 - add_tx_pre CeruleanCityPokecenterBenchGuyText ; 11 - add_tx_pre LavenderCityPokecenterBenchGuyText ; 12 - add_tx_pre VermilionCityPokecenterBenchGuyText ; 13 - add_tx_pre CeladonCityPokecenterBenchGuyText ; 14 - add_tx_pre CeladonCityHotelText ; 15 - add_tx_pre FuchsiaCityPokecenterBenchGuyText ; 16 - add_tx_pre CinnabarIslandPokecenterBenchGuyText ; 17 - add_tx_pre SaffronCityPokecenterBenchGuyText ; 18 - add_tx_pre MtMoonPokecenterBenchGuyText ; 19 - add_tx_pre RockTunnelPokecenterBenchGuyText ; 1A - add_tx_pre UnusedBenchGuyText1 ; 1B XXX unused - add_tx_pre UnusedBenchGuyText2 ; 1C XXX unused - add_tx_pre UnusedBenchGuyText3 ; 1D XXX unused - add_tx_pre UnusedPredefText ; 1E XXX unused - add_tx_pre PokemonCenterPCText ; 1F - add_tx_pre ViridianSchoolNotebook ; 20 - add_tx_pre ViridianSchoolBlackboard ; 21 - add_tx_pre JustAMomentText ; 22 - add_tx_pre OpenBillsPCText ; 23 - add_tx_pre FoundHiddenItemText ; 24 - add_tx_pre HiddenItemBagFullText ; 25 XXX unused - add_tx_pre VermilionGymTrashText ; 26 - add_tx_pre IndigoPlateauHQText ; 27 - add_tx_pre GameCornerOutOfOrderText ; 28 - add_tx_pre GameCornerOutToLunchText ; 29 - add_tx_pre GameCornerSomeonesKeysText ; 2A - add_tx_pre FoundHiddenCoinsText ; 2B - add_tx_pre DroppedHiddenCoinsText ; 2C - add_tx_pre BillsHouseMonitorText ; 2D - add_tx_pre BillsHouseInitiatedText ; 2E - add_tx_pre BillsHousePokemonList ; 2F - add_tx_pre MagazinesText ; 30 - add_tx_pre CinnabarGymQuiz ; 31 - add_tx_pre GameCornerNoCoinsText ; 32 - add_tx_pre GameCornerCoinCaseText ; 33 - add_tx_pre LinkCableHelp ; 34 - add_tx_pre TMNotebook ; 35 - add_tx_pre FightingDojoText ; 36 - add_tx_pre FightingDojoText_52a10 ; 37 - add_tx_pre FightingDojoText_52a1d ; 38 - add_tx_pre NewBicycleText ; 39 - add_tx_pre IndigoPlateauStatues ; 3A - add_tx_pre VermilionGymTrashSuccesText1 ; 3B - add_tx_pre VermilionGymTrashSuccesText2 ; 3C XXX unused - add_tx_pre VermilionGymTrashSuccesText3 ; 3D - add_tx_pre VermilionGymTrashFailText ; 3E - add_tx_pre TownMapText ; 3F - add_tx_pre BookOrSculptureText ; 40 - add_tx_pre ElevatorText ; 41 - add_tx_pre PokemonStuffText ; 42 +TextPredefs:: ; 3f67 (0:3f67) + dr $3f67,$4000 +; add_tx_pre CardKeySuccessText ; 01 +; add_tx_pre CardKeyFailText ; 02 +; add_tx_pre RedBedroomPC ; 03 +; add_tx_pre RedBedroomSNESText ; 04 +; add_tx_pre PushStartText ; 05 +; add_tx_pre SaveOptionText ; 06 +; add_tx_pre StrengthsAndWeaknessesText ; 07 +; add_tx_pre OakLabEmailText ; 08 +; add_tx_pre AerodactylFossilText ; 09 +; add_tx_pre Route15UpstairsBinocularsText ; 0A +; add_tx_pre KabutopsFossilText ; 0B +; add_tx_pre GymStatueText1 ; 0C +; add_tx_pre GymStatueText2 ; 0D +; add_tx_pre BookcaseText ; 0E +; add_tx_pre ViridianCityPokecenterBenchGuyText ; 0F +; add_tx_pre PewterCityPokecenterBenchGuyText ; 10 +; add_tx_pre CeruleanCityPokecenterBenchGuyText ; 11 +; add_tx_pre LavenderCityPokecenterBenchGuyText ; 12 +; add_tx_pre VermilionCityPokecenterBenchGuyText ; 13 +; add_tx_pre CeladonCityPokecenterBenchGuyText ; 14 +; add_tx_pre CeladonCityHotelText ; 15 +; add_tx_pre FuchsiaCityPokecenterBenchGuyText ; 16 +; add_tx_pre CinnabarIslandPokecenterBenchGuyText ; 17 +; add_tx_pre SaffronCityPokecenterBenchGuyText ; 18 +; add_tx_pre MtMoonPokecenterBenchGuyText ; 19 +; add_tx_pre RockTunnelPokecenterBenchGuyText ; 1A +; add_tx_pre UnusedBenchGuyText1 ; 1B +; add_tx_pre UnusedBenchGuyText2 ; 1C +; add_tx_pre UnusedBenchGuyText3 ; 1D +; add_tx_pre TerminatorText_62508 ; 1E +; add_tx_pre PredefText1f ; 1F +; add_tx_pre ViridianSchoolNotebook ; 20 +; add_tx_pre ViridianSchoolBlackboard ; 21 +; add_tx_pre JustAMomentText ; 22 +; add_tx_pre PredefText23 ; 23 +; add_tx_pre FoundHiddenItemText ; 24 +; add_tx_pre HiddenItemBagFullText ; 25 +; add_tx_pre VermilionGymTrashText ; 26 +; add_tx_pre IndigoPlateauHQText ; 27 +; add_tx_pre GameCornerOutOfOrderText ; 28 +; add_tx_pre GameCornerOutToLunchText ; 29 +; add_tx_pre GameCornerSomeonesKeysText ; 2A +; add_tx_pre FoundHiddenCoinsText ; 2B +; add_tx_pre DroppedHiddenCoinsText ; 2C +; add_tx_pre BillsHouseMonitorText ; 2D +; add_tx_pre BillsHouseInitiatedText ; 2E +; add_tx_pre BillsHousePokemonList ; 2F +; add_tx_pre MagazinesText ; 30 +; add_tx_pre CinnabarGymQuiz ; 31 +; add_tx_pre GameCornerNoCoinsText ; 32 +; add_tx_pre GameCornerCoinCaseText ; 33 +; add_tx_pre LinkCableHelp ; 34 +; add_tx_pre TMNotebook ; 35 +; add_tx_pre FightingDojoText ; 36 +; add_tx_pre FightingDojoText_52a10 ; 37 +; add_tx_pre FightingDojoText_52a1d ; 38 +; add_tx_pre NewBicycleText ; 39 +; add_tx_pre IndigoPlateauStatues ; 3A +; add_tx_pre VermilionGymTrashSuccesText1 ; 3B +; add_tx_pre VermilionGymTrashSuccesText2 ; 3C +; add_tx_pre VermilionGymTrashSuccesText3 ; 3D +; add_tx_pre VermilionGymTrashFailText ; 3E +; add_tx_pre TownMapText ; 3F +; add_tx_pre BookOrSculptureText ; 40 +; add_tx_pre ElevatorText ; 41 +; add_tx_pre PokemonStuffText ; 42 |