Retro computing with a touch of modern and the home for all things, retroCombs (aka Steven Combs).
by Steven B. Combs, Ph.D.
tags: commodore - retro - plus4 - vic20 - c64 - keyboard - keys - calculations - numbers - basic
In this Commodore Plus/4 retroCombs episode, I cover chapter 5 of the Commodore Plus/4 user’s manual. In this chapter, Number and Calculation, I learn how to use the Plus/4 as a calculator in immediate mode, create a function, and learn more about working with numbers in Commodore BASIC 3.5. I even combine some things we learned in previous chapters to amp up our programs. It is a packed chapter and even though I’m no math teacher;Getting Started_ I, “begin to acquaint you with some of the characteristics and capabilities of the Plus/4, and how to take the first steps toward programming with your computer.” We spend more time learning how to use the keyboard, correcting mistakes, creating simple programs, and then I shope I do the concepts justice. This is one chapter where I find the User’s Manual a bit lacking but adequatew you how to use windows on the Plus/4. No, not the operating system, but another unique feature of the Plus/4’s BASIC.
MEMBERSHIP: I now offer retroCombs memberships from $1 (PET level membership) to $20 (MEGA65 level membership) that include levels in between for all budgets (VIC-20, C64, Plus/4, and C128). If you’d like to support my content and get access to my Discord server along with other cool freebies, check out each level at https://www.buymeacoffee.com/retroCombs.
Table of Contents
This episode is a small part of my larger Commodore Plus/4 series. You can read the entire series and view additional resources at:
</plus4>
As I progress through the user’s manual, I enter and execute sample programs. The link below is to a .d81
image that contains every program from each episode. Like the series, the image is not complete.
retroCombs User’s Manual Disk Image - UPDATED AS OF: 2020-11-01
I use the following file name convention to make it easy to locate specific programs:
Sample Program Name: 02 RCOMBS SCROLL.PRG
02
- The chapter numberRCOMBS SCROLL
- my self assigned name for the BASIC program which will be immediately identifiable if you follow along.As part of my Commodore Plus/4 YouTube series, I work through each chapter of the Plus/4 manual. I’ve taken the time to scan each chapter so you can read and follow along. Use the link below to view chapter 3:
Chapter 54 - Numbers and CalculationsGetting Started
Below are the links for previous chapters covered:
In the video below, I work through Chapter 5 of the user’s manual.
Robin, from 8-Bit Show and Tell points out:
I'm enjoying this! At about 14:30 you mention how integer variables are truncated if assigned a float - this is correct, but then you say that 12.75 would be rounded to 13; it would actually be truncated to 12. Even 12.99999 would be truncated to 12 if assigned to an integer variable. If you want rounding, you'd need to do something like A% = 12.75 + 0.5. The INT() function isn't needed, but may improve readability.
Thanks for the catch and correction, Robin!
Below are the links I mention in the video.
Because the Commodore Plus/4 keyboard is so different from modern keyboards, I devised a modern key nomenclature to identify keystroke combinations as shown in the table below:
Key | Description | Key | Description |
---|---|---|---|
⇪ |
Caps Lock | F1 |
Function 1 |
C= |
Commodore | F2 |
Function 2 |
⌃ |
Control | F3 |
Function 3 |
⎋ |
Escape | F4 |
Function 4 |
⌂ |
Home | F5 |
Function 5 |
⌫ |
Insert Delete | F6 |
Function 6 |
⏎ |
Return | F7 |
Function 7 |
RS |
Run/Stop | F8 |
Help |
⇧ |
Shift | ␣ |
Space |
No feedback from previous episode. I must have gotten most things correct!
I’m going to feel a bit like a math teacher in this episode! But an easy one. No homework.
We’ll talk about mathematical operators, but relational operators should appear when get deeper into programming. Operators are shown in the image below:
π
, is a key on the Plus/4 keyboard (which is unique since most keyboards today don’t have this key). Press it to represent the value of π in a calculation.Numbers larger than nine digits are represented using scientific notation. Here are some examples:
20 = 2E+1
10500 = 1.05E+5
.0666 = 6.66E-2
We can use a PRINT
command in a BASIC program to perform calculations as shown in the example below:
10 ? 1+2,2-1
20 ? 2*2,4/2
You can print both a calculation, the result of a calculation, or the calculation and the result in a line of BASIC code as shown below:
10 ? "2001/2010"
20 ? 2*3
30 ? "2*3+1=";2*3+1
Immediate mode allows us to use the Plus/4 like a calculator without creating a BASIC program and using the RUN
command. Enter the calculation on a new line preceded by the PRINT
command or the ?
character. Below are a few examples:
TIP: ? = PRINT in Commodore BASIC)
? 3-6 ⏎
-3
? 24/(6+2) ⏎
3
Let’s combine what we’ve learned to use immediate mode to display a calculation and a result. Type the line below on an empty line:
? "2 TO THE 3RD POWER EQUALS";2↑3 ⏎
Commodore Basic 3.5 uses the mathematical concept of order of operations. In the example below, 50/5 is performed first with 200 added after the result:
? 200+50/5
Below is a short summary of precedence of operators:
To modify the precedence of operators, surround the values between (
and )
as shown in the example below. The operation A/3
will complete, followed by 12 +
the value of A/3
, and then that result multiplied by 36.
? 36*(12+(A/3))
TYPE | SYMBOL | DESCRIPTION | EXAMPLES | SAMPLE VALUES |
---|---|---|---|---|
Floating Point | n/a | Real (Decimal) or Whole Numbers | X, AB, T4 | 23.5, 12, 1.3E+2 |
Integer | % | Whole Numbers | X%, AI% | 15, 102, 3 |
Text String | $ | Letters, Numbers, Characters | X$, MS$ | “TOTAL:” , “DAY 1”, “CBM”won’t spend time on relational operators. They should appear again in a programming chapter. |
FUNCTION(X)
where function equals a specific function (such as SIN) and the X
between the (
and )
is a specific value the function will act upon.Below is a sample program that uses the SQR(X)
function, or Square Root of a number to print the square root of 1, 2, 3, 4, and 5:
10 FOR X=1TO5
20 ?"THE SQUARE ROOT OF";X;"IS";SQR(X)
30 NEXT X
💾 On Disk: 05 SQUARE ROOT
RND(X)
function to produce random numbers within a range of values.Below is a sample program that will print five random values.
10 FOR X = 1 TO 5 : ? RND(X): NEXT X
TIP: The line of code above could have been three different lines; however, we use a
:
to place three lines of code on a single line. This can reduce memory usage for longer programs.
The program above creates five unique random numbers, but what if we want random numbers between 1 and 5? We will need to use the INT(X)
function as well as setting a range (5) and lower limit (+1) as shown in the program below:
10 FOR X = 1 TO 5
20 ? INT(5*RND(1))+1 : REM 5 IS THE RANGE & +1 IS THE LOWER LIMIT
30 NEXT X
💾 On Disk: 05 RANDOM 1-5
It is also possible to create your own unique function to use throughout a program. If the function is used regularly in a program, this can save memory and speed of operation. Below is an example of a program below that will alternate a line of text on the screen various colors:
10 DEF FNR(X)=INT(X*RND(1))+1
20 DO
30 COLOR 1,FNR(16),5 : REM PICK A COLOR FROM 1 TO 16
40 ? "THE SEARCH GOES ON..."
50 LOOP
💾 On Disk: 05 FUNCTION
HINT: The DO/LOOP commands create an infinite loop. Press
RS
to stop the program.
This chapter provides the cursory basics of number and calculations. I recommend you check out more functions on page 151 in the user’s manual. Of particular interest is that most of the examples I provide can be accomplished using the Python interpreter on a modern computer. On that note, the concepts used here will help anyone who wants to learn program BASICs (pun intended).ic Functions
Help make this series better! Post feedback, questions, and ideas. Let me know if you are following along. Let’s make this a community project. For now, Leave your comments and thoughts below or in the comments under the YouTube video.
Thanks for watching and if you are so inclined, please let other Commodore fans know about the series by sharing these videos using #retroCombs.
🕹️ retroCombs, OUT!