Image result for basic for commodore 64
[Image from Retro64 – showing a game coded in BASIC]

Most beginners to coding on the C64 won’t start with Machine Code or Assembly language coding. They will begin to explore their programming potential with BASIC. I included the previous chapters on Assembly language to help beginners understand what goes on behind the scenes when we craft a game or a program in an interpreted language like BASIC.

What is BASIC?

BASIC is a computer program which is always available in the Commodore 64. It’s full name is BASIC Interpreter. It translates or interprets BASIC keywords, which humans can understand into Machine Code which the C64 can understand.

The BASIC interpreter program is stored in a type of memory called ROM memory – this stands for Read Only Memory. The BASIC interpreter is placed into a ROM unit when it is manufactured. After this, it cannot be changed (this is the Read Only component of the acronym).

Before We Start Coding – Correcting Mistakes

I want to start this section by helping you explore your Screen Editor. This is the screen which you see when you boot up your C64. The beautiful blue iconic screen where you can run your programs and code. It’s not just a pretty face however, it contains multiple ways to help you edit your code should you make a mistake. This is probably one of the most important lessons for a beginner to learn as mistakes are common when typing in code.

The Screen Editor and the Cursors

The screen editor provides several ways to edit your code, if you made a massive series of errors and want to completely clear the screen and start again. Locate the <CLR/HOME> and the <SHIFT> keys. Holding these down at the same time will clear all text from the screen and move the cursor (this is the blinking rectangle) to the upper left-hand screen corner.

If you don’t want to do anything quite so drastic and just want to delete a line of code. Simply type the line number of the line you wish to delete and press the <Return> key. This removes the line from memory.

If you want to replace a line of code, you type the line number followed by the data you wish to replace the current line data with. Then press the <Return> key. In other words you are simply typing the line over again.

Deleting a single character in a line is a common edit. To do this, locate the <INST/DEL> and the <SHIFT> keys on your keyboard. Now locate the <CRSR> keys, these should be at the bottom right of your keyboard. These are marked differently with one showing an up/down arrow and the other a left/right arrow. You can use these keys to move left and right on the current line. If your mistake resides there, position your cursor over it and press the <INST/DEL> key to remove the character.

If your mistake is located on a line above or below the current line, hold down the <SHIFT> key along with the appropriate <CRSR> key to move up or down. Once you have located the mistake, place your cursor over it and press the <INST/DEL> key to remove it.

Your First Program in BASIC

So here we are, after all the preamble and lectures about machine architecture we are ready to begin coding. The first programming keyword I am going to introduce you to is PRINT. This is a keyword in BASIC which you will use often. It has several uses. One is to PRINT something onto the screen. Type the following into your code editor and press the <RETURN> key.

If you haven’t found the quotation marks on your keyboard yet, they are made by holding down the <SHIFT> key and the number 2

The <RETURN> key is the signal to the BASIC interpreter that you have typed something in that you want it to accept.

On the top line of the screen, you will see the instruction that you typed. You asked the computer to print out the sentence Hello World. After you pressed the <RETURN> key you can see the computer’s response. It printed the sentence without the quotation marks.

Quotation marks are a way to define what is to be printed on the screen. The computer prints the characters between the quotation marks but never the quotation marks themselves!

After printing the Hello World! statement, the computer has finished the instruction. It has dones exactly as you had asked it to do. It then displays the BASIC prompt symbol READY, to show that it is ready for it’s next instruction. The cursor is automatically placed at the beginning of the screen line just below the prompt symbol. The next character will be displayed at that location.

Programming Terminology

Throughout these blog posts, I want to enable you to ‘talk like a programmer’. It’s my belief that you won’t just stop coding after you finish with the C64 but will perhaps pursue it as a career path. I therefor want to arm you not just with code but terms linked to the code you have written.

In the previous section I asked you to type an instruction and then press RETURN. When you type something and press the <RETURN> key, this is known as entering whatever was typed. The instruction enters the computer when you press the <RETURN> key.

The line of code you wrote PRINT “HELLO WORLD!” is referred to as a statement. If I was using consistent standard terminology I would have asked you to enter the statement PRINT “HELLO WORLD!”. Sometimes I use the term instruction interchangeably with statement, this means the same thing.

When the computer printed out HELLO WORLD this is known as the computer executing the statement.

Immediate Mode in BASIC

One line of code doesn’t make a program. A program is a way of storing a group of statements that the computer executes in sequence when you run the program. When you entered the statement PRINT “HELLO WORLD!” the computer executed it immediately. The statement is not being stored anywhere. It has been executed. In order to run this code again you would have to enter the statement all over again.

You are currently using the Commodore 64 in Immediate Mode because it executes statements immediately, as soon as they are entered. This will soon change, in the next section of our coding tutorials you will begin to user the Program Mode.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s