2023-12-23 14:18:15 +01:00
|
|
|
;;********************************************************************************
|
|
|
|
;; @module string
|
|
|
|
;; @type utility
|
|
|
|
;; @details
|
|
|
|
;; String utility
|
|
|
|
;;********************************************************************************
|
2023-12-08 22:56:35 +01:00
|
|
|
.ifndef INCLUDE_STRING
|
|
|
|
INCLUDE_STRING = 1
|
|
|
|
|
|
|
|
.include "system/system.h65"
|
|
|
|
|
|
|
|
|
2024-08-08 00:11:15 +02:00
|
|
|
;;********************************************************************************
|
|
|
|
;; @brief String utility
|
|
|
|
;;********************************************************************************
|
2023-12-08 22:56:35 +01:00
|
|
|
.scope str
|
2023-12-31 01:57:05 +01:00
|
|
|
Import str, strf, printf_buffer
|
2023-12-27 16:56:14 +01:00
|
|
|
Import str, hex_char_to_uint8, hex_str_to_uint
|
|
|
|
Import str, uint8_to_hex_str, uint_to_hex_str
|
2023-12-08 22:56:35 +01:00
|
|
|
|
|
|
|
|
2024-08-08 00:11:15 +02:00
|
|
|
;;********************************************************************************
|
|
|
|
;; @macro Helper for str::Strf macro
|
|
|
|
;; @details
|
|
|
|
;; Store arg in ARG4-ARG... and increment counter variable @N_ARGS one.
|
|
|
|
;; Arg can be x, y, immediate or an address
|
|
|
|
;;********************************************************************************
|
2023-12-08 22:56:35 +01:00
|
|
|
.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
|
|
|
|
|
2023-12-23 14:18:15 +01:00
|
|
|
;;********************************************************************************
|
2024-08-08 00:11:15 +02:00
|
|
|
;; @macro Macro for passing arguments to strf
|
2023-12-23 14:18:15 +01:00
|
|
|
;; @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,#>addr`
|
2023-12-27 16:56:14 +01:00
|
|
|
;; @modifies: A, X, Y, ARG4, ARG5
|
2024-08-08 00:11:15 +02:00
|
|
|
;; @see str::strf
|
2023-12-23 14:18:15 +01:00
|
|
|
;;********************************************************************************
|
2023-12-08 22:56:35 +01:00
|
|
|
.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
|
2023-12-21 17:27:54 +01:00
|
|
|
.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 ARG0
|
|
|
|
lda #>fmt
|
|
|
|
sta ARG1
|
|
|
|
.endif
|
2023-12-08 22:56:35 +01:00
|
|
|
lda #<out
|
|
|
|
sta ARG2
|
|
|
|
lda #>out
|
|
|
|
sta ARG3
|
|
|
|
_StrfStoreArg x0
|
|
|
|
_StrfStoreArg x1
|
|
|
|
_StrfStoreArg x2
|
|
|
|
_StrfStoreArg x3
|
|
|
|
_StrfStoreArg x4
|
|
|
|
_StrfStoreArg x5
|
|
|
|
_StrfStoreArg x6
|
|
|
|
_StrfStoreArg x7
|
2023-12-21 17:27:54 +01:00
|
|
|
_StrfStoreArg x8
|
|
|
|
_StrfStoreArg x9
|
2023-12-08 22:56:35 +01:00
|
|
|
jsr str::strf
|
2023-12-21 17:27:54 +01:00
|
|
|
; .out .sprintf("info: Strf: called with %d arguments", @N_ARGS)
|
2023-12-08 22:56:35 +01:00
|
|
|
.endmacro
|
|
|
|
|
2024-08-08 00:11:15 +02:00
|
|
|
;;********************************************************************************
|
|
|
|
;; @function Macro for formated printing
|
|
|
|
;; @details
|
|
|
|
;; Pass all arguments to str::Strf macro, then call lcd::PrintNC macro
|
|
|
|
;; @see str::strf
|
|
|
|
;;********************************************************************************
|
2023-12-31 01:57:05 +01:00
|
|
|
.macro Printf fmt,x0,x1,x2,x3,x4,x5,x6,x7,x8,x9
|
|
|
|
Strf fmt,str::printf_buffer,x0,x1,x2,x3,x4,x5,x6,x7,x8,x9
|
|
|
|
PrintNC str::printf_buffer
|
|
|
|
.endmacro
|
|
|
|
|
2023-12-08 22:56:35 +01:00
|
|
|
.endscope
|
|
|
|
.endif ; guard
|