C64 Basic Marathon
This YouTube session will be my best attempt at speed coding. Essentially I’ll be talking and programming at a fast pace. The goal is not to discourage people from watching, but to see how fast one can think when solving problems. Besides the slow downed solutions will be available on this website. This is the goal.
When you first start out writing your own program in Basic, you are going to be learning simple concepts. Although this section, is not meant to be a tutorial, it should get you where you want to go. I will do my best to break things down at an elementary level, but the tutorials will progress as each video is released.
Basic Set Up for C64
First be sure you have installed the WinVICE emulator on your desktop computer. Then you will benefit by creating a working disk image directory where you can save your program to. Essentially a disk iamge allows the program to be saved so it can be loaded again later. This will be necessary since this program will be compounded over a long period of time and grew immensely.
First let’s learn how to write a comment in Commodore 64 Basic. Comments allow you to write mini descriptions about what a line or segment, subroutine, etc. is doing. It is more natural to add comments at the end of a line.
To create a comment you will type the statement 10 REM follows by the comment description. REM stands for ‘remark’, and goes back as far as the beginning of Basic. Next you can add a fast remark with no comment proceeding it. Just type a semicolon on a single line for line 20.
Note: Line numbers are building blocks for your program. Each line will include a different or similar statement and as you continue adding new lines, Basic will recall them in the exact order as they are numbered.
So far we have:
10 REM EXAMPLE 1
20 :
C64 Basic Variables
Next we are going to learn about variable. Essentially, a variable is a way of storing a value that is used by your program. More often, they are used to keep track of totals, flags, and calculations. A variable is creating with two letters followed by an equal sign and the value you want to insert there. The equal sign assigns that value to memory under that variable label name.
We are going to create 3 variables for this program example called CO, NM, and EX. The values are assigned below and will be explained as this tutorial expands.
So far we have
10 REM EXAMPLE 1
20 :
30 CO=4:NM=16:EX=1
For the next line we will need to clear the screen. The Commodore 64 has a character built into the PET ascii character set that makes this possible. Character 147 does the trick nice and clean. You can utilize up to 256 characters (0-255) on your Commodore 64 system!
30 PRINTCHR$(147)
Changing C64 Screen Colors
After this we will want to add some color to add variety to our first program. So for this example, I will show you how to change the border color. You can use up to 16 colors (0-15) built into the Commodore 64 system. Below is the line to change the border to green. We have also added the comment to the end of the remark.
32 POKE53280,2:REM BORDER TO GREEN
Changing C64 Screen Colors
The Commodore 64 also has the ability to change the screen color. Just like the border, you can select from a palette of up to 16 colors. We will be keeping the screen black for now to make it easier to see on YouTube.
33 POKE53281,0:REM SCREEN TO BLACK
Now that you are getting used to changing colors you may also be surprised to learn that you can change the text color too. There are several ways to do this, but for now we will just write a value to a memory location like we do with the border and screen colors. You can also again choose up to 16 colors. Notice we also utilized our first variable CO that is used to set our beginning text color.
34 POKE646,CO
Cycle through C64 Colors
Once this is complete, we can now increase the value of the variable so we can cycle through different text color and splash them on our message. So the line below takes the original variable value of 4 and adds a one to it to get 5. When this line is executed again it will increase to 6, and so on.
Next we will create a statement to throw a message on the screen that specifies a special number range has been reached. So the CO>255 checks to be sure the value never goes above 255 and resets the value back to one if it does. Then it prints the message to the screen as seen below. The extra PRINT produces a carriage return to leave a new blank line.
36 IFCO>255THENCO=1:PRINT:PRINT”VALUE NEARLY EXCEEDED”:PRINT
C64 Loop Interations
Now we are going to create a condition that will check if we have counted an iteration of 16 each time. So this routine waits until CO is equal to 16 before printing a message. Then it resets to wait for the next 16 and so on. If the CO/16 = 16 then the program will change the border color at that time. At this moment, we have also increased the value in EX to keep track of the example message value we are current displaying.
37 IFCO/NM=INT(CO/16)THENPOKE53280,1+INT(RND(0)*NM):EX=EX+1
To wrap up the program we show the line that is being written onto the screen ‘THIS IS AN EXAMPLE’ and set the value next to it (EX). Then we repeat back to line 34 and begin the process over in an infinite loop.
10 REM EXAMPLE 1
20 :
25 CO=4:NM=16:EX=1
30 PRINTCHR$(147):EX=1
32 POKE53280,3:REM BORDER TO GREEN
33 POKE53281,0:REM SCREEN TO BLACK
34 POKE646,CO
35 CO=CO+1
36 IFCO>255THENCO=1:PRINT:PRINT”VALUE NEARLY EXCEEDED”:PRINT
37 IFCO/NM=INT(CO/16)THENPOKE53280,1+INT(RND(0)*NM):EX=EX+1
40 PRINT”THIS IS EXAMPLE “;EX
50 GOTO34
Get Connected!
Come and join our community. Expand your network and get to know new people!
No posts found.
No posts found.
Nothing more to show.
Leave A Comment