2019-11-18 13:40:23 -05:00
|
|
|
|
2019-11-23 14:56:23 -05:00
|
|
|
; Same as fmtDecimal, but DE is considered a signed number
|
|
|
|
fmtDecimalS:
|
|
|
|
bit 7, d
|
|
|
|
jr z, fmtDecimal ; unset, not negative
|
|
|
|
; Invert DE. spit '-', unset bit, then call fmtDecimal
|
|
|
|
push de
|
|
|
|
ld a, '-'
|
|
|
|
ld (hl), a
|
|
|
|
inc hl
|
|
|
|
ld a, d
|
|
|
|
cpl
|
|
|
|
ld d, a
|
|
|
|
ld a, e
|
|
|
|
cpl
|
|
|
|
ld e, a
|
|
|
|
inc de
|
|
|
|
call fmtDecimal
|
|
|
|
dec hl
|
|
|
|
pop de
|
|
|
|
ret
|
|
|
|
|
2019-11-18 13:40:23 -05:00
|
|
|
; Format the number in DE into the string at (HL) in a decimal form.
|
|
|
|
; Null-terminated. DE is considered an unsigned number.
|
|
|
|
fmtDecimal:
|
|
|
|
push ix
|
|
|
|
push hl
|
|
|
|
push de
|
|
|
|
push af
|
|
|
|
|
|
|
|
push hl \ pop ix
|
|
|
|
ex de, hl ; orig number now in HL
|
|
|
|
ld e, 0
|
|
|
|
.loop1:
|
|
|
|
call .div10
|
|
|
|
push hl ; push remainder. --> lvl E
|
|
|
|
inc e
|
|
|
|
ld a, b ; result 0?
|
|
|
|
or c
|
|
|
|
push bc \ pop hl
|
|
|
|
jr nz, .loop1 ; not zero, continue
|
|
|
|
; We now have C digits to print in the stack.
|
|
|
|
; Spit them!
|
|
|
|
push ix \ pop hl ; restore orig HL.
|
|
|
|
ld b, e
|
|
|
|
.loop2:
|
|
|
|
pop de ; <-- lvl E
|
|
|
|
ld a, '0'
|
|
|
|
add a, e
|
|
|
|
ld (hl), a
|
|
|
|
inc hl
|
|
|
|
djnz .loop2
|
|
|
|
|
|
|
|
; null terminate
|
|
|
|
xor a
|
|
|
|
ld (hl), a
|
|
|
|
pop af
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
pop ix
|
|
|
|
ret
|
|
|
|
.div10:
|
|
|
|
push de
|
|
|
|
ld de, 0x000a
|
|
|
|
call divide
|
|
|
|
pop de
|
|
|
|
ret
|