2018-06-24 14:09:41 +00:00
|
|
|
GiveMoney::
|
2016-01-04 13:43:55 +00:00
|
|
|
ld a, 3
|
2015-11-17 02:46:36 +00:00
|
|
|
call AddMoney
|
|
|
|
ld bc, MaxMoney
|
2016-01-04 13:43:55 +00:00
|
|
|
ld a, 3
|
2015-11-17 02:46:36 +00:00
|
|
|
call CompareMoney
|
2016-01-04 13:43:55 +00:00
|
|
|
jr z, .not_maxed_out
|
|
|
|
jr c, .not_maxed_out
|
2015-11-17 02:46:36 +00:00
|
|
|
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
|
|
|
|
|
2016-01-04 13:43:55 +00:00
|
|
|
.not_maxed_out
|
2015-11-17 02:46:36 +00:00
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
MaxMoney:
|
2017-12-25 00:35:35 +00:00
|
|
|
dt MAX_MONEY
|
2015-11-17 02:46:36 +00:00
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
TakeMoney::
|
2015-11-17 02:46:36 +00:00
|
|
|
ld a, 3
|
|
|
|
call SubtractMoney
|
2016-01-04 13:43:55 +00:00
|
|
|
jr nc, .okay
|
|
|
|
; leave with 0 money
|
2015-11-17 02:46:36 +00:00
|
|
|
xor a
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
ld [de], a
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2016-01-04 13:43:55 +00:00
|
|
|
.okay
|
2015-11-17 02:46:36 +00:00
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CompareMoney::
|
2016-01-04 13:43:55 +00:00
|
|
|
ld a, 3
|
2018-06-24 14:09:41 +00:00
|
|
|
CompareFunds:
|
2016-01-04 13:43:55 +00:00
|
|
|
; a: number of bytes
|
|
|
|
; bc: start addr of amount (big-endian)
|
|
|
|
; de: start addr of account (big-endian)
|
2015-11-17 02:46:36 +00:00
|
|
|
push hl
|
|
|
|
push de
|
|
|
|
push bc
|
|
|
|
ld h, b
|
|
|
|
ld l, c
|
2016-01-04 13:43:55 +00:00
|
|
|
ld c, 0
|
2015-11-17 02:46:36 +00: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 21:28:22 +00:00
|
|
|
ld a, 1
|
2015-11-17 02:46:36 +00:00
|
|
|
and a
|
|
|
|
scf
|
|
|
|
.skip_carry
|
|
|
|
pop bc
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
SubtractMoney:
|
2015-11-17 02:46:36 +00:00
|
|
|
ld a, 3
|
2018-06-24 14:09:41 +00:00
|
|
|
SubtractFunds:
|
2016-01-04 13:43:55 +00:00
|
|
|
; a: number of bytes
|
|
|
|
; bc: start addr of amount (big-endian)
|
|
|
|
; de: start addr of account (big-endian)
|
2015-11-17 02:46:36 +00: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
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
AddMoney:
|
2016-01-04 13:43:55 +00:00
|
|
|
ld a, 3
|
2018-06-24 14:09:41 +00:00
|
|
|
AddFunds:
|
2016-01-04 13:43:55 +00:00
|
|
|
; a: number of bytes
|
|
|
|
; bc: start addr of amount (big-endian)
|
|
|
|
; de: start addr of account (big-endian)
|
2015-11-17 02:46:36 +00:00
|
|
|
push hl
|
|
|
|
push de
|
|
|
|
push bc
|
2016-01-04 13:43:55 +00:00
|
|
|
|
2015-11-17 02:46:36 +00: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 13:43:55 +00:00
|
|
|
|
2015-11-17 02:46:36 +00:00
|
|
|
pop bc
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
GiveCoins::
|
2015-11-17 02:46:36 +00:00
|
|
|
ld a, 2
|
2018-01-23 21:45:34 +00:00
|
|
|
ld de, wCoins
|
2015-11-17 02:46:36 +00:00
|
|
|
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
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
.maxcoins
|
2017-12-25 00:35:35 +00:00
|
|
|
bigdw MAX_COINS
|
2015-11-17 02:46:36 +00:00
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
TakeCoins::
|
2015-11-17 02:46:36 +00:00
|
|
|
ld a, 2
|
2018-01-23 21:45:34 +00:00
|
|
|
ld de, wCoins
|
2015-11-17 02:46:36 +00:00
|
|
|
call SubtractFunds
|
2016-01-04 13:43:55 +00:00
|
|
|
jr nc, .okay
|
|
|
|
; leave with 0 coins
|
2015-11-17 02:46:36 +00:00
|
|
|
xor a
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
ld [de], a
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2016-01-04 13:43:55 +00:00
|
|
|
.okay
|
2015-11-17 02:46:36 +00:00
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CheckCoins::
|
2016-01-04 13:43:55 +00:00
|
|
|
ld a, 2
|
2018-01-23 21:45:34 +00:00
|
|
|
ld de, wCoins
|
2015-11-17 02:46:36 +00:00
|
|
|
jp CompareFunds
|