Commodore 64 BASIC is fun, and remarkably foundational to many programmers today. My goal is to generate even more BASIC programmers with this series!
Introduction to Commodore 64 BASIC Programming
BASIC Programming was the default, it was THE programming language of the 1980s. It was what appeared for everyone who turned on their home computer, but it also created an entire generation of “bedroom coders”, who are today’s professional programmers.
In this series I will be teaching you how to make a fully playable game in BASIC. Specifically Commodore BASIC (AKA Microsoft BASIC) on the Commodore 64. This first episode is an introduction to programming in BASIC, then over the coming episodes the goal is to build up the game in stages, with other diversions along the way, which will teach you all the fundamentals of the language.
Get Bonus Content, Just Add Your Email
Never miss an update PLUS get these bonuses for this lesson:
- Commodore 64 BASIC Programming Slide Deck
- Formatted better-than-word-for-word transcript PDF
- .D64 disk to use on a real C64 or emulator
Commodore 64 Programming Using an Emulator
Don’t have a Commodore 64, emulator or TheC64? Try out my browser-based C64 emulator! (beta)
For a more fully-featured Commodore 64 emulator for your Windows PC, Mac or Linux, I recommend Vice emulator.
Commodore 64 BASIC Programming IDE
For now we can simply type our BASIC into the Commodore 64 environment, and my browser emulator also supports the drag and dropping of BASIC as text files (using the .BAS filename extension), but once you get serious you might want to check out CBM PRG Studio for Windows which is a full Commodore 64 Programming integrated development environment.
Commodore 64 basic – How to get started and why you should.
What do all these programmers have in common? Now, most of them are dudes, but they’re not all dudes.
What they have in common is they all got started with BASIC (Beginners, All-purpose, Symbolic Instruction Code), and BASIC was a programming language that was intended for people to learn programming, which is a fancy way of saying that it’s human readable.
Now, Carol Shaw is the first female game programmer ever. The first recorded, documented female game programmer. She learned basic in high school, on a teletype. She developed a game called polo, which was the first documented video game developed. By a woman develop the Atari basic reference manual along with a guy called Keith Brewster.
Her 3D Tic-Tac-Toe was the first commercial video game by a woman – programming the sound and all the graphics.
One of my favorite all-time games, River Raid was also developed by her. A best-selling game, won loads of awards.
Partly off the back of that she retired at the age of 35 … and it all started with basic in high school.
Next we’ve got, Steve Wozniak. The famous was of Apple fame. He first started with basic to also with a terminal connected up at the school over their modem
Bill Gates also started with basic started at school
He learned Atari BASIC first from his dad and then his Dad saw that he had potential and hired a private tutor for him.
John Carmack of Oculus and ID software fame. He started out with basic, amongst other things. He also taught basic. At age 11 and it was such a foundational experience for him that he’s now teaching his kids, computer programming, using basic on an Apple to see, he says it’s like Kung Fu training, in the primitive wilderness,
Elon Musk of Tesla and Space X fame.
He started just like me Commodore Vic 20, using the. Basic manual that came with it. And his first commercial program, he sold his game blaster for $500. And you can actually play that game right now,
Linus Torvalds of Linux fame, and also the inventor of Git the version control software. He started out age 10, again, Vic 20 writing basic programs and his sister claims his first basic program repeated “Sarah is the best”.
What IS BASIC Programming?
So, what is programming?
Programming is teaching your computer how to do new things. All computer programs involve some form of input, whether that’s from the keyboard or from storage, it involves processing that input. It could involve writing back to short term storage, which is your memory, your Ram or long-term storage, which could be.
Disk, it could be tape and then some form of output, which in terms of a video game, the input and output might be joystick and sprites on screen.
Why Commodore 64 BASIC?
So why Commodore 64 basic one of the advantages that Commodore 64 basic and a lot of the basics of the era have you don’t need. Anything extra other than the computer or an emulator, because it’s instantly on, you don’t have to wait for it to boot up.
You don’t have to configure anything. You don’t have to install anything as soon as you turn the computer on. You’re actually in basic because it is the operating system. It’s also easy to learn. All of these famous programmers started when they were kids. Unaided. They had the manual that came with the computer.
That was pretty much it. And you can see immediate results and for learning immediate results and being able to iterate quickly, fix your mistakes. That’s really vital. You don’t want to have to do a lot of things before you can see any results because people lose interest. They get frustrated because they’re not good at it right away, or even they might not understand what they’ve done wrong.
Even though my community is called Retro Game CODERS. It’s really all about programming. Once you’ve learned how to do programming, it doesn’t matter which language you use. You’ve got those foundational principles that you can take anywhere.
Why NOT Program in BASIC?
A guy called Dijkstra said “it’s practically impossible to teach good programming to students that have prior exposure to basic.”
He is wrong. Most of us sort of a certain age did start with basic. Commercial programmers who do it for our day jobs. Most of us self-taught. We might’ve started with a Commodore 64 or the BBC, Vic 20 the ZX81. We learned basic and now are professional programmers, it doesn’t matter what age you are.
Learn basic. You’re a programmer.
The reason he had a thing against basic was because some of the hacky things that used to have to do back in the day, but basic actually does contain. Everything you need to do what is “Structured Programming”.
- You need routines. That means breaking your program down into smaller pieces.
- You need sequences, which is do one thing after another.
- You need to selection, which is if this is the case, do this, other choice do this other thing.
- And you need iteration, which is doing something continuously until a value is set or a condition is met.
BASIC Compared to Other Languages
Basic is a high level language. It means that it’s actually easier to understand.
So when people say they’re programming in machine code, usually what they actually mean is the programming in assembly, which is then converted into machine code. It is pretty much almost English, but it’s still less readable than those on the far right hand side, which were more abstracted from machine code, but more easy for people to grok.
So basic and things like scratch are at the easiest end to understand the easiest way to code and those on the far left low level languages, are closest to the hardware, but harder for humans to understand, and then many languages fall somewhere in the middle.
Learn programming, the principles of solving a problem with computer programming, going lower level if you need that performance, you don’t have to make things hard for yourself. If it gets the job done.
Get Started with Commodore 64 BASIC Programming
To start with Commodore 64 basic we need a Commodore 64. Even if you don’t have a Commodore 64 or anything like it, you can get started straight away by opening your web browser to Retro Game Coders.com/ C64-emulator/
Commodore BASIC Direct Commands
Up will pop the screen on the right and the first commands you need to learn are
LIST, RUN, NEW, LOAD and SAVE
List allows you to show the basic program that’s currently in memory.
So enter list and it’ll show you the currently stored basic program.
Load allows you to load a program from tape or disk. If you using a tape, then you just have to enter load, but we’re not using a tape we are using a virtual disk. So we need to first look to see what is on this disk. So we use the dollar sign and our device, which is the number of the disk drive, which is eight.
And that allows us to list the currently stored programs that are on disk. And we just have one program called “readme” and the disk itself is called “Blank”. Now we can load readme also by specifying drive 8.
We can see that this is the program that was on disk called “readme” and the reason why this started up as soon as we started the emulator, which I’ll show you again.
As you can see, it’s been told to load the first program from this into memory where it was stored. And the first program on disk is that readme. So with the comma 1, it will load into memory where it was originally saved without the comma 1 it’ll load into BASIC.
As well as listing it back to read it as a program, we can also execute it by typing RUN.
RUN will execute program.
Just as we can list individual lines, or we can list a set of lines, just the same we can actually just run from a certain point.
If we want to start a new program, we can just type NEW. And that means we have nothing in memory and can start over.
HELLO WORLD.BAS for Commodore BASIC
We can save it away again using device eight, which is the first disk drive. And to make sure it’s saved, we have a VERIFY command, again using Device 8.
Special Commodore Keyboard Keys
Now you saw that I used RUN STOP to stop the currently running program. That is one of the special keys. In the emulator. It’s mapped to the escape key on a PC or Mac keyboard, but we’ve also got this virtual keyboard here that allows you to do Run Stop.
Another special key is the Commodore key. As you can see in the emulator allows you to click it, to mimic holding it down, and then we can do a clear home to clear the screen. Can also changed upper and lower case. The weird thing about the Commodore 64 is that it has two character sets. You have to choose between them upper case with graphics or lowercase.
Input and Output – What’s Your Name?
So the first line is going to output “what is your name” and you notice that semi-colon, that means we don’t want to start a new line afterwards because the next line is going to be what actually asks the question. And that automatically puts a question mark in there.
Once it’s got the input, it puts it into the variable
name$ (or name string).
Then we can output a kind response, again using semi-colon, to give you a greeting.
So if we run that and I put in my name is Chris, it will say “well hello, Chris”.
Commodore BASIC Programming with Special Keys
These special keys can do quite a lot and one of the things that you might want to do is use the text colors and Reverse Text.
So for example, if I do control and then I choose 2, and then I hit control again, I’m going to get some white text. Hit Reverse, I get reverse text, and then we can turn reverse off again.
Now, if I was going to put this into a program, you’ll notice something weird happens instead of it actually being reverse. It puts that funny letter R and then a different symbol for when it’s turned off. But when it’s output, it is reversed. And that’s because these are special symbols that are interpreted by basic to do the same thing as these special keys.
Math BASIC Example – Temperature Conversion Program
10 print “ convert celsius to fahrenheit" 20 print "what is the temperature"; 30 input c 40 f=(c*9)/5+32 50 print c;" in f is ";f
For a final example, let’s do some math. What we’ll do is we’ll convert Celsius into Fahrenheit. We want our program to start on a blank screen with the cursor in the top left-hand corner so we can use clear home. And it puts this heart symbol in its place. You’ll notice that when we get to the right-hand side, it will loop around to the left-hand side, but we still need to press return after each line.
Again, as before we don’t want to put a question mark, but we do need the semi-colon so that the question mark appears straight after.
Unlike before, where we had
name$ or Name String, this time it’s a number, so it doesn’t have the dollar. It doesn’t have that symbol after, it’s just
Our math equation: Fahrenheit = Celsius * 9 / 5 + 32.
Then we display the result, putting in spaces for readability.
That will output whatever the variable C contains, which is our Celsius number, and it’ll output the Fahrenheit F at the end.
If we run it, 20 C is 68 Fahrenheit.
Using the Commodore BASIC Editor to Fix Mistakes
The good thing is this editor, this basic editor that comes to the Commodore 64, does have the ability to be able to change and edit, our mistakes.
What we do is we cursor up to where we made the mistake, change it, and then make sure we press return.
Then we can list again, and we should have a correct spelling.
So that’s the end of part one. I did go quite long, so I’ll stop there, but look out for next time where we start building the foundations of knowledge so we can build an actual game PLUS get a free Commodore BASIC Command List Cheat Sheet.