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 --- engine/items/inventory.asm | 46 +++++++++++++++++++++++++ engine/items/item_effects.asm | 79 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100755 engine/items/item_effects.asm (limited to 'engine/items') 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 -- cgit v1.2.3