ref: 794410352fd92ccf06974763e4b3be0b807641ab
dir: /engine/money.asm/
GiveMoney:: ; 15fd7 ld a, $3 call AddMoney ld bc, MaxMoney ld a, $3 call CompareMoney jr z, .asm_15ff5 jr c, .asm_15ff5 ld hl, MaxMoney ld a, [hli] ld [de], a inc de ld a, [hli] ld [de], a inc de ld a, [hli] ld [de], a scf ret .asm_15ff5 and a ret ; 15ff7 MaxMoney: ; 15ff7 dt 999999 ; 15ffa TakeMoney:: ; 15ffa ld a, 3 call SubtractMoney jr nc, .asm_16009 xor a ld [de], a inc de ld [de], a inc de ld [de], a scf ret .asm_16009 and a ret ; 1600b CompareMoney:: ; 1600b ld a, $3 CompareFunds: ; 1600d push hl push de push bc ld h, b ld l, c ld c, $0 ld b, a .loop1 dec a jr z, .done inc de inc hl jr .loop1 .done and a .loop2 ld a, [de] sbc [hl] jr z, .okay inc c .okay dec de dec hl dec b jr nz, .loop2 jr c, .set_carry ld a, c and a jr .skip_carry .set_carry ld a, $1 and a scf .skip_carry pop bc pop de pop hl ret ; 16035 SubtractMoney: ; 16035 ld a, 3 SubtractFunds: ; 16037 push hl push de push bc ld h, b ld l, c ld b, a ld c, 0 .loop dec a jr z, .done inc de inc hl jr .loop .done and a .loop2 ld a, [de] sbc [hl] ld [de], a dec de dec hl dec b jr nz, .loop2 pop bc pop de pop hl ret ; 16053 AddMoney: ; 16053 ld a, $3 AddFunds: ; 16055 push hl push de push bc ld h, b ld l, c ld b, a .loop1 dec a jr z, .done inc de inc hl jr .loop1 .done and a .loop2 ld a, [de] adc [hl] ld [de], a dec de dec hl dec b jr nz, .loop2 pop bc pop de pop hl ret ; 1606f GiveCoins:: ; 1606f ld a, 2 ld de, Coins call AddFunds ld a, 2 ld bc, .maxcoins call CompareFunds jr c, .not_maxed ld hl, .maxcoins ld a, [hli] ld [de], a inc de ld a, [hli] ld [de], a scf ret .not_maxed and a ret ; 1608d .maxcoins: ; 1608d bigdw 9999 ; 1608f TakeCoins:: ; 1608f ld a, 2 ld de, Coins call SubtractFunds jr nc, .asm_1609f xor a ld [de], a inc de ld [de], a scf ret .asm_1609f and a ret ; 160a1 CheckCoins:: ; 160a1 ld a, $2 ld de, Coins jp CompareFunds ; 160a9