Clean up some bank 3 functions and rename flag action functions.

This commit is contained in:
yenatch 2014-05-25 10:09:39 -07:00
parent cdd34eb45b
commit d307c85499
11 changed files with 326 additions and 232 deletions

View file

@ -17,8 +17,8 @@ Func_5525f: ; 5525f (15:525f)
ld a, [wWhichPokemon] ; $cf92 ld a, [wWhichPokemon] ; $cf92
ld c, a ld c, a
ld b, $2 ld b, $2
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
ld a, c ld a, c
and a and a
pop hl pop hl
@ -251,8 +251,8 @@ Func_5525f: ; 5525f (15:525f)
ld a, [wWhichPokemon] ; $cf92 ld a, [wWhichPokemon] ; $cf92
ld c, a ld c, a
ld b, $1 ld b, $1
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
pop hl pop hl
pop af pop af
ld [W_CURENEMYLVL], a ; $d127 ld [W_CURENEMYLVL], a ; $d127
@ -277,14 +277,14 @@ Func_55436: ; 55436 (15:5436)
ld c, a ld c, a
ld b, $1 ld b, $1
push bc push bc
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
ld hl, $ccf5 ld hl, $ccf5
xor a xor a
ld [hl], a ld [hl], a
pop bc pop bc
ld a, $10 ld a, $10 ; FlagActionPredef
jp Predef ; indirect jump to HandleBitArray (f666 (3:7666)) jp Predef
Func_5546c: ; 5546c (15:546c) Func_5546c: ; 5546c (15:546c)
ld a, [W_PLAYERMONSALIVEFLAGS] ld a, [W_PLAYERMONSALIVEFLAGS]

View file

@ -320,12 +320,12 @@ Func_3c1ad: ; 3c1ad (f:41ad)
ld b, $1 ld b, $1
push bc push bc
ld hl, W_PLAYERMONSALIVEFLAGS ld hl, W_PLAYERMONSALIVEFLAGS
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
ld hl, $ccf5 ld hl, $ccf5
pop bc pop bc
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
call Func_3cba6 call Func_3cba6
call LoadScreenTilesFromBuffer1 call LoadScreenTilesFromBuffer1
call Func_3cc91 call Func_3cc91
@ -1053,8 +1053,8 @@ Func_3c741: ; 3c741 (f:4741)
ld c, a ld c, a
ld hl, W_PLAYERMONSALIVEFLAGS ; clear fainted mon's alive flag ld hl, W_PLAYERMONSALIVEFLAGS ; clear fainted mon's alive flag
ld b, $0 ld b, $0
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
ld hl, W_ENEMYBATTSTATUS1 ; $d067 ld hl, W_ENEMYBATTSTATUS1 ; $d067
res 2, [hl] ; reset "attacking multiple times" flag res 2, [hl] ; reset "attacking multiple times" flag
ld a, [$d083] ld a, [$d083]
@ -1153,12 +1153,12 @@ Func_3c7d8: ; 3c7d8 (f:47d8)
ld hl, W_PLAYERMONSALIVEFLAGS ld hl, W_PLAYERMONSALIVEFLAGS
ld b, $1 ld b, $1
push bc push bc
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
pop bc pop bc
ld hl, $ccf5 ld hl, $ccf5
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
call Func_3cba6 call Func_3cba6
call GBPalWhiteOut call GBPalWhiteOut
call Func_3ee5b call Func_3ee5b
@ -2440,12 +2440,12 @@ Func_3d1ba: ; 3d1ba (f:51ba)
ld b, $1 ld b, $1
push bc push bc
ld hl, W_PLAYERMONSALIVEFLAGS ld hl, W_PLAYERMONSALIVEFLAGS
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
pop bc pop bc
ld hl, $ccf5 ld hl, $ccf5
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
call Func_3cba6 call Func_3cba6
call Func_3cc91 call Func_3cc91
call SaveScreenTilesToBuffer1 call SaveScreenTilesToBuffer1
@ -6185,8 +6185,8 @@ Func_3eb01: ; 3eb01 (f:6b01)
ld c, a ld c, a
ld b, $1 ld b, $1
ld hl, wPokedexSeen ; $d30a ld hl, wPokedexSeen ; $d30a
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
ld hl, W_ENEMYMONLEVEL ; $cff3 ld hl, W_ENEMYMONLEVEL ; $cff3
ld de, $cd23 ld de, $cd23
ld bc, $b ld bc, $b

View file

@ -489,7 +489,7 @@ WriteMonMoves_ShiftMoveData: ; 3b04e (e:704e)
ret ret
Func_3b057: ; 3b057 (e:7057) Func_3b057: ; 3b057 (e:7057)
ld a, $10 ld a, $10 ; FlagActionPredef
jp Predef ; indirect jump to HandleBitArray (f666 (3:7666)) jp Predef
INCLUDE "data/evos_moves.asm" INCLUDE "data/evos_moves.asm"

View file

@ -59,8 +59,8 @@ SetPokedexOwnedFlag: ; 4fe11 (13:7e11)
ld c, a ld c, a
ld hl, wPokedexOwned ; $d2f7 ld hl, wPokedexOwned ; $d2f7
ld b, $1 ld b, $1
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
pop af pop af
ld [$d11e], a ld [$d11e], a
call GetMonName call GetMonName

View file

@ -194,8 +194,8 @@ CinnabarQuizQuestionsText6: ; 1ea85 (7:6a85)
CinnabarGymQuiz_1ea8a: ; 1ea8a (7:6a8a) CinnabarGymQuiz_1ea8a: ; 1ea8a (7:6a8a)
ld hl, $d79c ld hl, $d79c
ld a, $10 ld a, $10 ; FlagActionPredef
jp Predef ; indirect jump to HandleBitArray (f666 (3:7666)) jp Predef
CinnabarGymQuiz_1ea92: ; 1ea92 (7:6a92) CinnabarGymQuiz_1ea92: ; 1ea92 (7:6a92)
call YesNoChoice call YesNoChoice
@ -227,8 +227,8 @@ CinnabarGymQuiz_1ea92: ; 1ea92 (7:6a92)
ld c, a ld c, a
ld b, $2 ld b, $2
ld hl, $d79a ld hl, $d79a
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
ld a, c ld a, c
and a and a
ret nz ret nz

View file

@ -11,8 +11,8 @@ HiddenItemNear: ; 7481f (1d:481f)
ld hl, $d6f0 ld hl, $d6f0
ld c, b ld c, b
ld b, $2 ld b, $2
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
ld a, c ld a, c
pop hl pop hl
pop bc pop bc

View file

@ -18,8 +18,8 @@ TestMonMoveCompatibility: ; 1373e (4:773e)
.TMfoundLoop .TMfoundLoop
pop hl pop hl
ld b, $2 ; read corresponding bit from TM compatibility array ld b, $2 ; read corresponding bit from TM compatibility array
ld a, $10 ld a, $10 ; FlagActionPredef
jp Predef ; indirect jump to HandleBitArray (f666 (3:7666)) jp Predef
; converts TM/HM number in $d11e into move number ; converts TM/HM number in $d11e into move number
; HMs start at 51 ; HMs start at 51

View file

@ -78,7 +78,7 @@ MoveAnimationPredef: ; 4fe91 (13:7e91)
dbw BANK(Func_f71e),Func_f71e dbw BANK(Func_f71e),Func_f71e
db BANK(InitializePlayerData) db BANK(InitializePlayerData)
dw InitializePlayerData dw InitializePlayerData
dbw BANK(HandleBitArray),HandleBitArray dbw BANK(FlagActionPredef),FlagActionPredef
db BANK(RemoveMissableObject) db BANK(RemoveMissableObject)
dw RemoveMissableObject dw RemoveMissableObject
db BANK(IsMissableObjectHidden) db BANK(IsMissableObjectHidden)

472
main.asm
View file

@ -7666,10 +7666,9 @@ ReadTrainerHeaderInfo:: ; 3193 (0:3193)
pop de pop de
ret ret
; calls HandleBitArray TrainerFlagAction::
HandleBitArray_Bank0:: ; 31c7 (0:31c7) ld a, $10 ; FlagActionPredef
ld a, $10 jp Predef
jp Predef ; indirect jump to HandleBitArray (f666 (3:7666))
; direct talking to a trainer (rather than getting seen by one) ; direct talking to a trainer (rather than getting seen by one)
TalkToTrainer:: ; 31cc (0:31cc) TalkToTrainer:: ; 31cc (0:31cc)
@ -7681,7 +7680,7 @@ TalkToTrainer:: ; 31cc (0:31cc)
ld a, [wTrainerHeaderFlagBit] ld a, [wTrainerHeaderFlagBit]
ld c, a ld c, a
ld b, $2 ld b, $2
call HandleBitArray_Bank0 ; read trainer's flag call TrainerFlagAction ; read trainer's flag
ld a, c ld a, c
and a and a
jr z, .trainerNotYetFought ; test trainer's flag jr z, .trainerNotYetFought ; test trainer's flag
@ -7774,7 +7773,7 @@ EndTrainerBattle:: ; 3275 (0:3275)
ld a, [wTrainerHeaderFlagBit] ld a, [wTrainerHeaderFlagBit]
ld c, a ld c, a
ld b, $1 ld b, $1
call HandleBitArray_Bank0 ; flag trainer as fought call TrainerFlagAction ; flag trainer as fought
ld a, [W_ENEMYMONORTRAINERCLASS] ld a, [W_ENEMYMONORTRAINERCLASS]
cp $c8 cp $c8
jr nc, .skipRemoveSprite ; test if trainer was fought (in that case skip removing the corresponding sprite) jr nc, .skipRemoveSprite ; test if trainer was fought (in that case skip removing the corresponding sprite)
@ -7857,7 +7856,7 @@ CheckForEngagingTrainers:: ; 3306 (0:3306)
ld b, $2 ld b, $2
ld a, [wTrainerHeaderFlagBit] ld a, [wTrainerHeaderFlagBit]
ld c, a ld c, a
call HandleBitArray_Bank0 ; read trainer flag call TrainerFlagAction ; read trainer flag
ld a, c ld a, c
and a and a
jr nz, .trainerAlreadyFought jr nz, .trainerAlreadyFought
@ -10173,6 +10172,7 @@ PointerTable_3f22:: ; 3f22 (0:3f22)
dw ElevatorText ; id = 41 dw ElevatorText ; id = 41
dw PokemonStuffText ; id = 42 dw PokemonStuffText ; id = 42
SECTION "bank1",ROMX,BANK[$1] SECTION "bank1",ROMX,BANK[$1]
SpriteFacingAndAnimationTable: ; 4000 (1:4000) SpriteFacingAndAnimationTable: ; 4000 (1:4000)
@ -10285,11 +10285,8 @@ INCLUDE "engine/battle/safari_zone.asm"
INCLUDE "engine/titlescreen.asm" INCLUDE "engine/titlescreen.asm"
NintenText: ; 45aa (1:45aa) NintenText: db "NINTEN@"
db "NINTEN@" SonyText: db "SONY@"
SonyText: ; 45b1 (1:45b1)
db "SONY@"
; loads pokemon data from one of multiple sources to $cf98 ; loads pokemon data from one of multiple sources to $cf98
; loads base stats to $d0b8 ; loads base stats to $d0b8
@ -10541,12 +10538,13 @@ DMARoutine: ; 4bfb (1:4bfb)
jr nz, .waitLoop jr nz, .waitLoop
ret ret
PrintWaitingText: ; 4c05 (1:4c05)
FuncCoord 3, 10 ; $c46b PrintWaitingText:
FuncCoord 3, 10
ld hl, Coord ld hl, Coord
ld b, $1 ld b, $1
ld c, $b ld c, $b
ld a, [W_ISINBATTLE] ; $d057 ld a, [W_ISINBATTLE]
and a and a
jr z, .asm_4c17 jr z, .asm_4c17
call TextBoxBorder call TextBoxBorder
@ -10554,16 +10552,17 @@ PrintWaitingText: ; 4c05 (1:4c05)
.asm_4c17 .asm_4c17
call Func_5ab3 call Func_5ab3
.asm_4c1a .asm_4c1a
FuncCoord 4, 11 ; $c480 FuncCoord 4, 11
ld hl, Coord ld hl, Coord
ld de, WaitingText ld de, WaitingText
call PlaceString call PlaceString
ld c, $32 ld c, 50
jp DelayFrames jp DelayFrames
WaitingText: ; 4c28 (1:4c28) WaitingText:
db "Waiting...!@" db "Waiting...!@"
_UpdateSprites: ; 4c34 (1:4c34) _UpdateSprites: ; 4c34 (1:4c34)
ld h, $c1 ld h, $c1
inc h inc h
@ -10594,7 +10593,7 @@ _UpdateSprites: ; 4c34 (1:4c34)
jp nz, UpdateNonPlayerSprite jp nz, UpdateNonPlayerSprite
jp UpdatePlayerSprite jp UpdatePlayerSprite
UpdateNonPlayerSprite: ; 4c5c (1:4c5c) UpdateNonPlayerSprite:
dec a dec a
swap a swap a
ld [$ff93], a ; $10 * sprite# ld [$ff93], a ; $10 * sprite#
@ -10607,36 +10606,46 @@ UpdateNonPlayerSprite: ; 4c5c (1:4c5c)
.unequal .unequal
jp Func_4ed1 jp Func_4ed1
Func_4c70: ; 4c70 (1:4c70)
Func_4c70:
nop nop
ld h, $c1
ld h, $c100 / $100
ld a, [H_CURRENTSPRITEOFFSET] ld a, [H_CURRENTSPRITEOFFSET]
add $0 add $c100 % $100
ld l, a ld l, a
ld a, [hl] ld a, [hl]
and a and a
ret z ret z
ld a, l ld a, l
add $3 add 3
ld l, a ld l, a
ld a, [hli] ld a, [hli]
call Func_4d72 call Func_4d72
ld a, [hli] ld a, [hli]
add $4 add 4
add b add b
and $f0 and $f0
or c or c
ld [$ff90], a ld [$ff90], a
ld a, [hli] ld a, [hli]
call Func_4d72 call Func_4d72
ld a, [hl] ld a, [hl]
add b add b
and $f0 and $f0
or c or c
ld [$ff91], a ld [$ff91], a
ld a, l ld a, l
add $7 add 7
ld l, a ld l, a
xor a xor a
ld [hld], a ld [hld], a
ld [hld], a ld [hld], a
@ -10646,31 +10655,36 @@ Func_4c70: ; 4c70 (1:4c70)
ld [hl], a ld [hl], a
xor a xor a
Func_4ca5: ; 4ca5 (1:4ca5) .loop
ld [$ff8f], a ld [$ff8f], a
swap a swap a
ld e, a ld e, a
ld a, [H_CURRENTSPRITEOFFSET] ld a, [H_CURRENTSPRITEOFFSET]
cp e cp e
jp z, .asm_4d69 jp z, .next
ld d, h ld d, h
ld a, [de] ld a, [de]
and a and a
jp z, .asm_4d69 jp z, .next
inc e inc e
inc e inc e
ld a, [de] ld a, [de]
inc a inc a
jp z, .asm_4d69 jp z, .next
ld a, [H_CURRENTSPRITEOFFSET] ld a, [H_CURRENTSPRITEOFFSET]
add $a add 10
ld l, a ld l, a
inc e inc e
ld a, [de] ld a, [de]
call Func_4d72 call Func_4d72
inc e inc e
ld a, [de] ld a, [de]
add $4 add 4
add b add b
and $f0 and $f0
or c or c
@ -10680,16 +10694,17 @@ Func_4ca5: ; 4ca5 (1:4ca5)
inc a inc a
.asm_4cd4 .asm_4cd4
ld [$ff90], a ld [$ff90], a
push af push af
rl c rl c
pop af pop af
ccf ccf
rl c rl c
ld b, $7 ld b, 7
ld a, [hl] ld a, [hl]
and $f and $f
jr z, .asm_4ce6 jr z, .asm_4ce6
ld b, $9 ld b, 9
.asm_4ce6 .asm_4ce6
ld a, [$ff90] ld a, [$ff90]
sub b sub b
@ -10697,22 +10712,25 @@ Func_4ca5: ; 4ca5 (1:4ca5)
ld a, b ld a, b
ld [$ff90], a ld [$ff90], a
jr c, .asm_4d01 jr c, .asm_4d01
ld b, $7
ld b, 7
dec e dec e
ld a, [de] ld a, [de]
inc e inc e
and a and a
jr z, .asm_4cfa jr z, .asm_4cfa
ld b, $9 ld b, 9
.asm_4cfa .asm_4cfa
ld a, [$ff92] ld a, [$ff92]
sub b sub b
jr z, .asm_4d01 jr z, .asm_4d01
jr nc, .asm_4d69 jr nc, .next
.asm_4d01 .asm_4d01
inc e inc e
inc l inc l
ld a, [de] ld a, [de]
push bc push bc
call Func_4d72 call Func_4d72
inc e inc e
@ -10721,22 +10739,24 @@ Func_4ca5: ; 4ca5 (1:4ca5)
and $f0 and $f0
or c or c
pop bc pop bc
sub [hl] sub [hl]
jr nc, .asm_4d14 jr nc, .asm_4d14
cpl cpl
inc a inc a
.asm_4d14 .asm_4d14
ld [$ff91], a ld [$ff91], a
push af push af
rl c rl c
pop af pop af
ccf ccf
rl c rl c
ld b, $7 ld b, 7
ld a, [hl] ld a, [hl]
and $f and $f
jr z, .asm_4d26 jr z, .asm_4d26
ld b, $9 ld b, 9
.asm_4d26 .asm_4d26
ld a, [$ff91] ld a, [$ff91]
sub b sub b
@ -10744,18 +10764,19 @@ Func_4ca5: ; 4ca5 (1:4ca5)
ld a, b ld a, b
ld [$ff91], a ld [$ff91], a
jr c, .asm_4d41 jr c, .asm_4d41
ld b, $7 ld b, 7
dec e dec e
ld a, [de] ld a, [de]
inc e inc e
and a and a
jr z, .asm_4d3a jr z, .asm_4d3a
ld b, $9 ld b, 9
.asm_4d3a .asm_4d3a
ld a, [$ff92] ld a, [$ff92]
sub b sub b
jr z, .asm_4d41 jr z, .asm_4d41
jr nc, .asm_4d69 jr nc, .next
.asm_4d41 .asm_4d41
ld a, [$ff91] ld a, [$ff91]
ld b, a ld b, a
@ -10763,10 +10784,10 @@ Func_4ca5: ; 4ca5 (1:4ca5)
inc l inc l
cp b cp b
jr c, .asm_4d4e jr c, .asm_4d4e
ld b, $c ld b, 12
jr .asm_4d50 jr .asm_4d50
.asm_4d4e .asm_4d4e
ld b, $3 ld b, 3
.asm_4d50 .asm_4d50
ld a, c ld a, c
and b and b
@ -10776,7 +10797,7 @@ Func_4ca5: ; 4ca5 (1:4ca5)
inc l inc l
inc l inc l
ld a, [$ff8f] ld a, [$ff8f]
ld de, DiagonalLines ; $4d85 ld de, DiagonalLines
add a add a
add e add e
ld e, a ld e, a
@ -10790,46 +10811,56 @@ Func_4ca5: ; 4ca5 (1:4ca5)
ld a, [de] ld a, [de]
or [hl] or [hl]
ld [hl], a ld [hl], a
.asm_4d69
.next
ld a, [$ff8f] ld a, [$ff8f]
inc a inc a
cp $10 cp $10
jp nz, Func_4ca5 jp nz, .loop
ret ret
Func_4d72: ; 4d72 (1:4d72) Func_4d72:
and a and a
ld b, $0 ld b, 0
ld c, $0 ld c, 0
jr z, .asm_4d84 jr z, .done
ld c, $9 ld c, 9
cp $ff cp -1
jr z, .asm_4d83 jr z, .ok
ld c, $7 ld c, 7
ld a, $0 ld a, 0
.asm_4d83 .ok
ld b, a ld b, a
.asm_4d84 .done
ret ret
DiagonalLines: ; 4d85 (1:4d85) DiagonalLines: INCBIN "gfx/diagonal_lines.2bpp"
INCBIN "gfx/diagonal_lines.2bpp"
Func_4da5: ; 4da5 (1:4da5)
TestBattle:
ret ret
Func_4da6: ; 4da6 (1:4da6) .loop
call GBPalNormal call GBPalNormal
ld a, $80
; Don't mess around
; with obedience.
ld a, %10000000 ; EARTHBADGE
ld [W_OBTAINEDBADGES], a ld [W_OBTAINEDBADGES], a
ld hl, W_FLAGS_D733 ld hl, W_FLAGS_D733
set 0, [hl] set 0, [hl]
; Reset the party.
ld hl, W_NUMINPARTY ld hl, W_NUMINPARTY
xor a xor a
ld [hli], a ld [hli], a
dec a dec a
ld [hl], a ld [hl], a
ld a, $1
; Give the player a
; level 20 Rhydon.
ld a, RHYDON
ld [$cf91], a ld [$cf91], a
ld a, 20 ld a, 20
ld [W_CURENEMYLVL], a ld [W_CURENEMYLVL], a
@ -10837,17 +10868,26 @@ Func_4da6: ; 4da6 (1:4da6)
ld [$cc49], a ld [$cc49], a
ld [W_CURMAP], a ld [W_CURMAP], a
call AddPokemonToParty call AddPokemonToParty
; Fight against a
; level 20 Rhydon.
ld a, RHYDON ld a, RHYDON
ld [W_CUROPPONENT], a ld [W_CUROPPONENT], a
ld a, $2c
ld a, $2c ; PREDEF_BATTLE
call Predef call Predef
ld a, $1
; When the battle ends,
; do it all again.
ld a, 1
ld [$cfcb], a ld [$cfcb], a
ld [H_AUTOBGTRANSFERENABLED], a ld [H_AUTOBGTRANSFERENABLED], a
jr Func_4da6 jr .loop
PickupItem: ; 4de1 (1:4de1)
PickupItem:
call EnableAutoTextBoxDrawing call EnableAutoTextBoxDrawing
ld a, [H_DOWNARROWBLINKCNT2] ; $ff8c ld a, [H_DOWNARROWBLINKCNT2] ; $ff8c
ld b, a ld b, a
ld hl, W_MISSABLEOBJECTLIST ld hl, W_MISSABLEOBJECTLIST
@ -10859,44 +10899,49 @@ PickupItem: ; 4de1 (1:4de1)
jr z, .isMissable jr z, .isMissable
inc hl inc hl
jr .missableObjectsListLoop jr .missableObjectsListLoop
.isMissable .isMissable
ld a, [hl] ld a, [hl]
ld [$ffdb], a ld [$ffdb], a
ld hl, W_MAPSPRITEEXTRADATA ld hl, W_MAPSPRITEEXTRADATA
ld a, [H_DOWNARROWBLINKCNT2] ; $ff8c ld a, [H_DOWNARROWBLINKCNT2] ; $ff8c
dec a dec a
add a add a
ld d, $0 ld d, 0
ld e, a ld e, a
add hl, de ; seek to item data of found item add hl, de
ld a, [hl] ; read Item type ld a, [hl]
ld b, a ld b, a ; item
ld c, 1 ; quantity is 1 ld c, 1 ; quantity
call GiveItem call GiveItem
jr nc, .BagFull jr nc, .BagFull
ld a, [$ffdb] ld a, [$ffdb]
ld [$cc4d], a ld [$cc4d], a
ld a, $11 ld a, $11 ; RemoveMissableObject
call Predef ; indirect jump to RemoveMissableObject (f1d7 (3:71d7)) call Predef
ld a, $1 ld a, 1
ld [$cc3c], a ld [$cc3c], a
ld hl, FoundItemText ld hl, FoundItemText
jr .printText jr .print
.BagFull .BagFull
ld hl, NoMoreRoomForItemText ld hl, NoMoreRoomForItemText
.printText .print
call PrintText call PrintText
ret ret
FoundItemText: ; 4e26 (1:4e26) FoundItemText:
TX_FAR _FoundItemText TX_FAR _FoundItemText
db $0B db $0B
db "@" db "@"
NoMoreRoomForItemText: ; 4e2c (1:4e2c) NoMoreRoomForItemText:
TX_FAR _NoMoreRoomForItemText TX_FAR _NoMoreRoomForItemText
db "@" db "@"
UpdatePlayerSprite: ; 4e31 (1:4e31) UpdatePlayerSprite: ; 4e31 (1:4e31)
ld a, [wSpriteStateData2] ld a, [wSpriteStateData2]
and a and a
@ -13200,9 +13245,9 @@ Func_7c18: ; 7c18 (1:7c18)
SECTION "bank3",ROMX,BANK[$3] SECTION "bank3",ROMX,BANK[$3]
_GetJoypadState: ; c000 (3:4000) _GetJoypadState::
ld a, [H_JOYPADSTATE] ld a, [H_JOYPADSTATE]
cp A_BUTTON | B_BUTTON | SELECT | START ; soft reset sequence cp A_BUTTON + B_BUTTON + SELECT + START ; soft reset
jp z, HandleJoypadResetButtons jp z, HandleJoypadResetButtons
ld b, a ld b, a
ld a, [H_OLDPRESSEDBUTTONS] ld a, [H_OLDPRESSEDBUTTONS]
@ -14436,8 +14481,8 @@ Func_f113: ; f113 (3:7113)
ld c, a ld c, a
ld b, $1 ld b, $1
ld hl, W_TOWNVISITEDFLAG ; mark town as visited (for flying) ld hl, W_TOWNVISITEDFLAG ; mark town as visited (for flying)
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
.notInTown .notInTown
ld hl, MapHSPointers ld hl, MapHSPointers
ld a, [W_CURMAP] ; $d35e ld a, [W_CURMAP] ; $d35e
@ -14519,7 +14564,7 @@ InitializeMissableObjectsFlags: ; f175 (3:7175)
ld a, [$d048] ld a, [$d048]
ld c, a ld c, a
ld b, $1 ld b, $1
call HandleBitArray2 ; set flag iff Item is hidden call MissableObjectFlagAction ; set flag iff Item is hidden
.asm_f19d .asm_f19d
ld hl, $d048 ld hl, $d048
inc [hl] inc [hl]
@ -14544,7 +14589,7 @@ IsMissableObjectHidden: ; f1a6 (3:71a6)
ld c, a ld c, a
ld b, $2 ld b, $2
ld hl, W_MISSABLEOBJECTFLAGS ld hl, W_MISSABLEOBJECTFLAGS
call HandleBitArray2 call MissableObjectFlagAction
ld a, c ld a, c
and a and a
jr nz, .hidden jr nz, .hidden
@ -14561,7 +14606,7 @@ AddMissableObject: ; f1c8 (3:71c8)
ld a, [$cc4d] ld a, [$cc4d]
ld c, a ld c, a
ld b, $0 ld b, $0
call HandleBitArray2 ; reset "removed" flag call MissableObjectFlagAction ; reset "removed" flag
jp UpdateSprites jp UpdateSprites
; removes missable object (items, leg. pokemon, etc.) from the map ; removes missable object (items, leg. pokemon, etc.) from the map
@ -14571,53 +14616,58 @@ RemoveMissableObject: ; f1d7 (3:71d7)
ld a, [$cc4d] ld a, [$cc4d]
ld c, a ld c, a
ld b, $1 ld b, $1
call HandleBitArray2 ; set "removed" flag call MissableObjectFlagAction ; set "removed" flag
jp UpdateSprites jp UpdateSprites
; functionally identical to _HandleBitArray, but with less optimized instructions MissableObjectFlagAction:
; executes operations on a field of bits ; identical to FlagAction
; b = 0 -> reset bit
; b = 1 -> set bit
; b = 2 -> read bit (into c and z-flag)
; hl: base address
; c: bit index
HandleBitArray2: ; f1e6 (3:71e6)
push hl push hl
push de push de
push bc push bc
; bit
ld a, c ld a, c
ld d, a ld d, a
and $7 and 7
ld e, a ; store bit offset in e ld e, a
; byte
ld a, d ld a, d
srl a srl a
srl a srl a
srl a ; calc byte offset srl a
add l add l
ld l, a ld l, a
jr nc, .noCarry jr nc, .ok
inc h inc h
.noCarry .ok
; d = 1 << e (bitmask)
inc e inc e
ld d, $1 ld d, 1
.shiftLeftLoop ; d = 1 << e, bitmask for the used bit .shift
dec e dec e
jr z, .operationSelect jr z, .shifted
sla d sla d
jr .shiftLeftLoop jr .shift
.operationSelect .shifted
ld a, b ld a, b
and a and a
jr z, .resetBit jr z, .reset
cp $2 cp 2
jr z, .readBit jr z, .read
ld a, [hl] ; set bit
.set
ld a, [hl]
ld b, a ld b, a
ld a, d ld a, d
or b or b
ld [hl], a ld [hl], a
jr .done jr .done
.resetBit
.reset
ld a, [hl] ld a, [hl]
ld b, a ld b, a
ld a, d ld a, d
@ -14625,11 +14675,13 @@ HandleBitArray2: ; f1e6 (3:71e6)
and b and b
ld [hl], a ld [hl], a
jr .done jr .done
.readBit
.read
ld a, [hl] ld a, [hl]
ld b, a ld b, a
ld a, d ld a, d
and b and b
.done .done
pop bc pop bc
pop de pop de
@ -14831,7 +14883,7 @@ _AddPokemonToParty: ; f2e5 (3:72e5)
ld c, a ld c, a
ld b, $2 ld b, $2
ld hl, wPokedexOwned ; $d2f7 ld hl, wPokedexOwned ; $d2f7
call _HandleBitArray call FlagAction
ld a, c ld a, c
ld [$d153], a ld [$d153], a
ld a, [$d11e] ld a, [$d11e]
@ -14839,10 +14891,10 @@ _AddPokemonToParty: ; f2e5 (3:72e5)
ld c, a ld c, a
ld b, $1 ld b, $1
push bc push bc
call _HandleBitArray call FlagAction
pop bc pop bc
ld hl, wPokedexSeen ; $d30a ld hl, wPokedexSeen ; $d30a
call _HandleBitArray call FlagAction
pop hl pop hl
push hl push hl
ld a, [W_ISINBATTLE] ; $d057 ld a, [W_ISINBATTLE] ; $d057
@ -15069,10 +15121,10 @@ _AddEnemyMonToPlayerParty: ; f49d (3:749d)
ld b, $1 ld b, $1
ld hl, wPokedexOwned ld hl, wPokedexOwned
push bc push bc
call _HandleBitArray ; add to owned pokemon call FlagAction ; add to owned pokemon
pop bc pop bc
ld hl, wPokedexSeen ld hl, wPokedexSeen
call _HandleBitArray ; add to seen pokemon call FlagAction ; add to seen pokemon
and a and a
ret ; return success ret ; return success
@ -15249,59 +15301,71 @@ Func_f51e: ; f51e (3:751e)
and a and a
ret ret
; predef $10
; executes operations on a field of bits FlagActionPredef:
; b = 0 -> reset bit
; b = 1 -> set bit
; b = 2 -> read bit (into c and z-flag)
; hl: base address
; c: bit index
HandleBitArray: ; f666 (3:7666)
call GetPredefRegisters call GetPredefRegisters
_HandleBitArray: ; f669 (3:7669) FlagAction:
; Perform action b on bit c
; in the bitfield at hl.
; 0: reset
; 1: set
; 2: read
; Return the result in c.
push hl push hl
push de push de
push bc push bc
; bit
ld a, c ld a, c
ld d, a ld d, a
and $7 and 7
ld e, a ; store bit offset in e ld e, a
; byte
ld a, d ld a, d
srl a srl a
srl a srl a
srl a ; calc byte offset srl a
add l add l
ld l, a ld l, a
jr nc, .noCarry jr nc, .ok
inc h inc h
.noCarry .ok
; d = 1 << e (bitmask)
inc e inc e
ld d, $1 ld d, 1
.shiftLeftLoop ; d = 1 << e, bitmask for the used bit .shift
dec e dec e
jr z, .operationSelect jr z, .shifted
sla d sla d
jr .shiftLeftLoop jr .shift
.operationSelect .shifted
ld a, b ld a, b
and a and a
jr z, .resetBit jr z, .reset
cp $2 cp 2
jr z, .readBit jr z, .read
ld b, [hl] ; set bit
.set
ld b, [hl]
ld a, d ld a, d
or b or b
ld [hl], a ld [hl], a
jr .done jr .done
.resetBit
.reset
ld b, [hl] ld b, [hl]
ld a, d ld a, d
xor $ff xor $ff
and b and b
ld [hl], a ld [hl], a
jr .done jr .done
.readBit
.read
ld b, [hl] ld b, [hl]
ld a, d ld a, d
and b and b
@ -15312,43 +15376,55 @@ _HandleBitArray: ; f669 (3:7669)
ld c, a ld c, a
ret ret
HealParty: ; f6a5 (3:76a5)
HealParty:
; Restore HP and PP.
ld hl, W_PARTYMON1 ld hl, W_PARTYMON1
ld de, W_PARTYMON1_HP ld de, W_PARTYMON1_HP
.HealPokemon: ; f6ab (3:76ab) .healmon
ld a, [hli] ld a, [hli]
cp $ff cp $ff
jr z, .DoneHealing ; End if there's no Pokémon jr z, .done
push hl push hl
push de push de
ld hl, $0003 ; Status offset
ld hl, $0003 ; status
add hl, de add hl, de
xor a xor a
ld [hl], a ; Clean status conditions ld [hl], a
push de push de
ld b, $4 ; A Pokémon has 4 moves ld b, $4 ; A Pokémon has 4 moves
.RestorePP: ; f6bb (3:76bb) .pp
ld hl, $0007 ; Move offset ld hl, $0007 ; moves
add hl, de add hl, de
ld a, [hl] ld a, [hl]
and a and a
jr z, .HealNext ; Skip if there's no move here jr z, .nextmove
dec a dec a
ld hl, $001c ; PP offset ld hl, $001c ; pp
add hl, de add hl, de
push hl push hl
push de push de
push bc push bc
ld hl, Moves ld hl, Moves
ld bc, $0006 ld bc, $0006
call AddNTimes call AddNTimes
ld de, $cd6d ld de, $cd6d
ld a, BANK(Moves) ld a, BANK(Moves)
call FarCopyData ; copy move header to memory call FarCopyData
ld a, [$cd72] ; get default PP ld a, [$cd72] ; default pp
pop bc pop bc
pop de pop de
pop hl pop hl
inc de inc de
push bc push bc
ld b, a ld b, a
@ -15357,44 +15433,51 @@ HealParty: ; f6a5 (3:76a5)
add b add b
ld [hl], a ld [hl], a
pop bc pop bc
.HealNext: ; f6eb (3:76eb)
.nextmove
dec b dec b
jr nz, .RestorePP ; Continue if there's still moves jr nz, .pp
pop de pop de
ld hl, $0021 ; Max HP offset
ld hl, $0021 ; max hp - cur hp
add hl, de add hl, de
ld a, [hli] ld a, [hli]
ld [de], a ld [de], a
inc de inc de
ld a, [hl] ld a, [hl]
ld [de], a ; Restore full HP ld [de], a
pop de pop de
pop hl pop hl
push hl push hl
ld bc, $002c ld bc, $002c ; next mon
ld h, d ld h, d
ld l, e ld l, e
add hl, bc add hl, bc
ld d, h ld d, h
ld e, l ld e, l
pop hl pop hl
jr .HealPokemon ; Next Pokémon jr .healmon
.DoneHealing
.done
xor a xor a
ld [wWhichPokemon], a ld [wWhichPokemon], a
ld [$d11e], a ld [$d11e], a
ld a, [W_NUMINPARTY] ld a, [W_NUMINPARTY]
ld b, a ld b, a
.restoreBonusPPLoop ; loop to restore bonus PP from PP Ups .ppup
push bc push bc
call RestoreBonusPP call RestoreBonusPP
pop bc pop bc
ld hl, wWhichPokemon ld hl, wWhichPokemon
inc [hl] inc [hl]
dec b dec b
jr nz,.restoreBonusPPLoop jr nz, .ppup
ret ret
; predef $9 ; predef $9
; predef $a ; predef $a
; predef $d ; predef $d
@ -15603,50 +15686,63 @@ Func_f839: ; f839 (3:7839)
.asm_f84f .asm_f84f
ret ret
InitializePlayerData: ; f850 (3:7850)
InitializePlayerData:
call Random call Random
ld a, [hRandomSub] ld a, [hRandomSub]
ld [wPlayerID], a ; set player trainer id ld [wPlayerID], a
call Random call Random
ld a, [hRandomAdd] ld a, [hRandomAdd]
ld [wPlayerID + 1], a ld [wPlayerID + 1], a
ld a, $ff ld a, $ff
ld [$d71b], a ; XXX what's this? ld [$d71b], a ; XXX what's this?
ld hl, W_NUMINPARTY ; $d163
call InitializeEmptyList ; no party mons ld hl, W_NUMINPARTY
ld hl, W_NUMINBOX ; $da80 call InitializeEmptyList
call InitializeEmptyList ; no boxed mons ld hl, W_NUMINBOX
ld hl, wNumBagItems ; $d31d call InitializeEmptyList
call InitializeEmptyList ; no items ld hl, wNumBagItems
ld hl, wNumBoxItems ; $d53a call InitializeEmptyList
call InitializeEmptyList ; no boxed items ld hl, wNumBoxItems
ld hl, wPlayerMoney + 1 ; $d348 call InitializeEmptyList
ld a, $30
ld [hld], a ; set money to 00 30 00 (3000) START_MONEY EQU $3000
ld hl, wPlayerMoney + 1
ld a, START_MONEY / $100
ld [hld], a
xor a xor a
ld [hli], a ld [hli], a
inc hl inc hl
ld [hl], a ld [hl], a
ld [$cc49], a ; XXX what's this?
ld [$cc49], a
ld hl, W_OBTAINEDBADGES ld hl, W_OBTAINEDBADGES
ld [hli], a ; no badges obtained ld [hli], a
ld [hl], a ; XXX what's this?
ld hl, wPlayerCoins ; $d5a4
ld [hli], a ; no coins
ld [hl], a ld [hl], a
ld hl, W_GAMEPROGRESSFLAGS ; $d5f0
ld hl, wPlayerCoins
ld [hli], a
ld [hl], a
ld hl, W_GAMEPROGRESSFLAGS
ld bc, $c8 ld bc, $c8
call FillMemory ; clear all game progress flags call FillMemory ; clear all game progress flags
jp InitializeMissableObjectsFlags jp InitializeMissableObjectsFlags
; writes two bytes $00 $ff to hl InitializeEmptyList:
InitializeEmptyList: ; f8a0 (3:78a0) xor a ; count
xor a
ld [hli], a ld [hli], a
dec a dec a ; terminator
ld [hl], a ld [hl], a
ret ret
IsItemInBag_: ; f8a5 (3:78a5) IsItemInBag_: ; f8a5 (3:78a5)
call GetPredefRegisters call GetPredefRegisters
ld hl, wNumBagItems ; $d31d ld hl, wNumBagItems ; $d31d
@ -16595,13 +16691,12 @@ BaseStats: INCLUDE "data/base_stats.asm"
INCLUDE "data/cries.asm" INCLUDE "data/cries.asm"
INCLUDE "engine/battle/e.asm" INCLUDE "engine/battle/e.asm"
; tiles for gameboy and link cable graphics used for trading sequence animation
TradingAnimationGraphics: TradingAnimationGraphics:
INCBIN "gfx/game_boy.norepeat.2bpp" INCBIN "gfx/game_boy.norepeat.2bpp"
INCBIN "gfx/link_cable.2bpp" INCBIN "gfx/link_cable.2bpp"
; 4 tiles for actual wire transfer animation (pokeball wandering inside wire)
TradingAnimationGraphics2: TradingAnimationGraphics2:
; Pokeball traveling through the link cable.
INCBIN "gfx/trade2.2bpp" INCBIN "gfx/trade2.2bpp"
INCLUDE "engine/evos_moves.asm" INCLUDE "engine/evos_moves.asm"
@ -16942,8 +17037,7 @@ SafariZoneWestBlocks: INCBIN "maps/safarizonewest.blk"
INCLUDE "data/mapHeaders/safarizonesecrethouse.asm" INCLUDE "data/mapHeaders/safarizonesecrethouse.asm"
INCLUDE "scripts/safarizonesecrethouse.asm" INCLUDE "scripts/safarizonesecrethouse.asm"
INCLUDE "data/mapObjects/safarizonesecrethouse.asm" INCLUDE "data/mapObjects/safarizonesecrethouse.asm"
SafariZoneSecretHouseBlocks: SafariZoneSecretHouseBlocks: INCBIN "maps/safarizonesecrethouse.blk"
INCBIN "maps/safarizonesecrethouse.blk"
SECTION "bank13",ROMX,BANK[$13] SECTION "bank13",ROMX,BANK[$13]

View file

@ -87,8 +87,8 @@ CinnabarGymScript1: ; 757dc (1d:57dc)
jp DisplayTextID jp DisplayTextID
CinnabarGymScript_757f1: ; 757f1 (1d:57f1) CinnabarGymScript_757f1: ; 757f1 (1d:57f1)
ld a, $10 ld a, $10 ; FlagActionPredef
jp Predef ; indirect jump to HandleBitArray (f666 (3:7666)) jp Predef
CinnabarGymScript2: ; 757f6 (1d:57f6) CinnabarGymScript2: ; 757f6 (1d:57f6)
ld a, [$d057] ld a, [$d057]

View file

@ -198,8 +198,8 @@ Route23Script_51346: ; 51346 (14:5346)
ld c, a ld c, a
ld b, $2 ld b, $2
ld hl, W_OBTAINEDBADGES ld hl, W_OBTAINEDBADGES
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
ld a, c ld a, c
and a and a
jr nz, .asm_5136e jr nz, .asm_5136e
@ -216,8 +216,8 @@ Route23Script_51346: ; 51346 (14:5346)
ld c, a ld c, a
ld b, $1 ld b, $1
ld hl, $d7ed ld hl, $d7ed
ld a, $10 ld a, $10 ; FlagActionPredef
call Predef ; indirect jump to HandleBitArray (f666 (3:7666)) call Predef
ld a, $2 ld a, $2
ld [W_ROUTE23CURSCRIPT], a ld [W_ROUTE23CURSCRIPT], a
ret ret