Skip to content

Instantly share code, notes, and snippets.

@reidrac
Created October 5, 2017 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reidrac/80fd055cea3a9c7b30ba86a919209936 to your computer and use it in GitHub Desktop.
Save reidrac/80fd055cea3a9c7b30ba86a919209936 to your computer and use it in GitHub Desktop.
void pad_numbers8(uint8_t *s, uint8_t limit, uint8_t number)
{
/*
s += limit;
*s = 0;
do
{
limit--;
*--s = (number % 10) + '0';
number /= 10;
} while (limit);
*/
__asm
ld hl, #4
add hl, sp
ld b, #0
ld c, (hl)
dec hl
ld d, (hl)
dec hl
ld e, (hl)
ld hl, #5
add hl, sp
ld a, (hl) ; number
ex de, hl
add hl, bc ; s+ = limit
ld (hl), #0
ld b, c ; limit
ld c, a ; number
pad_numbers8_loop:
dec hl
; mod
ld a, c
ld de, #0x05a0
mod_loop:
sub e
jr nc, skip_mod_add
add a, e
skip_mod_add:
srl e
dec d
jr nz, mod_loop
add a, #0x30 ; (number mod 10) + '0'
ld (hl), a ; store in *s
push hl
ld d, #0
ld e, c
ld h, d
ld l, e
add hl, hl
add hl, de
add hl, hl
add hl, hl
add hl, de
add hl, hl
ld c, h ; number /= 10
pop hl
djnz pad_numbers8_loop
__endasm;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment