Today special topic! Begin the programming course in Basic, the Commodore language. Today's episode is about creating a very simple program.
Let's see how to type it, how to view its list, how to modify it, then start it and even stop it. We begin to learn how the computer thinks and we discover first commands.
The lines of instructions we analyze today are: REM, PRINT, INPUT and GOTO.
We also use special keys: RUN/STOP, SHIFT + CLR-HOME and SHIFT + INST-DEL.
The commands we analyze are: RUN, CONT and LIST.
In the next installments, we will also see how to save and load files, how to transfer them to the PC and vice versa and also how to create programs on the PC, using the notepad, and then transfer them to the Commodore and run them.
Here is the program to type!
And here is the example program of the first lesson of the Basic programming course. At the bottom of this page, you can already find it in TXT format (to view it on the screen), and in PRG format, to start it on the Commodore 64.
10 REM IL MIO PRIMO PROGRAMMA IN BASIC 20 REM WWW.VALOROSO.IT 30 INPUT "COME TI CHIAMI";A$ 40 PRINT "CIAO " A$ "! "; 50 GOTO 40: REM VAI ALLA RIGA 40
Basic Programming Course, for which computers?
The simple program that we make in the tutorial can be run on many different Commodore: on the Commodore 16, on the Commodore Vic20, on the C64, on the C128, but also on the Commodore PET. It can also be run on emulators (e.g. emulators for Windows VICE and CCS64) and you can also run it on the old GWBASIC that was in the PC DOS.
If you are using the Commodore PET, remember to type the program in all lowercase.
If the topic interests you, I suggest you subscribe to my YouTube channel and activate the notification bell, in this way you will be notified when I publish the other episodes of the course.
Sequence of instructions
Let's start the Basic programming course with a question: Do you know how the instructions are executed in Basic?
The Commodore executes the instructions sequentially, from the lower line number to the upper one, unless you encounter instructions such as GOTO, GOSUB, functions or loops, which can jump from one point to another in the program.
Each line of the program begins with a number. It doesn't matter what number it is, the important thing is that each row has a different number.
If we write a line with the same number several times, only the most recent one remains in memory.
In addition, I recommend leaving some empty numbers between the various lines, also to be able to insert other features in the future.
To confirm and store the program line, after typing it, press RETURN (or ENTER if you are using a PC emulator, such as VICE or CCS64).
Remember that the instructions must be entered precisely and correctly, with all spaces and punctuation marks. Otherwise the program may not work!
If we want to type more instructions on the same line, in Basic these are divided with a colon ":". In line 50 of the program, there are two statements: GOTO and REM.
Basic Programming Course: REM instruction
The first instruction we see in the tutorial, REM, indicates a comment that we want to include in the program: it is useless in execution, but it is useful to remind us, in the future, what the program or part of it is for.
It is good to put a lot of comments in the programs, to remind us not so much what the various instructions are for, for this there are the manuals, but more to remind us of the operating logic of the software we have created. In the second comment line, I suggest this website, where I publish my videos and articles!
INPUT? What is it for in Basic?
The third line of the program, the one indicated with 30, contains an instruction, INPUT, indicating a data entry. The computer asks us what we have indicated in the quotation marks, in this case “What's your name”. The question mark is automatically added by the Basic. Our response, which we type on the keyboard, is saved in a variable, which is a data container. In this case, I added a dollar $ after the variable name A$, to specify that it is a string, that is, I expect a sequence of characters and not, for example, a number on which to make accounts.
Deepening the discussion of variables, we must consider that the Commodore Basic considers only the first two letters of the variable name, so, for example, variables ABC$, AB $, but also ABD$ represent the same container.
The PRINT statement, present in the fourth line of the example program for the Basic programming course, it is used to write on the screen. In our example, the computer writes what is indicated in the quotation marks, but also the variable, which we typed earlier, and the exclamation point. The message “HELLO ” with the name contained in the variable A $ as well as the exclamation point. The semicolon at the end of the line, it serves to indicate to the Basic of do not go to line, with the cursor, after having finished writing on the monitor.
Education PRINT it can also write to other destinations, such as a file or printer. This, however, we will see in other episodes of the course.
Basic Programming Course: GOTO instruction
Education GOTO serves to move the program execution sequence and is therefore useful for jumping to another line (in the case of the example of the Basic programming course, line 40).
Launch the execution of a program in Basic
We see it on various computers: on the Commodore 64, on the C16, on the Commodore Vic20, on the emulator for the Commodore PET, on the C128. We also see this on the GWBASIC for DOS of an IBM computer. It is always the same program and works on all devices.
Manage the execution of the program
To interrupt the execution of the program, press the key RUN/STOP on the Commodore keyboard.
On emulators, the RUN/STOP is replaced by ESC. So, both on VICE and on CCS64, to stop the execution of the program, we must press ESC.
On the Commodore PET VICE emulator, you have to press CTRL to stop the program. On the Commodore Plus4 emulator the key is END.
It is possible to restart the program from where it left off, typing the command CONT. If we had typed RUN instead of CONT, the program would restart from the first line.
Display the listing of the program, LIST command
After typing the tutorial program, when it is not running, you can call up and view the typed listing.
First of all, to clean the monitor you have to press the keys simultaneously SHIFT and CLR-HOME. On Windows emulators, you have to press SHIFT + HOME (O SHIFT + START). The monitor is cleaned, but the program is not cleared.
To view the listing of the program we typed earlier, we write the command LIST and we press RETURN. The example program of the Basic programming course is short and fits all in one screen.
In case the program is much longer, it is possible to display only a certain range of lines, for example:
- LIST -20 displays up to line 20;
- LIST 30 displays only line 30;
- LIST 30 - shows the program from line 30 onwards;
- LIST 20-30 displays the listing from lines 20 to 30, inclusive.
Change the lines of the program to Basic
It is possible to modify the program lines, simply by moving over with the cursor, modifying the relevant line. After making the changes, you must confirm the insertion of the line by pressing RETURN.
It may be necessary to insert some blank spaces in the line, for example when the edited text is longer than the previous one. In this case, you can insert the missing spaces by pressing SHIFT+INST-DEL on the Commodore keyboard. On emulators installed on Windows, the keys can be SHIFT + DEL (backspace) or, SHIFT + INS.
Basic program listing of the step-by-step tutorial
And here is the listing of the Basic program of the first installment of the Commodore's Basic programming course.
The program is available in two formats:
- COURSE-BASIC-1. TXT, in text format, to analyze it on a PC or to transcribe it on the various Commodore or on the DOS GwBasic;
- COURSE-BASIC-1. ZIP, ZIP compressed folder to unpack. It includes the program in PRG format, loadable and bootable from the Commodore 64 and a virtual disk D64 containing the program loadable from the C16, Vic20, C64 and C128, as well as emulators (CCS64, VICE or others).
The topics of the course are still many!
Credits: in the video tutorial, SID music is Noisy Pillars by Jeroen Tel.