
Sign up to save your podcasts
Or


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.
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:
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:
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
In this episode I’ll demonstrate how to sort a numeric array on the Commodore 64. The same principle works for string arrays, and of course on all other Commodore BASIC computers.
The technique I’m using here is called Bubble Sort: in effect we’re comparing the first two items in the array, and if the left one is larger than the right one, the values are swapped around. This loop continues until all items in the array have been compared and sorted (hence the smallest items “bubble” to the front of the array, much like the smallest bubbles in a soda float to the top first).
Here’s the full code I’m building, including the lottery portion. The Bubble Sort code starts in line 200.
I’ve explained how to build the lottery generator in this code here: https://wpguru.co.uk/2018/03/how-to-generate-lottery-numbers-on-the-commodore-64/
Happy retro hacking!
In this episode I’ll demonstrate how to draw random lottery numbers on a Commodore 64. The secret sauce here is not only the RND function to generate random numbers, but also two loops inside each other that prevent the same number from coming up more than once.
Here’s the lottery generator code:
To adapt this listing to match your local lottery, change line 20 to the amount of numbers to be drawn from your pool (6 in my example), and change the value in line 30 to match the size of your pool (49 in my example).
Any questions, please let me know below.
Happy retro hacking!
In this episode I’m demonstrating how to build a word splitter on the Commodore 64. We’ll use string functions to parse a sentence and split each word off into an array of words so that they can be analysed later (for example, as part of an adventure game).
Here’s the code I’m building:
The interesting part starts in line 100 and onwards, where I’m building a subroutine that deals with the string functions. In line 110 I’m resetting/initialising two of the three important variables: LT$ holds a single letter from the phrase we’re getting in A$, while WD is counting each word we’re splitting out.
The FOR loop in line 120 parses each letter of the phrase, and if it finds a space character (line 140), the word count is increased. If the letter is not a space, then it’s added to the current word held in WD$(WD). The current word is assembled character by character.
Apologies for the audio quality, I did this on my laptop while sitting on the balcony, hence sea planes flying overhead can be heard (as well as the neighbours dog and kids).
Happy hacking
In this video I’ll demonstrate how to build a simple clock on the C64. We’ll go through this process step by step, including the built-in TI and TI$ variables, string formatting with LEFT$, RIGHT$ and MID$, as well as screen formatting.
Here’s the code I’m writing – works in Commodore BASIC v2 and above:
Many of the characters that appear in this listing are cursor control characters and appear in reverse in the video. They either position the cursor or print PETSCII graphics.
Inspired by David’s video, in which he connects an LCD screen to his C64’s User Port: https://www.youtube.com/watch?v=vV8FbwobrKY
In this episode I’ll demonstrate how to create those seemingly random YouTube Video IDs using a Commodore 64.
Here’s the code I’m writing – works in BASIC v2 and above:
The first line switches to lower case letters (I forgot to show that in the video).
NOTE: In addition to the upper case and lower case alphabet, and the numbers 0-9, YouTube also use two special characters that I forgot to mention in the video. One is the standard minus sign (-), and the other one is the underscore (_). The Commodore machines cannot produce the latter. For simplicity’s sake, I’ve left both of those out (just though I’d mention it here).
Inspired by Tom Scott’s video “Will YouTube ever run out of Video IDs” – watch it here: https://www.youtube.com/watch?v=gocwRvLhDf8
From the publisher's feed