pokecrystal-board/engine/events/coins.asm

227 lines
2.4 KiB
NASM
Raw Normal View History

GiveCoins::
2016-01-04 05:43:55 -08:00
ld a, 3
call AddCoins
call LoadMaxCoins_bc
2016-01-04 05:43:55 -08:00
ld a, 3
call CompareCoins
2016-01-04 05:43:55 -08:00
jr z, .not_maxed_out
jr c, .not_maxed_out
call LoadMaxCoins_hl
2015-11-16 18:46:36 -08:00
ld a, [hli]
ld [de], a
inc de
ld a, [hli]
ld [de], a
inc de
ld a, [hli]
ld [de], a
scf
ret
2016-01-04 05:43:55 -08:00
.not_maxed_out
2015-11-16 18:46:36 -08:00
and a
ret
LoadMaxCoins_bc:
ld a, d
cp HIGH(wCurLevelCoins)
ld bc, MaxCurLevelCoins ; CUR_LEVEL_COINS
ret z
ld bc, MaxCoins ; YOUR_COINS
ret
LoadMaxCoins_hl:
call LoadMaxCoins_bc
ld h, b
ld l, c
ret
MaxCoins:
dt MAX_COINS
2015-11-16 18:46:36 -08:00
MaxCurLevelCoins:
dt MAX_LEVEL_COINS
TakeCoins::
2015-11-16 18:46:36 -08:00
ld a, 3
call SubtractCoins
2016-01-04 05:43:55 -08:00
jr nc, .okay
; leave with 0 coins
2015-11-16 18:46:36 -08:00
xor a
ld [de], a
inc de
ld [de], a
inc de
ld [de], a
scf
ret
2016-01-04 05:43:55 -08:00
.okay
2015-11-16 18:46:36 -08:00
and a
ret
CompareCoins::
2016-01-04 05:43:55 -08:00
ld a, 3
2018-06-24 07:09:41 -07:00
CompareFunds:
2016-01-04 05:43:55 -08:00
; a: number of bytes
; bc: start addr of amount (big-endian)
; de: start addr of account (big-endian)
2015-11-16 18:46:36 -08:00
push hl
push de
push bc
ld h, b
ld l, c
2016-01-04 05:43:55 -08:00
ld c, 0
2015-11-16 18:46:36 -08:00
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
2016-01-09 13:28:22 -08:00
ld a, 1
2015-11-16 18:46:36 -08:00
and a
scf
.skip_carry
pop bc
pop de
pop hl
ret
SubtractCoins:
2015-11-16 18:46:36 -08:00
ld a, 3
2018-06-24 07:09:41 -07:00
SubtractFunds:
2016-01-04 05:43:55 -08:00
; a: number of bytes
; bc: start addr of amount (big-endian)
; de: start addr of account (big-endian)
2015-11-16 18:46:36 -08:00
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
AddCoins:
2016-01-04 05:43:55 -08:00
ld a, 3
2018-06-24 07:09:41 -07:00
AddFunds:
2016-01-04 05:43:55 -08:00
; a: number of bytes
; bc: start addr of amount (big-endian)
; de: start addr of account (big-endian)
2015-11-16 18:46:36 -08:00
push hl
push de
push bc
2016-01-04 05:43:55 -08:00
2015-11-16 18:46:36 -08:00
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
2016-01-04 05:43:55 -08:00
2015-11-16 18:46:36 -08:00
pop bc
pop de
pop hl
ret
GiveChips::
2015-11-16 18:46:36 -08:00
ld a, 2
ld de, wChips
2015-11-16 18:46:36 -08:00
call AddFunds
ld a, 2
ld bc, .maxchips
2015-11-16 18:46:36 -08:00
call CompareFunds
jr c, .not_maxed
ld hl, .maxchips
2015-11-16 18:46:36 -08:00
ld a, [hli]
ld [de], a
inc de
ld a, [hli]
ld [de], a
scf
ret
.not_maxed
and a
ret
.maxchips
bigdw MAX_CHIPS
2015-11-16 18:46:36 -08:00
TakeChips::
2015-11-16 18:46:36 -08:00
ld a, 2
ld de, wChips
2015-11-16 18:46:36 -08:00
call SubtractFunds
2016-01-04 05:43:55 -08:00
jr nc, .okay
; leave with 0 chips
2015-11-16 18:46:36 -08:00
xor a
ld [de], a
inc de
ld [de], a
scf
ret
2016-01-04 05:43:55 -08:00
.okay
2015-11-16 18:46:36 -08:00
and a
ret
CheckChips::
2016-01-04 05:43:55 -08:00
ld a, 2
ld de, wChips
2015-11-16 18:46:36 -08:00
jp CompareFunds