diff --git a/spicode.s65 b/spicode.s65 index ba1bb66..0a9da16 100644 --- a/spicode.s65 +++ b/spicode.s65 @@ -34,9 +34,11 @@ CODE_START: fmt_idx = $30 out_idx = $31 +fmt_digit = $32 .proc strf stz out_idx stz fmt_idx + stz fmt_digit ldx #0 ; index of format args @loop: ldy fmt_idx @@ -57,9 +59,31 @@ out_idx = $31 lda (ARG0),y ; next char beq @null ; formats + cmp #'9' + ble @percent_number ; numbers < letters cmp #'x' beq @format_hex1 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 lda ARG4,x phx @@ -112,6 +136,17 @@ out_idx = $31 rts .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