added more convenient number-to-string functions to conv library

This commit is contained in:
Irmen de Jong 2021-03-06 13:47:27 +01:00
parent 076a547f91
commit de04bd8cfa
3 changed files with 34 additions and 31 deletions

View File

@ -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
}}
}

View File

@ -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)

View File

@ -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()
}
}