wip char_to_hex

This commit is contained in:
Matthias@Dell 2023-12-10 12:10:55 +01:00
parent 2c41506765
commit 8b8a94e2e7

View File

@ -34,9 +34,11 @@ CODE_START:
fmt_idx = $30 fmt_idx = $30
out_idx = $31 out_idx = $31
fmt_digit = $32
.proc strf .proc strf
stz out_idx stz out_idx
stz fmt_idx stz fmt_idx
stz fmt_digit
ldx #0 ; index of format args ldx #0 ; index of format args
@loop: @loop:
ldy fmt_idx ldy fmt_idx
@ -57,9 +59,31 @@ out_idx = $31
lda (ARG0),y ; next char lda (ARG0),y ; next char
beq @null beq @null
; formats ; formats
cmp #'9'
ble @percent_number ; numbers < letters
cmp #'x' cmp #'x'
beq @format_hex1 beq @format_hex1
bra @normal_char bra @normal_char
@percent_number:
cmp #'1'
blt @normal_char ; NaN or zero
; todo covert from char
jsr hex_char_to_int ; only 0-9 supported
; A is now number of digits to convert
sta fmt_digit
iny
sty fmt_idx
lda (ARG0),y ; next char
beq @null
cmp #'x'
beq @format_hexN
bra @normal_char
@format_hexN:
lda fmt_digit
jsr int_to_hex_str
bra @format_return
@format_hex1: ; 1 byte hex -> 2 chars @format_hex1: ; 1 byte hex -> 2 chars
lda ARG4,x lda ARG4,x
phx phx
@ -112,6 +136,17 @@ out_idx = $31
rts rts
.endproc .endproc
; todo error handling
.proc hex_char_to_int
cmp #'A'
bge @char
sbc #'0'
rts
@char:
sbc #('A' - $A)
rts
.endproc
;******************************************************************************** ;********************************************************************************
; @function Convert any int into hex ; @function Convert any int into hex