I'm not aware of a
good way, but personally I've used a macro that outputs the value in a special "build log" segment, which is then directed to a separate file in the linker configuration. Note that since we don't know the value of the variable, we always have to output a constant number of characters and pad it from the left with spaces or zeros. You can of course also output explanatory strings with
.byte in the build log segment.
Here's the macro: (
https://github.com/fo-fo/ngin/blob/mast ... e.inc#L409)
Code:
.macro __ngin_decimalInteger integer
.local divider
divider .set 100000000
.local value
value = integer
; \note .charmap isn't a problem here, because string/character literals
; are not used.
; \todo This doesn't seem to work properly for signed numbers (try
; e.g. $FFFFFFFF).
.repeat 9, i
; Output the corresponding digit, or a space if the digit and all the
; more significant digits are zeroes. Unless we're outputting the least
; significant digit, which is always displayed (so that 0 is displayed).
.byte .lobyte( __ngin_choice \
(value/divider) <> 0 .or divider = 1, \
(value/divider) .mod 10 + ngin_Ascii::kZero, \
ngin_Ascii::kSpace )
divider .set divider/10
.endrepeat
.endmacro
I'm not sure why I chose to output only 9 characters (this may have been what caused it not to work with $FFFFFFFF as seen in the TODO comment). Seems like it should be 10 characters to cover the full range of a 32 bit variable. It's easy to modify this to output hexadecimal, if desired (see the
__ngin_hexInteger macro in the above link).
__ngin_choice is a ternary macro defined as:
Code:
.define __ngin_choice( condition, if, else ) \
((!!(condition)) * (if) + (!(condition)) * (else))
ngin_Ascii is defined as:
Code:
.enum ngin_Ascii
kLf = 10
kCr = 13
kSpace = 32
kQuote = 34
kZero = 48
kNine = kZero+9
kPlus = 43
kMinus = 45
kDot = 46
kA = 65
.endenum
EDIT: Added
__ngin_hexInteger reference.