In this Commodore Plus/4 retroCombs episode, I cover chapter 5 of the Commodore Plus/4 user’s manual. In this chapter, Numbers and Calculations, 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, I hope I do the concepts justice. This is one chapter where I find the User’s Manual a bit lacking but adequate.
TIP: If you enjoy this series, leave a tip.
Table of Contents
- Series Information
- Companion Disk Image
- User’s Manual
- YouTube Video: retroCombs: Commodore Plus/4, Chapter 5 - Numbers and Calculations
- Video Errata
- Links Mentioned in this Episode:
- Key to Keys
- Episode Errata
- Introduction
- Numbers and Basic Operations
- Fractions and Decimals
- Scientific Notation
- Performing Calculations
- Immediate (Direct) Mode
- Order of Calculation
- Using Variables
- Mid Video Retro Break
- Numeric Functions
- Numbers and Other Functions
- Final Thoughts
- Join the Fun
Series Information
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>
Companion Disk Image
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.
User’s Manual
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 5:
Chapter 5 - Numbers and Calculations
Below are the links for previous chapters covered:
- Front Matter
- Chapter 1 - Unpacking and Setting Up
- Chapter 2 - Using the Keyboard and the Screen
- Chapter 3 - Using Software
- Chapter 4 - Getting Started
YouTube Video: retroCombs: Commodore Plus/4, Chapter 5 - Numbers and Calculations
In the video below, I work through Chapter 5 of the user’s manual.
YouTube Video: _retroCombs: Commodore Plus/4, Chapter 5 - Numbers and Calculations
Video Errata
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!
Links Mentioned in this Episode:
Below are the links I mention in the video.
- Commodore Plus/4 User’s Manual Series
- TEDuino - A TED Series inspired Datasette powered by Tapuino
- [The Tapuino Project](/tap](/teduino-1)
Key to Keys
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 |
Episode Errata
No feedback from previous episode. I must have gotten most things correct!
Introduction
- Thanks to all my viewers for the feedback.
- .d81 disk image is now available here.link).
- Proud of the companion website for this episode. Check it out!
- Don’t forget to subscribe to the channel!
I’m going to feel a bit like a math teacher in this episode! But an easy one. No homework.
Numbers and Basic Operations
-
We’ll talk about mathematical operators, but relational operators should appear when get deeper into programming. Operators are shown in the image below:

Fractions and Decimals
- Fractions are not native to the Commodore Basic 3.5. A fraction such as 1/2 is converted to decimal form (.5). The Plus/4 will never display a result in fraction format.
- Pi, or
π, 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.
Scientific Notation
-
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
Performing Calculations
-
We can use a
PRINTcommand 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 (Direct) Mode
-
Immediate mode allows us to use the Plus/4 like a calculator without creating a BASIC program and using the
RUNcommand. Enter the calculation on a new line preceded by thePRINTcommand 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 ⏎
Order of Calculation
-
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:
- FIRST: Negative numbers identified
- SECOND: Solve exponents
- THIRD: Solve multiplication and division
- FOURTH: Solve addition and subtraction
-
To modify the precedence of operators, surround the values between
(and)as shown in the example below. The operationA/3will complete, followed by12 +the value ofA/3, and then that result multiplied by 36.? 36*(12+(A/3))
Using Variables
- Variable are an important concept to both algebra and programming.
- A variable is a placeholder for a value.
- There are three types of variables in Commodore BASIC as shown in the table below:
| 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. |
Mid Video Retro Break
- Be sure to LIKE each video and SUBSCRIBE to the channel! The community is slowly growing.
Numeric Functions
- Commodore BASIC 3.5 includes numeric functions such as the trigonometric SIN function. A listing can be found on page 151 along with all other Commodore BASIC commands.
- A function uses the format:
FUNCTION(X)where function equals a specific function (such as SIN) and theXbetween 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
Numbers and Other Functions
- Random numbers are important for simulation and game software.
- Commodore Basic includes a
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 XTIP: 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 FUNCTIONHINT: The DO/LOOP commands create an infinite loop. Press
RSto stop the program.
Final Thoughts
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
Join the Fun
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 in the comments below.
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!
Comments
Comments use GitHub Discussions; sign in with GitHub to join in.