ref: 0dea0cc3fb815aae7d7a5e856aabf9b402d45cd0
parent: 15427f532085846ab6b51719be687951a094cb6c
author: yenatch <yenatch@gmail.com>
date: Fri May 23 11:11:09 EDT 2014
Comment some bank 0 functions, and add wram labels for Predef.
--- a/engine/battle/4.asm
+++ b/engine/battle/4.asm
@@ -16,12 +16,12 @@
ret
Func_128ef: ; 128ef (4:68ef)
- call Load16BitRegisters
+ call GetPredefRegisters
ld a, $1
jr asm_128fb
Func_128f6: ; 128f6 (4:68f6)
- call Load16BitRegisters
+ call GetPredefRegisters
ld a, $2
asm_128fb: ; 128fb (4:68fb)
ld [wListMenuID], a ; $cf94
--- a/engine/battle/9.asm
+++ b/engine/battle/9.asm
@@ -1,5 +1,5 @@
Func_27d6b: ; 27d6b (9:7d6b)
- call Load16BitRegisters
+ call GetPredefRegisters
push hl
call GetMonHeader
pop hl
@@ -26,7 +26,7 @@
jp FillMemory
Func_27d98: ; 27d98 (9:7d98)
- call Load16BitRegisters
+ call GetPredefRegisters
push hl
ld a, [W_PLAYERMOVETYPE] ; $cfd5
asm_27d9f: ; 27d9f (9:7d9f)
--- a/engine/battle/animations.asm
+++ b/engine/battle/animations.asm
@@ -2509,7 +2509,7 @@
jr asm_79acb
Func_79aba: ; 79aba (1e:5aba)
- call Load16BitRegisters
+ call GetPredefRegisters
ld a, [$cd6c]
and a
jr nz, .asm_79ac8
@@ -2790,7 +2790,7 @@
jp Func_79e0d
Func_79dda: ; 79dda (1e:5dda)
- call Load16BitRegisters
+ call GetPredefRegisters
ld a, c
ld [H_DOWNARROWBLINKCNT1], a ; $ff8b
ld a, b
--- a/engine/cable_club.asm
+++ b/engine/cable_club.asm
@@ -919,7 +919,7 @@
ret
Func_5ab0:
- call Load16BitRegisters
+ call GetPredefRegisters
Func_5ab3: ; 5ab3 (1:5ab3)
push hl
--- a/engine/evos_moves.asm
+++ b/engine/evos_moves.asm
@@ -372,7 +372,7 @@
; move slots are being filled up sequentially and shifted if all slots are full
; [$cee9]: (?)
WriteMonMoves: ; 3afb8 (e:6fb8)
- call Load16BitRegisters
+ call GetPredefRegisters
push hl
push de
push bc
--- a/engine/hp_bar.asm
+++ b/engine/hp_bar.asm
@@ -1,5 +1,5 @@
UpdateHPBar_LoadRegisters: ; f9dc (3:79dc)
- call Load16BitRegisters
+ call GetPredefRegisters
; calculates bc * 48 / de, the number of pixels the HP bar has
; the result is always at least 1
@@ -72,7 +72,7 @@
ld a, $1
.HPdecrease
ld [wHPBarDelta], a
- call Load16BitRegisters
+ call GetPredefRegisters
ld a, [wHPBarNewHP]
ld e, a
ld a, [wHPBarNewHP+1]
--- a/engine/items/itemfinder.asm
+++ b/engine/items/itemfinder.asm
@@ -4,7 +4,7 @@
.asm_74824
ld de, $0003
ld a, [W_CURMAP]
- call IsInArrayCummulativeCount
+ call IsInRestOfArray
ret nc ; return if current map has no hidden items
push bc
push hl
--- a/engine/menu/naming_screen.asm
+++ b/engine/menu/naming_screen.asm
@@ -1,6 +1,6 @@
AskForMonNickname: ; 64eb (1:64eb)
call SaveScreenTilesToBuffer1
- call Load16BitRegisters
+ call GetPredefRegisters
push hl
ld a, [W_ISINBATTLE] ; $d057
dec a
--- a/engine/oak_speech.asm
+++ b/engine/oak_speech.asm
@@ -211,7 +211,7 @@
jr .next
Predef3B: ; 62a1 (1:62a1)
- call Load16BitRegisters
+ call GetPredefRegisters
IntroPredef3B: ; 62a4 (1:62a4)
; bank of sprite given in b
push bc
--- a/engine/palettes.asm
+++ b/engine/palettes.asm
@@ -1,5 +1,5 @@
Func_71ddf: ; 71ddf (1c:5ddf)
- call Load16BitRegisters
+ call GetPredefRegisters
ld a, b
cp $ff
jr nz, .asm_71dea
--- a/engine/predefs12.asm
+++ b/engine/predefs12.asm
@@ -1,5 +1,5 @@
Func_480eb: ; 480eb (12:40eb)
- call Load16BitRegisters
+ call GetPredefRegisters
ld a, [rBGP] ; $ff47
or b
ld [rBGP], a ; $ff47
@@ -11,7 +11,7 @@
ret
Func_480ff: ; 480ff (12:40ff)
- call Load16BitRegisters
+ call GetPredefRegisters
ld a, $1
ld [$d0a0], a
xor a
@@ -35,7 +35,7 @@
jp DelayFrames
Func_48125: ; 48125 (12:4125)
- call Load16BitRegisters
+ call GetPredefRegisters
xor a
.asm_48129
ld [$ff97], a
--- a/engine/predefs17_2.asm
+++ b/engine/predefs17_2.asm
@@ -1,6 +1,6 @@
; updates the types of a party mon (pointed to in hl) to the ones of the mon specified in $d11e
SetPartyMonTypes: ; 5db5e (17:5b5e)
- call Load16BitRegisters
+ call GetPredefRegisters
ld bc, W_PARTYMON1_TYPE1 - W_PARTYMON1DATA ; $5
add hl, bc
ld a, [$d11e]
--- a/main.asm
+++ b/main.asm
@@ -926,103 +926,118 @@
jp z,GBFadeIn2
jp LoadGBPal
-; for when all the player's pokemon faint
-; other code prints the "you blacked out" message before this is called
-HandleBlackOut:: ; 0931 (0:0931)
+HandleBlackOut::
+; For when all the player's pokemon faint.
+; Does not print the "blacked out" message.
+
call GBFadeIn1
- ld a,$08
+ ld a, $08
call StopMusic
- ld hl,$d72e
- res 5,[hl]
- ld a,Bank(Func_40b0) ; Bank(Func_40b0) and Bank(Func_62ce) need to be equal.
- ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ ld hl, $d72e
+ res 5, [hl]
+ ld a, Bank(Func_40b0) ; Bank(Func_40b0) and Bank(Func_62ce) need to be equal.
+ ld [H_LOADEDROMBANK], a
+ ld [$2000], a
call Func_40b0
call Func_62ce
call Func_2312
jp Func_5d5f
-StopMusic:: ; 0951 (0:0951)
- ld [wMusicHeaderPointer],a
- ld a,$ff
- ld [$c0ee],a
+StopMusic::
+ ld [wMusicHeaderPointer], a
+ ld a, $ff
+ ld [$c0ee], a
call PlaySound
-.waitLoop
- ld a,[wMusicHeaderPointer]
+.wait
+ ld a, [wMusicHeaderPointer]
and a
- jr nz,.waitLoop
+ jr nz, .wait
jp StopAllSounds
-HandleFlyOrTeleportAway:: ; 0965 (0:0965)
- call UpdateSprites ; move sprites
+HandleFlyOrTeleportAway::
+ call UpdateSprites
call Delay3
xor a
- ld [$cf0b],a
- ld [$d700],a
- ld [$d057],a
- ld [$d35d],a
- ld hl,$d732
- set 2,[hl]
- res 5,[hl]
+ ld [$cf0b], a
+ ld [$d700], a
+ ld [$d057], a
+ ld [$d35d], a
+ ld hl, $d732
+ set 2, [hl]
+ res 5, [hl]
call DoFlyOrTeleportAwayGraphics
- ld a,Bank(Func_62ce)
- ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ ld a, Bank(Func_62ce)
+ ld [H_LOADEDROMBANK], a
+ ld [$2000], a
call Func_62ce
jp Func_5d5f
-; function that calls a function to do fly away or teleport away graphics
-DoFlyOrTeleportAwayGraphics:: ; 098f (0:098f)
+DoFlyOrTeleportAwayGraphics::
ld b, BANK(_DoFlyOrTeleportAwayGraphics)
ld hl, _DoFlyOrTeleportAwayGraphics
jp Bankswitch
-; load sprite graphics based on whether the player is standing, biking, or surfing
-LoadPlayerSpriteGraphics:: ; 0997 (0:0997)
- ld a,[$d700]
+LoadPlayerSpriteGraphics::
+; Load sprite graphics based on whether the player is standing, biking, or surfing.
+
+ ; 0: standing
+ ; 1: biking
+ ; 2: surfing
+
+ ld a, [$d700]
dec a
- jr z,.ridingBike
- ld a,[$ffd7]
+ jr z, .ridingBike
+
+ ld a, [$ffd7]
and a
- jr nz,.determineGraphics
+ jr nz, .determineGraphics
jr .startWalking
+
.ridingBike
+ ; If the bike can't be used,
+ ; start walking instead.
call IsBikeRidingAllowed
- jr c,.determineGraphics ; don't start walking if bike riding is allowed
+ jr c, .determineGraphics
+
.startWalking
xor a
- ld [$d700],a
- ld [$d11a],a
+ ld [$d700], a
+ ld [$d11a], a
jp LoadWalkingPlayerSpriteGraphics
+
.determineGraphics
- ld a,[$d700]
+ ld a, [$d700]
and a
- jp z,LoadWalkingPlayerSpriteGraphics
+ jp z, LoadWalkingPlayerSpriteGraphics
dec a
- jp z,LoadBikePlayerSpriteGraphics
+ jp z, LoadBikePlayerSpriteGraphics
dec a
- jp z,LoadSurfingPlayerSpriteGraphics
+ jp z, LoadSurfingPlayerSpriteGraphics
jp LoadWalkingPlayerSpriteGraphics
-; function to check if bike riding is allowed on the current map
-; sets carry if bike is allowed, clears carry otherwise
-IsBikeRidingAllowed:: ; 09c5 (0:09c5)
- ld a,[W_CURMAP]
- cp a,ROUTE_23
- jr z,.allowed
- cp a,INDIGO_PLATEAU
- jr z,.allowed
- ld a,[W_CURMAPTILESET]
- ld b,a
- ld hl,BikeRidingTilesets
+IsBikeRidingAllowed::
+; The bike can be used on Route 23 and Indigo Plateau,
+; or maps with tilesets in BikeRidingTilesets.
+; Return carry if biking is allowed.
+
+ ld a, [W_CURMAP]
+ cp ROUTE_23
+ jr z, .allowed
+ cp INDIGO_PLATEAU
+ jr z, .allowed
+
+ ld a, [W_CURMAPTILESET]
+ ld b, a
+ ld hl, BikeRidingTilesets
.loop
- ld a,[hli]
+ ld a, [hli]
cp b
- jr z,.allowed
+ jr z, .allowed
inc a
- jr nz,.loop
+ jr nz, .loop
and a
ret
+
.allowed
scf
ret
@@ -2584,14 +2599,11 @@
res 0, [hl]
ret
-;appears to be called twice inside function $C38B
-;if $d700,$d11a == $1 then biking
-;if $d700,$d11a == $2 then surfing
ForceBikeOrSurf:: ; 12ed (0:12ed)
- ld b,5 ;graphics bank 5
- ld hl,LoadPlayerSpriteGraphics ;load player sprite graphics
- call Bankswitch ;loads bank 5 and then calls LoadPlayerSpriteGraphics
- jp Func_2307 ;update map/player state?
+ ld b, BANK(RedSprite)
+ ld hl, LoadPlayerSpriteGraphics
+ call Bankswitch
+ jp Func_2307 ; update map/player state?
; this is used to check if the player wants to interrupt the opening sequence at several points
; XXX is this used anywhere else?
@@ -2626,7 +2638,7 @@
ld b,a
ld a,[H_LOADEDROMBANK]
push af
- ld a,[$cf12]
+ ld a,[wPredefParentBank]
ld [H_LOADEDROMBANK],a
ld [$2000],a
ld a,b
@@ -9804,31 +9816,34 @@
pop hl
ret
-; searches an array at hl for the value in a.
-; skips (de − 1) bytes between reads, so to check every byte, de should be 1.
-; if found, returns count in b and sets carry.
-IsInArray:: ; 3dab (0:3dab)
- ld b,0
- ; fall through
-IsInArrayCummulativeCount:: ; 3dad (0:3dad)
- ld c,a
+IsInArray::
+; Search an array at hl for the value in a.
+; Entry size is de bytes.
+; Return count b and carry if found.
+ ld b, 0
+
+IsInRestOfArray::
+ ld c, a
.loop
- ld a,[hl]
- cp a,$FF
- jr z,.NotInArray
+ ld a, [hl]
+ cp -1
+ jr z, .notfound
cp c
- jr z,.InArray
+ jr z, .found
inc b
- add hl,de
+ add hl, de
jr .loop
-.NotInArray
+
+.notfound
and a
ret
-.InArray
+
+.found
scf
ret
+
Func_3dbe:: ; 3dbe (0:3dbe)
call CleanLCD_OAM
ld a, $1
@@ -9839,25 +9854,26 @@
call GoPAL_SET_CF1C
jr Delay3
-; calls GBPalWhiteOut and then Delay3
-GBPalWhiteOutWithDelay3:: ; 3dd4 (0:3dd4)
+
+GBPalWhiteOutWithDelay3::
call GBPalWhiteOut
-Delay3:: ; 3dd7 (0:3dd7)
-; call Delay with a parameter of 3
- ld c,3
+Delay3::
+; The bg map is updated each frame in thirds.
+; Wait three frames to let the bg map fully update.
+ ld c, 3
jp DelayFrames
-; resets BGP and OBP0 to their usual colors
-GBPalNormal:: ; 3ddc (0:3ddc)
- ld a,%11100100
- ld [rBGP],a
- ld a,%11010000
- ld [rOBP0],a
+GBPalNormal::
+; Reset BGP and OBP0.
+ ld a, %11100100 ; 3210
+ ld [rBGP], a
+ ld a, %11010000 ; 3100
+ ld [rOBP0], a
ret
-; makes all palette colors white
-GBPalWhiteOut:: ; 3de5 (0:3de5)
+GBPalWhiteOut::
+; White out all palettes.
xor a
ld [rBGP],a
ld [rOBP0],a
@@ -9864,6 +9880,7 @@
ld [rOBP1],a
ret
+
GoPAL_SET_CF1C:: ; 3ded (0:3ded)
ld b,$ff
GoPAL_SET:: ; 3def (0:3def)
@@ -9945,54 +9962,59 @@
pop hl
ret
-Predef:: ; 3e6d (0:3e6d)
-; runs a predefined ASM command, where the command ID is read from $D0B7
-; $3E6D grabs the ath pointer from PredefPointers and executes it
- ld [$CC4E],a ; save the predef routine's ID for later
+Predef::
+; Call predefined function a.
+; To preserve other registers, have the
+; destination call GetPredefRegisters.
- ld a,[H_LOADEDROMBANK]
- ld [$CF12],a
+ ; Save the predef id for GetPredefPointer.
+ ld [wPredefID], a
- ; save bank and call 13:7E49
+ ; A hack for LoadDestinationWarpPosition.
+ ; See Func_c754 (predef $19).
+ ld a, [H_LOADEDROMBANK]
+ ld [wPredefParentBank], a
+
push af
- ld a,BANK(GetPredefPointer)
- ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ ld a, BANK(GetPredefPointer)
+ ld [H_LOADEDROMBANK], a
+ ld [$2000], a
+
call GetPredefPointer
- ; call the predef function
- ; ($D0B7 has the bank of the predef routine)
- ld a,[$D0B7]
- ld [H_LOADEDROMBANK],a
- ld [$2000],a
- ld de,.Return
+ ld a, [wPredefBank]
+ ld [H_LOADEDROMBANK], a
+ ld [$2000], a
+
+ ld de, .done
push de
jp [hl]
- ; after the predefined function finishes it returns here
-.Return
+.done
+
pop af
- ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ ld [H_LOADEDROMBANK], a
+ ld [$2000], a
ret
-;loads hl from cc4f, de from cc51, and bc from cc53
-
-Load16BitRegisters:: ; 3e94 (0:3e94)
- ld a, [$cc4f]
+GetPredefRegisters::
+; Restore the contents of register pairs
+; when GetPredefPointer was called.
+ ld a, [wPredefRegisters + 0]
ld h, a
- ld a, [$cc50]
+ ld a, [wPredefRegisters + 1]
ld l, a
- ld a, [$cc51]
+ ld a, [wPredefRegisters + 2]
ld d, a
- ld a, [$cc52]
+ ld a, [wPredefRegisters + 3]
ld e, a
- ld a, [$cc53]
+ ld a, [wPredefRegisters + 4]
ld b, a
- ld a, [$cc54]
+ ld a, [wPredefRegisters + 5]
ld c, a
ret
+
Func_3ead:: ; 3ead (0:3ead)
ld b, BANK(CinnabarGymQuiz_1eb0a)
ld hl, CinnabarGymQuiz_1eb0a
@@ -13514,7 +13536,7 @@
db "BALL×× @"
Func_c586: ; c586 (3:4586)
- call Load16BitRegisters
+ call GetPredefRegisters
Func_c589: ; c589 (3:4589)
ld a, [W_YCOORD] ; $d361
@@ -13814,7 +13836,7 @@
ret
Func_c754: ; c754 (3:4754)
- call Load16BitRegisters
+ call GetPredefRegisters
push hl
ld d, $0
ld a, [W_CURMAPTILESET] ; $d367
@@ -14265,7 +14287,7 @@
INCBIN "gfx/badges.w16.2bpp"
Func_ee9e: ; ee9e (3:6e9e)
- call Load16BitRegisters
+ call GetPredefRegisters
ld hl, $c6e8
ld a, [W_CURMAPWIDTH] ; $d369
add $6
@@ -14942,7 +14964,7 @@
ret
LoadMovePPs: ; f473 (3:7473)
- call Load16BitRegisters
+ call GetPredefRegisters
; fallthrough
AddPokemonToParty_WriteMovePP: ; f476 (3:7476)
ld b, $4
@@ -15216,7 +15238,7 @@
; hl: base address
; c: bit index
HandleBitArray: ; f666 (3:7666)
- call Load16BitRegisters
+ call GetPredefRegisters
_HandleBitArray: ; f669 (3:7669)
push hl
@@ -15359,7 +15381,7 @@
; predef $d
; predef $e
Func_f71e: ; f71e (3:771e)
- call Load16BitRegisters
+ call GetPredefRegisters
xor a
ld [$ffa5], a
ld [$ffa6], a
@@ -15512,7 +15534,7 @@
jr .asm_f803
Func_f81d: ; f81d (3:781d)
- call Load16BitRegisters
+ call GetPredefRegisters
and a
ld b, c
.asm_f822
@@ -15536,7 +15558,7 @@
ret
Func_f836: ; f836 (3:7836)
- call Load16BitRegisters
+ call GetPredefRegisters
Func_f839: ; f839 (3:7839)
and a
@@ -15607,7 +15629,7 @@
ret
IsItemInBag_: ; f8a5 (3:78a5)
- call Load16BitRegisters
+ call GetPredefRegisters
ld hl, wNumBagItems ; $d31d
.asm_f8ab
inc hl
--- a/wram.asm
+++ b/wram.asm
@@ -140,8 +140,13 @@
; set to 0 if you can't go past the top or bottom of the menu
ds 1
- ds 10
+ ds 3
+wPredefID:: ; cc4e
+ ds 1
+wPredefRegisters:: ; cc4f
+ ds 6
+
wTrainerHeaderFlagBit:: ; cc55
ds 1
@@ -288,8 +293,13 @@
; sound ID during battle animations
ds 1
- ds 12
+ ds 10
+wPredefParentBank:: ; cf12
+ ds 1
+
+ ds 1
+
wCurSpriteMovement2:: ; cf14
; movement byte 2 of current sprite
ds 1
@@ -707,6 +717,7 @@
W_LISTTYPE:: ; d0b6
ds 1
+wPredefBank:: ; d0b7
ds 1
W_MONHEADER:: ; d0b8