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/bcd.asm | 55 ++++++++++++++++ engine/items/inventory.asm | 46 ++++++++++++++ engine/items/item_effects.asm | 79 +++++++++++++++++++++++ engine/pokemon/health.asm | 141 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 321 insertions(+) create mode 100755 engine/bcd.asm create mode 100755 engine/items/item_effects.asm create mode 100755 engine/pokemon/health.asm (limited to 'engine') 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 -- cgit v1.2.3