summaryrefslogtreecommitdiff
path: root/home.asm
diff options
context:
space:
mode:
Diffstat (limited to 'home.asm')
-rw-r--r--home.asm2834
1 files changed, 1524 insertions, 1310 deletions
diff --git a/home.asm b/home.asm
index 0db583a6..336bfb1f 100644
--- a/home.asm
+++ b/home.asm
@@ -21,8 +21,8 @@ SECTION "rst 38", ROM0 [$38]
SECTION "vblank", ROM0 [$40]
jp VBlank
SECTION "hblank", ROM0 [$48]
- rst $38
-SECTION "timer", ROM0 [$50]
+ jp LCDC
+SECTION "timer", ROM0 [$50]
jp Timer
SECTION "serial", ROM0 [$58]
jp Serial
@@ -87,7 +87,7 @@ INCLUDE "home/copy.asm"
SECTION "Entry", ROM0 [$100]
nop
- jp Start
+ jp Start ; 01ab
SECTION "Header", ROM0 [$104]
@@ -101,25 +101,74 @@ SECTION "Header", ROM0 [$104]
SECTION "Main", ROM0
+PlayPikachuPCM::
+ 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
+.playSingleSample
+ dec a
+ jr nz, .playSingleSample
+
+ rept 7
+ call LoadNextSoundClipSample
+ call PlaySoundClipSample
+ endr
+
+ call LoadNextSoundClipSample
+ dec bc
+ ld a, c
+ or b
+ jr nz, .loop
+ pop af
+ call BankswitchCommon
+ ret
+
+LoadNextSoundClipSample::
+ ld a, d
+ and $80
+ srl a
+ srl a
+ ld [rNR32], a
+ sla d
+ ret
+
+PlaySoundClipSample::
+ ld a, $3
+.loop
+ dec a
+ jr nz, .loop
+ 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::
+ homecall_jump _Joypad
-INCLUDE "home/joypad.asm"
-INCLUDE "data/map_header_pointers.asm"
-INCLUDE "home/overworld.asm"
+ReadJoypad::
+ homecall_jump ReadJoypad_
+INCLUDE "home/overworld.asm"
CheckForUserInterruption::
-; Return carry if Up+Select+B, Start or A are pressed in c frames.
+; Return carry if Up + Select + B, Start or A are pressed in c frames.
; Used only in the intro and title screen.
call DelayFrame
@@ -149,24 +198,24 @@ CheckForUserInterruption::
; INPUT:
; a = ID of destination warp within destination map
LoadDestinationWarpPosition::
- ld b,a
- ld a,[H_LOADEDROMBANK]
+ ld b, a
+ ld a, [H_LOADEDROMBANK]
push af
- ld a,[wPredefParentBank]
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
- ld a,b
+ ld a, [wPredefParentBank]
+ ld [H_LOADEDROMBANK], a
+ ld [MBC1RomBank], a
+ ld a, b
add a
add a
- ld c,a
- ld b,0
- add hl,bc
- ld bc,4
- ld de,wCurrentTileBlockMapViewPointer
+ ld c, a
+ ld b, 0
+ add hl, bc
+ ld bc, 4
+ ld de, wCurrentTileBlockMapViewPointer
call CopyData
pop af
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
+ ld [H_LOADEDROMBANK], a
+ ld [MBC1RomBank], a
ret
@@ -177,7 +226,7 @@ DrawHPBar::
push hl
push de
- push bc
+ ;push bc
; Left
ld a, $71 ; "HP:"
@@ -190,18 +239,18 @@ DrawHPBar::
; Middle
ld a, $63 ; empty
.draw
- ld [hli],a
+ ld [hli], a
dec d
jr nz, .draw
; Right
- ld a,[wHPBarType]
+ ld a, [wHPBarType]
dec a
ld a, $6d ; status screen and battle
jr z, .ok
dec a ; pokemon menu
.ok
- ld [hl],a
+ ld [hl], a
pop hl
@@ -233,7 +282,7 @@ DrawHPBar::
add e
ld [hl], a
.done
- pop bc
+ ;pop bc
pop de
pop hl
ret
@@ -251,11 +300,10 @@ DrawHPBar::
; OUTPUT:
; [wcf91] = pokemon ID
; wLoadedMon = base address of pokemon data
-; wMonHeader = base address of base stats
+; W_MONHDEXNUM = base address of base stats
LoadMonData::
jpab LoadMonData_
-
OverwritewMoves::
; Write c to [wMoves + b]. Unused.
ld hl, wMoves
@@ -297,25 +345,31 @@ LoadFrontSpriteByMonIndex::
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 [wSpriteFlipped], a
pop af
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
- ret
-
+ jp BankswitchCommon
PlayCry::
; 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::
; Load cry data for monster a.
@@ -327,7 +381,7 @@ GetCryData::
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,12 +401,11 @@ GetCryData::
add c
ret
-
DisplayPartyMenu::
- ld a,[hTilesetType]
+ ld a, [hTilesetType]
push af
xor a
- ld [hTilesetType],a
+ ld [hTilesetType], a
call GBPalWhiteOutWithDelay3
call ClearSprites
call PartyMenuInit
@@ -360,10 +413,10 @@ DisplayPartyMenu::
jp HandlePartyMenuInput
GoBackToPartyMenu::
- ld a,[hTilesetType]
+ ld a, [hTilesetType]
push af
xor a
- ld [hTilesetType],a
+ ld [hTilesetType], a
call PartyMenuInit
call RedrawPartyMenu
jp HandlePartyMenuInput
@@ -408,67 +461,90 @@ PartyMenuInit::
ret
HandlePartyMenuInput::
- ld a,1
- ld [wMenuWrappingEnabled],a
- ld a,$40
- ld [wPartyMenuAnimMonEnabled],a
- call HandleMenuInput_
+ ld a, 1
+ ld [wMenuWrappingEnabled], a
+ ld a, $40
+ ld [wPartyMenuAnimMonEnabled], 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 IsThisPartymonStarterPikachu_Party ; 3f:4e18
+ jr nc, .asm_1258
+ call CheckPikachuFollowingPlayer
+ jr nz, .asm_128f
+.asm_1258
+ pop af
call PlaceUnfilledArrowMenuCursor
- ld b,a
- xor a
- ld [wPartyMenuAnimMonEnabled],a
- ld a,[wCurrentMenuItem]
- ld [wPartyAndBillsPCSavedMenuItem],a
- ld hl,wd730
- res 6,[hl] ; turn on letter printing delay
- ld a,[wMenuItemToSwap]
+ ld b, a
+ ld hl, wd730
+ res 6, [hl] ; turn on letter printing delay
+ ld a, [wMenuItemToSwap]
and a
- jp nz,.swappingPokemon
- pop af
- ld [hTilesetType],a
- bit 1,b
- jr nz,.noPokemonChosen
- ld a,[wPartyCount]
+ jp nz, .swappingPokemon
+ pop af ; double pop af?
+ ld [hTilesetType], a
+ bit 1, b
+ jr nz, .noPokemonChosen
+ ld a, [wPartyCount]
and a
- jr z,.noPokemonChosen
- ld a,[wCurrentMenuItem]
- ld [wWhichPokemon],a
- ld hl,wPartySpecies
- ld b,0
- ld c,a
- add hl,bc
- ld a,[hl]
- ld [wcf91],a
- ld [wBattleMonSpecies2],a
+ jr z, .noPokemonChosen
+ ld a, [wCurrentMenuItem]
+ ld [wWhichPokemon], a
+ ld hl, wPartySpecies
+ ld b, 0
+ ld c, a
+ add hl, bc
+ ld a, [hl]
+ ld [wcf91], a
+ ld [wBattleMonSpecies2], a
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
ret
.swappingPokemon
- bit 1,b ; was the B button pressed?
- jr z,.handleSwap ; if not, handle swapping the pokemon
+ 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
+ ld [wMenuItemToSwap], a
+ ld [wPartyMenuTypeOrMessageID], a
call RedrawPartyMenu
- jr HandlePartyMenuInput
+ jp HandlePartyMenuInput
.handleSwap
- ld a,[wCurrentMenuItem]
- ld [wWhichPokemon],a
- callba SwitchPartyMon
- jr HandlePartyMenuInput
+ ld a, [wCurrentMenuItem]
+ ld [wWhichPokemon], a
+ callba SwitchPartyMon ; 4:61c5
+ jp HandlePartyMenuInput
+
+PartyMenuText_12cc::
+ TX_FAR _SleepingPikachuText1 ; 28:411b
+ db "@"
DrawPartyMenu::
- ld hl, DrawPartyMenu_
+ ld hl, DrawPartyMenu_ ; 4:5875
jr DrawPartyMenuCommon
RedrawPartyMenu::
- ld hl, RedrawPartyMenu_
+ ld hl, RedrawPartyMenu_ ; 4:5886
DrawPartyMenuCommon::
ld b, BANK(RedrawPartyMenu_)
@@ -482,45 +558,36 @@ PrintStatusCondition::
push de
dec de
dec de ; de = address of current HP
- ld a,[de]
- ld b,a
+ ld a, [de]
+ ld b, a
dec de
- ld a,[de]
+ ld a, [de]
or b ; is the pokemon's HP zero?
pop de
- jr nz,PrintStatusConditionNotFainted
+ jr nz, PrintStatusConditionNotFainted
; if the pokemon's HP is 0, print "FNT"
- ld a,"F"
- ld [hli],a
- ld a,"N"
- ld [hli],a
- ld [hl],"T"
+ ld a, "F"
+ ld [hli], a
+ ld a, "N"
+ ld [hli], a
+ 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:
+ 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::
- ld a,$6e ; ":L" tile ID
- ld [hli],a
- ld c,2 ; number of digits
- ld a,[wLoadedMonLevel] ; level
- cp a,100
- jr c,PrintLevelCommon
+ ld a, $6e ; ":L" tile ID
+ ld [hli], a
+ ld c, 2 ; number of digits
+ ld a, [wLoadedMonLevel] ; level
+ cp 100
+ jr c, PrintLevelCommon
; if level at least 100, write over the ":L" tile
dec hl
inc c ; increment number of digits to 3
@@ -531,105 +598,95 @@ PrintLevel::
; hl = destination address
; [wLoadedMonLevel] = level
PrintLevelFull::
- ld a,$6e ; ":L" tile ID
- ld [hli],a
- ld c,3 ; number of digits
- ld a,[wLoadedMonLevel] ; level
+ ld a, $6e ; ":L" tile ID
+ ld [hli], a
+ ld c, 3 ; number of digits
+ ld a, [wLoadedMonLevel] ; level
PrintLevelCommon::
- ld [wd11e],a
- ld de,wd11e
- ld b,LEFT_ALIGN | 1 ; 1 byte
+ ld [wd11e], a
+ ld de, wd11e
+ ld b, LEFT_ALIGN | 1 ; 1 byte
jp PrintNumber
GetwMoves::
; Unused. Returns the move at index a from wMoves in a
- ld hl,wMoves
- ld c,a
- ld b,0
- add hl,bc
- ld a,[hl]
+ ld hl, wMoves
+ ld c, a
+ ld b, 0
+ add hl, bc
+ ld a, [hl]
ret
; copies the base stat data of a pokemon to wMonHeader
; INPUT:
; [wd0b5] = pokemon ID
GetMonHeader::
- ld a,[H_LOADEDROMBANK]
+ 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
- ld a,[wd11e]
+ ld a, [wd11e]
push af
- ld a,[wd0b5]
- ld [wd11e],a
- ld de,FossilKabutopsPic
- ld b,$66 ; size of Kabutops fossil and Ghost sprites
- cp a,FOSSIL_KABUTOPS ; Kabutops fossil
- jr z,.specialID
- ld de,GhostPic
- cp a,MON_GHOST ; Ghost
- jr z,.specialID
- ld de,FossilAerodactylPic
- ld b,$77 ; size of Aerodactyl fossil sprite
- cp a,FOSSIL_AERODACTYL ; Aerodactyl fossil
- jr z,.specialID
- cp a,MEW
- jr z,.mew
+ ld a, [wd0b5]
+ ld [wd11e], a
+ ld de, FossilKabutopsPic
+ ld b, $66 ; size of Kabutops fossil and Ghost sprites
+ cp FOSSIL_KABUTOPS ; Kabutops fossil
+ jr z, .specialID
+ ld de, GhostPic
+ cp MON_GHOST ; Ghost
+ jr z, .specialID
+ ld de, FossilAerodactylPic
+ ld b, $77 ; size of Aerodactyl fossil sprite
+ cp FOSSIL_AERODACTYL ; Aerodactyl fossil
+ jr z, .specialID
+ ;cp MEW
+ ;jr z, .mew
predef IndexToPokedex ; convert pokemon ID in [wd11e] to pokedex number
- ld a,[wd11e]
+ ld a, [wd11e]
dec a
- ld bc,MonBaseStatsEnd - MonBaseStats
- ld hl,BaseStats
+ ld bc, 28
+ ld hl, BaseStats
call AddNTimes
- ld de,wMonHeader
- ld bc,MonBaseStatsEnd - MonBaseStats
+ ld de, wMonHeader
+ ld bc, 28
call CopyData
jr .done
.specialID
- ld hl,wMonHSpriteDim
- ld [hl],b ; write sprite dimensions
+ ld hl, wMonHSpriteDim
+ ld [hl], b ; write sprite dimensions
inc hl
- ld [hl],e ; write front sprite pointer
+ ld [hl], e ; write front sprite pointer
inc hl
- ld [hl],d
- jr .done
-.mew
- ld hl,MewBaseStats
- ld de,wMonHeader
- ld bc,MonBaseStatsEnd - MonBaseStats
- ld a,BANK(MewBaseStats)
- call FarCopyData
+ ld [hl], d
.done
- ld a,[wd0b5]
- ld [wMonHIndex],a
+ ld a, [wd0b5]
+ ld [wMonHIndex], a
pop af
- ld [wd11e],a
+ ld [wd11e], a
pop hl
pop de
pop bc
pop af
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
+ call BankswitchCommon
ret
; copy party pokemon's name to wcd6d
GetPartyMonName2::
- ld a,[wWhichPokemon] ; index within party
- ld hl,wPartyMonNicks
+ ld a, [wWhichPokemon] ; index within party
+ ld hl, wPartyMonNicks
; this is called more often
GetPartyMonName::
push hl
push bc
call SkipFixedLengthTextEntries ; add NAME_LENGTH to hl, a times
- ld de,wcd6d
+ ld de, wcd6d
push de
- ld bc,NAME_LENGTH
+ ld bc, NAME_LENGTH
call CopyData
pop de
pop bc
@@ -650,38 +707,38 @@ GetPartyMonName::
; Note that bits 5 and 7 are modified during execution. The above reflects
; their meaning at the beginning of the functions's execution.
PrintBCDNumber::
- ld b,c ; save flags in b
- res 7,c
- res 6,c
- res 5,c ; c now holds the length
- bit 5,b
- jr z,.loop
- bit 7,b
- jr nz,.loop
- ld [hl],"¥"
+ ld b, c ; save flags in b
+ res 7, c
+ res 6, c
+ res 5, c ; c now holds the length
+ bit 5, b
+ jr z, .loop
+ bit 7, b
+ jr nz, .loop
+ ld [hl], "¥"
inc hl
.loop
- ld a,[de]
+ ld a, [de]
swap a
call PrintBCDDigit ; print upper digit
- ld a,[de]
+ ld a, [de]
call PrintBCDDigit ; print lower digit
inc de
dec c
- jr nz,.loop
- bit 7,b ; were any non-zero digits printed?
- jr z,.done ; if so, we are done
+ jr nz, .loop
+ bit 7, b ; were any non-zero digits printed?
+ jr z, .done ; if so, we are done
.numberEqualsZero ; if every digit of the BCD number is zero
- bit 6,b ; left or right alignment?
- jr nz,.skipRightAlignmentAdjustment
+ bit 6, b ; left or right alignment?
+ jr nz, .skipRightAlignmentAdjustment
dec hl ; if the string is right-aligned, it needs to be moved back one space
.skipRightAlignmentAdjustment
- bit 5,b
- jr z,.skipCurrencySymbol
- ld [hl],"¥"
+ bit 5, b
+ jr z, .skipCurrencySymbol
+ ld [hl], "¥"
inc hl
.skipCurrencySymbol
- ld [hl],"0"
+ ld [hl], "0"
call PrintLetterDelay
inc hl
.done
@@ -690,26 +747,26 @@ PrintBCDNumber::
PrintBCDDigit::
and $f
and a
- jr z,.zeroDigit
+ jr z, .zeroDigit
.nonzeroDigit
- bit 7,b ; have any non-space characters been printed?
- jr z,.outputDigit
+ bit 7, b ; have any non-space characters been printed?
+ jr z, .outputDigit
; if bit 7 is set, then no numbers have been printed yet
- bit 5,b ; print the currency symbol?
- jr z,.skipCurrencySymbol
- ld [hl],"¥"
+ bit 5, b ; print the currency symbol?
+ jr z, .skipCurrencySymbol
+ ld [hl], "¥"
inc hl
- res 5,b
+ res 5, b
.skipCurrencySymbol
- res 7,b ; unset 7 to indicate that a nonzero digit has been reached
+ res 7, b ; unset 7 to indicate that a nonzero digit has been reached
.outputDigit
- add a,"0"
- ld [hli],a
+ add "0"
+ ld [hli], a
jp PrintLetterDelay
.zeroDigit
- bit 7,b ; either printing leading zeroes or already reached a nonzero digit?
- jr z,.outputDigit ; if so, print a zero digit
- bit 6,b ; left or right alignment?
+ bit 7, b ; either printing leading zeroes or already reached a nonzero digit?
+ jr z, .outputDigit ; if so, print a zero digit
+ bit 6, b ; left or right alignment?
ret nz
inc hl ; if right-aligned, "print" a space by advancing the pointer
ret
@@ -718,12 +775,12 @@ PrintBCDDigit::
; assumes the corresponding mon header is already loaded
; hl contains offset to sprite pointer ($b for front or $d for back)
UncompressMonSprite::
- ld bc,wMonHeader
- add hl,bc
- ld a,[hli]
- ld [wSpriteInputPtr],a ; fetch sprite input pointer
- ld a,[hl]
- ld [wSpriteInputPtr+1],a
+ ld bc, wMonHeader
+ add hl, bc
+ ld a, [hli]
+ ld [wSpriteInputPtr], a ; fetch sprite input pointer
+ ld a, [hl]
+ ld [wSpriteInputPtr + 1], a
; define (by index number) the bank that a pokemon's image is in
; index = Mew, bank 1
; index = Kabutops fossil, bank $B
@@ -731,35 +788,35 @@ UncompressMonSprite::
; $1F ≤ index < $4A, bank $A
; $4A ≤ index < $74, bank $B
; $74 ≤ index < $99, bank $C
-; $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
+; $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 FOSSIL_KABUTOPS
- ld a,BANK(FossilKabutopsPic)
- jr z,.GotBank
- ld a,b
+ ld a, BANK(FossilKabutopsPic)
+ jr z, .GotBank
+ ld a, b
cp TANGELA + 1
- ld a,BANK(TangelaPicFront)
- jr c,.GotBank
- ld a,b
+ ld a, BANK(TangelaPicFront)
+ jr c, .GotBank
+ ld a, b
cp MOLTRES + 1
- ld a,BANK(MoltresPicFront)
- jr c,.GotBank
- ld a,b
+ ld a, BANK(MoltresPicFront)
+ jr c, .GotBank
+ ld a, b
cp BEEDRILL + 2
- ld a,BANK(BeedrillPicFront)
- jr c,.GotBank
- ld a,b
+ ld a, BANK(BeedrillPicFront)
+ jr c, .GotBank
+ ld a, b
cp STARMIE + 1
- ld a,BANK(StarmiePicFront)
- jr c,.GotBank
- ld a,BANK(VictreebelPicFront)
+ ld a, BANK(StarmiePicFront)
+ jr c, .GotBank
+ ld a, BANK(VictreebelPicFront)
.GotBank
- jp UncompressSpriteData
+ jp UncompressSpriteData ; 23f8
; de: destination location
LoadMonFrontSprite::
@@ -775,7 +832,7 @@ LoadMonFrontSprite::
; postprocesses uncompressed sprite chunks to a 2bpp sprite and loads it into video ram
; calculates alignment parameters to place both sprite chunks in the center of the 7*7 tile sprite buffers
; de: destination location
-; a,c: sprite dimensions (in tiles of 8x8 each)
+; a, c: sprite dimensions (in tiles of 8x8 each)
LoadUncompressedSpriteData::
push de
and $f
@@ -808,8 +865,8 @@ LoadUncompressedSpriteData::
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, sSpriteBuffer0
call ZeroSpriteBuffer ; zero buffer 0
ld de, sSpriteBuffer1
@@ -820,8 +877,9 @@ LoadUncompressedSpriteData::
ld de, sSpriteBuffer2
ld hl, sSpriteBuffer1
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
@@ -866,8 +924,8 @@ ZeroSpriteBuffer::
; in the resulting sprite, the rows of the two source sprites are interlaced
; de: output address
InterlaceMergeSpriteBuffers::
- xor a
- ld [$4000], a
+ ld a, $0
+ call SwitchSRAMBankAndLatchClockData
push de
ld hl, sSpriteBuffer2 + (SPRITEBUFFERSIZE - 1) ; destination: end of buffer 2
ld de, sSpriteBuffer1 + (SPRITEBUFFERSIZE - 1) ; source 2: end of buffer 1
@@ -909,16 +967,26 @@ InterlaceMergeSpriteBuffers::
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
+INCLUDE "home/pikachu.asm"
+;INCLUDE "data/collision.asm"
+
+INCLUDE "home/lcdc.asm"
+
+IsTilePassable::
+; 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"
@@ -930,13 +998,14 @@ UpdateSprites::
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"
@@ -944,7 +1013,7 @@ INCLUDE "data/mart_inventories.asm"
TextScriptEndingChar::
db "@"
TextScriptEnd::
- ld hl,TextScriptEndingChar
+ ld hl, TextScriptEndingChar
ret
ExclamationText::
@@ -968,7 +1037,6 @@ PokeCenterSignText::
db "@"
PickUpItemText::
-; XXX better label (what does predef $5C do?)
TX_ASM
predef PickUpItem
jp TextScriptEnd
@@ -996,19 +1064,21 @@ ResetPlayerSpriteData::
ResetPlayerSpriteData_ClearSpriteData::
ld bc, $10
xor a
- jp FillMemory
+ call FillMemory ; XXX why replaced with call + ret?
+ ret
+ ;jp FillMemory
FadeOutAudio::
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 +1090,7 @@ FadeOutAudio::
ld [wAudioFadeOutCounter], a
ld a, [rNR50]
and a
- jr z, .asm_2903
+ jr z, .asm_27fa
ld b, a
and $f
dec a
@@ -1033,183 +1103,174 @@ FadeOutAudio::
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::
+ 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::
- ld a,[H_LOADEDROMBANK]
+ ld a, [H_LOADEDROMBANK]
push af
callba DisplayTextIDInit ; initialization
- ld hl,wTextPredefFlag
- bit 0,[hl]
- res 0,[hl]
- jr nz,.skipSwitchToMapBank
- ld a,[wCurMap]
+ ld hl, wTextPredefFlag
+ bit 0, [hl]
+ res 0, [hl]
+ jr nz, .skipSwitchToMapBank
+ ld a, [wCurMap]
call SwitchToMapRomBank
.skipSwitchToMapBank
- ld a,30 ; half a second
- ld [H_FRAMECOUNTER],a ; used as joypad poll timer
- ld hl,wMapTextPtr
- ld a,[hli]
- ld h,[hl]
- ld l,a ; hl = map text pointer
- ld d,$00
- ld a,[hSpriteIndexOrTextID] ; text ID
- ld [wSpriteIndex],a
+ ld a, 30 ; half a second
+ ld [H_FRAMECOUNTER], a ; used as joypad poll timer
+ ld hl, wMapTextPtr
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a ; hl = map text pointer
+ ld d, $00
+ ld a, [hSpriteIndexOrTextID] ; text ID
+ ld [wSpriteIndex], a
and a
- jp z,DisplayStartMenu
- cp a,TEXT_SAFARI_GAME_OVER
- jp z,DisplaySafariGameOverText
- cp a,TEXT_MON_FAINTED
- jp z,DisplayPokemonFaintedText
- cp a,TEXT_BLACKED_OUT
- jp z,DisplayPlayerBlackedOutText
- cp a,TEXT_REPEL_WORE_OFF
- jp z,DisplayRepelWoreOffText
- ld a,[wNumSprites]
- ld e,a
- ld a,[hSpriteIndexOrTextID] ; sprite ID
+ jp z, DisplayStartMenu
+ cp TEXT_PIKACHU_ANIM ; new yellow asm
+ jp z, DisplayPikachuEmotion
+ cp TEXT_SAFARI_GAME_OVER
+ jp z, DisplaySafariGameOverText
+ cp TEXT_MON_FAINTED
+ jp z, DisplayPokemonFaintedText
+ cp TEXT_BLACKED_OUT
+ jp z, DisplayPlayerBlackedOutText
+ cp TEXT_REPEL_WORE_OFF
+ jp z, DisplayRepelWoreOffText
+ ld a, [wNumSprites]
+ ld e, a
+ ld a, [hSpriteIndexOrTextID] ; sprite ID
cp e
- jr z,.spriteHandling
- jr nc,.skipSpriteHandling
+ jr z, .spriteHandling
+ jr nc, .skipSpriteHandling
.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
- ld hl,wMapSpriteData ; NPC text entries
- ld a,[hSpriteIndexOrTextID]
+ ;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, wMapSpriteData ; 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
+ ld a, [hl] ; a = text ID of the sprite
pop hl
.skipSpriteHandling
; look up the address of the text in the map's text entries
dec a
- ld e,a
- sla e
- add hl,de
- ld a,[hli]
- ld h,[hl]
- ld l,a ; hl = address of the text
- ld a,[hl] ; a = first byte of text
+ ld e, a
+ ld d, $0
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a ; hl = address of the text
+ ld a, [hl] ; a = first byte of text
; check first byte of text for special cases
- cp a,$fe ; Pokemart NPC
- jp z,DisplayPokemartDialogue
- cp a,$ff ; Pokemon Center NPC
- jp z,DisplayPokemonCenterDialogue
- cp a,$fc ; Item Storage PC
- jp z,FuncTX_ItemStoragePC
- cp a,$fd ; Bill's PC
- jp z,FuncTX_BillsPC
- cp a,$f9 ; Pokemon Center PC
- jp z,FuncTX_PokemonCenterPC
- cp a,$f5 ; Vending Machine
- jr nz,.notVendingMachine
+ cp $fe ; Pokemart NPC
+ jp z, DisplayPokemartDialogue
+ cp $ff ; Pokemon Center NPC
+ jp z, DisplayPokemonCenterDialogue
+ cp $fc ; Item Storage PC
+ jp z, FuncTX_ItemStoragePC
+ cp $fd ; Bill's PC
+ jp z, FuncTX_BillsPC
+ cp $f9 ; Pokemon Center PC
+ jp z, FuncTX_PokemonCenterPC
+ cp $f5 ; Vending Machine
+ jr nz, .notVendingMachine
callba VendingMachineMenu ; jump banks to vending machine routine
jr AfterDisplayingTextID
.notVendingMachine
- cp a,$f7 ; slot machine
- jp z,FuncTX_SlotMachine
- cp a,$f6 ; cable connection NPC in Pokemon Center
- jr nz,.notSpecialCase
+ cp $f7 ; slot machine
+ jp z, FuncTX_GameCornerPrizeMenu
+ cp $f6 ; cable connection NPC in Pokemon Center
+ jr nz, .notSpecialCase
callab CableClubNPC
jr AfterDisplayingTextID
.notSpecialCase
call PrintText_NoCreatingTextBox ; display the text
- ld a,[wDoNotWaitForButtonPressAfterDisplayingText]
+ ld a, [wDoNotWaitForButtonPressAfterDisplayingText]
and a
- jr nz,HoldTextDisplayOpen
+ jr nz, HoldTextDisplayOpen
AfterDisplayingTextID::
- ld a,[wEnteringCableClub]
+ ld a, [wEnteringCableClub]
and a
- jr nz,HoldTextDisplayOpen
+ 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::
call Joypad
- ld a,[hJoyHeld]
- bit 0,a ; is the A button being pressed?
- jr nz,HoldTextDisplayOpen
+ ld a, [hJoyHeld]
+ bit 0, a ; is the A button being pressed?
+ jr nz, HoldTextDisplayOpen
CloseTextDisplay::
- ld a,[wCurMap]
+ ld a, [wCurMap]
call SwitchToMapRomBank
- ld a,$90
- ld [hWY],a ; move the window off the screen
+ ld a, $90
+ ld [hWY], a ; move the window off the screen
call DelayFrame
call LoadGBPal
xor a
- ld [H_AUTOBGTRANSFERENABLED],a ; disable continuous WRAM to VRAM transfer each V-blank
+ ld [H_AUTOBGTRANSFERENABLED], a ; disable continuous WRAM to VRAM transfer each V-blank
; loop to make sprites face the directions they originally faced before the dialogue
- ld hl,wSpriteStateData2 + $19
- ld c,$0f
- ld de,$0010
+ ld hl, wSpriteStateData2 + $19
+ ld c, $0f
+ ld de, $0010
.restoreSpriteFacingDirectionLoop
- ld a,[hl]
+ ld a, [hl]
dec h
- ld [hl],a
+ ld [hl], a
inc h
- add hl,de
+ add hl, de
dec c
- jr nz,.restoreSpriteFacingDirectionLoop
- ld a,BANK(InitMapSprites)
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
+ jr nz, .restoreSpriteFacingDirectionLoop
call InitMapSprites ; reload sprite tile pattern data (since it was partially overwritten by text tile patterns)
- ld hl,wFontLoaded
- res 0,[hl]
- ld a,[wd732]
- bit 3,a ; used fly warp
- call z,LoadPlayerSpriteGraphics
+ ld hl, wFontLoaded
+ res 0, [hl]
+ ld a, [wd732]
+ bit 3, a ; used fly warp
+ call z, LoadPlayerSpriteGraphics
call LoadCurrentMapView
pop af
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
+ call BankswitchCommon
jp UpdateSprites
DisplayPokemartDialogue::
push hl
- ld hl,PokemartGreetingText
+ ld hl, PokemartGreetingText
call PrintText
pop hl
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 a, PRICEDITEMLISTMENU
+ ld [wListMenuID], a ; selects between subtypes of menus
+ homecall DisplayPokemartDialogue_
jp AfterDisplayingTextID
PokemartGreetingText::
@@ -1217,38 +1278,30 @@ PokemartGreetingText::
db "@"
LoadItemList::
- ld a,1
- ld [wUpdateSpritesEnabled],a
- ld a,h
- ld [wItemListPointer],a
- ld a,l
- ld [wItemListPointer + 1],a
- ld de,wItemList
+ ld a, 1
+ ld [wUpdateSpritesEnabled], a
+ ld a, h
+ ld [wItemListPointer], a
+ ld a, l
+ ld [wItemListPointer + 1], a
+ ld de, wItemList
.loop
- ld a,[hli]
- ld [de],a
+ ld a, [hli]
+ ld [de], a
inc de
- cp a,$ff
- jr nz,.loop
+ cp $ff
+ jr nz, .loop
ret
DisplayPokemonCenterDialogue::
; zeroing these doesn't appear to serve any purpose
xor a
- ld [$ff8b],a
- ld [$ff8c],a
- ld [$ff8d],a
+ ld [$ff8b], a
+ ld [$ff8c], a
+ 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::
@@ -1256,7 +1309,7 @@ DisplaySafariGameOverText::
jp AfterDisplayingTextID
DisplayPokemonFaintedText::
- ld hl,PokemonFaintedText
+ ld hl, PokemonFaintedText
call PrintText
jp AfterDisplayingTextID
@@ -1265,11 +1318,21 @@ PokemonFaintedText::
db "@"
DisplayPlayerBlackedOutText::
- ld hl,PlayerBlackedOutText
+ ld hl, PlayerBlackedOutText
call PrintText
- ld a,[wd732]
- res 5,a ; reset forced to use bike bit
- ld [wd732],a
+ ld a, [wd732]
+ res 5, a ; reset forced to use bike bit
+ ld [wd732], a
+ CheckEvent EVENT_IN_SAFARI_ZONE
+ jr z, .didnotblackoutinsafari
+ xor a
+ ld [wNumSafariBalls], a
+ ld [wSafariSteps], a
+ ld [wSafariSteps + 1], a
+ EventFlagAddressa EVENT_IN_SAFARI_ZONE
+ ld [wcf0d], a
+ ld [wSafariZoneEntranceCurScript], a
+.didnotblackoutinsafari
jp HoldTextDisplayOpen
PlayerBlackedOutText::
@@ -1277,7 +1340,7 @@ PlayerBlackedOutText::
db "@"
DisplayRepelWoreOffText::
- ld hl,RepelWoreOffText
+ ld hl, RepelWoreOffText
call PrintText
jp AfterDisplayingTextID
@@ -1285,6 +1348,10 @@ RepelWoreOffText::
TX_FAR _RepelWoreOffText
db "@"
+DisplayPikachuEmotion::
+ callab TalkToPikachu ; 3f:5004
+ jp CloseTextDisplay
+
INCLUDE "engine/menu/start_menu.asm"
; function to count how many bits are set in a string of bytes
@@ -1294,22 +1361,22 @@ INCLUDE "engine/menu/start_menu.asm"
; OUTPUT:
; [wNumSetBits] = number of set bits
CountSetBits::
- ld c,0
+ ld c, 0
.loop
- ld a,[hli]
- ld e,a
- ld d,8
+ ld a, [hli]
+ ld e, a
+ ld d, 8
.innerLoop ; count how many bits are set in the current byte
srl e
- ld a,0
+ ld a, 0
adc c
- ld c,a
+ ld c, a
dec d
- jr nz,.innerLoop
+ jr nz, .innerLoop
dec b
- jr nz,.loop
- ld a,c
- ld [wNumSetBits],a
+ jr nz, .loop
+ ld a, c
+ ld [wNumSetBits], a
ret
; subtracts the amount the player paid from their money
@@ -1319,16 +1386,16 @@ SubtractAmountPaidFromMoney::
; adds the amount the player sold to their money
AddAmountSoldToMoney::
- ld de,wPlayerMoney + 2
- ld hl,$ffa1 ; total price of items
- ld c,3 ; length of money in bytes
+ ld de, wPlayerMoney + 2
+ ld hl, $ffa1 ; total price of items
+ ld c, 3 ; length of money in bytes
predef AddBCDPredef ; add total price to money
- ld a,MONEY_BOX
- ld [wTextBoxID],a
+ ld a, MONEY_BOX
+ ld [wTextBoxID], a
call DisplayTextBoxID ; redraw money text box
- ld a, SFX_PURCHASE
- call PlaySoundWaitForCurrent
- jp WaitForSoundToFinish
+ ld a, $b2 ; SFX_PURCHASE
+ call PlaySoundWaitForCurrent ; play sound
+ jp WaitForSoundToFinish ; wait until sound is done playing
; function to remove an item (in varying quantities) from the player's bag or PC box
; INPUT:
@@ -1336,15 +1403,7 @@ AddAmountSoldToMoney::
; [wWhichPokemon] = index (within the inventory) of the item to remove
; [wItemQuantity] = quantity to remove
RemoveItemFromInventory::
- 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
+ homecall RemoveItemFromInventory_
ret
; function to add an item (in varying quantities) to the player's bag or PC box
@@ -1355,16 +1414,7 @@ RemoveItemFromInventory::
; sets carry flag if successful, unsets carry flag if unsuccessful
AddItemToInventory::
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
@@ -1373,80 +1423,80 @@ AddItemToInventory::
; [wListPointer] = address of the list (2 bytes)
DisplayListMenuID::
xor a
- ld [H_AUTOBGTRANSFERENABLED],a ; disable auto-transfer
- ld a,1
- ld [hJoy7],a ; joypad state update flag
- ld a,[wBattleType]
+ ld [H_AUTOBGTRANSFERENABLED], a ; disable auto-transfer
+ ld a, 1
+ ld [hJoy7], a ; joypad state update flag
+ ld a, [wBattleType]
and a ; is it the Old Man battle?
- jr nz,.specialBattleType
- ld a,$01 ; hardcoded bank
+ jr nz, .specialBattleType
+ 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
- set 6,[hl] ; turn off letter printing delay
+ ld hl, wd730
+ set 6, [hl] ; turn off letter printing delay
xor a
- ld [wMenuItemToSwap],a ; 0 means no item is currently being swapped
- ld [wListCount],a
- ld a,[wListPointer]
- ld l,a
- ld a,[wListPointer + 1]
- ld h,a ; hl = address of the list
- ld a,[hl] ; the first byte is the number of entries in the list
- ld [wListCount],a
- ld a,LIST_MENU_BOX
- ld [wTextBoxID],a
+ ld [wMenuItemToSwap], a ; 0 means no item is currently being swapped
+ ld [wListCount], a
+ ld a, [wListPointer]
+ ld l, a
+ ld a, [wListPointer + 1]
+ ld h, a ; hl = address of the list
+ ld a, [hl] ; the first byte is the number of entries in the list
+ ld [wListCount], a
+ ld a, LIST_MENU_BOX
+ ld [wTextBoxID], a
call DisplayTextBoxID ; draw the menu text box
call UpdateSprites ; disable sprites behind the text box
; the code up to .skipMovingSprites appears to be useless
coord hl, 4, 2 ; coordinates of upper left corner of menu text box
lb de, 9, 14 ; height and width of menu text box
- ld a,[wListMenuID]
+ ld a, [wListMenuID]
and a ; is it a PC pokemon list?
- jr nz,.skipMovingSprites
+ jr nz, .skipMovingSprites
call UpdateSprites
.skipMovingSprites
- ld a,1 ; max menu item ID is 1 if the list has less than 2 entries
- ld [wMenuWatchMovingOutOfBounds],a
- ld a,[wListCount]
- cp a,2 ; does the list have less than 2 entries?
- jr c,.setMenuVariables
- ld a,2 ; max menu item ID is 2 if the list has at least 2 entries
+ ld a, 1 ; max menu item ID is 1 if the list has less than 2 entries
+ ld [wMenuWatchMovingOutOfBounds], a
+ ld a, [wListCount]
+ cp 2 ; does the list have less than 2 entries?
+ jr c, .setMenuVariables
+ ld a, 2 ; max menu item ID is 2 if the list has at least 2 entries
.setMenuVariables
- ld [wMaxMenuItem],a
- ld a,4
- ld [wTopMenuItemY],a
- ld a,5
- ld [wTopMenuItemX],a
- ld a,A_BUTTON | B_BUTTON | SELECT
- ld [wMenuWatchedKeys],a
- ld c,10
+ ld [wMaxMenuItem], a
+ ld a, 4
+ ld [wTopMenuItemY], a
+ ld a, 5
+ ld [wTopMenuItemX], a
+ ld a, A_BUTTON | B_BUTTON | SELECT
+ ld [wMenuWatchedKeys], a
+ ld c, 10
call DelayFrames
DisplayListMenuIDLoop::
xor a
- ld [H_AUTOBGTRANSFERENABLED],a ; disable transfer
+ ld [H_AUTOBGTRANSFERENABLED], a ; disable transfer
call PrintListMenuEntries
- ld a,1
- ld [H_AUTOBGTRANSFERENABLED],a ; enable transfer
+ ld a, 1
+ ld [H_AUTOBGTRANSFERENABLED], a ; enable transfer
call Delay3
- ld a,[wBattleType]
+ ld a, [wBattleType]
and a ; is it the Old Man battle?
- jr z,.notOldManBattle
+ jr z, .notOldManBattle
.oldManBattle
- ld a,"▶"
+ 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
+ ld [wCurrentMenuItem], a
coord hl, 5, 4
- ld a,l
- ld [wMenuCursorLocation],a
- ld a,h
- ld [wMenuCursorLocation + 1],a
+ ld a, l
+ ld [wMenuCursorLocation], a
+ ld a, h
+ ld [wMenuCursorLocation + 1], a
jr .buttonAPressed
.notOldManBattle
call LoadGBPal
@@ -1454,231 +1504,229 @@ DisplayListMenuIDLoop::
push af
call PlaceMenuCursor
pop af
- bit 0,a ; was the A button pressed?
- jp z,.checkOtherKeys
+ bit 0, a ; was the A button pressed?
+ jp z, .checkOtherKeys
.buttonAPressed
- ld a,[wCurrentMenuItem]
+ ld a, [wCurrentMenuItem]
call PlaceUnfilledArrowMenuCursor
; pointless because both values are overwritten before they are read
- ld a,$01
- ld [wMenuExitMethod],a
- ld [wChosenMenuItem],a
+ ld a, $01
+ ld [wMenuExitMethod], a
+ ld [wChosenMenuItem], a
xor a
- ld [wMenuWatchMovingOutOfBounds],a
- ld a,[wCurrentMenuItem]
- ld c,a
- ld a,[wListScrollOffset]
+ ld [wMenuWatchMovingOutOfBounds], a
+ ld a, [wCurrentMenuItem]
+ ld c, a
+ ld a, [wListScrollOffset]
add c
- ld c,a
- ld a,[wListCount]
+ ld c, a
+ ld a, [wListCount]
and a ; is the list empty?
- jp z,ExitListMenu ; if so, exit the menu
+ jp z, ExitListMenu ; if so, exit the menu
dec a
cp c ; did the player select Cancel?
- jp c,ExitListMenu ; if so, exit the menu
- ld a,c
- ld [wWhichPokemon],a
- ld a,[wListMenuID]
- cp a,ITEMLISTMENU
- jr nz,.skipMultiplying
+ jp c, ExitListMenu ; if so, exit the menu
+ ld a, c
+ ld [wWhichPokemon], a
+ ld a, [wListMenuID]
+ cp ITEMLISTMENU
+ jr nz, .skipMultiplying
; if it's an item menu
sla c ; item entries are 2 bytes long, so multiply by 2
.skipMultiplying
- ld a,[wListPointer]
- ld l,a
- ld a,[wListPointer + 1]
- ld h,a
+ ld a, [wListPointer]
+ ld l, a
+ ld a, [wListPointer + 1]
+ ld h, a
inc hl ; hl = beginning of list entries
- ld b,0
- add hl,bc
- ld a,[hl]
- ld [wcf91],a
- ld a,[wListMenuID]
+ ld b, 0
+ add hl, bc
+ ld a, [hl]
+ ld [wcf91], a
+ ld a, [wListMenuID]
and a ; is it a PC pokemon list?
- jr z,.pokemonList
+ jr z, .pokemonList
push hl
call GetItemPrice
pop hl
- ld a,[wListMenuID]
- cp a,ITEMLISTMENU
- jr nz,.skipGettingQuantity
+ ld a, [wListMenuID]
+ cp ITEMLISTMENU
+ jr nz, .skipGettingQuantity
; if it's an item menu
inc hl
- ld a,[hl] ; a = item quantity
- ld [wMaxItemQuantity],a
+ ld a, [hl] ; a = item quantity
+ ld [wMaxItemQuantity], a
.skipGettingQuantity
- ld a,[wcf91]
- ld [wd0b5],a
- ld a,BANK(ItemNames)
- ld [wPredefBank],a
+ ld a, [wcf91]
+ ld [wd0b5], a
+ ld a, BANK(ItemNames)
+ ld [wPredefBank], a
call GetName
jr .storeChosenEntry
.pokemonList
- ld hl,wPartyCount
- ld a,[wListPointer]
+ ld hl, wPartyCount
+ ld a, [wListPointer]
cp l ; is it a list of party pokemon or box pokemon?
- ld hl,wPartyMonNicks
- jr z,.getPokemonName
+ ld hl, wPartyMonNicks
+ jr z, .getPokemonName
ld hl, wBoxMonNicks ; box pokemon names
.getPokemonName
- ld a,[wWhichPokemon]
+ ld a, [wWhichPokemon]
call GetPartyMonName
.storeChosenEntry ; store the menu entry that the player chose and return
- ld de,wcd6d
+ ld de, wcd6d
call CopyStringToCF4B ; copy name to wcf4b
- ld a,CHOSE_MENU_ITEM
- ld [wMenuExitMethod],a
- ld a,[wCurrentMenuItem]
- ld [wChosenMenuItem],a
+ ld a, CHOSE_MENU_ITEM
+ ld [wMenuExitMethod], a
+ ld a, [wCurrentMenuItem]
+ ld [wChosenMenuItem], a
xor a
- ld [hJoy7],a ; joypad state update flag
- ld hl,wd730
- res 6,[hl] ; turn on letter printing delay
+ ld [hJoy7], a ; joypad state update flag
+ ld hl, wd730
+ res 6, [hl] ; turn on letter printing delay
jp BankswitchBack
.checkOtherKeys ; check B, SELECT, Up, and Down keys
- bit 1,a ; was the B button pressed?
- jp nz,ExitListMenu ; if so, exit the menu
- bit 2,a ; was the select button pressed?
- jp nz,HandleItemListSwapping ; if so, allow the player to swap menu entries
- ld b,a
- bit 7,b ; was Down pressed?
- ld hl,wListScrollOffset
- jr z,.upPressed
+ bit 1, a ; was the B button pressed?
+ jp nz, ExitListMenu ; if so, exit the menu
+ bit 2, a ; was the select button pressed?
+ jp nz, HandleItemListSwapping ; if so, allow the player to swap menu entries
+ ld b, a
+ bit 7, b ; was Down pressed?
+ ld hl, wListScrollOffset
+ jr z, .upPressed
.downPressed
- ld a,[hl]
- add a,3
- ld b,a
- ld a,[wListCount]
+ ld a, [hl]
+ add 3
+ ld b, a
+ ld a, [wListCount]
cp b ; will going down scroll past the Cancel button?
- jp c,DisplayListMenuIDLoop
+ jp c, DisplayListMenuIDLoop
inc [hl] ; if not, go down
jp DisplayListMenuIDLoop
.upPressed
- ld a,[hl]
+ ld a, [hl]
and a
- jp z,DisplayListMenuIDLoop
+ jp z, DisplayListMenuIDLoop
dec [hl]
jp DisplayListMenuIDLoop
DisplayChooseQuantityMenu::
; text box dimensions/coordinates for just quantity
coord hl, 15, 9
- ld b,1 ; height
- ld c,3 ; width
- ld a,[wListMenuID]
- cp a,PRICEDITEMLISTMENU
- jr nz,.drawTextBox
+ lb bc, 1, 3 ; height and width
+ ld a, [wListMenuID]
+ cp PRICEDITEMLISTMENU
+ jr nz, .drawTextBox
; text box dimensions/coordinates for quantity and price
coord hl, 7, 9
- ld b,1 ; height
- ld c,11 ; width
+ lb bc, 1, 11 ; height and width
.drawTextBox
call TextBoxBorder
coord hl, 16, 10
- ld a,[wListMenuID]
- cp a,PRICEDITEMLISTMENU
- jr nz,.printInitialQuantity
+ ld a, [wListMenuID]
+ cp PRICEDITEMLISTMENU
+ jr nz, .printInitialQuantity
coord hl, 8, 10
.printInitialQuantity
- ld de,InitialQuantityText
+ ld de, InitialQuantityText
call PlaceString
xor a
- ld [wItemQuantity],a ; initialize current quantity to 0
+ ld [wItemQuantity], a ; initialize current quantity to 0
jp .incrementQuantity
.waitForKeyPressLoop
call JoypadLowSensitivity
- ld a,[hJoyPressed] ; newly pressed buttons
- bit 0,a ; was the A button pressed?
- jp nz,.buttonAPressed
- bit 1,a ; was the B button pressed?
- jp nz,.buttonBPressed
- bit 6,a ; was Up pressed?
- jr nz,.incrementQuantity
- bit 7,a ; was Down pressed?
- jr nz,.decrementQuantity
+ ld a, [hJoyPressed] ; newly pressed buttons
+ bit 0, a ; was the A button pressed?
+ jp nz, .buttonAPressed
+ bit 1, a ; was the B button pressed?
+ jp nz, .buttonBPressed
+ bit 6, a ; was Up pressed?
+ jr nz, .incrementQuantity
+ bit 7, a ; was Down pressed?
+ jr nz, .decrementQuantity
jr .waitForKeyPressLoop
.incrementQuantity
- ld a,[wMaxItemQuantity]
+ ld a, [wMaxItemQuantity]
inc a
- ld b,a
- ld hl,wItemQuantity ; current quantity
+ ld b, a
+ ld hl, wItemQuantity ; current quantity
inc [hl]
- ld a,[hl]
+ ld a, [hl]
cp b
- jr nz,.handleNewQuantity
+ jr nz, .handleNewQuantity
; wrap to 1 if the player goes above the max quantity
- ld a,1
- ld [hl],a
+ ld a, 1
+ ld [hl], a
jr .handleNewQuantity
.decrementQuantity
- ld hl,wItemQuantity ; current quantity
+ ld hl, wItemQuantity ; current quantity
dec [hl]
- jr nz,.handleNewQuantity
+ jr nz, .handleNewQuantity
; wrap to the max quantity if the player goes below 1
- ld a,[wMaxItemQuantity]
- ld [hl],a
+ ld a, [wMaxItemQuantity]
+ ld [hl], a
.handleNewQuantity
coord hl, 17, 10
- ld a,[wListMenuID]
- cp a,PRICEDITEMLISTMENU
- jr nz,.printQuantity
+ ld a, [wListMenuID]
+ cp PRICEDITEMLISTMENU
+ jr nz, .printQuantity
.printPrice
- ld c,$03
- ld a,[wItemQuantity]
- ld b,a
- ld hl,hMoney ; total price
+ ld c, $03
+ ld a, [wItemQuantity]
+ ld b, a
+ ld hl, hMoney ; total price
; initialize total price to 0
xor a
- ld [hli],a
- ld [hli],a
- ld [hl],a
+ ld [hli], a
+ ld [hli], a
+ ld [hl], a
.addLoop ; loop to multiply the individual price by the quantity to get the total price
- ld de,hMoney + 2
- ld hl,hItemPrice + 2
+ ld de, hMoney + 2
+ ld hl, hItemPrice + 2
push bc
predef AddBCDPredef ; add the individual price to the current sum
pop bc
dec b
- jr nz,.addLoop
- ld a,[hHalveItemPrices]
+ jr nz, .addLoop
+ ld a, [hHalveItemPrices]
and a ; should the price be halved (for selling items)?
- jr z,.skipHalvingPrice
+ jr z, .skipHalvingPrice
xor a
- ld [hDivideBCDDivisor],a
- ld [hDivideBCDDivisor + 1],a
- ld a,$02
- ld [hDivideBCDDivisor + 2],a
+ ld [hDivideBCDDivisor], a
+ ld [hDivideBCDDivisor + 1], a
+ ld a, $02
+ ld [hDivideBCDDivisor + 2], a
predef DivideBCDPredef3 ; halves the price
; store the halved price
- ld a,[hDivideBCDQuotient]
- ld [hMoney],a
- ld a,[hDivideBCDQuotient + 1]
- ld [hMoney + 1],a
- ld a,[hDivideBCDQuotient + 2]
- ld [hMoney + 2],a
+ ld a, [hDivideBCDQuotient]
+ ld [hMoney], a
+ ld a, [hDivideBCDQuotient + 1]
+ ld [hMoney + 1], a
+ ld a, [hDivideBCDQuotient + 2]
+ ld [hMoney + 2], a
.skipHalvingPrice
coord hl, 12, 10
- ld de,SpacesBetweenQuantityAndPriceText
+ ld de, SpacesBetweenQuantityAndPriceText
call PlaceString
- ld de,hMoney ; total price
- ld c,$a3
+ ld de, hMoney ; total price
+ ld c, $a3
call PrintBCDNumber
coord hl, 9, 10
.printQuantity
- ld de,wItemQuantity ; current quantity
+ ld de, wItemQuantity ; current quantity
lb bc, LEADING_ZEROES | 1, 2 ; 1 byte, 2 digits
call PrintNumber
jp .waitForKeyPressLoop
.buttonAPressed ; the player chose to make the transaction
xor a
- ld [wMenuItemToSwap],a ; 0 means no item is currently being swapped
+ ld [wMenuItemToSwap], a ; 0 means no item is currently being swapped
ret
.buttonBPressed ; the player chose to cancel the transaction
xor a
- ld [wMenuItemToSwap],a ; 0 means no item is currently being swapped
- ld a,$ff
+ ld [wMenuItemToSwap], a ; 0 means no item is currently being swapped
+ ld a, $ff
ret
InitialQuantityText::
@@ -1688,84 +1736,83 @@ SpacesBetweenQuantityAndPriceText::
db " @"
ExitListMenu::
- ld a,[wCurrentMenuItem]
- ld [wChosenMenuItem],a
- ld a,CANCELLED_MENU
- ld [wMenuExitMethod],a
- ld [wMenuWatchMovingOutOfBounds],a
+ ld a, [wCurrentMenuItem]
+ ld [wChosenMenuItem], a
+ ld a, CANCELLED_MENU
+ ld [wMenuExitMethod], a
+ ld [wMenuWatchMovingOutOfBounds], a
xor a
- ld [hJoy7],a
- ld hl,wd730
- res 6,[hl]
+ ld [hJoy7], a
+ ld hl, wd730
+ res 6, [hl]
call BankswitchBack
xor a
- ld [wMenuItemToSwap],a ; 0 means no item is currently being swapped
+ ld [wMenuItemToSwap], a ; 0 means no item is currently being swapped
scf
ret
PrintListMenuEntries::
coord hl, 5, 3
- ld b,9
- ld c,14
+ lb bc, 9, 14
call ClearScreenArea
- ld a,[wListPointer]
- ld e,a
- ld a,[wListPointer + 1]
- ld d,a
+ ld a, [wListPointer]
+ ld e, a
+ ld a, [wListPointer + 1]
+ ld d, a
inc de ; de = beginning of list entries
- ld a,[wListScrollOffset]
- ld c,a
- ld a,[wListMenuID]
- cp a,ITEMLISTMENU
- ld a,c
- jr nz,.skipMultiplying
+ ld a, [wListScrollOffset]
+ ld c, a
+ ld a, [wListMenuID]
+ cp ITEMLISTMENU
+ ld a, c
+ 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
- ld e,a
- jr nc,.noCarry
+ ld e, a
+ jr nc, .noCarry
inc d
.noCarry
coord hl, 6, 4 ; coordinates of first list entry name
- ld b,4 ; print 4 names
+ ld b, 4 ; print 4 names
.loop
- ld a,b
- ld [wWhichPokemon],a
- ld a,[de]
- ld [wd11e],a
- cp a,$ff
- jp z,.printCancelMenuItem
+ ld a, b
+ ld [wWhichPokemon], a
+ ld a, [de]
+ ld [wd11e], a
+ cp $ff
+ jp z, .printCancelMenuItem
push bc
push de
push hl
push hl
push de
- ld a,[wListMenuID]
+ ld a, [wListMenuID]
and a
- jr z,.pokemonPCMenu
- cp a,$01
- jr z,.movesMenu
+ jr z, .pokemonPCMenu
+ cp $01
+ jr z, .movesMenu
.itemMenu
call GetItemName
jr .placeNameString
.pokemonPCMenu
push hl
- ld hl,wPartyCount
- ld a,[wListPointer]
+ ld hl, wPartyCount
+ ld a, [wListPointer]
cp l ; is it a list of party pokemon or box pokemon?
- ld hl,wPartyMonNicks
- jr z,.getPokemonName
+ ld hl, wPartyMonNicks
+ jr z, .getPokemonName
ld hl, wBoxMonNicks ; box pokemon names
.getPokemonName
- ld a,[wWhichPokemon]
- ld b,a
- ld a,4
+ ld a, [wWhichPokemon]
+ ld b, a
+ ld a, 4
sub b
- ld b,a
- ld a,[wListScrollOffset]
+ ld b, a
+ ld a, [wListScrollOffset]
add b
call GetPartyMonName
pop hl
@@ -1776,90 +1823,90 @@ PrintListMenuEntries::
call PlaceString
pop de
pop hl
- ld a,[wPrintItemPrices]
+ ld a, [wPrintItemPrices]
and a ; should prices be printed?
- jr z,.skipPrintingItemPrice
+ jr z, .skipPrintingItemPrice
.printItemPrice
push hl
- ld a,[de]
- ld de,ItemPrices
- ld [wcf91],a
+ ld a, [de]
+ ld de, ItemPrices
+ ld [wcf91], a
call GetItemPrice ; get price
pop hl
ld bc, SCREEN_WIDTH + 5 ; 1 row down and 5 columns right
- add hl,bc
- ld c,$a3 ; no leading zeroes, right-aligned, print currency symbol, 3 bytes
+ add hl, bc
+ ld c, $a3 ; no leading zeroes, right-aligned, print currency symbol, 3 bytes
call PrintBCDNumber
.skipPrintingItemPrice
- ld a,[wListMenuID]
+ ld a, [wListMenuID]
and a
- jr nz,.skipPrintingPokemonLevel
+ jr nz, .skipPrintingPokemonLevel
.printPokemonLevel
- ld a,[wd11e]
+ ld a, [wd11e]
push af
push hl
- ld hl,wPartyCount
- ld a,[wListPointer]
+ ld hl, wPartyCount
+ ld a, [wListPointer]
cp l ; is it a list of party pokemon or box pokemon?
- ld a,PLAYER_PARTY_DATA
- jr z,.next
- ld a,BOX_DATA
+ ld a, PLAYER_PARTY_DATA
+ jr z, .next
+ ld a, BOX_DATA
.next
- ld [wMonDataLocation],a
- ld hl,wWhichPokemon
- ld a,[hl]
- ld b,a
- ld a,$04
+ ld [wMonDataLocation], a
+ ld hl, wWhichPokemon
+ ld a, [hl]
+ ld b, a
+ ld a, $04
sub b
- ld b,a
- ld a,[wListScrollOffset]
+ ld b, a
+ ld a, [wListScrollOffset]
add b
- ld [hl],a
+ ld [hl], a
call LoadMonData
- ld a,[wMonDataLocation]
+ ld a, [wMonDataLocation]
and a ; is it a list of party pokemon or box pokemon?
- jr z,.skipCopyingLevel
+ jr z, .skipCopyingLevel
.copyLevel
- ld a,[wLoadedMonBoxLevel]
- ld [wLoadedMonLevel],a
+ ld a, [wLoadedMonBoxLevel]
+ ld [wLoadedMonLevel], a
.skipCopyingLevel
pop hl
- ld bc,$001c
- add hl,bc
+ ld bc, $001c
+ add hl, bc
call PrintLevel
pop af
- ld [wd11e],a
+ ld [wd11e], a
.skipPrintingPokemonLevel
pop hl
pop de
inc de
- ld a,[wListMenuID]
- cp a,ITEMLISTMENU
- jr nz,.nextListEntry
+ ld a, [wListMenuID]
+ cp ITEMLISTMENU
+ jr nz, .nextListEntry
.printItemQuantity
- ld a,[wd11e]
- ld [wcf91],a
+ ld a, [wd11e]
+ ld [wcf91], a
call IsKeyItem ; check if item is unsellable
- ld a,[wIsKeyItem]
+ ld a, [wIsKeyItem]
and a ; is the item unsellable?
- jr nz,.skipPrintingItemQuantity ; if so, don't print the quantity
+ jr nz, .skipPrintingItemQuantity ; if so, don't print the quantity
push hl
ld bc, SCREEN_WIDTH + 8 ; 1 row down and 8 columns right
- add hl,bc
- ld a,"×"
- ld [hli],a
- ld a,[wd11e]
+ add hl, bc
+ ld a, "×"
+ ld [hli], a
+ ld a, [wd11e]
push af
- ld a,[de]
- ld [wMaxItemQuantity],a
+ ld a, [de]
+ ld [wMaxItemQuantity], a
push de
- ld de,wd11e
- ld [de],a
+ ld de, wd11e
+ ld [de], a
lb bc, 1, 2
call PrintNumber
pop de
pop af
- ld [wd11e],a
+ ld [wd11e], a
pop hl
.skipPrintingItemQuantity
inc de
@@ -1867,29 +1914,29 @@ PrintListMenuEntries::
inc c
push bc
inc c
- ld a,[wMenuItemToSwap] ; ID of item chosen for swapping (counts from 1)
+ ld a, [wMenuItemToSwap] ; ID of item chosen for swapping (counts from 1)
and a ; is an item being swapped?
- jr z,.nextListEntry
- sla a
+ jr z, .nextListEntry
+ add a
cp c ; is it this item?
- jr nz,.nextListEntry
+ jr nz, .nextListEntry
dec hl
- ld a,$ec ; unfilled right arrow menu cursor to indicate an item being swapped
- ld [hli],a
+ ld a, $ec ; unfilled right arrow menu cursor to indicate an item being swapped
+ ld [hli], a
.nextListEntry
- ld bc,2 * SCREEN_WIDTH ; 2 rows
- add hl,bc
+ ld bc, 2 * SCREEN_WIDTH ; 2 rows
+ add hl, bc
pop bc
inc c
dec b
- jp nz,.loop
- ld bc,-8
- add hl,bc
- ld a,$ee ; down arrow
- ld [hl],a
+ jp nz, .loop
+ ld bc, -8
+ add hl, bc
+ ld a, $ee ; down arrow
+ ld [hl], a
ret
.printCancelMenuItem
- ld de,ListMenuCancelText
+ ld de, ListMenuCancelText
jp PlaceString
ListMenuCancelText::
@@ -1897,27 +1944,27 @@ ListMenuCancelText::
GetMonName::
push hl
- ld a,[H_LOADEDROMBANK]
+ ld a, [H_LOADEDROMBANK]
push af
- ld a,BANK(MonsterNames)
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
- ld a,[wd11e]
+ ld a, BANK(MonsterNames) ; 3a
+ ld [H_LOADEDROMBANK], a
+ ld [MBC1RomBank], a
+ ld a, [wd11e]
dec a
- ld hl,MonsterNames
- ld c,10
- ld b,0
+ ld hl, MonsterNames ; 4000
+ ld c, 10
+ ld b, 0
call AddNTimes
- ld de,wcd6d
+ ld de, wcd6d
push de
- ld bc,10
+ ld bc, 10
call CopyData
- ld hl,wcd6d + 10
+ ld hl, wcd6d + 10
ld [hl], "@"
pop de
pop af
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
+ ld [H_LOADEDROMBANK], a
+ ld [MBC1RomBank], a
pop hl
ret
@@ -1926,22 +1973,22 @@ GetItemName::
; starting at wcd6d
push hl
push bc
- ld a,[wd11e]
+ ld a, [wd11e]
cp HM_01 ; is this a TM/HM?
- jr nc,.Machine
+ jr nc, .Machine
- ld [wd0b5],a
- ld a,ITEM_NAME
- ld [wNameListType],a
- ld a,BANK(ItemNames)
- ld [wPredefBank],a
+ ld [wd0b5], a
+ ld a, ITEM_NAME
+ ld [wNameListType], a
+ ld a, BANK(ItemNames)
+ ld [wPredefBank], a
call GetName
jr .Finish
.Machine
call GetMachineName
.Finish
- ld de,wcd6d ; pointer to where item name is stored in RAM
+ ld de, wcd6d ; pointer to where item name is stored in RAM
pop bc
pop hl
ret
@@ -1951,49 +1998,48 @@ GetMachineName::
push hl
push de
push bc
- ld a,[wd11e]
+ ld a, [wd11e]
push af
cp TM_01 ; is this a TM? [not HM]
- jr nc,.WriteTM
+ jr nc, .WriteTM
; if HM, then write "HM" and add 5 to the item ID, so we can reuse the
; TM printing code
add 5
- ld [wd11e],a
- ld hl,HiddenPrefix ; points to "HM"
- ld bc,2
+ ld [wd11e], a
+ ld hl, HiddenPrefix ; points to "HM"
+ ld bc, 2
jr .WriteMachinePrefix
.WriteTM
- ld hl,TechnicalPrefix ; points to "TM"
- ld bc,2
+ ld hl, TechnicalPrefix ; points to "TM"
+ ld bc, 2
.WriteMachinePrefix
- ld de,wcd6d
+ ld de, wcd6d
call CopyData
; now get the machine number and convert it to text
- ld a,[wd11e]
+ ld a, [wd11e]
sub TM_01 - 1
ld b, "0"
.FirstDigit
sub 10
- jr c,.SecondDigit
+ jr c, .SecondDigit
inc b
jr .FirstDigit
.SecondDigit
add 10
push af
- ld a,b
- ld [de],a
+ ld a, b
+ ld [de], a
inc de
pop af
ld b, "0"
add b
- ld [de],a
+ ld [de], a
inc de
- ld a,"@"
- ld [de],a
-
+ ld a, "@"
+ ld [de], a
pop af
- ld [wd11e],a
+ ld [wd11e], a
pop bc
pop de
pop hl
@@ -2007,9 +2053,9 @@ HiddenPrefix::
; sets carry if item is HM, clears carry if item is not HM
; Input: a = item ID
IsItemHM::
- cp a,HM_01
- jr c,.notHM
- cp a,TM_01
+ cp HM_01
+ jr c, .notHM
+ cp TM_01
ret
.notHM
and a
@@ -2018,32 +2064,32 @@ IsItemHM::
; sets carry if move is an HM, clears carry if move is not an HM
; Input: a = move ID
IsMoveHM::
- ld hl,HMMoves
- ld de,1
+ ld hl, HMMoves
+ ld de, 1
jp IsInArray
HMMoves::
- db CUT,FLY,SURF,STRENGTH,FLASH
+ db CUT, FLY, SURF, STRENGTH, FLASH
db $ff ; terminator
GetMoveName::
push hl
- ld a,MOVE_NAME
- ld [wNameListType],a
- ld a,[wd11e]
- ld [wd0b5],a
- ld a,BANK(MoveNames)
- ld [wPredefBank],a
+ ld a, MOVE_NAME
+ ld [wNameListType], a
+ ld a, [wd11e]
+ ld [wd0b5], a
+ ld a, BANK(MoveNames)
+ ld [wPredefBank], a
call GetName
- ld de,wcd6d ; pointer to where move name is stored in RAM
+ ld de, wcd6d ; pointer to where move name is stored in RAM
pop hl
ret
; reloads text box tile patterns, current map view, and tileset tile patterns
ReloadMapData::
- ld a,[H_LOADEDROMBANK]
+ ld a, [H_LOADEDROMBANK]
push af
- ld a,[wCurMap]
+ ld a, [wCurMap]
call SwitchToMapRomBank
call DisableLCD
call LoadTextBoxTilePatterns
@@ -2051,34 +2097,60 @@ ReloadMapData::
call LoadTilesetTilePatternData
call EnableLCD
pop af
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
+ call BankswitchCommon
ret
; reloads tileset tile patterns
ReloadTilesetTilePatterns::
- ld a,[H_LOADEDROMBANK]
+ ld a, [H_LOADEDROMBANK]
push af
- ld a,[wCurMap]
+ ld a, [wCurMap]
call SwitchToMapRomBank
call DisableLCD
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::
- ld hl,wd72e
- res 4,[hl]
+ ld hl, wd72e
+ res 4, [hl]
jpba LoadTownMap_Fly
+PrinterSerial::
+ homecall PrinterSerial_
+ ret
+
+SerialFunction::
+ ld a, [wPrinterConnectionOpen]
+ bit 0, a
+ ret z
+ ld a, [wPrinterOpcode]
+ 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 [wPrinterOpcode], 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::
- ld a,$01
- ld [wDoNotWaitForButtonPressAfterDisplayingText],a
+ ld a, $01
+ ld [wDoNotWaitForButtonPressAfterDisplayingText], a
ret
; uses an item
@@ -2102,16 +2174,16 @@ UseItem::
; OUTPUT:
; clears carry flag if the item is tossed, sets carry flag if not
TossItem::
- ld a,[H_LOADEDROMBANK]
+ ld a, [H_LOADEDROMBANK]
push af
- ld a,BANK(TossItem_)
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
+ ld a, BANK(TossItem_)
+ ld [H_LOADEDROMBANK], a
+ ld [MBC1RomBank], a
call TossItem_
pop de
- ld a,d
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
+ ld a, d
+ ld [H_LOADEDROMBANK], a
+ ld [MBC1RomBank], a
ret
; checks if an item is a key item
@@ -2134,18 +2206,90 @@ IsKeyItem::
; function to draw various text boxes
; INPUT:
; [wTextBoxID] = text box ID
-; b, c = y, x cursor position (TWO_OPTION_MENU only)
DisplayTextBoxID::
- ld a,[H_LOADEDROMBANK]
+ homecall_sf DisplayTextBoxID_
+ ret
+
+UpdateGBCPal_BGP::
+ push af
+ ld a, [hGBC]
+ and a
+ jr z, .notGBC
+ push bc
+ push de
+ push hl
+ ld a, [rBGP]
+ ld b, a
+ ld a, [wLastBGP]
+ cp b
+ jr z, .noChangeInBGP
+ callba _UpdateGBCPal_BGP
+.noChangeInBGP
+ pop hl
+ pop de
+ pop bc
+.notGBC
+ pop af
+ ret
+
+UpdateGBCPal_OBP0::
+ push af
+ ld a, [hGBC]
+ and a
+ jr z, .notGBC
+ push bc
+ push de
+ push hl
+ ld a, [rOBP0]
+ ld b, a
+ ld a, [wLastOBP0]
+ cp b
+ jr z, .noChangeInOBP0
+ ld b, BANK(_UpdateGBCPal_OBP)
+ ld hl, _UpdateGBCPal_OBP
+ ld c, CONVERT_OBP0
+ call Bankswitch
+.noChangeInOBP0
+ pop hl
+ pop de
+ pop bc
+.notGBC
+ pop af
+ ret
+
+UpdateGBCPal_OBP1::
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, [rOBP1]
+ ld b, a
+ ld a, [wLastOBP1]
+ cp b
+ jr z, .noChangeInOBP1
+ ld b, BANK(_UpdateGBCPal_OBP)
+ ld hl, _UpdateGBCPal_OBP
+ ld c, CONVERT_OBP1
+ call Bankswitch
+.noChangeInOBP1
+ pop hl
+ pop de
pop bc
- ld a,b
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
+.notGBC
+ pop af
+ ret
+
+Func_3082::
+ ld a, [H_LOADEDROMBANK]
+ push af
+ call FadeOutAudio
+ callbs Music_DoLowHealthAlarm
+ callbs Audio1_UpdateMusic
+ pop af
+ call BankswitchCommon
ret
; not zero if an NPC movement script is running, the player character is
@@ -2181,14 +2325,13 @@ RunNPCMovementScript::
ld a, [H_LOADEDROMBANK]
push af
ld a, [wNPCMovementScriptBank]
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
+ call BankswitchCommon
ld a, [wNPCMovementScriptFunctionNum]
- call CallFunctionInTable
+ call JumpTable
pop af
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
+ call BankswitchCommon
ret
+
.NPCMovementScriptPointerTables
dw PalletMovementScriptPointerTable
dw PewterMuseumGuyMovementScriptPointerTable
@@ -2207,7 +2350,7 @@ StoreTrainerHeaderPointer::
ld a, h
ld [wTrainerHeaderPtr], a
ld a, l
- ld [wTrainerHeaderPtr+1], a
+ ld [wTrainerHeaderPtr + 1], a
ret
; executes the current map script from the function pointer array provided in hl.
@@ -2227,7 +2370,7 @@ ExecuteCurMapScriptInTable::
.useProvidedIndex
pop hl
ld [wCurMapScript], a
- call CallFunctionInTable
+ call JumpTable
ld a, [wCurMapScript]
ret
@@ -2581,17 +2724,6 @@ TrainerEndBattleText::
call TextCommandProcessor
jp TextScriptEnd
-; only engage withe trainer if the player is not already
-; engaged with another trainer
-; XXX unused?
-CheckIfAlreadyEngaged::
- ld a, [wFlags_0xcd60]
- bit 0, a
- ret nz
- call EngageMapTrainer
- xor a
- ret
-
PlayTrainerMusic::
ld a, [wEngagedTrainerClass]
cp OPP_SONY1
@@ -2605,8 +2737,7 @@ PlayTrainerMusic::
ret nz
xor a
ld [wAudioFadeOutControl], a
- ld a, $ff
- call PlaySound
+ call StopAllMusic ; stop music
ld a, BANK(Music_MeetEvilTrainer)
ld [wAudioROMBank], a
ld [wAudioSavedROMBank], a
@@ -2679,11 +2810,11 @@ FuncTX_BillsPC::
ld hl, BillsPC_
jr bankswitchAndContinue
-FuncTX_SlotMachine::
+FuncTX_GameCornerPrizeMenu::
; XXX find a better name for this function
; special_F7
- ld b,BANK(CeladonPrizeMenu)
- ld hl,CeladonPrizeMenu
+ ld b, BANK(CeladonPrizeMenu)
+ ld hl, CeladonPrizeMenu
bankswitchAndContinue::
call Bankswitch
jp HoldTextDisplayOpen ; continue to main text-engine function
@@ -2707,10 +2838,64 @@ IsItemInBag::
; else reset zero flag
; related to Pokémon Tower and ghosts
predef GetQuantityOfItemInBag
- ld a,b
+ ld a, b
and a
ret
+IsSurfingPikachuInParty::
+; set bit 6 of wd472 if true
+; also calls Func_3467, which is a bankswitch to IsStarterPikachuInOurParty
+ 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::
+ push hl
+ push bc
+ callab IsStarterPikachuInOurParty
+ pop bc
+ pop hl
+ ret nc
+ ld a, [wd472]
+ set 7, a
+ ld [wd472], a
+ ret
+
DisplayPokedex::
ld [wd11e], a
jpba _DisplayPokedex
@@ -2734,6 +2919,26 @@ SetSpriteImageIndexAfterSettingFacingDirection::
ld [hl], a
ret
+SpriteFunc_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
@@ -2741,32 +2946,32 @@ SetSpriteImageIndexAfterSettingFacingDirection::
; [wCoordIndex] = if there is match, the matching array index
; sets carry if the coordinates are in the array, clears carry if not
ArePlayerCoordsInArray::
- ld a,[wYCoord]
- ld b,a
- ld a,[wXCoord]
- ld c,a
+ ld a, [wYCoord]
+ ld b, a
+ ld a, [wXCoord]
+ ld c, a
; fallthrough
CheckCoords::
xor a
- ld [wCoordIndex],a
+ ld [wCoordIndex], a
.loop
- ld a,[hli]
- cp a,$ff ; reached terminator?
- jr z,.notInArray
+ ld a, [hli]
+ cp $ff ; reached terminator?
+ jr z, .notInArray
push hl
- ld hl,wCoordIndex
+ ld hl, wCoordIndex
inc [hl]
pop hl
.compareYCoord
cp b
- jr z,.compareXCoord
+ jr z, .compareXCoord
inc hl
jr .loop
.compareXCoord
- ld a,[hli]
+ ld a, [hli]
cp c
- jr nz,.loop
+ jr nz, .loop
.inArray
scf
ret
@@ -2860,31 +3065,31 @@ SetSpriteMovementBytesToFE::
SetSpriteMovementBytesToFF::
push hl
call GetSpriteMovementByte1Pointer
- ld [hl],$FF
+ ld [hl], $FF
call GetSpriteMovementByte2Pointer
- ld [hl],$FF ; prevent person from walking?
+ ld [hl], $FF ; prevent person from walking?
pop hl
ret
; returns the sprite movement byte 1 pointer for sprite [H_SPRITEINDEX] in hl
GetSpriteMovementByte1Pointer::
- ld h,$C2
- ld a,[H_SPRITEINDEX]
+ ld h, $C2
+ ld a, [H_SPRITEINDEX]
swap a
- add a,6
- ld l,a
+ add 6
+ ld l, a
ret
; returns the sprite movement byte 2 pointer for sprite [H_SPRITEINDEX] in hl
GetSpriteMovementByte2Pointer::
push de
- ld hl,wMapSpriteData
- ld a,[H_SPRITEINDEX]
+ ld hl, wMapSpriteData
+ ld a, [H_SPRITEINDEX]
dec a
add a
- ld d,0
- ld e,a
- add hl,de
+ ld e, a
+ ld d, 0
+ add hl, de
pop de
ret
@@ -2893,7 +3098,7 @@ GetTrainerInformation::
ld a, [wLinkState]
and a
jr nz, .linkBattle
- ld a, Bank(TrainerPicAndMoneyPointers)
+ ld a, BANK(TrainerPicAndMoneyPointers)
call BankswitchHome
ld a, [wTrainerClass]
dec a
@@ -2912,6 +3117,7 @@ GetTrainerInformation::
inc de
ld a, [hli]
ld [de], a
+ call IsFightingJessieJames
jp BankswitchBack
.linkBattle
ld hl, wTrainerPicPointer
@@ -2921,10 +3127,27 @@ GetTrainerInformation::
ld [hl], d
ret
+IsFightingJessieJames::
+ ld a, [wTrainerClass]
+ cp ROCKET
+ ret nz
+ ld a, [wTrainerNo]
+ 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::
jpba GetTrainerName_
-
HasEnoughMoney::
; Check if the player has at least as much
; money as the 3-byte BCD value at hMoney.
@@ -2945,37 +3168,17 @@ HasEnoughCoins::
BankswitchHome::
; 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
+ ld [wBankswitchHomeTemp], a
+ ld a, [H_LOADEDROMBANK]
+ ld [wBankswitchHomeSavedROMBank], a
+ ld a, [wBankswitchHomeTemp]
+ call BankswitchCommon
ret
BankswitchBack::
; returns from BankswitchHome
- ld a,[wBankswitchHomeSavedROMBank]
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
- ret
-
-Bankswitch::
-; 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 [MBC1RomBank],a
- ld bc,.Return
- push bc
- jp [hl]
-.Return
- pop bc
- ld a,b
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
+ ld a, [wBankswitchHomeSavedROMBank]
+ call BankswitchCommon
ret
; displays yes/no choice
@@ -2985,7 +3188,7 @@ YesNoChoice::
call InitYesNoTextBoxParameters
jr DisplayYesNoChoice
-Func_35f4::
+Func_35f7::
ld a, TWO_OPTION_MENU
ld [wTextBoxID], a
call InitYesNoTextBoxParameters
@@ -3006,7 +3209,7 @@ YesNoChoicePokeCenter::
lb bc, 8, 12
jr DisplayYesNoChoice
-Func_361a::
+Func_361d::
call SaveScreenTilesToBuffer1
ld a, WIDE_YES_NO_MENU
ld [wTwoOptionMenuID], a
@@ -3036,37 +3239,37 @@ MoveSprite_::
push bc
call GetSpriteMovementByte1Pointer
xor a
- ld [hl],a
- ld hl,wNPCMovementDirections
- ld c,0
+ ld [hl], a
+ ld hl, wNPCMovementDirections
+ ld c, 0
.loop
- ld a,[de]
- ld [hli],a
+ ld a, [de]
+ ld [hli], a
inc de
inc c
- cp a,$FF ; have we reached the end of the movement data?
- jr nz,.loop
+ cp $FF ; have we reached the end of the movement data?
+ jr nz, .loop
- ld a,c
- ld [wNPCNumScriptedSteps],a ; number of steps taken
+ ld a, c
+ ld [wNPCNumScriptedSteps], a ; number of steps taken
pop bc
- ld hl,wd730
- set 0,[hl]
+ ld hl, wd730
+ set 0, [hl]
pop hl
xor a
- ld [wOverrideSimulatedJoypadStatesMask],a
- ld [wSimulatedJoypadStatesEnd],a
+ ld [wOverrideSimulatedJoypadStatesMask], a
+ ld [wSimulatedJoypadStatesEnd], a
dec a
- ld [wJoyIgnore],a
- ld [wWastedByteCD3A],a
+ ld [wJoyIgnore], a
+ ld [wWastedByteCD3A], a
ret
; divides [hDividend2] by [hDivisor2] and stores the quotient in [hQuotient2]
DivideBytes::
push hl
- ld hl, $ffe7
+ ld hl, hQuotient2
xor a
ld [hld], a
ld a, [hld]
@@ -3110,7 +3313,7 @@ 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
@@ -3126,29 +3329,13 @@ 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::
; Decompress pic at a:de.
ld hl, wSpriteInputPtr
@@ -3157,17 +3344,15 @@ UncompressSpriteFromDE::
ld [hl], d
jp UncompressSpriteData
-
SaveScreenTilesToBuffer2::
coord hl, 0, 0
ld de, wTileMapBackup2
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
- call CopyData
- ret
+ jp CopyData
LoadScreenTilesFromBuffer2::
call LoadScreenTilesFromBuffer2DisableBGTransfer
- ld a, 1
+ ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
ret
@@ -3178,8 +3363,7 @@ LoadScreenTilesFromBuffer2DisableBGTransfer::
ld hl, wTileMapBackup2
coord de, 0, 0
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
- call CopyData
- ret
+ jp CopyData
SaveScreenTilesToBuffer1::
coord hl, 0, 0
@@ -3194,15 +3378,15 @@ LoadScreenTilesFromBuffer1::
coord de, 0, 0
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
call CopyData
- ld a, 1
+ ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
ret
DelayFrames::
-; wait n frames, where n is the value in c
+; wait c frames
call DelayFrame
dec c
- jr nz,DelayFrames
+ jr nz, DelayFrames
ret
PlaySoundWaitForCurrent::
@@ -3226,6 +3410,7 @@ WaitForSoundToFinish::
inc hl
inc hl
or [hl]
+ and a
jr nz, .waitLoop
pop hl
ret
@@ -3246,82 +3431,80 @@ GetName::
; [wPredefBank] = bank of list
;
; returns pointer to name in de
- ld a,[wd0b5]
- ld [wd11e],a
+ ld a, [wd0b5]
+ ld [wd11e], a
; TM names are separate from item names.
; BUG: This applies to all names instead of just items.
cp HM_01
jp nc, GetMachineName
- ld a,[H_LOADEDROMBANK]
+ ld a, [H_LOADEDROMBANK]
push af
push hl
push bc
push de
- ld a,[wNameListType] ;List3759_entrySelector
+ ld a, [wNameListType] ;List3759_entrySelector
dec a
- jr nz,.otherEntries
+ jr nz, .otherEntries
;1 = MON_NAMES
call GetMonName
- ld hl,NAME_LENGTH
- add hl,de
- ld e,l
- ld d,h
+ ld hl, NAME_LENGTH
+ add hl, de
+ ld e, l
+ ld d, h
jr .gotPtr
.otherEntries
;2-7 = OTHER ENTRIES
- ld a,[wPredefBank]
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
- ld a,[wNameListType] ;VariousNames' entryID
+ ld a, [wPredefBank]
+ call BankswitchCommon
+ ld a, [wNameListType] ;VariousNames' entryID
dec a
add a
- ld d,0
- ld e,a
- jr nc,.skip
+ ld d, 0
+ ld e, a
+ jr nc, .skip
inc d
.skip
- ld hl,NamePointers
- add hl,de
- ld a,[hli]
- ld [$ff96],a
- ld a,[hl]
- ld [$ff95],a
- ld a,[$ff95]
- ld h,a
- ld a,[$ff96]
- ld l,a
- ld a,[wd0b5]
- ld b,a
- ld c,0
+ ld hl, NamePointers
+ add hl, de
+ ld a, [hli]
+ ld [$ff96], a
+ ld a, [hl]
+ ld [$ff95], a
+ ld a, [$ff95]
+ ld h, a
+ ld a, [$ff96]
+ ld l, a
+ ld a, [wd0b5]
+ ld b, a
+ ld c, 0
.nextName
- ld d,h
- ld e,l
+ ld d, h
+ ld e, l
.nextChar
- ld a,[hli]
- cp a, "@"
- jr nz,.nextChar
+ ld a, [hli]
+ cp "@"
+ jr nz, .nextChar
inc c ;entry counter
- ld a,b ;wanted entry
+ ld a, b ;wanted entry
cp c
- jr nz,.nextName
- ld h,d
- ld l,e
- ld de,wcd6d
- ld bc,$0014
+ jr nz, .nextName
+ ld h, d
+ ld l, e
+ ld de, wcd6d
+ ld bc, $0014
call CopyData
.gotPtr
- ld a,e
- ld [wUnusedCF8D],a
- ld a,d
- ld [wUnusedCF8D + 1],a
+ ld a, e
+ ld [wUnusedCF8D], a
+ ld a, d
+ ld [wUnusedCF8D + 1], a
pop de
pop bc
pop hl
pop af
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
+ call BankswitchCommon
ret
GetItemPrice::
@@ -3332,11 +3515,10 @@ GetItemPrice::
ld a, [wListMenuID]
cp MOVESLISTMENU
ld a, BANK(ItemPrices)
- jr nz, .asm_37ed
+ 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 +3527,10 @@ GetItemPrice::
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,17 +3538,13 @@ GetItemPrice::
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]
@@ -3400,41 +3578,41 @@ CopyString::
; ([hJoy7] == 1, [hJoy6] == 0)
JoypadLowSensitivity::
call Joypad
- ld a,[hJoy7] ; flag
+ ld a, [hJoy7] ; flag
and a ; get all currently pressed buttons or only newly pressed buttons?
- ld a,[hJoyPressed] ; newly pressed buttons
- jr z,.storeButtonState
- ld a,[hJoyHeld] ; all currently pressed buttons
+ ld a, [hJoyPressed] ; newly pressed buttons
+ jr z, .storeButtonState
+ ld a, [hJoyHeld] ; all currently pressed buttons
.storeButtonState
- ld [hJoy5],a
- ld a,[hJoyPressed] ; newly pressed buttons
+ ld [hJoy5], a
+ ld a, [hJoyPressed] ; newly pressed buttons
and a ; have any buttons been newly pressed since last check?
- jr z,.noNewlyPressedButtons
+ jr z, .noNewlyPressedButtons
.newlyPressedButtons
- ld a,30 ; half a second delay
- ld [H_FRAMECOUNTER],a
+ ld a, 30 ; half a second delay
+ ld [H_FRAMECOUNTER], a
ret
.noNewlyPressedButtons
- ld a,[H_FRAMECOUNTER]
+ ld a, [H_FRAMECOUNTER]
and a ; is the delay over?
- jr z,.delayOver
+ jr z, .delayOver
.delayNotOver
xor a
- ld [hJoy5],a ; report no buttons as pressed
+ ld [hJoy5], a ; report no buttons as pressed
ret
.delayOver
; if [hJoy6] = 0 and A or B is pressed, report no buttons as pressed
- ld a,[hJoyHeld]
+ ld a, [hJoyHeld]
and A_BUTTON | B_BUTTON
- jr z,.setShortDelay
- ld a,[hJoy6] ; flag
+ jr z, .setShortDelay
+ ld a, [hJoy6] ; flag
and a
- jr nz,.setShortDelay
+ jr nz, .setShortDelay
xor a
- ld [hJoy5],a
+ ld [hJoy5], a
.setShortDelay
- ld a,5 ; 1/12 of a second delay
- ld [H_FRAMECOUNTER],a
+ ld a, 5 ; 1/12 of a second delay
+ ld [H_FRAMECOUNTER], a
ret
WaitForTextScrollButtonPress::
@@ -3451,7 +3629,11 @@ WaitForTextScrollButtonPress::
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
@@ -3473,7 +3655,8 @@ ManualTextScroll::
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
@@ -3489,7 +3672,7 @@ ManualTextScroll::
Multiply::
push hl
push bc
- callab _Multiply
+ callab _Multiply ; 3d:660e
pop bc
pop hl
ret
@@ -3507,15 +3690,7 @@ Divide::
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
@@ -3525,42 +3700,42 @@ Divide::
; screen unless the player presses the A/B button or the delay is turned off
; through the [wd730] or [wLetterPrintingDelayFlags] flags.
PrintLetterDelay::
- ld a,[wd730]
- bit 6,a
+ ld a, [wd730]
+ bit 6, a
ret nz
- ld a,[wLetterPrintingDelayFlags]
- bit 1,a
+ ld a, [wLetterPrintingDelayFlags]
+ bit 1, a
ret z
push hl
push de
push bc
- ld a,[wLetterPrintingDelayFlags]
- bit 0,a
- jr z,.waitOneFrame
- ld a,[wOptions]
+ ld a, [wLetterPrintingDelayFlags]
+ bit 0, a
+ jr z, .waitOneFrame
+ ld a, [wOptions]
and $f
- ld [H_FRAMECOUNTER],a
+ ld [H_FRAMECOUNTER], a
jr .checkButtons
.waitOneFrame
- ld a,1
- ld [H_FRAMECOUNTER],a
+ ld a, 1
+ ld [H_FRAMECOUNTER], a
.checkButtons
call Joypad
- ld a,[hJoyHeld]
+ ld a, [hJoyHeld]
.checkAButton
- bit 0,a ; is the A button pressed?
- jr z,.checkBButton
+ bit 0, a ; is the A button pressed?
+ jr z, .checkBButton
jr .endWait
.checkBButton
- bit 1,a ; is the B button pressed?
- jr z,.buttonsNotPressed
+ bit 1, a ; is the B button pressed?
+ jr z, .buttonsNotPressed
.endWait
call DelayFrame
jr .done
.buttonsNotPressed ; if neither A nor B is pressed
- ld a,[H_FRAMECOUNTER]
+ ld a, [H_FRAMECOUNTER]
and a
- jr nz,.checkButtons
+ jr nz, .checkButtons
.done
pop bc
pop de
@@ -3571,15 +3746,15 @@ PrintLetterDelay::
; In other words, the source data is from hl up to but not including bc,
; and the destination is de.
CopyDataUntil::
- ld a,[hli]
- ld [de],a
+ ld a, [hli]
+ ld [de], a
inc de
- ld a,h
+ ld a, h
cp b
- jr nz,CopyDataUntil
- ld a,l
+ jr nz, CopyDataUntil
+ ld a, l
cp c
- jr nz,CopyDataUntil
+ jr nz, CopyDataUntil
ret
; Function to remove a pokemon from the party or the current box.
@@ -3605,10 +3780,10 @@ CalcStats::
.statsLoop
inc c
call CalcStat
- ld a, [H_MULTIPLICAND+1]
+ ld a, [H_MULTIPLICAND + 1]
ld [de], a
inc de
- ld a, [H_MULTIPLICAND+2]
+ ld a, [H_MULTIPLICAND + 2]
ld [de], a
inc de
ld a, c
@@ -3617,7 +3792,7 @@ CalcStats::
ret
; calculates stat c of current mon
-; c: stat to calc (HP=1,Atk=2,Def=3,Spd=4,Spc=5)
+; 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::
@@ -3642,12 +3817,12 @@ CalcStat::
.statExpLoop ; calculates ceil(Sqrt(stat exp)) in b
xor a
ld [H_MULTIPLICAND], a
- ld [H_MULTIPLICAND+1], a
+ ld [H_MULTIPLICAND + 1], a
inc b ; increment current stat exp bonus
ld a, b
cp $ff
jr z, .statExpDone
- ld [H_MULTIPLICAND+2], a
+ ld [H_MULTIPLICAND + 2], a
ld [H_MULTIPLIER], a
call Multiply
ld a, [hld]
@@ -3736,9 +3911,9 @@ CalcStat::
jr nc, .noCarry2
inc d ; da = (Base + IV) * 2 + ceil(Sqrt(stat exp)) / 4
.noCarry2
- ld [H_MULTIPLICAND+2], a
+ ld [H_MULTIPLICAND + 2], a
ld a, d
- ld [H_MULTIPLICAND+1], a
+ ld [H_MULTIPLICAND + 1], a
xor a
ld [H_MULTIPLICAND], a
ld a, [wCurEnemyLVL]
@@ -3746,10 +3921,10 @@ CalcStat::
call Multiply ; ((Base + IV) * 2 + ceil(Sqrt(stat exp)) / 4) * Level
ld a, [H_MULTIPLICAND]
ld [H_DIVIDEND], a
- ld a, [H_MULTIPLICAND+1]
- ld [H_DIVIDEND+1], a
- ld a, [H_MULTIPLICAND+2]
- ld [H_DIVIDEND+2], a
+ ld a, [H_MULTIPLICAND + 1]
+ ld [H_DIVIDEND + 1], a
+ ld a, [H_MULTIPLICAND + 2]
+ ld [H_DIVIDEND + 2], a
ld a, $64
ld [H_DIVISOR], a
ld a, $3
@@ -3761,38 +3936,38 @@ CalcStat::
jr nz, .notHPStat
ld a, [wCurEnemyLVL]
ld b, a
- ld a, [H_MULTIPLICAND+2]
+ ld a, [H_MULTIPLICAND + 2]
add b
- ld [H_MULTIPLICAND+2], a
+ ld [H_MULTIPLICAND + 2], a
jr nc, .noCarry3
- ld a, [H_MULTIPLICAND+1]
+ ld a, [H_MULTIPLICAND + 1]
inc a
- ld [H_MULTIPLICAND+1], a ; HP: (((Base + IV) * 2 + ceil(Sqrt(stat exp)) / 4) * Level) / 100 + Level
+ ld [H_MULTIPLICAND + 1], a ; HP: (((Base + IV) * 2 + ceil(Sqrt(stat exp)) / 4) * Level) / 100 + Level
.noCarry3
- ld a, 10 ; +10 for HP stat
+ ld a, 10 ; + 10 for HP stat
.notHPStat
ld b, a
- ld a, [H_MULTIPLICAND+2]
+ ld a, [H_MULTIPLICAND + 2]
add b
- ld [H_MULTIPLICAND+2], a
+ ld [H_MULTIPLICAND + 2], a
jr nc, .noCarry4
- ld a, [H_MULTIPLICAND+1]
+ ld a, [H_MULTIPLICAND + 1]
inc a ; non-HP: (((Base + IV) * 2 + ceil(Sqrt(stat exp)) / 4) * Level) / 100 + 5
- ld [H_MULTIPLICAND+1], a ; HP: (((Base + IV) * 2 + ceil(Sqrt(stat exp)) / 4) * Level) / 100 + Level + 10
+ ld [H_MULTIPLICAND + 1], a ; HP: (((Base + IV) * 2 + ceil(Sqrt(stat exp)) / 4) * Level) / 100 + Level + 10
.noCarry4
- ld a, [H_MULTIPLICAND+1] ; check for overflow (>999)
+ ld a, [H_MULTIPLICAND + 1] ; check for overflow (>999)
cp 999 / $100 + 1
jr nc, .overflow
cp 999 / $100
jr c, .noOverflow
- ld a, [H_MULTIPLICAND+2]
+ ld a, [H_MULTIPLICAND + 2]
cp 999 % $100 + 1
jr c, .noOverflow
.overflow
ld a, 999 / $100 ; overflow: cap at 999
- ld [H_MULTIPLICAND+1], a
+ ld [H_MULTIPLICAND + 1], a
ld a, 999 % $100
- ld [H_MULTIPLICAND+2], a
+ ld [H_MULTIPLICAND + 2], a
.noOverflow
pop bc
pop de
@@ -3800,29 +3975,11 @@ CalcStat::
ret
AddEnemyMonToPlayerParty::
- 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
+ homecall_sf _AddEnemyMonToPlayerParty
ret
MoveMon::
- 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
+ homecall_sf _MoveMon
ret
; skips a text entries, each of size NAME_LENGTH (like trainer name, OT name, rival name, ...)
@@ -3842,21 +3999,21 @@ AddNTimes::
and a
ret z
.loop
- add hl,bc
+ add hl, bc
dec a
- jr nz,.loop
+ jr nz, .loop
ret
; Compare strings, c bytes in length, at de and hl.
; Often used to compare big endian numbers in battle calculations.
StringCmp::
- ld a,[de]
+ ld a, [de]
cp [hl]
ret nz
inc de
inc hl
dec c
- jr nz,StringCmp
+ jr nz, StringCmp
ret
; INPUT:
@@ -3865,228 +4022,226 @@ StringCmp::
; c = X coordinate of upper left corner of sprite
; de = base address of 4 tile number and attribute pairs
WriteOAMBlock::
- ld h,wOAMBuffer / $100
+ ld h, wOAMBuffer / $100
swap a ; multiply by 16
- ld l,a
+ ld l, a
call .writeOneEntry ; upper left
push bc
- ld a,8
+ ld a, 8
add c
- ld c,a
+ ld c, a
call .writeOneEntry ; upper right
pop bc
- ld a,8
+ ld a, 8
add b
- ld b,a
+ ld b, a
call .writeOneEntry ; lower left
- ld a,8
+ ld a, 8
add c
- ld c,a
+ ld c, a
; lower right
-.writeOneEntry
- ld [hl],b ; Y coordinate
+.writeOneEntry ; 3aa0 (0:3aa0)
+ ld [hl], b ; Y coordinate
inc hl
- ld [hl],c ; X coordinate
+ ld [hl], c ; X coordinate
inc hl
- ld a,[de] ; tile number
+ ld a, [de] ; tile number
inc de
- ld [hli],a
- ld a,[de] ; attribute
+ ld [hli], a
+ ld a, [de] ; attribute
inc de
- ld [hli],a
+ ld [hli], a
ret
HandleMenuInput::
xor a
- ld [wPartyMenuAnimMonEnabled],a
+ ld [wPartyMenuAnimMonEnabled], a
-HandleMenuInput_::
- ld a,[H_DOWNARROWBLINKCNT1]
+HandleMenuInputPokemonSelection::
+ ld a, [H_DOWNARROWBLINKCNT1]
push af
- ld a,[H_DOWNARROWBLINKCNT2]
+ ld a, [H_DOWNARROWBLINKCNT2]
push af ; save existing values on stack
xor a
- ld [H_DOWNARROWBLINKCNT1],a ; blinking down arrow timing value 1
- ld a,6
- ld [H_DOWNARROWBLINKCNT2],a ; blinking down arrow timing value 2
+ ld [H_DOWNARROWBLINKCNT1], a ; blinking down arrow timing value 1
+ ld a, 6
+ ld [H_DOWNARROWBLINKCNT2], a ; blinking down arrow timing value 2
.loop1
xor a
- ld [wAnimCounter],a ; counter for pokemon shaking animation
+ ld [wAnimCounter], a ; counter for pokemon shaking animation
call PlaceMenuCursor
call Delay3
.loop2
push hl
- ld a,[wPartyMenuAnimMonEnabled]
+ ld a, [wPartyMenuAnimMonEnabled]
and a ; is it a pokemon selection menu?
- jr z,.getJoypadState
- callba AnimatePartyMon ; shake mini sprite of selected pokemon
+ jr z, .getJoypadState
+ callba AnimatePartyMon ; shake mini sprite of selected pokemon (1c:578c)
.getJoypadState
pop hl
call JoypadLowSensitivity
- ld a,[hJoy5]
+ ld a, [hJoy5]
and a ; was a key pressed?
- jr nz,.keyPressed
+ jr nz, .keyPressed
push hl
coord hl, 18, 11 ; coordinates of blinking down arrow in some menus
call HandleDownArrowBlinkTiming ; blink down arrow (if any)
pop hl
- ld a,[wMenuJoypadPollCount]
+ ld a, [wMenuJoypadPollCount]
dec a
- jr z,.giveUpWaiting
+ jr z, .giveUpWaiting
jr .loop2
.giveUpWaiting
; if a key wasn't pressed within the specified number of checks
pop af
- ld [H_DOWNARROWBLINKCNT2],a
+ ld [H_DOWNARROWBLINKCNT2], a
pop af
- ld [H_DOWNARROWBLINKCNT1],a ; restore previous values
+ ld [H_DOWNARROWBLINKCNT1], a ; restore previous values
xor a
- ld [wMenuWrappingEnabled],a ; disable menu wrapping
+ ld [wMenuWrappingEnabled], a ; disable menu wrapping
ret
.keyPressed
xor a
- ld [wCheckFor180DegreeTurn],a
- ld a,[hJoy5]
- ld b,a
- bit 6,a ; pressed Up key?
- jr z,.checkIfDownPressed
+ 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
- ld a,[wCurrentMenuItem] ; selected menu item
+ ld a, [wCurrentMenuItem] ; selected menu item
and a ; already at the top of the menu?
- jr z,.alreadyAtTop
+ jr z, .alreadyAtTop
.notAtTop
dec a
- ld [wCurrentMenuItem],a ; move selected menu item up one space
+ ld [wCurrentMenuItem], a ; move selected menu item up one space
jr .checkOtherKeys
.alreadyAtTop
- ld a,[wMenuWrappingEnabled]
+ ld a, [wMenuWrappingEnabled]
and a ; is wrapping around enabled?
- jr z,.noWrappingAround
- ld a,[wMaxMenuItem]
- ld [wCurrentMenuItem],a ; wrap to the bottom of the menu
+ jr z, .noWrappingAround
+ ld a, [wMaxMenuItem]
+ ld [wCurrentMenuItem], a ; wrap to the bottom of the menu
jr .checkOtherKeys
.checkIfDownPressed
- bit 7,a
- jr z,.checkOtherKeys
+ bit 7, a
+ jr z, .checkOtherKeys
.downPressed
- ld a,[wCurrentMenuItem]
+ ld a, [wCurrentMenuItem]
inc a
- ld c,a
- ld a,[wMaxMenuItem]
+ ld c, a
+ ld a, [wMaxMenuItem]
cp c
- jr nc,.notAtBottom
+ jr nc, .notAtBottom
.alreadyAtBottom
- ld a,[wMenuWrappingEnabled]
+ ld a, [wMenuWrappingEnabled]
and a ; is wrapping around enabled?
- jr z,.noWrappingAround
- ld c,$00 ; wrap from bottom to top
+ jr z, .noWrappingAround
+ ld c, $00 ; wrap from bottom to top
.notAtBottom
- ld a,c
- ld [wCurrentMenuItem],a
+ ld a, c
+ ld [wCurrentMenuItem], a
.checkOtherKeys
- ld a,[wMenuWatchedKeys]
+ ld a, [wMenuWatchedKeys]
and b ; does the menu care about any of the pressed keys?
- jp z,.loop1
+ jp z, .loop1
.checkIfAButtonOrBButtonPressed
- ld a,[hJoy5]
+ ld a, [hJoy5]
and A_BUTTON | B_BUTTON
- jr z,.skipPlayingSound
+ jr z, .skipPlayingSound
.AButtonOrBButtonPressed
push hl
- ld hl,wFlags_0xcd60
- bit 5,[hl]
+ ld hl, wFlags_0xcd60
+ bit 5, [hl]
pop hl
- jr nz,.skipPlayingSound
- ld a,SFX_PRESS_AB
- call PlaySound
+ jr nz, .skipPlayingSound
+ ld a, $90 ; SFX_PRESS_AB
+ call PlaySound ; play sound
.skipPlayingSound
pop af
- ld [H_DOWNARROWBLINKCNT2],a
+ ld [H_DOWNARROWBLINKCNT2], a
pop af
- ld [H_DOWNARROWBLINKCNT1],a ; restore previous values
+ ld [H_DOWNARROWBLINKCNT1], a ; restore previous values
xor a
- ld [wMenuWrappingEnabled],a ; disable menu wrapping
- ld a,[hJoy5]
+ ld [wMenuWrappingEnabled], a ; disable menu wrapping
+ ld a, [hJoy5]
ret
.noWrappingAround
- ld a,[wMenuWatchMovingOutOfBounds]
+ ld a, [wMenuWatchMovingOutOfBounds]
and a ; should we return if the user tried to go past the top or bottom?
- jr z,.checkOtherKeys
+ jr z, .checkOtherKeys
jr .checkIfAButtonOrBButtonPressed
PlaceMenuCursor::
- ld a,[wTopMenuItemY]
+ ld a, [wTopMenuItemY]
and a ; is the y coordinate 0?
- jr z,.adjustForXCoord
+ jr z, .adjustForXCoord
coord hl, 0, 0
- ld bc,SCREEN_WIDTH
+ ld bc, SCREEN_WIDTH
.topMenuItemLoop
- add hl,bc
+ add hl, bc
dec a
- jr nz,.topMenuItemLoop
+ jr nz, .topMenuItemLoop
.adjustForXCoord
- ld a,[wTopMenuItemX]
- ld b,0
- ld c,a
- add hl,bc
+ ld a, [wTopMenuItemX]
+ ld b, 0
+ ld c, a
+ add hl, bc
push hl
- ld a,[wLastMenuItem]
+ ld a, [wLastMenuItem]
and a ; was the previous menu id 0?
- jr z,.checkForArrow1
+ jr z, .checkForArrow1
+ ld bc, 40
push af
- ld a,[hFlags_0xFFF6]
- bit 1,a ; is the menu double spaced?
- jr z,.doubleSpaced1
- ld bc,20
- jr .getOldMenuItemScreenPosition
+ ld a, [hFlags_0xFFFA]
+ bit 1, a ; is the menu double spaced?
+ jr z, .doubleSpaced1
+ ld bc, 20
.doubleSpaced1
- ld bc,40
-.getOldMenuItemScreenPosition
pop af
.oldMenuItemLoop
- add hl,bc
+ add hl, bc
dec a
- jr nz,.oldMenuItemLoop
+ jr nz, .oldMenuItemLoop
.checkForArrow1
- ld a,[hl]
- cp a,"▶" ; was an arrow next to the previously selected menu item?
- jr nz,.skipClearingArrow
+ ld a, [hl]
+ cp "▶" ; was an arrow next to the previously selected menu item?
+ jr nz, .skipClearingArrow
.clearArrow
- ld a,[wTileBehindCursor]
- ld [hl],a
+ ld a, [wTileBehindCursor]
+ ld [hl], a
.skipClearingArrow
pop hl
- ld a,[wCurrentMenuItem]
+ ld a, [wCurrentMenuItem]
and a
- jr z,.checkForArrow2
+ jr z, .checkForArrow2
+ ld bc, 40
push af
- ld a,[hFlags_0xFFF6]
- bit 1,a ; is the menu double spaced?
- jr z,.doubleSpaced2
- ld bc,20
- jr .getCurrentMenuItemScreenPosition
+ ld a, [hFlags_0xFFFA]
+ bit 1, a ; is the menu double spaced?
+ jr z, .doubleSpaced2
+ ld bc, 20
.doubleSpaced2
- ld bc,40
-.getCurrentMenuItemScreenPosition
pop af
.currentMenuItemLoop
- add hl,bc
+ add hl, bc
dec a
- jr nz,.currentMenuItemLoop
+ jr nz, .currentMenuItemLoop
.checkForArrow2
- ld a,[hl]
- cp a,"▶" ; has the right arrow already been placed?
- jr z,.skipSavingTile ; if so, don't lose the saved tile
- ld [wTileBehindCursor],a ; save tile before overwriting with right arrow
+ ld a, [hl]
+ cp "▶" ; has the right arrow already been placed?
+ jr z, .skipSavingTile ; if so, don't lose the saved tile
+ ld [wTileBehindCursor], a ; save tile before overwriting with right arrow
.skipSavingTile
- ld a,"▶" ; place right arrow
- ld [hl],a
- ld a,l
- ld [wMenuCursorLocation],a
- ld a,h
- ld [wMenuCursorLocation + 1],a
- ld a,[wCurrentMenuItem]
- ld [wLastMenuItem],a
+ ld a, "▶" ; place right arrow
+ ld [hl], a
+ ld a, l
+ ld [wMenuCursorLocation], a
+ ld a, h
+ ld [wMenuCursorLocation + 1], a
+ ld a, [wCurrentMenuItem]
+ ld [wLastMenuItem], a
ret
; This is used to mark a menu cursor other than the one currently being
@@ -4094,22 +4249,22 @@ PlaceMenuCursor::
; 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::
- ld b,a
- ld a,[wMenuCursorLocation]
- ld l,a
- ld a,[wMenuCursorLocation + 1]
- ld h,a
- ld [hl],$ec ; outline of right arrow
- ld a,b
+ ld b, a
+ ld a, [wMenuCursorLocation]
+ ld l, a
+ ld a, [wMenuCursorLocation + 1]
+ ld h, a
+ ld [hl], $ec ; outline of right arrow
+ ld a, b
ret
; Replaces the menu cursor with a blank space.
EraseMenuCursor::
- ld a,[wMenuCursorLocation]
- ld l,a
- ld a,[wMenuCursorLocation + 1]
- ld h,a
- ld [hl]," "
+ ld a, [wMenuCursorLocation]
+ ld l, a
+ ld a, [wMenuCursorLocation + 1]
+ ld h, a
+ ld [hl], " "
ret
; This toggles a blinking down arrow at hl on and off after a delay has passed.
@@ -4121,44 +4276,44 @@ EraseMenuCursor::
; That allows this to be called without worrying about if a down arrow should
; be blinking.
HandleDownArrowBlinkTiming::
- ld a,[hl]
- ld b,a
- ld a,$ee ; down arrow
+ ld a, [hl]
+ ld b, a
+ ld a, $ee ; down arrow
cp b
- jr nz,.downArrowOff
+ jr nz, .downArrowOff
.downArrowOn
- ld a,[H_DOWNARROWBLINKCNT1]
+ ld a, [H_DOWNARROWBLINKCNT1]
dec a
- ld [H_DOWNARROWBLINKCNT1],a
+ ld [H_DOWNARROWBLINKCNT1], a
ret nz
- ld a,[H_DOWNARROWBLINKCNT2]
+ ld a, [H_DOWNARROWBLINKCNT2]
dec a
- ld [H_DOWNARROWBLINKCNT2],a
+ ld [H_DOWNARROWBLINKCNT2], a
ret nz
- ld a," "
- ld [hl],a
- ld a,$ff
- ld [H_DOWNARROWBLINKCNT1],a
- ld a,$06
- ld [H_DOWNARROWBLINKCNT2],a
+ ld a, " "
+ ld [hl], a
+ ld a, $ff
+ ld [H_DOWNARROWBLINKCNT1], a
+ ld a, $06
+ ld [H_DOWNARROWBLINKCNT2], a
ret
.downArrowOff
- ld a,[H_DOWNARROWBLINKCNT1]
+ ld a, [H_DOWNARROWBLINKCNT1]
and a
ret z
dec a
- ld [H_DOWNARROWBLINKCNT1],a
+ ld [H_DOWNARROWBLINKCNT1], a
ret nz
dec a
- ld [H_DOWNARROWBLINKCNT1],a
- ld a,[H_DOWNARROWBLINKCNT2]
+ ld [H_DOWNARROWBLINKCNT1], a
+ ld a, [H_DOWNARROWBLINKCNT2]
dec a
- ld [H_DOWNARROWBLINKCNT2],a
+ ld [H_DOWNARROWBLINKCNT2], a
ret nz
- ld a,$06
- ld [H_DOWNARROWBLINKCNT2],a
- ld a,$ee ; down arrow
- ld [hl],a
+ ld a, $06
+ ld [H_DOWNARROWBLINKCNT2], a
+ ld a, $ee ; down arrow
+ ld [hl], a
ret
; The following code either enables or disables the automatic drawing of
@@ -4170,19 +4325,19 @@ EnableAutoTextBoxDrawing::
jr AutoTextBoxDrawingCommon
DisableAutoTextBoxDrawing::
- ld a,$01
+ ld a, $01
AutoTextBoxDrawingCommon::
- ld [wAutoTextBoxDrawingControl],a
+ ld [wAutoTextBoxDrawingControl], a
xor a
- ld [wDoNotWaitForButtonPressAfterDisplayingText],a ; make DisplayTextID wait for button press
+ ld [wDoNotWaitForButtonPressAfterDisplayingText], a ; make DisplayTextID wait for button press
ret
PrintText::
; Print text hl at (1, 14).
push hl
- ld a,MESSAGE_BOX
- ld [wTextBoxID],a
+ ld a, MESSAGE_BOX
+ ld [wTextBoxID], a
call DisplayTextBoxID
call UpdateSprites
call Delay3
@@ -4191,8 +4346,18 @@ PrintText_NoCreatingTextBox::
coord bc, 1, 14
jp TextCommandProcessor
+FarPrintText::
+; 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:: ; 3c5f
+PrintNumber::
; 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.
@@ -4411,7 +4576,6 @@ endm
ret
-CallFunctionInTable::
JumpTable::
; Call function a in jumptable hl.
; de is not preserved.
@@ -4461,6 +4625,8 @@ IsInRestOfArray::
scf
ret
+InitMapSprites::
+ jpab _InitMapSprites
RestoreScreenTilesAndReloadTilePatterns::
call ClearSprites
@@ -4488,21 +4654,27 @@ GBPalNormal::
ld [rBGP], a
ld a, %11010000 ; 3100
ld [rOBP0], a
+ call UpdateGBCPal_BGP
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
ret
GBPalWhiteOut::
; White out all palettes.
xor a
- ld [rBGP],a
- ld [rOBP0],a
- ld [rOBP1],a
+ ld [rBGP], a
+ ld [rOBP0], a
+ ld [rOBP1], a
+ call UpdateGBCPal_BGP
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
ret
RunDefaultPaletteCommand::
- ld b,$ff
+ ld b, $ff
RunPaletteCommand::
- ld a,[wOnSGB]
+ ld a, [wOnSGB]
and a
ret z
predef_jump _RunPaletteCommand
@@ -4533,7 +4705,7 @@ ReloadMapSpriteTilePatterns::
xor a
ld [wSpriteSetID], a
call DisableLCD
- callba InitMapSprites
+ call InitMapSprites
call EnableLCD
pop hl
pop af
@@ -4552,7 +4724,7 @@ GiveItem::
ld [wcf91], a
ld a, c
ld [wItemQuantity], a
- ld hl,wNumBagItems
+ ld hl, wNumBagItems
call AddItemToInventory
ret nc
call GetItemName
@@ -4568,8 +4740,7 @@ GivePokemon::
ld [wCurEnemyLVL], a
xor a ; PLAYER_PARTY_DATA
ld [wMonDataLocation], a
- jpba _GivePokemon
-
+ jpba _GivePokemon ; 3d:66fa
Random::
; Return a random number in a.
@@ -4584,12 +4755,52 @@ Random::
pop hl
ret
+BankswitchCommon::
+ ld [H_LOADEDROMBANK], a
+ ld [MBC1RomBank], a
+ ret
-INCLUDE "home/predef.asm"
+Bankswitch::
+; 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 [MBC1RomBank], a
+ call JumpToAddress
+ pop bc
+ ld a, b
+ ld [H_LOADEDROMBANK], a
+ ld [MBC1RomBank], a
+ ret
+JumpToAddress::
+ jp [hl]
+SwitchSRAMBankAndLatchClockData::
+ push af
+ ld a, $1
+ ld [MBC1SRamBankingMode], a
+ ld a, SRAM_ENABLE
+ ld [MBC1SRamEnable], a
+ pop af
+ ld [MBC1SRamBank], a
+ ret
+
+PrepareRTCDataAndDisableSRAM::
+ push af
+ ld a, $0
+ ld [MBC1SRamBankingMode], a
+ ld [MBC1SRamEnable], a
+ pop af
+ ret
+
+INCLUDE "home/predef.asm"
UpdateCinnabarGymGateTileBlocks::
- jpba UpdateCinnabarGymGateTileBlocks_
+ callba UpdateCinnabarGymGateTileBlocks_
+ ret ; again?
+ ;jp Bankswitch
CheckForHiddenObjectOrBookshelfOrCardKeyDoor::
ld a, [H_LOADEDROMBANK]
@@ -4598,23 +4809,19 @@ CheckForHiddenObjectOrBookshelfOrCardKeyDoor::
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,12 +4831,11 @@ CheckForHiddenObjectOrBookshelfOrCardKeyDoor::
.done
ld [$ffeb], a
pop af
- ld [MBC1RomBank], a
- ld [H_LOADEDROMBANK], a
+ call BankswitchCommon
ret
PrintPredefTextID::
- ld [hSpriteIndexOrTextID], a
+ ld [hSpriteIndexOrTextID], a ; $ff8c
ld hl, TextPredefs
call SetMapTextPointer
ld hl, wTextPredefFlag
@@ -4656,6 +4862,8 @@ SetMapTextPointer::
ret
TextPredefs::
+const_value = 1
+
add_tx_pre CardKeySuccessText ; 01
add_tx_pre CardKeyFailText ; 02
add_tx_pre RedBedroomPCText ; 03
@@ -4667,58 +4875,64 @@ TextPredefs::
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 VermilionGymTrashSuccessText1 ; 3B
- add_tx_pre VermilionGymTrashSuccessText2 ; 3C XXX unused
- add_tx_pre VermilionGymTrashSuccessText3 ; 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
+ add_tx_pre FanClubPicture1Text ; 0C
+ add_tx_pre FanClubPicture2Text ; 0D
+ add_tx_pre GymStatueText1 ; 0E
+ add_tx_pre GymStatueText2 ; 0F
+ add_tx_pre BookcaseText ; 10
+ add_tx_pre ViridianCityPokecenterBenchGuyText ; 11
+ add_tx_pre PewterCityPokecenterBenchGuyText ; 12
+ add_tx_pre CeruleanCityPokecenterBenchGuyText ; 13
+ add_tx_pre LavenderCityPokecenterBenchGuyText ; 14
+ add_tx_pre VermilionCityPokecenterBenchGuyText ; 15
+ add_tx_pre CeladonCityPokecenterBenchGuyText ; 16
+ add_tx_pre CeladonCityHotelText ; 17
+ add_tx_pre FuchsiaCityPokecenterBenchGuyText ; 18
+ add_tx_pre CinnabarIslandPokecenterBenchGuyText ; 19
+ add_tx_pre SaffronCityPokecenterBenchGuyText ; 1A
+ add_tx_pre MtMoonPokecenterBenchGuyText ; 1B
+ add_tx_pre RockTunnelPokecenterBenchGuyText ; 1C
+ add_tx_pre UnusedBenchGuyText1 ; 1D
+ add_tx_pre UnusedBenchGuyText2 ; 1E
+ add_tx_pre UnusedBenchGuyText3 ; 1F
+ add_tx_pre UnusedPredefText ; 20
+ add_tx_pre PokemonCenterPCText ; 21
+ add_tx_pre ViridianSchoolNotebook ; 22
+ add_tx_pre ViridianSchoolBlackboard ; 23
+ ; add_tx_pre FakeTextPredef22
+ ; add_tx_pre FakeTextPredef23
+ add_tx_pre JustAMomentText ; 24
+ add_tx_pre OpenBillsPCText ; 25
+ add_tx_pre FoundHiddenItemText ; 26
+ add_tx_pre HiddenItemBagFullText ; 27
+ add_tx_pre VermilionGymTrashText ; 28
+ add_tx_pre IndigoPlateauHQText ; 29
+ add_tx_pre GameCornerOutOfOrderText ; 2A
+ add_tx_pre GameCornerOutToLunchText ; 2B
+ add_tx_pre GameCornerSomeonesKeysText ; 2C
+ add_tx_pre FoundHiddenCoinsText ; 2D
+ add_tx_pre DroppedHiddenCoinsText ; 2E
+ add_tx_pre BillsHouseMonitorText ; 2F
+ add_tx_pre BillsHouseInitiatedText ; 30
+ add_tx_pre BillsHousePokemonList ; 31
+ add_tx_pre MagazinesText ; 32
+ add_tx_pre CinnabarGymQuiz ; 33
+ add_tx_pre GameCornerNoCoinsText ; 34
+ add_tx_pre GameCornerCoinCaseText ; 35
+ add_tx_pre LinkCableHelp ; 36
+ add_tx_pre TMNotebook ; 37
+ add_tx_pre FightingDojoText ; 38
+ add_tx_pre EnemiesOnEverySideText ; 39
+ add_tx_pre WhatGoesAroundComesAroundText ; 3A
+ add_tx_pre NewBicycleText ; 3B
+ add_tx_pre IndigoPlateauStatues ; 3C XXX unused
+ add_tx_pre VermilionGymTrashSuccessText1 ; 3D
+ add_tx_pre VermilionGymTrashSuccessText2 ; 3E
+ add_tx_pre VermilionGymTrashSuccessText3 ; 3F
+ add_tx_pre VermilionGymTrashFailText ; 40
+ add_tx_pre TownMapText ; 41
+ add_tx_pre BookOrSculptureText ; 42
+ add_tx_pre ElevatorText ; 43
+ add_tx_pre PokemonStuffText ; 44
+
+ ; dr $3f67, $4000