diff options
Diffstat (limited to 'engine')
118 files changed, 6791 insertions, 6436 deletions
diff --git a/engine/HoF_room_pc.asm b/engine/HoF_room_pc.asm index ae4ecb0d..e00fc57d 100755 --- a/engine/HoF_room_pc.asm +++ b/engine/HoF_room_pc.asm @@ -1,45 +1,45 @@ HallOfFamePC: ; 7405c (1d:405c) callba AnimateHallOfFame call ClearScreen - ld c, $64 + ld c, 100 call DelayFrames call DisableLCD ld hl, vFont ld bc, $800 / 2 - call Func_74171 + call ZeroMemory ld hl, vChars2 + $600 ld bc, $200 / 2 - call Func_74171 + call ZeroMemory ld hl, vChars2 + $7e0 ld bc, $10 ld a, $ff call FillMemory - ld hl, wTileMap - call Func_7417b - hlCoord 0, 14 - call Func_7417b + coord hl, 0, 0 + call FillFourRowsWithBlack + coord hl, 0, 14 + call FillFourRowsWithBlack ld a, $c0 - ld [rBGP], a ; $ff47 + ld [rBGP], a call EnableLCD ld a, $ff call PlaySoundWaitForCurrent ld c, BANK(Music_Credits) ld a, MUSIC_CREDITS call PlayMusic - ld c, $80 + ld c, 128 call DelayFrames xor a - ld [wWhichTrade], a ; wWhichTrade - ld [wTrainerEngageDistance], a + ld [wUnusedCD3D], a ; not read + ld [wNumCreditsMonsDisplayed], a jp Credits -Func_740ba: ; 740ba (1d:40ba) - ld hl, DataTable_74160 ; $4160 - ld b, $4 +FadeInCreditsText: ; 740ba (1d:40ba) + ld hl, HoFGBPalettes + ld b, 4 .asm_740bf ld a, [hli] - ld [rBGP], a ; $ff47 - ld c, $5 + ld [rBGP], a + ld c, 5 call DelayFrames dec b jr nz, .asm_740bf @@ -52,7 +52,7 @@ DisplayCreditsMon: ; 740cb (1d:40cb) call FillMiddleOfScreenWithWhite ; display the next monster from CreditsMons - ld hl,wTrainerEngageDistance + ld hl,wNumCreditsMonsDisplayed ld c,[hl] ; how many monsters have we displayed so far? inc [hl] ld b,0 @@ -61,132 +61,143 @@ DisplayCreditsMon: ; 740cb (1d:40cb) ld a,[hl] ld [wcf91],a ld [wd0b5],a - hlCoord 8, 6 + coord hl, 8, 6 call GetMonHeader call LoadFrontSpriteByMonIndex ld hl,vBGMap0 + $c - call Func_74164 + call CreditsCopyTileMapToVRAM xor a ld [H_AUTOBGTRANSFERENABLED],a call LoadScreenTilesFromBuffer1 ld hl,vBGMap0 - call Func_74164 + call CreditsCopyTileMapToVRAM ld a,$A7 - ld [$FF4B],a + ld [rWX],a ld hl,vBGMap1 - call Func_74164 + call CreditsCopyTileMapToVRAM call FillMiddleOfScreenWithWhite - ld a,$FC - ld [$FF47],a + ld a,%11111100 ; make the mon a black silhouette + ld [rBGP],a + +; scroll the mon left by one tile 7 times ld bc,7 -.next - call Func_74140 +.scrollLoop1 + call ScrollCreditsMonLeft dec c - jr nz,.next - ld c,$14 -.next2 - call Func_74140 - ld a,[$FF4B] + jr nz,.scrollLoop1 + +; scroll the mon left by one tile 20 times +; This time, we have to move the window left too in order to hide the text that +; is wrapping around to the right side of the screen. + ld c,20 +.scrollLoop2 + call ScrollCreditsMonLeft + ld a,[rWX] sub 8 - ld [$FF4B],a + ld [rWX],a dec c - jr nz,.next2 + jr nz,.scrollLoop2 + xor a ld [hWY],a - ld a,$C0 - ld [$FF47],a + ld a,%11000000 + ld [rBGP],a ret INCLUDE "data/credit_mons.asm" -Func_74140: ; 74140 (1d:4140) +ScrollCreditsMonLeft: ; 74140 (1d:4140) ld h, b ld l, $20 - call Func_74152 + call ScrollCreditsMonLeft_SetSCX ld h, $0 ld l, $70 - call Func_74152 + call ScrollCreditsMonLeft_SetSCX ld a, b add $8 ld b, a ret -Func_74152: ; 74152 (1d:4152) - ld a, [$ff44] +ScrollCreditsMonLeft_SetSCX: ; 74152 (1d:4152) + ld a, [rLY] cp l - jr nz, Func_74152 + jr nz, ScrollCreditsMonLeft_SetSCX ld a, h - ld [rSCX], a ; $ff43 -.asm_7415a - ld a, [$ff44] + ld [rSCX], a +.loop + ld a, [rLY] cp h - jr z, .asm_7415a + jr z, .loop ret -DataTable_74160: ; 74160 (1d:4160) - db $C0,$D0,$E0,$F0 +HoFGBPalettes: ; 74160 (1d:4160) + db %11000000 + db %11010000 + db %11100000 + db %11110000 -Func_74164: ; 74164 (1d:4164) +CreditsCopyTileMapToVRAM: ; 74164 (1d:4164) ld a, l - ld [H_AUTOBGTRANSFERDEST], a ; $ffbc + ld [H_AUTOBGTRANSFERDEST], a ld a, h - ld [$ffbd], a - ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba + ld [H_AUTOBGTRANSFERDEST + 1], a + ld a, 1 + ld [H_AUTOBGTRANSFERENABLED], a jp Delay3 -Func_74171: ; 74171 (1d:4171) - ld [hl], $0 +ZeroMemory: ; 74171 (1d:4171) +; zero bc bytes at hl + ld [hl], 0 inc hl inc hl dec bc ld a, b or c - jr nz, Func_74171 + jr nz, ZeroMemory ret -Func_7417b: ; 7417b (1d:417b) - ld bc, $50 +FillFourRowsWithBlack: ; 7417b (1d:417b) + ld bc, SCREEN_WIDTH * 4 ld a, $7e jp FillMemory FillMiddleOfScreenWithWhite: ; 74183 (1d:4183) - hlCoord 0, 4 - ld bc, $c8 ; 10 rows of 20 tiles each - ld a, $7f ; blank white tile + coord hl, 0, 4 + ld bc, SCREEN_WIDTH * 10 + ld a, " " jp FillMemory Credits: ; 7418e (1d:418e) - ld de, CreditsOrder ; $4243 + ld de, CreditsOrder push de -.asm_74192 +.nextCreditsScreen pop de - hlCoord 9, 6 + coord hl, 9, 6 push hl call FillMiddleOfScreenWithWhite pop hl -.asm_7419b +.nextCreditsCommand ld a, [de] inc de push de cp $ff - jr z, .asm_741d5 + jr z, .fadeInTextAndShowMon cp $fe - jr z, .asm_741dc + jr z, .showTextAndShowMon cp $fd - jr z, .asm_741e6 + jr z, .fadeInText cp $fc - jr z, .asm_741ed + jr z, .showText cp $fb - jr z, .asm_741f4 + jr z, .showCopyrightText cp $fa jr z, .showTheEnd push hl push hl - ld hl, CreditsTextPointers ; $42c3 + ld hl, CreditsTextPointers add a ld c, a - ld b, $0 + ld b, 0 add hl, bc ld e, [hl] inc hl @@ -199,51 +210,51 @@ Credits: ; 7418e (1d:418e) add hl, bc call PlaceString pop hl - ld bc, $28 + ld bc, SCREEN_WIDTH * 2 add hl, bc pop de - jr .asm_7419b -.asm_741d5 - call Func_740ba - ld c, $5a - jr .asm_741de -.asm_741dc - ld c, $6e -.asm_741de + jr .nextCreditsCommand +.fadeInTextAndShowMon + call FadeInCreditsText + ld c, 90 + jr .next1 +.showTextAndShowMon + ld c, 110 +.next1 call DelayFrames call DisplayCreditsMon - jr .asm_74192 -.asm_741e6 - call Func_740ba - ld c, $78 - jr .asm_741ef -.asm_741ed - ld c, $8c -.asm_741ef + jr .nextCreditsScreen +.fadeInText + call FadeInCreditsText + ld c, 120 + jr .next2 +.showText + ld c, 140 +.next2 call DelayFrames - jr .asm_74192 -.asm_741f4 + jr .nextCreditsScreen +.showCopyrightText push de callba LoadCopyrightTiles pop de pop de - jr .asm_7419b + jr .nextCreditsCommand .showTheEnd - ld c, $10 + ld c, 16 call DelayFrames call FillMiddleOfScreenWithWhite pop de ld de, TheEndGfx ld hl, vChars2 + $600 - ld bc, (BANK(TheEndGfx) << 8) + $0a + lb bc, BANK(TheEndGfx), (TheEndGfxEnd - TheEndGfx) / $10 call CopyVideoData - hlCoord 4, 8 + coord hl, 4, 8 ld de, TheEndTextString call PlaceString - hlCoord 4, 9 + coord hl, 4, 9 inc de call PlaceString - jp Func_740ba + jp FadeInCreditsText TheEndTextString: ; 74229 (1d:4229) ; "T H E E N D" @@ -254,5 +265,6 @@ INCLUDE "data/credits_order.asm" INCLUDE "text/credits_text.asm" -TheEndGfx: ; 7473e (1d:473e) ; 473E (473F on blue) +TheEndGfx: ; 7473e (1d:473e) (7473f on blue) INCBIN "gfx/theend.interleave.2bpp" +TheEndGfxEnd: diff --git a/engine/bank3d/bank3d_battle.asm b/engine/bank3d/bank3d_battle.asm index 9ce82f5e..9a9b60f1 100644 --- a/engine/bank3d/bank3d_battle.asm +++ b/engine/bank3d/bank3d_battle.asm @@ -42,7 +42,7 @@ asm_f601d: ; f601d (f:601d) ld [$ffe1], a dec a ld [wAICount], a - hlCoord 12, 0 + coord hl, 12, 0 predef Func_3f0c6 ld a, $ff ld [wEnemyMonPartyPos], a @@ -103,7 +103,7 @@ InitWildBattle: ; f607c (3d:607c) xor a ld [W_TRAINERCLASS], a ld [$ffe1], a - hlCoord 12, 0 + coord hl, 12, 0 predef Func_3f0c6 ; common code that executes after init battle code specific to trainer or wild battles @@ -125,10 +125,10 @@ InitBattle_Common: ; f60eb (3d:60eb) ld a, $9c ld [$ffbd], a call LoadScreenTilesFromBuffer1 - hlCoord 9, 7 + coord hl, 9, 7 ld bc, $50a call ClearScreenArea - hlCoord 1, 0 + coord hl, 1, 0 ld bc, $40a call ClearScreenArea call ClearSprites @@ -173,7 +173,7 @@ LoadMonBackPic: ; f6178 (3d:6178) ; been loaded with GetMonHeader. ld a, [wBattleMonSpecies2] ld [wcf91], a - hlCoord 1, 5 + coord hl, 1, 5 ld bc,$708 call ClearScreenArea ld hl, W_MONHBACKSPRITE - W_MONHEADER @@ -226,15 +226,15 @@ Func_f61a6: ; f61a6 (3d:f61a6) add hl, bc ld a, [H_DOWNARROWBLINKCNT1] add $31 - jr asm_f6203 + jr CopyUncompressedPicToHL -Func_f61f9: ; 3f0c6 (f:70c6) +Func_f61f9: ; f61f9 (3d:61f9) ld a, [wPredefRegisters] ld h, a ld a, [wPredefRegisters + 1] ld l, a ld a, [$ffe1] -asm_f6203: ; f6203 (3d:6203) +CopyUncompressedPicToHL: ; f6203 (3d:6203) ld bc, $707 ld de, $14 push af diff --git a/engine/bank3d/link_menu.asm b/engine/bank3d/link_menu.asm index a460eb00..69d0458e 100644 --- a/engine/bank3d/link_menu.asm +++ b/engine/bank3d/link_menu.asm @@ -5,19 +5,19 @@ Func_f531b:: ; f531b (3d:531b) ld [wBuffer],a xor a ld [wUnknownSerialFlag_d499],a - hlCoord 0,0 + coord hl, 0,0 ld bc,$405 call TextBoxBorder ld de,Text_f5791 - hlCoord 1,2 + coord hl, 1,2 call PlaceString - hlCoord 8,0 + coord hl, 8,0 ld bc,$80a call TextBoxBorder - hlCoord 10,2 + coord hl, 10,2 ld de,Text_f579c call PlaceString - hlCoord 0,10 + coord hl, 0,10 ld bc,$612 call TextBoxBorder call UpdateSprites @@ -513,7 +513,7 @@ asm_f56ad:: ; f56ad (3d:56ad) Func_f56bd:: ; f56bd (3d:56bd) xor a ld [H_AUTOBGTRANSFERENABLED],a - hlCoord 1,11 + coord hl, 1,11 ld bc,$612 call ClearScreenArea ld a,[wCurrentMenuItem] @@ -530,7 +530,7 @@ Func_f56bd:: ; f56bd (3d:56bd) ld l,a ld d,h ld e,l - hlCoord 1,12 + coord hl, 1,12 call PlaceString .asm_f56e6 call Delay3 @@ -642,11 +642,11 @@ LinkMenu: ; f580c (3d:580c) call SaveScreenTilesToBuffer1 ld hl, ColosseumWhereToText call PrintText - hlCoord 5, 3 + coord hl, 5, 3 ld bc, $80d call TextBoxBorder call UpdateSprites - hlCoord 7, 5 + coord hl, 7, 5 ld de, TradeCenterText call PlaceString xor a diff --git a/engine/bank3d/main.asm b/engine/bank3d/main.asm index 7b3326c9..cdacf431 100644 --- a/engine/bank3d/main.asm +++ b/engine/bank3d/main.asm @@ -4,7 +4,7 @@ INCLUDE "engine/battle/unused_stats_functions.asm" INCLUDE "engine/battle/scroll_draw_trainer_pic.asm" Func_f429f:: ; f429f (3d:429f) - hlCoord 0,5 + coord hl, 0,5 ld c,$0 .asm_f42a4 inc c @@ -169,35 +169,35 @@ Func_f453f:: ; f453f (3d:453f) ret Func_f4578:: ; f4578 (3d:4578) - hlCoord 2,1 + coord hl, 2,1 ld de,Pointer_f45f9 ld bc,7 << 8 | 16 ; 16x7 (xy) call CopyScreenArea ret Func_f4585:: ; f4585 (3d:4585) - hlCoord 6,4 + coord hl, 6,4 ld de,Pointer_f4673 ld bc,4 << 8 | 7 ; 7x4 (xy) call CopyScreenArea - hlCoord 9,8 + coord hl, 9,8 ld [hl],$64 inc hl ld [hl],$65 ret Func_f459a:: ; f459a (3d:459a) - hlCoord 4,8 + coord hl, 4,8 ld de,Pointer_f468f ld bc,9 << 8 | 12 ; 12x9 (xy) call CopyScreenArea - hlCoord 16,10 + coord hl, 16,10 ld [hl],$96 - hlCoord 16,11 + coord hl, 16,11 ld [hl],$9d - hlCoord 16,12 + coord hl, 16,12 ld [hl],$a7 - hlCoord 16,13 + coord hl, 16,13 ld [hl],$b1 ld hl,Pointer_f45c7 ld de,wOAMBuffer @@ -349,7 +349,7 @@ Func_f5ab0:: ; f5ab0 (3d:5ab0) ld a,[wTopMenuItemY] and a jr z,.asm_f5ac0 - hlCoord 0,0 + coord hl, 0,0 ld bc,$14 .loop add hl,bc diff --git a/engine/battle/animations.asm b/engine/battle/animations.asm index 8791d538..626eea9e 100755 --- a/engine/battle/animations.asm +++ b/engine/battle/animations.asm @@ -163,14 +163,14 @@ DrawFrameBlock: ; 78000 (1e:4000) PlayAnimation: ; 780f1 (1e:40f1) xor a - ld [$FF8B],a + ld [$FF8B],a ; it looks like nothing reads this ld [W_SUBANIMTRANSFORM],a ld a,[W_ANIMATIONID] ; get animation number dec a ld l,a ld h,0 add hl,hl - ld de,AttackAnimationPointers ; $607d ; animation command stream pointers + ld de,AttackAnimationPointers ; animation command stream pointers add hl,de ld a,[hli] ld h,[hl] @@ -199,7 +199,7 @@ PlayAnimation: ; 780f1 (1e:40f1) ld [wAnimSoundID],a ; store sound push hl push de - call Func_7986f + call GetMoveSound call PlaySound pop de pop hl @@ -223,7 +223,7 @@ PlayAnimation: ; 780f1 (1e:40f1) rla sla c rla - ld [wd09f],a ; tile select + ld [wWhichBattleAnimTileset],a ld a,[hli] ; sound ld [wAnimSoundID],a ; store sound ld a,[hli] ; subanimation ID @@ -243,7 +243,7 @@ PlayAnimation: ; 780f1 (1e:40f1) push hl ld a,[rOBP0] push af - ld a,[wcc79] + ld a,[wAnimPalette] ld [rOBP0],a call LoadAnimationTileset call LoadSubanimation @@ -328,7 +328,7 @@ GetSubanimationTransform2: ; 781ca (1e:41ca) ; loads tile patterns for battle animations LoadAnimationTileset: ; 781d2 (1e:41d2) - ld a,[wd09f] ; tileset select + ld a,[wWhichBattleAnimTileset] add a add a ld hl,AnimationTilesetPointers @@ -336,14 +336,14 @@ LoadAnimationTileset: ; 781d2 (1e:41d2) ld d,0 add hl,de ld a,[hli] - ld [wd07d],a ; number of tiles + ld [wTempTilesetNumTiles],a ; number of tiles ld a,[hli] ld e,a ld a,[hl] ld d,a ; de = address of tileset ld hl,vSprites + $310 ld b, BANK(AnimationTileset1) ; ROM bank - ld a,[wd07d] + ld a,[wTempTilesetNumTiles] ld c,a ; number of tiles jp CopyVideoData ; load tileset @@ -375,7 +375,7 @@ MoveAnimation: ; 78d5e (1e:4d5e) push bc push af call WaitForSoundToFinish - call Func_78e23 + call SetAnimationPalette ld a,[W_ANIMATIONID] and a jr z,.AnimationFinished @@ -404,7 +404,7 @@ MoveAnimation: ; 78d5e (1e:4d5e) call WaitForSoundToFinish xor a ld [W_SUBANIMSUBENTRYADDR],a - ld [wd09b],a + ld [wUnusedD09B],a ld [W_SUBANIMTRANSFORM],a dec a ld [wAnimSoundID],a @@ -464,16 +464,16 @@ AnimationTypePointerTable: ; 78dcf (1e:4dcf) ShakeScreenVertically: ; 78ddb (1e:4ddb) call PlayApplyingAttackSound - ld b, $8 + ld b, 8 jp AnimationShakeScreenVertically ShakeScreenHorizontallyHeavy: ; 78de3 (1e:4de3) call PlayApplyingAttackSound - ld b, $8 + ld b, 8 jp AnimationShakeScreenHorizontallyFast ShakeScreenHorizontallySlow: ; 78deb (1e:4deb) - ld bc, $602 + lb bc, 6, 2 jr AnimationShakeScreenHorizontallySlow BlinkEnemyMonSprite: ; 78df0 (1e:4df0) @@ -482,71 +482,71 @@ BlinkEnemyMonSprite: ; 78df0 (1e:4df0) ShakeScreenHorizontallyLight: ; 78df6 (1e:4df6) call PlayApplyingAttackSound - ld b, $2 + ld b, 2 jp AnimationShakeScreenHorizontallyFast ShakeScreenHorizontallySlow2: ; 78dfe (1e:4dfe) - ld bc, $302 + lb bc, 3, 2 AnimationShakeScreenHorizontallySlow: ; 78e01 (1e:4e01) push bc push bc -.asm_78e03 - ld a, [rWX] ; $ff4b +.loop1 + ld a, [rWX] inc a - ld [rWX], a ; $ff4b - ld c, $2 + ld [rWX], a + ld c, 2 call DelayFrames dec b - jr nz, .asm_78e03 + jr nz, .loop1 pop bc -.asm_78e11 - ld a, [rWX] ; $ff4b +.loop2 + ld a, [rWX] dec a - ld [rWX], a ; $ff4b - ld c, $2 + ld [rWX], a + ld c, 2 call DelayFrames dec b - jr nz, .asm_78e11 + jr nz, .loop2 pop bc dec c jr nz, AnimationShakeScreenHorizontallySlow ret -Func_78e23: ; 78e23 (1e:4e23) +SetAnimationPalette: ; 78e23 (1e:4e23) ld a, [wOnSGB] and a ld a, $e4 - jr z, .asm_78e47 + jr z, .notSGB ld a, $f0 - ld [wcc79], a + ld [wAnimPalette], a ld b, $e4 - ld a, [W_ANIMATIONID] ; W_ANIMATIONID + ld a, [W_ANIMATIONID] cp TRADE_BALL_DROP_ANIM - jr c, .asm_78e3f + jr c, .next cp TRADE_BALL_POOF_ANIM + 1 - jr nc, .asm_78e3f + jr nc, .next ld b, $f0 -.asm_78e3f +.next ld a, b - ld [rOBP0], a ; $ff48 + ld [rOBP0], a ld a, $6c - ld [rOBP1], a ; $ff49 + ld [rOBP1], a ret -.asm_78e47 +.notSGB ld a, $e4 - ld [wcc79], a - ld [rOBP0], a ; $ff48 + ld [wAnimPalette], a + ld [rOBP0], a ld a, $6c - ld [rOBP1], a ; $ff49 + ld [rOBP1], a ret PlaySubanimation: ; 78e53 (1e:4e53) ld a,[wAnimSoundID] cp a,$FF jr z,.skipPlayingSound - call Func_7986f - call PlaySound ; play sound effect + call GetMoveSound + call PlaySound .skipPlayingSound ld hl,wOAMBuffer ; base address of OAM buffer ld a,l @@ -573,7 +573,7 @@ PlaySubanimation: ; 78e53 (1e:4e53) push hl ld e,[hl] ; base coordinate ID ld d,0 - ld hl,FrameBlockBaseCoords ; $7c85 ; base coordinate table + ld hl,FrameBlockBaseCoords ; base coordinate table add hl,de add hl,de ld a,[hli] @@ -659,7 +659,7 @@ AnimationIdSpecialEffects: ; 78ef5 (1e:4ef5) dw AnimationFlashScreen db TAIL_WHIP - dw Func_790d0 + dw TailWhipAnimationUnused db GROWL dw DoGrowlSpecialEffects @@ -695,13 +695,13 @@ AnimationIdSpecialEffects: ; 78ef5 (1e:4ef5) dw DoRockSlideSpecialEffects db TRADE_BALL_DROP_ANIM - dw Func_79041 + dw TradeHidePokemon db TRADE_BALL_SHAKE_ANIM - dw Func_7904c + dw TradeShakePokeball db TRADE_BALL_TILT_ANIM - dw Func_7907c + dw TradeJumpPokeball db TOSS_ANIM dw DoBallTossSpecialEffects @@ -733,8 +733,8 @@ DoBallTossSpecialEffects: ; 78f3e (1e:4f3e) cp a,11 ; is it the beginning of the subanimation? jr nz,.skipPlayingSound ; if it is the beginning of the subanimation, play a sound - ld a,(SFX_08_41 - SFX_Headers_08) / 3 - call PlaySound ; play sound + ld a,SFX_BALL_TOSS + call PlaySound .skipPlayingSound ld a,[W_ISINBATTLE] cp a,02 ; is it a trainer battle? @@ -751,20 +751,20 @@ DoBallTossSpecialEffects: ; 78f3e (1e:4f3e) cp a,1 ret nz .moveGhostMarowakLeft - hlCoord 17, 0 + coord hl, 17, 0 ld de,20 - ld bc,$0707 ; 7 rows and 7 columns + lb bc, 7, 7 .loop push hl push bc - call Func_79862 ; move row of tiles left + call AnimCopyRowRight ; move row of tiles left pop bc pop hl add hl,de dec b jr nz,.loop ld a,%00001000 - ld [$ff10],a ; Channel 1 sweep register + ld [rNR10],a ; Channel 1 sweep register ret .isTrainerBattle ; if it's a trainer battle, shorten the animation by one frame ld a,[W_SUBANIMCOUNTER] @@ -779,8 +779,8 @@ DoBallShakeSpecialEffects: ; 78f96 (1e:4f96) cp a,4 ; is it the beginning of a shake? jr nz,.skipPlayingSound ; if it is the beginning of a shake, play a sound and wait 2/3 of a second - ld a,(SFX_08_3c - SFX_Headers_08) / 3 - call PlaySound ; play sound + ld a,SFX_TINK + call PlaySound ld c,40 call DelayFrames .skipPlayingSound @@ -788,9 +788,9 @@ DoBallShakeSpecialEffects: ; 78f96 (1e:4f96) dec a ret nz ; if it's the end of the ball shaking subanimation, check if more shakes are left and restart the subanimation - ld a,[wWhichTrade] ; number of shakes + ld a,[wNumShakes] ; number of shakes dec a ; decrement number of shakes - ld [wWhichTrade],a + ld [wNumShakes],a ret z ; if there are shakes left, restart the subanimation ld a,[W_SUBANIMSUBENTRYADDR] @@ -812,7 +812,7 @@ DoPoofSpecialEffects: ; 78fce (1e:4fce) ld a,[W_SUBANIMCOUNTER] cp a,5 ret nz - ld a,(SFX_08_42 - SFX_Headers_08) / 3 + ld a,SFX_BALL_POOF jp PlaySound DoRockSlideSpecialEffects: ; 78fd9 (1e:4fd9) @@ -827,9 +827,9 @@ DoRockSlideSpecialEffects: ; 78fd9 (1e:4fd9) ; if the subaninmation counter is between 8 and 11, shake the screen horizontally and vertically .shakeScreen ld b,1 - predef Func_48125 ; shake horizontally + predef PredefShakeScreenHorizontally ; shake horizontally ld b,1 - predef_jump Func_480ff ; shake vertically + predef_jump PredefShakeScreenVertically ; shake vertically FlashScreenEveryEightFrameBlocks: ; 78ff7 (1e:4ff7) ld a,[W_SUBANIMCOUNTER] @@ -850,7 +850,7 @@ DoExplodeSpecialEffects: ; 79009 (1e:5009) cp a,1 ; is it the end of the subanimation? jr nz,FlashScreenEveryFourFrameBlocks ; if it's the end of the subanimation, make the attacking pokemon disappear - hlCoord 1, 5 + coord hl, 1, 5 jp AnimationHideMonPic ; make pokemon disappear ; flashes the screen when subanimation counter is 1 modulo 4 @@ -867,8 +867,8 @@ DoBlizzardSpecialEffects: ; 79016 (1e:5016) ret ; flashes the screen at 3 points in the subanimation -; XXX is this unused? -Func_7902e: ; 7902e (1e:502e) +; unused +FlashScreenUnused: ; 7902e (1e:502e) ld a,[W_SUBANIMCOUNTER] cp a,14 jp z,AnimationFlashScreen @@ -879,17 +879,15 @@ Func_7902e: ; 7902e (1e:502e) ret ; function to make the pokemon disappear at the beginning of the animation -; XXX probably a trade-related animation -Func_79041: ; 79041 (1e:5041) +TradeHidePokemon: ; 79041 (1e:5041) ld a,[W_SUBANIMCOUNTER] cp a,6 ret nz - ld a,$2F - jp Func_7980c ; make pokemon disappear + ld a,2 * SCREEN_WIDTH + 7 + jp ClearMonPicFromTileMap ; make pokemon disappear ; function to make a shaking pokeball jump up at the end of the animation -; XXX probably a trade-related animation -Func_7904c: ; 7904c (1e:504c) +TradeShakePokeball: ; 7904c (1e:504c) ld a,[W_SUBANIMCOUNTER] cp a,1 ret nz @@ -915,16 +913,15 @@ Func_7904c: ; 7904c (1e:504c) jr .loop .done call AnimationCleanOAM - ld a,(SFX_02_44 - SFX_Headers_02) / 3 - jp PlaySound ; play sound + ld a,SFX_TRADE_MACHINE + jp PlaySound BallMoveDistances1: ; 79078 (1e:5078) db -12,-12,-8 db $ff ; terminator ; function to make the pokeball jump up -; XXX probably a trade-related animation -Func_7907c ; 507C +TradeJumpPokeball: ; 507C ld de,BallMoveDistances2 .loop ld hl,wOAMBuffer ; OAM buffer @@ -947,7 +944,7 @@ Func_7907c ; 507C cp a,$ff jr nz,.skipPlayingSound .playSound ; play sound if next move distance is 12 or this is the last one - ld a,(SFX_08_58 - SFX_Headers_08) / 3 + ld a,SFX_BATTLE_18 call PlaySound .skipPlayingSound push bc @@ -977,7 +974,7 @@ DoGrowlSpecialEffects: ; 790bc (1e:50bc) ret ; this is associated with Tail Whip, but Tail Whip doesn't use any subanimations -Func_790d0: ; 790d0 (1e:50d0) +TailWhipAnimationUnused: ; 790d0 (1e:50d0) ld a,1 ld [W_SUBANIMCOUNTER],a ld c,20 @@ -1005,8 +1002,8 @@ SpecialEffectPointers: ; 790da (1e:50da) dw AnimationSlideMonDown db SE_FLASH_MON_PIC ; $F5 dw AnimationFlashMonPic - db SE_SLIDE_MON_OUT ; $F4 - dw AnimationSlideMonOut + db SE_SLIDE_MON_OFF ; $F4 + dw AnimationSlideMonOff db SE_BLINK_MON ; $F3 dw AnimationBlinkMon db SE_MOVE_MON_HORIZONTALLY ; $F2 @@ -1035,8 +1032,8 @@ SpecialEffectPointers: ; 790da (1e:50da) dw AnimationLeavesFalling db SE_PETALS_FALLING ; $E6 dw AnimationPetalsFalling - db SE_SLIDE_MON_HALF_LEFT ; $E5 - dw AnimationSlideMonHalfLeft + db SE_SLIDE_MON_HALF_OFF ; $E5 + dw AnimationSlideMonHalfOff db SE_SHAKE_ENEMY_HUD ; $E4 dw AnimationShakeEnemyHUD db SE_SHAKE_ENEMY_HUD_2 ; unused--same pointer as SE_SHAKE_ENEMY_HUD ($E4) @@ -1055,8 +1052,8 @@ SpecialEffectPointers: ; 790da (1e:50da) dw AnimationShowMonPic db SE_SHOW_ENEMY_MON_PIC ; $DC dw AnimationShowEnemyMonPic - db SE_SLIDE_ENEMY_MON_OUT ; $DB - dw AnimationSlideEnemyMonOut + db SE_SLIDE_ENEMY_MON_OFF ; $DB + dw AnimationSlideEnemyMonOff db SE_SHAKE_BACK_AND_FORTH ; $DA dw AnimationShakeBackAndForth db SE_SUBSTITUTE_MON ; $D9 @@ -1087,7 +1084,7 @@ CallWithTurnFlipped: ; 79155 (1e:5155) ; flashes the screen for an extended period (48 frames) AnimationFlashScreenLong: ; 79165 (1e:5165) ld a,3 ; cycle through the palettes 3 times - ld [wd08a],a + ld [wFlashScreenLongCounter],a ld a,[wOnSGB] ; running on SGB? and a ld hl,FlashScreenLongMonochrome @@ -1103,9 +1100,9 @@ AnimationFlashScreenLong: ; 79165 (1e:5165) call FlashScreenLongDelay jr .innerLoop .endOfPalettes - ld a,[wd08a] + ld a,[wFlashScreenLongCounter] dec a - ld [wd08a],a + ld [wFlashScreenLongCounter],a pop hl jr nz,.loop ret @@ -1145,8 +1142,8 @@ FlashScreenLongSGB: ; 7919b (1e:519b) ; causes a delay of 2 frames for the first cycle ; causes a delay of 1 frame for the second and third cycles FlashScreenLongDelay: ; 791a8 (1e:51a8) - ld a,[wd08a] - cp a,4 ; never true since [wd08a] starts at 3 + ld a,[wFlashScreenLongCounter] + cp a,4 ; never true since [wFlashScreenLongCounter] starts at 3 ld c,4 jr z,.delayFrames cp a,3 @@ -1174,233 +1171,248 @@ AnimationFlashScreen: ; 791be (1e:51be) AnimationDarkScreenPalette: ; 791d6 (1e:51d6) ; Changes the screen's palette to a dark palette. - ld bc, $6f6f - jr Func_791fc + lb bc, $6f, $6f + jr SetAnimationBGPalette AnimationDarkenMonPalette: ; 791db (1e:51db) ; Darkens the mon sprite's palette. - ld bc, $f9f4 - jr Func_791fc + lb bc, $f9, $f4 + jr SetAnimationBGPalette -Func_791e0: ; 791e0 (1e:51e0) - ld bc, $fef8 - jr Func_791fc +AnimationUnusedPalette1: ; 791e0 (1e:51e0) + lb bc, $fe, $f8 + jr SetAnimationBGPalette -Func_791e5: ; 791e5 (1e:51e5) - ld bc, $ffff - jr Func_791fc +AnimationUnusedPalette2: ; 791e5 (1e:51e5) + lb bc, $ff, $ff + jr SetAnimationBGPalette AnimationResetScreenPalette: ; 791ea (1e:51ea) ; Restores the screen's palette to the normal palette. - ld bc, $e4e4 - jr Func_791fc + lb bc, $e4, $e4 + jr SetAnimationBGPalette -Func_791ef: ; 791ef (1e:51ef) - ld bc, $0000 - jr Func_791fc +AnimationUnusedPalette3: ; 791ef (1e:51ef) + lb bc, $00, $00 + jr SetAnimationBGPalette AnimationLightScreenPalette: ; 791f4 (1e:51f4) ; Changes the screen to use a palette with light colors. - ld bc, $9090 - jr Func_791fc + lb bc, $90, $90 + jr SetAnimationBGPalette -Func_791f9: ; 791f9 (1e:51f9) - ld bc, $4040 +AnimationUnusedPalette4: ; 791f9 (1e:51f9) + lb bc, $40, $40 -Func_791fc: ; 791fc (1e:51fc) +SetAnimationBGPalette: ; 791fc (1e:51fc) ld a, [wOnSGB] and a ld a, b - jr z, .asm_79204 + jr z, .next ld a, c -.asm_79204 - ld [rBGP], a ; $ff47 +.next + ld [rBGP], a ret ld b, $5 AnimationShakeScreenVertically: ; 79209 (1e:5209) - predef_jump Func_480ff + predef_jump PredefShakeScreenVertically AnimationShakeScreen: ; 7920e (1e:520e) ; Shakes the screen for a while. Used in Earthquake/Fissure/etc. animations. ld b, $8 AnimationShakeScreenHorizontallyFast: ; 79210 (1e:5210) - predef_jump Func_48125 + predef_jump PredefShakeScreenHorizontally AnimationWaterDropletsEverywhere: ; 79215 (1e:5215) ; Draws water droplets all over the screen and makes them ; scroll. It's hard to describe, but it's the main animation ; in Surf/Mist/Toxic. xor a - ld [wd09f], a + ld [wWhichBattleAnimTileset], a call LoadAnimationTileset - ld d, $20 - ld a, $f0 - ld [W_BASECOORDX], a ; wd081 + ld d, 32 + ld a, -16 + ld [W_BASECOORDX], a ld a, $71 - ld [wd09f], a -.asm_79228 - ld a, $10 - ld [W_BASECOORDY], a ; wd082 - ld a, $0 - ld [wd08a], a - call Func_79246 - ld a, $18 - ld [W_BASECOORDY], a ; wd082 - ld a, $20 - ld [wd08a], a - call Func_79246 + ld [wDropletTile], a +.loop + ld a, 16 + ld [W_BASECOORDY], a + ld a, 0 + ld [wUnusedD08A], a + call _AnimationWaterDroplets + ld a, 24 + ld [W_BASECOORDY], a + ld a, 32 + ld [wUnusedD08A], a + call _AnimationWaterDroplets dec d - jr nz, .asm_79228 + jr nz, .loop ret -Func_79246: ; 79246 (1e:5246) +_AnimationWaterDroplets: ; 79246 (1e:5246) ld hl, wOAMBuffer -.asm_79249 - ld a, [W_BASECOORDY] ; wd082 - ld [hli], a - ld a, [W_BASECOORDX] ; wd081 - add $1b - ld [W_BASECOORDX], a ; wd081 - ld [hli], a - ld a, [wd09f] - ld [hli], a +.loop + ld a, [W_BASECOORDY] + ld [hli], a ; Y + ld a, [W_BASECOORDX] + add 27 + ld [W_BASECOORDX], a + ld [hli], a ; X + ld a, [wDropletTile] + ld [hli], a ; tile xor a - ld [hli], a - ld a, [W_BASECOORDX] ; wd081 - cp $90 - jr c, .asm_79249 - sub $a8 - ld [W_BASECOORDX], a ; wd081 - ld a, [W_BASECOORDY] ; wd082 - add $10 - ld [W_BASECOORDY], a ; wd082 - cp $70 - jr c, .asm_79249 + ld [hli], a ; attribute + ld a, [W_BASECOORDX] + cp 144 + jr c, .loop + sub 168 + ld [W_BASECOORDX], a + ld a, [W_BASECOORDY] + add 16 + ld [W_BASECOORDY], a + cp 112 + jr c, .loop call AnimationCleanOAM jp DelayFrame AnimationSlideMonUp: ; 7927a (1e:527a) ; Slides the mon's sprite upwards. - ld c, $7 + ld c, 7 ld a, [H_WHOSETURN] and a - ld hl, wTileMap + $79 - ld de, wTileMap + $65 + coord hl, 1, 6 + coord de, 1, 5 ld a, $30 - jr z, .asm_79291 - ld hl, wTileMap + $20 - ld de, wTileMap + $c + jr z, .next + coord hl, 12, 1 + coord de, 12, 0 ld a, $ff -.asm_79291 - ld [wd09f], a - jp Func_792bf +.next + ld [wSlideMonUpBottomRowLeftTile], a + jp _AnimationSlideMonUp AnimationSlideMonDown: ; 79297 (1e:5297) ; Slides the mon's sprite down out of the screen. xor a call GetTileIDList -.asm_7929b +.loop call GetMonSpriteTileMapPointerFromRowCount push bc push de - call Func_79aae + call CopyPicTiles call Delay3 call AnimationHideMonPic pop de pop bc dec b - jr nz, .asm_7929b + jr nz, .loop ret -AnimationSlideMonOut: ; 792af (1e:52af) -; Slides the mon's sprite out of the screen horizontally. - ld e, $8 - ld a, $3 - ld [W_SUBANIMTRANSFORM], a ; W_SUBANIMTRANSFORM - jp Func_795f8 +AnimationSlideMonOff: ; 792af (1e:52af) +; Slides the mon's sprite off the screen horizontally. + ld e, 8 + ld a, 3 + ld [wSlideMonDelay], a + jp _AnimationSlideMonOff -AnimationSlideEnemyMonOut: ; 792b9 (1e:52b9) -; Slides the enemy mon out of the screen horizontally. - ld hl, AnimationSlideMonOut ; $52af +AnimationSlideEnemyMonOff: ; 792b9 (1e:52b9) +; Slides the enemy mon off the screen horizontally. + ld hl, AnimationSlideMonOff jp CallWithTurnFlipped -Func_792bf: ; 792bf (1e:52bf) +_AnimationSlideMonUp: ; 792bf (1e:52bf) push de push hl push bc - ld b, $6 -.asm_792c4 + +; In each iteration, slide up all rows but the top one (which is overwritten). + ld b, 6 +.slideLoop push bc push de push hl - ld bc, $0007 + ld bc, 7 call CopyData +; Note that de and hl are popped in the same order they are pushed, swapping +; their values. When CopyData is called, hl points to a tile 1 row below +; the one de points to. To maintain this relationship, after swapping, we add 2 +; rows to hl so that it is 1 row below again. pop de pop hl - ld bc, $0028 + ld bc, SCREEN_WIDTH * 2 add hl, bc pop bc dec b - jr nz, .asm_792c4 + jr nz, .slideLoop + +; Fill in the bottom row of the mon pic with the next row's tile IDs. ld a, [H_WHOSETURN] and a - ld hl, wTileMap + $dd - jr z, .asm_792e2 - ld hl, wTileMap + $84 -.asm_792e2 - ld a, [wd09f] + coord hl, 1, 11 + jr z, .next + coord hl, 12, 6 +.next + ld a, [wSlideMonUpBottomRowLeftTile] inc a - ld [wd09f], a - ld c, $7 -.asm_792eb + ld [wSlideMonUpBottomRowLeftTile], a + ld c, 7 +.fillBottomRowLoop ld [hli], a - add $7 + add 7 dec c - jr nz, .asm_792eb - ld c, $2 + jr nz, .fillBottomRowLoop + + ld c, 2 call DelayFrames pop bc pop hl pop de dec c - jr nz, Func_792bf + jr nz, _AnimationSlideMonUp ret -Func_792fd: ; 792fd (1e:52fd) +ShakeEnemyHUD_WritePlayerMonPicOAM: ; 792fd (1e:52fd) +; Writes the OAM entries for a copy of the player mon's pic in OAM. +; The top 5 rows are reproduced in OAM, although only 2 are actually needed. ld a, $10 ld [W_BASECOORDX], a ld a, $30 ld [W_BASECOORDY], a ld hl, wOAMBuffer - ld d, $0 - ld c, $7 -.asm_7930e + ld d, 0 + ld c, 7 +.loop ld a, [W_BASECOORDY] ld e, a - ld b, $5 -.asm_79314 - call Func_79329 + ld b, 5 +.innerLoop + call BattleAnimWriteOAMEntry inc d dec b - jr nz, .asm_79314 + jr nz, .innerLoop dec c ret z inc d inc d ld a, [W_BASECOORDX] - add $8 + add 8 ld [W_BASECOORDX], a - jr .asm_7930e + jr .loop -Func_79329: ; 79329 (1e:5329) +BattleAnimWriteOAMEntry: ; 79329 (1e:5329) +; Y coordinate = e (increased by 8 each call, before the write to OAM) +; X coordinate = [W_BASECOORDX] +; tile = d +; attributes = 0 ld a, e - add $8 + add 8 ld e, a ld [hli], a - ld a, [W_BASECOORDX] ; wd081 + ld a, [W_BASECOORDX] ld [hli], a ld a, d ld [hli], a @@ -1413,16 +1425,17 @@ AdjustOAMBlockXPos: ; 79337 (1e:5337) ld h, d AdjustOAMBlockXPos2: ; 79339 (1e:5339) - ld de, $4 + ld de, 4 .loop - ld a, [wd08a] + ld a, [wCoordAdjustmentAmount] ld b, a ld a, [hl] add b - cp $a8 + cp 168 jr c, .skipPuttingEntryOffScreen +; put off-screen if X >= 168 dec hl - ld a, $a0 + ld a, 160 ld [hli], a .skipPuttingEntryOffScreen ld [hl], a @@ -1436,16 +1449,16 @@ AdjustOAMBlockYPos: ; 79350 (1e:5350) ld h, d AdjustOAMBlockYPos2: ; 79352 (1e:5352) - ld de, $4 + ld de, 4 .loop - ld a, [wd08a] + ld a, [wCoordAdjustmentAmount] ld b, a ld a, [hl] add b - cp $70 + cp 112 jr c, .skipSettingPreviousEntrysAttribute dec hl - ld a, $a0 ; bug, sets previous OAM entry's attribute + ld a, 160 ; bug, sets previous OAM entry's attribute ld [hli], a .skipSettingPreviousEntrysAttribute ld [hl], a @@ -1456,34 +1469,34 @@ AdjustOAMBlockYPos2: ; 79352 (1e:5352) AnimationBlinkEnemyMon: ; 79369 (1e:5369) ; Make the enemy mon's sprite blink on and off for a second or two - ld hl, AnimationBlinkMon ; $536f + ld hl, AnimationBlinkMon jp CallWithTurnFlipped AnimationBlinkMon: ; 7936f (1e:536f) ; Make the mon's sprite blink on and off for a second or two. push af - ld c, $6 -.asm_79372 + ld c, 6 +.loop push bc call AnimationHideMonPic - ld c, $5 + ld c, 5 call DelayFrames call AnimationShowMonPic - ld c, $5 + ld c, 5 call DelayFrames pop bc dec c - jr nz, .asm_79372 + jr nz, .loop pop af ret AnimationFlashMonPic: ; 79389 (1e:5389) ; Flashes the mon's sprite on and off ld a, [wBattleMonSpecies] - ld [wHPBarMaxHP + 1], a + ld [wChangeMonPicPlayerTurnSpecies], a ld a, [wEnemyMonSpecies] - ld [wHPBarMaxHP], a - jp Func_79793 + ld [wChangeMonPicEnemyTurnSpecies], a + jp ChangeMonPic AnimationFlashEnemyMonPic: ; 79398 (1e:5398) ; Flashes the enemy mon's sprite on and off @@ -1494,7 +1507,7 @@ AnimationShowMonPic: ; 7939e (1e:539e) xor a call GetTileIDList call GetMonSpriteTileMapPointerFromRowCount - call Func_79aae + call CopyPicTiles jp Delay3 AnimationShowEnemyMonPic: ; 793ab (1e:53ab) @@ -1508,16 +1521,16 @@ AnimationShakeBackAndForth: ; 793b1 (1e:53b1) ; The mon's sprite disappears after this animation. ld a, [H_WHOSETURN] and a - ld hl, wTileMap + $64 - ld de, wTileMap + $66 - jr z, .asm_793c2 - ld hl, wTileMap + $b - ld de, wTileMap + $d + coord hl, 0, 5 + coord de, 2, 5 + jr z, .next + coord hl, 11, 0 + coord de, 13, 0 -.asm_793c2 +.next xor a ld c, $10 -.asm_793c5 +.loop push af push bc push de @@ -1529,113 +1542,113 @@ AnimationShakeBackAndForth: ; 793b1 (1e:53b1) push hl call GetTileIDList pop hl - call Func_79aae + call CopyPicTiles call Delay3 pop hl - ld bc, $0709 + lb bc, 7, 9 call ClearScreenArea pop af call GetTileIDList pop hl - call Func_79aae + call CopyPicTiles call Delay3 pop hl - ld bc, $0709 + lb bc, 7, 9 call ClearScreenArea pop hl pop de pop bc pop af dec c - jr nz, .asm_793c5 + jr nz, .loop ret AnimationMoveMonHorizontally: ; 793f9 (1e:53f9) ; Shifts the mon's sprite horizontally to a fixed location. Used by lots of ; animations like Tackle/Body Slam. call AnimationHideMonPic - ld a, [H_WHOSETURN] ; $fff3 + ld a, [H_WHOSETURN] and a - hlCoord 2, 5 - jr z, .asm_79407 - hlCoord 11, 0 -.asm_79407 + coord hl, 2, 5 + jr z, .next + coord hl, 11, 0 +.next xor a push hl call GetTileIDList pop hl - call Func_79aae - ld c, $3 + call CopyPicTiles + ld c, 3 jp DelayFrames AnimationResetMonPosition: ; 79415 (1e:5415) ; Resets the mon's sprites to be located at the normal coordinates. - ld a, [H_WHOSETURN] ; $fff3 + ld a, [H_WHOSETURN] and a - ld a, $66 - jr z, .asm_7941e - ld a, $b -.asm_7941e - call Func_7980c + ld a, 5 * SCREEN_WIDTH + 2 + jr z, .next + ld a, 11 +.next + call ClearMonPicFromTileMap jp AnimationShowMonPic AnimationSpiralBallsInward: ; 79424 (1e:5424) -; Creates an effect that looks like energy balls sprialing into the +; Creates an effect that looks like energy balls spiralling into the ; player mon's sprite. Used in Focus Energy, for example. - ld a, [H_WHOSETURN] ; $fff3 + ld a, [H_WHOSETURN] and a - jr z, .asm_79435 - ld a, $d8 - ld [wd08a], a - ld a, $50 - ld [W_SUBANIMTRANSFORM], a ; W_SUBANIMTRANSFORM - jr .asm_7943c -.asm_79435 + jr z, .playerTurn + ld a, -40 + ld [wSpiralBallsBaseY], a + ld a, 80 + ld [wSpiralBallsBaseX], a + jr .next +.playerTurn xor a - ld [wd08a], a - ld [W_SUBANIMTRANSFORM], a ; W_SUBANIMTRANSFORM -.asm_7943c - ld d, $7a - ld c, $3 + ld [wSpiralBallsBaseY], a + ld [wSpiralBallsBaseX], a +.next + ld d, $7a ; ball tile + ld c, 3 ; number of balls xor a - call Func_797e8 - ld hl, SpiralBallAnimationCoordinates ; $5476 -.asm_79447 + call InitMultipleObjectsOAM + ld hl, SpiralBallAnimationCoordinates +.loop push hl - ld c, $3 + ld c, 3 ld de, wOAMBuffer -.asm_7944d +.innerLoop ld a, [hl] cp $ff - jr z, .asm_7946f - ld a, [wd08a] + jr z, .done + ld a, [wSpiralBallsBaseY] add [hl] - ld [de], a + ld [de], a ; Y inc de inc hl - ld a, [W_SUBANIMTRANSFORM] ; W_SUBANIMTRANSFORM + ld a, [wSpiralBallsBaseX] add [hl] - ld [de], a + ld [de], a ; X inc hl inc de inc de inc de dec c - jr nz, .asm_7944d - ld c, $5 + jr nz, .innerLoop + ld c, 5 call DelayFrames pop hl inc hl inc hl - jr .asm_79447 -.asm_7946f + jr .loop +.done pop hl call AnimationCleanOAM jp AnimationFlashScreen SpiralBallAnimationCoordinates: ; 79476 (1e:5476) ; y, x pairs -; This is the sequence of screen coordinates that the spiraling +; This is the sequence of screen coordinates that the spiralling ; balls are positioned at. db $38, $28 db $40, $18 @@ -1663,125 +1676,126 @@ SpiralBallAnimationCoordinates: ; 79476 (1e:5476) AnimationSquishMonPic: ; 794a1 (1e:54a1) ; Squishes the mon's sprite horizontally making it ; disappear. Used by Teleport/Sky Attack animations. - ld c, $4 -.asm_794a3 + ld c, 4 +.loop push bc - ld a, [H_WHOSETURN] ; $fff3 + ld a, [H_WHOSETURN] and a - jr z, .asm_794b1 - hlCoord 16, 0 - deCoord 14, 0 - jr .asm_794b7 -.asm_794b1 - hlCoord 5, 5 - deCoord 3, 5 -.asm_794b7 + jr z, .playerTurn + coord hl, 16, 0 + coord de, 14, 0 + jr .next +.playerTurn + coord hl, 5, 5 + coord de, 3, 5 +.next push de - xor a - ld [wd09f], a - call Func_794d4 + xor a ; left + ld [wSquishMonCurrentDirection], a + call _AnimationSquishMonPic pop hl - ld a, $1 - ld [wd09f], a - call Func_794d4 + ld a, 1 ; right + ld [wSquishMonCurrentDirection], a + call _AnimationSquishMonPic pop bc dec c - jr nz, .asm_794a3 + jr nz, .loop call AnimationHideMonPic - ld c, $2 + ld c, 2 jp DelayFrame -Func_794d4: ; 794d4 (1e:54d4) - ld c, $7 -.asm_794d6 +_AnimationSquishMonPic: ; 794d4 (1e:54d4) + ld c, 7 +.loop push bc push hl - ld c, $3 - ld a, [wd09f] - cp $0 - jr nz, .asm_794e7 - call Func_7985b + ld c, 3 + ld a, [wSquishMonCurrentDirection] + cp 0 + jr nz, .right + call AnimCopyRowLeft dec hl - jr .asm_794eb -.asm_794e7 - call Func_79862 + jr .next +.right + call AnimCopyRowRight inc hl -.asm_794eb - ld [hl], $7f +.next + ld [hl], " " pop hl - ld de, $14 + ld de, SCREEN_WIDTH add hl, de pop bc dec c - jr nz, .asm_794d6 + jr nz, .loop jp Delay3 AnimationShootBallsUpward: ; 794f9 (1e:54f9) ; Shoots one pillar of "energy" balls upwards. Used in Teleport/Sky Attack ; animations. - ld a, [H_WHOSETURN] ; $fff3 + ld a, [H_WHOSETURN] and a - jr z, .asm_79503 - ld bc, $80 - jr .asm_79506 -.asm_79503 - ld bc, $3028 -.asm_79506 + jr z, .playerTurn + lb bc, 0, 16 * 8 + jr .next +.playerTurn + lb bc, 6 * 8, 5 * 8 +.next ld a, b - ld [W_BASECOORDY], a ; wd082 + ld [W_BASECOORDY], a ld a, c - ld [W_BASECOORDX], a ; wd081 - ld bc, $501 - call Func_79517 + ld [W_BASECOORDX], a + lb bc, 5, 1 + call _AnimationShootBallsUpward jp AnimationCleanOAM -Func_79517: ; 79517 (1e:5517) +_AnimationShootBallsUpward: ; 79517 (1e:5517) push bc xor a - ld [wd09f], a + ld [wWhichBattleAnimTileset], a call LoadAnimationTileset pop bc - ld d, $7a + ld d, $7a ; ball tile ld hl, wOAMBuffer push bc - ld a, [W_BASECOORDY] ; wd082 + ld a, [W_BASECOORDY] ld e, a -.asm_7952a - call Func_79329 +.initOAMLoop + call BattleAnimWriteOAMEntry dec b - jr nz, .asm_7952a + jr nz, .initOAMLoop call DelayFrame pop bc ld a, b - ld [wd08a], a -.asm_79538 + ld [wNumShootingBalls], a +.loop push bc ld hl, wOAMBuffer -.asm_7953c - ld a, [W_BASECOORDY] ; wd082 - add $8 +.innerLoop + ld a, [W_BASECOORDY] + add 8 ld e, a ld a, [hl] - cp e - jr z, .asm_7954b - add $fc + cp e ; has the ball reached the top? + jr z, .reachedTop + add -4 ; ball hasn't reached the top. move it up 4 pixels ld [hl], a - jr .asm_79554 -.asm_7954b - ld [hl], $0 - ld a, [wd08a] + jr .next +.reachedTop +; remove the ball once it has reached the top + ld [hl], 0 ; put it off-screen + ld a, [wNumShootingBalls] dec a - ld [wd08a], a -.asm_79554 - ld de, $4 - add hl, de + ld [wNumShootingBalls], a +.next + ld de, 4 + add hl, de ; next OAM entry dec b - jr nz, .asm_7953c + jr nz, .innerLoop call DelayFrames pop bc - ld a, [wd08a] + ld a, [wNumShootingBalls] and a - jr nz, .asm_79538 + jr nz, .loop ret AnimationShootManyBallsUpward: ; 79566 (1e:5566) @@ -1794,17 +1808,17 @@ AnimationShootManyBallsUpward: ; 79566 (1e:5566) ld hl, UpwardBallsAnimXCoordinatesEnemyTurn ld a, $28 ; y coordinate for "energy" ball pillar .player - ld [wTrainerSpriteOffset], a + ld [wSavedY], a .loop - ld a, [wTrainerSpriteOffset] + ld a, [wSavedY] ld [W_BASECOORDY], a ld a, [hli] cp $ff jp z, AnimationCleanOAM ld [W_BASECOORDX], a - ld bc, $0401 + lb bc, 4, 1 push hl - call Func_79517 + call _AnimationShootBallsUpward pop hl jr .loop @@ -1831,16 +1845,16 @@ AnimationMinimizeMon: ; 7959f (1e:559f) pop hl ld de, $194 add hl, de - ld de, MinimizedMonSprite ; $55c4 + ld de, MinimizedMonSprite ld c, $5 -.asm_795b4 +.loop ld a, [de] ld [hli], a ld [hli], a inc de dec c - jr nz, .asm_795b4 - call Func_79652 + jr nz, .loop + call CopyTempPicToMonPic call Delay3 jp AnimationShowMonPic @@ -1851,7 +1865,7 @@ AnimationSlideMonDownAndHide: ; 795c9 (1e:55c9) ; Slides the mon's sprite down and disappears. Used in Acid Armor. ld a, $1 ld c, $2 -.asm_795cd +.loop push bc push af call AnimationHideMonPic @@ -1859,94 +1873,108 @@ AnimationSlideMonDownAndHide: ; 795c9 (1e:55c9) push af call GetTileIDList call GetMonSpriteTileMapPointerFromRowCount - call Func_79aae - ld c, $8 + call CopyPicTiles + ld c, 8 call DelayFrames pop af inc a pop bc dec c - jr nz, .asm_795cd + jr nz, .loop call AnimationHideMonPic ld hl, wTempPic ld bc, $0310 xor a call FillMemory - jp Func_79652 + jp CopyTempPicToMonPic -Func_795f8: ; 795f8 (1e:55f8) - ld a, [H_WHOSETURN] ; $fff3 +_AnimationSlideMonOff: ; 795f8 (1e:55f8) +; Slides the mon's sprite off the screen horizontally by e tiles and waits +; [wSlideMonDelay] V-blanks each time the pic is slid by one tile. + ld a, [H_WHOSETURN] and a - jr z, .asm_79602 - hlCoord 12, 0 - jr .asm_79605 -.asm_79602 - hlCoord 0, 5 -.asm_79605 - ld d, $8 -.asm_79607 + jr z, .playerTurn + coord hl, 12, 0 + jr .next +.playerTurn + coord hl, 0, 5 +.next + ld d, 8 ; d's value is unused +.slideLoop ; iterates once for each time the pic slides by one tile push hl - ld b, $7 -.asm_7960a - ld c, $8 -.asm_7960c - ld a, [H_WHOSETURN] ; $fff3 + ld b, 7 +.rowLoop ; iterates once for each row + ld c, 8 +.tileLoop ; iterates once for each tile in the row + ld a, [H_WHOSETURN] and a - jr z, .asm_79616 - call Func_7963c - jr .asm_79619 -.asm_79616 - call Func_79633 -.asm_79619 + jr z, .playerTurn2 + call .EnemyNextTile + jr .next2 +.playerTurn2 + call .PlayerNextTile +.next2 ld [hli], a dec c - jr nz, .asm_7960c + jr nz, .tileLoop push de - ld de, $c + ld de, SCREEN_WIDTH - 8 add hl, de pop de dec b - jr nz, .asm_7960a - ld a, [W_SUBANIMTRANSFORM] ; W_SUBANIMTRANSFORM + jr nz, .rowLoop + ld a, [wSlideMonDelay] ld c, a call DelayFrames pop hl dec d dec e - jr nz, .asm_79607 + jr nz, .slideLoop ret -Func_79633: ; 79633 (1e:5633) +; Since mon pic tile numbers go from top to bottom, left to right in order, +; adding the height of the mon pic in tiles to a tile number gives the tile +; number of the tile one column to the right (and thus subtracting the height +; gives the reverse). If the next tile would be past the edge of the pic, the 2 +; functions below catch it by checking if the tile number is within the valid +; range and if not, replacing it with a blank tile. + +.PlayerNextTile ; 79633 (1e:5633) ld a, [hl] - add $7 + add 7 +; This is a bug. The lower right corner tile of the mon back pic is blanked +; while the mon is sliding off the screen. It should compare with the max tile +; plus one instead. cp $61 ret c - ld a, $7f + ld a, " " ret -Func_7963c: ; 7963c (1e:563c) +.EnemyNextTile ; 7963c (1e:563c) ld a, [hl] - sub $7 + sub 7 +; This has the same problem as above, but it has no visible effect because +; the lower right tile is in the first column to slide off the screen. cp $30 ret c - ld a, $7f + ld a, " " ret -AnimationSlideMonHalfLeft: ; 79645 (1e:5645) -; Slides the mon's sprite halfway out of the screen. It's used in Softboiled. - ld e, $4 - ld a, $4 - ld [W_SUBANIMTRANSFORM], a - call Func_795f8 +AnimationSlideMonHalfOff: ; 79645 (1e:5645) +; Slides the mon's sprite halfway off the screen. It's used in Softboiled. + ld e, 4 + ld a, 4 + ld [wSlideMonDelay], a + call _AnimationSlideMonOff jp Delay3 -Func_79652: ; 79652 (1e:5652) - ld a, [H_WHOSETURN] ; $fff3 +CopyTempPicToMonPic: ; 79652 (1e:5652) + ld a, [H_WHOSETURN] and a - ld hl, vBackPic - jr z, .asm_7965d - ld hl, vFrontPic -.asm_7965d + ld hl, vBackPic ; player turn + jr z, .next + ld hl, vFrontPic ; enemy turn +.next ld de, wTempPic ld bc, 7 * 7 jp CopyVideoData @@ -1954,55 +1982,55 @@ Func_79652: ; 79652 (1e:5652) AnimationWavyScreen: ; 79666 (1e:5666) ; used in Psywave/Psychic etc. ld hl, vBGMap0 - call Func_79e0d + call BattleAnimCopyTileMapToVRAM call Delay3 xor a ld [H_AUTOBGTRANSFERENABLED], a - ld a, $90 + ld a, SCREEN_HEIGHT_PIXELS ld [hWY], a - ld d, $80 - ld e, $8f + ld d, $80 ; terminator + ld e, SCREEN_HEIGHT_PIXELS - 1 ld c, $ff ld hl, WavyScreenLineOffsets -.asm_7967f +.loop push hl -.asm_79680 - call Func_796ae - ld a, [$ff44] - cp e - jr nz, .asm_79680 +.innerLoop + call WavyScreen_SetSCX + ld a, [rLY] + cp e ; is it the last visible line in the frame? + jr nz, .innerLoop ; keep going if not pop hl inc hl ld a, [hl] - cp d - jr nz, .asm_79691 - ld hl, WavyScreenLineOffsets -.asm_79691 + cp d ; have we reached the end? + jr nz, .next + ld hl, WavyScreenLineOffsets ; go back to the beginning if so +.next dec c - jr nz, .asm_7967f + jr nz, .loop xor a ld [hWY], a call SaveScreenTilesToBuffer2 call ClearScreen - ld a, $1 + ld a, 1 ld [H_AUTOBGTRANSFERENABLED], a call Delay3 call LoadScreenTilesFromBuffer2 ld hl, vBGMap1 - call Func_79e0d + call BattleAnimCopyTileMapToVRAM ret -Func_796ae: ; 796ae (1e:56ae) - ld a, [$ff41] - and $3 - jr nz, Func_796ae +WavyScreen_SetSCX: ; 796ae (1e:56ae) + ld a, [rSTAT] + and $3 ; is it H-blank? + jr nz, WavyScreen_SetSCX ; wait until it's H-blank ld a, [hl] - ld [$ff43], a + ld [rSCX], a inc hl ld a, [hl] - cp d + cp d ; have we reached the end? ret nz - ld hl, WavyScreenLineOffsets + ld hl, WavyScreenLineOffsets ; go back to the beginning if so ret WavyScreenLineOffsets: ; 796bf (1e:56bf) @@ -2018,9 +2046,9 @@ AnimationSubstitute: ; 796e0 (1e:56e0) xor a ld bc, $0310 call FillMemory - ld a, [$fff3] + ld a, [H_WHOSETURN] and a - jr z, .asm_79715 ; 0x796ed $26 + jr z, .playerTurn ld hl, SlowbroSprite ; facing down sprite ld de, wTempPic + $120 call CopySlowbroSpriteData @@ -2033,8 +2061,8 @@ AnimationSubstitute: ; 796e0 (1e:56e0) ld hl, SlowbroSprite + $30 ld de, wTempPic + $120 + $10 + $70 call CopySlowbroSpriteData - jr .asm_79739 -.asm_79715 + jr .next +.playerTurn ld hl, SlowbroSprite + $40 ; facing up sprite ld de, wTempPic + $120 + $70 call CopySlowbroSpriteData @@ -2047,8 +2075,8 @@ AnimationSubstitute: ; 796e0 (1e:56e0) ld hl, SlowbroSprite + $70 ld de, wTempPic + $120 + $f0 call CopySlowbroSpriteData -.asm_79739 - call Func_79652 +.next + call CopyTempPicToMonPic jp AnimationShowMonPic CopySlowbroSpriteData: ; 7973f (1e:573f) @@ -2056,23 +2084,24 @@ CopySlowbroSpriteData: ; 7973f (1e:573f) ld a, BANK(SlowbroSprite) jp FarCopyData2 -Func_79747: ; 79747 (1e:5747) - ld a, [H_WHOSETURN] ; $fff3 +HideSubstituteShowMonAnim: ; 79747 (1e:5747) + ld a, [H_WHOSETURN] and a - ld hl, wccf7 - ld a, [W_PLAYERBATTSTATUS2] ; W_PLAYERBATTSTATUS2 - jr z, .asm_79758 - ld hl, wccf3 - ld a, [W_ENEMYBATTSTATUS2] ; W_ENEMYBATTSTATUS2 -.asm_79758 + ld hl, wPlayerMonMinimized + ld a, [W_PLAYERBATTSTATUS2] + jr z, .next1 + ld hl, wEnemyMonMinimized + ld a, [W_ENEMYBATTSTATUS2] +.next1 push hl - bit 4, a - jr nz, .asm_79762 +; if the substitute broke, slide it down, else slide it offscreen horizontally + bit HasSubstituteUp, a + jr nz, .substituteStillUp call AnimationSlideMonDown - jr .asm_79765 -.asm_79762 - call AnimationSlideMonOut -.asm_79765 + jr .next2 +.substituteStillUp + call AnimationSlideMonOff +.next2 pop hl ld a, [hl] and a @@ -2080,48 +2109,48 @@ Func_79747: ; 79747 (1e:5747) call AnimationFlashMonPic jp AnimationShowMonPic -Func_79771: ; 79771 (1e:5771) - call AnimationSlideMonOut +ReshowSubstituteAnim: ; 79771 (1e:5771) + call AnimationSlideMonOff call AnimationSubstitute jp AnimationShowMonPic AnimationBoundUpAndDown: ; 7977a (1e:577a) ; Bounces the mon's sprite up and down several times. It is used ; by Splash's animation. - ld c, $5 -.asm_7977c + ld c, 5 +.loop push bc call AnimationSlideMonDown pop bc dec c - jr nz, .asm_7977c ; 0x79782 $f8 + jr nz, .loop jp AnimationShowMonPic AnimationTransformMon: ; 79787 (1e:5787) ; Redraws this mon's sprite as the back/front sprite of the opposing mon. ; Used in Transform. ld a, [wEnemyMonSpecies] - ld [wHPBarMaxHP + 1], a + ld [wChangeMonPicPlayerTurnSpecies], a ld a, [wBattleMonSpecies] - ld [wHPBarMaxHP], a + ld [wChangeMonPicEnemyTurnSpecies], a -Func_79793: ; 79793 (1e:5793) - ld a, [H_WHOSETURN] ; $fff3 +ChangeMonPic: ; 79793 (1e:5793) + ld a, [H_WHOSETURN] and a - jr z, .asm_797b0 - ld a, [wHPBarMaxHP] + jr z, .playerTurn + ld a, [wChangeMonPicEnemyTurnSpecies] ld [wcf91], a ld [wd0b5], a xor a ld [W_SPRITEFLIPPED], a call GetMonHeader - hlCoord 12, 0 + coord hl, 12, 0 call LoadFrontSpriteByMonIndex - jr .asm_797d3 -.asm_797b0 + jr .done +.playerTurn ld a, [wBattleMonSpecies2] push af - ld a, [wHPBarMaxHP + 1] + ld a, [wChangeMonPicPlayerTurnSpecies] ld [wBattleMonSpecies2], a ld [wd0b5], a call GetMonHeader @@ -2129,59 +2158,63 @@ Func_79793: ; 79793 (1e:5793) xor a call GetTileIDList call GetMonSpriteTileMapPointerFromRowCount - call Func_79aae + call CopyPicTiles pop af ld [wBattleMonSpecies2], a -.asm_797d3 - ld b, $1 - jp GoPAL_SET +.done + ld b, SET_PAL_BATTLE + jp RunPaletteCommand AnimationHideEnemyMonPic: ; 797d8 (1e:57d8) ; Hides the enemy mon's sprite xor a - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba - ld hl, AnimationHideMonPic ; $5801 + ld [H_AUTOBGTRANSFERENABLED], a + ld hl, AnimationHideMonPic call CallWithTurnFlipped ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba + ld [H_AUTOBGTRANSFERENABLED], a jp Delay3 -Func_797e8: ; 797e8 (1e:57e8) +InitMultipleObjectsOAM: ; 797e8 (1e:57e8) +; Writes c OAM entries with tile d. +; Sets their Y coordinates to sequential multiples of 8, starting from 0. +; Sets their X coordinates to 0. +; Loads animation tileset a. push bc push de - ld [wd09f], a + ld [wWhichBattleAnimTileset], a call LoadAnimationTileset pop de pop bc xor a ld e, a - ld [W_BASECOORDX], a ; wd081 + ld [W_BASECOORDX], a ld hl, wOAMBuffer -.asm_797fa - call Func_79329 +.loop + call BattleAnimWriteOAMEntry dec c - jr nz, .asm_797fa + jr nz, .loop ret AnimationHideMonPic: ; 79801 (1e:5801) ; Hides the mon's sprite. - ld a, [H_WHOSETURN] ; $fff3 + ld a, [H_WHOSETURN] and a - jr z, .asm_7980a - ld a, $c - jr Func_7980c -.asm_7980a - ld a, $65 + jr z, .playerTurn + ld a, 12 + jr ClearMonPicFromTileMap +.playerTurn + ld a, 5 * SCREEN_WIDTH + 1 -Func_7980c: ; 7980c (1e:580c) +ClearMonPicFromTileMap: ; 7980c (1e:580c) push hl push de push bc ld e, a - ld d, $0 - ld hl, wTileMap + ld d, 0 + coord hl, 0, 0 add hl, de - ld bc, $707 + lb bc, 7, 7 call ClearScreenArea pop bc pop de @@ -2201,7 +2234,7 @@ GetMonSpriteTileMapPointerFromRowCount: ; 79820 (1e:5820) .enemyTurn ld a, 12 .next - ld hl, wTileMap + coord hl, 0, 0 ld e, a ld d, 0 add hl, de @@ -2245,29 +2278,33 @@ GetTileIDList: ; 79842 (1e:5842) ld b, a ret -Func_7985b: ; 7985b (1e:585b) +AnimCopyRowLeft: ; 7985b (1e:585b) +; copy a row of c tiles 1 tile left ld a, [hld] ld [hli], a inc hl dec c - jr nz, Func_7985b + jr nz, AnimCopyRowLeft ret -Func_79862: ; 79862 (1e:5862) +AnimCopyRowRight: ; 79862 (1e:5862) +; copy a row of c tiles 1 tile right ld a, [hli] ld [hld], a dec hl dec c - jr nz, Func_79862 + jr nz, AnimCopyRowRight ret -Func_79869: ; 79869 (1e:5869) +; get the sound of the move id in b +GetMoveSoundB: ; 79869 (1e:5869) ld a, b - call Func_7986f + call GetMoveSound ld b, a ret -Func_7986f: ; 7986f (1e:586f) +; get the sound of the (move id - 1) in a +GetMoveSound: ; 7986f (1e:586f) ld hl,MoveSoundTable ld e,a ld d,0 @@ -2290,19 +2327,19 @@ Func_7986f: ; 7986f (1e:586f) call GetCryData ld b,a pop hl - ld a,[wc0f1] + ld a,[wFrequencyModifier] add [hl] - ld [wc0f1],a + ld [wFrequencyModifier],a inc hl - ld a,[wc0f2] + ld a,[wTempoModifier] add [hl] - ld [wc0f2],a + ld [wTempoModifier],a jr .done .NotCryMove ld a,[hli] - ld [wc0f1],a + ld [wFrequencyModifier],a ld a,[hli] - ld [wc0f2],a + ld [wTempoModifier],a .done ld a,b ret @@ -2321,196 +2358,200 @@ IsCryMove: ; 798ad (1e:58ad) ret MoveSoundTable: ; 798bc (1e:58bc) - db (SFX_08_4a - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_4c - SFX_Headers_08) / 3,$10,$80 - db (SFX_08_5d - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_4b - SFX_Headers_08) / 3,$01,$80 - db (SFX_08_4d - SFX_Headers_08) / 3,$00,$40 - db (SFX_08_77 - SFX_Headers_08) / 3,$00,$ff - db (SFX_08_4d - SFX_Headers_08) / 3,$10,$60 - db (SFX_08_4d - SFX_Headers_08) / 3,$20,$80 - db (SFX_08_4d - SFX_Headers_08) / 3,$00,$a0 - db (SFX_08_50 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_4f - SFX_Headers_08) / 3,$20,$40 - db (SFX_08_4f - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_4e - SFX_Headers_08) / 3,$00,$a0 - db (SFX_08_51 - SFX_Headers_08) / 3,$10,$c0 - db (SFX_08_51 - SFX_Headers_08) / 3,$00,$a0 - db (SFX_08_52 - SFX_Headers_08) / 3,$00,$c0 - db (SFX_08_52 - SFX_Headers_08) / 3,$10,$a0 - db (SFX_08_53 - SFX_Headers_08) / 3,$00,$e0 - db (SFX_08_51 - SFX_Headers_08) / 3,$20,$c0 - db (SFX_08_54 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_62 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_55 - SFX_Headers_08) / 3,$01,$80 - db (SFX_08_60 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_57 - SFX_Headers_08) / 3,$f0,$40 - db (SFX_08_5a - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_57 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_61 - SFX_Headers_08) / 3,$10,$80 - db (SFX_08_5b - SFX_Headers_08) / 3,$01,$a0 - db (SFX_08_58 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_5e - SFX_Headers_08) / 3,$00,$60 - db (SFX_08_5e - SFX_Headers_08) / 3,$01,$40 - db (SFX_08_5f - SFX_Headers_08) / 3,$00,$a0 - db (SFX_08_5a - SFX_Headers_08) / 3,$10,$a0 - db (SFX_08_60 - SFX_Headers_08) / 3,$00,$c0 - db (SFX_08_54 - SFX_Headers_08) / 3,$10,$60 - db (SFX_08_5a - SFX_Headers_08) / 3,$00,$a0 - db (SFX_08_62 - SFX_Headers_08) / 3,$11,$c0 - db (SFX_08_5a - SFX_Headers_08) / 3,$20,$c0 - db (SFX_08_61 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_5b - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_5b - SFX_Headers_08) / 3,$20,$c0 - db (SFX_08_59 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_71 - SFX_Headers_08) / 3,$ff,$40 - db (SFX_08_5e - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_4b - SFX_Headers_08) / 3,$00,$c0 - db (SFX_08_4b - SFX_Headers_08) / 3,$00,$40 - db (SFX_08_75 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_67 - SFX_Headers_08) / 3,$40,$60 - db (SFX_08_67 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_67 - SFX_Headers_08) / 3,$ff,$40 - db (SFX_08_6a - SFX_Headers_08) / 3,$80,$c0 - db (SFX_08_59 - SFX_Headers_08) / 3,$10,$a0 - db (SFX_08_59 - SFX_Headers_08) / 3,$21,$e0 - db (SFX_08_69 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_64 - SFX_Headers_08) / 3,$20,$60 - db (SFX_08_6a - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_6c - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_68 - SFX_Headers_08) / 3,$40,$80 - db (SFX_08_69 - SFX_Headers_08) / 3,$f0,$e0 - db (SFX_08_6d - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_6a - SFX_Headers_08) / 3,$f0,$60 - db (SFX_08_68 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_76 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_47 - SFX_Headers_08) / 3,$01,$a0 - db (SFX_08_53 - SFX_Headers_08) / 3,$f0,$20 - db (SFX_08_63 - SFX_Headers_08) / 3,$01,$c0 - db (SFX_08_63 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_5a - SFX_Headers_08) / 3,$00,$e0 - db (SFX_08_66 - SFX_Headers_08) / 3,$01,$60 - db (SFX_08_66 - SFX_Headers_08) / 3,$20,$40 - db (SFX_08_64 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_64 - SFX_Headers_08) / 3,$40,$c0 - db (SFX_08_5b - SFX_Headers_08) / 3,$03,$60 - db (SFX_08_65 - SFX_Headers_08) / 3,$11,$e0 - db (SFX_08_52 - SFX_Headers_08) / 3,$20,$e0 - db (SFX_08_6e - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_5c - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_5c - SFX_Headers_08) / 3,$11,$a0 - db (SFX_08_5c - SFX_Headers_08) / 3,$01,$c0 - db (SFX_08_53 - SFX_Headers_08) / 3,$14,$c0 - db (SFX_08_5b - SFX_Headers_08) / 3,$02,$a0 - db (SFX_08_69 - SFX_Headers_08) / 3,$f0,$80 - db (SFX_08_69 - SFX_Headers_08) / 3,$20,$c0 - db (SFX_08_6f - SFX_Headers_08) / 3,$00,$20 - db (SFX_08_6f - SFX_Headers_08) / 3,$20,$80 - db (SFX_08_6e - SFX_Headers_08) / 3,$12,$60 - db (SFX_08_66 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_54 - SFX_Headers_08) / 3,$01,$e0 - db (SFX_08_69 - SFX_Headers_08) / 3,$0f,$e0 - db (SFX_08_69 - SFX_Headers_08) / 3,$11,$20 - db (SFX_08_50 - SFX_Headers_08) / 3,$10,$40 - db (SFX_08_4f - SFX_Headers_08) / 3,$10,$c0 - db (SFX_08_54 - SFX_Headers_08) / 3,$00,$20 - db (SFX_08_70 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_75 - SFX_Headers_08) / 3,$11,$18 - db (SFX_08_49 - SFX_Headers_08) / 3,$20,$c0 - db (SFX_08_48 - SFX_Headers_08) / 3,$20,$c0 - db (SFX_08_65 - SFX_Headers_08) / 3,$00,$10 - db (SFX_08_66 - SFX_Headers_08) / 3,$f0,$20 - db (SFX_08_73 - SFX_Headers_08) / 3,$f0,$c0 - db (SFX_08_51 - SFX_Headers_08) / 3,$f0,$e0 - db (SFX_08_49 - SFX_Headers_08) / 3,$f0,$40 - db (SFX_08_71 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_73 - SFX_Headers_08) / 3,$80,$40 - db (SFX_08_73 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_54 - SFX_Headers_08) / 3,$11,$20 - db (SFX_08_54 - SFX_Headers_08) / 3,$22,$10 - db (SFX_08_5b - SFX_Headers_08) / 3,$f1,$ff - db (SFX_08_53 - SFX_Headers_08) / 3,$f1,$ff - db (SFX_08_54 - SFX_Headers_08) / 3,$33,$30 - db (SFX_08_72 - SFX_Headers_08) / 3,$40,$c0 - db (SFX_08_4e - SFX_Headers_08) / 3,$20,$20 - db (SFX_08_4e - SFX_Headers_08) / 3,$f0,$10 - db (SFX_08_4f - SFX_Headers_08) / 3,$f8,$10 - db (SFX_08_51 - SFX_Headers_08) / 3,$f0,$10 - db (SFX_08_65 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_58 - SFX_Headers_08) / 3,$00,$c0 - db (SFX_08_72 - SFX_Headers_08) / 3,$c0,$ff - db (SFX_08_49 - SFX_Headers_08) / 3,$f2,$20 - db (SFX_08_74 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_74 - SFX_Headers_08) / 3,$00,$40 - db (SFX_08_49 - SFX_Headers_08) / 3,$00,$40 - db (SFX_08_51 - SFX_Headers_08) / 3,$10,$ff - db (SFX_08_6a - SFX_Headers_08) / 3,$20,$20 - db (SFX_08_72 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_69 - SFX_Headers_08) / 3,$1f,$20 - db (SFX_08_65 - SFX_Headers_08) / 3,$2f,$80 - db (SFX_08_4f - SFX_Headers_08) / 3,$1f,$ff - db (SFX_08_6b - SFX_Headers_08) / 3,$1f,$60 - db (SFX_08_66 - SFX_Headers_08) / 3,$1e,$20 - db (SFX_08_66 - SFX_Headers_08) / 3,$1f,$18 - db (SFX_08_54 - SFX_Headers_08) / 3,$0f,$80 - db (SFX_08_49 - SFX_Headers_08) / 3,$f8,$10 - db (SFX_08_48 - SFX_Headers_08) / 3,$18,$20 - db (SFX_08_72 - SFX_Headers_08) / 3,$08,$40 - db (SFX_08_57 - SFX_Headers_08) / 3,$01,$e0 - db (SFX_08_51 - SFX_Headers_08) / 3,$09,$ff - db (SFX_08_75 - SFX_Headers_08) / 3,$42,$01 - db (SFX_08_5c - SFX_Headers_08) / 3,$00,$ff - db (SFX_08_72 - SFX_Headers_08) / 3,$08,$e0 - db (SFX_08_64 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_49 - SFX_Headers_08) / 3,$88,$10 - db (SFX_08_65 - SFX_Headers_08) / 3,$48,$ff - db (SFX_08_48 - SFX_Headers_08) / 3,$ff,$ff - db (SFX_08_64 - SFX_Headers_08) / 3,$ff,$10 - db (SFX_08_48 - SFX_Headers_08) / 3,$ff,$04 - db (SFX_08_5c - SFX_Headers_08) / 3,$01,$ff - db (SFX_08_53 - SFX_Headers_08) / 3,$f8,$ff - db (SFX_08_4c - SFX_Headers_08) / 3,$f0,$f0 - db (SFX_08_4f - SFX_Headers_08) / 3,$08,$10 - db (SFX_08_4d - SFX_Headers_08) / 3,$f0,$ff - db (SFX_08_5a - SFX_Headers_08) / 3,$f0,$ff - db (SFX_08_74 - SFX_Headers_08) / 3,$10,$ff - db (SFX_08_4e - SFX_Headers_08) / 3,$f0,$20 - db (SFX_08_6b - SFX_Headers_08) / 3,$f0,$60 - db (SFX_08_61 - SFX_Headers_08) / 3,$12,$10 - db (SFX_08_76 - SFX_Headers_08) / 3,$f0,$20 - db (SFX_08_5e - SFX_Headers_08) / 3,$12,$ff - db (SFX_08_71 - SFX_Headers_08) / 3,$80,$04 - db (SFX_08_73 - SFX_Headers_08) / 3,$f0,$10 - db (SFX_08_69 - SFX_Headers_08) / 3,$f8,$ff - db (SFX_08_66 - SFX_Headers_08) / 3,$f0,$ff - db (SFX_08_51 - SFX_Headers_08) / 3,$01,$ff - db (SFX_08_6c - SFX_Headers_08) / 3,$d8,$04 - db (SFX_08_4b - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_4b - SFX_Headers_08) / 3,$00,$80 - -Func_79aae: ; 79aae (1e:5aae) + db SFX_POUND, $00,$80 ; POUND + db SFX_BATTLE_0C, $10,$80 ; KARATE_CHOP + db SFX_DOUBLESLAP, $00,$80 ; DOUBLESLAP + db SFX_BATTLE_0B, $01,$80 ; COMET_PUNCH + db SFX_BATTLE_0D, $00,$40 ; MEGA_PUNCH + db SFX_SILPH_SCOPE, $00,$ff ; PAY_DAY + db SFX_BATTLE_0D, $10,$60 ; FIRE_PUNCH + db SFX_BATTLE_0D, $20,$80 ; ICE_PUNCH + db SFX_BATTLE_0D, $00,$a0 ; THUNDERPUNCH + db SFX_DAMAGE, $00,$80 ; SCRATCH + db SFX_BATTLE_0F, $20,$40 ; VICEGRIP + db SFX_BATTLE_0F, $00,$80 ; GUILLOTINE + db SFX_BATTLE_0E, $00,$a0 ; RAZOR_WIND + db SFX_NOT_VERY_EFFECTIVE,$10,$c0 ; SWORDS_DANCE + db SFX_NOT_VERY_EFFECTIVE,$00,$a0 ; CUT + db SFX_BATTLE_12, $00,$c0 ; GUST + db SFX_BATTLE_12, $10,$a0 ; WING_ATTACK + db SFX_BATTLE_13, $00,$e0 ; WHIRLWIND + db SFX_NOT_VERY_EFFECTIVE,$20,$c0 ; FLY + db SFX_BATTLE_14, $00,$80 ; BIND + db SFX_BATTLE_22, $00,$80 ; SLAM + db SFX_VINE_WHIP, $01,$80 ; VINE_WHIP + db SFX_BATTLE_20, $00,$80 ; STOMP + db SFX_BATTLE_17, $f0,$40 ; DOUBLE_KICK + db SFX_SUPER_EFFECTIVE, $00,$80 ; MEGA_KICK + db SFX_BATTLE_17, $00,$80 ; JUMP_KICK + db SFX_BATTLE_21, $10,$80 ; ROLLING_KICK + db SFX_BATTLE_1B, $01,$a0 ; SAND_ATTACK + db SFX_BATTLE_18, $00,$80 ; HEADBUTT + db SFX_BATTLE_1E, $00,$60 ; HORN_ATTACK + db SFX_BATTLE_1E, $01,$40 ; FURY_ATTACK + db SFX_HORN_DRILL, $00,$a0 ; HORN_DRILL + db SFX_SUPER_EFFECTIVE, $10,$a0 ; TACKLE + db SFX_BATTLE_20, $00,$c0 ; BODY_SLAM + db SFX_BATTLE_14, $10,$60 ; WRAP + db SFX_SUPER_EFFECTIVE, $00,$a0 ; TAKE_DOWN + db SFX_BATTLE_22, $11,$c0 ; THRASH + db SFX_SUPER_EFFECTIVE, $20,$c0 ; DOUBLE_EDGE + db SFX_BATTLE_21, $00,$80 ; TAIL_WHIP + db SFX_BATTLE_1B, $00,$80 ; POISON_STING + db SFX_BATTLE_1B, $20,$c0 ; TWINEEDLE + db SFX_BATTLE_19, $00,$80 ; PIN_MISSILE + db SFX_BATTLE_31, $ff,$40 ; LEER + db SFX_BATTLE_1E, $00,$80 ; BITE + db SFX_BATTLE_0B, $00,$c0 ; GROWL + db SFX_BATTLE_0B, $00,$40 ; ROAR + db SFX_BATTLE_35, $00,$80 ; SING + db SFX_BATTLE_27, $40,$60 ; SUPERSONIC + db SFX_BATTLE_27, $00,$80 ; SONICBOOM + db SFX_BATTLE_27, $ff,$40 ; DISABLE + db SFX_BATTLE_2A, $80,$c0 ; ACID + db SFX_BATTLE_19, $10,$a0 ; EMBER + db SFX_BATTLE_19, $21,$e0 ; FLAMETHROWER + db SFX_BATTLE_29, $00,$80 ; MIST + db SFX_BATTLE_24, $20,$60 ; WATER_GUN + db SFX_BATTLE_2A, $00,$80 ; HYDRO_PUMP + db SFX_BATTLE_2C, $00,$80 ; SURF + db SFX_BATTLE_28, $40,$80 ; ICE_BEAM + db SFX_BATTLE_29, $f0,$e0 ; BLIZZARD + db SFX_PSYBEAM, $00,$80 ; PSYBEAM + db SFX_BATTLE_2A, $f0,$60 ; BUBBLEBEAM + db SFX_BATTLE_28, $00,$80 ; AURORA_BEAM + db SFX_BATTLE_36, $00,$80 ; HYPER_BEAM + db SFX_PECK,$01, $a0 ; PECK + db SFX_BATTLE_13, $f0,$20 ; DRILL_PECK + db SFX_BATTLE_23, $01,$c0 ; SUBMISSION + db SFX_BATTLE_23, $00,$80 ; LOW_KICK + db SFX_SUPER_EFFECTIVE, $00,$e0 ; COUNTER + db SFX_BATTLE_26, $01,$60 ; SEISMIC_TOSS + db SFX_BATTLE_26, $20,$40 ; STRENGTH + db SFX_BATTLE_24, $00,$80 ; ABSORB + db SFX_BATTLE_24, $40,$c0 ; MEGA_DRAIN + db SFX_BATTLE_1B, $03,$60 ; LEECH_SEED + db SFX_BATTLE_25, $11,$e0 ; GROWTH + db SFX_BATTLE_12, $20,$e0 ; RAZOR_LEAF + db SFX_BATTLE_2E, $00,$80 ; SOLARBEAM + db SFX_BATTLE_1C, $00,$80 ; POISONPOWDER + db SFX_BATTLE_1C, $11,$a0 ; STUN_SPORE + db SFX_BATTLE_1C, $01,$c0 ; SLEEP_POWDER + db SFX_BATTLE_13, $14,$c0 ; PETAL_DANCE + db SFX_BATTLE_1B, $02,$a0 ; STRING_SHOT + db SFX_BATTLE_29, $f0,$80 ; DRAGON_RAGE + db SFX_BATTLE_29, $20,$c0 ; FIRE_SPIN + db SFX_BATTLE_2F, $00,$20 ; THUNDERSHOCK + db SFX_BATTLE_2F, $20,$80 ; THUNDERBOLT + db SFX_BATTLE_2E, $12,$60 ; THUNDER_WAVE + db SFX_BATTLE_26, $00,$80 ; THUNDER + db SFX_BATTLE_14, $01,$e0 ; ROCK_THROW + db SFX_BATTLE_29, $0f,$e0 ; EARTHQUAKE + db SFX_BATTLE_29, $11,$20 ; FISSURE + db SFX_DAMAGE, $10,$40 ; DIG + db SFX_BATTLE_0F, $10,$c0 ; TOXIC + db SFX_BATTLE_14, $00,$20 ; CONFUSION + db SFX_PSYCHIC_M, $00,$80 ; PSYCHIC_M + db SFX_BATTLE_35, $11,$18 ; HYPNOSIS + db SFX_BATTLE_09, $20,$c0 ; MEDITATE + db SFX_FAINT_FALL, $20,$c0 ; AGILITY + db SFX_BATTLE_25, $00,$10 ; QUICK_ATTACK + db SFX_BATTLE_26, $f0,$20 ; RAGE + db SFX_BATTLE_33, $f0,$c0 ; TELEPORT + db SFX_NOT_VERY_EFFECTIVE,$f0,$e0 ; NIGHT_SHADE + db SFX_BATTLE_09, $f0,$40 ; MIMIC + db SFX_BATTLE_31, $00,$80 ; SCREECH + db SFX_BATTLE_33, $80,$40 ; DOUBLE_TEAM + db SFX_BATTLE_33, $00,$80 ; RECOVER + db SFX_BATTLE_14, $11,$20 ; HARDEN + db SFX_BATTLE_14, $22,$10 ; MINIMIZE + db SFX_BATTLE_1B, $f1,$ff ; SMOKESCREEN + db SFX_BATTLE_13, $f1,$ff ; CONFUSE_RAY + db SFX_BATTLE_14, $33,$30 ; WITHDRAW + db SFX_BATTLE_32, $40,$c0 ; DEFENSE_CURL + db SFX_BATTLE_0E, $20,$20 ; BARRIER + db SFX_BATTLE_0E, $f0,$10 ; LIGHT_SCREEN + db SFX_BATTLE_0F, $f8,$10 ; HAZE + db SFX_NOT_VERY_EFFECTIVE,$f0,$10 ; REFLECT + db SFX_BATTLE_25, $00,$80 ; FOCUS_ENERGY + db SFX_BATTLE_18, $00,$c0 ; BIDE + db SFX_BATTLE_32, $c0,$ff ; METRONOME + db SFX_BATTLE_09, $f2,$20 ; MIRROR_MOVE + db SFX_BATTLE_34, $00,$80 ; SELFDESTRUCT + db SFX_BATTLE_34, $00,$40 ; EGG_BOMB + db SFX_BATTLE_09, $00,$40 ; LICK + db SFX_NOT_VERY_EFFECTIVE,$10,$ff ; SMOG + db SFX_BATTLE_2A, $20,$20 ; SLUDGE + db SFX_BATTLE_32, $00,$80 ; BONE_CLUB + db SFX_BATTLE_29, $1f,$20 ; FIRE_BLAST + db SFX_BATTLE_25, $2f,$80 ; WATERFALL + db SFX_BATTLE_0F, $1f,$ff ; CLAMP + db SFX_BATTLE_2B, $1f,$60 ; SWIFT + db SFX_BATTLE_26, $1e,$20 ; SKULL_BASH + db SFX_BATTLE_26, $1f,$18 ; SPIKE_CANNON + db SFX_BATTLE_14, $0f,$80 ; CONSTRICT + db SFX_BATTLE_09, $f8,$10 ; AMNESIA + db SFX_FAINT_FALL, $18,$20 ; KINESIS + db SFX_BATTLE_32, $08,$40 ; SOFTBOILED + db SFX_BATTLE_17, $01,$e0 ; HI_JUMP_KICK + db SFX_NOT_VERY_EFFECTIVE,$09,$ff ; GLARE + db SFX_BATTLE_35, $42,$01 ; DREAM_EATER + db SFX_BATTLE_1C, $00,$ff ; POISON_GAS + db SFX_BATTLE_32, $08,$e0 ; BARRAGE + db SFX_BATTLE_24, $00,$80 ; LEECH_LIFE + db SFX_BATTLE_09, $88,$10 ; LOVELY_KISS + db SFX_BATTLE_25, $48,$ff ; SKY_ATTACK + db SFX_FAINT_FALL, $ff,$ff ; TRANSFORM + db SFX_BATTLE_24, $ff,$10 ; BUBBLE + db SFX_FAINT_FALL, $ff,$04 ; DIZZY_PUNCH + db SFX_BATTLE_1C, $01,$ff ; SPORE + db SFX_BATTLE_13, $f8,$ff ; FLASH + db SFX_BATTLE_0C, $f0,$f0 ; PSYWAVE + db SFX_BATTLE_0F, $08,$10 ; SPLASH + db SFX_BATTLE_0D, $f0,$ff ; ACID_ARMOR + db SFX_SUPER_EFFECTIVE, $f0,$ff ; CRABHAMMER + db SFX_BATTLE_34, $10,$ff ; EXPLOSION + db SFX_BATTLE_0E, $f0,$20 ; FURY_SWIPES + db SFX_BATTLE_2B, $f0,$60 ; BONEMERANG + db SFX_BATTLE_21, $12,$10 ; REST + db SFX_BATTLE_36, $f0,$20 ; ROCK_SLIDE + db SFX_BATTLE_1E, $12,$ff ; HYPER_FANG + db SFX_BATTLE_31, $80,$04 ; SHARPEN + db SFX_BATTLE_33, $f0,$10 ; CONVERSION + db SFX_BATTLE_29, $f8,$ff ; TRI_ATTACK + db SFX_BATTLE_26, $f0,$ff ; SUPER_FANG + db SFX_NOT_VERY_EFFECTIVE,$01,$ff ; SLASH + db SFX_BATTLE_2C, $d8,$04 ; SUBSTITUTE + db SFX_BATTLE_0B, $00,$80 ; STRUGGLE + db SFX_BATTLE_0B, $00,$80 + +CopyPicTiles: ; 79aae (1e:5aae) ld a, [H_WHOSETURN] and a ld a, $31 ; base tile ID of player mon sprite - jr z, .asm_79ab6 + jr z, .next ; enemy turn xor a ; base tile ID of enemy mon sprite -.asm_79ab6 +.next ld [hBaseTileID], a - jr asm_79acb + jr CopyTileIDs_NoBGTransfer -Func_79aba: ; 79aba (1e:5aba) +; copy the tiles used when a mon is being sent out of or into a pokeball +CopyDownscaledMonTiles: ; 79aba (1e:5aba) call GetPredefRegisters - ld a, [wcd6c] + ld a, [wDownscaledMonSize] and a - jr nz, .asm_79ac8 - ld de, Unknown_79b02 ; $5b02 - jr asm_79acb -.asm_79ac8 - ld de, Unknown_79b1b ; $5b1b -asm_79acb: ; 79acb (1e:5acb) + jr nz, .smallerSize + ld de, DownscaledMonTiles_5x5 + jr CopyTileIDs_NoBGTransfer +.smallerSize + ld de, DownscaledMonTiles_3x3 +; fall through + +CopyTileIDs_NoBGTransfer: ; 79acb (1e:5acb) xor a ld [H_AUTOBGTRANSFERENABLED], a +; fall through ; b = number of rows ; c = number of columns @@ -2557,14 +2598,14 @@ TileIDListPointerTable: ; 79aea (1e:5aea) dw Unknown_79c50 db $3C -Unknown_79b02: ; 79b02 (1e:5b02) +DownscaledMonTiles_5x5: ; 79b02 (1e:5b02) db $31,$38,$46,$54,$5B db $32,$39,$47,$55,$5C db $34,$3B,$49,$57,$5E db $36,$3D,$4B,$59,$60 db $37,$3E,$4C,$5A,$61 -Unknown_79b1b: ; 79b1b (1e:5b1b) +DownscaledMonTiles_3x3: ; 79b1b (1e:5b1b) db $31,$46,$5B db $34,$49,$5E db $37,$4C,$61 @@ -2635,130 +2676,135 @@ Unknown_79c50: ; 79c50 (1e:5c50) AnimationLeavesFalling: ; 79c74 (1e:5c74) ; Makes leaves float down from the top of the screen. This is used ; in Razor Leaf's animation. - ld a, [$ff48] + ld a, [rOBP0] push af - ld a, [wcc79] - ld [$ff48], a - ld d, $37 - ld a, $3 - ld [W_SUBANIMTRANSFORM], a - call Func_79c97 + ld a, [wAnimPalette] + ld [rOBP0], a + ld d, $37 ; leaf tile + ld a, 3 ; number of leaves + ld [wNumFallingObjects], a + call AnimationFallingObjects pop af - ld [$ff48], a + ld [rOBP0], a ret AnimationPetalsFalling: ; 79c8a (1e:5c8a) ; Makes lots of petals fall down from the top of the screen. It's used in ; the animation for Petal Dance. - ld d, $71 - ld a, $14 - ld [W_SUBANIMTRANSFORM], a - call Func_79c97 + ld d, $71 ; petal tile + ld a, 20 ; number of petals + ld [wNumFallingObjects], a + call AnimationFallingObjects jp ClearSprites -Func_79c97: ; 79c97 (1e:5c97) +AnimationFallingObjects: ; 79c97 (1e:5c97) ld c, a - ld a, $1 - call Func_797e8 - call Func_79d2a - call Func_79d52 + ld a, 1 + call InitMultipleObjectsOAM + call FallingObjects_InitXCoords + call FallingObjects_InitMovementData ld hl, wOAMBuffer - ld [hl], $0 -.asm_79ca8 - ld hl, wTrainerSpriteOffset - ld de, $0000 - ld a, [W_SUBANIMTRANSFORM] + ld [hl], 0 +.loop + ld hl, wFallingObjectsMovementData + ld de, 0 + ld a, [wNumFallingObjects] ld c, a -.asm_79cb2 +.innerLoop push bc push hl push de ld a, [hl] - ld [wd08a], a - call Func_79d16 - call Func_79cdb + ld [wFallingObjectMovementByte], a + call FallingObjects_UpdateMovementByte + call FallingObjects_UpdateOAMEntry pop de - ld hl, $0004 + ld hl, 4 add hl, de ld e, l ld d, h pop hl - ld a, [wd08a] + ld a, [wFallingObjectMovementByte] ld [hli], a pop bc dec c - jr nz, .asm_79cb2 + jr nz, .innerLoop call Delay3 ld hl, wOAMBuffer - ld a, [hl] - cp $68 - jr nz, .asm_79ca8 + ld a, [hl] ; Y + cp 104 ; has the top falling object reached 104 yet? + jr nz, .loop ; keep moving the falling objects down until it does ret -Func_79cdb: ; 79cdb (1e:5cdb) +FallingObjects_UpdateOAMEntry: ; 79cdb (1e:5cdb) +; Increases Y by 2 pixels and adjusts X and X flip based on the falling object's +; movement byte. ld hl, wOAMBuffer add hl, de ld a, [hl] inc a inc a - cp $70 - jr c, .asm_79ce8 - ld a, $a0 -.asm_79ce8 - ld [hli], a - ld a, [wd08a] + cp 112 + jr c, .next + ld a, 160 ; if Y >= 112, put it off-screen +.next + ld [hli], a ; Y + ld a, [wFallingObjectMovementByte] ld b, a - ld de, Unknown_79d0d + ld de, FallingObjects_DeltaXs and $7f add e - jr nc, .asm_79cf6 + jr nc, .noCarry inc d -.asm_79cf6 +.noCarry ld e, a ld a, b and $80 - jr nz, .asm_79d03 + jr nz, .movingLeft +; moving right ld a, [de] add [hl] - ld [hli], a + ld [hli], a ; X inc hl - xor a - jr .asm_79d0b -.asm_79d03 + xor a ; no horizontal flip + jr .next2 +.movingLeft ld a, [de] ld b, a ld a, [hl] sub b - ld [hli], a + ld [hli], a ; X inc hl - ld a, $20 -.asm_79d0b - ld [hl], a + ld a, (1 << OAM_X_FLIP) +.next2 + ld [hl], a ; attribute ret -Unknown_79d0d: ; 79d0d (1e:5d0d) - db $00,$01,$03,$05,$07,$09,$0B,$0D,$0F +FallingObjects_DeltaXs: ; 79d0d (1e:5d0d) + db 0, 1, 3, 5, 7, 9, 11, 13, 15 -Func_79d16: ; 79d16 (1e:5d16) - ld a, [wd08a] +FallingObjects_UpdateMovementByte: ; 79d16 (1e:5d16) + ld a, [wFallingObjectMovementByte] inc a ld b, a and $7f - cp $9 + cp 9 ; have we reached the end of the delta-Xs? ld a, b - jr nz, .asm_79d26 + jr nz, .next +; We've reached the end of the delta-Xs, so wrap to the start and change +; direction from right to left or vice versa. and $80 xor $80 -.asm_79d26 - ld [wd08a], a +.next + ld [wFallingObjectMovementByte], a ret -Func_79d2a: ; 79d2a (1e:5d2a) +FallingObjects_InitXCoords: ; 79d2a (1e:5d2a) ld hl, wOAMBuffer + $01 - ld de, Unknown_79d3e - ld a, [W_SUBANIMTRANSFORM] + ld de, FallingObjects_InitialXCoords + ld a, [wNumFallingObjects] ld c, a -.asm_79d34 +.loop ld a, [de] ld [hli], a inc hl @@ -2766,66 +2812,98 @@ Func_79d2a: ; 79d2a (1e:5d2a) inc hl inc de dec c - jr nz, .asm_79d34 + jr nz, .loop ret -Unknown_79d3e: ; 79d3e (1e:5d3e) +FallingObjects_InitialXCoords: ; 79d3e (1e:5d3e) db $38,$40,$50,$60,$70,$88,$90,$56,$67,$4A,$77,$84,$98,$32,$22,$5C,$6C,$7D,$8E,$99 -Func_79d52: ; 79d52 (1e:5d52) - ld hl, wTrainerSpriteOffset - ld de, Unknown_79d63 - ld a, [W_SUBANIMTRANSFORM] +FallingObjects_InitMovementData: ; 79d52 (1e:5d52) + ld hl, wFallingObjectsMovementData + ld de, FallingObjects_InitialMovementData + ld a, [wNumFallingObjects] ld c, a -.asm_79d5c +.loop ld a, [de] ld [hli], a inc de dec c - jr nz, .asm_79d5c + jr nz, .loop ret -Unknown_79d63: ; 79d63 (1e:5d63) +FallingObjects_InitialMovementData: ; 79d63 (1e:5d63) db $00,$84,$06,$81,$02,$88,$01,$83,$05,$89,$09,$80,$07,$87,$03,$82,$04,$85,$08,$86 AnimationShakeEnemyHUD: ; 79d77 (1e:5d77) +; Shakes the enemy HUD. + +; Make a copy of the back pic's tile patterns in sprite tile pattern VRAM. ld de, vBackPic ld hl, vSprites ld bc, 7 * 7 call CopyVideoData + xor a ld [hSCX], a + +; Copy wTileMap to BG map 0. The regular BG (not the window) is set to use +; map 0 and can be scrolled with SCX, which allows a shaking effect. ld hl, vBGMap0 - call Func_79e0d - ld a, $90 + call BattleAnimCopyTileMapToVRAM + +; Now that the regular BG is showing the same thing the window was, move the +; window off the screen so that we can modify its contents below. + ld a, SCREEN_HEIGHT_PIXELS ld [hWY], a - ld hl, vBGMap0 + $320 - call Func_79e0d - ld a, $38 + +; Copy wTileMap to VRAM such that the row below the enemy HUD (in wTileMap) is +; lined up with row 0 of the window. + ld hl, vBGMap1 - $20 * 7 + call BattleAnimCopyTileMapToVRAM + +; Move the window so that the row below the enemy HUD (in BG map 0) lines up +; with the top row of the window on the screen. This makes it so that the window +; covers everything below the enemy HD with a copy that looks just like what +; was there before. + ld a, 7 * 8 ld [hWY], a - call Func_792fd + +; Write OAM entries so that the copy of the back pic from the top of this +; function shows up on screen. We need this because the back pic's Y coordinates +; range overlaps with that of the enemy HUD and we don't want to shake the top +; of the back pic when we shake the enemy HUD. The OAM copy won't be affected +; by SCX. + call ShakeEnemyHUD_WritePlayerMonPicOAM + ld hl, vBGMap0 - call Func_79e0d + call BattleAnimCopyTileMapToVRAM + +; Remove the back pic from the BG map. call AnimationHideMonPic call Delay3 - ld de, $0208 - call Func_79de9 + +; Use SCX to shake the regular BG. The window and the back pic OAM copy are +; not affected. + lb de, 2, 8 + call ShakeEnemyHUD_ShakeBG + +; Restore the original graphics. call AnimationShowMonPic call ClearSprites - ld a, $90 + ld a, SCREEN_HEIGHT_PIXELS ld [hWY], a ld hl, vBGMap1 - call Func_79e0d + call BattleAnimCopyTileMapToVRAM xor a ld [hWY], a call SaveScreenTilesToBuffer1 ld hl, vBGMap0 - call Func_79e0d + call BattleAnimCopyTileMapToVRAM call ClearScreen call Delay3 call LoadScreenTilesFromBuffer1 ld hl, vBGMap1 - jp Func_79e0d + jp BattleAnimCopyTileMapToVRAM ; b = tile ID list index ; c = base tile ID @@ -2839,29 +2917,29 @@ CopyTileIDsFromList: ; 79dda (1e:5dda) pop hl jp CopyTileIDs -Func_79de9: ; 79de9 (1e:5de9) +ShakeEnemyHUD_ShakeBG: ; 79de9 (1e:5de9) ld a, [hSCX] - ld [wTrainerSpriteOffset], a -.asm_79dee - ld a, [wTrainerSpriteOffset] + ld [wTempSCX], a +.loop + ld a, [wTempSCX] add d ld [hSCX], a - ld c, $2 + ld c, 2 call DelayFrames - ld a, [wTrainerSpriteOffset] + ld a, [wTempSCX] sub d ld [hSCX], a - ld c, $2 + ld c, 2 call DelayFrames dec e - jr nz, .asm_79dee - ld a, [wTrainerSpriteOffset] + jr nz, .loop + ld a, [wTempSCX] ld [hSCX], a ret -Func_79e0d: ; 79e0d (1e:5e0d) +BattleAnimCopyTileMapToVRAM: ; 79e0d (1e:5e0d) ld a, h - ld [$ffbd], a + ld [H_AUTOBGTRANSFERDEST + 1], a ld a, l ld [H_AUTOBGTRANSFERDEST], a jp Delay3 @@ -2870,7 +2948,7 @@ TossBallAnimation: ; 79e16 (1e:5e16) ld a,[W_ISINBATTLE] cp a,2 jr z,.BlockBall ; if in trainer battle, play different animation - ld a,[wd11e] + ld a,[wPokeBallAnimData] ld b,a ; upper nybble: how many animations (from PokeBallAnimations) to play @@ -2883,7 +2961,7 @@ TossBallAnimation: ; 79e16 (1e:5e16) ; store these for later ld a,b and a,$F - ld [wWhichTrade],a + ld [wNumShakes],a ld hl,.PokeBallAnimations ; choose which toss animation to use @@ -2917,8 +2995,8 @@ TossBallAnimation: ; 79e16 (1e:5e16) ld a,TOSS_ANIM ld [W_ANIMATIONID],a call PlayAnimation - ld a,(SFX_08_43 - SFX_Headers_08) / 3 - call PlaySound ; play sound effect + ld a,SFX_FAINT_THUD + call PlaySound ld a,BLOCKBALL_ANIM ld [W_ANIMATIONID],a jp PlayAnimation @@ -2930,21 +3008,21 @@ PlayApplyingAttackSound: ; 79e6a (1e:5e6a) ld a, [wDamageMultipliers] and $7f ret z - cp $a + cp 10 ld a, $20 ld b, $30 - ld c, (SFX_08_50 - SFX_Headers_08) / 3 - jr z, .asm_79e8b + ld c, SFX_DAMAGE + jr z, .playSound ld a, $e0 ld b, $ff - ld c, (SFX_08_5a - SFX_Headers_08) / 3 - jr nc, .asm_79e8b + ld c, SFX_SUPER_EFFECTIVE + jr nc, .playSound ld a, $50 ld b, $1 - ld c, (SFX_08_51 - SFX_Headers_08) / 3 -.asm_79e8b - ld [wc0f1], a + ld c, SFX_NOT_VERY_EFFECTIVE +.playSound + ld [wFrequencyModifier], a ld a, b - ld [wc0f2], a + ld [wTempoModifier], a ld a, c jp PlaySound diff --git a/engine/battle/bank_e_misc.asm b/engine/battle/bank_e_misc.asm index 6ef4065f..dc766f23 100755 --- a/engine/battle/bank_e_misc.asm +++ b/engine/battle/bank_e_misc.asm @@ -24,7 +24,7 @@ FormatMovesString: ; 39b87 (e:5b87) jr .copyNameLoop .doneCopyingName ld a, b - ld [wcd6c], a + ld [wNumMovesMinusOne], a inc b ld a, $4e ; line break ld [de], a @@ -52,49 +52,49 @@ FormatMovesString: ; 39b87 (e:5b87) ret ; XXX this is called in a few places, but it doesn't appear to do anything useful -Func_39bd5: ; 39bd5 (e:5bd5) - ld a, [wd11b] - cp $1 - jr nz, .asm_39be6 +InitList: ; 39bd5 (e:5bd5) + ld a, [wInitListType] + cp INIT_ENEMYOT_LIST + jr nz, .notEnemy ld hl, wEnemyPartyCount ld de, wEnemyMonOT ld a, ENEMYOT_NAME - jr .asm_39c18 -.asm_39be6 - cp $4 - jr nz, .calcAttackStat4 + jr .done +.notEnemy + cp INIT_PLAYEROT_LIST + jr nz, .notPlayer ld hl, wPartyCount ld de, wPartyMonOT ld a, PLAYEROT_NAME - jr .asm_39c18 -.calcAttackStat4 - cp $5 - jr nz, .asm_39c02 - ld hl, wStringBuffer2 + 11 + jr .done +.notPlayer + cp INIT_MON_LIST + jr nz, .notMonster + ld hl, wItemList ld de, MonsterNames ld a, MONSTER_NAME - jr .asm_39c18 -.asm_39c02 - cp $2 - jr nz, .asm_39c10 + jr .done +.notMonster + cp INIT_BAG_ITEM_LIST + jr nz, .notBag ld hl, wNumBagItems ld de, ItemNames ld a, ITEM_NAME - jr .asm_39c18 -.asm_39c10 - ld hl, wStringBuffer2 + 11 + jr .done +.notBag + ld hl, wItemList ld de, ItemNames ld a, ITEM_NAME -.asm_39c18 +.done ld [wNameListType], a ld a, l - ld [wList], a + ld [wListPointer], a ld a, h - ld [wList + 1], a + ld [wListPointer + 1], a ld a, e - ld [wcf8d], a + ld [wUnusedCF8D], a ld a, d - ld [wcf8e], a + ld [wUnusedCF8D + 1], a ld bc, ItemPrices ld a, c ld [wItemPrices], a @@ -102,10 +102,10 @@ Func_39bd5: ; 39bd5 (e:5bd5) ld [wItemPrices + 1], a ret -; get species of mon e in list [wcc49] for LoadMonData +; get species of mon e in list [wMonDataLocation] for LoadMonData GetMonSpecies: ; 39c37 (e:5c37) ld hl, wPartySpecies - ld a, [wcc49] + ld a, [wMonDataLocation] and a jr z, .getSpecies dec a diff --git a/engine/battle/battle_transitions.asm b/engine/battle/battle_transitions.asm index 4a9ea782..f5af6826 100644 --- a/engine/battle/battle_transitions.asm +++ b/engine/battle/battle_transitions.asm @@ -7,10 +7,13 @@ BattleTransition: ; 709d7 (1c:49d7) dec a ld [wUpdateSpritesEnabled], a call DelayFrame + +; Determine which OAM block is being used by the enemy trainer sprite (if there +; is one). ld hl, wSpriteStateData1 + 2 - ld a, [H_DOWNARROWBLINKCNT2] + ld a, [hSpriteIndexOrTextID] ; enemy trainer sprite index (0 if wild battle) ld c, a - ld b, $0 + ld b, 0 ld de, $10 .loop1 ld a, [hl] @@ -21,13 +24,15 @@ BattleTransition: ; 709d7 (1c:49d7) add hl, de dec c jr nz, .loop1 + +; Clear OAM except for the blocks used by the player and enemy trainer sprites. ld hl, wOAMBuffer + $10 - ld c, $9 + ld c, 9 .loop2 ld a, b swap a cp l - jr z, .skip2 + jr z, .skip2 ; skip clearing the block if the enemy trainer is using it push hl push bc ld bc, $10 @@ -40,9 +45,10 @@ BattleTransition: ; 709d7 (1c:49d7) add hl, de dec c jr nz, .loop2 + call Delay3 call LoadBattleTransitionTile - ld bc, $0 + ld bc, 0 ld a, [wLinkState] cp LINK_STATE_BATTLING jr z, .linkBattle @@ -76,7 +82,7 @@ BattleTransitions: ; 70a3c (1c:4a3c) GetBattleTransitionID_WildOrTrainer: ; 70a4c (1c:4a4c) ld a, [W_CUROPPONENT] - cp $c8 + cp 200 jr nc, .trainer res 0, c ret @@ -103,13 +109,13 @@ GetBattleTransitionID_CompareLevels: ; 70a59 (1c:4a59) sub e jr nc, .highLevelEnemy res 1, c - ld a, $1 - ld [wcd47], a + ld a, 1 + ld [wBattleTransitionSpiralDirection], a ret .highLevelEnemy set 1, c xor a - ld [wcd47], a + ld [wBattleTransitionSpiralDirection], a ret ; fails to recognize VICTORY_ROAD_2, VICTORY_ROAD_3, all ROCKET_HIDEOUT maps, @@ -178,11 +184,12 @@ DungeonMaps2: ; 70aac (1c:4aac) LoadBattleTransitionTile: ; 70ab7 (1c:4ab7) ld hl, vChars1 + $7f0 ld de, BattleTransitionTile - ld bc, (BANK(BattleTransitionTile) << 8) + $01 + lb bc, BANK(BattleTransitionTile), (BattleTransitionTileEnd - BattleTransitionTile) / $10 jp CopyVideoData BattleTransitionTile: ; 70ac3 (1c:4ac3) INCBIN "gfx/battle_transition.2bpp" +BattleTransitionTileEnd: BattleTransition_BlackScreen: ; 70ad3 (1c:4ad3) ld a, $ff @@ -199,57 +206,57 @@ BattleTransition_BlackScreen: ; 70ad3 (1c:4ad3) ; outward spiral if enemy is at least 3 levels ; higher than player and does an inward spiral otherwise BattleTransition_Spiral: ; 70ae5 (1c:4ae5) - ld a, [wcd47] + ld a, [wBattleTransitionSpiralDirection] and a jr z, .outwardSpiral call BattleTransition_InwardSpiral jr .done .outwardSpiral - hlCoord 10, 10 + coord hl, 10, 10 ld a, $3 - ld [wd09f], a + ld [wOutwardSpiralCurrentDirection], a ld a, l - ld [wd09b], a + ld [wOutwardSpiralTileMapPointer + 1], a ld a, h - ld [wd09a], a - ld b, $78 -.loop1 - ld c, $3 -.loop2 + ld [wOutwardSpiralTileMapPointer], a + ld b, 120 +.loop + ld c, 3 +.innerLoop push bc call BattleTransition_OutwardSpiral_ pop bc dec c - jr nz, .loop2 + jr nz, .innerLoop call DelayFrame dec b - jr nz, .loop1 + jr nz, .loop .done call BattleTransition_BlackScreen xor a - ld [wd09b], a - ld [wd09a], a + ld [wOutwardSpiralTileMapPointer + 1], a + ld [wOutwardSpiralTileMapPointer], a ret BattleTransition_InwardSpiral: ; 70b1d (1c:4b1d) - ld a, $7 - ld [wWhichTrade], a - ld hl, wTileMap - ld c, $11 - ld de, $14 + ld a, 7 + ld [wInwardSpiralUpdateScreenCounter], a + coord hl, 0, 0 + ld c, SCREEN_HEIGHT - 1 + ld de, SCREEN_WIDTH call BattleTransition_InwardSpiral_ inc c jr .skip .loop - ld de, $14 + ld de, SCREEN_WIDTH call BattleTransition_InwardSpiral_ .skip inc c - ld de, $1 + ld de, 1 call BattleTransition_InwardSpiral_ dec c dec c - ld de, -$14 + ld de, -SCREEN_WIDTH call BattleTransition_InwardSpiral_ inc c ld de, -1 @@ -267,13 +274,13 @@ BattleTransition_InwardSpiral_: ; 70b53 (1c:4b53) ld [hl], $ff add hl, de push bc - ld a, [wWhichTrade] + ld a, [wInwardSpiralUpdateScreenCounter] dec a jr nz, .skip call BattleTransition_TransferDelay3 - ld a, $7 + ld a, 7 .skip - ld [wWhichTrade], a + ld [wInwardSpiralUpdateScreenCounter], a pop bc dec c jr nz, .loop @@ -281,71 +288,71 @@ BattleTransition_InwardSpiral_: ; 70b53 (1c:4b53) ret BattleTransition_OutwardSpiral_: ; 70b6c (1c:4b6c) - ld bc, -$14 - ld de, $14 - ld a, [wd09b] + ld bc, -SCREEN_WIDTH + ld de, SCREEN_WIDTH + ld a, [wOutwardSpiralTileMapPointer + 1] ld l, a - ld a, [wd09a] + ld a, [wOutwardSpiralTileMapPointer] ld h, a - ld a, [wd09f] + ld a, [wOutwardSpiralCurrentDirection] cp $0 - jr z, .zero + jr z, .up cp $1 - jr z, .one + jr z, .left cp $2 - jr z, .two + jr z, .down cp $3 - jr z, .three -.done1 + jr z, .right +.keepSameDirection ld [hl], $ff -.done2_ +.done ld a, l - ld [wd09b], a + ld [wOutwardSpiralTileMapPointer + 1], a ld a, h - ld [wd09a], a + ld [wOutwardSpiralTileMapPointer], a ret -.zero +.up dec hl ld a, [hl] cp $ff - jr nz, .done2 + jr nz, .changeDirection inc hl add hl, bc - jr .done1 -.one + jr .keepSameDirection +.left add hl, de ld a, [hl] cp $ff - jr nz, .done2 + jr nz, .changeDirection add hl, bc dec hl - jr .done1 -.two + jr .keepSameDirection +.down inc hl ld a, [hl] cp $ff - jr nz, .done2 + jr nz, .changeDirection dec hl add hl, de - jr .done1 -.three + jr .keepSameDirection +.right add hl, bc ld a, [hl] cp $ff - jr nz, .done2 + jr nz, .changeDirection add hl, de inc hl - jr .done1 -.done2 + jr .keepSameDirection +.changeDirection ld [hl], $ff - ld a, [wd09f] + ld a, [wOutwardSpiralCurrentDirection] inc a cp $4 jr nz, .skip xor a .skip - ld [wd09f], a - jr .done2_ + ld [wOutwardSpiralCurrentDirection], a + jr .done FlashScreen: BattleTransition_FlashScreen_: ; 70be8 (1c:4be8s) @@ -370,60 +377,58 @@ BattleTransition_FlashScreenPalettes: ; 70be8 (1c:4be8) ; used for low level trainer dungeon battles BattleTransition_Shrink: ; 70bf4 (1c:4bf4) - ld c, $9 .loop push bc xor a ld [H_AUTOBGTRANSFERENABLED], a - hlCoord 0, 7 - deCoord 0, 8 - ld bc, -$28 + coord hl, 0, 7 + coord de, 0, 8 + ld bc, -SCREEN_WIDTH * 2 call BattleTransition_CopyTiles1 - hlCoord 0, 10 - deCoord 0, 9 - ld bc, $28 + coord hl, 0, 10 + coord de, 0, 9 + ld bc, SCREEN_WIDTH * 2 call BattleTransition_CopyTiles1 - hlCoord 8, 0 - deCoord 9, 0 - ld bc, -$2 + coord hl, 8, 0 + coord de, 9, 0 + ld bc, -2 call BattleTransition_CopyTiles2 - hlCoord 11, 0 - deCoord 10, 0 - ld bc, $2 + coord hl, 11, 0 + coord de, 10, 0 + ld bc, 2 call BattleTransition_CopyTiles2 ld a, $1 ld [H_AUTOBGTRANSFERENABLED], a - ld c, $6 + ld c, 6 call DelayFrames pop bc dec c jr nz, .loop call BattleTransition_BlackScreen - ld c, $a + ld c, 10 jp DelayFrames ; used for high level trainer dungeon battles BattleTransition_Split: ; 70c40 (1c:4c40) - ld c, $9 xor a ld [H_AUTOBGTRANSFERENABLED], a .loop push bc - hlCoord 0, 16 - deCoord 0, 17 - ld bc, -$28 + coord hl, 0, 16 + coord de, 0, 17 + ld bc, -SCREEN_WIDTH * 2 call BattleTransition_CopyTiles1 - hlCoord 0, 1 - ld de, wTileMap - ld bc, $28 + coord hl, 0, 1 + coord de, 0, 0 + ld bc, SCREEN_WIDTH * 2 call BattleTransition_CopyTiles1 - hlCoord 18, 0 - deCoord 19, 0 - ld bc, -$2 + coord hl, 18, 0 + coord de, 19, 0 + ld bc, -2 call BattleTransition_CopyTiles2 - hlCoord 1, 0 - ld de, wTileMap - ld bc, $2 + coord hl, 1, 0 + coord de, 0, 0 + ld bc, 2 call BattleTransition_CopyTiles2 call BattleTransition_TransferDelay3 call Delay3 @@ -431,26 +436,26 @@ BattleTransition_Split: ; 70c40 (1c:4c40) dec c jr nz, .loop call BattleTransition_BlackScreen - ld c, $a + ld c, 10 jp DelayFrames BattleTransition_CopyTiles1: ; 70c88 (1c:4c88) ld a, c - ld [wWhichTrade], a + ld [wBattleTransitionCopyTilesOffset], a ld a, b - ld [wTrainerEngageDistance], a - ld c, $8 + ld [wBattleTransitionCopyTilesOffset + 1], a + ld c, 8 .loop1 push bc push hl push de - ld bc, $14 + ld bc, SCREEN_WIDTH call CopyData pop hl pop de - ld a, [wWhichTrade] + ld a, [wBattleTransitionCopyTilesOffset] ld c, a - ld a, [wTrainerEngageDistance] + ld a, [wBattleTransitionCopyTilesOffset + 1] ld b, a add hl, bc pop bc @@ -459,7 +464,7 @@ BattleTransition_CopyTiles1: ; 70c88 (1c:4c88) ld l, e ld h, d ld a, $ff - ld c, $14 + ld c, SCREEN_WIDTH .loop2 ld [hli], a dec c @@ -468,26 +473,26 @@ BattleTransition_CopyTiles1: ; 70c88 (1c:4c88) BattleTransition_CopyTiles2: ; 70cb5 (1c:4c3f) ld a, c - ld [wWhichTrade], a + ld [wBattleTransitionCopyTilesOffset], a ld a, b - ld [wTrainerEngageDistance], a - ld c, $9 + ld [wBattleTransitionCopyTilesOffset + 1], a + ld c, SCREEN_HEIGHT / 2 .loop1 push bc push hl push de - ld c, $12 + ld c, SCREEN_HEIGHT .loop2 ld a, [hl] ld [de], a ld a, e - add $14 + add SCREEN_WIDTH jr nc, .noCarry1 inc d .noCarry1 ld e, a ld a, l - add $14 + add SCREEN_WIDTH jr nc, .noCarry2 inc h .noCarry2 @@ -496,9 +501,9 @@ BattleTransition_CopyTiles2: ; 70cb5 (1c:4c3f) jr nz, .loop2 pop hl pop de - ld a, [wWhichTrade] + ld a, [wBattleTransitionCopyTilesOffset] ld c, a - ld a, [wTrainerEngageDistance] + ld a, [wBattleTransitionCopyTilesOffset + 1] ld b, a add hl, bc pop bc @@ -506,8 +511,8 @@ BattleTransition_CopyTiles2: ; 70cb5 (1c:4c3f) jr nz, .loop1 ld l, e ld h, d - ld de, $14 - ld c, $12 + ld de, SCREEN_WIDTH + ld c, SCREEN_HEIGHT .loop3 ld [hl], $ff add hl, de @@ -517,9 +522,9 @@ BattleTransition_CopyTiles2: ; 70cb5 (1c:4c3f) ; used for high level wild dungeon battles BattleTransition_VerticalStripes: ; 70cf4 (1c:4cf4) - ld c, $12 - ld hl, wTileMap - deCoord 1, 17 + ld c, SCREEN_HEIGHT + coord hl, 0, 0 + coord de, 1, 17 xor a ld [H_AUTOBGTRANSFERENABLED], a .loop @@ -532,12 +537,12 @@ BattleTransition_VerticalStripes: ; 70cf4 (1c:4cf4) call BattleTransition_VerticalStripes_ call BattleTransition_TransferDelay3 pop hl - ld bc, $ffec + ld bc, -SCREEN_WIDTH add hl, bc ld e, l ld d, h pop hl - ld bc, $14 + ld bc, SCREEN_WIDTH add hl, bc pop bc dec c @@ -545,7 +550,7 @@ BattleTransition_VerticalStripes: ; 70cf4 (1c:4cf4) jp BattleTransition_BlackScreen BattleTransition_VerticalStripes_: ; 70d20 (1c:4d20) - ld c, $a + ld c, SCREEN_WIDTH / 2 .loop ld [hl], $ff inc hl @@ -556,9 +561,9 @@ BattleTransition_VerticalStripes_: ; 70d20 (1c:4d20) ; used for low level wild dungeon battles BattleTransition_HorizontalStripes: ; 70d2a (1c:4d2a) - ld c, $14 - ld hl, wTileMap - deCoord 19, 1 + ld c, SCREEN_WIDTH + coord hl, 0, 0 + coord de, 19, 1 xor a ld [H_AUTOBGTRANSFERENABLED], a .loop @@ -580,8 +585,8 @@ BattleTransition_HorizontalStripes: ; 70d2a (1c:4d2a) jp BattleTransition_BlackScreen BattleTransition_HorizontalStripes_: ; 70d4e (1c:4d4e) - ld c, $9 - ld de, $28 + ld c, SCREEN_HEIGHT / 2 + ld de, SCREEN_WIDTH * 2 .loop ld [hl], $ff add hl, de @@ -594,11 +599,11 @@ BattleTransition_HorizontalStripes_: ; 70d4e (1c:4d4e) ; by animating each half circle one at a time BattleTransition_Circle: ; 70d5a (1c:4d5a) call BattleTransition_FlashScreen - ld bc, $000a + lb bc, 0, SCREEN_WIDTH / 2 ld hl, BattleTransition_HalfCircle1 call BattleTransition_Circle_Sub1 - ld c, $a - ld b, $1 + ld c, SCREEN_WIDTH / 2 + ld b, 1 ld hl, BattleTransition_HalfCircle2 call BattleTransition_Circle_Sub1 jp BattleTransition_BlackScreen @@ -616,7 +621,7 @@ BattleTransition_Circle_Sub1: ; 70d7c (1c:4d7c) ld a, b call BattleTransition_Circle_Sub2 pop hl - ld bc, $0005 + ld bc, 5 add hl, bc call BattleTransition_TransferDelay3 pop bc @@ -637,7 +642,7 @@ BattleTransition_TransferDelay3: ; 70d8f (1c:4d8f) ; by animating both half circles at the same time BattleTransition_DoubleCircle: ; 70d9a (1c:4d9a) call BattleTransition_FlashScreen - ld c, $a + ld c, SCREEN_WIDTH / 2 ld hl, BattleTransition_HalfCircle1 ld de, BattleTransition_HalfCircle2 .loop @@ -651,7 +656,7 @@ BattleTransition_DoubleCircle: ; 70d9a (1c:4d9a) ld a, $1 call BattleTransition_Circle_Sub2 pop hl - ld bc, $5 + ld bc, 5 add hl, bc ld e, l ld d, h @@ -664,9 +669,9 @@ BattleTransition_DoubleCircle: ; 70d9a (1c:4d9a) jp BattleTransition_BlackScreen BattleTransition_Circle_Sub2: ; 70dc6 (1c:4dc6) - ld [wWhichTrade], a + ld [wBattleTransitionCircleScreenQuadrantY], a ld a, [hli] - ld [wTrainerEngageDistance], a + ld [wBattleTransitionCircleScreenQuadrantX], a ld a, [hli] ld e, a ld a, [hli] @@ -765,7 +770,7 @@ BattleTransition_Circle_Sub3: ; 70e3b (1c:4e3b) inc de .loop1 ld [hl], $ff - ld a, [wTrainerEngageDistance] + ld a, [wBattleTransitionCircleScreenQuadrantX] and a jr z, .skip1 inc hl @@ -776,11 +781,11 @@ BattleTransition_Circle_Sub3: ; 70e3b (1c:4e3b) dec c jr nz, .loop1 pop hl - ld a, [wWhichTrade] + ld a, [wBattleTransitionCircleScreenQuadrantY] and a - ld bc, $14 + ld bc, SCREEN_WIDTH jr z, .skip3 - ld bc, $ffec + ld bc, -SCREEN_WIDTH .skip3 add hl, bc ld a, [de] @@ -791,7 +796,7 @@ BattleTransition_Circle_Sub3: ; 70e3b (1c:4e3b) jr z, BattleTransition_Circle_Sub3 ld c, a .loop2 - ld a, [wTrainerEngageDistance] + ld a, [wBattleTransitionCircleScreenQuadrantX] and a jr z, .skip4 dec hl diff --git a/engine/battle/common_text.asm b/engine/battle/common_text.asm index 5d427e97..e3c7e1fa 100644 --- a/engine/battle/common_text.asm +++ b/engine/battle/common_text.asm @@ -2,7 +2,7 @@ PrintBeginningBattleText: ; f4000 (3d:4000) ld a, [W_ISINBATTLE] ; W_ISINBATTLE dec a jr nz, .trainerBattle - ld a, [W_CURMAP] ; W_CURMAP + ld a, [W_CURMAP] cp POKEMONTOWER_3 jr c, .notPokemonTower cp LAVENDER_HOUSE_1 @@ -23,7 +23,7 @@ PrintBeginningBattleText: ; f4000 (3d:4000) call PlayCry .continue ld hl, WildMonAppearedText - ld a, [W_MOVEMISSED] ; W_MOVEMISSED + ld a, [W_MOVEMISSED] and a jr z, .notFishing ld hl, HookedMonAttackedText @@ -31,7 +31,7 @@ PrintBeginningBattleText: ; f4000 (3d:4000) jr .wildBattle .trainerBattle call .playSFX - ld c, $14 + ld c, 20 call DelayFrames ld hl, TrainerWantsToFightText .wildBattle @@ -77,7 +77,7 @@ PrintBeginningBattleText: ; f4000 (3d:4000) .playSFX xor a - ld [wc0f1], a + ld [wFrequencyModifier], a ld a, $80 ld [wc0f2], a ld a, $e9 ; (SFX_08_77 - SFX_Headers_08) / 3 @@ -120,10 +120,10 @@ PrintSendOutMonMessage: ; f40e0 (3d:40e5) ld [H_MULTIPLICAND], a ld hl, wEnemyMonHP ld a, [hli] - ld [wcce3], a + ld [wLastSwitchInEnemyMonHP], a ld [H_MULTIPLICAND + 1], a ld a, [hl] - ld [wcce4], a + ld [wLastSwitchInEnemyMonHP + 1], a ld [H_MULTIPLICAND + 2], a ld a, 25 ld [H_MULTIPLIER], a @@ -136,7 +136,7 @@ PrintSendOutMonMessage: ; f40e0 (3d:40e5) srl a rr b ld a, b - ld b, $4 + ld b, 4 ld [H_DIVISOR], a ; enemy mon max HP divided by 4 call Divide ld a, [H_QUOTIENT + 3] ; a = (enemy mon current HP * 25) / (enemy max HP / 4); this approximates the current percentage of max HP @@ -155,22 +155,22 @@ PrintSendOutMonMessage: ; f40e0 (3d:40e5) GoText: ; f413a (3d:413a) TX_FAR _GoText - db $08 ; asm + TX_ASM jr PrintPlayerMon1Text DoItText: ; f4141 (3d:4141) TX_FAR _DoItText - db $08 ; asm + TX_ASM jr PrintPlayerMon1Text GetmText: ; f4148 (3d:4148) TX_FAR _GetmText - db $08 ; asm + TX_ASM jr PrintPlayerMon1Text EnemysWeakText: ; f414f (3d:414f) TX_FAR _EnemysWeakText - db $08 ; asm + TX_ASM PrintPlayerMon1Text: ; f4154 (3d:4154) ld hl, PlayerMon1Text @@ -186,23 +186,23 @@ RetreatMon: ; f415d (3d:415d) PlayerMon2Text: ; f4163 (3d:4163) TX_FAR _PlayerMon2Text - db $08 ; asm + TX_ASM push de push bc ld hl, wEnemyMonHP + 1 - ld de, wcce4 + ld de, wLastSwitchInEnemyMonHP + 1 ld b, [hl] dec hl ld a, [de] sub b - ld [$ff98], a + ld [H_MULTIPLICAND + 2], a dec de ld b, [hl] ld a, [de] sbc b - ld [$ff97], a - ld a, $19 - ld [H_POWEROFTEN], a + ld [H_MULTIPLICAND + 1], a + ld a, 25 + ld [H_MULTIPLIER], a call Multiply ld hl, wEnemyMonMaxHP ld a, [hli] @@ -212,37 +212,42 @@ PlayerMon2Text: ; f4163 (3d:4163) srl a rr b ld a, b - ld b, $4 - ld [H_POWEROFTEN], a + ld b, 4 + ld [H_DIVISOR], a call Divide pop bc pop de - ld a, [$ff98] - ld hl, EnoughText + ld a, [H_QUOTIENT + 3] ; a = ((LastSwitchInEnemyMonHP - CurrentEnemyMonHP) / 25) / (EnemyMonMaxHP / 4) +; Assuming that the enemy mon hasn't gained HP since the last switch in, +; a approximates the percentage that the enemy mon's total HP has decreased +; since the last switch in. +; If the enemy mon has gained HP, then a is garbage due to wrap-around and +; can fall in any of the ranges below. + ld hl, EnoughText ; HP stayed the same and a ret z - ld hl, ComeBackText - cp $1e + ld hl, ComeBackText ; HP went down 1% - 29% + cp 30 ret c - ld hl, OKExclamationText - cp $46 + ld hl, OKExclamationText ; HP went down 30% - 69% + cp 70 ret c - ld hl, GoodText + ld hl, GoodText ; HP went down 70% or more ret EnoughText: ; f41b1 (3d:41b1) TX_FAR _EnoughText - db $08 ; asm + TX_ASM jr PrintComeBackText OKExclamationText: ; f41b8 (3d:41b8) TX_FAR _OKExclamationText - db $08 ; asm + TX_ASM jr PrintComeBackText GoodText: ; f41bf (3d:41bf) TX_FAR _GoodText - db $08 ; asm + TX_ASM jr PrintComeBackText PrintComeBackText: ; f41c6 (3d:41c6) diff --git a/engine/battle/core.asm b/engine/battle/core.asm index 1b8203b1..8a46c705 100755 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -101,8 +101,8 @@ SlidePlayerAndEnemySilhouettesOnScreen: ; 3c04c (f:404c) ld a, MESSAGE_BOX ; the usual text box at the bottom of the screen ld [wTextBoxID], a call DisplayTextBoxID - hlCoord 1, 5 - ld bc, $307 + coord hl, 1, 5 + lb bc, 3, 7 call ClearScreenArea call DisableLCD call LoadFontTilePatterns @@ -110,14 +110,14 @@ SlidePlayerAndEnemySilhouettesOnScreen: ; 3c04c (f:404c) ld hl, vBGMap0 ld bc, $400 .clearBackgroundLoop - ld a, $7f + ld a, " " ld [hli], a dec bc ld a, b or c jr nz, .clearBackgroundLoop ; copy the work RAM tile map to VRAM - ld hl, wTileMap + coord hl, 0, 0 ld de, vBGMap0 ld b, 18 ; number of rows .copyRowLoop @@ -175,21 +175,19 @@ SlidePlayerAndEnemySilhouettesOnScreen: ; 3c04c (f:404c) ld a, $1 ld [H_AUTOBGTRANSFERENABLED], a ld a, $31 - ld [$ffe1], a - hlCoord 1, 5 - predef Func_3f0c6 + ld [hStartTileID], a + coord hl, 1, 5 + predef CopyUncompressedPicToTilemap xor a ld [hWY], a ld [rWY], a inc a ld [H_AUTOBGTRANSFERENABLED], a call Delay3 - ld b, $1 - call GoPAL_SET + ld b, SET_PAL_BATTLE + call RunPaletteCommand call HideSprites - ld hl, PrintBeginningBattleText - ld b, BANK(PrintBeginningBattleText) - jp Bankswitch + jpab PrintBeginningBattleText ; when a battle is starting, silhouettes of the player's pic and the enemy's pic are slid onto the screen ; the lower of the player's pic (his body) is part of the background, but his head is a sprite @@ -225,9 +223,9 @@ StartBattle: ; 3c11e (f:411e) xor a ld [wPartyGainExpFlags], a ld [wPartyFoughtCurrentEnemyFlags], a - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a inc a - ld [wd11d], a + ld [wFirstMonsNotOutYet], a ld hl, wEnemyMon1HP ld bc, wEnemyMon2 - wEnemyMon1 - 1 ld d, $3 @@ -260,7 +258,7 @@ StartBattle: ; 3c11e (f:411e) .displaySafariZoneBattleMenu call DisplayBattleMenu ret c ; return if the player ran from battle - ld a, [wcd6a] + ld a, [wActionResultOrTookBattleTurn] and a ; was the item used successfully? jr z, .displaySafariZoneBattleMenu ; if not, display the menu again; XXX does this ever jump? ld a, [W_NUMSAFARIBALLS] @@ -324,13 +322,13 @@ StartBattle: ; 3c11e (f:411e) ld [wcf91], a ld [wBattleMonSpecies2], a call LoadScreenTilesFromBuffer1 - hlCoord 1, 5 + coord hl, 1, 5 ld a, $9 call SlideTrainerPicOffScreen call SaveScreenTilesToBuffer1 ld a, [wWhichPokemon] ld c, a - ld b, $1 + ld b, FLAG_SET push bc ld hl, wPartyGainExpFlags predef FlagActionPredef @@ -355,13 +353,11 @@ EnemyRan: ; 3c202 (f:4202) ld hl, EnemyRanText .printText call PrintText - ld a, (SFX_08_44 - SFX_Headers_08) / 3 + ld a, SFX_RUN call PlaySoundWaitForCurrent xor a ld [H_WHOSETURN], a - ld hl, AnimationSlideEnemyMonOut - ld b, BANK(AnimationSlideEnemyMonOut) - jp Bankswitch + jpab AnimationSlideEnemyMonOff WildRanText: ; 3c229 (f:4229) TX_FAR _WildRanText @@ -383,7 +379,7 @@ MainInBattleLoop: ; 3c233 (f:4233) jp z, HandleEnemyMonFainted ; if enemy mon HP is 0, jump call SaveScreenTilesToBuffer1 xor a - ld [wd11d], a + ld [wFirstMonsNotOutYet], a ld a, [W_PLAYERBATTSTATUS2] and (1 << NeedsToRecharge) | (1 << UsingRage) ; check if the player is using Rage or needs to recharge jr nz, .selectEnemyMove @@ -415,8 +411,8 @@ MainInBattleLoop: ; 3c233 (f:4233) ld [wPlayerSelectedMove], a jr .selectEnemyMove .selectPlayerMove - ld a, [wcd6a] - and a + ld a, [wActionResultOrTookBattleTurn] + and a ; has the player already used the turn (e.g. by using an item, trying to run or switching pokemon) jr nz, .selectEnemyMove ld [wMoveMenuType], a inc a @@ -620,7 +616,7 @@ HandlePoisonBurnLeechSeed: ; 3c3bd (f:43bd) or [hl] ret nz ; test if fainted call DrawHUDsAndHPBars - ld c, $14 + ld c, 20 call DelayFrames xor a ret @@ -721,8 +717,8 @@ HandlePoisonBurnLeechSeed_IncreaseEnemyHP: ; 3c4a3 (f:44a3) ld [wHPBarMaxHP+1], a ld a, [hl] ld [wHPBarMaxHP], a - ld de, $fff2 - add hl, de ; skip back fomr max hp to current hp + ld de, wBattleMonHP - wBattleMonMaxHP + add hl, de ; skip back from max hp to current hp ld a, [hl] ld [wHPBarOldHP], a ; add bc to current HP add c @@ -760,12 +756,12 @@ HandlePoisonBurnLeechSeed_IncreaseEnemyHP: ; 3c4a3 (f:44a3) ret UpdateCurMonHPBar: ; 3c4f6 (f:44f6) - hlCoord 10, 9 ; tile pointer to player HP bar + coord hl, 10, 9 ; tile pointer to player HP bar ld a, [H_WHOSETURN] and a ld a, $1 jr z, .playersTurn - hlCoord 2, 2 ; tile pointer to enemy HP bar + coord hl, 2, 2 ; tile pointer to enemy HP bar xor a .playersTurn push bc @@ -792,7 +788,7 @@ CheckNumAttacksLeft: ; 3c50f (f:450f) HandleEnemyMonFainted: ; 3c525 (f:4525) xor a - ld [wccf0], a + ld [wInHandlePlayerMonFainted], a call FaintEnemyPokemon call AnyPartyAlive ld a, d @@ -816,14 +812,14 @@ HandleEnemyMonFainted: ; 3c525 (f:4525) call ChooseNextMon .skipReplacingBattleMon ld a, $1 - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a call ReplaceFaintedEnemyMon jp z, EnemyRan xor a - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a jp MainInBattleLoop -FaintEnemyPokemon ; 0x3c567 +FaintEnemyPokemon: ; 0x3c567 call ReadPlayerMonCurHPAndStatus ld a, [W_ISINBATTLE] dec a @@ -838,8 +834,17 @@ FaintEnemyPokemon ; 0x3c567 .wild ld hl, W_PLAYERBATTSTATUS1 res AttackingMultipleTimes, [hl] - xor a - ld [wPlayerNumHits], a +; Bug. This only zeroes the high byte of the player's accumulated damage, +; setting the accumulated damage to itself mod 256 instead of 0 as was probably +; intended. That alone is problematic, but this mistake has another more severe +; effect. This function's counterpart for when the player mon faints, +; RemoveFaintedPlayerMon, zeroes both the high byte and the low byte. In a link +; battle, the other player's Game Boy will call that function in response to +; the enemy mon (the player mon from the other side's perspective) fainting, +; and the states of the two Game Boys will go out of sync unless the damage +; was congruent to 0 modulo 256. + xor a + ld [wPlayerBideAccumulatedDamage], a ld hl, wEnemyStatsToDouble ; clear enemy statuses ld [hli], a ld [hli], a @@ -848,29 +853,29 @@ FaintEnemyPokemon ; 0x3c567 ld [hl], a ld [W_ENEMYDISABLEDMOVE], a ld [wEnemyDisabledMoveNumber], a - ld [wccf3], a + ld [wEnemyMonMinimized], a ld hl, wPlayerUsedMove ld [hli], a ld [hl], a - hlCoord 12, 5 - deCoord 12, 6 + coord hl, 12, 5 + coord de, 12, 6 call SlideDownFaintedMonPic - ld hl, wTileMap - ld bc, $40b + coord hl, 0, 0 + lb bc, 4, 11 call ClearScreenArea ld a, [W_ISINBATTLE] dec a jr z, .wild_win xor a - ld [wc0f1], a - ld [wc0f2], a - ld a, (SFX_08_48 - SFX_Headers_08) / 3 ; SFX_FALL? + ld [wFrequencyModifier], a + ld [wTempoModifier], a + ld a, SFX_FAINT_FALL call PlaySoundWaitForCurrent .sfxwait - ld a, [wc02a] - cp (SFX_08_48 - SFX_Headers_08) / 3 + ld a, [wChannelSoundIDs + CH4] + cp SFX_FAINT_FALL jr z, .sfxwait - ld a, (SFX_08_43 - SFX_Headers_08) / 3 ; SFX_DROP + ld a, SFX_FAINT_THUD call PlaySound call WaitForSoundToFinish jr .sfxplayed @@ -883,9 +888,9 @@ FaintEnemyPokemon ; 0x3c567 ld a, [hli] or [hl] jr nz, .playermonnotfaint - ld a, [wccf0] - and a - jr nz, .playermonnotfaint + ld a, [wInHandlePlayerMonFainted] + and a ; was this called by HandlePlayerMonFainted? + jr nz, .playermonnotfaint ; if so, don't call RemoveFaintedPlayerMon twice call RemoveFaintedPlayerMon .playermonnotfaint call AnyPartyAlive @@ -938,20 +943,20 @@ FaintEnemyPokemon ; 0x3c567 jr nz, .gainExpFlagsLoop ld a, b ld [wPartyGainExpFlags], a - ld hl, GainExperience - ld b, BANK(GainExperience) - jp Bankswitch + jpab GainExperience EnemyMonFaintedText: ; 0x3c63e TX_FAR _EnemyMonFaintedText db "@" EndLowHealthAlarm: ; 3c643 (f:4643) +; This function is called when the player has the won the battle. It turns off +; the low health alarm and prevents it from reactivating until the next battle. xor a - ld [wLowHealthAlarm], a ;disable low health alarm - ld [wc02a], a + ld [wLowHealthAlarm], a ; turn off low health alarm + ld [wChannelSoundIDs + CH4], a inc a - ld [wccf6], a + ld [wLowHealthAlarmDisabled], a ; prevent it from reactivating ret AnyEnemyPokemonAliveCheck: ; 3c64f (f:464f) @@ -973,7 +978,7 @@ AnyEnemyPokemonAliveCheck: ; 3c64f (f:464f) ; stores whether enemy ran in Z flag ReplaceFaintedEnemyMon: ; 3c664 (f:4664) - ld hl, wcf1e + ld hl, wEnemyHPBarColor ld e, $30 call GetBattleHealthBarColor callab DrawEnemyPokeballs @@ -990,7 +995,7 @@ ReplaceFaintedEnemyMon: ; 3c664 (f:4664) call EnemySendOut xor a ld [W_ENEMYMOVENUM], a - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a ld [wAILayer2Encouragement], a inc a ; reset Z flag ret @@ -1020,10 +1025,10 @@ TrainerBattleVictory: ; 3c696 (f:4696) cp LINK_STATE_BATTLING ret z call ScrollTrainerPicAfterBattle - ld c, $28 + ld c, 40 call DelayFrames call PrintEndBattleText -; win money +; win money ld hl, MoneyForWinningText call PrintText ld de, wPlayerMoney + 2 @@ -1042,7 +1047,7 @@ TrainerDefeatedText: ; 3c6e9 (f:46e9) PlayBattleVictoryMusic: ; 3c6ee (f:46ee) push af ld a, $ff - ld [wc0ee], a + ld [wNewSoundID], a call PlaySoundWaitForCurrent ld c, BANK(Music_DefeatedTrainer) pop af @@ -1050,8 +1055,8 @@ PlayBattleVictoryMusic: ; 3c6ee (f:46ee) jp Delay3 HandlePlayerMonFainted: ; 3c700 (f:4700) - ld a, $1 - ld [wccf0], a + ld a, 1 + ld [wInHandlePlayerMonFainted], a call RemoveFaintedPlayerMon call AnyPartyAlive ; test if any more mons are alive ld a, d @@ -1075,11 +1080,11 @@ HandlePlayerMonFainted: ; 3c700 (f:4700) jp nz, MainInBattleLoop ; if the enemy mon has more than 0 HP, go back to battle loop ; the enemy mon has 0 HP ld a, $1 - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a call ReplaceFaintedEnemyMon jp z, EnemyRan ; if enemy ran from battle rather than sending out another mon, jump xor a - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a jp MainInBattleLoop ; resets flags, slides mon's pic down, plays cry, and prints fainted message @@ -1087,7 +1092,7 @@ RemoveFaintedPlayerMon: ; 3c741 (f:4741) ld a, [wPlayerMonNumber] ld c, a ld hl, wPartyGainExpFlags - ld b, $0 + ld b, FLAG_RESET predef FlagActionPredef ; clear gain exp flag for fainted mon ld hl, W_ENEMYBATTSTATUS1 res 2, [hl] ; reset "attacking multiple times" flag @@ -1098,24 +1103,29 @@ RemoveFaintedPlayerMon: ; 3c741 (f:4741) ld [wLowHealthAlarm], a ;disable low health alarm call WaitForSoundToFinish .skipWaitForSound -; bug? if the player mon faints while the enemy mon is using bide, -; the accumulated damage is overwritten. xxx what values can [wLowHealthAlarm] have here? +; a is 0, so this zeroes the enemy's accumulated damage. ld hl, wEnemyBideAccumulatedDamage ld [hli], a ld [hl], a ld [wBattleMonStatus], a call ReadPlayerMonCurHPAndStatus - hlCoord 9, 7 - ld bc, $50b + coord hl, 9, 7 + lb bc, 5, 11 call ClearScreenArea - hlCoord 1, 10 - deCoord 1, 11 + coord hl, 1, 10 + coord de, 1, 11 call SlideDownFaintedMonPic ld a, $1 ld [wBattleResult], a - ld a, [wccf0] - and a - ret z + +; When the player mon and enemy mon faint at the same time and the fact that the +; enemy mon has fainted is detected first (e.g. when the player mon knocks out +; the enemy mon using a move with recoil and faints due to the recoil), don't +; play the player mon's cry or show the "[player mon] fainted!" message. + ld a, [wInHandlePlayerMonFainted] + and a ; was this called by HandleEnemyMonFainted? + ret z ; if so, return + ld a, [wBattleMonSpecies] call PlayCry ld hl, PlayerMonFaintedText @@ -1137,13 +1147,13 @@ DoUseNextMonDialogue: ; 3c79b (f:479b) ld hl, UseNextMonText call PrintText .displayYesNoBox - hlCoord 13, 9 - ld bc, $a0e + coord hl, 13, 9 + lb bc, 10, 14 ld a, TWO_OPTION_MENU ld [wTextBoxID], a call DisplayTextBoxID - ld a, [wd12e] - cp $2 ; did the player choose NO? + ld a, [wMenuExitMethod] + cp CHOSE_SECOND_ITEM ; did the player choose NO? jr z, .tryRunning ; if the player chose NO, try running and a ; reset carry ret @@ -1162,8 +1172,8 @@ UseNextMonText: ; 3c7d3 (f:47d3) ; choose next player mon to send out ; stores whether enemy mon has no HP left in Z flag ChooseNextMon: ; 3c7d8 (f:47d8) - ld a, $2 - ld [wd07d], a + ld a, BATTLE_PARTY_MENU + ld [wPartyMenuTypeOrMessageID], a call DisplayPartyMenu .checkIfMonChosen jr nc, .monChosen @@ -1177,17 +1187,17 @@ ChooseNextMon: ; 3c7d8 (f:47d8) cp LINK_STATE_BATTLING jr nz, .notLinkBattle inc a - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a call LinkBattleExchangeData .notLinkBattle xor a - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a call ClearSprites ld a, [wWhichPokemon] ld [wPlayerMonNumber], a ld c, a ld hl, wPartyGainExpFlags - ld b, $1 + ld b, FLAG_SET push bc predef FlagActionPredef pop bc @@ -1197,7 +1207,7 @@ ChooseNextMon: ; 3c7d8 (f:47d8) call GBPalWhiteOut call LoadHudTilePatterns call LoadScreenTilesFromBuffer1 - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand call GBPalNormal call SendOutMon ld hl, wEnemyMonHP @@ -1212,13 +1222,13 @@ HandlePlayerBlackOut: ; 3c837 (f:4837) cp LINK_STATE_BATTLING jr z, .notSony1Battle ld a, [W_CUROPPONENT] - cp $c8 + SONY1 + cp OPP_SONY1 jr nz, .notSony1Battle - ld hl, wTileMap ; sony 1 battle - ld bc, $815 + coord hl, 0, 0 ; sony 1 battle + lb bc, 8, 21 call ClearScreenArea call ScrollTrainerPicAfterBattle - ld c, $28 + ld c, 40 call DelayFrames ld hl, Sony1WinText call PrintText @@ -1226,8 +1236,8 @@ HandlePlayerBlackOut: ; 3c837 (f:4837) cp OAKS_LAB ret z ; starter battle in oak's lab: don't black out .notSony1Battle - ld b, $0 - call GoPAL_SET + ld b, SET_PAL_BATTLE_BLACK + call RunPaletteCommand ld hl, PlayerBlackedOutText2 ld a, [wLinkState] cp LINK_STATE_BATTLING @@ -1310,7 +1320,7 @@ SevenSpacesText: ; 3c8d7 (f:48d7) ; if a is 8, the slide is to the right, else it is to the left ; bug: when this is called, [H_AUTOBGTRANSFERENABLED] is non-zero, so there is screen tearing SlideTrainerPicOffScreen: ; 3c8df (f:48df) - ld [$FF8B], a + ld [hSlideAmount], a ld c, a .slideStepLoop ; each iteration, the trainer pic is slid one tile left/right push bc @@ -1318,10 +1328,10 @@ SlideTrainerPicOffScreen: ; 3c8df (f:48df) ld b, 7 ; number of rows .rowLoop push hl - ld a, [$FF8B] + ld a, [hSlideAmount] ld c, a .columnLoop - ld a, [$FF8B] + ld a, [hSlideAmount] cp 8 jr z, .slideRight .slideLeft ; slide player sprite off screen @@ -1356,7 +1366,7 @@ EnemySendOut: ; 3c90e (f:490e) ld [hl],a ld a,[wPlayerMonNumber] ld c,a - ld b,1 + ld b,FLAG_SET push bc predef FlagActionPredef ld hl,wPartyFoughtCurrentEnemyFlags @@ -1376,7 +1386,7 @@ EnemySendOutFirstMon: ; 3c92a (f:492a) ld [hl],a ld [W_ENEMYDISABLEDMOVE],a ld [wEnemyDisabledMoveNumber],a - ld [wccf3],a + ld [wEnemyMonMinimized],a ld hl,wPlayerUsedMove ld [hli],a ld [hl],a @@ -1384,7 +1394,7 @@ EnemySendOutFirstMon: ; 3c92a (f:492a) ld [wAICount],a ld hl,W_PLAYERBATTSTATUS1 res 5,[hl] - hlCoord 18, 0 + coord hl, 18, 0 ld a,8 call SlideTrainerPicOffScreen call PrintEmptyString @@ -1435,12 +1445,12 @@ EnemySendOutFirstMon: ; 3c92a (f:492a) call LoadEnemyMonData ld hl,wEnemyMonHP ld a,[hli] - ld [wcce3],a + ld [wLastSwitchInEnemyMonHP],a ld a,[hl] - ld [wcce4],a + ld [wLastSwitchInEnemyMonHP + 1],a ld a,1 ld [wCurrentMenuItem],a - ld a,[wd11d] + ld a,[wFirstMonsNotOutYet] dec a jr z,.next4 ld a,[wPartyCount] @@ -1454,16 +1464,16 @@ EnemySendOutFirstMon: ; 3c92a (f:492a) jr nz,.next4 ld hl, TrainerAboutToUseText call PrintText - hlCoord 0, 7 - ld bc,$0801 + coord hl, 0, 7 + lb bc, 8, 1 ld a,TWO_OPTION_MENU ld [wTextBoxID],a call DisplayTextBoxID ld a,[wCurrentMenuItem] and a jr nz,.next4 - ld a,2 - ld [wd07d],a + ld a,BATTLE_PARTY_MENU + ld [wPartyMenuTypeOrMessageID],a call DisplayPartyMenu .next9 ld a,1 @@ -1489,11 +1499,11 @@ EnemySendOutFirstMon: ; 3c92a (f:492a) call LoadScreenTilesFromBuffer1 .next4 call ClearSprites - ld hl,wTileMap - ld bc,$040B + coord hl, 0, 0 + lb bc, 4, 11 call ClearScreenArea - ld b,1 - call GoPAL_SET + ld b, SET_PAL_BATTLE + call RunPaletteCommand call GBPalNormal ld hl,TrainerSentOutText call PrintText @@ -1503,10 +1513,10 @@ EnemySendOutFirstMon: ; 3c92a (f:492a) call GetMonHeader ld de,vFrontPic call LoadMonFrontSprite - ld a,$CF - ld [$FFE1],a - hlCoord 15, 6 - predef Func_3f073 + ld a,-$31 + ld [hStartTileID],a + coord hl, 15, 6 + predef AnimateSendingOutMon ld a,[wEnemyMonSpecies2] call PlayCry call DrawEnemyHUDAndHPBar @@ -1555,7 +1565,7 @@ HasMonFainted: ; 3ca97 (f:4a97) ld a, [hli] or [hl] ret nz - ld a, [wd11d] + ld a, [wFirstMonsNotOutYet] and a jr nz, .done ld hl, NoWillText @@ -1590,14 +1600,14 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9) ld a, [hl] ld [H_MULTIPLICAND + 2], a ld a, [de] - ld [$ff8d], a + ld [hEnemySpeed], a inc de ld a, [de] - ld [$ff8e], a + ld [hEnemySpeed + 1], a call LoadScreenTilesFromBuffer1 ld de, H_MULTIPLICAND + 1 - ld hl, $ff8d - ld c, $2 + ld hl, hEnemySpeed + ld c, 2 call StringCmp jr nc, .canEscape ; jump if player speed greater than enemy speed xor a @@ -1609,9 +1619,9 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9) ld [H_DIVIDEND], a ld a, [H_PRODUCT + 3] ld [H_DIVIDEND + 1], a - ld a, [$ff8d] + ld a, [hEnemySpeed] ld b, a - ld a, [$ff8e] + ld a, [hEnemySpeed + 1] ; divide enemy speed by 4 srl b rr a @@ -1642,19 +1652,19 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9) ld b, a ld a, [H_QUOTIENT + 3] cp b - jr nc, .canEscape ; if the random value was less than or equal to the quotient + jr nc, .canEscape ; if the random value was less than or equal to the quotient ; plus 30 times the number of attempts, the player can escape ; can't escape ld a, $1 - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a ; you lose your turn when you can't escape ld hl, CantEscapeText jr .printCantEscapeOrNoRunningText .trainerBattle ld hl, NoRunningText .printCantEscapeOrNoRunningText call PrintText - ld a, $1 - ld [wd11f], a + ld a, 1 + ld [wForcePlayerToChooseMon], a call SaveScreenTilesToBuffer1 and a ; reset carry ret @@ -1666,7 +1676,7 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9) ; link battle call SaveScreenTilesToBuffer1 xor a - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a ld a, $f ld [wPlayerMoveListIndex], a call LinkBattleExchangeData @@ -1678,7 +1688,7 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9) dec a .playSound ld [wBattleResult], a - ld a, (SFX_08_44 - SFX_Headers_08) / 3 + ld a, SFX_RUN call PlaySoundWaitForCurrent ld hl, GotAwayText call PrintText @@ -1702,19 +1712,19 @@ GotAwayText: ; 3cba1 (f:4ba1) ; copies from party data to battle mon data when sending out a new player mon LoadBattleMonFromParty: ; 3cba6 (f:4ba6) ld a, [wWhichPokemon] - ld bc, $2c + ld bc, wPartyMon2 - wPartyMon1 ld hl, wPartyMon1Species call AddNTimes ld de, wBattleMonSpecies - ld bc, $c + ld bc, wBattleMonDVs - wBattleMonSpecies call CopyData - ld bc, $f + ld bc, wPartyMon1DVs - wPartyMon1OTID add hl, bc ld de, wBattleMonDVs - ld bc, $2 + ld bc, NUM_DVS call CopyData ld de, wBattleMonPP - ld bc, $4 + ld bc, NUM_MOVES call CopyData ld de, wBattleMonLevel ld bc, $b @@ -1726,16 +1736,16 @@ LoadBattleMonFromParty: ; 3cba6 (f:4ba6) ld a, [wPlayerMonNumber] call SkipFixedLengthTextEntries ld de, wBattleMonNick - ld bc, $b + ld bc, NAME_LENGTH call CopyData ld hl, wBattleMonLevel ld de, wPlayerMonUnmodifiedLevel ; block of memory used for unmodified stats - ld bc, $b + ld bc, 1 + NUM_STATS * 2 call CopyData call ApplyBurnAndParalysisPenaltiesToPlayer call ApplyBadgeStatBoosts ld a, $7 ; default stat modifier - ld b, $8 + ld b, NUM_STAT_MODS ld hl, wPlayerMonAttackMod .statModLoop ld [hli], a @@ -1746,19 +1756,19 @@ LoadBattleMonFromParty: ; 3cba6 (f:4ba6) ; copies from enemy party data to current enemy mon data when sending out a new enemy mon LoadEnemyMonFromParty: ; 3cc13 (f:4c13) ld a, [wWhichPokemon] - ld bc, $2c + ld bc, wEnemyMon2 - wEnemyMon1 ld hl, wEnemyMons call AddNTimes ld de, wEnemyMonSpecies - ld bc, $c + ld bc, wEnemyMonDVs - wEnemyMonSpecies call CopyData - ld bc, $f + ld bc, wEnemyMon1DVs - wEnemyMon1OTID add hl, bc ld de, wEnemyMonDVs - ld bc, $2 + ld bc, NUM_DVS call CopyData ld de, wEnemyMonPP - ld bc, $4 + ld bc, NUM_MOVES call CopyData ld de, wEnemyMonLevel ld bc, $b @@ -1770,16 +1780,16 @@ LoadEnemyMonFromParty: ; 3cc13 (f:4c13) ld a, [wWhichPokemon] call SkipFixedLengthTextEntries ld de, wEnemyMonNick - ld bc, $b + ld bc, NAME_LENGTH call CopyData ld hl, wEnemyMonLevel ld de, wEnemyMonUnmodifiedLevel ; block of memory used for unmodified stats - ld bc, $b + ld bc, 1 + NUM_STATS * 2 call CopyData call ApplyBurnAndParalysisPenaltiesToEnemy ld hl, W_MONHBASESTATS ld de, wEnemyMonBaseStats - ld b, $5 + ld b, NUM_STATS .copyBaseStatsLoop ld a, [hli] ld [de], a @@ -1787,7 +1797,7 @@ LoadEnemyMonFromParty: ; 3cc13 (f:4c13) dec b jr nz, .copyBaseStatsLoop ld a, $7 ; default stat modifier - ld b, $8 + ld b, NUM_STAT_MODS ld hl, wEnemyMonStatMods .statModLoop ld [hli], a @@ -1808,8 +1818,8 @@ SendOutMon: ; 3cc91 (f:4c91) call DrawPlayerHUDAndHPBar predef LoadMonBackPic xor a - ld [$ffe1], a - ld hl, wcc2d + ld [hStartTileID], a + ld hl, wBattleAndStartSavedMenuItem ld [hli], a ld [hl], a ld [wBoostExpByExpAll], a @@ -1826,50 +1836,50 @@ SendOutMon: ; 3cc91 (f:4c91) ld [hl], a ld [W_PLAYERDISABLEDMOVE], a ld [wPlayerDisabledMoveNumber], a - ld [wccf7], a - ld b, $1 - call GoPAL_SET + ld [wPlayerMonMinimized], a + ld b, SET_PAL_BATTLE + call RunPaletteCommand ld hl, W_ENEMYBATTSTATUS1 res UsingTrappingMove, [hl] ld a, $1 ld [H_WHOSETURN], a ld a, POOF_ANIM call PlayMoveAnimation - hlCoord 4, 11 - predef Func_3f073 + coord hl, 4, 11 + predef AnimateSendingOutMon ld a, [wcf91] call PlayCry call PrintEmptyString jp SaveScreenTilesToBuffer1 -; show 2 stages of the player getting smaller before disappearing +; show 2 stages of the player mon getting smaller before disappearing AnimateRetreatingPlayerMon: ; 3ccfa (f:4cfa) - hlCoord 1, 5 - ld bc, $707 + coord hl, 1, 5 + lb bc, 7, 7 call ClearScreenArea - hlCoord 3, 7 - ld bc, $505 + coord hl, 3, 7 + lb bc, 5, 5 xor a - ld [wcd6c], a - ld [H_DOWNARROWBLINKCNT1], a - predef Func_79aba - ld c, $4 + ld [wDownscaledMonSize], a + ld [hBaseTileID], a + predef CopyDownscaledMonTiles + ld c, 4 call DelayFrames call .clearScreenArea - hlCoord 4, 9 - ld bc, $303 - ld a, $1 - ld [wcd6c], a + coord hl, 4, 9 + lb bc, 3, 3 + ld a, 1 + ld [wDownscaledMonSize], a xor a - ld [H_DOWNARROWBLINKCNT1], a - predef Func_79aba + ld [hBaseTileID], a + predef CopyDownscaledMonTiles call Delay3 call .clearScreenArea ld a, $4c Coorda 5, 11 .clearScreenArea - hlCoord 1, 5 - ld bc, $707 + coord hl, 1, 5 + lb bc, 7, 7 jp ClearScreenArea ; reads player's current mon's HP into wBattleMonHP @@ -1891,14 +1901,14 @@ DrawHUDsAndHPBars: ; 3cd5a (f:4d5a) DrawPlayerHUDAndHPBar: ; 3cd60 (f:4d60) xor a ld [H_AUTOBGTRANSFERENABLED], a - hlCoord 9, 7 - ld bc, $50b + coord hl, 9, 7 + lb bc, 5, 11 call ClearScreenArea callab PlacePlayerHUDTiles - hlCoord 18, 9 + coord hl, 18, 9 ld [hl], $73 ld de, wBattleMonNick - hlCoord 10, 7 + coord hl, 10, 7 call CenterMonName call PlaceString ld hl, wBattleMonSpecies @@ -1909,7 +1919,7 @@ DrawPlayerHUDAndHPBar: ; 3cd60 (f:4d60) ld de, wLoadedMonLevel ld bc, $b call CopyData - hlCoord 14, 8 + coord hl, 14, 8 push hl inc hl ld de, wLoadedMonStatus @@ -1920,21 +1930,21 @@ DrawPlayerHUDAndHPBar: ; 3cd60 (f:4d60) .asm_3cdae ld a, [wLoadedMonSpecies] ld [wcf91], a - hlCoord 10, 9 + coord hl, 10, 9 predef DrawHP ld a, $1 ld [H_AUTOBGTRANSFERENABLED], a - ld hl, wcf1d + ld hl, wPlayerHPBarColor call GetBattleHealthBarColor ld hl, wBattleMonHP ld a, [hli] or [hl] jr z, .asm_3cdd9 - ld a, [wccf6] - and a - ret nz - ld a, [wcf1d] - cp $2 + ld a, [wLowHealthAlarmDisabled] + and a ; has the alarm been disabled because the player has already won? + ret nz ; if so, return + ld a, [wPlayerHPBarColor] + cp HP_BAR_RED jr z, .asm_3cde6 .asm_3cdd9 ld hl, wLowHealthAlarm @@ -1942,7 +1952,7 @@ DrawPlayerHUDAndHPBar: ; 3cd60 (f:4d60) ld [hl], $0 ret z xor a - ld [wc02a], a + ld [wChannelSoundIDs + CH4], a ret .asm_3cde6 ld hl, wLowHealthAlarm @@ -1952,15 +1962,15 @@ DrawPlayerHUDAndHPBar: ; 3cd60 (f:4d60) DrawEnemyHUDAndHPBar: ; 3cdec (f:4dec) xor a ld [H_AUTOBGTRANSFERENABLED], a - ld hl, wTileMap - ld bc, $40c + coord hl, 0, 0 + lb bc, 4, 12 call ClearScreenArea callab PlaceEnemyHUDTiles ld de, wEnemyMonNick - hlCoord 1, 0 + coord hl, 1, 0 call CenterMonName call PlaceString - hlCoord 4, 1 + coord hl, 4, 1 push hl inc hl ld de, wEnemyMonStatus @@ -2033,11 +2043,11 @@ DrawEnemyHUDAndHPBar: ; 3cdec (f:4dec) .drawHPBar xor a ld [wHPBarType], a - hlCoord 2, 2 + coord hl, 2, 2 call DrawHPBar ld a, $1 ld [H_AUTOBGTRANSFERENABLED], a - ld hl, wcf1e + ld hl, wEnemyHPBarColor GetBattleHealthBarColor: ; 3ce90 (f:4e90) ld b, [hl] @@ -2045,8 +2055,8 @@ GetBattleHealthBarColor: ; 3ce90 (f:4e90) ld a, [hl] cp b ret z - ld b, $1 - jp GoPAL_SET + ld b, SET_PAL_BATTLE + jp RunPaletteCommand ; center's mon's name on the battle screen ; if the name is 1 or 2 letters long, it is printed 2 spaces more to the right than usual @@ -2061,11 +2071,11 @@ CenterMonName: ; 3ce9c (f:4e9c) .loop inc de ld a, [de] - cp $50 + cp "@" jr z, .done inc de ld a, [de] - cp $50 + cp "@" jr z, .done dec hl dec b @@ -2097,7 +2107,7 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3) ; the following happens for the old man tutorial ld hl, wPlayerName ld de, W_GRASSRATE - ld bc, $b + ld bc, NAME_LENGTH call CopyData ; temporarily save the player name in unused space, ; which is supposed to get overwritten when entering a ; map with wild Pokémon. Due to an oversight, the data @@ -2105,17 +2115,17 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3) ; Missingno. glitch can show up. ld hl, .oldManName ld de, wPlayerName - ld bc, $b + ld bc, NAME_LENGTH call CopyData ; the following simulates the keystrokes by drawing menus on screen - hlCoord 9, 14 + coord hl, 9, 14 ld [hl], "▶" - ld c, $50 + ld c, 80 call DelayFrames - ld [hl], $7f - hlCoord 9, 16 + ld [hl], " " + coord hl, 9, 16 ld [hl], "▶" - ld c, $32 + ld c, 50 call DelayFrames ld [hl], $ec ld a, $2 ; select the "ITEM" menu @@ -2123,7 +2133,7 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3) .oldManName db "OLD MAN@" .handleBattleMenuInput - ld a, [wcc2d] + ld a, [wBattleAndStartSavedMenuItem] ld [wCurrentMenuItem], a ld [wLastMenuItem], a sub 2 ; check if the cursor is in the left column @@ -2145,9 +2155,9 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3) .safariLeftColumn Coorda 13, 14 Coorda 13, 16 - hlCoord 7, 14 + coord hl, 7, 14 ld de, W_NUMSAFARIBALLS - ld bc, $102 + lb bc, 1, 2 call PrintNumber ld b, $1 ; top menu item X .leftColumn_WaitForInput @@ -2178,9 +2188,9 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3) .safariRightColumn Coorda 1, 14 ; clear upper cursor position in left column Coorda 1, 16 ; clear lower cursor position in left column - hlCoord 7, 14 + coord hl, 7, 14 ld de, W_NUMSAFARIBALLS - ld bc, $102 + lb bc, 1, 2 call PrintNumber ld b, $d ; top menu item X .rightColumn_WaitForInput @@ -2206,7 +2216,7 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3) ld a, [W_BATTLETYPE] cp $2 ; is it a Safari battle? ld a, [wCurrentMenuItem] - ld [wcc2d], a + ld [wBattleAndStartSavedMenuItem], a jr z, .handleMenuSelection ; not Safari battle ; swap the IDs of the item menu and party menu (this is probably because they swapped the positions @@ -2276,9 +2286,9 @@ BagWasSelected: jr nz, DisplayPlayerBag ; no, it is a normal battle ld hl, OldManItemList ld a, l - ld [wList], a + ld [wListPointer], a ld a, h - ld [wList + 1], a + ld [wListPointer + 1], a jr DisplayBagMenu OldManItemList: @@ -2290,22 +2300,22 @@ DisplayPlayerBag: ; get the pointer to player's bag when in a normal battle ld hl, wNumBagItems ld a, l - ld [wList], a + ld [wListPointer], a ld a, h - ld [wList + 1], a + ld [wListPointer + 1], a DisplayBagMenu: xor a - ld [wcf93], a + ld [wPrintItemPrices], a ld a, ITEMLISTMENU ld [wListMenuID], a - ld a, [wcc2c] + ld a, [wBagSavedMenuItem] ld [wCurrentMenuItem], a call DisplayListMenuID ld a, [wCurrentMenuItem] - ld [wcc2c], a + ld [wBagSavedMenuItem], a ld a, $0 - ld [wcc37], a + ld [wMenuWatchMovingOutOfBounds], a ld [wMenuItemToSwap], a jp c, DisplayBattleMenu ; go back to battle menu if an item was not selected @@ -2316,7 +2326,7 @@ UseBagItem: call GetItemName call CopyStringToCF4B ; copy name xor a - ld [wd152], a + ld [wPseudoItemID], a call UseItem call LoadHudTilePatterns call ClearSprites @@ -2326,7 +2336,7 @@ UseBagItem: cp $2 ; is it a safari battle? jr z, .checkIfMonCaptured - ld a, [wcd6a] + ld a, [wActionResultOrTookBattleTurn] and a ; was the item used successfully? jp z, BagWasSelected ; if not, go back to the bag menu @@ -2340,7 +2350,7 @@ UseBagItem: res UsingTrappingMove, [hl] ; not using multi-turn move any more .checkIfMonCaptured - ld a, [wd11c] + ld a, [wCapturedMonSpecies] and a ; was the enemy mon captured with a ball? jr nz, .returnAfterCapturingMon @@ -2360,7 +2370,7 @@ UseBagItem: .returnAfterCapturingMon call GBPalNormal xor a - ld [wd11c], a + ld [wCapturedMonSpecies], a ld a, $2 ld [wBattleResult], a scf ; set carry @@ -2384,8 +2394,8 @@ PartyMenuOrRockOrRun: jp UseBagItem .partyMenuWasSelected call LoadScreenTilesFromBuffer1 - xor a - ld [wd07d], a + xor a ; NORMAL_PARTY_MENU + ld [wPartyMenuTypeOrMessageID], a ld [wMenuItemToSwap], a call DisplayPartyMenu .checkIfPartyMonWasSelected @@ -2395,16 +2405,16 @@ PartyMenuOrRockOrRun: call GBPalWhiteOut call LoadHudTilePatterns call LoadScreenTilesFromBuffer2 - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand call GBPalNormal jp DisplayBattleMenu .partyMonDeselected - hlCoord 11, 11 - ld bc, $81 - ld a, $7f + coord hl, 11, 11 + ld bc, 6 * SCREEN_WIDTH + 9 + ld a, " " call FillMemory - xor a - ld [wd07d], a + xor a ; NORMAL_PARTY_MENU + ld [wPartyMenuTypeOrMessageID], a call GoBackToPartyMenu jr .checkIfPartyMonWasSelected .partyMonWasSelected @@ -2435,8 +2445,8 @@ PartyMenuOrRockOrRun: and a ; was Switch selected? jr z, .switchMon ; if so, jump ; Stats was selected - xor a - ld [wcc49], a + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation], a ld hl, wPartyMon1 call ClearSprites ; display the two status screens @@ -2448,7 +2458,7 @@ PartyMenuOrRockOrRun: ld hl, AnimationSubstitute jr nz, .doEnemyMonAnimation ; enemy mon doesn't have substitute - ld a, [wccf3] + ld a, [wEnemyMonMinimized] and a ; has the enemy mon used Minimise? ld hl, AnimationMinimizeMon jr nz, .doEnemyMonAnimation @@ -2479,24 +2489,24 @@ PartyMenuOrRockOrRun: call HasMonFainted jp z, .partyMonDeselected ; can't switch to fainted mon ld a, $1 - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a call GBPalWhiteOut call ClearSprites call LoadHudTilePatterns call LoadScreenTilesFromBuffer1 - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand call GBPalNormal ; fall through to SwitchPlayerMon SwitchPlayerMon: ; 3d1ba (f:51ba) callab RetreatMon - ld c, $32 + ld c, 50 call DelayFrames call AnimateRetreatingPlayerMon ld a, [wWhichPokemon] ld [wPlayerMonNumber], a ld c, a - ld b, $1 + ld b, FLAG_SET push bc ld hl, wPartyGainExpFlags predef FlagActionPredef @@ -2522,12 +2532,12 @@ BattleMenu_RunWasSelected: ; 3d1fa (f:51fa) ld hl, wBattleMonSpeed ld de, wEnemyMonSpeed call TryRunningFromBattle - ld a, $0 - ld [wd11f], a + ld a, 0 + ld [wForcePlayerToChooseMon], a ret c - ld a, [wcd6a] + ld a, [wActionResultOrTookBattleTurn] and a - ret nz + ret nz ; return if the player couldn't escape jp DisplayBattleMenu MoveSelectionMenu: ; 3d219 (f:5219) @@ -2561,17 +2571,17 @@ MoveSelectionMenu: ; 3d219 (f:5219) ret z ld hl, wBattleMonMoves call .loadmoves - hlCoord 4, 12 + coord hl, 4, 12 ld b, $4 ld c, $e di call TextBoxBorder - hlCoord 4, 12 + coord hl, 4, 12 ld [hl], $7a - hlCoord 10, 12 + coord hl, 10, 12 ld [hl], $7e ei - hlCoord 6, 13 + coord hl, 6, 13 call .writemoves ld b, $5 ld a, $c @@ -2579,11 +2589,11 @@ MoveSelectionMenu: ; 3d219 (f:5219) .mimicmenu ld hl, wEnemyMonMoves call .loadmoves - hlCoord 0, 7 + coord hl, 0, 7 ld b, $4 ld c, $e call TextBoxBorder - hlCoord 2, 8 + coord hl, 2, 8 call .writemoves ld b, $1 ld a, $7 @@ -2591,22 +2601,22 @@ MoveSelectionMenu: ; 3d219 (f:5219) .relearnmenu ld a, [wWhichPokemon] ld hl, wPartyMon1Moves - ld bc, $2c + ld bc, wPartyMon2 - wPartyMon1 call AddNTimes call .loadmoves - hlCoord 4, 7 + coord hl, 4, 7 ld b, $4 ld c, $e call TextBoxBorder - hlCoord 6, 8 + coord hl, 6, 8 call .writemoves ld b, $5 ld a, $7 .menuset ld hl, wTopMenuItemY - ld [hli], a + ld [hli], a ; wTopMenuItemY ld a, b - ld [hli], a + ld [hli], a ; wTopMenuItemX ld a, [wMoveMenuType] cp $1 jr z, .selectedmoveknown @@ -2615,30 +2625,30 @@ MoveSelectionMenu: ; 3d219 (f:5219) ld a, [wPlayerMoveListIndex] inc a .selectedmoveknown - ld [hli], a + ld [hli], a ; wCurrentMenuItem inc hl ; wTileBehindCursor untouched - ld a, [wcd6c] + ld a, [wNumMovesMinusOne] inc a inc a - ld [hli], a + ld [hli], a ; wMaxMenuItem ld a, [wMoveMenuType] dec a - ld b, $c1 ; can't use B + ld b, D_UP | D_DOWN | A_BUTTON jr z, .matchedkeyspicked dec a - ld b, $c3 + ld b, D_UP | D_DOWN | A_BUTTON | B_BUTTON jr z, .matchedkeyspicked ld a, [wLinkState] cp LINK_STATE_BATTLING jr z, .matchedkeyspicked ld a, [W_FLAGS_D733] - bit 0, a - ld b, $c7 + bit BIT_TEST_BATTLE, a + ld b, D_UP | D_DOWN | A_BUTTON | B_BUTTON | SELECT jr z, .matchedkeyspicked ld b, $ff .matchedkeyspicked ld a, b - ld [hli], a + ld [hli], a ; wMenuWatchedKeys ld a, [wMoveMenuType] cp $1 jr z, .movelistindex1 @@ -2654,21 +2664,21 @@ SelectMenuItem: ; 3d2fe (f:52fe) jr z, .battleselect dec a jr nz, .select - hlCoord 1, 14 + coord hl, 1, 14 ld de, WhichTechniqueString call PlaceString jr .select .battleselect ld a, [W_FLAGS_D733] - bit 0, a + bit BIT_TEST_BATTLE, a jr nz, .select call PrintMenuItem ld a, [wMenuItemToSwap] and a jr z, .select - hlCoord 5, 13 + coord hl, 5, 13 dec a - ld bc, $14 + ld bc, SCREEN_WIDTH call AddNTimes ld [hl], $ec .select @@ -2759,7 +2769,7 @@ CursorUp: ; 3d3c9 (f:53c9) and a jp nz, SelectMenuItem call EraseMenuCursor - ld a, [wcd6c] + ld a, [wNumMovesMinusOne] inc a ld [wCurrentMenuItem], a jp SelectMenuItem @@ -2767,7 +2777,7 @@ CursorUp: ; 3d3c9 (f:53c9) CursorDown: ; 3d3dd (f:53dd) ld a, [wCurrentMenuItem] ld b, a - ld a, [wcd6c] + ld a, [wNumMovesMinusOne] inc a inc a cp b @@ -2815,7 +2825,7 @@ AnyMoveToSelect: ; 3d3f5 (f:53f5) .asm_3d423 ld hl, NoMovesLeftText call PrintText - ld c, $3c + ld c, 60 call DelayFrames xor a ret @@ -2868,7 +2878,7 @@ SwapMovesInMenu: ; 3d435 (f:5435) push hl call .swapBytes ; swap moves pop hl - ld bc, $15 + ld bc, wPartyMon1PP - wPartyMon1Moves add hl, bc call .swapBytes ; swap move PP xor a @@ -2903,7 +2913,7 @@ SwapMovesInMenu: ; 3d435 (f:5435) PrintMenuItem: ; 3d4b6 (f:54b6) xor a ld [H_AUTOBGTRANSFERENABLED], a - hlCoord 0, 8 + coord hl, 0, 8 ld b, $3 ld c, $9 call TextBoxBorder @@ -2916,7 +2926,7 @@ PrintMenuItem: ; 3d4b6 (f:54b6) ld a, [wCurrentMenuItem] cp b jr nz, .notDisabled - hlCoord 1, 10 + coord hl, 1, 10 ld de, DisabledText call PlaceString jr .moveDisabled @@ -2930,13 +2940,13 @@ PrintMenuItem: ; 3d4b6 (f:54b6) ld c, a ld b, $0 ; which item in the menu is the cursor pointing to? (0-3) add hl, bc ; point to the item (move) in memory - ld a, [hl] - ld [wPlayerSelectedMove], a ; update wPlayerSelectedMove even if the move + ld a, [hl] + ld [wPlayerSelectedMove], a ; update wPlayerSelectedMove even if the move ; isn't actually selected (just pointed to by the cursor) ld a, [wPlayerMonNumber] ld [wWhichPokemon], a - ld a, $4 - ld [wcc49], a + ld a, BATTLE_MON_DATA + ld [wMonDataLocation], a callab GetMaxPP ld hl, wCurrentMenuItem ld c, [hl] @@ -2947,24 +2957,24 @@ PrintMenuItem: ; 3d4b6 (f:54b6) ld a, [hl] and $3f ld [wcd6d], a -; print TYPE/<type> and <curPP>/<maxPP> - hlCoord 1, 9 +; print TYPE/<type> and <curPP>/<maxPP> + coord hl, 1, 9 ld de, TypeText call PlaceString - hlCoord 7, 11 + coord hl, 7, 11 ld [hl], "/" - hlCoord 5, 9 + coord hl, 5, 9 ld [hl], "/" - hlCoord 5, 11 + coord hl, 5, 11 ld de, wcd6d - ld bc, $102 + lb bc, 1, 2 call PrintNumber - hlCoord 8, 11 - ld de, wd11e - ld bc, $102 + coord hl, 8, 11 + ld de, wMaxPP + lb bc, 1, 2 call PrintNumber - call GetCurrentMove - hlCoord 2, 10 + call GetCurrentMove + coord hl, 2, 10 predef PrintMoveType .moveDisabled ld a, $1 @@ -2979,7 +2989,7 @@ TypeText: ; 3d55f (f:555f) SelectEnemyMove: ; 3d564 (f:5564) ld a, [wLinkState] - sub $4 + sub LINK_STATE_BATTLING jr nz, .noLinkBattle ; link battle call SaveScreenTilesToBuffer1 @@ -3037,18 +3047,18 @@ SelectEnemyMove: ; 3d564 (f:5564) push hl call BattleRandom ld b, $1 - cp $3f ; select move 1 in [0,3e] (63/256 chance) + cp $3f ; select move 1, [0,3e] (63/256 chance) jr c, .moveChosen inc hl inc b - cp $7f ; select move 1 in [3f,7e] (64/256 chance) + cp $7f ; select move 2, [3f,7e] (64/256 chance) jr c, .moveChosen inc hl inc b - cp $be ; select move 1 in [7f,bd] (63/256 chance) + cp $be ; select move 3, [7f,bd] (63/256 chance) jr c, .moveChosen inc hl - inc b ; select move 4 in [be,ff] (66/256 chance) + inc b ; select move 4, [be,ff] (66/256 chance) .moveChosen ld a, b dec a @@ -3075,46 +3085,47 @@ LinkBattleExchangeData: ; 3d605 (f:5605) ld [wSerialExchangeNybbleReceiveData], a ld a, [wPlayerMoveListIndex] cp $f ; is the player running from battle? - jr z, .asm_3d630 - ld a, [wcd6a] - and a - jr nz, .asm_3d629 + jr z, .doExchange + ld a, [wActionResultOrTookBattleTurn] + and a ; is the player switching in another mon? + jr nz, .switching +; the player used a move ld a, [wPlayerSelectedMove] cp STRUGGLE ld b, $e - jr z, .asm_3d62f + jr z, .next dec b inc a - jr z, .asm_3d62f + jr z, .next ld a, [wPlayerMoveListIndex] - jr .asm_3d630 -.asm_3d629 + jr .doExchange +.switching ld a, [wWhichPokemon] - add $4 + add 4 ld b, a -.asm_3d62f +.next ld a, b -.asm_3d630 +.doExchange ld [wSerialExchangeNybbleSendData], a callab PrintWaitingText -.asm_3d63b +.syncLoop1 call Serial_ExchangeNybble call DelayFrame ld a, [wSerialExchangeNybbleReceiveData] inc a - jr z, .asm_3d63b - ld b, $a -.asm_3d649 + jr z, .syncLoop1 + ld b, 10 +.syncLoop2 call DelayFrame call Serial_ExchangeNybble dec b - jr nz, .asm_3d649 - ld b, $a -.asm_3d654 + jr nz, .syncLoop2 + ld b, 10 +.syncLoop3 call DelayFrame call Serial_SendZeroByte dec b - jr nz, .asm_3d654 + jr nz, .syncLoop3 ret ExecutePlayerMove: ; 3d65e (f:565e) @@ -3129,8 +3140,8 @@ ExecutePlayerMove: ; 3d65e (f:565e) ld [wMoveDidntMiss], a ld a, $a ld [wDamageMultipliers], a - ld a, [wcd6a] - and a + ld a, [wActionResultOrTookBattleTurn] + and a ; has the player already used the turn (e.g. by using an item, trying to run or switching pokemon) jp nz, ExecutePlayerMoveDone call PrintGhostText jp z, ExecutePlayerMoveDone @@ -3170,13 +3181,13 @@ PlayerCanExecuteMove: ; 3d6b0 (f:56b0) ld hl,ResidualEffects1 ld de,1 call IsInArray - jp c,JumpMoveEffect ; ResidualEffects1 moves skip damage calculation and accuracy tests - ; unless executed as part of their exclusive effect functions + jp c,JumpMoveEffect ; ResidualEffects1 moves skip damage calculation and accuracy tests + ; unless executed as part of their exclusive effect functions ld a,[W_PLAYERMOVEEFFECT] ld hl,SpecialEffectsCont ld de,1 call IsInArray - call c,JumpMoveEffect ; execute the effects of SpecialEffectsCont moves (e.g. Wrap, Thrash) but don't skip anything + call c,JumpMoveEffect ; execute the effects of SpecialEffectsCont moves (e.g. Wrap, Thrash) but don't skip anything PlayerCalcMoveDamage: ; 3d6dc (f:56dc) ld a,[W_PLAYERMOVEEFFECT] ld hl,SetDamageEffects @@ -3199,7 +3210,7 @@ handleIfPlayerMoveMissed and a jr z,getPlayerAnimationType ld a,[W_PLAYERMOVEEFFECT] - sub a,EXPLODE_EFFECT + sub a,EXPLODE_EFFECT jr z,playPlayerMoveAnimation ; don't play any animation if the move missed, unless it was EXPLODE_EFFECT jr playerCheckIfFlyOrChargeEffect getPlayerAnimationType @@ -3211,9 +3222,9 @@ getPlayerAnimationType playPlayerMoveAnimation push af ld a,[W_PLAYERBATTSTATUS2] - bit 4,a - ld hl,Func_79747 - ld b,BANK(Func_79747) + bit HasSubstituteUp,a + ld hl,HideSubstituteShowMonAnim + ld b,BANK(HideSubstituteShowMonAnim) call nz,Bankswitch pop af ld [wAnimationType],a @@ -3222,13 +3233,13 @@ playPlayerMoveAnimation call HandleExplodingAnimation call DrawPlayerHUDAndHPBar ld a,[W_PLAYERBATTSTATUS2] - bit 4,a - ld hl,Func_79771 - ld b,BANK(Func_79771) + bit HasSubstituteUp,a + ld hl,ReshowSubstituteAnim + ld b,BANK(ReshowSubstituteAnim) call nz,Bankswitch jr MirrorMoveCheck playerCheckIfFlyOrChargeEffect - ld c,$1E + ld c,30 call DelayFrames ld a,[W_PLAYERMOVEEFFECT] cp a,FLY_EFFECT @@ -3294,7 +3305,7 @@ MirrorMoveCheck ld a,[wPlayerNumAttacksLeft] dec a ld [wPlayerNumAttacksLeft],a - jp nz,getPlayerAnimationType ; for multi-hit moves, apply attack until PlayerNumAttacksLeft hits 0 or the enemy faints. + jp nz,getPlayerAnimationType ; for multi-hit moves, apply attack until PlayerNumAttacksLeft hits 0 or the enemy faints. ; damage calculation and accuracy tests only happen for the first hit res AttackingMultipleTimes,[hl] ; clear attacking multiple times status when all attacks are over ld hl,MultiHitText @@ -3320,7 +3331,7 @@ MultiHitText: ; 3d805 (f:5805) ExecutePlayerMoveDone: ; 3d80a (f:580a) xor a - ld [wcd6a],a + ld [wActionResultOrTookBattleTurn],a ld b,1 ret @@ -3505,8 +3516,8 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854) .MonHurtItselfOrFullyParalysed ld hl,W_PLAYERBATTSTATUS1 ld a,[hl] - ; clear bide, thrashing, charging up, and trapping moves such as warp (already cleared for confusion damage) - and $ff ^ ((1 << StoringEnergy) | (1 << ThrashingAbout) | (1 << ChargingUp) | (1 << UsingTrappingMove)) + ; clear bide, thrashing, charging up, and trapping moves such as warp (already cleared for confusion damage) + and $ff ^ ((1 << StoringEnergy) | (1 << ThrashingAbout) | (1 << ChargingUp) | (1 << UsingTrappingMove)) ld [hl],a ld a,[W_PLAYERMOVEEFFECT] cp a,FLY_EFFECT @@ -3584,7 +3595,7 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854) ld hl,wPlayerNumAttacksLeft dec [hl] ; did Thrashing About counter hit 0? ld hl,PlayerCalcMoveDamage ; skip DecrementPP - jp nz,.returnToHL + jp nz,.returnToHL push hl ld hl,W_PLAYERBATTSTATUS1 res ThrashingAbout,[hl] ; no longer thrashing about @@ -3605,7 +3616,7 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854) ld a,[wPlayerNumAttacksLeft] dec a ; did multi-turn move end? ld [wPlayerNumAttacksLeft],a - ld hl,getPlayerAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit), + ld hl,getPlayerAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit), ; DecrementPP and MoveHitTest jp nz,.returnToHL jp .returnToHL @@ -3702,7 +3713,7 @@ PrintMoveIsDisabledText: ; 3da88 (f:5a88) ld de, W_ENEMYBATTSTATUS1 .removeChargingUp ld a, [de] - res ChargingUp, a ; end the pokemon's + res ChargingUp, a ; end the pokemon's ld [de], a ld a, [hl] ld [wd11e], a @@ -3762,9 +3773,14 @@ PrintMonName1Text: ; 3daf5 (f:5af5) ld hl, MonName1Text jp PrintText +; this function wastes time calling DetermineExclamationPointTextNum +; and choosing between Used1Text and Used2Text, even though +; those text strings are identical and both continue at PrintInsteadText +; this likely had to do with Japanese grammar that got translated, +; but the functionality didn't get removed MonName1Text: ; 3dafb (f:5afb) TX_FAR _MonName1Text - db $08 ; asm + TX_ASM ld a, [H_WHOSETURN] and a ld a, [W_PLAYERMOVENUM] @@ -3775,7 +3791,7 @@ MonName1Text: ; 3dafb (f:5afb) .asm_3db11 ld [hl], a ld [wd11e], a - call Func_3db85 + call DetermineExclamationPointTextNum ld a, [wMonIsDisobedient] and a ld hl, Used2Text @@ -3789,33 +3805,35 @@ MonName1Text: ; 3dafb (f:5afb) Used1Text: ; 3db2d (f:5b2d) TX_FAR _Used1Text - db $08 ; asm + TX_ASM jr PrintInsteadText Used2Text: ; 3db34 (f:5b34) TX_FAR _Used2Text - db $08 ; asm + TX_ASM + ; fall through PrintInsteadText: ; 3db39 (f:5b39) ld a, [wMonIsDisobedient] and a - jr z, PrintCF4BText + jr z, PrintMoveName ld hl, InsteadText ret InsteadText: ; 3db43 (f:5b43) TX_FAR _InsteadText - db $08 ; asm + TX_ASM + ; fall through -PrintCF4BText: ; 3db48 (f:5b48) - ld hl, CF4BText +PrintMoveName: ; 3db48 (f:5b48) + ld hl, _PrintMoveName ret -CF4BText: ; 3db4c (f:5b4c) +_PrintMoveName: ; 3db4c (f:5b4c) TX_FAR _CF4BText - db $08 ; asm + TX_ASM ld hl, ExclamationPointPointerTable - ld a, [wd11e] + ld a, [wd11e] ; exclamation point num add a push bc ld b, $0 @@ -3854,29 +3872,36 @@ ExclamationPoint5Text: ; 3db80 (f:5b80) TX_FAR _ExclamationPoint5Text db "@" -Func_3db85: ; 3db85 (f:5b85) +; this function does nothing useful +; if the move being used is in set [1-4] from ExclamationPointMoveSets, +; use ExclamationPoint[1-4]Text +; otherwise, use ExclamationPoint5Text +; but all five text strings are identical +; this likely had to do with Japanese grammar that got translated, +; but the functionality didn't get removed +DetermineExclamationPointTextNum: ; 3db85 (f:5b85) push bc - ld a, [wd11e] ; move number + ld a, [wd11e] ; move ID ld c, a ld b, $0 - ld hl, UnknownMovesList_3dba3 -.asm_3db8f + ld hl, ExclamationPointMoveSets +.loop ld a, [hli] cp $ff - jr z, .asm_3db9d + jr z, .done cp c - jr z, .asm_3db9d + jr z, .done and a - jr nz, .asm_3db8f + jr nz, .loop inc b - jr .asm_3db8f -.asm_3db9d + jr .loop +.done ld a, b - ld [wd11e], a + ld [wd11e], a ; exclamation point num pop bc ret -UnknownMovesList_3dba3: ; 3dba3 (f:5ba3) +ExclamationPointMoveSets: ; 3dba3 (f:5ba3) db SWORDS_DANCE, GROWTH db $00 db RECOVER, BIDE, SELFDESTRUCT, AMNESIA @@ -3919,7 +3944,7 @@ PrintMoveFailureText: ; 3dbe2 (f:5be2) ; if you get here, the mon used jump kick or hi jump kick and missed ld hl, W_DAMAGE ; since the move missed, W_DAMAGE will always contain 0 at this point. - ; Thus, recoil damage will always be equal to 1 + ; Thus, recoil damage will always be equal to 1 ; even if it was intended to be potential damage/8. ld a, [hli] ld b, [hl] @@ -3940,7 +3965,7 @@ PrintMoveFailureText: ; 3dbe2 (f:5be2) ld hl, KeptGoingAndCrashedText call PrintText ld b, $4 - predef Func_48125 + predef PredefShakeScreenHorizontally ld a, [H_WHOSETURN] and a jr nz, .enemyTurn @@ -3986,7 +4011,7 @@ PrintCriticalOHKOText: ; 3dc5c (f:5c5c) xor a ld [wCriticalHitOrOHKO], a .done - ld c, $14 + ld c, 20 jp DelayFrames CriticalOHKOTextPointers: ; 3dc7a (f:5c7a) @@ -4673,7 +4698,7 @@ CriticalHitTest: ; 3e023 (f:6023) jr z, .calcCriticalHitProbability ld hl, W_ENEMYMOVEPOWER ld de, W_ENEMYBATTSTATUS2 -.calcCriticalHitProbability ; 0x3e04f +.calcCriticalHitProbability ld a, [hld] ; read base power from RAM and a ret z ; do nothing if zero @@ -4772,7 +4797,7 @@ HandleCounterMove: ; 3e093 (f:6093) ld a,[hli] or [hl] ret z ; If we made it here, Counter still misses if the last move used in battle did no damage to its target. - ; W_DAMAGE is shared by both players, so Counter may strike back damage dealt by the Counter user itself + ; W_DAMAGE is shared by both players, so Counter may strike back damage dealt by the Counter user itself ; if the conditions meet, even though 99% of the times damage will come from the target. ; if it did damage, double it ld a,[hl] @@ -4905,7 +4930,7 @@ ApplyDamageToEnemyPokemon: ; 3e142 (f:6142) ld [wHPBarNewHP+1],a ld a,[hl] ld [wHPBarNewHP],a - hlCoord 2, 2 + coord hl, 2, 2 xor a ld [wHPBarType],a predef UpdateHPBar2 ; animate the HP bar shortening @@ -5023,7 +5048,7 @@ ApplyDamageToPlayerPokemon: ; 3e200 (f:6200) ld [wHPBarMaxHP+1],a ld a,[hl] ld [wHPBarMaxHP],a - hlCoord 10, 9 + coord hl, 10, 9 ld a,$01 ld [wHPBarType],a predef UpdateHPBar2 ; animate the HP bar shortening @@ -5033,9 +5058,9 @@ ApplyAttackToPlayerPokemonDone AttackSubstitute: ; 3e25e (f:625e) ; Unlike the two ApplyAttackToPokemon functions, Attack Substitute is shared by player and enemy. ; Self-confusion damage as well as Hi-Jump Kick and Jump Kick recoil cause a momentary turn swap before being applied. -; If the user has a Substitute up and would take damage because of that, +; If the user has a Substitute up and would take damage because of that, ; damage will be applied to the other player's Substitute. -; Normal recoil such as from Double-Edge isn't affected by this glitch, +; Normal recoil such as from Double-Edge isn't affected by this glitch, ; because this function is never called in that case. ld hl,SubstituteTookDamageText @@ -5060,7 +5085,7 @@ AttackSubstitute: ; 3e25e (f:625e) ld [de],a ret nc .substituteBroke -; If the target's Substitute breaks, W_DAMAGE isn't updated with the amount of HP +; If the target's Substitute breaks, W_DAMAGE isn't updated with the amount of HP ; the Substitute had before being attacked. ld h,b ld l,c @@ -5071,7 +5096,7 @@ AttackSubstitute: ; 3e25e (f:625e) ld a,[H_WHOSETURN] xor a,$01 ld [H_WHOSETURN],a - callab Func_79747 ; animate the substitute breaking + callab HideSubstituteShowMonAnim ; animate the substitute breaking ; flip the turn back to the way it was ld a,[H_WHOSETURN] xor a,$01 @@ -5181,7 +5206,7 @@ ReloadMoveData: ; 3e329 (f:6329) ld [wd11e],a dec a ld hl,Moves - ld bc,$0006 + ld bc,MoveEnd - Moves call AddNTimes ld a,BANK(Moves) call FarCopyData ; copy the move's stats @@ -5266,7 +5291,7 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5) ld d,a ; d = type 1 of defender ld e,[hl] ; e = type 2 of defender ld a,[W_PLAYERMOVETYPE] - ld [wd11e],a + ld [wMoveType],a ld a,[H_WHOSETURN] and a jr z,.next @@ -5280,9 +5305,9 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5) ld d,a ; d = type 1 of defender ld e,[hl] ; e = type 2 of defender ld a,[W_ENEMYMOVETYPE] - ld [wd11e],a + ld [wMoveType],a .next - ld a,[wd11e] ; move type + ld a,[wMoveType] cp b ; does the move type match type 1 of the attacker? jr z,.sameTypeAttackBonus cp c ; does the move type match type 2 of the attacker? @@ -5307,8 +5332,8 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5) ld hl,wDamageMultipliers set 7,[hl] .skipSameTypeAttackBonus - ld a,[wd11e] - ld b,a ; b = move type + ld a,[wMoveType] + ld b,a ld hl,TypeEffects .loop ld a,[hli] ; a = "attacking type" of the current type pair @@ -5371,29 +5396,29 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5) ; function to tell how effective the type of an enemy attack is on the player's current pokemon ; this doesn't take into account the effects that dual types can have ; (e.g. 4x weakness / resistance, weaknesses and resistances canceling) -; the result is stored in [wd11e] +; the result is stored in [wTypeEffectiveness] ; ($05 is not very effective, $10 is neutral, $14 is super effective) ; as far is can tell, this is only used once in some AI code to help decide which move to use AIGetTypeEffectiveness: ; 3e449 (f:6449) ld a,[W_ENEMYMOVETYPE] - ld d,a ; d = type of enemy move + ld d,a ; d = type of enemy move ld hl,wBattleMonType - ld b,[hl] ; b = type 1 of player's pokemon + ld b,[hl] ; b = type 1 of player's pokemon inc hl - ld c,[hl] ; c = type 2 of player's pokemon + ld c,[hl] ; c = type 2 of player's pokemon ld a,$10 - ld [wd11e],a ; initialize [wd11e] to neutral effectiveness + ld [wTypeEffectiveness],a ; initialize to neutral effectiveness ld hl,TypeEffects .loop ld a,[hli] cp a,$ff ret z - cp d ; match the type of the move + cp d ; match the type of the move jr nz,.nextTypePair1 ld a,[hli] - cp b ; match with type 1 of pokemon + cp b ; match with type 1 of pokemon jr z,.done - cp c ; or match with type 2 of pokemon + cp c ; or match with type 2 of pokemon jr z,.done jr .nextTypePair2 .nextTypePair1 @@ -5403,7 +5428,7 @@ AIGetTypeEffectiveness: ; 3e449 (f:6449) jr .loop .done ld a,[hl] - ld [wd11e],a ; store damage multiplier + ld [wTypeEffectiveness],a ; store damage multiplier ret INCLUDE "data/type_effects.asm" @@ -5561,7 +5586,7 @@ CalcHitChance: ; 3e624 (f:6624) ; the second iteration multiplies by the evasion ratio .loop push bc - ld hl, StatModifierRatios ; $76cb ; stat modifier ratios + ld hl, StatModifierRatios ; stat modifier ratios dec b sla b ld c,b @@ -5749,8 +5774,8 @@ playEnemyMoveAnimation: ; 3e7a4 (f:67a4) push af ld a, [W_ENEMYBATTSTATUS2] bit HasSubstituteUp, a ; does mon have a substitute? - ld hl, Func_79747 - ld b, BANK(Func_79747) + ld hl, HideSubstituteShowMonAnim + ld b, BANK(HideSubstituteShowMonAnim) call nz, Bankswitch pop af ld [wAnimationType], a @@ -5760,14 +5785,14 @@ playEnemyMoveAnimation: ; 3e7a4 (f:67a4) call DrawEnemyHUDAndHPBar ld a, [W_ENEMYBATTSTATUS2] bit HasSubstituteUp, a ; does mon have a substitute? - ld hl, Func_79771 - ld b, BANK(Func_79771) + ld hl, ReshowSubstituteAnim + ld b, BANK(ReshowSubstituteAnim) call nz, Bankswitch ; slide the substitute's sprite out jr EnemyCheckIfMirrorMoveEffect EnemyCheckIfFlyOrChargeEffect: ; 3e7d1 (f:67d1) call SwapPlayerAndEnemyLevels - ld c, $1e + ld c, 30 call DelayFrames ld a, [W_ENEMYMOVEEFFECT] cp FLY_EFFECT @@ -6019,7 +6044,7 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f) .monHurtItselfOrFullyParalysed ld hl, W_ENEMYBATTSTATUS1 ld a, [hl] - ; clear bide, thrashing about, charging up, and multi-turn moves such as warp + ; clear bide, thrashing about, charging up, and multi-turn moves such as warp and $ff ^ ((1 << StoringEnergy) | (1 << ThrashingAbout) | (1 << ChargingUp) | (1 << UsingTrappingMove)) ld [hl], a ld a, [W_ENEMYMOVEEFFECT] @@ -6115,7 +6140,7 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f) call PrintText ld hl, wEnemyNumAttacksLeft dec [hl] ; did multi-turn move end? - ld hl, GetEnemyAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit), + ld hl, GetEnemyAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit), ; DecrementPP and MoveHitTest jp nz, .enemyReturnToHL jp .enemyReturnToHL @@ -6149,15 +6174,15 @@ GetCurrentMove: ; 3eabe (f:6abe) .player ld de, W_PLAYERMOVENUM ld a, [W_FLAGS_D733] - bit 0, a - ld a, [wccd9] + bit BIT_TEST_BATTLE, a + ld a, [wTestBattlePlayerSelectedMove] jr nz, .selected ld a, [wPlayerSelectedMove] .selected ld [wd0b5], a dec a ld hl, Moves - ld bc, $6 + ld bc, MoveEnd - Moves call AddNTimes ld a, BANK(Moves) call FarCopyData @@ -6180,7 +6205,7 @@ LoadEnemyMonData: ; 3eb01 (f:6b01) call GetMonHeader ld a, [W_ENEMYBATTSTATUS3] bit Transformed, a ; is enemy mon transformed? - ld hl, wcceb ; copied DVs from when it used Transform + ld hl, wTransformedEnemyMonOriginalDVs ; original DVs before transforming ld a, [hli] ld b, [hl] jr nz, .storeDVs @@ -6279,15 +6304,15 @@ LoadEnemyMonData: ; 3eb01 (f:6b01) dec de dec de xor a - ld [wHPBarMaxHP], a + ld [wLearningMovesFromDayCare], a predef WriteMonMoves ; get moves based on current level .loadMovePPs ld hl, wEnemyMonMoves - ld de, wEnemyMonSpecial + 1 + ld de, wEnemyMonPP - 1 predef LoadMovePPs ld hl, W_MONHBASESTATS ld de, wEnemyMonBaseStats - ld b, $5 + ld b, NUM_STATS .copyBaseStatsLoop ld a, [hli] ld [de], a @@ -6305,7 +6330,7 @@ LoadEnemyMonData: ; 3eb01 (f:6b01) call GetMonName ld hl, wcd6d ld de, wEnemyMonNick - ld bc, $b + ld bc, NAME_LENGTH call CopyData ld a, [wEnemyMonSpecies2] ld [wd11e], a @@ -6313,15 +6338,15 @@ LoadEnemyMonData: ; 3eb01 (f:6b01) ld a, [wd11e] dec a ld c, a - ld b, $1 + ld b, FLAG_SET ld hl, wPokedexSeen predef FlagActionPredef ; mark this mon as seen in the pokedex ld hl, wEnemyMonLevel ld de, wEnemyMonUnmodifiedLevel - ld bc, $b + ld bc, 1 + NUM_STATS * 2 call CopyData ld a, $7 ; default stat mod - ld b, $8 ; number of stat mods + ld b, NUM_STAT_MODS ; number of stat mods ld hl, wEnemyMonStatMods .statModLoop ld [hli], a @@ -6392,7 +6417,7 @@ LoadPlayerBackPic: ; 3ec92 (f:6c92) predef ScaleSpriteByTwo ld hl, wOAMBuffer xor a - ld [$FF8B], a ; initial tile number + ld [hOAMTile], a ; initial tile number ld b, $7 ; 7 columns ld e, $a0 ; X for the left-most column .loop ; each loop iteration writes 3 OAM entries in a vertical column @@ -6406,16 +6431,16 @@ LoadPlayerBackPic: ; 3ec92 (f:6c92) add d ; increase Y by height of tile ld d, a inc hl - ld a, [$FF8B] + ld a, [hOAMTile] ld [hli], a ; OAM tile number inc a ; increment tile number - ld [$FF8B], a + ld [hOAMTile], a inc hl dec c jr nz, .innerLoop - ld a, [$FF8B] + ld a, [hOAMTile] add $4 ; increase tile number by 4 - ld [$FF8B], a + ld [hOAMTile], a ld a, $8 ; width of tile add e ; increase X by width of tile ld e, a @@ -6436,21 +6461,17 @@ LoadPlayerBackPic: ; 3ec92 (f:6c92) xor a ld [$0], a ld a, $31 - ld [$ffe1], a - hlCoord 1, 5 - predef_jump Func_3f0c6 + ld [hStartTileID], a + coord hl, 1, 5 + predef_jump CopyUncompressedPicToTilemap ; does nothing since no stats are ever selected (barring glitches) DoubleOrHalveSelectedStats: ; 3ed02 (f:6d02) callab DoubleSelectedStats - ld hl, HalveSelectedStats - ld b, BANK(HalveSelectedStats) - jp Bankswitch + jpab HalveSelectedStats ScrollTrainerPicAfterBattle: ; 3ed12 (f:6d12) - ld hl, _ScrollTrainerPicAfterBattle - ld b, BANK(_ScrollTrainerPicAfterBattle) - jp Bankswitch + jpab _ScrollTrainerPicAfterBattle ApplyBurnAndParalysisPenaltiesToPlayer: ; 3ed1a (f:6d1a) ld a, $1 @@ -6552,7 +6573,7 @@ CalculateModifiedStats: ; 3ed99 (f:6d99) call CalculateModifiedStat inc c ld a, c - cp 4 + cp NUM_STATS - 1 jr nz, .loop ret @@ -6560,12 +6581,12 @@ CalculateModifiedStats: ; 3ed99 (f:6d99) CalculateModifiedStat: ; 3eda5 (f:6da5) push bc push bc - ld a, [wd11e] + ld a, [wCalculateWhoseStats] and a ld a, c ld hl, wBattleMonAttack ld de, wPlayerMonUnmodifiedAttack - ld bc, wPlayerMonAttackMod + ld bc, wPlayerMonStatMods jr z, .next ld hl, wEnemyMonAttack ld de, wEnemyMonUnmodifiedAttack @@ -6698,22 +6719,22 @@ LoadHudTilePatterns: ; 3ee5b (f:6e5b) .lcdDisabled ld hl, BattleHudTiles1 ld de, vChars2 + $6d0 - ld bc, $18 + ld bc, BattleHudTiles1End - BattleHudTiles1 ld a, BANK(BattleHudTiles1) call FarCopyDataDouble ld hl, BattleHudTiles2 ld de, vChars2 + $730 - ld bc, $30 + ld bc, BattleHudTiles3End - BattleHudTiles2 ld a, BANK(BattleHudTiles2) jp FarCopyDataDouble .lcdEnabled ld de, BattleHudTiles1 ld hl, vChars2 + $6d0 - ld bc, (BANK(BattleHudTiles1) << 8) + $03 + lb bc, BANK(BattleHudTiles1), (BattleHudTiles1End - BattleHudTiles1) / $8 call CopyVideoDataDouble ld de, BattleHudTiles2 ld hl, vChars2 + $730 - ld bc, (BANK(BattleHudTiles2) << 8) + $06 + lb bc, BANK(BattleHudTiles2), (BattleHudTiles3End - BattleHudTiles2) / $8 jp CopyVideoDataDouble PrintEmptyString: ; 3ee94 (f:6e94) @@ -6749,8 +6770,8 @@ BattleRandom: push hl push bc push af - -; point to seed 0 so we pick the first number the next time + +; point to seed 0 so we pick the first number the next time xor a ld [wLinkBattleRandomNumberListIndex], a @@ -6759,11 +6780,11 @@ BattleRandom: .loop ld a, [hl] ld c, a -; multiply by 5 +; multiply by 5 add a add a add c -; add 1 +; add 1 inc a ld [hli], a dec b @@ -6778,11 +6799,11 @@ BattleRandom: HandleExplodingAnimation: ; 3eed3 (f:6ed3) ld a, [H_WHOSETURN] and a - ld hl, wEnemyMonType1 ; wcfea + ld hl, wEnemyMonType1 ld de, W_ENEMYBATTSTATUS1 ld a, [W_PLAYERMOVENUM] jr z, .asm_3eeea - ld hl, wBattleMonType1 ; wd019 + ld hl, wBattleMonType1 ld de, W_ENEMYBATTSTATUS1 ld a, [W_ENEMYMOVENUM] .asm_3eeea @@ -6812,10 +6833,10 @@ PlayMoveAnimation: ; 3ef07 (f:6f07) predef_jump MoveAnimation ; unreferenced -Func_3f069: ; 3f069 (f:7069) +ResetCryModifiers: ; 3f069 (f:7069) xor a - ld [wc0f1], a - ld [wc0f2], a + ld [wFrequencyModifier], a + ld [wTempoModifier], a jp PlaySound JumpMoveEffect: ; 3f132 (f:7132) @@ -7063,7 +7084,7 @@ PoisonEffect: ; 3f24f (f:724f) cp POISON_EFFECT ret nz .didntAffect - ld c, $32 + ld c, 50 call DelayFrames jp PrintDidntAffectText @@ -7076,9 +7097,7 @@ BadlyPoisonedText: ; 3f2e4 (f:72e4) db "@" DrainHPEffect: ; 3f2e9 (f:72e9) - ld hl, DrainHPEffect_ - ld b, BANK(DrainHPEffect_) - jp Bankswitch + jpab DrainHPEffect_ ExplodeEffect: ; 3f2f1 (f:72f1) ld hl, wBattleMonHP @@ -7325,17 +7344,17 @@ StatModifierUpEffect: ; 3f428 (f:7428) add hl, bc pop bc xor a - ld [H_MULTIPLICAND], a + ld [H_MULTIPLICAND], a ld a, [de] ld [H_MULTIPLICAND + 1], a inc de ld a, [de] ld [H_MULTIPLICAND + 2], a ld a, [hli] - ld [H_MULTIPLIER], a + ld [H_MULTIPLIER], a call Multiply ld a, [hl] - ld [H_DIVISOR], a + ld [H_DIVISOR], a ld b, $4 call Divide pop hl @@ -7359,27 +7378,29 @@ UpdateStat: ; 3f4c3 (f:74c3) UpdateStatDone: ; 3f4ca (f:74ca) ld b, c inc b - call Func_3f688 + call PrintStatText ld hl, W_PLAYERBATTSTATUS2 ld de, W_PLAYERMOVENUM - ld bc, wccf7 + ld bc, wPlayerMonMinimized ld a, [H_WHOSETURN] and a jr z, .asm_3f4e6 ld hl, W_ENEMYBATTSTATUS2 ld de, W_ENEMYMOVENUM - ld bc, wccf3 + ld bc, wEnemyMonMinimized .asm_3f4e6 ld a, [de] cp MINIMIZE jr nz, .asm_3f4f9 - bit HasSubstituteUp, [hl] ; substitute + ; if a substitute is up, slide off the substitute and show the mon pic before + ; playing the minimize animation + bit HasSubstituteUp, [hl] push af push bc - ld hl, Func_79747 - ld b, BANK(Func_79747) + ld hl, HideSubstituteShowMonAnim + ld b, BANK(HideSubstituteShowMonAnim) push de - call nz, Bankswitch ; play Minimize animation unless there's Substitute involved + call nz, Bankswitch pop de .asm_3f4f9 call PlayCurrentMoveAnimation @@ -7389,8 +7410,8 @@ UpdateStatDone: ; 3f4ca (f:74ca) pop bc ld a, $1 ld [bc], a - ld hl, Func_79771 - ld b, BANK(Func_79771) + ld hl, ReshowSubstituteAnim + ld b, BANK(ReshowSubstituteAnim) pop af call nz, Bankswitch .applyBadgeBoostsAndStatusPenalties @@ -7415,7 +7436,7 @@ PrintNothingHappenedText: ; 3f522 (f:7522) MonsStatsRoseText: ; 3f528 (f:7528) TX_FAR _MonsStatsRoseText - db $08 ; asm + TX_ASM ld hl, GreatlyRoseText ld a, [H_WHOSETURN] and a @@ -7529,7 +7550,7 @@ StatModifierDownEffect: ; 3f54c (f:754c) jr nz, .recalculateStat ld a, [hl] and a - jp z, Func_3f64d + jp z, CantLowerAnymore_Pop .recalculateStat ; recalculate affected stat ; paralysis and burn penalties, as well as badge boosts are ignored @@ -7543,17 +7564,17 @@ StatModifierDownEffect: ; 3f54c (f:754c) add hl, bc pop bc xor a - ld [H_MULTIPLICAND], a + ld [H_MULTIPLICAND], a ld a, [de] ld [H_MULTIPLICAND + 1], a inc de ld a, [de] ld [H_MULTIPLICAND + 2], a ld a, [hli] - ld [H_MULTIPLIER], a + ld [H_MULTIPLIER], a call Multiply ld a, [hl] - ld [H_DIVISOR], a + ld [H_DIVISOR], a ld b, $4 call Divide pop hl @@ -7577,7 +7598,7 @@ UpdateLoweredStatDone: ; 3f62c (f:762c) ld b, c inc b push de - call Func_3f688 + call PrintStatText pop de ld a, [de] cp $44 @@ -7597,7 +7618,7 @@ UpdateLoweredStatDone: ; 3f62c (f:762c) call QuarterSpeedDueToParalysis jp HalveAttackDueToBurn -Func_3f64d: ; 3f64d (f:764d) +CantLowerAnymore_Pop: ; 3f64d (f:764d) pop de pop hl inc [hl] @@ -7617,7 +7638,7 @@ MoveMissed: ; 3f65a (f:765a) MonsStatsFellText: ; 3f661 (f:7661) TX_FAR _MonsStatsFellText - db $08 ; asm + TX_ASM ld hl, FellText ld a, [H_WHOSETURN] and a @@ -7640,9 +7661,9 @@ FellText: ; 3f683 (f:7683) TX_FAR _FellText db "@" -Func_3f688: ; 3f688 (f:7688) +PrintStatText: ; 3f688 (f:7688) ld hl, StatsTextStrings - ld c, $50 + ld c, "@" .asm_3f68d dec b jr z, .asm_3f696 @@ -7749,7 +7770,7 @@ SwitchAndTeleportEffect: ; 3f739 (f:7739) srl b cp b jr nc, .asm_3f76e - ld c, $32 + ld c, 50 call DelayFrames ld a, [W_PLAYERMOVENUM] cp TELEPORT @@ -7764,7 +7785,7 @@ SwitchAndTeleportEffect: ; 3f739 (f:7739) ld a, [W_PLAYERMOVENUM] jr .asm_3f7e4 .asm_3f77e - ld c, $32 + ld c, 50 call DelayFrames ld hl, IsUnaffectedText ld a, [W_PLAYERMOVENUM] @@ -7791,7 +7812,7 @@ SwitchAndTeleportEffect: ; 3f739 (f:7739) srl b cp b jr nc, .asm_3f7c1 - ld c, $32 + ld c, 50 call DelayFrames ld a, [W_ENEMYMOVENUM] cp TELEPORT @@ -7806,7 +7827,7 @@ SwitchAndTeleportEffect: ; 3f739 (f:7739) ld a, [W_ENEMYMOVENUM] jr .asm_3f7e4 .asm_3f7d1 - ld c, $32 + ld c, 50 call DelayFrames ld hl, IsUnaffectedText ld a, [W_ENEMYMOVENUM] @@ -7816,7 +7837,7 @@ SwitchAndTeleportEffect: ; 3f739 (f:7739) .asm_3f7e4 push af call PlayBattleAnimation - ld c, $14 + ld c, 20 call DelayFrames pop af ld hl, RanFromBattleText @@ -7911,9 +7932,7 @@ FlinchSideEffect: ; 3f85b (f:785b) ret OneHitKOEffect: ; 3f884 (f:7884) - ld hl, OneHitKOEffect_ - ld b, BANK(OneHitKOEffect_) - jp Bankswitch + jpab OneHitKOEffect_ ChargeEffect: ; 3f88c (f:788c) ld hl, W_PLAYERBATTSTATUS1 @@ -7945,14 +7964,14 @@ ChargeEffect: ; 3f88c (f:788c) ld a, b call PlayBattleAnimation ld a, [de] - ld [wWhichTrade], a + ld [wChargeMoveNum], a ld hl, ChargeMoveEffectText jp PrintText ChargeMoveEffectText: ; 3f8c8 (f:78c8) TX_FAR _ChargeMoveEffectText - db $08 ; asm - ld a, [wWhichTrade] + TX_ASM + ld a, [wChargeMoveNum] cp RAZOR_WIND ld hl, MadeWhirlwindText jr z, .asm_3f8f8 @@ -8008,8 +8027,8 @@ TrappingEffect: ; 3f917 (f:7917) .trappingEffect bit UsingTrappingMove, [hl] ret nz - call ClearHyperBeam ; since this effect is called before testing whether the move will hit, - ; the target won't need to recharge even if the trapping move missed + call ClearHyperBeam ; since this effect is called before testing whether the move will hit, + ; the target won't need to recharge even if the trapping move missed set UsingTrappingMove, [hl] ; mon is now using a trapping move call BattleRandom ; 3/8 chance for 2 and 3 attacks, and 1/8 chance for 4 and 5 attacks and $3 @@ -8023,19 +8042,13 @@ TrappingEffect: ; 3f917 (f:7917) ret MistEffect: ; 3f941 (f:7941) - ld hl, MistEffect_ - ld b, BANK(MistEffect_) - jp Bankswitch + jpab MistEffect_ FocusEnergyEffect: ; 3f949 (f:7949) - ld hl, FocusEnergyEffect_ - ld b, BANK(FocusEnergyEffect_) - jp Bankswitch + jpab FocusEnergyEffect_ RecoilEffect: ; 3f951 (f:7951) - ld hl, RecoilEffect_ - ld b, BANK(RecoilEffect_) - jp Bankswitch + jpab RecoilEffect_ ConfusionSideEffect: ; 3f959 (f:7959) call BattleRandom @@ -8067,7 +8080,7 @@ ConfusionSideEffectSuccess: ; 3f96f (f:796f) set Confused, [hl] ; mon is now confused push af call BattleRandom - and $3 + and $3 inc a inc a ld [bc], a ; confusion status will last 2-5 turns @@ -8084,19 +8097,15 @@ BecameConfusedText: ; 3f9a1 (f:79a1) ConfusionEffectFailed: ; 3f9a6 (f:79a6) cp CONFUSION_SIDE_EFFECT ret z - ld c, $32 + ld c, 50 call DelayFrames jp ConditionalPrintButItFailed ParalyzeEffect: ; 3f9b1 (f:79b1) - ld hl, ParalyzeEffect_ - ld b, BANK(ParalyzeEffect_) - jp Bankswitch + jpab ParalyzeEffect_ SubstituteEffect: ; 3f9b9 (f:79b9) - ld hl, SubstituteEffect_ - ld b, BANK(SubstituteEffect_) - jp Bankswitch + jpab SubstituteEffect_ HyperBeamEffect: ; 3f9c1 (f:79c1) ld hl, W_PLAYERBATTSTATUS2 @@ -8131,7 +8140,7 @@ RageEffect: ; 3f9df (f:79df) ret MimicEffect: ; 3f9ed (f:79ed) - ld c, $32 + ld c, 50 call DelayFrames call MoveHitTest ld a, [W_MOVEMISSED] @@ -8207,9 +8216,7 @@ MimicLearnedMoveText: ; 3fa77 (f:7a77) db "@" LeechSeedEffect: ; 3fa7c (f:7a7c) - ld hl, LeechSeedEffect_ - ld b, BANK(LeechSeedEffect_) - jp Bankswitch + jpab LeechSeedEffect_ SplashEffect: ; 3fa84 (f:7a84) call PlayCurrentMoveAnimation @@ -8248,12 +8255,12 @@ DisableEffect: ; 3fa8a (f:7a8a) ld a, [H_WHOSETURN] and a ld hl, wBattleMonPP - jr nz, .enemyTurn + jr nz, .enemyTurn ld a, [wLinkState] cp LINK_STATE_BATTLING pop hl ; wEnemyMonMoves jr nz, .playerTurnNotLinkBattle -; .playerTurnLinkBattle +; .playerTurnLinkBattle push hl ld hl, wEnemyMonPP .enemyTurn @@ -8278,7 +8285,7 @@ DisableEffect: ; 3fa8a (f:7a8a) and $7 inc a ; 1-8 turns disabled inc c ; move 1-4 will be disabled - swap c + swap c add c ; map disabled move to high nibble of W_ENEMYDISABLEDMOVE / W_PLAYERDISABLEDMOVE ld [de], a call PlayCurrentMoveAnimation2 @@ -8289,7 +8296,7 @@ DisableEffect: ; 3fa8a (f:7a8a) inc hl ; wEnemyDisabledMoveNumber .printDisableText ld a, [wd11e] ; move number - ld [hl], a + ld [hl], a call GetMoveName ld hl, MoveWasDisabledText jp PrintText @@ -8303,34 +8310,22 @@ MoveWasDisabledText: ; 3fb09 (f:7b09) db "@" PayDayEffect: ; 3fb0e (f:7b0e) - ld hl, PayDayEffect_ - ld b, BANK(PayDayEffect_) - jp Bankswitch + jpab PayDayEffect_ ConversionEffect: ; 3fb16 (f:7b16) - ld hl, ConversionEffect_ - ld b, BANK(ConversionEffect_) - jp Bankswitch + jpab ConversionEffect_ HazeEffect: ; 3fb1e (f:7b1e) - ld hl, HazeEffect_ - ld b, BANK(HazeEffect_) - jp Bankswitch + jpab HazeEffect_ HealEffect: ; 3fb26 (f:7b26) - ld hl, HealEffect_ - ld b, BANK(HealEffect_) - jp Bankswitch + jpab HealEffect_ TransformEffect: ; 3fb2e (f:7b2e) - ld hl, TransformEffect_ - ld b, BANK(TransformEffect_) - jp Bankswitch + jpab TransformEffect_ ReflectLightScreenEffect: ; 3fb36 (f:7b36) - ld hl, ReflectLightScreenEffect_ - ld b, BANK(ReflectLightScreenEffect_) - jp Bankswitch + jpab ReflectLightScreenEffect_ NothingHappenedText: ; 3fb3e (f:7b3e) TX_FAR _NothingHappenedText @@ -8380,12 +8375,12 @@ ParalyzedMayNotAttackText: ; 3fb74 (f:7b74) CheckTargetSubstitute: ; 3fb79 (f:7b79) push hl ld hl, W_ENEMYBATTSTATUS2 - ld a, [H_WHOSETURN] + ld a, [H_WHOSETURN] and a jr z, .next1 ld hl, W_PLAYERBATTSTATUS2 .next1 - bit HasSubstituteUp, [hl] + bit HasSubstituteUp, [hl] pop hl ret diff --git a/engine/battle/decrement_pp.asm b/engine/battle/decrement_pp.asm index 7774070c..c6a9f2b5 100644 --- a/engine/battle/decrement_pp.asm +++ b/engine/battle/decrement_pp.asm @@ -9,15 +9,15 @@ DecrementPP: ; f42db (3d:42db) ; W_PLAYERBATTSTATUS2 status flags later and a, (1 << StoringEnergy) | (1 << ThrashingAbout) | (1 << AttackingMultipleTimes) ret nz ; if any of these statuses are true, don't decrement PP - bit UsingRage, [hl] + bit UsingRage, [hl] ret nz ; don't decrement PP either if Pokemon is using Rage ld hl, wBattleMonPP ; PP of first move (in battle) - -; decrement PP in the battle struct - call .DecrementPP - -; decrement PP in the party struct - ld a, [W_PLAYERBATTSTATUS3] + +; decrement PP in the battle struct + call .DecrementPP + +; decrement PP in the party struct + ld a, [W_PLAYERBATTSTATUS3] bit Transformed, a ret nz ; Return if transformed. Pokemon Red stores the "current pokemon's" PP ; separately from the "Pokemon in your party's" PP. This is @@ -31,7 +31,7 @@ DecrementPP: ; f42db (3d:42db) ld hl, wPartyMon1PP ; PP of first move (in party) ld a, [wPlayerMonNumber] ; which mon in party is active - ld bc, wPartyMon2 - wPartyMon1 + ld bc, wPartyMon2 - wPartyMon1 call AddNTimes ; calculate address of the mon to modify .DecrementPP ; f4301 (3d:4301) ld a, [wPlayerMoveListIndex] ; which move (0, 1, 2, 3) did we use? diff --git a/engine/battle/draw_hud_pokeball_gfx.asm b/engine/battle/draw_hud_pokeball_gfx.asm index fce3701c..c1387b7b 100644 --- a/engine/battle/draw_hud_pokeball_gfx.asm +++ b/engine/battle/draw_hud_pokeball_gfx.asm @@ -1,46 +1,46 @@ DrawAllPokeballs: ; 3a849 (e:6849) call LoadPartyPokeballGfx call SetupOwnPartyPokeballs - ld a, [W_ISINBATTLE] ; W_ISINBATTLE + ld a, [W_ISINBATTLE] dec a ret z ; return if wild pokémon jp SetupEnemyPartyPokeballs -DrawEnemyPokeballs: ; 0x3a857 +DrawEnemyPokeballs: ; 3a857 (e:6857) call LoadPartyPokeballGfx jp SetupEnemyPartyPokeballs LoadPartyPokeballGfx: ; 3a85d (e:685d) - ld de, PokeballTileGraphics ; $697e + ld de, PokeballTileGraphics ld hl, vSprites + $310 - ld bc, (BANK(PokeballTileGraphics) << 8) + $04 + lb bc, BANK(PokeballTileGraphics), (PokeballTileGraphicsEnd - PokeballTileGraphics) / $10 jp CopyVideoData SetupOwnPartyPokeballs: ; 3a869 (e:6869) call PlacePlayerHUDTiles ld hl, wPartyMon1 - ld de, wPartyCount ; wPartyCount + ld de, wPartyCount call SetupPokeballs ld a, $60 - ld hl, W_BASECOORDX ; wd081 + ld hl, W_BASECOORDX ld [hli], a ld [hl], a - ld a, $8 - ld [wTrainerEngageDistance], a + ld a, 8 + ld [wHUDPokeballGfxOffsetX], a ld hl, wOAMBuffer jp WritePokeballOAMData SetupEnemyPartyPokeballs: ; 3a887 (e:6887) call PlaceEnemyHUDTiles ld hl, wEnemyMons - ld de, wEnemyPartyCount ; wEnemyPartyCount + ld de, wEnemyPartyCount call SetupPokeballs - ld hl, W_BASECOORDX ; wd081 + ld hl, W_BASECOORDX ld a, $48 ld [hli], a ld [hl], $20 - ld a, $f8 - ld [wTrainerEngageDistance], a + ld a, -8 + ld [wHUDPokeballGfxOffsetX], a ld hl, wOAMBuffer + PARTY_LENGTH * 4 jp WritePokeballOAMData @@ -90,39 +90,39 @@ PickPokeball: ; 3a8c2 (e:68c2) .done ld a, b ld [de], a - ld bc, $0028 ; rest of mon struct - add hl, bc + ld bc, wPartyMon2 - wPartyMon1Status + add hl, bc ; next mon struct ret WritePokeballOAMData: ; 3a8e1 (e:68e1) ld de, wBuffer ld c, PARTY_LENGTH .loop - ld a, [W_BASECOORDY] ; wd082 + ld a, [W_BASECOORDY] ld [hli], a - ld a, [W_BASECOORDX] ; wd081 + ld a, [W_BASECOORDX] ld [hli], a ld a, [de] ld [hli], a xor a ld [hli], a - ld a, [W_BASECOORDX] ; wd081 + ld a, [W_BASECOORDX] ld b, a - ld a, [wTrainerEngageDistance] + ld a, [wHUDPokeballGfxOffsetX] add b - ld [W_BASECOORDX], a ; wd081 + ld [W_BASECOORDX], a inc de dec c jr nz, .loop ret PlacePlayerHUDTiles: ; 3a902 (e:6902) - ld hl, PlayerBattleHUDGraphicsTiles ; $6916 - ld de, wTrainerFacingDirection + ld hl, PlayerBattleHUDGraphicsTiles + ld de, wHUDGraphicsTiles ld bc, $3 call CopyData - hlCoord 18, 10 - ld de, rIE ; $ffff + coord hl, 18, 10 + ld de, -1 jr PlaceHUDTiles PlayerBattleHUDGraphicsTiles: ; 3a916 (e:6916) @@ -132,11 +132,11 @@ PlayerBattleHUDGraphicsTiles: ; 3a916 (e:6916) db $6F ; lower-left triangle tile of the HUD PlaceEnemyHUDTiles: ; 3a919 (e:6919) - ld hl, EnemyBattleHUDGraphicsTiles ; $692d - ld de, wTrainerFacingDirection + ld hl, EnemyBattleHUDGraphicsTiles + ld de, wHUDGraphicsTiles ld bc, $3 call CopyData - hlCoord 1, 2 + coord hl, 1, 2 ld de, $1 jr PlaceHUDTiles @@ -148,38 +148,38 @@ EnemyBattleHUDGraphicsTiles: ; 3a92d (e:692d) PlaceHUDTiles: ; 3a930 (e:6930) ld [hl], $73 - ld bc, $14 + ld bc, SCREEN_WIDTH add hl, bc - ld a, [wTrainerScreenY] + ld a, [wHUDGraphicsTiles + 1] ; leftmost tile ld [hl], a - ld a, $8 -.asm_3a93c + ld a, 8 +.loop add hl, de ld [hl], $76 dec a - jr nz, .asm_3a93c + jr nz, .loop add hl, de - ld a, [wTrainerScreenX] + ld a, [wHUDGraphicsTiles + 2] ; rightmost tile ld [hl], a ret SetupPlayerAndEnemyPokeballs: ; 3a948 (e:6948) call LoadPartyPokeballGfx - ld hl, wPartyMon1Species ; wPartyMon1Species (aliases: wPartyMon1) - ld de, wPartyCount ; wPartyCount + ld hl, wPartyMons + ld de, wPartyCount call SetupPokeballs - ld hl, W_BASECOORDX ; wd081 + ld hl, W_BASECOORDX ld a, $50 ld [hli], a ld [hl], $40 - ld a, $8 - ld [wTrainerEngageDistance], a + ld a, 8 + ld [wHUDPokeballGfxOffsetX], a ld hl, wOAMBuffer call WritePokeballOAMData - ld hl, wEnemyMons ; wEnemyMon1Species - ld de, wEnemyPartyCount ; wEnemyPartyCount + ld hl, wEnemyMons + ld de, wEnemyPartyCount call SetupPokeballs - ld hl, W_BASECOORDX ; wd081 + ld hl, W_BASECOORDX ld a, $50 ld [hli], a ld [hl], $68 @@ -189,3 +189,4 @@ SetupPlayerAndEnemyPokeballs: ; 3a948 (e:6948) ; four tiles: pokeball, black pokeball (status ailment), crossed out pokeball (faited) and pokeball slot (no mon) PokeballTileGraphics:: ; 3a97e (e:697e) INCBIN "gfx/pokeball.2bpp" +PokeballTileGraphicsEnd: diff --git a/engine/battle/end_of_battle.asm b/engine/battle/end_of_battle.asm index 5d78af5b..f1de313c 100755 --- a/engine/battle/end_of_battle.asm +++ b/engine/battle/end_of_battle.asm @@ -19,9 +19,9 @@ EndOfBattle: ; 137aa (4:77aa) jr z, .placeWinOrLoseString ld de, DrawText .placeWinOrLoseString - hlCoord 6, 8 + coord hl, 6, 8 call PlaceString - ld c, $c8 + ld c, 200 call DelayFrames jr .evolution .notLinkBattle @@ -41,20 +41,20 @@ EndOfBattle: ; 137aa (4:77aa) call PrintText .evolution xor a - ld [wccd4], a + ld [wForceEvolution], a predef EvolutionAfterBattle .resetVariables xor a ld [wLowHealthAlarm], a ;disable low health alarm - ld [wc02a], a + ld [wChannelSoundIDs + CH4], a ld [W_ISINBATTLE], a ld [W_BATTLETYPE], a ld [W_MOVEMISSED], a ld [W_CUROPPONENT], a - ld [wd11f], a + ld [wForcePlayerToChooseMon], a ld [wNumRunAttempts], a ld [wEscapedFromBattle], a - ld hl, wcc2b + ld hl, wPartyAndBillsPCSavedMenuItem ld [hli], a ld [hli], a ld [hli], a diff --git a/engine/battle/experience.asm b/engine/battle/experience.asm index 9bd67654..ab3e3c19 100644 --- a/engine/battle/experience.asm +++ b/engine/battle/experience.asm @@ -15,7 +15,7 @@ GainExperience: ; 5524f (15:524f) ld hl, wPartyGainExpFlags ld a, [wWhichPokemon] ld c, a - ld b, $2 + ld b, FLAG_TEST predef FlagActionPredef ld a, c and a ; is mon's gain exp flag set? @@ -26,7 +26,7 @@ GainExperience: ; 5524f (15:524f) ld d, h ld e, l ld hl, wEnemyMonBaseStats - ld c, $5 + ld c, NUM_STATS .gainStatExpLoop ld a, [hli] ld b, a ; enemy mon base stat @@ -66,7 +66,7 @@ GainExperience: ; 5524f (15:524f) ld [H_DIVISOR], a ld b, 4 call Divide - ld hl, -((wPartyMon1HPExp + 1) - wPartyMon1OTID + 4 * 2) + ld hl, wPartyMon1OTID - (wPartyMon1DVs - 1) add hl, de ld b, [hl] ; party mon OTID inc hl @@ -76,11 +76,11 @@ GainExperience: ; 5524f (15:524f) ld b, [hl] ld a, [wPlayerID + 1] cp b - ld a, $0 + ld a, 0 jr z, .next .tradedMon call BoostExp ; traded mon exp boost - ld a, $1 + ld a, 1 .next ld [wGainBoostedExp], a ld a, [W_ISINBATTLE] @@ -92,12 +92,12 @@ GainExperience: ; 5524f (15:524f) ; add the gained exp to the party mon's exp ld b, [hl] ld a, [H_QUOTIENT + 3] - ld [wcf4c], a + ld [wExpAmountGained + 1], a add b ld [hld], a ld b, [hl] ld a, [H_QUOTIENT + 2] - ld [wcf4b], a + ld [wExpAmountGained], a adc b ld [hl], a jr nc, .noCarry @@ -148,8 +148,8 @@ GainExperience: ; 5524f (15:524f) call GetPartyMonName ld hl, GainedText call PrintText - xor a ; party mon data - ld [wcc49], a + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation], a call LoadMonData pop hl ld bc, wPartyMon1Level - wPartyMon1Exp @@ -220,7 +220,7 @@ GainExperience: ; 5524f (15:524f) add hl, bc push hl ld de, wBattleMonLevel - ld bc, $b ; size of stats + ld bc, 1 + NUM_STATS * 2 ; size of stats call CopyData pop hl ld a, [W_PLAYERBATTSTATUS3] @@ -228,11 +228,11 @@ GainExperience: ; 5524f (15:524f) jr nz, .recalcStatChanges ; the mon is not transformed, so update the unmodified stats ld de, wPlayerMonUnmodifiedLevel - ld bc, $b + ld bc, 1 + NUM_STATS * 2 call CopyData .recalcStatChanges - xor a - ld [wd11e], a + xor a ; battle mon + ld [wCalculateWhoseStats], a callab CalculateModifiedStats callab ApplyBurnAndParalysisPenaltiesToPlayer callab ApplyBadgeStatBoosts @@ -242,22 +242,22 @@ GainExperience: ; 5524f (15:524f) .printGrewLevelText ld hl, GrewLevelText call PrintText - xor a ; party mon data - ld [wcc49], a + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation], a call LoadMonData ld d, $1 callab PrintStatsBox call WaitForTextScrollButtonPress call LoadScreenTilesFromBuffer1 - xor a - ld [wcc49], a + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation], a ld a, [wd0b5] ld [wd11e], a predef LearnMoveFromLevelUp - ld hl, wccd3 + ld hl, wCanEvolveFlags ld a, [wWhichPokemon] ld c, a - ld b, $1 + ld b, FLAG_SET predef FlagActionPredef pop hl pop af @@ -281,7 +281,7 @@ GainExperience: ; 5524f (15:524f) ld [hl], a ; clear gain exp flags ld a, [wPlayerMonNumber] ld c, a - ld b, $1 + ld b, FLAG_SET push bc predef FlagActionPredef ; set the gain exp flag for the mon that is currently out ld hl, wPartyFoughtCurrentEnemyFlags @@ -308,7 +308,7 @@ DivideExpDataByNumMonsGainingExp: ; 5546c (15:546c) ret c ; return if only one mon is gaining exp ld [wd11e], a ; store number of mons gaining exp ld hl, wEnemyMonBaseStats - ld c, $7 + ld c, wEnemyMonBaseExp + 1 - wEnemyMonBaseStats .divideLoop xor a ld [H_DIVIDEND], a @@ -341,7 +341,7 @@ BoostExp: ; 5549f (15:549f) GainedText: ; 554b2 (15:54b2) TX_FAR _GainedText - db $08 ; asm + TX_ASM ld a, [wBoostExpByExpAll] ld hl, WithExpAllText and a @@ -355,7 +355,7 @@ GainedText: ; 554b2 (15:54b2) WithExpAllText: ; 554cb (15:54cb) TX_FAR _WithExpAllText - db $08 ; asm + TX_ASM ld hl, ExpPointsText ret diff --git a/engine/battle/ghost_marowak_anim.asm b/engine/battle/ghost_marowak_anim.asm index 5c9e6f1a..719fcf0a 100644 --- a/engine/battle/ghost_marowak_anim.asm +++ b/engine/battle/ghost_marowak_anim.asm @@ -5,18 +5,18 @@ MarowakAnim: ; 7092b (1c:492b) call Func_3061 call CopyMonPicFromBGToSpriteVRAM ; cover the BG ghost pic with a sprite ghost pic that looks the same ; now that the ghost pic is being displayed using sprites, clear the ghost pic from the BG tilemap - hlCoord 12, 0 - ld bc, $707 + coord hl, 12, 0 + lb bc, 7, 7 call ClearScreenArea call Delay3 xor a ld [H_AUTOBGTRANSFERENABLED], a ; disable BG transfer so we don't see the Marowak too soon ; replace ghost pic with Marowak in BG ld a, MAROWAK - ld [wHPBarMaxHP], a + ld [wChangeMonPicEnemyTurnSpecies], a ld a, $1 ld [H_WHOSETURN], a - callab Func_798d4 + callab ChangeMonPic ; alternate between black and light grey 8 times. ; this makes the ghost's body appear to flash ld d, $80 @@ -62,7 +62,7 @@ CopyMonPicFromBGToSpriteVRAM: ; 70994 (1c:4994) ld a, $70 ld [W_BASECOORDX], a ld hl, wOAMBuffer - ld bc, $606 + lb bc, 6, 6 ld d, $8 .oamLoop push bc diff --git a/engine/battle/init_battle_variables.asm b/engine/battle/init_battle_variables.asm index 94d964e8..78f4ad22 100644 --- a/engine/battle/init_battle_variables.asm +++ b/engine/battle/init_battle_variables.asm @@ -1,10 +1,10 @@ InitBattleVariables: ; f6236 (3d:6236) ld a, [hTilesetType] - ld [wd0d4], a + ld [wSavedTilesetType], a xor a - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a ld [wBattleResult], a - ld hl, wcc2b + ld hl, wPartyAndBillsPCSavedMenuItem ld [hli], a ld [hli], a ld [hli], a @@ -13,21 +13,21 @@ InitBattleVariables: ; f6236 (3d:6236) ld [wCriticalHitOrOHKO], a ld [wBattleMonSpecies], a ld [wPartyGainExpFlags], a - ld [wPlayerMonNumber], a + ld [wPlayerMonNumber], a ld [wEscapedFromBattle], a ld [wMapPalOffset], a - ld hl, wcf1d - ld [hli], a - ld [hl], a - ld hl, wccd3 + ld hl, wPlayerHPBarColor + ld [hli], a ; wPlayerHPBarColor + ld [hl], a ; wEnemyHPBarColor + ld hl, wCanEvolveFlags ld b, $3c .loop ld [hli], a dec b jr nz, .loop - inc a - ld [wccd9], a - ld a, [W_CURMAP] + inc a ; POUND + ld [wTestBattlePlayerSelectedMove], a + ld a, [W_CURMAP] cp SAFARI_ZONE_EAST jr c, .notSafariBattle cp SAFARI_ZONE_REST_HOUSE_1 @@ -35,6 +35,4 @@ InitBattleVariables: ; f6236 (3d:6236) ld a, $2 ; safari battle ld [W_BATTLETYPE], a .notSafariBattle - ld hl, PlayBattleMusic - ld b, BANK(PlayBattleMusic) - jp Bankswitch + jpab PlayBattleMusic diff --git a/engine/battle/link_battle_versus_text.asm b/engine/battle/link_battle_versus_text.asm index c29e1c85..9849cc9a 100644 --- a/engine/battle/link_battle_versus_text.asm +++ b/engine/battle/link_battle_versus_text.asm @@ -1,17 +1,17 @@ ; display "[player] VS [enemy]" text box with pokeballs representing their parties next to the names DisplayLinkBattleVersusTextBox: ; f41cf (3d:41cf) call LoadTextBoxTilePatterns - hlCoord 3, 4 + coord hl, 3, 4 ld bc, $70c call TextBoxBorder - hlCoord 4, 5 + coord hl, 4, 5 ld de, wPlayerName call PlaceString - hlCoord 4, 10 + coord hl, 4, 10 ld de, wLinkEnemyTrainerName call PlaceString ; place bold "VS" tiles between the names - hlCoord 9, 8 + coord hl, 9, 8 ld a, $69 ld [hli], a ld [hl], $6a diff --git a/engine/battle/moveEffects/conversion_effect.asm b/engine/battle/moveEffects/conversion_effect.asm index 2f05afb3..e4c5b4bd 100644 --- a/engine/battle/moveEffects/conversion_effect.asm +++ b/engine/battle/moveEffects/conversion_effect.asm @@ -13,7 +13,7 @@ ConversionEffect_: ; 139a3 (4:79a3) .conversionEffect bit Invulnerable, a ; is mon immune to typical attacks (dig/fly) jr nz, PrintButItFailedText -; copy target's types to user +; copy target's types to user ld a, [hli] ld [de], a inc de diff --git a/engine/battle/moveEffects/drain_hp_effect.asm b/engine/battle/moveEffects/drain_hp_effect.asm index 517d53d1..1096794f 100644 --- a/engine/battle/moveEffects/drain_hp_effect.asm +++ b/engine/battle/moveEffects/drain_hp_effect.asm @@ -1,5 +1,5 @@ DrainHPEffect_: ; 783f (1:783f) - ld hl, W_DAMAGE + ld hl, W_DAMAGE ld a, [hl] srl a ; divide damage by 2 ld [hli], a @@ -17,8 +17,8 @@ DrainHPEffect_: ; 783f (1:783f) ld a, [H_WHOSETURN] and a jp z, .addDamageToAttackerHP - ld hl, wEnemyMonHP - ld de, wEnemyMonMaxHP + ld hl, wEnemyMonHP + ld de, wEnemyMonMaxHP .addDamageToAttackerHP ld bc, wHPBarOldHP+1 ; copy current HP to wHPBarOldHP @@ -41,7 +41,7 @@ DrainHPEffect_: ; 783f (1:783f) add b ld [hld], a ld [wHPBarNewHP], a - ld a, [W_DAMAGE] + ld a, [W_DAMAGE] ld b, [hl] adc b ld [hli], a @@ -71,10 +71,10 @@ DrainHPEffect_: ; 783f (1:783f) .next ld a, [H_WHOSETURN] and a - hlCoord 10, 9 + coord hl, 10, 9 ld a, $1 jr z, .next2 - hlCoord 2, 2 + coord hl, 2, 2 xor a .next2 ld [wHPBarType], a @@ -87,7 +87,7 @@ DrainHPEffect_: ; 783f (1:783f) and a ld a, [W_PLAYERMOVEEFFECT] jr z, .next3 - ld a, [W_ENEMYMOVEEFFECT] + ld a, [W_ENEMYMOVEEFFECT] .next3 cp DREAM_EATER_EFFECT jr nz, .printText diff --git a/engine/battle/moveEffects/focus_energy_effect.asm b/engine/battle/moveEffects/focus_energy_effect.asm index 0089c8b1..e88d065a 100644 --- a/engine/battle/moveEffects/focus_energy_effect.asm +++ b/engine/battle/moveEffects/focus_energy_effect.asm @@ -12,11 +12,9 @@ FocusEnergyEffect_: ; f628b (3d:628b) ld hl, GettingPumpedText jp PrintText .alreadyUsing - ld c, $32 + ld c, 50 call DelayFrames - ld hl, PrintButItFailedText_ - ld b, BANK(PrintButItFailedText_) - jp Bankswitch + jpab PrintButItFailedText_ GettingPumpedText: ; f62b5 (3d:62b5) db $0a diff --git a/engine/battle/moveEffects/haze_effect.asm b/engine/battle/moveEffects/haze_effect.asm index 14b5f5dd..5c5443c0 100644 --- a/engine/battle/moveEffects/haze_effect.asm +++ b/engine/battle/moveEffects/haze_effect.asm @@ -1,11 +1,11 @@ HazeEffect_: ; 139da (4:79da) ld a, $7 -; store 7 on every stat mod +; store 7 on every stat mod ld hl, wPlayerMonAttackMod call ResetStatMods ld hl, wEnemyMonAttackMod call ResetStatMods -; copy unmodified stats to battle stats +; copy unmodified stats to battle stats ld hl, wPlayerMonUnmodifiedAttack ld de, wBattleMonAttack call ResetStats @@ -25,7 +25,7 @@ HazeEffect_: ; 139da (4:79da) ld [hl], $0 and SLP | (1 << FRZ) jr z, .cureVolatileStatuses -; prevent the Pokemon from executing a move if it was asleep or frozen +; prevent the Pokemon from executing a move if it was asleep or frozen ld a, $ff ld [de], a @@ -51,7 +51,7 @@ CureVolatileStatuses: ; 13a37 (4:7a37) inc hl ; BATTSTATUS2 ld a, [hl] ; clear UsingXAccuracy, ProtectedByMist, GettingPumped, and Seeded statuses - and $ff ^((1 << UsingXAccuracy) | (1 << ProtectedByMist) | (1 << GettingPumped) | (1 << Seeded)) + and $ff ^((1 << UsingXAccuracy) | (1 << ProtectedByMist) | (1 << GettingPumped) | (1 << Seeded)) ld [hli], a ; BATTSTATUS3 ld a, [hl] and %11110000 | (1 << Transformed) ; clear Bad Poison, Reflect and Light Screen statuses @@ -61,7 +61,7 @@ CureVolatileStatuses: ; 13a37 (4:7a37) ResetStatMods: ; 13a43 (4:7a43) ld b, $8 .loop - ld [hli], a + ld [hli], a dec b jr nz, .loop ret diff --git a/engine/battle/moveEffects/heal_effect.asm b/engine/battle/moveEffects/heal_effect.asm index d6d4e183..dbce6ebb 100644 --- a/engine/battle/moveEffects/heal_effect.asm +++ b/engine/battle/moveEffects/heal_effect.asm @@ -76,7 +76,7 @@ HealEffect_: ; f62ba (3d:62ba) ld a, [de] sbc [hl] jr c, .playAnim -; copy max HP to current HP if an overflow ocurred +; copy max HP to current HP if an overflow ocurred ld a, [hli] ld [de], a ld [wHPBarNewHP+1], a @@ -89,10 +89,10 @@ HealEffect_: ; f62ba (3d:62ba) call Bankswitch3DtoF ld a, [H_WHOSETURN] and a - hlCoord 10, 9 + coord hl, 10, 9 ld a, $1 jr z, .updateHPBar - hlCoord 2, 2 + coord hl, 2, 2 xor a .updateHPBar ld [wHPBarType], a diff --git a/engine/battle/moveEffects/leech_seed_effect.asm b/engine/battle/moveEffects/leech_seed_effect.asm index e29fd7c2..1b0afe4b 100644 --- a/engine/battle/moveEffects/leech_seed_effect.asm +++ b/engine/battle/moveEffects/leech_seed_effect.asm @@ -1,20 +1,20 @@ LeechSeedEffect_: ; 2bea9 (a:7ea9) callab MoveHitTest - ld a, [W_MOVEMISSED] + ld a, [W_MOVEMISSED] and a jr nz, .moveMissed - ld hl, W_ENEMYBATTSTATUS2 - ld de, wEnemyMonType1 - ld a, [H_WHOSETURN] + ld hl, W_ENEMYBATTSTATUS2 + ld de, wEnemyMonType1 + ld a, [H_WHOSETURN] and a jr z, .leechSeedEffect - ld hl, W_PLAYERBATTSTATUS2 - ld de, wBattleMonType1 + ld hl, W_PLAYERBATTSTATUS2 + ld de, wBattleMonType1 .leechSeedEffect ; miss if the target is grass-type or already seeded ld a, [de] cp GRASS - jr z, .moveMissed + jr z, .moveMissed inc de ld a, [de] cp GRASS @@ -23,12 +23,12 @@ LeechSeedEffect_: ; 2bea9 (a:7ea9) jr nz, .moveMissed set Seeded, [hl] callab PlayCurrentMoveAnimation - ld hl, WasSeededText ; $7ef2 + ld hl, WasSeededText jp PrintText .moveMissed - ld c, $32 + ld c, 50 call DelayFrames - ld hl, EvadedAttackText ; $7ef7 + ld hl, EvadedAttackText jp PrintText WasSeededText: ; 2bef2 (a:7ef2) diff --git a/engine/battle/moveEffects/mist_effect.asm b/engine/battle/moveEffects/mist_effect.asm index ed06d16c..5d7669f8 100644 --- a/engine/battle/moveEffects/mist_effect.asm +++ b/engine/battle/moveEffects/mist_effect.asm @@ -12,9 +12,7 @@ MistEffect_: ; f64ac (3d:64ac) ld hl, ShroudedInMistText jp PrintText .mistAlreadyInUse - ld hl, PrintButItFailedText_ - ld b, BANK(PrintButItFailedText_) - jp Bankswitch + jpab PrintButItFailedText_ ShroudedInMistText: ; f64d3 (3d:64d3) TX_FAR _ShroudedInMistText diff --git a/engine/battle/moveEffects/one_hit_ko_effect.asm b/engine/battle/moveEffects/one_hit_ko_effect.asm index f859f9c4..c1dde6ff 100644 --- a/engine/battle/moveEffects/one_hit_ko_effect.asm +++ b/engine/battle/moveEffects/one_hit_ko_effect.asm @@ -7,7 +7,7 @@ OneHitKOEffect_: ; f64db (3d:64db) ld [wCriticalHitOrOHKO], a ld hl, wBattleMonSpeed + 1 ld de, wEnemyMonSpeed + 1 - ld a, [H_WHOSETURN] + ld a, [H_WHOSETURN] and a jr z, .compareSpeed ld hl, wEnemyMonSpeed + 1 @@ -24,7 +24,7 @@ OneHitKOEffect_: ; f64db (3d:64db) ld a, [hl] sbc b jr c, .userIsSlower - ld hl, W_DAMAGE + ld hl, W_DAMAGE ld a, $ff ld [hli], a ld [hl], a @@ -34,5 +34,5 @@ OneHitKOEffect_: ; f64db (3d:64db) .userIsSlower ; keep damage at 0 and set move missed flag if target's current speed is higher instead ld a, $1 - ld [W_MOVEMISSED], a + ld [W_MOVEMISSED], a ret diff --git a/engine/battle/moveEffects/paralyze_effect.asm b/engine/battle/moveEffects/paralyze_effect.asm index 74a7319d..3e0cf062 100644 --- a/engine/battle/moveEffects/paralyze_effect.asm +++ b/engine/battle/moveEffects/paralyze_effect.asm @@ -4,7 +4,7 @@ ParalyzeEffect_: ; f6562 (3d:6562) ld a, [H_WHOSETURN] and a jp z, .next - ld hl, wBattleMonStatus + ld hl, wBattleMonStatus ld de, W_ENEMYMOVETYPE .next ld a, [hl] @@ -28,7 +28,7 @@ ParalyzeEffect_: ; f6562 (3d:6562) push hl callab MoveHitTest pop hl - ld a, [W_MOVEMISSED] + ld a, [W_MOVEMISSED] and a jr nz, .didntAffect set PAR, [hl] @@ -36,18 +36,12 @@ ParalyzeEffect_: ; f6562 (3d:6562) ld c, 30 call DelayFrames callab PlayCurrentMoveAnimation - ld hl, PrintMayNotAttackText - ld b, BANK(PrintMayNotAttackText) - jp Bankswitch + jpab PrintMayNotAttackText .didntAffect ld c, 50 call DelayFrames - ld hl, PrintDidntAffectText - ld b, BANK(PrintDidntAffectText) - jp Bankswitch + jpab PrintDidntAffectText .doesntAffect ld c, 50 call DelayFrames - ld hl, PrintDoesntAffectText - ld b, BANK(PrintDoesntAffectText) - jp Bankswitch + jpab PrintDoesntAffectText diff --git a/engine/battle/moveEffects/pay_day_effect.asm b/engine/battle/moveEffects/pay_day_effect.asm index 1fab9771..2fa6b53f 100644 --- a/engine/battle/moveEffects/pay_day_effect.asm +++ b/engine/battle/moveEffects/pay_day_effect.asm @@ -9,19 +9,19 @@ PayDayEffect_ ; f6511 (3d:6511) ld a, [wEnemyMonLevel] .payDayEffect ; level * 2 - add a + add a ld [H_DIVIDEND + 3], a xor a ld [H_DIVIDEND], a ld [H_DIVIDEND + 1], a ld [H_DIVIDEND + 2], a -; convert to BCD +; convert to BCD ld a, 100 ld [H_DIVISOR], a ld b, $4 call Divide ld a, [H_QUOTIENT + 3] - ld [hli], a + ld [hli], a ld a, [H_REMAINDER] ld [H_DIVIDEND + 3], a ld a, 10 diff --git a/engine/battle/moveEffects/recoil_effect.asm b/engine/battle/moveEffects/recoil_effect.asm index fe516c03..51232af6 100644 --- a/engine/battle/moveEffects/recoil_effect.asm +++ b/engine/battle/moveEffects/recoil_effect.asm @@ -46,19 +46,19 @@ RecoilEffect_: ; 1392c (4:792c) ld [wHPBarNewHP+1], a jr nc, .getHPBarCoords ; if recoil damage is higher than the Pokemon's HP, set its HP to 0 - xor a + xor a ld [hli], a ld [hl], a ld hl, wHPBarNewHP ld [hli], a ld [hl], a .getHPBarCoords - hlCoord 10, 9 + coord hl, 10, 9 ld a, [H_WHOSETURN] and a ld a, $1 jr z, .updateHPBar - hlCoord 2, 2 + coord hl, 2, 2 xor a .updateHPBar ld [wHPBarType], a diff --git a/engine/battle/moveEffects/reflect_light_screen_effect.asm b/engine/battle/moveEffects/reflect_light_screen_effect.asm index 83a97486..ee053670 100644 --- a/engine/battle/moveEffects/reflect_light_screen_effect.asm +++ b/engine/battle/moveEffects/reflect_light_screen_effect.asm @@ -27,7 +27,7 @@ ReflectLightScreenEffect_: ; f645d (3d:645d) pop hl jp PrintText .moveFailed - ld c, $32 + ld c, 50 call DelayFrames ld hl, PrintButItFailedText_ jp Bankswitch3DtoF diff --git a/engine/battle/moveEffects/substitute_effect.asm b/engine/battle/moveEffects/substitute_effect.asm index 8412e281..c72fffbe 100644 --- a/engine/battle/moveEffects/substitute_effect.asm +++ b/engine/battle/moveEffects/substitute_effect.asm @@ -11,15 +11,15 @@ SubstituteEffect_: ; 17dad (5:7dad) ld de, wEnemySubstituteHP ld bc, W_ENEMYBATTSTATUS2 .notEnemy - ld a, [bc] + ld a, [bc] bit HasSubstituteUp, a ; user already has substitute? - jr nz, .alreadyHasSubstitute + jr nz, .alreadyHasSubstitute ; quarter health to remove from user -; assumes max HP is 1023 or lower +; assumes max HP is 1023 or lower push bc ld a, [hli] ld b, [hl] - srl a + srl a rr b srl a rr b ; max hp / 4 @@ -27,37 +27,35 @@ SubstituteEffect_: ; 17dad (5:7dad) ld de, wBattleMonHP - wBattleMonMaxHP add hl, de ; point hl to current HP low byte pop de - ld a, b + ld a, b ld [de], a ; save copy of HP to subtract in ccd7/ccd8 [how much HP substitute has] ld a, [hld] -; subtract [max hp / 4] to current HP - sub b +; subtract [max hp / 4] to current HP + sub b ld d, a ld a, [hl] - sbc 0 + sbc 0 pop bc jr c, .notEnoughHP ; underflow means user would be left with negative health ; bug: since it only brances on carry, it will possibly leave user with 0 HP .userHasZeroOrMoreHP ldi [hl], a ; save resulting HP after substraction into current HP - ld [hl], d + ld [hl], d ld h, b ld l, c - set HasSubstituteUp, [hl] - ld a, [W_OPTIONS] + set HasSubstituteUp, [hl] + ld a, [W_OPTIONS] bit 7, a ; battle animation is enabled? - ld hl, PlayCurrentMoveAnimation + ld hl, PlayCurrentMoveAnimation ld b, BANK(PlayCurrentMoveAnimation) jr z, .animationEnabled - ld hl, AnimationSubstitute + ld hl, AnimationSubstitute ld b, BANK(AnimationSubstitute) .animationEnabled call Bankswitch ; jump to routine depending on animation setting ld hl, SubstituteText call PrintText - ld hl, DrawHUDsAndHPBars - ld b, BANK(DrawHUDsAndHPBars) - jp Bankswitch + jpab DrawHUDsAndHPBars .alreadyHasSubstitute ld hl, HasSubstituteText jr .printText diff --git a/engine/battle/moveEffects/transform_effect.asm b/engine/battle/moveEffects/transform_effect.asm index 74b70431..fef6f7aa 100644 --- a/engine/battle/moveEffects/transform_effect.asm +++ b/engine/battle/moveEffects/transform_effect.asm @@ -24,10 +24,10 @@ TransformEffect_: ; f637f (3d:637f) ld hl, W_ENEMYBATTSTATUS2 .transformEffect ; animation(s) played are different if target has Substitute up - bit HasSubstituteUp, [hl] + bit HasSubstituteUp, [hl] push af - ld hl, Func_79816 - ld b, BANK(Func_79816) + ld hl, HideSubstituteShowMonAnim + ld b, BANK(HideSubstituteShowMonAnim) call nz, Bankswitch ld a, [W_OPTIONS] add a @@ -38,8 +38,8 @@ TransformEffect_: ; f637f (3d:637f) ld b, BANK(AnimationTransformMon) .gotAnimToPlay call Bankswitch - ld hl, Func_798b2 - ld b, BANK(Func_798b2) + ld hl, ReshowSubstituteAnim + ld b, BANK(ReshowSubstituteAnim) pop af call nz, Bankswitch pop bc @@ -49,13 +49,13 @@ TransformEffect_: ; f637f (3d:637f) pop de pop hl push hl -; transform user into opposing Pokemon +; transform user into opposing Pokemon ; species - ld a, [hl] + ld a, [hl] ld [de], a -; type 1, type 2, catch rate, and moves +; type 1, type 2, catch rate, and moves ld bc, $5 - add hl, bc + add hl, bc inc de inc de inc de @@ -67,12 +67,12 @@ TransformEffect_: ; f637f (3d:637f) ld a, [H_WHOSETURN] and a jr z, .next -; save enemy mon DVs in wcceb/wccec (enemy turn only) +; save enemy mon DVs at wTransformedEnemyMonOriginalDVs ld a, [de] - ld [wcceb], a + ld [wTransformedEnemyMonOriginalDVs], a inc de ld a, [de] - ld [wccec], a + ld [wTransformedEnemyMonOriginalDVs + 1], a dec de .next ; DVs @@ -82,7 +82,7 @@ TransformEffect_: ; f637f (3d:637f) ld a, [hli] ld [de], a inc de -; Attack, Defense, Speed, and Special stats +; Attack, Defense, Speed, and Special stats inc hl inc hl inc hl @@ -91,7 +91,7 @@ TransformEffect_: ; f637f (3d:637f) inc de ld bc, $8 call CopyData - ld bc, wBattleMonMoves - wBattleMonPP + ld bc, wBattleMonMoves - wBattleMonPP add hl, bc ; ld hl, wBattleMonMoves ld b, NUM_MOVES .copyPPLoop diff --git a/engine/battle/read_trainer_party.asm b/engine/battle/read_trainer_party.asm index d8da714e..37a45476 100755 --- a/engine/battle/read_trainer_party.asm +++ b/engine/battle/read_trainer_party.asm @@ -55,8 +55,8 @@ ReadTrainer: ; 39c53 (e:5c53) and a ; have we reached the end of the trainer data? jr z,.FinishUp ld [wcf91],a ; write species somewhere (XXX why?) - ld a,1 - ld [wcc49],a + ld a,ENEMY_PARTY_DATA + ld [wMonDataLocation],a push hl call AddPartyMon pop hl @@ -72,8 +72,8 @@ ReadTrainer: ; 39c53 (e:5c53) ld [W_CURENEMYLVL],a ld a,[hli] ld [wcf91],a - ld a,1 - ld [wcc49],a + ld a,ENEMY_PARTY_DATA + ld [wMonDataLocation],a push hl call AddPartyMon pop hl @@ -101,7 +101,7 @@ ReadTrainer: ; 39c53 (e:5c53) ; get trainer class number ld a,[W_CUROPPONENT] - sub $C8 + sub 200 ld b,a ld hl,TeamMoves @@ -143,7 +143,7 @@ ReadTrainer: ; 39c53 (e:5c53) ld [wEnemyMon6Moves + 2],a .FinishUp ; clear wAmountMoneyWon addresses - xor a + xor a ld de,wAmountMoneyWon ld [de],a inc de @@ -154,7 +154,7 @@ ReadTrainer: ; 39c53 (e:5c53) ld b,a .LastLoop ; update wAmountMoneyWon addresses (money to win) based on enemy's level - ld hl,wd047 + ld hl,wTrainerBaseMoney + 1 ld c,2 ; wAmountMoneyWon is a 3-byte number push bc predef AddBCDPredef diff --git a/engine/battle/scale_sprites.asm b/engine/battle/scale_sprites.asm index dae4ad42..ed227984 100644 --- a/engine/battle/scale_sprites.asm +++ b/engine/battle/scale_sprites.asm @@ -41,16 +41,16 @@ ScaleFirstThreeSpriteColumnsByTwo: ; 2fe55 (b:7e55) ScaleLastSpriteColumnByTwo: ; 2fe7d (b:7e7d) ld a, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows - ld [H_SPRITEINTERLACECOUNTER], a ; $ff8b - ld bc, -1 ; $ffff + ld [H_SPRITEINTERLACECOUNTER], a + ld bc, -1 .columnInnerLoop ld a, [de] dec de swap a ; only high nybble contains information call ScalePixelsByTwo - ld a, [H_SPRITEINTERLACECOUNTER] ; $ff8b + ld a, [H_SPRITEINTERLACECOUNTER] dec a - ld [H_SPRITEINTERLACECOUNTER], a ; $ff8b + ld [H_SPRITEINTERLACECOUNTER], a jr nz, .columnInnerLoop dec de ; skip last 4 rows of new column dec de diff --git a/engine/battle/scroll_draw_trainer_pic.asm b/engine/battle/scroll_draw_trainer_pic.asm index c6b69362..e5e66b38 100644 --- a/engine/battle/scroll_draw_trainer_pic.asm +++ b/engine/battle/scroll_draw_trainer_pic.asm @@ -3,10 +3,10 @@ _ScrollTrainerPicAfterBattle: ; f4259 (e:f4259) ; the screen from the right. xor a ld [wEnemyMonSpecies2], a - ld b, $1 - call GoPAL_SET + ld b, SET_PAL_BATTLE + call RunPaletteCommand callab _LoadTrainerPic - hlCoord 19, 0 + coord hl, 19, 0 ld c, $0 .scrollLoop inc c diff --git a/engine/battle/trainer_ai.asm b/engine/battle/trainer_ai.asm index 19a184f2..afb04216 100644 --- a/engine/battle/trainer_ai.asm +++ b/engine/battle/trainer_ai.asm @@ -2,7 +2,7 @@ ; unused slots are filled with 0, all used slots may be chosen with equal probability AIEnemyTrainerChooseMoves: ; 39719 (e:5719) ld a, $a - ld hl, wHPBarMaxHP ; init temporary move selection array. Only the moves with the lowest numbers are chosen in the end + ld hl, wBuffer ; init temporary move selection array. Only the moves with the lowest numbers are chosen in the end ld [hli], a ; move 1 ld [hli], a ; move 2 ld [hli], a ; move 3 @@ -11,14 +11,14 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719) swap a and $f jr z, .noMoveDisabled - ld hl, wHPBarMaxHP + ld hl, wBuffer dec a ld c, a ld b, $0 add hl, bc ; advance pointer to forbidden move ld [hl], $50 ; forbid (highly discourage) disabled move .noMoveDisabled - ld hl, TrainerClassMoveChoiceModifications ; 589B + ld hl, TrainerClassMoveChoiceModifications ld a, [W_TRAINERCLASS] ld b, a .loopTrainerClasses @@ -40,11 +40,11 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719) and a jr z, .loopFindMinimumEntries push hl - ld hl, AIMoveChoiceModificationFunctionPointers ; $57a3 + ld hl, AIMoveChoiceModificationFunctionPointers dec a add a ld c, a - ld b, $0 + ld b, 0 add hl, bc ; skip to pointer ld a, [hli] ; read pointer into hl ld h, [hl] @@ -53,9 +53,9 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719) push de jp [hl] ; execute modification function .loopFindMinimumEntries ; all entries will be decremented sequentially until one of them is zero - ld hl, wHPBarMaxHP ; temp move selection array + ld hl, wBuffer ; temp move selection array ld de, wEnemyMonMoves ; enemy moves - ld c, $4 + ld c, NUM_MOVES .loopDecrementEntries ld a, [de] inc de @@ -73,15 +73,15 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719) inc [hl] dec hl inc a - cp $5 + cp NUM_MOVES + 1 jr nz, .loopUndoPartialIteration - ld hl, wHPBarMaxHP ; temp move selection array + ld hl, wBuffer ; temp move selection array ld de, wEnemyMonMoves ; enemy moves - ld c, $4 + ld c, NUM_MOVES .filterMinimalEntries ; all minimal entries now have value 1. All other slots will be disabled (move set to 0) ld a, [de] and a - jr nz, .moveExisting ; 0x3978a $1 + jr nz, .moveExisting ld [hl], a .moveExisting ld a, [hl] @@ -97,7 +97,7 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719) inc de dec c jr nz, .filterMinimalEntries - ld hl, wHPBarMaxHP ; use created temporary array as move set + ld hl, wBuffer ; use created temporary array as move set ret .useOriginalMoveSet ld hl, wEnemyMonMoves ; use original move set @@ -145,7 +145,7 @@ AIMoveChoiceModification1: ; 397ab (e:57ab) ld [hl], a jr .nextMove -StatusAilmentMoveEffects ; 57e2 +StatusAilmentMoveEffects: ; 57e2 db $01 ; unused sleep effect db SLEEP_EFFECT db POISON_EFFECT @@ -157,7 +157,7 @@ StatusAilmentMoveEffects ; 57e2 ; that fall in-bewteen AIMoveChoiceModification2: ; 397e7 (e:57e7) ld a, [wAILayer2Encouragement] - cp $1 + cp $1 ret nz ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset) ld de, wEnemyMonMoves ; enemy moves @@ -191,7 +191,7 @@ AIMoveChoiceModification2: ; 397e7 (e:57e7) AIMoveChoiceModification3: ; 39817 (e:5817) ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset) ld de, wEnemyMonMoves ; enemy moves - ld b, $5 + ld b, NUM_MOVES + 1 .nextMove dec b ret z ; processed all 4 moves @@ -208,7 +208,7 @@ AIMoveChoiceModification3: ; 39817 (e:5817) pop de pop bc pop hl - ld a, [wd11e] + ld a, [wTypeEffectiveness] cp $10 jr z, .nextMove jr c, .notEffectiveMove @@ -264,7 +264,7 @@ ReadMove: ; 39884 (e:5884) push bc dec a ld hl,Moves - ld bc,6 + ld bc,MoveEnd - Moves call AddNTimes ld de,W_ENEMYMOVENUM call CopyData @@ -325,8 +325,8 @@ TrainerClassMoveChoiceModifications: ; 3989b (e:589b) db 1,3,0 ; LANCE INCLUDE "engine/battle/trainer_pic_money_pointers.asm" - -INCLUDE "text/trainer_names.asm" + +INCLUDE "text/trainer_names.asm" INCLUDE "engine/battle/bank_e_misc.asm" @@ -337,7 +337,6 @@ INCLUDE "data/trainer_moves.asm" INCLUDE "data/trainer_parties.asm" TrainerAI: ; 3a52e (e:652e) -;XXX called at 34964, 3c342, 3c398 and a ld a,[W_ISINBATTLE] dec a @@ -553,14 +552,14 @@ DecrementAICount: ; 3a695 (e:6695) scf ret -Func_3a69b: ; 3a69b (e:669b) - ld a,(SFX_08_3e - SFX_Headers_08) / 3 +AIPlayRestoringSFX: ; 3a69b (e:669b) + ld a,SFX_HEAL_AILMENT jp PlaySoundWaitForCurrent AIUseFullRestore: ; 3a6a0 (e:66a0) call AICureStatus ld a,FULL_RESTORE - ld [wcf05],a + ld [wAIItem],a ld de,wHPBarOldHP ld hl,wEnemyMonHP + 1 ld a,[hld] @@ -601,7 +600,7 @@ AIUseHyperPotion: ; 3a6d6 (e:66d6) AIRecoverHP: ; 3a6da (e:66da) ; heal b HP and print "trainer used $(a) on pokemon!" - ld [wcf05],a + ld [wAIItem],a ld hl,wEnemyMonHP + 1 ld a,[hl] ld [wHPBarOldHP],a @@ -642,7 +641,7 @@ AIRecoverHP: ; 3a6da (e:66da) AIPrintItemUseAndUpdateHPBar: ; 3a718 (e:6718) call AIPrintItemUse_ - hlCoord 2, 2 + coord hl, 2, 2 xor a ld [wHPBarType],a predef UpdateHPBar2 @@ -666,7 +665,7 @@ AISwitchIfEnoughMons: ; 3a72a (e:672a) inc d .Fainted push bc - ld bc,$2C + ld bc, wEnemyMon2 - wEnemyMon1 add hl,bc pop bc dec c @@ -695,11 +694,13 @@ SwitchEnemyMon: ; 3a74b (e:674b) ld hl, AIBattleWithdrawText call PrintText + ; This wFirstMonsNotOutYet variable is abused to prevent the player from + ; switching in a new mon in response to this switch. ld a,1 - ld [wd11d],a + ld [wFirstMonsNotOutYet],a callab EnemySendOut xor a - ld [wd11d],a + ld [wFirstMonsNotOutYet],a ld a,[wLinkState] cp LINK_STATE_BATTLING @@ -712,7 +713,7 @@ AIBattleWithdrawText: ; 3a781 (e:6781) db "@" AIUseFullHeal: ; 3a786 (e:6786) - call Func_3a69b + call AIPlayRestoringSFX call AICureStatus ld a,FULL_HEAL jp AIPrintItemUse @@ -731,21 +732,21 @@ AICureStatus: ; 3a791 (e:6791) ret AIUseXAccuracy: ; 0x3a7a8 unused - call Func_3a69b + call AIPlayRestoringSFX ld hl,W_ENEMYBATTSTATUS2 set 0,[hl] ld a,X_ACCURACY jp AIPrintItemUse AIUseGuardSpec: ; 3a7b5 (e:67b5) - call Func_3a69b + call AIPlayRestoringSFX ld hl,W_ENEMYBATTSTATUS2 set 1,[hl] ld a,GUARD_SPEC_ jp AIPrintItemUse AIUseDireHit: ; 0x3a7c2 unused - call Func_3a69b + call AIPlayRestoringSFX ld hl,W_ENEMYBATTSTATUS2 set 2,[hl] ld a,DIRE_HIT @@ -798,7 +799,7 @@ AIUseXSpecial: ; 3a804 (e:6804) ; fallthrough AIIncreaseStat: ; 3a808 (e:6808) - ld [wcf05],a + ld [wAIItem],a push bc call AIPrintItemUse_ pop bc @@ -820,13 +821,13 @@ AIIncreaseStat: ; 3a808 (e:6808) jp DecrementAICount AIPrintItemUse: ; 3a82c (e:682c) - ld [wcf05],a + ld [wAIItem],a call AIPrintItemUse_ jp DecrementAICount AIPrintItemUse_: ; 3a835 (e:6835) -; print "x used [wcf05] on z!" - ld a,[wcf05] +; print "x used [wAIItem] on z!" + ld a,[wAIItem] ld [wd11e],a call GetItemName ld hl, AIBattleUseItemText diff --git a/engine/battle/wild_encounters.asm b/engine/battle/wild_encounters.asm index 61b318b9..144234bb 100644 --- a/engine/battle/wild_encounters.asm +++ b/engine/battle/wild_encounters.asm @@ -18,14 +18,14 @@ TryDoWildEncounter: ; 13870 (4:7870) jr z, .CantEncounter ld a, [wRepelRemainingSteps] and a - jr z, .asm_1389e + jr z, .next dec a jr z, .lastRepelStep ld [wRepelRemainingSteps], a -.asm_1389e -; determine if wild pokemon can appear in the half-block we're standing in +.next +; determine if wild pokemon can appear in the half-block we're standing in ; is the bottom right tile (9,9) of the half-block we're standing in a grass/water tile? - hlCoord 9, 9 + coord hl, 9, 9 ld c, [hl] ld a, [W_GRASSTILE] cp c @@ -64,14 +64,14 @@ TryDoWildEncounter: ; 13870 (4:7870) ; determine which wild pokemon (grass or water) can appear in the half-block we're standing in ld c, [hl] ld hl, W_GRASSMONS - aCoord 8, 9 - cp $14 ; is the bottom left tile (8,9) of the half-block we're standing in a water tile? + aCoord 8, 9 + cp $14 ; is the bottom left tile (8,9) of the half-block we're standing in a water tile? jr nz, .gotWildEncounterType ; else, it's treated as a grass tile by default ld hl, W_WATERMONS ; since the bottom right tile of a "left shore" half-block is $14 but the bottom left tile is not, -; "left shore" half-blocks (such as the one in the east coast of Cinnabar) load grass encounters. +; "left shore" half-blocks (such as the one in the east coast of Cinnabar) load grass encounters. .gotWildEncounterType - ld b, $0 + ld b, 0 add hl, bc ld a, [hli] ld [W_CURENEMYLVL], a @@ -89,8 +89,8 @@ TryDoWildEncounter: ; 13870 (4:7870) jr .willEncounter .lastRepelStep ld [wRepelRemainingSteps], a - ld a, $d2 - ld [H_DOWNARROWBLINKCNT2], a + ld a, TEXT_REPEL_WORE_OFF + ld [hSpriteIndexOrTextID], a call EnableAutoTextBoxDrawing call DisplayTextID .CantEncounter2 diff --git a/engine/cable_club.asm b/engine/cable_club.asm index 2cfb1734..465561ca 100755 --- a/engine/cable_club.asm +++ b/engine/cable_club.asm @@ -1,19 +1,19 @@ -; performs the appropriate action when the player uses the gameboy on the table in the Colosseum or Trade Centre -; In the Colosseum, it starts a battle. In the Trade Centre, it displays the trade selection screen. +; performs the appropriate action when the player uses the gameboy on the table in the Colosseum or Trade Center +; In the Colosseum, it starts a battle. In the Trade Center, it displays the trade selection screen. ; Before doing either action, it swaps random numbers, trainer names and party data with the other gameboy. CableClub_DoBattleOrTrade: ; 5317 (1:5317) - ld c, $50 + ld c, 80 call DelayFrames call ClearScreen call UpdateSprites call LoadFontTilePatterns call LoadHpBarAndStatusTilePatterns call LoadTrainerInfoTextBoxTiles - hlCoord 3, 8 + coord hl, 3, 8 ld b, 2 ld c, 12 call CableClub_TextBoxBorder - hlCoord 4, 10 + coord hl, 4, 10 ld de, PleaseWaitString call PlaceString ld hl, wPlayerNumHits @@ -96,7 +96,7 @@ CableClub_DoBattleOrTradeAgain: ; 5345 ld a, SERIAL_PATCH_LIST_PART_TERMINATOR ld [de], a ; end of part 1 inc de - ld bc, $100 + lb bc, 1, 0 jr .patchPartyMonsLoop .finishedPatchingPlayerData ld a, SERIAL_PATCH_LIST_PART_TERMINATOR @@ -176,7 +176,7 @@ CableClub_DoBattleOrTradeAgain: ; 5345 jr z, .findStartOfEnemyNameLoop dec hl ld de, wLinkEnemyTrainerName - ld c, 11 + ld c, NAME_LENGTH .copyEnemyNameLoop ld a, [hli] cp SERIAL_NO_DATA_BYTE @@ -256,9 +256,9 @@ CableClub_DoBattleOrTradeAgain: ; 5345 dec c jr nz, .unpatchEnemyMonsLoop ld a, wEnemyMonOT % $100 - ld [wcf8d], a + ld [wUnusedCF8D], a ld a, wEnemyMonOT / $100 - ld [wcf8e], a + ld [wUnusedCF8D + 1], a xor a ld [wTradeCenterPointerTableIndex], a ld a, $ff @@ -274,7 +274,7 @@ CableClub_DoBattleOrTradeAgain: ; 5345 jr nz, .asm_5506 ld a, LINK_STATE_BATTLING ld [wLinkState], a - ld a, SONY1 + $c8 + ld a, OPP_SONY1 ld [W_CUROPPONENT], a call ClearScreen call Delay3 @@ -297,7 +297,7 @@ CallCurrentTradeCenterFunction: ld b, 0 ld a, [wTradeCenterPointerTableIndex] cp $ff - jp z, LoadTitlescreenGraphics + jp z, DisplayTitleScreen add a ld c, a add hl, bc @@ -317,7 +317,7 @@ TradeCenter_SelectMon: ld [hli], a ld [hli], a ld [hl], a - ld [wcc37], a + ld [wMenuWatchMovingOutOfBounds], a ld [wCurrentMenuItem], a ld [wLastMenuItem], a ld [wMenuJoypadPollCount], a @@ -326,7 +326,7 @@ TradeCenter_SelectMon: jp .playerMonMenu .enemyMonMenu xor a - ld [wcc37], a + ld [wMenuWatchMovingOutOfBounds], a inc a ld [wWhichTradeMonSelectionMenu], a ld a, D_DOWN | D_LEFT | A_BUTTON @@ -357,9 +357,9 @@ TradeCenter_SelectMon: dec a ld [wCurrentMenuItem], a .displayEnemyMonStats - ld a, $1 - ld [wd11b], a - callab Func_39bd5 + ld a, INIT_ENEMYOT_LIST + ld [wInitListType], a + callab InitList ; the list isn't used ld hl, wEnemyMons call TradeCenter_DisplayStats jp .getNewInput @@ -390,7 +390,7 @@ TradeCenter_SelectMon: .playerMonMenu xor a ; player mon menu ld [wWhichTradeMonSelectionMenu], a - ld [wcc37], a + ld [wMenuWatchMovingOutOfBounds], a ld a, D_DOWN | D_RIGHT | A_BUTTON ld [wMenuWatchedKeys], a ld a, [wPartyCount] @@ -399,8 +399,8 @@ TradeCenter_SelectMon: ld [wTopMenuItemY], a ld a, 1 ld [wTopMenuItemX], a - hlCoord 1, 1 - ld bc, $0601 + coord hl, 1, 1 + lb bc, 6, 1 call ClearScreenArea .playerMonMenu_HandleInput ld hl, hFlags_0xFFF6 @@ -416,9 +416,9 @@ TradeCenter_SelectMon: jr z, .playerMonMenu_ANotPressed jp .chosePlayerMon ; jump if A button pressed ; unreachable code - ld a, $4 - ld [wd11b], a - callab Func_39bd5 + ld a, INIT_PLAYEROT_LIST + ld [wInitListType], a + callab InitList ; the list isn't used call TradeCenter_DisplayStats jp .getNewInput .playerMonMenu_ANotPressed @@ -464,11 +464,11 @@ TradeCenter_SelectMon: dec a .displayStatsTradeMenu push af - hlCoord 0, 14 + coord hl, 0, 14 ld b, 2 ld c, 18 call CableClub_TextBoxBorder - hlCoord 2, 16 + coord hl, 2, 16 ld de, .statsTrade call PlaceString xor a @@ -511,9 +511,9 @@ TradeCenter_SelectMon: .displayPlayerMonStats pop af ld [wCurrentMenuItem], a - ld a, $4 - ld [wd11b], a - callab Func_39bd5 + ld a, INIT_PLAYEROT_LIST + ld [wInitListType], a + callab InitList ; the list isn't used call TradeCenter_DisplayStats call LoadScreenTilesFromBuffer1 jp .playerMonMenu @@ -596,15 +596,15 @@ ReturnToCableClubRoom: ; 577d (1:577d) ret TradeCenter_DrawCancelBox: - hlCoord 11, 15 + coord hl, 11, 15 ld a, $7e - ld bc, 2 * 20 + 9 + ld bc, 2 * SCREEN_WIDTH + 9 call FillMemory - hlCoord 0, 15 + coord hl, 0, 15 ld b, 1 ld c, 9 call CableClub_TextBoxBorder - hlCoord 2, 16 + coord hl, 2, 16 ld de, CancelTextString jp PlaceString @@ -613,8 +613,8 @@ CancelTextString: TradeCenter_PlaceSelectedEnemyMonMenuCursor: ld a, [wSerialSyncAndExchangeNybbleReceiveData] - hlCoord 1, 9 - ld bc, 20 + coord hl, 1, 9 + ld bc, SCREEN_WIDTH call AddNTimes ld [hl], $ec ; cursor ret @@ -630,24 +630,24 @@ TradeCenter_DisplayStats: jp TradeCenter_DrawCancelBox TradeCenter_DrawPartyLists: - hlCoord 0, 0 + coord hl, 0, 0 ld b, 6 ld c, 18 call CableClub_TextBoxBorder - hlCoord 0, 8 + coord hl, 0, 8 ld b, 6 ld c, 18 call CableClub_TextBoxBorder - hlCoord 5, 0 + coord hl, 5, 0 ld de, wPlayerName call PlaceString - hlCoord 5, 8 + coord hl, 5, 8 ld de, wLinkEnemyTrainerName call PlaceString - hlCoord 2, 1 + coord hl, 2, 1 ld de, wPartySpecies call TradeCenter_PrintPartyListNames - hlCoord 2, 9 + coord hl, 2, 9 ld de, wEnemyPartyMons ; fall through @@ -682,9 +682,9 @@ TradeCenter_Trade: xor a ld [wSerialExchangeNybbleSendData + 1], a ; unnecessary ld [wSerialExchangeNybbleReceiveData], a - ld [wcc37], a + ld [wMenuWatchMovingOutOfBounds], a ld [wMenuJoypadPollCount], a - hlCoord 0, 12 + coord hl, 0, 12 ld b, 4 ld c, 18 call CableClub_TextBoxBorder @@ -698,7 +698,7 @@ TradeCenter_Trade: call GetMonName ld hl, wcd6d ld de, wNameOfPlayerMonToBeTraded - ld bc, 11 + ld bc, NAME_LENGTH call CopyData ld a, [wTradingWhichEnemyMon] ld hl, wEnemyPartyMons @@ -709,11 +709,11 @@ TradeCenter_Trade: ld [wd11e], a call GetMonName ld hl, WillBeTradedText - bcCoord 1, 14 + coord bc, 1, 14 call TextCommandProcessor call SaveScreenTilesToBuffer1 - hlCoord 10, 7 - ld bc, $080b + coord hl, 10, 7 + lb bc, 8, 11 ld a, TRADE_CANCEL_MENU ld [wTwoOptionMenuID], a ld a, TWO_OPTION_MENU @@ -726,11 +726,11 @@ TradeCenter_Trade: ; if trade cancelled ld a, $1 ld [wSerialExchangeNybbleSendData], a - hlCoord 0, 12 + coord hl, 0, 12 ld b, 4 ld c, 18 call CableClub_TextBoxBorder - hlCoord 1, 14 + coord hl, 1, 14 ld de, TradeCanceled call PlaceString call Serial_PrintWaitingTextAndSyncAndExchangeNybble @@ -743,11 +743,11 @@ TradeCenter_Trade: dec a ; did the other person cancel? jr nz, .doTrade ; if the other person cancelled - hlCoord 0, 12 + coord hl, 0, 12 ld b, 4 ld c, 18 call CableClub_TextBoxBorder - hlCoord 1, 14 + coord hl, 1, 14 ld de, TradeCanceled call PlaceString jp .tradeCancelled @@ -756,7 +756,7 @@ TradeCenter_Trade: ld hl, wPartyMonOT call SkipFixedLengthTextEntries ld de, wTradedPlayerMonOT - ld bc, 11 + ld bc, NAME_LENGTH call CopyData ld hl, wPartyMon1Species ld a, [wTradingWhichPlayerMon] @@ -772,7 +772,7 @@ TradeCenter_Trade: ld hl, wEnemyMonOT call SkipFixedLengthTextEntries ld de, wTradedEnemyMonOT - ld bc, 11 + ld bc, NAME_LENGTH call CopyData ld hl, wEnemyMons ld a, [wTradingWhichEnemyMon] @@ -793,7 +793,7 @@ TradeCenter_Trade: ld a, [hl] ld [wTradedPlayerMonSpecies], a xor a - ld [wcf95], a + ld [wRemoveMonFromBox], a call RemovePokemon ld a, [wTradingWhichEnemyMon] ld c, a @@ -816,7 +816,7 @@ TradeCenter_Trade: dec a ld [wWhichPokemon], a ld a, $1 - ld [wccd4], a + ld [wForceEvolution], a ld a, [wTradingWhichEnemyMon] ld hl, wEnemyPartyMons ld b, 0 @@ -824,19 +824,19 @@ TradeCenter_Trade: add hl, bc ld a, [hl] ld [wTradedEnemyMonSpecies], a - ld a, $a - ld [wMusicHeaderPointer], a + ld a, 10 + ld [wAudioFadeOutControl], a ld a, $2 - ld [wc0f0], a + ld [wAudioSavedROMBank], a ld a, MUSIC_SAFARI_ZONE - ld [wc0ee], a + ld [wNewSoundID], a call PlaySound ld c, 100 call DelayFrames call ClearScreen call LoadHpBarAndStatusTilePatterns xor a - ld [wcc5b], a + ld [wUnusedCC5B], a ld a, [hSerialConnectionStatus] cp USING_EXTERNAL_CLOCK jr z, .usingExternalClock @@ -851,11 +851,11 @@ TradeCenter_Trade: call Serial_PrintWaitingTextAndSyncAndExchangeNybble ld c, 40 call DelayFrames - hlCoord 0, 12 + coord hl, 0, 12 ld b, 4 ld c, 18 call CableClub_TextBoxBorder - hlCoord 1, 14 + coord hl, 1, 14 ld de, TradeCompleted call PlaceString predef SaveSAVtoSRAM2 @@ -915,12 +915,12 @@ CableClub_Run: ; 5a5f (1:5a5f) inc a ; LINK_STATE_IN_CABLE_CLUB ld [wLinkState], a ld [$ffb5], a - ld a, $a - ld [wMusicHeaderPointer], a + ld a, 10 + ld [wAudioFadeOutControl], a ld a, BANK(Music_Celadon) - ld [wc0f0], a + ld [wAudioSavedROMBank], a ld a, MUSIC_CELADON - ld [wc0ee], a + ld [wNewSoundID], a jp PlaySound EmptyFunc3: ; 5aaf (1:5aaf) diff --git a/engine/clear_save.asm b/engine/clear_save.asm index 66d7e920..adbef1a4 100755 --- a/engine/clear_save.asm +++ b/engine/clear_save.asm @@ -1,12 +1,12 @@ DoClearSaveDialogue: ; 1c98a (7:498a) call ClearScreen - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand call LoadFontTilePatterns call LoadTextBoxTilePatterns ld hl, ClearSaveDataText call PrintText - hlCoord 14, 7 - ld bc, $80f + coord hl, 14, 7 + lb bc, 8, 15 ld a, NO_YES_MENU ld [wTwoOptionMenuID], a ld a, TWO_OPTION_MENU diff --git a/engine/evolution.asm b/engine/evolution.asm index 7ae88fdf..c65cc293 100755 --- a/engine/evolution.asm +++ b/engine/evolution.asm @@ -1,4 +1,4 @@ -Func_7bde9: ; 7bde9 (1e:7de9) +EvolveMon: ; 7bde9 (1e:7de9) push hl push de push bc @@ -8,72 +8,72 @@ Func_7bde9: ; 7bde9 (1e:7de9) push af xor a ld [wLowHealthAlarm], a - ld [wc02a], a + ld [wChannelSoundIDs + CH4], a dec a - ld [wc0ee], a + ld [wNewSoundID], a call PlaySound ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba - ld a, (SFX_08_3c - SFX_Headers_08) / 3 + ld [H_AUTOBGTRANSFERENABLED], a + ld a, SFX_TINK call PlaySound call Delay3 xor a - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba + ld [H_AUTOBGTRANSFERENABLED], a ld [hTilesetType], a - ld a, [wHPBarMaxHP] - ld [wcf1d], a - ld c, $0 - call Func_7beb4 - ld a, [wHPBarMaxHP + 1] + ld a, [wEvoOldSpecies] + ld [wWholeScreenPaletteMonSpecies], a + ld c, 0 + call EvolutionSetWholeScreenPalette + ld a, [wEvoNewSpecies] ld [wcf91], a ld [wd0b5], a - call Func_7beb9 + call Evolution_LoadPic ld de, vFrontPic ld hl, vBackPic ld bc, 7 * 7 call CopyVideoData - ld a, [wHPBarMaxHP] + ld a, [wEvoOldSpecies] ld [wcf91], a ld [wd0b5], a - call Func_7beb9 + call Evolution_LoadPic ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba - ld a, [wHPBarMaxHP] + ld [H_AUTOBGTRANSFERENABLED], a + ld a, [wEvoOldSpecies] call PlayCry call WaitForSoundToFinish ld c, BANK(Music_SafariZone) ld a, MUSIC_SAFARI_ZONE call PlayMusic - ld c, $50 + ld c, 80 call DelayFrames - ld c, $1 - call Func_7beb4 - ld bc, $110 -.asm_7be63 + ld c, 1 ; set PAL_BLACK instead of mon palette + call EvolutionSetWholeScreenPalette + lb bc, $1, $10 +.animLoop push bc - call asm_7befa - jr c, .asm_7bea9 - call asm_7bec2 + call Evolution_CheckForCancel + jr c, .evolutionCancelled + call Evolution_BackAndForthAnim pop bc inc b dec c dec c - jr nz, .asm_7be63 + jr nz, .animLoop xor a - ld [wHPBarOldHP + 1], a + ld [wEvoCancelled], a ld a, $31 - ld [wHPBarOldHP], a - call Func_7bed6 - ld a, [wHPBarMaxHP + 1] -.asm_7be81 - ld [wcf1d], a + ld [wEvoMonTileOffset], a + call Evolution_ChangeMonPic ; show the new species pic + ld a, [wEvoNewSpecies] +.done + ld [wWholeScreenPaletteMonSpecies], a ld a, $ff - ld [wc0ee], a + ld [wNewSoundID], a call PlaySound - ld a, [wcf1d] + ld a, [wWholeScreenPaletteMonSpecies] call PlayCry - ld c, $0 - call Func_7beb4 + ld c, 0 + call EvolutionSetWholeScreenPalette pop af ld [wd0b5], a pop af @@ -81,77 +81,80 @@ Func_7bde9: ; 7bde9 (1e:7de9) pop bc pop de pop hl - ld a, [wHPBarOldHP + 1] + ld a, [wEvoCancelled] and a ret z scf ret -.asm_7bea9 +.evolutionCancelled pop bc - ld a, $1 - ld [wHPBarOldHP + 1], a - ld a, [wHPBarMaxHP] - jr .asm_7be81 + ld a, 1 + ld [wEvoCancelled], a + ld a, [wEvoOldSpecies] + jr .done -Func_7beb4: ; 7beb4 (1e:7eb4) - ld b, $b - jp GoPAL_SET +EvolutionSetWholeScreenPalette: ; 7beb4 (1e:7eb4) + ld b, SET_PAL_POKEMON_WHOLE_SCREEN + jp RunPaletteCommand -Func_7beb9: ; 7beb9 (1e:7eb9) +Evolution_LoadPic: ; 7beb9 (1e:7eb9) call GetMonHeader - hlCoord 7, 2 + coord hl, 7, 2 jp LoadFlippedFrontSpriteByMonIndex -asm_7bec2: ; 7bec2 (1e:7ec2) + +Evolution_BackAndForthAnim: ; 7bec2 (1e:7ec2) +; show the mon change back and forth between the new and old species b times ld a, $31 - ld [wHPBarOldHP], a - call Func_7bed6 - ld a, $cf - ld [wHPBarOldHP], a - call Func_7bed6 + ld [wEvoMonTileOffset], a + call Evolution_ChangeMonPic + ld a, -$31 + ld [wEvoMonTileOffset], a + call Evolution_ChangeMonPic dec b - jr nz, asm_7bec2 + jr nz, Evolution_BackAndForthAnim ret -Func_7bed6: ; 7bed6 (1e:7ed6) +Evolution_ChangeMonPic: ; 7bed6 (1e:7ed6) push bc xor a - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba - hlCoord 7, 2 - ld bc, $707 - ld de, $d -.asm_7bee3 + ld [H_AUTOBGTRANSFERENABLED], a + coord hl, 7, 2 + lb bc, 7, 7 + ld de, SCREEN_WIDTH - 7 +.loop push bc -.asm_7bee4 - ld a, [wHPBarOldHP] +.innerLoop + ld a, [wEvoMonTileOffset] add [hl] ld [hli], a dec c - jr nz, .asm_7bee4 + jr nz, .innerLoop pop bc add hl, de dec b - jr nz, .asm_7bee3 - ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba + jr nz, .loop + ld a, 1 + ld [H_AUTOBGTRANSFERENABLED], a call Delay3 pop bc ret -asm_7befa: ; 7befa (1e:7efa) + +Evolution_CheckForCancel: ; 7befa (1e:7efa) call DelayFrame push bc call JoypadLowSensitivity ld a, [hJoy5] pop bc - and $2 - jr nz, .asm_7bf0d -.asm_7bf08 + and B_BUTTON + jr nz, .pressedB +.notAllowedToCancel dec c - jr nz, asm_7befa + jr nz, Evolution_CheckForCancel and a ret -.asm_7bf0d - ld a, [wccd4] +.pressedB + ld a, [wForceEvolution] and a - jr nz, .asm_7bf08 + jr nz, .notAllowedToCancel scf ret diff --git a/engine/evolve_trade.asm b/engine/evolve_trade.asm index ec230677..81e41166 100755 --- a/engine/evolve_trade.asm +++ b/engine/evolve_trade.asm @@ -31,11 +31,11 @@ EvolveTradeMon: ; 17d7d (5:7d7d) ret nz .ok - ld a, [wPartyCount] ; wPartyCount + ld a, [wPartyCount] dec a - ld [wWhichPokemon], a ; wWhichPokemon + ld [wWhichPokemon], a ld a, $1 - ld [wccd4], a + ld [wForceEvolution], a ld a, LINK_STATE_TRADING ld [wLinkState], a callab TryEvolvingMon diff --git a/engine/evos_moves.asm b/engine/evos_moves.asm index e7750c22..056c125e 100755 --- a/engine/evos_moves.asm +++ b/engine/evos_moves.asm @@ -1,11 +1,11 @@ ; try to evolve the mon in [wWhichPokemon] TryEvolvingMon: ; 3ad0e (e:6d0e) - ld hl, wccd3 + ld hl, wCanEvolveFlags xor a ld [hl], a ld a, [wWhichPokemon] ld c, a - ld b, $1 + ld b, FLAG_SET call Evolution_FlagAction ; this is only called after battle @@ -14,7 +14,7 @@ EvolutionAfterBattle: ; 3ad1c (e:6d1c) ld a, [hTilesetType] push af xor a - ld [wd121], a + ld [wEvolutionOccurred], a dec a ld [wWhichPokemon], a push hl @@ -31,17 +31,17 @@ Evolution_PartyMonLoop: ; loop over party mons ld a, [hl] cp $ff ; have we reached the end of the party? jp z, .done - ld [wHPBarMaxHP], a + ld [wEvoOldSpecies], a push hl ld a, [wWhichPokemon] ld c, a - ld hl, wccd3 - ld b, $2 + ld hl, wCanEvolveFlags + ld b, FLAG_TEST call Evolution_FlagAction ld a, c and a ; is the mon's bit set? jp z, Evolution_PartyMonLoop ; if not, go to the next mon - ld a, [wHPBarMaxHP] + ld a, [wEvoOldSpecies] dec a ld b, 0 ld hl, EvosMovesPointerTable @@ -55,8 +55,8 @@ Evolution_PartyMonLoop: ; loop over party mons push hl ld a, [wcf91] push af - xor a - ld [wcc49], a + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation], a call LoadMonData pop af ld [wcf91], a @@ -76,7 +76,7 @@ Evolution_PartyMonLoop: ; loop over party mons ld a, b cp EV_ITEM jr z, .checkItemEvo - ld a, [wccd4] + ld a, [wForceEvolution] and a jr nz, Evolution_PartyMonLoop ld a, b @@ -91,7 +91,7 @@ Evolution_PartyMonLoop: ; loop over party mons ld a, [wLoadedMonLevel] cp b ; is the mon's level greater than the evolution requirement? jp c, Evolution_PartyMonLoop ; if so, go the next mon - jr .asm_3adb6 + jr .doEvolution .checkItemEvo ld a, [hli] ld b, a ; evolution item @@ -104,32 +104,32 @@ Evolution_PartyMonLoop: ; loop over party mons ld a, [wLoadedMonLevel] cp b ; is the mon's level greater than the evolution requirement? jp c, .nextEvoEntry2 ; if so, go the next evolution entry -.asm_3adb6 +.doEvolution ld [W_CURENEMYLVL], a - ld a, $1 - ld [wd121], a + ld a, 1 + ld [wEvolutionOccurred], a push hl ld a, [hl] - ld [wHPBarMaxHP + 1], a + ld [wEvoNewSpecies], a ld a, [wWhichPokemon] ld hl, wPartyMonNicks call GetPartyMonName call CopyStringToCF4B ld hl, IsEvolvingText call PrintText - ld c, $32 + ld c, 50 call DelayFrames xor a ld [H_AUTOBGTRANSFERENABLED], a - ld hl, wTileMap - ld bc, $c14 + coord hl, 0, 0 + lb bc, 12, 20 call ClearScreenArea ld a, $1 ld [H_AUTOBGTRANSFERENABLED], a ld a, $ff ld [wUpdateSpritesEnabled], a call ClearSprites - callab Func_7bde9 + callab EvolveMon jp c, CancelledEvolution ld hl, EvolvedText call PrintText @@ -137,7 +137,7 @@ Evolution_PartyMonLoop: ; loop over party mons ld a, [hl] ld [wd0b5], a ld [wLoadedMonSpecies], a - ld [wHPBarMaxHP + 1], a + ld [wEvoNewSpecies], a ld a, MONSTER_NAME ld [wNameListType], a ld a, BANK(TrainerNames) ; bank is not used for monster names @@ -145,11 +145,11 @@ Evolution_PartyMonLoop: ; loop over party mons call GetName push hl ld hl, IntoText - call Func_3c46 - ld a, (SFX_02_3b - SFX_Headers_02) / 3 + call PrintText_NoCreatingTextBox + ld a, SFX_GET_ITEM_2 call PlaySoundWaitForCurrent call WaitForSoundToFinish - ld c, $28 + ld c, 40 call DelayFrames call ClearScreen call RenameEvolvedMon @@ -161,12 +161,12 @@ Evolution_PartyMonLoop: ; loop over party mons ld a, [wd11e] dec a ld hl, BaseStats - ld bc, $1c + ld bc, MonBaseStatsEnd - MonBaseStats call AddNTimes ld de, W_MONHEADER call CopyData ld a, [wd0b5] - ld [W_MONHDEXNUM], a + ld [W_MONHINDEX], a pop af ld [wd11e], a ld hl, wLoadedMonHPExp - 1 @@ -206,7 +206,7 @@ Evolution_PartyMonLoop: ; loop over party mons ld a, [wd0b5] ld [wd11e], a xor a - ld [wcc49], a + ld [wMonDataLocation], a call LearnMoveFromLevelUp pop hl predef SetPartyMonTypes @@ -217,7 +217,7 @@ Evolution_PartyMonLoop: ; loop over party mons ld a, [wd11e] dec a ld c, a - ld b, $1 + ld b, FLAG_SET ld hl, wPokedexOwned push bc call Evolution_FlagAction @@ -252,17 +252,17 @@ Evolution_PartyMonLoop: ; loop over party mons ld a, [W_ISINBATTLE] and a ret nz - ld a, [wd121] + ld a, [wEvolutionOccurred] and a call nz, PlayDefaultMusic ret -; checks if the evolved mon's name is different from the standard name (i.e. it has a nickname) -; if so, rename it to is evolved form's standard name RenameEvolvedMon: ; 3aef7 (e:6ef7) +; Renames the mon to its new, evolved form's standard name unless it had a +; nickname, in which case the nickname is kept. ld a, [wd0b5] push af - ld a, [W_MONHDEXNUM] + ld a, [W_MONHINDEX] ld [wd0b5], a call GetName pop af @@ -275,10 +275,10 @@ RenameEvolvedMon: ; 3aef7 (e:6ef7) cp [hl] inc hl ret nz - cp $50 + cp "@" jr nz, .compareNamesLoop ld a, [wWhichPokemon] - ld bc, $b + ld bc, NAME_LENGTH ld hl, wPartyMonNicks call AddNTimes push hl @@ -345,18 +345,19 @@ LearnMoveFromLevelUp: ; 3af5b (e:6f5b) ld a, [hli] ; move ID jr nz, .learnSetLoop ld d, a ; ID of move to learn - ld a, [wcc49] + ld a, [wMonDataLocation] and a jr nz, .next -; if [wcc49] is 0, get the address of the mon's current moves -; there is no reason to make this conditional because the code wouldn't work properly without doing this -; every call to this function sets [wcc49] to 0 +; If [wMonDataLocation] is 0 (PLAYER_PARTY_DATA), get the address of the mon's +; current moves in party data. Every call to this function sets +; [wMonDataLocation] to 0 because other data locations are not supported. +; If it is not 0, this function will not work properly. ld hl, wPartyMon1Moves ld a, [wWhichPokemon] ld bc, wPartyMon2 - wPartyMon1 call AddNTimes .next - ld b, $4 + ld b, NUM_MOVES .checkCurrentMovesLoop ; check if the move to learn is already known ld a, [hli] cp d @@ -376,14 +377,13 @@ LearnMoveFromLevelUp: ; 3af5b (e:6f5b) ; writes the moves a mon has at level [W_CURENEMYLVL] to [de] ; move slots are being filled up sequentially and shifted if all slots are full -; [wHPBarMaxHP]: (?) WriteMonMoves: ; 3afb8 (e:6fb8) call GetPredefRegisters push hl push de push bc ld hl, EvosMovesPointerTable - ld b, $0 + ld b, 0 ld a, [wcf91] ; cur mon ID dec a add a @@ -407,28 +407,33 @@ WriteMonMoves: ; 3afb8 (e:6fb8) and a jp z, .done ; end of list ld b, a - ld a, [W_CURENEMYLVL] ; W_CURENEMYLVL + ld a, [W_CURENEMYLVL] cp b jp c, .done ; mon level < move level (assumption: learnset is sorted by level) - ld a, [wHPBarMaxHP] + ld a, [wLearningMovesFromDayCare] and a jr z, .skipMinLevelCheck - ld a, [wWhichTrade] ; wWhichTrade (min move level) + ld a, [wDayCareStartLevel] cp b jr nc, .nextMove2 ; min level >= move level + .skipMinLevelCheck + +; check if the move is already known push de - ld c, $4 -.moveAlreadyLearnedCheckLoop + ld c, NUM_MOVES +.alreadyKnowsCheckLoop ld a, [de] inc de cp [hl] jr z, .nextMove dec c - jr nz, .moveAlreadyLearnedCheckLoop + jr nz, .alreadyKnowsCheckLoop + +; try to find an empty move slot pop de push de - ld c, $4 + ld c, NUM_MOVES .findEmptySlotLoop ld a, [de] and a @@ -436,47 +441,55 @@ WriteMonMoves: ; 3afb8 (e:6fb8) inc de dec c jr nz, .findEmptySlotLoop - pop de ; no empty move slots found + +; no empty move slots found + pop de push de push hl ld h, d ld l, e call WriteMonMoves_ShiftMoveData ; shift all moves one up (deleting move 1) - ld a, [wHPBarMaxHP] + ld a, [wLearningMovesFromDayCare] and a jr z, .writeMoveToSlot + +; shift PP as well if learning moves from day care push de - ld bc, $12 + ld bc, wPartyMon1PP - (wPartyMon1Moves + 3) add hl, bc ld d, h ld e, l call WriteMonMoves_ShiftMoveData ; shift all move PP data one up pop de + .writeMoveToSlot pop hl .writeMoveToSlot2 ld a, [hl] ld [de], a - ld a, [wHPBarMaxHP] + ld a, [wLearningMovesFromDayCare] and a jr z, .nextMove - push hl ; write move PP value + +; write move PP value if learning moves from day care + push hl ld a, [hl] - ld hl, $15 + ld hl, wPartyMon1PP - wPartyMon1Moves add hl, de push hl dec a ld hl, Moves - ld bc, $6 + ld bc, MoveEnd - Moves call AddNTimes - ld de, wHPBarMaxHP + ld de, wBuffer ld a, BANK(Moves) call FarCopyData - ld a, [wHPBarNewHP + 1] + ld a, [wBuffer + 5] pop hl ld [hl], a pop hl jr .nextMove + .done pop bc pop de @@ -485,13 +498,13 @@ WriteMonMoves: ; 3afb8 (e:6fb8) ; shifts all move data one up (freeing 4th move slot) WriteMonMoves_ShiftMoveData: ; 3b04e (e:704e) - ld c, $3 -.asm_3b050 + ld c, NUM_MOVES - 1 +.loop inc de ld a, [de] ld [hli], a dec c - jr nz, .asm_3b050 + jr nz, .loop ret Evolution_FlagAction: ; 3b057 (e:7057) diff --git a/engine/experience.asm b/engine/experience.asm index 68d22843..b43fbcf9 100755 --- a/engine/experience.asm +++ b/engine/experience.asm @@ -10,15 +10,15 @@ CalcLevelFromExperience: ; 58f43 (16:4f43) push hl ld hl, wLoadedMonExp + 2 ; current exp ; compare exp needed for level d with current exp - ld a, [H_MULTIPLICAND + 2] + ld a, [hExperience + 2] ld c, a ld a, [hld] sub c - ld a, [H_MULTIPLICAND + 1] + ld a, [hExperience + 1] ld c, a ld a, [hld] sbc c - ld a, [H_MULTIPLICAND] + ld a, [hExperience] ld c, a ld a, [hl] sbc c @@ -33,113 +33,117 @@ CalcExperience: ; 58f6a (16:4f6a) add a add a ld c, a - ld b, $0 + ld b, 0 ld hl, GrowthRateTable add hl, bc call CalcDSquared ld a, d - ld [H_MULTIPLIER], a ; $ff99 + ld [H_MULTIPLIER], a call Multiply ld a, [hl] and $f0 swap a - ld [H_MULTIPLIER], a ; $ff99 + ld [H_MULTIPLIER], a call Multiply ld a, [hli] and $f - ld [H_DIVISOR], a ; $ff99 + ld [H_DIVISOR], a ld b, $4 call Divide - ld a, [H_MULTIPLICAND] ; $ff96 (aliases: H_NUMTOPRINT) + ld a, [H_QUOTIENT + 1] push af - ld a, [H_MULTIPLICAND+1] + ld a, [H_QUOTIENT + 2] push af - ld a, [H_MULTIPLICAND+2] + ld a, [H_QUOTIENT + 3] push af call CalcDSquared ld a, [hl] and $7f - ld [H_MULTIPLIER], a ; $ff99 + ld [H_MULTIPLIER], a call Multiply - ld a, [H_MULTIPLICAND] ; $ff96 (aliases: H_NUMTOPRINT) + ld a, [H_PRODUCT + 1] push af - ld a, [H_MULTIPLICAND+1] + ld a, [H_PRODUCT + 2] push af - ld a, [H_MULTIPLICAND+2] + ld a, [H_PRODUCT + 3] push af ld a, [hli] push af xor a - ld [H_MULTIPLICAND], a ; $ff96 - ld [H_MULTIPLICAND+1], a + ld [H_MULTIPLICAND], a + ld [H_MULTIPLICAND + 1], a ld a, d - ld [H_MULTIPLICAND+2], a + ld [H_MULTIPLICAND + 2], a ld a, [hli] ld [H_MULTIPLIER], a call Multiply ld b, [hl] - ld a, [H_MULTIPLICAND+2] + ld a, [H_PRODUCT + 3] sub b - ld [H_MULTIPLICAND+2], a + ld [H_PRODUCT + 3], a ld b, $0 - ld a, [H_MULTIPLICAND+1] + ld a, [H_PRODUCT + 2] sbc b - ld [H_MULTIPLICAND+1], a - ld a, [H_MULTIPLICAND] ; $ff96 + ld [H_PRODUCT + 2], a + ld a, [H_PRODUCT + 1] sbc b - ld [H_MULTIPLICAND], a ; $ff96 + ld [H_PRODUCT + 1], a +; The difference of the linear term and the constant term consists of 3 bytes +; starting at H_PRODUCT + 1. Below, hExperience (an alias of that address) will +; be used instead for the further work of adding or subtracting the squared +; term and adding the cubed term. pop af and $80 jr nz, .subtractSquaredTerm ; check sign pop bc - ld a, [H_MULTIPLICAND+2] + ld a, [hExperience + 2] add b - ld [H_MULTIPLICAND+2], a + ld [hExperience + 2], a pop bc - ld a, [H_MULTIPLICAND+1] + ld a, [hExperience + 1] adc b - ld [H_MULTIPLICAND+1], a + ld [hExperience + 1], a pop bc - ld a, [H_MULTIPLICAND] + ld a, [hExperience] adc b - ld [H_MULTIPLICAND], a + ld [hExperience], a jr .addCubedTerm .subtractSquaredTerm pop bc - ld a, [H_MULTIPLICAND+2] + ld a, [hExperience + 2] sub b - ld [H_MULTIPLICAND+2], a + ld [hExperience + 2], a pop bc - ld a, [H_MULTIPLICAND+1] + ld a, [hExperience + 1] sbc b - ld [H_MULTIPLICAND+1], a + ld [hExperience + 1], a pop bc - ld a, [H_MULTIPLICAND] + ld a, [hExperience] sbc b - ld [H_MULTIPLICAND], a + ld [hExperience], a .addCubedTerm pop bc - ld a, [H_MULTIPLICAND+2] + ld a, [hExperience + 2] add b - ld [H_MULTIPLICAND+2], a + ld [hExperience + 2], a pop bc - ld a, [H_MULTIPLICAND+1] + ld a, [hExperience + 1] adc b - ld [H_MULTIPLICAND+1], a + ld [hExperience + 1], a pop bc - ld a, [H_MULTIPLICAND] + ld a, [hExperience] adc b - ld [H_MULTIPLICAND], a + ld [hExperience], a ret ; calculates d*d CalcDSquared: ; 59010 (16:5010) xor a - ld [H_MULTIPLICAND], a ; $ff96 (aliases: H_NUMTOPRINT) - ld [H_MULTIPLICAND+1], a + ld [H_MULTIPLICAND], a + ld [H_MULTIPLICAND + 1], a ld a, d - ld [H_MULTIPLICAND+2], a - ld [H_MULTIPLIER], a ; $ff99 (aliases: H_DIVISOR, H_REMAINDER, H_POWEROFTEN) + ld [H_MULTIPLICAND + 2], a + ld [H_MULTIPLIER], a jp Multiply ; each entry has the following scheme: diff --git a/engine/game_corner_slots.asm b/engine/game_corner_slots.asm index 52f61daf..ff17d4d3 100755 --- a/engine/game_corner_slots.asm +++ b/engine/game_corner_slots.asm @@ -1,5 +1,5 @@ StartSlotMachine: ; 37e2d (d:7e2d) - ld a, [wTrainerSpriteOffset] + ld a, [wHiddenObjectFunctionArgument] cp $fd jr z, .printOutOfOrder cp $fe @@ -7,33 +7,33 @@ StartSlotMachine: ; 37e2d (d:7e2d) cp $ff jr z, .printSomeonesKeys callba AbleToPlaySlotsCheck - ld a, [wTrainerSpriteOffset] + ld a, [wCanPlaySlots] and a ret z - ld a, [wUnknownSlotVar] + ld a, [wLuckySlotHiddenObjectIndex] ld b, a - ld a, [wTrainerFacingDirection] + ld a, [wHiddenObjectIndex] inc a cp b - jr z, .asm_37e58 - ld a, $fd - jr .asm_37e5a -.asm_37e58 - ld a, $fa -.asm_37e5a - ld [wcc5b], a + jr z, .match + ld a, 253 + jr .next +.match + ld a, 250 +.next + ld [wSlotMachineSevenAndBarModeChance], a ld a, [H_LOADEDROMBANK] - ld [wcc5e], a + ld [wSlotMachineSavedROMBank], a call PromptUserToPlaySlots ret .printOutOfOrder - ld a, $28 + tx_pre_id GameCornerOutOfOrderText jr .printText .printOutToLunch - ld a, $29 + tx_pre_id GameCornerOutToLunchText jr .printText .printSomeonesKeys - ld a, $2a + tx_pre_id GameCornerSomeonesKeysText .printText push af call EnableAutoTextBoxDrawing diff --git a/engine/game_corner_slots2.asm b/engine/game_corner_slots2.asm index 66e51237..58386ba1 100755 --- a/engine/game_corner_slots2.asm +++ b/engine/game_corner_slots2.asm @@ -1,25 +1,25 @@ -AbleToPlaySlotsCheck ; 2ff09 (b:7f09) +AbleToPlaySlotsCheck: ; 2ff09 (b:7f09) ld a, [wSpriteStateData1 + 2] and $8 jr z, .done ; not able ld b, COIN_CASE - predef IsItemInBag_ ; IsItemInBag_ + predef GetQuantityOfItemInBag ld a, b and a - ld b, $33 ; GameCornerCoinCaseText + ld b, (GameCornerCoinCaseText_id - TextPredefs) / 2 + 1 jr z, .printCoinCaseRequired ld hl, wPlayerCoins ld a, [hli] or [hl] jr nz, .done ; able to play - ld b, $32 ; GameCornerNoCoinsText + ld b, (GameCornerNoCoinsText_id - TextPredefs) / 2 + 1 .printCoinCaseRequired call EnableAutoTextBoxDrawing ld a, b call PrintPredefTextID xor a .done - ld [wWhichTrade], a + ld [wCanPlaySlots], a ret GameCornerCoinCaseText: ; 2ff32 (b:7f32) diff --git a/engine/gamefreak.asm b/engine/gamefreak.asm index 528d355e..acbd5fc9 100755 --- a/engine/gamefreak.asm +++ b/engine/gamefreak.asm @@ -1,97 +1,107 @@ LoadShootingStarGraphics: ; 70000 (1c:4000) ld a, $f9 - ld [rOBP0], a ; $ff48 + ld [rOBP0], a ld a, $a4 ld [rOBP1], a ; $ff49 call Func_3040 call Func_3061 ld de, AnimationTileset2 ; $4757 ; star tile (top left quadrant) ld hl, vChars1 + $200 - ld bc, (BANK(AnimationTileset2) << 8) + $01 + lb bc, BANK(AnimationTileset2), $01 call CopyVideoData ld de, AnimationTileset2 + $100 ; $481e ; star tile (bottom left quadrant) ld hl, vChars1 + $210 - ld bc, (BANK(AnimationTileset2) << 8) + $01 + lb bc, BANK(AnimationTileset2), $01 call CopyVideoData - ld de, FallingStar ; $4190 + ld de, FallingStar ld hl, vChars1 + $220 - ld bc, (BANK(FallingStar) << 8) + $01 + lb bc, BANK(FallingStar), (FallingStarEnd - FallingStar) / $10 call CopyVideoData - ld hl, GameFreakLogoOAMData ; $4140 + ld hl, GameFreakLogoOAMData ld de, wOAMBuffer + $60 - ld bc, $40 + ld bc, GameFreakLogoOAMDataEnd - GameFreakLogoOAMData call CopyData - ld hl, GameFreakShootingStarOAMData ; $4180 + ld hl, GameFreakShootingStarOAMData ld de, wOAMBuffer - ld bc, $10 + ld bc, GameFreakShootingStarOAMDataEnd - GameFreakShootingStarOAMData jp CopyData AnimateShootingStar: ; 7004a (1c:404a) call LoadShootingStarGraphics ld a, $c2 ; (SFX_1f_67 - SFX_Headers_1f) / 3 call PlaySound + +; Move the big star down and left across the screen. ld hl, wOAMBuffer - ld bc, $a004 -.asm_70058 + lb bc, $a0, $4 +.bigStarLoop push hl push bc -.asm_7005a - ld a, [hl] - add $4 +.bigStarInnerLoop + ld a, [hl] ; Y + add 4 ; y ld [hli], a - ld a, [hl] - add $fc + ld a, [hl] ; X + add -4 ld [hli], a inc hl inc hl dec c - jr nz, .asm_7005a - ld c, $1 + jr nz, .bigStarInnerLoop + ld c, 1 call CheckForUserInterruption pop bc pop hl ret c ld a, [hl] - cp $50 - jr nz, .asm_70076 - jr .asm_70058 -.asm_70076 + cp 80 + jr nz, .next + jr .bigStarLoop +.next cp b - jr nz, .asm_70058 + jr nz, .bigStarLoop ld hl, wOAMBuffer - ld c, $4 - ld de, $4 -.loop - ld [hl], $a0 + ld c, 4 + ld de, 4 + +; Clear big star OAM. +.clearOAMLoop + ld [hl], 160 add hl, de dec c - jr nz, .loop - ld b, $3 -.asm_70089 + jr nz, .clearOAMLoop + +; Make Gamefreak logo flash. + ld b, 3 +.flashLogoLoop ld hl, rOBP0 ; $ff48 rrc [hl] rrc [hl] call Func_3040 - ld c, $a + ld c, 10 call CheckForUserInterruption ret c dec b - jr nz, .asm_70089 + jr nz, .flashLogoLoop +; Copy 24 instances of the small stars OAM data. +; Note that their coordinates put them off-screen. ld de, wOAMBuffer - ld a, $18 -.asm_700a1 + ld a, 24 +.initSmallStarsOAMLoop push af - ld hl, OAMData_70101 ; $40ee - ld bc, $4 + ld hl, SmallStarsOAM ; $40ee + ld bc, SmallStarsOAMEnd - SmallStarsOAM call CopyData pop af dec a - jr nz, .asm_700a1 + jr nz, .initSmallStarsOAMLoop + +; Animate the small stars falling from the Gamefreak logo. xor a - ld [wWhichTrade], a ; wWhichTrade - ld hl, PointerTable_70105 ; 1c:4105 - ld c, $6 -.asm_700b8 + ld [wMoveDownSmallStarsOAMCount], a ; wWhichTrade + ld hl, SmallStarsWaveCoordsPointerTable ; 1c:4105 + ld c, 6 +.smallStarsLoop ld a, [hli] ld e, a ld a, [hli] @@ -99,15 +109,15 @@ AnimateShootingStar: ; 7004a (1c:404a) push bc push hl ld hl, wOAMBuffer + $50 - ld c, $4 -.asm_700c3 + ld c, 4 +.smallStarsInnerLoop ; introduce new wave of 4 small stars OAM entries ld a, [de] cp $ff - jr z, .asm_700e8 - ld [hli], a + jr z, .next2 + ld [hli], a ; Y inc de ld a, [de] - ld [hli], a + ld [hli], a ; X inc de inc hl push bc @@ -121,41 +131,47 @@ AnimateShootingStar: ; 7004a (1c:404a) pop bc inc hl dec c - jr nz, .asm_700c3 - ld a, [wWhichTrade] ; wWhichTrade - cp $18 - jr z, .asm_700e8 - add $6 - ld [wWhichTrade], a ; wWhichTrade -.asm_700e8 - call Func_70142 + jr nz, .smallStarsInnerLoop + ld a, [wMoveDownSmallStarsOAMCount] + cp 24 + jr z, .next2 + add 6 ; should be 4, but the extra 2 aren't visible on screen + ld [wMoveDownSmallStarsOAMCount], a +.next2 + call MoveDownSmallStars push af + +; shift the existing OAM entries down to make room for the next wave ld hl, wOAMBuffer + $10 ld de, wOAMBuffer ld bc, $50 call CopyData + pop af pop hl pop bc ret c dec c - jr nz, .asm_700b8 + jr nz, .smallStarsLoop and a ret -OAMData_70101: ; 70101 (1c:4101) +SmallStarsOAM: ; 70101 (1c:4101) db $00,$00,$A2,$90 +SmallStarsOAMEnd: -PointerTable_70105: ; 70105 (1c:4105) - dw OAMData_70111 - dw OAMData_7011d - dw OAMData_70129 - dw OAMData_70135 - dw OAMData_70141 - dw OAMData_70141 +SmallStarsWaveCoordsPointerTable: ; 70105 (1c:4105) + dw SmallStarsWave1Coords + dw SmallStarsWave2Coords + dw SmallStarsWave3Coords + dw SmallStarsWave4Coords + dw SmallStarsEmptyWave + dw SmallStarsEmptyWave -; each entry is only half of an OAM tile -OAMData_70111: ; 70111 (1c:4111) +; The stars that fall from the Gamefreak logo come in 4 waves of 4 OAM entries. +; These arrays contain the Y and X coordinates of each OAM entry. + +SmallStarsWave1Coords: ; 70111 (1c:4111) db $68,$30 db $05,$68 db $40,$05 @@ -163,7 +179,7 @@ OAMData_70111: ; 70111 (1c:4111) db $04,$68 db $78,$07 -OAMData_7011d: ; 7011d (1c:411d) +SmallStarsWave2Coords: ; 7011d (1c:411d) db $68,$38 db $05,$68 db $48,$06 @@ -171,7 +187,7 @@ OAMData_7011d: ; 7011d (1c:411d) db $04,$68 db $70,$07 -OAMData_70129: ; 70129 (1c:4129) +SmallStarsWave3Coords: ; 70129 (1c:4129) db $68,$34 db $05,$68 db $4c,$06 @@ -179,7 +195,7 @@ OAMData_70129: ; 70129 (1c:4129) db $06,$68 db $64,$07 -OAMData_70135: ; 70135 (1c:4135) +SmallStarsWave4Coords: ; 70135 (1c:4135) db $68,$3c db $05,$68 db $5c,$04 @@ -187,30 +203,32 @@ OAMData_70135: ; 70135 (1c:4135) db $07,$68 db $74,$07 -OAMData_70141: ; 70141 (1c:4141) +SmallStarsEmptyWave: ; 70141 (1c:4141) db $FF -Func_70142: ; 70142 (1c:4142) - ld b, $8 -.asm_70144 +MoveDownSmallStars: ; 70142 (1c:4142) + ld b, 8 +.loop ld hl, wOAMBuffer + $5c - ld a, [wWhichTrade] ; wWhichTrade - ld de, $fffc + ld a, [wMoveDownSmallStarsOAMCount] + ld de, -4 ld c, a -.asm_7014e +.innerLoop inc [hl] add hl, de dec c - jr nz, .asm_7014e + jr nz, .innerLoop +; Toggle the palette so that the lower star in the small stars tile blinks in +; and out. ld a, [rOBP1] ; $ff49 - xor $a0 + xor %10100000 ld [rOBP1], a ; $ff49 call Func_3061 - ld c, $3 + ld c, 3 call CheckForUserInterruption ret c dec b - jr nz, .asm_70144 + jr nz, .loop ret GameFreakLogoOAMData: ; 70166 (1c:4166) @@ -230,12 +248,15 @@ GameFreakLogoOAMData: ; 70166 (1c:4166) db $60,$68,$83,$00 db $60,$70,$81,$00 db $60,$78,$86,$00 +GameFreakLogoOAMDataEnd: GameFreakShootingStarOAMData: ; 701a6 (1c:41a6) db $00,$A0,$A0,$14 db $00,$A8,$A0,$34 db $08,$A0,$A1,$14 db $08,$A8,$A1,$34 +GameFreakShootingStarOAMDataEnd: FallingStar: ; 701b6 (1c:41b6) INCBIN "gfx/falling_star.2bpp" +FallingStarEnd: diff --git a/engine/give_pokemon.asm b/engine/give_pokemon.asm index 93499cc8..410c9c33 100755 --- a/engine/give_pokemon.asm +++ b/engine/give_pokemon.asm @@ -1,33 +1,36 @@ _GivePokemon: ; f66fa (3d:66fa) +; returns success in carry +; and whether the mon was added to the party in [wAddedToParty] call EnableAutoTextBoxDrawing xor a - ld [wccd3], a - ld a, [wPartyCount] ; wPartyCount + ld [wAddedToParty], a + ld a, [wPartyCount] cp PARTY_LENGTH - jr c, .partyNotFull - ld a, [W_NUMINBOX] ; wda80 + jr c, .addToParty + ld a, [W_NUMINBOX] cp MONS_PER_BOX jr nc, .boxFull +; add to box xor a - ld [W_ENEMYBATTSTATUS3], a ; W_ENEMYBATTSTATUS3 + ld [W_ENEMYBATTSTATUS3], a ld a, [wcf91] ld [wEnemyMonSpecies2], a callab LoadEnemyMonData call SetPokedexOwnedFlag callab SendNewMonToBox ld hl, wcf4b - ld a, [wd5a0] + ld a, [wCurrentBoxNum] and $7f cp 9 - jr c, .boxEightOrLesser ; do not adjust box number to a 2 digit number + jr c, .singleDigitBoxNum sub 9 ld [hl], "1" inc hl add "0" - jr .continue -.boxEightOrLesser + jr .next +.singleDigitBoxNum add "1" -.continue +.next ld [hli], a ld [hl], "@" ld hl, SetToBoxText @@ -39,14 +42,14 @@ _GivePokemon: ; f66fa (3d:66fa) call PrintText and a ret -.partyNotFull +.addToParty call SetPokedexOwnedFlag ld hl, UnknownTerminator_f6794 call PrintText call AddPartyMon - ld a, $1 + ld a, 1 ld [wDoNotWaitForButtonPressAfterDisplayingText], a - ld [wccd3], a + ld [wAddedToParty], a scf ret @@ -58,8 +61,8 @@ SetPokedexOwnedFlag: ; f676c (3d:676c) ld a, [wd11e] dec a ld c, a - ld hl, wPokedexOwned ; wPokedexOwned - ld b, $1 + ld hl, wPokedexOwned + ld b, FLAG_SET predef FlagActionPredef pop af ld [wd11e], a diff --git a/engine/hall_of_fame.asm b/engine/hall_of_fame.asm index 0bd906c7..71b34dc3 100755 --- a/engine/hall_of_fame.asm +++ b/engine/hall_of_fame.asm @@ -1,5 +1,5 @@ AnimateHallOfFame: ; 701c6 (1c:41c6) - call Func_7047b + call HoFFadeOutScreenAndMusic call ClearScreen ld c, 100 call DelayFrames @@ -8,10 +8,10 @@ AnimateHallOfFame: ; 701c6 (1c:41c6) call DisableLCD ld hl,vBGMap0 ld bc, $800 - ld a, $7f + ld a, " " call FillMemory call EnableLCD - ld hl, rLCDC ; $ff40 + ld hl, rLCDC set 3, [hl] xor a ld hl, wHallOfFame @@ -21,16 +21,16 @@ AnimateHallOfFame: ; 701c6 (1c:41c6) ld [wUpdateSpritesEnabled], a ld [hTilesetType], a ld [W_SPRITEFLIPPED], a - ld [wd358], a - ld [wTrainerScreenY], a + ld [wLetterPrintingDelayFlags], a ; no delay + ld [wHoFMonOrPlayer], a ; mon inc a - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba - ld hl, wd5a2 + ld [H_AUTOBGTRANSFERENABLED], a + ld hl, wNumHoFTeams ld a, [hl] inc a - jr z, .asm_70211 + jr z, .skipInc ; don't wrap around to 0 inc [hl] -.asm_70211 +.skipInc ld a, $90 ld [hWY], a ld c, $1f ; BANK(Music_HallOfFame) @@ -38,29 +38,29 @@ AnimateHallOfFame: ; 701c6 (1c:41c6) call PlayMusic ld hl, wPartySpecies ld c, $ff -.asm_70221 +.partyMonLoop ld a, [hli] cp $ff - jr z, .asm_70266 + jr z, .doneShowingParty inc c push hl push bc - ld [wWhichTrade], a ; wWhichTrade + ld [wHoFMonSpecies], a ld a, c - ld [wTrainerEngageDistance], a - ld hl, wPartyMon1Level ; wPartyMon1Level + ld [wHoFPartyMonIndex], a + ld hl, wPartyMon1Level ld bc, wPartyMon2 - wPartyMon1 call AddNTimes ld a, [hl] - ld [wTrainerFacingDirection], a - call Func_702a2 - call Func_7030e - ld c, $50 + ld [wHoFMonLevel], a + call HoFShowMonOrPlayer + call HoFDisplayAndRecordMonInfo + ld c, 80 call DelayFrames - hlCoord 2, 13 - ld bc, $30e + coord hl, 2, 13 + lb bc, $3, $e call TextBoxBorder - hlCoord 4, 15 + coord hl, 4, 15 ld de, HallOfFameText call PlaceString ld c, 180 @@ -68,8 +68,8 @@ AnimateHallOfFame: ; 701c6 (1c:41c6) call GBFadeOutToWhite pop bc pop hl - jr .asm_70221 -.asm_70266 + jr .partyMonLoop +.doneShowingParty ld a, c inc a ld hl, wHallOfFame @@ -78,137 +78,138 @@ AnimateHallOfFame: ; 701c6 (1c:41c6) ld [hl], $ff callab SaveHallOfFameTeams ; useless since in same bank xor a - ld [wWhichTrade], a ; wWhichTrade + ld [wHoFMonSpecies], a inc a - ld [wTrainerScreenY], a - call Func_702a2 - call Func_703d1 - call Func_7047b + ld [wHoFMonOrPlayer], a ; player + call HoFShowMonOrPlayer + call HoFDisplayPlayerStats + call HoFFadeOutScreenAndMusic xor a ld [hWY], a - ld hl, rLCDC ; $ff40 + ld hl, rLCDC res 3, [hl] ret HallOfFameText: ; 70295 (1c:4295) db "HALL OF FAME@" -Func_702a2: ; 702a2 (1c:42a2) +HoFShowMonOrPlayer: ; 702a2 (1c:42a2) call ClearScreen ld a, $d0 ld [hSCY], a ld a, $c0 ld [hSCX], a - ld a, [wWhichTrade] ; wWhichTrade + ld a, [wHoFMonSpecies] ld [wcf91], a ld [wd0b5], a ld [wBattleMonSpecies2], a - ld [wcf1d], a - ld a, [wTrainerScreenY] + ld [wWholeScreenPaletteMonSpecies], a + ld a, [wHoFMonOrPlayer] and a - jr z, .asm_702c7 - call Func_70390 - jr .asm_702d5 -.asm_702c7 - hlCoord 12, 5 + jr z, .showMon +; show player + call HoFLoadPlayerPics + jr .next1 +.showMon + coord hl, 12, 5 call GetMonHeader call LoadFrontSpriteByMonIndex predef LoadMonBackPic -.asm_702d5 - ld b, $b - ld c, $0 - call GoPAL_SET - ld a, $e4 - ld [rBGP], a ; $ff47 +.next1 + ld b, SET_PAL_POKEMON_WHOLE_SCREEN + ld c, 0 + call RunPaletteCommand + ld a, %11100100 + ld [rBGP], a call Func_3021 - ld c, $31 - call Func_703c7 + ld c, $31 ; back pic + call HoFLoadMonPlayerPicTileIDs ld d, $a0 - ld e, $4 + ld e, 4 ld a, [wOnSGB] and a - jr z, .asm_702f4 - sla e -.asm_702f4 - call .asm_70302 + jr z, .next2 + sla e ; scroll more slowly on SGB +.next2 + call .ScrollPic ; scroll back pic left xor a ld [hSCY], a - ld c, a - call Func_703c7 - ld d, $0 - ld e, $fc -.asm_70302 + ld c, a ; front pic + call HoFLoadMonPlayerPicTileIDs + ld d, 0 + ld e, -4 +; scroll front pic right + +.ScrollPic call DelayFrame ld a, [hSCX] add e ld [hSCX], a cp d - jr nz, .asm_70302 + jr nz, .ScrollPic ret -Func_7030e: ; 7030e (1c:430e) - ld a, [wTrainerEngageDistance] +HoFDisplayAndRecordMonInfo: ; 7030e (1c:430e) + ld a, [wHoFPartyMonIndex] ld hl, wPartyMonNicks ; wPartyMonNicks call GetPartyMonName - call Func_70348 - ld a, [wTrainerEngageDistance] + call HoFDisplayMonInfo + ld a, [wHoFPartyMonIndex] ld [wWhichPokemon], a callab Func_fce18 ; 3f:4e18 jr nc, .asm_70336 - ld e,$22 + ld e, $22 callab Func_f0000 jr .asm_7033c .asm_70336 - ld a,[wWhichTrade] + ld a,[wHoFMonSpecies] call PlayCry .asm_7033c - jp Func_7045c + jp HoFRecordMonInfo Func_7033f: ; 7033f (1c:433f) - call Func_70348 - ld a,[wWhichTrade] + call HoFDisplayMonInfo + ld a,[wHoFMonSpecies] jp PlayCry -Func_70348: ; 70348 (1c:4348) - hlCoord 0, 2 - ld bc, $90a +HoFDisplayMonInfo: ; 70348 (1c:4348) + coord hl, 0, 2 + lb bc, 9, 10 call TextBoxBorder - hlCoord 2, 6 + coord hl, 2, 6 ld de, HoFMonInfoText call PlaceString - hlCoord 1, 4 + coord hl, 1, 4 ld de, wcd6d call PlaceString - ld a, [wTrainerFacingDirection] - hlCoord 8, 7 + ld a, [wHoFMonLevel] + coord hl, 8, 7 call PrintLevelCommon - ld a, [wWhichTrade] ; wWhichTrade + ld a, [wHoFMonSpecies] ld [wd0b5], a - hlCoord 3, 9 + coord hl, 3, 9 predef PrintMonType ret - ;ld a, [wWhichTrade] ; wWhichTrade - ;jp PlayCry HoFMonInfoText: ; 7037b (1c:437b) db "LEVEL/" next "TYPE1/" next "TYPE2/@" -Func_70390: ; 70390 (1c:433e) +HoFLoadPlayerPics: ; 70390 (1c:433e) ld de, RedPicFront ; $6ede ld a, BANK(RedPicFront) call UncompressSpriteFromDE ld a,$0 call SwitchSRAMBankAndLatchClockData ld hl, S_SPRITEBUFFER1 - ld de, $a000 + ld de, S_SPRITEBUFFER0 ld bc, $310 call CopyData call PrepareRTCDataAndDisableSRAM ld de, vFrontPic call InterlaceMergeSpriteBuffers - ld de, RedPicBack ; $7e0a + ld de, RedPicBack ld a, BANK(RedPicBack) call UncompressSpriteFromDE predef ScaleSpriteByTwo @@ -216,52 +217,52 @@ Func_70390: ; 70390 (1c:433e) call InterlaceMergeSpriteBuffers ld c, $1 -Func_703c7: ; 703c7 (1c:43c7) +HoFLoadMonPlayerPicTileIDs: ; 703c7 (1c:43c7) ld b, $0 - hlCoord 12, 5 + coord hl, 12, 5 predef_jump CopyTileIDsFromList -Func_703d1: ; 703d1 (1c:43d1) +HoFDisplayPlayerStats: ; 703d1 (1c:43d1) ld hl, wd747 set 3, [hl] predef DisplayDexRating - hlCoord 0, 4 - ld bc, $60a + coord hl, 0, 4 + lb bc, 6, 10 call TextBoxBorder - hlCoord 5, 0 - ld bc, $209 + coord hl, 5, 0 + lb bc, 2, 9 call TextBoxBorder - hlCoord 7, 2 - ld de, wPlayerName ; wd158 + coord hl, 7, 2 + ld de, wPlayerName call PlaceString - hlCoord 1, 6 + coord hl, 1, 6 ld de, HoFPlayTimeText call PlaceString - hlCoord 5, 7 + coord hl, 5, 7 ld de, W_PLAYTIMEHOURS + 1 - ld bc, $103 + lb bc, 1, 3 call PrintNumber ld [hl], $6d inc hl ld de, W_PLAYTIMEMINUTES + 1 - ld bc, $8102 + lb bc, LEADING_ZEROES | 1, 2 call PrintNumber - hlCoord 1, 9 + coord hl, 1, 9 ld de, HoFMoneyText call PlaceString - hlCoord 4, 10 - ld de, wPlayerMoney ; wPlayerMoney + coord hl, 4, 10 + ld de, wPlayerMoney ld c, $a3 call PrintBCDNumber ld hl, DexSeenOwnedText - call Func_7043a + call HoFPrintTextAndDelay ld hl, DexRatingText - call Func_7043a - ld hl, wcc5d + call HoFPrintTextAndDelay + ld hl, wDexRatingText -Func_7043a: ; 7043a (1c:443a) +HoFPrintTextAndDelay: ; 7043a (1c:443a) call PrintText - ld c, $78 + ld c, 120 jp DelayFrames HoFPlayTimeText: ; 70442 (1c:4442) @@ -278,25 +279,25 @@ DexRatingText: ; 70457 (1c:4457) TX_FAR _DexRatingText db "@" -Func_7045c: ; 7045c (1c:445c) +HoFRecordMonInfo: ; 7045c (1c:445c) ld hl, wHallOfFame ld bc, HOF_MON - ld a, [wTrainerEngageDistance] + ld a, [wHoFPartyMonIndex] call AddNTimes - ld a, [wWhichTrade] ; wWhichTrade + ld a, [wHoFMonSpecies] ld [hli], a - ld a, [wTrainerFacingDirection] + ld a, [wHoFMonLevel] ld [hli], a ld e, l ld d, h ld hl, wcd6d - ld bc, $b + ld bc, NAME_LENGTH jp CopyData -Func_7047b: ; 7047b (1c:447b) - ld a, $a - ld [wcfc8], a - ld [wcfc9], a +HoFFadeOutScreenAndMusic: ; 7047b (1c:447b) + ld a, 10 + ld [wAudioFadeOutCounterReloadValue], a + ld [wAudioFadeOutCounter], a ld a, $ff - ld [wMusicHeaderPointer], a + ld [wAudioFadeOutControl], a jp GBFadeOutToWhite diff --git a/engine/hidden_object_functions14.asm b/engine/hidden_object_functions14.asm index a162c905..97187638 100755 --- a/engine/hidden_object_functions14.asm +++ b/engine/hidden_object_functions14.asm @@ -2,7 +2,7 @@ PrintNotebookText: ; 52996 (14:6996) call EnableAutoTextBoxDrawing ld a, $1 ld [wDoNotWaitForButtonPressAfterDisplayingText], a - ld a, [wTrainerSpriteOffset] + ld a, [wHiddenObjectFunctionArgument] jp PrintPredefTextID TMNotebook: ; 529a4 (14:69a4) @@ -11,7 +11,7 @@ TMNotebook: ; 529a4 (14:69a4) db "@" ViridianSchoolNotebook: ; 529aa (14:69aa) - db $08 ; asm + TX_ASM ld hl, ViridianSchoolNotebookText1 call PrintText call TurnPageSchoolNotebook @@ -66,8 +66,7 @@ ViridianSchoolNotebookText4: ; 52a03 (14:6a03) PrintFightingDojoText2: ; 52a08 (14:6a08) call EnableAutoTextBoxDrawing - ld a, $37 - jp PrintPredefTextID + tx_pre_jump FightingDojoText_52a10 FightingDojoText_52a10: ; 52a10 (14:6a10) TX_FAR _FightingDojoText_52a10 @@ -75,8 +74,7 @@ FightingDojoText_52a10: ; 52a10 (14:6a10) PrintFightingDojoText3: ; 52a15 (14:6a15) call EnableAutoTextBoxDrawing - ld a, $38 - jp PrintPredefTextID + tx_pre_jump FightingDojoText_52a1d FightingDojoText_52a1d: ; 52a1d (14:6a1d) TX_FAR _FightingDojoText_52a1d @@ -84,8 +82,7 @@ FightingDojoText_52a1d: ; 52a1d (14:6a1d) PrintFightingDojoText: ; 52a22 (14:6a22) call EnableAutoTextBoxDrawing - ld a, $36 - jp PrintPredefTextID + tx_pre_jump FightingDojoText FightingDojoText: ; 52a2a (14:6a2a) TX_FAR _FightingDojoText @@ -93,11 +90,10 @@ FightingDojoText: ; 52a2a (14:6a2a) PrintIndigoPlateauHQText: ; 52a2f (14:6a2f) ld a, [wSpriteStateData1 + 9] - cp $4 + cp SPRITE_FACING_UP ret nz call EnableAutoTextBoxDrawing - ld a, $27 - jp PrintPredefTextID + tx_pre_jump IndigoPlateauHQText IndigoPlateauHQText: ; 52a3d (14:6a3d) TX_FAR _IndigoPlateauHQText diff --git a/engine/hidden_object_functions17.asm b/engine/hidden_object_functions17.asm index 9dbcbf98..77f3eeb9 100755 --- a/engine/hidden_object_functions17.asm +++ b/engine/hidden_object_functions17.asm @@ -1,7 +1,6 @@ PrintRedsNESText: ; 5db79 (17:5b79) call EnableAutoTextBoxDrawing - ld a, $4 ; RedBedroomSNESText - jp PrintPredefTextID + tx_pre_jump RedBedroomSNESText RedBedroomSNESText: ; 5db81 (17:5b81) TX_FAR _RedBedroomSNESText @@ -9,19 +8,17 @@ RedBedroomSNESText: ; 5db81 (17:5b81) OpenRedsPC: ; 5db86 (17:5b86) call EnableAutoTextBoxDrawing - ld a, $3 - jp PrintPredefTextID + tx_pre_jump RedBedroomPCText -RedBedroomPC: ; 5db8e (17:5b8e) +RedBedroomPCText: ; 5db8e (17:5b8e) db $fc ; FuncTX_ItemStoragePC Route15GateLeftBinoculars: ; 5db8f (17:5b8f) ld a, [wSpriteStateData1 + 9] - cp $4 ; i + cp SPRITE_FACING_UP ret nz call EnableAutoTextBoxDrawing - ld a, $a ; text id Route15UpstairsBinocularsText - call PrintPredefTextID + tx_pre Route15UpstairsBinocularsText ld a, ARTICUNO ld [wcf91], a call PlayCry @@ -36,8 +33,7 @@ AerodactylFossil: ; 5dbad (17:5bad) ld [wcf91], a call DisplayMonFrontSpriteInBox call EnableAutoTextBoxDrawing - ld a, $9 - call PrintPredefTextID + tx_pre AerodactylFossilText ret AerodactylFossilText: ; 5dbbe (17:5bbe) @@ -49,8 +45,7 @@ KabutopsFossil: ; 5bdc3 (17:5bc3) ld [wcf91], a call DisplayMonFrontSpriteInBox call EnableAutoTextBoxDrawing - ld a, $b - call PrintPredefTextID + tx_pre KabutopsFossilText ret KabutopsFossilText: ; 5dbd4 (17:5bd4) @@ -60,8 +55,8 @@ KabutopsFossilText: ; 5dbd4 (17:5bd4) DisplayMonFrontSpriteInBox: ; 5dbd9 (17:5bd9) ; Displays a pokemon's front sprite in a pop-up window. ; [wcf91] = pokemon interal id number - ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba + ld a, 1 + ld [H_AUTOBGTRANSFERENABLED], a call Delay3 xor a ld [hWY], a @@ -76,9 +71,9 @@ DisplayMonFrontSpriteInBox: ; 5dbd9 (17:5bd9) ld de, vChars1 + $310 call LoadMonFrontSprite ld a, $80 - ld [$ffe1], a - hlCoord 10, 11 - predef Func_3f073 + ld [hStartTileID], a + coord hl, 10, 11 + predef AnimateSendingOutMon call WaitForTextScrollButtonPress call LoadScreenTilesFromBuffer1 call Delay3 @@ -90,12 +85,12 @@ PrintBlackboardLinkCableText: ; 5dc1a (17:5c1a) call EnableAutoTextBoxDrawing ld a, $1 ld [wDoNotWaitForButtonPressAfterDisplayingText], a - ld a, [wWhichTrade] + ld a, [wHiddenObjectFunctionArgument] call PrintPredefTextID ret LinkCableHelp: ; 5dc29 (17:5c29) - db $08 ; asm + TX_ASM call SaveScreenTilesToBuffer1 ld hl, LinkCableHelpText1 call PrintText @@ -103,7 +98,7 @@ LinkCableHelp: ; 5dc29 (17:5c29) ld [W_ANIMATIONID], a ld [wCurrentMenuItem], a ld [wLastMenuItem], a - ld a, $3 + ld a, A_BUTTON | B_BUTTON ld [wMenuWatchedKeys], a ld a, $3 ld [wMaxMenuItem], a @@ -111,24 +106,24 @@ LinkCableHelp: ; 5dc29 (17:5c29) ld [wTopMenuItemY], a ld a, $1 ld [wTopMenuItemX], a -.asm_5c51 +.linkHelpLoop ld hl, wd730 set 6, [hl] - ld hl, wTileMap + coord hl, 0, 0 ld b, $8 ld c, $d call TextBoxBorder - ld hl, wTileMap + $2a + coord hl, 2, 2 ld de, HowToLinkText call PlaceString ld hl, LinkCableHelpText2 call PrintText call HandleMenuInput - bit 1, a - jr nz, .asm_5dc93 ; 0x5dc74 $1d + bit 1, a ; pressed b + jr nz, .exit ld a, [wCurrentMenuItem] - cp $3 - jr z, .asm_5dc93 ; 0x5dc7b $16 + cp $3 ; pressed a on "STOP READING" + jr z, .exit ld hl, wd730 res 6, [hl] ld hl, LinkCableInfoTexts @@ -140,8 +135,8 @@ LinkCableHelp: ; 5dc29 (17:5c29) ld h, [hl] ld l, a call PrintText - jp .asm_5c51 -.asm_5dc93 + jp .linkHelpLoop +.exit ld hl, wd730 res 6, [hl] call LoadScreenTilesFromBuffer1 @@ -179,7 +174,7 @@ LinkCableInfoText3: ; 5dce8 (17:5ce8) db "@" ViridianSchoolBlackboard: ; 5dced (17:5ced) - db $08 ; asm + TX_ASM call SaveScreenTilesToBuffer1 ld hl, ViridianSchoolBlackboardText1 call PrintText @@ -187,7 +182,7 @@ ViridianSchoolBlackboard: ; 5dced (17:5ced) ld [W_ANIMATIONID], a ld [wCurrentMenuItem], a ld [wLastMenuItem], a - ld a, $33 + ld a, D_LEFT | D_RIGHT | A_BUTTON | B_BUTTON ld [wMenuWatchedKeys], a ld a, $2 ld [wMaxMenuItem], a @@ -195,25 +190,26 @@ ViridianSchoolBlackboard: ; 5dced (17:5ced) ld [wTopMenuItemY], a ld a, $1 ld [wTopMenuItemX], a -.asm_5dd15 +.blackboardLoop ld hl, wd730 set 6, [hl] - ld hl, wTileMap - ld bc, $060a + coord hl, 0, 0 + lb bc, 6, 10 call TextBoxBorder - ld hl, wTileMap + $29 + coord hl, 1, 2 ld de, StatusAilmentText1 call PlaceString - ld hl, wTileMap + $2e + coord hl, 6, 2 ld de, StatusAilmentText2 call PlaceString ld hl, ViridianSchoolBlackboardText2 call PrintText - call HandleMenuInput - bit 1, a + call HandleMenuInput ; pressing up and down is handled in here + bit 1, a ; pressed b jr nz, .exitBlackboard - bit 4, a - jr z, .asm_5dd5c + bit 4, a ; pressed right + jr z, .didNotPressRight + ; move cursor to right column ld a, $2 ld [wMaxMenuItem], a ld a, $2 @@ -222,10 +218,11 @@ ViridianSchoolBlackboard: ; 5dced (17:5ced) ld [wTopMenuItemX], a ld a, $3 ld [W_ANIMATIONID], a - jr .asm_5dd15 -.asm_5dd5c - bit 5, a - jr z, .asm_5dd75 + jr .blackboardLoop +.didNotPressRight + bit 5, a ; pressed left + jr z, .didNotPressLeftOrRight + ; move cursor to left column ld a, $2 ld [wMaxMenuItem], a ld a, $2 @@ -234,14 +231,16 @@ ViridianSchoolBlackboard: ; 5dced (17:5ced) ld [wTopMenuItemX], a xor a ld [W_ANIMATIONID], a - jr .asm_5dd15 -.asm_5dd75 + jr .blackboardLoop +.didNotPressLeftOrRight ld a, [wCurrentMenuItem] ld b, a ld a, [W_ANIMATIONID] add b - cp $5 + cp $5 ; cursor is pointing to "QUIT" jr z, .exitBlackboard + ; we must have pressed a on a status condition + ; so print the text ld hl, wd730 res 6, [hl] ld hl, ViridianBlackboardStatusPointers @@ -253,7 +252,7 @@ ViridianSchoolBlackboard: ; 5dced (17:5ced) ld h, [hl] ld l, a call PrintText - jp .asm_5dd15 + jp .blackboardLoop .exitBlackboard ld hl, wd730 res 6, [hl] @@ -307,8 +306,7 @@ ViridianBlackboardFrozenText: ; 5ddea (17:5dea) PrintTrashText: ; 5ddef (17:5def) call EnableAutoTextBoxDrawing - ld a, $26 - jp PrintPredefTextID + tx_pre_jump VermilionGymTrashText VermilionGymTrashText: ; 5ddf7 (17:5df7) TX_FAR _VermilionGymTrashText @@ -316,37 +314,34 @@ VermilionGymTrashText: ; 5ddf7 (17:5df7) GymTrashScript: ; 5ddfc (17:5dfc) call EnableAutoTextBoxDrawing - ld a, [wWhichTrade] ; wWhichTrade - ld [wcd5b], a + ld a, [wHiddenObjectFunctionArgument] + ld [wGymTrashCanIndex], a ; Don't do the trash can puzzle if it's already been done. - ld a, [wd773] - bit 0, a + CheckEvent EVENT_2ND_LOCK_OPENED jr z, .ok - ld a, $26 ; DisplayTextID $26 = VermilionGymTrashText (nothing in the trash) - jp PrintPredefTextID + tx_pre_jump VermilionGymTrashText .ok - bit 1, a + CheckEventReuseA EVENT_1ST_LOCK_OPENED jr nz, .trySecondLock - ld a, [wd743] + ld a, [wFirstLockTrashCanIndex] ld b, a - ld a, [wcd5b] + ld a, [wGymTrashCanIndex] cp b jr z, .openFirstLock - ld a, $26 ; DisplayTextID $26 = VermilionGymTrashText (nothing in the trash) + tx_pre_id VermilionGymTrashText jr .done .openFirstLock ; Next can is trying for the second switch. - ld hl, wd773 - set 1, [hl] + SetEvent EVENT_1ST_LOCK_OPENED - ld hl, GymTrashCans ; $5e7d - ld a, [wcd5b] + ld hl, GymTrashCans + ld a, [wGymTrashCanIndex] ; * 5 ld b, a add a @@ -358,12 +353,21 @@ GymTrashScript: ; 5ddfc (17:5dfc) add hl, de ld a, [hli] - ld [$ffdb], a +; There is a bug in this code. It should calculate a value in the range [0, 3] +; but if the mask and random number don't have any 1 bits in common, then +; the result of the AND will be 0. When 1 is subtracted from that, the value +; will become $ff. This will result in 255 being added to hl, which will cause +; hl to point to one of the zero bytes that pad the end of the ROM bank. +; Trash can 0 was intended to be able to have the second lock only when the +; first lock was in trash can 1 or 3. However, due to this bug, trash can 0 can +; have the second lock regardless of which trash can had the first lock. + + ld [hGymTrashCanRandNumMask], a push hl call Random swap a ld b, a - ld a, [$ffdb] + ld a, [hGymTrashCanRandNumMask] and b dec a pop hl @@ -373,42 +377,46 @@ GymTrashScript: ; 5ddfc (17:5dfc) add hl, de ld a, [hl] and $f - ld [wd744], a + ld [wSecondLockTrashCanIndex], a - ld a, $3b ; DisplayTextID $3b = VermilionGymTrashSuccesText1 (first lock opened!) + tx_pre_id VermilionGymTrashSuccesText1 jr .done .trySecondLock - ld a, [wd744] + ld a, [wSecondLockTrashCanIndex] ld b, a - ld a, [wcd5b] + ld a, [wGymTrashCanIndex] cp b jr z, .openSecondLock ; Reset the cans. - ld hl, wd773 - res 1, [hl] + ResetEvent EVENT_1ST_LOCK_OPENED call Random and $e - ld [wd743], a + ld [wFirstLockTrashCanIndex], a - ld a, $3e ; DisplayTextID $3e = VermilionGymTrashFailText (locks reset!) + tx_pre_id VermilionGymTrashFailText jr .done .openSecondLock ; Completed the trash can puzzle. - ld hl, wd773 - set 0, [hl] + SetEvent EVENT_2ND_LOCK_OPENED ld hl, wd126 set 6, [hl] - ld a, $3d ; DisplayTextID $3d = VermilionGymTrashSuccesText3 (2nd lock opened!) + tx_pre_id VermilionGymTrashSuccesText3 .done jp PrintPredefTextID GymTrashCans: ; 5de7d (17:5e7d) +; byte 0: mask for random number +; bytes 1-4: indices of the trash cans that can have the second lock +; (but see the comment above explaining a bug regarding this) +; Note that the mask is simply the number of valid trash can indices that +; follow. The remaining bytes are filled with 0 to pad the length of each entry +; to 5 bytes. db 2, 1, 3, 0, 0 ; 0 db 3, 0, 2, 4, 0 ; 1 db 2, 1, 5, 0, 0 ; 2 @@ -428,39 +436,41 @@ GymTrashCans: ; 5de7d (17:5e7d) VermilionGymTrashSuccesText1: ; 5dec8 (17:5ec8) TX_FAR _VermilionGymTrashSuccesText1 - db $08 ; asm + TX_ASM call WaitForSoundToFinish - ld a, (SFX_02_49 - SFX_Headers_02) / 3 + ld a, SFX_SWITCH call PlaySound call WaitForSoundToFinish jp TextScriptEnd +; unused VermilionGymTrashSuccesText2: ; 5dedb (17:5edb) TX_FAR _VermilionGymTrashSuccesText2 db "@" -UnnamedText_5dee0: ; 5dee0 (17:5ee0) - db $08 ; asm +; unused +VermilionGymTrashSuccesPlaySfx: ; 5dee0 (17:5ee0) + TX_ASM call WaitForSoundToFinish - ld a, (SFX_02_49 - SFX_Headers_02) / 3 + ld a, SFX_SWITCH call PlaySound call WaitForSoundToFinish jp TextScriptEnd VermilionGymTrashSuccesText3: ; 5deef (17:5eef) TX_FAR _VermilionGymTrashSuccesText3 - db $08 ; asm + TX_ASM call WaitForSoundToFinish - ld a, (SFX_02_57 - SFX_Headers_02) / 3 + ld a, SFX_GO_INSIDE call PlaySound call WaitForSoundToFinish jp TextScriptEnd VermilionGymTrashFailText: ; 5df02 (17:5f02) TX_FAR _VermilionGymTrashFailText - db $08 ; asm + TX_ASM call WaitForSoundToFinish - ld a, (SFX_02_51 - SFX_Headers_02) / 3 + ld a, SFX_DENIED call PlaySound call WaitForSoundToFinish jp TextScriptEnd diff --git a/engine/hidden_object_functions18.asm b/engine/hidden_object_functions18.asm index 7696626f..0a93fd44 100755 --- a/engine/hidden_object_functions18.asm +++ b/engine/hidden_object_functions18.asm @@ -1,31 +1,31 @@ GymStatues: ; 62419 (18:6419) -; if in a gym and have the corresponding badge, a = $D and jp PrintPredefTextID -; if in a gym and don’t have the corresponding badge, a = $C and jp PrintPredefTextID +; if in a gym and have the corresponding badge, a = GymStatueText2_id and jp PrintPredefTextID +; if in a gym and don’t have the corresponding badge, a = GymStatueText1_id and jp PrintPredefTextID ; else ret call EnableAutoTextBoxDrawing ld a, [wSpriteStateData1 + 9] - cp $4 + cp SPRITE_FACING_UP ret nz ld hl, .BadgeFlags ld a, [W_CURMAP] ld b, a -.asm_62429 +.loop ld a, [hli] cp $ff ret z cp b - jr z, .asm_62433 ; 0x6242e $3 + jr z, .match inc hl - jr .asm_62429 ; 0x62431 $f6 -.asm_62433 + jr .loop +.match ld b, [hl] - ld a, [wd72a] + ld a, [wBeatGymFlags] and b cp b - ld a, $d - jr z, .asm_6243f ; 0x6243b $2 - ld a, $c -.asm_6243f + tx_pre_id GymStatueText2 + jr z, .haveBadge + tx_pre_id GymStatueText1 +.haveBadge jp PrintPredefTextID .BadgeFlags: ; 62442 (18:6442) @@ -49,41 +49,53 @@ GymStatueText2: ; 62458 (18:6458) PrintBenchGuyText: ; 6245d (18:645d) call EnableAutoTextBoxDrawing - ld hl, PokeCenterMapIDList + ld hl, BenchGuyTextPointers ld a, [W_CURMAP] ld b, a -.asm_62467 +.loop ld a, [hli] cp $ff ret z cp b - jr z, .asm_62472 + jr z, .match inc hl inc hl - jr .asm_62467 -.asm_62472 + jr .loop +.match ld a, [hli] ld b, a ld a, [wSpriteStateData1 + 9] cp b - jr nz, .asm_62467 + jr nz, .loop ; player isn't facing left at the bench guy ld a, [hl] jp PrintPredefTextID -; format: db map id, 08, text id of PredefTextIDPointerTable -PokeCenterMapIDList: ; 6247e (18:647e) - db VIRIDIAN_POKECENTER,$08,$0F - db PEWTER_POKECENTER,$08,$10 - db CERULEAN_POKECENTER,$08,$11 - db LAVENDER_POKECENTER,$08,$12 - db VERMILION_POKECENTER,$08,$13 - db CELADON_POKECENTER,$08,$14 - db CELADON_HOTEL,$08,$15 - db FUCHSIA_POKECENTER,$08,$16 - db CINNABAR_POKECENTER,$08,$17 - db SAFFRON_POKECENTER,$08,$18 - db MT_MOON_POKECENTER,$08,$19 - db ROCK_TUNNEL_POKECENTER,$08,$1A +; format: db map id, player sprite facing direction, text id of PredefTextIDPointerTable +BenchGuyTextPointers: ; 6247e (18:647e) + db VIRIDIAN_POKECENTER, SPRITE_FACING_LEFT + db (ViridianCityPokecenterBenchGuyText_id - TextPredefs) / 2 + 1 + db PEWTER_POKECENTER, SPRITE_FACING_LEFT + db (PewterCityPokecenterBenchGuyText_id - TextPredefs) / 2 + 1 + db CERULEAN_POKECENTER, SPRITE_FACING_LEFT + db (CeruleanCityPokecenterBenchGuyText_id - TextPredefs) / 2 + 1 + db LAVENDER_POKECENTER, SPRITE_FACING_LEFT + db (LavenderCityPokecenterBenchGuyText_id - TextPredefs) / 2 + 1 + db VERMILION_POKECENTER, SPRITE_FACING_LEFT + db (VermilionCityPokecenterBenchGuyText_id - TextPredefs) / 2 + 1 + db CELADON_POKECENTER, SPRITE_FACING_LEFT + db (CeladonCityPokecenterBenchGuyText_id - TextPredefs) / 2 + 1 + db CELADON_HOTEL, SPRITE_FACING_LEFT + db (CeladonCityHotelText_id - TextPredefs) / 2 + 1 + db FUCHSIA_POKECENTER, SPRITE_FACING_LEFT + db (FuchsiaCityPokecenterBenchGuyText_id - TextPredefs) / 2 + 1 + db CINNABAR_POKECENTER, SPRITE_FACING_LEFT + db (CinnabarIslandPokecenterBenchGuyText_id - TextPredefs) / 2 + 1 + db SAFFRON_POKECENTER, SPRITE_FACING_LEFT + db (SaffronCityPokecenterBenchGuyText_id - TextPredefs) / 2 + 1 + db MT_MOON_POKECENTER, SPRITE_FACING_LEFT + db (MtMoonPokecenterBenchGuyText_id - TextPredefs) / 2 + 1 + db ROCK_TUNNEL_POKECENTER,SPRITE_FACING_LEFT + db (RockTunnelPokecenterBenchGuyText_id - TextPredefs) / 2 + 1 db $FF ViridianCityPokecenterBenchGuyText: ; 624a3 (18:64a3) @@ -139,11 +151,10 @@ CinnabarIslandPokecenterBenchGuyText: ; 624df (18:64df) db "@" SaffronCityPokecenterBenchGuyText: ; 624e4 (18:64e4) - db $8 ; asm - ld a, [wd838] - bit 7, a + TX_ASM + CheckEvent EVENT_BEAT_SILPH_CO_GIOVANNI ld hl, SaffronCityPokecenterBenchGuyText2 - jr nz, .asm_624f2 ; 0x624ed $3 + jr nz, .asm_624f2 ld hl, SaffronCityPokecenterBenchGuyText1 .asm_624f2 call PrintText @@ -163,13 +174,12 @@ CeladonCityHotelText: ; 62502 (18:6502) ret -TerminatorText_62508: ; 62508 (18:6508) +UnusedPredefText: ; 62508 (18:6508) db "@" PrintBookcaseText: ; 6509 (18:6509) call EnableAutoTextBoxDrawing - ld a, $e ; BookcaseText - jp PrintPredefTextID + tx_pre_jump BookcaseText BookcaseText: ; 62511 (18:6511) TX_FAR _BookcaseText @@ -177,13 +187,12 @@ BookcaseText: ; 62511 (18:6511) OpenPokemonCenterPC: ; 62516 (18:6516) ld a, [wSpriteStateData1 + 9] - cp $4 ; check to see if player is facing up + cp SPRITE_FACING_UP ; check to see if player is facing up ret nz call EnableAutoTextBoxDrawing ld a, $1 ld [wAutoTextBoxDrawingControl], a - ld a, $1f ; PredefText1f - jp PrintPredefTextID + tx_pre_jump PokemonCenterPCText -PredefText1f: ; 62529 (18:6529) +PokemonCenterPCText: ; 62529 (18:6529) db $F9 ; FuncTX_PokemonCenterPC diff --git a/engine/hidden_object_functions3.asm b/engine/hidden_object_functions3.asm index c471c7bb..80251b94 100755 --- a/engine/hidden_object_functions3.asm +++ b/engine/hidden_object_functions3.asm @@ -34,33 +34,48 @@ PrintBookshelfText: ; fb50 (3:7b50) .noMatch ld a, $ff ld [$ffdb], a - ld b, BANK(PrintCardKeyText) - ld hl, PrintCardKeyText - jp Bankswitch + jpba PrintCardKeyText ; format: db tileset id, bookshelf tile id, text id BookshelfTileIDs: ; fb8b (3:7b8b) - db PLATEAU, $30, $3A - db HOUSE, $3D, $3F - db HOUSE, $1E, $40 - db MANSION, $32, $40 - db REDS_HOUSE_1, $32, $40 - db LAB, $28, $40 - db LOBBY, $16, $41 - db GYM, $1D, $40 - db DOJO, $1D, $40 - db GATE, $22, $40 - db MART, $54, $42 - db MART, $55, $42 - db POKECENTER, $54, $42 - db POKECENTER, $55, $42 - db LOBBY, $50, $42 - db LOBBY, $52, $42 - db SHIP, $36, $40 + db PLATEAU, $30 + db (IndigoPlateauStatues_id - TextPredefs) / 2 + 1 + db HOUSE, $3D + db (TownMapText_id - TextPredefs) / 2 + 1 + db HOUSE, $1E + db (BookOrSculptureText_id - TextPredefs) / 2 + 1 + db MANSION, $32 + db (BookOrSculptureText_id - TextPredefs) / 2 + 1 + db REDS_HOUSE_1, $32 + db (BookOrSculptureText_id - TextPredefs) / 2 + 1 + db LAB, $28 + db (BookOrSculptureText_id - TextPredefs) / 2 + 1 + db LOBBY, $16 + db (ElevatorText_id - TextPredefs) / 2 + 1 + db GYM, $1D + db (BookOrSculptureText_id - TextPredefs) / 2 + 1 + db DOJO, $1D + db (BookOrSculptureText_id - TextPredefs) / 2 + 1 + db GATE, $22 + db (BookOrSculptureText_id - TextPredefs) / 2 + 1 + db MART, $54 + db (PokemonStuffText_id - TextPredefs) / 2 + 1 + db MART, $55 + db (PokemonStuffText_id - TextPredefs) / 2 + 1 + db POKECENTER, $54 + db (PokemonStuffText_id - TextPredefs) / 2 + 1 + db POKECENTER, $55 + db (PokemonStuffText_id - TextPredefs) / 2 + 1 + db LOBBY, $50 + db (PokemonStuffText_id - TextPredefs) / 2 + 1 + db LOBBY, $52 + db (PokemonStuffText_id - TextPredefs) / 2 + 1 + db SHIP, $36 + db (BookOrSculptureText_id - TextPredefs) / 2 + 1 db $FF IndigoPlateauStatues: ; fbbf (3:7bbf) - db $08 ; asm + TX_ASM ld hl, IndigoPlateauStatuesText1 call PrintText ld a, [W_XCOORD] @@ -85,12 +100,12 @@ IndigoPlateauStatuesText3: ; fbe3 (3:7be3) db "@" BookOrSculptureText: ; fbe8 (3:7be8) - db $08 ; asm + TX_ASM ld hl, PokemonBooksText ld a, [W_CURMAPTILESET] cp MANSION ; Celadon Mansion tileset jr nz, .asm_fbfd - ld a, [wTileMap + $80] + aCoord 8, 6 cp $38 jr nz, .asm_fbfd ld hl, DiglettSculptureText @@ -113,7 +128,7 @@ ElevatorText: ; fc0d (3:7c0d) TownMapText: ; fc12 (3:7c12) TX_FAR _TownMapText db $06 - db $08 ; asm + TX_ASM ld a, $1 ld [wDoNotWaitForButtonPressAfterDisplayingText], a ld hl, wd730 diff --git a/engine/hidden_object_functions7.asm b/engine/hidden_object_functions7.asm index f97190de..02d3928a 100755 --- a/engine/hidden_object_functions7.asm +++ b/engine/hidden_object_functions7.asm @@ -1,7 +1,6 @@ PrintNewBikeText: ; 1e94b (7:694b) call EnableAutoTextBoxDrawing - ld a, $39 - jp PrintPredefTextID + tx_pre_jump NewBicycleText NewBicycleText: ; 1e953 (7:6953) TX_FAR _NewBicycleText @@ -9,8 +8,7 @@ NewBicycleText: ; 1e953 (7:6953) DisplayOakLabLeftPoster: ; 1e958 (7:6958) call EnableAutoTextBoxDrawing - ld a, $05 ; PushStartText - jp PrintPredefTextID + tx_pre_jump PushStartText PushStartText: ; 1e960 (7:6960) TX_FAR _PushStartText @@ -21,12 +19,12 @@ DisplayOakLabRightPoster: ; 1e965 (7:6965) ld hl, wPokedexOwned ld b, wPokedexOwnedEnd - wPokedexOwned call CountSetBits - ld a, [wd11e] - cp $2 - ld a, $6 ; SaveOptionText - jr c, .asm_1e97b - ld a, $7 ; StrengthsAndWeaknessesText -.asm_1e97b + ld a, [wNumSetBits] + cp 2 + tx_pre_id SaveOptionText + jr c, .ownThreeOrMoreMon + tx_pre_id StrengthsAndWeaknessesText +.ownThreeOrMoreMon jp PrintPredefTextID SaveOptionText: ; 1e97e (7:697e) @@ -38,57 +36,56 @@ StrengthsAndWeaknessesText: ; 1e983 (7:6983) db "@" SafariZoneCheck: ; 1e988 (7:6988) - ld hl, wd790 - bit 7, [hl] - jr z, asm_1e9ab - ld a, [W_NUMSAFARIBALLS] ; W_NUMSAFARIBALLS + CheckEventHL EVENT_IN_SAFARI_ZONE ; if we are not in the Safari Zone, + jr z, SafariZoneGameStillGoing ; don't bother printing game over text + ld a, [W_NUMSAFARIBALLS] and a - jr z, asm_1e9b0 - jr asm_1e9ab + jr z, SafariZoneGameOver + jr SafariZoneGameStillGoing SafariZoneCheckSteps: ; 1e997 (7:6997) - ld a, [wSafariSteps] ; wd70d + ld a, [wSafariSteps] ld b, a - ld a, [wSafariSteps + 1] ; wd70e + ld a, [wSafariSteps + 1] ld c, a or b - jr z, asm_1e9b0 + jr z, SafariZoneGameOver dec bc ld a, b - ld [wSafariSteps], a ; wd70d + ld [wSafariSteps], a ld a, c - ld [wSafariSteps + 1], a ; wd70e -asm_1e9ab: ; 1e9ab (7:69ab) + ld [wSafariSteps + 1], a +SafariZoneGameStillGoing: ; 1e9ab (7:69ab) xor a ld [wSafariZoneGameOver], a ret -asm_1e9b0: ; 1e9b0 (7:69b0) + +SafariZoneGameOver: ; 1e9b0 (7:69b0) call EnableAutoTextBoxDrawing xor a - ld [wMusicHeaderPointer], a + ld [wAudioFadeOutControl], a dec a call PlaySound - ld c, BANK(SFX_02_5f) - ld a, (SFX_02_5f - SFX_Headers_02) / 3 + ld c, BANK(SFX_Safari_Zone_PA) + ld a, SFX_SAFARI_ZONE_PA call PlayMusic .asm_1e9c2 - ld a, [wc02a] + ld a, [wChannelSoundIDs + CH4] cp $b9 jr nz, .asm_1e9c2 - ld a, $d3 - ld [H_DOWNARROWBLINKCNT2], a ; $ff8c + ld a, TEXT_SAFARI_GAME_OVER + ld [hSpriteIndexOrTextID], a call DisplayTextID xor a - ld [wd528], a + ld [wPlayerMovingDirection], a ld a, SAFARI_ZONE_ENTRANCE - ld [H_DOWNARROWBLINKCNT1], a ; $ff8b + ld [hWarpDestinationMap], a ld a, $3 ld [wDestinationWarpID], a ld a, $5 ld [W_SAFARIZONEENTRANCECURSCRIPT], a - ld hl, wd790 - set 6, [hl] - ld a, $1 + SetEvent EVENT_SAFARI_GAME_OVER + ld a, 1 ld [wSafariZoneGameOver], a ret @@ -99,8 +96,8 @@ PrintSafariGameOverText: ; 1e9ed (7:69ed) jp PrintText SafariGameOverText: ; 1e9f7 (7:69f7) - db $08 ; asm - ld a, [W_NUMSAFARIBALLS] ; W_NUMSAFARIBALLS + TX_ASM + ld a, [W_NUMSAFARIBALLS] and a jr z, .asm_1ea04 ld hl, TimesUpText @@ -120,30 +117,29 @@ GameOverText: ; 1ea12 (7:6a12) PrintCinnabarQuiz: ; 1ea17 (7:6a17) ld a, [wSpriteStateData1 + 9] - cp $4 + cp SPRITE_FACING_UP ret nz call EnableAutoTextBoxDrawing - ld a, $31 - jp PrintPredefTextID + tx_pre_jump CinnabarGymQuiz CinnabarGymQuiz: ; 1ea25 (7:6a25) - db $08 ; asm + TX_ASM xor a - ld [wda38], a - ld a, [wWhichTrade] ; wWhichTrade + ld [wOpponentAfterWrongAnswer], a + ld a, [wHiddenObjectFunctionArgument] push af and $f - ld [$ffdb], a + ld [hGymGateIndex], a pop af and $f0 swap a ld [$ffdc], a ld hl, CinnabarGymQuizIntroText call PrintText - ld a, [$ffdb] + ld a, [hGymGateIndex] dec a add a - ld d, $0 + ld d, 0 ld e, a ld hl, CinnabarQuizQuestions add hl, de @@ -192,63 +188,67 @@ CinnabarQuizQuestionsText6: ; 1ea85 (7:6a85) TX_FAR _CinnabarQuizQuestionsText6 db "@" -CinnabarGymQuiz_1ea8a: ; 1ea8a (7:6a8a) - ld hl, wd79c +CinnabarGymGateFlagAction: ; 1ea8a (7:6a8a) + EventFlagAddress hl, EVENT_CINNABAR_GYM_GATE0_UNLOCKED predef_jump FlagActionPredef CinnabarGymQuiz_1ea92: ; 1ea92 (7:6a92) call YesNoChoice ld a, [$ffdc] ld c, a - ld a, [wCurrentMenuItem] ; wCurrentMenuItem + ld a, [wCurrentMenuItem] cp c - jr nz, .asm_1eab8 + jr nz, .wrongAnswer ld hl, wd126 set 5, [hl] - ld a, [$ffdb] + ld a, [hGymGateIndex] ld [$ffe0], a ld hl, CinnabarGymQuizCorrectText call PrintText ld a, [$ffe0] + AdjustEventBit EVENT_CINNABAR_GYM_GATE0_UNLOCKED, 0 ld c, a - ld b, $1 - call CinnabarGymQuiz_1ea8a - jp CinnabarGymQuiz_1eb0a -.asm_1eab8 + ld b, FLAG_SET + call CinnabarGymGateFlagAction + jp UpdateCinnabarGymGateTileBlocks_ +.wrongAnswer call WaitForSoundToFinish - ld a, (SFX_02_51 - SFX_Headers_02) / 3 + ld a, SFX_DENIED call PlaySound call WaitForSoundToFinish ld hl, CinnabarGymQuizIncorrectText call PrintText - ld a, [$ffdb] + ld a, [hGymGateIndex] add $2 + AdjustEventBit EVENT_BEAT_CINNABAR_GYM_TRAINER_0, 2 ld c, a - ld b, $2 - ld hl, wd79a + ld b, FLAG_TEST + EventFlagAddress hl, EVENT_BEAT_CINNABAR_GYM_TRAINER_0 predef FlagActionPredef ld a, c and a ret nz - ld a, [$ffdb] + ld a, [hGymGateIndex] add $2 - ld [wda38], a + ld [wOpponentAfterWrongAnswer], a ret CinnabarGymQuizCorrectText: ; 1eae3 (7:6ae3) db $0b TX_FAR _CinnabarGymQuizCorrectText - db $06,$08 + db $06 + TX_ASM ld a, [$ffe0] + AdjustEventBit EVENT_CINNABAR_GYM_GATE0_UNLOCKED, 0 ld c, a - ld b, $2 - call CinnabarGymQuiz_1ea8a + ld b, FLAG_TEST + call CinnabarGymGateFlagAction ld a, c and a jp nz, TextScriptEnd call WaitForSoundToFinish - ld a, (SFX_02_57 - SFX_Headers_02) / 3 + ld a, SFX_GO_INSIDE call PlaySound call WaitForSoundToFinish jp TextScriptEnd @@ -257,44 +257,47 @@ CinnabarGymQuizIncorrectText: ; 1eb05 (7:6b05) TX_FAR _CinnabarGymQuizIncorrectText db "@" -CinnabarGymQuiz_1eb0a: ; 1eb0a (7:6b0a) - ld a, $6 - ld [$ffdb], a -.asm_1eb0e - ld a, [$ffdb] +UpdateCinnabarGymGateTileBlocks_: ; 1eb0a (7:6b0a) +; Update the overworld map with open floor blocks or locked gate blocks +; depending on event flags. + ld a, 6 + ld [hGymGateIndex], a +.loop + ld a, [hGymGateIndex] dec a add a add a - ld d, $0 + ld d, 0 ld e, a - ld hl, CinnabarGymGateCoords ; $6b48 + ld hl, CinnabarGymGateCoords add hl, de ld a, [hli] ld b, [hl] ld c, a inc hl ld a, [hl] - ld [wd12f], a + ld [wGymGateTileBlock], a push bc - ld a, [$ffdb] + ld a, [hGymGateIndex] ld [$ffe0], a + AdjustEventBit EVENT_CINNABAR_GYM_GATE0_UNLOCKED, 0 ld c, a - ld b, $2 - call CinnabarGymQuiz_1ea8a + ld b, FLAG_TEST + call CinnabarGymGateFlagAction ld a, c and a - jr nz, .asm_1eb36 - ld a, [wd12f] - jr .asm_1eb38 -.asm_1eb36 + jr nz, .unlocked + ld a, [wGymGateTileBlock] + jr .next +.unlocked ld a, $e -.asm_1eb38 +.next pop bc - ld [wd09f], a + ld [wNewTileBlockID], a predef ReplaceTileBlock - ld hl, $ffdb + ld hl, hGymGateIndex dec [hl] - jr nz, .asm_1eb0e + jr nz, .loop ret CinnabarGymGateCoords: ; 1eb48 (7:6b48) @@ -309,8 +312,7 @@ CinnabarGymGateCoords: ; 1eb48 (7:6b48) PrintMagazinesText: ; 1eb60 (7:6b60) call EnableAutoTextBoxDrawing - ld a, $30 - call PrintPredefTextID + tx_pre MagazinesText ret MagazinesText: ; 1eb69 (7:6b69) @@ -320,52 +322,47 @@ MagazinesText: ; 1eb69 (7:6b69) BillsHousePC: ; 1eb6e (7:6b6e) call EnableAutoTextBoxDrawing ld a, [wSpriteStateData1 + 9] - cp $4 + cp SPRITE_FACING_UP ret nz - ld a, [wd7f2] - bit 7, a + CheckEvent EVENT_LEFT_BILLS_HOUSE_AFTER_HELPING jr nz, .asm_1ebd2 - bit 3, a + CheckEventReuseA EVENT_USED_CELL_SEPARATOR_ON_BILL jr nz, .asm_1eb86 - bit 6, a + CheckEventReuseA EVENT_BILL_SAID_USE_CELL_SEPARATOR jr nz, .asm_1eb8b .asm_1eb86 - ld a, $2d - jp PrintPredefTextID + tx_pre_jump BillsHouseMonitorText .asm_1eb8b ld a, $1 ld [wDoNotWaitForButtonPressAfterDisplayingText], a - ld a, $2e - call PrintPredefTextID - ld c, $20 + tx_pre BillsHouseInitiatedText + ld c, 32 call DelayFrames - ld a, (SFX_02_3c - SFX_Headers_02) / 3 + ld a, SFX_TINK call PlaySound call WaitForSoundToFinish - ld c, $50 + ld c, 80 call DelayFrames - ld a, (SFX_02_48 - SFX_Headers_02) / 3 + ld a, SFX_SHRINK call PlaySound call WaitForSoundToFinish - ld c, $30 + ld c, 48 call DelayFrames - ld a, (SFX_02_3c - SFX_Headers_02) / 3 + ld a, SFX_TINK call PlaySound call WaitForSoundToFinish - ld c, $20 + ld c, 32 call DelayFrames - ld a, (SFX_02_3a - SFX_Headers_02) / 3 + ld a, SFX_GET_ITEM_1 call PlaySound call WaitForSoundToFinish call PlayDefaultMusic - ld hl, wd7f2 - set 3, [hl] + SetEvent EVENT_USED_CELL_SEPARATOR_ON_BILL ret .asm_1ebd2 ld a, $1 ld [wDoNotWaitForButtonPressAfterDisplayingText], a - ld a, $2f - call PrintPredefTextID + tx_pre BillsHousePokemonList ret BillsHouseMonitorText: ; 1ebdd (7:6bdd) @@ -375,21 +372,21 @@ BillsHouseMonitorText: ; 1ebdd (7:6bdd) BillsHouseInitiatedText: ; 1ebe2 (7:6be2) TX_FAR _BillsHouseInitiatedText db $06 - db $08 ; asm + TX_ASM ld a, $ff - ld [wc0ee], a + ld [wNewSoundID], a call PlaySound - ld c, $10 + ld c, 16 call DelayFrames - ld a, (SFX_02_49 - SFX_Headers_02) / 3 + ld a, SFX_SWITCH call PlaySound call WaitForSoundToFinish - ld c, $3c + ld c, 60 call DelayFrames jp TextScriptEnd BillsHousePokemonList: ; 1ec05 (7:6c05) - db $08 ; asm + TX_ASM call SaveScreenTilesToBuffer1 ld hl, BillsHousePokemonListText1 call PrintText @@ -397,7 +394,7 @@ BillsHousePokemonList: ; 1ec05 (7:6c05) ld [W_ANIMATIONID], a ld [wCurrentMenuItem], a ld [wLastMenuItem], a - ld a, $3 + ld a, A_BUTTON | B_BUTTON ld [wMenuWatchedKeys], a ld a, $4 ld [wMaxMenuItem], a @@ -405,38 +402,38 @@ BillsHousePokemonList: ; 1ec05 (7:6c05) ld [wTopMenuItemY], a ld a, $1 ld [wTopMenuItemX], a -.asm_1ec2d +.billsPokemonLoop ld hl, wd730 set 6, [hl] - ld hl, wTileMap + coord hl, 0, 0 ld b, $a ld c, $9 call TextBoxBorder - ld hl, wTileMap + $2a + coord hl, 2, 2 ld de, BillsMonListText call PlaceString ld hl, BillsHousePokemonListText2 call PrintText call SaveScreenTilesToBuffer2 call HandleMenuInput - bit 1, a - jr nz, .asm_1ec74 + bit 1, a ; pressed b + jr nz, .cancel ld a, [wCurrentMenuItem] add EEVEE cp EEVEE - jr z, .asm_1ec6c + jr z, .displayPokedex cp FLAREON - jr z, .asm_1ec6c + jr z, .displayPokedex cp JOLTEON - jr z, .asm_1ec6c + jr z, .displayPokedex cp VAPOREON - jr z, .asm_1ec6c - jr .asm_1ec74 -.asm_1ec6c + jr z, .displayPokedex + jr .cancel +.displayPokedex call DisplayPokedex call LoadScreenTilesFromBuffer2 - jr .asm_1ec2d -.asm_1ec74 + jr .billsPokemonLoop +.cancel ld hl, wd730 res 6, [hl] call LoadScreenTilesFromBuffer2 @@ -459,11 +456,10 @@ BillsHousePokemonListText2: ; 1ecaa (7:6caa) DisplayOakLabEmailText: ; 1ecaf (7:6caf) ld a, [wSpriteStateData1 + 9] - cp $4 + cp SPRITE_FACING_UP ret nz call EnableAutoTextBoxDrawing - ld a, $8 ; OakLabEmailText - jp PrintPredefTextID + tx_pre_jump OakLabEmailText OakLabEmailText: ; 1ecbd (7:6cbd) TX_FAR _OakLabEmailText diff --git a/engine/hp_bar.asm b/engine/hp_bar.asm index 333b0b90..792661ab 100755 --- a/engine/hp_bar.asm +++ b/engine/hp_bar.asm @@ -143,7 +143,7 @@ UpdateHPBar_AnimateHPBar: ; fab1 (3:7ab1) push de ld d, $6 call DrawHPBar - ld c, $2 + ld c, 2 call DelayFrames pop de ld a, [wHPBarDelta] ; +1 or -1 @@ -205,33 +205,34 @@ UpdateHPBar_PrintHPNumber: ; faf5 (3:7af5) push de ld a, [wHPBarType] and a - jr z, .asm_fb2d + jr z, .done ; don't print number in enemy HUD +; convert from little-endian to big-endian for PrintNumber ld a, [wHPBarOldHP] - ld [wcef1], a - ld a, [wHPBarOldHP+1] - ld [wcef0], a + ld [wHPBarTempHP + 1], a + ld a, [wHPBarOldHP + 1] + ld [wHPBarTempHP], a push hl ld a, [hFlags_0xFFF6] bit 0, a jr z, .asm_fb15 ld de, $9 - jr .asm_fb18 + jr .next .asm_fb15 ld de, $15 -.asm_fb18 +.next add hl, de push hl - ld a, $7f + ld a, " " ld [hli], a ld [hli], a ld [hli], a pop hl - ld de, wcef0 - ld bc, $203 + ld de, wHPBarTempHP + lb bc, 2, 3 call PrintNumber call DelayFrame pop hl -.asm_fb2d +.done pop de pop af ret diff --git a/engine/in_game_trades.asm b/engine/in_game_trades.asm index cb03a074..4229afd8 100755 --- a/engine/in_game_trades.asm +++ b/engine/in_game_trades.asm @@ -17,12 +17,12 @@ DoInGameTradeDialogue: ; 71ad9 (1c:5ad9) ld a,[hli] push af ld de,wInGameTradeMonNick - ld bc,$000b + ld bc, NAME_LENGTH call CopyData pop af ld l,a ld h,$0 - ld de,InGameTradeTextPointers ; $5d64 + ld de,InGameTradeTextPointers add hl,hl add hl,de ld a,[hli] @@ -38,7 +38,7 @@ DoInGameTradeDialogue: ; 71ad9 (1c:5ad9) ld hl,wCompletedInGameTradeFlags ld a,[wWhichTrade] ld c,a - ld b,$2 + ld b,FLAG_TEST predef FlagActionPredef ld a,c and a @@ -81,14 +81,14 @@ InGameTrade_GetMonName: ; 71b6a (1c:5b6a) call GetMonName ld hl,wcd6d pop de - ld bc,$b + ld bc, NAME_LENGTH jp CopyData INCLUDE "data/trades.asm" InGameTrade_DoTrade: ; 71c07 (1c:5c07) - xor a - ld [wd07d],a + xor a ; NORMAL_PARTY_MENU + ld [wPartyMenuTypeOrMessageID],a dec a ld [wUpdateSpritesEnabled],a call DisplayPartyMenu @@ -105,14 +105,14 @@ InGameTrade_DoTrade: ; 71c07 (1c:5c07) jr nz,.tradeFailed ; jump if the selected mon's species is not the required one ld a,[wWhichPokemon] ld hl,wPartyMon1Level - ld bc,$002c + ld bc, wPartyMon2 - wPartyMon1 call AddNTimes ld a,[hl] ld [W_CURENEMYLVL],a ld hl,wCompletedInGameTradeFlags ld a,[wWhichTrade] ld c,a - ld b,$1 + ld b,FLAG_SET predef FlagActionPredef ld hl, ConnectCableText call PrintText @@ -130,11 +130,11 @@ InGameTrade_DoTrade: ; 71c07 (1c:5c07) ld a,[wInGameTradeReceiveMonSpecies] ld [wcf91],a xor a - ld [wcc49],a - ld [wcf95],a + ld [wMonDataLocation],a ; not used + ld [wRemoveMonFromBox],a call RemovePokemon - ld a,$80 - ld [wcc49],a + ld a,$80 ; prevent the player from naming the mon + ld [wMonDataLocation],a call AddPartyMon call InGameTrade_CopyDataToReceivedMon callab EvolveTradeMon @@ -159,9 +159,7 @@ InGameTrade_RestoreScreen: ; 71ca2 (1c:5ca2) call LoadGBPal ld c, 10 call DelayFrames - ld b, BANK(LoadWildData) - ld hl, LoadWildData - jp Bankswitch + jpba LoadWildData InGameTrade_PrepareTradeData: ; 71cc1 (1c:5cc1) ld hl, wTradedPlayerMonSpecies @@ -170,16 +168,16 @@ InGameTrade_PrepareTradeData: ; 71cc1 (1c:5cc1) ld a, [wInGameTradeReceiveMonSpecies] ld [hl], a ; wTradedEnemyMonSpecies ld hl, wPartyMonOT - ld bc, $b + ld bc, NAME_LENGTH ld a, [wWhichPokemon] call AddNTimes ld de, wTradedPlayerMonOT - ld bc, $b + ld bc, NAME_LENGTH call InGameTrade_CopyData ld hl, InGameTrade_TrainerString - ld de, wcd4e + ld de, wTradedEnemyMonOT call InGameTrade_CopyData - ld de, W_GRASSRATE + ld de, wLinkEnemyTrainerName call InGameTrade_CopyData ld hl, wPartyMon1OTID ld bc, wPartyMon2 - wPartyMon1 @@ -203,16 +201,16 @@ InGameTrade_CopyData: ; 71d11 (1c:5d11) InGameTrade_CopyDataToReceivedMon: ; 71d19 (1c:5d19) ld hl, wPartyMonNicks - ld bc, $b + ld bc, NAME_LENGTH call InGameTrade_GetReceivedMonPointer ld hl, wInGameTradeMonNick - ld bc, $b + ld bc, NAME_LENGTH call CopyData ld hl, wPartyMonOT - ld bc, $b + ld bc, NAME_LENGTH call InGameTrade_GetReceivedMonPointer ld hl, InGameTrade_TrainerString - ld bc, $b + ld bc, NAME_LENGTH call CopyData ld hl, wPartyMon1OTID ld bc, wPartyMon2 - wPartyMon1 diff --git a/engine/intro.asm b/engine/intro.asm index 5b03f23a..6d2e350c 100755 --- a/engine/intro.asm +++ b/engine/intro.asm @@ -1,3 +1,7 @@ +MOVE_GENGAR_RIGHT EQU $00 +MOVE_GENGAR_LEFT EQU $01 +MOVE_NIDORINO_RIGHT EQU $ff + PlayIntro: ; 41682 (10:5682) xor a ld [hJoyHeld], a @@ -14,35 +18,35 @@ PlayIntro: ; 41682 (10:5682) ret PlayIntroScene: ; 4169d (10:569d) - ld b, $7 - call GoPAL_SET + ld b, SET_PAL_NIDORINO_INTRO + call RunPaletteCommand ld a, %11100100 ld [rBGP], a ld [rOBP0], a ld [rOBP1], a xor a ld [hSCX], a - ld b, $3 - call Func_4183f + ld b, $3 ; Gengar tiles + call IntroCopyTiles ld a, 0 ld [W_BASECOORDX], a ld a, 80 ld [W_BASECOORDY], a - ld bc, $606 - call Func_417c7 - ld de, $28ff - call Func_4180e + lb bc, 6, 6 + call InitIntroNidorinoOAM + lb de, 80 / 2, MOVE_NIDORINO_RIGHT + call IntroMoveMon ret c ; hip - ld a, (SFX_1f_5f - SFX_Headers_1f) / 3 + ld a, SFX_INTRO_HIP call PlaySound xor a - ld [wd09f], a + ld [wIntroNidorinoBaseTile], a ld de, IntroNidorinoAnimation1 call AnimateIntroNidorino ; hop - ld a, (SFX_1f_60 - SFX_Headers_1f) / 3 + ld a, SFX_INTRO_HOP call PlaySound ld de, IntroNidorinoAnimation2 call AnimateIntroNidorino @@ -51,12 +55,12 @@ PlayIntroScene: ; 4169d (10:569d) ret c ; hip - ld a, (SFX_1f_5f - SFX_Headers_1f) / 3 + ld a, SFX_INTRO_HIP call PlaySound ld de, IntroNidorinoAnimation1 call AnimateIntroNidorino ; hop - ld a, (SFX_1f_60 - SFX_Headers_1f) / 3 + ld a, SFX_INTRO_HOP call PlaySound ld de, IntroNidorinoAnimation2 call AnimateIntroNidorino @@ -66,284 +70,291 @@ PlayIntroScene: ; 4169d (10:569d) ; raise ld b, $4 - call Func_4183f - ld a, (SFX_1f_61 - SFX_Headers_1f) / 3 + call IntroCopyTiles + ld a, SFX_INTRO_RAISE call PlaySound - ld de, $401 - call Func_4180e + lb de, 8 / 2, MOVE_GENGAR_LEFT + call IntroMoveMon ld c, $1e call CheckForUserInterruption ret c ; slash ld b, $5 - call Func_4183f - ld a, (SFX_1f_62 - SFX_Headers_1f) / 3 + call IntroCopyTiles + ld a, SFX_INTRO_CRASH call PlaySound - ld de, $800 - call Func_4180e + lb de, 16 / 2, MOVE_GENGAR_RIGHT + call IntroMoveMon ; hip - ld a, (SFX_1f_5f - SFX_Headers_1f) / 3 + ld a, SFX_INTRO_HIP call PlaySound ld a, $24 - ld [wd09f], a + ld [wIntroNidorinoBaseTile], a ld de, IntroNidorinoAnimation3 call AnimateIntroNidorino ld c, $1e call CheckForUserInterruption ret c - ld de, $401 - call Func_4180e + lb de, 8 / 2, MOVE_GENGAR_LEFT + call IntroMoveMon ld b, $3 - call Func_4183f + call IntroCopyTiles ld c, $3c call CheckForUserInterruption ret c ; hip - ld a, (SFX_1f_5f - SFX_Headers_1f) / 3 + ld a, SFX_INTRO_HIP call PlaySound xor a - ld [wd09f], a - ld de, IntroNidorinoAnimation4 ; $5931 + ld [wIntroNidorinoBaseTile], a + ld de, IntroNidorinoAnimation4 call AnimateIntroNidorino ; hop - ld a, (SFX_1f_60 - SFX_Headers_1f) / 3 + ld a, SFX_INTRO_HOP call PlaySound - ld de, IntroNidorinoAnimation5 ; $593c + ld de, IntroNidorinoAnimation5 call AnimateIntroNidorino ld c, $14 call CheckForUserInterruption ret c ld a, $24 - ld [wd09f], a - ld de, IntroNidorinoAnimation6 ; $5947 + ld [wIntroNidorinoBaseTile], a + ld de, IntroNidorinoAnimation6 call AnimateIntroNidorino ld c, $1e call CheckForUserInterruption ret c ; lunge - ld a, (SFX_1f_5e - SFX_Headers_1f) / 3 + ld a, SFX_INTRO_LUNGE call PlaySound ld a, $48 - ld [wd09f], a - ld de, IntroNidorinoAnimation7 ; $5950 + ld [wIntroNidorinoBaseTile], a + ld de, IntroNidorinoAnimation7 jp AnimateIntroNidorino AnimateIntroNidorino: ; 41793 (10:5793) ld a, [de] cp $50 ret z - ld [W_BASECOORDY], a ; wd082 + ld [W_BASECOORDY], a inc de ld a, [de] - ld [W_BASECOORDX], a ; wd081 + ld [W_BASECOORDX], a push de - ld c, $24 - call Func_417ae + ld c, 6 * 6 + call UpdateIntroNidorinoOAM ld c, 5 call DelayFrames pop de inc de jr AnimateIntroNidorino -Func_417ae: ; 417ae (10:57ae) +UpdateIntroNidorinoOAM: ; 417ae (10:57ae) ld hl, wOAMBuffer - ld a, [wd09f] + ld a, [wIntroNidorinoBaseTile] ld d, a -.asm_417b5 - ld a, [W_BASECOORDY] ; wd082 +.loop + ld a, [W_BASECOORDY] add [hl] - ld [hli], a - ld a, [W_BASECOORDX] ; wd081 + ld [hli], a ; Y + ld a, [W_BASECOORDX] add [hl] - ld [hli], a + ld [hli], a ; X ld a, d - ld [hli], a + ld [hli], a ; tile inc hl inc d dec c - jr nz, .asm_417b5 + jr nz, .loop ret -Func_417c7: ; 417c7 (10:57c7) +InitIntroNidorinoOAM: ; 417c7 (10:57c7) ld hl, wOAMBuffer - ld d, $0 -.asm_417cc + ld d, 0 +.loop push bc - ld a, [W_BASECOORDY] ; wd082 + ld a, [W_BASECOORDY] ld e, a -.asm_417d1 +.innerLoop ld a, e - add $8 + add 8 ld e, a - ld [hli], a - ld a, [W_BASECOORDX] ; wd081 - ld [hli], a + ld [hli], a ; Y + ld a, [W_BASECOORDX] + ld [hli], a ; X ld a, d - ld [hli], a + ld [hli], a ; tile ld a, $80 - ld [hli], a + ld [hli], a ; attributes inc d dec c - jr nz, .asm_417d1 - ld a, [W_BASECOORDX] ; wd081 - add $8 - ld [W_BASECOORDX], a ; wd081 + jr nz, .innerLoop + ld a, [W_BASECOORDX] + add 8 + ld [W_BASECOORDX], a pop bc dec b - jr nz, .asm_417cc + jr nz, .loop ret -Func_417f0: ; 417f0 (10:57f0) +IntroClearScreen: ; 417f0 (10:57f0) ld hl, vBGMap1 ld bc, $240 - jr asm_417fe + jr IntroClearCommon + +IntroClearMiddleOfScreen: ; 417f8 (10:57f8) +; clear the area of the tile map between the black bars on the top and bottom + coord hl, 0, 4 + ld bc, SCREEN_WIDTH * 10 -Func_417f8: ; 417f8 (10:57f8) - hlCoord 0, 4 - ld bc, $c8 -asm_417fe: ; 417fe (10:57fe) +IntroClearCommon: ; 417fe (10:57fe) ld [hl], $0 inc hl dec bc ld a, b or c - jr nz, asm_417fe + jr nz, IntroClearCommon ret -Func_41807: ; 41807 (10:5807) +IntroPlaceBlackTiles: ; 41807 (10:5807) ld a, $1 -.asm_41809 +.loop ld [hli], a dec c - jr nz, .asm_41809 + jr nz, .loop ret -Func_4180e: ; 4180e (10:580e) +IntroMoveMon: ; 4180e (10:580e) +; d = number of times to move the mon (2 pixels each time) +; e: $00 = move Gengar right, $01 = move Gengar left, $ff = move Nidorino right ld a, e cp $ff - jr z, .asm_4181d + jr z, .moveNidorinoRight cp $1 - jr z, .asm_4182d + jr z, .moveGengarLeft +; move Gengar right ld a, [hSCX] dec a dec a - jr .asm_41831 -.asm_4181d + jr .next +.moveNidorinoRight push de - ld a, $2 - ld [W_BASECOORDX], a ; wd081 + ld a, 2 + ld [W_BASECOORDX], a xor a - ld [W_BASECOORDY], a ; wd082 - ld c, $24 - call Func_417ae + ld [W_BASECOORDY], a + ld c, 6 * 6 + call UpdateIntroNidorinoOAM pop de -.asm_4182d +.moveGengarLeft ld a, [hSCX] inc a inc a -.asm_41831 +.next ld [hSCX], a push de - ld c, $2 + ld c, 2 call CheckForUserInterruption pop de ret c dec d - jr nz, Func_4180e + jr nz, IntroMoveMon ret -Func_4183f: ; 4183f (10:583f) - hlCoord 13, 7 +IntroCopyTiles: ; 4183f (10:583f) + coord hl, 13, 7 CopyTileIDsFromList_ZeroBaseTileID: ; 41842 (10:5842) - ld c, $0 + ld c, 0 predef_jump CopyTileIDsFromList -Func_41849: ; 41849 (10:5849) - predef Func_79869 +PlayMoveSoundB: ; 41849 (10:5849) +; unused + predef GetMoveSoundB ld a, b jp PlaySound LoadIntroGraphics: ; 41852 (10:5852) - ld hl, FightIntroBackMon ; $5a99 + ld hl, FightIntroBackMon ld de, vChars2 - ld bc, $600 + ld bc, FightIntroBackMonEnd - FightIntroBackMon ld a, BANK(FightIntroBackMon) call FarCopyData2 - ld hl, GameFreakIntro ; $5959 + ld hl, GameFreakIntro ld de, vChars2 + $600 - ld bc, $140 + ld bc, GameFreakIntroEnd - GameFreakIntro ld a, BANK(GameFreakIntro) call FarCopyData2 - ld hl, GameFreakIntro ; $5959 + ld hl, GameFreakIntro ld de, vChars1 - ld bc, $140 + ld bc, GameFreakIntroEnd - GameFreakIntro ld a, BANK(GameFreakIntro) call FarCopyData2 - ld hl, FightIntroFrontMon ; $6099 + ld hl, FightIntroFrontMon ld de, vChars0 - ld bc, $6c0 + ld bc, FightIntroFrontMonEnd - FightIntroFrontMon ld a, BANK(FightIntroFrontMon) jp FarCopyData2 PlayShootingStar: ; 4188a (10:588a) - ld b, $c - call GoPAL_SET + ld b, SET_PAL_GAME_FREAK_INTRO + call RunPaletteCommand callba LoadCopyrightAndTextBoxTiles ld a, $e4 - ld [rBGP], a ; $ff47 - ld c, $b4 + ld [rBGP], a + ld c, 180 call DelayFrames call ClearScreen call DisableLCD xor a - ld [W_CUROPPONENT], a ; wd059 - call Func_418e9 + ld [W_CUROPPONENT], a + call IntroDrawBlackBars call LoadIntroGraphics call EnableLCD - ld hl, rLCDC ; $ff40 + ld hl, rLCDC res 5, [hl] set 3, [hl] - ld c, $40 + ld c, 64 call DelayFrames callba AnimateShootingStar push af pop af - jr c, .asm_418d0 - ld c, $28 + jr c, .next ; skip the delay if the user interrupted the animation + ld c, 40 call DelayFrames -.asm_418d0 +.next ld a, BANK(Music_IntroBattle) - ld [wc0ef], a - ld [wc0f0], a + ld [wAudioROMBank], a + ld [wAudioSavedROMBank], a ld a, MUSIC_INTRO_BATTLE - ld [wc0ee], a + ld [wNewSoundID], a call PlaySound - call Func_417f8 + call IntroClearMiddleOfScreen call ClearSprites jp Delay3 -Func_418e9: ; 418e9 (10:58e9) - call Func_417f0 - ld hl, wTileMap - ld c, $50 - call Func_41807 - hlCoord 0, 14 - ld c, $50 - call Func_41807 +IntroDrawBlackBars: ; 418e9 (10:58e9) +; clear the screen and draw black bars on the top and bottom + call IntroClearScreen + coord hl, 0, 0 + ld c, SCREEN_WIDTH * 4 + call IntroPlaceBlackTiles + coord hl, 0, 14 + ld c, SCREEN_WIDTH * 4 + call IntroPlaceBlackTiles ld hl, vBGMap1 ld c, $80 - call Func_41807 + call IntroPlaceBlackTiles ld hl, vBGMap1 + $1c0 ld c, $80 - jp Func_41807 + jp IntroPlaceBlackTiles -Func_4190c: ; 4190c (10:590c) +EmptyFunc4: ; 4190c (10:590c) ret IntroNidorinoAnimation0: ; 4190d (10:590d) @@ -423,12 +434,16 @@ GameFreakIntro: ; 41959 (10:5959) INCBIN "gfx/gamefreak_intro.2bpp" INCBIN "gfx/gamefreak_logo.2bpp" ds $10 ; blank tile +GameFreakIntroEnd: FightIntroBackMon: ; 41a99 (10:5a99) INCBIN "gfx/intro_fight.2bpp" +FightIntroBackMonEnd: FightIntroFrontMon: ; 42099 (10:6099) INCBIN "gfx/intro_nido_1.6x6.2bpp" INCBIN "gfx/intro_nido_2.6x6.2bpp" INCBIN "gfx/intro_nido_3.6x6.2bpp" +FightIntroFrontMonEnd: + ds $10 ; blank tile diff --git a/engine/items/itemfinder.asm b/engine/items/itemfinder.asm index d7e5b3ce..5da72388 100755 --- a/engine/items/itemfinder.asm +++ b/engine/items/itemfinder.asm @@ -1,16 +1,16 @@ HiddenItemNear: ; 7481f (1d:481f) ld hl, HiddenItemCoords - ld b, $0 -.asm_74824 - ld de, $0003 + ld b, 0 +.loop + ld de, 3 ld a, [W_CURMAP] call IsInRestOfArray ret nc ; return if current map has no hidden items push bc push hl - ld hl, wd6f0 + ld hl, wObtainedHiddenItemsFlags ld c, b - ld b, $2 + ld b, FLAG_TEST predef FlagActionPredef ld a, c pop hl @@ -22,28 +22,30 @@ HiddenItemNear: ; 7481f (1d:481f) inc hl ld e, [hl] inc hl - jr nz, .asm_74824 ; 0x74845 $dd + jr nz, .loop ; if the item has already been obtained +; check if the item is within 4-5 tiles (depending on the direction of item) ld a, [W_YCOORD] - call Func_7486b + call Sub5ClampTo0 cp d - jr nc, .asm_74824 ; 0x7484e $d4 + jr nc, .loop ld a, [W_YCOORD] - add $4 + add 4 cp d - jr c, .asm_74824 ; 0x74856 $cc + jr c, .loop ld a, [W_XCOORD] - call Func_7486b + call Sub5ClampTo0 cp e - jr nc, .asm_74824 ; 0x7485f $c3 + jr nc, .loop ld a, [W_XCOORD] - add $5 + add 5 cp e - jr c, .asm_74824 ; 0x74867 $bb + jr c, .loop scf ret -Func_7486b: ; 7486b (1d:486b) - sub $5 +Sub5ClampTo0: ; 7486b (1d:486b) +; subtract 5 but clamp to 0 + sub 5 cp $f0 ret c xor a diff --git a/engine/items/items.asm b/engine/items/items.asm index 7d939ae6..29289fd9 100755 --- a/engine/items/items.asm +++ b/engine/items/items.asm @@ -1,6 +1,6 @@ UseItem_: ; d5c7 (3:55c7) ld a,1 - ld [wcd6a],a + ld [wActionResultOrTookBattleTurn],a ; initialise to success value ld a,[wcf91] ;contains item_ID cp a,HM_01 jp nc,ItemUseTMHM @@ -91,9 +91,9 @@ ItemUsePtrTable: ; d5e1 (3:55e1) dw ItemUsePokeflute ; POKE_FLUTE dw UnusableItem ; LIFT_KEY dw UnusableItem ; EXP__ALL - dw OldRodCode ; OLD_ROD - dw GoodRodCode ; GOOD_ROD - dw SuperRodCode ; SUPER_ROD + dw ItemUseOldRod ; OLD_ROD + dw ItemUseGoodRod ; GOOD_ROD + dw ItemUseSuperRod ; SUPER_ROD dw ItemUsePPUp ; PP_UP (real one) dw ItemUsePPRestore ; ETHER dw ItemUsePPRestore ; MAX_ETHER @@ -115,10 +115,10 @@ ItemUseBall: ; d687 (3:5687) ld a,[W_NUMINBOX] ;is Box full? cp a,MONS_PER_BOX jp z,BoxFullCannotThrowBall -.UseBall ;$56a7 +.UseBall ;ok, you can use a ball xor a - ld [wd11c],a + ld [wCapturedMonSpecies],a ld a,[W_BATTLETYPE] cp a,2 ;SafariBattle jr nz,.skipSafariZoneCode @@ -126,8 +126,8 @@ ItemUseBall: ; d687 (3:5687) ; remove a Safari Ball from inventory ld hl,W_NUMSAFARIBALLS dec [hl] -.skipSafariZoneCode ;$56b6 - call GoPAL_SET_CF1C +.skipSafariZoneCode + call RunDefaultPaletteCommand ld a,$43 ld [wd11e],a call LoadScreenTilesFromBuffer1 ;restore screenBuffer from Backup @@ -142,10 +142,10 @@ ItemUseBall: ; d687 (3:5687) .oldManBattle ld hl,W_GRASSRATE ld de,wPlayerName - ld bc,11 + ld bc,NAME_LENGTH call CopyData ; save the player's name in the Wild Monster data (part of the Cinnabar Island Missingno glitch) - jp .BallSuccess ;$578b -.notOldManBattle ;$56e9 + jp .BallSuccess +.notOldManBattle ld a,[W_CURMAP] cp a,POKEMONTOWER_6 jr nz,.loop @@ -155,13 +155,13 @@ ItemUseBall: ; d687 (3:5687) jp z,.next12 ; if not fighting ghost Marowak, loop until a random number in the current ; pokeball's allowed range is found -.loop ;$56fa +.loop call Random ld b,a ld hl,wcf91 ld a,[hl] cp a,MASTER_BALL - jp z,.BallSuccess ;$578b + jp z,.BallSuccess cp a,POKE_BALL jr z,.checkForAilments ld a,200 @@ -173,7 +173,7 @@ ItemUseBall: ; d687 (3:5687) ld a,150 ;get only numbers <= 150 for Ultra Ball cp b jr c,.loop -.checkForAilments ;$571a +.checkForAilments ; pokemon can be caught more easily with any (primary) status ailment ; Frozen/Asleep pokemon are relatively even easier to catch ; for Frozen/Asleep pokemon, any random number from 0-24 ensures a catch. @@ -185,12 +185,12 @@ ItemUseBall: ; d687 (3:5687) ld c,12 jr z,.notFrozenOrAsleep ld c,25 -.notFrozenOrAsleep ;$5728 +.notFrozenOrAsleep ld a,b sub c - jp c,.BallSuccess ;$578b + jp c,.BallSuccess ld b,a -.noAilments ;$572e +.noAilments push bc ;save RANDOM number xor a ld [H_MULTIPLICAND],a @@ -207,7 +207,7 @@ ItemUseBall: ; d687 (3:5687) ld a,12 ;any other BallFactor jr nz,.next7 ld a,8 -.next7 ;$574d +.next7 ld [H_DIVISOR],a ld b,4 ; number of bytes in dividend call Divide @@ -226,7 +226,7 @@ ItemUseBall: ; d687 (3:5687) and a jr nz,.next8 inc a -.next8 ;$5766 +.next8 ld [H_DIVISOR],a ld b,4 call Divide ; ((MaxHP * 255) / BallFactor) / (CurHP / 4) @@ -235,7 +235,7 @@ ItemUseBall: ; d687 (3:5687) jr z,.next9 ld a,255 ld [H_QUOTIENT + 3],a -.next9 ;$5776 +.next9 pop bc ld a,[wEnemyMonCatchRate] ;enemy: Catch Rate cp b @@ -248,9 +248,9 @@ ItemUseBall: ; d687 (3:5687) ld a,[H_QUOTIENT + 3] cp b jr c,.next10 -.BallSuccess ;$578b +.BallSuccess jr .BallSuccess2 -.next10 ;$578d +.next10 ld a,[H_QUOTIENT + 3] ld [wd11e],a xor a @@ -271,7 +271,7 @@ ItemUseBall: ; d687 (3:5687) ld b,150 cp a,ULTRA_BALL jr z,.next11 -.next11 ;$57b8 +.next11 ld a,b ld [H_DIVISOR],a ld b,4 @@ -294,11 +294,11 @@ ItemUseBall: ; d687 (3:5687) ld b,5 jr z,.next14 ld b,10 -.next14 ;$57e6 +.next14 ld a,[H_QUOTIENT + 3] add b ld [H_QUOTIENT + 3],a -.next13 ;$57eb +.next13 ld a,[H_QUOTIENT + 3] cp a,10 ld b,$20 @@ -310,16 +310,16 @@ ItemUseBall: ; d687 (3:5687) ld b,$62 jr c,.next12 ld b,$63 -.next12 ;$5801 +.next12 ld a,b - ld [wd11e],a -.BallSuccess2 ;$5805 + ld [wPokeBallAnimData],a +.BallSuccess2 ld c,20 call DelayFrames ld a,TOSS_ANIM ld [W_ANIMATIONID],a xor a - ld [$fff3],a + ld [H_WHOSETURN],a ld [wAnimationType],a ld [wDamageMultipliers],a ld a,[wWhichPokemon] @@ -331,7 +331,7 @@ ItemUseBall: ; d687 (3:5687) ld [wcf91],a pop af ld [wWhichPokemon],a - ld a,[wd11e] + ld a,[wPokeBallAnimData] cp a,$10 ld hl,ItemUseBallText00 jp z,.printText0 @@ -362,14 +362,14 @@ ItemUseBall: ; d687 (3:5687) ld a,$4c ld [wEnemyMonSpecies2],a jr .next16 -.next15 ;$5871 +.next15 set Transformed,[hl] - ld hl,wcceb + ld hl,wTransformedEnemyMonOriginalDVs ld a,[wEnemyMonDVs] ld [hli],a ld a,[wEnemyMonDVs + 1] ld [hl],a -.next16 ;$587e +.next16 ld a,[wcf91] push af ld a,[wEnemyMonSpecies2] @@ -388,7 +388,7 @@ ItemUseBall: ; d687 (3:5687) pop af ld [hl],a ld a,[wEnemyMonSpecies] ;enemy - ld [wd11c],a + ld [wCapturedMonSpecies],a ld [wcf91],a ld [wd11e],a ld a,[W_BATTLETYPE] @@ -400,15 +400,15 @@ ItemUseBall: ; d687 (3:5687) ld a,[wd11e] dec a ld c,a - ld b,2 - ld hl,wPokedexOwned ;Dex_own_flags (pokemon) + ld b,FLAG_TEST + ld hl,wPokedexOwned predef FlagActionPredef ld a,c push af ld a,[wd11e] dec a ld c,a - ld b,1 + ld b,FLAG_SET predef FlagActionPredef pop af and a @@ -419,39 +419,38 @@ ItemUseBall: ; d687 (3:5687) ld a,[wEnemyMonSpecies] ;caught mon_ID ld [wd11e],a predef ShowPokedexData -.checkParty ;$58f4 +.checkParty ld a,[wPartyCount] cp a,PARTY_LENGTH ;is party full? jr z,.sendToBox - xor a - ld [wcc49],a + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation],a call ClearSprites call AddPartyMon ;add mon to Party jr .End -.sendToBox ;$5907 +.sendToBox call ClearSprites call SendNewMonToBox ld hl,ItemUseBallText07 - ld a,[wd7f1] - bit 0,a ;already met Bill? + CheckEvent EVENT_MET_BILL jr nz,.sendToBox2 ld hl,ItemUseBallText08 -.sendToBox2 ;$591a +.sendToBox2 call PrintText jr .End -.printText1 ;$591f +.printText1 ld hl,ItemUseBallText05 -.printText0 ;$5922 +.printText0 call PrintText call ClearSprites -.End ;$5928 +.End ld a,[W_BATTLETYPE] and a ret nz ld hl,wNumBagItems inc a - ld [wcf96],a - jp RemoveItemFromInventory ;remove ITEM (XXX) + ld [wItemQuantity],a + jp RemoveItemFromInventory ItemUseBallText00: ; d937 (3:5937) ;"It dodged the thrown ball!" ;"This pokemon can't be caught" @@ -499,9 +498,7 @@ ItemUseTownMap: ; d968 (3:5968) ld a,[W_ISINBATTLE] and a jp nz,ItemUseNotTime - ld b, BANK(DisplayTownMap) - ld hl, DisplayTownMap - jp Bankswitch ; display Town Map + jpba DisplayTownMap ItemUseBicycle: ; d977 (3:5977) ld a,[W_ISINBATTLE] @@ -556,11 +553,11 @@ ItemUseSurfboard: ; d9b4 (3:59b4) jp PrintText .tryToStopSurfing xor a - ld [$ff8c],a + ld [hSpriteIndexOrTextID],a ld d,16 ; talking range in pixels (normal range) call IsSpriteInFrontOfPlayer2 res 7,[hl] - ld a,[$ff8c] + ld a,[hSpriteIndexOrTextID] and a ; is there a sprite in the way? jr nz,.cannotStopSurfing ld hl,TilePairCollisionsWater @@ -593,14 +590,14 @@ ItemUseSurfboard: ; d9b4 (3:59b4) jp LoadWalkingPlayerSpriteGraphics ; uses a simulated button press to make the player move forward .makePlayerMoveForward - ld a,[wd52a] ; direction the player is going - bit 3,a + ld a,[wPlayerDirection] ; direction the player is going + bit PLAYER_DIR_BIT_UP,a ld b,D_UP jr nz,.storeSimulatedButtonPress - bit 2,a + bit PLAYER_DIR_BIT_DOWN,a ld b,D_DOWN jr nz,.storeSimulatedButtonPress - bit 1,a + bit PLAYER_DIR_BIT_LEFT,a ld b,D_LEFT jr nz,.storeSimulatedButtonPress ld b,D_RIGHT @@ -631,10 +628,10 @@ ItemUseEvoStone: ; da5b (3:5a5b) ld a,[wWhichPokemon] push af ld a,[wcf91] - ld [wd156],a + ld [wEvoStoneItemID],a push af - ld a,$05 ; evolution stone party menu - ld [wd07d],a + ld a,EVO_STONE_PARTY_MENU + ld [wPartyMenuTypeOrMessageID],a ld a,$ff ld [wUpdateSpritesEnabled],a call DisplayPartyMenu @@ -643,25 +640,25 @@ ItemUseEvoStone: ; da5b (3:5a5b) ld a,b ld [wcf91],a ld a,$01 - ld [wccd4],a - ld a,(SFX_02_3e - SFX_Headers_02) / 3 - call PlaySoundWaitForCurrent ; play sound - call WaitForSoundToFinish ; wait for sound to end + ld [wForceEvolution],a + ld a,SFX_HEAL_AILMENT + call PlaySoundWaitForCurrent + call WaitForSoundToFinish callab TryEvolvingMon ; try to evolve pokemon - ld a,[wd121] + ld a,[wEvolutionOccurred] and a jr z,.noEffect pop af ld [wWhichPokemon],a ld hl,wNumBagItems ld a,1 ; remove 1 stone - ld [wcf96],a + ld [wItemQuantity],a jp RemoveItemFromInventory .noEffect call ItemUseNoEffect .canceledItemUse xor a - ld [wcd6a],a + ld [wActionResultOrTookBattleTurn],a ; item not used pop af ret @@ -678,11 +675,11 @@ ItemUseMedicine: ; dabb (3:5abb) push af ld a,[wcf91] push af - ld a,$01 - ld [wd07d],a ; item use party menu + ld a,USE_ITEM_PARTY_MENU + ld [wPartyMenuTypeOrMessageID],a ld a,$ff ld [wUpdateSpritesEnabled],a - ld a,[wd152] + ld a,[wPseudoItemID] and a ; using Softboiled? jr z,.notUsingSoftboiled ; if using softboiled @@ -691,7 +688,7 @@ ItemUseMedicine: ; dabb (3:5abb) .emptyParty ld hl,.emptyPartyText xor a - ld [wcd6a],a ; item use failed + ld [wActionResultOrTookBattleTurn],a ; item use failed jp PrintText .emptyPartyText text "You don't have" @@ -706,7 +703,7 @@ ItemUseMedicine: ; dabb (3:5abb) ld a,[wWhichPokemon] call AddNTimes ld a,[wWhichPokemon] - ld [wcf06],a + ld [wUsedItemOnWhichPokemon],a ld d,a ld a,[wcf91] ld e,a @@ -715,7 +712,7 @@ ItemUseMedicine: ; dabb (3:5abb) ld [wcf91],a pop af ld [wWhichPokemon],a - ld a,[wd152] + ld a,[wPseudoItemID] and a ; using Softboiled? jr z,.checkItemType ; if using softboiled @@ -737,22 +734,22 @@ ItemUseMedicine: ; dabb (3:5abb) ld bc,4 add hl,bc ; hl now points to status ld a,[wcf91] - ld bc,$f008 + lb bc, ANTIDOTE_MSG, 1 << PSN cp a,ANTIDOTE jr z,.checkMonStatus - ld bc,$f110 + lb bc, BURN_HEAL_MSG, 1 << BRN cp a,BURN_HEAL jr z,.checkMonStatus - ld bc,$f220 + lb bc, ICE_HEAL_MSG, 1 << FRZ cp a,ICE_HEAL jr z,.checkMonStatus - ld bc,$f307 + lb bc, AWAKENING_MSG, SLP cp a,AWAKENING jr z,.checkMonStatus - ld bc,$f440 + lb bc, PARALYZ_HEAL_MSG, 1 << PAR cp a,PARLYZ_HEAL jr z,.checkMonStatus - ld bc,$f6ff ; Full Heal + lb bc, FULL_HEAL_MSG, $ff ; Full Heal .checkMonStatus ld a,[hl] ; pokemon's status and c ; does the pokemon have a status ailment the item can cure? @@ -761,7 +758,7 @@ ItemUseMedicine: ; dabb (3:5abb) xor a ld [hl],a ; remove the status ailment in the party data ld a,b - ld [wd07d],a ; the message to display for the item used + ld [wPartyMenuTypeOrMessageID],a ; the message to display for the item used ld a,[wPlayerMonNumber] cp d ; is pokemon the item was used on active in battle? jp nz,.doneHealing @@ -803,18 +800,18 @@ ItemUseMedicine: ; dabb (3:5abb) push hl push de push bc - ld a,[wcf06] + ld a,[wUsedItemOnWhichPokemon] ld c,a ld hl,wPartyFoughtCurrentEnemyFlags - ld b,$02 + ld b,FLAG_TEST predef FlagActionPredef ld a,c and a jr z,.next - ld a,[wcf06] + ld a,[wUsedItemOnWhichPokemon] ld c,a ld hl,wPartyGainExpFlags - ld b,$01 + ld b,FLAG_SET predef FlagActionPredef .next pop bc @@ -859,7 +856,7 @@ ItemUseMedicine: ; dabb (3:5abb) .notFullHP ; if the pokemon's current HP doesn't equal its max HP xor a ld [wLowHealthAlarm],a ;disable low health alarm - ld [wc02a],a + ld [wChannelSoundIDs + CH4],a push hl push de ld bc,32 @@ -868,7 +865,7 @@ ItemUseMedicine: ; dabb (3:5abb) ld [wHPBarMaxHP+1],a ld a,[hl] ld [wHPBarMaxHP],a ; max HP stored at wHPBarMaxHP (2 bytes, big-endian) - ld a,[wd152] + ld a,[wPseudoItemID] and a ; using Softboiled? jp z,.notUsingSoftboiled2 ; if using softboiled @@ -913,12 +910,12 @@ ItemUseMedicine: ; dabb (3:5abb) sbc b ld [hl],a ld [wHPBarNewHP+1],a - hlCoord 4, 1 + coord hl, 4, 1 ld a,[wWhichPokemon] - ld bc,2 * 20 + ld bc,2 * SCREEN_WIDTH call AddNTimes ; calculate coordinates of HP bar of pokemon that used Softboiled - ld a,(SFX_02_3d - SFX_Headers_02) / 3 - call PlaySoundWaitForCurrent ; play sound + ld a,SFX_HEAL_HP + call PlaySoundWaitForCurrent ld a,[hFlags_0xFFF6] set 0,a ld [hFlags_0xFFF6],a @@ -1055,7 +1052,7 @@ ItemUseMedicine: ; dabb (3:5abb) call ItemUseNoEffect jp .done .doneHealing - ld a,[wd152] + ld a,[wPseudoItemID] and a ; using Softboiled? jr nz,.skipRemovingItem ; no item to remove if using Softboiled push hl @@ -1067,8 +1064,8 @@ ItemUseMedicine: ; dabb (3:5abb) jr c,.playStatusAilmentCuringSound cp a,FULL_HEAL jr z,.playStatusAilmentCuringSound - ld a,(SFX_02_3d - SFX_Headers_02) / 3 ; HP healing sound - call PlaySoundWaitForCurrent ; play sound + ld a,SFX_HEAL_HP + call PlaySoundWaitForCurrent ld a,[hFlags_0xFFF6] set 0,a ld [hFlags_0xFFF6],a @@ -1078,18 +1075,18 @@ ItemUseMedicine: ; dabb (3:5abb) ld a,[hFlags_0xFFF6] res 0,a ld [hFlags_0xFFF6],a - ld a,$f7 ; revived message - ld [wd07d],a + ld a,REVIVE_MSG + ld [wPartyMenuTypeOrMessageID],a ld a,[wcf91] cp a,REVIVE jr z,.showHealingItemMessage cp a,MAX_REVIVE jr z,.showHealingItemMessage - ld a,$f5 ; standard HP healed message - ld [wd07d],a + ld a,POTION_MSG + ld [wPartyMenuTypeOrMessageID],a jr .showHealingItemMessage .playStatusAilmentCuringSound - ld a,(SFX_02_3e - SFX_Headers_02) / 3 ; status ailment curing sound + ld a,SFX_HEAL_AILMENT call PlaySoundWaitForCurrent .showHealingItemMessage xor a @@ -1106,15 +1103,15 @@ ItemUseMedicine: ; dabb (3:5abb) jr .done .canceledItemUse xor a - ld [wcd6a],a ; item use failed + ld [wActionResultOrTookBattleTurn],a ; item use failed pop af pop af .done - ld a,[wd152] + ld a,[wPseudoItemID] and a ; using Softboiled? ret nz ; if so, return call GBPalWhiteOut - call z,GoPAL_SET_CF1C + call z,RunDefaultPaletteCommand ld a,[W_ISINBATTLE] and a ret nz @@ -1178,8 +1175,8 @@ ItemUseMedicine: ; dabb (3:5abb) ld de,wcf4b ld bc,10 call CopyData ; copy the stat's name to wcf4b - ld a,(SFX_02_3e - SFX_Headers_02) / 3 - call PlaySound ; play sound + ld a,SFX_HEAL_AILMENT + call PlaySound ld hl,VitaminStatRoseText call PrintText jp RemoveUsedItem @@ -1216,11 +1213,11 @@ ItemUseMedicine: ; dabb (3:5abb) ld bc,-19 add hl,bc ; hl now points to experience ; update experience to minimum for new level - ld a,[$ff96] + ld a,[hExperience] ld [hli],a - ld a,[$ff97] + ld a,[hExperience + 1] ld [hli],a - ld a,[$ff98] + ld a,[hExperience + 2] ld [hl],a pop hl ld a,[wWhichPokemon] @@ -1257,25 +1254,25 @@ ItemUseMedicine: ; dabb (3:5abb) ld a,[hl] adc b ld [hl],a - ld a,$f8 ; level up message - ld [wd07d],a + ld a,RARE_CANDY_MSG + ld [wPartyMenuTypeOrMessageID],a call RedrawPartyMenu pop de ld a,d ld [wWhichPokemon],a ld a,e ld [wd11e],a - xor a - ld [wcc49],a ; load from player's party + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation],a call LoadMonData ld d,$01 callab PrintStatsBox ; display new stats text box call WaitForTextScrollButtonPress ; wait for button press - xor a - ld [wcc49],a + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation],a predef LearnMoveFromLevelUp ; learn level up move, if any xor a - ld [wccd4],a + ld [wForceEvolution],a callab TryEvolvingMon ; evolve pokemon, if appropriate ld a,$01 ld [wUpdateSpritesEnabled],a @@ -1327,7 +1324,7 @@ ItemUseRock: ; df67 (3:5f67) BaitRockCommon: ; df7f (3:5f7f) ld [W_ANIMATIONID],a xor a - ld [wcc5b],a + ld [wAnimationType],a ld [H_WHOSETURN],a ld [de],a ; zero escape factor (for bait), zero bait factor (for rock) .randomLoop ; loop until a random number less than 5 is generated @@ -1377,15 +1374,14 @@ ItemUseEscapeRope: ; dfaf (3:5faf) set 6,[hl] ld hl,wd72e res 4,[hl] - ld hl,wd790 - res 7,[hl] ; unset Safari Zone bit + ResetEvent EVENT_IN_SAFARI_ZONE xor a ld [W_NUMSAFARIBALLS],a ld [W_SAFARIZONEENTRANCECURSCRIPT],a inc a ld [wEscapedFromBattle],a - ld [wcd6a],a ; item used - ld a,[wd152] + ld [wActionResultOrTookBattleTurn],a ; item used + ld a,[wPseudoItemID] and a ; using Dig? ret nz ; if so, return call ItemUseReloadOverworldData @@ -1423,7 +1419,7 @@ ItemUseXAccuracy: ; e013 (3:6013) ; The Card Key is handled in a different way. ItemUseCardKey: ; e022 (3:6022) xor a - ld [wd71f],a + ld [wUnusedD71F],a call GetTileAndCoordsInFrontOfPlayer ld a,[GetTileAndCoordsInFrontOfPlayer] ; $4586 cp a,$18 @@ -1455,7 +1451,7 @@ ItemUseCardKey: ; e022 (3:6022) cp e jr nz,.nextEntry3 ld a,[hl] - ld [wd71f],a + ld [wUnusedD71F],a jr .done .nextEntry1 inc hl @@ -1550,7 +1546,7 @@ ItemUseXStat: ; e104 (3:6104) jr nz,.inBattle call ItemUseNotTime ld a,2 - ld [wcd6a],a ; item not used + ld [wActionResultOrTookBattleTurn],a ; item not used ret .inBattle ld hl,W_PLAYERMOVENUM @@ -1586,8 +1582,7 @@ ItemUsePokeflute: ; e140 (3:6140) ld a,[W_CURMAP] cp a,ROUTE_12 jr nz,.notRoute12 - ld a,[wd7d8] - bit 7,a ; has the player beaten Route 12 Snorlax yet? + CheckEvent EVENT_BEAT_ROUTE12_SNORLAX jr nz,.noSnorlaxToWakeUp ; if the player hasn't beaten Route 12 Snorlax ld hl,Route12SnorlaxFluteCoords @@ -1595,14 +1590,12 @@ ItemUsePokeflute: ; e140 (3:6140) jr nc,.noSnorlaxToWakeUp ld hl,PlayedFluteHadEffectText call PrintText - ld hl,wd7d8 - set 6,[hl] ; trigger Snorlax fight (handled by map script) + SetEvent EVENT_FIGHT_ROUTE12_SNORLAX ret .notRoute12 cp a,ROUTE_16 jr nz,.noSnorlaxToWakeUp - ld a,[wd7e0] - bit 1,a ; has the player beaten Route 16 Snorlax yet? + CheckEvent EVENT_BEAT_ROUTE16_SNORLAX jr nz,.noSnorlaxToWakeUp ; if the player hasn't beaten Route 16 Snorlax ld hl,Route16SnorlaxFluteCoords @@ -1610,16 +1603,15 @@ ItemUsePokeflute: ; e140 (3:6140) jr nc,.noSnorlaxToWakeUp ld hl,PlayedFluteHadEffectText call PrintText - ld hl,wd7e0 - set 0,[hl] ; trigger Snorlax fight (handled by map script) + SetEvent EVENT_FIGHT_ROUTE16_SNORLAX ret .noSnorlaxToWakeUp ld hl,PlayedFluteNoEffectText jp PrintText .inBattle xor a - ld [wWhichTrade],a ; initialize variable that indicates if any pokemon were woken up to zero - ld b,~SLP & $FF + ld [wWereAnyMonsAsleep],a + ld b,~SLP & $ff ld hl,wPartyMon1Status call WakeUpEntireParty ld a,[W_ISINBATTLE] @@ -1638,7 +1630,7 @@ ItemUsePokeflute: ; e140 (3:6140) and b ; remove Sleep status ld [hl],a call LoadScreenTilesFromBuffer2 ; restore saved screen - ld a,[wWhichTrade] + ld a,[wWereAnyMonsAsleep] and a ; were any pokemon asleep before playing the flute? ld hl,PlayedFluteNoEffectText jp z,PrintText ; if no pokemon were asleep @@ -1651,7 +1643,7 @@ ItemUsePokeflute: ; e140 (3:6140) call WaitForSoundToFinish ; wait for sound to end callba Music_PokeFluteInBattle ; play in-battle pokeflute music .musicWaitLoop ; wait for music to finish playing - ld a,[wc02c] + ld a,[wChannelSoundIDs + CH6] and a ; music off? jr nz,.musicWaitLoop .skipMusic @@ -1662,9 +1654,9 @@ ItemUsePokeflute: ; e140 (3:6140) ; INPUT: ; hl must point to status of first pokemon in party (player's or enemy's) ; b must equal ~SLP -; [wWhichTrade] should be initialized to 0 +; [wWereAnyMonsAsleep] should be initialized to 0 ; OUTPUT: -; [wWhichTrade]: set to 1 if any pokemon were asleep +; [wWereAnyMonsAsleep]: set to 1 if any pokemon were asleep WakeUpEntireParty: ; e1e5 (3:61e5) ld de,44 ld c,6 @@ -1674,7 +1666,7 @@ WakeUpEntireParty: ; e1e5 (3:61e5) and a,SLP ; is pokemon asleep? jr z,.notAsleep ld a,1 - ld [wWhichTrade],a ; indicate that a pokemon had to be woken up + ld [wWereAnyMonsAsleep],a ; indicate that a pokemon had to be woken up .notAsleep pop af and b ; remove Sleep status @@ -1713,19 +1705,19 @@ FluteWokeUpText: ; e210 (3:6210) PlayedFluteHadEffectText: ; e215 (3:6215) TX_FAR _PlayedFluteHadEffectText db $06 - db $08 + TX_ASM ld a,[W_ISINBATTLE] and a jr nz,.done ; play out-of-battle pokeflute music ld a,$ff call PlaySound ; turn off music - ld a, (SFX_02_5e - SFX_Headers_02) / 3 - ld c, BANK(SFX_02_5e) - call PlayMusic ; play music + ld a, SFX_POKEFLUE + ld c, BANK(SFX_Pokeflute) + call PlayMusic .musicWaitLoop ; wait for music to finish playing - ld a,[wc028] - cp a,$b8 + ld a,[wChannelSoundIDs + CH2] + cp a, SFX_POKEFLUE jr z,.musicWaitLoop call PlayDefaultMusic ; start playing normal music again .done @@ -1742,14 +1734,14 @@ CoinCaseNumCoinsText: ; e247 (3:6247) TX_FAR _CoinCaseNumCoinsText db "@" -OldRodCode: ; e24c (3:624c) +ItemUseOldRod: ; e24c (3:624c) call FishingInit jp c, ItemUseNotTime - ld bc, (5 << 8) | MAGIKARP + lb bc, 5, MAGIKARP ld a, $1 ; set bite - jr RodResponse ; 0xe257 $34 + jr RodResponse -GoodRodCode: ; e259 (3:6259) +ItemUseGoodRod: ; e259 (3:6259) call FishingInit jp c,ItemUseNotTime .RandomLoop @@ -1777,13 +1769,13 @@ GoodRodCode: ; e259 (3:6259) INCLUDE "data/good_rod.asm" -SuperRodCode: ; e283 (3:6283) +ItemUseSuperRod: ; e283 (3:6283) call FishingInit jp c, ItemUseNotTime - call ReadSuperRodData ; 0xe8ea + call ReadSuperRodData ld a, e RodResponse: ; e28d (3:628d) - ld [wWhichTrade], a + ld [wRodResponse], a dec a ; is there a bite? jr nz, .next @@ -1801,7 +1793,7 @@ RodResponse: ; e28d (3:628d) push af push hl ld [hl], 0 - callba Func_707b6 + callba FishingAnim pop hl pop af ld [hl], a @@ -1824,8 +1816,8 @@ FishingInit: ; e2b4 (3:62b4) call ItemUseReloadOverworldData ld hl,ItemUseText00 call PrintText - ld a,(SFX_02_3e - SFX_Headers_02) / 3 - call PlaySound ; play sound + ld a,SFX_HEAL_AILMENT + call PlaySound ld c,80 call DelayFrames and a @@ -1847,10 +1839,10 @@ ItemUseItemfinder: ; e2e1 (3:62e1) jr nc,.printText ; if no hidden items ld c,4 .loop - ld a,(SFX_02_4a - SFX_Headers_02) / 3 - call PlaySoundWaitForCurrent ; play sound - ld a,(SFX_02_5a - SFX_Headers_02) / 3 - call PlaySoundWaitForCurrent ; play sound + ld a,SFX_HEALING_MACHINE + call PlaySoundWaitForCurrent + ld a,SFX_PURCHASE + call PlaySoundWaitForCurrent dec c jr nz,.loop ld hl,ItemfinderFoundItemText @@ -1874,23 +1866,23 @@ ItemUsePPRestore: ; e31e (3:631e) ld a,[wWhichPokemon] push af ld a,[wcf91] - ld [wWhichTrade],a + ld [wPPRestoreItem],a .chooseMon xor a ld [wUpdateSpritesEnabled],a - ld a,$01 ; item use party menu - ld [wd07d],a + ld a,USE_ITEM_PARTY_MENU + ld [wPartyMenuTypeOrMessageID],a call DisplayPartyMenu jr nc,.chooseMove jp .itemNotUsed .chooseMove - ld a,[wWhichTrade] + ld a,[wPPRestoreItem] cp a,ELIXER jp nc,.useElixir ; if Elixir or Max Elixir ld a,$02 ld [wMoveMenuType],a ld hl,RaisePPWhichTechniqueText - ld a,[wWhichTrade] + ld a,[wPPRestoreItem] cp a,ETHER ; is it a PP Up? jr c,.printWhichTechniqueMessage ; if so, print the raise PP message ld hl,RestorePPWhichTechniqueText ; otherwise, print the restore PP message @@ -1903,7 +1895,7 @@ ItemUsePPRestore: ; e31e (3:631e) ld [wPlayerMoveListIndex],a jr nz,.chooseMon ld hl,wPartyMon1Moves - ld bc,44 + ld bc, wPartyMon2 - wPartyMon1 call GetSelectedMoveOffset push hl ld a,[hl] @@ -1911,7 +1903,7 @@ ItemUsePPRestore: ; e31e (3:631e) call GetMoveName call CopyStringToCF4B ; copy name to wcf4b pop hl - ld a,[wWhichTrade] + ld a,[wPPRestoreItem] cp a,ETHER jr nc,.useEther ; if Ether or Max Ether .usePPUp @@ -1936,7 +1928,7 @@ ItemUsePPRestore: ; e31e (3:631e) pop af ld [wWhichPokemon],a call GBPalWhiteOut - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand jp RemoveUsedItem .afterRestoringPP ; after using a (Max) Ether/Elixir ld a,[wWhichPokemon] @@ -1945,13 +1937,13 @@ ItemUsePPRestore: ; e31e (3:631e) cp b ; is the pokemon whose PP was restored active in battle? jr nz,.skipUpdatingInBattleData ld hl,wPartyMon1PP - ld bc,44 + ld bc, wPartyMon2 - wPartyMon1 call AddNTimes ld de,wBattleMonPP ld bc,4 call CopyData ; copy party data to in-battle data .skipUpdatingInBattleData - ld a,(SFX_02_3e - SFX_Headers_02) / 3 + ld a,SFX_HEAL_AILMENT call PlaySound ld hl,PPRestoredText call PrintText @@ -1963,17 +1955,17 @@ ItemUsePPRestore: ; e31e (3:631e) ; unsets zero flag if PP was restored, sets zero flag if not ; however, this is bugged for Max Ethers and Max Elixirs (see below) .restorePP - xor a - ld [wcc49],a ; party pokemon + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation],a call GetMaxPP ld hl,wPartyMon1Moves - ld bc,44 + ld bc, wPartyMon2 - wPartyMon1 call GetSelectedMoveOffset - ld bc,21 + ld bc, wPartyMon1PP - wPartyMon1Moves add hl,bc ; hl now points to move's PP - ld a,[wd11e] - ld b,a ; b = max PP - ld a,[wWhichTrade] + ld a,[wMaxPP] + ld b,a + ld a,[wPPRestoreItem] cp a,MAX_ETHER jr z,.fullyRestorePP ld a,[hl] ; move PP @@ -2005,7 +1997,7 @@ ItemUsePPRestore: ; e31e (3:631e) jr .storeNewAmount .useElixir ; decrement the item ID so that ELIXER becomes ETHER and MAX_ELIXER becomes MAX_ETHER - ld hl,wWhichTrade + ld hl,wPPRestoreItem dec [hl] dec [hl] xor a @@ -2017,7 +2009,7 @@ ItemUsePPRestore: ; e31e (3:631e) .elixirLoop push bc ld hl,wPartyMon1Moves - ld bc,44 + ld bc, wPartyMon2 - wPartyMon1 call GetSelectedMoveOffset ld a,[hl] and a ; does the current slot have a move? @@ -2040,10 +2032,10 @@ ItemUsePPRestore: ; e31e (3:631e) call ItemUseNoEffect .itemNotUsed call GBPalWhiteOut - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand pop af xor a - ld [wcd6a],a ; item use failed + ld [wActionResultOrTookBattleTurn],a ; item use failed ret RaisePPWhichTechniqueText: ; e45d (3:645d) @@ -2095,8 +2087,8 @@ ItemUseTMHM: ; e479 (3:6479) call PrintText ld hl,TeachMachineMoveText call PrintText - hlCoord 14, 7 - ld bc,$080f + coord hl, 14, 7 + lb bc, 8, 15 ld a,TWO_OPTION_MENU ld [wTextBoxID],a call DisplayTextBoxID ; yes/no menu @@ -2104,7 +2096,7 @@ ItemUseTMHM: ; e479 (3:6479) and a jr z,.useMachine ld a,2 - ld [wcd6a],a ; item not used + ld [wActionResultOrTookBattleTurn],a ; item not used ret .useMachine ld a,[wWhichPokemon] @@ -2113,16 +2105,16 @@ ItemUseTMHM: ; e479 (3:6479) push af .chooseMon ld hl,wcf4b - ld de,wd036 + ld de,wTempMoveNameBuffer ld bc,14 - call CopyData + call CopyData ; save the move name because DisplayPartyMenu will overwrite it ld a,$ff ld [wUpdateSpritesEnabled],a - ld a,$03 ; teach TM/HM party menu - ld [wd07d],a + ld a,TMHM_PARTY_MENU + ld [wPartyMenuTypeOrMessageID],a call DisplayPartyMenu push af - ld hl,wd036 + ld hl,wTempMoveNameBuffer ld de,wcf4b ld bc,14 call CopyData @@ -2133,7 +2125,7 @@ ItemUseTMHM: ; e479 (3:6479) pop af call GBPalWhiteOutWithDelay3 call ClearSprites - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand jp LoadScreenTilesFromBuffer1 ; restore saved screen .checkIfAbleToLearnMove predef CanLearnTM ; check if the pokemon can learn the move @@ -2146,8 +2138,8 @@ ItemUseTMHM: ; e479 (3:6479) and a ; can the pokemon learn the move? jr nz,.checkIfAlreadyLearnedMove ; if the pokemon can't learn the move - ld a,(SFX_02_51 - SFX_Headers_02) / 3 - call PlaySoundWaitForCurrent ; play sound + ld a,SFX_DENIED + call PlaySoundWaitForCurrent ld hl,MonCannotLearnMachineMoveText call PrintText jr .chooseMon @@ -2186,14 +2178,14 @@ MonCannotLearnMachineMoveText: ; e55e (3:655e) PrintItemUseTextAndRemoveItem: ; e563 (3:6563) ld hl,ItemUseText00 call PrintText - ld a,(SFX_02_3e - SFX_Headers_02) / 3 - call PlaySound ; play sound + ld a,SFX_HEAL_AILMENT + call PlaySound call WaitForTextScrollButtonPress ; wait for button press RemoveUsedItem: ; e571 (3:6571) ld hl,wNumBagItems ld a,1 ; one item - ld [wcf96],a ; store quantity + ld [wItemQuantity],a jp RemoveItemFromInventory ItemUseNoEffect: ; e57c (3:657c) @@ -2209,7 +2201,7 @@ ItemUseNotYoursToUse: ; e586 (3:6586) jr ItemUseFailed ThrowBallAtTrainerMon: ; e58b (3:658b) - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand call LoadScreenTilesFromBuffer1 ; restore saved screen call Delay3 ld a,TOSS_ANIM @@ -2234,7 +2226,7 @@ SurfingAttemptFailed: ; e5b6 (3:65b6) ItemUseFailed: ; e5b9 (3:65b9) xor a - ld [wcd6a],a ; item use failed + ld [wActionResultOrTookBattleTurn],a ; item use failed jp PrintText ItemUseNotTimeText: ; e5c0 (3:65c0) @@ -2291,23 +2283,20 @@ GotOffBicycleText: ; e5fc (3:65fc) ; also, when a PP Up is used, it increases the current PP by one PP Up bonus ; INPUT: ; [wWhichPokemon] = index of pokemon in party -; [wd11e] = mode -; 0: Pokemon Center healing -; 1: using a PP Up ; [wCurrentMenuItem] = index of move (when using a PP Up) RestoreBonusPP: ; e606 (3:6606) ld hl,wPartyMon1Moves - ld bc,44 + ld bc, wPartyMon2 - wPartyMon1 ld a,[wWhichPokemon] call AddNTimes push hl - ld de,wcd78 - 1 - predef LoadMovePPs ; loads the normal max PP of each of the pokemon's moves to wcd78 + ld de,wNormalMaxPPList - 1 + predef LoadMovePPs ; loads the normal max PP of each of the pokemon's moves to wNormalMaxPPList pop hl - ld c,21 + ld c, wPartyMon1PP - wPartyMon1Moves ld b,0 add hl,bc ; hl now points to move 1 PP - ld de,wcd78 + ld de,wNormalMaxPPList ld b,0 ; initialize move counter to zero ; loop through the pokemon's moves .loop @@ -2315,7 +2304,7 @@ RestoreBonusPP: ; e606 (3:6606) ld a,b cp a,5 ; reached the end of the pokemon's moves? ret z ; if so, return - ld a,[wd11e] + ld a,[wUsingPPUp] dec a ; using a PP Up? jr nz,.skipMenuItemIDCheck ; if using a PP Up, check if this is the move it's being used on @@ -2337,8 +2326,6 @@ RestoreBonusPP: ; e606 (3:6606) ; INPUT: ; [de] = normal max PP ; [hl] = move PP -; [wd11e] = max number of times to add bonus -; set to 1 when using a PP Up, set to 255 otherwise AddBonusPP: ; e642 (3:6642) push bc ld a,[de] ; normal max PP of move @@ -2366,9 +2353,9 @@ AddBonusPP: ; e642 (3:6642) .addAmount add b ld b,a - ld a,[wd11e] - dec a - jr z,.done + ld a,[wUsingPPUp] + dec a ; is the player using a PP Up right now? + jr z,.done ; if so, only add the bonus once dec c jr nz,.loop .done @@ -2379,7 +2366,7 @@ AddBonusPP: ; e642 (3:6642) ; gets max PP of a pokemon's move (including PP from PP Ups) ; INPUT: ; [wWhichPokemon] = index of pokemon within party/box -; [wcc49] = pokemon source +; [wMonDataLocation] = pokemon source ; 00: player's party ; 01: enemy's party ; 02: current box @@ -2387,9 +2374,9 @@ AddBonusPP: ; e642 (3:6642) ; 04: player's in-battle pokemon ; [wCurrentMenuItem] = move index ; OUTPUT: -; [wd11e] = max PP +; [wMaxPP] = max PP GetMaxPP: ; e677 (3:6677) - ld a,[wcc49] + ld a,[wMonDataLocation] and a ld hl,wPartyMon1Moves ld bc,wPartyMon2 - wPartyMon1 @@ -2415,21 +2402,21 @@ GetMaxPP: ; e677 (3:6677) dec a push hl ld hl,Moves - ld bc,6 + ld bc,MoveEnd - Moves call AddNTimes ld de,wcd6d ld a,BANK(Moves) call FarCopyData - ld de,wcd72 + ld de,wcd6d + 5 ; PP is byte 5 of move data ld a,[de] ld b,a ; b = normal max PP pop hl push bc - ld bc,21 ; PP offset if not player's in-battle pokemon data - ld a,[wcc49] + ld bc,wPartyMon1PP - wPartyMon1Moves ; PP offset if not player's in-battle pokemon data + ld a,[wMonDataLocation] cp a,4 ; player's in-battle pokemon? jr nz,.addPPOffset - ld bc,17 ; PP offset if player's in-battle pokemon data + ld bc,wBattleMonPP - wBattleMonMoves ; PP offset if player's in-battle pokemon data .addPPOffset add hl,bc ld a,[hl] ; a = current PP @@ -2440,12 +2427,12 @@ GetMaxPP: ; e677 (3:6677) ld l,e inc hl ; hl = wcd73 ld [hl],a - xor a - ld [wd11e],a ; no limit on PP Up amount + xor a ; add the bonus for the existing PP Up count + ld [wUsingPPUp],a call AddBonusPP ; add bonus PP from PP Ups ld a,[hl] and a,%00111111 ; mask out the PP Up count - ld [wd11e],a ; store max PP + ld [wMaxPP],a ; store max PP ret GetSelectedMoveOffset: ; e6e3 (3:66e3) @@ -2464,7 +2451,7 @@ GetSelectedMoveOffset2: ; e6e9 (3:66e9) ; hl = address of inventory (either wNumBagItems or wNumBoxItems) ; [wcf91] = item ID ; [wWhichPokemon] = index of item within inventory -; [wcf96] = quantity to toss +; [wItemQuantity] = quantity to toss ; OUTPUT: ; clears carry flag if the item is tossed, sets carry flag if not TossItem_: ; e6f1 (3:66f1) @@ -2475,7 +2462,7 @@ TossItem_: ; e6f1 (3:66f1) jr c,.tooImportantToToss push hl call IsKeyItem_ - ld a,[wd124] + ld a,[wIsKeyItem] pop hl and a jr nz,.tooImportantToToss @@ -2486,16 +2473,16 @@ TossItem_: ; e6f1 (3:66f1) call CopyStringToCF4B ; copy name to wcf4b ld hl,IsItOKToTossItemText call PrintText - hlCoord 14, 7 - ld bc,$080f + coord hl, 14, 7 + lb bc, 8, 15 ld a,TWO_OPTION_MENU ld [wTextBoxID],a call DisplayTextBoxID ; yes/no menu - ld a,[wd12e] - cp a,2 + ld a,[wMenuExitMethod] + cp a,CHOSE_SECOND_ITEM pop hl scf - ret z + ret z ; return if the player chose No ; if the player chose Yes push hl ld a,[wWhichPokemon] @@ -2533,27 +2520,27 @@ TooImportantToTossText: ; e75f (3:675f) ; INPUT: ; [wcf91] = item ID ; OUTPUT: -; [wd124] = result +; [wIsKeyItem] = result ; 00: item is not key item ; 01: item is key item IsKeyItem_: ; e764 (3:6764) ld a,$01 - ld [wd124],a + ld [wIsKeyItem],a ld a,[wcf91] cp a,HM_01 ; is the item an HM or TM? jr nc,.checkIfItemIsHM ; if the item is not an HM or TM push af ld hl,KeyItemBitfield - ld de,wHPBarMaxHP + ld de,wBuffer ld bc,15 ; only 11 bytes are actually used call CopyData pop af dec a ld c,a - ld hl,wHPBarMaxHP - ld b,$02 ; test bit - predef FlagActionPredef ; bitfield operation function + ld hl,wBuffer + ld b,FLAG_TEST + predef FlagActionPredef ld a,c and a ret nz @@ -2562,13 +2549,13 @@ IsKeyItem_: ; e764 (3:6764) call IsItemHM ret c xor a - ld [wd124],a + ld [wIsKeyItem],a ret INCLUDE "data/key_items.asm" SendNewMonToBox: ; e7a4 (3:67a4) - ld de, W_NUMINBOX ; wda80 + ld de, W_NUMINBOX ld a, [de] inc a ld [de], a @@ -2586,74 +2573,74 @@ SendNewMonToBox: ; e7a4 (3:67a4) jr nz, .asm_e7b1 call GetMonHeader ld hl, wBoxMonOT - ld bc, $b - ld a, [W_NUMINBOX] ; wda80 + ld bc, NAME_LENGTH + ld a, [W_NUMINBOX] dec a jr z, .asm_e7ee dec a call AddNTimes push hl - ld bc, $b + ld bc, NAME_LENGTH add hl, bc ld d, h ld e, l pop hl - ld a, [W_NUMINBOX] ; wda80 + ld a, [W_NUMINBOX] dec a ld b, a .asm_e7db push bc push hl - ld bc, $b + ld bc, NAME_LENGTH call CopyData pop hl ld d, h ld e, l - ld bc, $fff5 + ld bc, -NAME_LENGTH add hl, bc pop bc dec b jr nz, .asm_e7db .asm_e7ee - ld hl, wPlayerName ; wd158 + ld hl, wPlayerName ld de, wBoxMonOT - ld bc, $b + ld bc, NAME_LENGTH call CopyData - ld a, [W_NUMINBOX] ; wda80 + ld a, [W_NUMINBOX] dec a jr z, .asm_e82a ld hl, wBoxMonNicks - ld bc, $b + ld bc, NAME_LENGTH dec a call AddNTimes push hl - ld bc, $b + ld bc, NAME_LENGTH add hl, bc ld d, h ld e, l pop hl - ld a, [W_NUMINBOX] ; wda80 + ld a, [W_NUMINBOX] dec a ld b, a .asm_e817 push bc push hl - ld bc, $b + ld bc, NAME_LENGTH call CopyData pop hl ld d, h ld e, l - ld bc, $fff5 + ld bc, -NAME_LENGTH add hl, bc pop bc dec b jr nz, .asm_e817 .asm_e82a ld hl, wBoxMonNicks - ld a, $2 - ld [wd07d], a + ld a, NAME_MON_SCREEN + ld [wNamingScreenType], a predef AskName - ld a, [W_NUMINBOX] ; wda80 + ld a, [W_NUMINBOX] dec a jr z, .asm_e867 ld hl, wBoxMons @@ -2666,7 +2653,7 @@ SendNewMonToBox: ; e7a4 (3:67a4) ld d, h ld e, l pop hl - ld a, [W_NUMINBOX] ; wda80 + ld a, [W_NUMINBOX] dec a ld b, a .asm_e854 @@ -2677,19 +2664,19 @@ SendNewMonToBox: ; e7a4 (3:67a4) pop hl ld d, h ld e, l - ld bc, $ffdf + ld bc, wBoxMon1 - wBoxMon2 add hl, bc pop bc dec b jr nz, .asm_e854 .asm_e867 - ld a, [wEnemyMonLevel] ; wEnemyMonLevel + ld a, [wEnemyMonLevel] ld [wEnemyMonBoxLevel], a ld hl, wEnemyMon ld de, wBoxMon1 - ld bc, $c + ld bc, wEnemyMonDVs - wEnemyMon call CopyData - ld hl, wPlayerID ; wPlayerID + ld hl, wPlayerID ld a, [hli] ld [de], a inc de @@ -2697,21 +2684,21 @@ SendNewMonToBox: ; e7a4 (3:67a4) ld [de], a inc de push de - ld a, [W_CURENEMYLVL] ; W_CURENEMYLVL + ld a, [W_CURENEMYLVL] ld d, a callab CalcExperience pop de - ld a, [H_NUMTOPRINT] ; $ff96 (aliases: H_MULTIPLICAND) + ld a, [hExperience] ld [de], a inc de - ld a, [$ff97] + ld a, [hExperience + 1] ld [de], a inc de - ld a, [$ff98] + ld a, [hExperience + 2] ld [de], a inc de xor a - ld b, $a + ld b, NUM_STATS * 2 .asm_e89f ld [de], a inc de @@ -2723,8 +2710,8 @@ SendNewMonToBox: ; e7a4 (3:67a4) inc de ld a, [hli] ld [de], a - ld hl, wEnemyMonPP ; wcffe - ld b, $4 + ld hl, wEnemyMonPP + ld b, NUM_MOVES .asm_e8b1 ld a, [hli] inc de @@ -2781,7 +2768,7 @@ ReadSuperRodData: ; e8ea (3:68ea) ld e, $2 ; $2 if no fishing groups found ret -.ReadFishingGroup ; 0xe8f6 +.ReadFishingGroup ; hl points to the fishing group entry in the index inc hl ; skip map id @@ -2794,7 +2781,7 @@ ReadSuperRodData: ; e8ea (3:68ea) inc hl ; point to data ld e, $0 ; no bite yet -.RandomLoop ; 0xe90c +.RandomLoop call Random srl a ret c ; 50% chance of no battle diff --git a/engine/items/tm_prices.asm b/engine/items/tm_prices.asm index ccc5fc5a..a3a8c608 100755 --- a/engine/items/tm_prices.asm +++ b/engine/items/tm_prices.asm @@ -1,12 +1,11 @@ GetMachinePrice: ; f65d4 (3d:65d4) ; Input: [wcf91] = Item Id of a TM -; Output: Stores the 2-byte TM price in [H_DOWNARROWBLINKCNT1] and [H_DOWNARROWBLINKCNT2] -; as a BCD +; Output: Stores the TM price at hItemPrice ld a, [wcf91] ; a contains TM item id sub TM_01 ret c ld d, a - ld hl, TechnicalMachinePrices ; $7fa7 + ld hl, TechnicalMachinePrices srl a ld c, a ld b, 0 @@ -17,10 +16,10 @@ GetMachinePrice: ; f65d4 (3d:65d4) swap a .highNybbleIsPrice and $f0 - ld [H_DOWNARROWBLINKCNT2], a ; $ff8c + ld [hItemPrice + 1], a xor a - ld [H_DOWNARROWBLINKCNT1], a ; $ff8b - ld [$ff8d], a + ld [hItemPrice], a + ld [hItemPrice + 2], a ret INCLUDE "data/tm_prices.asm" diff --git a/engine/items/tms.asm b/engine/items/tms.asm index 511aab5b..23912b34 100755 --- a/engine/items/tms.asm +++ b/engine/items/tms.asm @@ -17,7 +17,7 @@ CanLearnTM: ; 1373e (4:773e) jr .findTMloop .TMfoundLoop pop hl - ld b, $2 ; read corresponding bit from TM compatibility array + ld b, FLAG_TEST predef_jump FlagActionPredef ; converts TM/HM number in wd11e into move number diff --git a/engine/learn_move.asm b/engine/learn_move.asm index 75056edb..c0ced4a0 100755 --- a/engine/learn_move.asm +++ b/engine/learn_move.asm @@ -4,25 +4,25 @@ LearnMove: ; 6e43 (1:6e43) ld hl, wPartyMonNicks call GetPartyMonName ld hl, wcd6d - ld de, wd036 - ld bc, $b + ld de, wLearnMoveMonName + ld bc, NAME_LENGTH call CopyData DontAbandonLearning: ; 6e5b (1:6e5b) ld hl, wPartyMon1Moves - ld bc, $2c + ld bc, wPartyMon2Moves - wPartyMon1Moves ld a, [wWhichPokemon] call AddNTimes ld d, h ld e, l - ld b, $4 -.asm_6e6b + ld b, NUM_MOVES +.findEmptyMoveSlotLoop ld a, [hl] and a - jr z, .asm_6e8b + jr z, .next inc hl dec b - jr nz, .asm_6e6b + jr nz, .findEmptyMoveSlotLoop push de call TryingToLearn pop de @@ -35,21 +35,21 @@ DontAbandonLearning: ; 6e5b (1:6e5b) call PrintText pop de pop hl -.asm_6e8b +.next ld a, [wMoveNum] ld [hl], a - ld bc, $15 + ld bc, wPartyMon1PP - wPartyMon1Moves add hl, bc push hl push de dec a ld hl, Moves - ld bc, $6 + ld bc, MoveEnd - Moves call AddNTimes - ld de, wHPBarMaxHP + ld de, wBuffer ld a, BANK(Moves) call FarCopyData - ld a, [wHPBarNewHP + 1] + ld a, [wBuffer + 5] ; a = move's max PP pop de pop hl ld [hl], a @@ -66,18 +66,18 @@ DontAbandonLearning: ; 6e5b (1:6e5b) ld de, wBattleMonMoves ld bc, NUM_MOVES call CopyData - ld bc, $11 + ld bc, wPartyMon1PP - wPartyMon1OTID add hl, bc ld de, wBattleMonPP - ld bc, $4 + ld bc, NUM_MOVES call CopyData jp PrintLearnedMove AbandonLearning: ; 6eda (1:6eda) ld hl, AbandonLearningText call PrintText - hlCoord 14, 7 - ld bc, $80f + coord hl, 14, 7 + lb bc, 8, 15 ld a, TWO_OPTION_MENU ld [wTextBoxID], a call DisplayTextBoxID ; yes/no menu @@ -86,21 +86,21 @@ AbandonLearning: ; 6eda (1:6eda) jp nz, DontAbandonLearning ld hl, DidNotLearnText call PrintText - ld b, $0 + ld b, 0 ret PrintLearnedMove: ; 6efe (1:6efe) ld hl, LearnedMove1Text call PrintText - ld b, $1 + ld b, 1 ret TryingToLearn: ; 6f07 (1:6f07) push hl ld hl, TryingToLearnText call PrintText - hlCoord 14, 7 - ld bc, $80f + coord hl, 14, 7 + lb bc, 8, 15 ld a, TWO_OPTION_MENU ld [wTextBoxID], a call DisplayTextBoxID ; yes/no menu @@ -108,7 +108,7 @@ TryingToLearn: ; 6f07 (1:6f07) ld a, [wCurrentMenuItem] rra ret c - ld bc, $fffc + ld bc, -NUM_MOVES add hl, bc push hl ld de, wMoves @@ -116,15 +116,15 @@ TryingToLearn: ; 6f07 (1:6f07) call CopyData callab FormatMovesString pop hl -.asm_6f39 +.loop push hl ld hl, WhichMoveToForgetText call PrintText - hlCoord 4, 7 - ld b, $4 - ld c, $e + coord hl, 4, 7 + ld b, 4 + ld c, 14 call TextBoxBorder - hlCoord 6, 8 + coord hl, 6, 8 ld de, wMovesString ld a, [hFlags_0xFFF6] set 2, a @@ -134,18 +134,18 @@ TryingToLearn: ; 6f07 (1:6f07) res 2, a ld [hFlags_0xFFF6], a ld hl, wTopMenuItemY - ld a, $8 - ld [hli], a - ld a, $5 - ld [hli], a + ld a, 8 + ld [hli], a ; wTopMenuItemY + ld a, 5 + ld [hli], a ; wTopMenuItemX xor a - ld [hli], a + ld [hli], a ; wCurrentMenuItem inc hl - ld a, [wcd6c] - ld [hli], a - ld a, $3 - ld [hli], a - ld [hl], $0 + ld a, [wNumMovesMinusOne] + ld [hli], a ; wMaxMenuItem + ld a, A_BUTTON | B_BUTTON + ld [hli], a ; wMenuWatchedKeys + ld [hl], 0 ; wLastMenuItem ld hl, hFlags_0xFFF6 set 1, [hl] call HandleMenuInput @@ -155,12 +155,12 @@ TryingToLearn: ; 6f07 (1:6f07) call LoadScreenTilesFromBuffer1 pop af pop hl - bit 1, a - jr nz, .asm_6fab + bit 1, a ; pressed b + jr nz, .cancel push hl ld a, [wCurrentMenuItem] ld c, a - ld b, $0 + ld b, 0 add hl, bc ld a, [hl] push af @@ -169,17 +169,17 @@ TryingToLearn: ; 6f07 (1:6f07) pop bc pop de ld a, d - jr c, .asm_6fa2 + jr c, .hm pop hl add hl, bc and a ret -.asm_6fa2 +.hm ld hl, HMCantDeleteText call PrintText pop hl - jr .asm_6f39 -.asm_6fab + jr .loop +.cancel scf ret @@ -206,8 +206,8 @@ TryingToLearnText: ; 6fc3 (1:6fc3) OneTwoAndText: ; 6fc8 (1:6fc8) TX_FAR _OneTwoAndText db $a - db $8 - ld a, (SFX_02_58 - SFX_Headers_02) / 3 + TX_ASM + ld a, SFX_SWAP call PlaySoundWaitForCurrent ld hl, PoofText ret diff --git a/engine/load_pokedex_tiles.asm b/engine/load_pokedex_tiles.asm index e8205ef8..1189d2f0 100755 --- a/engine/load_pokedex_tiles.asm +++ b/engine/load_pokedex_tiles.asm @@ -1,11 +1,11 @@ ; Loads tile patterns for tiles used in the pokedex. LoadPokedexTilePatterns: ; 17840 (5:7840) call LoadHpBarAndStatusTilePatterns - ld de,PokedexTileGraphics ; $6488 + ld de,PokedexTileGraphics ld hl,vChars2 + $600 - ld bc,(BANK(PokedexTileGraphics) << 8) + $12 + lb bc, BANK(PokedexTileGraphics), (PokedexTileGraphicsEnd - PokedexTileGraphics) / $10 call CopyVideoData - ld de,PokeballTileGraphics ; $697e + ld de,PokeballTileGraphics ld hl,vChars2 + $720 - ld bc,(BANK(PokeballTileGraphics) << 8) + $01 + lb bc, BANK(PokeballTileGraphics), $01 jp CopyVideoData ; load pokeball tile for marking caught mons diff --git a/engine/menu/bills_pc.asm b/engine/menu/bills_pc.asm index 70b5bc33..87595a09 100644 --- a/engine/menu/bills_pc.asm +++ b/engine/menu/bills_pc.asm @@ -1,90 +1,87 @@ -Func_213c8:: ; 213c8 (8:53c8) +DisplayPCMainMenu:: ; 213c8 (8:53c8) xor a ld [H_AUTOBGTRANSFERENABLED], a call SaveScreenTilesToBuffer2 - ld a, [wd5a2] + ld a, [wNumHoFTeams] and a - jr nz, .asm_213f3 - ld a, [wd74b] - bit 5, a - jr z, .asm_213ea - ld a, [wd5a2] + jr nz, .leaguePCAvailable + CheckEvent EVENT_GOT_POKEDEX + jr z, .noOaksPC + ld a, [wNumHoFTeams] and a - jr nz, .asm_213f3 - ld hl, wTileMap - ld b, $8 - ld c, $e - jr .asm_213fa -.asm_213ea - ld hl, wTileMap - ld b, $6 - ld c, $e - jr .asm_213fa -.asm_213f3 - ld hl, wTileMap - ld b, $a - ld c, $e -.asm_213fa + jr nz, .leaguePCAvailable + coord hl, 0, 0 + ld b, 8 + ld c, 14 + jr .next +.noOaksPC + coord hl, 0, 0 + ld b, 6 + ld c, 14 + jr .next +.leaguePCAvailable + coord hl, 0, 0 + ld b, 10 + ld c, 14 +.next call TextBoxBorder call UpdateSprites - ld a, $3 + ld a, 3 ld [wMaxMenuItem], a - ld a, [wd7f1] - bit 0, a - jr nz, .asm_21414 - hlCoord 2, 2 + CheckEvent EVENT_MET_BILL + jr nz, .metBill + coord hl, 2, 2 ld de, SomeonesPCText - jr .asm_2141a -.asm_21414 - hlCoord 2, 2 + jr .next2 +.metBill + coord hl, 2, 2 ld de, BillsPCText -.asm_2141a +.next2 call PlaceString - hlCoord 2, 4 + coord hl, 2, 4 ld de, wPlayerName call PlaceString ld l, c ld h, b ld de, PlayersPCText call PlaceString - ld a, [wd74b] - bit 5, a - jr z, .asm_21462 - hlCoord 2, 6 + CheckEvent EVENT_GOT_POKEDEX + jr z, .noOaksPC2 + coord hl, 2, 6 ld de, OaksPCText call PlaceString - ld a, [wd5a2] + ld a, [wNumHoFTeams] and a - jr z, .asm_2145a - ld a, $4 + jr z, .noLeaguePC + ld a, 4 ld [wMaxMenuItem], a - hlCoord 2, 8 + coord hl, 2, 8 ld de, PKMNLeaguePCText call PlaceString - hlCoord 2, 10 + coord hl, 2, 10 ld de, LogOffPCText - jr .asm_2146d -.asm_2145a - hlCoord 2, 8 + jr .next3 +.noLeaguePC + coord hl, 2, 8 ld de, LogOffPCText - jr .asm_2146d -.asm_21462 + jr .next3 +.noOaksPC2 ld a, $2 ld [wMaxMenuItem], a - hlCoord 2, 6 + coord hl, 2, 6 ld de, LogOffPCText -.asm_2146d +.next3 call PlaceString - ld a, $3 + ld a, A_BUTTON | B_BUTTON ld [wMenuWatchedKeys], a - ld a, $2 + ld a, 2 ld [wTopMenuItemY], a - ld a, $1 + ld a, 1 ld [wTopMenuItemX], a xor a ld [wCurrentMenuItem], a ld [wLastMenuItem], a - ld a, $1 + ld a, 1 ld [H_AUTOBGTRANSFERENABLED], a ret @@ -99,103 +96,105 @@ BillsPC_:: ; 0x214c2 ld hl, wd730 set 6, [hl] xor a - ld [wccd3], a + ld [wParentMenuItem], a inc a ; MONSTER_NAME ld [wNameListType], a call LoadHpBarAndStatusTilePatterns ld a, [wListScrollOffset] push af ld a, [wFlags_0xcd60] - bit 3, a + bit 3, a ; accessing Bill's PC through another PC? jr nz, BillsPCMenu +; accessing it directly ld a, $99 call PlaySound ld hl, SwitchOnText call PrintText -Func_214e8: ; 214e8 (8:54e8) -BillsPCMenu: - ld a, [wccd3] +BillsPCMenu: ; 214e8 (8:54e8) + ld a, [wParentMenuItem] ld [wCurrentMenuItem], a ld hl, vChars2 + $780 ld de, PokeballTileGraphics - ld bc, (BANK(PokeballTileGraphics) << 8) + $01 + lb bc, BANK(PokeballTileGraphics), $01 call CopyVideoData call LoadScreenTilesFromBuffer2DisableBGTransfer - ld hl, wTileMap - ld b, $a - ld c, $c + coord hl, 0, 0 + ld b, 10 + ld c, 12 call TextBoxBorder - hlCoord 2, 2 + coord hl, 2, 2 ld de, BillsPCMenuText call PlaceString ld hl, wTopMenuItemY - ld a, $2 - ld [hli], a + ld a, 2 + ld [hli], a ; wTopMenuItemY dec a - ld [hli], a + ld [hli], a ; wTopMenuItemX inc hl inc hl - ld a, $4 - ld [hli], a - ld a, $3 - ld [hli], a + ld a, 4 + ld [hli], a ; wMaxMenuItem + ld a, A_BUTTON | B_BUTTON + ld [hli], a ; wMenuWatchedKeys xor a - ld [hli], a - ld [hli], a + ld [hli], a ; wLastMenuItem + ld [hli], a ; wPartyAndBillsPCSavedMenuItem ld hl, wListScrollOffset - ld [hli], a - ld [hl], a + ld [hli], a ; wListScrollOffset + ld [hl], a ; wMenuWatchMovingOutOfBounds ld [wPlayerMonNumber], a ld hl, WhatText call PrintText - hlCoord 9, 14 - ld b, $2 - ld c, $9 + coord hl, 9, 14 + ld b, 2 + ld c, 9 call TextBoxBorder - ld a, [wd5a0] + ld a, [wCurrentBoxNum] and $7f cp 9 - jr c, .asm_2154f + jr c, .singleDigitBoxNum +; two digit box num sub 9 - hlCoord 17, 16 + coord hl, 17, 16 ld [hl], "1" add "0" - jr .asm_21551 -.asm_2154f + jr .next +.singleDigitBoxNum add "1" -.asm_21551 +.next Coorda 18, 16 - hlCoord 10, 16 + coord hl, 10, 16 ld de, BoxNoPCText call PlaceString - ld a, $1 + ld a, 1 ld [H_AUTOBGTRANSFERENABLED], a call Delay3 call HandleMenuInput bit 1, a - jp nz, Func_21588 ; b button + jp nz, ExitBillsPC ; b button call PlaceUnfilledArrowMenuCursor ld a, [wCurrentMenuItem] - ld [wccd3], a + ld [wParentMenuItem], a and a - jp z, Func_21618 ; withdraw + jp z, BillsPCWithdraw ; withdraw cp $1 - jp z, Func_215ac ; deposit + jp z, BillsPCDeposit ; deposit cp $2 - jp z, Func_21673 ; release + jp z, BillsPCRelease ; release cp $3 - jp z, Func_216b3 ; change box + jp z, BillsPCChangeBox ; change box -Func_21588: ; 21588 (8:5588) +ExitBillsPC: ; 21588 (8:5588) ld a, [wFlags_0xcd60] - bit 3, a - jr nz, .asm_2159a + bit 3, a ; accessing Bill's PC through another PC? + jr nz, .next +; accessing it directly call LoadTextBoxTilePatterns ld a, $9a call PlaySound call WaitForSoundToFinish -.asm_2159a +.next ld hl, wFlags_0xcd60 res 5, [hl] call LoadScreenTilesFromBuffer2 @@ -205,139 +204,138 @@ Func_21588: ; 21588 (8:5588) res 6, [hl] ret -Func_215ac: ; 215ac (8:55ac) -BillsPCDeposit: +BillsPCDeposit: ; 215ac (8:55ac) ld a, [wPartyCount] dec a - jr nz, .asm_215bb + jr nz, .partyLargeEnough ld hl, CantDepositLastMonText call PrintText jp BillsPCMenu -.asm_215bb +.partyLargeEnough ld a, [W_NUMINBOX] cp MONS_PER_BOX - jr nz, .asm_215cb + jr nz, .boxNotFull ld hl, BoxFullText call PrintText jp BillsPCMenu -.asm_215cb +.boxNotFull ld hl, wPartyCount - call Func_216be + call DisplayMonListMenu jp c, BillsPCMenu - call Func_2174b + call DisplayDepositWithdrawMenu jp nc, BillsPCMenu ld a, [wcf91] call GetCryData call PlaySoundWaitForCurrent - ld a, $1 - ld [wcf95], a - call Func_3a68 + ld a, PARTY_TO_BOX + ld [wMoveMonType], a + call MoveMon xor a - ld [wcf95], a + ld [wRemoveMonFromBox], a call RemovePokemon call WaitForSoundToFinish - ld hl, wWhichTrade - ld a, [wd5a0] + ld hl, wBoxNumString + ld a, [wCurrentBoxNum] and $7f cp 9 - jr c, .asm_2160a + jr c, .singleDigitBoxNum sub 9 ld [hl], "1" inc hl add "0" - jr .asm_2160c -.asm_2160a + jr .next +.singleDigitBoxNum add "1" -.asm_2160c +.next ld [hli], a ld [hl], $50 ld hl, MonWasStoredText call PrintText jp BillsPCMenu -Func_21618: ; 21618 (8:5618) +BillsPCWithdraw: ; 21618 (8:5618) ld a, [W_NUMINBOX] and a - jr nz, .asm_21627 + jr nz, .boxNotEmpty ld hl, NoMonText call PrintText - jp Func_214e8 -.asm_21627 + jp BillsPCMenu +.boxNotEmpty ld a, [wPartyCount] cp PARTY_LENGTH - jr nz, .asm_21637 + jr nz, .partyNotFull ld hl, CantTakeMonText call PrintText - jp Func_214e8 -.asm_21637 + jp BillsPCMenu +.partyNotFull ld hl, W_NUMINBOX - call Func_216be - jp c, Func_214e8 - call Func_2174b - jp nc, Func_214e8 + call DisplayMonListMenu + jp c, BillsPCMenu + call DisplayDepositWithdrawMenu + jp nc, BillsPCMenu ld a, [wWhichPokemon] ld hl, wBoxMonNicks call GetPartyMonName ld a, [wcf91] call GetCryData call PlaySoundWaitForCurrent - xor a - ld [wcf95], a - call Func_3a68 - ld a, $1 - ld [wcf95], a + xor a ; BOX_TO_PARTY + ld [wMoveMonType], a + call MoveMon + ld a, 1 + ld [wRemoveMonFromBox], a call RemovePokemon call WaitForSoundToFinish ld hl, MonIsTakenOutText call PrintText - jp Func_214e8 + jp BillsPCMenu -Func_21673: ; 21673 (8:5673) +BillsPCRelease: ; 21673 (8:5673) ld a, [W_NUMINBOX] and a - jr nz, .asm_21682 + jr nz, .loop ld hl, NoMonText call PrintText - jp Func_214e8 -.asm_21682 + jp BillsPCMenu +.loop ld hl, W_NUMINBOX - call Func_216be - jp c, Func_214e8 + call DisplayMonListMenu + jp c, BillsPCMenu ld hl, OnceReleasedText call PrintText call YesNoChoice ld a, [wCurrentMenuItem] and a - jr nz, .asm_21682 + jr nz, .loop inc a - ld [wcf95], a + ld [wRemoveMonFromBox], a call RemovePokemon call WaitForSoundToFinish ld a, [wcf91] call PlayCry ld hl, MonWasReleasedText call PrintText - jp Func_214e8 + jp BillsPCMenu -Func_216b3: ; 216b3 (8:56b3) +BillsPCChangeBox: ; 216b3 (8:56b3) callba ChangeBox - jp Func_214e8 + jp BillsPCMenu -Func_216be: ; 216be (8:56be) +DisplayMonListMenu: ; 216be (8:56be) ld a, l - ld [wList], a + ld [wListPointer], a ld a, h - ld [wList + 1], a + ld [wListPointer + 1], a xor a - ld [wcf93], a + ld [wPrintItemPrices], a ld [wListMenuID], a inc a ; MONSTER_NAME ld [wNameListType], a - ld a, [wcc2b] + ld a, [wPartyAndBillsPCSavedMenuItem] ld [wCurrentMenuItem], a call DisplayListMenuID ld a, [wCurrentMenuItem] - ld [wcc2b], a + ld [wPartyAndBillsPCSavedMenuItem], a ret BillsPCMenuText: ; 216e1 (8:56e1) @@ -352,17 +350,19 @@ BillsPCMenuText: ; 216e1 (8:56e1) BoxNoPCText: ; 21713 (8:5713) db "BOX No.@" -Func_2171b:: ; 2171b (8:571b) +KnowsHMMove:: ; 2171b (8:571b) +; returns whether mon with party index [wWhichPokemon] knows an HM move ld hl, wPartyMon1Moves ld bc, wPartyMon2 - wPartyMon1 - jr .asm_21729 ; 0x21721 $6 + jr .next +; unreachable ld hl, wBoxMon1Moves ld bc, wBoxMon2 - wBoxMon1 -.asm_21729 +.next ld a, [wWhichPokemon] call AddNTimes ld b, NUM_MOVES -.asm_21731 +.loop ld a, [hli] push hl push bc @@ -373,7 +373,7 @@ Func_2171b:: ; 2171b (8:571b) pop hl ret c dec b - jr nz, .asm_21731 ; 0x21741 $ee + jr nz, .loop and a ret @@ -385,72 +385,72 @@ HMMoveArray: ; 21745 (8:5745) db FLASH db -1 -Func_2174b: ; 2174b (8:574b) - hlCoord 9, 10 - ld b, $6 - ld c, $9 +DisplayDepositWithdrawMenu: ; 2174b (8:574b) + coord hl, 9, 10 + ld b, 6 + ld c, 9 call TextBoxBorder - ld a, [wccd3] - and a + ld a, [wParentMenuItem] + and a ; was the Deposit or Withdraw item selected in the parent menu? ld de, DepositPCText - jr nz, .asm_21761 + jr nz, .next ld de, WithdrawPCText -.asm_21761 - hlCoord 11, 12 +.next + coord hl, 11, 12 call PlaceString - hlCoord 11, 14 + coord hl, 11, 14 ld de, StatsCancelPCText call PlaceString ld hl, wTopMenuItemY - ld a, $c - ld [hli], a - ld a, $a - ld [hli], a + ld a, 12 + ld [hli], a ; wTopMenuItemY + ld a, 10 + ld [hli], a ; wTopMenuItemX xor a - ld [hli], a + ld [hli], a ; wCurrentMenuItem inc hl - ld a, $2 - ld [hli], a - ld a, $3 - ld [hli], a + ld a, 2 + ld [hli], a ; wMaxMenuItem + ld a, A_BUTTON | B_BUTTON + ld [hli], a ; wMenuWatchedKeys xor a - ld [hl], a + ld [hl], a ; wLastMenuItem ld hl, wListScrollOffset - ld [hli], a - ld [hl], a + ld [hli], a ; wListScrollOffset + ld [hl], a ; wMenuWatchMovingOutOfBounds ld [wPlayerMonNumber], a - ld [wcc2b], a -.asm_2178f + ld [wPartyAndBillsPCSavedMenuItem], a +.loop call HandleMenuInput - bit 1, a - jr nz, .asm_2179f + bit 1, a ; pressed B? + jr nz, .exit ld a, [wCurrentMenuItem] and a - jr z, .asm_217a1 + jr z, .choseDepositWithdraw dec a - jr z, .asm_217a3 -.asm_2179f + jr z, .viewStats +.exit and a ret -.asm_217a1 +.choseDepositWithdraw scf ret -.asm_217a3 +.viewStats call SaveScreenTilesToBuffer1 - ld a, [wccd3] + ld a, [wParentMenuItem] and a - ld a, $0 - jr nz, .asm_217b0 - ld a, $2 -.asm_217b0 - ld [wcc49], a + ld a, PLAYER_PARTY_DATA + jr nz, .next2 + ld a, BOX_DATA +.next2 + ld [wMonDataLocation], a predef StatusScreen predef StatusScreen2 call LoadScreenTilesFromBuffer1 call ReloadTilesetTilePatterns - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand call LoadGBPal - jr .asm_2178f + jr .loop DepositPCText: db "DEPOSIT@" WithdrawPCText: db "WITHDRAW@" @@ -514,15 +514,14 @@ CableClubLeftGameboy:: ; 5824 (8:5825) cp SPRITE_FACING_RIGHT ret nz ld a, [W_CURMAP] - cp BATTLE_CENTER + cp TRADE_CENTER ld a, LINK_STATE_START_TRADE - jr z, .asm_2183a + jr z, .next inc a ; LINK_STATE_START_BATTLE -.asm_2183a +.next ld [wLinkState], a call EnableAutoTextBoxDrawing - ld a, $22 ; JustAMomentText - jp PrintPredefTextID + tx_pre_jump JustAMomentText CableClubRightGameboy:: ; 5845 (8:5845) ld a, [hSerialConnectionStatus] @@ -532,15 +531,14 @@ CableClubRightGameboy:: ; 5845 (8:5845) cp SPRITE_FACING_LEFT ret nz ld a, [W_CURMAP] - cp BATTLE_CENTER + cp TRADE_CENTER ld a, LINK_STATE_START_TRADE - jr z, .asm_2185a + jr z, .next inc a ; LINK_STATE_START_BATTLE -.asm_2185a +.next ld [wLinkState], a call EnableAutoTextBoxDrawing - ld a, $22 ; JustAMomentText - jp PrintPredefTextID + tx_pre_jump JustAMomentText JustAMomentText:: ; 21865 (8:5865) TX_FAR _JustAMomentText @@ -550,9 +548,8 @@ JustAMomentText:: ; 21865 (8:5865) cp SPRITE_FACING_UP ret nz call EnableAutoTextBoxDrawing - ld a, $23 - jp PrintPredefTextID + tx_pre_jump OpenBillsPCText -PredefText23:: ; 21878 (8:5878) +OpenBillsPCText:: ; 21878 (8:5878) db $FD ; FuncTX_BillsPC diff --git a/engine/menu/diploma.asm b/engine/menu/diploma.asm index 1624ed70..630c6c23 100755 --- a/engine/menu/diploma.asm +++ b/engine/menu/diploma.asm @@ -7,15 +7,15 @@ DisplayDiploma: ; 566e2 (15:66e2) ld hl, wd730 set 6, [hl] call DisableLCD - ld hl, CircleTile ; $7d88 + ld hl, CircleTile ld de, vChars2 + $700 ld bc, $0010 ld a, BANK(CircleTile) call FarCopyData2 - ld hl, wTileMap - ld bc, $1012 + coord hl, 0, 0 + lb bc, 16, 18 predef Diploma_TextBoxBorder - ld hl, DiplomaTextPointersAndCoords ; $6784 + ld hl, DiplomaTextPointersAndCoords ld c, $5 .asm_56715 push bc @@ -32,31 +32,35 @@ DisplayDiploma: ; 566e2 (15:66e2) inc hl pop bc dec c - jr nz, .asm_56715 ; 0x56725 $ee - hlCoord 10, 4 + jr nz, .asm_56715 + coord hl, 10, 4 ld de, wPlayerName call PlaceString - callba Func_44dd + callba DrawPlayerCharacter + +; Move the player 33 pixels right and set the priority bit so he appears +; behind the background layer. ld hl, wOAMBuffer + $01 - ld bc, $8028 -.asm_5673e - ld a, [hl] - add $21 + lb bc, $80, $28 +.adjustPlayerGfxLoop + ld a, [hl] ; X + add 33 ld [hli], a inc hl ld a, b - ld [hli], a + ld [hli], a ; attributes inc hl dec c - jr nz, .asm_5673e ; 0x56747 $f5 + jr nz, .adjustPlayerGfxLoop + call EnableLCD callba LoadTrainerInfoTextBoxTiles - ld b, $8 - call GoPAL_SET + ld b, SET_PAL_GENERIC + call RunPaletteCommand call Delay3 call GBPalNormal ld a, $90 - ld [$ff48], a + ld [rOBP0], a call WaitForTextScrollButtonPress ld hl, wd730 res 6, [hl] @@ -65,27 +69,29 @@ DisplayDiploma: ; 566e2 (15:66e2) call Delay3 jp GBPalNormal -Func_56777: ; 56777 (15:6777) +UnusedPlayerNameLengthFunc: ; 56777 (15:6777) +; Unused function that does a calculation involving the length of the player's +; name. ld hl, wPlayerName ld bc, $ff00 -.asm_5677d +.loop ld a, [hli] - cp $50 + cp "@" ret z dec c - jr .asm_5677d ; 0x56782 $f9 + jr .loop DiplomaTextPointersAndCoords: ; 56784 (15:6784) dw DiplomaText - dw wTileMap + $2d + dwCoord 5, 2 dw DiplomaPlayer - dw wTileMap + $53 + dwCoord 3, 4 dw DiplomaEmptyText - dw wTileMap + $5f + dwCoord 15, 4 dw DiplomaCongrats - dw wTileMap + $7a + dwCoord 2, 6 dw DiplomaGameFreak - dw wTileMap + $149 + dwCoord 9, 16 DiplomaText: db $70,"Diploma",$70,"@" diff --git a/engine/menu/league_pc.asm b/engine/menu/league_pc.asm index a6dd7021..5b8ae7f0 100755 --- a/engine/menu/league_pc.asm +++ b/engine/menu/league_pc.asm @@ -12,31 +12,33 @@ PKMNLeaguePC: ; 0x7657e ld [hTilesetType], a ld [W_SPRITEFLIPPED], a ld [wUpdateSpritesEnabled], a - ld [wTrainerScreenX], a - ld [wcd42], a - ld a, [wd5a2] + ld [wHoFTeamIndex2], a + ld [wHoFTeamNo], a + ld a, [wNumHoFTeams] ld b, a - cp NUM_HOF_TEAMS + 1 - jr c, .first - ld b, NUM_HOF_TEAMS + cp HOF_TEAM_CAPACITY + 1 + jr c, .loop +; If the total number of hall of fame teams is greater than the storage +; capacity, then calculate the number of the first team that is still recorded. + ld b, HOF_TEAM_CAPACITY sub b - ld [wcd42], a -.first - ld hl, wcd42 + ld [wHoFTeamNo], a +.loop + ld hl, wHoFTeamNo inc [hl] push bc - ld a, [wTrainerScreenX] - ld [wWhichTrade], a + ld a, [wHoFTeamIndex2] + ld [wHoFTeamIndex], a callba LoadHallOfFameTeams - call Func_765e5 + call LeaguePCShowTeam pop bc - jr c, .second - ld hl, wTrainerScreenX + jr c, .doneShowingTeams + ld hl, wHoFTeamIndex2 inc [hl] ld a, [hl] cp b - jr nz, .first -.second + jr nz, .loop +.doneShowingTeams pop af ld [hTilesetType], a pop af @@ -45,14 +47,14 @@ PKMNLeaguePC: ; 0x7657e res 6, [hl] call GBPalWhiteOutWithDelay3 call ClearScreen - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand jp GBPalNormal -Func_765e5: ; 765e5 (1d:65e5) +LeaguePCShowTeam: ; 765e5 (1d:65e5) ld c, PARTY_LENGTH .loop push bc - call Func_76610 + call LeaguePCShowMon call WaitForTextScrollButtonPress ld a, [hJoyHeld] bit 1, a @@ -75,42 +77,40 @@ Func_765e5: ; 765e5 (1d:65e5) scf ret -Func_76610: ; 76610 (1d:6610) +LeaguePCShowMon: ; 76610 (1d:6610) call GBPalWhiteOutWithDelay3 call ClearScreen ld hl, wHallOfFame ld a, [hli] - ld [wWhichTrade], a + ld [wHoFMonSpecies], a ld [wcf91], a ld [wd0b5], a ld [wBattleMonSpecies2], a - ld [wcf1d], a + ld [wWholeScreenPaletteMonSpecies], a ld a, [hli] - ld [wTrainerFacingDirection], a + ld [wHoFMonLevel], a ld de, wcd6d - ld bc, $000B + ld bc, NAME_LENGTH call CopyData - ld b, $0B + ld b, SET_PAL_POKEMON_WHOLE_SCREEN ld c, 0 - call GoPAL_SET - hlCoord 12, 5 + call RunPaletteCommand + coord hl, 12, 5 call GetMonHeader call LoadFrontSpriteByMonIndex call GBPalNormal - hlCoord 0, 13 + coord hl, 0, 13 ld b, 2 ld c, $12 call TextBoxBorder - hlCoord 1, 15 + coord hl, 1, 15 ld de, HallOfFameNoText call PlaceString - hlCoord 16, 15 - ld de, wcd42 - ld bc, $0103 + coord hl, 16, 15 + ld de, wHoFTeamNo + lb bc, 1, 3 call PrintNumber - ld b, BANK(Func_702f0) - ld hl, Func_702f0 - jp Bankswitch + jpba HoFDisplayMonInfo HallOfFameNoText: ; 76670 (1d:6670) db "HALL OF FAME No @" diff --git a/engine/menu/main_menu.asm b/engine/menu/main_menu.asm index 756c7755..6c109cec 100755 --- a/engine/menu/main_menu.asm +++ b/engine/menu/main_menu.asm @@ -1,22 +1,21 @@ MainMenu: ; 5af2 (1:5af2) ; Check save file - call Func_5bff + call InitOptions xor a - ld [wd08a],a + ld [wOptionsInitialized],a inc a - ld [wd088],a - call Func_609e - jr nc,.next0 + ld [wSaveFileStatus],a + call CheckForPlayerNameInSRAM + jr nc,.mainMenuLoop - ; Predef 52 loads the save from SRAM to RAM predef LoadSAV -.next0 +.mainMenuLoop ld c,20 call DelayFrames xor a ; LINK_STATE_NONE ld [wLinkState],a - ld hl,wcc2b + ld hl,wPartyAndBillsPCSavedMenuItem ld [hli],a ld [hli],a ld [hli],a @@ -25,34 +24,35 @@ MainMenu: ; 5af2 (1:5af2) ld hl,wd72e res 6,[hl] call ClearScreen - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand call LoadTextBoxTilePatterns call LoadFontTilePatterns ld hl,wd730 set 6,[hl] - ld a,[wd088] + ld a,[wSaveFileStatus] cp a,1 - jr z,.next1 - hlCoord 0, 0 + jr z,.noSaveFile +; there's a save file + coord hl, 0, 0 ld b,6 ld c,13 call TextBoxBorder - hlCoord 2, 2 + coord hl, 2, 2 ld de,ContinueText call PlaceString jr .next2 -.next1 - hlCoord 0, 0 +.noSaveFile + coord hl, 0, 0 ld b,4 ld c,13 call TextBoxBorder - hlCoord 2, 2 + coord hl, 2, 2 ld de,NewGameText call PlaceString .next2 ld hl,wd730 res 6,[hl] - call UpdateSprites ; OAM? + call UpdateSprites xor a ld [wCurrentMenuItem],a ld [wLastMenuItem],a @@ -61,36 +61,38 @@ MainMenu: ; 5af2 (1:5af2) ld [wTopMenuItemX],a inc a ld [wTopMenuItemY],a - ld a,$B + ld a,A_BUTTON | B_BUTTON | START ld [wMenuWatchedKeys],a - ld a,[wd088] + ld a,[wSaveFileStatus] ld [wMaxMenuItem],a call HandleMenuInput - bit 1,a - jp nz,LoadTitlescreenGraphics ; load title screen (gfx and arrangement) + bit 1,a ; pressed B? + jp nz,DisplayTitleScreen ; if so, go back to the title screen ld c,20 call DelayFrames ld a,[wCurrentMenuItem] ld b,a - ld a,[wd088] + ld a,[wSaveFileStatus] cp a,2 - jp z,.next3 - inc b ; adjust MenuArrow_Counter -.next3 + jp z,.skipInc +; If there's no save file, increment the current menu item so that the numbers +; are the same whether or not there's a save file. + inc b +.skipInc ld a,b and a - jr z,.next4 ; if press_A on Continue + jr z,.choseContinue cp a,1 - jp z,Func_5d52 ; if press_A on NewGame - call DisplayOptionMenu ; if press_a on Options + jp z,StartNewGame + call DisplayOptionMenu ld a,1 - ld [wd08a],a - jp .next0 -.next4 - call ContinueGame + ld [wOptionsInitialized],a + jp .mainMenuLoop +.choseContinue + call DisplayContinueGameInfo ld hl,wd126 set 5,[hl] -.next6 +.inputLoop xor a ld [hJoyPressed],a ld [hJoyReleased],a @@ -98,18 +100,18 @@ MainMenu: ; 5af2 (1:5af2) call Joypad ld a,[hJoyHeld] bit 0,a - jr nz,.next5 + jr nz,.pressedA bit 1,a - jp nz,.next0 - jr .next6 -.next5 + jp nz,.mainMenuLoop ; pressed B + jr .inputLoop +.pressedA call GBPalWhiteOutWithDelay3 call ClearScreen - ld a,4 - ld [wd52a],a + ld a,PLAYER_DIR_DOWN + ld [wPlayerDirection],a ld c,10 call DelayFrames - ld a,[wd5a2] + ld a,[wNumHoFTeams] and a jp z,SpecialEnterMap ld a,[W_CURMAP] ; map ID @@ -121,16 +123,17 @@ MainMenu: ; 5af2 (1:5af2) set 2,[hl] ; fly warp or dungeon warp call SpecialWarpIn jp SpecialEnterMap -Func_5bff: ; 5bff (1:5bff) - ld a,1 - ld [wd358],a - ld a,3 + +InitOptions: ; 5bff (1:5bff) + ld a,1 ; no delay + ld [wLetterPrintingDelayFlags],a + ld a,3 ; medium speed ld [W_OPTIONS],a ret LinkMenu: ; 5c0a (1:5c0a) xor a - ld [wd358], a + ld [wLetterPrintingDelayFlags], a ld hl, wd72e set 6, [hl] ld hl, TextTerminator_6b20 @@ -138,16 +141,16 @@ LinkMenu: ; 5c0a (1:5c0a) call SaveScreenTilesToBuffer1 ld hl, WhereWouldYouLikeText call PrintText - hlCoord 5, 5 + coord hl, 5, 5 ld b, $6 ld c, $d call TextBoxBorder call UpdateSprites - hlCoord 7, 7 - ld de, TradeCenterText + coord hl, 7, 7 + ld de, CableClubOptionsText call PlaceString xor a - ld [wcd37], a + ld [wUnusedCD37], a ld [wd72d], a ld hl, wTopMenuItemY ld a, $7 @@ -160,7 +163,8 @@ LinkMenu: ; 5c0a (1:5c0a) ld a, $2 ld [hli], a inc a - ld [hli], a + ; ld a, A_BUTTON | B_BUTTON + ld [hli], a ; wMenuWatchedKeys xor a ld [hl], a .waitForInputLoop @@ -208,7 +212,7 @@ LinkMenu: ; 5c0a (1:5c0a) ld a, b ld [wLinkMenuSelectionSendBuffer], a and $3 - ld [wCurrentMenuItem], a ; wCurrentMenuItem + ld [wCurrentMenuItem], a .doneChoosingMenuSelection ld a, [hSerialConnectionStatus] cp USING_INTERNAL_CLOCK @@ -254,28 +258,28 @@ LinkMenu: ; 5c0a (1:5c0a) ld [wWalkBikeSurfState], a ; start walking ld a, [wCurrentMenuItem] and a - ld a, TRADE_CENTER + ld a, COLOSSEUM jr nz, .next - ld a, BATTLE_CENTER + ld a, TRADE_CENTER .next ld [wd72d], a ld hl, PleaseWaitText call PrintText - ld c, $32 + ld c, 50 call DelayFrames ld hl, wd732 res 1, [hl] ld a, [W_ANIMATIONID] ld [wDestinationMap], a call SpecialWarpIn - ld c, $14 + ld c, 20 call DelayFrames xor a ld [wMenuJoypadPollCount], a ld [wSerialExchangeNybbleSendData], a inc a ; LINK_STATE_IN_CABLE_CLUB ld [wLinkState], a - ld [wcc47], a + ld [wEnteringCableClub], a jr SpecialEnterMap .choseCancel xor a @@ -300,11 +304,11 @@ LinkCanceledText: ; 5d4d (1:5d4d) TX_FAR _LinkCanceledText db "@" -Func_5d52: ; 5d52 (1:5d52) +StartNewGame: ; 5d52 (1:5d52) ld hl, wd732 res 1, [hl] call OakSpeech - ld c, $14 + ld c, 20 call DelayFrames ; enter map after using a special warp or loading the game from the main menu @@ -319,7 +323,7 @@ SpecialEnterMap: ; 5d5f (1:5d5f) call ResetPlayerSpriteData ld c, 20 call DelayFrames - ld a, [wcc47] + ld a, [wEnteringCableClub] and a ret nz jp EnterMap @@ -331,89 +335,89 @@ NewGameText: ; 5d87 (1:5d87) db "NEW GAME", $4e db "OPTION@" -TradeCenterText: ; 5d97 (1:5d97) +CableClubOptionsText: ; 5d97 (1:5d97) db "TRADE CENTER", $4e db "COLOSSEUM", $4e db "CANCEL@" -ContinueGame: ; 5db5 (1:5db5) +DisplayContinueGameInfo: ; 5db5 (1:5db5) xor a - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba - hlCoord 4, 7 - ld b, $8 - ld c, $e + ld [H_AUTOBGTRANSFERENABLED], a + coord hl, 4, 7 + ld b, 8 + ld c, 14 call TextBoxBorder - hlCoord 5, 9 + coord hl, 5, 9 ld de, SaveScreenInfoText call PlaceString - hlCoord 12, 9 - ld de, wPlayerName ; wd158 + coord hl, 12, 9 + ld de, wPlayerName call PlaceString - hlCoord 17, 11 - call Func_5e2f - hlCoord 16, 13 - call Func_5e42 - hlCoord 13, 15 - call Func_5e55 - ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba - ld c, $1e + coord hl, 17, 11 + call PrintNumBadges + coord hl, 16, 13 + call PrintNumOwnedMons + coord hl, 13, 15 + call PrintPlayTime + ld a, 1 + ld [H_AUTOBGTRANSFERENABLED], a + ld c, 30 jp DelayFrames PrintSaveScreenText: ; 5def (1:5def) xor a ld [H_AUTOBGTRANSFERENABLED], a - ld hl, wTileMap + $4 + coord hl, 4, 0 ld b, $8 ld c, $e call TextBoxBorder call LoadTextBoxTilePatterns call UpdateSprites - ld hl, wTileMap + $2d + coord hl, 5, 2 ld de, SaveScreenInfoText call PlaceString - ld hl, wTileMap + $34 + coord hl, 12, 2 ld de, wPlayerName call PlaceString - ld hl, wTileMap + $61 - call Func_5e2f - ld hl, wTileMap + $88 - call Func_5e42 - ld hl, wTileMap + $ad - call Func_5e55 + coord hl, 17, 4 + call PrintNumBadges + coord hl, 16, 6 + call PrintNumOwnedMons + coord hl, 13, 8 + call PrintPlayTime ld a, $1 ld [H_AUTOBGTRANSFERENABLED], a - ld c, $1e + ld c, 30 jp DelayFrames -Func_5e2f: ; 5e2f (1:5e2f) +PrintNumBadges: ; 5e2f (1:5e2f) push hl ld hl, W_OBTAINEDBADGES ld b, $1 call CountSetBits pop hl - ld de, wd11e - ld bc, $102 + ld de, wNumSetBits + lb bc, 1, 2 jp PrintNumber -Func_5e42: ; 5e42 (1:5e42) +PrintNumOwnedMons: ; 5e42 (1:5e42) push hl - ld hl, wPokedexOwned ; wPokedexOwned + ld hl, wPokedexOwned ld b, wPokedexOwnedEnd - wPokedexOwned call CountSetBits pop hl - ld de, wd11e - ld bc, $103 + ld de, wNumSetBits + lb bc, 1, 3 jp PrintNumber -Func_5e55: ; 5e55 (1:5e55) +PrintPlayTime: ; 5e55 (1:5e55) ld de, W_PLAYTIMEHOURS + 1 - ld bc, $103 + lb bc, 1, 3 call PrintNumber ld [hl], $6d inc hl ld de, W_PLAYTIMEMINUTES + 1 - ld bc, $8102 + lb bc, LEADING_ZEROES | 1, 2 jp PrintNumber SaveScreenInfoText: ; 5e6a (1:5e6a) @@ -423,40 +427,40 @@ SaveScreenInfoText: ; 5e6a (1:5e6a) next "TIME@" DisplayOptionMenu: ; 5e8a (1:5e8a) - hlCoord 0, 0 + coord hl, 0, 0 ld b,3 ld c,18 call TextBoxBorder - hlCoord 0, 5 + coord hl, 0, 5 ld b,3 ld c,18 call TextBoxBorder - hlCoord 0, 10 + coord hl, 0, 10 ld b,3 ld c,18 call TextBoxBorder - hlCoord 1, 1 + coord hl, 1, 1 ld de,TextSpeedOptionText call PlaceString - hlCoord 1, 6 + coord hl, 1, 6 ld de,BattleAnimationOptionText call PlaceString - hlCoord 1, 11 + coord hl, 1, 11 ld de,BattleStyleOptionText call PlaceString - hlCoord 2, 16 + coord hl, 2, 16 ld de,OptionMenuCancelText call PlaceString xor a ld [wCurrentMenuItem],a ld [wLastMenuItem],a inc a - ld [wd358],a - ld [wTrainerScreenY],a + ld [wLetterPrintingDelayFlags],a + ld [wUnusedCD40],a ld a,3 ; text speed cursor Y coordinate ld [wTopMenuItemY],a call SetCursorPositionsFromOptions - ld a,[wWhichTrade] ; text speed cursor X coordinate + ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate ld [wTopMenuItemX],a ld a,$01 ld [H_AUTOBGTRANSFERENABLED],a ; enable auto background transfer @@ -468,7 +472,7 @@ DisplayOptionMenu: ; 5e8a (1:5e8a) call JoypadLowSensitivity ld a,[hJoy5] ld b,a - and a,%11111011 ; any key besides select pressed? + and a,A_BUTTON | B_BUTTON | START | D_RIGHT | D_LEFT | D_UP | D_DOWN ; any key besides select pressed? jr z,.getJoypadStateLoop bit 1,b ; B button pressed? jr nz,.exitMenu @@ -480,8 +484,8 @@ DisplayOptionMenu: ; 5e8a (1:5e8a) cp a,16 ; is the cursor on Cancel? jr nz,.loop .exitMenu - ld a,(SFX_02_40 - SFX_Headers_02) / 3 - call PlaySound ; play sound + ld a,SFX_PRESS_AB + call PlaySound ret .eraseOldMenuCursor ld [wTopMenuItemX],a @@ -506,7 +510,7 @@ DisplayOptionMenu: ; 5e8a (1:5e8a) .downPressed cp a,16 ld b,-13 - ld hl,wWhichTrade + ld hl,wOptionsTextSpeedCursorX jr z,.updateMenuVariables ld b,5 cp a,3 @@ -521,7 +525,7 @@ DisplayOptionMenu: ; 5e8a (1:5e8a) .upPressed cp a,8 ld b,-5 - ld hl,wWhichTrade + ld hl,wOptionsTextSpeedCursorX jr z,.updateMenuVariables cp a,13 inc hl @@ -540,17 +544,17 @@ DisplayOptionMenu: ; 5e8a (1:5e8a) call PlaceUnfilledArrowMenuCursor jp .loop .cursorInBattleAnimation - ld a,[wTrainerEngageDistance] ; battle animation cursor X coordinate + ld a,[wOptionsBattleAnimCursorX] ; battle animation cursor X coordinate xor a,$0b ; toggle between 1 and 10 - ld [wTrainerEngageDistance],a + ld [wOptionsBattleAnimCursorX],a jp .eraseOldMenuCursor .cursorInBattleStyle - ld a,[wTrainerFacingDirection] ; battle style cursor X coordinate + ld a,[wOptionsBattleStyleCursorX] ; battle style cursor X coordinate xor a,$0b ; toggle between 1 and 10 - ld [wTrainerFacingDirection],a + ld [wOptionsBattleStyleCursorX],a jp .eraseOldMenuCursor .pressedLeftInTextSpeed - ld a,[wWhichTrade] ; text speed cursor X coordinate + ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate cp a,1 jr z,.updateTextSpeedXCoord cp a,7 @@ -561,7 +565,7 @@ DisplayOptionMenu: ; 5e8a (1:5e8a) sub a,7 jr .updateTextSpeedXCoord .pressedRightInTextSpeed - ld a,[wWhichTrade] ; text speed cursor X coordinate + ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate cp a,14 jr z,.updateTextSpeedXCoord cp a,7 @@ -571,7 +575,7 @@ DisplayOptionMenu: ; 5e8a (1:5e8a) .fromFastToMedium add a,6 .updateTextSpeedXCoord - ld [wWhichTrade],a ; text speed cursor X coordinate + ld [wOptionsTextSpeedCursorX],a ; text speed cursor X coordinate jp .eraseOldMenuCursor TextSpeedOptionText: ; 5fc0 (1:5fc0) @@ -592,7 +596,7 @@ OptionMenuCancelText: ; 6018 (1:6018) ; sets the options variable according to the current placement of the menu cursors in the options menu SetOptionsFromCursorPositions: ; 601f (1:601f) ld hl,TextSpeedOptionData - ld a,[wWhichTrade] ; text speed cursor X coordinate + ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate ld c,a .loop ld a,[hli] @@ -603,7 +607,7 @@ SetOptionsFromCursorPositions: ; 601f (1:601f) .textSpeedMatchFound ld a,[hl] ld d,a - ld a,[wTrainerEngageDistance] ; battle animation cursor X coordinate + ld a,[wOptionsBattleAnimCursorX] ; battle animation cursor X coordinate dec a jr z,.battleAnimationOn .battleAnimationOff @@ -612,7 +616,7 @@ SetOptionsFromCursorPositions: ; 601f (1:601f) .battleAnimationOn res 7,d .checkBattleStyle - ld a,[wTrainerFacingDirection] ; battle style cursor X coordinate + ld a,[wOptionsBattleStyleCursorX] ; battle style cursor X coordinate dec a jr z,.battleStyleShift .battleStyleSet @@ -637,27 +641,27 @@ SetCursorPositionsFromOptions: ; 604c (1:604c) pop bc dec hl ld a,[hl] - ld [wWhichTrade],a ; text speed cursor X coordinate - hlCoord 0, 3 + ld [wOptionsTextSpeedCursorX],a ; text speed cursor X coordinate + coord hl, 0, 3 call .placeUnfilledRightArrow sla c ld a,1 ; On jr nc,.storeBattleAnimationCursorX ld a,10 ; Off .storeBattleAnimationCursorX - ld [wTrainerEngageDistance],a ; battle animation cursor X coordinate - hlCoord 0, 8 + ld [wOptionsBattleAnimCursorX],a ; battle animation cursor X coordinate + coord hl, 0, 8 call .placeUnfilledRightArrow sla c ld a,1 jr nc,.storeBattleStyleCursorX ld a,10 .storeBattleStyleCursorX - ld [wTrainerFacingDirection],a ; battle style cursor X coordinate - hlCoord 0, 13 + ld [wOptionsBattleStyleCursorX],a ; battle style cursor X coordinate + coord hl, 0, 13 call .placeUnfilledRightArrow ; cursor in front of Cancel - hlCoord 0, 16 + coord hl, 0, 16 ld a,1 .placeUnfilledRightArrow ld e,a @@ -677,28 +681,32 @@ TextSpeedOptionData: ; 6096 (1:6096) db 7 ; default X coordinate (Medium) db $ff ; terminator -Func_609e: ; 609e (1:609e) - ld a, $a - ld [$0], a +CheckForPlayerNameInSRAM: ; 609e (1:609e) +; Check if the player name data in SRAM has a string terminator character +; (indicating that a name may have been saved there) and return whether it does +; in carry. + ld a, SRAM_ENABLE + ld [MBC1SRamEnable], a ld a, $1 - ld [$6000], a - ld [$4000], a - ld b, $b - ld hl, $a598 -.asm_60b0 + ld [MBC1SRamBankingMode], a + ld [MBC1SRamBank], a + ld b, NAME_LENGTH + ld hl, sPlayerName +.loop ld a, [hli] - cp $50 - jr z, .asm_60c1 + cp "@" + jr z, .found dec b - jr nz, .asm_60b0 + jr nz, .loop +; not found xor a - ld [$0], a - ld [$6000], a + ld [MBC1SRamEnable], a + ld [MBC1SRamBankingMode], a and a ret -.asm_60c1 +.found xor a - ld [$0], a - ld [$6000], a + ld [MBC1SRamEnable], a + ld [MBC1SRamBankingMode], a scf ret diff --git a/engine/menu/naming_screen.asm b/engine/menu/naming_screen.asm index df862d69..978216c8 100755 --- a/engine/menu/naming_screen.asm +++ b/engine/menu/naming_screen.asm @@ -4,37 +4,37 @@ AskName: ; 64eb (1:64eb) push hl ld a, [W_ISINBATTLE] dec a - ld hl, wTileMap - ld b, $4 - ld c, $b + coord hl, 0, 0 + ld b, 4 + ld c, 11 call z, ClearScreenArea ; only if in wild batle ld a, [wcf91] ld [wd11e], a call GetMonName ld hl, DoYouWantToNicknameText call PrintText - hlCoord 14, 7 - ld bc, $80f + coord hl, 14, 7 + lb bc, 8, 15 ld a, TWO_OPTION_MENU ld [wTextBoxID], a call DisplayTextBoxID pop hl ld a, [wCurrentMenuItem] and a - jr nz, .asm_654c + jr nz, .declinedNickname ld a, [wUpdateSpritesEnabled] push af xor a ld [wUpdateSpritesEnabled], a push hl - ld a, $2 - ld [wd07d], a + ld a, NAME_MON_SCREEN + ld [wNamingScreenType], a call DisplayNamingScreen ld a, [W_ISINBATTLE] and a - jr nz, .asm_653e + jr nz, .inBattle call ReloadMapSpriteTilePatterns -.asm_653e +.inBattle call LoadScreenTilesFromBuffer1 pop hl pop af @@ -42,42 +42,42 @@ AskName: ; 64eb (1:64eb) ld a, [wcf4b] cp $50 ret nz -.asm_654c +.declinedNickname ld d, h ld e, l ld hl, wcd6d - ld bc, $000b + ld bc, NAME_LENGTH jp CopyData DoYouWantToNicknameText: ; 0x6557 TX_FAR _DoYouWantToNicknameText db "@" -Func_655c: ; 655c (1:655c) - ld hl, wHPBarMaxHP +DisplayNameRaterScreen: ; 655c (1:655c) + ld hl, wBuffer xor a ld [wUpdateSpritesEnabled], a - ld a, $2 - ld [wd07d], a + ld a, NAME_MON_SCREEN + ld [wNamingScreenType], a call DisplayNamingScreen call GBPalWhiteOutWithDelay3 call RestoreScreenTilesAndReloadTilePatterns call LoadGBPal ld a, [wcf4b] - cp $50 - jr z, .asm_6594 + cp "@" + jr z, .playerCancelled ld hl, wPartyMonNicks - ld bc, $b + ld bc, NAME_LENGTH ld a, [wWhichPokemon] call AddNTimes ld e, l ld d, h - ld hl, wHPBarMaxHP - ld bc, $b + ld hl, wBuffer + ld bc, NAME_LENGTH call CopyData and a ret -.asm_6594 +.playerCancelled scf ret @@ -88,44 +88,44 @@ DisplayNamingScreen: ; 6596 (1:6596) call GBPalWhiteOutWithDelay3 call ClearScreen call UpdateSprites - ld b, $8 - call GoPAL_SET + ld b, SET_PAL_GENERIC + call RunPaletteCommand call LoadHpBarAndStatusTilePatterns call LoadEDTile callba LoadMonPartySpriteGfx - hlCoord 0, 4 - ld b, $9 - ld c, $12 + coord hl, 0, 4 + ld b, 9 + ld c, 18 call TextBoxBorder call PrintNamingText - ld a, $3 + ld a, 3 ld [wTopMenuItemY], a - ld a, $1 + ld a, 1 ld [wTopMenuItemX], a ld [wLastMenuItem], a ld [wCurrentMenuItem], a ld a, $ff ld [wMenuWatchedKeys], a - ld a, $7 + ld a, 7 ld [wMaxMenuItem], a ld a, $50 ld [wcf4b], a xor a - ld hl, wHPBarMaxHP + 1 + ld hl, wNamingScreenSubmitName ld [hli], a ld [hli], a - ld [wPartyMonAnimCounter], a -.asm_65ed + ld [wAnimCounter], a +.selectReturnPoint call PrintAlphabet call GBPalNormal -.asm_65f3 - ld a, [wHPBarMaxHP + 1] +.ABStartReturnPoint + ld a, [wNamingScreenSubmitName] and a - jr nz, .asm_662d - call Func_680e -.asm_65fc + jr nz, .submitNickname + call PrintNicknameAndUnderscores +.dPadReturnPoint call PlaceMenuCursor -.asm_65ff +.inputLoop ld a, [wCurrentMenuItem] push af callba AnimatePartyMon_ForceSpeed1 @@ -134,17 +134,17 @@ DisplayNamingScreen: ; 6596 (1:6596) call JoypadLowSensitivity ld a, [hJoyPressed] and a - jr z, .asm_65ff - ld hl, .unknownPointerTable_665e -.asm_661a + jr z, .inputLoop + ld hl, .namingScreenButtonFunctions +.checkForPressedButton sla a - jr c, .asm_6624 + jr c, .foundPressedButton inc hl inc hl inc hl inc hl - jr .asm_661a -.asm_6624 + jr .checkForPressedButton +.foundPressedButton ld a, [hli] ld e, a ld a, [hli] @@ -154,15 +154,16 @@ DisplayNamingScreen: ; 6596 (1:6596) ld l, a push de jp [hl] -.asm_662d + +.submitNickname pop de ld hl, wcf4b - ld bc, $b + ld bc, NAME_LENGTH call CopyData call GBPalWhiteOutWithDelay3 call ClearScreen call ClearSprites - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand call GBPalNormal xor a ld [W_SUBANIMTRANSFORM], a @@ -171,193 +172,197 @@ DisplayNamingScreen: ; 6596 (1:6596) ld a, [W_ISINBATTLE] and a jp z, LoadTextBoxTilePatterns - ld hl, LoadHudTilePatterns - ld b, BANK(LoadHudTilePatterns) - jp Bankswitch + jpab LoadHudTilePatterns -.unknownPointerTable_665e: ; 665e (1:665e) - dw .asm_65fc - dw .asm_673e - dw .asm_65fc - dw .asm_672c - dw .asm_65fc - dw .asm_6718 - dw .asm_65fc - dw .asm_6702 - dw .asm_65f3 - dw .asm_668c - dw .asm_65ed - dw .asm_6683 - dw .asm_65f3 - dw .deleteLetter - dw .asm_65f3 - dw .asm_6692 +.namingScreenButtonFunctions + dw .dPadReturnPoint + dw .pressedDown + dw .dPadReturnPoint + dw .pressedUp + dw .dPadReturnPoint + dw .pressedLeft + dw .dPadReturnPoint + dw .pressedRight + dw .ABStartReturnPoint + dw .pressedStart + dw .selectReturnPoint + dw .pressedSelect + dw .ABStartReturnPoint + dw .pressedB + dw .ABStartReturnPoint + dw .pressedA -.asm_667e +.pressedA_changedCase pop de - ld de, .asm_65ed ; $65ed + ld de, .selectReturnPoint push de -.asm_6683 - ld a, [wHPBarOldHP] +.pressedSelect + ld a, [wAlphabetCase] xor $1 - ld [wHPBarOldHP], a + ld [wAlphabetCase], a ret -.asm_668c - ld a, $1 - ld [wHPBarMaxHP + 1], a + +.pressedStart + ld a, 1 + ld [wNamingScreenSubmitName], a ret -.asm_6692 + +.pressedA ld a, [wCurrentMenuItem] - cp $5 - jr nz, .asm_66a0 + cp $5 ; "ED" row + jr nz, .didNotPressED ld a, [wTopMenuItemX] - cp $11 - jr z, .asm_668c -.asm_66a0 + cp $11 ; "ED" column + jr z, .pressedStart +.didNotPressED ld a, [wCurrentMenuItem] - cp $6 - jr nz, .asm_66ae + cp $6 ; case switch row + jr nz, .didNotPressCaseSwtich ld a, [wTopMenuItemX] - cp $1 - jr z, .asm_667e -.asm_66ae + cp $1 ; case switch column + jr z, .pressedA_changedCase +.didNotPressCaseSwtich ld hl, wMenuCursorLocation ld a, [hli] ld h, [hl] ld l, a inc hl ld a, [hl] - ld [wHPBarNewHP], a + ld [wNamingScreenLetter], a call CalcStringLength - ld a, [wHPBarNewHP] + ld a, [wNamingScreenLetter] cp $e5 - ld de, Dakutens ; $6885 - jr z, .asm_66e3 + ld de, Dakutens + jr z, .dakutensAndHandakutens cp $e4 - ld de, Handakutens ; $68d6 - jr z, .asm_66e3 - ld a, [wd07d] - cp $2 + ld de, Handakutens + jr z, .dakutensAndHandakutens + ld a, [wNamingScreenType] + cp NAME_MON_SCREEN jr nc, .checkMonNameLength - ld a, [wHPBarMaxHP] + ld a, [wNamingScreenNameLength] cp $7 ; max length of player/rival names jr .checkNameLength .checkMonNameLength - ld a, [wHPBarMaxHP] + ld a, [wNamingScreenNameLength] cp $a ; max length of pokemon nicknames .checkNameLength jr c, .addLetter ret -.asm_66e3 + +.dakutensAndHandakutens push hl - call Func_6871 + call DakutensAndHandakutens pop hl ret nc dec hl .addLetter - ld a, [wHPBarNewHP] + ld a, [wNamingScreenLetter] ld [hli], a ld [hl], $50 - ld a, (SFX_02_40 - SFX_Headers_02) / 3 + ld a, SFX_PRESS_AB call PlaySound ret -.deleteLetter - ld a, [wHPBarMaxHP] +.pressedB + ld a, [wNamingScreenNameLength] and a ret z call CalcStringLength dec hl - ld [hl], $50 + ld [hl], "@" ret -.asm_6702 +.pressedRight ld a, [wCurrentMenuItem] cp $6 - ret z + ret z ; can't scroll right on bottom row ld a, [wTopMenuItemX] - cp $11 - jp z, .asm_6714 + cp $11 ; max + jp z, .wrapToFirstColumn inc a inc a - jr .asm_6755 -.asm_6714 + jr .done +.wrapToFirstColumn ld a, $1 - jr .asm_6755 -.asm_6718 + jr .done +.pressedLeft ld a, [wCurrentMenuItem] cp $6 - ret z + ret z ; can't scroll right on bottom row ld a, [wTopMenuItemX] dec a - jp z, .asm_6728 + jp z, .wrapToLastColumn dec a - jr .asm_6755 -.asm_6728 - ld a, $11 - jr .asm_6755 -.asm_672c + jr .done +.wrapToLastColumn + ld a, $11 ; max + jr .done +.pressedUp ld a, [wCurrentMenuItem] dec a ld [wCurrentMenuItem], a and a ret nz - ld a, $6 + ld a, $6 ; wrap to bottom row ld [wCurrentMenuItem], a - ld a, $1 - jr .asm_6755 -.asm_673e + ld a, $1 ; force left column + jr .done +.pressedDown ld a, [wCurrentMenuItem] inc a ld [wCurrentMenuItem], a cp $7 - jr nz, .asm_6750 + jr nz, .wrapToTopRow ld a, $1 ld [wCurrentMenuItem], a - jr .asm_6755 -.asm_6750 + jr .done +.wrapToTopRow cp $6 ret nz ld a, $1 -.asm_6755 +.done ld [wTopMenuItemX], a jp EraseMenuCursor LoadEDTile: ; 675b (1:675b) ld de, ED_Tile ld hl, vFont + $700 - ld bc, $1 + ld bc, (ED_TileEnd - ED_Tile) / $8 + ; to fix the graphical bug on poor emulators + ;lb bc, BANK(ED_Tile), (ED_TileEnd - ED_Tile) / $8 jp CopyVideoDataDouble ED_Tile: ; 6767 (1:6767) INCBIN "gfx/ED_tile.1bpp" +ED_TileEnd: PrintAlphabet: ; 676f (1:676f) xor a - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba - ld a, [wHPBarOldHP] + ld [H_AUTOBGTRANSFERENABLED], a + ld a, [wAlphabetCase] and a - ld de, LowerCaseAlphabet ; $679e - jr nz, .asm_677e - ld de, UpperCaseAlphabet ; $67d6 -.asm_677e - hlCoord 2, 5 - ld bc, $509 -.asm_6784 + ld de, LowerCaseAlphabet + jr nz, .lowercase + ld de, UpperCaseAlphabet +.lowercase + coord hl, 2, 5 + lb bc, 5, 9 ; 5 rows, 9 columns +.outerLoop push bc -.asm_6785 +.innerLoop ld a, [de] ld [hli], a inc hl inc de dec c - jr nz, .asm_6785 - ld bc, $16 + jr nz, .innerLoop + ld bc, SCREEN_WIDTH + 2 add hl, bc pop bc dec b - jr nz, .asm_6784 + jr nz, .outerLoop call PlaceString ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba + ld [H_AUTOBGTRANSFERENABLED], a jp Delay3 LowerCaseAlphabet: ; 679e (1:679e) @@ -366,59 +371,61 @@ LowerCaseAlphabet: ; 679e (1:679e) UpperCaseAlphabet: ; 67d6 (1:67d6) db "ABCDEFGHIJKLMNOPQRSTUVWXYZ ×():;[]",$e1,$e2,"-?!♂♀/",$f2,",¥lower case@" -Func_680e: ; 680e (1:680e) +PrintNicknameAndUnderscores: ; 680e (1:680e) call CalcStringLength ld a, c - ld [wHPBarMaxHP], a - hlCoord 10, 2 - ld bc, $10a + ld [wNamingScreenNameLength], a + coord hl, 10, 2 + lb bc, 1, 10 call ClearScreenArea - hlCoord 10, 2 + coord hl, 10, 2 ld de, wcf4b call PlaceString - hlCoord 10, 3 - ld a, [wd07d] - cp $2 - jr nc, .asm_6835 - ld b, $7 - jr .asm_6837 -.asm_6835 - ld b, $a -.asm_6837 - ld a, $76 -.asm_6839 + coord hl, 10, 3 + ld a, [wNamingScreenType] + cp NAME_MON_SCREEN + jr nc, .pokemon1 + ld b, 7 ; player or rival max name length + jr .playerOrRival1 +.pokemon1 + ld b, 10 ; pokemon max name length +.playerOrRival1 + ld a, $76 ; underscore tile id +.placeUnderscoreLoop ld [hli], a dec b - jr nz, .asm_6839 - ld a, [wd07d] - cp $2 - ld a, [wHPBarMaxHP] - jr nc, .asm_684b - cp $7 - jr .asm_684d -.asm_684b - cp $a -.asm_684d - jr nz, .asm_6867 + jr nz, .placeUnderscoreLoop + ld a, [wNamingScreenType] + cp NAME_MON_SCREEN + ld a, [wNamingScreenNameLength] + jr nc, .pokemon2 + cp 7 ; player or rival max name length + jr .playerOrRival2 +.pokemon2 + cp 10 ; pokemon max name length +.playerOrRival2 + jr nz, .emptySpacesRemaining + ; when all spaces are filled, force the cursor onto the ED tile call EraseMenuCursor - ld a, $11 + ld a, $11 ; "ED" x coord ld [wTopMenuItemX], a - ld a, $5 + ld a, $5 ; "ED" y corrd ld [wCurrentMenuItem], a - ld a, [wd07d] - cp $2 - ld a, $9 - jr nc, .asm_6867 - ld a, $6 -.asm_6867 + ld a, [wNamingScreenType] + cp NAME_MON_SCREEN + ld a, 9 ; keep the last underscore raised + jr nc, .pokemon3 + ld a, 6 ; keep the last underscore raised +.pokemon3 +.emptySpacesRemaining ld c, a ld b, $0 - hlCoord 10, 3 + coord hl, 10, 3 add hl, bc - ld [hl], $77 + ld [hl], $77 ; raised underscore tile id ret -Func_6871: ; 6871 (1:6871) +DakutensAndHandakutens: ; 6871 (1:6871) push de call CalcStringLength dec hl @@ -429,7 +436,7 @@ Func_6871: ; 6871 (1:6871) ret nc inc hl ld a, [hl] - ld [wHPBarNewHP], a + ld [wNamingScreenLetter], a ret Dakutens: ; 6885 (1:6885) @@ -452,17 +459,17 @@ Handakutens: ; 68d6 (1:68d6) CalcStringLength: ; 68eb (1:68eb) ld hl, wcf4b ld c, $0 -.asm_68f0 +.loop ld a, [hl] - cp $50 + cp "@" ret z inc hl inc c - jr .asm_68f0 + jr .loop PrintNamingText: ; 68f8 (1:68f8) - hlCoord 0, 1 - ld a, [wd07d] + coord hl, 0, 1 + ld a, [wNamingScreenType] ld de, YourTextString and a jr z, .notNickname @@ -476,12 +483,12 @@ PrintNamingText: ; 68f8 (1:68f8) pop af ld [wd11e], a call GetMonName - hlCoord 4, 1 + coord hl, 4, 1 call PlaceString ld hl, $1 add hl, bc ld [hl], $c9 - hlCoord 1, 3 + coord hl, 1, 3 ld de, NicknameTextString jr .placeString .notNickname diff --git a/engine/menu/oaks_pc.asm b/engine/menu/oaks_pc.asm index 6e7edda2..7ff03c46 100755 --- a/engine/menu/oaks_pc.asm +++ b/engine/menu/oaks_pc.asm @@ -5,7 +5,7 @@ OpenOaksPC: ; 1e915 (7:6915) ld hl, GetDexRatedText call PrintText call YesNoChoice - ld a, [wCurrentMenuItem] ; wCurrentMenuItem + ld a, [wCurrentMenuItem] and a jr nz, .asm_1e932 predef DisplayDexRating diff --git a/engine/menu/party_menu.asm b/engine/menu/party_menu.asm index 242edd40..f3e1a138 100755 --- a/engine/menu/party_menu.asm +++ b/engine/menu/party_menu.asm @@ -1,4 +1,4 @@ -; [wd07d] = menu type / message ID +; [wPartyMenuTypeOrMessageID] = menu type / message ID ; if less than $F0, it is a menu type ; menu types: ; 00: normal pokemon menu (e.g. Start menu) @@ -21,21 +21,21 @@ DrawPartyMenu_: ; 12cd2 (4:6cd2) xor a ld [H_AUTOBGTRANSFERENABLED],a call ClearScreen - call UpdateSprites ; move sprites + call UpdateSprites callba LoadMonPartySpriteGfxWithLCDDisabled ; load pokemon icon graphics RedrawPartyMenu_: ; 12ce3 (4:6ce3) - ld a,[wd07d] - cp a,$04 + ld a,[wPartyMenuTypeOrMessageID] + cp a,SWAP_MONS_PARTY_MENU jp z,.printMessage call ErasePartyMenuCursors - callba SendBlkPacket_PartyMenu ; loads some data to wcf2e - hlCoord 3, 0 + callba InitPartyMenuBlkPacket + coord hl, 3, 0 ld de,wPartySpecies xor a ld c,a ld [hPartyMonIndex],a - ld [wcf2d],a + ld [wWhichPartyMenuHPBar],a .loop ld a,[de] cp a,$FF ; reached the terminator? @@ -75,10 +75,10 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3) inc hl inc hl .skipUnfilledRightArrow - ld a,[wd07d] ; menu type - cp a,$03 + ld a,[wPartyMenuTypeOrMessageID] ; menu type + cp a,TMHM_PARTY_MENU jr z,.teachMoveMenu - cp a,$05 + cp a,EVO_STONE_PARTY_MENU jr z,.evolutionStoneMenu push hl ld bc,14 ; 14 columns to the right @@ -96,7 +96,7 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3) ld a,[hFlags_0xFFF6] res 0,a ld [hFlags_0xFFF6],a - call SetPartyMenuHealthBarColor ; color the HP bar (on SGB) + call SetPartyMenuHPBarColor ; color the HP bar (on SGB) pop hl jr .printLevel .teachMoveMenu @@ -150,7 +150,7 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3) ld l,a ld de,wcd6d ld a,BANK(EvosMovesPointerTable) - ld bc,13 + ld bc,Mon133_EvosEnd - Mon133_EvosMoves call FarCopyData ld hl,wcd6d ld de,.notAbleToEvolveText @@ -167,7 +167,7 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3) dec hl dec hl ld b,[hl] - ld a,[wd156] ; evolution stone item ID + ld a,[wEvoStoneItemID] ; the stone the player used inc hl inc hl inc hl @@ -188,15 +188,15 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3) .notAbleToEvolveText db "NOT ABLE@" .afterDrawingMonEntries - ld b,$0A - call GoPAL_SET + ld b, SET_PAL_PARTY_MENU + call RunPaletteCommand .printMessage ld hl,wd730 ld a,[hl] push af push hl set 6,[hl] ; turn off letter printing delay - ld a,[wd07d] ; message ID + ld a,[wPartyMenuTypeOrMessageID] ; message ID cp a,$F0 jr nc,.printItemUseMessage add a @@ -227,7 +227,7 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3) ld h,[hl] ld l,a push hl - ld a,[wcf06] + ld a,[wUsedItemOnWhichPokemon] ld hl,wPartyMonNicks call GetPartyMonName pop hl @@ -311,15 +311,15 @@ RareCandyText: ; 12ec0 (4:6ec0) db $06 db "@" -SetPartyMenuHealthBarColor: ; 12ec7 (4:6ec7) - ld hl, wcf1f - ld a, [wcf2d] +SetPartyMenuHPBarColor: ; 12ec7 (4:6ec7) + ld hl, wPartyMenuHPBarColors + ld a, [wWhichPartyMenuHPBar] ld c, a - ld b, $0 + ld b, 0 add hl, bc call GetHealthBarColor - ld b, $fc - call GoPAL_SET - ld hl, wcf2d + ld b, UPDATE_PARTY_MENU_BLK_PACKET + call RunPaletteCommand + ld hl, wWhichPartyMenuHPBar inc [hl] ret diff --git a/engine/menu/pc.asm b/engine/menu/pc.asm index 97895ca6..78b35b95 100755 --- a/engine/menu/pc.asm +++ b/engine/menu/pc.asm @@ -1,16 +1,16 @@ ActivatePC: ; 17e2c (5:7e2c) - call SaveScreenTilesToBuffer2 ;XXX: copy background from wTileMap to wTileMapBackup2 - ld a, (SFX_02_45 - SFX_Headers_02) / 3 - call PlaySound ;XXX: play sound or stop music + call SaveScreenTilesToBuffer2 + ld a, SFX_TURN_ON_PC + call PlaySound ld hl, TurnedOnPC1Text call PrintText - call WaitForSoundToFinish ;XXX: wait for sound to be done + call WaitForSoundToFinish ld hl, wFlags_0xcd60 set 3, [hl] - call LoadScreenTilesFromBuffer2 ;XXX: restore saved screen + call LoadScreenTilesFromBuffer2 call Delay3 PCMainMenu: ; 17e48 (5:7e48) - callba Func_213c8 + callba DisplayPCMainMenu ld hl, wFlags_0xcd60 set 5, [hl] call HandleMenuInput @@ -51,31 +51,30 @@ PCMainMenu: ; 17e48 (5:7e48) ld hl, wFlags_0xcd60 res 5, [hl] set 3, [hl] - ld a, (SFX_02_47 - SFX_Headers_02) / 3 - call PlaySound ;XXX: play sound or stop music - call WaitForSoundToFinish ;XXX: wait for sound to be done + ld a, SFX_ENTER_PC + call PlaySound + call WaitForSoundToFinish ld hl, AccessedMyPCText call PrintText callba PlayerPC jr ReloadMainMenu OaksPC: ; 17ec0 (5:7ec0) - ld a, (SFX_02_47 - SFX_Headers_02) / 3 - call PlaySound ;XXX: play sound or stop music - call WaitForSoundToFinish ;XXX: wait for sound to be done + ld a, SFX_ENTER_PC + call PlaySound + call WaitForSoundToFinish callba OpenOaksPC jr ReloadMainMenu PKMNLeague: ; 17ed2 (5:7ed2) - ld a, (SFX_02_47 - SFX_Headers_02) / 3 - call PlaySound ;XXX: play sound or stop music - call WaitForSoundToFinish ;XXX: wait for sound to be done + ld a, SFX_ENTER_PC + call PlaySound + call WaitForSoundToFinish callba PKMNLeaguePC jr ReloadMainMenu BillsPC: ; 17ee4 (5:7ee4) - ld a, (SFX_02_47 - SFX_Headers_02) / 3 - call PlaySound ;XXX: play sound or stop music - call WaitForSoundToFinish ;XXX: wait for sound to be done - ld a, [wd7f1] ;has to do with having met Bill - bit 0, a + ld a, SFX_ENTER_PC + call PlaySound + call WaitForSoundToFinish + CheckEvent EVENT_MET_BILL jr nz, .billsPC ;if you've met bill, use that bill's instead of someone's ld hl, AccessedSomeonesPCText jr .printText @@ -88,12 +87,12 @@ ReloadMainMenu: ; 17f06 (5:7f06) xor a ld [wDoNotWaitForButtonPressAfterDisplayingText], a call ReloadMapData - call UpdateSprites ;XXX: moves sprites + call UpdateSprites jp PCMainMenu LogOff: ; 17f13 (5:7f13) - ld a, (SFX_02_46 - SFX_Headers_02) / 3 - call PlaySound ;XXX: play sound or stop music - call WaitForSoundToFinish ;XXX: wait for sound to be done + ld a, SFX_TURN_OFF_PC + call PlaySound + call WaitForSoundToFinish ld hl, wFlags_0xcd60 res 3, [hl] res 5, [hl] @@ -115,13 +114,13 @@ AccessedMyPCText: ; 17f32 (5:7f32) TX_FAR _AccessedMyPCText db "@" -; removes one of the specified item ID [$FFdb] from bag (if existent) +; removes one of the specified item ID [hItemToRemoveID] from bag (if existent) RemoveItemByID: ; 17f37 (5:7f37) - ld hl, wBagItems ; wd31e - ld a, [$ffdb] + ld hl, wBagItems + ld a, [hItemToRemoveID] ld b, a xor a - ld [$ffdc], a + ld [hItemToRemoveIndex], a .asm_17f40 ld a, [hli] cp $ff @@ -129,14 +128,14 @@ RemoveItemByID: ; 17f37 (5:7f37) cp b jr z, .asm_17f4f inc hl - ld a, [$ffdc] + ld a, [hItemToRemoveIndex] inc a - ld [$ffdc], a + ld [hItemToRemoveIndex], a jr .asm_17f40 .asm_17f4f ld a, $1 - ld [wcf96], a - ld a, [$ffdc] - ld [wWhichPokemon], a ; wWhichPokemon - ld hl, wNumBagItems ; wNumBagItems + ld [wItemQuantity], a + ld a, [hItemToRemoveIndex] + ld [wWhichPokemon], a + ld hl, wNumBagItems jp RemoveItemFromInventory diff --git a/engine/menu/players_pc.asm b/engine/menu/players_pc.asm index 147a27a4..00889e93 100755 --- a/engine/menu/players_pc.asm +++ b/engine/menu/players_pc.asm @@ -5,238 +5,240 @@ PlayerPC: ; 78e6 (1:78e6) ld [wNameListType], a call SaveScreenTilesToBuffer1 xor a - ld [wcc2c], a - ld [wccd3], a + ld [wBagSavedMenuItem], a + ld [wParentMenuItem], a ld a, [wFlags_0xcd60] - bit 3, a - jr nz, Func_790c - ld a, (SFX_02_45 - SFX_Headers_02) / 3 + bit 3, a ; accessing player's PC through another PC? + jr nz, PlayerPCMenu +; accessing it directly + ld a, SFX_TURN_ON_PC call PlaySound ld hl, TurnedOnPC2Text call PrintText -Func_790c: ; 790c (1:790c) - ld a, [wccd3] +PlayerPCMenu: ; 790c (1:790c) + ld a, [wParentMenuItem] ld [wCurrentMenuItem], a ld hl, wFlags_0xcd60 set 5, [hl] call LoadScreenTilesFromBuffer2 - ld hl, wTileMap + coord hl, 0, 0 ld b, $8 ld c, $e call TextBoxBorder call UpdateSprites - hlCoord 2, 2 + coord hl, 2, 2 ld de, PlayersPCMenuEntries call PlaceString ld hl, wTopMenuItemY - ld a, $2 - ld [hli], a + ld a, 2 + ld [hli], a ; wTopMenuItemY dec a - ld [hli], a + ld [hli], a ; wTopMenuItemX inc hl inc hl - ld a, $3 - ld [hli], a - ld a, $3 - ld [hli], a + ld a, 3 + ld [hli], a ; wMaxMenuItem + ld a, A_BUTTON | B_BUTTON + ld [hli], a ; wMenuWatchedKeys xor a ld [hl], a ld hl, wListScrollOffset - ld [hli], a - ld [hl], a + ld [hli], a ; wListScrollOffset + ld [hl], a ; wMenuWatchMovingOutOfBounds ld [wPlayerMonNumber], a ld hl, WhatDoYouWantText call PrintText call HandleMenuInput bit 1, a - jp nz, Func_796d + jp nz, ExitPlayerPC call PlaceUnfilledArrowMenuCursor ld a, [wCurrentMenuItem] - ld [wccd3], a + ld [wParentMenuItem], a and a - jp z, Func_7a12 + jp z, PlayerPCWithdraw dec a - jp z, Func_7995 + jp z, PlayerPCDeposit dec a - jp z, Func_7a8f + jp z, PlayerPCToss -Func_796d: ; 796d (1:796d) +ExitPlayerPC: ; 796d (1:796d) ld a, [wFlags_0xcd60] - bit 3, a - jr nz, .asm_797c - ld a, (SFX_02_46 - SFX_Headers_02) / 3 + bit 3, a ; accessing player's PC through another PC? + jr nz, .next +; accessing it directly + ld a, SFX_TURN_OFF_PC call PlaySound call WaitForSoundToFinish -.asm_797c +.next ld hl, wFlags_0xcd60 res 5, [hl] call LoadScreenTilesFromBuffer2 xor a ld [wListScrollOffset], a - ld [wcc2c], a + ld [wBagSavedMenuItem], a ld hl, wd730 res 6, [hl] xor a ld [wDoNotWaitForButtonPressAfterDisplayingText], a ret -Func_7995: ; 7995 (1:7995) +PlayerPCDeposit: ; 7995 (1:7995) xor a ld [wCurrentMenuItem], a ld [wListScrollOffset], a ld a, [wNumBagItems] and a - jr nz, Func_79ab + jr nz, .loop ld hl, NothingToDepositText call PrintText - jp Func_790c - -Func_79ab: ; 79ab (1:79ab) + jp PlayerPCMenu +.loop ld hl, WhatToDepositText call PrintText ld hl, wNumBagItems ld a, l - ld [wList], a + ld [wListPointer], a ld a, h - ld [wList + 1], a + ld [wListPointer + 1], a xor a - ld [wcf93], a - ld a, $3 + ld [wPrintItemPrices], a + ld a, ITEMLISTMENU ld [wListMenuID], a call DisplayListMenuID - jp c, Func_790c + jp c, PlayerPCMenu call IsKeyItem - ld a, $1 - ld [wcf96], a - ld a, [wd124] + ld a, 1 + ld [wItemQuantity], a + ld a, [wIsKeyItem] and a - jr nz, .asm_79e7 + jr nz, .next +; if it's not a key item, there can be more than one of the item ld hl, DepositHowManyText call PrintText call DisplayChooseQuantityMenu cp $ff - jp z, Func_79ab -.asm_79e7 + jp z, .loop +.next ld hl, wNumBoxItems call AddItemToInventory - jr c, .asm_79f8 + jr c, .roomAvailable ld hl, NoRoomToStoreText call PrintText - jp Func_79ab -.asm_79f8 + jp .loop +.roomAvailable ld hl, wNumBagItems call RemoveItemFromInventory call WaitForSoundToFinish - ld a, (SFX_02_55 - SFX_Headers_02) / 3 + ld a, SFX_WITHDRAW_DEPOSIT call PlaySound call WaitForSoundToFinish ld hl, ItemWasStoredText call PrintText - jp Func_79ab + jp .loop -Func_7a12: ; 7a12 (1:7a12) +PlayerPCWithdraw: ; 7a12 (1:7a12) xor a ld [wCurrentMenuItem], a ld [wListScrollOffset], a ld a, [wNumBoxItems] and a - jr nz, Func_7a28 + jr nz, .loop ld hl, NothingStoredText call PrintText - jp Func_790c - -Func_7a28: ; 7a28 (1:7a28) + jp PlayerPCMenu +.loop ld hl, WhatToWithdrawText call PrintText ld hl, wNumBoxItems ld a, l - ld [wList], a + ld [wListPointer], a ld a, h - ld [wList + 1], a + ld [wListPointer + 1], a xor a - ld [wcf93], a - ld a, $3 + ld [wPrintItemPrices], a + ld a, ITEMLISTMENU ld [wListMenuID], a call DisplayListMenuID - jp c, Func_790c + jp c, PlayerPCMenu call IsKeyItem - ld a, $1 - ld [wcf96], a - ld a, [wd124] + ld a, 1 + ld [wItemQuantity], a + ld a, [wIsKeyItem] and a - jr nz, .asm_7a64 + jr nz, .next +; if it's not a key item, there can be more than one of the item ld hl, WithdrawHowManyText call PrintText call DisplayChooseQuantityMenu cp $ff - jp z, Func_7a28 -.asm_7a64 + jp z, .loop +.next ld hl, wNumBagItems call AddItemToInventory - jr c, .asm_7a75 + jr c, .roomAvailable ld hl, CantCarryMoreText call PrintText - jp Func_7a28 -.asm_7a75 + jp .loop +.roomAvailable ld hl, wNumBoxItems call RemoveItemFromInventory call WaitForSoundToFinish - ld a, (SFX_02_55 - SFX_Headers_02) / 3 + ld a, SFX_WITHDRAW_DEPOSIT call PlaySound call WaitForSoundToFinish ld hl, WithdrewItemText call PrintText - jp Func_7a28 + jp .loop -Func_7a8f: ; 7a8f (1:7a8f) +PlayerPCToss: ; 7a8f (1:7a8f) xor a ld [wCurrentMenuItem], a ld [wListScrollOffset], a ld a, [wNumBoxItems] and a - jr nz, Func_7aa5 + jr nz, .loop ld hl, NothingStoredText call PrintText - jp Func_790c - -Func_7aa5: ; 7aa5 (1:7aa5) + jp PlayerPCMenu +.loop ld hl, WhatToTossText call PrintText ld hl, wNumBoxItems ld a, l - ld [wList], a + ld [wListPointer], a ld a, h - ld [wList + 1], a + ld [wListPointer + 1], a xor a - ld [wcf93], a - ld a, $3 + ld [wPrintItemPrices], a + ld a, ITEMLISTMENU ld [wListMenuID], a push hl call DisplayListMenuID pop hl - jp c, Func_790c + jp c, PlayerPCMenu push hl call IsKeyItem pop hl - ld a, $1 - ld [wcf96], a - ld a, [wd124] + ld a, 1 + ld [wItemQuantity], a + ld a, [wIsKeyItem] and a - jr nz, .asm_7aef + jr nz, .next ld a, [wcf91] call IsItemHM - jr c, .asm_7aef + jr c, .next +; if it's not a key item, there can be more than one of the item push hl ld hl, TossHowManyText call PrintText call DisplayChooseQuantityMenu pop hl cp $ff - jp z, Func_7aa5 -.asm_7aef - call TossItem - jp Func_7aa5 + jp z, .loop +.next + call TossItem ; disallows tossing key items + jp .loop PlayersPCMenuEntries: ; 7af5 (1:7af5) db "WITHDRAW ITEM" diff --git a/engine/menu/pokedex.asm b/engine/menu/pokedex.asm index bd4c40bd..7953b849 100755 --- a/engine/menu/pokedex.asm +++ b/engine/menu/pokedex.asm @@ -1,7 +1,7 @@ ShowPokedexMenu: ; 40000 (10:4000) call GBPalWhiteOut call ClearScreen - call UpdateSprites ; move sprites + call UpdateSprites ld a,[wListScrollOffset] push af xor a @@ -12,8 +12,8 @@ ShowPokedexMenu: ; 40000 (10:4000) ld [wd11e],a ld [hJoy7],a .setUpGraphics - ld b,$08 - call GoPAL_SET + ld b, SET_PAL_GENERIC + call RunPaletteCommand callab LoadPokedexTilePatterns .doPokemonListMenu ld hl,wTopMenuItemY @@ -22,17 +22,17 @@ ShowPokedexMenu: ; 40000 (10:4000) xor a ld [hli],a ; top menu item X inc a - ld [wcc37],a + ld [wMenuWatchMovingOutOfBounds],a inc hl inc hl ld a,6 ld [hli],a ; max menu item ID - ld [hl],%00110011 ; menu watched keys (Left, Right, B button, A button) + ld [hl],D_LEFT | D_RIGHT | B_BUTTON | A_BUTTON call HandlePokedexListMenu jr c,.goToSideMenu ; if the player chose a pokemon from the list .exitPokedex xor a - ld [wcc37],a + ld [wMenuWatchMovingOutOfBounds],a ld [wCurrentMenuItem],a ld [wLastMenuItem],a ld [hJoy7],a @@ -41,7 +41,7 @@ ShowPokedexMenu: ; 40000 (10:4000) pop af ld [wListScrollOffset],a call GBPalWhiteOutWithDelay3 - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand jp ReloadMapData .goToSideMenu call HandlePokedexSideMenu @@ -71,8 +71,8 @@ HandlePokedexSideMenu: ; 4006d (10:406d) ld [wd11e],a ld a,[wd11e] push af - ld a,[wWhichTrade] - push af + ld a,[wDexMaxSeenMon] + push af ; this doesn't need to be preserved ld hl,wPokedexSeen call IsPokemonBitSet ld b,2 @@ -88,10 +88,11 @@ HandlePokedexSideMenu: ; 4006d (10:406d) inc hl ld a,3 ld [hli],a ; max menu item ID + ;ld a, A_BUTTON | B_BUTTON ld [hli],a ; menu watched keys (A button and B button) xor a ld [hli],a ; old menu item ID - ld [wcc37],a + ld [wMenuWatchMovingOutOfBounds],a .handleMenuInput call HandleMenuInput bit 1,a ; was the B button pressed? @@ -108,7 +109,7 @@ HandlePokedexSideMenu: ; 4006d (10:406d) ld b,1 .exitSideMenu pop af - ld [wWhichTrade],a + ld [wDexMaxSeenMon],a pop af ld [wd11e],a pop af @@ -118,17 +119,17 @@ HandlePokedexSideMenu: ; 4006d (10:406d) pop af ld [wCurrentMenuItem],a push bc - hlCoord 0, 3 + coord hl, 0, 3 ld de,20 - ld bc,$7f0d ; 13 blank tiles + lb bc, " ", 13 call DrawTileLine ; cover up the menu cursor in the pokemon list pop bc ret .buttonBPressed push bc - hlCoord 15, 10 + coord hl, 15, 10 ld de,20 - ld bc,$7f07 ; 7 blank tiles + lb bc, " ", 7 call DrawTileLine ; cover up the menu cursor in the side menu pop bc jr .exitSideMenu @@ -139,8 +140,8 @@ HandlePokedexSideMenu: ; 4006d (10:406d) ; play pokemon cry .choseCry ld a,[wd11e] - call GetCryData ; get cry data - call PlaySound ; play sound + call GetCryData + call PlaySound jr .handleMenuInput .choseArea predef LoadTownMap_Nest ; display pokemon areas @@ -153,43 +154,43 @@ HandlePokedexListMenu: ; 40111 (10:4111) xor a ld [H_AUTOBGTRANSFERENABLED],a ; draw the horizontal line separating the seen and owned amounts from the menu - hlCoord 15, 8 + coord hl, 15, 8 ld a,$7a ; horizontal line tile ld [hli],a ld [hli],a ld [hli],a ld [hli],a ld [hli],a - hlCoord 14, 0 + coord hl, 14, 0 ld [hl],$71 ; vertical line tile - hlCoord 14, 1 + coord hl, 14, 1 call DrawPokedexVerticalLine - hlCoord 14, 9 + coord hl, 14, 9 call DrawPokedexVerticalLine ld hl,wPokedexSeen ld b,wPokedexSeenEnd - wPokedexSeen call CountSetBits - ld de,wd11e - hlCoord 16, 3 - ld bc,$0103 + ld de, wNumSetBits + coord hl, 16, 3 + lb bc, 1, 3 call PrintNumber ; print number of seen pokemon ld hl,wPokedexOwned ld b,wPokedexOwnedEnd - wPokedexOwned call CountSetBits - ld de,wd11e - hlCoord 16, 6 - ld bc,$0103 + ld de, wNumSetBits + coord hl, 16, 6 + lb bc, 1, 3 call PrintNumber ; print number of owned pokemon - hlCoord 16, 2 + coord hl, 16, 2 ld de,PokedexSeenText call PlaceString - hlCoord 16, 5 + coord hl, 16, 5 ld de,PokedexOwnText call PlaceString - hlCoord 1, 1 + coord hl, 1, 1 ld de,PokedexContentsText call PlaceString - hlCoord 16, 10 + coord hl, 16, 10 ld de,PokedexMenuItemsText call PlaceString ; find the highest pokedex number among the pokemon the player has seen @@ -207,18 +208,18 @@ HandlePokedexListMenu: ; 40111 (10:4111) jr .maxSeenPokemonLoop .storeMaxSeenPokemon ld a,b - ld [wWhichTrade],a ; max seen pokemon + ld [wDexMaxSeenMon],a .loop xor a ld [H_AUTOBGTRANSFERENABLED],a - hlCoord 4, 2 - ld bc,$0e0a + coord hl, 4, 2 + lb bc, 14, 10 call ClearScreenArea - hlCoord 1, 3 + coord hl, 1, 3 ld a,[wListScrollOffset] ld [wd11e],a ld d,7 - ld a,[wWhichTrade] + ld a,[wDexMaxSeenMon] cp a,7 jr nc,.printPokemonLoop ld d,a @@ -233,12 +234,12 @@ HandlePokedexListMenu: ; 40111 (10:4111) push af push de push hl - ld de,-20 + ld de,-SCREEN_WIDTH add hl,de ld de,wd11e - ld bc,$8103 + lb bc, LEADING_ZEROES | 1, 3 call PrintNumber ; print the pokedex number - ld de,20 + ld de,SCREEN_WIDTH add hl,de dec hl push hl @@ -294,9 +295,9 @@ HandlePokedexListMenu: ; 40111 (10:4111) bit 7,a ; was Down pressed? jr z,.checkIfRightPressed .downPressed ; scroll down one row - ld a,[wWhichTrade] + ld a,[wDexMaxSeenMon] cp a,7 - jp c,.loop + jp c,.loop ; can't if the list is shorter than 7 sub a,7 ld b,a ld a,[wListScrollOffset] @@ -309,9 +310,9 @@ HandlePokedexListMenu: ; 40111 (10:4111) bit 4,a ; was Right pressed? jr z,.checkIfLeftPressed .rightPressed ; scroll down 7 rows - ld a,[wWhichTrade] + ld a,[wDexMaxSeenMon] cp a,7 - jp c,.loop + jp c,.loop ; can't if the list is shorter than 7 sub a,6 ld b,a ld a,[wListScrollOffset] @@ -377,7 +378,7 @@ IsPokemonBitSet: ; 402c2 (10:42c2) ld a,[wd11e] dec a ld c,a - ld b,2 + ld b,FLAG_TEST predef FlagActionPredef ld a,c and a @@ -395,32 +396,32 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2) ld hl,wd72c set 1,[hl] ld a,$33 ; 3/7 volume - ld [$ff24],a + ld [rNR50],a call GBPalWhiteOut ; zero all palettes call ClearScreen ld a,[wd11e] ; pokemon ID ld [wcf91],a push af - ld b,04 - call GoPAL_SET + ld b, SET_PAL_POKEDEX + call RunPaletteCommand pop af ld [wd11e],a ld a,[hTilesetType] push af xor a ld [hTilesetType],a - hlCoord 0, 0 + coord hl, 0, 0 ld de,1 - ld bc,$6414 + lb bc, $64, SCREEN_WIDTH call DrawTileLine ; draw top border - hlCoord 0, 17 - ld b,$6f + coord hl, 0, 17 + ld b, $6f call DrawTileLine ; draw bottom border - hlCoord 0, 1 + coord hl, 0, 1 ld de,20 - ld bc,$6610 + lb bc, $66, $10 call DrawTileLine ; draw left border - hlCoord 19, 1 + coord hl, 19, 1 ld b,$67 call DrawTileLine ; draw right border ld a,$63 ; upper left corner tile @@ -431,14 +432,14 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2) Coorda 0, 17 ld a,$6e ; lower right corner tile Coorda 19, 17 - hlCoord 0, 9 + coord hl, 0, 9 ld de,PokedexDataDividerLine call PlaceString ; draw horizontal divider line - hlCoord 9, 6 + coord hl, 9, 6 ld de,HeightWeightText call PlaceString call GetMonName - hlCoord 9, 2 + coord hl, 9, 2 call PlaceString ld hl,PokedexEntryPointers ld a,[wd11e] @@ -450,7 +451,7 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2) ld a,[hli] ld e,a ld d,[hl] ; de = address of pokedex entry - hlCoord 9, 4 + coord hl, 9, 4 call PlaceString ; print species name ld h,b ld l,c @@ -458,13 +459,13 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2) ld a,[wd11e] push af call IndexToPokedex - hlCoord 2, 8 + coord hl, 2, 8 ld a, "№" ld [hli],a ld a,$f2 ld [hli],a ld de,wd11e - ld bc,$8103 + lb bc, LEADING_ZEROES | 1, 3 call PrintNumber ; print pokedex number ld hl,wPokedexOwned call IsPokemonBitSet @@ -480,7 +481,7 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2) call Delay3 call GBPalNormal call GetMonHeader ; load pokemon picture location - hlCoord 1, 1 + coord hl, 1, 1 call LoadFlippedFrontSpriteByMonIndex ; draw pokemon picture ld a,[wcf91] call PlayCry ; play pokemon cry @@ -493,15 +494,15 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2) jp z,.waitForButtonPress ; if the pokemon has not been owned, don't print the height, weight, or description inc de ; de = address of feet (height) ld a,[de] ; reads feet, but a is overwritten without being used - hlCoord 12, 6 - ld bc,$0102 + coord hl, 12, 6 + lb bc, 1, 2 call PrintNumber ; print feet (height) ld a,$60 ; feet symbol tile (one tick) ld [hl],a inc de inc de ; de = address of inches (height) - hlCoord 15, 6 - ld bc,$8102 + coord hl, 15, 6 + lb bc, LEADING_ZEROES | 1, 2 call PrintNumber ; print inches (height) ld a,$61 ; inches symbol tile (two ticks) ld [hl],a @@ -510,25 +511,25 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2) inc de inc de ; de = address of upper byte of weight push de -; put weight in big-endian order at $ff8b - ld hl,$ff8b - ld a,[hl] ; save existing value of [$ff8b] +; put weight in big-endian order at hDexWeight + ld hl,hDexWeight + ld a,[hl] ; save existing value of [hDexWeight] push af ld a,[de] ; a = upper byte of weight - ld [hli],a ; store upper byte of weight in [$ff8b] - ld a,[hl] ; save existing value of [$ff8c] + ld [hli],a ; store upper byte of weight in [hDexWeight] + ld a,[hl] ; save existing value of [hDexWeight + 1] push af dec de ld a,[de] ; a = lower byte of weight - ld [hl],a ; store lower byte of weight in [$ff8c] - ld de,$ff8b - hlCoord 11, 8 - ld bc,$0205 ; no leading zeroes, right-aligned, 2 bytes, 5 digits + ld [hl],a ; store lower byte of weight in [hDexWeight + 1] + ld de,hDexWeight + coord hl, 11, 8 + lb bc, 2, 5 ; 2 bytes, 5 digits call PrintNumber ; print weight - hlCoord 14, 8 - ld a,[$ff8c] + coord hl, 14, 8 + ld a,[hDexWeight + 1] sub a,10 - ld a,[$ff8b] + ld a,[hDexWeight] sbc a,0 jr nc,.next ld [hl],"0" ; if the weight is less than 10, put a 0 before the decimal point @@ -538,12 +539,12 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2) ld [hld],a ; make space for the decimal point by moving the last digit forward one tile ld [hl],$f2 ; decimal point tile pop af - ld [$ff8c],a ; restore original value of [$ff8c] + ld [hDexWeight + 1],a ; restore original value of [hDexWeight + 1] pop af - ld [$ff8b],a ; restore original value of [$ff8b] + ld [hDexWeight],a ; restore original value of [hDexWeight] pop hl inc hl ; hl = address of pokedex description text - bcCoord 1, 11 + coord bc, 1, 11 ld a,2 ld [$fff4],a call TextCommandProcessor ; print pokedex description text @@ -552,27 +553,27 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2) .waitForButtonPress call JoypadLowSensitivity ld a,[hJoy5] - and a,%00000011 ; A button and B button + and a,A_BUTTON | B_BUTTON jr z,.waitForButtonPress pop af ld [hTilesetType],a call GBPalWhiteOut call ClearScreen - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand call LoadTextBoxTilePatterns call GBPalNormal ld hl,wd72c res 1,[hl] ld a,$77 ; max volume - ld [$ff24],a + ld [rNR50],a ret HeightWeightText: ; 40448 (10:4448) db "HT ?",$60,"??",$61,$4E,"WT ???lb@" ; XXX does anything point to this? -Unknown_4045D: ; 4045d (10:445d) - db $54,$50 +PokeText: ; 4045d (10:445d) + db "#@" ; horizontal line that divides the pokedex text description from the rest of the data PokedexDataDividerLine: ; 4045f (10:445f) diff --git a/engine/menu/prize_menu.asm b/engine/menu/prize_menu.asm index 0e904200..409f0bdb 100755 --- a/engine/menu/prize_menu.asm +++ b/engine/menu/prize_menu.asm @@ -13,7 +13,7 @@ CeladonPrizeMenu: ; 5271b (14:671b) xor a ld [wCurrentMenuItem],a ld [wLastMenuItem],a - ld a,$03 + ld a,A_BUTTON | B_BUTTON ld [wMenuWatchedKeys],a ld a,$03 ld [wMaxMenuItem],a @@ -21,12 +21,12 @@ CeladonPrizeMenu: ; 5271b (14:671b) ld [wTopMenuItemY],a ld a,$01 ld [wTopMenuItemX],a - call PrintPrizePrice ; 687A - hlCoord 0, 2 + call PrintPrizePrice + coord hl, 0, 2 ld b,$08 ld c,$10 call TextBoxBorder - call GetPrizeMenuId ;678E + call GetPrizeMenuId call UpdateSprites ld hl,WhichPrizeTextPtr call PrintText @@ -36,7 +36,7 @@ CeladonPrizeMenu: ; 5271b (14:671b) ld a,[wCurrentMenuItem] cp a,$03 ; "NO,THANKS" choice jr z,.NoChoice - call HandlePrizeChoice ; 14:68C6 + call HandlePrizeChoice .NoChoice ld hl,wd730 res 6,[hl] @@ -58,18 +58,18 @@ WhichPrizeTextPtr: ; 52789 (14:6789) GetPrizeMenuId: ; 5278e (14:678e) ; determine which one among the three ; prize-texts has been selected -; using the text ID (stored in [$FF8C]) +; using the text ID (stored in [hSpriteIndexOrTextID]) ; load the three prizes at wd13d-wd13f ; load the three prices at wd141-wd146 ; display the three prizes' names ; (distinguishing between Pokemon names ; and Items (specifically TMs) names) - ld a,[$FF8C] - sub a,$03 ; prize-texts' id are 3, 4 and 5 - ld [wd12f],a ; prize-texts' id (relative, i.e. 0, 1 or 2) + ld a,[hSpriteIndexOrTextID] + sub a,3 ; prize-texts' id are 3, 4 and 5 + ld [wWhichPrizeWindow],a ; prize-texts' id (relative, i.e. 0, 1 or 2) add a add a - ld d,$00 + ld d,0 ld e,a ld hl,PrizeDifferentMenuPtrs add hl,de @@ -79,178 +79,184 @@ GetPrizeMenuId: ; 5278e (14:678e) inc hl push hl ld hl,W_PRIZE1 - call CopyString ; XXX what does this do + call CopyString pop hl ld a,[hli] ld h,[hl] ld l,a - ld de,wd141 - ld bc,$0006 + ld de,wPrize1Price + ld bc,6 call CopyData - ld a,[wd12f] + ld a,[wWhichPrizeWindow] cp a,$02 ;is TM_menu? jr nz,.putMonName ld a,[W_PRIZE1] ld [wd11e],a call GetItemName - hlCoord 2, 4 + coord hl, 2, 4 call PlaceString ld a,[W_PRIZE2] ld [wd11e],a call GetItemName - hlCoord 2, 6 + coord hl, 2, 6 call PlaceString ld a,[W_PRIZE3] ld [wd11e],a call GetItemName - hlCoord 2, 8 + coord hl, 2, 8 call PlaceString jr .putNoThanksText -.putMonName ; 14:67EC +.putMonName ld a,[W_PRIZE1] ld [wd11e],a call GetMonName - hlCoord 2, 4 + coord hl, 2, 4 call PlaceString ld a,[W_PRIZE2] ld [wd11e],a call GetMonName - hlCoord 2, 6 + coord hl, 2, 6 call PlaceString ld a,[W_PRIZE3] ld [wd11e],a call GetMonName - hlCoord 2, 8 + coord hl, 2, 8 call PlaceString -.putNoThanksText ; 14:6819 - hlCoord 2, 10 +.putNoThanksText + coord hl, 2, 10 ld de,NoThanksText call PlaceString ; put prices on the right side of the textbox - ld de,wd141 - hlCoord 13, 5 + ld de,wPrize1Price + coord hl, 13, 5 ; reg. c: ; [low nybble] number of bytes ; [bit 765 = %100] space-padding (not zero-padding) ld c,(1 << 7 | 2) ; Function $15CD displays BCD value (same routine ; used by text-command $02) - call PrintBCDNumber ; Print_BCD - ld de,wd143 - hlCoord 13, 7 + call PrintBCDNumber + ld de,wPrize2Price + coord hl, 13, 7 ld c,(%1 << 7 | 2) call PrintBCDNumber - ld de,wd145 - hlCoord 13, 9 + ld de,wPrize3Price + coord hl, 13, 9 ld c,(1 << 7 | 2) jp PrintBCDNumber INCLUDE "data/prizes.asm" PrintPrizePrice: ; 5287a (14:687a) - hlCoord 11, 0 + coord hl, 11, 0 ld b,$01 ld c,$07 call TextBoxBorder - call UpdateSprites ; XXX save OAM? - hlCoord 12, 0 + call UpdateSprites + coord hl, 12, 0 ld de,.CoinText call PlaceString - hlCoord 13, 1 + coord hl, 13, 1 ld de,.SixSpacesText call PlaceString - hlCoord 13, 1 + coord hl, 13, 1 ld de,wPlayerCoins ld c,%10000010 call PrintBCDNumber ret -.CoinText ; 14:68A5 +.CoinText db "COIN@" -.SixSpacesText ; 14:68AA +.SixSpacesText db " @" LoadCoinsToSubtract: ; 528b1 (14:68b1) - ld a,[wd139] ; backup of selected menu_entry + ld a,[wWhichPrize] add a - ld d,$00 + ld d,0 ld e,a - ld hl,wd141 ; first prize's price + ld hl,wPrize1Price add hl,de ; get selected prize's price xor a - ld [$FF9F],a + ld [hUnusedCoinsByte],a ld a,[hli] - ld [$FFA0],a + ld [hCoins],a ld a,[hl] - ld [$FFA1],a + ld [hCoins + 1],a ret HandlePrizeChoice: ; 528c6 (14:68c6) - ld a,[wCurrentMenuItem] ; selected menu_entry - ld [wd139],a - ld d,$00 + ld a,[wCurrentMenuItem] + ld [wWhichPrize],a + ld d,0 ld e,a ld hl,W_PRIZE1 add hl,de ld a,[hl] ld [wd11e],a - ld a,[wd12f] + ld a,[wWhichPrizeWindow] cp a,$02 ; is prize a TM? jr nz,.GetMonName call GetItemName jr .GivePrize -.GetMonName ; 14:68E3 +.GetMonName call GetMonName -.GivePrize ; 14:68E6 +.GivePrize ld hl,SoYouWantPrizeTextPtr call PrintText - call YesNoChoice ; yes/no textbox + call YesNoChoice ld a,[wCurrentMenuItem] ; yes/no answer (Y=0, N=1) and a jr nz,.PrintOhFineThen call LoadCoinsToSubtract call HasEnoughCoins jr c,.NotEnoughCoins - ld a,[wd12f] + ld a,[wWhichPrizeWindow] cp a,$02 jr nz,.GiveMon ld a,[wd11e] ld b,a ld a,1 ld c,a - call GiveItem ; GiveItem + call GiveItem jr nc,.BagFull jr .SubtractCoins -.GiveMon ; 14:6912 +.GiveMon ld a,[wd11e] ld [wcf91],a push af - call GetPrizeMonLevel ; 14:6977 + call GetPrizeMonLevel ld c,a pop af ld b,a call GivePokemon + +; If either the party or box was full, wait after displaying message. push af - ld a,[wccd3] ; XXX is there room? + ld a,[wAddedToParty] and a call z,WaitForTextScrollButtonPress pop af + +; If the mon couldn't be given to the player (because both the party and box +; were full), return without subtracting coins. ret nc -.SubtractCoins ; 14:692C + +.SubtractCoins call LoadCoinsToSubtract - ld hl,$FFA1 + ld hl,hCoins + 1 ld de,wPlayerCoins + 1 ld c,$02 ; how many bytes - predef SubBCDPredef ; subtract coins (BCD daa operations) + predef SubBCDPredef jp PrintPrizePrice .BagFull ld hl,PrizeRoomBagIsFullTextPtr jp PrintText -.NotEnoughCoins ; 14:6945 +.NotEnoughCoins ld hl,SorryNeedMoreCoinsText jp PrintText -.PrintOhFineThen ; 14:694B +.PrintOhFineThen ld hl,OhFineThenTextPtr jp PrintText @@ -286,13 +292,13 @@ GetPrizeMonLevel: ; 52977 (14:6977) ld a,[wcf91] ld b,a ld hl,PrizeMonLevelDictionary -.loop ; 14:697E +.loop ld a,[hli] cp b jr z,.matchFound inc hl jr .loop -.matchFound ; 14:6985 +.matchFound ld a,[hl] ld [W_CURENEMYLVL],a ret diff --git a/engine/menu/start_menu.asm b/engine/menu/start_menu.asm index 3c3b837c..adedc263 100755 --- a/engine/menu/start_menu.asm +++ b/engine/menu/start_menu.asm @@ -8,7 +8,7 @@ DisplayStartMenu:: ; 29d1 (0:29d1) RedisplayStartMenu:: ; 29e1 (0:29e1) callba DrawStartMenu callba PrintSafariZoneSteps ; print Safari Zone info, if in Safari Zone - call UpdateSprites ; move sprites + call UpdateSprites .loop call HandleMenuInput ld b,a @@ -52,7 +52,7 @@ RedisplayStartMenu:: ; 29e1 (0:29e1) .buttonPressed ; A, B, or Start button pressed call PlaceUnfilledArrowMenuCursor ld a,[wCurrentMenuItem] - ld [wcc2d],a ; save current menu item ID + ld [wBattleAndStartSavedMenuItem],a ; save current menu selection ld a,b and a,%00001010 ; was the Start button or B button pressed? jp nz,CloseStartMenu diff --git a/engine/menu/start_sub_menus.asm b/engine/menu/start_sub_menus.asm index 589224ab..ab8c8756 100755 --- a/engine/menu/start_sub_menus.asm +++ b/engine/menu/start_sub_menus.asm @@ -12,14 +12,14 @@ StartMenu_Pokemon: ; 130a9 (4:70a9) jp z,RedisplayStartMenu xor a ld [wMenuItemToSwap],a - ld [wd07d],a + ld [wPartyMenuTypeOrMessageID],a ld [wUpdateSpritesEnabled],a call DisplayPartyMenu jr .checkIfPokemonChosen .loop xor a ld [wMenuItemToSwap],a - ld [wd07d],a + ld [wPartyMenuTypeOrMessageID],a call GoBackToPartyMenu .checkIfPokemonChosen jr nc,.chosePokemon @@ -33,14 +33,14 @@ StartMenu_Pokemon: ; 130a9 (4:70a9) ld a,FIELD_MOVE_MON_MENU ld [wTextBoxID],a call DisplayTextBoxID ; display pokemon menu options - ld hl,wWhichTrade - ld bc,$020c ; max menu item ID, top menu item Y + ld hl,wFieldMoves + lb bc, $02, $0c ; max menu item ID, top menu item Y ld e,5 .adjustMenuVariablesLoop dec e jr z,.storeMenuVariables ld a,[hli] - and a + and a ; end of field moves? jr z,.storeMenuVariables inc b dec c @@ -50,14 +50,14 @@ StartMenu_Pokemon: ; 130a9 (4:70a9) ld hl,wTopMenuItemY ld a,c ld [hli],a ; top menu item Y - ld a,[$fff7] + ld a,[hFieldMoveMonMenuTopMenuItemX] ld [hli],a ; top menu item X xor a ld [hli],a ; current menu item ID inc hl ld a,b ld [hli],a ; max menu item ID - ld a,%00000011 ; A button, B button + ld a,A_BUTTON | B_BUTTON ld [hli],a ; menu watched keys xor a ld [hl],a @@ -81,22 +81,22 @@ StartMenu_Pokemon: ; 130a9 (4:70a9) jp z,.choseStats ld c,a ld b,0 - ld hl,wWhichTrade + ld hl,wFieldMoves add hl,bc jp .choseOutOfBattleMove .choseSwitch ld a,[wPartyCount] cp a,2 ; is there more than one pokemon in the party? jp c,StartMenu_Pokemon ; if not, no switching - call SwitchPartyMon_Stats - ld a,$04 ; swap pokemon positions menu - ld [wd07d],a + call SwitchPartyMon_InitVarOrSwapData ; init [wMenuItemToSwap] + ld a,SWAP_MONS_PARTY_MENU + ld [wPartyMenuTypeOrMessageID],a call GoBackToPartyMenu jp .checkIfPokemonChosen .choseStats call ClearSprites - xor a - ld [wcc49],a + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation],a predef StatusScreen predef StatusScreen2 call ReloadMapData @@ -153,7 +153,7 @@ StartMenu_Pokemon: ; 130a9 (4:70a9) bit 1,a ; does the player have the Cascade Badge? jp z,.newBadgeRequired predef UsedCut - ld a,[wcd6a] + ld a,[wActionResultOrTookBattleTurn] and a jp z,.loop jp CloseTextDisplay @@ -167,9 +167,9 @@ StartMenu_Pokemon: ; 130a9 (4:70a9) jp z,.loop ld a,SURFBOARD ld [wcf91],a - ld [wd152],a + ld [wPseudoItemID],a call UseItem - ld a,[wcd6a] + ld a,[wActionResultOrTookBattleTurn] and a jp z,.loop call GBPalWhiteOutWithDelay3 @@ -195,9 +195,9 @@ StartMenu_Pokemon: ; 130a9 (4:70a9) .dig ld a,ESCAPE_ROPE ld [wcf91],a - ld [wd152],a + ld [wPseudoItemID],a call UseItem - ld a,[wcd6a] + ld a,[wActionResultOrTookBattleTurn] and a jp z,.loop call GBPalWhiteOutWithDelay3 @@ -256,14 +256,14 @@ StartMenu_Pokemon: ; 130a9 (4:70a9) ld a,[H_QUOTIENT + 2] sbc b jp nc,.notHealthyEnough - ld a,[wcc2b] + ld a,[wPartyAndBillsPCSavedMenuItem] push af ld a,POTION ld [wcf91],a - ld [wd152],a + ld [wPseudoItemID],a call UseItem pop af - ld [wcc2b],a + ld [wPartyAndBillsPCSavedMenuItem],a jp .loop .notHealthyEnough ; if current HP is less than 1/5 of max HP ld hl,.notHealthyEnoughText @@ -285,7 +285,7 @@ StartMenu_Pokemon: ; 130a9 (4:70a9) ; writes a blank tile to all possible menu cursor positions on the party menu ErasePartyMenuCursors: ; 132ed (4:72ed) - hlCoord 0, 1 + coord hl, 0, 1 ld bc,2 * 20 ; menu cursor positions are 2 rows apart ld a,6 ; 6 menu cursor positions .loop @@ -297,7 +297,7 @@ ErasePartyMenuCursors: ; 132ed (4:72ed) ItemMenuLoop: ; 132fc (4:72fc) call LoadScreenTilesFromBuffer2DisableBGTransfer ; restore saved screen - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand StartMenu_Item: ; 13302 (4:7302) ld a,[wLinkState] @@ -308,24 +308,24 @@ StartMenu_Item: ; 13302 (4:7302) jr .exitMenu .notInCableClubRoom ld bc,wNumBagItems - ld hl,wList + ld hl,wListPointer ld a,c ld [hli],a - ld [hl],b ; store item bag pointer at wList (for DisplayListMenuID) + ld [hl],b ; store item bag pointer in wListPointer (for DisplayListMenuID) xor a - ld [wcf93],a + ld [wPrintItemPrices],a ld a,ITEMLISTMENU ld [wListMenuID],a - ld a,[wcc2c] + ld a,[wBagSavedMenuItem] ld [wCurrentMenuItem],a call DisplayListMenuID ld a,[wCurrentMenuItem] - ld [wcc2c],a + ld [wBagSavedMenuItem],a jr nc,.choseItem .exitMenu call LoadScreenTilesFromBuffer2 ; restore saved screen call LoadTextBoxTilePatterns - call UpdateSprites ; move sprites + call UpdateSprites jp RedisplayStartMenu .choseItem ; erase menu cursor (blank each tile in front of an item name) @@ -354,7 +354,7 @@ StartMenu_Item: ; 13302 (4:7302) inc hl inc a ; a = 1 ld [hli],a ; max menu item ID - ld a,%00000011 ; A button, B button + ld a,A_BUTTON | B_BUTTON ld [hli],a ; menu watched keys xor a ld [hl],a ; old menu item id @@ -381,8 +381,8 @@ StartMenu_Item: ; 13302 (4:7302) ld a,[wCurrentMenuItem] and a jr nz,.tossItem -.useItem - ld [wd152],a +; use item + ld [wPseudoItemID],a ; a must be 0 due to above conditional jump ld a,[wcf91] cp a,HM_01 jr nc,.useItem_partyMenu @@ -399,9 +399,9 @@ StartMenu_Item: ; 13302 (4:7302) jp ItemMenuLoop .useItem_closeMenu xor a - ld [wd152],a + ld [wPseudoItemID],a call UseItem - ld a,[wcd6a] + ld a,[wActionResultOrTookBattleTurn] and a jp z,ItemMenuLoop jp CloseStartMenu @@ -409,7 +409,7 @@ StartMenu_Item: ; 13302 (4:7302) ld a,[wUpdateSpritesEnabled] push af call UseItem - ld a,[wcd6a] + ld a,[wActionResultOrTookBattleTurn] cp a,$02 jp z,.partyMenuNotDisplayed call GBPalWhiteOutWithDelay3 @@ -423,7 +423,7 @@ StartMenu_Item: ; 13302 (4:7302) jp ItemMenuLoop .tossItem call IsKeyItem - ld a,[wd124] + ld a,[wIsKeyItem] and a jr nz,.skipAskingQuantity ld a,[wcf91] @@ -499,21 +499,21 @@ UsableItems_CloseMenu: ; 13459 (4:7459) StartMenu_TrainerInfo: ; 13460 (4:7460) call GBPalWhiteOut call ClearScreen - call UpdateSprites ; move sprites + call UpdateSprites ld a,[hTilesetType] push af xor a ld [hTilesetType],a call DrawTrainerInfo predef DrawBadges ; draw badges - ld b,$0d - call GoPAL_SET + ld b, SET_PAL_TRAINER_CARD + call RunPaletteCommand call GBPalNormal call WaitForTextScrollButtonPress ; wait for button press call GBPalWhiteOut call LoadFontTilePatterns call LoadScreenTilesFromBuffer2 ; restore saved screen - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand call ReloadMapData call LoadGBPal pop af @@ -523,37 +523,37 @@ StartMenu_TrainerInfo: ; 13460 (4:7460) ; loads tile patterns and draws everything except for gym leader faces / badges DrawTrainerInfo: ; 1349a (4:749a) ld de,RedPicFront - ld bc,(BANK(RedPicFront) << 8) | $01 - predef Predef3B + lb bc, BANK(RedPicFront), $01 + predef DisplayPicCenteredOrUpperRight call DisableLCD - hlCoord 0, 2 + coord hl, 0, 2 ld a," " call TrainerInfo_DrawVerticalLine - hlCoord 1, 2 + coord hl, 1, 2 call TrainerInfo_DrawVerticalLine ld hl,vChars2 + $70 ld de,vChars2 ld bc,$70 * 4 call CopyData - ld hl,TrainerInfoTextBoxTileGraphics ; $7b98 ; trainer info text box tile patterns + ld hl,TrainerInfoTextBoxTileGraphics ; trainer info text box tile patterns ld de,vChars2 + $770 ld bc,$0080 push bc call TrainerInfo_FarCopyData - ld hl,BlankLeaderNames ; $7c28 + ld hl,BlankLeaderNames ld de,vChars2 + $600 ld bc,$0170 call TrainerInfo_FarCopyData pop bc - ld hl,BadgeNumbersTileGraphics ; $7d98 ; badge number tile patterns + ld hl,BadgeNumbersTileGraphics ; badge number tile patterns ld de,vChars1 + $580 call TrainerInfo_FarCopyData - ld hl,GymLeaderFaceAndBadgeTileGraphics ; $6a9e ; gym leader face and badge tile patterns + ld hl,GymLeaderFaceAndBadgeTileGraphics ; gym leader face and badge tile patterns ld de,vChars2 + $200 ld bc,$0400 ld a,$03 call FarCopyData2 - ld hl,TextBoxGraphics ; $6288 + ld hl,TextBoxGraphics ld de,$00d0 add hl,de ; hl = colon tile pattern ld de,vChars1 + $560 @@ -562,56 +562,56 @@ DrawTrainerInfo: ; 1349a (4:749a) push bc call FarCopyData2 pop bc - ld hl,TrainerInfoTextBoxTileGraphics + $80 ; $7c18 ; background tile pattern + ld hl,TrainerInfoTextBoxTileGraphics + $80 ; background tile pattern ld de,vChars1 + $570 call TrainerInfo_FarCopyData call EnableLCD - ld hl,wWhichTrade + ld hl,wTrainerInfoTextBoxWidthPlus1 ld a,18 + 1 ld [hli],a dec a ld [hli],a ld [hl],1 - hlCoord 0, 0 + coord hl, 0, 0 call TrainerInfo_DrawTextBox - ld hl,wWhichTrade + ld hl,wTrainerInfoTextBoxWidthPlus1 ld a,16 + 1 ld [hli],a dec a ld [hli],a ld [hl],3 - hlCoord 1, 10 + coord hl, 1, 10 call TrainerInfo_DrawTextBox - hlCoord 0, 10 + coord hl, 0, 10 ld a,$d7 call TrainerInfo_DrawVerticalLine - hlCoord 19, 10 + coord hl, 19, 10 call TrainerInfo_DrawVerticalLine - hlCoord 6, 9 + coord hl, 6, 9 ld de,TrainerInfo_BadgesText call PlaceString - hlCoord 2, 2 + coord hl, 2, 2 ld de,TrainerInfo_NameMoneyTimeText call PlaceString - hlCoord 7, 2 + coord hl, 7, 2 ld de,wPlayerName call PlaceString - hlCoord 8, 4 + coord hl, 8, 4 ld de,wPlayerMoney ld c,$e3 call PrintBCDNumber - hlCoord 9, 6 + coord hl, 9, 6 ld de,W_PLAYTIMEHOURS + 1 ; hours - ld bc,$4103 + lb bc, LEFT_ALIGN | 1, 3 call PrintNumber ld [hl],$d6 ; colon tile ID inc hl ld de,W_PLAYTIMEMINUTES + 1 ; minutes - ld bc,$8102 + lb bc, LEADING_ZEROES | 1, 2 jp PrintNumber TrainerInfo_FarCopyData: ; 1357f (4:757f) - ld a,$0b + ld a,BANK(TrainerInfoTextBoxTileGraphics) jp FarCopyData2 TrainerInfo_NameMoneyTimeText: ; 13584 (4:7584) @@ -627,15 +627,15 @@ TrainerInfo_BadgesText: ; 13597 (4:7597) ; height is always 6 ; INPUT: ; hl = destination address -; [wWhichTrade] = width + 1 -; [wTrainerEngageDistance] = width -; [wTrainerFacingDirection] = distance from the end of a text box row to the start of the next +; [wTrainerInfoTextBoxWidthPlus1] = width +; [wTrainerInfoTextBoxWidth] = width - 1 +; [wTrainerInfoTextBoxNextRowOffset] = distance from the end of a text box row to the start of the next TrainerInfo_DrawTextBox: ; 135a0 (4:75a0) ld a,$79 ; upper left corner tile ID - ld de,$7a7b ; top edge and upper right corner tile ID's + lb de, $7a, $7b ; top edge and upper right corner tile ID's call TrainerInfo_DrawHorizontalEdge ; draw top edge call TrainerInfo_NextTextBoxRow - ld a,[wWhichTrade] ; width of the text box plus one + ld a,[wTrainerInfoTextBoxWidthPlus1] ld e,a ld d,0 ld c,6 ; height of the text box @@ -647,11 +647,11 @@ TrainerInfo_DrawTextBox: ; 135a0 (4:75a0) dec c jr nz,.loop ld a,$7d ; lower left corner tile ID - ld de,$777e ; bottom edge and lower right corner tile ID's + lb de,$77, $7e ; bottom edge and lower right corner tile ID's TrainerInfo_DrawHorizontalEdge: ; 135c3 (4:75c3) ld [hli],a ; place left corner tile - ld a,[wTrainerEngageDistance] ; width of the text box + ld a,[wTrainerInfoTextBoxWidth] ld c,a ld a,d .loop @@ -663,7 +663,7 @@ TrainerInfo_DrawHorizontalEdge: ; 135c3 (4:75c3) ret TrainerInfo_NextTextBoxRow: ; 135d0 (4:75d0) - ld a,[wTrainerFacingDirection] ; distance to the start of the next row + ld a,[wTrainerInfoTextBoxNextRowOffset] ; distance to the start of the next row .loop inc hl dec a @@ -704,62 +704,65 @@ StartMenu_Option: ; 135f6 (4:75f6) jp RedisplayStartMenu SwitchPartyMon: ; 13613 (4:7613) - call SwitchPartyMon_Stats - ld a, [wWhichTrade] ; wWhichTrade - call SwitchPartyMon_OAM - ld a, [wCurrentMenuItem] ; wCurrentMenuItem - call SwitchPartyMon_OAM + call SwitchPartyMon_InitVarOrSwapData ; swap data + ld a, [wSwappedMenuItem] + call SwitchPartyMon_ClearGfx + ld a, [wCurrentMenuItem] + call SwitchPartyMon_ClearGfx jp RedrawPartyMenu_ -SwitchPartyMon_OAM: ; 13625 (4:7625) +SwitchPartyMon_ClearGfx: ; 13625 (4:7625) push af - ld hl, wTileMap - ld bc, $28 + coord hl, 0, 0 + ld bc, SCREEN_WIDTH * 2 call AddNTimes - ld c, $28 - ld a, $7f -.asm_13633 + ld c, SCREEN_WIDTH * 2 + ld a, " " +.clearMonBGLoop ; clear the mon's row in the party menu ld [hli], a dec c - jr nz, .asm_13633 + jr nz, .clearMonBGLoop pop af ld hl, wOAMBuffer ld bc, $10 call AddNTimes ld de, $4 ld c, e -.asm_13645 +.clearMonOAMLoop ld [hl], $a0 add hl, de dec c - jr nz, .asm_13645 + jr nz, .clearMonOAMLoop call WaitForSoundToFinish - ld a, (SFX_02_58 - SFX_Headers_02) / 3 + ld a, SFX_SWAP jp PlaySound -SwitchPartyMon_Stats: ; 13653 (4:7653) +SwitchPartyMon_InitVarOrSwapData: ; 13653 (4:7653) +; This is used to initialise [wMenuItemToSwap] and to actually swap the data. ld a, [wMenuItemToSwap] - and a - jr nz, .asm_13661 - ld a, [wWhichPokemon] ; wWhichPokemon - inc a + and a ; has [wMenuItemToSwap] been initialised yet? + jr nz, .pickedMonsToSwap +; If not, initialise [wMenuItemToSwap] so that it matches the current mon. + ld a, [wWhichPokemon] + inc a ; [wMenuItemToSwap] counts from 1 ld [wMenuItemToSwap], a ret -.asm_13661 +.pickedMonsToSwap xor a - ld [wd07d], a + ld [wPartyMenuTypeOrMessageID], a ld a, [wMenuItemToSwap] dec a ld b, a - ld a, [wCurrentMenuItem] ; wCurrentMenuItem - ld [wWhichTrade], a ; wWhichTrade - cp b - jr nz, .asm_1367b + ld a, [wCurrentMenuItem] + ld [wSwappedMenuItem], a + cp b ; swapping a mon with itself? + jr nz, .swappingDifferentMons +; can't swap a mon with itself xor a ld [wMenuItemToSwap], a - ld [wd07d], a + ld [wPartyMenuTypeOrMessageID], a ret -.asm_1367b +.swappingDifferentMons ld a, b ld [wMenuItemToSwap], a push hl @@ -767,85 +770,85 @@ SwitchPartyMon_Stats: ; 13653 (4:7653) ld hl, wPartySpecies ld d, h ld e, l - ld a, [wCurrentMenuItem] ; wCurrentMenuItem + ld a, [wCurrentMenuItem] add l ld l, a - jr nc, .asm_1368e + jr nc, .noCarry inc h -.asm_1368e +.noCarry ld a, [wMenuItemToSwap] add e ld e, a - jr nc, .asm_13696 + jr nc, .noCarry2 inc d -.asm_13696 +.noCarry2 ld a, [hl] - ld [H_DIVIDEND], a ; $ff95 (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT) + ld [hSwapTemp], a ld a, [de] ld [hl], a - ld a, [H_DIVIDEND] ; $ff95 (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT) + ld a, [hSwapTemp] ld [de], a ld hl, wPartyMons ld bc, wPartyMon2 - wPartyMon1 - ld a, [wCurrentMenuItem] ; wCurrentMenuItem + ld a, [wCurrentMenuItem] call AddNTimes push hl ld de, wSwitchPartyMonTempBuffer - ld bc, $2c + ld bc, wPartyMon2 - wPartyMon1 call CopyData ld hl, wPartyMons - ld bc, $2c + ld bc, wPartyMon2 - wPartyMon1 ld a, [wMenuItemToSwap] call AddNTimes pop de push hl - ld bc, $2c + ld bc, wPartyMon2 - wPartyMon1 call CopyData pop de ld hl, wSwitchPartyMonTempBuffer - ld bc, $2c + ld bc, wPartyMon2 - wPartyMon1 call CopyData - ld hl, wPartyMonOT ; wd273 - ld a, [wCurrentMenuItem] ; wCurrentMenuItem + ld hl, wPartyMonOT + ld a, [wCurrentMenuItem] call SkipFixedLengthTextEntries push hl ld de, wSwitchPartyMonTempBuffer - ld bc, $b + ld bc, NAME_LENGTH call CopyData - ld hl, wPartyMonOT ; wd273 + ld hl, wPartyMonOT ld a, [wMenuItemToSwap] call SkipFixedLengthTextEntries pop de push hl - ld bc, $b + ld bc, NAME_LENGTH call CopyData pop de ld hl, wSwitchPartyMonTempBuffer - ld bc, $b + ld bc, NAME_LENGTH call CopyData - ld hl, wPartyMonNicks ; wPartyMonNicks - ld a, [wCurrentMenuItem] ; wCurrentMenuItem + ld hl, wPartyMonNicks + ld a, [wCurrentMenuItem] call SkipFixedLengthTextEntries push hl ld de, wSwitchPartyMonTempBuffer - ld bc, $b + ld bc, NAME_LENGTH call CopyData - ld hl, wPartyMonNicks ; wPartyMonNicks + ld hl, wPartyMonNicks ld a, [wMenuItemToSwap] call SkipFixedLengthTextEntries pop de push hl - ld bc, $b + ld bc, NAME_LENGTH call CopyData pop de ld hl, wSwitchPartyMonTempBuffer - ld bc, $b + ld bc, NAME_LENGTH call CopyData ld a, [wMenuItemToSwap] - ld [wWhichTrade], a ; wWhichTrade + ld [wSwappedMenuItem], a xor a ld [wMenuItemToSwap], a - ld [wd07d], a + ld [wPartyMenuTypeOrMessageID], a pop de pop hl ret diff --git a/engine/menu/status_screen.asm b/engine/menu/status_screen.asm index b5254694..c91d5eda 100755 --- a/engine/menu/status_screen.asm +++ b/engine/menu/status_screen.asm @@ -50,12 +50,12 @@ DrawHP_: ; 128fb (4:68fb) .printFraction add hl, bc ld de, wLoadedMonHP - ld bc, $203 + lb bc, 2, 3 call PrintNumber ld a, "/" ld [hli], a ld de, wLoadedMonMaxHP - ld bc, $203 + lb bc, 2, 3 call PrintNumber pop hl pop de @@ -65,9 +65,10 @@ DrawHP_: ; 128fb (4:68fb) ; Predef 0x37 StatusScreen: ; 12953 (4:6953) call LoadMonData - ld a, [wcc49] - cp $2 ; 2 means we're in a PC box - jr c, .DontRecalculate ; 0x1295b $14 + ld a, [wMonDataLocation] + cp BOX_DATA + jr c, .DontRecalculate +; mon is in a box or daycare ld a, [wLoadedMonBoxLevel] ld [wLoadedMonLevel], a ld [W_CURENEMYLVL], a @@ -79,95 +80,95 @@ StatusScreen: ; 12953 (4:6953) ld hl, wd72c set 1, [hl] ld a, $33 - ld [$ff24], a ; Reduce the volume + ld [rNR50], a ; Reduce the volume call GBPalWhiteOutWithDelay3 call ClearScreen - call UpdateSprites ; move sprites (?) + call UpdateSprites call LoadHpBarAndStatusTilePatterns - ld de, BattleHudTiles1 ; $6080 ; source + ld de, BattleHudTiles1 ; source ld hl, vChars2 + $6d0 ; dest - ld bc, (BANK(BattleHudTiles1) << 8) + $03 ; bank bytes/8 + lb bc, BANK(BattleHudTiles1), $03 call CopyVideoDataDouble ; ·│ :L and halfarrow line end - ld de, BattleHudTiles2 ; $6098 + ld de, BattleHudTiles2 ld hl, vChars2 + $780 - ld bc, (BANK(BattleHudTiles2) << 8) + $01 + lb bc, BANK(BattleHudTiles2), $01 call CopyVideoDataDouble ; │ - ld de, BattleHudTiles3 ; $60b0 + ld de, BattleHudTiles3 ld hl, vChars2 + $760 - ld bc, (BANK(BattleHudTiles3) << 8) + $02 + lb bc, BANK(BattleHudTiles3), $02 call CopyVideoDataDouble ; ─┘ ld de, PTile ld hl, vChars2 + $720 - ld bc,(BANK(PTile) << 8 | $01) + lb bc, BANK(PTile), (PTileEnd - PTile) / $8 call CopyVideoDataDouble ; P (for PP), inline ld a, [hTilesetType] push af xor a ld [hTilesetType], a - hlCoord 19, 1 - ld bc, $060a + coord hl, 19, 1 + lb bc, 6, 10 call DrawLineBox ; Draws the box around name, HP and status - ld de, $fffa + ld de, -6 add hl, de ld [hl], $f2 ; . after No ("." is a different one) dec hl ld [hl], "№" - hlCoord 19, 9 - ld bc, $0806 + coord hl, 19, 9 + lb bc, 8, 6 call DrawLineBox ; Draws the box around types, ID No. and OT - hlCoord 10, 9 + coord hl, 10, 9 ld de, Type1Text call PlaceString ; "TYPE1/" - hlCoord 11, 3 + coord hl, 11, 3 predef DrawHP - ld hl, wcf25 + ld hl, wStatusScreenHPBarColor call GetHealthBarColor - ld b, $3 - call GoPAL_SET ; SGB palette - hlCoord 16, 6 + ld b, SET_PAL_STATUS_SCREEN + call RunPaletteCommand + coord hl, 16, 6 ld de, wLoadedMonStatus call PrintStatusCondition - jr nz, .StatusWritten ; 0x129fc $9 - hlCoord 16, 6 + jr nz, .StatusWritten + coord hl, 16, 6 ld de, OKText call PlaceString ; "OK" .StatusWritten - hlCoord 9, 6 + coord hl, 9, 6 ld de, StatusText call PlaceString ; "STATUS/" - hlCoord 14, 2 + coord hl, 14, 2 call PrintLevel ; Pokémon level - ld a, [W_MONHDEXNUM] + ld a, [W_MONHINDEX] ld [wd11e], a ld [wd0b5], a predef IndexToPokedex - hlCoord 3, 7 + coord hl, 3, 7 ld de, wd11e - ld bc, $8103 ; Zero-padded, 3 + lb bc, LEADING_ZEROES | 1, 3 call PrintNumber ; Pokémon no. - hlCoord 11, 10 + coord hl, 11, 10 predef PrintMonType - ld hl, NamePointers2 ; $6a9d - call .unk_12a7e + ld hl, NamePointers2 + call .GetStringPointer ld d, h ld e, l - hlCoord 9, 1 + coord hl, 9, 1 call PlaceString ; Pokémon name - ld hl, OTPointers ; $6a95 - call .unk_12a7e + ld hl, OTPointers + call .GetStringPointer ld d, h ld e, l - hlCoord 12, 16 + coord hl, 12, 16 call PlaceString ; OT - hlCoord 12, 14 + coord hl, 12, 14 ld de, wLoadedMonOTID - ld bc, $8205 ; 5 + lb bc, LEADING_ZEROES | 2, 5 call PrintNumber ; ID Number ld d, $0 call PrintStatsBox call Delay3 call GBPalNormal - hlCoord 1, 0 + coord hl, 1, 0 call LoadFlippedFrontSpriteByMonIndex ; draw Pokémon picture ld a, [wcf91] call PlayCry ; play Pokémon cry @@ -175,17 +176,18 @@ StatusScreen: ; 12953 (4:6953) pop af ld [hTilesetType], a ret -.unk_12a7e ; 0x12a7e ; I don't know what this does, iterates over pointers? - ld a, [wcc49] + +.GetStringPointer + ld a, [wMonDataLocation] add a ld c, a - ld b, $0 + ld b, 0 add hl, bc ld a, [hli] ld h, [hl] ld l, a - ld a, [wcc49] - cp $3 + ld a, [wMonDataLocation] + cp DAYCARE_DATA ret z ld a, [wWhichPokemon] jp SkipFixedLengthTextEntries @@ -221,43 +223,44 @@ OKText: ; 12ac4 (4:6ac4) db "OK@" ; Draws a line starting from hl high b and wide c -DrawLineBox ; 0x12ac7 - ld de, $0014 ; New line +DrawLineBox: ; 0x12ac7 + ld de, SCREEN_WIDTH ; New line .PrintVerticalLine ld [hl], $78 ; │ add hl, de dec b - jr nz, .PrintVerticalLine ; 0x12ace $fa + jr nz, .PrintVerticalLine ld [hl], $77 ; ┘ dec hl .PrintHorizLine ld [hl], $76 ; ─ dec hl dec c - jr nz, .PrintHorizLine ; 0x12ad7 $fa + jr nz, .PrintHorizLine ld [hl], $6f ; ← (halfarrow ending) ret PTile: ; 12adc (4:6adc) ; This is a single 1bpp "P" tile INCBIN "gfx/p_tile.1bpp" +PTileEnd: PrintStatsBox: ; 12ae4 (4:6ae4) ld a, d and a ; a is 0 from the status screen - jr nz, .DifferentBox ; 0x12ae6 $12 - hlCoord 0, 8 + jr nz, .DifferentBox + coord hl, 0, 8 ld b, $8 ld c, $8 call TextBoxBorder ; Draws the box - hlCoord 1, 9 ; Start printing stats from here + coord hl, 1, 9 ; Start printing stats from here ld bc, $0019 ; Number offset - jr .PrintStats ; 0x12af8 $10 + jr .PrintStats .DifferentBox - hlCoord 9, 2 + coord hl, 9, 2 ld b, $8 ld c, $9 call TextBoxBorder - hlCoord 11, 3 + coord hl, 11, 3 ld bc, $0018 .PrintStats push bc @@ -268,7 +271,7 @@ PrintStatsBox: ; 12ae4 (4:6ae4) pop bc add hl, bc ld de, wLoadedMonAttack - ld bc, $0203 ; three digits + lb bc, 2, 3 call PrintStat ld de, wLoadedMonDefense call PrintStat @@ -280,7 +283,7 @@ PrintStat push hl call PrintNumber pop hl - ld de, $0028 + ld de, SCREEN_WIDTH * 2 add hl, de ret @@ -295,8 +298,8 @@ StatusScreen2: ; 12b57 (4:6b57) push af xor a ld [hTilesetType], a - ld [$ffba], a - ld bc, $0005 + ld [H_AUTOBGTRANSFERENABLED], a + ld bc, NUM_MOVES + 1 ld hl, wMoves call FillMemory ld hl, wLoadedMonMoves @@ -304,42 +307,42 @@ StatusScreen2: ; 12b57 (4:6b57) ld bc, NUM_MOVES call CopyData callab FormatMovesString - hlCoord 9, 2 - ld bc, $050a + coord hl, 9, 2 + lb bc, 5, 10 call ClearScreenArea ; Clear under name - hlCoord 19, 3 + coord hl, 19, 3 ld [hl], $78 - hlCoord 0, 8 - ld b, $8 - ld c, $12 + coord hl, 0, 8 + ld b, 8 + ld c, 18 call TextBoxBorder ; Draw move container - hlCoord 2, 9 + coord hl, 2, 9 ld de, wMovesString call PlaceString ; Print moves - ld a, [wcd6c] + ld a, [wNumMovesMinusOne] inc a ld c, a ld a, $4 sub c ld b, a ; Number of moves ? - hlCoord 11, 10 - ld de, $0028 - ld a, $72 - call Func_12ccb ; Print "PP" + coord hl, 11, 10 + ld de, SCREEN_WIDTH * 2 + ld a, $72 ; special P tile id + call StatusScreen_PrintPP ; Print "PP" ld a, b and a - jr z, .InitPP ; 0x12bb3 $6 + jr z, .InitPP ld c, a ld a, "-" - call Func_12ccb ; Fill the rest with -- + call StatusScreen_PrintPP ; Fill the rest with -- .InitPP ; 12bbb ld hl, wLoadedMonMoves - deCoord 14, 10 - ld b, $0 + coord de, 14, 10 + ld b, 0 .PrintPP ; 12bc3 ld a, [hli] and a - jr z, .PPDone ; 0x12bc5 $4a + jr z, .PPDone push bc push hl push de @@ -356,24 +359,24 @@ StatusScreen2: ; 12b57 (4:6b57) pop de pop hl push hl - ld bc, $0014 + ld bc, wPartyMon1PP - wPartyMon1Moves - 1 add hl, bc ld a, [hl] and $3f - ld [wcd71], a + ld [wStatusScreenCurrentPP], a ld h, d ld l, e push hl - ld de, wcd71 - ld bc, $0102 + ld de, wStatusScreenCurrentPP + lb bc, 1, 2 call PrintNumber ld a, "/" ld [hli], a - ld de, wd11e - ld bc, $0102 + ld de, wMaxPP + lb bc, 1, 2 call PrintNumber pop hl - ld de, $0028 + ld de, SCREEN_WIDTH * 2 add hl, de ld d, h ld e, l @@ -382,19 +385,19 @@ StatusScreen2: ; 12b57 (4:6b57) inc b ld a, b cp $4 - jr nz, .PrintPP ; 0x12c0f $b2 + jr nz, .PrintPP .PPDone - hlCoord 9, 3 - ld de, EXPPointsText + coord hl, 9, 3 + ld de, StatusScreenExpText call PlaceString - ld a, [wLoadedMonLevel] ; level + ld a, [wLoadedMonLevel] push af cp MAX_LEVEL - jr z, .Level100 ; 0x12c20 $4 + jr z, .Level100 inc a ld [wLoadedMonLevel], a ; Increase temporarily if not 100 .Level100 - hlCoord 14, 6 + coord hl, 14, 6 ld [hl], $70 ; 1-tile "to" inc hl inc hl @@ -402,25 +405,25 @@ StatusScreen2: ; 12b57 (4:6b57) pop af ld [wLoadedMonLevel], a ld de, wLoadedMonExp - hlCoord 12, 4 - ld bc, $0307 + coord hl, 12, 4 + lb bc, 3, 7 call PrintNumber ; exp - call .asm_12c86 + call CalcExpToLevelUp ld de, wLoadedMonExp - hlCoord 7, 6 - ld bc, $0307 - call PrintNumber - hlCoord 9, 0 - call Func_12cc3 - hlCoord 9, 1 - call Func_12cc3 - ld a, [W_MONHDEXNUM] + coord hl, 7, 6 + lb bc, 3, 7 + call PrintNumber ; exp needed to level up + coord hl, 9, 0 + call StatusScreen_ClearName + coord hl, 9, 1 + call StatusScreen_ClearName + ld a, [W_MONHINDEX] ld [wd11e], a call GetMonName - hlCoord 9, 1 + coord hl, 9, 1 call PlaceString ld a, $1 - ld [$ffba], a + ld [H_AUTOBGTRANSFERENABLED], a call Delay3 call WaitForTextScrollButtonPress ; wait for button pop af @@ -428,28 +431,29 @@ StatusScreen2: ; 12b57 (4:6b57) ld hl, wd72c res 1, [hl] ld a, $77 - ld [$ff24], a + ld [rNR50], a call GBPalWhiteOut jp ClearScreen -.asm_12c86 ; This does some magic with lvl/exp? - ld a, [wLoadedMonLevel] ; Load level + +CalcExpToLevelUp: ; 12c86 (4:6c86) + ld a, [wLoadedMonLevel] cp MAX_LEVEL - jr z, .asm_12ca7 ; 0x12c8b $1a ; If 100 + jr z, .atMaxLevel inc a ld d, a callab CalcExperience ld hl, wLoadedMonExp + 2 - ld a, [$ff98] + ld a, [hExperience + 2] sub [hl] ld [hld], a - ld a, [$ff97] + ld a, [hExperience + 1] sbc [hl] ld [hld], a - ld a, [$ff96] + ld a, [hExperience] sbc [hl] ld [hld], a ret -.asm_12ca7 +.atMaxLevel ld hl, wLoadedMonExp xor a ld [hli], a @@ -457,21 +461,20 @@ StatusScreen2: ; 12b57 (4:6b57) ld [hl], a ret -EXPPointsText: ; 12caf (4:6caf) - db "EXP POINTS", $4e - -LevelUpText: ; 12cba (4:6cba) - db "LEVEL UP@" +StatusScreenExpText: ; 12caf (4:6caf) + db "EXP POINTS" + next "LEVEL UP@" -Func_12cc3: ; 12cc3 (4:6cc3) - ld bc, $a - ld a, $7f +StatusScreen_ClearName: ; 12cc3 (4:6cc3) + ld bc, 10 + ld a, " " jp FillMemory -Func_12ccb: ; 12ccb (4:6ccb) +StatusScreen_PrintPP: ; 12ccb (4:6ccb) +; print PP or -- c times, going down two rows each time ld [hli], a ld [hld], a add hl, de dec c - jr nz, Func_12ccb + jr nz, StatusScreen_PrintPP ret diff --git a/engine/menu/vending_machine.asm b/engine/menu/vending_machine.asm index 88cfcf65..8460889f 100755 --- a/engine/menu/vending_machine.asm +++ b/engine/menu/vending_machine.asm @@ -7,65 +7,66 @@ VendingMachineMenu: ; 74ee0 (1d:4ee0) xor a ld [wCurrentMenuItem], a ld [wLastMenuItem], a - ld a, $3 + ld a, A_BUTTON | B_BUTTON ld [wMenuWatchedKeys], a - ld a, $3 + ld a, 3 ld [wMaxMenuItem], a - ld a, $5 + ld a, 5 ld [wTopMenuItemY], a - ld a, $1 + ld a, 1 ld [wTopMenuItemX], a ld hl, wd730 set 6, [hl] - hlCoord 0, 3 - ld b, $8 - ld c, $c + coord hl, 0, 3 + ld b, 8 + ld c, 12 call TextBoxBorder call UpdateSprites - hlCoord 2, 5 + coord hl, 2, 5 ld de, DrinkText call PlaceString - hlCoord 9, 6 + coord hl, 9, 6 ld de, DrinkPriceText call PlaceString ld hl, wd730 res 6, [hl] call HandleMenuInput - bit 1, a - jr nz, .asm_74f93 + bit 1, a ; pressed B? + jr nz, .notThirsty ld a, [wCurrentMenuItem] - cp $3 - jr z, .asm_74f93 + cp 3 ; chose Cancel? + jr z, .notThirsty xor a - ld [$ff9f], a - ld [$ffa1], a + ld [hMoney], a + ld [hMoney + 2], a ld a, $2 - ld [$ffa0], a + ld [hMoney + 1], a call HasEnoughMoney jr nc, .enoughMoney ld hl, VendingMachineText4 jp PrintText .enoughMoney - call Func_74fe7 - ld a, [$ffdb] + call LoadVendingMachineItem + ld a, [hVendingMachineItem] ld b, a ld c, 1 call GiveItem jr nc, .BagFull - ld b, $3c ; number of times to play the "brrrrr" sound -.playDeliverySound ; 0x74f63 - ld c, $2 + + ld b, 60 ; number of times to play the "brrrrr" sound +.playDeliverySound + ld c, 2 call DelayFrames push bc - ld a, (SFX_02_53 - SFX_Headers_02) / 3 + ld a, SFX_PUSH_BOULDER call PlaySound pop bc dec b jr nz, .playDeliverySound -.asm_74f72 + ld hl, VendingMachineText5 call PrintText - ld hl, $ffde + ld hl, hVendingMachinePrice + 2 ld de, wPlayerMoney + 2 ld c, $3 predef SubBCDPredef @@ -75,7 +76,7 @@ VendingMachineMenu: ; 74ee0 (1d:4ee0) .BagFull ld hl, VendingMachineText6 jp PrintText -.asm_74f93 +.notThirsty ld hl, VendingMachineText7 jp PrintText @@ -110,22 +111,22 @@ VendingMachineText7: ; 74fe2 (1d:4fe2) TX_FAR _VendingMachineText7 db "@" -Func_74fe7: ; 74fe7 (1d:4fe7) +LoadVendingMachineItem: ; 74fe7 (1d:4fe7) ld hl, VendingPrices ld a, [wCurrentMenuItem] add a add a - ld d, $0 + ld d, 0 ld e, a add hl, de ld a, [hli] - ld [$ffdb], a + ld [hVendingMachineItem], a ld a, [hli] - ld [$ffdc], a + ld [hVendingMachinePrice], a ld a, [hli] - ld [$ffdd], a + ld [hVendingMachinePrice + 1], a ld a, [hl] - ld [$ffde], a + ld [hVendingMachinePrice + 2], a ret VendingPrices: ; 75000 (1d:5000) diff --git a/engine/mon_party_sprites.asm b/engine/mon_party_sprites.asm index e3323cfc..185151cb 100755 --- a/engine/mon_party_sprites.asm +++ b/engine/mon_party_sprites.asm @@ -5,15 +5,15 @@ AnimatePartyMon_ForceSpeed1: ; 716f7 (1c:56f7) inc a jr GetAnimationSpeed -; wcf1f contains the party mon's health bar colors +; wPartyMenuHPBarColors contains the party mon's health bar colors ; 0: green ; 1: yellow ; 2: red AnimatePartyMon: ; 716ff (1c:56ff) - ld hl, wcf1f + ld hl, wPartyMenuHPBarColors ld a, [wCurrentMenuItem] ld c, a - ld b, $0 + ld b, 0 add hl, bc ld a, [hl] @@ -27,7 +27,7 @@ GetAnimationSpeed: ; 7170a (1c:570a) ld c, a add a ld b, a - ld a, [wPartyMonAnimCounter] + ld a, [wAnimCounter] and a jr z, .resetSprites cp c @@ -38,11 +38,11 @@ GetAnimationSpeed: ; 7170a (1c:570a) jr nz, .skipResetTimer xor a ; reset timer .skipResetTimer - ld [wPartyMonAnimCounter], a + ld [wAnimCounter], a jp DelayFrame .resetSprites push bc - ld hl, wcc5b + ld hl, wMonPartySpritesSavedOAM ld de, wOAMBuffer ld bc, $60 call CopyData @@ -86,7 +86,7 @@ GetAnimationSpeed: ; 7170a (1c:570a) ; that each frame lasts for green HP, yellow HP, and red HP in order. ; On the naming screen, the yellow HP speed is always used. PartyMonSpeeds: ; 71769 (1c:5769) - db $05,$10,$20 + db 5, 16, 32 LoadMonPartySpriteGfx: ; 7176c (1c:576c) ; Load mon party sprite tile patterns into VRAM during V-blank. @@ -315,7 +315,7 @@ WriteMonPartySpriteOAMByPartyIndex: ; 71868 (1c:5868) add hl, de ld a, [hl] call GetPartyMonSpriteID - ld [wcd5b], a + ld [wOAMBaseTile], a call WriteMonPartySpriteOAM pop bc pop de @@ -329,7 +329,7 @@ WriteMonPartySpriteOAMBySpecies: ; 71882 (1c:5882) ld [hPartyMonIndex], a ld a, [wMonPartySpriteSpecies] call GetPartyMonSpriteID - ld [wcd5b], a + ld [wOAMBaseTile], a jr WriteMonPartySpriteOAM UnusedPartyMonSpriteFunction: ; 71890 (1c:5890) @@ -372,7 +372,7 @@ UnusedPartyMonSpriteFunction: ; 71890 (1c:5890) WriteMonPartySpriteOAM: ; 718c3 (1c:58c3) ; Write the OAM blocks for the first animation frame into the OAM buffer and -; make a copy at wcc5b. +; make a copy at wMonPartySpritesSavedOAM. push af ld c, $10 ld h, wOAMBuffer / $100 @@ -392,7 +392,7 @@ WriteMonPartySpriteOAM: ; 718c3 (1c:58c3) ; we can flip back to it from the second frame by copying it back. .makeCopy ld hl, wOAMBuffer - ld de, wcc5b + ld de, wMonPartySpritesSavedOAM ld bc, $60 jp CopyData diff --git a/engine/multiply_divide.asm b/engine/multiply_divide.asm index 6ff427c6..7cb381b4 100755 --- a/engine/multiply_divide.asm +++ b/engine/multiply_divide.asm @@ -58,6 +58,10 @@ _Multiply: ; f660e (3d:660e) ld [H_PRODUCT+1], a ; $ff96 ld a, [H_MULTIPLYBUFFER] ld [H_PRODUCT], a ; $ff95 + ld a, [H_MULTIPLYBUFFER+1] + ld [H_PRODUCT+1], a + ld a, [H_MULTIPLYBUFFER] + ld [H_PRODUCT], a ret _Divide: ; f6672 (3d:6672) diff --git a/engine/oak_speech.asm b/engine/oak_speech.asm index 0cbdaa3d..0de7ffad 100755 --- a/engine/oak_speech.asm +++ b/engine/oak_speech.asm @@ -1,11 +1,11 @@ SetDefaultNames: ; 60ca (1:60ca) - ld a, [wd358] + ld a, [wLetterPrintingDelayFlags] push af - ld a, [W_OPTIONS] ; W_OPTIONS + ld a, [W_OPTIONS] push af ld a, [wd732] push af - ld hl, wPlayerName ; wd158 + ld hl, wPlayerName ld bc, $d8a xor a call FillMemory @@ -16,28 +16,28 @@ SetDefaultNames: ; 60ca (1:60ca) pop af ld [wd732], a pop af - ld [W_OPTIONS], a ; W_OPTIONS + ld [W_OPTIONS], a pop af - ld [wd358], a - ld a, [wd08a] + ld [wLetterPrintingDelayFlags], a + ld a, [wOptionsInitialized] and a - call z, Func_5bff + call z, InitOptions ld hl, NintenText - ld de, wPlayerName ; wd158 - ld bc, $b + ld de, wPlayerName + ld bc, NAME_LENGTH call CopyData ld hl, SonyText - ld de, W_RIVALNAME ; wd34a - ld bc, $b + ld de, W_RIVALNAME + ld bc, NAME_LENGTH jp CopyData OakSpeech: ; 6115 (1:6115) ld a,$FF call PlaySound ; stop music - ld a, BANK(Music_Routes2) ; bank of song + ld a, BANK(Music_Routes2) ld c,a - ld a, MUSIC_ROUTES2 ; song # - call PlayMusic ; plays music + ld a, MUSIC_ROUTES2 + call PlayMusic call ClearScreen call LoadTextBoxTilePatterns call SetDefaultNames @@ -46,7 +46,7 @@ OakSpeech: ; 6115 (1:6115) ld a,POTION ld [wcf91],a ld a,1 - ld [wcf96],a + ld [wItemQuantity],a call AddItemToInventory ; give one potion ld a,[W_ANIMATIONID] ld [wDestinationMap],a @@ -54,50 +54,49 @@ OakSpeech: ; 6115 (1:6115) xor a ld [hTilesetType],a ld a,[wd732] - bit 1,a ; XXX when is bit 1 set? - jp nz,Func_61bc ; easter egg: skip the intro + bit 1,a ; possibly a debug mode bit + jp nz,.skipChoosingNames ld de,ProfOakPic - ld bc, (Bank(ProfOakPic) << 8) | $00 - call IntroPredef3B ; displays Oak pic? + lb bc, Bank(ProfOakPic), $00 + call IntroDisplayPicCenteredOrUpperRight call FadeInIntroPic ld hl,OakSpeechText1 - call PrintText ; prints text box + call PrintText call GBFadeOutToWhite call ClearScreen ld a,NIDORINO - ld [wd0b5],a ; pic displayed is stored at this location + ld [wd0b5],a ld [wcf91],a - call GetMonHeader ; this is also related to the pic - hlCoord 6, 4 ; position on tilemap the pic is displayed - call LoadFlippedFrontSpriteByMonIndex ; displays pic? + call GetMonHeader + coord hl, 6, 4 + call LoadFlippedFrontSpriteByMonIndex call MovePicLeft ld hl,OakSpeechText2 - call PrintText ; Prints text box + call PrintText call GBFadeOutToWhite call ClearScreen ld de,RedPicFront - ld bc,(Bank(RedPicFront) << 8) | $00 - call IntroPredef3B ; displays player pic? + lb bc, Bank(RedPicFront), $00 + call IntroDisplayPicCenteredOrUpperRight call MovePicLeft ld hl,IntroducePlayerText call PrintText - call LoadDefaultNamesPlayer ; brings up NewName/Red/etc menu + call ChoosePlayerName call GBFadeOutToWhite call ClearScreen ld de,Rival1Pic - ld bc,(Bank(Rival1Pic) << 8) | $00 - call IntroPredef3B ; displays rival pic + lb bc, Bank(Rival1Pic), $00 + call IntroDisplayPicCenteredOrUpperRight call FadeInIntroPic ld hl,IntroduceRivalText call PrintText - call LoadDefaultNamesRival - -Func_61bc: ; 61bc (1:61bc) + call ChooseRivalName +.skipChoosingNames call GBFadeOutToWhite call ClearScreen ld de,RedPicFront - ld bc,(Bank(RedPicFront) << 8) | $00 - call IntroPredef3B + lb bc, Bank(RedPicFront), $00 + call IntroDisplayPicCenteredOrUpperRight call GBFadeInFromWhite ld a,[wd72d] and a @@ -107,49 +106,49 @@ Func_61bc: ; 61bc (1:61bc) .next ld a,[H_LOADEDROMBANK] push af - ld a,(SFX_02_48 - SFX_Headers_02) / 3 + ld a,SFX_SHRINK call PlaySound pop af ld [H_LOADEDROMBANK],a - ld [$2000],a + ld [MBC1RomBank],a ld c,4 call DelayFrames - ld de,RedSprite ; $4180 + ld de,RedSprite ld hl,vSprites - ld bc,(BANK(RedSprite) << 8) | $0C + lb bc, BANK(RedSprite), $0C call CopyVideoData ld de,ShrinkPic1 - ld bc,(BANK(ShrinkPic1) << 8) | $00 - call IntroPredef3B + lb bc, BANK(ShrinkPic1), $00 + call IntroDisplayPicCenteredOrUpperRight ld c,4 call DelayFrames ld de,ShrinkPic2 - ld bc,(BANK(ShrinkPic2) << 8) | $00 - call IntroPredef3B + lb bc, BANK(ShrinkPic2), $00 + call IntroDisplayPicCenteredOrUpperRight call ResetPlayerSpriteData ld a,[H_LOADEDROMBANK] push af ld a, BANK(Music_PalletTown) - ld [wc0ef],a - ld [wc0f0],a - ld a,$A - ld [wMusicHeaderPointer],a + ld [wAudioROMBank],a + ld [wAudioSavedROMBank],a + ld a, 10 + ld [wAudioFadeOutControl],a ld a,$FF - ld [wc0ee],a + ld [wNewSoundID],a call PlaySound ; stop music pop af ld [H_LOADEDROMBANK],a - ld [$2000],a - ld c,$14 + ld [MBC1RomBank],a + ld c,20 call DelayFrames - hlCoord 6, 5 + coord hl, 6, 5 ld b,7 ld c,7 call ClearScreenArea call LoadTextBoxTilePatterns ld a,1 ld [wUpdateSpritesEnabled],a - ld c,$32 + ld c,50 call DelayFrames call GBFadeOutToWhite jp ClearScreen @@ -193,24 +192,26 @@ IntroFadePalettes: ; 6282 (1:6282) MovePicLeft: ; 6288 (1:6288) ld a,119 - ld [$FF4B],a + ld [rWX],a call DelayFrame ld a,$E4 ld [rBGP],a .next call DelayFrame - ld a,[$FF4B] + ld a,[rWX] sub 8 cp $FF ret z - ld [$FF4B],a + ld [rWX],a jr .next -Predef3B: ; 62a1 (1:62a1) +DisplayPicCenteredOrUpperRight: ; 62a1 (1:62a1) call GetPredefRegisters -IntroPredef3B: ; 62a4 (1:62a4) -; bank of sprite given in b +IntroDisplayPicCenteredOrUpperRight: ; 62a4 (1:62a4) +; b = bank +; de = address of compressed pic +; c: 0 = centred, non-zero = upper-right push bc ld a,b call UncompressSpriteFromDE @@ -223,10 +224,10 @@ IntroPredef3B: ; 62a4 (1:62a4) pop bc ld a,c and a - hlCoord 15, 1 + coord hl, 15, 1 jr nz,.next - hlCoord 6, 4 + coord hl, 6, 4 .next xor a - ld [$FFE1],a - predef_jump Func_3f0c6 + ld [hStartTileID],a + predef_jump CopyUncompressedPicToTilemap diff --git a/engine/oak_speech2.asm b/engine/oak_speech2.asm index 16a97377..c0349d2e 100755 --- a/engine/oak_speech2.asm +++ b/engine/oak_speech2.asm @@ -1,29 +1,29 @@ -LoadDefaultNamesPlayer: ; 695d (1:695d) - call Func_6a12 - ld de, DefaultNamesPlayer ; $6aa8 +ChoosePlayerName: ; 695d (1:695d) + call OakSpeechSlidePicRight + ld de, DefaultNamesPlayer call DisplayIntroNameTextBox - ld a, [wCurrentMenuItem] ; wCurrentMenuItem + ld a, [wCurrentMenuItem] and a - jr z, .asm_697a - ld hl, DefaultNamesPlayerList ; $6af2 - call Func_6ad6 - ld de, wPlayerName ; wd158 - call Func_69ec - jr .asm_6999 -.asm_697a - ld hl, wPlayerName ; wd158 - xor a - ld [wd07d], a + jr z, .customName + ld hl, DefaultNamesPlayerList + call GetDefaultName + ld de, wPlayerName + call OakSpeechSlidePicLeft + jr .done +.customName + ld hl, wPlayerName + xor a ; NAME_PLAYER_SCREEN + ld [wNamingScreenType], a call DisplayNamingScreen ld a, [wcf4b] - cp $50 - jr z, .asm_697a + cp "@" + jr z, .customName call ClearScreen call Delay3 - ld de, RedPicFront ; $6ede + ld de, RedPicFront ld b, BANK(RedPicFront) - call IntroPredef3B -.asm_6999 + call IntroDisplayPicCenteredOrUpperRight +.done ld hl, YourNameIsText jp PrintText @@ -31,32 +31,32 @@ YourNameIsText: ; 699f (1:699f) TX_FAR _YourNameIsText db "@" -LoadDefaultNamesRival: ; 69a4 (1:69a4) - call Func_6a12 ; 0x69a4 call 0x6a12 +ChooseRivalName: ; 69a4 (1:69a4) + call OakSpeechSlidePicRight ld de, DefaultNamesRival call DisplayIntroNameTextBox - ld a, [wCurrentMenuItem] ; wCurrentMenuItem + ld a, [wCurrentMenuItem] and a - jr z, .asm_69c1 + jr z, .customName ld hl, DefaultNamesRivalList - call Func_6ad6 - ld de, W_RIVALNAME ; wd34a - call Func_69ec - jr .asm_69e1 -.asm_69c1 - ld hl, W_RIVALNAME ; wd34a - ld a, $1 - ld [wd07d], a + call GetDefaultName + ld de, W_RIVALNAME + call OakSpeechSlidePicLeft + jr .done +.customName + ld hl, W_RIVALNAME + ld a, NAME_RIVAL_SCREEN + ld [wNamingScreenType], a call DisplayNamingScreen ld a, [wcf4b] - cp $50 - jr z, .asm_69c1 + cp "@" + jr z, .customName call ClearScreen call Delay3 - ld de, Rival1Pic ; $6049 + ld de, Rival1Pic ld b, $13 - call IntroPredef3B -.asm_69e1 + call IntroDisplayPicCenteredOrUpperRight +.done ld hl, HisNameIsText jp PrintText @@ -64,90 +64,96 @@ HisNameIsText: ; 69e7 (1:69e7) TX_FAR _HisNameIsText db "@" -Func_69ec: ; 69ec (1:69ec) +OakSpeechSlidePicLeft: ; 69ec (1:69ec) push de - ld hl, wTileMap - ld bc, $c0b - call ClearScreenArea - ld c, $a + coord hl, 0, 0 + lb bc, 12, 11 + call ClearScreenArea ; clear the name list text box + ld c, 10 call DelayFrames pop de ld hl, wcd6d - ld bc, $b + ld bc, NAME_LENGTH call CopyData call Delay3 - hlCoord 12, 4 - ld de, $67d + coord hl, 12, 4 + lb de, 6, 6 * SCREEN_WIDTH + 5 ld a, $ff - jr asm_6a19 + jr OakSpeechSlidePicCommon -Func_6a12: ; 6a12 (1:6a12) - hlCoord 5, 4 - ld de, $67d +OakSpeechSlidePicRight: ; 6a12 (1:6a12) + coord hl, 5, 4 + lb de, 6, 6 * SCREEN_WIDTH + 5 xor a -asm_6a19: ; 6a19 (1:6a19) + +OakSpeechSlidePicCommon: ; 6a19 (1:6a19) push hl push de push bc - ld [$ff8d], a + ld [hSlideDirection], a ld a, d - ld [H_DOWNARROWBLINKCNT1], a ; $ff8b + ld [hSlideAmount], a ld a, e - ld [H_DOWNARROWBLINKCNT2], a ; $ff8c + ld [hSlidingRegionSize], a ld c, a - ld a, [$ff8d] + ld a, [hSlideDirection] and a - jr nz, .asm_6a2d - ld d, $0 + jr nz, .next +; If sliding right, point hl to the end of the pic's tiles. + ld d, 0 add hl, de -.asm_6a2d +.next ld d, h ld e, l -.asm_6a2f +.loop xor a - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba - ld a, [$ff8d] + ld [H_AUTOBGTRANSFERENABLED], a + ld a, [hSlideDirection] and a - jr nz, .asm_6a3c + jr nz, .slideLeft +; sliding right ld a, [hli] ld [hld], a dec hl - jr .asm_6a3f -.asm_6a3c + jr .next2 +.slideLeft ld a, [hld] ld [hli], a inc hl -.asm_6a3f +.next2 dec c - jr nz, .asm_6a2f - ld a, [$ff8d] + jr nz, .loop + ld a, [hSlideDirection] and a - jr z, .asm_6a4a + jr z, .next3 +; If sliding left, we need to zero the last tile in the pic (there is no need +; to take a corresponding action when sliding right because hl initially points +; to a 0 tile in that case). xor a dec hl ld [hl], a -.asm_6a4a - ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba +.next3 + ld a, 1 + ld [H_AUTOBGTRANSFERENABLED], a call Delay3 - ld a, [H_DOWNARROWBLINKCNT2] ; $ff8c + ld a, [hSlidingRegionSize] ld c, a ld h, d ld l, e - ld a, [$ff8d] + ld a, [hSlideDirection] and a - jr nz, .asm_6a5e + jr nz, .slideLeft2 inc hl - jr .asm_6a5f -.asm_6a5e + jr .next4 +.slideLeft2 dec hl -.asm_6a5f +.next4 ld d, h ld e, l - ld a, [H_DOWNARROWBLINKCNT1] ; $ff8b + ld a, [hSlideAmount] dec a - ld [H_DOWNARROWBLINKCNT1], a ; $ff8b - jr nz, .asm_6a2f + ld [hSlideAmount], a + jr nz, .loop pop bc pop de pop hl @@ -155,27 +161,27 @@ asm_6a19: ; 6a19 (1:6a19) DisplayIntroNameTextBox: ; 6a6c (1:6a6c) push de - ld hl, wTileMap + coord hl, 0, 0 ld b, $a ld c, $9 call TextBoxBorder - hlCoord 3, 0 - ld de, .namestring ; $6aa3 + coord hl, 3, 0 + ld de, .namestring call PlaceString pop de - hlCoord 2, 2 + coord hl, 2, 2 call PlaceString call UpdateSprites xor a - ld [wCurrentMenuItem], a ; wCurrentMenuItem - ld [wLastMenuItem], a ; wLastMenuItem + ld [wCurrentMenuItem], a + ld [wLastMenuItem], a inc a - ld [wTopMenuItemX], a ; wTopMenuItemX - ld [wMenuWatchedKeys], a ; wMenuWatchedKeys + ld [wTopMenuItemX], a + ld [wMenuWatchedKeys], a ; A_BUTTON inc a - ld [wTopMenuItemY], a ; wTopMenuItemY + ld [wTopMenuItemY], a inc a - ld [wMaxMenuItem], a ; wMaxMenuItem + ld [wMaxMenuItem], a jp HandleMenuInput .namestring ; 6aa3 (1:6aa3) @@ -195,27 +201,30 @@ DefaultNamesRival: next "JOHN" db "@" -Func_6ad6: ; 6ad6 (1:6ad6) +GetDefaultName: ; 6ad6 (1:6ad6) +; a = name index +; hl = name list ld b, a - ld c, $0 -.asm_6ad9 + ld c, 0 +.loop ld d, h ld e, l -.asm_6adb +.innerLoop ld a, [hli] - cp $50 - jr nz, .asm_6adb + cp "@" + jr nz, .innerLoop ld a, b cp c - jr z, .asm_6ae7 + jr z, .foundName inc c - jr .asm_6ad9 -.asm_6ae7 + jr .loop +.foundName ld h, d ld l, e ld de, wcd6d ld bc, $14 jp CopyData + DefaultNamesPlayerList: db "NEW NAME@YELLOW@ASH@JACK@" DefaultNamesRivalList: diff --git a/engine/oam_dma.asm b/engine/oam_dma.asm index 3de4d773..7326445e 100644 --- a/engine/oam_dma.asm +++ b/engine/oam_dma.asm @@ -15,11 +15,12 @@ WriteDMACodeToHRAM: DMARoutine: ; initiate DMA ld a, wOAMBuffer / $100 - ld [$ff46], a + ld [rDMA], a ; wait for DMA to finish ld a, $28 -.wait dec a +.wait + dec a jr nz, .wait ret DMARoutineEnd: diff --git a/engine/overworld/cable_club_npc.asm b/engine/overworld/cable_club_npc.asm index bdab41a6..a2feba06 100755 --- a/engine/overworld/cable_club_npc.asm +++ b/engine/overworld/cable_club_npc.asm @@ -1,15 +1,14 @@ CableClubNPC: ; 71c5 (1:71c5) ld hl, CableClubNPCWelcomeText call PrintText - ld a, [wd74b] - bit 5, a ; received pokedex? + CheckEvent EVENT_GOT_POKEDEX jp nz, .receivedPokedex ; if the player hasn't received the pokedex - ld c, $3c + ld c, 60 call DelayFrames ld hl, CableClubNPCMakingPreparationsText call PrintText - jp Func_7298 + jp .didNotConnect .receivedPokedex ld a, $1 ld [wMenuJoypadPollCount], a @@ -57,7 +56,7 @@ CableClubNPC: ; 71c5 (1:71c5) jr nz, .choseNo callab SaveSAVtoSRAM call WaitForSoundToFinish - ld a, (SFX_02_5d - SFX_Headers_02) / 3 + ld a, SFX_SAVE call PlaySoundWaitForCurrent ld hl, CableClubNPCPleaseWaitText call PrintText @@ -72,31 +71,29 @@ CableClubNPC: ; 71c5 (1:71c5) ld hl, wUnknownSerialCounter ld a, [hli] inc a - jr nz, Func_72a8 ; 0x726b $3b + jr nz, .connected ld a, [hl] inc a - jr nz, Func_72a8 ; 0x726f $37 - ld b, $a -.asm_7273 + jr nz, .connected + ld b, 10 +.syncLoop call DelayFrame call Serial_SendZeroByte dec b - jr nz, .asm_7273 ; 0x727a $f7 + jr nz, .syncLoop call CloseLinkConnection ld hl, CableClubNPCLinkClosedBecauseOfInactivityText call PrintText - jr Func_7298 ; 0x7285 $11 + jr .didNotConnect .failedToEstablishConnection ld hl, CableClubNPCAreaReservedFor2FriendsLinkedByCableText call PrintText - jr Func_7298 ; 0x728d $9 + jr .didNotConnect .choseNo call CloseLinkConnection ld hl, CableClubNPCPleaseComeAgainText call PrintText - ; fall through - -Func_7298: ; 7298 (1:7298) +.didNotConnect xor a ld hl, wUnknownSerialCounter ld [hli], a @@ -106,14 +103,11 @@ Func_7298: ; 7298 (1:7298) xor a ld [wMenuJoypadPollCount], a ret - -Func_72a8: ; 72a8 (1:72a8) +.connected xor a ld [hld], a ld [hl], a - ld hl, LinkMenu - ld b, BANK(LinkMenu) - jp Bankswitch + jpab LinkMenu CableClubNPCAreaReservedFor2FriendsLinkedByCableText: ; 72b3 (1:72b3) TX_FAR _CableClubNPCAreaReservedFor2FriendsLinkedByCableText diff --git a/engine/overworld/card_key.asm b/engine/overworld/card_key.asm index c4df0d51..cc9fe3a7 100755 --- a/engine/overworld/card_key.asm +++ b/engine/overworld/card_key.asm @@ -27,8 +27,8 @@ PrintCardKeyText: ; 52673 (14:6673) jr z, .noCardKey call GetCoordsInFrontOfPlayer push de - ld a, $1 - ld [H_DOWNARROWBLINKCNT2], a + tx_pre_id CardKeySuccessText + ld [hSpriteIndexOrTextID], a call PrintPredefTextID pop de srl d @@ -47,15 +47,15 @@ PrintCardKeyText: ; 52673 (14:6673) .notSilphCo11F ld a, $e .replaceCardKeyDoorTileBlock - ld [wd09f], a + ld [wNewTileBlockID], a predef ReplaceTileBlock ld hl, wd126 set 5, [hl] - ld a, (SFX_1f_57 - SFX_Headers_1f) / 3 + ld a, SFX_GO_INSIDE jp PlaySound .noCardKey - ld a, $2 - ld [H_DOWNARROWBLINKCNT2], a + tx_pre_id CardKeyFailText + ld [hSpriteIndexOrTextID], a jp PrintPredefTextID SilphCoMapList: ; 526e3 (14:66e3) diff --git a/engine/overworld/cinnabar_lab.asm b/engine/overworld/cinnabar_lab.asm index eefa2176..f81324e0 100755 --- a/engine/overworld/cinnabar_lab.asm +++ b/engine/overworld/cinnabar_lab.asm @@ -2,36 +2,36 @@ GiveFossilToCinnabarLab: ; 61006 (18:5006) ld hl, wd730 set 6, [hl] xor a - ld [wCurrentMenuItem], a ; wCurrentMenuItem - ld a, $3 - ld [wMenuWatchedKeys], a ; wMenuWatchedKeys - ld a, [wcd37] + ld [wCurrentMenuItem], a + ld a, A_BUTTON | B_BUTTON + ld [wMenuWatchedKeys], a + ld a, [wFilteredBagItemsCount] dec a - ld [wMaxMenuItem], a ; wMaxMenuItem - ld a, $2 - ld [wTopMenuItemY], a ; wTopMenuItemY - ld a, $1 - ld [wTopMenuItemX], a ; wTopMenuItemX - ld a, [wcd37] + ld [wMaxMenuItem], a + ld a, 2 + ld [wTopMenuItemY], a + ld a, 1 + ld [wTopMenuItemX], a + ld a, [wFilteredBagItemsCount] dec a - ld bc, $2 - ld hl, $3 + ld bc, 2 + ld hl, 3 call AddNTimes dec l ld b, l ld c, $d - ld hl, wTileMap + coord hl, 0, 0 call TextBoxBorder call UpdateSprites - call Func_610c2 + call PrintFossilsInBag ld hl, wd730 res 6, [hl] call HandleMenuInput - bit 1, a - jr nz, .asm_610a7 - ld hl, wcc5b - ld a, [wCurrentMenuItem] ; wCurrentMenuItem - ld d, $0 + bit 1, a ; pressed B? + jr nz, .cancelledGivingFossil + ld hl, wFilteredBagItems + ld a, [wCurrentMenuItem] + ld d, 0 ld e, a add hl, de ld a, [hl] @@ -55,21 +55,19 @@ GiveFossilToCinnabarLab: ; 61006 (18:5006) ld hl, LabFossil_610ae call PrintText call YesNoChoice - ld a, [wCurrentMenuItem] ; wCurrentMenuItem + ld a, [wCurrentMenuItem] and a - jr nz, .asm_610a7 + jr nz, .cancelledGivingFossil ld hl, LabFossil_610b3 call PrintText ld a, [W_FOSSILITEM] - ld [$ffdb], a + ld [hItemToRemoveID], a callba RemoveItemByID ld hl, LabFossil_610b8 call PrintText - ld hl, wd7a3 - set 0, [hl] - set 1, [hl] + SetEvents EVENT_GAVE_FOSSIL_TO_LAB, EVENT_LAB_STILL_REVIVING_FOSSIL ret -.asm_610a7 +.cancelledGivingFossil ld hl, LabFossil_610bd call PrintText ret @@ -90,27 +88,28 @@ LabFossil_610bd: ; 610bd (18:50bd) TX_FAR _Lab4Text_610bd db "@" -Func_610c2: ; 610c2 (18:50c2) - ld hl, wcc5b +PrintFossilsInBag: ; 610c2 (18:50c2) +; Prints each fossil in the player's bag on a separate line in the menu. + ld hl, wFilteredBagItems xor a - ld [$ffdb], a -.asm_610c8 + ld [hItemCounter], a +.loop ld a, [hli] cp $ff ret z push hl ld [wd11e], a call GetItemName - hlCoord 2, 2 - ld a, [$ffdb] - ld bc, $28 + coord hl, 2, 2 + ld a, [hItemCounter] + ld bc, SCREEN_WIDTH * 2 call AddNTimes ld de, wcd6d call PlaceString - ld hl, $ffdb + ld hl, hItemCounter inc [hl] pop hl - jr .asm_610c8 + jr .loop ; loads the names of the fossil item and the resulting mon LoadFossilItemAndMonName: ; 610eb (18:50eb) diff --git a/engine/overworld/cut.asm b/engine/overworld/cut.asm index 7b92bca3..30aedbc1 100755 --- a/engine/overworld/cut.asm +++ b/engine/overworld/cut.asm @@ -1,43 +1,43 @@ UsedCut: ; ef54 (3:6f54) xor a - ld [wcd6a], a - ld a, [W_CURMAPTILESET] ; W_CURMAPTILESET + ld [wActionResultOrTookBattleTurn], a ; initialise to failure value + ld a, [W_CURMAPTILESET] and a ; OVERWORLD - jr z, .asm_ef6b + jr z, .overworld cp GYM - jr nz, .asm_ef77 + jr nz, .nothingToCut ld a, [wTileInFrontOfPlayer] cp $50 ; gym cut tree - jr nz, .asm_ef77 - jr asm_ef82 -.asm_ef6b + jr nz, .nothingToCut + jr .canCut +.overworld dec a ld a, [wTileInFrontOfPlayer] cp $3d ; cut tree - jr z, asm_ef82 + jr z, .canCut cp $52 ; grass - jr z, asm_ef82 -.asm_ef77 - ld hl, NothingToCutText + jr z, .canCut +.nothingToCut + ld hl, .NothingToCutText jp PrintText -NothingToCutText: ; ef7d (3:6f7d) +.NothingToCutText TX_FAR _NothingToCutText db "@" -asm_ef82: ; ef82 (3:6f82) - ld [wcd4d], a - ld a, $1 - ld [wcd6a], a - ld a, [wWhichPokemon] ; wWhichPokemon - ld hl, wPartyMonNicks ; wPartyMonNicks +.canCut + ld [wCutTile], a + ld a, 1 + ld [wActionResultOrTookBattleTurn], a ; used cut + ld a, [wWhichPokemon] + ld hl, wPartyMonNicks call GetPartyMonName ld hl, wd730 set 6, [hl] call GBPalWhiteOutWithDelay3 call ClearSprites call RestoreScreenTilesAndReloadTilePatterns - ld a, $90 + ld a, SCREEN_HEIGHT_PIXELS ld [hWY], a call Delay3 call LoadGBPal @@ -53,14 +53,14 @@ asm_ef82: ; ef82 (3:6f82) res 6, [hl] ld a, $ff ld [wUpdateSpritesEnabled], a - call AnimateCutTree - ld de, CutTreeBlockSwaps ; $7100 - call Func_f09f + call InitCutAnimOAM + ld de, CutTreeBlockSwaps + call ReplaceTreeTileBlock call RedrawMapView - callba Func_79e96 + callba AnimCut ld a, $1 ld [wUpdateSpritesEnabled], a - ld a, (SFX_02_56 - SFX_Headers_02) / 3 + ld a, SFX_CUT call PlaySound ld a, $90 ld [hWY], a @@ -71,61 +71,62 @@ UsedCutText: ; eff2 (3:6ff2) TX_FAR _UsedCutText db "@" -AnimateCutTree: ; eff7 (3:6ff7) +InitCutAnimOAM: ; eff7 (3:6ff7) xor a - ld [wcd50], a + ld [wWhichAnimationOffsets], a ld a, $e4 - ld [rOBP1], a ; $ff49 - ld a, [wcd4d] + ld [rOBP1], a + ld a, [wCutTile] cp $52 - jr z, .asm_f020 - ld de, Overworld_GFX + $2d0 ; $42d0 ; cuttable tree sprite top row + jr z, .grass +; tree + ld de, Overworld_GFX + $2d0 ; cuttable tree sprite top row ld hl, vChars1 + $7c0 - ld bc, (BANK(Overworld_GFX) << 8) + $02 + lb bc, BANK(Overworld_GFX), $02 call CopyVideoData - ld de, Overworld_GFX + $3d0 ; $43d0 ; cuttable tree sprite bottom row + ld de, Overworld_GFX + $3d0 ; cuttable tree sprite bottom row ld hl, vChars1 + $7e0 - ld bc, (BANK(Overworld_GFX) << 8) + $02 + lb bc, BANK(Overworld_GFX), $02 call CopyVideoData - jr WriteCutTreeBoulderDustAnimationOAMBlock -.asm_f020 + jr WriteCutOrBoulderDustAnimationOAMBlock +.grass ld hl, vChars1 + $7c0 - call LoadCutTreeAnimationTilePattern + call LoadCutGrassAnimationTilePattern ld hl, vChars1 + $7d0 - call LoadCutTreeAnimationTilePattern + call LoadCutGrassAnimationTilePattern ld hl, vChars1 + $7e0 - call LoadCutTreeAnimationTilePattern + call LoadCutGrassAnimationTilePattern ld hl, vChars1 + $7f0 - call LoadCutTreeAnimationTilePattern - call WriteCutTreeBoulderDustAnimationOAMBlock + call LoadCutGrassAnimationTilePattern + call WriteCutOrBoulderDustAnimationOAMBlock ld hl, wOAMBuffer + $93 - ld de, $4 + ld de, 4 ld a, $30 ld c, e -.asm_f044 +.loop ld [hl], a add hl, de xor $60 dec c - jr nz, .asm_f044 + jr nz, .loop ret -LoadCutTreeAnimationTilePattern: ; f04c (3:704c) - ld de, AnimationTileset2 + $60 ; $474e ; tile depicting a leaf - ld bc, (BANK(AnimationTileset2) << 8) + $01 +LoadCutGrassAnimationTilePattern: ; f04c (3:704c) + ld de, AnimationTileset2 + $60 ; tile depicting a leaf + lb bc, BANK(AnimationTileset2), $01 jp CopyVideoData -WriteCutTreeBoulderDustAnimationOAMBlock: ; f055 (3:7055) - call GetCutTreeBoulderDustAnimationOffsets +WriteCutOrBoulderDustAnimationOAMBlock: ; f055 (3:7055) + call GetCutOrBoulderDustAnimationOffsets ld a, $9 - ld de, CutTreeBoulderDustAnimationTilesAndAttributes + ld de, CutOrBoulderDustAnimationTilesAndAttributes jp WriteOAMBlock -CutTreeBoulderDustAnimationTilesAndAttributes: ; f060 (3:7060) +CutOrBoulderDustAnimationTilesAndAttributes: ; f060 (3:7060) db $FC,$10,$FD,$10 db $FE,$10,$FF,$10 -GetCutTreeBoulderDustAnimationOffsets: ; f068 (3:7068) +GetCutOrBoulderDustAnimationOffsets: ; f068 (3:7068) ld hl, wSpriteStateData1 + 4 ld a, [hli] ; player's sprite screen Y position ld b, a @@ -138,12 +139,12 @@ GetCutTreeBoulderDustAnimationOffsets: ; f068 (3:7068) srl a ld e, a ld d, $0 ; de holds direction (00: down, 02: up, 04: left, 06: right) - ld a, [wcd50] + ld a, [wWhichAnimationOffsets] and a - ld hl, CutTreeAnimationOffsets - jr z, .asm_f084 + ld hl, CutAnimationOffsets + jr z, .next ld hl, BoulderDustAnimationOffsets -.asm_f084 +.next add hl, de ld e, [hl] inc hl @@ -156,7 +157,7 @@ GetCutTreeBoulderDustAnimationOffsets: ; f068 (3:7068) ld c, a ret -CutTreeAnimationOffsets: ; f08f (3:708f) +CutAnimationOffsets: ; f08f (3:708f) ; Each pair represents the x and y pixels offsets from the player of where the cut tree animation should be drawn db 8, 36 ; player is facing down db 8, 4 ; player is facing up @@ -171,75 +172,79 @@ BoulderDustAnimationOffsets: ; f097 (3:7097) db -24, 20 ; player is facing left db 40, 20 ; player is facing right -Func_f09f: ; f09f (3:709f) +ReplaceTreeTileBlock: ; f09f (3:709f) +; Determine the address of the tile block that contains the tile in front of the +; player (i.e. where the tree is) and replace it with the corresponding tile +; block that doesn't have the tree. push de - ld a, [W_CURMAPWIDTH] ; wd369 - add $6 + ld a, [W_CURMAPWIDTH] + add 6 ld c, a - ld b, $0 - ld d, $0 + ld b, 0 + ld d, 0 ld hl, wCurrentTileBlockMapViewPointer ld a, [hli] ld h, [hl] ld l, a add hl, bc - ld a, [wSpriteStateData1 + 9] + ld a, [wSpriteStateData1 + 9] ; player sprite's facing direction and a - jr z, .asm_f0c7 - cp $4 - jr z, .asm_f0cf - cp $8 - jr z, .asm_f0d7 - ld a, [W_XBLOCKCOORD] ; wd364 + jr z, .down + cp SPRITE_FACING_UP + jr z, .up + cp SPRITE_FACING_LEFT + jr z, .left +; right + ld a, [W_XBLOCKCOORD] and a - jr z, .asm_f0e0 - jr .asm_f0ec -.asm_f0c7 - ld a, [W_YBLOCKCOORD] ; wd363 + jr z, .centerTileBlock + jr .rightOfCenter +.down + ld a, [W_YBLOCKCOORD] and a - jr z, .asm_f0e0 - jr .asm_f0df -.asm_f0cf - ld a, [W_YBLOCKCOORD] ; wd363 + jr z, .centerTileBlock + jr .belowCenter +.up + ld a, [W_YBLOCKCOORD] and a - jr z, .asm_f0e1 - jr .asm_f0e0 -.asm_f0d7 - ld a, [W_XBLOCKCOORD] ; wd364 + jr z, .aboveCenter + jr .centerTileBlock +.left + ld a, [W_XBLOCKCOORD] and a - jr z, .asm_f0e6 - jr .asm_f0e0 -.asm_f0df + jr z, .leftOfCenter + jr .centerTileBlock +.belowCenter add hl, bc -.asm_f0e0 +.centerTileBlock add hl, bc -.asm_f0e1 +.aboveCenter ld e, $2 add hl, de - jr .asm_f0f0 -.asm_f0e6 + jr .next +.leftOfCenter ld e, $1 add hl, bc add hl, de - jr .asm_f0f0 -.asm_f0ec + jr .next +.rightOfCenter ld e, $3 add hl, bc add hl, de -.asm_f0f0 +.next pop de ld a, [hl] ld c, a -.asm_f0f3 +.loop ; find the matching tile block in the array ld a, [de] inc de inc de cp $ff ret z cp c - jr nz, .asm_f0f3 + jr nz, .loop dec de - ld a, [de] + ld a, [de] ; replacement tile block from matching array entry ld [hl], a ret diff --git a/engine/overworld/cut2.asm b/engine/overworld/cut2.asm index de2b9d55..1cf832b5 100755 --- a/engine/overworld/cut2.asm +++ b/engine/overworld/cut2.asm @@ -1,89 +1,89 @@ -Func_79e96: ; 79e96 (1e:5e96) - ld a, [wcd4d] +AnimCut: ; 79e96 (1e:5e96) + ld a, [wCutTile] cp $52 - jr z, .asm_79ec8 + jr z, .grass ld c, $8 -.asm_79e9f +.cutTreeLoop push bc ld hl, wOAMBuffer + $91 - ld a, $1 - ld [wd08a], a - ld c, $2 + ld a, 1 + ld [wCoordAdjustmentAmount], a + ld c, 2 call AdjustOAMBlockXPos2 ld hl, wOAMBuffer + $99 - ld a, $ff - ld [wd08a], a - ld c, $2 + ld a, -1 + ld [wCoordAdjustmentAmount], a + ld c, 2 call AdjustOAMBlockXPos2 - ld a, [rOBP1] ; $ff49 + ld a, [rOBP1] xor $64 - ld [rOBP1], a ; $ff49 + ld [rOBP1], a call DelayFrame pop bc dec c - jr nz, .asm_79e9f + jr nz, .cutTreeLoop ret -.asm_79ec8 - ld c, $2 -.asm_79eca +.grass + ld c, 2 +.cutGrassLoop push bc ld c, $8 - call Func_79eed - call Func_79f30 + call AnimCutGrass_UpdateOAMEntries + call AnimCutGrass_SwapOAMEntries ld c, $8 - call Func_79eed - call Func_79f30 + call AnimCutGrass_UpdateOAMEntries + call AnimCutGrass_SwapOAMEntries ld hl, wOAMBuffer + $90 - ld a, $2 - ld [wd08a], a - ld c, $4 + ld a, 2 + ld [wCoordAdjustmentAmount], a + ld c, 4 call AdjustOAMBlockYPos2 pop bc dec c - jr nz, .asm_79eca + jr nz, .cutGrassLoop ret -Func_79eed: ; 79eed (1e:5eed) +AnimCutGrass_UpdateOAMEntries: ; 79eed (1e:5eed) push bc ld hl, wOAMBuffer + $91 - ld a, $1 - ld [wd08a], a - ld c, $1 + ld a, 1 + ld [wCoordAdjustmentAmount], a + ld c, 1 call AdjustOAMBlockXPos2 ld hl, wOAMBuffer + $95 - ld a, $2 - ld [wd08a], a - ld c, $1 + ld a, 2 + ld [wCoordAdjustmentAmount], a + ld c, 1 call AdjustOAMBlockXPos2 ld hl, wOAMBuffer + $99 - ld a, $fe - ld [wd08a], a - ld c, $1 + ld a, -2 + ld [wCoordAdjustmentAmount], a + ld c, 1 call AdjustOAMBlockXPos2 ld hl, wOAMBuffer + $9d - ld a, $ff - ld [wd08a], a - ld c, $1 + ld a, -1 + ld [wCoordAdjustmentAmount], a + ld c, 1 call AdjustOAMBlockXPos2 - ld a, [rOBP1] ; $ff49 + ld a, [rOBP1] xor $64 - ld [rOBP1], a ; $ff49 + ld [rOBP1], a call DelayFrame pop bc dec c - jr nz, Func_79eed + jr nz, AnimCutGrass_UpdateOAMEntries ret -Func_79f30: ; 79f30 (1e:5f30) +AnimCutGrass_SwapOAMEntries: ; 79f30 (1e:5f30) ld hl, wOAMBuffer + $90 - ld de, wHPBarMaxHP + ld de, wBuffer ld bc, $8 call CopyData ld hl, wOAMBuffer + $98 ld de, wOAMBuffer + $90 ld bc, $8 call CopyData - ld hl, wHPBarMaxHP + ld hl, wBuffer ld de, wOAMBuffer + $98 ld bc, $8 jp CopyData diff --git a/engine/overworld/doors.asm b/engine/overworld/doors.asm index ac345af9..641c021f 100755 --- a/engine/overworld/doors.asm +++ b/engine/overworld/doors.asm @@ -1,8 +1,8 @@ ; returns whether the player is standing on a door tile in carry IsPlayerStandingOnDoorTile: ; 1a609 (6:6609) push de - ld hl, DoorTileIDPointers ; $662c - ld a, [W_CURMAPTILESET] ; W_CURMAPTILESET + ld hl, DoorTileIDPointers + ld a, [W_CURMAPTILESET] ld de, $3 call IsInArray pop de diff --git a/engine/overworld/elevator.asm b/engine/overworld/elevator.asm index 3a23d410..05a9cc4e 100755 --- a/engine/overworld/elevator.asm +++ b/engine/overworld/elevator.asm @@ -1,46 +1,48 @@ ShakeElevator: ; 7bf15 (1e:7f15) - ld de, $ffe0 - call Func_7bf64 - ld de, $240 - call Func_7bf64 + ld de, -$20 + call ShakeElevatorRedrawRow + ld de, SCREEN_HEIGHT * $20 + call ShakeElevatorRedrawRow call Delay3 ld a, $ff call PlaySound ld a, [hSCY] ld d, a ld e, $1 - ; number of times to play collision sfx - ld b, $64 -.asm_7bf30 + ld b, 100 +.shakeLoop ; scroll the BG up and down and play a sound effect ld a, e xor $fe ld e, a add d ld [hSCY], a push bc - ld c, BANK(SFX_02_5b) - ld a, (SFX_02_5b - SFX_Headers_02) / 3 + ld c, BANK(SFX_Collision_1) + ld a, SFX_COLLISION call PlayMusic pop bc - ld c, $2 + ld c, 2 call DelayFrames dec b - jr nz, .asm_7bf30 + jr nz, .shakeLoop ld a, d ld [hSCY], a ld a, $ff call PlaySound - ld c, BANK(SFX_02_5f) - ld a, (SFX_02_5f - SFX_Headers_02) / 3 + ld c, BANK(SFX_Safari_Zone_PA) + ld a, SFX_SAFARI_ZONE_PA call PlayMusic -.asm_7bf57 - ld a, [wc02a] +.musicLoop + ld a, [wChannelSoundIDs + CH4] cp $b9 - jr z, .asm_7bf57 + jr z, .musicLoop call UpdateSprites jp PlayDefaultMusic -Func_7bf64: ; 7bf64 (1e:7f64) +ShakeElevatorRedrawRow: ; 7bf64 (1e:7f64) +; This function is used to redraw certain portions of the screen, but it does +; not appear to ever result in any visible effect, so this function seems to +; be pointless. ld hl, wMapViewVRAMPointer + 1 ld a, [hld] push af diff --git a/engine/overworld/emotion_bubbles.asm b/engine/overworld/emotion_bubbles.asm index 7106063b..f8665dd6 100755 --- a/engine/overworld/emotion_bubbles.asm +++ b/engine/overworld/emotion_bubbles.asm @@ -1,30 +1,33 @@ EmotionBubble: ; 17c47 (5:7c47) - ld a, [wcd50] + ld a, [wWhichEmotionBubble] ld c, a - ld b, $0 - ld hl, EmotionBubblesPointerTable ; $7caf + ld b, 0 + ld hl, EmotionBubblesPointerTable add hl, bc add hl, bc ld e, [hl] inc hl ld d, [hl] ld hl, vChars1 + $780 - ld bc, (BANK(EmotionBubblesPointerTable) << 8) + $04 + lb bc, BANK(EmotionBubbles), $04 call CopyVideoData ld a, [wUpdateSpritesEnabled] push af ld a, $ff ld [wUpdateSpritesEnabled], a ld a, [wd736] - bit 6, a + bit 6, a ; are the last 4 OAM entries reserved for a shadow or fishing rod? ld hl, wOAMBuffer + $8f ld de, wOAMBuffer + $9f - jr z, .asm_17c7a + jr z, .next ld hl, wOAMBuffer + $7f ld de, wOAMBuffer + $8f -.asm_17c7a + +; Copy OAM data 16 bytes forward to make room for emotion bubble OAM data at the +; start of the OAM buffer. +.next ld bc, $90 -.asm_17c7d +.loop ld a, [hl] ld [de], a dec hl @@ -32,12 +35,14 @@ EmotionBubble: ; 17c47 (5:7c47) dec bc ld a, c or b - jr nz, .asm_17c7d + jr nz, .loop + +; get the screen coordinates of the sprite the bubble is to be displayed above ld hl, wSpriteStateData1 + 4 - ld a, [wcd4f] + ld a, [wEmotionBubbleSpriteIndex] swap a ld c, a - ld b, $0 + ld b, 0 add hl, bc ld a, [hli] ld b, a @@ -45,10 +50,11 @@ EmotionBubble: ; 17c47 (5:7c47) ld a, [hl] add $8 ld c, a - ld de, EmotionBubblesOAM ; $7cb5 + + ld de, EmotionBubblesOAM xor a call WriteOAMBlock - ld c, $3c + ld c, 60 call DelayFrames pop af ld [wUpdateSpritesEnabled], a diff --git a/engine/overworld/healing_machine.asm b/engine/overworld/healing_machine.asm index 23e24b23..8269aefd 100755 --- a/engine/overworld/healing_machine.asm +++ b/engine/overworld/healing_machine.asm @@ -1,59 +1,56 @@ AnimateHealingMachine: ; 7048b (1c:448b) ld de, PokeCenterFlashingMonitorAndHealBall ; $44b7 ld hl, vChars0 + $7c0 - ld bc, (BANK(PokeCenterFlashingMonitorAndHealBall) << 8) + $03 + lb bc, BANK(PokeCenterFlashingMonitorAndHealBall), $03 ; loads one too many tiles call CopyVideoData ld hl, wUpdateSpritesEnabled ld a, [hl] push af ld [hl], $ff push hl - ld a, [rOBP1] ; $ff49 + ld a, [rOBP1] push af ld a, $e0 ld [rOBP1], a ; $ff49 call Func_3061 ld hl, wOAMBuffer + $84 ld de, PokeCenterOAMData ; $44d7 - call Func_7055a - ld a, $4 - ld [wMusicHeaderPointer], a + call CopyHealingMachineOAM + ld a, 4 + ld [wAudioFadeOutControl], a call StopAllMusic - ;ld a, $ff - ;ld [wc0ee], a - ;call PlaySound -.asm_704ba - ld a, [wMusicHeaderPointer] +.waitLoop + ld a, [wAudioFadeOutControl] and a - jr nz, .asm_704ba + jr nz, .waitLoop ld a, [wPartyCount] ; wPartyCount ld b, a -.asm_704c4 - call Func_7055a +.partyLoop + call CopyHealingMachineOAM ld a, $9e ; (SFX_02_4a - SFX_Headers_02) / 3 call PlaySound - ld c, $1e + ld c, 30 call DelayFrames dec b - jr nz, .asm_704c4 - ld a, [wc0ef] + jr nz, .partyLoop + ld a, [wAudioROMBank] cp $1f - ld [wc0f0], a - jr nz, .asm_704e6 + ld [wAudioSavedROMBank], a + jr nz, .next call StopAllMusic ld a, $2 ; BANK(Music_PkmnHealed) - ld [wc0ef], a -.asm_704e6 + ld [wAudioROMBank], a +.next ld a, $e8 ; MUSIC_PKMN_HEALED - ld [wc0ee], a + ld [wNewSoundID], a call PlaySound ld d, $28 call FlashSprite8Times -.asm_704f3 +.waitLoop2 ld a, [wc026] cp $e8 ; MUSIC_PKMN_HEALED - jr z, .asm_704f3 - ld c, $20 + jr z, .waitLoop2 + ld c, 32 call DelayFrames pop af ld [rOBP1], a ; $ff49 @@ -89,7 +86,8 @@ FlashSprite8Times: ; 70547 (1c:4547) jr nz, .loop ret -Func_7055a: ; 7055a (1c:455a) +CopyHealingMachineOAM: ; 7055a (1c:455a) +; copy one OAM entry and advance the pointers ld a, [de] inc de ld [hli], a diff --git a/engine/overworld/hidden_items.asm b/engine/overworld/hidden_items.asm index 17288a17..28528116 100755 --- a/engine/overworld/hidden_items.asm +++ b/engine/overworld/hidden_items.asm @@ -1,43 +1,41 @@ HiddenItems: ; 76688 (1d:6688) ld hl, HiddenItemCoords - call Func_76857 - ld [wTrainerScreenX], a - ld hl, wd6f0 - ld a, [wTrainerScreenX] + call FindHiddenItemOrCoinsIndex + ld [wHiddenItemOrCoinsIndex], a + ld hl, wObtainedHiddenItemsFlags + ld a, [wHiddenItemOrCoinsIndex] ld c, a - ld b, $2 + ld b, FLAG_TEST predef FlagActionPredef ld a, c and a ret nz call EnableAutoTextBoxDrawing - ld a, $1 + ld a, 1 ld [wDoNotWaitForButtonPressAfterDisplayingText], a - ld a, [wWhichTrade] ; item ID + ld a, [wHiddenObjectFunctionArgument] ; item ID ld [wd11e], a call GetItemName - ld a, $24 - jp PrintPredefTextID + tx_pre_jump FoundHiddenItemText INCLUDE "data/hidden_item_coords.asm" FoundHiddenItemText: ; 7675b (1d:675b) -; XXX where is the pointer to this? TX_FAR _FoundHiddenItemText - db $8 - ld a, [wWhichTrade] ; item ID + TX_ASM + ld a, [wHiddenObjectFunctionArgument] ; item ID ld b, a ld c, 1 call GiveItem jr nc, .BagFull - ld hl, wd6f0 - ld a, [wTrainerScreenX] + ld hl, wObtainedHiddenItemsFlags + ld a, [wHiddenItemOrCoinsIndex] ld c, a - ld b, $1 + ld b, FLAG_SET predef FlagActionPredef - ld a, (SFX_02_3b - SFX_Headers_02) / 3 - call PlaySoundWaitForCurrent ; play sound - call WaitForSoundToFinish ; wait for sound to finish playing + ld a, SFX_GET_ITEM_2 + call PlaySoundWaitForCurrent + call WaitForSoundToFinish jp TextScriptEnd .BagFull call WaitForTextScrollButtonPress ; wait for button press @@ -53,26 +51,26 @@ HiddenItemBagFullText: ; 76794 (1d:6794) HiddenCoins: ; 76799 (1d:6799) ld b, COIN_CASE - predef IsItemInBag_ + predef GetQuantityOfItemInBag ld a, b and a ret z ld hl, HiddenCoinCoords - call Func_76857 - ld [wTrainerScreenX], a - ld hl, wd6fe - ld a, [wTrainerScreenX] + call FindHiddenItemOrCoinsIndex + ld [wHiddenItemOrCoinsIndex], a + ld hl, wObtainedHiddenCoinsFlags + ld a, [wHiddenItemOrCoinsIndex] ld c, a - ld b, $2 + ld b, FLAG_TEST predef FlagActionPredef ld a, c and a ret nz xor a - ld [$ff9f], a - ld [$ffa0], a - ld [$ffa1], a - ld a, [wWhichTrade] + ld [hUnusedCoinsByte], a + ld [hCoins], a + ld [hCoins + 1], a + ld a, [wHiddenObjectFunctionArgument] sub COIN cp 10 jr z, .bcd10 @@ -83,28 +81,28 @@ HiddenCoins: ; 76799 (1d:6799) jr .bcd100 .bcd10 ld a, $10 - ld [$ffa1], a + ld [hCoins + 1], a jr .bcddone .bcd20 ld a, $20 - ld [$ffa1], a + ld [hCoins + 1], a jr .bcddone .bcd40 ; due to a typo, this is never used ld a, $40 - ld [$ffa1], a + ld [hCoins + 1], a jr .bcddone .bcd100 ld a, $1 - ld [$ffa0], a + ld [hCoins], a .bcddone ld de, wPlayerCoins + 1 - ld hl, $ffa1 + ld hl, hCoins + 1 ld c, $2 predef AddBCDPredef - ld hl, wd6fe - ld a, [wTrainerScreenX] + ld hl, wObtainedHiddenCoinsFlags + ld a, [wHiddenItemOrCoinsIndex] ld c, a - ld b, $1 + ld b, FLAG_SET predef FlagActionPredef call EnableAutoTextBoxDrawing ld a, [wPlayerCoins] @@ -113,10 +111,10 @@ HiddenCoins: ; 76799 (1d:6799) ld a, [wPlayerCoins + 1] cp $99 jr nz, .RoomInCoinCase - ld a, $2c + tx_pre_id DroppedHiddenCoinsText jr .done .RoomInCoinCase - ld a, $2b + tx_pre_id FoundHiddenCoinsText .done jp PrintPredefTextID @@ -132,31 +130,31 @@ DroppedHiddenCoinsText: ; 7684d (1d:684d) TX_FAR _DroppedHiddenCoinsText db "@" -Func_76857: ; 76857 (1d:6857) - ld a, [wTrainerScreenY] +FindHiddenItemOrCoinsIndex: ; 76857 (1d:6857) + ld a, [wHiddenObjectY] ld d, a - ld a, [wTrainerScreenX] + ld a, [wHiddenObjectX] ld e, a ld a, [W_CURMAP] ld b, a - ld c, $ff + ld c, -1 .loop inc c ld a, [hli] cp $ff ; end of the list? ret z ; if so, we're done here cp b - jr nz, .asm_76877 ; 0x7686b $a + jr nz, .next1 ld a, [hli] cp d - jr nz, .asm_76878 ; 0x7686f $7 + jr nz, .next2 ld a, [hli] cp e jr nz, .loop ld a, c ret -.asm_76877 +.next1 inc hl -.asm_76878 +.next2 inc hl jr .loop diff --git a/engine/overworld/hidden_objects.asm b/engine/overworld/hidden_objects.asm index ae67aeed..cabfc093 100755 --- a/engine/overworld/hidden_objects.asm +++ b/engine/overworld/hidden_objects.asm @@ -1,4 +1,4 @@ -Func_46981: ; 46981 (11:6981) +IsPlayerOnDungeonWarp: ; 46981 (11:6981) xor a ld [wWhichDungeonWarp], a ld a, [wd72d] @@ -6,7 +6,7 @@ Func_46981: ; 46981 (11:6981) ret nz call ArePlayerCoordsInArray ret nc - ld a, [wWhichTrade] + ld a, [wCoordIndex] ld [wWhichDungeonWarp], a ld hl, wd72d set 4, [hl] @@ -58,7 +58,7 @@ CheckForHiddenObject: ; 469a0 (11:69a0) ld [wHiddenObjectX], a ld c, a call CheckIfCoordsInFrontOfPlayerMatch - ld a, [$ffea] + ld a, [hCoordsInFrontOfPlayerMatch] and a jr z, .foundMatchingObject inc hl @@ -85,7 +85,7 @@ CheckForHiddenObject: ; 469a0 (11:69a0) ret ; checks if the coordinates in front of the player's sprite match Y in b and X in c -; [$ffea] = $00 if they match, $ff if they don't match +; [hCoordsInFrontOfPlayerMatch] = $00 if they match, $ff if they don't match CheckIfCoordsInFrontOfPlayerMatch: ; 46a01 (11:6a01) ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction cp SPRITE_FACING_UP @@ -127,7 +127,7 @@ CheckIfCoordsInFrontOfPlayerMatch: ; 46a01 (11:6a01) .didNotMatch ld a, $ff .done - ld [$ffea], a + ld [hCoordsInFrontOfPlayerMatch], a ret INCLUDE "data/hidden_objects.asm" diff --git a/engine/overworld/item.asm b/engine/overworld/item.asm index a49fc268..6fbe823d 100644 --- a/engine/overworld/item.asm +++ b/engine/overworld/item.asm @@ -1,7 +1,7 @@ -PickupItem: +PickUpItem: call EnableAutoTextBoxDrawing - ld a, [H_DOWNARROWBLINKCNT2] ; $ff8c + ld a, [hSpriteIndexOrTextID] ld b, a ld hl, W_MISSABLEOBJECTLIST .missableObjectsListLoop @@ -18,7 +18,7 @@ PickupItem: ld [$ffdb], a ld hl, W_MAPSPRITEEXTRADATA - ld a, [H_DOWNARROWBLINKCNT2] ; $ff8c + ld a, [hSpriteIndexOrTextID] dec a add a ld d, 0 @@ -31,7 +31,7 @@ PickupItem: jr nc, .BagFull ld a, [$ffdb] - ld [wcc4d], a + ld [wMissableObjectIndex], a predef HideObject ld a, 1 ld [wDoNotWaitForButtonPressAfterDisplayingText], a diff --git a/engine/overworld/ledges.asm b/engine/overworld/ledges.asm index b8c19181..df4273fd 100755 --- a/engine/overworld/ledges.asm +++ b/engine/overworld/ledges.asm @@ -2,7 +2,7 @@ HandleLedges: ; 1a672 (6:6672) ld a, [wd736] bit 6, a ; already jumping down ledge ret nz - ld a, [W_CURMAPTILESET] ; W_CURMAPTILESET + ld a, [W_CURMAPTILESET] and a ; OVERWORLD ret nz predef GetTileAndCoordsInFrontOfPlayer @@ -50,7 +50,7 @@ HandleLedges: ; 1a672 (6:6672) ld a, $2 ld [wSimulatedJoypadStatesIndex], a call LoadHoppingShadowOAM - ld a, (SFX_02_4e - SFX_Headers_02) / 3 + ld a, SFX_LEDGE call PlaySound ret @@ -69,16 +69,17 @@ LedgeTiles: ; 1a6cf (6:66cf) LoadHoppingShadowOAM: ; 1a6f0 (6:66f0) ld hl, vChars1 + $7f0 ld de, LedgeHoppingShadow - ld bc, (BANK(LedgeHoppingShadow) << 8) + $01 + lb bc, BANK(LedgeHoppingShadow), (LedgeHoppingShadowEnd - LedgeHoppingShadow) / $8 call CopyVideoDataDouble ld a, $9 - ld bc, $5448 ; b, c = y, x coordinates of shadow + lb bc, $54, $48 ; b, c = y, x coordinates of shadow ld de, LedgeHoppingShadowOAM call WriteOAMBlock ret LedgeHoppingShadow: ; 1a708 (6:6708) INCBIN "gfx/ledge_hopping_shadow.1bpp" +LedgeHoppingShadowEnd: LedgeHoppingShadowOAM: ; 1a710 (6:6710) db $FF,$10,$FF,$20 diff --git a/engine/overworld/map_sprites.asm b/engine/overworld/map_sprites.asm index 747a0a45..84d67b36 100755 --- a/engine/overworld/map_sprites.asm +++ b/engine/overworld/map_sprites.asm @@ -39,7 +39,7 @@ LoadMapSpriteTilePatterns: ; 17871 (5:7871) ld b,$10 ; number of sprite slots ld hl,wSpriteStateData2 + $0d xor a - ld [$ff8e],a ; 4-tile sprite counter + ld [hFourTileSpriteCount],a .copyPictureIDLoop ; loop to copy picture ID from $C2XD to $C2XE ld a,[hli] ; $C2XD (sprite picture ID) ld [hld],a ; $C2XE @@ -98,14 +98,14 @@ LoadMapSpriteTilePatterns: ; 17871 (5:7871) cp a,SPRITE_BALL ; is it a 4-tile sprite? jr c,.notFourTileSprite pop af - ld a,[$ff8e] ; 4-tile sprite counter + ld a,[hFourTileSpriteCount] add a,11 jr .storeVRAMSlot .notFourTileSprite pop af .storeVRAMSlot ld [hl],a ; store VRAM slot at $C2XE - ld [$ff8d],a ; used to determine if it's 4-tile sprite later + ld [hVRAMSlot],a ; used to determine if it's 4-tile sprite later ld a,b ; a = current sprite picture ID dec a add a @@ -128,7 +128,7 @@ LoadMapSpriteTilePatterns: ; 17871 (5:7871) push bc ld hl,vNPCSprites ; VRAM base address ld bc,$c0 ; number of bytes per VRAM slot - ld a,[$ff8d] + ld a,[hVRAMSlot] cp a,11 ; is it a 4-tile sprite? jr nc,.fourTileSpriteVRAMAddr ld d,a @@ -142,13 +142,13 @@ LoadMapSpriteTilePatterns: ; 17871 (5:7871) jr .loadStillTilePattern .fourTileSpriteVRAMAddr ld hl,vSprites + $7c0 ; address for second 4-tile sprite - ld a,[$ff8e] ; 4-tile sprite counter - and a ; is it the first 4-tile sprite? + ld a,[hFourTileSpriteCount] + and a jr nz,.loadStillTilePattern ; if it's the first 4-tile sprite ld hl,vSprites + $780 ; address for first 4-tile sprite inc a - ld [$ff8e],a ; 4-tile sprite counter + ld [hFourTileSpriteCount],a .loadStillTilePattern pop bc pop de @@ -168,7 +168,7 @@ LoadMapSpriteTilePatterns: ; 17871 (5:7871) .skipFirstLoad pop de pop hl - ld a,[$ff8d] + ld a,[hVRAMSlot] cp a,11 ; is it a 4-tile sprite? jr nc,.skipSecondLoad ; if so, there is no second block push de diff --git a/engine/overworld/movement.asm b/engine/overworld/movement.asm index c4482700..be10fd69 100644 --- a/engine/overworld/movement.asm +++ b/engine/overworld/movement.asm @@ -12,7 +12,7 @@ UpdatePlayerSprite: ; 4e31 (1:4e31) ; the maximum number for map tiles .checkIfTextBoxInFrontOfSprite aCoord 8, 9 - ld [$ff93], a + ld [hTilePlayerStandingOn], a cp $60 jr c, .lowerLeftTileIsMapTile .disableSprite @@ -21,52 +21,54 @@ UpdatePlayerSprite: ; 4e31 (1:4e31) ret .lowerLeftTileIsMapTile call DetectCollisionBetweenSprites - ld h, $c1 - ld a, [wWalkCounter] ; wcfc5 + ld h, wSpriteStateData1 / $100 + ld a, [wWalkCounter] and a - jr nz, .asm_4e90 - ld a, [wd528] - bit 2, a - jr z, .asm_4e65 - xor a - jr .asm_4e86 -.asm_4e65 - bit 3, a - jr z, .asm_4e6d - ld a, $4 - jr .asm_4e86 -.asm_4e6d - bit 1, a - jr z, .asm_4e75 - ld a, $8 - jr .asm_4e86 -.asm_4e75 - bit 0, a - jr z, .asm_4e7d - ld a, $c - jr .asm_4e86 -.asm_4e7d + jr nz, .moving + ld a, [wPlayerMovingDirection] +; check if down + bit PLAYER_DIR_BIT_DOWN, a + jr z, .checkIfUp + xor a ; ld a, SPRITE_FACING_DOWN + jr .next +.checkIfUp + bit PLAYER_DIR_BIT_UP, a + jr z, .checkIfLeft + ld a, SPRITE_FACING_UP + jr .next +.checkIfLeft + bit PLAYER_DIR_BIT_LEFT, a + jr z, .checkIfRight + ld a, SPRITE_FACING_LEFT + jr .next +.checkIfRight + bit PLAYER_DIR_BIT_RIGHT, a + jr z, .notMoving + ld a, SPRITE_FACING_RIGHT + jr .next +.notMoving +; zero the animation counters xor a ld [wSpriteStateData1 + 7], a ld [wSpriteStateData1 + 8], a - jr .asm_4eab -.asm_4e86 - ld [wSpriteStateData1 + 9], a + jr .calcImageIndex +.next + ld [wSpriteStateData1 + 9], a ; facing direction ld a, [wFontLoaded] bit 0, a - jr nz, .asm_4e7d -.asm_4e90 + jr nz, .notMoving +.moving ld a, [wd736] - bit 7, a - jr nz, .asm_4eb6 + bit 7, a ; is the player sprite spinning due to a spin tile? + jr nz, .skipSpriteAnim ld a, [H_CURRENTSPRITEOFFSET] add $7 ld l, a ld a, [hl] inc a ld [hl], a - cp $4 - jr nz, .asm_4eab + cp 4 + jr nz, .calcImageIndex xor a ld [hl], a inc hl @@ -74,28 +76,32 @@ UpdatePlayerSprite: ; 4e31 (1:4e31) inc a and $3 ld [hl], a -.asm_4eab +.calcImageIndex ld a, [wSpriteStateData1 + 8] ld b, a ld a, [wSpriteStateData1 + 9] add b ld [wSpriteStateData1 + 2], a -.asm_4eb6 - ld a, [$ff93] +.skipSpriteAnim +; If the player is standing on a grass tile, make the player's sprite have +; lower priority than the background so that it's partially obscured by the +; grass. Only the lower half of the sprite is permitted to have the priority +; bit set by later logic. + ld a, [hTilePlayerStandingOn] ld c, a ld a, [W_GRASSTILE] cp c ld a, $0 - jr nz, .asm_4ec3 + jr nz, .next2 ld a, $80 -.asm_4ec3 +.next2 ld [wSpriteStateData2 + $07], a ret -Func_4ec7: ; 4ec7 (1:4ec7) +UnusedReadSpriteDataFunction: ; 4ec7 (1:4ec7) push bc push af - ld a, [$ffda] + ld a, [H_CURRENTSPRITEOFFSET] ld c, a pop af add c @@ -103,12 +109,12 @@ Func_4ec7: ; 4ec7 (1:4ec7) pop bc ret -Func_4ed1: ; 4ed1 (1:4ed1) +UpdateNPCSprite: ; 4ed1 (1:4ed1) ld a, [H_CURRENTSPRITEOFFSET] swap a dec a add a - ld hl, W_MAPSPRITEDATA ; wd4e4 + ld hl, W_MAPSPRITEDATA add l ld l, a ld a, [hl] ; read movement byte 2 @@ -138,7 +144,7 @@ Func_4ed1: ; 4ed1 (1:4ed1) jp z, UpdateSpriteMovementDelay ; c1x1 == 2 cp $3 jp z, UpdateSpriteInWalkingAnimation ; c1x1 == 3 - ld a, [wWalkCounter] ; wcfc5 + ld a, [wWalkCounter] and a ret nz ; don't do anything yet if player is currently moving (redundant, already tested in CheckSpriteAvailability) call InitializeSpriteScreenPosition @@ -148,40 +154,43 @@ Func_4ed1: ; 4ed1 (1:4ed1) ld l, a ld a, [hl] ; c2x6: movement byte 1 inc a - jr z, .asm_4f59 ; value $FF + jr z, .randomMovement ; value $FF inc a - jr z, .asm_4f59 ; value $FE + jr z, .randomMovement ; value $FE +; scripted movement dec a - ld [hl], a ; (temporarily) increment movement byte 1 + ld [hl], a ; increment movement byte 1 (movement data index) dec a push hl - ld hl, wcf0f - dec [hl] ; decrement wcf0f + ld hl, wNPCNumScriptedSteps + dec [hl] ; decrement wNPCNumScriptedSteps pop hl - ld de, wcc5b - call LoadDEPlusA ; a = [wcc5b + movement byte 1] + ld de, wNPCMovementDirections + call LoadDEPlusA ; a = [wNPCMovementDirections + movement byte 1] cp $e0 jp z, ChangeFacingDirection cp $ff - jr nz, .asm_4f4b - ld [hl], a ; reset movement byte 1 to initial value + jr nz, .next +; reached end of wNPCMovementDirections list + ld [hl], a ; store $ff in movement byte 1, disabling scripted movement ld hl, wd730 res 0, [hl] xor a ld [wSimulatedJoypadStatesIndex], a ld [wWastedByteCD3A], a ret -.asm_4f4b +.next cp $fe - jr nz, .asm_4f5f + jr nz, .determineDirection +; current NPC movement data is $fe. this seems buggy ld [hl], $1 ; set movement byte 1 to $1 - ld de, wcc5b - call LoadDEPlusA ; a = [wcc5b + $fe] (?) - jr .asm_4f5f -.asm_4f59 - call getTileSpriteStandsOn + ld de, wNPCMovementDirections + call LoadDEPlusA ; a = [wNPCMovementDirections + $fe] (?) + jr .determineDirection +.randomMovement + call GetTileSpriteStandsOn call Random -.asm_4f5f +.determineDirection ld b, a ld a, [wCurSpriteMovement2] cp $d0 @@ -199,11 +208,10 @@ Func_4ed1: ; 4ed1 (1:4ed1) cp $2 jr z, .moveLeft ; movement byte 2 = $2 only allows left or right .moveDown - ld de, 2*20 + ld de, 2*SCREEN_WIDTH add hl, de ; move tile pointer two rows down - ld de, $100 - - ld bc, $400 + lb de, 1, 0 + lb bc, 4, SPRITE_FACING_DOWN jr TryWalking .notDown cp $80 ; $40 <= a < $80: up (or right) @@ -212,10 +220,10 @@ Func_4ed1: ; 4ed1 (1:4ed1) cp $2 jr z, .moveRight ; movement byte 2 = $2 only allows left or right .moveUp - ld de, -2*20 ; $ffd8 + ld de, -2*SCREEN_WIDTH add hl, de ; move tile pointer two rows up - ld de, $ff00 - ld bc, $804 + lb de, -1, 0 + lb bc, 8, SPRITE_FACING_UP jr TryWalking .notUp cp $c0 ; $80 <= a < $c0: left (or up) @@ -226,8 +234,8 @@ Func_4ed1: ; 4ed1 (1:4ed1) .moveLeft dec hl dec hl ; move tile pointer two columns left - ld de, $ff - ld bc, $208 + lb de, 0, -1 + lb bc, 2, SPRITE_FACING_LEFT jr TryWalking .notLeft ; $c0 <= a: right (or down) ld a, [wCurSpriteMovement2] @@ -236,8 +244,8 @@ Func_4ed1: ; 4ed1 (1:4ed1) .moveRight inc hl inc hl ; move tile pointer two columns right - ld de, $1 - ld bc, $10c + lb de, 0, 1 + lb bc, 1, SPRITE_FACING_RIGHT jr TryWalking ; changes facing direction by zeroing the movement delta and calling TryWalking @@ -249,7 +257,7 @@ ChangeFacingDirection: ; 4fc8 (1:4fc8) ; c: new facing direction (0,4,8 or $c) ; d: Y movement delta (-1, 0 or 1) ; e: X movement delta (-1, 0 or 1) -; hl: pointer to tile the sprite would wlak onto +; hl: pointer to tile the sprite would walk onto ; set carry on failure, clears carry on success TryWalking: ; 4fcb (1:4fcb) push hl @@ -397,23 +405,23 @@ InitializeSpriteFacingDirection: ; 507f (1:507f) bit 5, a jr nz, notYetMoving res 7, [hl] - ld a, [wd52a] - bit 3, a + ld a, [wPlayerDirection] + bit PLAYER_DIR_BIT_UP, a jr z, .notFacingDown - ld c, $0 ; make sprite face down + ld c, SPRITE_FACING_DOWN jr .facingDirectionDetermined .notFacingDown - bit 2, a + bit PLAYER_DIR_BIT_DOWN, a jr z, .notFacingUp - ld c, $4 ; make sprite face up + ld c, SPRITE_FACING_UP jr .facingDirectionDetermined .notFacingUp - bit 1, a + bit PLAYER_DIR_BIT_LEFT, a jr z, .notFacingRight - ld c, $c ; make sprite face right + ld c, SPRITE_FACING_RIGHT jr .facingDirectionDetermined .notFacingRight - ld c, $8 ; make sprite face left + ld c, SPRITE_FACING_LEFT .facingDirectionDetermined ld a, [H_CURRENTSPRITEOFFSET] add $9 @@ -440,7 +448,7 @@ InitializeSpriteScreenPosition: ; 50bd (1:50bd) ld a, [H_CURRENTSPRITEOFFSET] add $4 ld l, a - ld a, [W_YCOORD] ; wd361 + ld a, [W_YCOORD] ld b, a ld a, [hl] ; c2x4 (Y position + 4) sub b ; relative to player position @@ -449,7 +457,7 @@ InitializeSpriteScreenPosition: ; 50bd (1:50bd) dec h ld [hli], a ; c1x4 (screen Y position) inc h - ld a, [W_XCOORD] ; wd362 + ld a, [W_XCOORD] ld b, a ld a, [hli] ; c2x6 (X position + 4) sub b ; relative to player position @@ -470,12 +478,12 @@ CheckSpriteAvailability: ; 50dc (1:50dc) ld l, a ld a, [hl] ; c2x6: movement byte 1 cp $fe - jr c, .skipXVisibilityTest ; movement byte 1 < $fe + jr c, .skipXVisibilityTest ; movement byte 1 < $fe (i.e. the sprite's movement is scripted) ld a, [H_CURRENTSPRITEOFFSET] add $4 ld l, a ld b, [hl] ; c2x4: Y pos (+4) - ld a, [W_YCOORD] ; wd361 + ld a, [W_YCOORD] cp b jr z, .skipYVisibilityTest jr nc, .spriteInvisible ; above screen region @@ -485,7 +493,7 @@ CheckSpriteAvailability: ; 50dc (1:50dc) .skipYVisibilityTest inc l ld b, [hl] ; c2x5: X pos (+4) - ld a, [W_XCOORD] ; wd362 + ld a, [W_XCOORD] cp b jr z, .skipXVisibilityTest jr nc, .spriteInvisible ; left of screen region @@ -495,7 +503,7 @@ CheckSpriteAvailability: ; 50dc (1:50dc) .skipXVisibilityTest ; make the sprite invisible if a text box is in front of it ; $5F is the maximum number for map tiles - call getTileSpriteStandsOn + call GetTileSpriteStandsOn ld d, $60 ld a, [hli] cp d @@ -503,7 +511,7 @@ CheckSpriteAvailability: ; 50dc (1:50dc) ld a, [hld] cp d jr nc, .spriteInvisible ; standing on tile with ID >=$60 (bottom right tile) - ld bc, -20 ; $ffec + ld bc, -20 add hl, bc ; go back one row of tiles ld a, [hli] cp d @@ -521,7 +529,7 @@ CheckSpriteAvailability: ; 50dc (1:50dc) jr .done .spriteVisible ld c, a - ld a, [wWalkCounter] ; wcfc5 + ld a, [wWalkCounter] and a jr nz, .done ; if player is currently walking, we're done call UpdateSpriteImage @@ -572,10 +580,11 @@ CanWalkOntoTile: ; 516e (1:516e) ld l, a ld a, [hl] ; c2x6 (movement byte 1) cp $fe - jr nc, .canMove ; values $fe and $ff + jr nc, .notScripted ; values $fe and $ff +; always allow walking if the movement is scripted and a ret -.canMove +.notScripted ld a, [W_TILESETCOLLISIONPTR] ld l, a ld a, [W_TILESETCOLLISIONPTR+1] @@ -675,7 +684,7 @@ CanWalkOntoTile: ; 516e (1:516e) ; calculates the tile pointer pointing to the tile the current sprite stancs on ; this is always the lower left tile of the 2x2 tile blocks all sprites are snapped to ; hl: output pointer -getTileSpriteStandsOn: ; 5207 (1:5207) +GetTileSpriteStandsOn: ; 5207 (1:5207) ld h, $c1 ld a, [H_CURRENTSPRITEOFFSET] add $4 @@ -690,11 +699,11 @@ getTileSpriteStandsOn: ; 5207 (1:5207) ld a, [hl] ; c1x6: screen Y position srl a srl a - srl a ; screen X tile - add $14 ; screen X tile + 20 + srl a ; screen X tile + add SCREEN_WIDTH ; screen X tile + 20 ld d, $0 ld e, a - ld hl, wTileMap + coord hl, 0, 0 add hl, bc add hl, bc add hl, bc @@ -713,53 +722,58 @@ LoadDEPlusA: ; 522f (1:522f) ld a, [de] ret -Func_5236: ; 5236 (1:5236) +DoScriptedNPCMovement: ; 5236 (1:5236) +; This is an alternative method of scripting an NPC's movement and is only used +; a few times in the game. It is used when the NPC and player must walk together +; in sync, such as when the player is following the NPC somewhere. An NPC can't +; be moved in sync with the player using the other method. ld a, [wd730] bit 7, a ret z ld hl, wd72e bit 7, [hl] set 7, [hl] - jp z, Func_52a6 + jp z, InitScriptedNPCMovement ld hl, wNPCMovementDirections2 ld a, [wNPCMovementDirections2Index] add l ld l, a - jr nc, .asm_5251 + jr nc, .noCarry inc h -.asm_5251 +.noCarry ld a, [hl] - cp $40 - jr nz, .asm_525f - call Func_52b2 - ld c, $4 - ld a, $fe - jr .asm_5289 -.asm_525f - cp $0 - jr nz, .asm_526c - call Func_52b2 - ld c, $0 - ld a, $2 - jr .asm_5289 -.asm_526c - cp $80 - jr nz, .asm_5279 - call Func_52b7 - ld c, $8 - ld a, $fe - jr .asm_5289 -.asm_5279 - cp $c0 - jr nz, .asm_5286 - call Func_52b7 - ld c, $c - ld a, $2 - jr .asm_5289 -.asm_5286 +; check if moving up + cp NPC_MOVEMENT_UP + jr nz, .checkIfMovingDown + call GetSpriteScreenYPointer + ld c, SPRITE_FACING_UP + ld a, -2 + jr .move +.checkIfMovingDown + cp NPC_MOVEMENT_DOWN + jr nz, .checkIfMovingLeft + call GetSpriteScreenYPointer + ld c, SPRITE_FACING_DOWN + ld a, 2 + jr .move +.checkIfMovingLeft + cp NPC_MOVEMENT_LEFT + jr nz, .checkIfMovingRight + call GetSpriteScreenXPointer + ld c, SPRITE_FACING_LEFT + ld a, -2 + jr .move +.checkIfMovingRight + cp NPC_MOVEMENT_RIGHT + jr nz, .noMatch + call GetSpriteScreenXPointer + ld c, SPRITE_FACING_RIGHT + ld a, 2 + jr .move +.noMatch cp $ff ret -.asm_5289 +.move ld b, a ld a, [hl] add b @@ -768,33 +782,34 @@ Func_5236: ; 5236 (1:5236) add $9 ld l, a ld a, c - ld [hl], a - call Func_52c3 - ld hl, wcf18 + ld [hl], a ; facing direction + call AnimScriptedNPCMovement + ld hl, wScriptedNPCWalkCounter dec [hl] ret nz - ld a, $8 - ld [wcf18], a + ld a, 8 + ld [wScriptedNPCWalkCounter], a ld hl, wNPCMovementDirections2Index inc [hl] ret -Func_52a6: ; 52a6 (1:52a6) +InitScriptedNPCMovement: ; 52a6 (1:52a6) xor a ld [wNPCMovementDirections2Index], a - ld a, $8 - ld [wcf18], a - jp Func_52c3 + ld a, 8 + ld [wScriptedNPCWalkCounter], a + jp AnimScriptedNPCMovement -Func_52b2: ; 52b2 (1:52b2) +GetSpriteScreenYPointer: ; 52b2 (1:52b2) ld a, $4 ld b, a - jr asm_52ba + jr GetSpriteScreenXYPointerCommon -Func_52b7: ; 52b7 (1:52b7) +GetSpriteScreenXPointer: ; 52b7 (1:52b7) ld a, $6 ld b, a -asm_52ba: ; 52ba (1:52ba) + +GetSpriteScreenXYPointerCommon: ; 52ba (1:52ba) ld hl, wSpriteStateData1 ld a, [H_CURRENTSPRITEOFFSET] add l @@ -802,12 +817,12 @@ asm_52ba: ; 52ba (1:52ba) ld l, a ret -Func_52c3: ; 52c3 (1:52c3) +AnimScriptedNPCMovement: ; 52c3 (1:52c3) ld hl, wSpriteStateData2 ld a, [H_CURRENTSPRITEOFFSET] add $e ld l, a - ld a, [hl] + ld a, [hl] ; VRAM slot dec a swap a ld b, a @@ -815,47 +830,47 @@ Func_52c3: ; 52c3 (1:52c3) ld a, [H_CURRENTSPRITEOFFSET] add $9 ld l, a - ld a, [hl] - cp $0 - jr z, .asm_52ea - cp $4 - jr z, .asm_52ea - cp $8 - jr z, .asm_52ea - cp $c - jr z, .asm_52ea + ld a, [hl] ; facing direction + cp SPRITE_FACING_DOWN + jr z, .anim + cp SPRITE_FACING_UP + jr z, .anim + cp SPRITE_FACING_LEFT + jr z, .anim + cp SPRITE_FACING_RIGHT + jr z, .anim ret -.asm_52ea +.anim add b ld b, a - ld [$ffe9], a - call Func_5301 + ld [hSpriteVRAMSlotAndFacing], a + call AdvanceScriptedNPCAnimFrameCounter ld hl, wSpriteStateData1 ld a, [H_CURRENTSPRITEOFFSET] add $2 ld l, a - ld a, [$ffe9] + ld a, [hSpriteVRAMSlotAndFacing] ld b, a - ld a, [$ffea] + ld a, [hSpriteAnimFrameCounter] add b ld [hl], a ret -Func_5301: ; 5301 (1:5301) +AdvanceScriptedNPCAnimFrameCounter: ; 5301 (1:5301) ld a, [H_CURRENTSPRITEOFFSET] add $7 ld l, a - ld a, [hl] + ld a, [hl] ; intra-animation frame counter inc a ld [hl], a - cp $4 + cp 4 ret nz xor a - ld [hl], a + ld [hl], a ; reset intra-animation frame counter inc l - ld a, [hl] + ld a, [hl] ; animation frame counter inc a and $3 ld [hl], a - ld [$ffea], a + ld [hSpriteAnimFrameCounter], a ret diff --git a/engine/overworld/npc_movement.asm b/engine/overworld/npc_movement.asm index 84e39853..098be875 100755 --- a/engine/overworld/npc_movement.asm +++ b/engine/overworld/npc_movement.asm @@ -44,60 +44,66 @@ _EndNPCMovementScript: ; 1a41d (6:641d) ld [wSimulatedJoypadStatesEnd], a ret -ProfOakMovementScriptPointerTable: ; 1a442 (6:6442) - dw Func_1a44c - dw Func_1a485 - dw Func_1a4a1 - dw Func_1a4a6 - dw Func_1a4f4 +PalletMovementScriptPointerTable: ; 1a442 (6:6442) + dw PalletMovementScript_OakMoveLeft + dw PalletMovementScript_PlayerMoveLeft + dw PalletMovementScript_WaitAndWalkToLab + dw PalletMovementScript_WalkToLab + dw PalletMovementScript_Done -Func_1a44c: ; 1a44c (6:644c) - ld a, [W_XCOORD] ; wd362 +PalletMovementScript_OakMoveLeft: ; 1a44c (6:644c) + ld a, [W_XCOORD] sub $a - ld [wcca1], a - jr z, .asm_1a475 - ld b, $0 + ld [wNumStepsToTake], a + jr z, .playerOnLeftTile +; The player is on the right tile of the northern path out of Pallet Town and +; Prof. Oak is below. +; Make Prof. Oak step to the left. + ld b, 0 ld c, a ld hl, wNPCMovementDirections2 - ld a, $80 + ld a, NPC_MOVEMENT_LEFT call FillMemory ld [hl], $ff ld a, [wSpriteIndex] - ld [H_DOWNARROWBLINKCNT2], a ; $ff8c + ld [H_SPRITEINDEX], a ld de, wNPCMovementDirections2 call MoveSprite ld a, $1 ld [wNPCMovementScriptFunctionNum], a - jr .asm_1a47a -.asm_1a475 + jr .done +; The player is on the left tile of the northern path out of Pallet Town and +; Prof. Oak is below. +; Prof. Oak is already where he needs to be. +.playerOnLeftTile ld a, $3 ld [wNPCMovementScriptFunctionNum], a -.asm_1a47a +.done ld hl, W_FLAGS_D733 set 1, [hl] ld a, $fc ld [wJoyIgnore], a ret -Func_1a485: ; 1a485 (6:6485) +PalletMovementScript_PlayerMoveLeft: ; 1a485 (6:6485) ld a, [wd730] - bit 0, a - ret nz - ld a, [wcca1] + bit 0, a ; is an NPC being moved by a script? + ret nz ; return if Oak is still moving + ld a, [wNumStepsToTake] ld [wSimulatedJoypadStatesIndex], a - ld [$ff95], a + ld [hNPCMovementDirections2Index], a predef ConvertNPCMovementDirectionsToJoypadMasks call StartSimulatingJoypadStates ld a, $2 ld [wNPCMovementScriptFunctionNum], a ret -Func_1a4a1: ; 1a4a1 (6:64a1) +PalletMovementScript_WaitAndWalkToLab: ; 1a4a1 (6:64a1) ld a, [wSimulatedJoypadStatesIndex] - and a + and a ; is the player done moving left yet? ret nz -Func_1a4a6: ; 1a4a6 (6:64a6) +PalletMovementScript_WalkToLab: ; 1a4a6 (6:64a6) xor a ld [wOverrideSimulatedJoypadStatesMask], a ld a, [wSpriteIndex] @@ -122,12 +128,12 @@ Func_1a4a6: ; 1a4a6 (6:64a6) ret RLEList_ProfOakWalkToLab: ; 1a4dc (6:64dc) - db $00, $05 - db $80, $01 - db $00, $05 - db $C0, $03 - db $40, $01 - db $E0, $01 + db NPC_MOVEMENT_DOWN, $05 + db NPC_MOVEMENT_LEFT, $01 + db NPC_MOVEMENT_DOWN, $05 + db NPC_MOVEMENT_RIGHT, $03 + db NPC_MOVEMENT_UP, $01 + db $E0, $01 ; stand still db $FF RLEList_PlayerWalkToLab: ; 1a4e9 (6:64e9) @@ -138,12 +144,12 @@ RLEList_PlayerWalkToLab: ; 1a4e9 (6:64e9) db D_DOWN, $06 db $FF -Func_1a4f4: ; 1a4f4 (6:64f4) +PalletMovementScript_Done: ; 1a4f4 (6:64f4) ld a, [wSimulatedJoypadStatesIndex] and a ret nz ld a, $0 - ld [wcc4d], a + ld [wMissableObjectIndex], a predef HideObject ld hl, wd730 res 7, [hl] @@ -152,15 +158,15 @@ Func_1a4f4: ; 1a4f4 (6:64f4) jp EndNPCMovementScript PewterMuseumGuyMovementScriptPointerTable: ; 1a510 (6:6510) - dw Func_1a514 - dw PewterMovementScriptDone + dw PewterMovementScript_WalkToMuseum + dw PewterMovementScript_Done -Func_1a514: ; 1a514 (6:6514) +PewterMovementScript_WalkToMuseum: ; 1a514 (6:6514) ld a, BANK(Music_MuseumGuy) - ld [wc0ef], a - ld [wc0f0], a + ld [wAudioROMBank], a + ld [wAudioSavedROMBank], a ld a, MUSIC_MUSEUM_GUY - ld [wc0ee], a + ld [wNewSoundID], a call PlaySound ld a, [wSpriteIndex] swap a @@ -172,7 +178,7 @@ Func_1a514: ; 1a514 (6:6514) dec a ld [wSimulatedJoypadStatesIndex], a xor a - ld [wd12f], a + ld [wWhichPewterGuy], a predef PewterGuys ld hl, wNPCMovementDirections2 ld de, RLEList_PewterMuseumGuy @@ -191,13 +197,13 @@ RLEList_PewterMuseumPlayer: ; 1a559 (6:6559) db $FF RLEList_PewterMuseumGuy: ; 1a562 (6:6562) - db $40, $06 - db $80, $0D - db $40, $03 - db $80, $01 + db NPC_MOVEMENT_UP, $06 + db NPC_MOVEMENT_LEFT, $0D + db NPC_MOVEMENT_UP, $03 + db NPC_MOVEMENT_LEFT, $01 db $FF -PewterMovementScriptDone: ; 1a56b (6:656b) +PewterMovementScript_Done: ; 1a56b (6:656b) ld a, [wSimulatedJoypadStatesIndex] and a ret nz @@ -208,15 +214,15 @@ PewterMovementScriptDone: ; 1a56b (6:656b) jp EndNPCMovementScript PewterGymGuyMovementScriptPointerTable: ; 1a57d (6:657d) - dw Func_1a581 - dw PewterMovementScriptDone + dw PewterMovementScript_WalkToGym + dw PewterMovementScript_Done -Func_1a581: ; 1a581 (6:6581) +PewterMovementScript_WalkToGym: ; 1a581 (6:6581) ld a, BANK(Music_MuseumGuy) - ld [wc0ef], a - ld [wc0f0], a + ld [wAudioROMBank], a + ld [wAudioSavedROMBank], a ld a, MUSIC_MUSEUM_GUY - ld [wc0ee], a + ld [wNewSoundID], a call PlaySound ld a, [wSpriteIndex] swap a @@ -228,8 +234,8 @@ Func_1a581: ; 1a581 (6:6581) call DecodeRLEList dec a ld [wSimulatedJoypadStatesIndex], a - ld a, $1 - ld [wd12f], a + ld a, 1 + ld [wWhichPewterGuy], a predef PewterGuys ld hl, wNPCMovementDirections2 ld de, RLEList_PewterGymGuy @@ -252,12 +258,12 @@ RLEList_PewterGymPlayer: ; 1a5cd (6:65cd) db $FF RLEList_PewterGymGuy: ; 1a5da (6:65da) - db $00, $02 - db $80, $0F - db $40, $05 - db $80, $0B - db $00, $05 - db $C0, $03 + db NPC_MOVEMENT_DOWN, $02 + db NPC_MOVEMENT_LEFT, $0F + db NPC_MOVEMENT_UP, $05 + db NPC_MOVEMENT_LEFT, $0B + db NPC_MOVEMENT_DOWN, $05 + db NPC_MOVEMENT_RIGHT, $03 db $FF FreezeEnemyTrainerSprite: ; 1a5e7 (6:65e7) @@ -280,7 +286,7 @@ FreezeEnemyTrainerSprite: ; 1a5e7 (6:65e7) jp SetSpriteMovementBytesToFF RivalIDs: ; 1a605 (6:6605) - db SONY1 + $c8 - db SONY2 + $c8 - db SONY3 + $c8 + db OPP_SONY1 + db OPP_SONY2 + db OPP_SONY3 db $ff diff --git a/engine/overworld/oaks_aide.asm b/engine/overworld/oaks_aide.asm index 68135287..8ac456d2 100755 --- a/engine/overworld/oaks_aide.asm +++ b/engine/overworld/oaks_aide.asm @@ -1,48 +1,48 @@ -OaksAideScript ; 0x59035 +OaksAideScript: ; 0x59035 ld hl, OaksAideHiText call PrintText call YesNoChoice ld a, [wCurrentMenuItem] and a - jr nz, .asm_59086 ; 0x59042 $42 + jr nz, .choseNo ld hl, wPokedexOwned ld b, wPokedexOwnedEnd - wPokedexOwned call CountSetBits - ld a, [wd11e] - ld [$ffdd], a + ld a, [wNumSetBits] + ld [hOaksAideNumMonsOwned], a ld b, a - ld a, [$ffdb] + ld a, [hOaksAideRequirement] cp b - jr z, .asm_59059 ; 0x59055 $2 - jr nc, .asm_5907c ; 0x59057 $23 -.asm_59059 + jr z, .giveItem + jr nc, .notEnoughOwnedMons +.giveItem ld hl, OaksAideHereYouGoText call PrintText - ld a, [$ffdc] + ld a, [hOaksAideRewardItem] ld b, a ld c, 1 call GiveItem - jr nc, .BagFull + jr nc, .bagFull ld hl, OaksAideGotItemText call PrintText ld a, $1 - jr .asm_5908e ; 0x59071 $1b -.BagFull + jr .done +.bagFull ld hl, OaksAideNoRoomText call PrintText xor a - jr .asm_5908e ; 0x5907a $12 -.asm_5907c + jr .done +.notEnoughOwnedMons ld hl, OaksAideUhOhText call PrintText ld a, $80 - jr .asm_5908e ; 0x59084 $8 -.asm_59086 + jr .done +.choseNo ld hl, OaksAideComeBackText call PrintText ld a, $ff -.asm_5908e - ld [$ffdb], a +.done + ld [hOaksAideResult], a ret OaksAideHiText: ; 59091 (16:5091) diff --git a/engine/overworld/oam.asm b/engine/overworld/oam.asm index 71eb297c..ff85eb3e 100644 --- a/engine/overworld/oam.asm +++ b/engine/overworld/oam.asm @@ -4,25 +4,26 @@ PrepareOAMData: ld a, [wUpdateSpritesEnabled] dec a - jr z, .asm_4b1e + jr z, .updateEnabled cp 0 - 1 ret nz ld [wUpdateSpritesEnabled], a jp HideSprites -.asm_4b1e +.updateEnabled xor a - ld [$ff90], a -.asm_4b21 - ld [$ff8f], a + ld [hOAMBufferOffset], a + +.spriteLoop + ld [hSpriteOffset2], a ld d, wSpriteStateData1 / $100 - ld a, [$ff8f] + ld a, [hSpriteOffset2] ld e, a ld a, [de] ; c1x0 and a - jp z, .asm_4bad + jp z, .nextSprite inc e inc e @@ -31,21 +32,25 @@ PrepareOAMData: cp $ff ; off-screen (don't draw) jr nz, .visible - call Func_4bd1 - jr .asm_4bad + call GetSpriteScreenXY + jr .nextSprite .visible - cp $a0 + cp $a0 ; is the sprite unchanging like an item ball or boulder? jr c, .usefacing + +; unchanging and $f - add $10 - jr .asm_4b48 + add $10 ; skip to the second half of the table which doesn't account for facing direction + jr .next .usefacing and $f -.asm_4b48 + +.next ld l, a +; get sprite priority push de inc d ld a, e @@ -53,15 +58,15 @@ PrepareOAMData: ld e, a ld a, [de] ; c2x7 and $80 - ld [$ff94], a ; temp store sprite priority + ld [hSpritePriority], a ; temp store sprite priority pop de +; read the entry from the table ld h, 0 ld bc, SpriteFacingAndAnimationTable add hl, hl add hl, hl add hl, bc - ld a, [hli] ld c, a ld a, [hli] @@ -70,24 +75,25 @@ PrepareOAMData: ld h, [hl] ld l, a - call Func_4bd1 + call GetSpriteScreenXY - ld a, [$ff90] + ld a, [hOAMBufferOffset] ld e, a ld d, wOAMBuffer / $100 -.tile - ld a, [$ff92] ; temp for sprite Y position + +.tileLoop + ld a, [hSpriteScreenY] ; temp for sprite Y position add $10 ; Y=16 is top of screen (Y=0 is invisible) add [hl] ; add Y offset from table ld [de], a ; write new sprite OAM Y position inc hl - ld a, [$ff91] ; temp for sprite X position + ld a, [hSpriteScreenX] ; temp for sprite X position add $8 ; X=8 is left of screen (X=0 is invisible) add [hl] ; add X offset from table inc e ld [de], a ; write new sprite OAM X position inc e - ld a, [bc] ; read pattern number offset (accomodates orientation (offset 0,4 or 8) and animation (offset 0 or $80)) + ld a, [bc] ; read pattern number offset (accommodates orientation (offset 0,4 or 8) and animation (offset 0 or $80)) inc bc push bc ld b, a @@ -99,55 +105,60 @@ PrepareOAMData: ; Sprites $a and $b have one face (and therefore 4 tiles instead of 12). ; As a result, sprite $b's tile offset is less than normal. cp $b - jr nz, .offset + jr nz, .notFourTileSprite ld a, $a * 12 + 4 - jr .gotoffset + jr .next2 -.offset +.notFourTileSprite ; a *= 12 sla a sla a ld c, a sla a add c -.gotoffset - add b ; which frame + +.next2 + add b ; add the tile offset from the table (based on frame and facing direction) pop bc ld [de], a ; tile id inc hl inc e ld a, [hl] - bit 1, a ; sprite priority - jr z, .fg - ld a, [$ff94] ; facing priority + bit 1, a ; is the tile allowed to set the sprite priority bit? + jr z, .skipPriority + ld a, [hSpritePriority] or [hl] -.fg +.skipPriority inc hl ld [de], a inc e bit 0, a ; OAMFLAG_ENDOFDATA - jr z, .tile + jr z, .tileLoop ld a, e - ld [$ff90], a + ld [hOAMBufferOffset], a -.asm_4bad - ld a, [$ff8f] +.nextSprite + ld a, [hSpriteOffset2] add $10 cp $100 % $100 - jp nz, .asm_4b21 + jp nz, .spriteLoop ; Clear unused OAM. - ld a, [$ff90] + ld a, [hOAMBufferOffset] ld l, a ld h, wOAMBuffer / $100 ld de, $4 ld b, $a0 ld a, [wd736] - bit 6, a + bit 6, a ; jumping down ledge or fishing animation? ld a, $a0 jr z, .clear + +; Don't clear the last 4 entries because they are used for the shadow in the +; jumping down ledge animation and the rod in the fishing animation. ld a, $90 + .clear cp l ret z @@ -155,24 +166,24 @@ PrepareOAMData: add hl, de jr .clear -Func_4bd1: ; 4bd1 (1:4bd1) +GetSpriteScreenXY: ; 4bd1 (1:4bd1) inc e inc e ld a, [de] ; c1x4 - ld [$ff92], a + ld [hSpriteScreenY], a inc e inc e ld a, [de] ; c1x6 - ld [$ff91], a - ld a, $4 + ld [hSpriteScreenX], a + ld a, 4 add e ld e, a - ld a, [$ff92] - add $4 + ld a, [hSpriteScreenY] + add 4 and $f0 ld [de], a ; c1xa (y) inc e - ld a, [$ff91] + ld a, [hSpriteScreenX] and $f0 ld [de], a ; c1xb (x) ret diff --git a/engine/overworld/pewter_guys.asm b/engine/overworld/pewter_guys.asm index eb6dd5ac..4ac60e00 100755 --- a/engine/overworld/pewter_guys.asm +++ b/engine/overworld/pewter_guys.asm @@ -9,7 +9,7 @@ PewterGuys: ; 37ca1 (d:7ca1) ld d, h ld e, l ld hl, PointerTable_37ce6 - ld a, [wd12f] + ld a, [wWhichPewterGuy] add a ld b, 0 ld c, a @@ -21,17 +21,17 @@ PewterGuys: ; 37ca1 (d:7ca1) ld b, a ld a, [W_XCOORD] ld c, a -.asm_37cc7 +.findMatchingCoordsLoop ld a, [hli] cp b - jr nz, .asm_37ce1 + jr nz, .nextEntry1 ld a, [hli] cp c - jr nz, .asm_37ce2 + jr nz, .nextEntry2 ld a, [hli] ld h, [hl] ld l, a -.asm_37cd2 +.copyMovementDataLoop ld a, [hli] cp $ff ret z @@ -40,13 +40,13 @@ PewterGuys: ; 37ca1 (d:7ca1) ld a, [wSimulatedJoypadStatesIndex] inc a ld [wSimulatedJoypadStatesIndex], a - jr .asm_37cd2 -.asm_37ce1 + jr .copyMovementDataLoop +.nextEntry1 inc hl -.asm_37ce2 +.nextEntry2 inc hl inc hl - jr .asm_37cc7 + jr .findMatchingCoordsLoop PointerTable_37ce6: ; 37ce6 (d:7ce6) dw PewterMuseumGuyCoords @@ -66,17 +66,18 @@ PewterMuseumGuyCoords: ; 37cea (d:7cea) dw .right .down - db $40, $40, $ff + db D_UP, D_UP, $ff .up - db $10, $20, $ff + db D_RIGHT, D_LEFT, $ff .left - db $40, $10, $ff + db D_UP, D_RIGHT, $ff .right - db $40, $20, $ff + db D_UP, D_LEFT, $ff ; these are the five coordinates which trigger the gym guy and pointers to ; different movements for the player to make to get positioned before the ; main movement +; $00 is a pause PewterGymGuyCoords: ; 37d06 (d:7d06) db 16, 34 dw .one @@ -90,12 +91,12 @@ PewterGymGuyCoords: ; 37d06 (d:7d06) dw .five .one - db $20, $80, $80, $10, $ff + db D_LEFT, D_DOWN, D_DOWN, D_RIGHT, $ff .two - db $20, $80, $10, $20, $ff + db D_LEFT, D_DOWN, D_RIGHT, D_LEFT, $ff .three - db $20, $20, $20, $00, $00, $00, $00, $00, $00, $00, $00, $ff + db D_LEFT, D_LEFT, D_LEFT, $00, $00, $00, $00, $00, $00, $00, $00, $ff .four - db $20, $20, $40, $20, $ff + db D_LEFT, D_LEFT, D_UP, D_LEFT, $ff .five - db $20, $80, $20, $00, $00, $00, $00, $00, $00, $00, $00, $ff + db D_LEFT, D_DOWN, D_LEFT, $00, $00, $00, $00, $00, $00, $00, $00, $ff diff --git a/engine/overworld/player_animations.asm b/engine/overworld/player_animations.asm index fc0a3a6c..6488eaac 100755 --- a/engine/overworld/player_animations.asm +++ b/engine/overworld/player_animations.asm @@ -1,5 +1,5 @@ EnterMapAnim: ; 70567 (1c:4567) - call InitFacingDirectionBuffer + call InitFacingDirectionList ld a, $ec ld [wSpriteStateData1 + 4], a ; player's sprite Y screen position call Delay3 @@ -32,7 +32,7 @@ EnterMapAnim: ; 70567 (1c:4567) ld a, $8 ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayEndValue ld [hl], $ff ; wPlayerSpinInPlaceAnimSoundID - ld hl, wcd48 + ld hl, wFacingDirectionList call PlayerSpinInPlace ld a, $1 ld [wd431], a @@ -50,12 +50,8 @@ EnterMapAnim: ; 70567 (1c:4567) jr .done .flyAnimation pop hl - ;ld de, BirdSprite - ;ld hl, vNPCSprites - ;ld bc, (BANK(BirdSprite) << 8) + $0c - ;call CopyVideoData call LoadBirdSpriteGraphics - ld a, $a4 ; (SFX_02_50 - SFX_Headers_02) / 3 + ld a, $a4 ; SFX_BIRD_FLY call PlaySound ld hl, wFlyAnimUsingCoordList xor a ; is using coord list @@ -63,7 +59,7 @@ EnterMapAnim: ; 70567 (1c:4567) ld a, 12 ld [hli], a ; wFlyAnimCounter ld [hl], $8 ; wFlyAnimBirdSpriteImageIndex (facing right) - ld de, FlyAnimationEnterScreenCoords ; $4592 + ld de, FlyAnimationEnterScreenCoords call DoFlyAnimation call LoadPlayerSpriteGraphics ld a, $1 @@ -97,9 +93,10 @@ PlayerSpinWhileMovingDown: ; 70605 (1c:4605) ld [hl], a ; wPlayerSpinWhileMovingUpOrDownAnimFrameDelay jp PlayerSpinWhileMovingUpOrDown + _LeaveMapAnim: ; 70615 (1c:4615) call Func_1510 - call InitFacingDirectionBuffer + call InitFacingDirectionList call IsPlayerStandingOnWarpPadOrHole ld a, b and a @@ -141,8 +138,8 @@ _LeaveMapAnim: ; 70615 (1c:4615) ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayDelta xor a ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayEndValue - ld [hl], $a1 ; (SFX_02_4d - SFX_Headers_02) / 3 ; wPlayerSpinInPlaceAnimSoundID - ld hl, wcd48 + ld [hl], $a1 ; SFX_TELEPORT_EXIT_2 + ld hl, wFacingDirectionList call PlayerSpinInPlace jr .spinWhileMovingUp .flyAnimation @@ -154,7 +151,7 @@ _LeaveMapAnim: ; 70615 (1c:4615) ld [hli], a ; wFlyAnimCounter ld [hl], $c ; wFlyAnimBirdSpriteImageIndex call DoFlyAnimation - ld a, $a4 ; (SFX_02_50 - SFX_Headers_02) / 3 + ld a, $a4 ; SFX_FLY call PlaySound ld hl, wFlyAnimUsingCoordList xor a ; is using coord list @@ -162,7 +159,7 @@ _LeaveMapAnim: ; 70615 (1c:4615) ld a, $c ld [hli], a ; wFlyAnimCounter ld [hl], $c ; wFlyAnimBirdSpriteImageIndex (facing right) - ld de, FlyAnimationScreenCoords1 ; $464f + ld de, FlyAnimationScreenCoords1 call DoFlyAnimation ld c, 40 call DelayFrames @@ -170,7 +167,7 @@ _LeaveMapAnim: ; 70615 (1c:4615) ld a, 11 ld [hli], a ; wFlyAnimCounter ld [hl], $8 ; wFlyAnimBirdSpriteImageIndex (facing left) - ld de, FlyAnimationScreenCoords2 ; $4667 + ld de, FlyAnimationScreenCoords2 call DoFlyAnimation call GBFadeOutToWhite jp RestoreFacingDirectionAndYScreenPos @@ -222,7 +219,7 @@ LeaveMapThroughHoleAnim: ; 706db (1c:46db) ld [wOAMBuffer + 1 * 4], a ld c, 2 call DelayFrames - ; hide lower half of player's sprite + ; hide upper half of player's sprite ld a, $a0 ld [wOAMBuffer + 2 * 4], a ld [wOAMBuffer + 3 * 4], a @@ -239,7 +236,7 @@ DoFlyAnimation: ; 7070c (1c:470c) call Delay3 ld a, [wFlyAnimUsingCoordList] cp $ff - jr z, .asm_7072b + jr z, .skipCopyingCoords ; if the bird is flapping its wings in place ld hl, wSpriteStateData1 + 4 ld a, [de] inc de @@ -248,7 +245,7 @@ DoFlyAnimation: ; 7070c (1c:470c) ld a, [de] inc de ld [hl], a -.asm_7072b +.skipCopyingCoords ld a, [wFlyAnimCounter] dec a ld [wFlyAnimCounter], a @@ -258,7 +255,7 @@ DoFlyAnimation: ; 7070c (1c:470c) LoadBirdSpriteGraphics: ; 70735 (1c:4735) ld de, BirdSprite ; $4d80 ld b, BANK(BirdSprite) - ld c,$c + ld c, $c ld hl, vNPCSprites call CopyVideoData ld de, BirdSprite + $c0 ; $4e40 ; moving amination sprite @@ -267,17 +264,18 @@ LoadBirdSpriteGraphics: ; 70735 (1c:4735) ld hl, vNPCSprites2 jp CopyVideoData -InitFacingDirectionBuffer: ; 7074f (1c:474f) +InitFacingDirectionList: ; 7074f (1c:474f) ld a, [wSpriteStateData1 + 2] ; player's sprite facing direction (image index is locked to standing images) - ld [wcd50], a + ld [wSavedPlayerFacingDirection], a ld a, [wSpriteStateData1 + 4] ; player's sprite Y screen position - ld [wcd4f], a + ld [wSavedPlayerScreenY], a ld hl, PlayerSpinningFacingOrder - ld de, wcd48 - ld bc, $4 + ld de, wFacingDirectionList + ld bc, 4 call CopyData ld a, [wSpriteStateData1 + 2] ; player's sprite facing direction (image index is locked to standing images) - ld hl, wcd48 + ld hl, wFacingDirectionList +; find the place in the list that matches the current facing direction .loop cp [hl] inc hl @@ -291,15 +289,16 @@ PlayerSpinningFacingOrder: ; 70773 (1c:4773) db SPRITE_FACING_DOWN, SPRITE_FACING_LEFT, SPRITE_FACING_UP, SPRITE_FACING_RIGHT SpinPlayerSprite: ; 70777 (1c:4777) +; copy the current value from the list into the sprite data and rotate the list ld a, [hl] ld [wSpriteStateData1 + 2], a ; player's sprite facing direction (image index is locked to standing images) push hl - ld hl, wcd48 - ld de, wcd47 - ld bc, $4 + ld hl, wFacingDirectionList + ld de, wFacingDirectionList - 1 + ld bc, 4 call CopyData - ld a, [wcd47] - ld [wcd4b], a + ld a, [wFacingDirectionList - 1] + ld [wFacingDirectionList + 3], a pop hl ret @@ -308,11 +307,12 @@ PlayerSpinInPlace: ; 70790 (1c:4790) ld a, [wPlayerSpinInPlaceAnimFrameDelay] ld c, a and $3 - jr nz, .asm_707a3 + jr nz, .skipPlayingSound +; when the last delay was a multiple of 4, play a sound if there is one ld a, [wPlayerSpinInPlaceAnimSoundID] cp $ff call nz, PlaySound -.asm_707a3 +.skipPlayingSound ld a, [wPlayerSpinInPlaceAnimFrameDelayDelta] add c ld [wPlayerSpinInPlaceAnimFrameDelay], a @@ -340,9 +340,9 @@ PlayerSpinWhileMovingUpOrDown: ; 707b5 (1c:47b5) jr PlayerSpinWhileMovingUpOrDown RestoreFacingDirectionAndYScreenPos: ; 707d2 (1c:47d2) - ld a, [wcd4f] + ld a, [wSavedPlayerScreenY] ld [wSpriteStateData1 + 4], a - ld a, [wcd50] + ld a, [wSavedPlayerFacingDirection] ld [wSpriteStateData1 + 2], a ret @@ -377,10 +377,10 @@ IsPlayerStandingOnWarpPadOrHole: ; 707e7 (1c:47e7) ld b, [hl] .done ld a, b - ld [wcd5b], a + ld [wStandingOnWarpPadOrHole], a ret -; format: db tileset id, tile id, value to be put in wcd5b +; format: db tileset id, tile id, value to be put in [wStandingOnWarpPadOrHole] .warpPadAndHoleData: ; 70809 (1c:4809) db FACILITY, $20, 1 ; warp pad db FACILITY, $11, 2 ; hole @@ -388,8 +388,8 @@ IsPlayerStandingOnWarpPadOrHole: ; 707e7 (1c:47e7) db INTERIOR, $55, 1 ; warp pad db $FF -Func_70816: ; 70816 (1c:4816) - ld c, $a +FishingAnim: ; 70816 (1c:4816) + ld c, 10 call DelayFrames ld hl, wd736 set 6, [hl] @@ -399,60 +399,71 @@ Func_70816: ; 70816 (1c:4816) ld c, $c call CopyVideoData ld a, $4 - ld hl, RedFishingTiles ; $4866 + ld hl, RedFishingTiles call LoadAnimSpriteGfx ld a, [wSpriteStateData1 + 2] ld c, a ld b, $0 - ld hl, FishingRodGfxProperties ; $4856 + ld hl, FishingRodOAM add hl, bc ld de, wOAMBuffer + $9c ld bc, $4 call CopyData ld c, 100 call DelayFrames - ld a, [wWhichTrade] ; wWhichTrade + ld a, [wRodResponse] and a ld hl, NoNibbleText - jr z, .asm_70897 + jr z, .done cp $2 ld hl, NothingHereText - jr z, .asm_70897 - ld b, $a -.asm_7085f - ld hl, wSpriteStateData1 + 4 - call Func_708a3 + jr z, .done + +; there was a bite + +; shake the player's sprite vertically + + ld b, 10 +.loop + ld hl, wSpriteStateData1 + 4 ; player's sprite Y screen position + call .ShakePlayerSprite ld hl, wOAMBuffer + $9c - call Func_708a3 + call .ShakePlayerSprite call Delay3 dec b - jr nz, .asm_7085f + jr nz, .loop + +; If the player is facing up, hide the fishing rod so it doesn't overlap with +; the exclamation bubble that will be shown next. ld a, [wSpriteStateData1 + 2] - cp $4 - jr nz, .asm_7087d + cp SPRITE_FACING_UP + jr nz, .skipHidingFishingRod ld a, $a0 ld [wOAMBuffer + $9c], a -.asm_7087d - ld hl, wcd4f +.skipHidingFishingRod + ld hl, wEmotionBubbleSpriteIndex xor a - ld [hli], a - ld [hl], a + ld [hli], a ; player's sprite + ld [hl], a ; EXCLAMATION_BUBBLE predef EmotionBubble - ld a, [wSpriteStateData1 + 2] - cp $4 - jr nz, .asm_70894 +; If the player is facing up, unhide the fishing rod. + ld a, [wSpriteStateData1 + 2] ; player's sprite facing direction + cp SPRITE_FACING_UP + jr nz, .skipUnhidingFishingRod ld a, $44 ld [wOAMBuffer + $9c], a -.asm_70894 + +.skipUnhidingFishingRod ld hl, ItsABiteText -.asm_70897 + +.done call PrintText ld hl, wd736 - res 6, [hl] + res 6, [hl] ; unreserve the last 4 OAM entries call LoadFontTilePatterns ret -Func_708a3: ; 708a3 (1c:48a3) +.ShakePlayerSprite ; 708a3 (1c:48a3) ld a, [hl] xor $1 ld [hl], a @@ -470,7 +481,7 @@ ItsABiteText: ; 708b2 (1c:48b2) TX_FAR _ItsABiteText db "@" -FishingRodGfxProperties: ; 708b7 (1c:48b7) +FishingRodOAM: ; 708b7 (1c:48b7) ; specifies how the fishing rod should be drawn on the screen ; first byte = screen y coordinate ; second byte = screen x coordinate diff --git a/engine/overworld/pokecenter.asm b/engine/overworld/pokecenter.asm index 3c640d8e..f302d994 100755 --- a/engine/overworld/pokecenter.asm +++ b/engine/overworld/pokecenter.asm @@ -24,12 +24,12 @@ DisplayPokemonCenterDialogue_: ; 6fe6 (1:6fe6) predef HealParty callba AnimateHealingMachine ; do the healing machine animation xor a - ld [wMusicHeaderPointer], a - ld a, [wc0f0] - ld [wc0ef], a - ld a, [wd35b] - ld [wcfca], a - ld [wc0ee], a + ld [wAudioFadeOutControl], a + ld a, [wAudioSavedROMBank] + ld [wAudioROMBank], a + ld a, [wMapMusicSoundID] + ld [wLastMusicSoundID], a + ld [wNewSoundID], a call PlaySound ld hl, PokemonFightingFitText call PrintText @@ -43,7 +43,7 @@ DisplayPokemonCenterDialogue_: ; 6fe6 (1:6fe6) .done ld hl, PokemonCenterFarewellText call PrintText - jp UpdateSprites ; move sprites + jp UpdateSprites PokemonCenterWelcomeText: ; 705d (1:705d) TX_FAR _PokemonCenterWelcomeText diff --git a/engine/overworld/pokemart.asm b/engine/overworld/pokemart.asm index 8325b93f..ae96c4a9 100755 --- a/engine/overworld/pokemart.asm +++ b/engine/overworld/pokemart.asm @@ -1,30 +1,34 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) ld a,[wListScrollOffset] - ld [wd07e],a - call UpdateSprites ; move sprites + ld [wSavedListScrollOffset],a + call UpdateSprites xor a - ld [wcf0a],a ; flag that is set if something is sold or bought + ld [wBoughtOrSoldItemInMart],a .loop xor a ld [wListScrollOffset],a ld [wCurrentMenuItem],a ld [wPlayerMonNumber],a inc a - ld [wcf93],a + ld [wPrintItemPrices],a ld a,MONEY_BOX ld [wTextBoxID],a - call DisplayTextBoxID ; draw money text box + call DisplayTextBoxID ld a,BUY_SELL_QUIT_MENU ld [wTextBoxID],a - call DisplayTextBoxID ; do buy/sell/quit menu - ld hl,wd128 ; pointer to this pokemart's inventory + call DisplayTextBoxID + +; This code is useless. It copies the address of the pokemart's inventory to hl, +; but the address is never used. + ld hl,wItemListPointer ld a,[hli] ld l,[hl] - ld h,a ; hl = address of inventory - ld a,[wd12e] - cp a,$02 + ld h,a + + ld a,[wMenuExitMethod] + cp a,CANCELLED_MENU jp z,.done - ld a,[wd12d] ; ID of the chosen menu item + ld a,[wChosenMenuItem] and a ; buying? jp z,.buyMenu dec a ; selling? @@ -32,11 +36,14 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) dec a ; quitting? jp z,.done .sellMenu + +; the same variables are set again below, so this code has no effect xor a - ld [wcf93],a - ld a,$02 - ld [wd11b],a - callab Func_39bd5 + ld [wPrintItemPrices],a + ld a,INIT_BAG_ITEM_LIST + ld [wInitListType],a + callab InitList + ld a,[wNumBagItems] and a jp z,.bagEmpty @@ -50,19 +57,19 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) call DisplayTextBoxID ; draw money text box ld hl,wNumBagItems ld a,l - ld [wList],a + ld [wListPointer],a ld a,h - ld [wList + 1],a + ld [wListPointer + 1],a xor a - ld [wcf93],a + ld [wPrintItemPrices],a ld [wCurrentMenuItem],a ld a,ITEMLISTMENU ld [wListMenuID],a call DisplayListMenuID jp c,.returnToMainPokemartMenu ; if the player closed the menu .confirmItemSale ; if the player is trying to sell a specific item - call IsKeyItem ; check if item is unsellable - ld a,[wd124] + call IsKeyItem + ld a,[wIsKeyItem] and a jr nz,.unsellableItem ld a,[wcf91] @@ -70,30 +77,34 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) jr c,.unsellableItem ld a,PRICEDITEMLISTMENU ld [wListMenuID],a - ld [$ff8e],a ; halve prices when selling + ld [hHalveItemPrices],a ; halve prices when selling call DisplayChooseQuantityMenu inc a jr z,.sellMenuLoop ; if the player closed the choose quantity menu with the B button ld hl,PokemartTellSellPriceText - ld bc,$0e01 + lb bc, 14, 1 ; location that PrintText always prints to, this is useless call PrintText - hlCoord 14, 7 - ld bc,$080f + coord hl, 14, 7 + lb bc, 08, 15 ld a,TWO_OPTION_MENU ld [wTextBoxID],a call DisplayTextBoxID ; yes/no menu - ld a,[wd12e] - cp a,$02 - jr z,.sellMenuLoop ; if the player pressed the B button - ld a,[wd12d] ; ID of the chosen menu item + ld a,[wMenuExitMethod] + cp a,CHOSE_SECOND_ITEM + jr z,.sellMenuLoop ; if the player chose No or pressed the B button + +; The following code is supposed to check if the player chose No, but the above +; check already catches it. + ld a,[wChosenMenuItem] dec a - jr z,.sellMenuLoop ; if the player chose No + jr z,.sellMenuLoop + .sellItem - ld a,[wcf0a] ; flag that is set if something is sold or bought + ld a,[wBoughtOrSoldItemInMart] and a jr nz,.skipSettingFlag1 inc a - ld [wcf0a],a + ld [wBoughtOrSoldItemInMart],a .skipSettingFlag1 call AddAmountSoldToMoney ld hl,wNumBagItems @@ -106,39 +117,42 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) .bagEmpty ld hl,PokemartItemBagEmptyText call PrintText - call SaveScreenTilesToBuffer1 ; save screen + call SaveScreenTilesToBuffer1 jp .returnToMainPokemartMenu .buyMenu - ld a,$01 - ld [wcf93],a - ld a,$03 - ld [wd11b],a - callab Func_39bd5 + +; the same variables are set again below, so this code has no effect + ld a,1 + ld [wPrintItemPrices],a + ld a,INIT_OTHER_ITEM_LIST + ld [wInitListType],a + callab InitList + ld hl,PokemartBuyingGreetingText call PrintText - call SaveScreenTilesToBuffer1 ; save screen + call SaveScreenTilesToBuffer1 .buyMenuLoop - call LoadScreenTilesFromBuffer1 ; restore saved screen + call LoadScreenTilesFromBuffer1 ld a,MONEY_BOX ld [wTextBoxID],a - call DisplayTextBoxID ; draw money text box - ld hl,wStringBuffer2 + 11 + call DisplayTextBoxID + ld hl,wItemList ld a,l - ld [wList],a + ld [wListPointer],a ld a,h - ld [wList + 1],a + ld [wListPointer + 1],a xor a ld [wCurrentMenuItem],a inc a - ld [wcf93],a + ld [wPrintItemPrices],a inc a ; a = 2 (PRICEDITEMLISTMENU) ld [wListMenuID],a call DisplayListMenuID jr c,.returnToMainPokemartMenu ; if the player closed the menu - ld a,$63 - ld [wcf97],a + ld a,99 + ld [wMaxItemQuantity],a xor a - ld [$ff8e],a + ld [hHalveItemPrices],a ; don't halve item prices when buying call DisplayChooseQuantityMenu inc a jr z,.buyMenuLoop ; if the player closed the choose quantity menu with the B button @@ -148,17 +162,21 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) call CopyStringToCF4B ; copy name to wcf4b ld hl,PokemartTellBuyPriceText call PrintText - hlCoord 14, 7 - ld bc,$080f + coord hl, 14, 7 + lb bc, 8, 15 ld a,TWO_OPTION_MENU ld [wTextBoxID],a call DisplayTextBoxID ; yes/no menu - ld a,[wd12e] - cp a,$02 - jp z,.buyMenuLoop ; if the player pressed the B button - ld a,[wd12d] ; ID of the chosen menu item + ld a,[wMenuExitMethod] + cp a,CHOSE_SECOND_ITEM + jp z,.buyMenuLoop ; if the player chose No or pressed the B button + +; The following code is supposed to check if the player chose No, but the above +; check already catches it. + ld a,[wChosenMenuItem] dec a - jr z,.buyMenuLoop ; if the player chose No + jr z,.buyMenuLoop + .buyItem call .isThereEnoughMoney jr c,.notEnoughMoney @@ -166,13 +184,13 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) call AddItemToInventory jr nc,.bagFull call SubtractAmountPaidFromMoney - ld a,[wcf0a] ; flag that is set if something is sold or bought + ld a,[wBoughtOrSoldItemInMart] and a jr nz,.skipSettingFlag2 - ld a,$01 - ld [wcf0a],a + ld a,1 + ld [wBoughtOrSoldItemInMart],a .skipSettingFlag2 - ld a,(SFX_02_5a - SFX_Headers_02) / 3 + ld a,SFX_PURCHASE call PlaySoundWaitForCurrent call WaitForSoundToFinish ld hl,PokemartBoughtItemText @@ -182,13 +200,13 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) call LoadScreenTilesFromBuffer1 ld a,MONEY_BOX ld [wTextBoxID],a - call DisplayTextBoxID ; draw money text box + call DisplayTextBoxID ld hl,PokemartAnythingElseText call PrintText jp .loop .isThereEnoughMoney ld de,wPlayerMoney - ld hl,$ff9f ; item price + ld hl,hMoney ld c,3 ; length of money in bytes jp StringCmp .notEnoughMoney @@ -202,10 +220,10 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) .done ld hl,PokemartThankYouText call PrintText - ld a,$01 + ld a,1 ld [wUpdateSpritesEnabled],a - call UpdateSprites ; move sprites - ld a,[wd07e] + call UpdateSprites + ld a,[wSavedListScrollOffset] ld [wListScrollOffset],a ret diff --git a/engine/overworld/saffron_guards.asm b/engine/overworld/saffron_guards.asm index 8e584a2d..c0d6a985 100755 --- a/engine/overworld/saffron_guards.asm +++ b/engine/overworld/saffron_guards.asm @@ -10,9 +10,7 @@ RemoveGuardDrink: ; 5a59f (16:659f) call IsItemInBag pop hl jr z, .drinkLoop - ld b, BANK(RemoveItemByID) - ld hl, RemoveItemByID - jp Bankswitch + jpba RemoveItemByID GuardDrinksList: ; 5a5b7 (16:65b7) db FRESH_WATER, SODA_POP, LEMONADE, $00 diff --git a/engine/overworld/ssanne.asm b/engine/overworld/ssanne.asm index f1a8ecf9..e631bbfa 100755 --- a/engine/overworld/ssanne.asm +++ b/engine/overworld/ssanne.asm @@ -1,6 +1,6 @@ AnimateBoulderDust: ; 79f54 (1e:5f54) ld a, $1 - ld [wcd50], a ; select the boulder dust offsets + ld [wWhichAnimationOffsets], a ; select the boulder dust offsets ld a, [wUpdateSpritesEnabled] push af ld a, $ff @@ -8,14 +8,14 @@ AnimateBoulderDust: ; 79f54 (1e:5f54) ld a, %11100100 ld [rOBP1], a call LoadSmokeTileFourTimes - callba WriteCutTreeBoulderDustAnimationOAMBlock + callba WriteCutOrBoulderDustAnimationOAMBlock ld c, 8 ; number of steps in animation .loop push bc call GetMoveBoulderDustFunctionPointer ld bc, .returnAddress push bc - ld c, $4 + ld c, 4 jp [hl] .returnAddress ld a, [rOBP1] @@ -36,7 +36,7 @@ GetMoveBoulderDustFunctionPointer: ; 79f92 (1e:5f92) ld b, $0 add hl, bc ld a, [hli] - ld [wd08a], a + ld [wCoordAdjustmentAmount], a ld a, [hli] ld e, a ld a, [hli] @@ -84,9 +84,10 @@ LoadSmokeTileFourTimes: ; 79fc0 (1e:5fc0) ret LoadSmokeTile: ; 79fd4 (1e:5fd4) - ld de, SSAnneSmokePuffTile ; $5fdd - ld bc, (BANK(SSAnneSmokePuffTile) << 8) + $01 + ld de, SSAnneSmokePuffTile + lb bc, BANK(SSAnneSmokePuffTile), (SSAnneSmokePuffTileEnd - SSAnneSmokePuffTile) / $10 jp CopyVideoData SSAnneSmokePuffTile: ; 79fdd (1e:5fdd) INCBIN "gfx/ss_anne_smoke_puff.2bpp" +SSAnneSmokePuffTileEnd: diff --git a/engine/overworld/trainers.asm b/engine/overworld/trainers.asm index 4aaab3ed..7d2ec0dd 100755 --- a/engine/overworld/trainers.asm +++ b/engine/overworld/trainers.asm @@ -24,16 +24,16 @@ _GetSpritePosition2: ; 56819 (15:6819) ld [H_SPRITEINDEX], a call GetSpriteDataPointer ld a, [hli] ; c1x4 (screen Y pos) - ld [wd130], a + ld [wSavedSpriteScreenY], a inc hl ld a, [hl] ; c1x6 (screen X pos) - ld [wd131], a + ld [wSavedSpriteScreenX], a ld de, $104 - $6 add hl, de ld a, [hli] ; c2x4 (map Y pos) - ld [wd132], a + ld [wSavedSpriteMapY], a ld a, [hl] ; c2x5 (map X pos) - ld [wd133], a + ld [wSavedSpriteMapX], a ret _SetSpritePosition1: ; 5683d (15:683d) @@ -61,23 +61,23 @@ _SetSpritePosition2: ; 5685d (15:685d) ld a, [wSpriteIndex] ld [H_SPRITEINDEX], a call GetSpriteDataPointer - ld a, [wd130] + ld a, [wSavedSpriteScreenY] ld [hli], a inc hl - ld a, [wd131] + ld a, [wSavedSpriteScreenX] ld [hl], a ld de, $00fe add hl, de - ld a, [wd132] + ld a, [wSavedSpriteMapY] ld [hli], a - ld a, [wd133] + ld a, [wSavedSpriteMapX] ld [hl], a ret TrainerWalkUpToPlayer: ; 56881 (15:6881) ld a, [wSpriteIndex] swap a - ld [wTrainerSpriteOffset], a ; wWhichTrade + ld [wTrainerSpriteOffset], a call ReadTrainerScreenPosition ld a, [wTrainerFacingDirection] and a @@ -164,7 +164,7 @@ GetSpriteDataPointer: ; 56903 (15:6903) TrainerEngage: ; 5690f (15:690f) push hl push de - ld a, [wTrainerSpriteOffset] ; wWhichTrade + ld a, [wTrainerSpriteOffset] add $2 ld d, $0 ld e, a @@ -175,7 +175,7 @@ TrainerEngage: ; 5690f (15:690f) jr nz, .spriteOnScreen ; test if sprite is on screen jp .noEngage .spriteOnScreen - ld a, [wTrainerSpriteOffset] ; wWhichTrade + ld a, [wTrainerSpriteOffset] add $9 ld d, $0 ld e, a @@ -218,7 +218,7 @@ TrainerEngage: ; 5690f (15:690f) jp .noEngage .engage call CheckPlayerIsInFrontOfSprite - ld a, [wTrainerSpriteOffset] ; wWhichTrade + ld a, [wTrainerSpriteOffset] and a jr z, .noEngage ld hl, wFlags_0xcd60 @@ -226,14 +226,14 @@ TrainerEngage: ; 5690f (15:690f) call EngageMapTrainer ld a, $ff .noEngage: ; 56988 (15:6988) - ld [wTrainerSpriteOffset], a ; wWhichTrade + ld [wTrainerSpriteOffset], a pop de pop hl ret ; reads trainer's Y position to wTrainerScreenY and X position to wTrainerScreenX ReadTrainerScreenPosition: ; 5698e (15:698e) - ld a, [wTrainerSpriteOffset] ; wWhichTrade + ld a, [wTrainerSpriteOffset] add $4 ld d, $0 ld e, a @@ -241,7 +241,7 @@ ReadTrainerScreenPosition: ; 5698e (15:698e) add hl, de ld a, [hl] ld [wTrainerScreenY], a - ld a, [wTrainerSpriteOffset] ; wWhichTrade + ld a, [wTrainerSpriteOffset] add $6 ld d, $0 ld e, a @@ -256,7 +256,7 @@ ReadTrainerScreenPosition: ; 5698e (15:698e) ; a: distance player to sprite CheckSpriteCanSeePlayer: ; 569af (15:69af) ld b, a - ld a, [wTrainerEngageDistance] ; sprite line of sight (engage distance) + ld a, [wTrainerEngageDistance] ; how far the trainer can see cp b jr nc, .checkIfLinedUp jr .notInLine ; player too far away @@ -291,10 +291,10 @@ CheckSpriteCanSeePlayer: ; 569af (15:69af) ; tests if the player is in front of the sprite (rather than behind it) CheckPlayerIsInFrontOfSprite: ; 569e3 (15:69e3) - ld a, [W_CURMAP] ; W_CURMAP + ld a, [W_CURMAP] cp POWER_PLANT - jp z, .engage ; XXX not sure why bypass this for power plant (maybe to get voltorb fake items to work?) - ld a, [wTrainerSpriteOffset] ; wWhichTrade + jp z, .engage ; bypass this for power plant to get voltorb fake items to work + ld a, [wTrainerSpriteOffset] add $4 ld d, $0 ld e, a @@ -306,7 +306,7 @@ CheckPlayerIsInFrontOfSprite: ; 569e3 (15:69e3) ld a, $c .notOnTopmostTile ld [wTrainerScreenY], a - ld a, [wTrainerSpriteOffset] ; wWhichTrade + ld a, [wTrainerSpriteOffset] add $6 ld d, $0 ld e, a @@ -345,5 +345,5 @@ CheckPlayerIsInFrontOfSprite: ; 569e3 (15:69e3) .noEngage xor a .done - ld [wTrainerSpriteOffset], a ; wWhichTrade + ld [wTrainerSpriteOffset], a ret diff --git a/engine/palettes.asm b/engine/palettes.asm index 2536fefc..810f8e77 100755 --- a/engine/palettes.asm +++ b/engine/palettes.asm @@ -1,33 +1,33 @@ -Func_71eb3: ; 71eb3 (1c:5eb3) +_RunPaletteCommand: ; 71ddf (1c:5ddf) call GetPredefRegisters ld a, b cp $ff - jr nz, .asm_71ebe - ld a, [wcf1c] -.asm_71ebe - cp $fc - jp z, Func_7218b + jr nz, .next + ld a, [wDefaultPaletteCommand] ; use default command if command ID is $ff +.next + cp UPDATE_PARTY_MENU_BLK_PACKET + jp z, UpdatePartyMenuBlkPacket ld l, a - ld h, $0 + ld h, 0 add hl, hl - ld de, PointerTable_7206b + ld de, SetPalFunctions add hl, de ld a, [hli] ld h, [hl] ld l, a - ld de, Func_72328 + ld de, SendSGBPackets push de jp [hl] -SendPalPacket_Black: ; 71ed3 (1c:5ed3) +SetPal_Black: ; 71ed3 (1c:5ed3) ld hl, PalPacket_Black ld de, BlkPacket_Battle ret ; uses PalPacket_Empty to build a packet based on mon IDs and health color -BuildBattlePalPacket: ; 71eda (1c:5eda) +SetPal_Battle: ; 71eda (1c:5eda) ld hl, PalPacket_Empty - ld de, wcf2d + ld de, wPalPacket ld bc, $10 call CopyData ;ld a, [W_PLAYERBATTSTATUS3] @@ -46,12 +46,12 @@ BuildBattlePalPacket: ; 71eda (1c:5eda) ld hl, wEnemyMonSpecies2 call DeterminePaletteID ld c, a - ld hl, wcf2e - ld a, [wcf1d] + ld hl, wPalPacket + 1 + ld a, [wPlayerHPBarColor] add PAL_GREENBAR ld [hli], a inc hl - ld a, [wcf1e] + ld a, [wEnemyHPBarColor] add PAL_GREENBAR ld [hli], a inc hl @@ -60,21 +60,21 @@ BuildBattlePalPacket: ; 71eda (1c:5eda) inc hl ld a, c ld [hl], a - ld hl, wcf2d + ld hl, wPalPacket ld de, BlkPacket_Battle - ld a, $1 - ld [wcf1c], a + ld a, SET_PAL_BATTLE + ld [wDefaultPaletteCommand], a ret -SendPalPacket_TownMap: ; 71f26 (1c:5f26) +SetPal_TownMap: ; 71f26 (1c:5f26) ld hl, PalPacket_TownMap ld de, BlkPacket_WholeScreen ret ; uses PalPacket_Empty to build a packet based the mon ID -BuildStatusScreenPalPacket: ; 71f2d (1c:5f2d) +SetPal_StatusScreen: ; 71f2d (1c:5f2d) ld hl, PalPacket_Empty - ld de, wcf2d + ld de, wPalPacket ld bc, $10 call CopyData ld a, [wcf91] @@ -84,67 +84,67 @@ BuildStatusScreenPalPacket: ; 71f2d (1c:5f2d) .pokemon call DeterminePaletteIDOutOfBattle push af - ld hl, wcf2e - ld a, [wcf25] - add $1f + ld hl, wPalPacket + 1 + ld a, [wStatusScreenHPBarColor] + add PAL_GREENBAR ld [hli], a inc hl pop af ld [hl], a - ld hl, wcf2d + ld hl, wPalPacket ld de, BlkPacket_StatusScreen ret -SendPalPacket_PartyMenu: ; 71f59 (1c:5f59) +SetPal_PartyMenu: ; 71f59 (1c:5f59) ld hl, PalPacket_PartyMenu - ld de, wcf2e + ld de, wPartyMenuBlkPacket ret -SendPalPacket_Pokedex: ; 71f60 (1c:5f60) +SetPal_Pokedex: ; 71f60 (1c:5f60) ld hl, PalPacket_Pokedex - ld de, wcf2d + ld de, wPalPacket ld bc, $10 call CopyData ld a, [wcf91] call DeterminePaletteIDOutOfBattle - ld hl, wcf30 + ld hl, wPalPacket + 3 ld [hl], a - ld hl, wcf2d + ld hl, wPalPacket ld de, BlkPacket_Pokedex ret -SendPalPacket_Slots: ; 71f7d (1c:5f7d) +SetPal_Slots: ; 71f7d (1c:5f7d) ld hl, PalPacket_Slots ld de, BlkPacket_Slots ret -SendPalPacket_Titlescreen: ; 71f84 (1c:5f84) +SetPal_Titlescreen: ; 71f84 (1c:5f84) ld hl, PalPacket_Titlescreen ld de, BlkPacket_Titlescreen ret ; used mostly for menus and the Oak intro -SendPalPacket_Generic: ; 71f8b (1c:5f8b) +SetPal_Generic: ; 71f8b (1c:5f8b) ld hl, PalPacket_Generic ld de, BlkPacket_WholeScreen ret -SendPalPacket_NidorinoIntro: ; 71f92 (1c:5f92) +SetPal_NidorinoIntro: ; 71f92 (1c:5f92) ld hl, PalPacket_NidorinoIntro ld de, BlkPacket_NidorinoIntro ret -SendPalPacket_GameFreakIntro: ; 71f99 (1c:5f99) +SetPal_GameFreakIntro: ; 71f99 (1c:5f99) ld hl, PalPacket_GameFreakIntro ld de, BlkPacket_GameFreakIntro - ld a, $8 - ld [wcf1c], a + ld a, SET_PAL_GENERIC + ld [wDefaultPaletteCommand], a ret ; uses PalPacket_Empty to build a packet based on the current map -BuildOverworldPalPacket: ; 71fa5 (1c:5fa5) +SetPal_Overworld: ; 71fa5 (1c:5fa5) ld hl, PalPacket_Empty - ld de, wcf2d + ld de, wPalPacket ld bc, $10 call CopyData ld a, [W_CURMAPTILESET] @@ -174,12 +174,12 @@ BuildOverworldPalPacket: ; 71fa5 (1c:5fa5) jr c, .town ld a, PAL_ROUTE - 1 .town - inc a ; a town's pallete ID is its map ID + 1 - ld hl, wcf2e + inc a ; a town's palette ID is its map ID + 1 + ld hl, wPalPacket + 1 ld [hld], a ld de, BlkPacket_WholeScreen - ld a, $9 - ld [wcf1c], a + ld a, SET_PAL_OVERWORLD + ld [wDefaultPaletteCommand], a ret .PokemonTowerOrAgatha ld a, PAL_GREYMON - 1 @@ -196,61 +196,63 @@ BuildOverworldPalPacket: ; 71fa5 (1c:5fa5) ; used when a Pokemon is the only thing on the screen ; such as evolution, trading and the Hall of Fame -SendPokemonPalette_WholeScreen: ; 72001 (1c:6001) +SetPal_PokemonWholeScreen: ; 72001 (1c:6001) push bc ld hl, PalPacket_Empty - ld de, wcf2d + ld de, wPalPacket ld bc, $10 call CopyData pop bc ld a, c and a - ld a, $1e - jr nz, .asm_7201b - ld a, [wcf1d] + ld a, PAL_BLACK + jr nz, .next + ld a, [wWholeScreenPaletteMonSpecies] call DeterminePaletteIDOutOfBattle -.asm_7201b - ld [wcf2e], a - ld hl, wcf2d +.next + ld [wPalPacket + 1], a + ld hl, wPalPacket ld de, BlkPacket_WholeScreen ret -BuildTrainerCardPalPacket: ; 72025 (1c:6025) +SetPal_TrainerCard: ; 72025 (1c:6025) ld hl, BlkPacket_TrainerCard - ld de, wcc5b + ld de, wTrainerCardBlkPacket ld bc, $40 call CopyData - ld de, LoopCounts_7208b - ld hl, wcc5d + ld de, BadgeBlkDataLengths + ld hl, wTrainerCardBlkPacket + 2 ld a, [W_OBTAINEDBADGES] - ld c, $8 -.asm_7203c + ld c, 8 +.badgeLoop srl a push af - jr c, .asm_7204c + jr c, .haveBadge +; The player doens't have the badge, so zero the badge's blk data. push bc ld a, [de] ld c, a xor a -.asm_72045 +.zeroBadgeDataLoop ld [hli], a dec c - jr nz, .asm_72045 + jr nz, .zeroBadgeDataLoop pop bc - jr .asm_72051 -.asm_7204c + jr .nextBadge +.haveBadge +; The player does have the badge, so skip past the badge's blk data. ld a, [de] -.asm_7204d +.skipBadgeDataLoop inc hl dec a - jr nz, .asm_7204d -.asm_72051 + jr nz, .skipBadgeDataLoop +.nextBadge pop af inc de dec c - jr nz, .asm_7203c + jr nz, .badgeLoop ld hl, PalPacket_TrainerCard - ld de, wcc5b + ld de, wTrainerCardBlkPacket ret SendUnknownPalPacket_7205d:: ; 7205d (1c:605d) @@ -263,46 +265,50 @@ SendUnknownPalPacket_72064:: ; 72064 (1c:6064) ld de,UnknownPacket_72751 ret -PointerTable_7206b: ; 7206b (1c:606b) - dw SendPalPacket_Black - dw BuildBattlePalPacket - dw SendPalPacket_TownMap - dw BuildStatusScreenPalPacket - dw SendPalPacket_Pokedex - dw SendPalPacket_Slots - dw SendPalPacket_Titlescreen - dw SendPalPacket_NidorinoIntro - dw SendPalPacket_Generic - dw BuildOverworldPalPacket - dw SendPalPacket_PartyMenu - dw SendPokemonPalette_WholeScreen - dw SendPalPacket_GameFreakIntro - dw BuildTrainerCardPalPacket +SetPalFunctions: ; 7206b (1c:606b) + dw SetPal_Black + dw SetPal_Battle + dw SetPal_TownMap + dw SetPal_StatusScreen + dw SetPal_Pokedex + dw SetPal_Slots + dw SetPal_Titlescreen + dw SetPal_NidorinoIntro + dw SetPal_Generic + dw SetPal_Overworld + dw SetPal_PartyMenu + dw SetPal_PokemonWholeScreen + dw SetPal_GameFreakIntro + dw SetPal_TrainerCard dw SendUnknownPalPacket_7205d dw SendUnknownPalPacket_72064 -; each byte is the number of loops to make in .asm_71f5b for each badge -LoopCounts_7208b: ; 7208b (1c:608b) - db $06,$06,$06,$12,$06,$06,$06,$06 +; The length of the blk data of each badge on the Trainer Card. +; The Rainbow Badge has 3 entries because of its many colors. +BadgeBlkDataLengths: ; 7208b (1c:608b) + db 6 ; Boulder Badge + db 6 ; Cascade Badge + db 6 ; Thunder Badge + db 6 * 3 ; Rainbow Badge + db 6 ; Soul Badge + db 6 ; Marsh Badge + db 6 ; Volcano Badge + db 6 ; Earth Badge -;DeterminePaletteID: ; 71f97 (1c:5f97) - ;bit 3, a ; bit 3 of battle status 3, set if ;current Pokemon is transformed - ;ld a, PAL_GREYMON ; if yes, use Ditto's palette - ;ret nz DeterminePaletteID: ; 72093 (1c:6093) ld a, [hl] DeterminePaletteIDOutOfBattle: ; 72094 (1c:6094) ld [wd11e], a - and a - jr z, .idZero + and a ; is the mon index 0? + jr z, .skipDexNumConversion push bc - predef IndexToPokedex ; turn Pokemon ID number into Pokedex number + predef IndexToPokedex pop bc ld a, [wd11e] -.idZero +.skipDexNumConversion ld e, a - ld d, $00 - ld hl, MonsterPalettes ; not just for Pokemon, Trainers use it too + ld d, 0 + ld hl, MonsterPalettes ; not just for Pokemon, Trainers use it too add hl, de ld a, [hl] ret @@ -384,7 +390,7 @@ Func_720e3:: ; 720e3 (1c:60e3) ret Func_7213b:: ; 7213b (1c:613b) -; similar to BuildOverworldPalPacket +; similar to SetPal_Overworld ld a, [W_CURMAPTILESET] cp CEMETERY jr z, .PokemonTowerOrAgatha @@ -427,33 +433,35 @@ Func_7213b:: ; 7213b (1c:613b) ld a,$18 jr .town -SendBlkPacket_PartyMenu: ; 7217f (1c:617f) - ld hl, BlkPacket_PartyMenu ; $62f4 - ld de, wcf2e +InitPartyMenuBlkPacket: ; 7217f (1c:617f) + ld hl, BlkPacket_PartyMenu + ld de, wPartyMenuBlkPacket ld bc, $30 jp CopyData -Func_7218b: ; 7218b (1c:618b) - ld hl, wcf1f - ld a, [wcf2d] +UpdatePartyMenuBlkPacket: ; 7218b (1c:618b) +; Update the blk packet with the palette of the HP bar that is +; specified in [wWhichPartyMenuHPBar]. + ld hl, wPartyMenuHPBarColors + ld a, [wWhichPartyMenuHPBar] ld e, a - ld d, $0 + ld d, 0 add hl, de ld e, l ld d, h ld a, [de] and a - ld e, $5 - jr z, .asm_721a4 + ld e, (1 << 2) | 1 ; green + jr z, .next dec a - ld e, $a - jr z, .asm_721a4 - ld e, $f -.asm_721a4 + ld e, (2 << 2) | 2 ; yellow + jr z, .next + ld e, (3 << 2) | 3 ; red +.next push de - ld hl, wcf37 - ld bc, $6 - ld a, [wcf2d] + ld hl, wPartyMenuBlkPacket + 8 + 1 + ld bc, 6 + ld a, [wWhichPartyMenuHPBar] call AddNTimes pop de ld [hl], e @@ -482,10 +490,10 @@ SendSGBPacket: ; 71feb (1c:5feb) push bc ; send RESET signal (P14=LOW, P15=LOW) xor a - ld [$ff00],a + ld [rJOYP],a ; set P14=HIGH, P15=HIGH ld a,$30 - ld [$ff00],a + ld [rJOYP],a ;load length of packets (16 bytes) ld b,$10 .nextByte @@ -502,10 +510,10 @@ SendSGBPacket: ; 71feb (1c:5feb) ; else (if 0th bit is zero) set P14=LOW,P15=HIGH (send bit 0) ld a,$20 .next0 - ld [$ff00],a + ld [rJOYP],a ; must set P14=HIGH,P15=HIGH between each "pulse" ld a,$30 - ld [$ff00],a + ld [rJOYP],a ; rotation will put next bit in 0th position (so we can always use command ; "bit 0,d" to fetch the bit that has to be sent) rr d @@ -516,13 +524,11 @@ SendSGBPacket: ; 71feb (1c:5feb) jr nz,.nextByte ; send bit 1 as a "stop bit" (end of parameter data) ld a,$20 - ld [$ff00],a + ld [rJOYP],a ; set P14=HIGH,P15=HIGH ld a,$30 - ld [$ff00],a + ld [rJOYP],a call Wait7000 -; xor a -; ld [$fff9],a ; wait for about 70000 cycles ; call Wait7000 ; restore (previously pushed) number of packets @@ -549,30 +555,30 @@ LoadSGB: ; 721f8 (1c:61f8) ld a, $1 ld [wOnSGB], a di - call Func_72247 + call PrepareSuperNintendoVRAMTransfer ei - ld a, $1 - ld [wcf2d], a + ld a, 1 + ld [wCopyingSGBTileData], a ld de, ChrTrnPacket ld hl, SGBBorderGraphics - call Func_722d7 + call CopyGfxToSuperNintendoVRAM xor a - ld [wcf2d], a + ld [wCopyingSGBTileData], a ld de, PctTrnPacket ld hl, BorderPalettes - call Func_722d7 + call CopyGfxToSuperNintendoVRAM xor a - ld [wcf2d], a + ld [wCopyingSGBTileData], a ld de, PalTrnPacket ld hl, SuperPalettes - call Func_722d7 + call CopyGfxToSuperNintendoVRAM call ClearVram ld hl, MaskEnCancelPacket jp Func_721b4 -Func_72247: ; 72247 (1c:6247) - ld hl, PointerTable_7225b - ld c, $9 +PrepareSuperNintendoVRAMTransfer: ; 72247 (1c:6247) + ld hl, .packetPointers + ld c, 9 .loop push bc ld a, [hli] @@ -587,7 +593,8 @@ Func_72247: ; 72247 (1c:6247) jr nz, .loop ret -PointerTable_7225b: ; 7225b (1c:625b) +.packetPointers ; 7225b (1c:625b) +; Only the first packet is needed. dw MaskEnFreezePacket dw DataSnd_728a1 dw DataSnd_728b1 @@ -602,55 +609,55 @@ CheckSGB: ; 7226d (1c:626d) ld hl, MltReq2Packet call Func_721b4 call Wait7000 - ld a, [rJOYP] ; $ff0 + ld a, [rJOYP] and $3 cp $3 - jr nz, .asm_722c9 + jr nz, .isSGB ld a, $20 - ld [rJOYP], a ; $ff0 - ld a, [rJOYP] ; $ff0 - ld a, [rJOYP] ; $ff0 + ld [rJOYP], a + ld a, [rJOYP] + ld a, [rJOYP] call Wait7000 call Wait7000 ld a, $30 - ld [rJOYP], a ; $ff0 + ld [rJOYP], a call Wait7000 call Wait7000 ld a, $10 - ld [rJOYP], a ; $ff0 - ld a, [rJOYP] ; $ff0 - ld a, [rJOYP] ; $ff0 - ld a, [rJOYP] ; $ff0 - ld a, [rJOYP] ; $ff0 - ld a, [rJOYP] ; $ff0 - ld a, [rJOYP] ; $ff0 + ld [rJOYP], a + ld a, [rJOYP] + ld a, [rJOYP] + ld a, [rJOYP] + ld a, [rJOYP] + ld a, [rJOYP] + ld a, [rJOYP] call Wait7000 call Wait7000 ld a, $30 - ld [rJOYP], a ; $ff0 - ld a, [rJOYP] ; $ff0 - ld a, [rJOYP] ; $ff0 - ld a, [rJOYP] ; $ff0 + ld [rJOYP], a + ld a, [rJOYP] + ld a, [rJOYP] + ld a, [rJOYP] call Wait7000 call Wait7000 - ld a, [rJOYP] ; $ff0 + ld a, [rJOYP] and $3 cp $3 - jr nz, .asm_722c9 - call Func_722ce + jr nz, .isSGB + call SendMltReq1Packet and a ret -.asm_722c9 - call Func_722ce +.isSGB + call SendMltReq1Packet scf ret -Func_722ce: ; 722ce (1c:62ce) +SendMltReq1Packet: ; 722ce (1c:62ce) ld hl, MltReq1Packet call Func_721b4 jp Wait7000 -Func_722d7: ; 722d7 (1c:62d7) +CopyGfxToSuperNintendoVRAM: ; 722d7 (1c:62d7) di push de call DisableLCD @@ -658,31 +665,31 @@ Func_722d7: ; 722d7 (1c:62d7) ld [rBGP], a ; $ff47 call Func_72520 ld de, vChars1 - ld a, [wcf2d] + ld a, [wCopyingSGBTileData] and a - jr z, .asm_722f1 - call Func_725fb - jr .asm_722f7 -.asm_722f1 + jr z, .notCopyingTileData + call CopySGBBorderTiles + jr .next +.notCopyingTileData ld bc, $1000 call CopyData -.asm_722f7 +.next ld hl, vBGMap0 ld de, $c ld a, $80 ld c, $d -.asm_72301 +.loop ld b, $14 -.asm_72303 +.innerLoop ld [hli], a inc a dec b - jr nz, .asm_72303 + jr nz, .innerLoop add hl, de dec c - jr nz, .asm_72301 + jr nz, .loop ld a, $e3 - ld [rLCDC], a ; $ff40 + ld [rLCDC], a pop hl call Func_721b4 xor a @@ -704,26 +711,26 @@ Wait7000: ; 7231c (1c:631c) jr nz, .loop ret -Func_72328: ; 72328 (1c:6328) +SendSGBPackets: ; 72328 (1c:6328) ld a, [hGBC] and a - jr z, .asm_7233e + jr z, .notGBC push de - call Func_72346 + call InitGBCPalettes pop hl - call Func_72346 + call InitGBCPalettes ld a,[rLCDC] and rLCDC_ENABLE_MASK ret z call Delay3 ret -.asm_7233e +.notGBC push de call Func_721b4 pop hl jp Func_721b4 -Func_72346: ; 72346 (1c:6346) +InitGBCPalettes: ; 72346 (1c:6346) ld a,[hl] and $f8 cp $20 @@ -1140,25 +1147,34 @@ Pointer_725e2:: ; 725e2 (1c:65e2) db $0c,$11,$66,$21,$66,$41,$66,$51,$66,$61,$66,$81,$66,$a1,$66,$2d db $cf,$5b,$cc,$31,$67,$2c,$cf,$51,$67 -Func_725fb: ; 725fb (1c:65fb) - ld b, $80 -.loop - ld c, $10 -.asm_725ff +CopySGBBorderTiles: ; 725fb (1c:65fb) +; SGB tile data is stored in a 4BPP planar format. +; Each tile is 32 bytes. The first 16 bytes contain bit planes 1 and 2, while +; the second 16 bytes contain bit planes 3 and 4. +; This function converts 2BPP planar data into this format by mapping +; 2BPP colors 0-3 to 4BPP colors 0-3. 4BPP colors 4-15 are not used. + ld b, 128 +.tileLoop +; Copy bit planes 1 and 2 of the tile data. + ld c, 16 +.copyLoop ld a, [hli] ld [de], a inc de dec c - jr nz, .asm_725ff - ld c, $10 + jr nz, .copyLoop + +; Zero bit planes 3 and 4. + ld c, 16 xor a -.asm_72608 +.zeroLoop ld [de], a inc de dec c - jr nz, .asm_72608 + jr nz, .zeroLoop + dec b - jr nz, .loop + jr nz, .tileLoop ret ;dr $725e2,$734b9 diff --git a/engine/pokedex_rating.asm b/engine/pokedex_rating.asm index 080025c6..73025f0a 100755 --- a/engine/pokedex_rating.asm +++ b/engine/pokedex_rating.asm @@ -2,18 +2,18 @@ DisplayDexRating: ; 44169 (11:4169) ld hl, wPokedexSeen ld b, wPokedexSeenEnd - wPokedexSeen call CountSetBits - ld a, [wd11e] ; result of CountSetBits (seen count) - ld [$FFDB], a + ld a, [wNumSetBits] + ld [hDexRatingNumMonsSeen], a ld hl, wPokedexOwned ld b, wPokedexOwnedEnd - wPokedexOwned call CountSetBits - ld a, [wd11e] ; result of CountSetBits (own count) - ld [$FFDC], a + ld a, [wNumSetBits] + ld [hDexRatingNumMonsOwned], a ld hl, DexRatingsTable .findRating ld a, [hli] ld b, a - ld a, [$FFDC] ; number of pokemon owned + ld a, [hDexRatingNumMonsOwned] cp b jr c, .foundRating inc hl @@ -23,34 +23,31 @@ DisplayDexRating: ; 44169 (11:4169) ld a, [hli] ld h, [hl] ld l, a ; load text pointer into hl - ld a, [wd747] - bit 3, a - res 3, a - ld [wd747], a - jr nz, .label3 + CheckAndResetEventA EVENT_HALL_OF_FAME_DEX_RATING + jr nz, .hallOfFame push hl ld hl, PokedexRatingText_441cc call PrintText pop hl call PrintText - callba Func_7d13b - jp WaitForTextScrollButtonPress ; wait for button press -.label3 - ld de, wcc5b - ld a, [$FFDB] + callba PlayPokedexRatingSfx + jp WaitForTextScrollButtonPress +.hallOfFame + ld de, wDexRatingNumMonsSeen + ld a, [hDexRatingNumMonsSeen] ld [de], a inc de - ld a, [$FFDC] + ld a, [hDexRatingNumMonsOwned] ld [de], a inc de -.label4 +.copyRatingTextLoop ld a, [hli] - cp a, $50 - jr z, .label5 + cp a, "@" + jr z, .doneCopying ld [de], a inc de - jr .label4 -.label5 + jr .copyRatingTextLoop +.doneCopying ld [de], a ret diff --git a/engine/predefs.asm b/engine/predefs.asm index 6cf84511..ed588d9a 100755 --- a/engine/predefs.asm +++ b/engine/predefs.asm @@ -151,4 +151,4 @@ PredefPointers:: ; f681d (3d:681d) ;add_predef DrawHP ; 5F ;add_predef DrawHP2 ;add_predef Func_1c9c6 - ;add_predef OaksAideScript + ;add_predef OaksAideScript
\ No newline at end of file diff --git a/engine/predefs12.asm b/engine/predefs12.asm index 90032a14..269a681e 100755 --- a/engine/predefs12.asm +++ b/engine/predefs12.asm @@ -4,62 +4,68 @@ ChangeBGPalColor0_4Frames: ; 480eb (12:40eb) ld a, [rBGP] or b ld [rBGP], a - ld c, $4 + ld c, 4 call DelayFrames ld a, [rBGP] and %11111100 ld [rBGP], a ret -Func_480ff: ; 480ff (12:40ff) +PredefShakeScreenVertically: ; 480ff (12:40ff) +; Moves the window down and then back in a sequence of progressively smaller +; numbers of pixels, starting at b. call GetPredefRegisters - ld a, $1 - ld [wd0a0], a + ld a, 1 + ld [wDisableVBlankWYUpdate], a xor a -.asm_48108 - ld [H_NUMTOPRINT], a ; $ff96 (aliases: H_MULTIPLICAND) - call Func_48119 - call Func_48119 +.loop + ld [$ff96], a + call .MutateWY + call .MutateWY dec b ld a, b - jr nz, .asm_48108 + jr nz, .loop xor a - ld [wd0a0], a + ld [wDisableVBlankWYUpdate], a ret -Func_48119: ; 48119 (12:4119) - ld a, [H_NUMTOPRINT] ; $ff96 (aliases: H_MULTIPLICAND) +.MutateWY ; 48119 (12:4119) + ld a, [$ff96] xor b - ld [H_NUMTOPRINT], a ; $ff96 (aliases: H_MULTIPLICAND) - ld [rWY], a ; $ff4a - ld c, $3 + ld [$ff96], a + ld [rWY], a + ld c, 3 jp DelayFrames -Func_48125: ; 48125 (12:4125) +PredefShakeScreenHorizontally: ; 48125 (12:4125) +; Moves the window right and then back in a sequence of progressively smaller +; numbers of pixels, starting at b. call GetPredefRegisters xor a -.asm_48129 +.loop ld [$ff97], a - call Func_4813f - ld c, $1 + call .MutateWX + ld c, 1 call DelayFrames - call Func_4813f + call .MutateWX dec b ld a, b - jr nz, .asm_48129 - ld a, $7 - ld [rWX], a ; $ff4b + jr nz, .loop + +; restore normal WX + ld a, 7 + ld [rWX], a ret -Func_4813f: ; 4813f (12:413f) +.MutateWX ; 4813f (12:413f) ld a, [$ff97] xor b ld [$ff97], a bit 7, a - jr z, .asm_48149 - xor a -.asm_48149 - add $7 - ld [rWX], a ; $ff4b - ld c, $4 + jr z, .skipZeroing + xor a ; zero a if it's negative +.skipZeroing + add 7 + ld [rWX], a + ld c, 4 jp DelayFrames diff --git a/engine/predefs17.asm b/engine/predefs17.asm index 74977ee8..a674b45a 100755 --- a/engine/predefs17.asm +++ b/engine/predefs17.asm @@ -2,8 +2,8 @@ ; so that the full Pokedex information gets displayed in Oak's lab StarterDex: ; 5c0dc (17:40dc) ld a, %01001011 ; set starter flags - ld [wPokedexOwned], a ; wPokedexOwned + ld [wPokedexOwned], a predef ShowPokedexData xor a ; unset starter flags - ld [wPokedexOwned], a ; wPokedexOwned + ld [wPokedexOwned], a ret diff --git a/engine/predefs7.asm b/engine/predefs7.asm index 9786c097..a2c08171 100755 --- a/engine/predefs7.asm +++ b/engine/predefs7.asm @@ -1,18 +1,18 @@ -Func_1c9c6: ; 1c9c6 (7:49c6) +DisplayElevatorFloorMenu: ; 1c9c6 (7:49c6) ld hl, WhichFloorText call PrintText - ld hl, wStringBuffer2 + 11 + ld hl, wItemList ld a, l - ld [wList], a + ld [wListPointer], a ld a, h - ld [wList + 1], a + ld [wListPointer + 1], a ld a, [wListScrollOffset] push af xor a ld [wCurrentMenuItem], a ld [wListScrollOffset], a - ld [wcf93], a - ld a, $4 + ld [wPrintItemPrices], a + ld a, SPECIALLISTMENU ld [wListMenuID], a call DisplayListMenuID pop bc @@ -21,10 +21,10 @@ Func_1c9c6: ; 1c9c6 (7:49c6) ret c ld hl, wd126 set 7, [hl] - ld hl, wcc5b + ld hl, wElevatorWarpMaps ld a, [wWhichPokemon] add a - ld d, $0 + ld d, 0 ld e, a add hl, de ld a, [hli] @@ -32,15 +32,15 @@ Func_1c9c6: ; 1c9c6 (7:49c6) ld a, [hl] ld c, a ld hl, wWarpEntries - call Func_1ca0d + call .UpdateWarp -Func_1ca0d: ; 1ca0d (7:4a0d) +.UpdateWarp inc hl inc hl ld a, b - ld [hli], a + ld [hli], a ; destination warp ID ld a, c - ld [hli], a + ld [hli], a ; destination map ID ret WhichFloorText: ; 1ca14 (7:4a14) diff --git a/engine/save.asm b/engine/save.asm index 93b70be4..a7b2a7c0 100755 --- a/engine/save.asm +++ b/engine/save.asm @@ -4,11 +4,11 @@ LoadSAV: ; 735e8 (1c:75e8) call ClearScreen call LoadFontTilePatterns call LoadTextBoxTilePatterns - call LoadSAVCheckSum + call LoadSAV0 jr c, .badsum - call LoadSAVCheckSum1 + call LoadSAV1 jr c, .badsum - call LoadSAVCheckSum2 + call LoadSAV2 jr c, .badsum ld a, $2 ; good checksum jr .goodsum @@ -18,103 +18,105 @@ LoadSAV: ; 735e8 (1c:75e8) set 6, [hl] ld hl, FileDataDestroyedText call PrintText - ld c, $64 + ld c, 100 call DelayFrames pop hl res 6, [hl] ld a, $1 ; bad checksum .goodsum - ld [wd088], a ; checksum flag + ld [wSaveFileStatus], a ret FileDataDestroyedText: ; 7361e (1c:761e) TX_FAR _FileDataDestroyedText db "@" -LoadSAVCheckSum: ; 73623 (1c:7623) +LoadSAV0: ; 73623 (1c:7623) ld a, SRAM_ENABLE ld [MBC1SRamEnable], a ld a, $1 ld [MBC1SRamBankingMode], a ld [MBC1SRamBank], a - ld hl, S_SAVEDPLAYERNAME ; hero name located in SRAM - ld bc, $f8b ; but here checks the full SAV + ld hl, sPlayerName ; hero name located in SRAM + ld bc, sMainDataCheckSum - sPlayerName ; but here checks the full SAV call SAVCheckSum ld c, a - ld a, [S_SAVEDMAINDATACHECKSUM] ; SAV's checksum + ld a, [sMainDataCheckSum] ; SAV's checksum cp c - jp z, .Func_73652 - ld hl, S_SAVEDPLAYERNAME - ld bc, $f8b + jp z, .checkSumsMatched + +; If the computed checksum didn't match the saved on, try again. + ld hl, sPlayerName + ld bc, sMainDataCheckSum - sPlayerName call SAVCheckSum ld c, a - ld a, [S_SAVEDMAINDATACHECKSUM] ; SAV's checksum + ld a, [sMainDataCheckSum] ; SAV's checksum cp c jp nz, SAVBadCheckSum -.Func_73652 ; 73652 (1c:7652) - ld hl, S_SAVEDPLAYERNAME - ld de, wPlayerName ; wd158 - ld bc, $b +.checkSumsMatched + ld hl, sPlayerName + ld de, wPlayerName + ld bc, NAME_LENGTH call CopyData - ld hl, S_SAVEDMAINDATA - ld de, wPokedexOwned - ld bc, $789 + ld hl, sMainData + ld de, wMainDataStart + ld bc, wMainDataEnd - wMainDataStart call CopyData ld hl, W_CURMAPTILESET set 7, [hl] - ld hl, S_SAVEDSPRITEDATA - ld de, wSpriteStateData1 - ld bc, $200 + ld hl, sSpriteData + ld de, wSpriteDataStart + ld bc, wSpriteDataEnd - wSpriteDataStart call CopyData - ld a, [S_SAVEDhTilesetType] + ld a, [sTilesetType] ld [hTilesetType], a - ld hl, S_SAVEDCURBOXDATA - ld de, W_NUMINBOX - ld bc, wBoxMonNicksEnd - W_NUMINBOX + ld hl, sCurBoxData + ld de, wBoxDataStart + ld bc, wBoxDataEnd - wBoxDataStart call CopyData and a jp SAVGoodChecksum -LoadSAVCheckSum1: ; 73690 (1c:7690) +LoadSAV1: ; 73690 (1c:7690) ld a, SRAM_ENABLE ld [MBC1SRamEnable], a ld a, $1 ld [MBC1SRamBankingMode], a ld [MBC1SRamBank], a - ld hl, S_SAVEDPLAYERNAME ; hero name located in SRAM - ld bc, $f8b ; but here checks the full SAV + ld hl, sPlayerName ; hero name located in SRAM + ld bc, sMainDataCheckSum - sPlayerName ; but here checks the full SAV call SAVCheckSum ld c, a - ld a, [S_SAVEDMAINDATACHECKSUM] ; SAV's checksum + ld a, [sMainDataCheckSum] ; SAV's checksum cp c jr nz, SAVBadCheckSum - ld hl, S_SAVEDCURBOXDATA - ld de, W_NUMINBOX - ld bc, wBoxMonNicksEnd - W_NUMINBOX + ld hl, sCurBoxData + ld de, wBoxDataStart + ld bc, wBoxDataEnd - wBoxDataStart call CopyData and a jp SAVGoodChecksum -LoadSAVCheckSum2: ; 736bd (1c:76bd) +LoadSAV2: ; 736bd (1c:76bd) ld a, SRAM_ENABLE ld [MBC1SRamEnable], a ld a, $1 ld [MBC1SRamBankingMode], a ld [MBC1SRamBank], a - ld hl, S_SAVEDPLAYERNAME ; hero name located in SRAM - ld bc, $f8b ; but here checks the full SAV + ld hl, sPlayerName ; hero name located in SRAM + ld bc, sMainDataCheckSum - sPlayerName ; but here checks the full SAV call SAVCheckSum ld c, a - ld a, [S_SAVEDMAINDATACHECKSUM] ; SAV's checksum + ld a, [sMainDataCheckSum] ; SAV's checksum cp c jp nz, SAVBadCheckSum - ld hl, S_SAVEDPARTYDATA - ld de, wPartyCount ; wPartyCount - ld bc, wPokedexOwned - wPartyCount + ld hl, sPartyData + ld de, wPartyDataStart + ld bc, wPartyDataEnd - wPartyDataStart call CopyData - ld hl, S_SAVEDMAINDATA - ld de, wPokedexOwned ; wPokedexOwned + ld hl, sMainData + ld de, wPokedexOwned ld bc, wPokedexSeenEnd - wPokedexOwned call CopyData and a @@ -129,18 +131,19 @@ SAVGoodChecksum: ; 736f8 (1c:76f8) ld [MBC1SRamEnable], a ret -Func_73701: ; 0x73701 - call LoadSAVCheckSum - call LoadSAVCheckSum1 - jp LoadSAVCheckSum2 +LoadSAVIgnoreBadCheckSum: ; 73701 (1c:7701) +; unused function that loads save data and ignores bad checksums + call LoadSAV0 + call LoadSAV1 + jp LoadSAV2 -SaveSAV: ;$770a +SaveSAV: ; 7370a (1c:770a) callba PrintSaveScreenText ld hl,WouldYouLikeToSaveText call SaveSAVConfirm and a ;|0 = Yes|1 = No| ret nz - ld a,[wd088] + ld a,[wSaveFileStatus] dec a jr z,.save call SAVCheckRandomID @@ -149,22 +152,22 @@ SaveSAV: ;$770a call SaveSAVConfirm and a ret nz -.save ;$772d - call SaveSAVtoSRAM ;$7848 - hlCoord 1, 13 - ld bc,$0412 - call ClearScreenArea ; clear area 4x12 starting at 13,1 - hlCoord 1, 14 +.save + call SaveSAVtoSRAM + coord hl, 1, 13 + lb bc, 4, 18 + call ClearScreenArea + coord hl, 1, 14 ld de,NowSavingString call PlaceString - ld c,$78 + ld c,120 call DelayFrames ld hl,GameSavedText call PrintText - ld a, (SFX_02_5d - SFX_Headers_02) / 3 ;sound for saved game + ld a, SFX_SAVE call PlaySoundWaitForCurrent call WaitForSoundToFinish - ld c,$1e + ld c,30 jp DelayFrames NowSavingString: @@ -172,8 +175,8 @@ NowSavingString: SaveSAVConfirm: ; 73768 (1c:7768) call PrintText - hlCoord 0, 7 - ld bc,$0801 + coord hl, 0, 7 + lb bc, 8, 1 ld a,TWO_OPTION_MENU ld [wTextBoxID],a call DisplayTextBoxID ; yes/no menu @@ -199,27 +202,27 @@ SaveSAVtoSRAM0: ; 7378c (1c:778c) ld [MBC1SRamBankingMode], a ld [MBC1SRamBank], a ld hl, wPlayerName - ld de, S_SAVEDPLAYERNAME - ld bc, $b + ld de, sPlayerName + ld bc, NAME_LENGTH call CopyData - ld hl, wPokedexOwned - ld de, S_SAVEDMAINDATA - ld bc, W_NUMINBOX - wPokedexOwned + ld hl, wMainDataStart + ld de, sMainData + ld bc, wMainDataEnd - wMainDataStart call CopyData - ld hl, wSpriteStateData1 - ld de, S_SAVEDSPRITEDATA - ld bc, $200 + ld hl, wSpriteDataStart + ld de, sSpriteData + ld bc, wSpriteDataEnd - wSpriteDataStart call CopyData - ld hl, W_NUMINBOX - ld de, S_SAVEDCURBOXDATA - ld bc, wBoxMonNicksEnd - W_NUMINBOX + ld hl, wBoxDataStart + ld de, sCurBoxData + ld bc, wBoxDataEnd - wBoxDataStart call CopyData ld a, [hTilesetType] - ld [S_SAVEDhTilesetType], a - ld hl, S_SAVEDPLAYERNAME - ld bc, $f8b + ld [sTilesetType], a + ld hl, sPlayerName + ld bc, sMainDataCheckSum - sPlayerName call SAVCheckSum - ld [S_SAVEDMAINDATACHECKSUM], a + ld [sMainDataCheckSum], a xor a ld [MBC1SRamBankingMode], a ld [MBC1SRamEnable], a @@ -232,14 +235,14 @@ SaveSAVtoSRAM1: ; 737e2 (1c:77e2) ld a, $1 ld [MBC1SRamBankingMode], a ld [MBC1SRamBank], a - ld hl, W_NUMINBOX - ld de, S_SAVEDCURBOXDATA - ld bc, wBoxMonNicksEnd - W_NUMINBOX + ld hl, wBoxDataStart + ld de, sCurBoxData + ld bc, wBoxDataEnd - wBoxDataStart call CopyData - ld hl, S_SAVEDPLAYERNAME - ld bc, $f8b + ld hl, sPlayerName + ld bc, sMainDataCheckSum - sPlayerName call SAVCheckSum - ld [S_SAVEDMAINDATACHECKSUM], a + ld [sMainDataCheckSum], a xor a ld [MBC1SRamBankingMode], a ld [MBC1SRamEnable], a @@ -251,18 +254,18 @@ SaveSAVtoSRAM2: ; 7380f (1c:780f) ld a, $1 ld [MBC1SRamBankingMode], a ld [MBC1SRamBank], a - ld hl, wPartyCount - ld de, S_SAVEDPARTYDATA - ld bc, wPokedexOwned - wPartyCount + ld hl, wPartyDataStart + ld de, sPartyData + ld bc, wPartyDataEnd - wPartyDataStart call CopyData ld hl, wPokedexOwned ; pokédex only - ld de, S_SAVEDMAINDATA + ld de, sMainData ld bc, wPokedexSeenEnd - wPokedexOwned call CopyData - ld hl, S_SAVEDPLAYERNAME - ld bc, $f8b + ld hl, sPlayerName + ld bc, sMainDataCheckSum - sPlayerName call SAVCheckSum - ld [S_SAVEDMAINDATACHECKSUM], a + ld [sMainDataCheckSum], a xor a ld [MBC1SRamBankingMode], a ld [MBC1SRamEnable], a @@ -270,14 +273,14 @@ SaveSAVtoSRAM2: ; 7380f (1c:780f) SaveSAVtoSRAM: ; 73848 (1c:7848) ld a, $2 - ld [wd088], a + ld [wSaveFileStatus], a call SaveSAVtoSRAM0 call SaveSAVtoSRAM1 jp SaveSAVtoSRAM2 SAVCheckSum: ; 73856 (1c:7856) ;Check Sum (result[1 byte] is complemented) - ld d, $0 + ld d, 0 .loop ld a, [hli] add d @@ -290,35 +293,37 @@ SAVCheckSum: ; 73856 (1c:7856) cpl ret -Func_73863: ; 73863 (1c:7863) - ld hl, $a000 - ld de, S_SAVEDBOXESCHECKSUM2 ; $ba4d - ld b, $6 -.asm_7386b +CalcIndividualBoxCheckSums: ; 73863 (1c:7863) + ld hl, sBox1 ; sBox7 + ld de, sBank2IndividualBoxChecksums ; sBank3IndividualBoxChecksums + ld b, NUM_BOXES / 2 +.loop push bc push de - ld bc, $462 + ld bc, wBoxDataEnd - wBoxDataStart call SAVCheckSum pop de ld [de], a inc de pop bc dec b - jr nz, .asm_7386b + jr nz, .loop ret -Func_7387b: ; 7387b (1c:787b) - ld hl, PointerTable_73895 ; $7895 - ld a, [wd5a0] +GetBoxSRAMLocation: ; 7387b (1c:787b) +; in: a = box num +; out: b = box SRAM bank, hl = pointer to start of box + ld hl, BoxSRAMPointerTable + ld a, [wCurrentBoxNum] and $7f - cp $6 - ld b, $2 - jr c, .asm_7388c + cp NUM_BOXES / 2 + ld b, 2 + jr c, .next inc b - sub $6 -.asm_7388c + sub NUM_BOXES / 2 +.next ld e, a - ld d, $0 + ld d, 0 add hl, de add hl, de ld a, [hli] @@ -326,13 +331,13 @@ Func_7387b: ; 7387b (1c:787b) ld l, a ret -PointerTable_73895: ; 73895 (1c:7895) - dw S_SAVEDBOX1 - dw S_SAVEDBOX2 - dw S_SAVEDBOX3 - dw S_SAVEDBOX4 - dw S_SAVEDBOX5 - dw S_SAVEDBOX6 +BoxSRAMPointerTable: ; 73895 (1c:7895) + dw sBox1 ; sBox7 + dw sBox2 ; sBox8 + dw sBox3 ; sBox9 + dw sBox4 ; sBox10 + dw sBox5 ; sBox11 + dw sBox6 ; sBox12 ChangeBox:: ; 738a1 (1c:78a1) ld hl, WhenYouChangeBoxText @@ -341,29 +346,29 @@ ChangeBox:: ; 738a1 (1c:78a1) ld a, [wCurrentMenuItem] and a ret nz ; return if No was chosen - ld hl, wd5a0 - bit 7, [hl] - call z, Func_73a29 - call Func_7393f + ld hl, wCurrentBoxNum + bit 7, [hl] ; is it the first time player is changing the box? + call z, EmptyAllSRAMBoxes ; if so, empty all boxes in SRAM + call DisplayChangeBoxMenu call UpdateSprites ld hl, hFlags_0xFFF6 set 1, [hl] call HandleMenuInput ld hl, hFlags_0xFFF6 res 1, [hl] - bit 1, a + bit 1, a ; pressed b ret nz - call Func_7387b + call GetBoxSRAMLocation ld e, l ld d, h - ld hl, W_NUMINBOX - call Func_7390e + ld hl, wBoxDataStart + call CopyBoxToOrFromSRAM ; copy old box from WRAM to SRAM ld a, [wCurrentMenuItem] set 7, a - ld [wd5a0], a - call Func_7387b - ld de, W_NUMINBOX - call Func_7390e + ld [wCurrentBoxNum], a + call GetBoxSRAMLocation + ld de, wBoxDataStart + call CopyBoxToOrFromSRAM ; copy new box from SRAM to WRAM ld hl, W_MAPTEXTPTR ld de, wChangeBoxSavedMapTextPointer ld a, [hli] @@ -375,7 +380,7 @@ ChangeBox:: ; 738a1 (1c:78a1) call SaveSAVtoSRAM ld hl, wChangeBoxSavedMapTextPointer call SetMapTextPointer - ld a, (SFX_02_5d - SFX_Headers_02) / 3 + ld a, SFX_SAVE call PlaySoundWaitForCurrent call WaitForSoundToFinish ret @@ -384,7 +389,8 @@ WhenYouChangeBoxText: ; 73909 (1c:7909) TX_FAR _WhenYouChangeBoxText db "@" -Func_7390e: ; 7390e (1c:790e) +CopyBoxToOrFromSRAM: ; 7390e (1c:790e) +; copy an entire box from hl to de with b as the SRAM bank push hl ld a, SRAM_ENABLE ld [MBC1SRamEnable], a @@ -392,92 +398,95 @@ Func_7390e: ; 7390e (1c:790e) ld [MBC1SRamBankingMode], a ld a, b ld [MBC1SRamBank], a - ld bc, $462 + ld bc, wBoxDataEnd - wBoxDataStart call CopyData pop hl + +; mark the memory that the box was copied from as am empty box xor a ld [hli], a dec a ld [hl], a - ld hl, $a000 - ld bc, $1a4c + + ld hl, sBox1 ; sBox7 + ld bc, sBank2AllBoxesChecksum - sBox1 call SAVCheckSum - ld [S_SAVEDBOXESCHECKSUM], a - call Func_73863 + ld [sBank2AllBoxesChecksum], a ; sBank3AllBoxesChecksum + call CalcIndividualBoxCheckSums xor a ld [MBC1SRamBankingMode], a ld [MBC1SRamEnable], a ret -Func_7393f: ; 7393f (1c:793f) +DisplayChangeBoxMenu: ; 7393f (1c:793f) xor a - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba - ld a, $3 - ld [wMenuWatchedKeys], a ; wMenuWatchedKeys - ld a, $b - ld [wMaxMenuItem], a ; wMaxMenuItem - ld a, $1 - ld [wTopMenuItemY], a ; wTopMenuItemY - ld a, $c - ld [wTopMenuItemX], a ; wTopMenuItemX + ld [H_AUTOBGTRANSFERENABLED], a + ld a, A_BUTTON | B_BUTTON + ld [wMenuWatchedKeys], a + ld a, 11 + ld [wMaxMenuItem], a + ld a, 1 + ld [wTopMenuItemY], a + ld a, 12 + ld [wTopMenuItemX], a xor a - ld [wcc37], a - ld a, [wd5a0] + ld [wMenuWatchMovingOutOfBounds], a + ld a, [wCurrentBoxNum] and $7f - ld [wCurrentMenuItem], a ; wCurrentMenuItem - ld [wLastMenuItem], a ; wLastMenuItem - ld hl, wTileMap - ld b, $2 - ld c, $9 + ld [wCurrentMenuItem], a + ld [wLastMenuItem], a + coord hl, 0, 0 + ld b, 2 + ld c, 9 call TextBoxBorder ld hl, ChooseABoxText call PrintText - hlCoord 11, 0 - ld b, $c - ld c, $7 + coord hl, 11, 0 + ld b, 12 + ld c, 7 call TextBoxBorder ld hl, hFlags_0xFFF6 set 2, [hl] - ld de, BoxNames ; $79d9 - hlCoord 13, 1 + ld de, BoxNames + coord hl, 13, 1 call PlaceString ld hl, hFlags_0xFFF6 res 2, [hl] - ld a, [wd5a0] + ld a, [wCurrentBoxNum] and $7f cp 9 - jr c, .asm_739a6 + jr c, .singleDigitBoxNum sub 9 - hlCoord 8, 2 + coord hl, 8, 2 ld [hl], "1" add "0" - jr .asm_739a8 -.asm_739a6 + jr .next +.singleDigitBoxNum add "1" -.asm_739a8 +.next Coorda 9, 2 - hlCoord 1, 2 + coord hl, 1, 2 ld de, BoxNoText call PlaceString - call Func_73a84 - hlCoord 18, 1 - ld de, wWhichTrade ; wWhichTrade - ld bc, $14 + call GetMonCountsForAllBoxes + coord hl, 18, 1 + ld de, wBoxMonCounts + ld bc, SCREEN_WIDTH ld a, $c -.asm_739c2 +.loop push af ld a, [de] - and a - jr z, .asm_739c9 - ld [hl], $78 -.asm_739c9 + and a ; is the box empty? + jr z, .skipPlacingPokeball + ld [hl], $78 ; place pokeball tile next to box name if box not empty +.skipPlacingPokeball add hl, bc inc de pop af dec a - jr nz, .asm_739c2 - ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba + jr nz, .loop + ld a, 1 + ld [H_AUTOBGTRANSFERENABLED], a ret ChooseABoxText: ; 739d4 (1c:79d4) @@ -501,51 +510,54 @@ BoxNames: ; 739d9 (1c:79d9) BoxNoText: ; 73a21 (1c:7a21) db "BOX No.@" -Func_73a29: ; 73a29 (1c:7a29) +EmptyAllSRAMBoxes: ; 73a29 (1c:7a29) +; marks all boxes in SRAM as empty (initialisation for the first time the +; player changes the box) ld a, SRAM_ENABLE ld [MBC1SRamEnable], a ld a, $1 ld [MBC1SRamBankingMode], a - ld a, $2 + ld a, 2 ld [MBC1SRamBank], a - call Func_73a4b - ld a, $3 + call EmptySRAMBoxesInBank + ld a, 3 ld [MBC1SRamBank], a - call Func_73a4b + call EmptySRAMBoxesInBank xor a ld [MBC1SRamBankingMode], a ld [MBC1SRamEnable], a ret -Func_73a4b: ; 73a4b (1c:7a4b) - ld hl, S_SAVEDBOX1 - call Func_73a7f - ld hl, S_SAVEDBOX2 - call Func_73a7f - ld hl, S_SAVEDBOX3 - call Func_73a7f - ld hl, S_SAVEDBOX4 - call Func_73a7f - ld hl, S_SAVEDBOX5 - call Func_73a7f - ld hl, S_SAVEDBOX6 - call Func_73a7f - ld hl, S_SAVEDBOX1 - ld bc, $6 * (S_SAVEDBOX2 - S_SAVEDBOX1) ; $1a4c +EmptySRAMBoxesInBank: ; 73a4b (1c:7a4b) +; marks every box in the current SRAM bank as empty + ld hl, sBox1 ; sBox7 + call EmptySRAMBox + ld hl, sBox2 ; sBox8 + call EmptySRAMBox + ld hl, sBox3 ; sBox9 + call EmptySRAMBox + ld hl, sBox4 ; sBox10 + call EmptySRAMBox + ld hl, sBox5 ; sBox11 + call EmptySRAMBox + ld hl, sBox6 ; sBox12 + call EmptySRAMBox + ld hl, sBox1 ; sBox7 + ld bc, sBank2AllBoxesChecksum - sBox1 call SAVCheckSum - ld [S_SAVEDBOXESCHECKSUM], a - call Func_73863 + ld [sBank2AllBoxesChecksum], a ; sBank3AllBoxesChecksum + call CalcIndividualBoxCheckSums ret -Func_73a7f: ; 73a7f (1c:7a7f) +EmptySRAMBox: ; 73a7f (1c:7a7f) xor a ld [hli], a dec a ld [hl], a ret -Func_73a84: ; 73a84 (1c:7a84) - ld hl, wWhichTrade ; wWhichTrade +GetMonCountsForAllBoxes: ; 73a84 (1c:7a84) + ld hl, wBoxMonCounts push hl ld a, SRAM_ENABLE ld [MBC1SRamEnable], a @@ -553,58 +565,61 @@ Func_73a84: ; 73a84 (1c:7a84) ld [MBC1SRamBankingMode], a ld a, $2 ld [MBC1SRamBank], a - call Func_73ab8 + call GetMonCountsForBoxesInBank ld a, $3 ld [MBC1SRamBank], a - call Func_73ab8 + call GetMonCountsForBoxesInBank xor a ld [MBC1SRamBankingMode], a ld [MBC1SRamEnable], a pop hl - ld a, [wd5a0] + +; copy the count for the current box from WRAM + ld a, [wCurrentBoxNum] and $7f ld c, a - ld b, $0 + ld b, 0 add hl, bc - ld a, [W_NUMINBOX] ; wda80 + ld a, [W_NUMINBOX] ld [hl], a + ret -Func_73ab8: ; 73ab8 (1c:7ab8) - ld a, [S_SAVEDBOX1] +GetMonCountsForBoxesInBank: ; 73ab8 (1c:7ab8) + ld a, [sBox1] ; sBox7 ld [hli], a - ld a, [S_SAVEDBOX2] + ld a, [sBox2] ; sBox8 ld [hli], a - ld a, [S_SAVEDBOX3] + ld a, [sBox3] ; sBox9 ld [hli], a - ld a, [S_SAVEDBOX4] + ld a, [sBox4] ; sBox10 ld [hli], a - ld a, [S_SAVEDBOX5] + ld a, [sBox5] ; sBox11 ld [hli], a - ld a, [S_SAVEDBOX6] + ld a, [sBox6] ; sBox12 ld [hli], a ret -SAVCheckRandomID: ;$7ad1 +SAVCheckRandomID: ; 73ad1 (1c:7ad1) ;checks if Sav file is the same by checking player's name 1st letter ($a598) ; and the two random numbers generated at game beginning -;(which are stored at wPlayerID) +;(which are stored at wPlayerID)s ld a,$0a - ld [$0000],a + ld [MBC1SRamEnable],a ld a,$01 ld [MBC1SRamBankingMode],a ld [MBC1SRamBank],a - ld a,[S_SAVEDPLAYERNAME] + ld a,[sPlayerName] and a jr z,.next - ld hl,S_SAVEDPLAYERNAME - ld bc,$0f8b + ld hl,sPlayerName + ld bc, sMainDataCheckSum - sPlayerName call SAVCheckSum ld c,a - ld a,[S_SAVEDMAINDATACHECKSUM] + ld a,[sMainDataCheckSum] cp c jr nz,.next - ld hl,S_SAVEDMAINDATA + 98 ; player ID + ld hl,sMainData + 98 ; player ID ld a,[hli] ld h,[hl] ld l,a @@ -616,39 +631,39 @@ SAVCheckRandomID: ;$7ad1 .next ld a,$00 ld [MBC1SRamBankingMode],a - ld [$0000],a + ld [MBC1SRamEnable],a ret SaveHallOfFameTeams: ; 73b0d (1c:7b0d) - ld a, [wd5a2] + ld a, [wNumHoFTeams] dec a - cp NUM_HOF_TEAMS + cp HOF_TEAM_CAPACITY jr nc, .asm_73b28 ld hl, sHallOfFame ld bc, HOF_TEAM call AddNTimes ld e, l ld d, h - ld hl, wcc5b + ld hl, wHallOfFame ld bc, HOF_TEAM jr HallOfFame_Copy .asm_73b28 ld hl, sHallOfFame + HOF_TEAM ld de, sHallOfFame - ld bc, HOF_TEAM * (NUM_HOF_TEAMS - 1) + ld bc, HOF_TEAM * (HOF_TEAM_CAPACITY - 1) call HallOfFame_Copy - ld hl, wcc5b - ld de, sHallOfFame + HOF_TEAM * (NUM_HOF_TEAMS - 1) + ld hl, wHallOfFame + ld de, sHallOfFame + HOF_TEAM * (HOF_TEAM_CAPACITY - 1) ld bc, HOF_TEAM jr HallOfFame_Copy LoadHallOfFameTeams: ; 73b3f (1c:7b3f) ld hl, sHallOfFame ld bc, HOF_TEAM - ld a, [wWhichTrade] ; wWhichTrade + ld a, [wHoFTeamIndex] call AddNTimes - ld de, wcc5b + ld de, wHallOfFame ld bc, HOF_TEAM ; fallthrough diff --git a/engine/slot_machine.asm b/engine/slot_machine.asm index fc1a3e11..0b72d7e5 100755 --- a/engine/slot_machine.asm +++ b/engine/slot_machine.asm @@ -10,45 +10,45 @@ PromptUserToPlaySlots: ; 3730e (d:730e) call YesNoChoice ld a, [wCurrentMenuItem] and a - jr nz, .skip + jr nz, .done ; if player chose No dec a ld [wUpdateSpritesEnabled], a - ld hl, wcd4f + ld hl, wSlotMachineRerollCounter xor a ld [hli], a - ld [hl], $2 + ld [hl], SMILE_BUBBLE predef EmotionBubble call GBPalWhiteOutWithDelay3 call LoadSlotMachineTiles call LoadFontTilePatterns - ld b, $5 - call GoPAL_SET + ld b, SET_PAL_SLOTS + call RunPaletteCommand call GBPalNormal ld a, $e4 - ld [$ff48], a + ld [rOBP0], a ld hl, wd730 set 6, [hl] xor a - ld [W_SUBANIMSUBENTRYADDR], a - ld hl, wTrainerSpriteOffset + ld [wSlotMachineAllowMatchesCounter], a + ld hl, wStoppingWhichSlotMachineWheel ld bc, $0014 call FillMemory call MainSlotMachineLoop ld hl, wd730 res 6, [hl] xor a - ld [W_SUBANIMSUBENTRYADDR], a + ld [wSlotMachineAllowMatchesCounter], a call GBPalWhiteOutWithDelay3 ld a, $1 ld [wUpdateSpritesEnabled], a - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand call ReloadMapSpriteTilePatterns call ReloadTilesetTilePatterns -.skip +.done call LoadScreenTilesFromBuffer2 call Delay3 call GBPalNormal - ld a, [wcc5e] + ld a, [wSlotMachineSavedROMBank] push af jp CloseTextDisplay @@ -57,43 +57,43 @@ PlaySlotMachineText: ; 37390 (d:7390) db "@" MainSlotMachineLoop: ; 37395 (d:7395) - call SlotMachine_37754 + call SlotMachine_PrintCreditCoins xor a - ld hl, wcd4a + ld hl, wPayoutCoins ld [hli], a ld [hl], a - call SlotMachine_3775f + call SlotMachine_PrintPayoutCoins ld hl, BetHowManySlotMachineText call PrintText call SaveScreenTilesToBuffer1 .loop - ld a, $3 + ld a, A_BUTTON | B_BUTTON ld [wMenuWatchedKeys], a - ld a, $2 + ld a, 2 ld [wMaxMenuItem], a - ld a, $c + ld a, 12 ld [wTopMenuItemY], a - ld a, $f + ld a, 15 ld [wTopMenuItemX], a xor a ld [wCurrentMenuItem], a ld [wLastMenuItem], a - ld [wcc37], a - ld hl, wTileMap + $ea - ld b, $5 - ld c, $4 + ld [wMenuWatchMovingOutOfBounds], a + coord hl, 14, 11 + ld b, 5 + ld c, 4 call TextBoxBorder - ld hl, wTileMap + $100 + coord hl, 16, 12 ld de, CoinMultiplierSlotMachineText call PlaceString call HandleMenuInput - and $2 + and B_BUTTON jp nz, LoadScreenTilesFromBuffer1 ld a, [wCurrentMenuItem] ld b, a - ld a, $3 + ld a, 3 sub b - ld [wcd50], a + ld [wSlotMachineBet], a ld hl, wPlayerCoins ld c, a ld a, [hli] @@ -107,34 +107,34 @@ MainSlotMachineLoop: ; 37395 (d:7395) jr .loop .skip1 call LoadScreenTilesFromBuffer1 - call SlotMachine_37741 - call SlotMachine_377d5 - call SlotMachine_37480 - ld a, $4 - ld hl, wcd4d + call SlotMachine_SubtractBetFromPlayerCoins + call SlotMachine_LightBalls + call SlotMachine_SetFlags + ld a, 4 + ld hl, wSlotMachineWheel1SlipCounter ld [hli], a ld [hli], a ld [hl], a call WaitForSoundToFinish - ld a, (SFX_1f_66 - SFX_Headers_1f) / 3 + ld a, SFX_SLOTS_NEW_SPIN call PlaySound ld hl, StartSlotMachineText call PrintText - call SlotMachine_374ad - call SlotMachine_37588 + call SlotMachine_SpinWheels + call SlotMachine_CheckForMatches ld hl, wPlayerCoins ld a, [hli] or [hl] jr nz, .skip2 ld hl, OutOfCoinsSlotMachineText call PrintText - ld c, $3c + ld c, 60 jp DelayFrames .skip2 ld hl, OneMoreGoSlotMachineText call PrintText - ld hl, wTileMap + $fe - ld bc, $0d0f + coord hl, 14, 12 + lb bc, 13, 15 xor a ; YES_NO_MENU ld [wTwoOptionMenuID], a ld a, TWO_OPTION_MENU @@ -143,7 +143,7 @@ MainSlotMachineLoop: ; 37395 (d:7395) ld a, [wCurrentMenuItem] and a ret nz - call SlotMachine_377ce + call SlotMachine_PutOutLitBalls jp MainSlotMachineLoop CoinMultiplierSlotMachineText: ; 3745e (d:745e) @@ -171,55 +171,55 @@ OneMoreGoSlotMachineText: ; 3747b (d:747b) TX_FAR _OneMoreGoSlotMachineText db "@" -SlotMachine_37480: ; 37480 (d:7480) - ld hl, wcd4c +SlotMachine_SetFlags: ; 37480 (d:7480) + ld hl, wSlotMachineFlags bit 7, [hl] ret nz - ld a, [W_SUBANIMSUBENTRYADDR] + ld a, [wSlotMachineAllowMatchesCounter] and a - jr nz, .skip1 + jr nz, .allowMatches call Random and a - jr z, .skip2 + jr z, .setAllowMatchesCounter ; 1/256 (~0.4%) chance ld b, a - ld a, [wcc5b] + ld a, [wSlotMachineSevenAndBarModeChance] cp b - jr c, .skip3 - ld a, $d2 + jr c, .allowSevenAndBarMatches + ld a, 210 cp b - jr c, .skip1 - ld [hl], $0 + jr c, .allowMatches ; 55/256 (~21.5%) chance + ld [hl], 0 ret -.skip1 +.allowMatches set 6, [hl] ret -.skip2 - ld a, $3c - ld [W_SUBANIMSUBENTRYADDR], a +.setAllowMatchesCounter + ld a, 60 + ld [wSlotMachineAllowMatchesCounter], a ret -.skip3 +.allowSevenAndBarMatches set 7, [hl] ret -SlotMachine_374ad: ; 374ad (d:74ad) - ld c, $14 +SlotMachine_SpinWheels: ; 374ad (d:74ad) + ld c, 20 .loop1 push bc - call SlotMachine_37813 - call SlotMachine_37823 - call SlotMachine_37833 - ld c, $2 + call SlotMachine_AnimWheel1 + call SlotMachine_AnimWheel2 + call SlotMachine_AnimWheel3 + ld c, 2 call DelayFrames pop bc dec c jr nz, .loop1 xor a - ld [wTrainerSpriteOffset], a + ld [wStoppingWhichSlotMachineWheel], a .loop2 - call SlotMachine_37882 - call SlotMachine_374df - call SlotMachine_374fb - call SlotMachine_37517 + call SlotMachine_HandleInputWhileWheelsSpin + call SlotMachine_StopOrAnimWheel1 + call SlotMachine_StopOrAnimWheel2 + call SlotMachine_StopOrAnimWheel3 ret c ld a, [wOnSGB] xor $1 @@ -228,194 +228,214 @@ SlotMachine_374ad: ; 374ad (d:74ad) call DelayFrames jr .loop2 -SlotMachine_374df: ; 374df (d:74df) - ld a, [wTrainerSpriteOffset] - cp $1 - jr c, .skip - ld de, wTrainerEngageDistance +; Note that the wheels can only stop when a symbol is centred in the wheel +; and thus 3 full symbols rather than 2 full symbols and 2 half symbols are +; visible. The 3 functions below ensure this by checking if the wheel offset +; is even before stopping the wheel. + +SlotMachine_StopOrAnimWheel1: ; 374df (d:74df) + ld a, [wStoppingWhichSlotMachineWheel] + cp 1 + jr c, .animWheel + ld de, wSlotMachineWheel1Offset ld a, [de] rra - jr nc, .skip - ld hl, wcd4d + jr nc, .animWheel ; check that a symbol is centred in the wheel + ld hl, wSlotMachineWheel1SlipCounter ld a, [hl] and a ret z dec [hl] - call SlotMachine_3752c + call SlotMachine_StopWheel1Early ret nz -.skip - jp SlotMachine_37813 - -SlotMachine_374fb: ; 374fb (d:74fb) - ld a, [wTrainerSpriteOffset] - cp $2 - jr c, .skip - ld de, wTrainerFacingDirection +.animWheel + jp SlotMachine_AnimWheel1 + +SlotMachine_StopOrAnimWheel2: ; 374fb (d:74fb) + ld a, [wStoppingWhichSlotMachineWheel] + cp 2 + jr c, .animWheel + ld de, wSlotMachineWheel2Offset ld a, [de] rra - jr nc, .skip - ld hl, wcd4e + jr nc, .animWheel ; check that a symbol is centred in the wheel + ld hl, wSlotMachineWheel2SlipCounter ld a, [hl] and a ret z dec [hl] - call SlotMachine_37552 + call SlotMachine_StopWheel2Early ret z -.skip - jp SlotMachine_37823 - -SlotMachine_37517: ; 37517 (d:7517) - ld a, [wTrainerSpriteOffset] - cp $3 - jr c, .skip - ld de, wTrainerScreenY +.animWheel + jp SlotMachine_AnimWheel2 + +SlotMachine_StopOrAnimWheel3: ; 37517 (d:7517) + ld a, [wStoppingWhichSlotMachineWheel] + cp 3 + jr c, .animWheel + ld de, wSlotMachineWheel3Offset ld a, [de] rra - jr nc, .skip + jr nc, .animWheel ; check that a symbol is centred in the wheel +; wheel 3 stops as soon as possible scf ret -.skip - call SlotMachine_37833 +.animWheel + call SlotMachine_AnimWheel3 and a ret -SlotMachine_3752c: ; 3752c (d:752c) - call SlotMachine_GetWheelOneTile - ld hl, wTrainerScreenX - ld a, [wcd4c] +SlotMachine_StopWheel1Early: ; 3752c (d:752c) + call SlotMachine_GetWheel1Tiles + ld hl, wSlotMachineWheel1BottomTile + ld a, [wSlotMachineFlags] and $80 - jr nz, .skip1 + jr nz, .sevenAndBarMode +; Stop early if the middle symbol is not a cherry. inc hl ld a, [hl] - cp $a - jr nz, .skip2 + cp SLOTSCHERRY >> 8 + jr nz, .stopWheel ret -.skip1 +; It looks like this was intended to make the wheel stop when a 7 symbol was +; visible, but it has a bug and so the wheel stops randomly. +.sevenAndBarMode ld c, $3 .loop ld a, [hli] - cp $2 - jr c, .skip2 + cp SLOTS7 >> 8 + jr c, .stopWheel ; condition never true dec c jr nz, .loop ret -.skip2 +.stopWheel inc a - ld hl, wcd4d - ld [hl], $0 + ld hl, wSlotMachineWheel1SlipCounter + ld [hl], 0 ret -SlotMachine_37552: ; 37552 (d:7552) - call SlotMachine_GetWheelTwoTile - ld a, [wcd4c] +SlotMachine_StopWheel2Early: ; 37552 (d:7552) + call SlotMachine_GetWheel2Tiles + ld a, [wSlotMachineFlags] and $80 - jr nz, .skip1 - call SlotMachine_3756e + jr nz, .sevenAndBarMode +; Stop early if any symbols are lined up in the first two wheels. + call SlotMachine_FindWheel1Wheel2Matches ret nz - jr .skip2 -.skip1 - call SlotMachine_3756e + jr .stopWheel +; Stop early if two 7 symbols or two bar symbols are lined up in the first two +; wheels OR if no symbols are lined up and the bottom symbol in wheel 2 is a +; 7 symbol or bar symbol. The second part could be a bug or a way to reduce the +; player's odds. +.sevenAndBarMode + call SlotMachine_FindWheel1Wheel2Matches ld a, [de] - cp $7 + cp (SLOTSBAR >> 8) + 1 ret nc -.skip2 +.stopWheel xor a - ld [wcd4e], a + ld [wSlotMachineWheel2SlipCounter], a ret -SlotMachine_3756e: ; 3756e (d:756e) - ld hl, wTrainerScreenX - ld de, wcd44 +SlotMachine_FindWheel1Wheel2Matches: ; 3756e (d:756e) +; return whether wheel 1 and wheel 2's current positions allow a match (given +; that wheel 3 stops in a good position) in Z + ld hl, wSlotMachineWheel1BottomTile + ld de, wSlotMachineWheel2BottomTile ld a, [de] - cp [hl] + cp [hl] ; wheel 1 bottom, wheel 2 bottom ret z inc de ld a, [de] - cp [hl] + cp [hl] ; wheel 1 bottom, wheel 2 middle ret z inc hl - cp [hl] + cp [hl] ; wheel 1 middle, wheel 2 middle ret z inc hl - cp [hl] + cp [hl] ; wheel 1 top, wheel 2 middle ret z inc de ld a, [de] - cp [hl] + cp [hl] ; wheel 1 top, wheel 2 top ret z dec de dec de ret -SlotMachine_37588: ; 37588 (d:7588) - call SlotMachine_GetWheelThreeTile - ld a, [wcd50] - cp $2 - jr z, .skip1 - cp $1 - jr z, .skip2 - ld hl, wTrainerScreenX - ld de, wcd45 - ld bc, wcd49 +SlotMachine_CheckForMatches: ; 37588 (d:7588) + call SlotMachine_GetWheel3Tiles + ld a, [wSlotMachineBet] + cp 2 + jr z, .checkMatchesFor2CoinBet + cp 1 + jr z, .checkMatchFor1CoinBet +; 3 coin bet allows diagonal matches (plus the matches for 1/2 coin bets) + ld hl, wSlotMachineWheel1BottomTile + ld de, wSlotMachineWheel2MiddleTile + ld bc, wSlotMachineWheel3TopTile call SlotMachine_CheckForMatch - jp z, .skip5 - ld hl, wcd43 - ld de, wcd45 - ld bc, wcd47 + jp z, .foundMatch + ld hl, wSlotMachineWheel1TopTile + ld de, wSlotMachineWheel2MiddleTile + ld bc, wSlotMachineWheel3BottomTile call SlotMachine_CheckForMatch - jr z, .skip5 -.skip1 - ld hl, wcd43 - ld de, wcd46 - ld bc, wcd49 + jr z, .foundMatch +; 2 coin bet allows top/bottom horizontal matches (plus the match for a 1 coin bet) +.checkMatchesFor2CoinBet + ld hl, wSlotMachineWheel1TopTile + ld de, wSlotMachineWheel2TopTile + ld bc, wSlotMachineWheel3TopTile call SlotMachine_CheckForMatch - jr z, .skip5 - ld hl, wTrainerScreenX - ld de, wcd44 - ld bc, wcd47 + jr z, .foundMatch + ld hl, wSlotMachineWheel1BottomTile + ld de, wSlotMachineWheel2BottomTile + ld bc, wSlotMachineWheel3BottomTile call SlotMachine_CheckForMatch - jr z, .skip5 -.skip2 - ld hl, wcd42 - ld de, wcd45 - ld bc, wcd48 + jr z, .foundMatch +; 1 coin bet only allows a middle horizontal match +.checkMatchFor1CoinBet + ld hl, wSlotMachineWheel1MiddleTile + ld de, wSlotMachineWheel2MiddleTile + ld bc, wSlotMachineWheel3MiddleTile call SlotMachine_CheckForMatch - jr z, .skip5 - ld a, [wcd4c] + jr z, .foundMatch + ld a, [wSlotMachineFlags] and $c0 - jr z, .skip3 - ld hl, wcd4f + jr z, .noMatch + ld hl, wSlotMachineRerollCounter dec [hl] - jr nz, .skip4 -.skip3 + jr nz, .rollWheel3DownByOneSymbol +.noMatch ld hl, NotThisTimeText call PrintText -.loop +.done xor a - ld [wc002], a + ld [wMuteAudioAndPauseMusic], a ret -.skip4 - call SlotMachine_37833 +.rollWheel3DownByOneSymbol + call SlotMachine_AnimWheel3 call DelayFrame - call SlotMachine_37833 + call SlotMachine_AnimWheel3 call DelayFrame - jp SlotMachine_37588 -.skip5 - ld a, [wcd4c] + jp SlotMachine_CheckForMatches +.foundMatch + ld a, [wSlotMachineFlags] and $c0 - jr z, .skip4 + jr z, .rollWheel3DownByOneSymbol ; roll wheel if player isn't allowed to win and $80 - jr nz, .skip6 + jr nz, .acceptMatch +; if 7/bar matches aren't enabled and the match was a 7/bar symbol, roll wheel ld a, [hl] - cp $7 - jr c, .skip4 -.skip6 + cp (SLOTSBAR >> 8) + 1 + jr c, .rollWheel3DownByOneSymbol +.acceptMatch ld a, [hl] sub $2 - ld [wTrainerScreenX], a + ld [wSlotMachineWinningSymbol], a ld hl, SlotRewardPointers ld c, a - ld b, $0 + ld b, 0 add hl, bc ld a, [hli] ld e, a @@ -426,39 +446,39 @@ SlotMachine_37588: ; 37588 (d:7588) ld h, [hl] ld l, a ld de, wcf4b - ld bc, $0004 + ld bc, 4 call CopyData pop hl - ld de, .asm_37638 + ld de, .flashScreenLoop push de jp [hl] -.asm_37638 - ld a, [$ff47] +.flashScreenLoop + ld a, [rBGP] xor $40 - ld [$ff47], a - ld c, $5 + ld [rBGP], a + ld c, 5 call DelayFrames dec b - jr nz, .asm_37638 - ld hl, wcd4a + jr nz, .flashScreenLoop + ld hl, wPayoutCoins ld [hl], d inc hl ld [hl], e - call SlotMachine_3775f - ld hl, SlotsMachineText_37665 + call SlotMachine_PrintPayoutCoins + ld hl, SymbolLinedUpSlotMachineText call PrintText call WaitForTextScrollButtonPress - call SlotMachine_3776b - call SlotMachine_3775f + call SlotMachine_PayCoinsToPlayer + call SlotMachine_PrintPayoutCoins ld a, $e4 - ld [$ff48], a - jp .loop + ld [rOBP0], a + jp .done -SlotsMachineText_37665: ; 37665 (d:7665) - db $08 ; asm +SymbolLinedUpSlotMachineText: ; 37665 (d:7665) + TX_ASM push bc - call SlotMachine_37728 + call SlotMachine_PrintWinningSymbol ld hl, LinedUpText pop bc inc bc @@ -510,28 +530,28 @@ SlotMachine_CheckForMatch: ; 376a2 (d:76a2) cp [hl] ret -SlotMachine_GetWheelThreeTile: ; 376a8 (d:76a8) - ld de, wcd47 +SlotMachine_GetWheel3Tiles: ; 376a8 (d:76a8) + ld de, wSlotMachineWheel3BottomTile ld hl, SlotMachineWheel3 - ld a, [wTrainerScreenY] - call SlotMachine_GetWheelTile + ld a, [wSlotMachineWheel3Offset] + call SlotMachine_GetWheelTiles -SlotMachine_GetWheelTwoTile: ; 376b4 (d:76b4) - ld de, wcd44 +SlotMachine_GetWheel2Tiles: ; 376b4 (d:76b4) + ld de, wSlotMachineWheel2BottomTile ld hl, SlotMachineWheel2 - ld a, [wTrainerFacingDirection] - call SlotMachine_GetWheelTile + ld a, [wSlotMachineWheel2Offset] + call SlotMachine_GetWheelTiles -SlotMachine_GetWheelOneTile: ; 376c0 (d:76c0) - ld de, wTrainerScreenX +SlotMachine_GetWheel1Tiles: ; 376c0 (d:76c0) + ld de, wSlotMachineWheel1BottomTile ld hl, SlotMachineWheel1 - ld a, [wTrainerEngageDistance] + ld a, [wSlotMachineWheel1Offset] -SlotMachine_GetWheelTile: ; 376c9 (d:76c9) +SlotMachine_GetWheelTiles: ; 376c9 (d:76c9) ld c, a - ld b, $0 + ld b, 0 add hl, bc - ld c, $3 + ld c, 3 .loop ld a, [hli] ld [de], a @@ -542,7 +562,7 @@ SlotMachine_GetWheelTile: ; 376c9 (d:76c9) ret SlotReward8Func: ; 376d7 (d:76d7) - ld hl, W_SUBANIMSUBENTRYADDR + ld hl, wSlotMachineAllowMatchesCounter ld a, [hl] and a jr z, .skip @@ -553,7 +573,7 @@ SlotReward8Func: ; 376d7 (d:76d7) ret SlotReward15Func: ; 376e5 (d:76e5) - ld hl, W_SUBANIMSUBENTRYADDR + ld hl, wSlotMachineAllowMatchesCounter ld a, [hl] and a jr z, .skip @@ -564,10 +584,10 @@ SlotReward15Func: ; 376e5 (d:76e5) ret SlotReward100Func: ; 376f3 (d:76f3) - ld a, (SFX_1f_42 - SFX_Headers_1f) / 3 + ld a, SFX_GET_KEY_ITEM call PlaySound xor a - ld [wcd4c], a + ld [wSlotMachineFlags], a ld b, $8 ld de, 100 ret @@ -575,15 +595,15 @@ SlotReward100Func: ; 376f3 (d:76f3) SlotReward300Func: ; 37702 (d:7702) ld hl, YeahText call PrintText - ld a, (SFX_1f_3b - SFX_Headers_1f) / 3 + ld a, SFX_GET_ITEM_2 call PlaySound call Random cp $80 ld a, $0 jr c, .skip - ld [wcd4c], a + ld [wSlotMachineFlags], a .skip - ld [W_SUBANIMSUBENTRYADDR], a + ld [wSlotMachineAllowMatchesCounter], a ld b, $14 ld de, 300 ret @@ -592,26 +612,27 @@ YeahText: ; 37722 (d:7722) TX_FAR _YeahText db $0a, "@" -SlotMachine_37728: ; 37728 (d:7728) - ld hl, wTileMap + $11a - ld a, [wTrainerScreenX] +SlotMachine_PrintWinningSymbol: ; 37728 (d:7728) +; prints winning symbol and down arrow in text box + coord hl, 2, 14 + ld a, [wSlotMachineWinningSymbol] add $25 ld [hli], a inc a ld [hld], a inc a - ld de, $ffec + ld de, -SCREEN_WIDTH add hl, de ld [hli], a inc a ld [hl], a - ld hl, wTileMap + $152 - ld [hl], $ee + coord hl, 18, 16 + ld [hl], $ee ; down arrow ret -SlotMachine_37741: ; 37741 (d:7741) - ld hl, wcd4b - ld a, [wcd50] +SlotMachine_SubtractBetFromPlayerCoins: ; 37741 (d:7741) + ld hl, wTempCoins2 + 1 + ld a, [wSlotMachineBet] ld [hld], a xor a ld [hli], a @@ -619,136 +640,143 @@ SlotMachine_37741: ; 37741 (d:7741) ld c, $2 predef SubBCDPredef -SlotMachine_37754: ; 37754 (d:7754) - ld hl, wTileMap + $19 +SlotMachine_PrintCreditCoins: ; 37754 (d:7754) + coord hl, 5, 1 ld de, wPlayerCoins ld c, $2 jp PrintBCDNumber -SlotMachine_3775f: ; 3775f (d:775f) - ld hl, wTileMap + $1f - ld de, wcd4a - ld bc, $8204 +SlotMachine_PrintPayoutCoins: ; 3775f (d:775f) + coord hl, 11, 1 + ld de, wPayoutCoins + lb bc, LEADING_ZEROES | 2, 4 ; 2 bytes, 4 digits jp PrintNumber -SlotMachine_3776b: ; 3776b (d:776b) +SlotMachine_PayCoinsToPlayer: ; 3776b (d:776b) ld a, $1 - ld [wc002], a + ld [wMuteAudioAndPauseMusic], a call WaitForSoundToFinish - ld hl, wcd46 + +; Put 1 in the temp coins variable. This value is added to the player's coins +; repeatedly so the player can watch the value go up 1 coin at a time. + ld hl, wTempCoins1 xor a ld [hli], a inc a ld [hl], a - ld a, $5 - ld [W_SUBANIMTRANSFORM], a + + ld a, 5 + ld [wAnimCounter], a + +; Subtract 1 from the payout amount and add 1 to the player's coins each +; iteration until the payout amount reaches 0. .loop - ld a, [wcd4b] + ld a, [wPayoutCoins + 1] ld l, a - ld a, [wcd4a] + ld a, [wPayoutCoins] ld h, a or l ret z - ld de, $ffff + ld de, -1 add hl, de ld a, l - ld [wcd4b], a + ld [wPayoutCoins + 1], a ld a, h - ld [wcd4a], a - ld hl, wcd47 + ld [wPayoutCoins], a + ld hl, wTempCoins1 + 1 ld de, wPlayerCoins + 1 ld c, $2 predef AddBCDPredef - call SlotMachine_37754 - call SlotMachine_3775f - ld a, (SFX_1f_65 - SFX_Headers_1f) / 3 + call SlotMachine_PrintCreditCoins + call SlotMachine_PrintPayoutCoins + ld a, SFX_SLOTS_REWARD call PlaySound - ld a, [W_SUBANIMTRANSFORM] + ld a, [wAnimCounter] dec a jr nz, .skip1 - ld a, [$ff48] - xor $40 - ld [$ff48], a - ld a, $5 + ld a, [rOBP0] + xor $40 ; make the slot wheel symbols flash + ld [rOBP0], a + ld a, 5 .skip1 - ld [W_SUBANIMTRANSFORM], a - ld a, [wTrainerScreenX] - cp $7 - ld c, $8 + ld [wAnimCounter], a + ld a, [wSlotMachineWinningSymbol] + cp (SLOTSBAR >> 8) + 1 + ld c, 8 jr nc, .skip2 - srl c + srl c ; c = 4 (make the the coins transfer faster if the symbol was 7 or bar) .skip2 call DelayFrames jr .loop -SlotMachine_377ce: ; 377ce (d:77ce) +SlotMachine_PutOutLitBalls: ; 377ce (d:77ce) ld a, $23 - ld [wd08a], a - jr SlotMachine_377e3 + ld [wNewSlotMachineBallTile], a + jr SlotMachine_UpdateThreeCoinBallTiles -SlotMachine_377d5: ; 377d5 (d:77d5) +SlotMachine_LightBalls: ; 377d5 (d:77d5) ld a, $14 - ld [wd08a], a - ld a, [wcd50] + ld [wNewSlotMachineBallTile], a + ld a, [wSlotMachineBet] dec a - jr z, SlotMachine_377fb + jr z, SlotMachine_UpdateOneCoinBallTiles dec a - jr z, SlotMachine_377ef + jr z, SlotMachine_UpdateTwoCoinBallTiles -SlotMachine_377e3: ; 377e3 (d:77e3) - ld hl, wTileMap + $2b - call SlotMachine_377fe - ld hl, wTileMap + $cb - call SlotMachine_377fe +SlotMachine_UpdateThreeCoinBallTiles: ; 377e3 (d:77e3) + coord hl, 3, 2 + call SlotMachine_UpdateBallTiles + coord hl, 3, 10 + call SlotMachine_UpdateBallTiles -SlotMachine_377ef: ; 377ef (d:77ef) - ld hl, wTileMap + $53 - call SlotMachine_377fe - ld hl, wTileMap + $a3 - call SlotMachine_377fe +SlotMachine_UpdateTwoCoinBallTiles: ; 377ef (d:77ef) + coord hl, 3, 4 + call SlotMachine_UpdateBallTiles + coord hl, 3, 8 + call SlotMachine_UpdateBallTiles -SlotMachine_377fb: ; 377fb (d:77fb) - ld hl, wTileMap + $7b +SlotMachine_UpdateOneCoinBallTiles: ; 377fb (d:77fb) + coord hl, 3, 6 -SlotMachine_377fe: ; 377fe (d:77fe) - ld a, [wd08a] +SlotMachine_UpdateBallTiles: ; 377fe (d:77fe) + ld a, [wNewSlotMachineBallTile] ld [hl], a - ld bc, $000d + ld bc, 13 add hl, bc ld [hl], a - ld bc, $0007 + ld bc, 7 add hl, bc inc a ld [hl], a - ld bc, $000d + ld bc, 13 add hl, bc ld [hl], a ret -SlotMachine_37813: ; 37813 (d:7813) +SlotMachine_AnimWheel1: ; 37813 (d:7813) ld bc, SlotMachineWheel1 - ld de, wTrainerEngageDistance + ld de, wSlotMachineWheel1Offset ld hl, wOAMBuffer ld a, $30 ld [W_BASECOORDX], a - jr SlotMachine_37841 + jr SlotMachine_AnimWheel -SlotMachine_37823: ; 37823 (d:7823) +SlotMachine_AnimWheel2: ; 37823 (d:7823) ld bc, SlotMachineWheel2 - ld de, wTrainerFacingDirection + ld de, wSlotMachineWheel2Offset ld hl, wOAMBuffer + $30 ld a, $50 ld [W_BASECOORDX], a - jr SlotMachine_37841 + jr SlotMachine_AnimWheel -SlotMachine_37833: ; 37833 (d:7833) +SlotMachine_AnimWheel3: ; 37833 (d:7833) ld bc, SlotMachineWheel3 - ld de, wTrainerScreenY + ld de, wSlotMachineWheel3Offset ld hl, wOAMBuffer + $60 ld a, $70 ld [W_BASECOORDX], a -SlotMachine_37841: ; 37841 (d:7841) +SlotMachine_AnimWheel: ; 37841 (d:7841) ld a, $58 ld [W_BASECOORDY], a push de @@ -756,10 +784,9 @@ SlotMachine_37841: ; 37841 (d:7841) ld d, b add c ld e, a - jr nc, SlotMachine_3784e + jr nc, .loop inc d - -SlotMachine_3784e: ; 3784e (d:784e) +.loop ld a, [W_BASECOORDY] ld [hli], a ld a, [W_BASECOORDX] @@ -783,34 +810,34 @@ SlotMachine_3784e: ; 3784e (d:784e) sub $8 ld [W_BASECOORDY], a cp $28 - jr nz, SlotMachine_3784e + jr nz, .loop pop de ld a, [de] - inc a - cp $1e + inc a ; advance the offset so that the wheel animates + cp 30 jr nz, .skip - xor a + xor a ; wrap around to 0 when the offset reaches 30 .skip ld [de], a ret -SlotMachine_37882: ; 37882 (d:7882) +SlotMachine_HandleInputWhileWheelsSpin: ; 37882 (d:7882) call DelayFrame call JoypadLowSensitivity ld a, [hJoy5] - and $1 + and A_BUTTON ret z - ld hl, wTrainerSpriteOffset + ld hl, wStoppingWhichSlotMachineWheel ld a, [hl] dec a - ld de, wcd4d + ld de, wSlotMachineWheel1SlipCounter jr z, .skip dec a - ld de, wcd4e + ld de, wSlotMachineWheel2SlipCounter jr z, .skip .loop inc [hl] - ld a, (SFX_1f_64 - SFX_Headers_1f) / 3 + ld a, SFX_SLOTS_STOP_WHEEL jp PlaySound .skip ld a, [de] @@ -836,29 +863,22 @@ LoadSlotMachineTiles: ; 378a8 (d:78a8) ld a, BANK(SlotMachineTiles2) call FarCopyData2 ld hl, SlotMachineMap - ld de, wTileMap + coord de, 0, 0 ld bc, $00f0 call CopyData call EnableLCD - ld hl, wTrainerEngageDistance + ld hl, wSlotMachineWheel1Offset ld a, $1c ld [hli], a ld [hli], a ld [hl], a - call SlotMachine_37813 - call SlotMachine_37823 - jp SlotMachine_37833 + call SlotMachine_AnimWheel1 + call SlotMachine_AnimWheel2 + jp SlotMachine_AnimWheel3 SlotMachineMap: ; 378f5 (d:78f5) INCBIN "gfx/tilemaps/slotmachine.map" -SLOTS7 EQU $0200 -SLOTSBAR EQU $0604 -SLOTSCHERRY EQU $0A08 -SLOTSFISH EQU $0E0C -SLOTSBIRD EQU $1210 -SLOTSMOUSE EQU $1614 - INCLUDE "data/slot_machine_wheels.asm" SlotMachineTiles1: ; 37a51 (d:7a51) diff --git a/engine/titlescreen.asm b/engine/titlescreen.asm index 8f2fcfe7..8d605c49 100755 --- a/engine/titlescreen.asm +++ b/engine/titlescreen.asm @@ -1,30 +1,30 @@ -; copy text of fixed length $b (like player name, rival name, mon names, ...) +; copy text of fixed length NAME_LENGTH (like player name, rival name, mon names, ...) CopyFixedLengthText: ; 42b1 (1:42b1) - ld bc, $b + ld bc, NAME_LENGTH jp CopyData SetDefaultNamesBeforeTitlescreen: ; 42b7 (1:42b7) ld hl, NintenText - ld de, wPlayerName ; wd158 + ld de, wPlayerName call CopyFixedLengthText ld hl, SonyText - ld de, W_RIVALNAME ; wd34a + ld de, W_RIVALNAME call CopyFixedLengthText xor a ld [hWY], a - ld [wd358], a + ld [wLetterPrintingDelayFlags], a ld hl, wd732 ld [hli], a ld [hli], a ld [hl], a ld a, BANK(Music_TitleScreen) - ld [wc0ef], a - ld [wc0f0], a + ld [wAudioROMBank], a + ld [wAudioSavedROMBank], a -LoadTitlescreenGraphics: ; 42dd (1:42dd) +DisplayTitleScreen: ; 42dd (1:42dd) call GBPalWhiteOut ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba + ld [H_AUTOBGTRANSFERENABLED], a xor a ld [hTilesetType], a ld [hSCX], a @@ -35,112 +35,123 @@ LoadTitlescreenGraphics: ; 42dd (1:42dd) call ClearScreen call DisableLCD call LoadFontTilePatterns - ld hl, NintendoCopyrightLogoGraphics ; $60c8 + ld hl, NintendoCopyrightLogoGraphics ld de, vTitleLogo2 + $100 ld bc, $50 ld a, BANK(NintendoCopyrightLogoGraphics) call FarCopyData2 - ld hl, GamefreakLogoGraphics ; $61f8 + ld hl, GamefreakLogoGraphics ld de, vTitleLogo2 + $100 + $50 ld bc, $90 ld a, BANK(GamefreakLogoGraphics) call FarCopyData2 - ld hl, PokemonLogoGraphics ; $5380 + ld hl, PokemonLogoGraphics ld de, vTitleLogo ld bc, $600 ld a, BANK(PokemonLogoGraphics) call FarCopyData2 ; first chunk - ld hl, PokemonLogoGraphics+$600 ; $5980 + ld hl, PokemonLogoGraphics+$600 ld de, vTitleLogo2 ld bc, $100 ld a, BANK(PokemonLogoGraphics) call FarCopyData2 ; second chunk ld hl, Version_GFX ; $402f ld de,vChars2 + $600 - ld bc,$50 - + ld bc, Version_GFXEnd - Version_GFX ld a, BANK(Version_GFX) call FarCopyDataDouble - call Func_4519 - hlCoord 2, 1 + call ClearBothBGMaps + +; place tiles for pokemon logo (except for the last row) + coord hl, 2, 1 ld a, $80 - ld de, $14 - ld c, $6 -.asm_434d + ld de, SCREEN_WIDTH + ld c, 6 +.pokemonLogoTileLoop ld b, $10 push hl -.asm_4350 +.pokemonLogoTileRowLoop ; place tiles for one row ld [hli], a inc a dec b - jr nz, .asm_4350 + jr nz, .pokemonLogoTileRowLoop pop hl add hl, de dec c - jr nz, .asm_434d - hlCoord 2, 7 + jr nz, .pokemonLogoTileLoop + +; place tiles for the last row of the pokemon logo + coord hl, 2, 7 ld a, $31 ld b, $10 -.asm_4361 +.pokemonLogoLastTileRowLoop ld [hli], a inc a dec b - jr nz, .asm_4361 - call Func_44dd + jr nz, .pokemonLogoLastTileRowLoop + + call DrawPlayerCharacter + +; put a pokeball in the player's hand ld hl, wOAMBuffer + $28 ld a, $74 ld [hl], a - hlCoord 2, 17 - ld de, .titlescreenTilemap ; $437f + +; place tiles for title screen copyright + coord hl, 2, 17 + ld de, .tileScreenCopyrightTiles ld b, $10 -.asm_4377 +.tileScreenCopyrightTilesLoop ld a, [de] ld [hli], a inc de dec b - jr nz, .asm_4377 - jr .asm_438f + jr nz, .tileScreenCopyrightTilesLoop + + jr .next -.titlescreenTilemap ; 437f (1:437f) +.tileScreenCopyrightTiles ; 437f (1:437f) db $41,$42,$43,$42,$44,$42,$45,$46,$47,$48,$49,$4A,$4B,$4C,$4D,$4E ; ©'95.'96.'98 GAME FREAK inc. -.asm_438f +.next call SaveScreenTilesToBuffer2 call LoadScreenTilesFromBuffer2 call EnableLCD ld a,CHARMANDER ; which Pokemon to show first on the title screen - ld [wWhichTrade], a ; wWhichTrade - call Func_4524 - ld a, $9b - call Func_4533 + ld [wTitleMonSpecies], a + call LoadTitleMonSprite + ld a, (vBGMap0 + $300) / $100 + call TitleScreenCopyTileMapToVRAM call SaveScreenTilesToBuffer1 ld a, $40 ld [hWY], a call LoadScreenTilesFromBuffer2 - ld a, $98 - call Func_4533 - ld b, $6 - call GoPAL_SET + ld a, vBGMap0 / $100 + call TitleScreenCopyTileMapToVRAM + ld b, SET_PAL_TITLE_SCREEN + call RunPaletteCommand call GBPalNormal - ld a, $e4 - ld [rOBP0], a ; $ff48 - ld bc, $ffaf ; background scroll Y - ld hl, .TitleScreenPokemonLogoYScrolls ; $43db -.asm_43c6 + ld a, %11100100 + ld [rOBP0], a + +; make pokemon logo bounce up and down + ld bc, hSCY ; background scroll Y + ld hl, .TitleScreenPokemonLogoYScrolls +.bouncePokemonLogoLoop ld a, [hli] and a - jr z, .asm_43f4 + jr z, .finishedBouncingPokemonLogo ld d, a - cp $fd - jr nz, .asm_43d4 - ld a, (SFX_1f_62 - SFX_Headers_1f) / 3 + cp -3 + jr nz, .skipPlayingSound + ld a, SFX_INTRO_CRASH call PlaySound -.asm_43d4 +.skipPlayingSound ld a, [hli] ld e, a call .ScrollTitleScreenPokemonLogo - jr .asm_43c6 + jr .bouncePokemonLogoLoop .TitleScreenPokemonLogoYScrolls: ; 43db (1:43db) ; Controls the bouncing effect of the Pokemon logo on the title screen @@ -157,58 +168,65 @@ LoadTitlescreenGraphics: ; 42dd (1:42dd) ; Scrolls the Pokemon logo on the title screen to create the bouncing effect ; Scrolls d pixels e times call DelayFrame - ld a, [bc] + ld a, [bc] ; background scroll Y add d ld [bc], a dec e jr nz, .ScrollTitleScreenPokemonLogo ret -.asm_43f4 + +.finishedBouncingPokemonLogo call LoadScreenTilesFromBuffer1 - ld c, $24 + ld c, 36 call DelayFrames - ld a, (SFX_1f_63 - SFX_Headers_1f) / 3 + ld a, SFX_INTRO_WHOOSH call PlaySound + +; scroll game version in from the right call PrintGameVersionOnTitleScreen - ld a, $90 + ld a, SCREEN_HEIGHT_PIXELS ld [hWY], a - ld d, $90 -.asm_440a + ld d, 144 +.scrollTitleScreenGameVersionLoop ld h, d - ld l, $40 - call Func_44cf - ld h, $0 - ld l, $50 - call Func_44cf + ld l, 64 + call ScrollTitleScreenGameVersion + ld h, 0 + ld l, 80 + call ScrollTitleScreenGameVersion ld a, d - add $4 + add 4 ld d, a and a - jr nz, .asm_440a - ld a, $9c - call Func_4533 + jr nz, .scrollTitleScreenGameVersionLoop + + ld a, vBGMap1 / $100 + call TitleScreenCopyTileMapToVRAM call LoadScreenTilesFromBuffer2 call PrintGameVersionOnTitleScreen call Delay3 call WaitForSoundToFinish ld a, MUSIC_TITLE_SCREEN - ld [wc0ee], a + ld [wNewSoundID], a call PlaySound xor a - ld [wcc5b], a -.asm_443b - ld c, $c8 + ld [wUnusedCC5B], a + +; Keep scrolling in new mons indefinitely until the user performs input. +.awaitUserInterruptionLoop + ld c, 200 call CheckForUserInterruption - jr c, .asm_4459 - call Func_44c1 - ld c, $1 + jr c, .finishedWaiting + call TitleScreenScrollInMon + ld c, 1 call CheckForUserInterruption - jr c, .asm_4459 - callba Func_372ac - call Func_4496 - jr .asm_443b -.asm_4459 - ld a, [wWhichTrade] ; wWhichTrade + jr c, .finishedWaiting + callba TitleScreenAnimateBallIfStarterOut + call TitleScreenPickNewMon + jr .awaitUserInterruptionLoop + +.finishedWaiting + ld a, [wTitleMonSpecies] call PlayCry call WaitForSoundToFinish call GBPalWhiteOutWithDelay3 @@ -216,12 +234,12 @@ LoadTitlescreenGraphics: ; 42dd (1:42dd) xor a ld [hWY], a inc a - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba + ld [H_AUTOBGTRANSFERENABLED], a call ClearScreen - ld a, $98 - call Func_4533 - ld a, $9c - call Func_4533 + ld a, vBGMap0 / $100 + call TitleScreenCopyTileMapToVRAM + ld a, vBGMap1 / $100 + call TitleScreenCopyTileMapToVRAM call Delay3 call LoadGBPal ld a, [hJoyHeld] @@ -232,16 +250,14 @@ LoadTitlescreenGraphics: ; 42dd (1:42dd) jp MainMenu .doClearSaveDialogue - ld b, BANK(DoClearSaveDialogue) - ld hl, DoClearSaveDialogue - jp Bankswitch + jpba DoClearSaveDialogue -Func_4496: ; 4496 (1:4496) - ld a, $98 - call Func_4533 +TitleScreenPickNewMon: ; 4496 (1:4496) + ld a, vBGMap0 / $100 + call TitleScreenCopyTileMapToVRAM -.new -; Generate a new TitleMon. +.loop +; Keep looping until a mon different from the current one is picked. call Random and $f ld c, a @@ -249,14 +265,14 @@ Func_4496: ; 4496 (1:4496) ld hl, TitleMons add hl, bc ld a, [hl] - ld hl, wWhichTrade ; wWhichTrade + ld hl, wTitleMonSpecies ; Can't be the same as before. cp [hl] - jr z, .new + jr z, .loop ld [hl], a - call Func_4524 + call LoadTitleMonSprite ld a, $90 ld [hWY], a @@ -264,80 +280,80 @@ Func_4496: ; 4496 (1:4496) callba TitleScroll ret -Func_44c1: ; 44c1 (1:44c1) +TitleScreenScrollInMon: ; 44c1 (1:44c1) ld d, 0 ; scroll in callba TitleScroll xor a ld [hWY], a ret -Func_44cf: ; 44cf (1:44cf) +ScrollTitleScreenGameVersion: ; 44cf (1:44cf) .wait - ld a, [$ff44] ; rLY + ld a, [rLY] cp l jr nz, .wait ld a, h - ld [rSCX], a ; $ff43 + ld [rSCX], a .wait2 - ld a, [$ff44] ; rLY + ld a, [rLY] cp h jr z, .wait2 ret -Func_44dd: ; 44dd (1:44dd) - ld hl, PlayerCharacterTitleGraphics ; $66a8 +DrawPlayerCharacter: ; 44dd (1:44dd) + ld hl, PlayerCharacterTitleGraphics ld de, vSprites - ld bc, $230 + ld bc, PlayerCharacterTitleGraphicsEnd - PlayerCharacterTitleGraphics ld a, BANK(PlayerCharacterTitleGraphics) call FarCopyData2 call ClearSprites xor a - ld [wWhichTrade], a ; wWhichTrade + ld [wPlayerCharacterOAMTile], a ld hl, wOAMBuffer ld de, $605a - ld b, $7 -.asm_44fa + ld b, 7 +.loop push de - ld c, $5 -.asm_44fd + ld c, 5 +.innerLoop ld a, d - ld [hli], a + ld [hli], a ; Y ld a, e - ld [hli], a - add $8 + ld [hli], a ; X + add 8 ld e, a - ld a, [wWhichTrade] ; wWhichTrade - ld [hli], a + ld a, [wPlayerCharacterOAMTile] + ld [hli], a ; tile inc a - ld [wWhichTrade], a ; wWhichTrade + ld [wPlayerCharacterOAMTile], a inc hl dec c - jr nz, .asm_44fd + jr nz, .innerLoop pop de - ld a, $8 + ld a, 8 add d ld d, a dec b - jr nz, .asm_44fa + jr nz, .loop ret -Func_4519: ; 4519 (1:4519) +ClearBothBGMaps: ; 4519 (1:4519) ld hl, vBGMap0 - ld bc, $800 - ld a, $7f + ld bc, $400 * 2 + ld a, " " jp FillMemory -Func_4524: ; 4524 (1:4524) +LoadTitleMonSprite: ; 4524 (1:4524) ld [wcf91], a ld [wd0b5], a - hlCoord 5, 10 + coord hl, 5, 10 call GetMonHeader jp LoadFrontSpriteByMonIndex -Func_4533: ; 4533 (1:4533) - ld [$ffbd], a +TitleScreenCopyTileMapToVRAM: ; 4533 (1:4533) + ld [H_AUTOBGTRANSFERDEST + 1], a jp Delay3 LoadCopyrightAndTextBoxTiles: ; 4538 (1:4538) @@ -347,12 +363,12 @@ LoadCopyrightAndTextBoxTiles: ; 4538 (1:4538) call LoadTextBoxTilePatterns LoadCopyrightTiles: ; 4541 (1:4541) - ld de, NintendoCopyrightLogoGraphics ; $60c8 + ld de, NintendoCopyrightLogoGraphics ld hl, vChars2 + $600 - ld bc, (BANK(NintendoCopyrightLogoGraphics) << 8) + $1c + lb bc, BANK(NintendoCopyrightLogoGraphics), (GamefreakLogoGraphicsEnd - NintendoCopyrightLogoGraphics) / $10 call CopyVideoData - hlCoord 2, 7 - ld de, CopyrightTextString ; $4556 + coord hl, 2, 7 + ld de, CopyrightTextString jp PlaceString CopyrightTextString: ; 4556 (1:4556) @@ -365,7 +381,7 @@ INCLUDE "data/title_mons.asm" ; prints version text (red, blue) PrintGameVersionOnTitleScreen: ; 4598 (1:4598) - hlCoord 7, 8 + coord hl, 7, 8 ld de, VersionOnTitleScreenText jp PlaceString diff --git a/engine/titlescreen2.asm b/engine/titlescreen2.asm index dc1c633a..c0853a0d 100755 --- a/engine/titlescreen2.asm +++ b/engine/titlescreen2.asm @@ -69,15 +69,15 @@ _TitleScroll: ; 3726a (d:726a) .ScrollBetween ; 37292 (d:7292) .wait - ld a, [$ff44] ; rLY + ld a, [rLY] ; rLY cp l jr nz, .wait ld a, h - ld [rSCX], a ; $ff43 + ld [rSCX], a .wait2 - ld a, [$ff44] ; rLY + ld a, [rLY] ; rLY cp h jr z, .wait2 ret @@ -87,9 +87,9 @@ TitleBallYTable: ; 372a0 (d:72a0) ; This is really two 0-terminated lists. Initiated with an index of 1. db 0, $71, $6f, $6e, $6d, $6c, $6d, $6e, $6f, $71, $74, 0 -Func_372ac: ; 372ac (d:72ac) +TitleScreenAnimateBallIfStarterOut: ; 372ac (d:72ac) ; Animate the TitleBall if a starter just got scrolled out. - ld a, [wWhichTrade] ; wWhichTrade + ld a, [wTitleMonSpecies] cp STARTER1 jr z, .ok cp STARTER2 diff --git a/engine/town_map.asm b/engine/town_map.asm index 535756b8..31eefcfd 100755 --- a/engine/town_map.asm +++ b/engine/town_map.asm @@ -7,11 +7,11 @@ DisplayTownMap: ; 70eb7 (1c:4eb7) push hl ld a, $1 ld [hJoy7], a - ld a, [W_CURMAP] ; W_CURMAP + ld a, [W_CURMAP] push af ld b, $0 - call Func_7124e - hlCoord 1, 0 + call DrawPlayerOrBirdSprite ; player sprite + coord hl, 1, 0 ld de, wcd6d call PlaceString ld hl, wOAMBuffer @@ -19,101 +19,103 @@ DisplayTownMap: ; 70eb7 (1c:4eb7) ld bc, $10 call CopyData ld hl, vSprites + $40 - ld de, TownMapCursor ; $4f40 - ld bc, (BANK(TownMapCursor) << 8) + $04 + ld de, TownMapCursor + lb bc, BANK(TownMapCursor), (TownMapCursorEnd - TownMapCursor) / $8 call CopyVideoDataDouble xor a - ld [wWhichTrade], a ; wWhichTrade + ld [wWhichTownMapLocation], a pop af - jr Func_70f08 + jr .enterLoop -Func_70ef4: ; 70ef4 (1c:4ef4) - ld hl, wTileMap - ld bc, $114 +.townMapLoop ; 70ef4 (1c:4ef4) + coord hl, 0, 0 + lb bc, 1, 20 call ClearScreenArea - ld hl, TownMapOrder ; $4f11 - ld a, [wWhichTrade] ; wWhichTrade + ld hl, TownMapOrder + ld a, [wWhichTownMapLocation] ld c, a - ld b, $0 + ld b, 0 add hl, bc ld a, [hl] - -Func_70f08: ; 70f08 (1c:4f08) - ld de, wHPBarMaxHP - call Func_7137a +.enterLoop ; 70f08 (1c:4f08) + ld de, wTownMapCoords + call LoadTownMapEntry ld a, [de] push hl - call Func_712e1 + call TownMapCoordsToOAMCoords ld a, $4 - ld [wcd5b], a + ld [wOAMBaseTile], a ld hl, wOAMBuffer + $10 - call Func_71302 + call WriteTownMapSpriteOAM ; town map cursor sprite pop hl ld de, wcd6d -.loop +.copyMapName ld a, [hli] ld [de], a inc de - cp "@" - jr nz, .loop - hlCoord 1, 0 + cp $50 + jr nz, .copyMapName + coord hl, 1, 0 ld de, wcd6d call PlaceString ld hl, wOAMBuffer + $10 ld de, wTileMapBackup + 16 ld bc, $10 call CopyData -.asm_70f3e +.inputLoop call TownMapSpriteBlinkingAnimation call JoypadLowSensitivity ld a, [hJoy5] ld b, a - and D_DOWN | D_UP | B_BUTTON | A_BUTTON - jr z, .asm_70f3e - ld a, $8c ; (SFX_02_3c - SFX_Headers_02) / 3 + and A_BUTTON | B_BUTTON | D_UP | D_DOWN + jr z, .inputLoop + ld a, $8c call PlaySound bit 6, b - jr nz, .asm_70f68 + jr nz, .pressedUp bit 7, b - jr nz, .asm_70f77 + jr nz, .pressedDown xor a ld [wTownMapSpriteBlinkingEnabled], a ld [hJoy7], a - ld [wTownMapSpriteBlinkingCounter], a - call Func_71235 + ld [wAnimCounter], a + call ExitTownMap pop hl pop af ld [hl], a ret -.asm_70f68 - ld a, [wWhichTrade] ; wWhichTrade + +.pressedUp + ld a, [wWhichTownMapLocation] inc a - cp $2f - jr nz, .asm_70f71 + cp TownMapOrderEnd - TownMapOrder ; number of list items + 1 + jr nz, .noOverflow xor a -.asm_70f71 - ld [wWhichTrade], a ; wWhichTrade - jp Func_70ef4 -.asm_70f77 - ld a, [wWhichTrade] ; wWhichTrade +.noOverflow + ld [wWhichTownMapLocation], a + jp .townMapLoop +.pressedDown + ld a, [wWhichTownMapLocation] dec a - cp $ff - jr nz, .asm_70f81 - ld a, $2e -.asm_70f81 - ld [wWhichTrade], a ; wWhichTrade - jp Func_70ef4 + cp -1 + jr nz, .noUnderflow + ld a, TownMapOrderEnd - TownMapOrder - 1 ; number of list items +.noUnderflow + ld [wWhichTownMapLocation], a + jp .townMapLoop + .asm_70f87 ld a,[hJoy5] and D_DOWN | D_UP ret z callab Func_f0000 ret - + INCLUDE "data/town_map_order.asm" TownMapCursor: ; 70fc4 (1c:4fc4) INCBIN "gfx/town_map_cursor.1bpp" +TownMapCursorEnd: LoadTownMap_Nest: ; 70fe4 (1c:4fe4) call LoadTownMap @@ -122,16 +124,16 @@ LoadTownMap_Nest: ; 70fe4 (1c:4fe4) push af ld [hl], $ff push hl - call Func_71279 + call DisplayWildLocations call GetMonName - hlCoord 1, 0 + coord hl, 1, 0 call PlaceString ld h, b ld l, c ld de, MonsNestText call PlaceString call WaitForTextScrollButtonPress - call Func_71235 + call ExitTownMap pop hl pop af ld [hl], a @@ -152,67 +154,66 @@ LoadTownMap_Fly: ; 71014 (1c:5014) ld c, $c ld hl, vSprites + $40 call CopyVideoData - ld de, TownMapUpArrow ; $5093 + ld de, TownMapUpArrow ld hl, vChars1 + $6d0 - ld bc, (BANK(TownMapUpArrow) << 8) + $01 + lb bc, BANK(TownMapUpArrow), (TownMapUpArrowEnd - TownMapUpArrow) / $8 call CopyVideoDataDouble - call Func_710fb + call BuildFlyLocationsList ld hl, wUpdateSpritesEnabled ld a, [hl] push af ld [hl], $ff push hl - ld hl, wTileMap + coord hl, 0, 0 ld de, ToText call PlaceString - ld a, [W_CURMAP] ; W_CURMAP + ld a, [W_CURMAP] ld b, $0 - call Func_7124e - ld hl, wTrainerEngageDistance - deCoord 18, 0 - + call DrawPlayerOrBirdSprite + ld hl, wFlyLocationsList + coord de, 18, 0 .townMapFlyLoop - ld a, $7f + ld a, " " ld [de], a push hl push hl - hlCoord 3, 0 - ld bc, $10f + coord hl, 3, 0 + lb bc, 1, 15 call ClearScreenArea pop hl ld a, [hl] ld b, $4 - call Func_7124e - hlCoord 3, 0 + call DrawPlayerOrBirdSprite ; draw bird sprite + coord hl, 3, 0 ld de, wcd6d call PlaceString - ld c, $f + ld c, 15 call DelayFrames - hlCoord 18, 0 + coord hl, 18, 0 ld [hl], "▶" - hlCoord 19, 0 + coord hl, 19, 0 ld [hl], $ee pop hl -.asm_7108d +.inputLoop push hl call DelayFrame call JoypadLowSensitivity ld a, [hJoy5] ld b, a pop hl - and D_DOWN | D_UP | B_BUTTON | A_BUTTON - jr z, .asm_7108d + and A_BUTTON | B_BUTTON | D_UP | D_DOWN + jr z, .inputLoop bit 0, b - jr nz, .asm_710af - ld a, $8c ; (SFX_02_3c - SFX_Headers_02) / 3 + jr nz, .pressedA + ld a, $8c ; SFX_TINK call PlaySound bit 6, b - jr nz, .asm_710cd + jr nz, .pressedUp bit 7, b - jr nz, .asm_710e3 - jr .asm_710c0 -.asm_710af - ld a, $8e ; (SFX_02_3e - SFX_Headers_02) / 3 + jr nz, .pressedDown + jr .pressedB +.pressedA + ld a, $8e ; SFX_HEAL_AILMENT call PlaySound ld a, [hl] ld [wDestinationMap], a @@ -220,7 +221,7 @@ LoadTownMap_Fly: ; 71014 (1c:5014) set 3, [hl] inc hl set 7, [hl] -.asm_710c0 +.pressedB xor a ld [wTownMapSpriteBlinkingEnabled], a ld [hJoy7], a @@ -229,85 +230,86 @@ LoadTownMap_Fly: ; 71014 (1c:5014) pop af ld [hl], a ret -.asm_710cd - deCoord 18, 0 +.pressedUp + coord de, 18, 0 inc hl ld a, [hl] cp $ff - jr z, .asm_710dd + jr z, .wrapToStartOfList cp $fe - jr z, .asm_710cd + jr z, .pressedUp ; skip past unvisited towns jp .townMapFlyLoop -.asm_710dd - ld hl, wTrainerEngageDistance +.wrapToStartOfList + ld hl, wFlyLocationsList jp .townMapFlyLoop -.asm_710e3 - deCoord 19, 0 +.pressedDown + coord de, 19, 0 dec hl ld a, [hl] cp $ff - jr z, .asm_710f3 + jr z, .wrapToEndOfList cp $fe - jr z, .asm_710e3 + jr z, .pressedDown ; skip past unvisited towns jp .townMapFlyLoop -.asm_710f3 - ld hl, wcd49 - jr .asm_710e3 +.wrapToEndOfList + ld hl, wFlyLocationsList + 11 + jr .pressedDown ToText: ; 710f8 (1c:50f8) db "To@" -Func_710fb: ; 710fb (1c:50fb) - ld hl, wWhichTrade ; wWhichTrade +BuildFlyLocationsList: ; 710fb (1c:50fb) + ld hl, wFlyLocationsList - 1 ld [hl], $ff inc hl ld a, [W_TOWNVISITEDFLAG] ld e, a ld a, [W_TOWNVISITEDFLAG + 1] ld d, a - ld bc, $b -.asm_7110c + ld bc, SAFFRON_CITY + 1 +.loop srl d rr e - ld a, $fe - jr nc, .asm_71115 - ld a, b -.asm_71115 + ld a, $fe ; store $fe if the town hasn't been visited + jr nc, .notVisited + ld a, b ; store the map number of the town if it has been visited +.notVisited ld [hl], a inc hl inc b dec c - jr nz, .asm_7110c + jr nz, .loop ld [hl], $ff ret TownMapUpArrow: ; 7111e (1c:511e) INCBIN "gfx/up_arrow.1bpp" +TownMapUpArrowEnd: LoadTownMap: ; 71126 (1c:5126) call GBPalWhiteOutWithDelay3 call ClearScreen call UpdateSprites - ld hl, wTileMap - ld bc, $1212 + coord hl, 0, 0 + lb bc, $12, $12 call TextBoxBorder call DisableLCD - ld hl, WorldMapTileGraphics ; $65a8 + ld hl, WorldMapTileGraphics ld de, vChars2 + $600 - ld bc, $100 + ld bc, WorldMapTileGraphicsEnd - WorldMapTileGraphics ld a, BANK(WorldMapTileGraphics) call FarCopyData ld hl, MonNestIcon ; $574b ld de, vSprites + $40 - ld bc, $8 + ld bc, MonNestIconEnd - MonNestIcon ld a, BANK(MonNestIcon) call FarCopyDataDouble - ld hl, wTileMap - ld de, CompressedMap ; $5100 -.asm_710d3 + coord hl, 0, 0 + ld de, CompressedMap +.nextTile ld a, [de] and a - jr z, .asm_71173 + jr z, .done ld b, a and $f ld c, a @@ -315,20 +317,20 @@ LoadTownMap: ; 71126 (1c:5126) swap a and $f add $60 -.loop +.writeRunLoop ld [hli], a dec c - jr nz, .loop + jr nz, .writeRunLoop inc de - jr .asm_710d3 -.asm_71173 + jr .nextTile +.done call EnableLCD - ld b, $2 - call GoPAL_SET + ld b, SET_PAL_TOWN_MAP + call RunPaletteCommand call Delay3 call GBPalNormal xor a - ld [wTownMapSpriteBlinkingCounter], a + ld [wAnimCounter], a inc a ld [wTownMapSpriteBlinkingEnabled], a ret @@ -337,7 +339,8 @@ CompressedMap: ; 7118a (1c:518a) ; you can decompress this file with the redrle program in the extras/ dir INCBIN "gfx/town_map.rle" -Func_71235: ; 71235 (1c:5235) +ExitTownMap: ; 71235 (1c:5235) +; clear town map graphics data and load usual graphics data xor a ld [wTownMapSpriteBlinkingEnabled], a call GBPalWhiteOut @@ -346,19 +349,21 @@ Func_71235: ; 71235 (1c:5235) call LoadPlayerSpriteGraphics call LoadFontTilePatterns call UpdateSprites - jp GoPAL_SET_CF1C + jp RunDefaultPaletteCommand -Func_7124e: ; 7124e (1c:524e) +DrawPlayerOrBirdSprite: ; 7124e (1c:524e) +; a = map number +; b = OAM base tile push af ld a, b - ld [wcd5b], a + ld [wOAMBaseTile], a pop af - ld de, wHPBarMaxHP - call Func_7137a + ld de, wTownMapCoords + call LoadTownMapEntry ld a, [de] push hl - call Func_712e1 - call Func_712f6 + call TownMapCoordsToOAMCoords + call WritePlayerOrBirdSpriteOAM pop hl ld de, wcd6d .asm_71266 @@ -372,48 +377,48 @@ Func_7124e: ; 7124e (1c:524e) ld bc, $a0 jp CopyData -Func_71279: ; 71279 (1c:5279) +DisplayWildLocations: ; 71279 (1c:5279) callba FindWildLocationsOfMon - call Func_71362 + call ZeroOutDuplicatesInList ld hl, wOAMBuffer - ld de, wBuffer -.asm_7128a + ld de, wTownMapCoords +.loop ld a, [de] cp $ff - jr z, .asm_712a7 + jr z, .exitLoop and a - jr z, .asm_712a4 + jr z, .nextEntry push hl - call Func_7137a + call LoadTownMapEntry pop hl ld a, [de] - cp $19 - jr z, .asm_712a4 - call Func_712e1 - ld a, $4 + cp $19 ; Cerulean Cave's coordinates + jr z, .nextEntry ; skip Cerulean Cave + call TownMapCoordsToOAMCoords + ld a, $4 ; nest icon tile no. ld [hli], a xor a ld [hli], a -.asm_712a4 +.nextEntry inc de - jr .asm_7128a -.asm_712a7 + jr .loop +.exitLoop ld a, l - and a - ; continue from here - jr nz, .asm_712bf - hlCoord 1, 7 - ld bc, $20f + and a ; were any OAM entries written? + jr nz, .drawPlayerSprite +; if no OAM entries were written, print area unknown text + coord hl, 1, 7 + lb bc, 2, 15 call TextBoxBorder - hlCoord 2, 9 + coord hl, 2, 9 ld de, AreaUnknownText call PlaceString - jr .asm_712c7 -.asm_712bf - ld a, [W_CURMAP] ; W_CURMAP + jr .done +.drawPlayerSprite + ld a, [W_CURMAP] ld b, $0 - call Func_7124e -.asm_712c7 + call DrawPlayerOrBirdSprite +.done ld hl, wOAMBuffer ld de, wTileMapBackup ld bc, $a0 @@ -422,33 +427,35 @@ Func_71279: ; 71279 (1c:5279) AreaUnknownText: ; 712d3 (1c:52d3) db " AREA UNKNOWN@" -Func_712e1: ; 712e1 (1c:52e1) +TownMapCoordsToOAMCoords: ; 712e1 (1c:52e1) +; in: lower nybble of a = x, upper nybble of a = y +; out: b and [hl] = (y * 8) + 24, c and [hl+1] = (x * 8) + 24 push af and $f0 srl a - add $18 + add 24 ld b, a ld [hli], a pop af and $f swap a srl a - add $18 + add 24 ld c, a ld [hli], a ret -Func_712f6: ; 712f6 (1c:52f6) - ld a, [wcd5b] +WritePlayerOrBirdSpriteOAM: ; 712f6 (1c:52f6) + ld a, [wOAMBaseTile] and a - ld hl, wOAMBuffer + $90 - jr z, Func_71302 - ld hl, wOAMBuffer + $80 + ld hl, wOAMBuffer + $90 ; for player sprite + jr z, WriteTownMapSpriteOAM + ld hl, wOAMBuffer + $80 ; for bird sprite -Func_71302: ; 71302 (1c:5302) +WriteTownMapSpriteOAM: ; 71302 (1c:5302) push hl - ld hl, $fcfc - add hl, bc + lb hl, -4, -4 + add hl, bc ; subtract 4 from c (X coord) and 4 from b (Y coord) ld b, h ld c, l pop hl @@ -456,7 +463,7 @@ Func_71302: ; 71302 (1c:5302) WriteAsymmetricMonPartySpriteOAM: ; 7130a (1c:530a) ; Writes 4 OAM blocks for a helix mon party sprite, since is does not have ; a vertical line of symmetry. - ld de, $202 + lb de, 2, 2 .loop push de push bc @@ -465,10 +472,10 @@ WriteAsymmetricMonPartySpriteOAM: ; 7130a (1c:530a) ld [hli], a ld a, c ld [hli], a - ld a, [wcd5b] + ld a, [wOAMBaseTile] ld [hli], a inc a - ld [wcd5b], a + ld [wOAMBaseTile], a xor a ld [hli], a inc d @@ -492,24 +499,24 @@ WriteSymmetricMonPartySpriteOAM: ; 7132f (1c:532f) ; the X-flip OAM bit to be used so that only 2 rather than 4 tile patterns are ; needed. xor a - ld [wcd5c], a - ld de, $202 + ld [wSymmetricSpriteOAMAttributes], a + lb de, 2, 2 .loop push de push bc .innerLoop ld a, b - ld [hli], a + ld [hli], a ; Y ld a, c - ld [hli], a - ld a, [wcd5b] - ld [hli], a - ld a, [wcd5c] - ld [hli], a - xor $20 - ld [wcd5c], a + ld [hli], a ; X + ld a, [wOAMBaseTile] + ld [hli], a ; tile + ld a, [wSymmetricSpriteOAMAttributes] + ld [hli], a ; attributes + xor (1 << OAM_X_FLIP) + ld [wSymmetricSpriteOAMAttributes], a inc d - ld a, $8 + ld a, 8 add c ld c, a dec e @@ -517,20 +524,21 @@ WriteSymmetricMonPartySpriteOAM: ; 7132f (1c:532f) pop bc pop de push hl - ld hl, wcd5b + ld hl, wOAMBaseTile inc [hl] inc [hl] pop hl - ld a, $8 + ld a, 8 add b ld b, a dec d jr nz, .loop ret -Func_71362: ; 71362 (1c:5362) - ld de, wHPBarMaxHP -.asm_71365 +ZeroOutDuplicatesInList: ; 71362 (1c:5362) +; replace duplicate bytes in the list of wild pokemon locations with 0 + ld de, wBuffer +.loop ld a, [de] inc de cp $ff @@ -538,38 +546,41 @@ Func_71362: ; 71362 (1c:5362) ld c, a ld l, e ld h, d -.asm_7136d +.zeroDuplicatesLoop ld a, [hl] cp $ff - jr z, .asm_71365 + jr z, .loop cp c - jr nz, .asm_71377 + jr nz, .skipZeroing xor a ld [hl], a -.asm_71377 +.skipZeroing inc hl - jr .asm_7136d -Func_7137a: ; 7137a (1c:537a) + jr .zeroDuplicatesLoop + +LoadTownMapEntry: ; 7137a (1c:537a) +; in: a = map number +; out: lower nybble of [de] = x, upper nybble of [de] = y, hl = address of name cp REDS_HOUSE_1F - jr c, .asm_7138d - ld bc, $4 - ld hl, InternalMapEntries ; $540b -.asm_71384 + jr c, .external + ld bc, 4 + ld hl, InternalMapEntries +.loop cp [hl] - jr c, .asm_7138a + jr c, .foundEntry add hl, bc - jr .asm_71384 -.asm_7138a + jr .loop +.foundEntry inc hl - jr .asm_71396 -.asm_7138d - ld hl, ExternalMapEntries ; $539c + jr .readEntry +.external + ld hl, ExternalMapEntries ld c, a - ld b, $0 + ld b, 0 add hl, bc add hl, bc add hl, bc -.asm_71396 +.readEntry ld a, [hli] ld [de], a ld a, [hli] @@ -586,11 +597,12 @@ InternalMapEntries: ; 7140b (1c:540b) ;INCLUDE "text/map_names.asm" ; TODO: relabel addresses -MonNestIcon: ; 7174b (1c:574b) ; relabel this too +MonNestIcon: ; 7174b (1c:574b) INCBIN "gfx/mon_nest_icon.1bpp" +MonNestIconEnd: TownMapSpriteBlinkingAnimation: ; 71753 (1c:5753) - ld a, [wTownMapSpriteBlinkingCounter] + ld a, [wAnimCounter] inc a cp 25 jr z, .hideSprites @@ -614,5 +626,5 @@ TownMapSpriteBlinkingAnimation: ; 71753 (1c:5753) jr nz, .hideSpritesLoop ld a, 25 .done - ld [wTownMapSpriteBlinkingCounter], a + ld [wAnimCounter], a jp DelayFrame diff --git a/engine/trade.asm b/engine/trade.asm index bb4fa4e1..66afa47e 100755 --- a/engine/trade.asm +++ b/engine/trade.asm @@ -13,7 +13,7 @@ ExternalClockTradeAnim: ; 410f3 (10:50f3) ; Externally clocked link cable trades use this. ld a, [wTradedEnemyMonSpecies] ld [wLeftGBMonSpecies], a - ld a, [wTrainerSpriteOffset] + ld a, [wTradedPlayerMonSpecies] ld [wRightGBMonSpecies], a ld de, ExternalClockTradeFuncSequence @@ -148,8 +148,8 @@ Trade_Delay80: ; 41191 (10:5191) jp DelayFrames Trade_ClearTileMap: ; 41196 (10:5196) - ld hl, wTileMap - ld bc, 20 * 18 + coord hl, 0, 0 + ld bc, SCREEN_WIDTH * SCREEN_HEIGHT ld a, " " jp FillMemory @@ -158,12 +158,12 @@ LoadTradingGFXAndMonNames: ; 411a1 (10:51a1) call DisableLCD ld hl, TradingAnimationGraphics ld de, vChars2 + $310 - ld bc, $310 + ld bc, TradingAnimationGraphicsEnd - TradingAnimationGraphics ld a, BANK(TradingAnimationGraphics) call FarCopyData2 ld hl, TradingAnimationGraphics2 ld de, vSprites + $7c0 - ld bc, $40 + ld bc, TradingAnimationGraphics2End - TradingAnimationGraphics2 ld a, BANK(TradingAnimationGraphics2) call FarCopyData2 ld hl, vBGMap0 @@ -190,7 +190,7 @@ LoadTradingGFXAndMonNames: ; 411a1 (10:51a1) call GetMonName ld hl, wcd6d ld de, wcf4b - ld bc, $b + ld bc, NAME_LENGTH call CopyData ld a, [wTradedEnemyMonSpecies] ld [wd11e], a @@ -199,22 +199,20 @@ LoadTradingGFXAndMonNames: ; 411a1 (10:51a1) Trade_LoadMonPartySpriteGfx: ; 4120b (10:520b) ld a, %11010000 ld [rOBP1], a - ld b, BANK(LoadMonPartySpriteGfx) - ld hl, LoadMonPartySpriteGfx - jp Bankswitch + jpba LoadMonPartySpriteGfx Trade_SwapNames: ; 41217 (10:5217) ld hl, wPlayerName ld de, wBuffer - ld bc, 11 + ld bc, NAME_LENGTH call CopyData ld hl, wLinkEnemyTrainerName ld de, wPlayerName - ld bc, 11 + ld bc, NAME_LENGTH call CopyData ld hl, wBuffer ld de, wLinkEnemyTrainerName - ld bc, 11 + ld bc, NAME_LENGTH jp CopyData Trade_Cleanup: ; 4123b (10:523b) @@ -234,7 +232,7 @@ Trade_ShowPlayerMon: ; 41245 (10:5245) ld [hSCX], a xor a ld [H_AUTOBGTRANSFERENABLED], a - hlCoord 4, 0 + coord hl, 4, 0 ld b, 6 ld c, 10 call TextBoxBorder @@ -259,7 +257,7 @@ Trade_ShowPlayerMon: ; 41245 (10:5245) ld a, TRADE_BALL_POOF_ANIM call Trade_ShowAnimation ld a, TRADE_BALL_DROP_ANIM - call Trade_ShowAnimation + call Trade_ShowAnimation ; clears mon pic ld a, [wTradedPlayerMonSpecies] call PlayCry xor a @@ -270,20 +268,24 @@ Trade_DrawOpenEndOfLinkCable: ; 41298 (10:5298) call Trade_ClearTileMap ld b, vBGMap0 / $100 call CopyScreenTileBufferToVRAM - ld b, $8 - call GoPAL_SET + ld b, SET_PAL_GENERIC + call RunPaletteCommand + +; This function call is pointless. It just copies blank tiles to VRAM that was +; already filled with blank tiles. ld hl, vBGMap1 + $8c call Trade_CopyCableTilesOffScreen + ld a, $a0 ld [hSCX], a call DelayFrame ld a, %10001011 ld [rLCDC], a - hlCoord 6, 2 + coord hl, 6, 2 ld b, $7 ; open end of link cable tile ID list index call CopyTileIDsFromList_ZeroBaseTileID call Trade_CopyTileMapToVRAM - ld a, (SFX_02_3d - SFX_Headers_02) / 3 + ld a, SFX_HEAL_HP call PlaySound ld c, 20 .loop @@ -302,25 +304,25 @@ Trade_AnimateBallEnteringLinkCable: ; 412d2 (10:52d2) ld a, %11100100 ld [rOBP0], a xor a - ld [wd09f], a + ld [wLinkCableAnimBulgeToggle], a ld bc, $2060 .moveBallInsideLinkCableLoop push bc xor a ld de, Trade_BallInsideLinkCableOAM call WriteOAMBlock - ld a, [wd09f] + ld a, [wLinkCableAnimBulgeToggle] xor $1 - ld [wd09f], a + ld [wLinkCableAnimBulgeToggle], a add $7e ld hl, wOAMBuffer + $02 - ld de, $4 + ld de, 4 ld c, e -.cycleSpriteFramesLoop +.cycleLinkCableBulgeTile ld [hl], a add hl, de dec c - jr nz, .cycleSpriteFramesLoop + jr nz, .cycleLinkCableBulgeTile call Delay3 pop bc ld a, c @@ -328,7 +330,7 @@ Trade_AnimateBallEnteringLinkCable: ; 412d2 (10:52d2) ld c, a cp $a0 jr nc, .ballSpriteReachedEdgeOfScreen - ld a, (SFX_02_3c - SFX_Headers_02) / 3 + ld a, SFX_TINK call PlaySound jr .moveBallInsideLinkCableLoop .ballSpriteReachedEdgeOfScreen @@ -351,7 +353,7 @@ Trade_ShowEnemyMon: ; 41336 (10:5336) ld a, TRADE_BALL_TILT_ANIM call Trade_ShowAnimation call Trade_ShowClearedWindow - hlCoord 4, 10 + coord hl, 4, 10 ld b, 6 ld c, 10 call TextBoxBorder @@ -368,8 +370,8 @@ Trade_ShowEnemyMon: ; 41336 (10:5336) ld a, [wTradedEnemyMonSpecies] call PlayCry call Trade_Delay100 - hlCoord 4, 10 - ld bc, $80c + coord hl, 4, 10 + lb bc, 8, 12 call ClearScreenArea jp PrintTradeTakeCareText @@ -460,7 +462,7 @@ Trade_DrawLeftGameboy: ; 4142d (10:542d) call Trade_ClearTileMap ; draw link cable - hlCoord 11, 4 + coord hl, 11, 4 ld a, $5d ld [hli], a ld a, $5e @@ -471,16 +473,16 @@ Trade_DrawLeftGameboy: ; 4142d (10:542d) jr nz, .loop ; draw gameboy pic - hlCoord 5, 3 + coord hl, 5, 3 ld b, $6 call CopyTileIDsFromList_ZeroBaseTileID ; draw text box with player name below gameboy pic - hlCoord 4, 12 + coord hl, 4, 12 ld b, 2 ld c, 7 call TextBoxBorder - hlCoord 5, 14 + coord hl, 5, 14 ld de, wPlayerName call PlaceString @@ -490,7 +492,7 @@ Trade_DrawRightGameboy: ; 4145c (10:545c) call Trade_ClearTileMap ; draw horizontal segment of link cable - hlCoord 0, 4 + coord hl, 0, 4 ld a, $5e ld c, $e .loop @@ -518,16 +520,16 @@ Trade_DrawRightGameboy: ; 4145c (10:545c) ld [hl], a ; draw gameboy pic - hlCoord 7, 8 + coord hl, 7, 8 ld b, $6 call CopyTileIDsFromList_ZeroBaseTileID ; draw text box with enemy name above link cable - hlCoord 6, 0 + coord hl, 6, 0 ld b, $2 ld c, $7 call TextBoxBorder - hlCoord 7, 2 + coord hl, 7, 2 ld de, wLinkEnemyTrainerName call PlaceString @@ -536,7 +538,7 @@ Trade_DrawRightGameboy: ; 4145c (10:545c) Trade_DrawCableAcrossScreen: ; 4149f (10:549f) ; Draws the link cable across the screen. call Trade_ClearTileMap - hlCoord 0, 4 + coord hl, 0, 4 ld a, $5e ld c, SCREEN_WIDTH .loop @@ -549,15 +551,15 @@ Trade_CopyCableTilesOffScreen: ; 414ae (10:54ae) ; This is used to copy the link cable tiles off screen so that the cable ; continues when the screen is scrolled. push hl - hlCoord 0, 4 - call CopyToScreenEdgeTiles + coord hl, 0, 4 + call CopyToRedrawRowOrColumnSrcTiles pop hl ld a, h - ld [H_SCREENEDGEREDRAWADDR + 1], a + ld [hRedrawRowOrColumnDest + 1], a ld a, l - ld [H_SCREENEDGEREDRAWADDR], a - ld a, REDRAWROW - ld [H_SCREENEDGEREDRAW], a + ld [hRedrawRowOrColumnDest], a + ld a, REDRAW_ROW + ld [hRedrawRowOrColumnMode], a ld c, 10 jp DelayFrames @@ -645,14 +647,14 @@ Trade_AnimMonMoveVertical: ; 41525 (10:5525) and a jr z, .movingLeft ; moving right - ld bc, $400 ; move right + lb bc, 4, 0 ; move right call .doAnim - ld bc, $a ; move down + lb bc, 0, 10 ; move down jr .doAnim .movingLeft - ld bc, $f6 ; move up + lb bc, 0, -10 ; move up call .doAnim - ld bc, $fc00 ; move left + lb bc, -4, 0 ; move left .doAnim ld a, b ld [W_BASECOORDX], a @@ -662,7 +664,7 @@ Trade_AnimMonMoveVertical: ; 41525 (10:5525) .loop call Trade_AddOffsetsToOAMCoords call Trade_AnimCircledMon - ld c, $8 + ld c, 8 call DelayFrames dec d jr nz, .loop @@ -725,15 +727,15 @@ Trade_CircleOAM3: ; 4159c (10:559c) Trade_LoadMonSprite: ; 415a4 (10:55a4) ld [wcf91], a ld [wd0b5], a - ld [wcf1d], a - ld b, $b - ld c, $0 - call GoPAL_SET + ld [wWholeScreenPaletteMonSpecies], a + ld b, SET_PAL_POKEMON_WHOLE_SCREEN + ld c, 0 + call RunPaletteCommand ld a, [H_AUTOBGTRANSFERENABLED] xor $1 ld [H_AUTOBGTRANSFERENABLED], a call GetMonHeader - hlCoord 7, 2 + coord hl, 7, 2 call LoadFlippedFrontSpriteByMonIndex ld c, 10 jp DelayFrames @@ -754,7 +756,10 @@ Trade_ShowClearedWindow: ; 415c8 (10:55c8) ret Trade_SlideTextBoxOffScreen: ; 415df (10:55df) -; Slides the window right until it's off screen. +; Slides the window right until it's off screen. The window usually just has +; a text box at the bottom when this is called. However, when this is called +; after Trade_ShowEnemyMon in the external clock sequence, there is a mon pic +; above the text box and it is also scrolled off the screen. ld c, 50 call DelayFrames .loop @@ -844,5 +849,5 @@ TradeforText: ; 41671 (10:5671) Trade_ShowAnimation: ; 41676 (10:5676) ld [W_ANIMATIONID], a xor a - ld [wcc5b], a + ld [wAnimationType], a predef_jump MoveAnimation diff --git a/engine/trade2.asm b/engine/trade2.asm index da199e77..10bef792 100755 --- a/engine/trade2.asm +++ b/engine/trade2.asm @@ -1,45 +1,45 @@ Trade_PrintPlayerMonInfoText: ; 42769 (10:6769) - hlCoord 5, 0 + coord hl, 5, 0 ld de,Trade_MonInfoText call PlaceString ld a,[wTradedPlayerMonSpecies] ld [wd11e],a predef IndexToPokedex - hlCoord 9, 0 + coord hl, 9, 0 ld de,wd11e - ld bc,$8103 + lb bc, LEADING_ZEROES | 1, 3 call PrintNumber - hlCoord 5, 2 + coord hl, 5, 2 ld de,wcf4b call PlaceString - hlCoord 8, 4 + coord hl, 8, 4 ld de,wTradedPlayerMonOT call PlaceString - hlCoord 8, 6 + coord hl, 8, 6 ld de,wTradedPlayerMonOTID - ld bc,$8205 + lb bc, LEADING_ZEROES | 2, 5 jp PrintNumber Trade_PrintEnemyMonInfoText: ; 427a7 (10:67a7) - hlCoord 5, 10 + coord hl, 5, 10 ld de,Trade_MonInfoText call PlaceString ld a,[wTradedEnemyMonSpecies] ld [wd11e],a predef IndexToPokedex - hlCoord 9, 10 + coord hl, 9, 10 ld de,wd11e - ld bc,$8103 + lb bc, LEADING_ZEROES | 1, 3 call PrintNumber - hlCoord 5, 12 + coord hl, 5, 12 ld de,wcd6d call PlaceString - hlCoord 8, 14 + coord hl, 8, 14 ld de,wTradedEnemyMonOT call PlaceString - hlCoord 8, 16 + coord hl, 8, 16 ld de,wTradedEnemyMonOTID - ld bc,$8205 + lb bc, LEADING_ZEROES | 2, 5 jp PrintNumber Trade_MonInfoText: ; 427e5 (10:67e5) |