Skip to content

Instantly share code, notes, and snippets.

@jacobly0
Last active January 18, 2019 16:25
Show Gist options
  • Save jacobly0/0d4ae865187a88cc4a42 to your computer and use it in GitHub Desktop.
Save jacobly0/0d4ae865187a88cc4a42 to your computer and use it in GitHub Desktop.
Displays a 16.8 fixed point number.
call AbsDE
ld hl, OP1
jp m, Positive
ld (hl), $1a
inc hl
Positive:
ex de, hl
push hl
push af
inc sp
inc sp
push hl
inc sp
pop hl
ld a, $8c
ld bc, -10000 << 1
call Digit
ld bc, -1000 << 3
call Digit
ld bc, -100 << 3
call Digit
ld bc, -10 << 3
call Digit
ld bc, -1 << 3
call Digit
ex de, hl
ld (hl), '.'
inc hl
pop de
ld b, 2
Loop:
ld d, 10
mlt de
ld a, '0'
add a, d
ld (hl), a
inc hl
djnz Loop
ld (hl), b
bit 7, e
ret z
_: dec hl
ld a, (hl)
cp '.'
jr z, -_
inc (hl)
cp '9'
ret nz
ld (hl), '0'
jr -_
DigitLoop:
rr b
rr c
Digit:
add hl, bc
jr c, DigitSkip
sbc hl, bc
DigitSkip:
rla
jr c, DigitLoop
ld (de), a
inc de
ld a, $e3
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment