diff --git a/compiler/res/prog8lib/conv.p8 b/compiler/res/prog8lib/conv.p8 index f039245fb..5353f5692 100644 --- a/compiler/res/prog8lib/conv.p8 +++ b/compiler/res/prog8lib/conv.p8 @@ -31,7 +31,7 @@ asmsub str_ub (ubyte value @ A) clobbers(A,Y) { ldy #0 sty P8ZP_SCRATCH_B1 jsr conv.ubyte2decimal -_print_byte_digits +_output_byte_digits ; hundreds? cpy #'0' beq + @@ -72,7 +72,7 @@ asmsub str_b (byte value @ A) clobbers(A,Y) { inc P8ZP_SCRATCH_B1 pla + jsr conv.byte2decimal - bra str_ub._print_byte_digits + bra str_ub._output_byte_digits }} } @@ -167,8 +167,9 @@ asmsub str_uw (uword value @ AY) clobbers(A,Y) { %asm {{ phx jsr conv.uword2decimal - ldy #0 ldx #0 +_output_digits + ldy #0 - lda conv.uword2decimal.decTenThousands,y beq _allzero cmp #'0' @@ -195,22 +196,24 @@ _allzero lda #'0' asmsub str_w (word value @ AY) clobbers(A,Y) { ; ---- convert the (signed) word in A/Y in decimal string form, without left padding 0's %asm {{ - rts -; cpy #0 -; bpl + -; pha -; lda #'-' -; jsr c64.CHROUT -; tya -; eor #255 -; tay -; pla -; eor #255 -; clc -; adc #1 -; bcc + -; iny -;+ bra print_uw + cpy #0 + bpl str_uw + phx + pha + lda #'-' + sta string_out + tya + eor #255 + tay + pla + eor #255 + clc + adc #1 + bcc + + iny ++ jsr conv.uword2decimal + ldx #1 + bne str_uw._output_digits }} } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 5cfa2849e..1d0879009 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,7 +2,6 @@ TODO ==== -- add more convenient number-to-string conversion routines to conv (and clean up the number printing routine in the blobs example?) - add a warning if not using basicsafe and main.start ends with a rts - optimize assigning array and struct variables (multi-element assings -> memcopy) diff --git a/examples/test.p8 b/examples/test.p8 index c906b7c52..2c82b2c2b 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -90,16 +90,17 @@ main { txt.nl() txt.nl() -; conv.str_w(ww) -; txt.print(conv.string_out) -; txt.nl() -; txt.print_w(ww) -; txt.nl() -; conv.str_uw(7) -; txt.print(conv.string_out) -; txt.nl() -; txt.print_uw(7) -; txt.nl() -; txt.nl() + conv.str_w(ww) + txt.print(conv.string_out) + txt.nl() + txt.print_w(ww) + txt.nl() + txt.nl() + + conv.str_w(99) + txt.print(conv.string_out) + txt.nl() + txt.print_w(99) + txt.nl() } }