Hi folks.
Working on a recent asm project I had the need for a flexible way of printing text strings. All the usual approaches made me impatient, so I put together a macro/function combination that basically makes it possible to use syntax close to C printf()'s. Some examples:
Code:
lda #42
sta value
printf "8-bit value: %02d at %04ld\n", value, &value
rts
value: .byte 0
Output: "8-bit value: 42 at 3163".
Code:
printf "$%X = %d dec\n", value, value
Output: "$2A = 42 dec".
Code:
lda #<text
sta ptr
lda #>text
sta ptr + 1
printf "Pointer at $%04lx, pointing to string at $%04lx, which is \'%ps\'.\n", &ptr, ptr, ptr
rts
text: .byte "Hello, Underworld", 0
ptr: .word 0
Output: "Pointer at $0ce3, pointing to string at $0cd1, which is 'Hello, Underworld'."
Code:
ldx #2
loop: printf "Content of register X is $%02x\n", ^X
dex
bpl loop
Output:
"Content of register X is $02
Content of register X is $01
Content of register X is $00"
It's been immensely useful so far, and hugely accelerated my work, so I decided to release it at
https://github.com/laubzega/tiny_printf_6502, where you will find more details.
Hopefully somebody has some use for it.
And since this is my first (I think) post here, let me introduce myself - I used to program 8-bit Ataris in the '80s as Thorgal/WFMH, mostly on the demoscene, although I built one or two utilities, too. A few years ago I purchased several 6502 computers to help me learn electrical engineering and that somehow reignited the old passion - although this time the C64 is my machine of choice. Last year, working with a friend we released the BeamRacer (
http://beamracer.net) and are now working on follow up products.