fix conv.str_ub and conv.str_b for missing tens digits

This commit is contained in:
Irmen de Jong
2024-03-13 22:33:25 +01:00
parent 1fc79ff6dd
commit 7e1e7a0780
2 changed files with 60 additions and 45 deletions

View File

@@ -28,30 +28,29 @@ asmsub str_ub (ubyte value @ A) clobbers(X) -> str @AY {
%asm {{ %asm {{
ldy #0 ldy #0
sty P8ZP_SCRATCH_B1 sty P8ZP_SCRATCH_B1
jsr conv.ubyte2decimal jsr ubyte2decimal ; result in Y/A/X (100s, 10s, 1s).
_output_byte_digits
; hundreds? ; hundreds?
cpy #'0' cpy #'0'
beq + beq +
pha sty string_out
tya sta string_out+1
ldy P8ZP_SCRATCH_B1 stx string_out+2
sta string_out,y lda #0
pla sta string_out+3
inc P8ZP_SCRATCH_B1 jmp _done
; tens? ; tens?
+ ldy P8ZP_SCRATCH_B1 + cmp #'0'
cmp #'0'
beq + beq +
sta string_out,y sta string_out
iny stx string_out+1
lda #0
sta string_out+2
jmp _done
+ ; ones. + ; ones.
txa stx string_out
sta string_out,y lda #0
iny sta string_out+1
lda #0 _done lda #<string_out
sta string_out,y
lda #<string_out
ldy #>string_out ldy #>string_out
rts rts
}} }}
@@ -60,17 +59,39 @@ _output_byte_digits
asmsub str_b (byte value @ A) clobbers(X) -> str @AY { asmsub str_b (byte value @ A) clobbers(X) -> str @AY {
; ---- convert the byte in A in decimal string form, without left padding 0s ; ---- convert the byte in A in decimal string form, without left padding 0s
%asm {{ %asm {{
ldy #0 ldy #0
sty P8ZP_SCRATCH_B1
cmp #0 cmp #0
bpl + bpl +
pha ldy #'-'
lda #'-' sty string_out
sta string_out ldy #1
inc P8ZP_SCRATCH_B1 + sty P8ZP_SCRATCH_REG
pla jsr conv.byte2decimal ; result in Y/A/X (100s, 10s, 1s). and in uword2decimal.decHundreds, decTens, decOnes.
+ jsr conv.byte2decimal ; hundreds?
bra str_ub._output_byte_digits cpy #'0'
bne _out_hundreds
ldy P8ZP_SCRATCH_REG
cmp #'0'
bne _out_tens
beq _out_ones
_out_hundreds
ldy P8ZP_SCRATCH_REG
lda uword2decimal.decHundreds
sta string_out,y
iny
_out_tens
lda uword2decimal.decTens
sta string_out,y
iny
_out_ones
lda uword2decimal.decOnes
sta string_out,y
iny
lda #0
sta string_out,y
lda #<string_out
ldy #>string_out
rts
}} }}
} }

View File

@@ -1,27 +1,21 @@
; conv_bug.p8
%import textio %import textio
%import conv
%zeropage basicsafe %zeropage basicsafe
%option no_sysinit %option no_sysinit
main { main {
sub start() { sub start() {
uword[3] uwarray = [1111,2222,3333] ubyte num8 = 99
uword[3] @split uwarray_s = [1111,2222,3333] ubyte i
ubyte[3] array = [11,22,33] ubyte jj = 99
rol(array[1])
array[1] <<=1
ror(array[1])
array[1] >>=1
rol(uwarray[1])
uwarray[1] <<=1
ror(uwarray[1])
uwarray[1] >>=1
rol(uwarray_s[1])
uwarray_s[1] *=3
ror(uwarray_s[1])
uwarray_s[1] *=3
for i in 0 to 255 {
txt.print(conv.str_ub(i))
txt.spc()
txt.print(conv.str_b(i as byte))
txt.chrout(';')
txt.nl()
}
} }
} }