From e67786a7a26ae7531301e928870b204043fb8a6a Mon Sep 17 00:00:00 2001 From: entrpntr Date: Tue, 17 Mar 2020 16:20:00 -0400 Subject: Cleanup of files for banks $02 and $03 for main.asm. --- data/text/common_2.asm | 2 +- data/text/common_3.asm | 2 +- engine/anim_hp_bar.asm | 421 ----- engine/battle/anim_hp_bar.asm | 421 +++++ engine/color.asm | 1903 -------------------- engine/engine_flags.asm | 195 -- engine/events/bug_contest/caught_mon.asm | 37 + engine/events/checktime.asm | 19 + engine/events/engine_flags.asm | 195 ++ engine/events/specials.asm | 572 ++++++ engine/gfx/color.asm | 1903 ++++++++++++++++++++ engine/health.asm | 102 -- engine/items.asm | 551 ------ engine/items/item_effects.asm | 2897 ++++++++++++++++++++++++++++++ engine/items/items.asm | 551 ++++++ engine/math/sine.asm | 40 + engine/move_mon.asm | 1651 ----------------- engine/overworld/variables.asm | 119 ++ engine/pokemon/breedmon_level_growth.asm | 27 + engine/pokemon/health.asm | 102 ++ engine/pokemon/knows_move.asm | 24 + engine/pokemon/move_mon.asm | 1651 +++++++++++++++++ engine/pokemon/search2.asm | 134 ++ engine/sine.asm | 40 - engine/smallflag.asm | 74 + engine/specials.asm | 572 ------ engine/tilesets/map_palettes.asm | 110 ++ engine/variables.asm | 119 -- gfx/tileset_palette_maps.asm | 6 + items/item_effects.asm | 2897 ------------------------------ main.asm | 437 +---- pokegold.link | 4 - pokesilver.link | 4 - 33 files changed, 8905 insertions(+), 8877 deletions(-) delete mode 100755 engine/anim_hp_bar.asm create mode 100755 engine/battle/anim_hp_bar.asm delete mode 100755 engine/color.asm delete mode 100755 engine/engine_flags.asm create mode 100644 engine/events/bug_contest/caught_mon.asm create mode 100644 engine/events/checktime.asm create mode 100755 engine/events/engine_flags.asm create mode 100755 engine/events/specials.asm create mode 100755 engine/gfx/color.asm delete mode 100755 engine/health.asm delete mode 100755 engine/items.asm create mode 100755 engine/items/item_effects.asm create mode 100755 engine/items/items.asm create mode 100644 engine/math/sine.asm delete mode 100755 engine/move_mon.asm create mode 100755 engine/overworld/variables.asm create mode 100644 engine/pokemon/breedmon_level_growth.asm create mode 100755 engine/pokemon/health.asm create mode 100644 engine/pokemon/knows_move.asm create mode 100755 engine/pokemon/move_mon.asm create mode 100644 engine/pokemon/search2.asm delete mode 100644 engine/sine.asm create mode 100644 engine/smallflag.asm delete mode 100755 engine/specials.asm create mode 100644 engine/tilesets/map_palettes.asm delete mode 100755 engine/variables.asm create mode 100644 gfx/tileset_palette_maps.asm delete mode 100755 items/item_effects.asm diff --git a/data/text/common_2.asm b/data/text/common_2.asm index bba69b4c..f9caef49 100644 --- a/data/text/common_2.asm +++ b/data/text/common_2.asm @@ -580,7 +580,7 @@ Text_CantTakeAnyMorePokemon_:: line "more #MON." prompt -Text_CaughtBugMon_:: +_ContestCaughtMonText:: text "Caught @" text_ram wStringBuffer1 text "!" diff --git a/data/text/common_3.asm b/data/text/common_3.asm index 503d5a76..d89d72d2 100644 --- a/data/text/common_3.asm +++ b/data/text/common_3.asm @@ -445,7 +445,7 @@ Text_GotOffItem_:: text "." prompt -Text_KnowsMove_:: +_KnowsMoveText:: text_ram wStringBuffer1 text " knows" line "@" diff --git a/engine/anim_hp_bar.asm b/engine/anim_hp_bar.asm deleted file mode 100755 index 561cba42..00000000 --- a/engine/anim_hp_bar.asm +++ /dev/null @@ -1,421 +0,0 @@ -HP_BAR_MAX_PIXELS EQU $30 - -AnimateHPBar_: ; d62d (3:562d) - call Functiond665 - jr c, .asm_d64b - call Functiond676 -.asm_d635 - push bc - push hl - call Functiond6e8 - pop hl - pop bc - push af - push bc - push hl - call Functiond736 - call Functiond7cf - pop hl - pop bc - pop af - jr nc, .asm_d635 - ret - -.asm_d64b - call Functiond676 -.asm_d64e - push bc - push hl - call Functiond6fb - pop hl - pop bc - ret c - push af - push bc - push hl - call Functiond74f - call Functiond7cf - pop hl - pop bc - pop af - jr nc, .asm_d64e - ret - -Functiond665: ; d665 (3:5665) - ld a, [wCurHPAnimMaxHP + 1] - and a - jr nz, .asm_d674 - ld a, [wCurHPAnimMaxHP] - cp HP_BAR_MAX_PIXELS - jr nc, .asm_d674 - and a - ret - -.asm_d674 - scf - ret - -Functiond676: ; d676 (3:5676) - push hl - ld hl, wCurHPAnimMaxHP - ld a, [hli] - ld e, a - ld a, [hli] - ld d, a - ld a, [hli] - ld c, a - ld a, [hli] - ld b, a - pop hl - call ComputeHPBarPixels - ld a, e - ld [wCurHPBarPixels], a - ld a, [wCurHPAnimNewHP] - ld c, a - ld a, [wCurHPAnimNewHP + 1] - ld b, a - ld a, [wCurHPAnimMaxHP] - ld e, a - ld a, [wCurHPAnimMaxHP + 1] - ld d, a - call ComputeHPBarPixels - ld a, e - ld [wNewHPBarPixels], a - push hl - ld hl, wCurHPAnimOldHP - ld a, [hli] - ld c, a - ld a, [hli] - ld b, a - ld a, [hli] - ld e, a - ld a, [hli] - ld d, a - pop hl - ld a, e - sub c - ld e, a - ld a, d - sbc b - ld d, a - jr c, .asm_d6c7 - ld a, [wCurHPAnimOldHP] - ld [wCurHPAnimLowHP], a - ld a, [wCurHPAnimNewHP] - ld [wCurHPAnimHighHP], a - ld bc, $1 - jr .asm_d6df - -.asm_d6c7 - ld a, [wCurHPAnimOldHP] - ld [wCurHPAnimHighHP], a - ld a, [wCurHPAnimNewHP] - ld [wCurHPAnimLowHP], a - ld a, e - xor $ff - inc a - ld e, a - ld a, d - xor $ff - ld d, a - ld bc, rIE -.asm_d6df - ld a, d - ld [wCurHPAnimDeltaHP], a - ld a, e - ld [wCurHPAnimDeltaHP + 1], a - ret - -Functiond6e8: ; d6e8 (3:56e8) - ld hl, wCurHPBarPixels - ld a, [wNewHPBarPixels] - cp [hl] - jr nz, .asm_d6f3 - scf - ret - -.asm_d6f3 - ld a, c - add [hl] - ld [hl], a - call Functiond83f - and a - ret - -Functiond6fb: ; d6fb (3:56fb) - ld hl, wCurHPAnimOldHP - ld a, [hli] - ld e, a - ld a, [hli] - ld d, a - ld a, e - cp [hl] - jr nz, .asm_d70d - inc hl - ld a, d - cp [hl] - jr nz, .asm_d70d - scf - ret - -.asm_d70d - ld l, e - ld h, d - add hl, bc - ld a, l - ld [wCurHPAnimOldHP], a - ld a, h - ld [wCurHPAnimOldHP + 1], a - push hl - push de - push bc - ld hl, wCurHPAnimMaxHP - ld a, [hli] - ld e, a - ld a, [hli] - ld d, a - ld a, [hli] - ld c, a - ld a, [hli] - ld b, a - ; BUG: This routine is meant to make the HP bar move at - ; the same rate regardless of how many HP the Pokemon has. - ; In actuality, this causes Pokemon with more than 48 HP - ; to gain or lose HP at the rate of 1 HP per BGMap update - ; rather than 1 pixel on the HUD. - ; To fix, move the "ld a, e" above the "pop de". - call ComputeHPBarPixels ; returns to e - pop bc - pop de ; overloads e - pop hl - ld a, e ; expects result from ComputeHPBarPixels - ld hl, wCurHPBarPixels - cp [hl] - jr z, Functiond6fb - ld [hl], a - and a - ret - -Functiond736: ; d736 (3:5736) - call Functiond78a - ld d, $6 - ld a, [wWhichHPBar] - and $1 - ld b, a - ld a, [wCurHPBarPixels] - ld e, a - ld c, a - push de - call Functiond777 - pop de - call Functiond7ba - ret - -Functiond74f: ; d74f (3:574f) - call Functiond78a - ld a, [wCurHPAnimOldHP] - ld c, a - ld a, [wCurHPAnimOldHP + 1] - ld b, a - ld a, [wCurHPAnimMaxHP] - ld e, a - ld a, [wCurHPAnimMaxHP + 1] - ld d, a - call ComputeHPBarPixels - ld c, e - ld d, $6 - ld a, [wWhichHPBar] - and $1 - ld b, a - push de - call Functiond777 - pop de - call Functiond7ba - ret - -Functiond777: ; d777 (3:5777) - ld a, [wWhichHPBar] - cp $2 - jr nz, .asm_d786 - ld a, $28 - add l - ld l, a - ld a, $0 - adc h - ld h, a -.asm_d786 - call DrawBattleHPBar - ret - -Functiond78a: ; d78a (3:578a) - ld a, [wWhichHPBar] - and a - ret z - cp $1 - jr z, .asm_d798 - ld de, $16 - jr .asm_d79b - -.asm_d798 - ld de, $15 -.asm_d79b - push hl - add hl, de - ld a, $7f - ld [hli], a - ld [hli], a - ld [hld], a - dec hl - ld a, [wCurHPAnimOldHP] - ld [wStringBuffer2 + 1], a - ld a, [wCurHPAnimOldHP + 1] - ld [wStringBuffer2], a - ld de, wStringBuffer2 - lb bc, 2, 3 - call PrintNum - pop hl - ret - -Functiond7ba: ; d7ba (3:57ba) - ldh a, [hCGB] - and a - ret z - ld hl, wCurHPAnimPal - call SetHPPal - ld a, [wCurHPAnimPal] - ld c, a - ld a, $2 - ld hl, $520b - rst FarCall - ret - -Functiond7cf: ; d7cf (3:57cf) - ldh a, [hCGB] - and a - jr nz, .asm_d7db - call DelayFrame - call DelayFrame - ret - -.asm_d7db - ld a, [wWhichHPBar] - and a - jr z, .asm_d82f - cp $1 - jr z, .asm_d833 - ld a, [wCurPartyMon] - cp $3 - jr nc, .asm_d7f0 - ld c, $0 - jr .asm_d7f2 - -.asm_d7f0 - ld c, $1 -.asm_d7f2 - push af - cp $2 - jr z, .asm_d805 - cp $5 - jr z, .asm_d805 - ld a, $2 - ldh [hBGMapMode], a - ld a, c - ldh [hBGMapThird], a - call DelayFrame -.asm_d805 - ld a, $1 - ldh [hBGMapMode], a - ld a, c - ldh [hBGMapThird], a - call DelayFrame - pop af - cp $2 - jr z, .asm_d819 - cp $5 - jr z, .asm_d819 - ret - -.asm_d819 - inc c - ld a, $2 - ldh [hBGMapMode], a - ld a, c - ldh [hBGMapThird], a - call DelayFrame - ld a, $1 - ldh [hBGMapMode], a - ld a, c - ldh [hBGMapThird], a - call DelayFrame - ret - -.asm_d82f - ld c, $0 - jr .asm_d835 - -.asm_d833 - ld c, $1 -.asm_d835 - call DelayFrame - ld a, c - ldh [hBGMapThird], a - call DelayFrame - ret - -Functiond83f: ; d83f (3:583f) - ld a, [wCurHPAnimMaxHP] - ld c, a - ld b, $0 - ld hl, $0 - ld a, [wCurHPBarPixels] - cp HP_BAR_MAX_PIXELS - jr nc, .asm_d88b - and a - jr z, .asm_d886 - call AddNTimes - ld b, $0 -.asm_d857 - ld a, l - sub HP_BAR_MAX_PIXELS % $100 - ld l, a - ld a, h - sbc HP_BAR_MAX_PIXELS / $100 - ld h, a - jr c, .asm_d864 - inc b - jr .asm_d857 - -.asm_d864 - push bc - ld bc, $80 - add hl, bc - pop bc - ld a, l - sub HP_BAR_MAX_PIXELS % $100 - ld l, a - ld a, h - sbc HP_BAR_MAX_PIXELS / $100 - ld h, a - jr c, .asm_d875 - inc b -.asm_d875 - ld a, [wCurHPAnimLowHP] - cp b - jr nc, .asm_d882 - ld a, [wCurHPAnimHighHP] - cp b - jr c, .asm_d882 - ld a, b -.asm_d882 - ld [wCurHPAnimOldHP], a - ret - -.asm_d886 - xor a - ld [wCurHPAnimOldHP], a - ret - -.asm_d88b - ld a, [wCurHPAnimMaxHP] - ld [wCurHPAnimOldHP], a - ret diff --git a/engine/battle/anim_hp_bar.asm b/engine/battle/anim_hp_bar.asm new file mode 100755 index 00000000..561cba42 --- /dev/null +++ b/engine/battle/anim_hp_bar.asm @@ -0,0 +1,421 @@ +HP_BAR_MAX_PIXELS EQU $30 + +AnimateHPBar_: ; d62d (3:562d) + call Functiond665 + jr c, .asm_d64b + call Functiond676 +.asm_d635 + push bc + push hl + call Functiond6e8 + pop hl + pop bc + push af + push bc + push hl + call Functiond736 + call Functiond7cf + pop hl + pop bc + pop af + jr nc, .asm_d635 + ret + +.asm_d64b + call Functiond676 +.asm_d64e + push bc + push hl + call Functiond6fb + pop hl + pop bc + ret c + push af + push bc + push hl + call Functiond74f + call Functiond7cf + pop hl + pop bc + pop af + jr nc, .asm_d64e + ret + +Functiond665: ; d665 (3:5665) + ld a, [wCurHPAnimMaxHP + 1] + and a + jr nz, .asm_d674 + ld a, [wCurHPAnimMaxHP] + cp HP_BAR_MAX_PIXELS + jr nc, .asm_d674 + and a + ret + +.asm_d674 + scf + ret + +Functiond676: ; d676 (3:5676) + push hl + ld hl, wCurHPAnimMaxHP + ld a, [hli] + ld e, a + ld a, [hli] + ld d, a + ld a, [hli] + ld c, a + ld a, [hli] + ld b, a + pop hl + call ComputeHPBarPixels + ld a, e + ld [wCurHPBarPixels], a + ld a, [wCurHPAnimNewHP] + ld c, a + ld a, [wCurHPAnimNewHP + 1] + ld b, a + ld a, [wCurHPAnimMaxHP] + ld e, a + ld a, [wCurHPAnimMaxHP + 1] + ld d, a + call ComputeHPBarPixels + ld a, e + ld [wNewHPBarPixels], a + push hl + ld hl, wCurHPAnimOldHP + ld a, [hli] + ld c, a + ld a, [hli] + ld b, a + ld a, [hli] + ld e, a + ld a, [hli] + ld d, a + pop hl + ld a, e + sub c + ld e, a + ld a, d + sbc b + ld d, a + jr c, .asm_d6c7 + ld a, [wCurHPAnimOldHP] + ld [wCurHPAnimLowHP], a + ld a, [wCurHPAnimNewHP] + ld [wCurHPAnimHighHP], a + ld bc, $1 + jr .asm_d6df + +.asm_d6c7 + ld a, [wCurHPAnimOldHP] + ld [wCurHPAnimHighHP], a + ld a, [wCurHPAnimNewHP] + ld [wCurHPAnimLowHP], a + ld a, e + xor $ff + inc a + ld e, a + ld a, d + xor $ff + ld d, a + ld bc, rIE +.asm_d6df + ld a, d + ld [wCurHPAnimDeltaHP], a + ld a, e + ld [wCurHPAnimDeltaHP + 1], a + ret + +Functiond6e8: ; d6e8 (3:56e8) + ld hl, wCurHPBarPixels + ld a, [wNewHPBarPixels] + cp [hl] + jr nz, .asm_d6f3 + scf + ret + +.asm_d6f3 + ld a, c + add [hl] + ld [hl], a + call Functiond83f + and a + ret + +Functiond6fb: ; d6fb (3:56fb) + ld hl, wCurHPAnimOldHP + ld a, [hli] + ld e, a + ld a, [hli] + ld d, a + ld a, e + cp [hl] + jr nz, .asm_d70d + inc hl + ld a, d + cp [hl] + jr nz, .asm_d70d + scf + ret + +.asm_d70d + ld l, e + ld h, d + add hl, bc + ld a, l + ld [wCurHPAnimOldHP], a + ld a, h + ld [wCurHPAnimOldHP + 1], a + push hl + push de + push bc + ld hl, wCurHPAnimMaxHP + ld a, [hli] + ld e, a + ld a, [hli] + ld d, a + ld a, [hli] + ld c, a + ld a, [hli] + ld b, a + ; BUG: This routine is meant to make the HP bar move at + ; the same rate regardless of how many HP the Pokemon has. + ; In actuality, this causes Pokemon with more than 48 HP + ; to gain or lose HP at the rate of 1 HP per BGMap update + ; rather than 1 pixel on the HUD. + ; To fix, move the "ld a, e" above the "pop de". + call ComputeHPBarPixels ; returns to e + pop bc + pop de ; overloads e + pop hl + ld a, e ; expects result from ComputeHPBarPixels + ld hl, wCurHPBarPixels + cp [hl] + jr z, Functiond6fb + ld [hl], a + and a + ret + +Functiond736: ; d736 (3:5736) + call Functiond78a + ld d, $6 + ld a, [wWhichHPBar] + and $1 + ld b, a + ld a, [wCurHPBarPixels] + ld e, a + ld c, a + push de + call Functiond777 + pop de + call Functiond7ba + ret + +Functiond74f: ; d74f (3:574f) + call Functiond78a + ld a, [wCurHPAnimOldHP] + ld c, a + ld a, [wCurHPAnimOldHP + 1] + ld b, a + ld a, [wCurHPAnimMaxHP] + ld e, a + ld a, [wCurHPAnimMaxHP + 1] + ld d, a + call ComputeHPBarPixels + ld c, e + ld d, $6 + ld a, [wWhichHPBar] + and $1 + ld b, a + push de + call Functiond777 + pop de + call Functiond7ba + ret + +Functiond777: ; d777 (3:5777) + ld a, [wWhichHPBar] + cp $2 + jr nz, .asm_d786 + ld a, $28 + add l + ld l, a + ld a, $0 + adc h + ld h, a +.asm_d786 + call DrawBattleHPBar + ret + +Functiond78a: ; d78a (3:578a) + ld a, [wWhichHPBar] + and a + ret z + cp $1 + jr z, .asm_d798 + ld de, $16 + jr .asm_d79b + +.asm_d798 + ld de, $15 +.asm_d79b + push hl + add hl, de + ld a, $7f + ld [hli], a + ld [hli], a + ld [hld], a + dec hl + ld a, [wCurHPAnimOldHP] + ld [wStringBuffer2 + 1], a + ld a, [wCurHPAnimOldHP + 1] + ld [wStringBuffer2], a + ld de, wStringBuffer2 + lb bc, 2, 3 + call PrintNum + pop hl + ret + +Functiond7ba: ; d7ba (3:57ba) + ldh a, [hCGB] + and a + ret z + ld hl, wCurHPAnimPal + call SetHPPal + ld a, [wCurHPAnimPal] + ld c, a + ld a, $2 + ld hl, $520b + rst FarCall + ret + +Functiond7cf: ; d7cf (3:57cf) + ldh a, [hCGB] + and a + jr nz, .asm_d7db + call DelayFrame + call DelayFrame + ret + +.asm_d7db + ld a, [wWhichHPBar] + and a + jr z, .asm_d82f + cp $1 + jr z, .asm_d833 + ld a, [wCurPartyMon] + cp $3 + jr nc, .asm_d7f0 + ld c, $0 + jr .asm_d7f2 + +.asm_d7f0 + ld c, $1 +.asm_d7f2 + push af + cp $2 + jr z, .asm_d805 + cp $5 + jr z, .asm_d805 + ld a, $2 + ldh [hBGMapMode], a + ld a, c + ldh [hBGMapThird], a + call DelayFrame +.asm_d805 + ld a, $1 + ldh [hBGMapMode], a + ld a, c + ldh [hBGMapThird], a + call DelayFrame + pop af + cp $2 + jr z, .asm_d819 + cp $5 + jr z, .asm_d819 + ret + +.asm_d819 + inc c + ld a, $2 + ldh [hBGMapMode], a + ld a, c + ldh [hBGMapThird], a + call DelayFrame + ld a, $1 + ldh [hBGMapMode], a + ld a, c + ldh [hBGMapThird], a + call DelayFrame + ret + +.asm_d82f + ld c, $0 + jr .asm_d835 + +.asm_d833 + ld c, $1 +.asm_d835 + call DelayFrame + ld a, c + ldh [hBGMapThird], a + call DelayFrame + ret + +Functiond83f: ; d83f (3:583f) + ld a, [wCurHPAnimMaxHP] + ld c, a + ld b, $0 + ld hl, $0 + ld a, [wCurHPBarPixels] + cp HP_BAR_MAX_PIXELS + jr nc, .asm_d88b + and a + jr z, .asm_d886 + call AddNTimes + ld b, $0 +.asm_d857 + ld a, l + sub HP_BAR_MAX_PIXELS % $100 + ld l, a + ld a, h + sbc HP_BAR_MAX_PIXELS / $100 + ld h, a + jr c, .asm_d864 + inc b + jr .asm_d857 + +.asm_d864 + push bc + ld bc, $80 + add hl, bc + pop bc + ld a, l + sub HP_BAR_MAX_PIXELS % $100 + ld l, a + ld a, h + sbc HP_BAR_MAX_PIXELS / $100 + ld h, a + jr c, .asm_d875 + inc b +.asm_d875 + ld a, [wCurHPAnimLowHP] + cp b + jr nc, .asm_d882 + ld a, [wCurHPAnimHighHP] + cp b + jr c, .asm_d882 + ld a, b +.asm_d882 + ld [wCurHPAnimOldHP], a + ret + +.asm_d886 + xor a + ld [wCurHPAnimOldHP], a + ret + +.asm_d88b + ld a, [wCurHPAnimMaxHP] + ld [wCurHPAnimOldHP], a + ret diff --git a/engine/color.asm b/engine/color.asm deleted file mode 100755 index 05c13b2b..00000000 --- a/engine/color.asm +++ /dev/null @@ -1,1903 +0,0 @@ -PALPACKET_LENGTH EQU $10 -INCLUDE "predef/sgb.asm" - -SHINY_ATK_BIT EQU 5 -SHINY_DEF_VAL EQU 10 -SHINY_SPD_VAL EQU 10 -SHINY_SPC_VAL EQU 10 - -CheckShininess: - ld l, c - ld h, b - ld a, [hl] - and $20 - jr z, .asm_9070 - ld a, [hli] - and $f - cp $a - jr nz, .asm_9070 - ld a, [hl] - and $f0 - cp $a0 - jr nz, .asm_9070 - ld a, [hl] - and $f - cp $a - jr nz, .asm_9070 - scf - ret - -.asm_9070 - and a - ret - -Unused_CheckShininess: ; 9072 (2:5072) - ld a, [hl] - cp $a0 - jr c, .asm_908c - ld a, [hli] - and $f - cp $a - jr c, .asm_908c - ld a, [hl] - cp $a0 - jr c, .asm_908c - ld a, [hl] - and $f - cp $a - jr c, .asm_908c - scf - ret - -.asm_908c - and a - ret - -Function908e: - push de - push bc - ld hl, PalPacket_a155 - ld de, wcca9 - ld bc, $10 - call CopyBytes - pop bc - pop de - ld a, c - ld [wccac], a - ld a, b - ld [wccad], a - ld a, e - ld [wccae], a - ld a, d - ld [wccaf], a - ld hl, wcca9 - call PushSGBPals_ - ld hl, BlkPacket_9ee5 - call PushSGBPals_ - ret - -InitPartyMenuPalettes: - call CheckCGB - jr nz, .asm_90cc - ld hl, BlkPacket_9fa5 - ld de, wccaa - ld bc, $30 - jp CopyBytes - -.asm_90cc - ld hl, PalPacket_a0c5 + 1 - call Function9ab2 - call Function9b9c - call Function9b1d - ret - -SGB_ApplyPartyMenuHPPals: - ld hl, wcc9b - ld a, [wcca9] - ld e, a - ld d, $0 - add hl, de - ld e, l - ld d, h - ld a, [de] - and a - ld e, $5 - jr z, .asm_90f2 - dec a - ld e, $a - jr z, .asm_90f2 - ld e, $f -.asm_90f2 - push de - ld hl, wccb3 - ld bc, $6 - ld a, [wcca9] - call AddNTimes - pop de - ld [hl], e - ret - -Function9102: - call CheckCGB - ret z - ld hl, .BGPal - ld de, wTempBGPals - ld bc, $8 - call CopyBytes - ld hl, .OBPal - ld de, wTempOBPals - ld bc, $8 - call CopyBytes - call Function9b28 - ld a, $1 - ldh [hCGBPalUpdate], a - ret - -.BGPal: - RGB 31, 31, 31 - RGB 18, 23, 31 - RGB 15, 20, 31 - RGB 00, 00, 00 - -.OBPal: - RGB 31, 31, 31 - RGB 31, 31, 12 - RGB 08, 16, 28 - RGB 00, 00, 00 - -Function9136: - call CheckCGB - ret nz - ldh a, [hSGB] - and a - ret z - ld hl, BlkPacket_9ee5 - jp PushSGBPals_ - -Function9144: - call CheckCGB - jr nz, .asm_9153 - ldh a, [hSGB] - and a - ret z - ld hl, PalPacket_a095 - jp PushSGBPals_ - -.asm_9153 - ld de, wTempOBPals - ld a, $3b - call Function9ac7 - jp Function9ad2 - -Function915e: - call CheckCGB - jr nz, .asm_916d - ldh a, [hSGB] - and a - ret z - ld hl, PalPacket_a0a5 - jp PushSGBPals_ - -.asm_916d - ld de, wTempOBPals - ld a, $3c - call Function9ac7 - jp Function9ad2 - -Function9178: - call CheckCGB - jr nz, .asm_91a9 - ldh a, [hSGB] - and a - ret z - ld a, c - push af - ld hl, PalPacket_a155 - ld de, wcca9 - ld bc, $10 - call CopyBytes - pop af - call Function9be4 - ld a, [hli] - ld [wccac], a - ld a, [hli] - ld [wccad], a - ld a, [hli] - ld [wccae], a - ld a, [hl] - ld [wccaf], a - ld hl, wcca9 - jp PushSGBPals_ - -.asm_91a9 - ld de, wTempOBPals - ld a, c - call Function9be4 - call Function9adb - ret - -Function91b4: - ldh a, [hCGB] - and a - jr nz, .asm_91bf - ld hl, wc602 - jp PushSGBPals_ - -.asm_91bf - ld a, [wc606] - ld c, a - ld a, [wc607] - ld hl, wAttrmap - ld de, $14 -.asm_91cc - and a - jr z, .asm_91d3 - add hl, de - dec a - jr .asm_91cc - -.asm_91d3 - ld b, $0 - add hl, bc - lb bc, 6, 4 - ld a, [wc605] - and $3 - call Function9af1 - call CopyTilemapAtOnce - ret - -ApplyMonOrTrainerPals: ; 91e5 (2:51e5) - call CheckCGB - ret z - ld a, e - and a - jr z, .asm_91f5 - ld a, [wCurPartySpecies] - call Function9be4 - jr .asm_91fb - -.asm_91f5 - ld a, [wTrainerClass] - call Function9bda -.asm_91fb - ld de, wTempBGPals - call Function9adb - call Function9b1d - call Function9b35 - call Function9b28 - ret - -ApplyHPBarPals: - ld a, [wWhichHPBar] - and a - jr z, .asm_921a - cp $1 - jr z, .asm_921f - cp $2 - jr z, .asm_9236 - ret - -.asm_921a - ld de, $c292 - jr .asm_9222 - -.asm_921f - ld de, $c29a -.asm_9222 - ld l, c - ld h, $0 - add hl, hl - add hl, hl - ld bc, $6d2d - add hl, bc - ld bc, $4 - call CopyBytes - ld a, $1 - ldh [hCGBPalUpdate], a - ret - -.asm_9236 - ld e, c - inc e - hlcoord 11, 1, wAttrmap - ld bc, 2 * SCREEN_WIDTH - ld a, [wCurPartyMon] -.asm_9241 - and a - jr z, .asm_9248 - add hl, bc - dec a - jr .asm_9241 - -.asm_9248 - lb bc, 2, 8 - ld a, e - call Function9af1 - ret - -LoadStatsScreenPals: - call CheckCGB - ret z - ld hl, StatsScreenPals ; $54eb - ld b, $0 - dec c - add hl, bc - add hl, bc - ld a, [hli] - ld [wTempBGPals], a - ld [wTempBGPals + $10], a - ld a, [hl] - ld [wTempBGPals + 1], a - ld [wTempBGPals + $11], a - call Function9b28 - ld a, $1 - ldh [hCGBPalUpdate], a - ret - -LoadMailPalettes: - ld l, e - ld h, $0 - add hl, hl - add hl, hl - add hl, hl - ld de, .MailPals - add hl, de - call CheckCGB - jr nz, .asm_92ae - push hl - ld hl, PalPacket_a155 - ld de, wcca9 - ld bc, $10 - call CopyBytes - pop hl - inc hl - inc hl - ld a, [hli] - ld [wccac], a - ld a, [hli] - ld [wccad], a - ld a, [hli] - ld [wccae], a - ld a, [hli] - ld [wccaf], a - ld hl, wcca9 - call PushSGBPals_ - ld hl, BlkPacket_9ee5 - call PushSGBPals_ - ret - -.asm_92ae - ld de, wTempBGPals - ld bc, $8 - call CopyBytes - call Function9b28 - call Function9b1d - call Function9b35 - ret - -.MailPals: - RGB 20, 31, 11 - RGB 31, 19, 00 - RGB 31, 10, 09 - RGB 00, 00, 00 - - RGB 15, 20, 31 - RGB 30, 26, 00 - RGB 31, 12, 00 - RGB 00, 00, 00 - - RGB 24, 17, 31 - RGB 30, 26, 00 - RGB 08, 11, 31 - RGB 00, 00, 00 - - RGB 31, 25, 17 - RGB 31, 18, 04 - RGB 28, 12, 05 - RGB 00, 00, 00 - - RGB 19, 26, 31 - RGB 31, 05, 08 - RGB 31, 09, 31 - RGB 00, 00, 00 - - RGB 31, 19, 28 - RGB 31, 21, 00 - RGB 12, 22, 00 - RGB 00, 00, 00 - - RGB 19, 17, 23 - RGB 30, 26, 00 - RGB 31, 12, 00 - RGB 00, 00, 00 - - RGB 07, 26, 31 - RGB 26, 26, 27 - RGB 31, 11, 11 - RGB 00, 00, 00 - - RGB 21, 31, 21 - RGB 30, 26, 00 - RGB 31, 12, 00 - RGB 00, 00, 00 - - RGB 07, 26, 31 - RGB 31, 31, 00 - RGB 00, 21, 00 - RGB 00, 00, 00 - -INCLUDE "predef/cgb.asm" - -Function9a94: ; 9a94 (2:5a94) - ld hl, Palettes_9aaa - ld de, wTempBGPals - ld bc, $8 - call CopyBytes - call Function9b28 - call Function9b1d - call Function9b35 - ret - -Palettes_9aaa: - RGB 31, 31, 31 - RGB 9, 31, 31 - RGB 10, 12, 31 - RGB 0, 3, 19 - -Function9ab2: ; 9ab2 (2:5ab2) - ld de, wTempBGPals - ld c, $4 -Function9ab7: ; 9ab7 (2:5ab7) - push bc - ld a, [hli] - push hl - call Function9ac7 - call Function9ad2 - pop hl - inc hl - pop bc - dec c - jr nz, Function9ab7 - ret - -Function9ac7: ; 9ac7 (2:5ac7) - ld l, a - ld h, $0 - add hl, hl - add hl, hl - add hl, hl - ld bc, Palettes_a265 - add hl, bc - ret - -Function9ad2: ; 9ad2 (2:5ad2) - ld c, $8 -.asm_9ad4 - ld a, [hli] - ld [de], a - inc de - dec c - jr nz, .asm_9ad4 - ret - -Function9adb: ; 9adb (2:5adb) - ld a, $ff - ld [de], a - inc de - ld a, $7f - ld [de], a - inc de - ld c, $4 -.asm_9ae5 - ld a, [hli] - ld [de], a - inc de - dec c - jr nz, .asm_9ae5 - xor a - ld [de], a - inc de - ld [de], a - inc de - ret - -Function9af1: ; 9af1 (2:5af1) - push bc - push hl -.asm_9af3 - ld [hli], a - dec c - jr nz, .asm_9af3 - pop hl - ld bc, $14 - add hl, bc - pop bc - dec b - jr nz, Function9af1 - ret - -Function9b01: ; 9b01 (2:5b01) - push af - push bc - push de - push hl - ld hl, wTempBGPals - ld c, $8 -.asm_9b0a - ld a, $ff - ld [hli], a - ld [hli], a - ld [hli], a - ld [hli], a - xor a - ld [hli], a - ld [hli], a - ld [hli], a - ld [hli], a - dec c - jr nz, .asm_9b0a - pop hl - pop de - pop bc - pop af - ret - -Function9b1d: ; 9b1d (2:5b1d) - hlcoord 0, 0, wAttrmap - ld bc, SCREEN_HEIGHT * SCREEN_WIDTH - xor a - call ByteFill - ret - -Function9b28: ; 9b28 (2:5b28) - ld hl, wTempBGPals - ld de, wBGPals - ld bc, $80 - call CopyBytes - ret - -Function9b35: ; 9b35 (2:5b35) - ldh a, [rLCDC] - bit 7, a - jr z, .asm_9b52 - ldh a, [hBGMapMode] - push af - ld a, $2 - ldh [hBGMapMode], a - call DelayFrame - call DelayFrame - call DelayFrame - call DelayFrame - pop af - ldh [hBGMapMode], a - ret - -.asm_9b52 - hlcoord 0, 0, wAttrmap - ld de, $9800 - ld b, $12 - ld a, $1 - ldh [rVBK], a -.asm_9b5e - ld c, $14 -.asm_9b60 - ld a, [hli] - ld [de], a - inc de - dec c - jr nz, .asm_9b60 - ld a, $c - add e - jr nc, .asm_9b6c - inc d -.asm_9b6c - ld e, a - dec b - jr nz, .asm_9b5e - ld a, $0 - ldh [rVBK], a - ret - -Function9b75: ; 9b75 (2:5b75) - ld hl, wcc9b - ld a, [wcca9] - ld e, a - ld d, $0 - add hl, de - ld e, l - ld d, h - ld a, [de] - inc a - ld e, a - hlcoord 11, 2, wAttrmap - ld bc, $28 - ld a, [wcca9] -.asm_9b8d - and a - jr z, .asm_9b94 - add hl, bc - dec a - jr .asm_9b8d - -.asm_9b94 - lb bc, 2, 8 - ld a, e - call Function9af1 - ret - -Function9b9c: ; 9b9c (2:5b9c) - ld hl, Palettes_bac6 - ld de, wTempOBPal0 - ld bc, $10 - call CopyBytes - ret - -Function9ba9: ; 9ba9 (2:5ba9) - push de - farcall Function3d8f5 - ld c, l - ld b, h - ld a, [wd0ee] - call Function9bcb - pop de - ret - -Function9bba: ; 9bba (2:5bba) - push de - farcall Function3d907 - ld c, l - ld b, h - ld a, [wTempEnemyMonSpecies] - call Function9bd3 - pop de - ret - -Function9bcb: ; 9bcb (2:5bcb) - and a - jp nz, Function9c66 - ld hl, TrainerPalettes - ret - -Function9bd3: ; 9bd3 (2:5bd3) - and a - jp nz, Function9c66 - ld a, [wTrainerClass] -Function9bda: ; 9bda (2:5bda) - ld l, a - ld h, $0 - add hl, hl - add hl, hl - ld bc, TrainerPalettes - add hl, bc - ret - -Function9be4: ; 9be4 (2:5be4) - call Function9c5b - ret - -Function9be8: - ret - -Function9be9: - call CheckCGB - ret z - ld hl, Palettes_9c09 - ld a, $90 - ldh [rOBPI], a - ld c, $30 -.asm_9bf6 - ld a, [hli] - ldh [rOBPD], a - dec c - jr nz, .asm_9bf6 - ld hl, Palettes_9c09 - ld de, wTempOBPal2 - ld bc, $10 - call CopyBytes - ret - -Palettes_9c09: - RGB 31, 31, 31 - RGB 25, 25, 25 - RGB 13, 13, 13 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 31, 31, 7 - RGB 31, 16, 1 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 31, 19, 24 - RGB 30, 10, 6 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 12, 25, 1 - RGB 5, 14, 0 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 8, 12, 31 - RGB 1, 4, 31 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 24, 18, 7 - RGB 20, 15, 3 - RGB 0, 0, 0 - -Function9c39: - call CheckCGB - ret z - ld a, $90 - ldh [rOBPI], a - ld a, $1c - call Function9ac7 - call Function9c52 - ld a, $21 - call Function9ac7 - call Function9c52 - ret - -Function9c52: ; 9c52 (2:5c52) - ld c, $8 -.asm_9c54 - ld a, [hli] - ldh [rOBPD], a - dec c - jr nz, .asm_9c54 - ret - -Function9c5b: ; 9c5b (2:5c5b) - ld l, a - ld h, $0 - add hl, hl - add hl, hl - add hl, hl - ld bc, PokemonPalettes - add hl, bc - ret - -Function9c66: ; 9c66 (2:5c66) - push bc - call Function9c5b - pop bc - push hl - call CheckShininess - pop hl - ret nc - inc hl - inc hl - inc hl - inc hl - ret - -PushSGBPals_: ; 9c76 (2:5c76) - ld a, [wd8ba] - push af - set 7, a - ld [wd8ba], a - call Function9c87 - pop af - ld [wd8ba], a - ret - -Function9c87: ; 9c87 (2:5c87) - ld a, [hl] - and $7 - ret z - ld b, a -.asm_9c8c - push bc - xor a - ldh [rJOYP], a - ld a, $30 - ldh [rJOYP], a - ld b, $10 -.asm_9c96 - ld e, $8 - ld a, [hli] - ld d, a -.asm_9c9a - bit 0, d - ld a, $10 - jr nz, .asm_9ca2 - ld a, $20 -.asm_9ca2 - ldh [rJOYP], a - ld a, $30 - ldh [rJOYP], a - rr d - dec e - jr nz, .asm_9c9a - dec b - jr nz, .asm_9c96 - ld a, $20 - ldh [rJOYP], a - ld a, $30 - ldh [rJOYP], a - call Function9ed9 - pop bc - dec b - jr nz, .asm_9c8c - ret - -InitSGBBorder: ; 9cc0 (2:5cc0) - call CheckCGB - ret nz - di - ld a, [wd8ba] - push af - set 7, a - ld [wd8ba], a - xor a - ldh [rJOYP], a - ldh [hSGB], a - call Function9da9 - jr nc, .asm_9cf7 - ld a, $1 - ldh [hSGB], a - call Function9d4a - call Function9e13 - call Function9ed9 - call Function9d9e - call Function9d8b - call Function9ed9 - call Function9d9e - ld hl, PalPacket_a1d5 - call Function9c87 -.asm_9cf7 - pop af - ld [wd8ba], a - ei - ret - -InitCGBPals:: ; 9cfd (2:5cfd) - call CheckCGB - ret z - ld a, $1 - ldh [rVBK], a - ld hl, $8000 - ld bc, $2000 - xor a - call ByteFill - ld a, $0 - ldh [rVBK], a - ld a, $80 - ldh [rBGPI], a - ld c, $20 -.asm_9d19 - ld a, $ff - ldh [rBGPD], a - ld a, $7f - ldh [rBGPD], a - dec c - jr nz, .asm_9d19 - ld a, $80 - ldh [rOBPI], a - ld c, $20 -.asm_9d2a - ld a, $ff - ldh [rOBPD], a - ld a, $7f - ldh [rOBPD], a - dec c - jr nz, .asm_9d2a - ld hl, wTempBGPals - call Function9d3e - ld hl, wBGPals -Function9d3e: ; 9d3e (2:5d3e) - ld c, $40 -.asm_9d40 - ld a, $ff - ld [hli], a - ld a, $7f - ld [hli], a - dec c - jr nz, .asm_9d40 - ret - -Function9d4a: ; 9d4a (2:5d4a) - ld hl, .Pointers - ld c, $9 -.asm_9d4f - push bc - ld a, [hli] - push hl - ld h, [hl] - ld l, a - call Function9c87 - pop hl - inc hl - pop bc - dec c - jr nz, .asm_9d4f - ret - -.Pointers: - dw PalPacket_a1c5 - dw PalPacket_a1e5 - dw PalPacket_a1f5 - dw PalPacket_a205 - dw PalPacket_a215 - dw PalPacket_a225 - dw PalPacket_a235 - dw PalPacket_a245 - dw PalPacket_a255 - -Function9d70: - di - xor a - ldh [rJOYP], a - ld hl, PalPacket_a1c5 - call Function9c87 - call Function9d8b - call Function9ed9 - call Function9d9e - ld hl, PalPacket_a1d5 - call Function9c87 - ei - ret - -Function9d8b: ; 9d8b (2:5d8b) - call Function9d97 - push de - call Function9e83 - pop hl - call Function9e37 - ret - -Function9d97: ; 9d97 (2:5d97) - ld hl, SGBBorder - ld de, SGBBorderMap - ret - -Function9d9e: ; 9d9e (2:5d9e) - ld hl, $8000 - ld bc, $2000 - xor a - call ByteFill - ret - -Function9da9: ; 9da9 (2:5da9) - ld hl, PalPacket_a195 - call Function9c87 - call Function9ed9 - ldh a, [rJOYP] - and $3 - cp $3 - jr nz, .asm_9e05 - ld a, $20 - ldh [rJOYP], a - ldh a, [rJOYP] - ldh a, [rJOYP] - call Function9ed9 - call Function9ed9 - ld a, $30 - ldh [rJOYP], a - call Function9ed9 - call Function9ed9 - ld a, $10 - ldh [rJOYP], a - ldh a, [rJOYP] - ldh a, [rJOYP] - ldh a, [rJOYP] - ldh a, [rJOYP] - ldh a, [rJOYP] - ldh a, [rJOYP] - call Function9ed9 - call Function9ed9 - ld a, $30 - ldh [rJOYP], a - ldh a, [rJOYP] - ldh a, [rJOYP] - ldh a, [rJOYP] - call Function9ed9 - call Function9ed9 - ldh a, [rJOYP] - and $3 - cp $3 - jr nz, .asm_9e05 - call Function9e0a - and a - ret - -.asm_9e05 - call Function9e0a - scf - ret - -Function9e0a: ; 9e0a (2:5e0a) - ld hl, PalPacket_a185 - call Function9c87 - jp Function9ed9 - -Function9e13: ; 9e13 (2:5e13) - call DisableLCD - ld a, $e4 - ldh [rBGP], a - ld hl, Palettes_a265 - ld de, $8800 - ld bc, $1000 - call Function9eb1 - call Function9ec3 - ld a, $e3 - ldh [rLCDC], a - ld hl, PalPacket_a175 - call Function9c87 - xor a - ldh [rBGP], a - ret - -Function9e37: ; 9e37 (2:5e37) - call DisableLCD - ld a, $e4 - ldh [rBGP], a - ld de, $8800 - ld bc, $140 - call Function9eb1 - ld b, $12 -.asm_9e49 - push bc - ld bc, $c - call Function9eb1 - ld bc, $28 - call Function9eba - ld bc, $c - call Function9eb1 - pop bc - dec b - jr nz, .asm_9e49 - ld bc, $140 - call Function9eb1 - ld bc, $100 - call Function9eba - ld bc, $80 - call Function9eb1 - call Function9ec3 - ld a, $e3 - ldh [rLCDC], a - ld hl, PalPacket_a1b5 - call Function9c87 - xor a - ldh [rBGP], a - ret - -Function9e83: ; 9e83 (2:5e83) - call DisableLCD - ld a, $e4 - ldh [rBGP], a - ld de, $8800 - ld b, $80 -.asm_9e8f - push bc - ld bc, $10 - call Function9eb1 - ld bc, $10 - call Function9eba - pop bc - dec b - jr nz, .asm_9e8f - call Function9ec3 - ld a, $e3 - ldh [rLCDC], a - ld hl, PalPacket_a1a5 - call Function9c87 - xor a - ldh [rBGP], a - ret - -Function9eb1: ; 9eb1 (2:5eb1) - ld a, [hli] - ld [de], a - inc de - dec bc - ld a, c - or b - jr nz, Function9eb1 - ret - -Function9eba: ; 9eba (2:5eba) - xor a - ld [de], a - inc de - dec bc - ld a, c - or b - jr nz, Function9eba - ret - -Function9ec3: ; 9ec3 (2:5ec3) - ld hl, $9800 - ld de, $c - ld a, $80 - ld c, $d -.asm_9ecd - ld b, $14 -.asm_9ecf - ld [hli], a - inc a - dec b - jr nz, .asm_9ecf - add hl, de - dec c - jr nz, .asm_9ecd - ret - -Function9ed9: ; 9ed9 (2:5ed9) - ld de, 7000 -.asm_9edc - nop - nop - nop - dec de - ld a, d - or e - jr nz, .asm_9edc - ret - -BlkPacket_9ee5: db $21, $01, $03, $00, $00, $00, $13, $11, $00, $00, $00, $00, $00, $00, $00, $00 -BlkPacket_9ef5: db $21, $01, $07, $05, $00, $0a, $13, $0d, $00, $00, $00, $00, $00, $00, $00, $00 -BlkPacket_9f05: db $22, $05, $07, $0a, $00, $0c, $13, $11, $03, $05, $01, $00, $0a, $03, $03, $00 -BlkPacket_9f15: db $0a, $08, $13, $0a, $03, $0a, $00, $04, $08, $0b, $03, $0f, $0b, $00, $13, $07 -BlkPacket_9f25: db $21, $01, $07, $05, $00, $00, $06, $06, $00, $00, $00, $00, $00, $00, $00, $00 -BlkPacket_9f35: db $21, $01, $06, $05, $0b, $01, $13, $02, $00, $00, $00, $00, $00, $00, $00, $00 -BlkPacket_9f45: db $21, $01, $07, $05, $00, $01, $07, $07, $00, $00, $00, $00, $00, $00, $00, $00 -BlkPacket_9f55: db $21, $01, $07, $05, $01, $04, $07, $0a, $00, $00, $00, $00, $00, $00, $00, $00 -BlkPacket_9f65: db $21, $01, $07, $05, $01, $01, $05, $05, $00, $00, $00, $00, $00, $00, $00, $00 -BlkPacket_9f75: db $21, $01, $07, $05, $07, $05, $0d, $0b, $00, $00, $00, $00, $00, $00, $00, $00 -BlkPacket_9f85: db $22, $05, $03, $05, $00, $00, $13, $0b, $03, $0a, $00, $04, $13, $09, $02, $0f -BlkPacket_9f95: db $00, $06, $13, $07, $03, $00, $04, $04, $0f, $09, $03, $00, $00, $0c, $13, $11 -BlkPacket_9fa5: db $23, $07, $07, $10, $00, $00, $02, $0c, $02, $00, $0c, $01, $12, $02, $02, $00 -BlkPacket_9fb5: db $0c, $03, $12, $04, $02, $00, $0c, $05, $12, $06, $02, $00, $0c, $07, $12, $08 -BlkPacket_9fc5: db $02, $00, $0c, $09, $12, $0a, $02, $00, $0c, $0b, $12, $0c, $00, $00, $00, $00 -BlkPacket_9fd5: db $21, $02, $07, $30, $00, $00, $13, $06, $02, $04, $05, $06, $0e, $06, $00, $00 -BlkPacket_9fe5: db $21, $01, $07, $10, $00, $00, $13, $05, $00, $00, $00, $00, $00, $00, $00, $00 -BlkPacket_9ff5: db $21, $02, $07, $0a, $00, $04, $13, $0d, $03, $05, $00, $06, $13, $0b, $00, $00 - -PalPacket_a005: - db $51 - RGB 8, 2, 0 - RGB 9, 2, 0 - RGB 10, 2, 0 - RGB 11, 2, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a015: - db $51 - RGB 11, 1, 0 - RGB 4, 1, 0 - RGB 0, 1, 0 - RGB 0, 0, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a025: - db $51 - RGB 1, 2, 0 - RGB 2, 2, 0 - RGB 3, 2, 0 - RGB 4, 2, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a035: - db $51 - RGB 12, 2, 0 - RGB 12, 2, 0 - RGB 12, 2, 0 - RGB 12, 2, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a045: - db $51 - RGB 0, 0, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a055: - db $51 - RGB 22, 1, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a065: - db $51 - RGB 23, 1, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a075: - db $51 - RGB 24, 1, 0 - RGB 25, 1, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a085: - db $51 - RGB 26, 1, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a095: - db $51 - RGB 27, 1, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a0a5: - db $51 - RGB 28, 1, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a0b5: - db $51 - RGB 25, 1, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a0c5: - db $51 - RGB 14, 1, 0 - RGB 15, 1, 0 - RGB 16, 1, 0 - RGB 17, 1, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a0d5: - db $51 - RGB 26, 0, 0 - RGB 26, 0, 0 - RGB 26, 0, 0 - RGB 26, 0, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a0e5: - db $51 - RGB 18, 1, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a0f5: - db $51 - RGB 28, 1, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a105: - db $51 - RGB 29, 1, 0 - RGB 30, 1, 0 - RGB 31, 1, 0 - RGB 0, 2, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a115: - db $51 - RGB 19, 1, 0 - RGB 20, 1, 0 - RGB 27, 0, 0 - RGB 31, 0, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a125: - db $51 - RGB 27, 0, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a135: - db $51 - RGB 28, 0, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a145: - db $51 - RGB 21, 1, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - RGB 0, 0, 0 - db $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a155: db $01, $ff, $7f, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 -PalPacket_a165: db $09, $ff, $7f, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 -PalPacket_a175: db $59, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 -PalPacket_a185: db $89, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 -PalPacket_a195: db $89, $01, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 -PalPacket_a1a5: db $99, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 -PalPacket_a1b5: db $a1, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 - -PalPacket_a1c5: db $b9, $01, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 -PalPacket_a1d5: db $b9, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 -PalPacket_a1e5: db $79, $5d, $08, $00, $0b, $8c, $d0, $f4, $60, $00, $00, $00, $00, $00, $00, $00 -PalPacket_a1f5: db $79, $52, $08, $00, $0b, $a9, $e7, $9f, $01, $c0, $7e, $e8, $e8, $e8, $e8, $e0 -PalPacket_a205: db $79, $47, $08, $00, $0b, $c4, $d0, $16, $a5, $cb, $c9, $05, $d0, $10, $a2, $28 -PalPacket_a215: db $79, $3c, $08, $00, $0b, $f0, $12, $a5, $c9, $c9, $c8, $d0, $1c, $a5, $ca, $c9 -PalPacket_a225: db $79, $31, $08, $00, $0b, $0c, $a5, $ca, $c9, $7e, $d0, $06, $a5, $cb, $c9, $7e -PalPacket_a235: db $79, $26, $08, $00, $0b, $39, $cd, $48, $0c, $d0, $34, $a5, $c9, $c9, $80, $d0 -PalPacket_a245: db $79, $1b, $08, $00, $0b, $ea, $ea, $ea, $ea, $ea, $a9, $01, $cd, $4f, $0c, $d0 -PalPacket_a255: db $79, $10, $08, $00, $0b, $4c, $20, $08, $ea, $ea, $ea, $ea, $ea, $60, $ea, $ea - -IF DEF(GOLD) -Palettes_a265: INCLUDE "gfx/pals/gold_a265.pal" -ENDC -IF DEF(SILVER) -Palettes_a265: INCLUDE "gfx/pals/silver_a265.pal" -ENDC - -IF DEF(GOLD) -SGBBorderMap: INCBIN "gfx/sgb_border/gold.map" -SGBBorderPalettes: INCLUDE "gfx/sgb_border/pals/gold.pal" -SGBBorder: INCBIN "gfx/sgb_border/gold.2bpp" -ENDC - -IF DEF(SILVER) -SGBBorderMap: INCBIN "gfx/sgb_border/silver.map" -SGBBorderPalettes: INCLUDE "gfx/sgb_border/pals/silver.pal" -SGBBorder: INCBIN "gfx/sgb_border/silver.2bpp" -ENDC - -Palettes_ad2d: - RGB 30, 26, 15 - RGB 00, 23, 00 - - RGB 30, 26, 15 - RGB 31, 21, 00 - - RGB 30, 26, 15 - RGB 31, 00, 00 - -Palettes_ad39: - RGB 30, 26, 15 - RGB 04, 17, 31 - -INCLUDE "gfx/pics/palette_pointers.asm" -INCLUDE "gfx/trainers/palette_pointers.asm" - -Functionb649: ; b649 (2:7649) - ld a, [wPermission] - and $7 - ld e, a - ld d, $0 - ld hl, Pointers_b6ce - add hl, de - add hl, de - ld a, [hli] - ld h, [hl] - ld l, a - ld a, [wTimeOfDayPal] - and $3 - add a - add a - add a - ld e, a - ld d, $0 - add hl, de - ld e, l - ld d, h - ld hl, wTempBGPals - ld b, $8 -.asm_b66c - ld a, [de] - push de - push hl - ld l, a - ld h, $0 - add hl, hl - add hl, hl - add hl, hl - ld de, $775e - add hl, de - ld e, l - ld d, h - pop hl - ld c, $8 -.asm_b67e - ld a, [de] - inc de - ld [hli], a - dec c - jr nz, .asm_b67e - pop de - inc de - dec b - jr nz, .asm_b66c - ld a, [wTimeOfDayPal] - and $3 - ld bc, $40 - ld hl, MapObjectPals - call AddNTimes - ld de, wTempOBPal0 - ld bc, $40 - call CopyBytes - ld a, [wPermission] - cp $1 - jr z, .asm_b6aa - cp $2 - ret nz -.asm_b6aa - ld a, [wMapGroup] - ld l, a - ld h, $0 - add hl, hl - add hl, hl - add hl, hl - ld de, RoofPals - add hl, de - ld a, [wTimeOfDayPal] - and $3 - cp $2 - jr c, .asm_b6c4 - inc hl - inc hl - inc hl - inc hl -.asm_b6c4 - ld de, wTempBGPal6 + 2 - ld bc, $4 - call CopyBytes - ret - -Pointers_b6ce: - dw .OutdoorColors ; unused - dw .OutdoorColors ; TOWN - dw .OutdoorColors ; ROUTE - dw .IndoorColors ; INDOOR - dw .DungeonColors ; CAVE - dw .Perm5Colors ; ENVIRONMENT_5 - dw .IndoorColors ; GATE - dw .DungeonColors ; DUNGEON - -; Valid indices: $00 - $29 -.OutdoorColors: - db $00, $01, $02, $28, $04, $05, $06, $07 ; morn - db $08, $09, $0a, $28, $0c, $0d, $0e, $0f ; day - db $10, $11, $12, $29, $14, $15, $16, $17 ; nite - db $18, $19, $1a, $1b, $1c, $1d, $1e, $1f ; dark - -.IndoorColors: - db $20, $21, $22, $23, $24, $25, $26, $07 ; morn - db $20, $21, $22, $23, $24, $25, $26, $07 ; day - db $10, $11, $12, $13, $14, $15, $16, $07 ; nite - db $18, $19, $1a, $1b, $1c, $1d, $1e, $07 ; dark - -.DungeonColors: - db $00, $01, $02, $03, $04, $05, $06, $07 ; morn - db $08, $09, $0a, $0b, $0c, $0d, $0e, $0f ; day - db $10, $11, $12, $13, $14, $15, $16, $17 ; nite - db $18, $19, $1a, $1b, $1c, $1d, $1e, $1f ; dark - -.Perm5Colors: - db $00, $01, $02, $03, $04, $05, $06, $07 ; morn - db $08, $09, $0a, $0b, $0c, $0d, $0e, $0f ; day - db $10, $11, $12, $13, $14, $15, $16, $17 ; nite - db $18, $19, $1a, $1b, $1c, $1d, $1e, $1f ; dark - -TilesetBGPalette: ; b75e -INCLUDE "gfx/tilesets/bg.pal" - -MapObjectPals:: ; b8ae -INCLUDE "gfx/tilesets/ob.pal" - -RoofPals: ; b9ae -INCLUDE "gfx/tilesets/roof.pal" - -Palettes_ba86: - RGB 27, 31, 27 - RGB 21, 21, 21 - RGB 13, 13, 13 - RGB 00, 00, 00 - - RGB 27, 31, 27 - RGB 31, 07, 06 - RGB 20, 02, 03 - RGB 00, 00, 00 - - RGB 27, 31, 27 - RGB 10, 31, 09 - RGB 04, 14, 01 - RGB 00, 00, 00 - - RGB 27, 31, 27 - RGB 08, 12, 31 - RGB 01, 04, 31 - RGB 00, 00, 00 - - RGB 27, 31, 27 - RGB 31, 31, 07 - RGB 31, 16, 01 - RGB 00, 00, 00 - - RGB 27, 31, 27 - RGB 22, 16, 08 - RGB 13, 07, 01 - RGB 00, 00, 00 - - RGB 27, 31, 27 - RGB 15, 31, 31 - RGB 05, 17, 31 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 11, 11, 19 - RGB 07, 07, 12 - RGB 00, 00, 00 - -Palettes_bac6: - RGB 27, 31, 27 - RGB 31, 19, 10 - RGB 31, 07, 04 - RGB 00, 00, 00 - - RGB 27, 31, 27 - RGB 31, 19, 10 - RGB 10, 14, 20 - RGB 00, 00, 00 - - RGB 27, 31, 27 - RGB 31, 19, 10 - RGB 31, 07, 04 - RGB 00, 00, 00 - - RGB 27, 31, 27 - RGB 31, 19, 10 - RGB 31, 07, 04 - RGB 00, 00, 00 - - RGB 27, 31, 27 - RGB 31, 19, 10 - RGB 31, 07, 04 - RGB 00, 00, 00 - - RGB 27, 31, 27 - RGB 31, 19, 10 - RGB 31, 07, 04 - RGB 00, 00, 00 - - RGB 27, 31, 27 - RGB 31, 19, 10 - RGB 31, 07, 04 - RGB 00, 00, 00 - - RGB 27, 31, 27 - RGB 31, 19, 10 - RGB 31, 07, 04 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 21, 21, 21 - RGB 13, 13, 13 - RGB 07, 07, 07 - - RGB 31, 31, 31 - RGB 31, 31, 07 - RGB 31, 16, 01 - RGB 07, 07, 07 - - RGB 31, 31, 31 - RGB 31, 19, 24 - RGB 30, 10, 06 - RGB 07, 07, 07 - - RGB 31, 31, 31 - RGB 12, 25, 01 - RGB 05, 14, 00 - RGB 07, 07, 07 - - RGB 31, 31, 31 - RGB 08, 12, 31 - RGB 01, 04, 31 - RGB 07, 07, 07 - - RGB 31, 31, 31 - RGB 24, 18, 07 - RGB 20, 15, 03 - RGB 07, 07, 07 - -Palettes_bb36: -IF DEF(GOLD) - RGB 31, 31, 31 - RGB 18, 23, 31 - RGB 15, 20, 31 - RGB 0, 0, 0 - - RGB 31, 21, 0 - RGB 12, 14, 12 - RGB 15, 20, 31 - RGB 0, 0, 17 - - RGB 31, 31, 31 - RGB 31, 0, 0 - RGB 15, 20, 31 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 29, 25, 0 - RGB 15, 20, 31 - RGB 17, 10, 1 - - RGB 31, 31, 31 - RGB 23, 26, 31 - RGB 18, 23, 31 - RGB 0, 0, 0 -ENDC - -IF DEF(SILVER) - RGB 31, 31, 31 - RGB 0, 12, 15 - RGB 4, 8, 21 - RGB 0, 0, 0 - - RGB 31, 21, 0 - RGB 15, 17, 15 - RGB 4, 8, 21 - RGB 0, 0, 17 - - RGB 31, 31, 31 - RGB 31, 0, 0 - RGB 4, 8, 21 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 24, 23, 25 - RGB 4, 8, 21 - RGB 8, 8, 9 - - RGB 31, 31, 31 - RGB 5, 10, 11 - RGB 0, 12, 15 - RGB 0, 0, 0 -ENDC - -Palettes_bb5e: - RGB 31, 31, 31 - RGB 07, 06, 03 - RGB 07, 06, 03 - RGB 07, 06, 03 - - RGB 31, 31, 31 - RGB 31, 31, 00 - RGB 26, 22, 00 - RGB 00, 00, 00 - -Palettes_bb6e: - RGB 28, 31, 20 - RGB 21, 21, 21 - RGB 13, 13, 13 - RGB 00, 00, 00 - - RGB 28, 31, 20 - RGB 00, 31, 00 - RGB 00, 00, 31 - RGB 00, 00, 00 - - RGB 28, 31, 20 - RGB 00, 31, 00 - RGB 15, 07, 00 - RGB 00, 00, 00 - - RGB 28, 31, 20 - RGB 31, 15, 00 - RGB 15, 07, 00 - RGB 00, 00, 00 - - RGB 28, 31, 20 - RGB 00, 31, 00 - RGB 00, 00, 31 - RGB 31, 00, 00 - - RGB 28, 31, 20 - RGB 00, 31, 00 - RGB 15, 07, 00 - RGB 31, 00, 00 - -Palettes_bb9e: - RGB 31, 31, 31 - RGB 30, 22, 24 - RGB 18, 18, 18 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 10, 11, 31 - RGB 18, 18, 18 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 12, 31, 11 - RGB 18, 18, 18 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 29, 26, 05 - RGB 18, 18, 18 - RGB 00, 00, 00 - -Palettes_bbbe: -IF DEF(GOLD) - RGB 31, 31, 31 - RGB 24, 25, 28 - RGB 24, 24, 09 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 30, 10, 06 - RGB 24, 24, 09 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 15, 31, 00 - RGB 24, 24, 09 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 31, 15, 31 - RGB 24, 24, 09 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 15, 21, 31 - RGB 24, 24, 09 - RGB 00, 00, 00 - - RGB 31, 31, 11 - RGB 31, 31, 06 - RGB 24, 24, 09 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 16, 19, 29 - RGB 25, 22, 00 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 21, 21, 21 - RGB 13, 13, 13 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 30, 10, 06 - RGB 31, 00, 00 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 12, 25, 01 - RGB 05, 14, 00 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 12, 25, 01 - RGB 30, 10, 06 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 31, 31, 06 - RGB 20, 15, 03 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 31, 31, 06 - RGB 15, 21, 31 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 31, 31, 06 - RGB 20, 15, 03 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 31, 24, 21 - RGB 31, 13, 31 - RGB 00, 00, 00 - - RGB 31, 31, 31 - RGB 31, 31, 31 - RGB 00, 00, 00 - RGB 00, 00, 00 -ENDC - -IF DEF(SILVER) - RGB 31, 31, 31 - RGB 25, 26, 14 - RGB 20, 17, 31 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 30, 10, 6 - RGB 20, 17, 31 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 15, 31, 0 - RGB 20, 17, 31 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 31, 15, 31 - RGB 20, 17, 31 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 15, 21, 31 - RGB 20, 17, 31 - RGB 0, 0, 0 - - RGB 31, 31, 11 - RGB 31, 31, 6 - RGB 20, 17, 31 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 16, 19, 29 - RGB 25, 22, 0 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 21, 21, 21 - RGB 13, 13, 13 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 30, 10, 6 - RGB 31, 0, 0 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 12, 25, 1 - RGB 5, 14, 0 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 12, 25, 1 - RGB 30, 10, 6 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 31, 31, 6 - RGB 20, 15, 3 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 31, 31, 6 - RGB 15, 21, 31 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 31, 31, 6 - RGB 20, 15, 3 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 31, 24, 21 - RGB 31, 13, 31 - RGB 0, 0, 0 - - RGB 31, 31, 31 - RGB 31, 31, 31 - RGB 0, 0, 0 - RGB 0, 0, 0 -ENDC diff --git a/engine/engine_flags.asm b/engine/engine_flags.asm deleted file mode 100755 index 9fa5f8c0..00000000 --- a/engine/engine_flags.asm +++ /dev/null @@ -1,195 +0,0 @@ -EngineFlagAction:: ; c01b -; Do action b on engine flag de -; -; b = 0: reset flag -; = 1: set flag -; > 1: check flag, result in c -; -; Setting/resetting does not return a result. - - -; 16-bit flag ids are considered invalid, but it's nice -; to know that the infrastructure is there. - - ld a, d - cp 0 - jr z, .ceiling - jr c, .read ; cp 0 can't set carry! - jr .invalid - -; There are only $a2 engine flags, so -; anything beyond that is invalid too. - -.ceiling - ld a, e - cp NUM_ENGINE_FLAGS - jr c, .read - -; Invalid flags are treated as flag 00. - -.invalid - xor a - ld e, a - ld d, a - -; Get this flag's location. - -.read - ld hl, EngineFlags -; location - add hl, de - add hl, de -; bit - add hl, de - -; location - ld e, [hl] - inc hl - ld d, [hl] - inc hl -; bit - ld c, [hl] - -; What are we doing with this flag? - - ld a, b - cp 1 - jr c, .reset ; b = 0 - jr z, .set ; b = 1 - -; Return the given flag in c. -.check - ld a, [de] - and c - ld c, a - ret - -; Set the given flag. -.set - ld a, [de] - or c - ld [de], a - ret - -; Reset the given flag. -.reset - ld a, c - cpl ; AND all bits except the one in question - ld c, a - ld a, [de] - and c - ld [de], a - ret - -; 404d -EngineFlags: -; All locations are in WRAM bank 1. - - ; location, bit - engine_flag ENGINE_RADIO_CARD - engine_flag ENGINE_MAP_CARD - engine_flag ENGINE_PHONE_CARD - engine_flag ENGINE_EXPN_CARD - engine_flag ENGINE_POKEGEAR - - engine_flag ENGINE_DAY_CARE_MAN_HAS_EGG - engine_flag ENGINE_DAY_CARE_MAN_HAS_MON - - engine_flag ENGINE_DAY_CARE_LADY_HAS_MON - - engine_flag ENGINE_MOM_SAVING_MONEY - engine_flag ENGINE_DST - - engine_flag ENGINE_0A - - engine_flag ENGINE_POKEDEX - engine_flag ENGINE_UNOWN_DEX - engine_flag ENGINE_POKERUS - engine_flag ENGINE_ROCKET_SIGNAL_ON_CH20 - engine_flag ENGINE_CREDITS_SKIP - engine_flag ENGINE_BUG_CONTEST_TIMER - engine_flag ENGINE_SAFARI_ZONE - engine_flag ENGINE_ROCKETS_IN_RADIO_TOWER - engine_flag ENGINE_BIKE_SHOP_CALL_ENABLED - engine_flag ENGINE_GIVE_POKERUS - engine_flag ENGINE_REACHED_GOLDENROD - engine_flag ENGINE_ROCKETS_IN_MAHOGANY - - engine_flag ENGINE_STRENGTH_ACTIVE - engine_flag ENGINE_ALWAYS_ON_BIKE - engine_flag ENGINE_DOWNHILL - - engine_flag ENGINE_ZEPHYRBADGE - engine_flag ENGINE_HIVEBADGE - engine_flag ENGINE_PLAINBADGE - engine_flag ENGINE_FOGBADGE - engine_flag ENGINE_MINERALBADGE - engine_flag ENGINE_STORMBADGE - engine_flag ENGINE_GLACIERBADGE - engine_flag ENGINE_RISINGBADGE - - engine_flag ENGINE_BOULDERBADGE - engine_flag ENGINE_CASCADEBADGE - engine_flag ENGINE_THUNDERBADGE - engine_flag ENGINE_RAINBOWBADGE - engine_flag ENGINE_SOULBADGE - engine_flag ENGINE_MARSHBADGE - engine_flag ENGINE_VOLCANOBADGE - engine_flag ENGINE_EARTHBADGE - - engine_flag ENGINE_UNLOCKED_UNOWNS_A_TO_K - engine_flag ENGINE_UNLOCKED_UNOWNS_L_TO_R - engine_flag ENGINE_UNLOCKED_UNOWNS_S_TO_W - engine_flag ENGINE_UNLOCKED_UNOWNS_X_TO_Z - engine_flag ENGINE_UNLOCKED_UNOWNS_UNUSED_4 - engine_flag ENGINE_UNLOCKED_UNOWNS_UNUSED_5 - engine_flag ENGINE_UNLOCKED_UNOWNS_UNUSED_6 - engine_flag ENGINE_UNLOCKED_UNOWNS_UNUSED_7 - - engine_flag ENGINE_FLYPOINT_PLAYERS_HOUSE - engine_flag ENGINE_FLYPOINT_VIRIDIAN_POKECENTER - engine_flag ENGINE_FLYPOINT_PALLET - engine_flag ENGINE_FLYPOINT_VIRIDIAN - engine_flag ENGINE_FLYPOINT_PEWTER - engine_flag ENGINE_FLYPOINT_CERULEAN - engine_flag ENGINE_FLYPOINT_ROCK_TUNNEL - engine_flag ENGINE_FLYPOINT_VERMILION - engine_flag ENGINE_FLYPOINT_LAVENDER - engine_flag ENGINE_FLYPOINT_SAFFRON - engine_flag ENGINE_FLYPOINT_CELADON - engine_flag ENGINE_FLYPOINT_FUCHSIA - engine_flag ENGINE_FLYPOINT_CINNABAR - engine_flag ENGINE_FLYPOINT_INDIGO_PLATEAU - engine_flag ENGINE_FLYPOINT_NEW_BARK - engine_flag ENGINE_FLYPOINT_CHERRYGROVE - engine_flag ENGINE_FLYPOINT_VIOLET - - engine_flag ENGINE_FLYPOINT_AZALEA - engine_flag ENGINE_FLYPOINT_CIANWOOD - engine_flag ENGINE_FLYPOINT_GOLDENROD - engine_flag ENGINE_FLYPOINT_OLIVINE - engine_flag ENGINE_FLYPOINT_ECRUTEAK - engine_flag ENGINE_FLYPOINT_MAHOGANY - engine_flag ENGINE_FLYPOINT_LAKE_OF_RAGE - engine_flag ENGINE_FLYPOINT_BLACKTHORN - engine_flag ENGINE_FLYPOINT_SILVER_CAVE - - engine_flag ENGINE_FLYPOINT_UNUSED - engine_flag ENGINE_LUCKY_NUMBER_SHOW - engine_flag ENGINE_4E - - engine_flag ENGINE_KURT_MAKING_BALLS - engine_flag ENGINE_DAILY_BUG_CONTEST - engine_flag ENGINE_SPECIAL_WILDDATA - engine_flag ENGINE_TIME_CAPSULE - engine_flag ENGINE_ALL_FRUIT_TREES - engine_flag ENGINE_GOT_SHUCKIE_TODAY - engine_flag ENGINE_GOLDENROD_UNDERGROUND_MERCHANT_CLOSED - engine_flag ENGINE_FOUGHT_IN_TRAINER_HALL_TODAY - - engine_flag ENGINE_MT_MOON_SQUARE_CLEFAIRY - engine_flag ENGINE_UNION_CAVE_LAPRAS - engine_flag ENGINE_GOLDENROD_UNDERGROUND_GOT_HAIRCUT - engine_flag ENGINE_GOLDENROD_DEPT_STORE_TM27_RETURN - engine_flag ENGINE_DAISYS_GROOMING - engine_flag ENGINE_INDIGO_PLATEAU_RIVAL_FIGHT diff --git a/engine/events/bug_contest/caught_mon.asm b/engine/events/bug_contest/caught_mon.asm new file mode 100644 index 00000000..b2cc044a --- /dev/null +++ b/engine/events/bug_contest/caught_mon.asm @@ -0,0 +1,37 @@ +BugContest_SetCaughtContestMon: + ld a, [wContestMon] + and a + jr z, .firstcatch + ld [wNamedObjectIndexBuffer], a + farcall DisplayAlreadyCaughtText + farcall DisplayCaughtContestMonStats + lb bc, 14, 7 + call PlaceYesNoBox + ret c + +.firstcatch + call .generatestats + ld a, [wTempEnemyMonSpecies] + ld [wNamedObjectIndexBuffer], a + call GetPokemonName + ld hl, .ContestCaughtMonText + call PrintText + ret + +.generatestats + ld a, [wTempEnemyMonSpecies] + ld [wCurSpecies], a + ld [wCurPartySpecies], a + call GetBaseData + xor a + ld bc, PARTYMON_STRUCT_LENGTH + ld hl, wContestMon + call ByteFill + xor a + ld [wMonType], a + ld hl, wContestMon + jp GeneratePartyMonStats + +.ContestCaughtMonText: + text_far _ContestCaughtMonText + text_end diff --git a/engine/events/checktime.asm b/engine/events/checktime.asm new file mode 100644 index 00000000..6e470e88 --- /dev/null +++ b/engine/events/checktime.asm @@ -0,0 +1,19 @@ +CheckTime:: + ld a, [wTimeOfDay] + ld hl, .TimeOfDayTable + ld de, 2 + call IsInArray + inc hl + ld c, [hl] + ret c + + xor a + ld c, a + ret + +.TimeOfDayTable: + db MORN_F, MORN + db DAY_F, DAY + db NITE_F, NITE + db NITE_F, NITE + db -1 diff --git a/engine/events/engine_flags.asm b/engine/events/engine_flags.asm new file mode 100755 index 00000000..9fa5f8c0 --- /dev/null +++ b/engine/events/engine_flags.asm @@ -0,0 +1,195 @@ +EngineFlagAction:: ; c01b +; Do action b on engine flag de +; +; b = 0: reset flag +; = 1: set flag +; > 1: check flag, result in c +; +; Setting/resetting does not return a result. + + +; 16-bit flag ids are considered invalid, but it's nice +; to know that the infrastructure is there. + + ld a, d + cp 0 + jr z, .ceiling + jr c, .read ; cp 0 can't set carry! + jr .invalid + +; There are only $a2 engine flags, so +; anything beyond that is invalid too. + +.ceiling + ld a, e + cp NUM_ENGINE_FLAGS + jr c, .read + +; Invalid flags are treated as flag 00. + +.invalid + xor a + ld e, a + ld d, a + +; Get this flag's location. + +.read + ld hl, EngineFlags +; location + add hl, de + add hl, de +; bit + add hl, de + +; location + ld e, [hl] + inc hl + ld d, [hl] + inc hl +; bit + ld c, [hl] + +; What are we doing with this flag? + + ld a, b + cp 1 + jr c, .reset ; b = 0 + jr z, .set ; b = 1 + +; Return the given flag in c. +.check + ld a, [de] + and c + ld c, a + ret + +; Set the given flag. +.set + ld a, [de] + or c + ld [de], a + ret + +; Reset the given flag. +.reset + ld a, c + cpl ; AND all bits except the one in question + ld c, a + ld a, [de] + and c + ld [de], a + ret + +; 404d +EngineFlags: +; All locations are in WRAM bank 1. + + ; location, bit + engine_flag ENGINE_RADIO_CARD + engine_flag ENGINE_MAP_CARD + engine_flag ENGINE_PHONE_CARD + engine_flag ENGINE_EXPN_CARD + engine_flag ENGINE_POKEGEAR + + engine_flag ENGINE_DAY_CARE_MAN_HAS_EGG + engine_flag ENGINE_DAY_CARE_MAN_HAS_MON + + engine_flag ENGINE_DAY_CARE_LADY_HAS_MON + + engine_flag ENGINE_MOM_SAVING_MONEY + engine_flag ENGINE_DST + + engine_flag ENGINE_0A + + engine_flag ENGINE_POKEDEX + engine_flag ENGINE_UNOWN_DEX + engine_flag ENGINE_POKERUS + engine_flag ENGINE_ROCKET_SIGNAL_ON_CH20 + engine_flag ENGINE_CREDITS_SKIP + engine_flag ENGINE_BUG_CONTEST_TIMER + engine_flag ENGINE_SAFARI_ZONE + engine_flag ENGINE_ROCKETS_IN_RADIO_TOWER + engine_flag ENGINE_BIKE_SHOP_CALL_ENABLED + engine_flag ENGINE_GIVE_POKERUS + engine_flag ENGINE_REACHED_GOLDENROD + engine_flag ENGINE_ROCKETS_IN_MAHOGANY + + engine_flag ENGINE_STRENGTH_ACTIVE + engine_flag ENGINE_ALWAYS_ON_BIKE + engine_flag ENGINE_DOWNHILL + + engine_flag ENGINE_ZEPHYRBADGE + engine_flag ENGINE_HIVEBADGE + engine_flag ENGINE_PLAINBADGE + engine_flag ENGINE_FOGBADGE + engine_flag ENGINE_MINERALBADGE + engine_flag ENGINE_STORMBADGE + engine_flag ENGINE_GLACIERBADGE + engine_flag ENGINE_RISINGBADGE + + engine_flag ENGINE_BOULDERBADGE + engine_flag ENGINE_CASCADEBADGE + engine_flag ENGINE_THUNDERBADGE + engine_flag ENGINE_RAINBOWBADGE + engine_flag ENGINE_SOULBADGE + engine_flag ENGINE_MARSHBADGE + engine_flag ENGINE_VOLCANOBADGE + engine_flag ENGINE_EARTHBADGE + + engine_flag ENGINE_UNLOCKED_UNOWNS_A_TO_K + engine_flag ENGINE_UNLOCKED_UNOWNS_L_TO_R + engine_flag ENGINE_UNLOCKED_UNOWNS_S_TO_W + engine_flag ENGINE_UNLOCKED_UNOWNS_X_TO_Z + engine_flag ENGINE_UNLOCKED_UNOWNS_UNUSED_4 + engine_flag ENGINE_UNLOCKED_UNOWNS_UNUSED_5 + engine_flag ENGINE_UNLOCKED_UNOWNS_UNUSED_6 + engine_flag ENGINE_UNLOCKED_UNOWNS_UNUSED_7 + + engine_flag ENGINE_FLYPOINT_PLAYERS_HOUSE + engine_flag ENGINE_FLYPOINT_VIRIDIAN_POKECENTER + engine_flag ENGINE_FLYPOINT_PALLET + engine_flag ENGINE_FLYPOINT_VIRIDIAN + engine_flag ENGINE_FLYPOINT_PEWTER + engine_flag ENGINE_FLYPOINT_CERULEAN + engine_flag ENGINE_FLYPOINT_ROCK_TUNNEL + engine_flag ENGINE_FLYPOINT_VERMILION + engine_flag ENGINE_FLYPOINT_LAVENDER + engine_flag ENGINE_FLYPOINT_SAFFRON + engine_flag ENGINE_FLYPOINT_CELADON + engine_flag ENGINE_FLYPOINT_FUCHSIA + engine_flag ENGINE_FLYPOINT_CINNABAR + engine_flag ENGINE_FLYPOINT_INDIGO_PLATEAU + engine_flag ENGINE_FLYPOINT_NEW_BARK + engine_flag ENGINE_FLYPOINT_CHERRYGROVE + engine_flag ENGINE_FLYPOINT_VIOLET + + engine_flag ENGINE_FLYPOINT_AZALEA + engine_flag ENGINE_FLYPOINT_CIANWOOD + engine_flag ENGINE_FLYPOINT_GOLDENROD + engine_flag ENGINE_FLYPOINT_OLIVINE + engine_flag ENGINE_FLYPOINT_ECRUTEAK + engine_flag ENGINE_FLYPOINT_MAHOGANY + engine_flag ENGINE_FLYPOINT_LAKE_OF_RAGE + engine_flag ENGINE_FLYPOINT_BLACKTHORN + engine_flag ENGINE_FLYPOINT_SILVER_CAVE + + engine_flag ENGINE_FLYPOINT_UNUSED + engine_flag ENGINE_LUCKY_NUMBER_SHOW + engine_flag ENGINE_4E + + engine_flag ENGINE_KURT_MAKING_BALLS + engine_flag ENGINE_DAILY_BUG_CONTEST + engine_flag ENGINE_SPECIAL_WILDDATA + engine_flag ENGINE_TIME_CAPSULE + engine_flag ENGINE_ALL_FRUIT_TREES + engine_flag ENGINE_GOT_SHUCKIE_TODAY + engine_flag ENGINE_GOLDENROD_UNDERGROUND_MERCHANT_CLOSED + engine_flag ENGINE_FOUGHT_IN_TRAINER_HALL_TODAY + + engine_flag ENGINE_MT_MOON_SQUARE_CLEFAIRY + engine_flag ENGINE_UNION_CAVE_LAPRAS + engine_flag ENGINE_GOLDENROD_UNDERGROUND_GOT_HAIRCUT + engine_flag ENGINE_GOLDENROD_DEPT_STORE_TM27_RETURN + engine_flag ENGINE_DAISYS_GROOMING + engine_flag ENGINE_INDIGO_PLATEAU_RIVAL_FIGHT diff --git a/engine/events/specials.asm b/engine/events/specials.asm new file mode 100755 index 00000000..e51f3451 --- /dev/null +++ b/engine/events/specials.asm @@ -0,0 +1,572 @@ +Special:: ; c22b + ld hl, SpecialsPointers ; $4239 + add hl, de + add hl, de + add hl, de + ld b, [hl] + inc hl + ld a, [hli] + ld h, [hl] + ld l, a + ld a, b + rst FarCall + ret + +; Special routines can be used with the "special" map script command. +; They often use wScriptVar for arguments and return values. + +add_special: MACRO +; Some ROM0 specials have a nonzero bank. +\1Special:: +IF _NARG == 1 + dba \1 +ELSE + dbw \2, \1 +ENDC +ENDM + +SpecialsPointers: + add_special WarpToSpawnPoint + +; Communications + add_special SetBitsForLinkTradeRequest + add_special WaitForLinkedFriend + add_special CheckLinkTimeout + add_special TryQuickSave + add_special CheckBothSelectedSameRoom + add_special FailedLinkToPast + add_special CloseLink + add_special WaitForOtherPlayerToExit + add_special SetBitsForBattleRequest + add_special SetBitsForTimeCapsuleRequest + add_special CheckTimeCapsuleCompatibility + add_special EnterTimeCapsule + add_special TradeCenter + add_special Colosseum + add_special TimeCapsule + add_special CableClubCheckWhichChris + add_special CheckMysteryGift + add_special GetMysteryGiftItem + add_special UnlockMysteryGift + +; Map events + add_special BugContestJudging + add_special CheckPartyFullAfterContest + add_special ContestDropOffMons + add_special ContestReturnMons + add_special GiveParkBalls + add_special CheckMagikarpLength + add_special MagikarpHouseSign + add_special HealParty + add_special PokemonCenterPC + add_special PlayersHousePC + add_special DayCareMan + add_special DayCareLady + add_special DayCareManOutside + add_special MoveDeletion + add_special BankOfMom + add_special MagnetTrain + add_special NameRival + add_special SetDayOfWeek + add_special OverworldTownMap + add_special UnownPrinter + add_special MapRadio + add_special UnownPuzzle + add_special SlotMachine + add_special CardFlip + add_special DummyNonfunctionalGameCornerGame + add_special ClearBGPalettesBufferScreen + add_special FadeOutPalettes + add_special FadeBlackQuickly + add_special FadeInPalettes + add_special FadeInQuickly + add_special ReloadSpritesNoPalettes, $02 + add_special ClearBGPalettes + add_special UpdateTimePals + add_special ClearTilemap + add_special UpdateSprites + add_special ReplacePlayerSprite + add_special GameCornerPrizeMonCheckDex + add_special UnusedSetSeenMon + add_special WaitSFX, $03 + add_special PlayMapMusic + add_special RestartMapMusic + add_special HealMachineAnim + add_special SurfStartStep + add_special FindPartyMonAboveLevel + add_special FindPartyMonAtLeastThatHappy + add_special FindPartyMonThatSpecies + add_special FindPartyMonThatSpeciesYourTrainerID + add_special UnusedCheckUnusedTwoDayTimer + add_special DayCareMon1 + add_special DayCareMon2 + add_special SelectRandomBugContestContestants + add_special ActivateFishingSwarm + add_special ToggleMaptileDecorations + add_special ToggleDecorationsVisibility + add_special GiveShuckle + add_special ReturnShuckle + add_special BillsGrandfather + add_special CheckPokerus + add_special DisplayCoinCaseBalance + add_special DisplayMoneyAndCoinBalance + add_special PlaceMoneyTopRight + add_special CheckForLuckyNumberWinners + add_special CheckLuckyNumberShowFlag + add_special ResetLuckyNumberShowFlag + add_special PrintTodaysLuckyNumber + add_special SelectApricornForKurt + add_special NameRater + add_special DisplayLinkRecord + add_special GetFirstPokemonHappiness + add_special CheckFirstMonIsEgg + add_special RandomUnseenWildMon + add_special RandomPhoneWildMon + add_special RandomPhoneMon + add_special LoadUsedSpritesGFX + add_special PlaySlowCry + add_special SnorlaxAwake + add_special YoungerHaircutBrother + add_special OlderHaircutBrother + add_special DaisysGrooming + add_special PlayCurMonCry + add_special ProfOaksPCBoot + add_special GameboyCheck + add_special TrainerHouse + add_special PhotoStudio + add_special InitRoamMons + add_special FadeOutMusic + add_special Diploma + add_special PrintDiploma + add_special InitialSetDSTFlag + add_special InitialClearDSTFlag + add_special MrChrono + add_special SpecialNone + +SpecialNone: ; c389 + ret + +GameCornerPrizeMonCheckDex: ; c38a + ld a, [wScriptVar] + dec a + call CheckCaughtMon + ret nz + ld a, [wScriptVar] + dec a + call SetSeenAndCaughtMon + call FadeToMenu + ld a, [wScriptVar] + ld [wd151], a + farcall NewPokedexEntry + call ExitAllMenus + ret + +UnusedSetSeenMon: ; c3ac + ld a, [wScriptVar] + dec a + call SetSeenMon + ret + +FindPartyMonAboveLevel: + ld a, [wScriptVar] + ld b, a + farcall _FindPartyMonAboveLevel ; same bank + jr z, FoundNone + jr FoundOne + +FindPartyMonAtLeastThatHappy: + ld a, [wScriptVar] + ld b, a + farcall _FindPartyMonAtLeastThatHappy ; same bank + jr z, FoundNone + jr FoundOne + +FindPartyMonThatSpecies: + ld a, [wScriptVar] + ld b, a + farcall _FindPartyMonThatSpecies ; same bank + jr z, FoundNone + jr FoundOne + +FindPartyMonThatSpeciesYourTrainerID: + ld a, [wScriptVar] + ld b, a + farcall _FindPartyMonThatSpeciesYourTrainerID ; same bank + jr z, FoundNone + jr FoundOne + +FoundOne: + ld a, TRUE + ld [wScriptVar], a + ret + +FoundNone: + xor a + ld [wScriptVar], a + ret + +NameRival: ; c3f7 + ld b, $2 + ld de, wRivalName + farcall NamingScreen_ + ld hl, wRivalName + ld de, .DefaultName + call InitName + ret + +.DefaultName: +IF DEF(GOLD) + db "SILVER@" +ENDC + +IF DEF(SILVER) + db "GOLD@" +ENDC + +NameRater: + farcall _NameRater + ret + +OverworldTownMap: ; c41a (3:441a) + call FadeToMenu + farcall Function9188a + call ExitAllMenus + ret + +UnownPrinter: ; c427 (3:4427) + call FadeToMenu + farcall Function16e3a + call ExitAllMenus + ret + +DisplayLinkRecord: ; c434 (3:4434) + call FadeToMenu + farcall Function3f55d + call ExitAllMenus + ret + +PlayersHousePC: ; c441 (3:4441) + xor a + ld [wScriptVar], a + farcall Function159b0 + ld a, c + ld [wScriptVar], a + ret + +CheckMysteryGift: ; c450 (3:4450) + ld a, $0 + call OpenSRAM + ld a, [$abe2] + and a + jr z, .asm_c45c + inc a +.asm_c45c + ld [wScriptVar], a + call CloseSRAM + ret + +GetMysteryGiftItem: ; c463 (3:4463) + ld a, $0 + call OpenSRAM + ld a, [$abe2] + ld [wCurItem], a + ld a, $1 + ld [wItemQuantityChangeBuffer], a + ld hl, wNumItems + call ReceiveItem + jr nc, .asm_c497 + xor a + ld [$abe2], a + call CloseSRAM + ld a, [wCurItem] + ld [wd151], a + call GetItemName + ld hl, ReceivedMysteryGiftText ; $449f + call PrintText + ld a, $1 + ld [wScriptVar], a + ret + +.asm_c497 + call CloseSRAM + xor a + ld [wScriptVar], a + ret + +ReceivedMysteryGiftText: + text_far ReceivedMysteryGiftText_ + db "@" + +BugContestJudging: ; c4a4 (3:44a4) + farcall _BugContestJudging + ld a, b + ld [wScriptVar], a + ret + +MapRadio: ; c4af (3:44af) + ld a, [wScriptVar] + ld e, a + farcall Function919c1 + ret + +UnownPuzzle: ; c4ba (3:44ba) + call FadeToMenu + farcall Functione199d + ld a, [wFieldMoveSucceeded] + ld [wScriptVar], a + call ExitAllMenus + ret + +SlotMachine: ; c4cd (3:44cd) + call Functionc508 + ret c + ld a, BANK(Function92c36) + ld hl, Function92c36 + call Functionc4f4 + ret + +CardFlip: ; c4da (3:44da) + call Functionc508 + ret c + ld a, BANK(Functione0909) + ld hl, Functione0909 + call Functionc4f4 + ret + +DummyNonfunctionalGameCornerGame: ; c4e7 (3:44e7) + call Functionc508 + ret c + ld a, BANK(Functione2668) + ld hl, Functione2668 + call Functionc4f4 + ret + +Functionc4f4: ; c4f4 (3:44f4) + call FarQueueScript + call FadeToMenu + ld hl, wQueuedScriptBank + ld a, [hli] + push af + ld a, [hli] + ld h, [hl] + ld l, a + pop af + rst FarCall + call ExitAllMenus + ret + +Functionc508: ; c508 (3:4508) + ld hl, wCoins + ld a, [hli] + or [hl] + jr z, .asm_c51e + ld a, COIN_CASE + ld [wCurItem], a + ld hl, wNumItems + call CheckItem + jr nc, .asm_c523 + and a + ret + +.asm_c51e + ld hl, .NoCoinsText + jr .asm_c526 + +.asm_c523 + ld hl, .NoCoinCaseText +.asm_c526 + call PrintText + scf + ret + +.NoCoinsText: + text_far NoCoinsText_ + db "@" + +.NoCoinCaseText: + text_far NoCoinCaseText_ + db "@" + +ClearBGPalettesBufferScreen: ; c535 (3:4535) + call ClearBGPalettes + call BufferScreen + ret + +Functionc53c: ; c53c (3:453c) + jr c, .asm_c543 + xor a + ld [wScriptVar], a + ret + +.asm_c543 + ld a, $1 + ld [wScriptVar], a + ret + +UnusedCheckUnusedTwoDayTimer: ; c549 (3:4549) + farcall Function118f8 + ld a, [wUnusedTwoDayTimer] + ld [wScriptVar], a + ret + +ActivateFishingSwarm: ; c556 (3:4556) + ld a, [wScriptVar] + ld [wFishingSwarmFlag], a + jr .asm_c566 + +.asm_c55e + ld a, d + ld [wDunsparceMapGroup], a + ld a, e + ld [wDunsparceMapNumber], a +.asm_c566 + SetFlag ENGINE_SPECIAL_WILDDATA + ret + +Functionc56c: + CheckFlagHL ENGINE_SPECIAL_WILDDATA + jr z, .asm_c578 + xor a + ld [wScriptVar], a + ret + +.asm_c578 + ld a, $1 + ld [wScriptVar], a + xor a + ld [wFishingSwarmFlag], a + ld [wDunsparceMapGroup], a + ld [wDunsparceMapNumber], a + ret + +CheckPokerus: ; c588 (3:4588) + farcall Functionc7a40 + jp Functionc53c + +ResetLuckyNumberShowFlag: ; c591 (3:4591) + farcall Function11917 + ClearFlag ENGINE_LUCKY_NUMBER_SHOW + farcall LoadOrRegenerateLuckyIDNumber + ret + +CheckLuckyNumberShowFlag: ; c5a3 (3:45a3) + farcall Function1192e + jp Functionc53c + +CountUnown: ; c5ac (3:45ac) + ld hl, wUnownDex + ld b, $0 +.asm_c5b1 + ld a, [hli] + and a + ret z + inc b + ld a, b + cp $1a + jr c, .asm_c5b1 + ret + +SelectApricornForKurt: ; c5bb (3:45bb) + farcall Function24b8d + ld a, c + ld [wScriptVar], a + and a + ret z + ld [wCurItem], a + ld a, $1 + ld [wItemQuantityChangeBuffer], a + ld hl, wNumItems + call TossItem + ret + +SnorlaxAwake: ; c5d6 (3:45d6) + ld a, [wChannelsEnd] + cp $40 + jr nz, .asm_c5fb + ld a, [wXCoord] + ld b, a + ld a, [wYCoord] + ld c, a + ld hl, .ProximityCoords +.asm_c5e8 + ld a, [hli] + cp $ff + jr z, .asm_c5fb + cp b + jr nz, .asm_c5f8 + ld a, [hli] + cp c + jr nz, .asm_c5e8 + ld a, $1 + jr .asm_c5fc + +.asm_c5f8 + inc hl + jr .asm_c5e8 + +.asm_c5fb + xor a +.asm_c5fc + ld [wScriptVar], a + ret + +.ProximityCoords: + ; x, y + db 33, 8 ; left + db 34, 10 ; below + db 35, 10 ; below + db 36, 8 ; right + db 36, 9 ; right + db -1 + +PlayCurMonCry: ; c60b (3:460b) + ld a, [wCurPartySpecies] + jp PlayMonCry + +GameboyCheck: ; c611 (3:4611) + ldh a, [hCGB] + and a + jr nz, .asm_c622 + ldh a, [hSGB] + and a + jr nz, .asm_c61e + xor a + jr .asm_c624 + +.asm_c61e + ld a, $1 + jr .asm_c624 + +.asm_c622 + ld a, $2 +.asm_c624 + ld [wScriptVar], a + ret + +FadeOutMusic: ; c628 (3:4628) + ld a, $0 + ld [wMusicFadeID], a + ld a, $0 + ld [wMusicFadeID + 1], a + ld a, $2 + ld [wMusicFade], a + ret + +Diploma: ; c638 (3:4638) + call FadeToMenu + farcall Functione0002 + call ExitAllMenus + ret + +PrintDiploma: ; c645 (3:4645) + call FadeToMenu + farcall Function84684 + call ExitAllMenus + ret + +TrainerHouse: ; c652 (3:4652) + ld a, $0 + call OpenSRAM + ld a, [$abfd] + ld [wScriptVar], a + jp CloseSRAM diff --git a/engine/gfx/color.asm b/engine/gfx/color.asm new file mode 100755 index 00000000..05c13b2b --- /dev/null +++ b/engine/gfx/color.asm @@ -0,0 +1,1903 @@ +PALPACKET_LENGTH EQU $10 +INCLUDE "predef/sgb.asm" + +SHINY_ATK_BIT EQU 5 +SHINY_DEF_VAL EQU 10 +SHINY_SPD_VAL EQU 10 +SHINY_SPC_VAL EQU 10 + +CheckShininess: + ld l, c + ld h, b + ld a, [hl] + and $20 + jr z, .asm_9070 + ld a, [hli] + and $f + cp $a + jr nz, .asm_9070 + ld a, [hl] + and $f0 + cp $a0 + jr nz, .asm_9070 + ld a, [hl] + and $f + cp $a + jr nz, .asm_9070 + scf + ret + +.asm_9070 + and a + ret + +Unused_CheckShininess: ; 9072 (2:5072) + ld a, [hl] + cp $a0 + jr c, .asm_908c + ld a, [hli] + and $f + cp $a + jr c, .asm_908c + ld a, [hl] + cp $a0 + jr c, .asm_908c + ld a, [hl] + and $f + cp $a + jr c, .asm_908c + scf + ret + +.asm_908c + and a + ret + +Function908e: + push de + push bc + ld hl, PalPacket_a155 + ld de, wcca9 + ld bc, $10 + call CopyBytes + pop bc + pop de + ld a, c + ld [wccac], a + ld a, b + ld [wccad], a + ld a, e + ld [wccae], a + ld a, d + ld [wccaf], a + ld hl, wcca9 + call PushSGBPals_ + ld hl, BlkPacket_9ee5 + call PushSGBPals_ + ret + +InitPartyMenuPalettes: + call CheckCGB + jr nz, .asm_90cc + ld hl, BlkPacket_9fa5 + ld de, wccaa + ld bc, $30 + jp CopyBytes + +.asm_90cc + ld hl, PalPacket_a0c5 + 1 + call Function9ab2 + call Function9b9c + call Function9b1d + ret + +SGB_ApplyPartyMenuHPPals: + ld hl, wcc9b + ld a, [wcca9] + ld e, a + ld d, $0 + add hl, de + ld e, l + ld d, h + ld a, [de] + and a + ld e, $5 + jr z, .asm_90f2 + dec a + ld e, $a + jr z, .asm_90f2 + ld e, $f +.asm_90f2 + push de + ld hl, wccb3 + ld bc, $6 + ld a, [wcca9] + call AddNTimes + pop de + ld [hl], e + ret + +Function9102: + call CheckCGB + ret z + ld hl, .BGPal + ld de, wTempBGPals + ld bc, $8 + call CopyBytes + ld hl, .OBPal + ld de, wTempOBPals + ld bc, $8 + call CopyBytes + call Function9b28 + ld a, $1 + ldh [hCGBPalUpdate], a + ret + +.BGPal: + RGB 31, 31, 31 + RGB 18, 23, 31 + RGB 15, 20, 31 + RGB 00, 00, 00 + +.OBPal: + RGB 31, 31, 31 + RGB 31, 31, 12 + RGB 08, 16, 28 + RGB 00, 00, 00 + +Function9136: + call CheckCGB + ret nz + ldh a, [hSGB] + and a + ret z + ld hl, BlkPacket_9ee5 + jp PushSGBPals_ + +Function9144: + call CheckCGB + jr nz, .asm_9153 + ldh a, [hSGB] + and a + ret z + ld hl, PalPacket_a095 + jp PushSGBPals_ + +.asm_9153 + ld de, wTempOBPals + ld a, $3b + call Function9ac7 + jp Function9ad2 + +Function915e: + call CheckCGB + jr nz, .asm_916d + ldh a, [hSGB] + and a + ret z + ld hl, PalPacket_a0a5 + jp PushSGBPals_ + +.asm_916d + ld de, wTempOBPals + ld a, $3c + call Function9ac7 + jp Function9ad2 + +Function9178: + call CheckCGB + jr nz, .asm_91a9 + ldh a, [hSGB] + and a + ret z + ld a, c + push af + ld hl, PalPacket_a155 + ld de, wcca9 + ld bc, $10 + call CopyBytes + pop af + call Function9be4 + ld a, [hli] + ld [wccac], a + ld a, [hli] + ld [wccad], a + ld a, [hli] + ld [wccae], a + ld a, [hl] + ld [wccaf], a + ld hl, wcca9 + jp PushSGBPals_ + +.asm_91a9 + ld de, wTempOBPals + ld a, c + call Function9be4 + call Function9adb + ret + +Function91b4: + ldh a, [hCGB] + and a + jr nz, .asm_91bf + ld hl, wc602 + jp PushSGBPals_ + +.asm_91bf + ld a, [wc606] + ld c, a + ld a, [wc607] + ld hl, wAttrmap + ld de, $14 +.asm_91cc + and a + jr z, .asm_91d3 + add hl, de + dec a + jr .asm_91cc + +.asm_91d3 + ld b, $0 + add hl, bc + lb bc, 6, 4 + ld a, [wc605] + and $3 + call Function9af1 + call CopyTilemapAtOnce + ret + +ApplyMonOrTrainerPals: ; 91e5 (2:51e5) + call CheckCGB + ret z + ld a, e + and a + jr z, .asm_91f5 + ld a, [wCurPartySpecies] + call Function9be4 + jr .asm_91fb + +.asm_91f5 + ld a, [wTrainerClass] + call Function9bda +.asm_91fb + ld de, wTempBGPals + call Function9adb + call Function9b1d + call Function9b35 + call Function9b28 + ret + +ApplyHPBarPals: + ld a, [wWhichHPBar] + and a + jr z, .asm_921a + cp $1 + jr z, .asm_921f + cp $2 + jr z, .asm_9236 + ret + +.asm_921a + ld de, $c292 + jr .asm_9222 + +.asm_921f + ld de, $c29a +.asm_9222 + ld l, c + ld h, $0 + add hl, hl + add hl, hl + ld bc, $6d2d + add hl, bc + ld bc, $4 + call CopyBytes + ld a, $1 + ldh [hCGBPalUpdate], a + ret + +.asm_9236 + ld e, c + inc e + hlcoord 11, 1, wAttrmap + ld bc, 2 * SCREEN_WIDTH + ld a, [wCurPartyMon] +.asm_9241 + and a + jr z, .asm_9248 + add hl, bc + dec a + jr .asm_9241 + +.asm_9248 + lb bc, 2, 8 + ld a, e + call Function9af1 + ret + +LoadStatsScreenPals: + call CheckCGB + ret z + ld hl, StatsScreenPals ; $54eb + ld b, $0 + dec c + add hl, bc + add hl, bc + ld a, [hli] + ld [wTempBGPals], a + ld [wTempBGPals + $10], a + ld a, [hl] + ld [wTempBGPals + 1], a + ld [wTempBGPals + $11], a + call Function9b28 + ld a, $1 + ldh [hCGBPalUpdate], a + ret + +LoadMailPalettes: + ld l, e + ld h, $0 + add hl, hl + add hl, hl + add hl, hl + ld de, .MailPals + add hl, de + call CheckCGB + jr nz, .asm_92ae + push hl + ld hl, PalPacket_a155 + ld de, wcca9 + ld bc, $10 + call CopyBytes + pop hl + inc hl + inc hl + ld a, [hli] + ld [wccac], a + ld a, [hli] + ld [wccad], a + ld a, [hli] + ld [wccae], a + ld a, [hli] + ld [wccaf], a + ld hl, wcca9 + call PushSGBPals_ + ld hl, BlkPacket_9ee5 + call PushSGBPals_ + ret + +.asm_92ae + ld de, wTempBGPals + ld bc, $8 + call CopyBytes + call Function9b28 + call Function9b1d + call Function9b35 + ret + +.MailPals: + RGB 20, 31, 11 + RGB 31, 19, 00 + RGB 31, 10, 09 + RGB 00, 00, 00 + + RGB 15, 20, 31 + RGB 30, 26, 00 + RGB 31, 12, 00 + RGB 00, 00, 00 + + RGB 24, 17, 31 + RGB 30, 26, 00 + RGB 08, 11, 31 + RGB 00, 00, 00 + + RGB 31, 25, 17 + RGB 31, 18, 04 + RGB 28, 12, 05 + RGB 00, 00, 00 + + RGB 19, 26, 31 + RGB 31, 05, 08 + RGB 31, 09, 31 + RGB 00, 00, 00 + + RGB 31, 19, 28 + RGB 31, 21, 00 + RGB 12, 22, 00 + RGB 00, 00, 00 + + RGB 19, 17, 23 + RGB 30, 26, 00 + RGB 31, 12, 00 + RGB 00, 00, 00 + + RGB 07, 26, 31 + RGB 26, 26, 27 + RGB 31, 11, 11 + RGB 00, 00, 00 + + RGB 21, 31, 21 + RGB 30, 26, 00 + RGB 31, 12, 00 + RGB 00, 00, 00 + + RGB 07, 26, 31 + RGB 31, 31, 00 + RGB 00, 21, 00 + RGB 00, 00, 00 + +INCLUDE "predef/cgb.asm" + +Function9a94: ; 9a94 (2:5a94) + ld hl, Palettes_9aaa + ld de, wTempBGPals + ld bc, $8 + call CopyBytes + call Function9b28 + call Function9b1d + call Function9b35 + ret + +Palettes_9aaa: + RGB 31, 31, 31 + RGB 9, 31, 31 + RGB 10, 12, 31 + RGB 0, 3, 19 + +Function9ab2: ; 9ab2 (2:5ab2) + ld de, wTempBGPals + ld c, $4 +Function9ab7: ; 9ab7 (2:5ab7) + push bc + ld a, [hli] + push hl + call Function9ac7 + call Function9ad2 + pop hl + inc hl + pop bc + dec c + jr nz, Function9ab7 + ret + +Function9ac7: ; 9ac7 (2:5ac7) + ld l, a + ld h, $0 + add hl, hl + add hl, hl + add hl, hl + ld bc, Palettes_a265 + add hl, bc + ret + +Function9ad2: ; 9ad2 (2:5ad2) + ld c, $8 +.asm_9ad4 + ld a, [hli] + ld [de], a + inc de + dec c + jr nz, .asm_9ad4 + ret + +Function9adb: ; 9adb (2:5adb) + ld a, $ff + ld [de], a + inc de + ld a, $7f + ld [de], a + inc de + ld c, $4 +.asm_9ae5 + ld a, [hli] + ld [de], a + inc de + dec c + jr nz, .asm_9ae5 + xor a + ld [de], a + inc de + ld [de], a + inc de + ret + +Function9af1: ; 9af1 (2:5af1) + push bc + push hl +.asm_9af3 + ld [hli], a + dec c + jr nz, .asm_9af3 + pop hl + ld bc, $14 + add hl, bc + pop bc + dec b + jr nz, Function9af1 + ret + +Function9b01: ; 9b01 (2:5b01) + push af + push bc + push de + push hl + ld hl, wTempBGPals + ld c, $8 +.asm_9b0a + ld a, $ff + ld [hli], a + ld [hli], a + ld [hli], a + ld [hli], a + xor a + ld [hli], a + ld [hli], a + ld [hli], a + ld [hli], a + dec c + jr nz, .asm_9b0a + pop hl + pop de + pop bc + pop af + ret + +Function9b1d: ; 9b1d (2:5b1d) + hlcoord 0, 0, wAttrmap + ld bc, SCREEN_HEIGHT * SCREEN_WIDTH + xor a + call ByteFill + ret + +Function9b28: ; 9b28 (2:5b28) + ld hl, wTempBGPals + ld de, wBGPals + ld bc, $80 + call CopyBytes + ret + +Function9b35: ; 9b35 (2:5b35) + ldh a, [rLCDC] + bit 7, a + jr z, .asm_9b52 + ldh a, [hBGMapMode] + push af + ld a, $2 + ldh [hBGMapMode], a + call DelayFrame + call DelayFrame + call DelayFrame + call DelayFrame + pop af + ldh [hBGMapMode], a + ret + +.asm_9b52 + hlcoord 0, 0, wAttrmap + ld de, $9800 + ld b, $12 + ld a, $1 + ldh [rVBK], a +.asm_9b5e + ld c, $14 +.asm_9b60 + ld a, [hli] + ld [de], a + inc de + dec c + jr nz, .asm_9b60 + ld a, $c + add e + jr nc, .asm_9b6c + inc d +.asm_9b6c + ld e, a + dec b + jr nz, .asm_9b5e + ld a, $0 + ldh [rVBK], a + ret + +Function9b75: ; 9b75 (2:5b75) + ld hl, wcc9b + ld a, [wcca9] + ld e, a + ld d, $0 + add hl, de + ld e, l + ld d, h + ld a, [de] + inc a + ld e, a + hlcoord 11, 2, wAttrmap + ld bc, $28 + ld a, [wcca9] +.asm_9b8d + and a + jr z, .asm_9b94 + add hl, bc + dec a + jr .asm_9b8d + +.asm_9b94 + lb bc, 2, 8 + ld a, e + call Function9af1 + ret + +Function9b9c: ; 9b9c (2:5b9c) + ld hl, Palettes_bac6 + ld de, wTempOBPal0 + ld bc, $10 + call CopyBytes + ret + +Function9ba9: ; 9ba9 (2:5ba9) + push de + farcall Function3d8f5 + ld c, l + ld b, h + ld a, [wd0ee] + call Function9bcb + pop de + ret + +Function9bba: ; 9bba (2:5bba) + push de + farcall Function3d907 + ld c, l + ld b, h + ld a, [wTempEnemyMonSpecies] + call Function9bd3 + pop de + ret + +Function9bcb: ; 9bcb (2:5bcb) + and a + jp nz, Function9c66 + ld hl, TrainerPalettes + ret + +Function9bd3: ; 9bd3 (2:5bd3) + and a + jp nz, Function9c66 + ld a, [wTrainerClass] +Function9bda: ; 9bda (2:5bda) + ld l, a + ld h, $0 + add hl, hl + add hl, hl + ld bc, TrainerPalettes + add hl, bc + ret + +Function9be4: ; 9be4 (2:5be4) + call Function9c5b + ret + +Function9be8: + ret + +Function9be9: + call CheckCGB + ret z + ld hl, Palettes_9c09 + ld a, $90 + ldh [rOBPI], a + ld c, $30 +.asm_9bf6 + ld a, [hli] + ldh [rOBPD], a + dec c + jr nz, .asm_9bf6 + ld hl, Palettes_9c09 + ld de, wTempOBPal2 + ld bc, $10 + call CopyBytes + ret + +Palettes_9c09: + RGB 31, 31, 31 + RGB 25, 25, 25 + RGB 13, 13, 13 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 31, 31, 7 + RGB 31, 16, 1 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 31, 19, 24 + RGB 30, 10, 6 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 12, 25, 1 + RGB 5, 14, 0 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 8, 12, 31 + RGB 1, 4, 31 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 24, 18, 7 + RGB 20, 15, 3 + RGB 0, 0, 0 + +Function9c39: + call CheckCGB + ret z + ld a, $90 + ldh [rOBPI], a + ld a, $1c + call Function9ac7 + call Function9c52 + ld a, $21 + call Function9ac7 + call Function9c52 + ret + +Function9c52: ; 9c52 (2:5c52) + ld c, $8 +.asm_9c54 + ld a, [hli] + ldh [rOBPD], a + dec c + jr nz, .asm_9c54 + ret + +Function9c5b: ; 9c5b (2:5c5b) + ld l, a + ld h, $0 + add hl, hl + add hl, hl + add hl, hl + ld bc, PokemonPalettes + add hl, bc + ret + +Function9c66: ; 9c66 (2:5c66) + push bc + call Function9c5b + pop bc + push hl + call CheckShininess + pop hl + ret nc + inc hl + inc hl + inc hl + inc hl + ret + +PushSGBPals_: ; 9c76 (2:5c76) + ld a, [wd8ba] + push af + set 7, a + ld [wd8ba], a + call Function9c87 + pop af + ld [wd8ba], a + ret + +Function9c87: ; 9c87 (2:5c87) + ld a, [hl] + and $7 + ret z + ld b, a +.asm_9c8c + push bc + xor a + ldh [rJOYP], a + ld a, $30 + ldh [rJOYP], a + ld b, $10 +.asm_9c96 + ld e, $8 + ld a, [hli] + ld d, a +.asm_9c9a + bit 0, d + ld a, $10 + jr nz, .asm_9ca2 + ld a, $20 +.asm_9ca2 + ldh [rJOYP], a + ld a, $30 + ldh [rJOYP], a + rr d + dec e + jr nz, .asm_9c9a + dec b + jr nz, .asm_9c96 + ld a, $20 + ldh [rJOYP], a + ld a, $30 + ldh [rJOYP], a + call Function9ed9 + pop bc + dec b + jr nz, .asm_9c8c + ret + +InitSGBBorder: ; 9cc0 (2:5cc0) + call CheckCGB + ret nz + di + ld a, [wd8ba] + push af + set 7, a + ld [wd8ba], a + xor a + ldh [rJOYP], a + ldh [hSGB], a + call Function9da9 + jr nc, .asm_9cf7 + ld a, $1 + ldh [hSGB], a + call Function9d4a + call Function9e13 + call Function9ed9 + call Function9d9e + call Function9d8b + call Function9ed9 + call Function9d9e + ld hl, PalPacket_a1d5 + call Function9c87 +.asm_9cf7 + pop af + ld [wd8ba], a + ei + ret + +InitCGBPals:: ; 9cfd (2:5cfd) + call CheckCGB + ret z + ld a, $1 + ldh [rVBK], a + ld hl, $8000 + ld bc, $2000 + xor a + call ByteFill + ld a, $0 + ldh [rVBK], a + ld a, $80 + ldh [rBGPI], a + ld c, $20 +.asm_9d19 + ld a, $ff + ldh [rBGPD], a + ld a, $7f + ldh [rBGPD], a + dec c + jr nz, .asm_9d19 + ld a, $80 + ldh [rOBPI], a + ld c, $20 +.asm_9d2a + ld a, $ff + ldh [rOBPD], a + ld a, $7f + ldh [rOBPD], a + dec c + jr nz, .asm_9d2a + ld hl, wTempBGPals + call Function9d3e + ld hl, wBGPals +Function9d3e: ; 9d3e (2:5d3e) + ld c, $40 +.asm_9d40 + ld a, $ff + ld [hli], a + ld a, $7f + ld [hli], a + dec c + jr nz, .asm_9d40 + ret + +Function9d4a: ; 9d4a (2:5d4a) + ld hl, .Pointers + ld c, $9 +.asm_9d4f + push bc + ld a, [hli] + push hl + ld h, [hl] + ld l, a + call Function9c87 + pop hl + inc hl + pop bc + dec c + jr nz, .asm_9d4f + ret + +.Pointers: + dw PalPacket_a1c5 + dw PalPacket_a1e5 + dw PalPacket_a1f5 + dw PalPacket_a205 + dw PalPacket_a215 + dw PalPacket_a225 + dw PalPacket_a235 + dw PalPacket_a245 + dw PalPacket_a255 + +Function9d70: + di + xor a + ldh [rJOYP], a + ld hl, PalPacket_a1c5 + call Function9c87 + call Function9d8b + call Function9ed9 + call Function9d9e + ld hl, PalPacket_a1d5 + call Function9c87 + ei + ret + +Function9d8b: ; 9d8b (2:5d8b) + call Function9d97 + push de + call Function9e83 + pop hl + call Function9e37 + ret + +Function9d97: ; 9d97 (2:5d97) + ld hl, SGBBorder + ld de, SGBBorderMap + ret + +Function9d9e: ; 9d9e (2:5d9e) + ld hl, $8000 + ld bc, $2000 + xor a + call ByteFill + ret + +Function9da9: ; 9da9 (2:5da9) + ld hl, PalPacket_a195 + call Function9c87 + call Function9ed9 + ldh a, [rJOYP] + and $3 + cp $3 + jr nz, .asm_9e05 + ld a, $20 + ldh [rJOYP], a + ldh a, [rJOYP] + ldh a, [rJOYP] + call Function9ed9 + call Function9ed9 + ld a, $30 + ldh [rJOYP], a + call Function9ed9 + call Function9ed9 + ld a, $10 + ldh [rJOYP], a + ldh a, [rJOYP] + ldh a, [rJOYP] + ldh a, [rJOYP] + ldh a, [rJOYP] + ldh a, [rJOYP] + ldh a, [rJOYP] + call Function9ed9 + call Function9ed9 + ld a, $30 + ldh [rJOYP], a + ldh a, [rJOYP] + ldh a, [rJOYP] + ldh a, [rJOYP] + call Function9ed9 + call Function9ed9 + ldh a, [rJOYP] + and $3 + cp $3 + jr nz, .asm_9e05 + call Function9e0a + and a + ret + +.asm_9e05 + call Function9e0a + scf + ret + +Function9e0a: ; 9e0a (2:5e0a) + ld hl, PalPacket_a185 + call Function9c87 + jp Function9ed9 + +Function9e13: ; 9e13 (2:5e13) + call DisableLCD + ld a, $e4 + ldh [rBGP], a + ld hl, Palettes_a265 + ld de, $8800 + ld bc, $1000 + call Function9eb1 + call Function9ec3 + ld a, $e3 + ldh [rLCDC], a + ld hl, PalPacket_a175 + call Function9c87 + xor a + ldh [rBGP], a + ret + +Function9e37: ; 9e37 (2:5e37) + call DisableLCD + ld a, $e4 + ldh [rBGP], a + ld de, $8800 + ld bc, $140 + call Function9eb1 + ld b, $12 +.asm_9e49 + push bc + ld bc, $c + call Function9eb1 + ld bc, $28 + call Function9eba + ld bc, $c + call Function9eb1 + pop bc + dec b + jr nz, .asm_9e49 + ld bc, $140 + call Function9eb1 + ld bc, $100 + call Function9eba + ld bc, $80 + call Function9eb1 + call Function9ec3 + ld a, $e3 + ldh [rLCDC], a + ld hl, PalPacket_a1b5 + call Function9c87 + xor a + ldh [rBGP], a + ret + +Function9e83: ; 9e83 (2:5e83) + call DisableLCD + ld a, $e4 + ldh [rBGP], a + ld de, $8800 + ld b, $80 +.asm_9e8f + push bc + ld bc, $10 + call Function9eb1 + ld bc, $10 + call Function9eba + pop bc + dec b + jr nz, .asm_9e8f + call Function9ec3 + ld a, $e3 + ldh [rLCDC], a + ld hl, PalPacket_a1a5 + call Function9c87 + xor a + ldh [rBGP], a + ret + +Function9eb1: ; 9eb1 (2:5eb1) + ld a, [hli] + ld [de], a + inc de + dec bc + ld a, c + or b + jr nz, Function9eb1 + ret + +Function9eba: ; 9eba (2:5eba) + xor a + ld [de], a + inc de + dec bc + ld a, c + or b + jr nz, Function9eba + ret + +Function9ec3: ; 9ec3 (2:5ec3) + ld hl, $9800 + ld de, $c + ld a, $80 + ld c, $d +.asm_9ecd + ld b, $14 +.asm_9ecf + ld [hli], a + inc a + dec b + jr nz, .asm_9ecf + add hl, de + dec c + jr nz, .asm_9ecd + ret + +Function9ed9: ; 9ed9 (2:5ed9) + ld de, 7000 +.asm_9edc + nop + nop + nop + dec de + ld a, d + or e + jr nz, .asm_9edc + ret + +BlkPacket_9ee5: db $21, $01, $03, $00, $00, $00, $13, $11, $00, $00, $00, $00, $00, $00, $00, $00 +BlkPacket_9ef5: db $21, $01, $07, $05, $00, $0a, $13, $0d, $00, $00, $00, $00, $00, $00, $00, $00 +BlkPacket_9f05: db $22, $05, $07, $0a, $00, $0c, $13, $11, $03, $05, $01, $00, $0a, $03, $03, $00 +BlkPacket_9f15: db $0a, $08, $13, $0a, $03, $0a, $00, $04, $08, $0b, $03, $0f, $0b, $00, $13, $07 +BlkPacket_9f25: db $21, $01, $07, $05, $00, $00, $06, $06, $00, $00, $00, $00, $00, $00, $00, $00 +BlkPacket_9f35: db $21, $01, $06, $05, $0b, $01, $13, $02, $00, $00, $00, $00, $00, $00, $00, $00 +BlkPacket_9f45: db $21, $01, $07, $05, $00, $01, $07, $07, $00, $00, $00, $00, $00, $00, $00, $00 +BlkPacket_9f55: db $21, $01, $07, $05, $01, $04, $07, $0a, $00, $00, $00, $00, $00, $00, $00, $00 +BlkPacket_9f65: db $21, $01, $07, $05, $01, $01, $05, $05, $00, $00, $00, $00, $00, $00, $00, $00 +BlkPacket_9f75: db $21, $01, $07, $05, $07, $05, $0d, $0b, $00, $00, $00, $00, $00, $00, $00, $00 +BlkPacket_9f85: db $22, $05, $03, $05, $00, $00, $13, $0b, $03, $0a, $00, $04, $13, $09, $02, $0f +BlkPacket_9f95: db $00, $06, $13, $07, $03, $00, $04, $04, $0f, $09, $03, $00, $00, $0c, $13, $11 +BlkPacket_9fa5: db $23, $07, $07, $10, $00, $00, $02, $0c, $02, $00, $0c, $01, $12, $02, $02, $00 +BlkPacket_9fb5: db $0c, $03, $12, $04, $02, $00, $0c, $05, $12, $06, $02, $00, $0c, $07, $12, $08 +BlkPacket_9fc5: db $02, $00, $0c, $09, $12, $0a, $02, $00, $0c, $0b, $12, $0c, $00, $00, $00, $00 +BlkPacket_9fd5: db $21, $02, $07, $30, $00, $00, $13, $06, $02, $04, $05, $06, $0e, $06, $00, $00 +BlkPacket_9fe5: db $21, $01, $07, $10, $00, $00, $13, $05, $00, $00, $00, $00, $00, $00, $00, $00 +BlkPacket_9ff5: db $21, $02, $07, $0a, $00, $04, $13, $0d, $03, $05, $00, $06, $13, $0b, $00, $00 + +PalPacket_a005: + db $51 + RGB 8, 2, 0 + RGB 9, 2, 0 + RGB 10, 2, 0 + RGB 11, 2, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a015: + db $51 + RGB 11, 1, 0 + RGB 4, 1, 0 + RGB 0, 1, 0 + RGB 0, 0, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a025: + db $51 + RGB 1, 2, 0 + RGB 2, 2, 0 + RGB 3, 2, 0 + RGB 4, 2, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a035: + db $51 + RGB 12, 2, 0 + RGB 12, 2, 0 + RGB 12, 2, 0 + RGB 12, 2, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a045: + db $51 + RGB 0, 0, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a055: + db $51 + RGB 22, 1, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a065: + db $51 + RGB 23, 1, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a075: + db $51 + RGB 24, 1, 0 + RGB 25, 1, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a085: + db $51 + RGB 26, 1, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a095: + db $51 + RGB 27, 1, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a0a5: + db $51 + RGB 28, 1, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a0b5: + db $51 + RGB 25, 1, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a0c5: + db $51 + RGB 14, 1, 0 + RGB 15, 1, 0 + RGB 16, 1, 0 + RGB 17, 1, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a0d5: + db $51 + RGB 26, 0, 0 + RGB 26, 0, 0 + RGB 26, 0, 0 + RGB 26, 0, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a0e5: + db $51 + RGB 18, 1, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a0f5: + db $51 + RGB 28, 1, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a105: + db $51 + RGB 29, 1, 0 + RGB 30, 1, 0 + RGB 31, 1, 0 + RGB 0, 2, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a115: + db $51 + RGB 19, 1, 0 + RGB 20, 1, 0 + RGB 27, 0, 0 + RGB 31, 0, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a125: + db $51 + RGB 27, 0, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a135: + db $51 + RGB 28, 0, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a145: + db $51 + RGB 21, 1, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + RGB 0, 0, 0 + db $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a155: db $01, $ff, $7f, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 +PalPacket_a165: db $09, $ff, $7f, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 +PalPacket_a175: db $59, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 +PalPacket_a185: db $89, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 +PalPacket_a195: db $89, $01, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 +PalPacket_a1a5: db $99, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 +PalPacket_a1b5: db $a1, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 + +PalPacket_a1c5: db $b9, $01, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 +PalPacket_a1d5: db $b9, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 +PalPacket_a1e5: db $79, $5d, $08, $00, $0b, $8c, $d0, $f4, $60, $00, $00, $00, $00, $00, $00, $00 +PalPacket_a1f5: db $79, $52, $08, $00, $0b, $a9, $e7, $9f, $01, $c0, $7e, $e8, $e8, $e8, $e8, $e0 +PalPacket_a205: db $79, $47, $08, $00, $0b, $c4, $d0, $16, $a5, $cb, $c9, $05, $d0, $10, $a2, $28 +PalPacket_a215: db $79, $3c, $08, $00, $0b, $f0, $12, $a5, $c9, $c9, $c8, $d0, $1c, $a5, $ca, $c9 +PalPacket_a225: db $79, $31, $08, $00, $0b, $0c, $a5, $ca, $c9, $7e, $d0, $06, $a5, $cb, $c9, $7e +PalPacket_a235: db $79, $26, $08, $00, $0b, $39, $cd, $48, $0c, $d0, $34, $a5, $c9, $c9, $80, $d0 +PalPacket_a245: db $79, $1b, $08, $00, $0b, $ea, $ea, $ea, $ea, $ea, $a9, $01, $cd, $4f, $0c, $d0 +PalPacket_a255: db $79, $10, $08, $00, $0b, $4c, $20, $08, $ea, $ea, $ea, $ea, $ea, $60, $ea, $ea + +IF DEF(GOLD) +Palettes_a265: INCLUDE "gfx/pals/gold_a265.pal" +ENDC +IF DEF(SILVER) +Palettes_a265: INCLUDE "gfx/pals/silver_a265.pal" +ENDC + +IF DEF(GOLD) +SGBBorderMap: INCBIN "gfx/sgb_border/gold.map" +SGBBorderPalettes: INCLUDE "gfx/sgb_border/pals/gold.pal" +SGBBorder: INCBIN "gfx/sgb_border/gold.2bpp" +ENDC + +IF DEF(SILVER) +SGBBorderMap: INCBIN "gfx/sgb_border/silver.map" +SGBBorderPalettes: INCLUDE "gfx/sgb_border/pals/silver.pal" +SGBBorder: INCBIN "gfx/sgb_border/silver.2bpp" +ENDC + +Palettes_ad2d: + RGB 30, 26, 15 + RGB 00, 23, 00 + + RGB 30, 26, 15 + RGB 31, 21, 00 + + RGB 30, 26, 15 + RGB 31, 00, 00 + +Palettes_ad39: + RGB 30, 26, 15 + RGB 04, 17, 31 + +INCLUDE "gfx/pics/palette_pointers.asm" +INCLUDE "gfx/trainers/palette_pointers.asm" + +Functionb649: ; b649 (2:7649) + ld a, [wPermission] + and $7 + ld e, a + ld d, $0 + ld hl, Pointers_b6ce + add hl, de + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [wTimeOfDayPal] + and $3 + add a + add a + add a + ld e, a + ld d, $0 + add hl, de + ld e, l + ld d, h + ld hl, wTempBGPals + ld b, $8 +.asm_b66c + ld a, [de] + push de + push hl + ld l, a + ld h, $0 + add hl, hl + add hl, hl + add hl, hl + ld de, $775e + add hl, de + ld e, l + ld d, h + pop hl + ld c, $8 +.asm_b67e + ld a, [de] + inc de + ld [hli], a + dec c + jr nz, .asm_b67e + pop de + inc de + dec b + jr nz, .asm_b66c + ld a, [wTimeOfDayPal] + and $3 + ld bc, $40 + ld hl, MapObjectPals + call AddNTimes + ld de, wTempOBPal0 + ld bc, $40 + call CopyBytes + ld a, [wPermission] + cp $1 + jr z, .asm_b6aa + cp $2 + ret nz +.asm_b6aa + ld a, [wMapGroup] + ld l, a + ld h, $0 + add hl, hl + add hl, hl + add hl, hl + ld de, RoofPals + add hl, de + ld a, [wTimeOfDayPal] + and $3 + cp $2 + jr c, .asm_b6c4 + inc hl + inc hl + inc hl + inc hl +.asm_b6c4 + ld de, wTempBGPal6 + 2 + ld bc, $4 + call CopyBytes + ret + +Pointers_b6ce: + dw .OutdoorColors ; unused + dw .OutdoorColors ; TOWN + dw .OutdoorColors ; ROUTE + dw .IndoorColors ; INDOOR + dw .DungeonColors ; CAVE + dw .Perm5Colors ; ENVIRONMENT_5 + dw .IndoorColors ; GATE + dw .DungeonColors ; DUNGEON + +; Valid indices: $00 - $29 +.OutdoorColors: + db $00, $01, $02, $28, $04, $05, $06, $07 ; morn + db $08, $09, $0a, $28, $0c, $0d, $0e, $0f ; day + db $10, $11, $12, $29, $14, $15, $16, $17 ; nite + db $18, $19, $1a, $1b, $1c, $1d, $1e, $1f ; dark + +.IndoorColors: + db $20, $21, $22, $23, $24, $25, $26, $07 ; morn + db $20, $21, $22, $23, $24, $25, $26, $07 ; day + db $10, $11, $12, $13, $14, $15, $16, $07 ; nite + db $18, $19, $1a, $1b, $1c, $1d, $1e, $07 ; dark + +.DungeonColors: + db $00, $01, $02, $03, $04, $05, $06, $07 ; morn + db $08, $09, $0a, $0b, $0c, $0d, $0e, $0f ; day + db $10, $11, $12, $13, $14, $15, $16, $17 ; nite + db $18, $19, $1a, $1b, $1c, $1d, $1e, $1f ; dark + +.Perm5Colors: + db $00, $01, $02, $03, $04, $05, $06, $07 ; morn + db $08, $09, $0a, $0b, $0c, $0d, $0e, $0f ; day + db $10, $11, $12, $13, $14, $15, $16, $17 ; nite + db $18, $19, $1a, $1b, $1c, $1d, $1e, $1f ; dark + +TilesetBGPalette: ; b75e +INCLUDE "gfx/tilesets/bg.pal" + +MapObjectPals:: ; b8ae +INCLUDE "gfx/tilesets/ob.pal" + +RoofPals: ; b9ae +INCLUDE "gfx/tilesets/roof.pal" + +Palettes_ba86: + RGB 27, 31, 27 + RGB 21, 21, 21 + RGB 13, 13, 13 + RGB 00, 00, 00 + + RGB 27, 31, 27 + RGB 31, 07, 06 + RGB 20, 02, 03 + RGB 00, 00, 00 + + RGB 27, 31, 27 + RGB 10, 31, 09 + RGB 04, 14, 01 + RGB 00, 00, 00 + + RGB 27, 31, 27 + RGB 08, 12, 31 + RGB 01, 04, 31 + RGB 00, 00, 00 + + RGB 27, 31, 27 + RGB 31, 31, 07 + RGB 31, 16, 01 + RGB 00, 00, 00 + + RGB 27, 31, 27 + RGB 22, 16, 08 + RGB 13, 07, 01 + RGB 00, 00, 00 + + RGB 27, 31, 27 + RGB 15, 31, 31 + RGB 05, 17, 31 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 11, 11, 19 + RGB 07, 07, 12 + RGB 00, 00, 00 + +Palettes_bac6: + RGB 27, 31, 27 + RGB 31, 19, 10 + RGB 31, 07, 04 + RGB 00, 00, 00 + + RGB 27, 31, 27 + RGB 31, 19, 10 + RGB 10, 14, 20 + RGB 00, 00, 00 + + RGB 27, 31, 27 + RGB 31, 19, 10 + RGB 31, 07, 04 + RGB 00, 00, 00 + + RGB 27, 31, 27 + RGB 31, 19, 10 + RGB 31, 07, 04 + RGB 00, 00, 00 + + RGB 27, 31, 27 + RGB 31, 19, 10 + RGB 31, 07, 04 + RGB 00, 00, 00 + + RGB 27, 31, 27 + RGB 31, 19, 10 + RGB 31, 07, 04 + RGB 00, 00, 00 + + RGB 27, 31, 27 + RGB 31, 19, 10 + RGB 31, 07, 04 + RGB 00, 00, 00 + + RGB 27, 31, 27 + RGB 31, 19, 10 + RGB 31, 07, 04 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 21, 21, 21 + RGB 13, 13, 13 + RGB 07, 07, 07 + + RGB 31, 31, 31 + RGB 31, 31, 07 + RGB 31, 16, 01 + RGB 07, 07, 07 + + RGB 31, 31, 31 + RGB 31, 19, 24 + RGB 30, 10, 06 + RGB 07, 07, 07 + + RGB 31, 31, 31 + RGB 12, 25, 01 + RGB 05, 14, 00 + RGB 07, 07, 07 + + RGB 31, 31, 31 + RGB 08, 12, 31 + RGB 01, 04, 31 + RGB 07, 07, 07 + + RGB 31, 31, 31 + RGB 24, 18, 07 + RGB 20, 15, 03 + RGB 07, 07, 07 + +Palettes_bb36: +IF DEF(GOLD) + RGB 31, 31, 31 + RGB 18, 23, 31 + RGB 15, 20, 31 + RGB 0, 0, 0 + + RGB 31, 21, 0 + RGB 12, 14, 12 + RGB 15, 20, 31 + RGB 0, 0, 17 + + RGB 31, 31, 31 + RGB 31, 0, 0 + RGB 15, 20, 31 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 29, 25, 0 + RGB 15, 20, 31 + RGB 17, 10, 1 + + RGB 31, 31, 31 + RGB 23, 26, 31 + RGB 18, 23, 31 + RGB 0, 0, 0 +ENDC + +IF DEF(SILVER) + RGB 31, 31, 31 + RGB 0, 12, 15 + RGB 4, 8, 21 + RGB 0, 0, 0 + + RGB 31, 21, 0 + RGB 15, 17, 15 + RGB 4, 8, 21 + RGB 0, 0, 17 + + RGB 31, 31, 31 + RGB 31, 0, 0 + RGB 4, 8, 21 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 24, 23, 25 + RGB 4, 8, 21 + RGB 8, 8, 9 + + RGB 31, 31, 31 + RGB 5, 10, 11 + RGB 0, 12, 15 + RGB 0, 0, 0 +ENDC + +Palettes_bb5e: + RGB 31, 31, 31 + RGB 07, 06, 03 + RGB 07, 06, 03 + RGB 07, 06, 03 + + RGB 31, 31, 31 + RGB 31, 31, 00 + RGB 26, 22, 00 + RGB 00, 00, 00 + +Palettes_bb6e: + RGB 28, 31, 20 + RGB 21, 21, 21 + RGB 13, 13, 13 + RGB 00, 00, 00 + + RGB 28, 31, 20 + RGB 00, 31, 00 + RGB 00, 00, 31 + RGB 00, 00, 00 + + RGB 28, 31, 20 + RGB 00, 31, 00 + RGB 15, 07, 00 + RGB 00, 00, 00 + + RGB 28, 31, 20 + RGB 31, 15, 00 + RGB 15, 07, 00 + RGB 00, 00, 00 + + RGB 28, 31, 20 + RGB 00, 31, 00 + RGB 00, 00, 31 + RGB 31, 00, 00 + + RGB 28, 31, 20 + RGB 00, 31, 00 + RGB 15, 07, 00 + RGB 31, 00, 00 + +Palettes_bb9e: + RGB 31, 31, 31 + RGB 30, 22, 24 + RGB 18, 18, 18 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 10, 11, 31 + RGB 18, 18, 18 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 12, 31, 11 + RGB 18, 18, 18 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 29, 26, 05 + RGB 18, 18, 18 + RGB 00, 00, 00 + +Palettes_bbbe: +IF DEF(GOLD) + RGB 31, 31, 31 + RGB 24, 25, 28 + RGB 24, 24, 09 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 30, 10, 06 + RGB 24, 24, 09 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 15, 31, 00 + RGB 24, 24, 09 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 31, 15, 31 + RGB 24, 24, 09 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 15, 21, 31 + RGB 24, 24, 09 + RGB 00, 00, 00 + + RGB 31, 31, 11 + RGB 31, 31, 06 + RGB 24, 24, 09 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 16, 19, 29 + RGB 25, 22, 00 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 21, 21, 21 + RGB 13, 13, 13 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 30, 10, 06 + RGB 31, 00, 00 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 12, 25, 01 + RGB 05, 14, 00 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 12, 25, 01 + RGB 30, 10, 06 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 31, 31, 06 + RGB 20, 15, 03 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 31, 31, 06 + RGB 15, 21, 31 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 31, 31, 06 + RGB 20, 15, 03 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 31, 24, 21 + RGB 31, 13, 31 + RGB 00, 00, 00 + + RGB 31, 31, 31 + RGB 31, 31, 31 + RGB 00, 00, 00 + RGB 00, 00, 00 +ENDC + +IF DEF(SILVER) + RGB 31, 31, 31 + RGB 25, 26, 14 + RGB 20, 17, 31 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 30, 10, 6 + RGB 20, 17, 31 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 15, 31, 0 + RGB 20, 17, 31 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 31, 15, 31 + RGB 20, 17, 31 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 15, 21, 31 + RGB 20, 17, 31 + RGB 0, 0, 0 + + RGB 31, 31, 11 + RGB 31, 31, 6 + RGB 20, 17, 31 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 16, 19, 29 + RGB 25, 22, 0 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 21, 21, 21 + RGB 13, 13, 13 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 30, 10, 6 + RGB 31, 0, 0 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 12, 25, 1 + RGB 5, 14, 0 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 12, 25, 1 + RGB 30, 10, 6 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 31, 31, 6 + RGB 20, 15, 3 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 31, 31, 6 + RGB 15, 21, 31 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 31, 31, 6 + RGB 20, 15, 3 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 31, 24, 21 + RGB 31, 13, 31 + RGB 0, 0, 0 + + RGB 31, 31, 31 + RGB 31, 31, 31 + RGB 0, 0, 0 + RGB 0, 0, 0 +ENDC diff --git a/engine/health.asm b/engine/health.asm deleted file mode 100755 index a94a3ec3..00000000 --- a/engine/health.asm +++ /dev/null @@ -1,102 +0,0 @@ -HealParty: ; c69d (3:469d) - xor a - ld [wCurPartyMon], a - ld hl, wPartySpecies -.asm_c6a4 - ld a, [hli] - cp $ff - jr z, .asm_c6bb - cp $fd - jr z, .asm_c6b2 - push hl - call Functionc6bc - pop hl -.asm_c6b2 - ld a, [wCurPartyMon] - inc a - ld [wCurPartyMon], a - jr .asm_c6a4 - -.asm_c6bb - ret - -Functionc6bc: ; c6bc (3:46bc) - ld a, $0 - call GetPartyParamLocation - ld d, h - ld e, l - ld hl, $20 - add hl, de - xor a - ld [hli], a - ld [hl], a - ld hl, $24 - add hl, de - ld b, h - ld c, l - dec bc - dec bc - ld a, [hli] - ld [bc], a - inc bc - ld a, [hl] - ld [bc], a - farcall Functionf900 - ret - -ComputeHPBarPixels: -; e = bc * (6 * 8) / de - ld a, b - or c - jr z, .asm_c722 - push hl - xor a - ldh [hMultiplicand + 0], a - ld a, b - ldh [hMultiplicand + 1], a - ld a, c - ldh [hMultiplicand + 2], a - ld a, 6 * 8 - ldh [hMultiplier], a - call Multiply - ; We need de to be under 256 because hDivisor is only 1 byte. - ld a, d - and a - jr z, .asm_c711 - ; divide de and hProduct by 4 - srl d - rr e - srl d - rr e - ldh a, [hProduct + 2] - ld b, a - ldh a, [hProduct + 3] - srl b - rr a - srl b - rr a - ldh [hDividend + 3], a - ld a, b - ldh [hDividend + 2], a -.asm_c711 - ld a, e - ldh [hPrintNum5], a - ld b, $4 - call Divide - ldh a, [hPrintNum4] - ld e, a - pop hl - and a - ret nz - ld e, $1 - ret - -.asm_c722 - ld e, $0 - ret - -AnimateHPBar: ; c725 (3:4725) - call WaitBGMap - call AnimateHPBar_ - call WaitBGMap - ret diff --git a/engine/items.asm b/engine/items.asm deleted file mode 100755 index 428f652e..00000000 --- a/engine/items.asm +++ /dev/null @@ -1,551 +0,0 @@ -_ReceiveItem:: ; d1e2 (3:51e2) - call CheckBagOrPC - jp nz, PutItemInPocketOrPC - push hl - call CheckItemPocket - pop de - ld a, [wItemAttributeParamBuffer] - dec a - ld hl, .Jumptable - rst JumpTable - ret - -.Jumptable - dw ReceiveNormalItem - dw ReceiveKeyItem - dw ReceiveBall - dw ReceiveTMHM - -ReceiveNormalItem: - ld h, d - ld l, e - jp PutItemInPocketOrPC - -ReceiveKeyItem: - ld h, d - ld l, e - jp PutItemInKeyItemPocket - -ReceiveBall: - ld hl, wNumBalls - jp PutItemInPocketOrPC - -ReceiveTMHM: - ld h, d - ld l, e - ld a, [wCurItem] - ld c, a - call GetTMHMNumber - jp PutItemInTMPocket - -_TossItem:: ; d21a (3:521a) - call CheckBagOrPC - jr nz, remove_item_from_bag_or_pc - push hl - call CheckItemPocket - pop de - ld a, [wItemAttributeParamBuffer] - dec a - ld hl, .Jumptable ; $522d - rst JumpTable - ret - -.Jumptable - dw RemoveNormalItem - dw RemoveKeyItem - dw RemoveBall - dw RemoveTMHM - -RemoveBall: - ld hl, wNumBalls - jp RemoveItemAndQuantity - -RemoveTMHM: - ld h, d - ld l, e - ld a, [wCurItem] - ld c, a - call GetTMHMNumber - jp RemoveTMorHM - -RemoveKeyItem: - ld h, d - ld l, e - jp RemoveItemWithoutQuantity - -RemoveNormalItem: - ld h, d - ld l, e -remove_item_from_bag_or_pc - jp RemoveItemAndQuantity - -_CheckItem:: ; d251 (3:5251) - call CheckBagOrPC - jr nz, check_item_in_bag_or_pc - push hl - call CheckItemPocket - pop de - ld a, [wItemAttributeParamBuffer] - dec a - ld hl, .Jumptable - rst JumpTable - ret - -.Jumptable - dw CheckNormalItem - dw CheckKeyItem - dw CheckBall - dw CheckTMHM - -CheckBall: - ld hl, wNumBalls - jp CheckItemWithQuantity - -CheckTMHM: - ld h, d - ld l, e - ld a, [wCurItem] - ld c, a - call GetTMHMNumber - jp CheckTMorHM - -CheckKeyItem: - ld h, d - ld l, e - jp CheckItemWithoutQuantity - -CheckNormalItem: - ld h, d - ld l, e -check_item_in_bag_or_pc - jp CheckItemWithQuantity - -CheckBagOrPC: ; d288 (3:5288) - ld a, l - cp wNumItems % $100 - ret nz - ld a, h - cp wNumItems / $100 - ret - -GetPocketCapacity: ; d290 (3:5290) - ld c, MAX_ITEMS - ld a, e - cp wNumItems % $100 - jr nz, .asm_d29b - ld a, d - cp wNumItems / $100 - ret z -.asm_d29b - ld c, MAX_PC_ITEMS - ld a, e - cp wPCItems % $100 - jr nz, .asm_d2a6 - ld a, d - cp wPCItems / $100 - ret z -.asm_d2a6 - ld c, MAX_BALLS - ret - -PutItemInPocketOrPC: ; d2a9 (3:52a9) - ld d, h - ld e, l - inc hl - ld a, [wCurItem] - ld c, a - ld b, $0 -.asm_d2b2 - ld a, [hli] - cp $ff - jr z, .asm_d2ca - cp c - jr nz, .asm_d2c7 - ld a, $63 - sub [hl] - add b - ld b, a - ld a, [wItemQuantityChangeBuffer] - cp b - jr z, .asm_d2d3 - jr c, .asm_d2d3 -.asm_d2c7 - inc hl - jr .asm_d2b2 - -.asm_d2ca - call GetPocketCapacity - ld a, [de] - cp c - jr c, .asm_d2d3 - and a - ret - -.asm_d2d3 - ld h, d - ld l, e - ld a, [wCurItem] - ld c, a - ld a, [wItemQuantityChangeBuffer] - ld [wItemQuantityBuffer], a -.asm_d2df - inc hl - ld a, [hli] - cp $ff - jr z, .asm_d2fc - cp c - jr nz, .asm_d2df - ld a, [wItemQuantityBuffer] - add [hl] - cp $64 - jr nc, .asm_d2f3 - ld [hl], a - jr .asm_d30a - -.asm_d2f3 - ld [hl], $63 - sub $63 - ld [wItemQuantityBuffer], a - jr .asm_d2df - -.asm_d2fc - dec hl - ld a, [wCurItem] - ld [hli], a - ld a, [wItemQuantityBuffer] - ld [hli], a - ld [hl], $ff - ld h, d - ld l, e - inc [hl] -.asm_d30a - scf - ret - -RemoveItemAndQuantity: ; d30c (3:530c) - ld d, h - ld e, l - ld a, [hli] - ld c, a - ld a, [wCurItemQuantity] - cp c - jr nc, .asm_d325 - ld c, a - ld b, $0 - add hl, bc - add hl, bc - ld a, [wCurItem] - cp [hl] - inc hl - jr z, .asm_d334 - ld h, d - ld l, e - inc hl -.asm_d325 - ld a, [wCurItem] - ld b, a -.asm_d329 - ld a, [hli] - cp b - jr z, .asm_d334 - cp $ff - jr z, .asm_d354 - inc hl - jr .asm_d329 - -.asm_d334 - ld a, [wItemQuantityChangeBuffer] - ld b, a - ld a, [hl] - sub b - jr c, .asm_d354 - ld [hl], a - ld [wItemQuantityBuffer], a - and a - jr nz, .asm_d352 - dec hl - ld b, h - ld c, l - inc hl - inc hl -.asm_d348 - ld a, [hli] - ld [bc], a - inc bc - cp $ff - jr nz, .asm_d348 - ld h, d - ld l, e - dec [hl] -.asm_d352 - scf - ret - -.asm_d354 - and a - ret - -CheckItemWithQuantity: ; d356 (3:5356) - ld a, [wCurItem] - ld c, a -.asm_d35a - inc hl - ld a, [hli] - cp $ff - jr z, .asm_d365 - cp c - jr nz, .asm_d35a - scf - ret - -.asm_d365 - and a - ret - -PutItemInKeyItemPocket: ; d367 (3:5367) - ld hl, wItemsEnd - ld a, [hli] - cp $19 - jr nc, .asm_d37f - ld c, a - ld b, $0 - add hl, bc - ld a, [wCurItem] - ld [hli], a - ld [hl], $ff - ld hl, wNumKeyItems - inc [hl] - scf - ret - -.asm_d37f - and a - ret - -RemoveItemWithoutQuantity: ; d381 (3:5381) - ld a, [wCurItemQuantity] - ld e, a - ld d, $0 - ld hl, wItemsEnd - ld a, [hl] - cp e - jr nc, .asm_d394 - call FindAndTossKeyItem - ret nc - jr .asm_d397 - -.asm_d394 - dec [hl] - inc hl - add hl, de -.asm_d397 - ld d, h - ld e, l - inc hl -.asm_d39a - ld a, [hli] - ld [de], a - inc de - cp $ff - jr nz, .asm_d39a - scf - ret - -FindAndTossKeyItem: ; d3a3 (3:53a3) - ld hl, wItemsEnd - ld a, [wCurItem] - ld c, a -.asm_d3aa - inc hl - ld a, [hl] - cp c - jr z, .asm_d3b5 - cp $ff - jr nz, .asm_d3aa - xor a - ret - -.asm_d3b5 - ld a, [wNumKeyItems] - dec a - ld [wNumKeyItems], a - scf - ret - -CheckItemWithoutQuantity: ; d3be (3:53be) - ld a, [wCurItem] - ld c, a - ld hl, wKeyItems -.asm_d3c5 - ld a, [hli] - cp c - jr z, .asm_d3cf - cp $ff - jr nz, .asm_d3c5 - and a - ret - -.asm_d3cf - scf - ret - -PutItemInTMPocket: ; d3d1 (3:53d1) - dec c - ld b, $0 - ld hl, wTMsHMs - add hl, bc - ld a, [wItemQuantityChangeBuffer] - add [hl] - cp $64 - jr nc, .asm_d3e3 - ld [hl], a - scf - ret - -.asm_d3e3 - and a - ret - -RemoveTMorHM: ; d3e5 (3:53e5) - dec c - ld b, $0 - ld hl, wTMsHMs - add hl, bc - ld a, [wItemQuantityChangeBuffer] - ld b, a - ld a, [hl] - sub b - jr c, .asm_d406 - ld [hl], a - ld [wItemQuantityBuffer], a - jr nz, .asm_d404 - ld a, [wcfd2] - and a - jr z, .asm_d404 - dec a - ld [wcfd2], a -.asm_d404 - scf - ret - -.asm_d406 - and a - ret - -CheckTMorHM: ; d408 (3:5408) - dec c - ld b, $0 - ld hl, wTMsHMs - add hl, bc - ld a, [hl] - and a - ret z - scf - ret - -GetTMHMNumber:: ; d414 (3:5414) - ld a, c - cp ITEM_C3 - jr c, .asm_d41f - cp ITEM_DC - jr c, .asm_d41e - dec a -.asm_d41e - dec a -.asm_d41f - sub $bf - inc a - ld c, a - ret - -GetNumberedTM: - ld a, c - cp ITEM_C3 - (TM01 - 1) - jr c, .asm_d42f - cp ITEM_DC - (TM01 - 1) - 1 - jr c, .asm_d42e - inc a -.asm_d42e - inc a -.asm_d42f - add TM01 - dec a - ld c, a - ret - -_CheckTossableItem:: ; d434 (3:5434) - ld a, $4 - call GetItemAttr - bit 7, a - jr nz, ItemAttr_ReturnCarry - and a - ret - -CheckSelectableItem: - ld a, $4 - call GetItemAttr - bit 6, a - jr nz, ItemAttr_ReturnCarry - and a - ret - -CheckItemPocket: ; d44a (3:544a) - ld a, $5 - call GetItemAttr - and $f - ld [wItemAttributeParamBuffer], a - ret - -CheckItemContext: - ld a, $6 - call GetItemAttr - and $f - ld [wItemAttributeParamBuffer], a - ret - -CheckItemMenu: - ld a, $6 - call GetItemAttr - swap a - and $f - ld [wItemAttributeParamBuffer], a - ret - -GetItemAttr: ; d46d (3:546d) - push hl - push bc - ld hl, ItemAttributes - ld c, a - ld b, $0 - add hl, bc - xor a - ld [wItemAttributeParamBuffer], a - ld a, [wCurItem] - dec a - ld c, a - ld a, $7 - call AddNTimes - ld a, BANK(ItemAttributes) - call GetFarByte - pop bc - pop hl - ret - -ItemAttr_ReturnCarry - ld a, $1 - ld [wItemAttributeParamBuffer], a - scf - ret - -GetItemPrice: - push hl - push bc - ld a, $0 - call GetItemAttr - ld e, a - ld a, $1 - call GetItemAttr - ld d, a - pop bc - pop hl - ret diff --git a/engine/items/item_effects.asm b/engine/items/item_effects.asm new file mode 100755 index 00000000..274b8468 --- /dev/null +++ b/engine/items/item_effects.asm @@ -0,0 +1,2897 @@ +_DoItemEffect:: ; e7a6 (3:67a6) + ld a, [wCurItem] + ld [wd151], a + call GetItemName + call CopyName1 + ld a, $1 + ld [wFieldMoveSucceeded], a + ld a, [wCurItem] + dec a + ld hl, .ItemEffects + rst JumpTable + ret + +.ItemEffects + dw MasterBall + dw UltraBall + dw Brightpowder + dw GreatBall + dw PokeBall + dw TownMap + dw Bicycle + dw MoonStone + dw Antidote + dw BurnHeal + dw IceHeal + dw Awakening + dw ParlyzHeal + dw FullRestore + dw MaxPotion + dw HyperPotion + dw SuperPotion + dw Potion + dw EscapeRope + dw Repel + dw MaxElixer + dw FireStone + dw Thunderstone + dw WaterStone + dw Item19 + dw HPUp + dw Protein + dw Iron + dw Carbos + dw LuckyPunch + dw Calcium + dw RareCandy + dw XAccuracy + dw LeafStone + dw MetalPowder + dw Nugget + dw PokeDoll + dw FullHeal + dw Revive + dw MaxRevive + dw GuardSpec + dw SuperRepel + dw MaxRepel + dw DireHit + dw Item2D + dw FreshWater + dw SodaPop + dw Lemonade + dw XAttack + dw Item32 + dw XDefend + dw XSpeed + dw XSpecial + dw CoinCase + dw ItemfinderEffect + dw PokeFlute + dw ExpShare + dw OldRod + dw GoodRod + dw SilverLeaf + dw SuperRod + dw PPUp + dw Ether + dw MaxEther + dw Elixer + dw RedScale + dw Secretpotion + dw SSTicket + dw MysteryEgg + dw Item47 + dw SilverWing + dw MoomooMilk + dw QuickClaw + dw Psncureberry + dw GoldLeaf + dw SoftSand + dw SharpBeak + dw Przcureberry + dw BurntBerry + dw IceBerry + dw PoisonBarb + dw KingsRock + dw BitterBerry + dw MintBerry + dw RedApricorn + dw Tinymushroom + dw BigMushroom + dw Silverpowder + dw BluApricorn + dw Item5A + dw AmuletCoin + dw YlwApricorn + dw GrnApricorn + dw CleanseTag + dw MysticWater + dw Twistedspoon + dw WhtApricorn + dw Blackbelt + dw BlkApricorn + dw Item64 + dw PnkApricorn + dw Blackglasses + dw Slowpoketail + dw PinkBow + dw Stick + dw SmokeBall + dw Nevermeltice + dw Magnet + dw Miracleberry + dw Pearl + dw BigPearl + dw Everstone + dw SpellTag + dw Ragecandybar + dw Item73 + dw Item74 + dw MiracleSeed + dw ThickClub + dw FocusBand + dw Item78 + dw Energypowder + dw EnergyRoot + dw HealPowder + dw RevivalHerb + dw HardStone + dw LuckyEgg + dw CardKey + dw MachinePart + dw Item81 + dw LostItem + dw Stardust + dw StarPiece + dw BasementKey + dw Pass + dw Item87 + dw Item88 + dw Item89 + dw Charcoal + dw BerryJuice + dw ScopeLens + dw Item8D + dw Item8E + dw MetalCoat + dw DragonFang + dw Item91 + dw Leftovers + dw Item93 + dw Item94 + dw Item95 + dw Mysteryberry + dw DragonScale + dw BerserkGene + dw Item99 + dw Item9A + dw Item9B + dw SacredAsh + dw HeavyBall + dw FlowerMail + dw LevelBall + dw LureBall + dw FastBall + dw ItemA2 + dw LightBall + dw FriendBall + dw MoonBall + dw LoveBall + dw NormalBox + dw GorgeousBox + dw SunStone + dw PolkadotBow + dw ItemAB + dw UpGrade + dw Berry + dw GoldBerry + dw Squirtbottle + dw ItemB0 + dw ParkBall + dw RainbowWing + dw ItemB3 + +FastBall: ; e926 +FriendBall: ; e926 +GreatBall: ; e926 +HeavyBall: ; e926 +LevelBall: ; e926 +LoveBall: ; e926 +LureBall: ; e926 +MasterBall: ; e926 +MoonBall: ; e926 +ParkBall: ; e926 +PokeBall: ; e926 +UltraBall: ; e926 + ld a, [wBattleMode] + dec a + jp nz, Functionf7e7 + ld a, [wPartyCount] + cp PARTY_LENGTH + jr nz, .room_in_party_or_pc + ld a, $1 + call OpenSRAM + ld a, [$ad6c] + cp $14 + call CloseSRAM + jp z, FailToUseBall +.room_in_party_or_pc + xor a + ld [wWildMon], a + ld a, [wCurItem] + cp PARK_BALL + call nz, ReturnToBattle_UseBall + ld hl, wOptions + res NO_TEXT_SCROLL, [hl] + ld hl, Text_UsedItem ; $7884 + call PrintText + ld a, [wd114] + ld b, a + ld a, [wBattleType] + cp BATTLETYPE_TUTORIAL + jp z, .catch_without_fail + ld a, [wCurItem] + cp MASTER_BALL + jp z, .catch_without_fail + ld a, [wCurItem] + ld c, a + ld hl, BallMultiplierFunctionTable ; $6c73 +.get_multiplier_loop + ld a, [hli] + cp $ff + jr z, .skip_or_return_from_ball_fn + cp c + jr z, .call_ball_function + inc hl + inc hl + jr .get_multiplier_loop + +.call_ball_function + ld a, [hli] + ld h, [hl] + ld l, a + ld de, .skip_or_return_from_ball_fn + push de + jp hl + +.skip_or_return_from_ball_fn + ld a, [wCurItem] + cp LEVEL_BALL + ld a, b + jp z, .skip_hp_calc + ld a, b + ldh [hPrintNum4], a + ld hl, wEnemyMonHP + ld b, [hl] + inc hl + ld c, [hl] + inc hl + ld d, [hl] + inc hl + ld e, [hl] +; (3 * MaxHP - 2 * CurHP) / (3 * MaxHP) * level + sla c + rl b + ld h, d + ld l, e + add hl, de + add hl, de + ld d, h + ld e, l +; This routine is buggy. The intention is to get de, the Max HP score, +; to be an 8-bit number. To do this, we divide both bc and de by 4. +; It only does this division once, and doesn't check to make sure that +; e is not zero. In addition to passing along a divide-by-zero error, +; this could also cause an unusually small denominator to be passed, +; sending the resulting catch rate through the floor. + ld a, d + and a + jr z, .okay_hp_div + srl d + rr e + srl d + rr e + srl b + rr c + srl b + rr c + ld a, c + and a + jr nz, .okay_hp_div + ld c, $1 +.okay_hp_div + ld b, e + + push bc + ld a, b + sub c + ldh [hMultiplier], a + xor a + ldh [hDividend + 0], a + ldh [hMultiplicand + 0], a + ldh [hMultiplicand + 1], a + call Multiply + pop bc + + ld a, b + ldh [hDivisor], a + ld b, $4 + call Divide + + ldh a, [hQuotient + 2] + and a + jr nz, .statuscheck + ld a, 1 +.statuscheck +; This routine is buggy. It was intended that SLP and FRZ provide a higher +; catch rate than BRN/PSN/PAR, which in turn provide a higher catch rate than +; no status effect at all. But instead, it makes BRN/PSN/PAR provide no +; benefit. +; Uncomment the line below to fix this. + ld b, a + ld a, [wEnemyMonStatus] + and 1 << FRZ | SLP + ld c, $a + jr nz, .add_status + ; ld a, [wEnemyMonStatus] + and a + ld c, $5 + jr nz, .add_status + ld c, $0 +.add_status + ld a, b + add c + jr nc, .max_catch_rate + ld a, $ff +.max_catch_rate + ld d, a + push de + + ; BUG: farcall overwrites a, + ; and GetItemHeldEffect takes b anyway. + + ; This is probably the reason + ; the HELD_CATCH_CHANCE effect + ; is never used. + + ; Uncomment the line below to fix. + + ld a, [wBattleMonItem] + ; ld b, a + farcall GetItemHeldEffect ; d:7e9b + ld a, b + cp HELD_CATCH_CHANCE + pop de + ld a, d + jr nz, .skip_hp_calc + add c + jr nc, .skip_hp_calc + ld a, $ff +.skip_hp_calc + ld b, a + ld [wCurHPAnimMaxHP], a + call Random + cp b + ld a, $0 + jr z, .catch_without_fail + jr nc, .asm_ea23 +.catch_without_fail + ld a, [wEnemyMonSpecies] +.asm_ea23 + ld [wWildMon], a + ld c, 20 + call DelayFrames + ld a, [wCurItem] + cp POKE_BALL + 1 + jr c, .asm_ea34 + ld a, $5 +.asm_ea34 + ld [wcb67], a + ld de, ANIM_THROW_POKE_BALL + ld a, e + ld [wcf3e], a + ld a, d + ld [wcf3f], a + xor a + ldh [hBattleTurn], a + ld [wBuffer2], a + ld [wcf46], a + predef PlayBattleAnim + ld a, [wWildMon] + and a + jr nz, .caught + ld a, [wBuffer2] + cp $1 + ld hl, Text_ThePokemonBrokeFree ; $6e09 + jp z, .break_free + cp $2 + ld hl, Text_AppearedToBeCaught ; $6e0e + jp z, .break_free + cp $3 + ld hl, Text_AarghAlmostHadIt ; $6e13 + jp z, .break_free + cp $4 + ld hl, Text_ShootItWasSoCloseToo ; $6e18 + jp z, .break_free +.caught + ld hl, wEnemyMonStatus + ld a, [hli] + push af + inc hl + ld a, [hli] + push af + ld a, [hl] + push af + push hl + ld hl, wEnemyMonItem + ld a, [hl] + push af + push hl + ld hl, wEnemySubStatus5 + ld a, [hl] + push af + set SUBSTATUS_TRANSFORMED, [hl] + bit SUBSTATUS_TRANSFORMED, a + jr nz, .ditto + jr .not_ditto + +.ditto + ld a, DITTO + ld [wTempEnemyMonSpecies], a + jr .load_data + +.not_ditto + set SUBSTATUS_TRANSFORMED, [hl] + ld hl, wcbd0 + ld a, [wEnemyMonDVs] + ld [hli], a + ld a, [wEnemyMonMovesEnd + 1] + ld [hl], a +.load_data + ld a, [wTempEnemyMonSpecies] + ld [wCurPartySpecies], a + ld a, [wEnemyMonLevel] + ld [wCurPartyLevel], a + farcall LoadEnemyMon + pop af + ld [wEnemySubStatus5], a + pop hl + pop af + ld [hl], a + pop hl + pop af + ld [hld], a + pop af + ld [hld], a + dec hl + pop af + ld [hl], a + ld hl, wEnemySubStatus5 + bit SUBSTATUS_TRANSFORMED, [hl] + jr nz, .transformed + ld hl, wWildMonMoves + ld de, wEnemyMonMoves + ld bc, NUM_MOVES + call CopyBytes + ld hl, wWildMonPP + ld de, wEnemyMonPP + ld bc, NUM_MOVES + call CopyBytes +.transformed + ld a, [wEnemyMonSpecies] + ld [wWildMon], a + ld [wCurPartySpecies], a + ld [wd151], a + ld a, [wBattleType] + cp BATTLETYPE_TUTORIAL + jp z, .finish_tutorial + ld hl, Text_GotchaMonWasCaught ; $6e1d + call PrintText + call ClearSprites + ld a, [wd151] + dec a + call CheckCaughtMon + ld a, c + push af + ld a, [wd151] + dec a + call SetSeenAndCaughtMon + pop af + and a + jr nz, .skip_dex + call CheckReceivedDex + jr z, .skip_dex + ld hl, Text_MonNewlyAddedToPokedex ; $6e44 + call PrintText + call ClearSprites + ld a, [wEnemyMonSpecies] + ld [wd151], a + predef NewPokedexEntry +.skip_dex + ld a, [wBattleType] + cp BATTLETYPE_CONTEST + jp z, .catch_bug_contest_mon + ld a, [wPartyCount] + cp PARTY_LENGTH + jr z, .send_mon_to_pc + xor a + ld [wMonType], a + call ClearSprites + predef TryAddMonToParty + ld a, [wCurItem] + cp FRIEND_BALL + jr nz, .skip_party_mon_friend_ball + ld a, [wPartyCount] + dec a + ld hl, wPartyMon1Happiness + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + ld a, FRIEND_BALL_HAPPINESS + ld [hl], a +.skip_party_mon_friend_ball + ld hl, Text_AskNicknameNewlyCaughtMon ; $6e49 + call PrintText + ld a, [wCurPartySpecies] + ld [wd151], a + call GetPokemonName + call YesNoBox + jp c, .end_ball_function + ld a, [wPartyCount] + dec a + ld [wCurPartyMon], a + ld hl, wPartyMon1Nickname + ld bc, MON_NAME_LENGTH + call AddNTimes + ld d, h + ld e, l + push de + xor a + ld [wMonType], a + ld b, $0 + farcall NamingScreen + call RotateThreePalettesRight + call Functiond9e + pop hl + ld de, wStringBuffer1 + call InitName + jp .end_ball_function + +.send_mon_to_pc + call ClearSprites + predef SendMonIntoBox + ld a, BANK(sBoxCount) + call OpenSRAM + ld a, [sBoxCount] + cp MONS_PER_BOX + jr nz, .not_full_yet + ld hl, wBattleResult + set 7, [hl] +.not_full_yet + ld a, [wCurItem] + cp FRIEND_BALL + jr nz, .skip_box_mon_friend_ball + ld a, FRIEND_BALL_HAPPINESS + ld [sBoxMon1Happiness], a +.skip_box_mon_friend_ball + call CloseSRAM + ld hl, Text_AskNicknameNewlyCaughtMon ; $6e49 + call PrintText + ld a, [wCurPartySpecies] + ld [wd151], a + call GetPokemonName + call YesNoBox + jr c, .init_name_in_sram + xor a + ld [wCurPartyMon], a + ld a, $2 + ld [wMonType], a + ld de, wMonOrItemNameBuffer + ld b, $0 + farcall NamingScreen + ld a, $1 + call OpenSRAM + ld hl, wMonOrItemNameBuffer + ld de, sBoxMonNicknames + ld bc, MON_NAME_LENGTH + call CopyBytes + ld hl, sBoxMonNicknames + ld de, wStringBuffer1 + call InitName + call CloseSRAM +.init_name_in_sram + ld a, $1 + call OpenSRAM + ld hl, sBoxMonNicknames + ld de, wMonOrItemNameBuffer + ld bc, MON_NAME_LENGTH + call CopyBytes + call CloseSRAM + ld hl, Text_SentToBillsPC ; $6e3f + call PrintText + call RotateThreePalettesRight + call Functiond9e + jr .end_ball_function + +.catch_bug_contest_mon + farcall BugContest_SetCaughtContestMon ; same bank + jr .end_ball_function + +.finish_tutorial + ld hl, Text_GotchaMonWasCaught ; $6e1d +.break_free + call PrintText + call ClearSprites +.end_ball_function + ld a, [wBattleType] + cp BATTLETYPE_TUTORIAL + ret z + cp BATTLETYPE_DEBUG + ret z + cp BATTLETYPE_CONTEST + jr z, .used_park_ball + ld a, [wWildMon] + and a + jr z, .toss + call ClearBGPalettes + call ClearTilemap +.toss + ld hl, wNumItems + inc a + ld [wItemQuantityChangeBuffer], a + jp TossItem + +.used_park_ball + ld hl, wParkBallsRemaining + dec [hl] + ret + +BallMultiplierFunctionTable: ; ec73 + dbw ULTRA_BALL, UltraBallMultiplier + dbw GREAT_BALL, GreatBallMultiplier + dbw SAFARI_BALL, SafariBallMultiplier ; Safari Ball, leftover from RBY + dbw HEAVY_BALL, HeavyBallMultiplier + dbw LEVEL_BALL, LevelBallMultiplier + dbw LURE_BALL, LureBallMultiplier + dbw FAST_BALL, FastBallMultiplier + dbw MOON_BALL, MoonBallMultiplier + dbw LOVE_BALL, LoveBallMultiplier + dbw PARK_BALL, ParkBallMultiplier + db $ff + +UltraBallMultiplier: + sla b + ret nc + ld b, $ff + ret + +GreatBallMultiplier: +SafariBallMultiplier: +ParkBallMultiplier: + ld a, b + srl a + add b + ld b, a + ret nc + ld b, $ff + ret + +HeavyBallMultiplier: + ld a, [wEnemyMon] + dec a + ld hl, PokedexDataPointerTable + ld e, a + ld d, $0 + add hl, de + add hl, de + rlca + rlca + and $3 + add BANK("Pokedex Entries 001-064") + ld d, a + ld a, BANK(PokedexDataPointerTable) + call GetFarHalfword +.loop + ld a, d + call GetFarByte + inc hl + cp "@" + jr nz, .loop + ld a, d + push bc + inc hl + inc hl + call GetFarHalfword + srl h + rr l + ld b, h + ld c, l + srl b + rr c + srl b + rr c + srl b + rr c + srl b + rr c + call .sub_bc + srl b + rr c + call .sub_bc + ld a, h + pop bc + jr .compare + +.sub_bc + push bc + ld a, b + cpl + ld b, a + ld a, c + cpl + ld c, a + inc bc + add hl, bc + pop bc + ret + +.compare + ld c, a + cp 1024 >> 8 ; 102.4 kg + jr c, .lightmon + ld hl, .WeightsTable ; $6d18 +.lookup + ld a, c + cp [hl] + jr c, .heavymon + inc hl + inc hl + jr .lookup + +.heavymon + inc hl + ld a, b + add [hl] + ld b, a + ret nc + ld b, $ff + ret + +.lightmon + ld a, b + sub 20 + ld b, a + ret nc + ld b, $1 + ret + +.WeightsTable +; weight factor, boost + db 2048 >> 8, 0 + db 3072 >> 8, 20 + db 4096 >> 8, 30 + db 65280 >> 8, 40 + +LureBallMultiplier: + ld a, [wBattleType] + cp BATTLETYPE_FISH + ret nz + ld a, b + add a + jr c, .asm_ed2d + add b + jr nc, .asm_ed2f +.asm_ed2d + ld a, $ff +.asm_ed2f + ld b, a + ret + +MoonBallMultiplier: +; This function is buggy. +; Intent: multiply catch rate by 4 if mon evolves with moon stone +; Reality: no boost + push bc + ld a, [wTempEnemyMonSpecies] + dec a + ld c, a + ld b, $0 + ld hl, EvosAttacksPointers ; $67bd + add hl, bc + add hl, bc + ld a, BANK(EvosAttacksPointers) ; $10 + call GetFarHalfword + pop bc + push bc + ld a, BANK(EvosAttacksPointers) ; $10 + call GetFarByte + cp EVOLVE_ITEM + pop bc + ret nz + inc hl + inc hl + inc hl +; Moon Stone's constant from Pokémon Red is used. +; No Pokémon evolve with Burn Heal, +; so Moon Balls always have a catch rate of 1×. + push bc + ld a, BANK(EvosAttacksPointers) ; $10 + call GetFarByte + cp MOON_STONE_RED ; BURN_HEAL + pop bc + ret nz + sla b + jr c, .max + sla b + jr nc, .done +.max + ld b, $ff +.done + ret + +LoveBallMultiplier: +; This function is buggy. +; Intent: multiply catch rate by 8 if mons are of same species, different sex +; Reality: multiply catch rate by 8 if mons are of same species, same sex + ld a, [wTempEnemyMonSpecies] + ld c, a + ld a, [wd0ee] + cp c + ret nz + push bc + ld a, [wd0ee] + ld [wCurPartySpecies], a + xor a + ld [wMonType], a + ld a, [wCurBattleMon] + ld [wCurPartyMon], a + farcall GetGender ; 14:52f1 + jr c, .asm_edba + ld d, $0 + jr nz, .asm_ed8d + inc d +.asm_ed8d + push de + ld a, [wTempEnemyMonSpecies] + ld [wCurPartySpecies], a + ld a, $4 + ld [wMonType], a + farcall GetGender ; 14:52f1 + jr c, .asm_edb9 + ld d, $0 + jr nz, .asm_eda6 + inc d +.asm_eda6 + ld a, d + pop de + cp d + pop bc + ret nz ; for the intended effect, this should be “ret z” + sla b + jr c, .asm_edb6 + sla b + jr c, .asm_edb6 + sla b + ret nc +.asm_edb6 + ld b, $ff + ret + +.asm_edb9 + pop de +.asm_edba + pop bc + ret + +FastBallMultiplier: +; This function is buggy. +; Intent: multiply catch rate by 4 if enemy mon is in one of the three +; FleeMons tables. +; Reality: multiply catch rate by 4 if enemy mon is one of the first three in +; the first FleeMons table. + ld a, [wTempEnemyMonSpecies] + ld c, a + ld hl, FleeMons + ld d, $3 +.asm_edc5 + ld a, BANK(FleeMons) + call GetFarByte + inc hl + cp $ff + jr z, .asm_eddc + cp c + jr nz, .asm_eddc ; for the intended effect, this should be “jr nz, .loop” + sla b + jr c, .asm_edd9 + sla b + ret nc +.asm_edd9 + ld b, $ff + ret + +.asm_eddc + dec d + jr nz, .asm_edc5 + ret + +LevelBallMultiplier: +; multiply catch rate by 8 if player mon level / 4 > enemy mon level +; multiply catch rate by 4 if player mon level / 2 > enemy mon level +; multiply catch rate by 2 if player mon level > enemy mon level + ld a, [wBattleMonLevel] + ld c, a + ld a, [wEnemyMonLevel] + cp c + ret nc + sla b + jr c, .asm_edfc + srl c + cp c + ret nc + sla b + jr c, .asm_edfc + srl c + cp c + ret nc + sla b + ret nc +.asm_edfc + ld b, $ff + ret + +; These two texts were carried over from gen 1. +; They are not used in gen 2, and are dummied out. + +Text_ThisMonCantBeCaught: + text_far Text_ThisMonCantBeCaught_ + db "@" + +Text_YouMissedThePokemon: + text_far Text_YouMissedThePokemon_ + db "@" + +Text_ThePokemonBrokeFree: + text_far Text_ThePokemonBrokeFree_ + db "@" + +Text_AppearedToBeCaught: + text_far Text_AppearedToBeCaught_ + db "@" + +Text_AarghAlmostHadIt: + text_far Text_AarghAlmostHadIt_ + db "@" + +Text_ShootItWasSoCloseToo: + text_far Text_ShootItWasSoCloseToo_ + db "@" + +Text_GotchaMonWasCaught: + text_far Text_GotchaMonWasCaught_ + text_asm + call WaitSFX + push bc + ld de, MUSIC_NONE + call PlayMusic + call DelayFrame + ld de, MUSIC_CAPTURE + call PlayMusic + pop bc + ld hl, Text_CaughtMonWaitbutton + ret + +Text_CaughtMonWaitbutton: + text_far Text_Promptbutton_2 + db "@" + +Text_SentToBillsPC: + text_far Text_SentToBillsPC_ + db "@" + +Text_MonNewlyAddedToPokedex: + text_far Text_MonNewlyAddedToPokedex_ + db "@" + +Text_AskNicknameNewlyCaughtMon: + text_far Text_AskNicknameNewlyCaughtMon_ + db "@" + +ReturnToBattle_UseBall: ; ee4e (3:6e4e) + farcall ReturnToBattle_UseBall_ ; 9:7307 + ret + +TownMap: ; ee55 (3:6e55) + farcall TownMap_ ; 24:5a4f + ret + +Bicycle: ; ee5c + farcall BicycleFunction ; same bank + ret + +FireStone: ; ee63 +LeafStone: ; ee63 +MoonStone: ; ee63 +SunStone: ; ee63 +Thunderstone: ; ee63 +WaterStone: ; ee63 + ld b, PARTYMENUACTION_EVO_STONE + call Functionf24f + jp c, .cancel + ld a, MON_ITEM + call GetPartyParamLocation + ld a, [hl] + cp EVERSTONE + jr z, .failed + ld a, $1 + ld [wd0d2], a + farcall EvolvePokemon ; 10:61db + ld a, [wd154] + and a + jr z, .failed + jp Functionf7dc + +.failed + call Functionf839 +.cancel + xor a + ld [wFieldMoveSucceeded], a + ret + + +Calcium: ; ee91 +Carbos: ; ee91 +HPUp: ; ee91 +Iron: ; ee91 +Protein: ; ee91 + ld b, PARTYMENUACTION_HEALING_ITEM + call Functionf24f + jp c, Functioneef3 + call Functionef49 + call Functionef2d + ld a, MON_STAT_EXP + call GetPartyParamLocation + add hl, bc + ld a, [hl] + cp 100 + jr nc, Functioneed7 + add 10 + ld [hl], a + call Functioneee0 + call Functionef2d + ld hl, StatStrings + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + ld de, wStringBuffer2 + ld bc, ITEM_NAME_LENGTH + call CopyBytes + call Functionf7c7 + ld hl, Text_StatRoseFromVitamin ; $6efa + call PrintText + ld c, HAPPINESS_USEDITEM + farcall ChangeHappiness + jp Functionf7dc + +Functioneed7: + ld hl, Text_WontHaveAnyEffect ; $7866 + call PrintText + jp ClearPalettes + +Functioneee0: ; eee0 (3:6ee0) + ld a, MON_MAXHP + call GetPartyParamLocation + ld d, h + ld e, l + ld a, MON_STAT_EXP - 1 + call GetPartyParamLocation + ld b, $1 + predef_jump CalcMonStats + +Functioneef3: ; eef3 (3:6ef3) + xor a + ld [wFieldMoveSucceeded], a + jp ClearPalettes + +Text_StatRoseFromVitamin: + text_far Text_StatRoseFromVitamin_ + db "@" + +StatStrings: + dw .health + dw .attack + dw .defense + dw .speed + dw .special + +.health db "HEALTH@" +.attack db "ATTACK@" +.defense db "DEFENSE@" +.speed db "SPEED@" +.special db "SPECIAL@" + +Functionef2d: ; ef2d (3:6f2d) + ld a, [wCurItem] + ld hl, StatOffsets +.asm_ef33 + cp [hl] + inc hl + jr z, .asm_ef3a + inc hl + jr .asm_ef33 + +.asm_ef3a + ld a, [hl] + ld c, a + ld b, $0 + ret + +StatOffsets: + db HP_UP, MON_HP_EXP - MON_STAT_EXP + db PROTEIN, MON_ATK_EXP - MON_STAT_EXP + db IRON, MON_DEF_EXP - MON_STAT_EXP + db CARBOS, MON_SPD_EXP - MON_STAT_EXP + db CALCIUM, MON_SPC_EXP - MON_STAT_EXP + +Functionef49: ; ef49 (3:6f49) + ld a, [wCurPartySpecies] + ld [wCurSpecies], a + ld [wd151], a + ld a, $1f + call GetPartyParamLocation + ld a, [hl] + ld [wCurPartyLevel], a + call GetBaseData + ld a, [wCurPartyMon] + ld hl, wPartyMonNicknames + call GetNick + ret + +RareCandy: ; ef68 (3:6f68) + ld b, PARTYMENUACTION_HEALING_ITEM + call Functionf24f + jp c, Functioneef3 + call Functionef49 + ld a, MON_LEVEL + call GetPartyParamLocation + ld a, [hl] + cp MAX_LEVEL + jp nc, Functioneed7 + inc a + ld [hl], a + ld [wCurPartyLevel], a + push de + ld d, a + farcall CalcExpAtLevel + pop de + ld a, $8 + call GetPartyParamLocation + ldh a, [hQuotient] + ld [hli], a + ldh a, [hPrintNum3] + ld [hli], a + ldh a, [hPrintNum4] + ld [hl], a + ld a, $24 + call GetPartyParamLocation + ld a, [hli] + ld b, a + ld c, [hl] + push bc + call Functioneee0 + ld a, $25 + call GetPartyParamLocation + pop bc + ld a, [hld] + sub c + ld c, a + ld a, [hl] + sbc b + ld b, a + dec hl + ld a, [hl] + add c + ld [hld], a + ld a, [hl] + adc b + ld [hl], a + ld c, $1 + farcall ChangeHappiness + ld a, PARTYMENUTEXT_LEVEL_UP + call Functionf2a0 + xor a + ld [wMonType], a + predef CopyMonToTempMon + hlcoord 9, 0 + ld b, 10 + ld c, 9 + call Textbox + hlcoord 11, 1 + ld bc, $4 + predef PrintTempMonStats + call WaitPressAorB_BlinkCursor + xor a + ld [wMonType], a + ld a, [wCurPartySpecies] + ld [wd151], a + predef LearnLevelMoves + xor a + ld [wd0d2], a + farcall EvolvePokemon + jp Functionf7dc + +HealPowder: ; f003 (3:7003) + ld b, $1 + call Functionf24f + jp c, Functionf2f4 + call Functionf030 + cp $0 + jr nz, .asm_f01f + ld c, $f + farcall ChangeHappiness + call Functionf81d + ld a, $0 +.asm_f01f + jp Functionf0f4 + +Antidote: ; f022 +Awakening: ; f022 +BurnHeal: ; f022 +BurntBerry: ; f022 +FullHeal: ; f022 +IceBerry: ; f022 +IceHeal: ; f022 +MintBerry: ; f022 +Miracleberry: ; f022 +ParlyzHeal: ; f022 +Przcureberry: ; f022 +Psncureberry: ; f022 + ld b, $1 + call Functionf24f + jp c, Functionf2f4 +Functionf02a: + call Functionf030 + jp Functionf0f4 + +Functionf030: ; f030 (3:7030) + call Functionf363 + ld a, $1 + ret z + call Functionf0ae + ld a, MON_STATUS + call GetPartyParamLocation + ld a, [hl] + and c + jr nz, .asm_f04a + call Functionf05f + ld a, $1 + ret nc + ld b, PARTYMENUTEXT_HEAL_CONFUSION +.asm_f04a + xor a + ld [hl], a + ld a, b + ld [wPartyMenuActionText], a + call Functionf086 + call Functionf7c7 + call Functionf2cf + call Functionf7dc + ld a, $0 + ret + +Functionf05f: ; f05f (3:705f) + call Functionf2fc + jr nc, .asm_f072 + ld a, [wPlayerSubStatus3] + bit SUBSTATUS_CONFUSED, a + jr z, .asm_f072 + ld a, c + cp $ff + jr nz, .asm_f072 + scf + ret + +.asm_f072 + and a + ret + +RestoreBattlemonHP: + call Functionf2fc + ret nc + ld a, $22 + call GetPartyParamLocation + ld a, [hli] + ld [wBattleMonHP], a + ld a, [hld] + ld [wBattleMonHP + 1], a + ret + +Functionf086: ; f086 (3:7086) + call Functionf2fc + ret nc + xor a + ld [wBattleMonStatus], a + ld hl, wPlayerSubStatus5 + res 0, [hl] + ld hl, wPlayerSubStatus1 + res 0, [hl] + call Functionf0ae + ld a, c + cp $ff + jr nz, .asm_f0a5 + ld hl, wPlayerSubStatus3 + res 7, [hl] +.asm_f0a5 + push bc + farcall CalcPlayerStats ; d:66f6 + pop bc + ret + +Functionf0ae: ; f0ae (3:70ae) + push hl + ld a, [wCurItem] + ld hl, .healingactions ; $70c7 + ld bc, $3 +.asm_f0b8 + cp [hl] + jr z, .asm_f0be + add hl, bc + jr .asm_f0b8 + +.asm_f0be + inc hl + ld b, [hl] + inc hl + ld a, [hl] + ld c, a + cp $ff + pop hl + ret + +.healingactions + db ANTIDOTE, PARTYMENUTEXT_HEAL_PSN, 1 << PSN + db BURN_HEAL, PARTYMENUTEXT_HEAL_BRN, 1 << BRN + db ICE_HEAL, PARTYMENUTEXT_HEAL_FRZ, 1 << FRZ + db AWAKENING, PARTYMENUTEXT_HEAL_SLP, SLP + db PARLYZ_HEAL, PARTYMENUTEXT_HEAL_PAR, 1 << PAR + db FULL_HEAL, PARTYMENUTEXT_HEAL_ALL, %11111111 + db FULL_RESTORE, PARTYMENUTEXT_HEAL_ALL, %11111111 + db HEAL_POWDER, PARTYMENUTEXT_HEAL_ALL, %11111111 + db PSNCUREBERRY, PARTYMENUTEXT_HEAL_PSN, 1 << PSN + db PRZCUREBERRY, PARTYMENUTEXT_HEAL_PAR, 1 << PAR + db BURNT_BERRY, PARTYMENUTEXT_HEAL_FRZ, 1 << FRZ + db ICE_BERRY, PARTYMENUTEXT_HEAL_BRN, 1 << BRN + db MINT_BERRY, PARTYMENUTEXT_HEAL_SLP, SLP + db MIRACLEBERRY, PARTYMENUTEXT_HEAL_ALL, %11111111 + db -1, 0, 0 + +Functionf0f4: ; f0f4 (3:70f4) + ld hl, .Jumptable ; $70f9 + rst JumpTable + ret + +.Jumptable: + dw Functionf2f8 + dw Functionf2ef + dw Functionf2f4 + +RevivalHerb: ; f0ff + ld b, $1 + call Functionf24f + jp c, Functionf2f4 + call Functionf12c + cp $0 + jr nz, .asm_f11b + ld c, $11 + farcall ChangeHappiness + call Functionf81d + ld a, $0 +.asm_f11b + jp Functionf0f4 + +MaxRevive: ; f11e +Revive: ; f11e + ld b, $1 + call Functionf24f + jp c, Functionf2f4 + call Functionf12c + jp Functionf0f4 + +Functionf12c: ; f12c (3:712c) + call Functionf363 + ld a, $1 + ret nz + ld a, [wBattleMode] + and a + jr z, .asm_f15a + ld a, [wCurPartyMon] + ld c, a + ld d, $0 + ld hl, wcbda + ld b, CHECK_FLAG + predef SmallFarFlagAction + ld a, c + and a + jr z, .asm_f15a + ld a, [wCurPartyMon] + ld c, a + ld hl, wcb42 + ld b, SET_FLAG + predef SmallFarFlagAction +.asm_f15a + xor a + ld [wLowHealthAlarm], a + ld a, [wCurItem] + cp REVIVE + jr z, .asm_f16a + call Functionf319 + jr .asm_f16d + +.asm_f16a + call Functionf310 +.asm_f16d + call Functionf231 + ld a, $f7 + ld [wPartyMenuActionText], a + call Functionf2cf + call Functionf7dc + ld a, $0 + ret + +FullRestore: ; f17e (3:717e) + ld b, $1 + call Functionf24f + jp c, Functionf2f4 + call Functionf363 + jp z, Functionf2ef + call CalculateCurHPAnimRemainingHP + jr c, .asm_f194 + jp Functionf02a + +.asm_f194 + call Functionf19a + jp Functionf0f4 + +Functionf19a: ; f19a (3:719a) + xor a + ld [wLowHealthAlarm], a + call Functionf319 + ld a, $20 + call GetPartyParamLocation + xor a + ld [hli], a + ld [hl], a + call Functionf086 + call RestoreBattlemonHP + call Functionf231 + ld a, $f5 + ld [wPartyMenuActionText], a + call Functionf2cf + call Functionf7dc + ld a, $0 + ret + +BitterBerry: ; f1c0 + ld hl, wPlayerSubStatus3 + bit 7, [hl] + ld a, $1 + jr z, .asm_f1d9 + res 7, [hl] + xor a + ldh [hBattleTurn], a + call Functionf7d0 + ld hl, ConfusedNoMoreText + call StdBattleTextbox + ld a, $0 +.asm_f1d9 + jp Functionf0f4 + +Berry: ; f1dc +BerryJuice: ; f1dc +FreshWater: ; f1dc +GoldBerry: ; f1dc +HyperPotion: ; f1dc +Lemonade: ; f1dc +MaxPotion: ; f1dc +MoomooMilk: ; f1dc +Potion: ; f1dc +Ragecandybar: ; f1dc +SodaPop: ; f1dc +SuperPotion: ; f1dc + call Functionf1ff + jp Functionf0f4 + +Energypowder: ; f1e2 (3:71e2) + ld c, $f + jr asm_f1e8 + +EnergyRoot: ; f1e6 (3:71e6) + ld c, $10 +asm_f1e8 + push bc + call Functionf1ff + pop bc + cp $0 + jr nz, .asm_f1fc + farcall ChangeHappiness + call Functionf81d + ld a, $0 +.asm_f1fc + jp Functionf0f4 + +Functionf1ff: ; f1ff (3:71ff) + ld b, PARTYMENUACTION_HEALING_ITEM + call Functionf24f + ld a, $2 + ret c + call Functionf363 + ld a, $1 + ret z + call CalculateCurHPAnimRemainingHP + ld a, $1 + ret nc + xor a + ld [wLowHealthAlarm], a + call Functionf3eb + call Functionf327 + call RestoreBattlemonHP + call Functionf231 + ld a, PARTYMENUTEXT_HEAL_HP + ld [wPartyMenuActionText], a + call Functionf2cf + call Functionf7dc + ld a, $0 + ret + +Functionf231: ; f231 (3:7231) + push de + ld de, $4 + call WaitPlaySFX + pop de + ld a, [wCurPartyMon] + hlcoord 11, 0 + ld bc, $28 + call AddNTimes + ld a, $2 + ld [wWhichHPBar], a + predef_jump AnimateHPBar + +Functionf24f: ; f24f (3:724f) + call Functionf261 + ret c + ld a, [wCurPartySpecies] + cp EGG + jr nz, .asm_f25f + call Functionf82f + scf + ret + +.asm_f25f + and a + ret + +Functionf261: ; f261 (3:7261) + ld a, b + ld [wPartyMenuActionText], a + push hl + push de + push bc + call ClearBGPalettes + call Functionf272 + pop bc + pop de + pop hl + ret + +Functionf272: ; f272 (3:7272) + farcall LoadPartyMenuGFX + farcall InitPartyMenuWithCancel + farcall InitPartyMenuGFX + farcall WritePartyMenuTilemap + farcall PrintPartyMenuText + call WaitBGMap + call SetPalettes + call DelayFrame + farcall PartyMenuSelect + ret + +Functionf2a0: ; f2a0 (3:72a0) + ld [wPartyMenuActionText], a + ld a, [wCurPartySpecies] + push af + ld a, [wCurPartyMon] + push af + push hl + push de + push bc + farcall WritePartyMenuTilemap + farcall PrintPartyMenuActionText + call WaitBGMap + call SetPalettes + call DelayFrame + pop bc + pop de + pop hl + pop af + ld [wCurPartyMon], a + pop af + ld [wCurPartySpecies], a + ret + +Functionf2cf: ; f2cf (3:72cf) + xor a + ldh [hBGMapMode], a + hlcoord 0, 0 + ld bc, SCREEN_HEIGHT * SCREEN_WIDTH + ld a, " " + call ByteFill + ld a, [wPartyMenuActionText] + call Functionf2a0 + ld a, $1 + ldh [hBGMapMode], a + ld c, 50 + call DelayFrames + jp WaitPressAorB_BlinkCursor + +Functionf2ef: ; f2ef (3:72ef) + call Functionf839 + jr Functionf2f8 + +Functionf2f4: ; f2f4 (3:72f4) + xor a + ld [wFieldMoveSucceeded], a +Functionf2f8: ; f2f8 (3:72f8) + call ClearPalettes + ret + +Functionf2fc: ; f2fc (3:72fc) + ld a, [wBattleMode] + and a + ret z + ld a, [wCurPartyMon] + push hl + ld hl, wCurBattleMon + cp [hl] + pop hl + jr nz, .asm_f30e + scf + ret + +.asm_f30e + xor a + ret + +Functionf310: ; f310 (3:7310) + call GetCurHPAnimMaxHP + srl d + rr e + jr asm_f31c + +Functionf319: ; f319 (3:7319) + call GetCurHPAnimMaxHP +asm_f31c + ld a, MON_HP + call GetPartyParamLocation + ld [hl], d + inc hl + ld [hl], e + jp CopyCurHPToAnimBufferNewHP + +Functionf327: ; f327 (3:7327) + ld a, $23 + call GetPartyParamLocation + ld a, [hl] + add e + ld [hld], a + ld a, [hl] + adc d + ld [hl], a + jr c, .asm_f34b + call CopyCurHPToAnimBufferNewHP + ld a, MON_HP + 1 + call GetPartyParamLocation + ld d, h + ld e, l + ld a, MON_MAXHP + 1 + call GetPartyParamLocation + ld a, [de] + sub [hl] + dec de + dec hl + ld a, [de] + sbc [hl] + jr c, .asm_f34e +.asm_f34b + call Functionf319 +.asm_f34e + ret + +Functionf34f: ; f34f (3:734f) + ld a, MON_HP + 1 + call GetPartyParamLocation + ld a, [hl] + sub e + ld [hld], a + ld a, [hl] + sbc d + ld [hl], a + jr nc, .asm_f35f + xor a + ld [hld], a + ld [hl], a +.asm_f35f + call CopyCurHPToAnimBufferNewHP + ret + +Functionf363: ; f363 (3:7363) + push de + call CopyMaxHPToAnimBufferMaxHP + call CopyCurHPToAnimBufferOldHP + call GetCurHPAnimOldHP + ld a, d + or e + pop de + ret + +CalculateCurHPAnimRemainingHP: ; f371 (3:7371) + call GetCurHPAnimOldHP + ld h, d + ld l, e + call GetCurHPAnimMaxHP + ld a, l + sub e + ld a, h + sbc d + ret + +CopyCurHPToAnimBufferNewHP: ; f37e (3:737e) + ld a, MON_HP + call GetPartyParamLocation + ld a, [hli] + ld [wCurHPAnimNewHP + 1], a + ld a, [hl] + ld [wCurHPAnimNewHP], a + ret + +SetCurHPAnimNewHP: + ld a, d + ld [wCurHPAnimNewHP + 1], a + ld a, e + ld [wCurHPAnimNewHP], a + ret + +GetCurHPAnimNewHP: + ld a, [wCurHPAnimNewHP + 1] + ld d, a + ld a, [wCurHPAnimNewHP] + ld e, a + ret + +CopyCurHPToAnimBufferOldHP: ; f39e (3:739e) + ld a, MON_HP + call GetPartyParamLocation + ld a, [hli] + ld [wCurHPAnimOldHP + 1], a + ld a, [hl] + ld [wCurHPAnimOldHP], a + ret + +GetCurHPAnimOldHP: ; f3ac (3:73ac) + ld a, [wCurHPAnimOldHP + 1] + ld d, a + ld a, [wCurHPAnimOldHP] + ld e, a + ret + +CopyMaxHPToAnimBufferMaxHP: ; f3b5 (3:73b5) + push hl + ld a, MON_MAXHP + call GetPartyParamLocation + ld a, [hli] + ld [wCurHPAnimMaxHP + 1], a + ld a, [hl] + ld [wCurHPAnimMaxHP], a + pop hl + ret + +GetCurHPAnimMaxHP: ; f3c5 (3:73c5) + ld a, [wCurHPAnimMaxHP + 1] + ld d, a + ld a, [wCurHPAnimMaxHP] + ld e, a + ret + +GetOneFifthMaxHP: ; f3ce (3:73ce) + push bc + ld a, MON_MAXHP + call GetPartyParamLocation + ld a, [hli] + ldh [hDividend + 0], a + ld a, [hl] + ldh [hDividend + 1], a + ld a, 5 + ldh [hDivisor], a + ld b, 2 + call Divide + ldh a, [hQuotient + 1] + ld d, a + ldh a, [hQuotient + 2] + ld e, a + pop bc + ret + +Functionf3eb: ; f3eb (3:73eb) + push hl + ld a, [wCurItem] + ld hl, HealingItemParameters + ld d, a +.asm_f3f3 + ld a, [hli] + cp -1 + jr z, .asm_f3ff + cp d + jr z, .asm_f400 + inc hl + inc hl + jr .asm_f3f3 + +.asm_f3ff + scf +.asm_f400 + ld e, [hl] + inc hl + ld d, [hl] + pop hl + ret + +HealingItemParameters: + dbw FRESH_WATER, 50 + dbw SODA_POP, 60 + dbw LEMONADE, 80 + dbw HYPER_POTION, 200 + dbw SUPER_POTION, 50 + dbw POTION, 20 + dbw MAX_POTION, 999 + dbw FULL_RESTORE, 999 + dbw MOOMOO_MILK, 100 + dbw BERRY, 10 + dbw GOLD_BERRY, 30 + dbw ENERGYPOWDER, 50 + dbw ENERGY_ROOT, 200 + dbw RAGECANDYBAR, 20 + dbw BERRY_JUICE, 20 + dbw -1, 0 + +Softboiled_MilkDrinkFunction: + ld a, [wPartyMenuCursor] + dec a + ld b, a + call Functionf46f + jr c, .asm_f469 + ld a, b + ld [wCurPartyMon], a + call Functionf363 + call GetOneFifthMaxHP + call Functionf34f + push bc + call Functionf231 + pop bc + call GetOneFifthMaxHP + ld a, c + ld [wCurPartyMon], a + call Functionf363 + call Functionf327 +.asm_f45d + call Functionf231 + ld a, PARTYMENUTEXT_HEAL_HP + call Functionf2a0 + call JoyWaitAorB +.asm_f469 + ld a, b + inc a + ld [wPartyMenuCursor], a + ret + +Functionf46f: ; f46f (3:746f) + push bc + ld a, $1 + ld [wPartyMenuActionText], a + call Functionf272 + pop bc + jr c, .asm_f494 + ld a, [wPartyMenuCursor] + dec a + ld c, a + ld a, b + cp c + jr z, .asm_f496 + ld a, c + ld [wCurPartyMon], a + call Functionf363 + jr z, .asm_f496 + call CalculateCurHPAnimRemainingHP + jr nc, .asm_f496 + xor a + ret + +.asm_f494 + scf + ret + +.asm_f496 + push bc + ld hl, Text_MilkDrinkCantBeUsed + call MenuTextboxBackup + pop bc + jr Functionf46f + +Text_MilkDrinkCantBeUsed: + text_far Text_MilkDrinkCantBeUsed_ + db "@" + +EscapeRope: ; f4a5 (3:74a5) + xor a + ld [wFieldMoveSucceeded], a + farcall EscapeRopeFunction ; same bank + ld a, [wFieldMoveSucceeded] + cp $1 + call z, Functionf7dc + ret + +SuperRepel: ; f4b8 (3:74b8) + ld b, 200 + jr asm_f4c2 + +MaxRepel: ; f4bc (3:74bc) + ld b, 250 + jr asm_f4c2 + +Repel: ; f4c0 (3:74c0) + ld b, 100 +asm_f4c2 + ld a, [wRepelSteps] + and a + ld hl, Text_RepelsEffectsStillLinger + jp nz, PrintText + ld a, b + ld [wRepelSteps], a + jp Functionf7d0 + +Text_RepelsEffectsStillLinger: + text_far Text_RepelUsedEarlierIsStillInEffect + db "@" + +XAccuracy: ; f4d8 (3:74d8) + ld hl, wPlayerSubStatus4 + bit SUBSTATUS_X_ACCURACY, [hl] + jp nz, Functionf811 + set SUBSTATUS_X_ACCURACY, [hl] + jp Functionf7d0 + +PokeDoll: ; f4e5 (3:74e5) + ld a, [wBattleMode] + dec a + jr nz, .asm_f4f6 + inc a + ld [wd11c], a + inc a + ld [wBattleResult], a + jp Functionf7d0 + +.asm_f4f6 + xor a + ld [wFieldMoveSucceeded], a + ret + +GuardSpec: ; f4fb (3:74fb) + ld hl, wPlayerSubStatus4 + bit SUBSTATUS_MIST, [hl] + jp nz, Functionf811 + set SUBSTATUS_MIST, [hl] + jp Functionf7d0 + +DireHit: ; f508 (3:7508) + ld hl, wPlayerSubStatus4 + bit SUBSTATUS_FOCUS_ENERGY, [hl] + jp nz, Functionf811 + set SUBSTATUS_FOCUS_ENERGY, [hl] + jp Functionf7d0 + +XAttack: ; f515 +XDefend: ; f515 +XSpecial: ; f515 +XSpeed: ; f515 + call Functionf7d0 + ld a, [wCurItem] + ld hl, .x_item_table +.asm_f51e + cp [hl] + jr z, .asm_f525 + inc hl + inc hl + jr .asm_f51e + +.asm_f525 + inc hl + ld b, [hl] + xor a + ldh [hBattleTurn], a + ld [wcb45], a + ld [wcbeb], a + farcall CheckIfStatCanBeRaised + call WaitSFX + farcall BattleCommand_StatUpMessage + farcall BattleCommand_StatUpFailText + ld a, [wCurBattleMon] + ld [wCurPartyMon], a + ld c, HAPPINESS_USEDXITEM + farcall ChangeHappiness + ret + +.x_item_table + db X_ATTACK, ATTACK + db X_DEFEND, DEFENSE + db X_SPEED, SPEED + db X_SPECIAL, SP_ATTACK + +PokeFlute: ; f55c (3:755c) + ld a, [wBattleMode] + and a + jr nz, .dummy +.dummy + + xor a + ld [wceed], a + + ld b, $ff ^ SLP + + ld hl, wPartyMon1Status + call .CureSleep + + ld a, [wBattleMode] + cp $1 + jr z, .skip_otrainer + ld hl, wOTPartyMon1Status + call .CureSleep +.skip_otrainer + + ld hl, wBattleMonStatus + ld a, [hl] + and b + ld [hl], a + ld hl, wEnemyMonStatus + ld a, [hl] + and b + ld [hl], a + + ld a, [wceed] + and a + ld hl, Text_NowThatsACatchyTune ; $75bc + jp z, PrintText + ld hl, Text_PlayedThePokeFlute ; $75c6 + call PrintText + + ld a, [wLowHealthAlarm] + and $80 + jr nz, .dummy2 +.dummy2 + ld hl, Text_AllSleepingMonWokeUp ; $75c1 + jp PrintText + +.CureSleep: ; f5a4 (3:75a4) + ld de, PARTYMON_STRUCT_LENGTH + ld c, PARTY_LENGTH + +.loop + ld a, [hl] + push af + and SLP + jr z, .not_asleep + ld a, 1 + ld [wceed], a +.not_asleep + pop af + and b + ld [hl], a + add hl, de + dec c + jr nz, .loop + ret + +Text_NowThatsACatchyTune: + text_far Text_NowThatsACatchyTune_ + db "@" + +Text_AllSleepingMonWokeUp: + text_far Text_AllSleepingMonWokeUp_ + db "@" + +Text_PlayedThePokeFlute: + text_far Text_PlayedThePokeFlute_ + text_asm + ld a, [wBattleMode] + and a + jr nz, .asm_f5dc + push de + ld de, SFX_POKEFLUTE + call WaitPlaySFX + call WaitSFX + pop de +.asm_f5dc + ld hl, .terminator + ret + +.terminator db "@" + +CoinCase: ; f5e1 (3:75e1) + ld hl, Text_CoinCase + jp MenuTextboxWaitButton + +Text_CoinCase: + text_far Text_CoinCase_ + db "@" + +OldRod: ; f5ec (3:75ec) + ld e, $0 + jr UseRod + +GoodRod: ; f5f0 (3:75f0) + ld e, $1 + jr UseRod + +SuperRod: ; f5f4 (3:75f4) + ld e, $2 + jr UseRod + +UseRod: + farcall FishingRodFunction ; same bank + ret + +ItemfinderEffect: ; f5ff (3:75ff) + farcall ItemFinder + ret + +Elixer: ; f606 +Ether: ; f606 +MaxElixer: ; f606 +MaxEther: ; f606 +Mysteryberry: ; f606 +PPUp: ; f606 (3:7606) + ld a, [wCurItem] + ld [wMovementBufferCount], a +.asm_f60c + ld b, $1 + call Functionf24f + jp c, Functionf727 +.asm_f614 + ld a, [wMovementBufferCount] + cp MAX_ELIXER + jp z, Functionf6f6 + cp ELIXER + jp z, Functionf6f6 + ld hl, Text_RaiseThePPOfWhichMove + ld a, [wMovementBufferCount] + cp PP_UP + jr z, .asm_f62e + ld hl, Text_RestoreThePPOfWhichMove +.asm_f62e + call PrintText + ld a, [wcfc7] + push af + xor a + ld [wcfc7], a + ld a, $2 + ld [wd11f], a + ld a, $f + ld hl, $62f3 + rst FarCall + pop bc + ld a, b + ld [wcfc7], a + jr nz, .asm_f60c + ld hl, wPartyMon1Moves + ld bc, $30 + call Functionf9aa + push hl + ld a, [hl] + ld [wd151], a + call GetMoveName + call CopyName1 + pop hl + ld a, [wceed] + cp PP_UP + jp nz, Functionf6ee + ld a, [hl] + cp $a6 + jr z, .asm_f676 + ld bc, $15 + add hl, bc + ld a, [hl] + cp $c0 + jr c, .asm_f67e +.asm_f676 + ld hl, Text_PPIsMaxedOut ; $7776 + call PrintText + jr .asm_f614 + +.asm_f67e + ld a, [hl] + add $40 + ld [hl], a + ld a, $1 + ld [wd151], a + call Functionf893 + call Functionf7c7 + ld hl, Text_PPsIncreased ; $777b + call PrintText +asm_f693 + call ClearPalettes + jp Functionf7dc + +asm_f699 + ld a, [wBattleMode] + and a + jr z, .asm_f6b3 + ld a, [wCurPartyMon] + ld b, a + ld a, [wCurBattleMon] + cp b + jr nz, .asm_f6b3 + ld a, [wPlayerSubStatus5] + bit SUBSTATUS_TRANSFORMED, a + jr nz, .asm_f6b3 + call Functionf6be +.asm_f6b3 + call Functionf7c7 + ld hl, Text_PPWasRestored + call PrintText + jr asm_f693 + +Functionf6be: ; f6be (3:76be) + ld a, [wCurPartyMon] + ld hl, wPartyMon1Moves + ld bc, $30 + call AddNTimes + ld de, wBattleMonMoves + ld b, $4 +.asm_f6cf + ld a, [de] + and a + jr z, .asm_f6ed + cp [hl] + jr nz, .asm_f6e8 + push hl + push de + push bc + inc de + inc de + inc de + inc de + inc de + inc de + ld bc, $15 + add hl, bc + ld a, [hl] + ld [de], a + pop bc + pop de + pop hl +.asm_f6e8 + inc hl + inc de + dec b + jr nz, .asm_f6cf +.asm_f6ed + ret + +Functionf6ee: ; f6ee (3:76ee) + call Functionf72f + jr nz, asm_f699 + jp Functionf724 + +Functionf6f6: ; f6f6 (3:76f6) + xor a + ld hl, wMenuCursorY + ld [hli], a + ld [hl], a + ld b, $4 +.asm_f6fe + push bc + ld hl, wPartyMon1Moves + ld bc, $30 + call Functionf9aa + ld a, [hl] + and a + jr z, .asm_f715 + call Functionf72f + jr z, .asm_f715 + ld hl, wcee1 + inc [hl] +.asm_f715 + ld hl, wMenuCursorY + inc [hl] + pop bc + dec b + jr nz, .asm_f6fe + ld a, [wcee1] + and a + jp nz, asm_f699 +Functionf724: ; f724 (3:7724) + call Functionf839 +Functionf727: ; f727 (3:7727) + call ClearPalettes + xor a + ld [wFieldMoveSucceeded], a + ret + +Functionf72f: ; f72f (3:772f) + xor a + ld [wMonType], a + call GetMaxPPOfMove + ld hl, wPartyMon1PP + ld bc, $30 + call Functionf9aa + ld a, [wd151] + ld b, a + ld a, [hl] + and $3f + cp b + jr nc, .asm_f76a + ld a, [wceed] + cp MAX_ELIXER + jr z, .asm_f764 + cp $40 + jr z, .asm_f764 + ld c, $5 + cp $96 + jr z, .asm_f75c + ld c, $a +.asm_f75c + ld a, [hl] + and $3f + add c + cp b + jr nc, .asm_f764 + ld b, a +.asm_f764 + ld a, [hl] + and $c0 + or b + ld [hl], a + ret + +.asm_f76a + xor a + ret + +Text_RaiseThePPOfWhichMove: + text_far Text_RaiseThePPOfWhichMove_ + db "@" + +Text_RestoreThePPOfWhichMove: + text_far Text_RestoreThePPOfWhichMove_ + db "@" + +Text_PPIsMaxedOut: + text_far Text_PPIsMaxedOut_ + db "@" + +Text_PPsIncreased: + text_far Text_PPsIncreased_ + db "@" + +Text_PPWasRestored: + text_far Text_PPWasRestored_ + db "@" + +Squirtbottle: ; f785 (3:7785) + farcall SquirtbottleFunction ; 14:4763 + ret + +CardKey: ; f78c (3:778c) + farcall CardKeyFunction ; 14:47ac + ret + +BasementKey: ; f793 (3:7793) + farcall BasementKeyFunction ; 14:47e7 + ret + +SacredAsh: ; f79a (3:779a) + farcall SacredAshFunction ; 14:4819 + ld a, [wFieldMoveSucceeded] + cp $1 + ret nz + call Functionf7dc + ret + +NormalBox: ; f7aa (3:77aa) + ld c, DECOFLAG_SILVER_TROPHY_DOLL + jr asm_f7b0 + +GorgeousBox: ; f7ae (3:77ae) + ld c, DECOFLAG_GOLD_TROPHY_DOLL +asm_f7b0 + farcall ReceiveDecorationC ; 9:70d5 + ld hl, Text_TrophyInside ; $77bf + call PrintText + jp Functionf7dc + +Text_TrophyInside: + text_far Text_TrophyInside_ + db "@" + +AmuletCoin: ; f7c4 +BerserkGene: ; f7c4 +BigMushroom: ; f7c4 +BigPearl: ; f7c4 +Blackbelt: ; f7c4 +Blackglasses: ; f7c4 +BlkApricorn: ; f7c4 +BluApricorn: ; f7c4 +Brightpowder: ; f7c4 +Charcoal: ; f7c4 +CleanseTag: ; f7c4 +DragonFang: ; f7c4 +DragonScale: ; f7c4 +Everstone: ; f7c4 +ExpShare: ; f7c4 +FlowerMail: ; f7c4 +FocusBand: ; f7c4 +GoldLeaf: ; f7c4 +GrnApricorn: ; f7c4 +HardStone: ; f7c4 +Item19: ; f7c4 +Item2D: ; f7c4 +Item32: ; f7c4 +Item47: ; f7c4 +Item5A: ; f7c4 +Item64: ; f7c4 +Item73: ; f7c4 +Item74: ; f7c4 +Item78: ; f7c4 +Item81: ; f7c4 +Item87: ; f7c4 +Item88: ; f7c4 +Item89: ; f7c4 +Item8D: ; f7c4 +Item8E: ; f7c4 +Item91: ; f7c4 +Item93: ; f7c4 +Item94: ; f7c4 +Item95: ; f7c4 +Item99: ; f7c4 +Item9A: ; f7c4 +Item9B: ; f7c4 +ItemA2: ; f7c4 +ItemAB: ; f7c4 +ItemB0: ; f7c4 +ItemB3: ; f7c4 +KingsRock: ; f7c4 +Leftovers: ; f7c4 +LightBall: ; f7c4 +LostItem: ; f7c4 +LuckyEgg: ; f7c4 +LuckyPunch: ; f7c4 +MachinePart: ; f7c4 +Magnet: ; f7c4 +MetalCoat: ; f7c4 +MetalPowder: ; f7c4 +MiracleSeed: ; f7c4 +MysteryEgg: ; f7c4 +MysticWater: ; f7c4 +Nevermeltice: ; f7c4 +Nugget: ; f7c4 +Pass: ; f7c4 +Pearl: ; f7c4 +PinkBow: ; f7c4 +PnkApricorn: ; f7c4 +PoisonBarb: ; f7c4 +PolkadotBow: ; f7c4 +QuickClaw: ; f7c4 +RainbowWing: ; f7c4 +RedApricorn: ; f7c4 +RedScale: ; f7c4 +SSTicket: ; f7c4 +ScopeLens: ; f7c4 +Secretpotion: ; f7c4 +SharpBeak: ; f7c4 +SilverLeaf: ; f7c4 +SilverWing: ; f7c4 +Silverpowder: ; f7c4 +Slowpoketail: ; f7c4 +SmokeBall: ; f7c4 +SoftSand: ; f7c4 +SpellTag: ; f7c4 +StarPiece: ; f7c4 +Stardust: ; f7c4 +Stick: ; f7c4 +ThickClub: ; f7c4 +Tinymushroom: ; f7c4 +Twistedspoon: ; f7c4 +UpGrade: ; f7c4 +WhtApricorn: ; f7c4 +YlwApricorn: ; f7c4 + jp Functionf834 + +Functionf7c7: ; f7c7 (3:77c7) + push de + ld de, SFX_FULL_HEAL + call WaitPlaySFX + pop de + ret + +Functionf7d0: ; f7d0 (3:77d0) + ld hl, Text_UsedItem + call PrintText + call Functionf7c7 + call WaitPressAorB_BlinkCursor +Functionf7dc: ; f7dc (3:77dc) + ld hl, wTMsHMsEnd + ld a, $1 + ld [wItemQuantityChangeBuffer], a + jp TossItem + +Functionf7e7: ; f7e7 (3:77e7) + call ReturnToBattle_UseBall + ld de, Start + ld a, e + ld [wcf3e], a + ld a, d + ld [wcf3f], a + xor a + ld [wcb67], a + ldh [hBattleTurn], a + ld [wcf46], a + predef PlayBattleAnim + ld hl, Text_BlockedTheBall + call PrintText + ld hl, Text_DontBeAThief + call PrintText + jr Functionf7dc + +Functionf811: ; f811 (3:7811) + ld hl, Text_WontHaveAnyEffect + call PrintText + ld a, $2 + ld [wFieldMoveSucceeded], a + ret + +Functionf81d: ; f81d (3:781d) + ld hl, Text_LooksBitter + jp PrintText + +FailToUseBall: ; f823 (3:7823) + ld hl, Text_CantUseBallBoxIsFull + call PrintText + ld a, $2 + ld [wFieldMoveSucceeded], a + ret + +Functionf82f: ; f82f (3:782f) + ld hl, Text_CantUseOnEgg + jr asm_f84b + +Functionf834: ; f834 (3:7834) + ld hl, Text_IsntTheTimeToUseThat + jr asm_f84b + +Functionf839: ; f839 (3:7839) + ld hl, Text_WontHaveAnyEffect + jr asm_f84b + +Functionf83e: + ld hl, Text_BelongsToSomeoneElse + jr asm_f84b + +Functionf843: + ld hl, Text_CyclingIsntAllowed + jr asm_f84b + +Functionf848: + ld hl, Text_CantGetOnYourItemNow +asm_f84b + xor a + ld [wFieldMoveSucceeded], a + jp PrintText + +Text_LooksBitter: + text_far Text_LooksBitter_ + db "@" + +Text_CantUseOnEgg: + text_far Text_CantUseOnEgg_ + db "@" + +Text_IsntTheTimeToUseThat: + text_far Text_IsntTheTimeToUseThat_ + db "@" + +Text_BelongsToSomeoneElse: + text_far Text_BelongsToSomeoneElse_ + db "@" + +Text_WontHaveAnyEffect: + text_far Text_WontHaveAnyEffect_ + db "@" + +Text_BlockedTheBall: + text_far Text_BlockedTheBall_ + db "@" + +Text_DontBeAThief: + text_far Text_DontBeAThief_ + db "@" + +Text_CyclingIsntAllowed: + text_far Text_CyclingIsntAllowed_ + db "@" + +Text_CantGetOnYourItemNow: + text_far Text_CantGetOnYourItemNow_ + db "@" + +Text_CantUseBallBoxIsFull: + text_far Text_CantUseBallBoxIsFull_ + db "@" + +Text_UsedItem: + text_far Text_UsedItem_ + db "@" + +Text_GotOnItem: + text_far Text_GotOnItem_ + db "@" + +Text_GotOffItem: + text_far Text_GotOffItem_ + db "@" + +Functionf893: ; f893 (3:7893) + ld a, $2 + call GetPartyParamLocation + push hl + ld de, wBuffer1 + predef FillPP + pop hl + ld bc, $15 + add hl, bc + ld de, wCurHPAnimMaxHP + ld b, $0 +.asm_f8ab + inc b + ld a, b + cp $5 + ret z + ld a, [wd151] + dec a + jr nz, .asm_f8bd + ld a, [wMenuCursorY] + inc a + cp b + jr nz, .asm_f8c4 +.asm_f8bd + ld a, [hl] + and $c0 + ld a, [de] + call nz, Functionf8c8 +.asm_f8c4 + inc hl + inc de + jr .asm_f8ab + +Functionf8c8: ; f8c8 (3:78c8) + push bc + ; Divide the base PP by 5. + ld a, [de] + ldh [hDividend + 3], a + xor a + ldh [hDividend], a + ldh [hDividend + 1], a + ldh [hDividend + 2], a + ld a, 5 + ldh [hDivisor], a + ld b, 4 + call Divide + ; Get the number of PP, which are bits 6 and 7 of the PP value stored in RAM. + ld a, [hl] + ld b, a + swap a + and $f + srl a + srl a + ld c, a + ; If this value is 0, we are done + and a + jr z, .asm_f8fd +.asm_f8ea + ldh a, [hPrintNum4] + cp $8 + jr c, .asm_f8f2 + ld a, $7 +.asm_f8f2 + add b + ld b, a + ld a, [wd151] + dec a + jr z, .asm_f8fd + dec c + jr nz, .asm_f8ea +.asm_f8fd + ld [hl], b + pop bc + ret + +Functionf900: ; f900 (3:7900) + ld a, $17 + call GetPartyParamLocation + push hl + ld a, $2 + call GetPartyParamLocation + pop de + xor a + ld [wMenuCursorY], a + ld [wMonType], a + ld c, $4 +.asm_f915 + ld a, [hli] + and a + ret z + push hl + push de + push bc + call GetMaxPPOfMove + pop bc + pop de + ld a, [de] + and $c0 + ld b, a + ld a, [wd151] + add b + ld [de], a + inc de + ld hl, wMenuCursorY + inc [hl] + pop hl + dec c + jr nz, .asm_f915 + ret + +GetMaxPPOfMove: ; f933 (3:7933) + ld a, [wStringBuffer1] + push af + ld a, [wStringBuffer1 + 1] + push af + ld a, [wMonType] + and a + ld hl, wPartyMon1Moves + ld bc, $30 + jr z, .asm_f961 + ld hl, wOTPartyMon1Moves + dec a + jr z, .asm_f961 + ld hl, wTempMonMoves + dec a + jr z, .asm_f95c + ld hl, wTempMonMoves + dec a + jr z, .asm_f95c + ld hl, wBattleMonMoves +.asm_f95c + call Functionf9b0 + jr .asm_f964 + +.asm_f961 + call Functionf9aa +.asm_f964 + ld a, [hl] + dec a + push hl + ld hl, Moves + MOVE_PP + ld bc, $7 + call AddNTimes + ld a, BANK(Moves) + call GetFarByte + ld b, a + ld de, wStringBuffer1 + ld [de], a + pop hl + push bc + ld bc, $15 + ld a, [wMonType] + cp $4 + jr nz, .asm_f989 + ld bc, $6 +.asm_f989 + add hl, bc + ld a, [hl] + and $c0 + pop bc + or b + ld hl, wStringBuffer1 + 1 + ld [hl], a + xor a + ld [wd151], a + ld a, b + call Functionf8c8 + ld a, [hl] + and $3f + ld [wd151], a + pop af + ld [wStringBuffer1 + 1], a +.asm_f9a3 + pop af + ld [wStringBuffer1], a + ret + +Functionf9aa: ; f9aa (3:79aa) + ld a, [wCurPartyMon] + call AddNTimes +Functionf9b0: ; f9b0 (3:79b0) + ld a, [wMenuCursorY] + ld c, a + ld b, $0 + add hl, bc + ret + +GetPokeballWobble: + ld a, [wBuffer2] + inc a + ld [wBuffer2], a + cp $4 + jr z, .asm_f9e3 + ld a, [wWildMon] + and a + ld c, $0 + ret nz + ld hl, PokeballWobbleProbabilities + ld a, [wCurHPAnimMaxHP] + ld b, a +.asm_f9d1 + ld a, [hli] + cp b + jr nc, .asm_f9d8 + inc hl + jr .asm_f9d1 + +.asm_f9d8 + ld b, [hl] + call Random + cp b + ld c, $0 + ret c + ld c, $2 + ret + +.asm_f9e3 + ld a, [wWildMon] + and a + ld c, $1 + ret nz + ld c, $2 + ret + +PokeballWobbleProbabilities: + db 1, 63 + db 2, 75 + db 3, 84 + db 4, 90 + db 5, 95 + db 7, 103 + db 10, 113 + db 15, 126 + db 20, 134 + db 30, 149 + db 40, 160 + db 50, 169 + db 60, 177 + db 80, 191 + db 100, 201 + db 120, 211 + db 140, 220 + db 160, 227 + db 180, 234 + db 200, 240 + db 220, 246 + db 240, 251 + db 254, 253 + db 255, 255 diff --git a/engine/items/items.asm b/engine/items/items.asm new file mode 100755 index 00000000..428f652e --- /dev/null +++ b/engine/items/items.asm @@ -0,0 +1,551 @@ +_ReceiveItem:: ; d1e2 (3:51e2) + call CheckBagOrPC + jp nz, PutItemInPocketOrPC + push hl + call CheckItemPocket + pop de + ld a, [wItemAttributeParamBuffer] + dec a + ld hl, .Jumptable + rst JumpTable + ret + +.Jumptable + dw ReceiveNormalItem + dw ReceiveKeyItem + dw ReceiveBall + dw ReceiveTMHM + +ReceiveNormalItem: + ld h, d + ld l, e + jp PutItemInPocketOrPC + +ReceiveKeyItem: + ld h, d + ld l, e + jp PutItemInKeyItemPocket + +ReceiveBall: + ld hl, wNumBalls + jp PutItemInPocketOrPC + +ReceiveTMHM: + ld h, d + ld l, e + ld a, [wCurItem] + ld c, a + call GetTMHMNumber + jp PutItemInTMPocket + +_TossItem:: ; d21a (3:521a) + call CheckBagOrPC + jr nz, remove_item_from_bag_or_pc + push hl + call CheckItemPocket + pop de + ld a, [wItemAttributeParamBuffer] + dec a + ld hl, .Jumptable ; $522d + rst JumpTable + ret + +.Jumptable + dw RemoveNormalItem + dw RemoveKeyItem + dw RemoveBall + dw RemoveTMHM + +RemoveBall: + ld hl, wNumBalls + jp RemoveItemAndQuantity + +RemoveTMHM: + ld h, d + ld l, e + ld a, [wCurItem] + ld c, a + call GetTMHMNumber + jp RemoveTMorHM + +RemoveKeyItem: + ld h, d + ld l, e + jp RemoveItemWithoutQuantity + +RemoveNormalItem: + ld h, d + ld l, e +remove_item_from_bag_or_pc + jp RemoveItemAndQuantity + +_CheckItem:: ; d251 (3:5251) + call CheckBagOrPC + jr nz, check_item_in_bag_or_pc + push hl + call CheckItemPocket + pop de + ld a, [wItemAttributeParamBuffer] + dec a + ld hl, .Jumptable + rst JumpTable + ret + +.Jumptable + dw CheckNormalItem + dw CheckKeyItem + dw CheckBall + dw CheckTMHM + +CheckBall: + ld hl, wNumBalls + jp CheckItemWithQuantity + +CheckTMHM: + ld h, d + ld l, e + ld a, [wCurItem] + ld c, a + call GetTMHMNumber + jp CheckTMorHM + +CheckKeyItem: + ld h, d + ld l, e + jp CheckItemWithoutQuantity + +CheckNormalItem: + ld h, d + ld l, e +check_item_in_bag_or_pc + jp CheckItemWithQuantity + +CheckBagOrPC: ; d288 (3:5288) + ld a, l + cp wNumItems % $100 + ret nz + ld a, h + cp wNumItems / $100 + ret + +GetPocketCapacity: ; d290 (3:5290) + ld c, MAX_ITEMS + ld a, e + cp wNumItems % $100 + jr nz, .asm_d29b + ld a, d + cp wNumItems / $100 + ret z +.asm_d29b + ld c, MAX_PC_ITEMS + ld a, e + cp wPCItems % $100 + jr nz, .asm_d2a6 + ld a, d + cp wPCItems / $100 + ret z +.asm_d2a6 + ld c, MAX_BALLS + ret + +PutItemInPocketOrPC: ; d2a9 (3:52a9) + ld d, h + ld e, l + inc hl + ld a, [wCurItem] + ld c, a + ld b, $0 +.asm_d2b2 + ld a, [hli] + cp $ff + jr z, .asm_d2ca + cp c + jr nz, .asm_d2c7 + ld a, $63 + sub [hl] + add b + ld b, a + ld a, [wItemQuantityChangeBuffer] + cp b + jr z, .asm_d2d3 + jr c, .asm_d2d3 +.asm_d2c7 + inc hl + jr .asm_d2b2 + +.asm_d2ca + call GetPocketCapacity + ld a, [de] + cp c + jr c, .asm_d2d3 + and a + ret + +.asm_d2d3 + ld h, d + ld l, e + ld a, [wCurItem] + ld c, a + ld a, [wItemQuantityChangeBuffer] + ld [wItemQuantityBuffer], a +.asm_d2df + inc hl + ld a, [hli] + cp $ff + jr z, .asm_d2fc + cp c + jr nz, .asm_d2df + ld a, [wItemQuantityBuffer] + add [hl] + cp $64 + jr nc, .asm_d2f3 + ld [hl], a + jr .asm_d30a + +.asm_d2f3 + ld [hl], $63 + sub $63 + ld [wItemQuantityBuffer], a + jr .asm_d2df + +.asm_d2fc + dec hl + ld a, [wCurItem] + ld [hli], a + ld a, [wItemQuantityBuffer] + ld [hli], a + ld [hl], $ff + ld h, d + ld l, e + inc [hl] +.asm_d30a + scf + ret + +RemoveItemAndQuantity: ; d30c (3:530c) + ld d, h + ld e, l + ld a, [hli] + ld c, a + ld a, [wCurItemQuantity] + cp c + jr nc, .asm_d325 + ld c, a + ld b, $0 + add hl, bc + add hl, bc + ld a, [wCurItem] + cp [hl] + inc hl + jr z, .asm_d334 + ld h, d + ld l, e + inc hl +.asm_d325 + ld a, [wCurItem] + ld b, a +.asm_d329 + ld a, [hli] + cp b + jr z, .asm_d334 + cp $ff + jr z, .asm_d354 + inc hl + jr .asm_d329 + +.asm_d334 + ld a, [wItemQuantityChangeBuffer] + ld b, a + ld a, [hl] + sub b + jr c, .asm_d354 + ld [hl], a + ld [wItemQuantityBuffer], a + and a + jr nz, .asm_d352 + dec hl + ld b, h + ld c, l + inc hl + inc hl +.asm_d348 + ld a, [hli] + ld [bc], a + inc bc + cp $ff + jr nz, .asm_d348 + ld h, d + ld l, e + dec [hl] +.asm_d352 + scf + ret + +.asm_d354 + and a + ret + +CheckItemWithQuantity: ; d356 (3:5356) + ld a, [wCurItem] + ld c, a +.asm_d35a + inc hl + ld a, [hli] + cp $ff + jr z, .asm_d365 + cp c + jr nz, .asm_d35a + scf + ret + +.asm_d365 + and a + ret + +PutItemInKeyItemPocket: ; d367 (3:5367) + ld hl, wItemsEnd + ld a, [hli] + cp $19 + jr nc, .asm_d37f + ld c, a + ld b, $0 + add hl, bc + ld a, [wCurItem] + ld [hli], a + ld [hl], $ff + ld hl, wNumKeyItems + inc [hl] + scf + ret + +.asm_d37f + and a + ret + +RemoveItemWithoutQuantity: ; d381 (3:5381) + ld a, [wCurItemQuantity] + ld e, a + ld d, $0 + ld hl, wItemsEnd + ld a, [hl] + cp e + jr nc, .asm_d394 + call FindAndTossKeyItem + ret nc + jr .asm_d397 + +.asm_d394 + dec [hl] + inc hl + add hl, de +.asm_d397 + ld d, h + ld e, l + inc hl +.asm_d39a + ld a, [hli] + ld [de], a + inc de + cp $ff + jr nz, .asm_d39a + scf + ret + +FindAndTossKeyItem: ; d3a3 (3:53a3) + ld hl, wItemsEnd + ld a, [wCurItem] + ld c, a +.asm_d3aa + inc hl + ld a, [hl] + cp c + jr z, .asm_d3b5 + cp $ff + jr nz, .asm_d3aa + xor a + ret + +.asm_d3b5 + ld a, [wNumKeyItems] + dec a + ld [wNumKeyItems], a + scf + ret + +CheckItemWithoutQuantity: ; d3be (3:53be) + ld a, [wCurItem] + ld c, a + ld hl, wKeyItems +.asm_d3c5 + ld a, [hli] + cp c + jr z, .asm_d3cf + cp $ff + jr nz, .asm_d3c5 + and a + ret + +.asm_d3cf + scf + ret + +PutItemInTMPocket: ; d3d1 (3:53d1) + dec c + ld b, $0 + ld hl, wTMsHMs + add hl, bc + ld a, [wItemQuantityChangeBuffer] + add [hl] + cp $64 + jr nc, .asm_d3e3 + ld [hl], a + scf + ret + +.asm_d3e3 + and a + ret + +RemoveTMorHM: ; d3e5 (3:53e5) + dec c + ld b, $0 + ld hl, wTMsHMs + add hl, bc + ld a, [wItemQuantityChangeBuffer] + ld b, a + ld a, [hl] + sub b + jr c, .asm_d406 + ld [hl], a + ld [wItemQuantityBuffer], a + jr nz, .asm_d404 + ld a, [wcfd2] + and a + jr z, .asm_d404 + dec a + ld [wcfd2], a +.asm_d404 + scf + ret + +.asm_d406 + and a + ret + +CheckTMorHM: ; d408 (3:5408) + dec c + ld b, $0 + ld hl, wTMsHMs + add hl, bc + ld a, [hl] + and a + ret z + scf + ret + +GetTMHMNumber:: ; d414 (3:5414) + ld a, c + cp ITEM_C3 + jr c, .asm_d41f + cp ITEM_DC + jr c, .asm_d41e + dec a +.asm_d41e + dec a +.asm_d41f + sub $bf + inc a + ld c, a + ret + +GetNumberedTM: + ld a, c + cp ITEM_C3 - (TM01 - 1) + jr c, .asm_d42f + cp ITEM_DC - (TM01 - 1) - 1 + jr c, .asm_d42e + inc a +.asm_d42e + inc a +.asm_d42f + add TM01 + dec a + ld c, a + ret + +_CheckTossableItem:: ; d434 (3:5434) + ld a, $4 + call GetItemAttr + bit 7, a + jr nz, ItemAttr_ReturnCarry + and a + ret + +CheckSelectableItem: + ld a, $4 + call GetItemAttr + bit 6, a + jr nz, ItemAttr_ReturnCarry + and a + ret + +CheckItemPocket: ; d44a (3:544a) + ld a, $5 + call GetItemAttr + and $f + ld [wItemAttributeParamBuffer], a + ret + +CheckItemContext: + ld a, $6 + call GetItemAttr + and $f + ld [wItemAttributeParamBuffer], a + ret + +CheckItemMenu: + ld a, $6 + call GetItemAttr + swap a + and $f + ld [wItemAttributeParamBuffer], a + ret + +GetItemAttr: ; d46d (3:546d) + push hl + push bc + ld hl, ItemAttributes + ld c, a + ld b, $0 + add hl, bc + xor a + ld [wItemAttributeParamBuffer], a + ld a, [wCurItem] + dec a + ld c, a + ld a, $7 + call AddNTimes + ld a, BANK(ItemAttributes) + call GetFarByte + pop bc + pop hl + ret + +ItemAttr_ReturnCarry + ld a, $1 + ld [wItemAttributeParamBuffer], a + scf + ret + +GetItemPrice: + push hl + push bc + ld a, $0 + call GetItemAttr + ld e, a + ld a, $1 + call GetItemAttr + ld d, a + pop bc + pop hl + ret diff --git a/engine/math/sine.asm b/engine/math/sine.asm new file mode 100644 index 00000000..e22d785a --- /dev/null +++ b/engine/math/sine.asm @@ -0,0 +1,40 @@ +_Sine:: ; 8ac9 (2:4ac9) + ld a, e + and $3f + cp $20 + jr nc, .negative + call .GetSine + ld a, h + ret +.negative + and $1f + call .GetSine + ld a, h + xor $ff + inc a + ret + +.GetSine: ; 8adf (2:4adf) + ld e, a + ld a, d + ld d, $0 + ld hl, .SineWave + add hl, de + add hl, de + ld e, [hl] + inc hl + ld d, [hl] + ld hl, $0 +.loop + srl a + jr nc, .no_add + add hl, de +.no_add + sla e + rl d + and a + jr nz, .loop + ret + +.SineWave: + sine_table $100 diff --git a/engine/move_mon.asm b/engine/move_mon.asm deleted file mode 100755 index 7198910d..00000000 --- a/engine/move_mon.asm +++ /dev/null @@ -1,1651 +0,0 @@ -TryAddMonToParty:: ; d892 (3:5892) - ld de, wPartyCount - ld a, [wMonType] - and $f - jr z, .asm_d89f - ld de, wOTPartyCount -.asm_d89f - ld a, [de] - inc a - cp $7 - ret nc - ld [de], a - ld a, [de] - ldh [hMoveMon], a - add e - ld e, a - jr nc, .asm_d8ad - inc d -.asm_d8ad - ld a, [wCurPartySpecies] - ld [de], a - inc de - ld a, $ff - ld [de], a - ld hl, wPartyMon1OT - ld a, [wMonType] - and $f - jr z, .asm_d8c2 - ld hl, wOTPartyMonOT -.asm_d8c2 - ldh a, [hMoveMon] - dec a - call SkipNames - ld d, h - ld e, l - ld hl, wPlayerName - ld bc, NAME_LENGTH - call CopyBytes - ld a, [wMonType] - and a - jr nz, .asm_d8f6 - ld a, [wCurPartySpecies] - ld [wd151], a - call GetPokemonName - ld hl, wPartyMonNicknames - ldh a, [hMoveMon] - dec a - call SkipNames - ld d, h - ld e, l - ld hl, wStringBuffer1 - ld bc, NAME_LENGTH - call CopyBytes -.asm_d8f6 - ld hl, wPartyMon1Species - ld a, [wMonType] - and $f - jr z, .asm_d903 - ld hl, wOTPartyMon1 -.asm_d903 - ldh a, [hMoveMon] - dec a - ld bc, PARTYMON_STRUCT_LENGTH - call AddNTimes -GeneratePartyMonStats: - ld e, l - ld d, h - push hl - ld a, [wCurPartySpecies] - ld [wCurSpecies], a - call GetBaseData - ld a, [wd120] - ld [de], a - inc de - ld a, [wBattleMode] - and a - ld a, $0 - jr z, .asm_d928 - ld a, [wEnemyMonItem] -.asm_d928 - ld [de], a - inc de - push de - ld h, d - ld l, e - ld a, [wBattleMode] - and a - jr z, .asm_d949 - ld a, [wMonType] - and a - jr nz, .asm_d949 - ld de, wEnemyMonMoves - ld a, [de] - inc de - ld [hli], a - ld a, [de] - inc de - ld [hli], a - ld a, [de] - inc de - ld [hli], a - ld a, [de] - ld [hl], a - jr .asm_d956 - -.asm_d949 - xor a - ld [hli], a - ld [hli], a - ld [hli], a - ld [hl], a - ld [wBuffer1], a - predef FillMoves -.asm_d956 - pop de - inc de - inc de - inc de - inc de - - ; Initialize ID. - ld a, [wPlayerID] - ld [de], a - inc de - ld a, [wPlayerID + 1] - ld [de], a - inc de - - ; Initialize Exp. - push de - ld a, [wCurPartyLevel] - ld d, a - callfar CalcExpAtLevel - pop de - ldh a, [hProduct + 1] - ld [de], a - inc de - ldh a, [hProduct + 2] - ld [de], a - inc de - ldh a, [hProduct + 3] - ld [de], a - inc de - - ; Initialize stat experience. - xor a - ld b, MON_DVS - MON_STAT_EXP -.asm_d980 - ld [de], a - inc de - dec b - jr nz, .asm_d980 - pop hl - push hl - ld a, [wMonType] - and $f - jr z, .asm_d998 - push hl - farcall GetTrainerDVs ; 9:7271 - pop hl - jr .asm_d9bb - -.asm_d998 - ld a, [wCurPartySpecies] - ld [wd151], a - dec a - push de - call CheckCaughtMon - ld a, [wd151] - dec a - call SetSeenAndCaughtMon - pop de - pop hl - push hl - ld a, [wBattleMode] - and a - jr nz, .asm_d9f9 - call Random - ld b, a - call Random - ld c, a -.asm_d9bb - ld a, b - ld [de], a - inc de - ld a, c - ld [de], a - inc de - push hl - push de - inc hl - inc hl - call FillPP - pop de - pop hl - inc de - inc de - inc de - inc de - ld a, $46 - ld [de], a - inc de - xor a - ld [de], a - inc de - ld [de], a - inc de - ld [de], a - inc de - ld a, [wCurPartyLevel] - ld [de], a - inc de - xor a - ld [de], a - inc de - ld [de], a - inc de - ld bc, $a - add hl, bc - ld a, $1 - ld c, a - ld b, $0 - call CalcMonStatC - ldh a, [hProduct + 2] - ld [de], a - inc de - ldh a, [hProduct + 3] - ld [de], a - inc de - jr .asm_da2f - -.asm_d9f9 - ld a, [wEnemyMonMovesEnd] - ld [de], a - inc de - ld a, [wEnemyMonMovesEnd + 1] - ld [de], a - inc de - push hl - ld hl, wEnemyMonPP - ld b, $4 -.asm_da09 - ld a, [hli] - ld [de], a - inc de - dec b - jr nz, .asm_da09 - pop hl - ld a, $46 - ld [de], a - inc de - xor a - ld [de], a - inc de - ld [de], a - inc de - ld [de], a - inc de - ld a, [wCurPartyLevel] - ld [de], a - inc de - ld hl, wEnemyMonStatus - ld a, [hli] - ld [de], a - inc de - ld a, [hli] - ld [de], a - inc de - ld a, [hli] - ld [de], a - inc de - ld a, [hl] - ld [de], a - inc de -.asm_da2f - ld a, [wBattleMode] - dec a - jr nz, .asm_da41 - ld hl, wEnemyMonMaxHP - ld bc, $c - call CopyBytes - pop hl - jr .asm_da4b - -.asm_da41 - pop hl - ld bc, $a - add hl, bc - ld b, $0 - call CalcMonStats -.asm_da4b - ld a, [wMonType] - and $f - jr nz, .asm_da71 - ld a, [wCurPartySpecies] - cp $c9 - jr nz, .asm_da71 - ld hl, wPartyMon1DVs - ld a, [wPokemonData] - dec a - ld bc, PARTYMON_STRUCT_LENGTH - call AddNTimes - predef GetUnownLetter - callfar UpdateUnownDex -.asm_da71 - scf - ret - -FillPP: ; da73 (3:5a73) - push bc - ld b, $4 -.asm_da76 - ld a, [hli] - and a - jr z, .asm_da95 - dec a - push hl - push de - push bc - ld hl, $5afe - ld bc, $7 - call AddNTimes - ld de, wStringBuffer1 - ld a, $10 - call FarCopyBytes - pop bc - pop de - pop hl - ld a, [wStringBuffer1 + 5] -.asm_da95 - ld [de], a - inc de - dec b - jr nz, .asm_da76 - pop bc - ret - -AddTempmonToParty: ; da9c (3:5a9c) - ld hl, wPartyCount - ld a, [hl] - cp $6 - scf - ret z - inc a - ld [hl], a - ld c, a - ld b, $0 - add hl, bc - ld a, [wCurPartySpecies] - ld [hli], a - ld [hl], $ff - ld hl, wPartyMon1Species - ld a, [wPartyCount] - dec a - ld bc, PARTYMON_STRUCT_LENGTH - call AddNTimes - ld e, l - ld d, h - ld hl, wTempMonSpecies - call CopyBytes - ld hl, wPartyMon6StatsEnd - ld a, [wPartyCount] - dec a - call SkipNames - ld d, h - ld e, l - ld hl, wOTPartyMon6StatsEnd - ld a, [wCurPartyMon] - call SkipNames - ld bc, NAME_LENGTH - call CopyBytes - ld hl, wPartyMonNicknames - ld a, [wPartyCount] - dec a - call SkipNames - ld d, h - ld e, l - ld hl, wOTPartyMon1Nickname - ld a, [wCurPartyMon] - call SkipNames - ld bc, NAME_LENGTH - call CopyBytes - ld a, [wCurPartySpecies] - ld [wd151], a - cp EGG - jr z, .asm_db18 - dec a - call SetSeenAndCaughtMon - ld hl, wPartyMon1Happiness - ld a, [wPokemonData] - dec a - ld bc, PARTYMON_STRUCT_LENGTH - call AddNTimes - ld [hl], 70 -.asm_db18 - ld a, [wCurPartySpecies] - cp UNOWN - jr nz, .asm_db43 - ld hl, wPartyMon1DVs - ld a, [wPartyCount] - dec a - ld bc, PARTYMON_STRUCT_LENGTH - call AddNTimes - predef GetUnownLetter - callfar UpdateUnownDex - ld a, [wFirstUnownSeen] - and a - jr nz, .asm_db43 - ld a, [wd11e] - ld [wFirstUnownSeen], a -.asm_db43 - and a - ret - -SendGetMonIntoFromBox: ; db45 (3:5b45) - ld a, $1 - call OpenSRAM - ld a, [wPokemonWithdrawDepositParameter] - and a - jr z, .asm_db66 - cp $2 - jr z, .asm_db66 - cp $3 - ld hl, wBreedMon1Species - jr z, .asm_dba1 - ld hl, sBoxCount - ld a, [hl] - cp MONS_PER_BOX - jr nz, .asm_db6f - jp Functiondcb7 - -.asm_db66 - ld hl, wPartyCount - ld a, [hl] - cp $6 - jp z, Functiondcb7 -.asm_db6f - inc a - ld [hl], a - ld c, a - ld b, $0 - add hl, bc - ld a, [wPokemonWithdrawDepositParameter] - cp $2 - ld a, [wBreedMon1Species] - jr z, .asm_db82 - ld a, [wCurPartySpecies] -.asm_db82 - ld [hli], a - ld [hl], $ff - ld a, [wPokemonWithdrawDepositParameter] - dec a - ld hl, wPartyMons - ld bc, PARTYMON_STRUCT_LENGTH - ld a, [wPokemonData] - jr nz, .asm_db9d - ld hl, sBoxMon1Species - ld bc, BOXMON_STRUCT_LENGTH - ld a, [sBoxCount] -.asm_db9d - dec a - call AddNTimes -.asm_dba1 - push hl - ld e, l - ld d, h - ld a, [wPokemonWithdrawDepositParameter] - and a - ld hl, sBoxMon1Species - ld bc, BOXMON_STRUCT_LENGTH - jr z, .asm_dbbd - cp $2 - ld hl, wBreedMon1Species - jr z, .asm_dbc3 - ld hl, wPartyMon1Species - ld bc, PARTYMON_STRUCT_LENGTH -.asm_dbbd - ld a, [wCurPartyMon] - call AddNTimes -.asm_dbc3 - ld bc, BOXMON_STRUCT_LENGTH - call CopyBytes - ld a, [wPokemonWithdrawDepositParameter] - cp $3 - ld de, wBreedMon1OT - jr z, .asm_dbe8 - dec a - ld hl, wPartyMonOT - ld a, [wPokemonData] - jr nz, .asm_dbe2 - ld hl, sBoxMonOT - ld a, [sBoxCount] -.asm_dbe2 - dec a - call SkipNames - ld d, h - ld e, l -.asm_dbe8 - ld hl, sBoxMonOT - ld a, [wPokemonWithdrawDepositParameter] - and a - jr z, .asm_dbfb - ld hl, wBreedMon1OT - cp $2 - jr z, .asm_dc01 - ld hl, wPartyMon6StatsEnd -.asm_dbfb - ld a, [wCurPartyMon] - call SkipNames -.asm_dc01 - ld bc, NAME_LENGTH - call CopyBytes - ld a, [wPokemonWithdrawDepositParameter] - cp $3 - ld de, wBreedMon1Nick - jr z, .asm_dc26 - dec a - ld hl, wPartyMon1Nickname - ld a, [wPokemonData] - jr nz, .asm_dc20 - ld hl, sBoxMonNicknames - ld a, [sBoxCount] -.asm_dc20 - dec a - call SkipNames - ld d, h - ld e, l -.asm_dc26 - ld hl, sBoxMonNicknames - ld a, [wPokemonWithdrawDepositParameter] - and a - jr z, .asm_dc39 - ld hl, wBreedMon1Nick - cp $2 - jr z, .asm_dc3f - ld hl, wPartyMon1Nickname -.asm_dc39 - ld a, [wCurPartyMon] - call SkipNames -.asm_dc3f - ld bc, NAME_LENGTH - call CopyBytes - pop hl - ld a, [wPokemonWithdrawDepositParameter] - cp $1 - jr z, .asm_dcaa - cp $3 - jp z, Functiondcb2 - push hl - srl a - add $2 - ld [wMonType], a - predef CopyMonToTempMon - callfar CalcLevel - ld a, d - ld [wCurPartyLevel], a - pop hl - ld b, h - ld c, l - ld hl, $1f - add hl, bc - ld [hl], a - ld hl, $24 - add hl, bc - ld d, h - ld e, l - ld hl, $a - add hl, bc - push bc - ld b, $1 - call CalcMonStats - pop bc - ld a, [wPokemonWithdrawDepositParameter] - and a - jr nz, Functiondcb2 - ld hl, $20 - add hl, bc - xor a - ld [hl], a - ld hl, $22 - add hl, bc - ld d, h - ld e, l - ld a, [wCurPartySpecies] - cp $fd - jr z, .asm_dca4 - inc hl - inc hl - ld a, [hli] - ld [de], a - ld a, [hl] - inc de - ld [de], a - jr Functiondcb2 - -.asm_dca4 - xor a - ld [de], a - inc de - ld [de], a - jr Functiondcb2 - -.asm_dcaa - ld a, [sBoxCount] - dec a - ld b, a - call Functiondcbc -Functiondcb2: ; dcb2 (3:5cb2) - call CloseSRAM - and a - ret - -Functiondcb7: ; dcb7 (3:5cb7) - call CloseSRAM - scf - ret - -Functiondcbc: ; dcbc (3:5cbc) - ld a, b - ld hl, sBoxMon1Species - ld bc, BOXMON_STRUCT_LENGTH - call AddNTimes - ld b, h - ld c, l - ld hl, $17 - add hl, bc - push hl - push bc - ld de, wTempMonPP - ld bc, $4 - call CopyBytes - pop bc - ld hl, $2 - add hl, bc - push hl - ld de, wTempMonMoves - ld bc, $4 - call CopyBytes - pop hl - pop de - ld a, [wMenuCursorY] - push af - ld a, [wMonType] - push af - ld b, $0 -.asm_dcf2 - ld a, [hli] - and a - jr z, .asm_dd1e - ld [wTempMonMoves], a - ld a, $2 - ld [wMonType], a - ld a, b - ld [wMenuCursorY], a - push bc - push hl - push de - farcall GetMaxPPOfMove ; same bank - pop de - pop hl - ld a, [wd151] - ld b, a - ld a, [de] - and $c0 - add b - ld [de], a - pop bc - inc de - inc b - ld a, b - cp $4 - jr c, .asm_dcf2 -.asm_dd1e - pop af - ld [wMonType], a - pop af - ld [wMenuCursorY], a - ret - -RetrieveMonFromDayCareMan: - ld a, [wBreedMon1Species] - ld [wCurPartySpecies], a - ld de, SFX_TRANSACTION - call PlaySFX - call WaitSFX - call GetBreedMon1LevelGrowth - ld a, b - ld [wMovementBufferCount], a - ld a, e - ld [wCurPartyLevel], a - xor a - ld [wPokemonWithdrawDepositParameter], a - jp Functiondd6a - -RetrieveMonFromDayCareLady: - ld a, [wBreedMon2Species] - ld [wCurPartySpecies], a - ld de, SFX_TRANSACTION - call PlaySFX - call WaitSFX - call GetBreedMon2LevelGrowth - ld a, b - ld [wMovementBufferCount], a - ld a, e - ld [wCurPartyLevel], a - ld a, $1 - ld [wPokemonWithdrawDepositParameter], a - jp Functiondd6a ; super long jump - -Functiondd6a: ; dd6a (3:5d6a) - ld hl, wPokemonData - ld a, [hl] - cp $6 - jr nz, .asm_dd74 - scf ; We shouldn't be here if we've come this far. - ret - -.asm_dd74 - inc a - ld [hl], a - ld c, a - ld b, $0 - add hl, bc - ld a, [wPokemonWithdrawDepositParameter] - and a - ld a, [wBreedMon1Species] - ld de, wBreedMon1Nick - jr z, .asm_dd8c - ld a, [wBreedMon2Species] - ld de, wBreedMon2Nick -.asm_dd8c - ld [hli], a - ld [wCurSpecies], a - ld a, $ff - ld [hl], a - ld hl, wPartyMon1Nickname - ld a, [wPartyCount] - dec a - call SkipNames - push hl - ld h, d - ld l, e - pop de - call CopyBytes - push hl - ld hl, wPartyMonOT - ld a, [wPartyCount] - dec a - call SkipNames - ld d, h - ld e, l - pop hl - call CopyBytes - push hl - call Functionde20 - pop hl - ld bc, BOXMON_STRUCT_LENGTH - call CopyBytes - call GetBaseData - call Functionde20 - ld b, d - ld c, e - ld hl, $1f - add hl, bc - ld a, [wCurPartyLevel] - ld [hl], a - ld hl, $24 - add hl, bc - ld d, h - ld e, l - ld hl, $a - add hl, bc - push bc - ld b, $1 - call CalcMonStats - ld hl, wPartyMon1Moves - ld a, [wPokemonData] - dec a - ld bc, PARTYMON_STRUCT_LENGTH - call AddNTimes - ld d, h - ld e, l - ld a, $1 - ld [wCurHPAnim], a - predef FillMoves - ld a, [wPartyCount] - dec a - ld [wCurPartyMon], a - farcall Functionc6bc ; same bank - ld a, [wCurPartyLevel] - ld d, a - callfar CalcExpAtLevel - pop bc - ld hl, $8 - add hl, bc - ldh a, [hQuotient] - ld [hli], a - ldh a, [hPrintNum3] - ld [hli], a - ldh a, [hPrintNum4] - ld [hl], a - and a - ret - -Functionde20: ; de20 (3:5e20) - ld a, [wPartyCount] - dec a - ld hl, wPartyMon1 - ld bc, PARTYMON_STRUCT_LENGTH - call AddNTimes - ld d, h - ld e, l - ret - -DepositMonWithDayCareMan: - ld de, wBreedMon1Nick - call Functionde4a - xor a - ld [wPokemonWithdrawDepositParameter], a - jp RemoveMonFromPartyOrBox - -DepositMonWithDayCareLady: - ld de, wBreedMon2Nick - call Functionde4a - xor a - ld [wPokemonWithdrawDepositParameter], a - jp RemoveMonFromPartyOrBox - -Functionde4a: ; de4a (3:5e4a) - ld a, [wCurPartyMon] - ld hl, wPartyMonNicknames - call SkipNames - call CopyBytes - ld a, [wCurPartyMon] - ld hl, wPartyMon1OT - call SkipNames - call CopyBytes - ld a, [wCurPartyMon] - ld hl, wPartyMon1 - ld bc, PARTYMON_STRUCT_LENGTH - call AddNTimes - ld bc, BOXMON_STRUCT_LENGTH - jp CopyBytes - -SendMonIntoBox: ; de74 (3:5e74) - ld a, $1 - call OpenSRAM - ld de, sBoxCount - ld a, [de] - cp $14 - jp nc, Functiondf48 - inc a - ld [de], a - ld a, [wCurPartySpecies] - ld [wCurSpecies], a - ld c, a -.asm_de8b - inc de - ld a, [de] - ld b, a - ld a, c - ld c, b - ld [de], a - inc a - jr nz, .asm_de8b - call GetBaseData - call Functiondf4d - ld hl, wPlayerName - ld de, sBoxMonOT - ld bc, NAME_LENGTH - call CopyBytes - ld a, [wCurPartySpecies] - ld [wd151], a - call GetPokemonName - ld de, sBoxMonNicknames - ld hl, wStringBuffer1 - ld bc, NAME_LENGTH - call CopyBytes - ld hl, wEnemyMon - ld de, sBoxMon1Species - ld bc, $6 - call CopyBytes - ld hl, wGameData - ld a, [hli] - ld [de], a - inc de - ld a, [hl] - ld [de], a - inc de - push de - ld a, [wCurPartyLevel] - ld d, a - callfar CalcExpAtLevel - pop de - ldh a, [hQuotient] - ld [de], a - inc de - ldh a, [hPrintNum3] - ld [de], a - inc de - ldh a, [hPrintNum4] - ld [de], a - inc de - xor a - ld b, $a -.asm_deeb - ld [de], a - inc de - dec b - jr nz, .asm_deeb - ld hl, wEnemyMonMovesEnd - ld b, $6 -.asm_def5 - ld a, [hli] - ld [de], a - inc de - dec b - jr nz, .asm_def5 - ld a, $46 - ld [de], a - inc de - xor a - ld [de], a - inc de - ld [de], a - inc de - ld [de], a - inc de - ld a, [wCurPartyLevel] - ld [de], a - ld a, [wCurPartySpecies] - dec a - call SetSeenAndCaughtMon - ld a, [wCurPartySpecies] - cp $c9 - jr nz, .asm_df26 - ld hl, sBoxMon1DVs - predef GetUnownLetter - callfar UpdateUnownDex -.asm_df26 - ld hl, sBoxMon1Moves - ld de, wTempMonMoves - ld bc, $4 - call CopyBytes - ld hl, sBoxMon1PP - ld de, wTempMonPP - ld bc, $4 - call CopyBytes - ld b, $0 - call Functiondcbc - call CloseSRAM - scf - ret - -Functiondf48: ; df48 (3:5f48) - call CloseSRAM - and a - ret - -Functiondf4d: ; df4d (3:5f4d) - ld hl, sBoxMonOT - ld bc, NAME_LENGTH - call Functiondf65 - ld hl, sBoxMonNicknames - ld bc, NAME_LENGTH - call Functiondf65 - ld hl, sBoxMon1Species - ld bc, BOXMON_STRUCT_LENGTH -Functiondf65: ; df65 (3:5f65) - ld a, [sBoxCount] - cp $2 - ret c - push hl - call AddNTimes - dec hl - ld e, l - ld d, h - pop hl - ld a, [sBoxCount] - dec a - call AddNTimes - dec hl - push hl - ld a, [sBoxCount] - dec a - ld hl, $0 - call AddNTimes - ld c, l - ld b, h - pop hl -.asm_df89 - ld a, [hld] - ld [de], a - dec de - dec bc - ld a, c - or b - jr nz, .asm_df89 - ret - -GiveEgg: ; df92 (3:5f92) - ld a, [wCurPartySpecies] - push af - callfar GetPreEvolution - callfar GetPreEvolution - ld a, [wCurPartySpecies] - dec a - push af - call CheckCaughtMon - pop af - push bc - call CheckSeenMon - push bc - call TryAddMonToParty - pop bc - ld a, c - and a - jr nz, .asm_dfc9 - ld a, [wCurPartySpecies] - dec a - ld c, a - ld d, $0 - ld hl, wPokedexCaught - ld b, RESET_FLAG - predef SmallFarFlagAction -.asm_dfc9 - pop bc - ld a, c - and a - jr nz, .asm_dfdf - ld a, [wCurPartySpecies] - dec a - ld c, a - ld d, $0 - ld hl, wPokedexSeen - ld b, RESET_FLAG - predef SmallFarFlagAction -.asm_dfdf - pop af - ld [wCurPartySpecies], a - ld a, [wPokemonData] - dec a - ld bc, PARTYMON_STRUCT_LENGTH - ld hl, wPartyMon1Species - call AddNTimes - ld a, [wCurPartySpecies] - ld [hl], a - ld hl, wPokemonData - ld a, [hl] - ld b, $0 - ld c, a - add hl, bc - ld a, $fd - ld [hl], a - ld a, [wPokemonData] - dec a - ld hl, wPartyMon1Nickname - call SkipNames - ld de, String_Egg - call CopyName2 - ld a, [wPartyCount] - dec a - ld hl, wPartyMon1Happiness - ld bc, PARTYMON_STRUCT_LENGTH - call AddNTimes - ld a, [wDebugFlags] - bit 1, a - ld a, $1 - jr nz, .asm_e028 - ld a, [wBaseEggSteps] -.asm_e028 - ld [hl], a - ld a, [wPartyCount] - dec a - ld hl, wPartyMon1HP - ld bc, PARTYMON_STRUCT_LENGTH - call AddNTimes - xor a - ld [hli], a - ld [hl], a - and a - ret - -String_Egg: - db "EGG@" - -RemoveMonFromPartyOrBox: ; e03f (3:603f) - ld hl, wPartyCount - ld a, [wPokemonWithdrawDepositParameter] - and a - jr z, .asm_e050 - ld a, $1 - call OpenSRAM - ld hl, sBoxCount -.asm_e050 - ld a, [hl] - dec a - ld [hli], a - ld a, [wCurPartyMon] - ld c, a - ld b, $0 - add hl, bc - ld e, l - ld d, h - inc de -.asm_e05d - ld a, [de] - inc de - ld [hli], a - inc a - jr nz, .asm_e05d - ld hl, wPartyMon6StatsEnd - ld d, $5 - ld a, [wPokemonWithdrawDepositParameter] - and a - jr z, .asm_e073 - ld hl, sBoxMonOT - ld d, $13 -.asm_e073 - ld a, [wCurPartyMon] - call SkipNames - ld a, [wCurPartyMon] - cp d - jr nz, .asm_e084 - ld [hl], $ff - jp .asm_e0f6 - -.asm_e084 - ld d, h - ld e, l - ld bc, NAME_LENGTH - add hl, bc - ld bc, wPartyMonNicknames - ld a, [wPokemonWithdrawDepositParameter] - and a - jr z, .asm_e096 - ld bc, sBoxMonNicknames -.asm_e096 - call CopyDataUntil - ld hl, wPartyMon1 - ld bc, PARTYMON_STRUCT_LENGTH - ld a, [wPokemonWithdrawDepositParameter] - and a - jr z, .asm_e0ab - ld hl, sBoxMon1Species - ld bc, BOXMON_STRUCT_LENGTH -.asm_e0ab - ld a, [wCurPartyMon] - call AddNTimes - ld d, h - ld e, l - ld a, [wPokemonWithdrawDepositParameter] - and a - jr z, .asm_e0c2 - ld bc, BOXMON_STRUCT_LENGTH - add hl, bc - ld bc, sBoxMonOT - jr .asm_e0c9 - -.asm_e0c2 - ld bc, PARTYMON_STRUCT_LENGTH - add hl, bc - ld bc, wPartyMonOT -.asm_e0c9 - call CopyDataUntil - ld hl, wPartyMonNicknames - ld a, [wPokemonWithdrawDepositParameter] - and a - jr z, .asm_e0d8 - ld hl, sBoxMonNicknames -.asm_e0d8 - ld bc, NAME_LENGTH - ld a, [wCurPartyMon] - call AddNTimes - ld d, h - ld e, l - ld bc, NAME_LENGTH - add hl, bc - ld bc, wPartyMonNicknamesEnd - ld a, [wPokemonWithdrawDepositParameter] - and a - jr z, .asm_e0f3 - ld bc, sBoxEnd -.asm_e0f3 - call CopyDataUntil -.asm_e0f6 - ld a, [wPokemonWithdrawDepositParameter] - and a - jp nz, CloseSRAM - ld a, [wLinkMode] - and a - ret nz - ld a, $0 - call OpenSRAM - ld hl, wPokemonData - ld a, [wCurPartyMon] - cp [hl] - jr z, .asm_e137 - ld hl, sPartyMail - ld bc, MAIL_STRUCT_LENGTH - call AddNTimes - push hl - add hl, bc - pop de - ld a, [wCurPartyMon] - ld b, a -.asm_e120 - push bc - push hl - ld bc, MAIL_STRUCT_LENGTH - call CopyBytes - pop hl - push hl - ld bc, MAIL_STRUCT_LENGTH - add hl, bc - pop de - pop bc - inc b - ld a, [wPartyCount] - cp b - jr nz, .asm_e120 -.asm_e137 - jp CloseSRAM - -ComputeNPCTrademonStats: - ld a, MON_LEVEL - call GetPartyParamLocation - ld a, [hl] - ld [MON_LEVEL], a ; wow - ld a, MON_SPECIES - call GetPartyParamLocation - ld a, [hl] - ld [wCurSpecies], a - call GetBaseData - ld a, MON_MAXHP - call GetPartyParamLocation - ld d, h - ld e, l - push de - ld a, MON_STAT_EXP - 1 - call GetPartyParamLocation - ld b, $1 - call CalcMonStats - pop de - ld a, MON_HP - call GetPartyParamLocation - ld a, [de] - inc de - ld [hli], a - ld a, [de] - ld [hl], a - ret - -CalcMonStats: ; e16d -; Calculates all 6 Stats of a Pkmn -; b: Take into account stat EXP if TRUE -; 'c' counts from 1-6 and points with 'BaseStats' to the base value -; hl is the path to the Stat EXP -; results in $ffb7 and $ffb8 are saved in [de] - - ld c, $0 -.loop - inc c - call CalcMonStatC - ldh a, [hMultiplicand + 1] - ld [de], a - inc de - ldh a, [hMultiplicand + 2] - ld [de], a - inc de - ld a, c - cp STAT_SDEF - jr nz, .loop - ret -; e17b - -CalcMonStatC: ; e181 -; 'c' is 1-6 and points to the BaseStat -; 1: HP -; 2: Attack -; 3: Defense -; 4: Speed -; 5: SpAtk -; 6: SpDef - push hl - push de - push bc - ld a, b - ld d, a - push hl - ld hl, wd121 - dec hl ; has to be decreased, because 'c' begins with 1 - ld b, $0 - add hl, bc - ld a, [hl] - ld e, a - pop hl - push hl - ld a, c - cp STAT_SDEF - jr nz, .not_spdef - dec hl - dec hl - -.not_spdef - sla c - ld a, d - and a - jr z, .no_stat_exp - add hl, bc -.sqrt_loop - xor a - ldh [hMultiplicand], a - ldh [hMultiplicand + 1], a - inc b - ld a, b - cp $ff - jr z, .no_stat_exp - ldh [hMultiplicand + 2], a - ldh [hMultiplier], a - call Multiply - ld a, [hld] - ld d, a - ldh a, [hProduct + 3] - sub d - ld a, [hli] - ld d, a - ldh a, [hProduct + 2] - sbc d - jr c, .sqrt_loop -.no_stat_exp - srl c - pop hl - push bc - ld bc, MON_DVS - MON_HP_EXP + 1 - add hl, bc - pop bc - ld a, c - cp STAT_ATK - jr z, .Attack - cp STAT_DEF - jr z, .Defense - cp STAT_SPD - jr z, .Speed - cp STAT_SATK - jr z, .Special - cp STAT_SDEF - jr z, .Special -; DV_HP = (DV_ATK & 1) << 3 + (DV_DEF & 1) << 2 + (DV_SPD & 1) << 1 + (DV_SPC & 1) - push bc - ld a, [hl] - swap a - and $1 - add a - add a - add a - ld b, a - ld a, [hli] - and $1 - add a - add a - add b - ld b, a - ld a, [hl] - swap a - and $1 - add a - add b - ld b, a - ld a, [hl] - and $1 - add b - pop bc - jr .GotDV - -.Attack: - ld a, [hl] - swap a - and $f - jr .GotDV - -.Defense: - ld a, [hl] - and $f - jr .GotDV - -.Speed: - inc hl - ld a, [hl] - swap a - and $f - jr .GotDV - -.Special: - inc hl - ld a, [hl] - and $f - -.GotDV: - ld d, 0 - add e - ld e, a - jr nc, .no_overflow_1 - inc d - -.no_overflow_1 - sla e - rl d - srl b - srl b - ld a, b - add e - jr nc, .no_overflow_2 - inc d - -.no_overflow_2 - ldh [hMultiplicand + 2], a - ld a, d - ldh [hMultiplicand + 1], a - xor a - ldh [hMultiplicand + 0], a - ld a, [wCurPartyLevel] - ldh [hMultiplier], a - call Multiply - ldh a, [hProduct + 1] - ldh [hDividend + 0], a - ldh a, [hProduct + 2] - ldh [hDividend + 1], a - ldh a, [hProduct + 3] - ldh [hDividend + 2], a - ld a, 100 - ldh [hDivisor], a - ld a, 3 - ld b, a - call Divide - ld a, c - cp STAT_HP - ld a, 5 - jr nz, .not_hp - ld a, [wCurPartyLevel] - ld b, a - ldh a, [hQuotient + 2] - add b - ldh [hMultiplicand + 2], a - jr nc, .no_overflow_3 - ldh a, [hQuotient + 1] - inc a - ldh [hMultiplicand + 1], a - -.no_overflow_3 - ld a, 10 - -.not_hp - ld b, a - ldh a, [hQuotient + 2] - add b - ldh [hMultiplicand + 2], a - jr nc, .no_overflow_4 - ldh a, [hQuotient + 1] - inc a - ldh [hMultiplicand + 1], a - -.no_overflow_4 - ldh a, [hQuotient + 1] - cp (1000 / $100) + 1 - jr nc, .max_stat - cp 1000 / $100 - jr c, .stat_value_okay - ldh a, [hQuotient + 2] - cp 1000 % $100 - jr c, .stat_value_okay - -.max_stat - ld a, 999 / $100 - ldh [hMultiplicand + 1], a - ld a, 999 % $100 - ldh [hMultiplicand + 2], a - -.stat_value_okay - pop bc - pop de - pop hl - ret - -GivePoke: ; Give a Pokemon from script - push de - push bc - xor a - ld [wMonType], a - call TryAddMonToParty - jr nc, .asm_e2c9 - ld hl, wPartyMon1Nickname - ld a, [wPokemonData] - dec a - ld [wCurPartyMon], a - call SkipNames - ld d, h - ld e, l - pop bc - ld a, b - ld b, $0 - push bc - push de - push af - ld a, [wCurItem] - and a - jr z, .asm_e2fa - ld a, [wCurPartyMon] - ld hl, wPartyMon1Item - ld bc, PARTYMON_STRUCT_LENGTH - call AddNTimes - ld a, [wCurItem] - ld [hl], a - jr .asm_e2fa - -.asm_e2c9 - ld a, [wCurPartySpecies] - ld [wTempEnemyMonSpecies], a - callfar LoadEnemyMon - call SendMonIntoBox - jp nc, Functione3af - ld a, BOXMON - ld [wMonType], a - xor a - ld [wCurPartyMon], a - ld de, wMonOrItemNameBuffer - pop bc - ld a, b - ld b, $1 - push bc - push de - push af - ld a, [wCurItem] - and a - jr z, .asm_e2fa - ld a, [wCurItem] - ld [sBoxMon1Item], a -.asm_e2fa - ld a, [wCurPartySpecies] - ld [wd151], a - ld [wTempEnemyMonSpecies], a - call GetPokemonName - ld hl, wStringBuffer1 - ld de, wMonOrItemNameBuffer - ld bc, MON_NAME_LENGTH - call CopyBytes - pop af - and a - jr z, .asm_e381 - pop de - pop bc - pop hl - push bc - push hl - ld a, [wScriptBank] - call GetFarHalfword - ld bc, MON_NAME_LENGTH - ld a, [wScriptBank] - call FarCopyBytes - pop hl - inc hl - inc hl - ld a, [wScriptBank] - call GetFarHalfword - pop bc - ld a, b - and a - push de - push bc - jr nz, .asm_e360 - push hl - ld a, [wCurPartyMon] - ld hl, wPartyMon1OT - call SkipNames - ld d, h - ld e, l - pop hl - ld a, [wScriptBank] - call FarCopyBytes - ld a, [wCurPartyMon] - ld hl, wPartyMon1ID - ld bc, PARTYMON_STRUCT_LENGTH - call AddNTimes - ld a, 01001 / $100 - ld [hli], a - ld [hl], 01001 % $100 - jr .asm_e38d - -.asm_e360 - ld a, BANK(sBoxMonOT) - call OpenSRAM - ld de, sBoxMonOT - ld bc, MON_NAME_LENGTH - ld a, [wScriptBank] - call FarCopyBytes - ld hl, sBoxMon1ID - call Random - ld [hli], a - call Random - ld [hl], a - call CloseSRAM - jr .asm_e38d - -.asm_e381 - callfar Functionc7cd0 - pop de - jr c, .asm_e38d - call InitNickname -.asm_e38d - pop bc - pop de - ld a, b - and a - ret z - ld hl, TextJump_WasSentToBillsPC - call PrintText - ld a, BANK(sBoxMonNicknames) - call OpenSRAM - ld hl, wMonOrItemNameBuffer - ld de, sBoxMonNicknames - ld bc, MON_NAME_LENGTH - call CopyBytes - call CloseSRAM - ld b, $1 - ret - -Functione3af: ; e3af (3:63af) - pop bc - pop de - ld b, $2 - ret - -TextJump_WasSentToBillsPC: - text_far Text_WasSentToBillsPC - db "@" - -InitNickname: ; e3b9 (3:63b9) - push de - call LoadStandardMenuHeader - call DisableSpriteUpdates - pop de - push de - ld b, $0 - farcall NamingScreen - pop hl - ld de, wStringBuffer1 - call InitName - ld a, $4 ; XXX could this be in bank 4 in pokered? - ld hl, ExitAllMenus - rst FarCall - ret diff --git a/engine/overworld/variables.asm b/engine/overworld/variables.asm new file mode 100755 index 00000000..7e6906ee --- /dev/null +++ b/engine/overworld/variables.asm @@ -0,0 +1,119 @@ +GetVarAction_:: + ld a, c + cp NUM_VARS + jr c, .valid + xor a +.valid + ld c, a + ld b, 0 + ld hl, .VarActionTable + add hl, bc + add hl, bc + add hl, bc + ld e, [hl] + inc hl + ld d, [hl] + inc hl + ld b, [hl] + ld a, b + and RETVAR_EXECUTE + jr nz, .call + ld a, b + and RETVAR_ADDR_DE + ret nz + ld a, [de] + jr .loadstringbuffer2 + +.call + call _de_ + ret + +.loadstringbuffer2 + ld de, wStringBuffer2 + ld [de], a + ret + +.VarActionTable: + dwb wStringBuffer2, RETVAR_STRBUF2 + dwb wPartyCount, RETVAR_STRBUF2 + dwb .BattleResult, RETVAR_EXECUTE + dwb wBattleType, RETVAR_ADDR_DE + dwb wTimeOfDay, RETVAR_STRBUF2 + dwb .CountCaughtMons, RETVAR_EXECUTE + dwb .CountSeenMons, RETVAR_EXECUTE + dwb .CountBadges, RETVAR_EXECUTE + dwb wPlayerState, RETVAR_ADDR_DE + dwb .PlayerFacing, RETVAR_EXECUTE + dwb hHours, RETVAR_STRBUF2 + dwb .DayOfWeek, RETVAR_EXECUTE + dwb wMapGroup, RETVAR_STRBUF2 + dwb wMapNumber, RETVAR_STRBUF2 + dwb .UnownCaught, RETVAR_EXECUTE + dwb wPermission, RETVAR_STRBUF2 + dwb .BoxFreeSpace, RETVAR_EXECUTE + dwb wBugContestMinsRemaining, RETVAR_STRBUF2 + dwb wXCoord, RETVAR_STRBUF2 + dwb wYCoord, RETVAR_STRBUF2 + dwb wSpecialPhoneCallID, RETVAR_STRBUF2 + dwb 0, 0 + +.CountCaughtMons: ; 41cf +; Caught mons. + ld hl, wPokedexCaught + ld b, $20 + call CountSetBits + ld a, [wd151] + jp .loadstringbuffer2 + +.CountSeenMons: ; 41dd +; Seen mons. + ld hl, wPokedexSeen + ld b, $20 + call CountSetBits + ld a, [wd151] + jp .loadstringbuffer2 + +.CountBadges: ; 41eb +; Number of owned badges. + ld hl, wBadges + ld b, 2 + call CountSetBits + ld a, [wd151] + jp .loadstringbuffer2 + +.PlayerFacing: ; 41f9 +; The direction the player is facing. + ld a, [wPlayerDirection] + and $c + rrca + rrca + jp .loadstringbuffer2 + +.DayOfWeek: ; 4203 +; The day of the week. + call GetWeekday + jp .loadstringbuffer2 + +.UnownCaught: ; 4209 +; Number of unique Unown caught. + call CountUnown ; gold: c5ac | silver: c5aa + ld a, b + jp .loadstringbuffer2 + +.BoxFreeSpace: ; 4210 +; Remaining slots in the current box. + ld a, BANK(sBoxCount) + call OpenSRAM + ld hl, sBoxCount + ld a, MONS_PER_BOX + sub [hl] + ld b, a + call CloseSRAM + ld a, b + jp .loadstringbuffer2 + +.BattleResult: ; 4223 + ld a, [wBattleResult] + and $7f + jp .loadstringbuffer2 +; 422b diff --git a/engine/pokemon/breedmon_level_growth.asm b/engine/pokemon/breedmon_level_growth.asm new file mode 100644 index 00000000..c6356dd6 --- /dev/null +++ b/engine/pokemon/breedmon_level_growth.asm @@ -0,0 +1,27 @@ +GetBreedMon1LevelGrowth: + ld hl, wBreedMon1Stats + ld de, wTempMon + ld bc, BOXMON_STRUCT_LENGTH + call CopyBytes + callfar CalcLevel + ld a, [wBreedMon1Level] + ld b, a + ld a, d + ld e, a + sub b + ld d, a + ret + +GetBreedMon2LevelGrowth: + ld hl, wBreedMon2Stats + ld de, wTempMon + ld bc, BOXMON_STRUCT_LENGTH + call CopyBytes + callfar CalcLevel + ld a, [wBreedMon2Level] + ld b, a + ld a, d + ld e, a + sub b + ld d, a + ret diff --git a/engine/pokemon/health.asm b/engine/pokemon/health.asm new file mode 100755 index 00000000..a94a3ec3 --- /dev/null +++ b/engine/pokemon/health.asm @@ -0,0 +1,102 @@ +HealParty: ; c69d (3:469d) + xor a + ld [wCurPartyMon], a + ld hl, wPartySpecies +.asm_c6a4 + ld a, [hli] + cp $ff + jr z, .asm_c6bb + cp $fd + jr z, .asm_c6b2 + push hl + call Functionc6bc + pop hl +.asm_c6b2 + ld a, [wCurPartyMon] + inc a + ld [wCurPartyMon], a + jr .asm_c6a4 + +.asm_c6bb + ret + +Functionc6bc: ; c6bc (3:46bc) + ld a, $0 + call GetPartyParamLocation + ld d, h + ld e, l + ld hl, $20 + add hl, de + xor a + ld [hli], a + ld [hl], a + ld hl, $24 + add hl, de + ld b, h + ld c, l + dec bc + dec bc + ld a, [hli] + ld [bc], a + inc bc + ld a, [hl] + ld [bc], a + farcall Functionf900 + ret + +ComputeHPBarPixels: +; e = bc * (6 * 8) / de + ld a, b + or c + jr z, .asm_c722 + push hl + xor a + ldh [hMultiplicand + 0], a + ld a, b + ldh [hMultiplicand + 1], a + ld a, c + ldh [hMultiplicand + 2], a + ld a, 6 * 8 + ldh [hMultiplier], a + call Multiply + ; We need de to be under 256 because hDivisor is only 1 byte. + ld a, d + and a + jr z, .asm_c711 + ; divide de and hProduct by 4 + srl d + rr e + srl d + rr e + ldh a, [hProduct + 2] + ld b, a + ldh a, [hProduct + 3] + srl b + rr a + srl b + rr a + ldh [hDividend + 3], a + ld a, b + ldh [hDividend + 2], a +.asm_c711 + ld a, e + ldh [hPrintNum5], a + ld b, $4 + call Divide + ldh a, [hPrintNum4] + ld e, a + pop hl + and a + ret nz + ld e, $1 + ret + +.asm_c722 + ld e, $0 + ret + +AnimateHPBar: ; c725 (3:4725) + call WaitBGMap + call AnimateHPBar_ + call WaitBGMap + ret diff --git a/engine/pokemon/knows_move.asm b/engine/pokemon/knows_move.asm new file mode 100644 index 00000000..9fe0f6ac --- /dev/null +++ b/engine/pokemon/knows_move.asm @@ -0,0 +1,24 @@ +KnowsMove: + ld a, MON_MOVES + call GetPartyParamLocation + ld a, [wPutativeTMHMMove] + ld b, a + ld c, NUM_MOVES +.loop + ld a, [hli] + cp b + jr z, .knows_move + dec c + jr nz, .loop + and a + ret + +.knows_move + ld hl, .KnowsMoveText + call PrintText + scf + ret + +.KnowsMoveText: + text_far _KnowsMoveText + text_end diff --git a/engine/pokemon/move_mon.asm b/engine/pokemon/move_mon.asm new file mode 100755 index 00000000..7198910d --- /dev/null +++ b/engine/pokemon/move_mon.asm @@ -0,0 +1,1651 @@ +TryAddMonToParty:: ; d892 (3:5892) + ld de, wPartyCount + ld a, [wMonType] + and $f + jr z, .asm_d89f + ld de, wOTPartyCount +.asm_d89f + ld a, [de] + inc a + cp $7 + ret nc + ld [de], a + ld a, [de] + ldh [hMoveMon], a + add e + ld e, a + jr nc, .asm_d8ad + inc d +.asm_d8ad + ld a, [wCurPartySpecies] + ld [de], a + inc de + ld a, $ff + ld [de], a + ld hl, wPartyMon1OT + ld a, [wMonType] + and $f + jr z, .asm_d8c2 + ld hl, wOTPartyMonOT +.asm_d8c2 + ldh a, [hMoveMon] + dec a + call SkipNames + ld d, h + ld e, l + ld hl, wPlayerName + ld bc, NAME_LENGTH + call CopyBytes + ld a, [wMonType] + and a + jr nz, .asm_d8f6 + ld a, [wCurPartySpecies] + ld [wd151], a + call GetPokemonName + ld hl, wPartyMonNicknames + ldh a, [hMoveMon] + dec a + call SkipNames + ld d, h + ld e, l + ld hl, wStringBuffer1 + ld bc, NAME_LENGTH + call CopyBytes +.asm_d8f6 + ld hl, wPartyMon1Species + ld a, [wMonType] + and $f + jr z, .asm_d903 + ld hl, wOTPartyMon1 +.asm_d903 + ldh a, [hMoveMon] + dec a + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes +GeneratePartyMonStats: + ld e, l + ld d, h + push hl + ld a, [wCurPartySpecies] + ld [wCurSpecies], a + call GetBaseData + ld a, [wd120] + ld [de], a + inc de + ld a, [wBattleMode] + and a + ld a, $0 + jr z, .asm_d928 + ld a, [wEnemyMonItem] +.asm_d928 + ld [de], a + inc de + push de + ld h, d + ld l, e + ld a, [wBattleMode] + and a + jr z, .asm_d949 + ld a, [wMonType] + and a + jr nz, .asm_d949 + ld de, wEnemyMonMoves + ld a, [de] + inc de + ld [hli], a + ld a, [de] + inc de + ld [hli], a + ld a, [de] + inc de + ld [hli], a + ld a, [de] + ld [hl], a + jr .asm_d956 + +.asm_d949 + xor a + ld [hli], a + ld [hli], a + ld [hli], a + ld [hl], a + ld [wBuffer1], a + predef FillMoves +.asm_d956 + pop de + inc de + inc de + inc de + inc de + + ; Initialize ID. + ld a, [wPlayerID] + ld [de], a + inc de + ld a, [wPlayerID + 1] + ld [de], a + inc de + + ; Initialize Exp. + push de + ld a, [wCurPartyLevel] + ld d, a + callfar CalcExpAtLevel + pop de + ldh a, [hProduct + 1] + ld [de], a + inc de + ldh a, [hProduct + 2] + ld [de], a + inc de + ldh a, [hProduct + 3] + ld [de], a + inc de + + ; Initialize stat experience. + xor a + ld b, MON_DVS - MON_STAT_EXP +.asm_d980 + ld [de], a + inc de + dec b + jr nz, .asm_d980 + pop hl + push hl + ld a, [wMonType] + and $f + jr z, .asm_d998 + push hl + farcall GetTrainerDVs ; 9:7271 + pop hl + jr .asm_d9bb + +.asm_d998 + ld a, [wCurPartySpecies] + ld [wd151], a + dec a + push de + call CheckCaughtMon + ld a, [wd151] + dec a + call SetSeenAndCaughtMon + pop de + pop hl + push hl + ld a, [wBattleMode] + and a + jr nz, .asm_d9f9 + call Random + ld b, a + call Random + ld c, a +.asm_d9bb + ld a, b + ld [de], a + inc de + ld a, c + ld [de], a + inc de + push hl + push de + inc hl + inc hl + call FillPP + pop de + pop hl + inc de + inc de + inc de + inc de + ld a, $46 + ld [de], a + inc de + xor a + ld [de], a + inc de + ld [de], a + inc de + ld [de], a + inc de + ld a, [wCurPartyLevel] + ld [de], a + inc de + xor a + ld [de], a + inc de + ld [de], a + inc de + ld bc, $a + add hl, bc + ld a, $1 + ld c, a + ld b, $0 + call CalcMonStatC + ldh a, [hProduct + 2] + ld [de], a + inc de + ldh a, [hProduct + 3] + ld [de], a + inc de + jr .asm_da2f + +.asm_d9f9 + ld a, [wEnemyMonMovesEnd] + ld [de], a + inc de + ld a, [wEnemyMonMovesEnd + 1] + ld [de], a + inc de + push hl + ld hl, wEnemyMonPP + ld b, $4 +.asm_da09 + ld a, [hli] + ld [de], a + inc de + dec b + jr nz, .asm_da09 + pop hl + ld a, $46 + ld [de], a + inc de + xor a + ld [de], a + inc de + ld [de], a + inc de + ld [de], a + inc de + ld a, [wCurPartyLevel] + ld [de], a + inc de + ld hl, wEnemyMonStatus + ld a, [hli] + ld [de], a + inc de + ld a, [hli] + ld [de], a + inc de + ld a, [hli] + ld [de], a + inc de + ld a, [hl] + ld [de], a + inc de +.asm_da2f + ld a, [wBattleMode] + dec a + jr nz, .asm_da41 + ld hl, wEnemyMonMaxHP + ld bc, $c + call CopyBytes + pop hl + jr .asm_da4b + +.asm_da41 + pop hl + ld bc, $a + add hl, bc + ld b, $0 + call CalcMonStats +.asm_da4b + ld a, [wMonType] + and $f + jr nz, .asm_da71 + ld a, [wCurPartySpecies] + cp $c9 + jr nz, .asm_da71 + ld hl, wPartyMon1DVs + ld a, [wPokemonData] + dec a + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + predef GetUnownLetter + callfar UpdateUnownDex +.asm_da71 + scf + ret + +FillPP: ; da73 (3:5a73) + push bc + ld b, $4 +.asm_da76 + ld a, [hli] + and a + jr z, .asm_da95 + dec a + push hl + push de + push bc + ld hl, $5afe + ld bc, $7 + call AddNTimes + ld de, wStringBuffer1 + ld a, $10 + call FarCopyBytes + pop bc + pop de + pop hl + ld a, [wStringBuffer1 + 5] +.asm_da95 + ld [de], a + inc de + dec b + jr nz, .asm_da76 + pop bc + ret + +AddTempmonToParty: ; da9c (3:5a9c) + ld hl, wPartyCount + ld a, [hl] + cp $6 + scf + ret z + inc a + ld [hl], a + ld c, a + ld b, $0 + add hl, bc + ld a, [wCurPartySpecies] + ld [hli], a + ld [hl], $ff + ld hl, wPartyMon1Species + ld a, [wPartyCount] + dec a + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + ld e, l + ld d, h + ld hl, wTempMonSpecies + call CopyBytes + ld hl, wPartyMon6StatsEnd + ld a, [wPartyCount] + dec a + call SkipNames + ld d, h + ld e, l + ld hl, wOTPartyMon6StatsEnd + ld a, [wCurPartyMon] + call SkipNames + ld bc, NAME_LENGTH + call CopyBytes + ld hl, wPartyMonNicknames + ld a, [wPartyCount] + dec a + call SkipNames + ld d, h + ld e, l + ld hl, wOTPartyMon1Nickname + ld a, [wCurPartyMon] + call SkipNames + ld bc, NAME_LENGTH + call CopyBytes + ld a, [wCurPartySpecies] + ld [wd151], a + cp EGG + jr z, .asm_db18 + dec a + call SetSeenAndCaughtMon + ld hl, wPartyMon1Happiness + ld a, [wPokemonData] + dec a + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + ld [hl], 70 +.asm_db18 + ld a, [wCurPartySpecies] + cp UNOWN + jr nz, .asm_db43 + ld hl, wPartyMon1DVs + ld a, [wPartyCount] + dec a + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + predef GetUnownLetter + callfar UpdateUnownDex + ld a, [wFirstUnownSeen] + and a + jr nz, .asm_db43 + ld a, [wd11e] + ld [wFirstUnownSeen], a +.asm_db43 + and a + ret + +SendGetMonIntoFromBox: ; db45 (3:5b45) + ld a, $1 + call OpenSRAM + ld a, [wPokemonWithdrawDepositParameter] + and a + jr z, .asm_db66 + cp $2 + jr z, .asm_db66 + cp $3 + ld hl, wBreedMon1Species + jr z, .asm_dba1 + ld hl, sBoxCount + ld a, [hl] + cp MONS_PER_BOX + jr nz, .asm_db6f + jp Functiondcb7 + +.asm_db66 + ld hl, wPartyCount + ld a, [hl] + cp $6 + jp z, Functiondcb7 +.asm_db6f + inc a + ld [hl], a + ld c, a + ld b, $0 + add hl, bc + ld a, [wPokemonWithdrawDepositParameter] + cp $2 + ld a, [wBreedMon1Species] + jr z, .asm_db82 + ld a, [wCurPartySpecies] +.asm_db82 + ld [hli], a + ld [hl], $ff + ld a, [wPokemonWithdrawDepositParameter] + dec a + ld hl, wPartyMons + ld bc, PARTYMON_STRUCT_LENGTH + ld a, [wPokemonData] + jr nz, .asm_db9d + ld hl, sBoxMon1Species + ld bc, BOXMON_STRUCT_LENGTH + ld a, [sBoxCount] +.asm_db9d + dec a + call AddNTimes +.asm_dba1 + push hl + ld e, l + ld d, h + ld a, [wPokemonWithdrawDepositParameter] + and a + ld hl, sBoxMon1Species + ld bc, BOXMON_STRUCT_LENGTH + jr z, .asm_dbbd + cp $2 + ld hl, wBreedMon1Species + jr z, .asm_dbc3 + ld hl, wPartyMon1Species + ld bc, PARTYMON_STRUCT_LENGTH +.asm_dbbd + ld a, [wCurPartyMon] + call AddNTimes +.asm_dbc3 + ld bc, BOXMON_STRUCT_LENGTH + call CopyBytes + ld a, [wPokemonWithdrawDepositParameter] + cp $3 + ld de, wBreedMon1OT + jr z, .asm_dbe8 + dec a + ld hl, wPartyMonOT + ld a, [wPokemonData] + jr nz, .asm_dbe2 + ld hl, sBoxMonOT + ld a, [sBoxCount] +.asm_dbe2 + dec a + call SkipNames + ld d, h + ld e, l +.asm_dbe8 + ld hl, sBoxMonOT + ld a, [wPokemonWithdrawDepositParameter] + and a + jr z, .asm_dbfb + ld hl, wBreedMon1OT + cp $2 + jr z, .asm_dc01 + ld hl, wPartyMon6StatsEnd +.asm_dbfb + ld a, [wCurPartyMon] + call SkipNames +.asm_dc01 + ld bc, NAME_LENGTH + call CopyBytes + ld a, [wPokemonWithdrawDepositParameter] + cp $3 + ld de, wBreedMon1Nick + jr z, .asm_dc26 + dec a + ld hl, wPartyMon1Nickname + ld a, [wPokemonData] + jr nz, .asm_dc20 + ld hl, sBoxMonNicknames + ld a, [sBoxCount] +.asm_dc20 + dec a + call SkipNames + ld d, h + ld e, l +.asm_dc26 + ld hl, sBoxMonNicknames + ld a, [wPokemonWithdrawDepositParameter] + and a + jr z, .asm_dc39 + ld hl, wBreedMon1Nick + cp $2 + jr z, .asm_dc3f + ld hl, wPartyMon1Nickname +.asm_dc39 + ld a, [wCurPartyMon] + call SkipNames +.asm_dc3f + ld bc, NAME_LENGTH + call CopyBytes + pop hl + ld a, [wPokemonWithdrawDepositParameter] + cp $1 + jr z, .asm_dcaa + cp $3 + jp z, Functiondcb2 + push hl + srl a + add $2 + ld [wMonType], a + predef CopyMonToTempMon + callfar CalcLevel + ld a, d + ld [wCurPartyLevel], a + pop hl + ld b, h + ld c, l + ld hl, $1f + add hl, bc + ld [hl], a + ld hl, $24 + add hl, bc + ld d, h + ld e, l + ld hl, $a + add hl, bc + push bc + ld b, $1 + call CalcMonStats + pop bc + ld a, [wPokemonWithdrawDepositParameter] + and a + jr nz, Functiondcb2 + ld hl, $20 + add hl, bc + xor a + ld [hl], a + ld hl, $22 + add hl, bc + ld d, h + ld e, l + ld a, [wCurPartySpecies] + cp $fd + jr z, .asm_dca4 + inc hl + inc hl + ld a, [hli] + ld [de], a + ld a, [hl] + inc de + ld [de], a + jr Functiondcb2 + +.asm_dca4 + xor a + ld [de], a + inc de + ld [de], a + jr Functiondcb2 + +.asm_dcaa + ld a, [sBoxCount] + dec a + ld b, a + call Functiondcbc +Functiondcb2: ; dcb2 (3:5cb2) + call CloseSRAM + and a + ret + +Functiondcb7: ; dcb7 (3:5cb7) + call CloseSRAM + scf + ret + +Functiondcbc: ; dcbc (3:5cbc) + ld a, b + ld hl, sBoxMon1Species + ld bc, BOXMON_STRUCT_LENGTH + call AddNTimes + ld b, h + ld c, l + ld hl, $17 + add hl, bc + push hl + push bc + ld de, wTempMonPP + ld bc, $4 + call CopyBytes + pop bc + ld hl, $2 + add hl, bc + push hl + ld de, wTempMonMoves + ld bc, $4 + call CopyBytes + pop hl + pop de + ld a, [wMenuCursorY] + push af + ld a, [wMonType] + push af + ld b, $0 +.asm_dcf2 + ld a, [hli] + and a + jr z, .asm_dd1e + ld [wTempMonMoves], a + ld a, $2 + ld [wMonType], a + ld a, b + ld [wMenuCursorY], a + push bc + push hl + push de + farcall GetMaxPPOfMove ; same bank + pop de + pop hl + ld a, [wd151] + ld b, a + ld a, [de] + and $c0 + add b + ld [de], a + pop bc + inc de + inc b + ld a, b + cp $4 + jr c, .asm_dcf2 +.asm_dd1e + pop af + ld [wMonType], a + pop af + ld [wMenuCursorY], a + ret + +RetrieveMonFromDayCareMan: + ld a, [wBreedMon1Species] + ld [wCurPartySpecies], a + ld de, SFX_TRANSACTION + call PlaySFX + call WaitSFX + call GetBreedMon1LevelGrowth + ld a, b + ld [wMovementBufferCount], a + ld a, e + ld [wCurPartyLevel], a + xor a + ld [wPokemonWithdrawDepositParameter], a + jp Functiondd6a + +RetrieveMonFromDayCareLady: + ld a, [wBreedMon2Species] + ld [wCurPartySpecies], a + ld de, SFX_TRANSACTION + call PlaySFX + call WaitSFX + call GetBreedMon2LevelGrowth + ld a, b + ld [wMovementBufferCount], a + ld a, e + ld [wCurPartyLevel], a + ld a, $1 + ld [wPokemonWithdrawDepositParameter], a + jp Functiondd6a ; super long jump + +Functiondd6a: ; dd6a (3:5d6a) + ld hl, wPokemonData + ld a, [hl] + cp $6 + jr nz, .asm_dd74 + scf ; We shouldn't be here if we've come this far. + ret + +.asm_dd74 + inc a + ld [hl], a + ld c, a + ld b, $0 + add hl, bc + ld a, [wPokemonWithdrawDepositParameter] + and a + ld a, [wBreedMon1Species] + ld de, wBreedMon1Nick + jr z, .asm_dd8c + ld a, [wBreedMon2Species] + ld de, wBreedMon2Nick +.asm_dd8c + ld [hli], a + ld [wCurSpecies], a + ld a, $ff + ld [hl], a + ld hl, wPartyMon1Nickname + ld a, [wPartyCount] + dec a + call SkipNames + push hl + ld h, d + ld l, e + pop de + call CopyBytes + push hl + ld hl, wPartyMonOT + ld a, [wPartyCount] + dec a + call SkipNames + ld d, h + ld e, l + pop hl + call CopyBytes + push hl + call Functionde20 + pop hl + ld bc, BOXMON_STRUCT_LENGTH + call CopyBytes + call GetBaseData + call Functionde20 + ld b, d + ld c, e + ld hl, $1f + add hl, bc + ld a, [wCurPartyLevel] + ld [hl], a + ld hl, $24 + add hl, bc + ld d, h + ld e, l + ld hl, $a + add hl, bc + push bc + ld b, $1 + call CalcMonStats + ld hl, wPartyMon1Moves + ld a, [wPokemonData] + dec a + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + ld d, h + ld e, l + ld a, $1 + ld [wCurHPAnim], a + predef FillMoves + ld a, [wPartyCount] + dec a + ld [wCurPartyMon], a + farcall Functionc6bc ; same bank + ld a, [wCurPartyLevel] + ld d, a + callfar CalcExpAtLevel + pop bc + ld hl, $8 + add hl, bc + ldh a, [hQuotient] + ld [hli], a + ldh a, [hPrintNum3] + ld [hli], a + ldh a, [hPrintNum4] + ld [hl], a + and a + ret + +Functionde20: ; de20 (3:5e20) + ld a, [wPartyCount] + dec a + ld hl, wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + ld d, h + ld e, l + ret + +DepositMonWithDayCareMan: + ld de, wBreedMon1Nick + call Functionde4a + xor a + ld [wPokemonWithdrawDepositParameter], a + jp RemoveMonFromPartyOrBox + +DepositMonWithDayCareLady: + ld de, wBreedMon2Nick + call Functionde4a + xor a + ld [wPokemonWithdrawDepositParameter], a + jp RemoveMonFromPartyOrBox + +Functionde4a: ; de4a (3:5e4a) + ld a, [wCurPartyMon] + ld hl, wPartyMonNicknames + call SkipNames + call CopyBytes + ld a, [wCurPartyMon] + ld hl, wPartyMon1OT + call SkipNames + call CopyBytes + ld a, [wCurPartyMon] + ld hl, wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + ld bc, BOXMON_STRUCT_LENGTH + jp CopyBytes + +SendMonIntoBox: ; de74 (3:5e74) + ld a, $1 + call OpenSRAM + ld de, sBoxCount + ld a, [de] + cp $14 + jp nc, Functiondf48 + inc a + ld [de], a + ld a, [wCurPartySpecies] + ld [wCurSpecies], a + ld c, a +.asm_de8b + inc de + ld a, [de] + ld b, a + ld a, c + ld c, b + ld [de], a + inc a + jr nz, .asm_de8b + call GetBaseData + call Functiondf4d + ld hl, wPlayerName + ld de, sBoxMonOT + ld bc, NAME_LENGTH + call CopyBytes + ld a, [wCurPartySpecies] + ld [wd151], a + call GetPokemonName + ld de, sBoxMonNicknames + ld hl, wStringBuffer1 + ld bc, NAME_LENGTH + call CopyBytes + ld hl, wEnemyMon + ld de, sBoxMon1Species + ld bc, $6 + call CopyBytes + ld hl, wGameData + ld a, [hli] + ld [de], a + inc de + ld a, [hl] + ld [de], a + inc de + push de + ld a, [wCurPartyLevel] + ld d, a + callfar CalcExpAtLevel + pop de + ldh a, [hQuotient] + ld [de], a + inc de + ldh a, [hPrintNum3] + ld [de], a + inc de + ldh a, [hPrintNum4] + ld [de], a + inc de + xor a + ld b, $a +.asm_deeb + ld [de], a + inc de + dec b + jr nz, .asm_deeb + ld hl, wEnemyMonMovesEnd + ld b, $6 +.asm_def5 + ld a, [hli] + ld [de], a + inc de + dec b + jr nz, .asm_def5 + ld a, $46 + ld [de], a + inc de + xor a + ld [de], a + inc de + ld [de], a + inc de + ld [de], a + inc de + ld a, [wCurPartyLevel] + ld [de], a + ld a, [wCurPartySpecies] + dec a + call SetSeenAndCaughtMon + ld a, [wCurPartySpecies] + cp $c9 + jr nz, .asm_df26 + ld hl, sBoxMon1DVs + predef GetUnownLetter + callfar UpdateUnownDex +.asm_df26 + ld hl, sBoxMon1Moves + ld de, wTempMonMoves + ld bc, $4 + call CopyBytes + ld hl, sBoxMon1PP + ld de, wTempMonPP + ld bc, $4 + call CopyBytes + ld b, $0 + call Functiondcbc + call CloseSRAM + scf + ret + +Functiondf48: ; df48 (3:5f48) + call CloseSRAM + and a + ret + +Functiondf4d: ; df4d (3:5f4d) + ld hl, sBoxMonOT + ld bc, NAME_LENGTH + call Functiondf65 + ld hl, sBoxMonNicknames + ld bc, NAME_LENGTH + call Functiondf65 + ld hl, sBoxMon1Species + ld bc, BOXMON_STRUCT_LENGTH +Functiondf65: ; df65 (3:5f65) + ld a, [sBoxCount] + cp $2 + ret c + push hl + call AddNTimes + dec hl + ld e, l + ld d, h + pop hl + ld a, [sBoxCount] + dec a + call AddNTimes + dec hl + push hl + ld a, [sBoxCount] + dec a + ld hl, $0 + call AddNTimes + ld c, l + ld b, h + pop hl +.asm_df89 + ld a, [hld] + ld [de], a + dec de + dec bc + ld a, c + or b + jr nz, .asm_df89 + ret + +GiveEgg: ; df92 (3:5f92) + ld a, [wCurPartySpecies] + push af + callfar GetPreEvolution + callfar GetPreEvolution + ld a, [wCurPartySpecies] + dec a + push af + call CheckCaughtMon + pop af + push bc + call CheckSeenMon + push bc + call TryAddMonToParty + pop bc + ld a, c + and a + jr nz, .asm_dfc9 + ld a, [wCurPartySpecies] + dec a + ld c, a + ld d, $0 + ld hl, wPokedexCaught + ld b, RESET_FLAG + predef SmallFarFlagAction +.asm_dfc9 + pop bc + ld a, c + and a + jr nz, .asm_dfdf + ld a, [wCurPartySpecies] + dec a + ld c, a + ld d, $0 + ld hl, wPokedexSeen + ld b, RESET_FLAG + predef SmallFarFlagAction +.asm_dfdf + pop af + ld [wCurPartySpecies], a + ld a, [wPokemonData] + dec a + ld bc, PARTYMON_STRUCT_LENGTH + ld hl, wPartyMon1Species + call AddNTimes + ld a, [wCurPartySpecies] + ld [hl], a + ld hl, wPokemonData + ld a, [hl] + ld b, $0 + ld c, a + add hl, bc + ld a, $fd + ld [hl], a + ld a, [wPokemonData] + dec a + ld hl, wPartyMon1Nickname + call SkipNames + ld de, String_Egg + call CopyName2 + ld a, [wPartyCount] + dec a + ld hl, wPartyMon1Happiness + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + ld a, [wDebugFlags] + bit 1, a + ld a, $1 + jr nz, .asm_e028 + ld a, [wBaseEggSteps] +.asm_e028 + ld [hl], a + ld a, [wPartyCount] + dec a + ld hl, wPartyMon1HP + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + xor a + ld [hli], a + ld [hl], a + and a + ret + +String_Egg: + db "EGG@" + +RemoveMonFromPartyOrBox: ; e03f (3:603f) + ld hl, wPartyCount + ld a, [wPokemonWithdrawDepositParameter] + and a + jr z, .asm_e050 + ld a, $1 + call OpenSRAM + ld hl, sBoxCount +.asm_e050 + ld a, [hl] + dec a + ld [hli], a + ld a, [wCurPartyMon] + ld c, a + ld b, $0 + add hl, bc + ld e, l + ld d, h + inc de +.asm_e05d + ld a, [de] + inc de + ld [hli], a + inc a + jr nz, .asm_e05d + ld hl, wPartyMon6StatsEnd + ld d, $5 + ld a, [wPokemonWithdrawDepositParameter] + and a + jr z, .asm_e073 + ld hl, sBoxMonOT + ld d, $13 +.asm_e073 + ld a, [wCurPartyMon] + call SkipNames + ld a, [wCurPartyMon] + cp d + jr nz, .asm_e084 + ld [hl], $ff + jp .asm_e0f6 + +.asm_e084 + ld d, h + ld e, l + ld bc, NAME_LENGTH + add hl, bc + ld bc, wPartyMonNicknames + ld a, [wPokemonWithdrawDepositParameter] + and a + jr z, .asm_e096 + ld bc, sBoxMonNicknames +.asm_e096 + call CopyDataUntil + ld hl, wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH + ld a, [wPokemonWithdrawDepositParameter] + and a + jr z, .asm_e0ab + ld hl, sBoxMon1Species + ld bc, BOXMON_STRUCT_LENGTH +.asm_e0ab + ld a, [wCurPartyMon] + call AddNTimes + ld d, h + ld e, l + ld a, [wPokemonWithdrawDepositParameter] + and a + jr z, .asm_e0c2 + ld bc, BOXMON_STRUCT_LENGTH + add hl, bc + ld bc, sBoxMonOT + jr .asm_e0c9 + +.asm_e0c2 + ld bc, PARTYMON_STRUCT_LENGTH + add hl, bc + ld bc, wPartyMonOT +.asm_e0c9 + call CopyDataUntil + ld hl, wPartyMonNicknames + ld a, [wPokemonWithdrawDepositParameter] + and a + jr z, .asm_e0d8 + ld hl, sBoxMonNicknames +.asm_e0d8 + ld bc, NAME_LENGTH + ld a, [wCurPartyMon] + call AddNTimes + ld d, h + ld e, l + ld bc, NAME_LENGTH + add hl, bc + ld bc, wPartyMonNicknamesEnd + ld a, [wPokemonWithdrawDepositParameter] + and a + jr z, .asm_e0f3 + ld bc, sBoxEnd +.asm_e0f3 + call CopyDataUntil +.asm_e0f6 + ld a, [wPokemonWithdrawDepositParameter] + and a + jp nz, CloseSRAM + ld a, [wLinkMode] + and a + ret nz + ld a, $0 + call OpenSRAM + ld hl, wPokemonData + ld a, [wCurPartyMon] + cp [hl] + jr z, .asm_e137 + ld hl, sPartyMail + ld bc, MAIL_STRUCT_LENGTH + call AddNTimes + push hl + add hl, bc + pop de + ld a, [wCurPartyMon] + ld b, a +.asm_e120 + push bc + push hl + ld bc, MAIL_STRUCT_LENGTH + call CopyBytes + pop hl + push hl + ld bc, MAIL_STRUCT_LENGTH + add hl, bc + pop de + pop bc + inc b + ld a, [wPartyCount] + cp b + jr nz, .asm_e120 +.asm_e137 + jp CloseSRAM + +ComputeNPCTrademonStats: + ld a, MON_LEVEL + call GetPartyParamLocation + ld a, [hl] + ld [MON_LEVEL], a ; wow + ld a, MON_SPECIES + call GetPartyParamLocation + ld a, [hl] + ld [wCurSpecies], a + call GetBaseData + ld a, MON_MAXHP + call GetPartyParamLocation + ld d, h + ld e, l + push de + ld a, MON_STAT_EXP - 1 + call GetPartyParamLocation + ld b, $1 + call CalcMonStats + pop de + ld a, MON_HP + call GetPartyParamLocation + ld a, [de] + inc de + ld [hli], a + ld a, [de] + ld [hl], a + ret + +CalcMonStats: ; e16d +; Calculates all 6 Stats of a Pkmn +; b: Take into account stat EXP if TRUE +; 'c' counts from 1-6 and points with 'BaseStats' to the base value +; hl is the path to the Stat EXP +; results in $ffb7 and $ffb8 are saved in [de] + + ld c, $0 +.loop + inc c + call CalcMonStatC + ldh a, [hMultiplicand + 1] + ld [de], a + inc de + ldh a, [hMultiplicand + 2] + ld [de], a + inc de + ld a, c + cp STAT_SDEF + jr nz, .loop + ret +; e17b + +CalcMonStatC: ; e181 +; 'c' is 1-6 and points to the BaseStat +; 1: HP +; 2: Attack +; 3: Defense +; 4: Speed +; 5: SpAtk +; 6: SpDef + push hl + push de + push bc + ld a, b + ld d, a + push hl + ld hl, wd121 + dec hl ; has to be decreased, because 'c' begins with 1 + ld b, $0 + add hl, bc + ld a, [hl] + ld e, a + pop hl + push hl + ld a, c + cp STAT_SDEF + jr nz, .not_spdef + dec hl + dec hl + +.not_spdef + sla c + ld a, d + and a + jr z, .no_stat_exp + add hl, bc +.sqrt_loop + xor a + ldh [hMultiplicand], a + ldh [hMultiplicand + 1], a + inc b + ld a, b + cp $ff + jr z, .no_stat_exp + ldh [hMultiplicand + 2], a + ldh [hMultiplier], a + call Multiply + ld a, [hld] + ld d, a + ldh a, [hProduct + 3] + sub d + ld a, [hli] + ld d, a + ldh a, [hProduct + 2] + sbc d + jr c, .sqrt_loop +.no_stat_exp + srl c + pop hl + push bc + ld bc, MON_DVS - MON_HP_EXP + 1 + add hl, bc + pop bc + ld a, c + cp STAT_ATK + jr z, .Attack + cp STAT_DEF + jr z, .Defense + cp STAT_SPD + jr z, .Speed + cp STAT_SATK + jr z, .Special + cp STAT_SDEF + jr z, .Special +; DV_HP = (DV_ATK & 1) << 3 + (DV_DEF & 1) << 2 + (DV_SPD & 1) << 1 + (DV_SPC & 1) + push bc + ld a, [hl] + swap a + and $1 + add a + add a + add a + ld b, a + ld a, [hli] + and $1 + add a + add a + add b + ld b, a + ld a, [hl] + swap a + and $1 + add a + add b + ld b, a + ld a, [hl] + and $1 + add b + pop bc + jr .GotDV + +.Attack: + ld a, [hl] + swap a + and $f + jr .GotDV + +.Defense: + ld a, [hl] + and $f + jr .GotDV + +.Speed: + inc hl + ld a, [hl] + swap a + and $f + jr .GotDV + +.Special: + inc hl + ld a, [hl] + and $f + +.GotDV: + ld d, 0 + add e + ld e, a + jr nc, .no_overflow_1 + inc d + +.no_overflow_1 + sla e + rl d + srl b + srl b + ld a, b + add e + jr nc, .no_overflow_2 + inc d + +.no_overflow_2 + ldh [hMultiplicand + 2], a + ld a, d + ldh [hMultiplicand + 1], a + xor a + ldh [hMultiplicand + 0], a + ld a, [wCurPartyLevel] + ldh [hMultiplier], a + call Multiply + ldh a, [hProduct + 1] + ldh [hDividend + 0], a + ldh a, [hProduct + 2] + ldh [hDividend + 1], a + ldh a, [hProduct + 3] + ldh [hDividend + 2], a + ld a, 100 + ldh [hDivisor], a + ld a, 3 + ld b, a + call Divide + ld a, c + cp STAT_HP + ld a, 5 + jr nz, .not_hp + ld a, [wCurPartyLevel] + ld b, a + ldh a, [hQuotient + 2] + add b + ldh [hMultiplicand + 2], a + jr nc, .no_overflow_3 + ldh a, [hQuotient + 1] + inc a + ldh [hMultiplicand + 1], a + +.no_overflow_3 + ld a, 10 + +.not_hp + ld b, a + ldh a, [hQuotient + 2] + add b + ldh [hMultiplicand + 2], a + jr nc, .no_overflow_4 + ldh a, [hQuotient + 1] + inc a + ldh [hMultiplicand + 1], a + +.no_overflow_4 + ldh a, [hQuotient + 1] + cp (1000 / $100) + 1 + jr nc, .max_stat + cp 1000 / $100 + jr c, .stat_value_okay + ldh a, [hQuotient + 2] + cp 1000 % $100 + jr c, .stat_value_okay + +.max_stat + ld a, 999 / $100 + ldh [hMultiplicand + 1], a + ld a, 999 % $100 + ldh [hMultiplicand + 2], a + +.stat_value_okay + pop bc + pop de + pop hl + ret + +GivePoke: ; Give a Pokemon from script + push de + push bc + xor a + ld [wMonType], a + call TryAddMonToParty + jr nc, .asm_e2c9 + ld hl, wPartyMon1Nickname + ld a, [wPokemonData] + dec a + ld [wCurPartyMon], a + call SkipNames + ld d, h + ld e, l + pop bc + ld a, b + ld b, $0 + push bc + push de + push af + ld a, [wCurItem] + and a + jr z, .asm_e2fa + ld a, [wCurPartyMon] + ld hl, wPartyMon1Item + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + ld a, [wCurItem] + ld [hl], a + jr .asm_e2fa + +.asm_e2c9 + ld a, [wCurPartySpecies] + ld [wTempEnemyMonSpecies], a + callfar LoadEnemyMon + call SendMonIntoBox + jp nc, Functione3af + ld a, BOXMON + ld [wMonType], a + xor a + ld [wCurPartyMon], a + ld de, wMonOrItemNameBuffer + pop bc + ld a, b + ld b, $1 + push bc + push de + push af + ld a, [wCurItem] + and a + jr z, .asm_e2fa + ld a, [wCurItem] + ld [sBoxMon1Item], a +.asm_e2fa + ld a, [wCurPartySpecies] + ld [wd151], a + ld [wTempEnemyMonSpecies], a + call GetPokemonName + ld hl, wStringBuffer1 + ld de, wMonOrItemNameBuffer + ld bc, MON_NAME_LENGTH + call CopyBytes + pop af + and a + jr z, .asm_e381 + pop de + pop bc + pop hl + push bc + push hl + ld a, [wScriptBank] + call GetFarHalfword + ld bc, MON_NAME_LENGTH + ld a, [wScriptBank] + call FarCopyBytes + pop hl + inc hl + inc hl + ld a, [wScriptBank] + call GetFarHalfword + pop bc + ld a, b + and a + push de + push bc + jr nz, .asm_e360 + push hl + ld a, [wCurPartyMon] + ld hl, wPartyMon1OT + call SkipNames + ld d, h + ld e, l + pop hl + ld a, [wScriptBank] + call FarCopyBytes + ld a, [wCurPartyMon] + ld hl, wPartyMon1ID + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + ld a, 01001 / $100 + ld [hli], a + ld [hl], 01001 % $100 + jr .asm_e38d + +.asm_e360 + ld a, BANK(sBoxMonOT) + call OpenSRAM + ld de, sBoxMonOT + ld bc, MON_NAME_LENGTH + ld a, [wScriptBank] + call FarCopyBytes + ld hl, sBoxMon1ID + call Random + ld [hli], a + call Random + ld [hl], a + call CloseSRAM + jr .asm_e38d + +.asm_e381 + callfar Functionc7cd0 + pop de + jr c, .asm_e38d + call InitNickname +.asm_e38d + pop bc + pop de + ld a, b + and a + ret z + ld hl, TextJump_WasSentToBillsPC + call PrintText + ld a, BANK(sBoxMonNicknames) + call OpenSRAM + ld hl, wMonOrItemNameBuffer + ld de, sBoxMonNicknames + ld bc, MON_NAME_LENGTH + call CopyBytes + call CloseSRAM + ld b, $1 + ret + +Functione3af: ; e3af (3:63af) + pop bc + pop de + ld b, $2 + ret + +TextJump_WasSentToBillsPC: + text_far Text_WasSentToBillsPC + db "@" + +InitNickname: ; e3b9 (3:63b9) + push de + call LoadStandardMenuHeader + call DisableSpriteUpdates + pop de + push de + ld b, $0 + farcall NamingScreen + pop hl + ld de, wStringBuffer1 + call InitName + ld a, $4 ; XXX could this be in bank 4 in pokered? + ld hl, ExitAllMenus + rst FarCall + ret diff --git a/engine/pokemon/search2.asm b/engine/pokemon/search2.asm new file mode 100644 index 00000000..c33d84ed --- /dev/null +++ b/engine/pokemon/search2.asm @@ -0,0 +1,134 @@ +_FindPartyMonAboveLevel: + ld hl, wPartyMon1Level + call FindAboveLevel + ret + +_FindPartyMonAtLeastThatHappy: + ld hl, wPartyMon1Happiness + call FindAtLeastThatHappy + ret + +_FindPartyMonThatSpecies: + ld hl, wPartyMon1Species + jp FindThatSpecies + +_FindPartyMonThatSpeciesYourTrainerID: + ld hl, wPartyMon1Species + call FindThatSpecies + ret z + ld a, c + ld hl, wPartyMon1ID + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + ld a, [wPlayerID] + cp [hl] + jr nz, .nope + inc hl + ld a, [wPlayerID + 1] + cp [hl] + jr nz, .nope + ld a, $1 + and a + ret + +.nope + xor a + ret + +FindAtLeastThatHappy: +; Sets the bits for the Pokemon that have a happiness greater than or equal to b. +; The lowest bits are used. Sets z if no Pokemon in your party is at least that happy. + ld c, $0 + ld a, [wPartyCount] + ld d, a +.loop + ld a, d + dec a + push hl + push bc + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + pop bc + ld a, b + cp [hl] + pop hl + jr z, .greater_equal + jr nc, .lower + +.greater_equal + ld a, c + or $1 + ld c, a + +.lower + sla c + dec d + jr nz, .loop + call RetroactivelyIgnoreEggs + ld a, c + and a + ret + +FindAboveLevel: + ld c, $0 + ld a, [wPartyCount] + ld d, a +.loop + ld a, d + dec a + push hl + push bc + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + pop bc + ld a, b + cp [hl] + pop hl + jr c, .greater + ld a, c + or $1 + ld c, a + +.greater + sla c + dec d + jr nz, .loop + call RetroactivelyIgnoreEggs + ld a, c + and a + ret + +FindThatSpecies: +; Find species b in your party. +; If you have no Pokemon, returns c = -1 and z. +; If that species is in your party, returns its location in c, and nz. +; Otherwise, returns z. + ld c, -1 + ld hl, wPartySpecies +.loop + ld a, [hli] + cp -1 + ret z + inc c + cp b + jr nz, .loop + ld a, $1 + and a + ret + +RetroactivelyIgnoreEggs: + ld e, %11111110 + ld hl, wPartySpecies +.loop + ld a, [hli] + cp -1 + ret z + cp EGG + jr nz, .skip_notegg + ld a, c + and e + ld c, a + +.skip_notegg + rlc e + jr .loop diff --git a/engine/sine.asm b/engine/sine.asm deleted file mode 100644 index e22d785a..00000000 --- a/engine/sine.asm +++ /dev/null @@ -1,40 +0,0 @@ -_Sine:: ; 8ac9 (2:4ac9) - ld a, e - and $3f - cp $20 - jr nc, .negative - call .GetSine - ld a, h - ret -.negative - and $1f - call .GetSine - ld a, h - xor $ff - inc a - ret - -.GetSine: ; 8adf (2:4adf) - ld e, a - ld a, d - ld d, $0 - ld hl, .SineWave - add hl, de - add hl, de - ld e, [hl] - inc hl - ld d, [hl] - ld hl, $0 -.loop - srl a - jr nc, .no_add - add hl, de -.no_add - sla e - rl d - and a - jr nz, .loop - ret - -.SineWave: - sine_table $100 diff --git a/engine/smallflag.asm b/engine/smallflag.asm new file mode 100644 index 00000000..f7d1406f --- /dev/null +++ b/engine/smallflag.asm @@ -0,0 +1,74 @@ +Functionc660: + nop + +SmallFarFlagAction: +; Perform action b on bit c in flag array hl. +; If checking a flag, check flag array d:hl unless d is 0. + +; For longer flag arrays, see FlagAction. + + push hl + push bc + +; Divide by 8 to get the byte we want. + push bc + srl c + srl c + srl c + ld b, 0 + add hl, bc + pop bc + +; Which bit we want from the byte + ld a, c + and 7 + ld c, a + +; Shift left until we can mask the bit + ld a, 1 + jr z, .shifted +.shift + add a + dec c + jr nz, .shift +.shifted + ld c, a + +; What are we doing to this flag? + dec b + jr z, .set ; 1 = SET_FLAG + dec b + jr z, .check ; 2 = CHECK_FLAG +; 0 = RESET_FLAG + +.reset + ld a, c + cpl + and [hl] + ld [hl], a + jr .done + +.set + ld a, [hl] + or c + ld [hl], a + jr .done + +.check + ld a, d + cp 0 + jr nz, .farcheck + + ld a, [hl] + and c + jr .done + +.farcheck + call GetFarByte + and c + +.done + pop bc + pop hl + ld c, a + ret diff --git a/engine/specials.asm b/engine/specials.asm deleted file mode 100755 index 80d32a02..00000000 --- a/engine/specials.asm +++ /dev/null @@ -1,572 +0,0 @@ -Special:: ; c22b - ld hl, SpecialsPointers ; $4239 - add hl, de - add hl, de - add hl, de - ld b, [hl] - inc hl - ld a, [hli] - ld h, [hl] - ld l, a - ld a, b - rst FarCall - ret - -; Special routines can be used with the "special" map script command. -; They often use wScriptVar for arguments and return values. - -add_special: MACRO -; Some ROM0 specials have a nonzero bank. -\1Special:: -IF _NARG == 1 - dba \1 -ELSE - dbw \2, \1 -ENDC -ENDM - -SpecialsPointers: - add_special WarpToSpawnPoint - -; Communications - add_special SetBitsForLinkTradeRequest - add_special WaitForLinkedFriend - add_special CheckLinkTimeout - add_special TryQuickSave - add_special CheckBothSelectedSameRoom - add_special FailedLinkToPast - add_special CloseLink - add_special WaitForOtherPlayerToExit - add_special SetBitsForBattleRequest - add_special SetBitsForTimeCapsuleRequest - add_special CheckTimeCapsuleCompatibility - add_special EnterTimeCapsule - add_special TradeCenter - add_special Colosseum - add_special TimeCapsule - add_special CableClubCheckWhichChris - add_special CheckMysteryGift - add_special GetMysteryGiftItem - add_special UnlockMysteryGift - -; Map events - add_special BugContestJudging - add_special CheckPartyFullAfterContest - add_special ContestDropOffMons - add_special ContestReturnMons - add_special GiveParkBalls - add_special CheckMagikarpLength - add_special MagikarpHouseSign - add_special HealParty - add_special PokemonCenterPC - add_special PlayersHousePC - add_special DayCareMan - add_special DayCareLady - add_special DayCareManOutside - add_special MoveDeletion - add_special BankOfMom - add_special MagnetTrain - add_special NameRival - add_special SetDayOfWeek - add_special OverworldTownMap - add_special UnownPrinter - add_special MapRadio - add_special UnownPuzzle - add_special SlotMachine - add_special CardFlip - add_special DummyNonfunctionalGameCornerGame - add_special ClearBGPalettesBufferScreen - add_special FadeOutPalettes - add_special FadeBlackQuickly - add_special FadeInPalettes - add_special FadeInQuickly - add_special ReloadSpritesNoPalettes, $02 - add_special ClearBGPalettes - add_special UpdateTimePals - add_special ClearTilemap - add_special UpdateSprites - add_special ReplacePlayerSprite - add_special GameCornerPrizeMonCheckDex - add_special UnusedSetSeenMon - add_special WaitSFX, $03 - add_special PlayMapMusic - add_special RestartMapMusic - add_special HealMachineAnim - add_special SurfStartStep - add_special FindPartyMonAboveLevel - add_special FindPartyMonAtLeastThatHappy - add_special FindPartyMonThatSpecies - add_special FindPartyMonThatSpeciesYourTrainerID - add_special UnusedCheckUnusedTwoDayTimer - add_special DayCareMon1 - add_special DayCareMon2 - add_special SelectRandomBugContestContestants - add_special ActivateFishingSwarm - add_special ToggleMaptileDecorations - add_special ToggleDecorationsVisibility - add_special GiveShuckle - add_special ReturnShuckle - add_special BillsGrandfather - add_special CheckPokerus - add_special DisplayCoinCaseBalance - add_special DisplayMoneyAndCoinBalance - add_special PlaceMoneyTopRight - add_special CheckForLuckyNumberWinners - add_special CheckLuckyNumberShowFlag - add_special ResetLuckyNumberShowFlag - add_special PrintTodaysLuckyNumber - add_special SelectApricornForKurt - add_special NameRater - add_special DisplayLinkRecord - add_special GetFirstPokemonHappiness - add_special CheckFirstMonIsEgg - add_special RandomUnseenWildMon - add_special RandomPhoneWildMon - add_special RandomPhoneMon - add_special LoadUsedSpritesGFX - add_special PlaySlowCry - add_special SnorlaxAwake - add_special YoungerHaircutBrother - add_special OlderHaircutBrother - add_special DaisysGrooming - add_special PlayCurMonCry - add_special ProfOaksPCBoot - add_special GameboyCheck - add_special TrainerHouse - add_special PhotoStudio - add_special InitRoamMons - add_special FadeOutMusic - add_special Diploma - add_special PrintDiploma - add_special InitialSetDSTFlag - add_special InitialClearDSTFlag - add_special MrChrono - add_special SpecialNone - -SpecialNone: ; c389 - ret - -GameCornerPrizeMonCheckDex: ; c38a - ld a, [wScriptVar] - dec a - call CheckCaughtMon - ret nz - ld a, [wScriptVar] - dec a - call SetSeenAndCaughtMon - call FadeToMenu - ld a, [wScriptVar] - ld [wd151], a - farcall NewPokedexEntry - call ExitAllMenus - ret - -UnusedSetSeenMon: ; c3ac - ld a, [wScriptVar] - dec a - call SetSeenMon - ret - -FindPartyMonAboveLevel: ; c3b4 - ld a, [wScriptVar] - ld b, a - farcall PartySearch_MaximumLevel ; same bank - jr z, asm_c3f2 - jr asm_c3ec - -FindPartyMonAtLeastThatHappy: ; c3c2 - ld a, [wScriptVar] - ld b, a - farcall PartySearch_MinimumHappiness ; same bank - jr z, asm_c3f2 - jr asm_c3ec - -FindPartyMonThatSpecies: ; c3d0 - ld a, [wScriptVar] - ld b, a - farcall PartySearch_SameSpecies ; same bank - jr z, asm_c3f2 - jr asm_c3ec - -FindPartyMonThatSpeciesYourTrainerID: ; c3de - ld a, [wScriptVar] - ld b, a - farcall PartySearch_SameSpeciesAndYourID ; same bank - jr z, asm_c3f2 - jr asm_c3ec - -asm_c3ec - ld a, $1 - ld [wScriptVar], a - ret - -asm_c3f2 - xor a - ld [wScriptVar], a - ret - -NameRival: ; c3f7 - ld b, $2 - ld de, wRivalName - farcall NamingScreen_ - ld hl, wRivalName - ld de, .DefaultName - call InitName - ret - -.DefaultName: -IF DEF(GOLD) - db "SILVER@" -ENDC - -IF DEF(SILVER) - db "GOLD@" -ENDC - -NameRater: - farcall _NameRater - ret - -OverworldTownMap: ; c41a (3:441a) - call FadeToMenu - farcall Function9188a - call ExitAllMenus - ret - -UnownPrinter: ; c427 (3:4427) - call FadeToMenu - farcall Function16e3a - call ExitAllMenus - ret - -DisplayLinkRecord: ; c434 (3:4434) - call FadeToMenu - farcall Function3f55d - call ExitAllMenus - ret - -PlayersHousePC: ; c441 (3:4441) - xor a - ld [wScriptVar], a - farcall Function159b0 - ld a, c - ld [wScriptVar], a - ret - -CheckMysteryGift: ; c450 (3:4450) - ld a, $0 - call OpenSRAM - ld a, [$abe2] - and a - jr z, .asm_c45c - inc a -.asm_c45c - ld [wScriptVar], a - call CloseSRAM - ret - -GetMysteryGiftItem: ; c463 (3:4463) - ld a, $0 - call OpenSRAM - ld a, [$abe2] - ld [wCurItem], a - ld a, $1 - ld [wItemQuantityChangeBuffer], a - ld hl, wNumItems - call ReceiveItem - jr nc, .asm_c497 - xor a - ld [$abe2], a - call CloseSRAM - ld a, [wCurItem] - ld [wd151], a - call GetItemName - ld hl, ReceivedMysteryGiftText ; $449f - call PrintText - ld a, $1 - ld [wScriptVar], a - ret - -.asm_c497 - call CloseSRAM - xor a - ld [wScriptVar], a - ret - -ReceivedMysteryGiftText: - text_far ReceivedMysteryGiftText_ - db "@" - -BugContestJudging: ; c4a4 (3:44a4) - farcall _BugContestJudging - ld a, b - ld [wScriptVar], a - ret - -MapRadio: ; c4af (3:44af) - ld a, [wScriptVar] - ld e, a - farcall Function919c1 - ret - -UnownPuzzle: ; c4ba (3:44ba) - call FadeToMenu - farcall Functione199d - ld a, [wFieldMoveSucceeded] - ld [wScriptVar], a - call ExitAllMenus - ret - -SlotMachine: ; c4cd (3:44cd) - call Functionc508 - ret c - ld a, BANK(Function92c36) - ld hl, Function92c36 - call Functionc4f4 - ret - -CardFlip: ; c4da (3:44da) - call Functionc508 - ret c - ld a, BANK(Functione0909) - ld hl, Functione0909 - call Functionc4f4 - ret - -DummyNonfunctionalGameCornerGame: ; c4e7 (3:44e7) - call Functionc508 - ret c - ld a, BANK(Functione2668) - ld hl, Functione2668 - call Functionc4f4 - ret - -Functionc4f4: ; c4f4 (3:44f4) - call FarQueueScript - call FadeToMenu - ld hl, wQueuedScriptBank - ld a, [hli] - push af - ld a, [hli] - ld h, [hl] - ld l, a - pop af - rst FarCall - call ExitAllMenus - ret - -Functionc508: ; c508 (3:4508) - ld hl, wCoins - ld a, [hli] - or [hl] - jr z, .asm_c51e - ld a, COIN_CASE - ld [wCurItem], a - ld hl, wNumItems - call CheckItem - jr nc, .asm_c523 - and a - ret - -.asm_c51e - ld hl, .NoCoinsText - jr .asm_c526 - -.asm_c523 - ld hl, .NoCoinCaseText -.asm_c526 - call PrintText - scf - ret - -.NoCoinsText: - text_far NoCoinsText_ - db "@" - -.NoCoinCaseText: - text_far NoCoinCaseText_ - db "@" - -ClearBGPalettesBufferScreen: ; c535 (3:4535) - call ClearBGPalettes - call BufferScreen - ret - -Functionc53c: ; c53c (3:453c) - jr c, .asm_c543 - xor a - ld [wScriptVar], a - ret - -.asm_c543 - ld a, $1 - ld [wScriptVar], a - ret - -UnusedCheckUnusedTwoDayTimer: ; c549 (3:4549) - farcall Function118f8 - ld a, [wUnusedTwoDayTimer] - ld [wScriptVar], a - ret - -ActivateFishingSwarm: ; c556 (3:4556) - ld a, [wScriptVar] - ld [wFishingSwarmFlag], a - jr .asm_c566 - -.asm_c55e - ld a, d - ld [wDunsparceMapGroup], a - ld a, e - ld [wDunsparceMapNumber], a -.asm_c566 - SetFlag ENGINE_SPECIAL_WILDDATA - ret - -Functionc56c: - CheckFlagHL ENGINE_SPECIAL_WILDDATA - jr z, .asm_c578 - xor a - ld [wScriptVar], a - ret - -.asm_c578 - ld a, $1 - ld [wScriptVar], a - xor a - ld [wFishingSwarmFlag], a - ld [wDunsparceMapGroup], a - ld [wDunsparceMapNumber], a - ret - -CheckPokerus: ; c588 (3:4588) - farcall Functionc7a40 - jp Functionc53c - -ResetLuckyNumberShowFlag: ; c591 (3:4591) - farcall Function11917 - ClearFlag ENGINE_LUCKY_NUMBER_SHOW - farcall LoadOrRegenerateLuckyIDNumber - ret - -CheckLuckyNumberShowFlag: ; c5a3 (3:45a3) - farcall Function1192e - jp Functionc53c - -CountUnown: ; c5ac (3:45ac) - ld hl, wUnownDex - ld b, $0 -.asm_c5b1 - ld a, [hli] - and a - ret z - inc b - ld a, b - cp $1a - jr c, .asm_c5b1 - ret - -SelectApricornForKurt: ; c5bb (3:45bb) - farcall Function24b8d - ld a, c - ld [wScriptVar], a - and a - ret z - ld [wCurItem], a - ld a, $1 - ld [wItemQuantityChangeBuffer], a - ld hl, wNumItems - call TossItem - ret - -SnorlaxAwake: ; c5d6 (3:45d6) - ld a, [wChannelsEnd] - cp $40 - jr nz, .asm_c5fb - ld a, [wXCoord] - ld b, a - ld a, [wYCoord] - ld c, a - ld hl, .ProximityCoords -.asm_c5e8 - ld a, [hli] - cp $ff - jr z, .asm_c5fb - cp b - jr nz, .asm_c5f8 - ld a, [hli] - cp c - jr nz, .asm_c5e8 - ld a, $1 - jr .asm_c5fc - -.asm_c5f8 - inc hl - jr .asm_c5e8 - -.asm_c5fb - xor a -.asm_c5fc - ld [wScriptVar], a - ret - -.ProximityCoords: - ; x, y - db 33, 8 ; left - db 34, 10 ; below - db 35, 10 ; below - db 36, 8 ; right - db 36, 9 ; right - db -1 - -PlayCurMonCry: ; c60b (3:460b) - ld a, [wCurPartySpecies] - jp PlayMonCry - -GameboyCheck: ; c611 (3:4611) - ldh a, [hCGB] - and a - jr nz, .asm_c622 - ldh a, [hSGB] - and a - jr nz, .asm_c61e - xor a - jr .asm_c624 - -.asm_c61e - ld a, $1 - jr .asm_c624 - -.asm_c622 - ld a, $2 -.asm_c624 - ld [wScriptVar], a - ret - -FadeOutMusic: ; c628 (3:4628) - ld a, $0 - ld [wMusicFadeID], a - ld a, $0 - ld [wMusicFadeID + 1], a - ld a, $2 - ld [wMusicFade], a - ret - -Diploma: ; c638 (3:4638) - call FadeToMenu - farcall Functione0002 - call ExitAllMenus - ret - -PrintDiploma: ; c645 (3:4645) - call FadeToMenu - farcall Function84684 - call ExitAllMenus - ret - -TrainerHouse: ; c652 (3:4652) - ld a, $0 - call OpenSRAM - ld a, [$abfd] - ld [wScriptVar], a - jp CloseSRAM diff --git a/engine/tilesets/map_palettes.asm b/engine/tilesets/map_palettes.asm new file mode 100644 index 00000000..0c45cf57 --- /dev/null +++ b/engine/tilesets/map_palettes.asm @@ -0,0 +1,110 @@ +_SwapTextboxPalettes:: + ld hl, wTilemap + ld de, wAttrmap + ld b, SCREEN_HEIGHT +.loop + ld c, SCREEN_WIDTH +.innerloop + ld a, [hli] + push hl + srl a + jr c, .UpperNybble + ld hl, wTilesetPalettes + add [hl] + ld l, a + ld a, [wTilesetPalettes + 1] + adc 0 + ld h, a + ld a, [hl] + and $f + bit 3, a + jr z, .next + jr .asm_8038 + +.UpperNybble: + ld hl, wTilesetPalettes + add [hl] + ld l, a + ld a, [wTilesetPalettes + 1] + adc 0 + ld h, a + ld a, [hl] + swap a + and $f + bit 3, a + jr z, .next + +.asm_8038 + ld a, [wMapGroup] + dec a + ld hl, Unknown85d7 + add l + ld l, a + jr nc, .asm_8044 + inc h +.asm_8044 + ld a, [hl] + +.next + pop hl + ld [de], a + inc de + dec c + jr nz, .innerloop + dec b + jr nz, .loop + ret + +_ScrollBGMapPalettes:: + ld hl, wBGMapBuffer + ld de, wBGMapPalBuffer +.loop + ld a, [hli] + push hl + srl a + jr c, .UpperNybble + +; .LowerNybble + ld hl, wTilesetPalettes + add [hl] + ld l, a + ld a, [wTilesetPalettes + 1] + adc 0 + ld h, a + ld a, [hl] + and $f + bit 3, a + jr z, .next + jr .asm_8083 + +.UpperNybble: + ld hl, wTilesetPalettes + add [hl] + ld l, a + ld a, [wTilesetPalettes + 1] + adc 0 + ld h, a + ld a, [hl] + swap a + and $f + bit 3, a + jr z, .next + +.asm_8083 + ld a, [wMapGroup] + dec a + ld hl, Unknown85d7 + add l + ld l, a + jr nc, .asm_808f + inc h +.asm_808f + ld a, [hl] + +.next + pop hl + ld [de], a + inc de + dec c + jr nz, .loop + ret diff --git a/engine/variables.asm b/engine/variables.asm deleted file mode 100755 index 7e6906ee..00000000 --- a/engine/variables.asm +++ /dev/null @@ -1,119 +0,0 @@ -GetVarAction_:: - ld a, c - cp NUM_VARS - jr c, .valid - xor a -.valid - ld c, a - ld b, 0 - ld hl, .VarActionTable - add hl, bc - add hl, bc - add hl, bc - ld e, [hl] - inc hl - ld d, [hl] - inc hl - ld b, [hl] - ld a, b - and RETVAR_EXECUTE - jr nz, .call - ld a, b - and RETVAR_ADDR_DE - ret nz - ld a, [de] - jr .loadstringbuffer2 - -.call - call _de_ - ret - -.loadstringbuffer2 - ld de, wStringBuffer2 - ld [de], a - ret - -.VarActionTable: - dwb wStringBuffer2, RETVAR_STRBUF2 - dwb wPartyCount, RETVAR_STRBUF2 - dwb .BattleResult, RETVAR_EXECUTE - dwb wBattleType, RETVAR_ADDR_DE - dwb wTimeOfDay, RETVAR_STRBUF2 - dwb .CountCaughtMons, RETVAR_EXECUTE - dwb .CountSeenMons, RETVAR_EXECUTE - dwb .CountBadges, RETVAR_EXECUTE - dwb wPlayerState, RETVAR_ADDR_DE - dwb .PlayerFacing, RETVAR_EXECUTE - dwb hHours, RETVAR_STRBUF2 - dwb .DayOfWeek, RETVAR_EXECUTE - dwb wMapGroup, RETVAR_STRBUF2 - dwb wMapNumber, RETVAR_STRBUF2 - dwb .UnownCaught, RETVAR_EXECUTE - dwb wPermission, RETVAR_STRBUF2 - dwb .BoxFreeSpace, RETVAR_EXECUTE - dwb wBugContestMinsRemaining, RETVAR_STRBUF2 - dwb wXCoord, RETVAR_STRBUF2 - dwb wYCoord, RETVAR_STRBUF2 - dwb wSpecialPhoneCallID, RETVAR_STRBUF2 - dwb 0, 0 - -.CountCaughtMons: ; 41cf -; Caught mons. - ld hl, wPokedexCaught - ld b, $20 - call CountSetBits - ld a, [wd151] - jp .loadstringbuffer2 - -.CountSeenMons: ; 41dd -; Seen mons. - ld hl, wPokedexSeen - ld b, $20 - call CountSetBits - ld a, [wd151] - jp .loadstringbuffer2 - -.CountBadges: ; 41eb -; Number of owned badges. - ld hl, wBadges - ld b, 2 - call CountSetBits - ld a, [wd151] - jp .loadstringbuffer2 - -.PlayerFacing: ; 41f9 -; The direction the player is facing. - ld a, [wPlayerDirection] - and $c - rrca - rrca - jp .loadstringbuffer2 - -.DayOfWeek: ; 4203 -; The day of the week. - call GetWeekday - jp .loadstringbuffer2 - -.UnownCaught: ; 4209 -; Number of unique Unown caught. - call CountUnown ; gold: c5ac | silver: c5aa - ld a, b - jp .loadstringbuffer2 - -.BoxFreeSpace: ; 4210 -; Remaining slots in the current box. - ld a, BANK(sBoxCount) - call OpenSRAM - ld hl, sBoxCount - ld a, MONS_PER_BOX - sub [hl] - ld b, a - call CloseSRAM - ld a, b - jp .loadstringbuffer2 - -.BattleResult: ; 4223 - ld a, [wBattleResult] - and $7f - jp .loadstringbuffer2 -; 422b diff --git a/gfx/tileset_palette_maps.asm b/gfx/tileset_palette_maps.asm new file mode 100644 index 00000000..e814fbae --- /dev/null +++ b/gfx/tileset_palette_maps.asm @@ -0,0 +1,6 @@ +INCLUDE "gfx/tilesets/palette_maps.asm" + +Unknown85d7: + rept 26 ; NUM_MAP_GROUPS + db PAL_BG_ROOF + endr diff --git a/items/item_effects.asm b/items/item_effects.asm deleted file mode 100755 index 274b8468..00000000 --- a/items/item_effects.asm +++ /dev/null @@ -1,2897 +0,0 @@ -_DoItemEffect:: ; e7a6 (3:67a6) - ld a, [wCurItem] - ld [wd151], a - call GetItemName - call CopyName1 - ld a, $1 - ld [wFieldMoveSucceeded], a - ld a, [wCurItem] - dec a - ld hl, .ItemEffects - rst JumpTable - ret - -.ItemEffects - dw MasterBall - dw UltraBall - dw Brightpowder - dw GreatBall - dw PokeBall - dw TownMap - dw Bicycle - dw MoonStone - dw Antidote - dw BurnHeal - dw IceHeal - dw Awakening - dw ParlyzHeal - dw FullRestore - dw MaxPotion - dw HyperPotion - dw SuperPotion - dw Potion - dw EscapeRope - dw Repel - dw MaxElixer - dw FireStone - dw Thunderstone - dw WaterStone - dw Item19 - dw HPUp - dw Protein - dw Iron - dw Carbos - dw LuckyPunch - dw Calcium - dw RareCandy - dw XAccuracy - dw LeafStone - dw MetalPowder - dw Nugget - dw PokeDoll - dw FullHeal - dw Revive - dw MaxRevive - dw GuardSpec - dw SuperRepel - dw MaxRepel - dw DireHit - dw Item2D - dw FreshWater - dw SodaPop - dw Lemonade - dw XAttack - dw Item32 - dw XDefend - dw XSpeed - dw XSpecial - dw CoinCase - dw ItemfinderEffect - dw PokeFlute - dw ExpShare - dw OldRod - dw GoodRod - dw SilverLeaf - dw SuperRod - dw PPUp - dw Ether - dw MaxEther - dw Elixer - dw RedScale - dw Secretpotion - dw SSTicket - dw MysteryEgg - dw Item47 - dw SilverWing - dw MoomooMilk - dw QuickClaw - dw Psncureberry - dw GoldLeaf - dw SoftSand - dw SharpBeak - dw Przcureberry - dw BurntBerry - dw IceBerry - dw PoisonBarb - dw KingsRock - dw BitterBerry - dw MintBerry - dw RedApricorn - dw Tinymushroom - dw BigMushroom - dw Silverpowder - dw BluApricorn - dw Item5A - dw AmuletCoin - dw YlwApricorn - dw GrnApricorn - dw CleanseTag - dw MysticWater - dw Twistedspoon - dw WhtApricorn - dw Blackbelt - dw BlkApricorn - dw Item64 - dw PnkApricorn - dw Blackglasses - dw Slowpoketail - dw PinkBow - dw Stick - dw SmokeBall - dw Nevermeltice - dw Magnet - dw Miracleberry - dw Pearl - dw BigPearl - dw Everstone - dw SpellTag - dw Ragecandybar - dw Item73 - dw Item74 - dw MiracleSeed - dw ThickClub - dw FocusBand - dw Item78 - dw Energypowder - dw EnergyRoot - dw HealPowder - dw RevivalHerb - dw HardStone - dw LuckyEgg - dw CardKey - dw MachinePart - dw Item81 - dw LostItem - dw Stardust - dw StarPiece - dw BasementKey - dw Pass - dw Item87 - dw Item88 - dw Item89 - dw Charcoal - dw BerryJuice - dw ScopeLens - dw Item8D - dw Item8E - dw MetalCoat - dw DragonFang - dw Item91 - dw Leftovers - dw Item93 - dw Item94 - dw Item95 - dw Mysteryberry - dw DragonScale - dw BerserkGene - dw Item99 - dw Item9A - dw Item9B - dw SacredAsh - dw HeavyBall - dw FlowerMail - dw LevelBall - dw LureBall - dw FastBall - dw ItemA2 - dw LightBall - dw FriendBall - dw MoonBall - dw LoveBall - dw NormalBox - dw GorgeousBox - dw SunStone - dw PolkadotBow - dw ItemAB - dw UpGrade - dw Berry - dw GoldBerry - dw Squirtbottle - dw ItemB0 - dw ParkBall - dw RainbowWing - dw ItemB3 - -FastBall: ; e926 -FriendBall: ; e926 -GreatBall: ; e926 -HeavyBall: ; e926 -LevelBall: ; e926 -LoveBall: ; e926 -LureBall: ; e926 -MasterBall: ; e926 -MoonBall: ; e926 -ParkBall: ; e926 -PokeBall: ; e926 -UltraBall: ; e926 - ld a, [wBattleMode] - dec a - jp nz, Functionf7e7 - ld a, [wPartyCount] - cp PARTY_LENGTH - jr nz, .room_in_party_or_pc - ld a, $1 - call OpenSRAM - ld a, [$ad6c] - cp $14 - call CloseSRAM - jp z, FailToUseBall -.room_in_party_or_pc - xor a - ld [wWildMon], a - ld a, [wCurItem] - cp PARK_BALL - call nz, ReturnToBattle_UseBall - ld hl, wOptions - res NO_TEXT_SCROLL, [hl] - ld hl, Text_UsedItem ; $7884 - call PrintText - ld a, [wd114] - ld b, a - ld a, [wBattleType] - cp BATTLETYPE_TUTORIAL - jp z, .catch_without_fail - ld a, [wCurItem] - cp MASTER_BALL - jp z, .catch_without_fail - ld a, [wCurItem] - ld c, a - ld hl, BallMultiplierFunctionTable ; $6c73 -.get_multiplier_loop - ld a, [hli] - cp $ff - jr z, .skip_or_return_from_ball_fn - cp c - jr z, .call_ball_function - inc hl - inc hl - jr .get_multiplier_loop - -.call_ball_function - ld a, [hli] - ld h, [hl] - ld l, a - ld de, .skip_or_return_from_ball_fn - push de - jp hl - -.skip_or_return_from_ball_fn - ld a, [wCurItem] - cp LEVEL_BALL - ld a, b - jp z, .skip_hp_calc - ld a, b - ldh [hPrintNum4], a - ld hl, wEnemyMonHP - ld b, [hl] - inc hl - ld c, [hl] - inc hl - ld d, [hl] - inc hl - ld e, [hl] -; (3 * MaxHP - 2 * CurHP) / (3 * MaxHP) * level - sla c - rl b - ld h, d - ld l, e - add hl, de - add hl, de - ld d, h - ld e, l -; This routine is buggy. The intention is to get de, the Max HP score, -; to be an 8-bit number. To do this, we divide both bc and de by 4. -; It only does this division once, and doesn't check to make sure that -; e is not zero. In addition to passing along a divide-by-zero error, -; this could also cause an unusually small denominator to be passed, -; sending the resulting catch rate through the floor. - ld a, d - and a - jr z, .okay_hp_div - srl d - rr e - srl d - rr e - srl b - rr c - srl b - rr c - ld a, c - and a - jr nz, .okay_hp_div - ld c, $1 -.okay_hp_div - ld b, e - - push bc - ld a, b - sub c - ldh [hMultiplier], a - xor a - ldh [hDividend + 0], a - ldh [hMultiplicand + 0], a - ldh [hMultiplicand + 1], a - call Multiply - pop bc - - ld a, b - ldh [hDivisor], a - ld b, $4 - call Divide - - ldh a, [hQuotient + 2] - and a - jr nz, .statuscheck - ld a, 1 -.statuscheck -; This routine is buggy. It was intended that SLP and FRZ provide a higher -; catch rate than BRN/PSN/PAR, which in turn provide a higher catch rate than -; no status effect at all. But instead, it makes BRN/PSN/PAR provide no -; benefit. -; Uncomment the line below to fix this. - ld b, a - ld a, [wEnemyMonStatus] - and 1 << FRZ | SLP - ld c, $a - jr nz, .add_status - ; ld a, [wEnemyMonStatus] - and a - ld c, $5 - jr nz, .add_status - ld c, $0 -.add_status - ld a, b - add c - jr nc, .max_catch_rate - ld a, $ff -.max_catch_rate - ld d, a - push de - - ; BUG: farcall overwrites a, - ; and GetItemHeldEffect takes b anyway. - - ; This is probably the reason - ; the HELD_CATCH_CHANCE effect - ; is never used. - - ; Uncomment the line below to fix. - - ld a, [wBattleMonItem] - ; ld b, a - farcall GetItemHeldEffect ; d:7e9b - ld a, b - cp HELD_CATCH_CHANCE - pop de - ld a, d - jr nz, .skip_hp_calc - add c - jr nc, .skip_hp_calc - ld a, $ff -.skip_hp_calc - ld b, a - ld [wCurHPAnimMaxHP], a - call Random - cp b - ld a, $0 - jr z, .catch_without_fail - jr nc, .asm_ea23 -.catch_without_fail - ld a, [wEnemyMonSpecies] -.asm_ea23 - ld [wWildMon], a - ld c, 20 - call DelayFrames - ld a, [wCurItem] - cp POKE_BALL + 1 - jr c, .asm_ea34 - ld a, $5 -.asm_ea34 - ld [wcb67], a - ld de, ANIM_THROW_POKE_BALL - ld a, e - ld [wcf3e], a - ld a, d - ld [wcf3f], a - xor a - ldh [hBattleTurn], a - ld [wBuffer2], a - ld [wcf46], a - predef PlayBattleAnim - ld a, [wWildMon] - and a - jr nz, .caught - ld a, [wBuffer2] - cp $1 - ld hl, Text_ThePokemonBrokeFree ; $6e09 - jp z, .break_free - cp $2 - ld hl, Text_AppearedToBeCaught ; $6e0e - jp z, .break_free - cp $3 - ld hl, Text_AarghAlmostHadIt ; $6e13 - jp z, .break_free - cp $4 - ld hl, Text_ShootItWasSoCloseToo ; $6e18 - jp z, .break_free -.caught - ld hl, wEnemyMonStatus - ld a, [hli] - push af - inc hl - ld a, [hli] - push af - ld a, [hl] - push af - push hl - ld hl, wEnemyMonItem - ld a, [hl] - push af - push hl - ld hl, wEnemySubStatus5 - ld a, [hl] - push af - set SUBSTATUS_TRANSFORMED, [hl] - bit SUBSTATUS_TRANSFORMED, a - jr nz, .ditto - jr .not_ditto - -.ditto - ld a, DITTO - ld [wTempEnemyMonSpecies], a - jr .load_data - -.not_ditto - set SUBSTATUS_TRANSFORMED, [hl] - ld hl, wcbd0 - ld a, [wEnemyMonDVs] - ld [hli], a - ld a, [wEnemyMonMovesEnd + 1] - ld [hl], a -.load_data - ld a, [wTempEnemyMonSpecies] - ld [wCurPartySpecies], a - ld a, [wEnemyMonLevel] - ld [wCurPartyLevel], a - farcall LoadEnemyMon - pop af - ld [wEnemySubStatus5], a - pop hl - pop af - ld [hl], a - pop hl - pop af - ld [hld], a - pop af - ld [hld], a - dec hl - pop af - ld [hl], a - ld hl, wEnemySubStatus5 - bit SUBSTATUS_TRANSFORMED, [hl] - jr nz, .transformed - ld hl, wWildMonMoves - ld de, wEnemyMonMoves - ld bc, NUM_MOVES - call CopyBytes - ld hl, wWildMonPP - ld de, wEnemyMonPP - ld bc, NUM_MOVES - call CopyBytes -.transformed - ld a, [wEnemyMonSpecies] - ld [wWildMon], a - ld [wCurPartySpecies], a - ld [wd151], a - ld a, [wBattleType] - cp BATTLETYPE_TUTORIAL - jp z, .finish_tutorial - ld hl, Text_GotchaMonWasCaught ; $6e1d - call PrintText - call ClearSprites - ld a, [wd151] - dec a - call CheckCaughtMon - ld a, c - push af - ld a, [wd151] - dec a - call SetSeenAndCaughtMon - pop af - and a - jr nz, .skip_dex - call CheckReceivedDex - jr z, .skip_dex - ld hl, Text_MonNewlyAddedToPokedex ; $6e44 - call PrintText - call ClearSprites - ld a, [wEnemyMonSpecies] - ld [wd151], a - predef NewPokedexEntry -.skip_dex - ld a, [wBattleType] - cp BATTLETYPE_CONTEST - jp z, .catch_bug_contest_mon - ld a, [wPartyCount] - cp PARTY_LENGTH - jr z, .send_mon_to_pc - xor a - ld [wMonType], a - call ClearSprites - predef TryAddMonToParty - ld a, [wCurItem] - cp FRIEND_BALL - jr nz, .skip_party_mon_friend_ball - ld a, [wPartyCount] - dec a - ld hl, wPartyMon1Happiness - ld bc, PARTYMON_STRUCT_LENGTH - call AddNTimes - ld a, FRIEND_BALL_HAPPINESS - ld [hl], a -.skip_party_mon_friend_ball - ld hl, Text_AskNicknameNewlyCaughtMon ; $6e49 - call PrintText - ld a, [wCurPartySpecies] - ld [wd151], a - call GetPokemonName - call YesNoBox - jp c, .end_ball_function - ld a, [wPartyCount] - dec a - ld [wCurPartyMon], a - ld hl, wPartyMon1Nickname - ld bc, MON_NAME_LENGTH - call AddNTimes - ld d, h - ld e, l - push de - xor a - ld [wMonType], a - ld b, $0 - farcall NamingScreen - call RotateThreePalettesRight - call Functiond9e - pop hl - ld de, wStringBuffer1 - call InitName - jp .end_ball_function - -.send_mon_to_pc - call ClearSprites - predef SendMonIntoBox - ld a, BANK(sBoxCount) - call OpenSRAM - ld a, [sBoxCount] - cp MONS_PER_BOX - jr nz, .not_full_yet - ld hl, wBattleResult - set 7, [hl] -.not_full_yet - ld a, [wCurItem] - cp FRIEND_BALL - jr nz, .skip_box_mon_friend_ball - ld a, FRIEND_BALL_HAPPINESS - ld [sBoxMon1Happiness], a -.skip_box_mon_friend_ball - call CloseSRAM - ld hl, Text_AskNicknameNewlyCaughtMon ; $6e49 - call PrintText - ld a, [wCurPartySpecies] - ld [wd151], a - call GetPokemonName - call YesNoBox - jr c, .init_name_in_sram - xor a - ld [wCurPartyMon], a - ld a, $2 - ld [wMonType], a - ld de, wMonOrItemNameBuffer - ld b, $0 - farcall NamingScreen - ld a, $1 - call OpenSRAM - ld hl, wMonOrItemNameBuffer - ld de, sBoxMonNicknames - ld bc, MON_NAME_LENGTH - call CopyBytes - ld hl, sBoxMonNicknames - ld de, wStringBuffer1 - call InitName - call CloseSRAM -.init_name_in_sram - ld a, $1 - call OpenSRAM - ld hl, sBoxMonNicknames - ld de, wMonOrItemNameBuffer - ld bc, MON_NAME_LENGTH - call CopyBytes - call CloseSRAM - ld hl, Text_SentToBillsPC ; $6e3f - call PrintText - call RotateThreePalettesRight - call Functiond9e - jr .end_ball_function - -.catch_bug_contest_mon - farcall BugContest_SetCaughtContestMon ; same bank - jr .end_ball_function - -.finish_tutorial - ld hl, Text_GotchaMonWasCaught ; $6e1d -.break_free - call PrintText - call ClearSprites -.end_ball_function - ld a, [wBattleType] - cp BATTLETYPE_TUTORIAL - ret z - cp BATTLETYPE_DEBUG - ret z - cp BATTLETYPE_CONTEST - jr z, .used_park_ball - ld a, [wWildMon] - and a - jr z, .toss - call ClearBGPalettes - call ClearTilemap -.toss - ld hl, wNumItems - inc a - ld [wItemQuantityChangeBuffer], a - jp TossItem - -.used_park_ball - ld hl, wParkBallsRemaining - dec [hl] - ret - -BallMultiplierFunctionTable: ; ec73 - dbw ULTRA_BALL, UltraBallMultiplier - dbw GREAT_BALL, GreatBallMultiplier - dbw SAFARI_BALL, SafariBallMultiplier ; Safari Ball, leftover from RBY - dbw HEAVY_BALL, HeavyBallMultiplier - dbw LEVEL_BALL, LevelBallMultiplier - dbw LURE_BALL, LureBallMultiplier - dbw FAST_BALL, FastBallMultiplier - dbw MOON_BALL, MoonBallMultiplier - dbw LOVE_BALL, LoveBallMultiplier - dbw PARK_BALL, ParkBallMultiplier - db $ff - -UltraBallMultiplier: - sla b - ret nc - ld b, $ff - ret - -GreatBallMultiplier: -SafariBallMultiplier: -ParkBallMultiplier: - ld a, b - srl a - add b - ld b, a - ret nc - ld b, $ff - ret - -HeavyBallMultiplier: - ld a, [wEnemyMon] - dec a - ld hl, PokedexDataPointerTable - ld e, a - ld d, $0 - add hl, de - add hl, de - rlca - rlca - and $3 - add BANK("Pokedex Entries 001-064") - ld d, a - ld a, BANK(PokedexDataPointerTable) - call GetFarHalfword -.loop - ld a, d - call GetFarByte - inc hl - cp "@" - jr nz, .loop - ld a, d - push bc - inc hl - inc hl - call GetFarHalfword - srl h - rr l - ld b, h - ld c, l - srl b - rr c - srl b - rr c - srl b - rr c - srl b - rr c - call .sub_bc - srl b - rr c - call .sub_bc - ld a, h - pop bc - jr .compare - -.sub_bc - push bc - ld a, b - cpl - ld b, a - ld a, c - cpl - ld c, a - inc bc - add hl, bc - pop bc - ret - -.compare - ld c, a - cp 1024 >> 8 ; 102.4 kg - jr c, .lightmon - ld hl, .WeightsTable ; $6d18 -.lookup - ld a, c - cp [hl] - jr c, .heavymon - inc hl - inc hl - jr .lookup - -.heavymon - inc hl - ld a, b - add [hl] - ld b, a - ret nc - ld b, $ff - ret - -.lightmon - ld a, b - sub 20 - ld b, a - ret nc - ld b, $1 - ret - -.WeightsTable -; weight factor, boost - db 2048 >> 8, 0 - db 3072 >> 8, 20 - db 4096 >> 8, 30 - db 65280 >> 8, 40 - -LureBallMultiplier: - ld a, [wBattleType] - cp BATTLETYPE_FISH - ret nz - ld a, b - add a - jr c, .asm_ed2d - add b - jr nc, .asm_ed2f -.asm_ed2d - ld a, $ff -.asm_ed2f - ld b, a - ret - -MoonBallMultiplier: -; This function is buggy. -; Intent: multiply catch rate by 4 if mon evolves with moon stone -; Reality: no boost - push bc - ld a, [wTempEnemyMonSpecies] - dec a - ld c, a - ld b, $0 - ld hl, EvosAttacksPointers ; $67bd - add hl, bc - add hl, bc - ld a, BANK(EvosAttacksPointers) ; $10 - call GetFarHalfword - pop bc - push bc - ld a, BANK(EvosAttacksPointers) ; $10 - call GetFarByte - cp EVOLVE_ITEM - pop bc - ret nz - inc hl - inc hl - inc hl -; Moon Stone's constant from Pokémon Red is used. -; No Pokémon evolve with Burn Heal, -; so Moon Balls always have a catch rate of 1×. - push bc - ld a, BANK(EvosAttacksPointers) ; $10 - call GetFarByte - cp MOON_STONE_RED ; BURN_HEAL - pop bc - ret nz - sla b - jr c, .max - sla b - jr nc, .done -.max - ld b, $ff -.done - ret - -LoveBallMultiplier: -; This function is buggy. -; Intent: multiply catch rate by 8 if mons are of same species, different sex -; Reality: multiply catch rate by 8 if mons are of same species, same sex - ld a, [wTempEnemyMonSpecies] - ld c, a - ld a, [wd0ee] - cp c - ret nz - push bc - ld a, [wd0ee] - ld [wCurPartySpecies], a - xor a - ld [wMonType], a - ld a, [wCurBattleMon] - ld [wCurPartyMon], a - farcall GetGender ; 14:52f1 - jr c, .asm_edba - ld d, $0 - jr nz, .asm_ed8d - inc d -.asm_ed8d - push de - ld a, [wTempEnemyMonSpecies] - ld [wCurPartySpecies], a - ld a, $4 - ld [wMonType], a - farcall GetGender ; 14:52f1 - jr c, .asm_edb9 - ld d, $0 - jr nz, .asm_eda6 - inc d -.asm_eda6 - ld a, d - pop de - cp d - pop bc - ret nz ; for the intended effect, this should be “ret z” - sla b - jr c, .asm_edb6 - sla b - jr c, .asm_edb6 - sla b - ret nc -.asm_edb6 - ld b, $ff - ret - -.asm_edb9 - pop de -.asm_edba - pop bc - ret - -FastBallMultiplier: -; This function is buggy. -; Intent: multiply catch rate by 4 if enemy mon is in one of the three -; FleeMons tables. -; Reality: multiply catch rate by 4 if enemy mon is one of the first three in -; the first FleeMons table. - ld a, [wTempEnemyMonSpecies] - ld c, a - ld hl, FleeMons - ld d, $3 -.asm_edc5 - ld a, BANK(FleeMons) - call GetFarByte - inc hl - cp $ff - jr z, .asm_eddc - cp c - jr nz, .asm_eddc ; for the intended effect, this should be “jr nz, .loop” - sla b - jr c, .asm_edd9 - sla b - ret nc -.asm_edd9 - ld b, $ff - ret - -.asm_eddc - dec d - jr nz, .asm_edc5 - ret - -LevelBallMultiplier: -; multiply catch rate by 8 if player mon level / 4 > enemy mon level -; multiply catch rate by 4 if player mon level / 2 > enemy mon level -; multiply catch rate by 2 if player mon level > enemy mon level - ld a, [wBattleMonLevel] - ld c, a - ld a, [wEnemyMonLevel] - cp c - ret nc - sla b - jr c, .asm_edfc - srl c - cp c - ret nc - sla b - jr c, .asm_edfc - srl c - cp c - ret nc - sla b - ret nc -.asm_edfc - ld b, $ff - ret - -; These two texts were carried over from gen 1. -; They are not used in gen 2, and are dummied out. - -Text_ThisMonCantBeCaught: - text_far Text_ThisMonCantBeCaught_ - db "@" - -Text_YouMissedThePokemon: - text_far Text_YouMissedThePokemon_ - db "@" - -Text_ThePokemonBrokeFree: - text_far Text_ThePokemonBrokeFree_ - db "@" - -Text_AppearedToBeCaught: - text_far Text_AppearedToBeCaught_ - db "@" - -Text_AarghAlmostHadIt: - text_far Text_AarghAlmostHadIt_ - db "@" - -Text_ShootItWasSoCloseToo: - text_far Text_ShootItWasSoCloseToo_ - db "@" - -Text_GotchaMonWasCaught: - text_far Text_GotchaMonWasCaught_ - text_asm - call WaitSFX - push bc - ld de, MUSIC_NONE - call PlayMusic - call DelayFrame - ld de, MUSIC_CAPTURE - call PlayMusic - pop bc - ld hl, Text_CaughtMonWaitbutton - ret - -Text_CaughtMonWaitbutton: - text_far Text_Promptbutton_2 - db "@" - -Text_SentToBillsPC: - text_far Text_SentToBillsPC_ - db "@" - -Text_MonNewlyAddedToPokedex: - text_far Text_MonNewlyAddedToPokedex_ - db "@" - -Text_AskNicknameNewlyCaughtMon: - text_far Text_AskNicknameNewlyCaughtMon_ - db "@" - -ReturnToBattle_UseBall: ; ee4e (3:6e4e) - farcall ReturnToBattle_UseBall_ ; 9:7307 - ret - -TownMap: ; ee55 (3:6e55) - farcall TownMap_ ; 24:5a4f - ret - -Bicycle: ; ee5c - farcall BicycleFunction ; same bank - ret - -FireStone: ; ee63 -LeafStone: ; ee63 -MoonStone: ; ee63 -SunStone: ; ee63 -Thunderstone: ; ee63 -WaterStone: ; ee63 - ld b, PARTYMENUACTION_EVO_STONE - call Functionf24f - jp c, .cancel - ld a, MON_ITEM - call GetPartyParamLocation - ld a, [hl] - cp EVERSTONE - jr z, .failed - ld a, $1 - ld [wd0d2], a - farcall EvolvePokemon ; 10:61db - ld a, [wd154] - and a - jr z, .failed - jp Functionf7dc - -.failed - call Functionf839 -.cancel - xor a - ld [wFieldMoveSucceeded], a - ret - - -Calcium: ; ee91 -Carbos: ; ee91 -HPUp: ; ee91 -Iron: ; ee91 -Protein: ; ee91 - ld b, PARTYMENUACTION_HEALING_ITEM - call Functionf24f - jp c, Functioneef3 - call Functionef49 - call Functionef2d - ld a, MON_STAT_EXP - call GetPartyParamLocation - add hl, bc - ld a, [hl] - cp 100 - jr nc, Functioneed7 - add 10 - ld [hl], a - call Functioneee0 - call Functionef2d - ld hl, StatStrings - add hl, bc - ld a, [hli] - ld h, [hl] - ld l, a - ld de, wStringBuffer2 - ld bc, ITEM_NAME_LENGTH - call CopyBytes - call Functionf7c7 - ld hl, Text_StatRoseFromVitamin ; $6efa - call PrintText - ld c, HAPPINESS_USEDITEM - farcall ChangeHappiness - jp Functionf7dc - -Functioneed7: - ld hl, Text_WontHaveAnyEffect ; $7866 - call PrintText - jp ClearPalettes - -Functioneee0: ; eee0 (3:6ee0) - ld a, MON_MAXHP - call GetPartyParamLocation - ld d, h - ld e, l - ld a, MON_STAT_EXP - 1 - call GetPartyParamLocation - ld b, $1 - predef_jump CalcMonStats - -Functioneef3: ; eef3 (3:6ef3) - xor a - ld [wFieldMoveSucceeded], a - jp ClearPalettes - -Text_StatRoseFromVitamin: - text_far Text_StatRoseFromVitamin_ - db "@" - -StatStrings: - dw .health - dw .attack - dw .defense - dw .speed - dw .special - -.health db "HEALTH@" -.attack db "ATTACK@" -.defense db "DEFENSE@" -.speed db "SPEED@" -.special db "SPECIAL@" - -Functionef2d: ; ef2d (3:6f2d) - ld a, [wCurItem] - ld hl, StatOffsets -.asm_ef33 - cp [hl] - inc hl - jr z, .asm_ef3a - inc hl - jr .asm_ef33 - -.asm_ef3a - ld a, [hl] - ld c, a - ld b, $0 - ret - -StatOffsets: - db HP_UP, MON_HP_EXP - MON_STAT_EXP - db PROTEIN, MON_ATK_EXP - MON_STAT_EXP - db IRON, MON_DEF_EXP - MON_STAT_EXP - db CARBOS, MON_SPD_EXP - MON_STAT_EXP - db CALCIUM, MON_SPC_EXP - MON_STAT_EXP - -Functionef49: ; ef49 (3:6f49) - ld a, [wCurPartySpecies] - ld [wCurSpecies], a - ld [wd151], a - ld a, $1f - call GetPartyParamLocation - ld a, [hl] - ld [wCurPartyLevel], a - call GetBaseData - ld a, [wCurPartyMon] - ld hl, wPartyMonNicknames - call GetNick - ret - -RareCandy: ; ef68 (3:6f68) - ld b, PARTYMENUACTION_HEALING_ITEM - call Functionf24f - jp c, Functioneef3 - call Functionef49 - ld a, MON_LEVEL - call GetPartyParamLocation - ld a, [hl] - cp MAX_LEVEL - jp nc, Functioneed7 - inc a - ld [hl], a - ld [wCurPartyLevel], a - push de - ld d, a - farcall CalcExpAtLevel - pop de - ld a, $8 - call GetPartyParamLocation - ldh a, [hQuotient] - ld [hli], a - ldh a, [hPrintNum3] - ld [hli], a - ldh a, [hPrintNum4] - ld [hl], a - ld a, $24 - call GetPartyParamLocation - ld a, [hli] - ld b, a - ld c, [hl] - push bc - call Functioneee0 - ld a, $25 - call GetPartyParamLocation - pop bc - ld a, [hld] - sub c - ld c, a - ld a, [hl] - sbc b - ld b, a - dec hl - ld a, [hl] - add c - ld [hld], a - ld a, [hl] - adc b - ld [hl], a - ld c, $1 - farcall ChangeHappiness - ld a, PARTYMENUTEXT_LEVEL_UP - call Functionf2a0 - xor a - ld [wMonType], a - predef CopyMonToTempMon - hlcoord 9, 0 - ld b, 10 - ld c, 9 - call Textbox - hlcoord 11, 1 - ld bc, $4 - predef PrintTempMonStats - call WaitPressAorB_BlinkCursor - xor a - ld [wMonType], a - ld a, [wCurPartySpecies] - ld [wd151], a - predef LearnLevelMoves - xor a - ld [wd0d2], a - farcall EvolvePokemon - jp Functionf7dc - -HealPowder: ; f003 (3:7003) - ld b, $1 - call Functionf24f - jp c, Functionf2f4 - call Functionf030 - cp $0 - jr nz, .asm_f01f - ld c, $f - farcall ChangeHappiness - call Functionf81d - ld a, $0 -.asm_f01f - jp Functionf0f4 - -Antidote: ; f022 -Awakening: ; f022 -BurnHeal: ; f022 -BurntBerry: ; f022 -FullHeal: ; f022 -IceBerry: ; f022 -IceHeal: ; f022 -MintBerry: ; f022 -Miracleberry: ; f022 -ParlyzHeal: ; f022 -Przcureberry: ; f022 -Psncureberry: ; f022 - ld b, $1 - call Functionf24f - jp c, Functionf2f4 -Functionf02a: - call Functionf030 - jp Functionf0f4 - -Functionf030: ; f030 (3:7030) - call Functionf363 - ld a, $1 - ret z - call Functionf0ae - ld a, MON_STATUS - call GetPartyParamLocation - ld a, [hl] - and c - jr nz, .asm_f04a - call Functionf05f - ld a, $1 - ret nc - ld b, PARTYMENUTEXT_HEAL_CONFUSION -.asm_f04a - xor a - ld [hl], a - ld a, b - ld [wPartyMenuActionText], a - call Functionf086 - call Functionf7c7 - call Functionf2cf - call Functionf7dc - ld a, $0 - ret - -Functionf05f: ; f05f (3:705f) - call Functionf2fc - jr nc, .asm_f072 - ld a, [wPlayerSubStatus3] - bit SUBSTATUS_CONFUSED, a - jr z, .asm_f072 - ld a, c - cp $ff - jr nz, .asm_f072 - scf - ret - -.asm_f072 - and a - ret - -RestoreBattlemonHP: - call Functionf2fc - ret nc - ld a, $22 - call GetPartyParamLocation - ld a, [hli] - ld [wBattleMonHP], a - ld a, [hld] - ld [wBattleMonHP + 1], a - ret - -Functionf086: ; f086 (3:7086) - call Functionf2fc - ret nc - xor a - ld [wBattleMonStatus], a - ld hl, wPlayerSubStatus5 - res 0, [hl] - ld hl, wPlayerSubStatus1 - res 0, [hl] - call Functionf0ae - ld a, c - cp $ff - jr nz, .asm_f0a5 - ld hl, wPlayerSubStatus3 - res 7, [hl] -.asm_f0a5 - push bc - farcall CalcPlayerStats ; d:66f6 - pop bc - ret - -Functionf0ae: ; f0ae (3:70ae) - push hl - ld a, [wCurItem] - ld hl, .healingactions ; $70c7 - ld bc, $3 -.asm_f0b8 - cp [hl] - jr z, .asm_f0be - add hl, bc - jr .asm_f0b8 - -.asm_f0be - inc hl - ld b, [hl] - inc hl - ld a, [hl] - ld c, a - cp $ff - pop hl - ret - -.healingactions - db ANTIDOTE, PARTYMENUTEXT_HEAL_PSN, 1 << PSN - db BURN_HEAL, PARTYMENUTEXT_HEAL_BRN, 1 << BRN - db ICE_HEAL, PARTYMENUTEXT_HEAL_FRZ, 1 << FRZ - db AWAKENING, PARTYMENUTEXT_HEAL_SLP, SLP - db PARLYZ_HEAL, PARTYMENUTEXT_HEAL_PAR, 1 << PAR - db FULL_HEAL, PARTYMENUTEXT_HEAL_ALL, %11111111 - db FULL_RESTORE, PARTYMENUTEXT_HEAL_ALL, %11111111 - db HEAL_POWDER, PARTYMENUTEXT_HEAL_ALL, %11111111 - db PSNCUREBERRY, PARTYMENUTEXT_HEAL_PSN, 1 << PSN - db PRZCUREBERRY, PARTYMENUTEXT_HEAL_PAR, 1 << PAR - db BURNT_BERRY, PARTYMENUTEXT_HEAL_FRZ, 1 << FRZ - db ICE_BERRY, PARTYMENUTEXT_HEAL_BRN, 1 << BRN - db MINT_BERRY, PARTYMENUTEXT_HEAL_SLP, SLP - db MIRACLEBERRY, PARTYMENUTEXT_HEAL_ALL, %11111111 - db -1, 0, 0 - -Functionf0f4: ; f0f4 (3:70f4) - ld hl, .Jumptable ; $70f9 - rst JumpTable - ret - -.Jumptable: - dw Functionf2f8 - dw Functionf2ef - dw Functionf2f4 - -RevivalHerb: ; f0ff - ld b, $1 - call Functionf24f - jp c, Functionf2f4 - call Functionf12c - cp $0 - jr nz, .asm_f11b - ld c, $11 - farcall ChangeHappiness - call Functionf81d - ld a, $0 -.asm_f11b - jp Functionf0f4 - -MaxRevive: ; f11e -Revive: ; f11e - ld b, $1 - call Functionf24f - jp c, Functionf2f4 - call Functionf12c - jp Functionf0f4 - -Functionf12c: ; f12c (3:712c) - call Functionf363 - ld a, $1 - ret nz - ld a, [wBattleMode] - and a - jr z, .asm_f15a - ld a, [wCurPartyMon] - ld c, a - ld d, $0 - ld hl, wcbda - ld b, CHECK_FLAG - predef SmallFarFlagAction - ld a, c - and a - jr z, .asm_f15a - ld a, [wCurPartyMon] - ld c, a - ld hl, wcb42 - ld b, SET_FLAG - predef SmallFarFlagAction -.asm_f15a - xor a - ld [wLowHealthAlarm], a - ld a, [wCurItem] - cp REVIVE - jr z, .asm_f16a - call Functionf319 - jr .asm_f16d - -.asm_f16a - call Functionf310 -.asm_f16d - call Functionf231 - ld a, $f7 - ld [wPartyMenuActionText], a - call Functionf2cf - call Functionf7dc - ld a, $0 - ret - -FullRestore: ; f17e (3:717e) - ld b, $1 - call Functionf24f - jp c, Functionf2f4 - call Functionf363 - jp z, Functionf2ef - call CalculateCurHPAnimRemainingHP - jr c, .asm_f194 - jp Functionf02a - -.asm_f194 - call Functionf19a - jp Functionf0f4 - -Functionf19a: ; f19a (3:719a) - xor a - ld [wLowHealthAlarm], a - call Functionf319 - ld a, $20 - call GetPartyParamLocation - xor a - ld [hli], a - ld [hl], a - call Functionf086 - call RestoreBattlemonHP - call Functionf231 - ld a, $f5 - ld [wPartyMenuActionText], a - call Functionf2cf - call Functionf7dc - ld a, $0 - ret - -BitterBerry: ; f1c0 - ld hl, wPlayerSubStatus3 - bit 7, [hl] - ld a, $1 - jr z, .asm_f1d9 - res 7, [hl] - xor a - ldh [hBattleTurn], a - call Functionf7d0 - ld hl, ConfusedNoMoreText - call StdBattleTextbox - ld a, $0 -.asm_f1d9 - jp Functionf0f4 - -Berry: ; f1dc -BerryJuice: ; f1dc -FreshWater: ; f1dc -GoldBerry: ; f1dc -HyperPotion: ; f1dc -Lemonade: ; f1dc -MaxPotion: ; f1dc -MoomooMilk: ; f1dc -Potion: ; f1dc -Ragecandybar: ; f1dc -SodaPop: ; f1dc -SuperPotion: ; f1dc - call Functionf1ff - jp Functionf0f4 - -Energypowder: ; f1e2 (3:71e2) - ld c, $f - jr asm_f1e8 - -EnergyRoot: ; f1e6 (3:71e6) - ld c, $10 -asm_f1e8 - push bc - call Functionf1ff - pop bc - cp $0 - jr nz, .asm_f1fc - farcall ChangeHappiness - call Functionf81d - ld a, $0 -.asm_f1fc - jp Functionf0f4 - -Functionf1ff: ; f1ff (3:71ff) - ld b, PARTYMENUACTION_HEALING_ITEM - call Functionf24f - ld a, $2 - ret c - call Functionf363 - ld a, $1 - ret z - call CalculateCurHPAnimRemainingHP - ld a, $1 - ret nc - xor a - ld [wLowHealthAlarm], a - call Functionf3eb - call Functionf327 - call RestoreBattlemonHP - call Functionf231 - ld a, PARTYMENUTEXT_HEAL_HP - ld [wPartyMenuActionText], a - call Functionf2cf - call Functionf7dc - ld a, $0 - ret - -Functionf231: ; f231 (3:7231) - push de - ld de, $4 - call WaitPlaySFX - pop de - ld a, [wCurPartyMon] - hlcoord 11, 0 - ld bc, $28 - call AddNTimes - ld a, $2 - ld [wWhichHPBar], a - predef_jump AnimateHPBar - -Functionf24f: ; f24f (3:724f) - call Functionf261 - ret c - ld a, [wCurPartySpecies] - cp EGG - jr nz, .asm_f25f - call Functionf82f - scf - ret - -.asm_f25f - and a - ret - -Functionf261: ; f261 (3:7261) - ld a, b - ld [wPartyMenuActionText], a - push hl - push de - push bc - call ClearBGPalettes - call Functionf272 - pop bc - pop de - pop hl - ret - -Functionf272: ; f272 (3:7272) - farcall LoadPartyMenuGFX - farcall InitPartyMenuWithCancel - farcall InitPartyMenuGFX - farcall WritePartyMenuTilemap - farcall PrintPartyMenuText - call WaitBGMap - call SetPalettes - call DelayFrame - farcall PartyMenuSelect - ret - -Functionf2a0: ; f2a0 (3:72a0) - ld [wPartyMenuActionText], a - ld a, [wCurPartySpecies] - push af - ld a, [wCurPartyMon] - push af - push hl - push de - push bc - farcall WritePartyMenuTilemap - farcall PrintPartyMenuActionText - call WaitBGMap - call SetPalettes - call DelayFrame - pop bc - pop de - pop hl - pop af - ld [wCurPartyMon], a - pop af - ld [wCurPartySpecies], a - ret - -Functionf2cf: ; f2cf (3:72cf) - xor a - ldh [hBGMapMode], a - hlcoord 0, 0 - ld bc, SCREEN_HEIGHT * SCREEN_WIDTH - ld a, " " - call ByteFill - ld a, [wPartyMenuActionText] - call Functionf2a0 - ld a, $1 - ldh [hBGMapMode], a - ld c, 50 - call DelayFrames - jp WaitPressAorB_BlinkCursor - -Functionf2ef: ; f2ef (3:72ef) - call Functionf839 - jr Functionf2f8 - -Functionf2f4: ; f2f4 (3:72f4) - xor a - ld [wFieldMoveSucceeded], a -Functionf2f8: ; f2f8 (3:72f8) - call ClearPalettes - ret - -Functionf2fc: ; f2fc (3:72fc) - ld a, [wBattleMode] - and a - ret z - ld a, [wCurPartyMon] - push hl - ld hl, wCurBattleMon - cp [hl] - pop hl - jr nz, .asm_f30e - scf - ret - -.asm_f30e - xor a - ret - -Functionf310: ; f310 (3:7310) - call GetCurHPAnimMaxHP - srl d - rr e - jr asm_f31c - -Functionf319: ; f319 (3:7319) - call GetCurHPAnimMaxHP -asm_f31c - ld a, MON_HP - call GetPartyParamLocation - ld [hl], d - inc hl - ld [hl], e - jp CopyCurHPToAnimBufferNewHP - -Functionf327: ; f327 (3:7327) - ld a, $23 - call GetPartyParamLocation - ld a, [hl] - add e - ld [hld], a - ld a, [hl] - adc d - ld [hl], a - jr c, .asm_f34b - call CopyCurHPToAnimBufferNewHP - ld a, MON_HP + 1 - call GetPartyParamLocation - ld d, h - ld e, l - ld a, MON_MAXHP + 1 - call GetPartyParamLocation - ld a, [de] - sub [hl] - dec de - dec hl - ld a, [de] - sbc [hl] - jr c, .asm_f34e -.asm_f34b - call Functionf319 -.asm_f34e - ret - -Functionf34f: ; f34f (3:734f) - ld a, MON_HP + 1 - call GetPartyParamLocation - ld a, [hl] - sub e - ld [hld], a - ld a, [hl] - sbc d - ld [hl], a - jr nc, .asm_f35f - xor a - ld [hld], a - ld [hl], a -.asm_f35f - call CopyCurHPToAnimBufferNewHP - ret - -Functionf363: ; f363 (3:7363) - push de - call CopyMaxHPToAnimBufferMaxHP - call CopyCurHPToAnimBufferOldHP - call GetCurHPAnimOldHP - ld a, d - or e - pop de - ret - -CalculateCurHPAnimRemainingHP: ; f371 (3:7371) - call GetCurHPAnimOldHP - ld h, d - ld l, e - call GetCurHPAnimMaxHP - ld a, l - sub e - ld a, h - sbc d - ret - -CopyCurHPToAnimBufferNewHP: ; f37e (3:737e) - ld a, MON_HP - call GetPartyParamLocation - ld a, [hli] - ld [wCurHPAnimNewHP + 1], a - ld a, [hl] - ld [wCurHPAnimNewHP], a - ret - -SetCurHPAnimNewHP: - ld a, d - ld [wCurHPAnimNewHP + 1], a - ld a, e - ld [wCurHPAnimNewHP], a - ret - -GetCurHPAnimNewHP: - ld a, [wCurHPAnimNewHP + 1] - ld d, a - ld a, [wCurHPAnimNewHP] - ld e, a - ret - -CopyCurHPToAnimBufferOldHP: ; f39e (3:739e) - ld a, MON_HP - call GetPartyParamLocation - ld a, [hli] - ld [wCurHPAnimOldHP + 1], a - ld a, [hl] - ld [wCurHPAnimOldHP], a - ret - -GetCurHPAnimOldHP: ; f3ac (3:73ac) - ld a, [wCurHPAnimOldHP + 1] - ld d, a - ld a, [wCurHPAnimOldHP] - ld e, a - ret - -CopyMaxHPToAnimBufferMaxHP: ; f3b5 (3:73b5) - push hl - ld a, MON_MAXHP - call GetPartyParamLocation - ld a, [hli] - ld [wCurHPAnimMaxHP + 1], a - ld a, [hl] - ld [wCurHPAnimMaxHP], a - pop hl - ret - -GetCurHPAnimMaxHP: ; f3c5 (3:73c5) - ld a, [wCurHPAnimMaxHP + 1] - ld d, a - ld a, [wCurHPAnimMaxHP] - ld e, a - ret - -GetOneFifthMaxHP: ; f3ce (3:73ce) - push bc - ld a, MON_MAXHP - call GetPartyParamLocation - ld a, [hli] - ldh [hDividend + 0], a - ld a, [hl] - ldh [hDividend + 1], a - ld a, 5 - ldh [hDivisor], a - ld b, 2 - call Divide - ldh a, [hQuotient + 1] - ld d, a - ldh a, [hQuotient + 2] - ld e, a - pop bc - ret - -Functionf3eb: ; f3eb (3:73eb) - push hl - ld a, [wCurItem] - ld hl, HealingItemParameters - ld d, a -.asm_f3f3 - ld a, [hli] - cp -1 - jr z, .asm_f3ff - cp d - jr z, .asm_f400 - inc hl - inc hl - jr .asm_f3f3 - -.asm_f3ff - scf -.asm_f400 - ld e, [hl] - inc hl - ld d, [hl] - pop hl - ret - -HealingItemParameters: - dbw FRESH_WATER, 50 - dbw SODA_POP, 60 - dbw LEMONADE, 80 - dbw HYPER_POTION, 200 - dbw SUPER_POTION, 50 - dbw POTION, 20 - dbw MAX_POTION, 999 - dbw FULL_RESTORE, 999 - dbw MOOMOO_MILK, 100 - dbw BERRY, 10 - dbw GOLD_BERRY, 30 - dbw ENERGYPOWDER, 50 - dbw ENERGY_ROOT, 200 - dbw RAGECANDYBAR, 20 - dbw BERRY_JUICE, 20 - dbw -1, 0 - -Softboiled_MilkDrinkFunction: - ld a, [wPartyMenuCursor] - dec a - ld b, a - call Functionf46f - jr c, .asm_f469 - ld a, b - ld [wCurPartyMon], a - call Functionf363 - call GetOneFifthMaxHP - call Functionf34f - push bc - call Functionf231 - pop bc - call GetOneFifthMaxHP - ld a, c - ld [wCurPartyMon], a - call Functionf363 - call Functionf327 -.asm_f45d - call Functionf231 - ld a, PARTYMENUTEXT_HEAL_HP - call Functionf2a0 - call JoyWaitAorB -.asm_f469 - ld a, b - inc a - ld [wPartyMenuCursor], a - ret - -Functionf46f: ; f46f (3:746f) - push bc - ld a, $1 - ld [wPartyMenuActionText], a - call Functionf272 - pop bc - jr c, .asm_f494 - ld a, [wPartyMenuCursor] - dec a - ld c, a - ld a, b - cp c - jr z, .asm_f496 - ld a, c - ld [wCurPartyMon], a - call Functionf363 - jr z, .asm_f496 - call CalculateCurHPAnimRemainingHP - jr nc, .asm_f496 - xor a - ret - -.asm_f494 - scf - ret - -.asm_f496 - push bc - ld hl, Text_MilkDrinkCantBeUsed - call MenuTextboxBackup - pop bc - jr Functionf46f - -Text_MilkDrinkCantBeUsed: - text_far Text_MilkDrinkCantBeUsed_ - db "@" - -EscapeRope: ; f4a5 (3:74a5) - xor a - ld [wFieldMoveSucceeded], a - farcall EscapeRopeFunction ; same bank - ld a, [wFieldMoveSucceeded] - cp $1 - call z, Functionf7dc - ret - -SuperRepel: ; f4b8 (3:74b8) - ld b, 200 - jr asm_f4c2 - -MaxRepel: ; f4bc (3:74bc) - ld b, 250 - jr asm_f4c2 - -Repel: ; f4c0 (3:74c0) - ld b, 100 -asm_f4c2 - ld a, [wRepelSteps] - and a - ld hl, Text_RepelsEffectsStillLinger - jp nz, PrintText - ld a, b - ld [wRepelSteps], a - jp Functionf7d0 - -Text_RepelsEffectsStillLinger: - text_far Text_RepelUsedEarlierIsStillInEffect - db "@" - -XAccuracy: ; f4d8 (3:74d8) - ld hl, wPlayerSubStatus4 - bit SUBSTATUS_X_ACCURACY, [hl] - jp nz, Functionf811 - set SUBSTATUS_X_ACCURACY, [hl] - jp Functionf7d0 - -PokeDoll: ; f4e5 (3:74e5) - ld a, [wBattleMode] - dec a - jr nz, .asm_f4f6 - inc a - ld [wd11c], a - inc a - ld [wBattleResult], a - jp Functionf7d0 - -.asm_f4f6 - xor a - ld [wFieldMoveSucceeded], a - ret - -GuardSpec: ; f4fb (3:74fb) - ld hl, wPlayerSubStatus4 - bit SUBSTATUS_MIST, [hl] - jp nz, Functionf811 - set SUBSTATUS_MIST, [hl] - jp Functionf7d0 - -DireHit: ; f508 (3:7508) - ld hl, wPlayerSubStatus4 - bit SUBSTATUS_FOCUS_ENERGY, [hl] - jp nz, Functionf811 - set SUBSTATUS_FOCUS_ENERGY, [hl] - jp Functionf7d0 - -XAttack: ; f515 -XDefend: ; f515 -XSpecial: ; f515 -XSpeed: ; f515 - call Functionf7d0 - ld a, [wCurItem] - ld hl, .x_item_table -.asm_f51e - cp [hl] - jr z, .asm_f525 - inc hl - inc hl - jr .asm_f51e - -.asm_f525 - inc hl - ld b, [hl] - xor a - ldh [hBattleTurn], a - ld [wcb45], a - ld [wcbeb], a - farcall CheckIfStatCanBeRaised - call WaitSFX - farcall BattleCommand_StatUpMessage - farcall BattleCommand_StatUpFailText - ld a, [wCurBattleMon] - ld [wCurPartyMon], a - ld c, HAPPINESS_USEDXITEM - farcall ChangeHappiness - ret - -.x_item_table - db X_ATTACK, ATTACK - db X_DEFEND, DEFENSE - db X_SPEED, SPEED - db X_SPECIAL, SP_ATTACK - -PokeFlute: ; f55c (3:755c) - ld a, [wBattleMode] - and a - jr nz, .dummy -.dummy - - xor a - ld [wceed], a - - ld b, $ff ^ SLP - - ld hl, wPartyMon1Status - call .CureSleep - - ld a, [wBattleMode] - cp $1 - jr z, .skip_otrainer - ld hl, wOTPartyMon1Status - call .CureSleep -.skip_otrainer - - ld hl, wBattleMonStatus - ld a, [hl] - and b - ld [hl], a - ld hl, wEnemyMonStatus - ld a, [hl] - and b - ld [hl], a - - ld a, [wceed] - and a - ld hl, Text_NowThatsACatchyTune ; $75bc - jp z, PrintText - ld hl, Text_PlayedThePokeFlute ; $75c6 - call PrintText - - ld a, [wLowHealthAlarm] - and $80 - jr nz, .dummy2 -.dummy2 - ld hl, Text_AllSleepingMonWokeUp ; $75c1 - jp PrintText - -.CureSleep: ; f5a4 (3:75a4) - ld de, PARTYMON_STRUCT_LENGTH - ld c, PARTY_LENGTH - -.loop - ld a, [hl] - push af - and SLP - jr z, .not_asleep - ld a, 1 - ld [wceed], a -.not_asleep - pop af - and b - ld [hl], a - add hl, de - dec c - jr nz, .loop - ret - -Text_NowThatsACatchyTune: - text_far Text_NowThatsACatchyTune_ - db "@" - -Text_AllSleepingMonWokeUp: - text_far Text_AllSleepingMonWokeUp_ - db "@" - -Text_PlayedThePokeFlute: - text_far Text_PlayedThePokeFlute_ - text_asm - ld a, [wBattleMode] - and a - jr nz, .asm_f5dc - push de - ld de, SFX_POKEFLUTE - call WaitPlaySFX - call WaitSFX - pop de -.asm_f5dc - ld hl, .terminator - ret - -.terminator db "@" - -CoinCase: ; f5e1 (3:75e1) - ld hl, Text_CoinCase - jp MenuTextboxWaitButton - -Text_CoinCase: - text_far Text_CoinCase_ - db "@" - -OldRod: ; f5ec (3:75ec) - ld e, $0 - jr UseRod - -GoodRod: ; f5f0 (3:75f0) - ld e, $1 - jr UseRod - -SuperRod: ; f5f4 (3:75f4) - ld e, $2 - jr UseRod - -UseRod: - farcall FishingRodFunction ; same bank - ret - -ItemfinderEffect: ; f5ff (3:75ff) - farcall ItemFinder - ret - -Elixer: ; f606 -Ether: ; f606 -MaxElixer: ; f606 -MaxEther: ; f606 -Mysteryberry: ; f606 -PPUp: ; f606 (3:7606) - ld a, [wCurItem] - ld [wMovementBufferCount], a -.asm_f60c - ld b, $1 - call Functionf24f - jp c, Functionf727 -.asm_f614 - ld a, [wMovementBufferCount] - cp MAX_ELIXER - jp z, Functionf6f6 - cp ELIXER - jp z, Functionf6f6 - ld hl, Text_RaiseThePPOfWhichMove - ld a, [wMovementBufferCount] - cp PP_UP - jr z, .asm_f62e - ld hl, Text_RestoreThePPOfWhichMove -.asm_f62e - call PrintText - ld a, [wcfc7] - push af - xor a - ld [wcfc7], a - ld a, $2 - ld [wd11f], a - ld a, $f - ld hl, $62f3 - rst FarCall - pop bc - ld a, b - ld [wcfc7], a - jr nz, .asm_f60c - ld hl, wPartyMon1Moves - ld bc, $30 - call Functionf9aa - push hl - ld a, [hl] - ld [wd151], a - call GetMoveName - call CopyName1 - pop hl - ld a, [wceed] - cp PP_UP - jp nz, Functionf6ee - ld a, [hl] - cp $a6 - jr z, .asm_f676 - ld bc, $15 - add hl, bc - ld a, [hl] - cp $c0 - jr c, .asm_f67e -.asm_f676 - ld hl, Text_PPIsMaxedOut ; $7776 - call PrintText - jr .asm_f614 - -.asm_f67e - ld a, [hl] - add $40 - ld [hl], a - ld a, $1 - ld [wd151], a - call Functionf893 - call Functionf7c7 - ld hl, Text_PPsIncreased ; $777b - call PrintText -asm_f693 - call ClearPalettes - jp Functionf7dc - -asm_f699 - ld a, [wBattleMode] - and a - jr z, .asm_f6b3 - ld a, [wCurPartyMon] - ld b, a - ld a, [wCurBattleMon] - cp b - jr nz, .asm_f6b3 - ld a, [wPlayerSubStatus5] - bit SUBSTATUS_TRANSFORMED, a - jr nz, .asm_f6b3 - call Functionf6be -.asm_f6b3 - call Functionf7c7 - ld hl, Text_PPWasRestored - call PrintText - jr asm_f693 - -Functionf6be: ; f6be (3:76be) - ld a, [wCurPartyMon] - ld hl, wPartyMon1Moves - ld bc, $30 - call AddNTimes - ld de, wBattleMonMoves - ld b, $4 -.asm_f6cf - ld a, [de] - and a - jr z, .asm_f6ed - cp [hl] - jr nz, .asm_f6e8 - push hl - push de - push bc - inc de - inc de - inc de - inc de - inc de - inc de - ld bc, $15 - add hl, bc - ld a, [hl] - ld [de], a - pop bc - pop de - pop hl -.asm_f6e8 - inc hl - inc de - dec b - jr nz, .asm_f6cf -.asm_f6ed - ret - -Functionf6ee: ; f6ee (3:76ee) - call Functionf72f - jr nz, asm_f699 - jp Functionf724 - -Functionf6f6: ; f6f6 (3:76f6) - xor a - ld hl, wMenuCursorY - ld [hli], a - ld [hl], a - ld b, $4 -.asm_f6fe - push bc - ld hl, wPartyMon1Moves - ld bc, $30 - call Functionf9aa - ld a, [hl] - and a - jr z, .asm_f715 - call Functionf72f - jr z, .asm_f715 - ld hl, wcee1 - inc [hl] -.asm_f715 - ld hl, wMenuCursorY - inc [hl] - pop bc - dec b - jr nz, .asm_f6fe - ld a, [wcee1] - and a - jp nz, asm_f699 -Functionf724: ; f724 (3:7724) - call Functionf839 -Functionf727: ; f727 (3:7727) - call ClearPalettes - xor a - ld [wFieldMoveSucceeded], a - ret - -Functionf72f: ; f72f (3:772f) - xor a - ld [wMonType], a - call GetMaxPPOfMove - ld hl, wPartyMon1PP - ld bc, $30 - call Functionf9aa - ld a, [wd151] - ld b, a - ld a, [hl] - and $3f - cp b - jr nc, .asm_f76a - ld a, [wceed] - cp MAX_ELIXER - jr z, .asm_f764 - cp $40 - jr z, .asm_f764 - ld c, $5 - cp $96 - jr z, .asm_f75c - ld c, $a -.asm_f75c - ld a, [hl] - and $3f - add c - cp b - jr nc, .asm_f764 - ld b, a -.asm_f764 - ld a, [hl] - and $c0 - or b - ld [hl], a - ret - -.asm_f76a - xor a - ret - -Text_RaiseThePPOfWhichMove: - text_far Text_RaiseThePPOfWhichMove_ - db "@" - -Text_RestoreThePPOfWhichMove: - text_far Text_RestoreThePPOfWhichMove_ - db "@" - -Text_PPIsMaxedOut: - text_far Text_PPIsMaxedOut_ - db "@" - -Text_PPsIncreased: - text_far Text_PPsIncreased_ - db "@" - -Text_PPWasRestored: - text_far Text_PPWasRestored_ - db "@" - -Squirtbottle: ; f785 (3:7785) - farcall SquirtbottleFunction ; 14:4763 - ret - -CardKey: ; f78c (3:778c) - farcall CardKeyFunction ; 14:47ac - ret - -BasementKey: ; f793 (3:7793) - farcall BasementKeyFunction ; 14:47e7 - ret - -SacredAsh: ; f79a (3:779a) - farcall SacredAshFunction ; 14:4819 - ld a, [wFieldMoveSucceeded] - cp $1 - ret nz - call Functionf7dc - ret - -NormalBox: ; f7aa (3:77aa) - ld c, DECOFLAG_SILVER_TROPHY_DOLL - jr asm_f7b0 - -GorgeousBox: ; f7ae (3:77ae) - ld c, DECOFLAG_GOLD_TROPHY_DOLL -asm_f7b0 - farcall ReceiveDecorationC ; 9:70d5 - ld hl, Text_TrophyInside ; $77bf - call PrintText - jp Functionf7dc - -Text_TrophyInside: - text_far Text_TrophyInside_ - db "@" - -AmuletCoin: ; f7c4 -BerserkGene: ; f7c4 -BigMushroom: ; f7c4 -BigPearl: ; f7c4 -Blackbelt: ; f7c4 -Blackglasses: ; f7c4 -BlkApricorn: ; f7c4 -BluApricorn: ; f7c4 -Brightpowder: ; f7c4 -Charcoal: ; f7c4 -CleanseTag: ; f7c4 -DragonFang: ; f7c4 -DragonScale: ; f7c4 -Everstone: ; f7c4 -ExpShare: ; f7c4 -FlowerMail: ; f7c4 -FocusBand: ; f7c4 -GoldLeaf: ; f7c4 -GrnApricorn: ; f7c4 -HardStone: ; f7c4 -Item19: ; f7c4 -Item2D: ; f7c4 -Item32: ; f7c4 -Item47: ; f7c4 -Item5A: ; f7c4 -Item64: ; f7c4 -Item73: ; f7c4 -Item74: ; f7c4 -Item78: ; f7c4 -Item81: ; f7c4 -Item87: ; f7c4 -Item88: ; f7c4 -Item89: ; f7c4 -Item8D: ; f7c4 -Item8E: ; f7c4 -Item91: ; f7c4 -Item93: ; f7c4 -Item94: ; f7c4 -Item95: ; f7c4 -Item99: ; f7c4 -Item9A: ; f7c4 -Item9B: ; f7c4 -ItemA2: ; f7c4 -ItemAB: ; f7c4 -ItemB0: ; f7c4 -ItemB3: ; f7c4 -KingsRock: ; f7c4 -Leftovers: ; f7c4 -LightBall: ; f7c4 -LostItem: ; f7c4 -LuckyEgg: ; f7c4 -LuckyPunch: ; f7c4 -MachinePart: ; f7c4 -Magnet: ; f7c4 -MetalCoat: ; f7c4 -MetalPowder: ; f7c4 -MiracleSeed: ; f7c4 -MysteryEgg: ; f7c4 -MysticWater: ; f7c4 -Nevermeltice: ; f7c4 -Nugget: ; f7c4 -Pass: ; f7c4 -Pearl: ; f7c4 -PinkBow: ; f7c4 -PnkApricorn: ; f7c4 -PoisonBarb: ; f7c4 -PolkadotBow: ; f7c4 -QuickClaw: ; f7c4 -RainbowWing: ; f7c4 -RedApricorn: ; f7c4 -RedScale: ; f7c4 -SSTicket: ; f7c4 -ScopeLens: ; f7c4 -Secretpotion: ; f7c4 -SharpBeak: ; f7c4 -SilverLeaf: ; f7c4 -SilverWing: ; f7c4 -Silverpowder: ; f7c4 -Slowpoketail: ; f7c4 -SmokeBall: ; f7c4 -SoftSand: ; f7c4 -SpellTag: ; f7c4 -StarPiece: ; f7c4 -Stardust: ; f7c4 -Stick: ; f7c4 -ThickClub: ; f7c4 -Tinymushroom: ; f7c4 -Twistedspoon: ; f7c4 -UpGrade: ; f7c4 -WhtApricorn: ; f7c4 -YlwApricorn: ; f7c4 - jp Functionf834 - -Functionf7c7: ; f7c7 (3:77c7) - push de - ld de, SFX_FULL_HEAL - call WaitPlaySFX - pop de - ret - -Functionf7d0: ; f7d0 (3:77d0) - ld hl, Text_UsedItem - call PrintText - call Functionf7c7 - call WaitPressAorB_BlinkCursor -Functionf7dc: ; f7dc (3:77dc) - ld hl, wTMsHMsEnd - ld a, $1 - ld [wItemQuantityChangeBuffer], a - jp TossItem - -Functionf7e7: ; f7e7 (3:77e7) - call ReturnToBattle_UseBall - ld de, Start - ld a, e - ld [wcf3e], a - ld a, d - ld [wcf3f], a - xor a - ld [wcb67], a - ldh [hBattleTurn], a - ld [wcf46], a - predef PlayBattleAnim - ld hl, Text_BlockedTheBall - call PrintText - ld hl, Text_DontBeAThief - call PrintText - jr Functionf7dc - -Functionf811: ; f811 (3:7811) - ld hl, Text_WontHaveAnyEffect - call PrintText - ld a, $2 - ld [wFieldMoveSucceeded], a - ret - -Functionf81d: ; f81d (3:781d) - ld hl, Text_LooksBitter - jp PrintText - -FailToUseBall: ; f823 (3:7823) - ld hl, Text_CantUseBallBoxIsFull - call PrintText - ld a, $2 - ld [wFieldMoveSucceeded], a - ret - -Functionf82f: ; f82f (3:782f) - ld hl, Text_CantUseOnEgg - jr asm_f84b - -Functionf834: ; f834 (3:7834) - ld hl, Text_IsntTheTimeToUseThat - jr asm_f84b - -Functionf839: ; f839 (3:7839) - ld hl, Text_WontHaveAnyEffect - jr asm_f84b - -Functionf83e: - ld hl, Text_BelongsToSomeoneElse - jr asm_f84b - -Functionf843: - ld hl, Text_CyclingIsntAllowed - jr asm_f84b - -Functionf848: - ld hl, Text_CantGetOnYourItemNow -asm_f84b - xor a - ld [wFieldMoveSucceeded], a - jp PrintText - -Text_LooksBitter: - text_far Text_LooksBitter_ - db "@" - -Text_CantUseOnEgg: - text_far Text_CantUseOnEgg_ - db "@" - -Text_IsntTheTimeToUseThat: - text_far Text_IsntTheTimeToUseThat_ - db "@" - -Text_BelongsToSomeoneElse: - text_far Text_BelongsToSomeoneElse_ - db "@" - -Text_WontHaveAnyEffect: - text_far Text_WontHaveAnyEffect_ - db "@" - -Text_BlockedTheBall: - text_far Text_BlockedTheBall_ - db "@" - -Text_DontBeAThief: - text_far Text_DontBeAThief_ - db "@" - -Text_CyclingIsntAllowed: - text_far Text_CyclingIsntAllowed_ - db "@" - -Text_CantGetOnYourItemNow: - text_far Text_CantGetOnYourItemNow_ - db "@" - -Text_CantUseBallBoxIsFull: - text_far Text_CantUseBallBoxIsFull_ - db "@" - -Text_UsedItem: - text_far Text_UsedItem_ - db "@" - -Text_GotOnItem: - text_far Text_GotOnItem_ - db "@" - -Text_GotOffItem: - text_far Text_GotOffItem_ - db "@" - -Functionf893: ; f893 (3:7893) - ld a, $2 - call GetPartyParamLocation - push hl - ld de, wBuffer1 - predef FillPP - pop hl - ld bc, $15 - add hl, bc - ld de, wCurHPAnimMaxHP - ld b, $0 -.asm_f8ab - inc b - ld a, b - cp $5 - ret z - ld a, [wd151] - dec a - jr nz, .asm_f8bd - ld a, [wMenuCursorY] - inc a - cp b - jr nz, .asm_f8c4 -.asm_f8bd - ld a, [hl] - and $c0 - ld a, [de] - call nz, Functionf8c8 -.asm_f8c4 - inc hl - inc de - jr .asm_f8ab - -Functionf8c8: ; f8c8 (3:78c8) - push bc - ; Divide the base PP by 5. - ld a, [de] - ldh [hDividend + 3], a - xor a - ldh [hDividend], a - ldh [hDividend + 1], a - ldh [hDividend + 2], a - ld a, 5 - ldh [hDivisor], a - ld b, 4 - call Divide - ; Get the number of PP, which are bits 6 and 7 of the PP value stored in RAM. - ld a, [hl] - ld b, a - swap a - and $f - srl a - srl a - ld c, a - ; If this value is 0, we are done - and a - jr z, .asm_f8fd -.asm_f8ea - ldh a, [hPrintNum4] - cp $8 - jr c, .asm_f8f2 - ld a, $7 -.asm_f8f2 - add b - ld b, a - ld a, [wd151] - dec a - jr z, .asm_f8fd - dec c - jr nz, .asm_f8ea -.asm_f8fd - ld [hl], b - pop bc - ret - -Functionf900: ; f900 (3:7900) - ld a, $17 - call GetPartyParamLocation - push hl - ld a, $2 - call GetPartyParamLocation - pop de - xor a - ld [wMenuCursorY], a - ld [wMonType], a - ld c, $4 -.asm_f915 - ld a, [hli] - and a - ret z - push hl - push de - push bc - call GetMaxPPOfMove - pop bc - pop de - ld a, [de] - and $c0 - ld b, a - ld a, [wd151] - add b - ld [de], a - inc de - ld hl, wMenuCursorY - inc [hl] - pop hl - dec c - jr nz, .asm_f915 - ret - -GetMaxPPOfMove: ; f933 (3:7933) - ld a, [wStringBuffer1] - push af - ld a, [wStringBuffer1 + 1] - push af - ld a, [wMonType] - and a - ld hl, wPartyMon1Moves - ld bc, $30 - jr z, .asm_f961 - ld hl, wOTPartyMon1Moves - dec a - jr z, .asm_f961 - ld hl, wTempMonMoves - dec a - jr z, .asm_f95c - ld hl, wTempMonMoves - dec a - jr z, .asm_f95c - ld hl, wBattleMonMoves -.asm_f95c - call Functionf9b0 - jr .asm_f964 - -.asm_f961 - call Functionf9aa -.asm_f964 - ld a, [hl] - dec a - push hl - ld hl, Moves + MOVE_PP - ld bc, $7 - call AddNTimes - ld a, BANK(Moves) - call GetFarByte - ld b, a - ld de, wStringBuffer1 - ld [de], a - pop hl - push bc - ld bc, $15 - ld a, [wMonType] - cp $4 - jr nz, .asm_f989 - ld bc, $6 -.asm_f989 - add hl, bc - ld a, [hl] - and $c0 - pop bc - or b - ld hl, wStringBuffer1 + 1 - ld [hl], a - xor a - ld [wd151], a - ld a, b - call Functionf8c8 - ld a, [hl] - and $3f - ld [wd151], a - pop af - ld [wStringBuffer1 + 1], a -.asm_f9a3 - pop af - ld [wStringBuffer1], a - ret - -Functionf9aa: ; f9aa (3:79aa) - ld a, [wCurPartyMon] - call AddNTimes -Functionf9b0: ; f9b0 (3:79b0) - ld a, [wMenuCursorY] - ld c, a - ld b, $0 - add hl, bc - ret - -GetPokeballWobble: - ld a, [wBuffer2] - inc a - ld [wBuffer2], a - cp $4 - jr z, .asm_f9e3 - ld a, [wWildMon] - and a - ld c, $0 - ret nz - ld hl, PokeballWobbleProbabilities - ld a, [wCurHPAnimMaxHP] - ld b, a -.asm_f9d1 - ld a, [hli] - cp b - jr nc, .asm_f9d8 - inc hl - jr .asm_f9d1 - -.asm_f9d8 - ld b, [hl] - call Random - cp b - ld c, $0 - ret c - ld c, $2 - ret - -.asm_f9e3 - ld a, [wWildMon] - and a - ld c, $1 - ret nz - ld c, $2 - ret - -PokeballWobbleProbabilities: - db 1, 63 - db 2, 75 - db 3, 84 - db 4, 90 - db 5, 95 - db 7, 103 - db 10, 113 - db 15, 126 - db 20, 134 - db 30, 149 - db 40, 160 - db 50, 169 - db 60, 177 - db 80, 191 - db 100, 201 - db 120, 211 - db 140, 220 - db 160, 227 - db 180, 234 - db 200, 240 - db 220, 246 - db 240, 251 - db 254, 253 - db 255, 255 diff --git a/main.asm b/main.asm index 36b63704..07dd24fe 100644 --- a/main.asm +++ b/main.asm @@ -17,431 +17,36 @@ INCLUDE "engine/events/happiness_egg.asm" INCLUDE "engine/events/shuckle.asm" INCLUDE "engine/events/haircut.asm" -SECTION "bank2", ROMX, BANK[$2] -_SwapTextboxPalettes:: - ld hl, wTilemap - ld de, wAttrmap - ld b, $12 -.asm_8008 - ld c, $14 -.asm_800a - ld a, [hli] - push hl - srl a - jr c, .asm_8024 - ld hl, wTilesetPalettes - add [hl] - ld l, a - ld a, [wTilesetPalettes + 1] - adc $0 - ld h, a - ld a, [hl] - and $f - bit 3, a - jr z, .asm_8045 - jr .asm_8038 - -.asm_8024 - ld hl, wTilesetPalettes - add [hl] - ld l, a - ld a, [wTilesetPalettes + 1] - adc $0 - ld h, a - ld a, [hl] - swap a - and $f - bit 3, a - jr z, .asm_8045 -.asm_8038 - ld a, [wMapGroup] - dec a - ld hl, Unknown85d7 - add l - ld l, a - jr nc, .asm_8044 - inc h -.asm_8044 - ld a, [hl] -.asm_8045 - pop hl - ld [de], a - inc de - dec c - jr nz, .asm_800a - dec b - jr nz, .asm_8008 - ret - -_ScrollBGMapPalettes:: ; 804f (2:404f) - ld hl, wBGMapBuffer - ld de, wBGMapPalBuffer -.asm_8055 - ld a, [hli] - push hl - srl a - jr c, .asm_806f - ld hl, wTilesetPalettes - add [hl] - ld l, a - ld a, [wTilesetPalettes + 1] - adc $0 - ld h, a - ld a, [hl] - and $f - bit 3, a - jr z, .asm_8090 - jr .asm_8083 - -.asm_806f - ld hl, wTilesetPalettes - add [hl] - ld l, a - ld a, [wTilesetPalettes + 1] - adc $0 - ld h, a - ld a, [hl] - swap a - and $f - bit 3, a - jr z, .asm_8090 -.asm_8083 - ld a, [wMapGroup] - dec a - ld hl, Unknown85d7 - add l - ld l, a - jr nc, .asm_808f - inc h -.asm_808f - ld a, [hl] -.asm_8090 - pop hl - ld [de], a - inc de - dec c - jr nz, .asm_8055 - ret - -INCLUDE "gfx/tilesets/palette_maps.asm" - -Unknown85d7: - rept 26 ; NUM_MAP_GROUPS - db PAL_BG_ROOF - endr +SECTION "bank2", ROMX +INCLUDE "engine/tilesets/map_palettes.asm" +INCLUDE "gfx/tileset_palette_maps.asm" INCLUDE "engine/overworld/player_object.asm" -INCLUDE "engine/sine.asm" +INCLUDE "engine/math/sine.asm" INCLUDE "engine/predef.asm" -INCLUDE "engine/color.asm" - -SECTION "bank3", ROMX, BANK[$3] -CheckTime:: - ld a, [wTimeOfDay] - ld hl, TimeOfDayTable - ld de, $2 - call IsInArray - inc hl - ld c, [hl] - ret c - xor a - ld c, a - ret - -TimeOfDayTable: - db MORN_F, MORN - db DAY_F, DAY - db NITE_F, NITE - db NITE_F, NITE - db -1 +INCLUDE "engine/gfx/color.asm" -INCLUDE "engine/engine_flags.asm" -INCLUDE "engine/variables.asm" -INCLUDE "engine/specials.asm" - -Functionc660: - nop -SmallFarFlagAction: - push hl - push bc - push bc - srl c - srl c - srl c - ld b, $0 - add hl, bc - pop bc - ld a, c - and $7 - ld c, a - ld a, $1 - jr z, .asm_c67a -.asm_c676 - add a - dec c - jr nz, .asm_c676 -.asm_c67a - ld c, a - dec b - jr z, .asm_c687 - dec b - jr z, .asm_c68c - ld a, c - cpl - and [hl] - ld [hl], a - jr .asm_c699 - -.asm_c687 - ld a, [hl] - or c - ld [hl], a - jr .asm_c699 - -.asm_c68c - ld a, d - cp $0 - jr nz, .asm_c695 - ld a, [hl] - and c - jr .asm_c699 - -.asm_c695 - call GetFarByte - and c -.asm_c699 - pop bc - pop hl - ld c, a - ret +SECTION "bank3", ROMX -INCLUDE "engine/health.asm" +INCLUDE "engine/events/checktime.asm" +INCLUDE "engine/events/engine_flags.asm" +INCLUDE "engine/overworld/variables.asm" +INCLUDE "engine/events/specials.asm" +INCLUDE "engine/smallflag.asm" +INCLUDE "engine/pokemon/health.asm" INCLUDE "engine/events/overworld.asm" -INCLUDE "engine/items.asm" +INCLUDE "engine/items/items.asm" INCLUDE "engine/overworld/player_step.asm" -INCLUDE "engine/anim_hp_bar.asm" -INCLUDE "engine/move_mon.asm" +INCLUDE "engine/battle/anim_hp_bar.asm" +INCLUDE "engine/pokemon/move_mon.asm" INCLUDE "engine/pokemon/bills_pc_top.asm" +INCLUDE "engine/pokemon/breedmon_level_growth.asm" +INCLUDE "engine/pokemon/search2.asm" +INCLUDE "engine/events/bug_contest/caught_mon.asm" +INCLUDE "engine/items/item_effects.asm" +INCLUDE "engine/pokemon/knows_move.asm" -GetBreedMon1LevelGrowth: - ld hl, wBreedMon1Species - ld de, wTempMonSpecies - ld bc, $20 - call CopyBytes - callfar CalcLevel - ld a, [wBreedMon1Level] - ld b, a - ld a, d - ld e, a - sub b - ld d, a - ret - -GetBreedMon2LevelGrowth: - ld hl, wBreedMon2Species - ld de, wTempMon - ld bc, $20 - call CopyBytes - callfar CalcLevel - ld a, [wBreedMon2Level] - ld b, a - ld a, d - ld e, a - sub b - ld d, a - ret - -PartySearch_MaximumLevel: ; e6a9 (3:66a9) - ld hl, wPartyMon1Level - call PartySearch_LessThanValue - ret - -PartySearch_MinimumHappiness: ; e6b0 (3:66b0) - ld hl, wPartyMon1Happiness - call PartySearch_GreaterThanOrEqualToValue - ret - -PartySearch_SameSpecies: ; e6b7 (3:66b7) - ld hl, wPartyMons - jp PartySearch_GetIndexOfSpeciesInParty - -PartySearch_SameSpeciesAndYourID: ; e6bd (3:66bd) - ld hl, wPartyMon1 - call PartySearch_GetIndexOfSpeciesInParty - ret z - ld a, c - ld hl, wPartyMon1ID - ld bc, PARTYMON_STRUCT_LENGTH - call AddNTimes - ld a, [wPlayerID] - cp [hl] - jr nz, .nope - inc hl - ld a, [wPlayerID + 1] - cp [hl] - jr nz, .nope - ld a, $1 - and a - ret - -.nope - xor a - ret - -PartySearch_GreaterThanOrEqualToValue: ; e6e1 (3:66e1) - ld c, $0 - ld a, [wPartyCount] - ld d, a -.loop - ld a, d - dec a - push hl - push bc - ld bc, PARTYMON_STRUCT_LENGTH - call AddNTimes - pop bc - ld a, b - cp [hl] - pop hl - jr z, .shift - jr nc, .skip -.shift - ld a, c - or $1 - ld c, a -.skip - sla c - dec d - jr nz, .loop - call PartySearch_FilterEggs - ld a, c - and a - ret - -PartySearch_LessThanValue: ; e708 (3:6708) - ld c, $0 - ld a, [wPokemonData] - ld d, a -.loop - ld a, d - dec a - push hl - push bc - ld bc, PARTYMON_STRUCT_LENGTH - call AddNTimes - pop bc - ld a, b - cp [hl] - pop hl - jr c, .skip - ld a, c - or $1 - ld c, a -.skip - sla c - dec d - jr nz, .loop - call PartySearch_FilterEggs - ld a, c - and a - ret - -PartySearch_GetIndexOfSpeciesInParty: ; e72d (3:672d) - ld c, -1 - ld hl, wPartySpecies -.loop - ld a, [hli] - cp $ff - ret z - inc c - cp b - jr nz, .loop - ld a, $1 - and a - ret - -PartySearch_FilterEggs: ; e73e (3:673e) - ld e, $FF ^ 1 - ld hl, wPartySpecies -.loop - ld a, [hli] - cp $ff - ret z - cp EGG - jr nz, .not_egg - ld a, c - and e - ld c, a -.not_egg - rlc e - jr .loop - -BugContest_SetCaughtContestMon: - ld a, [wContestMonSpecies] - and a - jr z, .asm_e76e - ld [wd151], a - farcall DisplayAlreadyCaughtText - farcall DisplayCaughtContestMonStats - lb bc, 14, 7 - call PlaceYesNoBox - ret c -.asm_e76e - call GenerateBugContestMonStats - ld a, [wTempEnemyMonSpecies] - ld [wd151], a - call GetPokemonName - ld hl, Text_CaughtBugMon - call PrintText - ret - -GenerateBugContestMonStats: ; e781 (3:6781) - ld a, [wTempEnemyMonSpecies] - ld [wCurSpecies], a - ld [wCurPartySpecies], a - call GetBaseData - xor a - ld bc, PARTYMON_STRUCT_LENGTH - ld hl, wContestMon - call ByteFill - xor a - ld [wMonType], a - ld hl, wContestMon - jp GeneratePartyMonStats - -Text_CaughtBugMon: - ; Caught @ ! - text_far Text_CaughtBugMon_ - db "@" - -INCLUDE "items/item_effects.asm" - -KnowsMove: - ld a, MON_MOVES - call GetPartyParamLocation - ld a, [wPutativeTMHMMove] - ld b, a - ld c, $4 -.asm_fa28 - ld a, [hli] - cp b - jr z, .asm_fa31 - dec c - jr nz, .asm_fa28 - and a - ret - -.asm_fa31 - ld hl, Text_KnowsMove - call PrintText - scf - ret - -Text_KnowsMove: - text_far Text_KnowsMove_ - db "@" - -SECTION "bank4", ROMX, BANK[$4] +SECTION "bank4", ROMX INCLUDE "engine/overworld/player_movement.asm" INCLUDE "engine/items/pack.asm" diff --git a/pokegold.link b/pokegold.link index 5eb704f5..7537b5f4 100644 --- a/pokegold.link +++ b/pokegold.link @@ -30,16 +30,12 @@ ROM0 org $0150 "Home" ROMX $01 - org $4000 "bank1" ROMX $02 - org $4000 "bank2" ROMX $03 - org $4000 "bank3" ROMX $04 - org $4000 "bank4" ROMX $05 org $4000 diff --git a/pokesilver.link b/pokesilver.link index 5eb704f5..7537b5f4 100644 --- a/pokesilver.link +++ b/pokesilver.link @@ -30,16 +30,12 @@ ROM0 org $0150 "Home" ROMX $01 - org $4000 "bank1" ROMX $02 - org $4000 "bank2" ROMX $03 - org $4000 "bank3" ROMX $04 - org $4000 "bank4" ROMX $05 org $4000 -- cgit v1.2.3