6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 10:21 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: tiny_printf_6502
PostPosted: Fri Aug 06, 2021 4:22 am 
Offline

Joined: Wed Oct 07, 2020 6:43 pm
Posts: 6
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: tiny_printf_6502
PostPosted: Fri Aug 06, 2021 12:26 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Welcome! Nice idea, and thanks for sharing your code.


Top
 Profile  
Reply with quote  
 Post subject: Re: tiny_printf_6502
PostPosted: Wed Dec 01, 2021 3:15 pm 
Offline

Joined: Sun Nov 08, 2009 1:56 am
Posts: 411
Location: Minnesota
Very cool!


Top
 Profile  
Reply with quote  
 Post subject: Re: tiny_printf_6502
PostPosted: Wed Jan 05, 2022 7:18 pm 
Offline

Joined: Sat Sep 05, 2020 3:12 pm
Posts: 22
This is very cool indeed!
And funnily enough, without having seen your post or project, I have recently done something similar, a printf() for my Small C compiler:
https://github.com/pzembrod/cc64/blob/m ... e/printf.a


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 22 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: