Home
Categories
EXPLORE
True Crime
Comedy
Society & Culture
Business
Sports
TV & Film
Technology
About Us
Contact Us
Copyright
© 2024 PodJoint
00:00 / 00:00
Sign in

or

Don't have an account?
Sign up
Forgot password
https://is1-ssl.mzstatic.com/image/thumb/Podcasts115/v4/d2/01/2f/d2012f8d-2bba-b9b1-e0e7-14a686e6e019/mza_12162428384170880572.jpg/600x600bb.jpg
Jay's Commodore Podcast
Jay Versluis
16 episodes
9 months ago
Join Jay Versluis for tips and tricks on programming in BASIC and Assembly on vintage Commodore systems.
Show more...
Technology
RSS
All content for Jay's Commodore Podcast is the property of Jay Versluis and is served directly from their servers with no modification, redirects, or rehosting. The podcast is not affiliated with or endorsed by Podjoint in any way.
Join Jay Versluis for tips and tricks on programming in BASIC and Assembly on vintage Commodore systems.
Show more...
Technology
https://wpguru.co.uk/wp-content/uploads/2018/08/Commodore-Podcast-Icon.jpg
How to print numbers as columns in Commodore BASIC
Jay's Commodore Podcast
8 minutes 48 seconds
7 years ago
How to print numbers as columns in Commodore BASIC

In this episode I’m demonstrating how to print numbers in evenly spaced columns in Commodore BASIC.
On the C128 and the Plus/4 we can use a nifty little function called PRINT USING for this, with which we can format the output of any printed text or variable.
On the C64 and VIC-20 that function doesn’t exist, so we’ll have to convert a numeric value into a string (using the STR$ function), and then determine how long our string is. Following that we’ll have to manually pad our string value with as many spaces as are required.
BASIC 3.5 / BASIC 7
Here’s the full code for the C128 and Plus/4, which is based on my earlier Lottery Number generator listing. PRINT USING appears in line 120:
10 x=rnd(-ti)
20 for i=1 to 6
30 rn=int(rnd(1)*49)+1
40 for j=1 to i
50 if n(j)=rn then 30
60 next j
70 n(i)=rn
80 next i
100 print:gosub 200
110 for i=1 to 6
120 print using "#####";n(i);
130 next
140 print
199 goto 20
200 rem bubble sort
210 for i=5 to 1 step -1
220 for j=1 to i
230 x=n(j):y=n(j+1)
240 if x>y then n(j)=y:n(j+1)=x
250 next:next
299 return
BASIC 2.0
And here’s the same listing without PRINT USING for the C64 and VIC-20. The string formatting happens in the subroutine in line 300:
10 x=rnd(-ti)
20 for i=1 to 6
30 rn=int(rnd(1)*49)+1
40 for j=1 to i
50 if n(j)=rn then 30
60 next j
70 n(i)=rn
80 next i
100 print:gosub 200
110 for i=1 to 6
120 gosub 300:print a$;
130 next
140 print
199 goto 20
200 rem bubble sort
210 for i=5 to 1 step -1
220 for j=1 to i
230 x=n(j):y=n(j+1)
240 if x>y then n(j)=y:n(j+1)=x
250 next:next
299 return
300 rem space the numbers
310 a$=str$(n(i))
320 if len(a$)=2 then a$=" "+str$(n(i))
399 return
Any questions, please let me know. Happy retro hacking!
PS: It got a bit dark there at the end on my webcam. Help me get some lights by supporting me on Patreon 😉
Jay's Commodore Podcast
Join Jay Versluis for tips and tricks on programming in BASIC and Assembly on vintage Commodore systems.