Category Archives: Commodore

30 years after its release it’s time to re-kindle with my first computer spirit – the C64. This was my first computer which changed my life forever. Thanks to VICE we can now enjoy the little guy again on modern hardware. Here are all my notes on how to talk to him, and his other friends from the 8 Bit Age.

Working with Keyboard Input in Commodore BASIC

In this episode I’ll show you three ways to take user input from the keyboard in Commodore BASIC.

The INPUT and GET commands work on all systems, while the GETKEY command only works on the Plus/4 and C128. I’ll demonstrate how to use all of them.

This will come in handy for our little lottery programme we’ve been working on, so that we can prompt the user for some numbers to compare against later.


Watch the full course in one convenient playlist:
Catch this episode on my Commodore Podcast:

Thoughts about the C64 Mini by Retro Games Ltd

In Europe, the brand new C64 Mini has just been released. Although I don’t have one myself, I’ve been following the Indiegogo campaign and have watched several “unboxing reviews” on YouTube. I must admit it’s a neat little machine, and I like the idea of somebody making the Commodore days available to a new generation of users.

However, I can’t stop thinking “what’s the point of this exercise?”

Don’t get me wrong, it’s not that I dislike the idea of Commodore BASIC making a re-appearence, or of new Commodore “herdware” being developed. Quite the opposite in fact.

What I can’t understand is why the hardware needs to be built on an emulator rather than real hardware. Because we HAVE that already, and completely FREE at that. We therefore do not need exotic hardware that’ll quite probably be off the shelf in a matter years.

I feel that it was different with the C64DTV project, with which Jeri Ellswoth reverse engineered the whole system using a new and combined chipset, basically building a new C64 wit modern components.

The Mini on the other hand – at least as far as I know – is a down-stripped Linux box which runs a software emulator. It could emulate anything. I might as well run VICE on my modern (and replaceable when broken) laptop, plug in a USB controller and get the same result. For free.

Why Mini?

If a company goes through all the trouble to recreate the C64 with modern components, I feel they should recreate the whole thing rather than something we already have access to. If it’s all about “some output on the screen”, then an emulator output or dedicated hardware output are arguably the same. And I guess that’s what the Mini project is all about: plug-and-play screen output.

But what I’d be more interested in is a fully reproduced piece of hardware, something to which I could solder homebrew stuff on the user port, or something I can plug in real floppy drives. I guess a fully recreated system is what I’m asking for, one that looks AND behaves exactly like the old breadbin. A system that lets me POKE a value and set a line on the cartridge port on high. That sort of thing.

With that in mind, I can’t help but wonder who the target audience of the Mini is. Total geek enthusiasts (like me and thousands of others around the globe) won’t be happy with a compromise. So perhaps it’s newcomers who hadn’t been born when the real Commodore devices were around? I wager that they might not care about pixelated slow and way-too-hard-to-enjoy retro games. Who then is the Mini aimed at?

Full-sized and Hand-held versions

A full-sized authentic recreation, as announced in the original crowdfunding campaign, definitely YES. I’m looking forward to that. Likewise, I can see the appeal of a handheld pocket sized version that plays old-school C64 games. Love both of those ideas. Both of these were annouced in the campaign

But the Mini? I just can’t see the point. If I want to play C64 games like back in the days, I might as well just play them on an emulator, or on authentic nostaliga hardware – with a fully working keyboard all.

Another question I have is, how did it go from these two models to the Mini in the first place? Whose idea was it, and what was the reasoning behind it?


I’m not bemoaning the project, not at all. I just don’t quite understand why we have it, that’s all.

I give Retro Games 10 out of 10 for the idea, and for seeing it through to release. But I can’t understand the concept of the Mini, or why it was produced at all (since it wasn’t part of the original idea behind this campaign). So only 5 out of 10 for that.

I’m interested to see the full size version as well as the handheld version. But I can’t see myself buying a Mini at this point.

Sorry 🙁

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. Continue reading How to print numbers as columns in Commodore BASIC

Watch the full course in one convenient playlist:
Catch this episode on my Commodore Podcast:

Sorting an Array on the Commodore 64

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:

Happy retro hacking!

Watch the full course in one convenient playlist:
Catch this episode on my Commodore Podcast:

How to generate Lottery Numbers on the Commodore 64

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!

Watch the full course in one convenient playlist:
Catch this episode on my Commodore Podcast:

How to build a Word Splitter on the C64 in Commodore BASIC

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 🙂

Watch the full course in one convenient playlist:
Catch this episode on my Commodore Podcast:

How to build a time of day clock on the Commodore 64

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:

Watch the full course in one convenient playlist:
Catch this episode on my Commodore Podcast:

How to create random YouTube URLs in Commodore BASIC v2

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:

Watch the full course in one convenient playlist:
Catch this episode on my Commodore Podcast:

String Operations on Commodore Computers

Commodore BASIC has some interesting and simple string functions built in. Three of them are self explanatory: LEN, LEFT$ and RIGHT$. But others, like the mysterious MID$ and INSTR functions, are a little tricker, and I can never remember how they works.

So here’s a quick recap on how they all work.

LEN (A$)

Returns the length of any given string. For example,

a$=”the cake is a lie”

print len (a$)

returns 17, which is the number of characters in our string.

LEFT$ (A$,X)

The LEFT$ function takes the x left characters from a given string. Here’s an example:

We get “one”, because those are the 3 leftmost characters in our string a$.


Likewise, RIGHT$ takes the x right characters from any given string:

Here we get “three”, because those are the 5 right characters of a$.

MID$ (A$,X,Y)

MID$ is a little more complex. It takes x characters from a given string, starting at position y. Let’s look at our earlier example again:

We get “two”, because those are the 3 characters, starting at position 5. The first position in all these string operations counts as one rather than zero.

But did you know that MID$ can also be used to assign and replace different characters in a string? Consider this:

Now we’ve replaced the 3 characters in our string with another string, starting at position 5.

I had no idea it cold do that! All these string operations work in all variations of the Commodore BASIC, except for the MID$ assignment which only works on the Plus/4 and the C128.


INSTR (A$, B$)

On the Plus/4 and C128, we can even check if one string is contained in another and at which position this occurs. Consider this:

In our example, INSTR returns 5 because “cake” has been found at position 5 of “the cake is a lie”.

We can also specify a position from which the search shall be started like this:

Now INSTR returns 0 because “cake” has not been found beyond position 6 of our input string.

How to play sounds and music on the Commodore Plus/4

The Plus/4 has a total of two voices thanks to its integrated TED chip, which is also responsible for rendering text and graphics on screen. The first voice can play square waves, while the second one can generate either square wave sounds or white noise.

Let’s see how we can make him play a tune.

We can use some BASIC keywords to make the Plus/4 be all musical. First we need to turn up the volume by using the VOL command. We can set this to anything between 0 and 8.

Next we can use the SOUND command to make each channel play a note, like so:

This will play a one-second long note on channel 1.

Continue reading How to play sounds and music on the Commodore Plus/4