From f5c61bb3b4e179d16af32c6b4c28f18b6e70e099 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 23 Aug 2025 07:43:53 +0200 Subject: [PATCH] strings: Added decimal printing --- src/strings.s | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/strings.s b/src/strings.s index edb2302..d43a961 100644 --- a/src/strings.s +++ b/src/strings.s @@ -81,12 +81,58 @@ puts: jr puts REL @done: ret - + + ; counts how many times + ; a number fits into n + ; inputs: + ; a: a number + ; $1: factor + ; returns: + ; b: count +#macro putn_count +.beginscope + ld b, 0 +@again: + cp a, $1 + jr z, @done REL + jr c, @done REL + sub a, $1 + inc b + jr @again REL +@done: +.endscope +#endmacro + ; prints a number in decimal ; input: ; de: tile location ; a: the value putn: + putn_count 100 + ; print 100s if > 0 + push af + ld a, b + cp a, 0 + jr z, @skip_100s REL + add a, FONT_OFFSET+1 + ld [de], a + inc de +@skip_100s: + pop af + + putn_count 10 + ; print 10s if > 0 + push af + ld a, b + cp a, 0 + jr z, @skip_10s REL + add a, FONT_OFFSET+1 + ld [de], a + inc de +@skip_10s: + pop af + + ; print remainder add a, FONT_OFFSET+1 ld [de], a ret -- 2.30.2