From f11e353fbb7d08f33ac58b49f586f65fb800cfba Mon Sep 17 00:00:00 2001 From: Pokeglitch Date: Sat, 16 Jun 2018 10:24:17 -0400 Subject: More Bank 3 routines --- constants/move_constants.asm | 3 + data/predef_pointers.inc | 20 +++--- engine/bcd.asm | 55 ++++++++++++++++ engine/items/inventory.asm | 46 ++++++++++++++ engine/items/item_effects.asm | 79 +++++++++++++++++++++++ engine/pokemon/health.asm | 141 ++++++++++++++++++++++++++++++++++++++++++ home/misc_32c8.asm | 2 +- shim.sym | 14 +---- wram.asm | 23 ++++++- 9 files changed, 359 insertions(+), 24 deletions(-) create mode 100755 engine/bcd.asm create mode 100755 engine/items/item_effects.asm create mode 100755 engine/pokemon/health.asm diff --git a/constants/move_constants.asm b/constants/move_constants.asm index b7daf0e..dee94ff 100644 --- a/constants/move_constants.asm +++ b/constants/move_constants.asm @@ -294,3 +294,6 @@ NUM_ATTACKS EQU const_value + -1 const BATTLEANIM_WOBBLE const BATTLEANIM_SHAKE const BATTLEANIM_HIT_CONFUSION + + +MOVE_DATA_SIZE EQU 7 \ No newline at end of file diff --git a/data/predef_pointers.inc b/data/predef_pointers.inc index 0b39ae2..46b648d 100644 --- a/data/predef_pointers.inc +++ b/data/predef_pointers.inc @@ -16,18 +16,18 @@ PredefPointers:: ; 1:62d3 add_predef Function6713 add_predef Function66b1 add_predef Function4031 - add_predef Functionce10 - add_predef Functioncd6f - add_predef Functioncde3 - add_predef Functioncde3_2 ; 8 - add_predef Functioncde3_3 - add_predef Functioncdf9 - add_predef Functionce10_2 - add_predef Functioncd33 + add_predef GetItemAmount + add_predef HealParty + add_predef AddBCD + dbw BANK(AddBCD), AddBCD ; 8 + dbw BANK(AddBCD), AddBCD + add_predef SubBCD + dbw BANK(GetItemAmount), GetItemAmount + add_predef SmallFarFlagAction GiveItemPredef:: dbw 3, GiveItem - add_predef Functionce3c - add_predef Functionda28 + add_predef ComputeHPBarPixels + add_predef FillPP add_predef Functiond886 ; 10 add_predef Functionda4f add_predef Functiondac8 diff --git a/engine/bcd.asm b/engine/bcd.asm new file mode 100755 index 0000000..53f0b20 --- /dev/null +++ b/engine/bcd.asm @@ -0,0 +1,55 @@ +INCLUDE "constants.asm" + +SECTION "BCD", ROMX[$4de3], BANK[$03] + +AddBCD: ; 03:4de3 + and a + ld b, c +.add + ld a, [de] + adc [hl] + daa + ld [de], a + dec de + dec hl + dec c + jr nz, .add + jr nc, .done + + ld a, $99 + inc de + +.fill + ld [de], a + inc de + dec b + jr nz, .fill + +.done + ret + + +SubBCD: ; 03:4df9 + and a + ld b, c +.sub + ld a, [de] + sbc [hl] + daa + ld [de], a + dec de + dec hl + dec c + jr nz, .sub + jr nc, .done + ld a, 0 + inc de + +.fill + ld [de], a + inc de + dec b + jr nz, .fill + scf +.done + ret \ No newline at end of file diff --git a/engine/items/inventory.asm b/engine/items/inventory.asm index 9c5a1ec..729ba45 100755 --- a/engine/items/inventory.asm +++ b/engine/items/inventory.asm @@ -587,6 +587,52 @@ GetNumberedTMHM: ; 03:4D1A .not_machine and a ret + +SECTION "GetItemAmount", ROMX[$4e10], BANK[$03] + +; Returns carry if user has the item +; and the amount in b +GetItemAmount: ; 03:4e10 + call CheckAmountInItemPocket + ret c + call CheckAmountInKeyItems + ret c + ld b, 0 + and a + ret + +; Returns the amount of item b in b +CheckAmountInItemPocket: ; 03:4E1C + ld hl, wItems +.loop + inc hl + ld a, [hli] + cp -1 + ret z + cp b + jr nz, .loop + + ld a, [hl] + ld b, a + scf + ret + +; Returns the amount of item b in b +CheckAmountInKeyItems: ; 03:4E2B + ld hl, wNumKeyItems + ld a, [hli] + and a + ret z + +.loop + ld a, [hli] + cp -1 + ret z + cp b + jr nz, .loop + ld b, 1 + scf + ret SECTION "_CheckTossableItem", ROMX[$53AD], BANK[$03] diff --git a/engine/items/item_effects.asm b/engine/items/item_effects.asm new file mode 100755 index 0000000..4ee9f42 --- /dev/null +++ b/engine/items/item_effects.asm @@ -0,0 +1,79 @@ +INCLUDE "constants.asm" + +SECTION "ApplyPPUp", ROMX[$78f6], BANK[$03] + +ApplyPPUp: ; 03:78f6 + ld a, MON_MOVES + call GetPartyParamLocation + push hl + ld de, wStringBuffer1 + predef FillPP + pop hl + ld c, MON_PP - MON_MOVES + ld b, 0 + add hl, bc + ld de, wStringBuffer1 + 1 + ld b, 0 +.loop + inc b + ld a, b + cp NUM_MOVES + 1 + ret z + ld a, [wce37] + dec a + jr nz, .use + ld a, [wMenuCursorY] + inc a + cp b + jr nz, .skip +.use + ld a, [hl] + and PP_UP_MASK + call nz, ComputeMaxPP +.skip + inc hl + inc de + jr .loop + +ComputeMaxPP: ; 03:792B + 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 +.loop + ; Normally, a move with 40 PP would have 64 PP with three PP Ups. + ; Since this would overflow into bit 6, we prevent that from happening + ; by decreasing the extra amount of PP each PP Up provides, resulting + ; in a maximum of 61. + ldh a, [hQuotient + 2] + cp $8 + jr c, .okay + ld a, $7 +.okay + add b + ld b, a + ld a, [wce37] + dec a + jr z, .no_pp_up + dec c + jr nz, .loop +.no_pp_up + ld [hl], b + pop bc + ret \ No newline at end of file diff --git a/engine/pokemon/health.asm b/engine/pokemon/health.asm new file mode 100755 index 0000000..59ec4db --- /dev/null +++ b/engine/pokemon/health.asm @@ -0,0 +1,141 @@ +INCLUDE "constants.asm" + +SECTION "HealParty", ROMX[$4d6f], BANK[$03] + +HealParty: ; 03:4d6f + ld hl, wPartySpecies + ld de, wPartyMons + +.party_loop + ld a, [hli] + cp -1 + jr z, .party_done + push hl + push de + +; Clear the status + ld hl, MON_STATUS + add hl, de + xor a + ld [hli], a + ld [hl], a + +; Reset the PP + ld hl, MON_MAXHP - MON_HP ; TODO - This should point to the MOVES, not max HP... + add hl, de + ld b, NUM_MOVES + +.move_loop + push hl + push bc + ld a, [hl] + and a + jr z, .next_move + dec a + push hl + ld hl, Moves + ld bc, MOVE_DATA_SIZE + call AddNTimes + ld a, BANK(Moves) + call GetFarByte + pop hl + ld bc, MON_PP - MON_MOVES + add hl, bc + ld b, a + ld a, [hl] + and PP_UP_MASK + add b + ld [hl], a + +.next_move + pop bc + pop hl + inc hl + dec b + jr nz, .move_loop + +; Reset the HP + pop de + push de + ld hl, MON_MAXHP + 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 + pop de + pop hl + push hl + ld hl, PARTYMON_STRUCT_LENGTH + add hl, de + ld d, h + ld e, l + pop hl + jr .party_loop + +.party_done + xor a + ld [wWhichPokemon], a + ld [wce37], a + ld a, [wPartyCount] + ld b, a + +.pp_up + push bc + call ApplyPPUp + pop bc + ld hl, wWhichPokemon + inc [hl] + dec b + jr nz, .pp_up + ret + +SECTION "ComputeHPBarPixels", ROMX[$4e3c], BANK[$03] + +ComputeHPBarPixels: ; 03:4e3c + push hl + xor a + ldh [hMultiplicand], 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, .divide + ; 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 +.divide + ld a, e + ldh [hDivisor], a + ld b, 4 + call Divide + ldh a, [hQuotient + 2] + ld e, a + pop hl + and a + ret nz + ld e, 1 + ret \ No newline at end of file diff --git a/home/misc_32c8.asm b/home/misc_32c8.asm index 3eabb12..8b423bb 100644 --- a/home/misc_32c8.asm +++ b/home/misc_32c8.asm @@ -7,7 +7,7 @@ SECTION "Unknown 32c8", ROM0[$328c] endc Function32c8:: - predef Functionce10 + predef GetItemAmount ld a, b and a ret diff --git a/shim.sym b/shim.sym index ae15054..ffe9c8a 100644 --- a/shim.sym +++ b/shim.sym @@ -5,6 +5,7 @@ 00:3233 Function3233 00:323E Function323e 00:3240 Function3240 +00:3C43 GetPartyParamLocation 00:3CA8 InitSpriteAnimStruct 00:3D86 WaitSFX 00:3D87 WaitSFX.wait @@ -62,20 +63,11 @@ 03:4000 Functionc000 03:47D5 SpawnPoints 03:488D Tilesets -03:4D33 Functioncd33 -03:4D6F Functioncd6f -03:4DE3 Functioncde3 -03:4DE3 Functioncde3_2 -03:4DE3 Functioncde3_3 -03:4DF9 Functioncdf9 -03:4E10 Functionce10 -03:4E10 Functionce10_2 -03:4E3C Functionce3c 03:4E7C Functionce7c 03:54E6 Functiond4e6 03:56E4 Functiond6e4 03:5886 Functiond886 -03:5A28 Functionda28 +03:5A28 FillPP 03:5A4F Functionda4f 03:5AC8 Functiondac8 03:5C16 Functiondc16 @@ -161,6 +153,7 @@ 10:4AC7 Function40ac7 10:4B45 Function40b45 10:4B5C Function40b5c +10:58BB Moves 10:5FA1 Function41fa1 10:61F8 Function421f8 10:6252 Function42252 @@ -478,5 +471,4 @@ ; The starting house's map script number is stored at d29a. Others are probably nearby. 01:D35F wOptions 01:D513 wWarpNumber -01:D7D2 wPartyMonOT 01:DA3B wOTPartyMonOT diff --git a/wram.asm b/wram.asm index 975a8ea..c845bf5 100644 --- a/wram.asm +++ b/wram.asm @@ -440,6 +440,7 @@ wcd72:: dw ; cd72 wCurItem:: db ; cd76 wItemIndex:: db ;cd77 wMonDexIndex: db ; cd78 +wWhichPokemon: db ; cd79 SECTION "CD7D", WRAM0[$CD7D] @@ -821,8 +822,26 @@ wTilesetCollisionAddress:: ; d6a4 ds 4 ; TODO wTilesetEnd:: ; d6aa - -SECTION "PokeDexFlags", WRAM0[$D81A] +wPartyCount:: db +wPartySpecies:: ds PARTY_LENGTH +wPartyEnd:: db + +wPartyMons:: +wPartyMon1:: party_struct wPartyMon1 ; d6b2 +wPartyMon2:: party_struct wPartyMon2 ; d6e2 +wPartyMon3:: party_struct wPartyMon3 ; d712 +wPartyMon4:: party_struct wPartyMon4 ; d742 +wPartyMon5:: party_struct wPartyMon5 ; d772 +wPartyMon6:: party_struct wPartyMon6 ; d7a2 +wPlayerPartyEnd:: ; d7d2 + +wPartyMonOT:: ; d7d2 + ds PARTY_LENGTH * 6 +wPartyMonOTEnd:: ; d7f6 + +wPartyMonNicknames:: ; d7f6 + ds PARTY_LENGTH * MON_NAME_LENGTH ; = $24 +wPartyMonNicknamesEnd:: ; d81a wPokedexOwned:: ; d81a flag_array NUM_POKEMON -- cgit v1.2.3