;;******************************************************************************** ;; @module string ;; @type utility ;; @details ;; String utility ;;******************************************************************************** .ifndef INCLUDE_STRING INCLUDE_STRING = 1 .include "system/system.h65" .scope str Import str, strf Import str, hex_char_to_uint8, hex_str_to_uint Import str, uint8_to_hex_str, uint_to_hex_str .macro _StrfStoreArg arg .if (.not .blank(arg)) .if .match(arg, x) stx ARG4 + @N_ARGS .elseif .match(arg, y) sty ARG4 + @N_ARGS .else lda arg sta ARG4 + @N_ARGS .endif @N_ARGS .set (@N_ARGS + 1) .endif .endmacro ;;******************************************************************************** ;; @function Macro for passing arguments to strf ;; @param fmt: Format string address or string literal ;; @param out: Output string address ;; @param x0-x9: Additional parameters ;; @warning Addresses as additional paramters must be passed like this `#addr` ;; @modifies: A, X, Y, ARG4, ARG5 ;; @see strf ;;******************************************************************************** .macro Strf fmt,out,x0,x1,x2,x3,x4,x5,x6,x7,x8,x9 @N_ARGS .set 0 ; @ so that it doesnt break cheap labels .if .match(fmt, "") ; fmt is a string literal -> store in rodata .pushseg .rodata : .asciiz fmt .popseg lda #<:- sta ARG0 lda #>:- sta ARG1 .else ; message is not a string lda #fmt sta ARG1 .endif lda #out sta ARG3 _StrfStoreArg x0 _StrfStoreArg x1 _StrfStoreArg x2 _StrfStoreArg x3 _StrfStoreArg x4 _StrfStoreArg x5 _StrfStoreArg x6 _StrfStoreArg x7 _StrfStoreArg x8 _StrfStoreArg x9 jsr str::strf ; .out .sprintf("info: Strf: called with %d arguments", @N_ARGS) .endmacro .endscope .endif ; guard