2023-09-02 14:16:35 -07:00
|
|
|
GiveCoins::
|
2016-01-04 05:43:55 -08:00
|
|
|
ld a, 3
|
2023-09-02 14:16:35 -07:00
|
|
|
call AddCoins
|
2023-12-24 09:42:07 -08:00
|
|
|
call LoadMaxCoins_bc
|
2016-01-04 05:43:55 -08:00
|
|
|
ld a, 3
|
2023-09-02 14:16:35 -07:00
|
|
|
call CompareCoins
|
2016-01-04 05:43:55 -08:00
|
|
|
jr z, .not_maxed_out
|
|
|
|
jr c, .not_maxed_out
|
2023-12-24 09:42:07 -08:00
|
|
|
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
|
|
|
|
|
2023-12-24 09:42:07 -08:00
|
|
|
LoadMaxCoins_bc:
|
|
|
|
ld a, d
|
|
|
|
cp HIGH(wCurLevelCoins)
|
|
|
|
ld bc, MaxCurLevelCoins ; CUR_LEVEL_COINS
|
|
|
|
ret z
|
|
|
|
ld bc, MaxCoins ; YOUR_COINS or MOMS_COINS
|
|
|
|
ret
|
|
|
|
|
|
|
|
LoadMaxCoins_hl:
|
|
|
|
call LoadMaxCoins_bc
|
|
|
|
ld h, b
|
|
|
|
ld l, c
|
|
|
|
ret
|
|
|
|
|
2023-09-02 14:16:35 -07:00
|
|
|
MaxCoins:
|
|
|
|
dt MAX_COINS
|
2015-11-16 18:46:36 -08:00
|
|
|
|
2023-12-24 09:42:07 -08:00
|
|
|
MaxCurLevelCoins:
|
|
|
|
dt MAX_LEVEL_COINS
|
|
|
|
|
2023-09-02 14:16:35 -07:00
|
|
|
TakeCoins::
|
2015-11-16 18:46:36 -08:00
|
|
|
ld a, 3
|
2023-09-02 14:16:35 -07:00
|
|
|
call SubtractCoins
|
2016-01-04 05:43:55 -08:00
|
|
|
jr nc, .okay
|
2023-09-02 14:16:35 -07:00
|
|
|
; 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
|
|
|
|
|
2023-09-02 14:16:35 -07:00
|
|
|
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
|
|
|
|
|
2023-09-02 14:16:35 -07:00
|
|
|
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
|
|
|
|
|
2023-09-02 14:16:35 -07:00
|
|
|
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
|
|
|
|
|
2023-09-02 09:23:25 -07:00
|
|
|
GiveChips::
|
2015-11-16 18:46:36 -08:00
|
|
|
ld a, 2
|
2023-09-02 09:23:25 -07:00
|
|
|
ld de, wChips
|
2015-11-16 18:46:36 -08:00
|
|
|
call AddFunds
|
|
|
|
ld a, 2
|
2023-09-02 09:23:25 -07:00
|
|
|
ld bc, .maxchips
|
2015-11-16 18:46:36 -08:00
|
|
|
call CompareFunds
|
|
|
|
jr c, .not_maxed
|
2023-09-02 09:23:25 -07:00
|
|
|
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
|
|
|
|
|
2023-09-02 09:23:25 -07:00
|
|
|
.maxchips
|
|
|
|
bigdw MAX_CHIPS
|
2015-11-16 18:46:36 -08:00
|
|
|
|
2023-09-02 09:23:25 -07:00
|
|
|
TakeChips::
|
2015-11-16 18:46:36 -08:00
|
|
|
ld a, 2
|
2023-09-02 09:23:25 -07:00
|
|
|
ld de, wChips
|
2015-11-16 18:46:36 -08:00
|
|
|
call SubtractFunds
|
2016-01-04 05:43:55 -08:00
|
|
|
jr nc, .okay
|
2023-09-02 09:23:25 -07:00
|
|
|
; 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
|
|
|
|
|
2023-09-02 09:23:25 -07:00
|
|
|
CheckChips::
|
2016-01-04 05:43:55 -08:00
|
|
|
ld a, 2
|
2023-09-02 09:23:25 -07:00
|
|
|
ld de, wChips
|
2015-11-16 18:46:36 -08:00
|
|
|
jp CompareFunds
|