Commodore 16 User Manual
تبلیغات
تبلیغات
www.commodore.ca
May Not Reprint Without Permission
Cr commodore II 111 I 1111116
USER M A\UAL
a s
111
Ail rights a:served.
No part of this manual may be dupt watt .1 copied. transmitted or reproduced :a x r. form or by any meanswithout mum written permission of CEL.
C
r commodore
I Hunters Road. Weldon, t. orhy. Northants NN
C
r commodore
COMMODORE 16
USER MANUAL
COPY/JO? (c11984 by Commodore Eleotromos Limited
All rights reserved .
This manta contains copyrIghled and Proprietary lotOnnalion
NO pan 01 this putScation may be reproduced, stored in a retrieval system. or transmitted In any form or by ary means. elf:townie, mechanical. photocopying. recording or otherwise. without the onor written permission of Commodore
Electronecs
Commodcxe BASIC v. 3.5
Copynght (01984 by Commodore Electronics Limited. all aunts reserved
Copyright 0)1977 by 'wet-rosary. are rights reserved
J I
I
TABLE OF CONTENTS
CHAPTER 1
CHAPTER 2
CHAPTER 3
CHAPTER 4
CHAPTER 5
CHAPTER 6
CHAPTER 7
Setting Up
The Keyboard
. .......... ..... 5
17
Software.
............
The First Steps . • . ..... • • • • • .........
Numbers and CalculationS
29
41
53
Graphics and Colour
Sound and Music
63
83
BASIC 3.5 ENCYCLOPEDIA
Commands
Statements
Functions.
Vatiab!es and Operators .....
Abbreviation and Reference Chart
93
96
109
143
152
157
APPENDICES
Error Messages
Disk Error Messages
Deriving Mathematical Functions
Musical Note Table....
Screen Display Codes
ASCII and CMS Codes
Book List
INDEX
161
162
166
172
173
.175
178
.180
181
2 3
4
CHAPTER 1
SETT ING
UP
• Unpacking your Commodore 16
• Getting to know the switches and sockets
• Setting up your Commodore 16
• Troubleshooting chart
• Peripherals
5
UNPACKING YOUR COMMODORE 16
Now that you've opened the box containing your new Commodore 16 and found this manual, the first thing that you should do is check to make sure mat you have all the items on this list. You should have
nainearlannettagalitil aotaaaaaaaamaas gieCIQ00111110111101•1111110111=1
RanagaaackamilliPPI
1 Your Commodore 16
2 The power supply
3. The TV cable
4. The user manual (You've probably found this, since you're reading it right now.)
5. Other assorted literature:
Warranty card
II
you don't find all these items in the box, check with your dealer immediately for replacements.
Before you connect anything, you should overlook these pictures of your computer. You can familiarize yourself with all the outlets and switches, so you can set up your computer system quickly and easily
6
GETTING TO KNOW THE SWITCHES AND SOCKETS
JOY I JOY 2 RESET
•
OFF ON POWER t,„)
The Right Side Of Your Commodore 16
THE ONIOFF SWITCH
Your Commodore 16 should be turner OFF when you install or remove cartridges or any peripheral device such as a printer or Datassette.
Theresa red power light located above the keyboard on the right. which lights up wnen power is on.
THE JOYSTICK SOCKETS
You can plug joysticks into these sockets, labelled JOY NI and JOY
#2. The Commodore 16 uses specially designed joysticks available from your Commodore dealer.
THE RESET BUTTON
Press the reset button when you want to "start over." as if you'd just turned your computer on. The reset button clears the screen and erases any BASIC orograms that were typed in. There are other ways to reset your computer without erasing programs. These will be discussed in
Chapter 4.
7
THE POWER SOCKET
Tne end of the power supply cable fits In here. Plug the other end into a standard electrical wail socket AFTER connecting the first end into your computer.
The Back Of Your Computer
THE MEMORY EXPANSION PORT
Commodore 16 software cartridges pug in here. Before you insert or remove cartridges. make sure the power is OFF.
THE 1W JACK
This is where you plug in one end of the TV cable (the thin black cable).
Only one end fits into this jack: the other end fits into the TV serial socket.
THE HIGHILOW SWITCH
This switch controls whch television channel your Commodore 16 is on. This Is primarily used for American TV's.
8
THE VIDEO SOCKET
This is where you plug in the cable that connects a monitor to your
Commodore 16. If you hook up your computer to a television set. you won't need to use this.
THE SERIAL SOCKET
You can plug a disk drive or a printer into this socket. If you want to plug in both, first plug the disk drive into this opening, and then plug the printer cable into the back of the disk drive.
THE CASSETTE PORT
The Commodore 1531 Datassette tape recorder for cassette tape software plugs in here.
SETTING UP FOR COMMODORE 16
Connecting your Commodore 16 is simple. You only need to do two things:
1 Plug in the POWER SUPPLY on the right side of your computer and then into a wall plug.
2 Connect the TV cable (the thin black one) from the aerial socket on your TV to the RE SOCKET on the back of your computer.
Make sure that you have enough electrical wall outlets to plug everything in near where you decide to set up your computer. You may need a power strip or extension cord for more outlets. especially if you're also hooking up a printer or a disk drive. Remember that the power on everything (computer. TV. etc.) should be turned OFF until you are completely set up and ready to go.
1: Connecting The Power Supply
• FIRST plug the round end of the POWER SUPPLY into the power
Jack on the right side of your computer .
• THEN plug the other end into an electrical socket on the wall
9
2: Plugging In The TV Cable
• Plug one end of the TV cable (only one will fit) into the serial socket on your TV
• Pug the other end of the cable Into the RE jack on the back of your computer
"N c
Connecting Your Commodore 16 To A Monitor
If you're connecting your computer to a monitor Instead of a TV, follow the instructions in the manual that is included with the monitor. Hooking up a monitor like the Commodore 1702 Colour Monitor is simple. You need to connect only one cable which goes directly from your monitor to the VIDEO socket on the back of your computer.
Finally . . .
Now ifs time to turn on your computer (If you've been paying attention, you should know where the POWER switch is by now.)
If all went well, the red POWER light goes on, and this message appears on your screen
COMMODORE BASIC V3.5 12277 BYTES FREE
READY.
U
The flashing cursor under the READY message tells you mat your
Commodore 16 is waiting for you to start typing. The background colour is white, while the letters are printed in black, with a light purple border around me screen.
If all didn't go well. the Troubleshooting Chart should come in handy.
TROUBLESHOOTING CHART
Symptom Cause Remedy
Indicator light not Computer not turned
'ON' ON
Make sure power switch is in ON position
Power cable not plugged in
Check power socket for loose or disconnected power cable
Power supply not plugged in
Check connection with wall outlet
Bad fuse in computer Take system to authorised dealer for replacement of fuse
It
Symptom
No picture
Cause
TV cable not plugged in
TV not on
Random pattern on Cartridge not
TV with cartridge properly inserted in place
Picture without colour
Poorly tuned TV
TV not connected properly
Colour set too low on TV or computer
Picture OK, but no TV volume too low sound
Poorly tuned TV
Remedy
Cneck TV cable connection
Turn TV on
Reinsert cartridge after turtling OFF power
Retune TV
Check connections
Adjust colour setting
Adjust volume of TV
Retune TV
IMPORTANT: Some TV sets cannot display the entire Commodore
16 screen. instead, their picture cuts off the far left and far right column of the screen. We recommend using a different TV set or a monitor such as me Commodore 1702, 1802 or 1 803 colour monitor
If this isn't possible. you can deal with the problem by pressing the
ESC key, followed by the 'R' key. This reduces the computer screen display size lo 38 columns, so that the entire picture can fit onscreen. You must repeat this each time you power up or reset your computer
PERIPHERALS
Peripherals are the accessories that you can gel to go with your
Commodore 16 that increase what you can do with your computer
These accessories are available at your Commodore dealer, and allow you to use your computer to the fullest.
12
)
Peripherals give you the capability to save and store data. print out what appears onscreen (in black and white or colour), use software programs that are stored on cassette tape and floppy diskette, and give you a sharp, clear picture of your computer's display.
To save or recall programs. you'll need a device that stores data. Data can be recorded on and retrieved from both cassette tapes and diskettes. To use cassette tape software (and to record your own programs on cassettes). you'll need the Commodore 1531.
13
DATASSETTE tape recorder. For diskettes. there are several DISK
DRIVES that are suitable. Disk drives are typically fast and efficient to use. Disk drives that are compatible with your Commodore 16 are the
Commodore models 1541 and 1551
When using a wordprocessing program or a graphics package on your
Commodore 16. a printer will reproduce what is on the screen on paper. There are several models of Commodore printers available that work With your computer. These include the MPS-801, MPS-802. MPS-
803 (with optional tractor-teed), and DPS-1 101 (letter quality).
Your television set may not give you as clear a picture as you'd like for your computer Commodore colour monitors are specially designed to give you the sharpest, brightest picture for viewing your Commodore
16 output There are several models available. Including the
Commodore 1702. 1802 and 1803.
14
15
16
I f i If
I
1 I f
1
I f f 1 f
J_
1
1
I
I
I
1
1
1 f f
CHAPTER 2
THE KEYBOARD
•
A
tour of the keyboard
• Special keys
• Graphic keys
• Function keys
• The HELP key
17
A TOUR OF THE KEYBOARD
014,1000006000000N ma canneloni:moans eaaaalsoaoaasomm cismaactageaestaisiag
OM pm
Most of the keys on your Commodore 16 keyboard are identical to the keys on a typewriter, but each key can do more than a typewriter key
In this section, you'll learn how to use special keys like the -45 .
- key and the four separate cursor keys, This section will show you the extra features of every key, including how to use the graphic symbols pictured on the fronts of many of the keys. With each explanation of the different keys on your computer keyboard, you should find the keys ana practice using them.
Using Your
Keyboard Like a Typewriter
When you first type letters on your computer, they appear as capitals on the Screen. The letters and numbers appear on the screen exactly as they appear on the face of the key when you press the key by itself.
Also, several other keys (+, =. fig, *, and f ) may be typed alone. Most punctuation marks need to be typed with the
801Ft
key. If you want to do some regular typing, you can type in capital and lowercase letters (like you would on a typewriter) by pressing the
SUIT key and the key at the same time. After you do this. all letter keys typed alone are printed In lowercase. When you press the
lin key along with a letter, you get a capital letter. Numbers and punctuation keys work the same as they would in regular (non-typing) mode To get out of typing mode, just press the two keys (SC and
) together again.
KEY + KEY =
UMT + CI
A
SEW + A
+ A
ENTER OR EXIT TYPING
MODE a
A
SHIFT r
0
18
1 f
1 f
1
Special Keys
Several keys on your Commodore 16 keyboard behave quite differently than any well brought-up typewriter key would even think of acting.
These keys act to enable other keys to do things they wouldn't ordinarily do, or perform functions related to the business ol computing.
Your Commodore 16 keyboard also contains special symbols not found on many typewriters. or even on most computers. These special symbols include the pound sign ( c ). pi ( Yr ), greater and less than signs ( < > ). brackets ( ). and arrows ( ). These special symbols keys are often used In writing programs on your Commodore
1 6
MUM
You nave to press the
arrow
key at the end of each line of
Instructions you enter on your Commodore 16 keyboard. You might think of this key as an ENTER key because RETURN actually enters information and Instructions into your computer
NWT
You've already come across an example of me SHOT key in action in using your keyboard like a typewriter. That is typical of the SHIFT key. it is always used to modify what other keys print onscreen, but can't do anything by itself (Always the bridesmaid, never the bride
) The
:son
key avows you to type capital letters. graphic symbols. punctuation marks, and a few other things—with a little help from another key. You'll be seeing more of the SIAPT key's functions throughout this section, for things such as getting graphic symbols
Tne ,SHIFT LOGE key is the same as the SHIFT key, except that it is locked into place, so you don't have to hold it down. When
81ilirCLOCZ is on, every character you type is SHIFTED. To release the lock, just press 11111 1 LOCK again. and everything you type is back to normal.
aurrarsor
Press this key to break into a running program to STOP what your
Commodore 16 is doing When your compute. Is running a program, pressing this key gets you back in control of the keyboard
.
When you hold down the
SHIT
and RON/STOP keys simultaneously. the Commodore 16 loads and runs the first program on a disk In the disk drive.
19
The Cursor Keys
The cursor, the flashing block that marks where you are on the computer screen, can be moved quickly and easily around the screen by using the CURSOR KEYS. There are four separate cursor keys, each with an arrow pointing out the direction the key moves the cursor up, down, ;eft. or right. You can use the cursor keys to move the cursor over anything on the screen without affecting those Characters
Like all keys on the Commodore 16 keyboard, each cursor key can automatically repeat. Th;s means that if you Continually hold the key down, the cursor continuously moves in the direction of the key you're pressing (saving you from having to perform the tabled "rapid-fire keypress").
INSTOMIL
You can INSERT and DELETE letters and numbers from the line you are typing with this key. When you press this key oy itself, the typed character immediately to the left of the cursor disappears. and the cursor moves over to wnere the missing character was. You can use the cursor keys to go back to the middle of a line and then use DEL to erase a letter. When you do this, the letter to the left is deleted, and the rest of the letters on the line move over one space to the left to close the gap.
To open up space to insert letters and numbers, type this key along with SENT Space opens to the right of the cursor: the cursor itself does not move. When you insert space in the middle of a line of letters. the rest of the line moves to the right
The ;IMIT/DEL key saves a lot of lime wnen you want to edit or change what you've typed
20
KEY
INST/DEL
SHIFT MST/DEL
= EFFECT
— DELETE (ERASE
TYPED
CHARACTERS)
- INSERT (ADD
SPACES)
SHIFT
CLEAR/HOME
This key serves two primary functions: HOME and CLEAR. When you press this key alone, the cursor immediately moves to the top left corner of the screen (which Is known as the HOME position). The rest of your screen stays the same If you hold down the r press ammo= . not only does the cursor move to HOME, but everything on the screen is erased (or cleared). All that remains on the screen is the blinking cursor at the top left corner of the screen.
KEY
CLERRMOITC
CISARAROME + ROM
= EFFECT
— HOME POSITION
CLEAR SCREEN
SHIFT re.. (Control)
The X:IBL7 key is like the San key In that it always works wiln another key. You must hold it down while you press other keys. CTRL s used in three Instances.
1) As the COLOUR KEYS section explains, pressing CMIL and a colour key lets you change the colour of the text printed on the screen.
2) You can pause a program that is PRINTing or LISTing on the screen by pressing CTRL and the S key.
(To re-start the program, press any key except RUN/STOP j
3) -01114 is also used with =VIM MOTT and FLASH ON/OFF
Triese are explained later in this section.
In addition, some software programs that you buy make use of the
CTRL. key for their own special functions.
21
CY (COMMODORE KEY)
The Commodore key Is very similar to CMIL . and can be used to perform tour functions:
1) When used with the SINT key. the
0
key lets you get into typing mode. where you can use both upper- and lowercase letters.
2) The a key always acts as a shift to let you type the graphic symbol pictured on the LEFT front of each key. Just hold down IV and press the graphic key you want
3) The C key is used like the COMM key to change the colour of what you type onscreen when pressed with a COLOUR KEY.
4) When you want to slow down a scrolling display (a program that appears line-by-line on the screen but might be going by too fast to follow), hold down the 4. key. The display scrolling speed slows down considerab;y. When you release the key, ■ 1 goes back to normal speed. (Hey, the „.D. key can db something by itself I)
1t8' NI MOW (Reverse On/Otb
Your Commodore 16 lets you print the reverse Image of letters and numbers. In other words, if your cursor is black and the screen background is yellow, what you type appears in yellow getters on a black background.
Here's all you do to get reversed images. Press the
CTRL key and the
NYS ON key. Everything you type is now displayed in reverse. until you press the CTRL- and RUOFF . the t1!TO111, key. or the SC key and 0 This returns you to typing normal (non-reversed) characters
.
KEY + = EFFECT
+ NYSOM.
.
= REVERSE PRINTING
ON
CTRL
ants + mar
= NORMAL PRINTING
0
CTRL
1RVS
OFF ,,
22
FLASH ON MAN Oft
You can make me characters on your screen flash on and off continuously, like the cursor flashes. Press 'MS and the
nem
key to make whatever you type flash. Typing CUL and PLYBOPE .
or 12101111 . or ESC and 0 makes your typing normal (non-flashing) again.
KEY + = EFFECT
'CM + ELISE Olt = CHARACTERS
FLASH
CTRL
If
COIL + .71/01/1.017 = NORMAL DISPLAY
CTRL
SW (Escape)
The tliC key lets you perform many special screen editing functions.
Including functions to set up and manipulate screen windows.
Windowing is a special property of your Commodore 16, which lets you set apart an area of the screen that may be used as work space without affecting the rest of the screen. The MO key can perform several window editing functions, as welt as many other regular uses, such as
Inserting, deleting, and scrolling. Ali the functions of the NBC key will be listed and explained when reviewing screen windows in Chapter 4
Colour Keys
141
The colour keys bear a striking resemblance to the number keys from 1 to 8. When pressed with either the OINL or the ,Ca-- key. they change the screen colour of everything you type. Your Commodore 16 starts out with a white background and a blue border, with the cursor
23
flashing black. When you type anything, the characters appear in black. To change the cursor (and what you type) to a different colour, use the colour keys. On the front of the keys numbered from 1 to 8, there we two colours written. Press CM along with a number key to gel the colour listed on top, or the
TA. key with a number to get the colour on the bottom. You can change only the colour of the characters using the colour keys. To change the screen background or border colour, you must use a BASIC command. (More on that later.)
NOTE: When changing colours, be careful that you do not press the number (colour) key even a split second before pressing Ann or
O. If you do, all you'll do is print a number on the screen rather than change the colour.
KEY + = EFFECT KEY + = EFFECT
vnk +
1 = BLACK A..
+
t
=
ORANGE
+ 2 = WHITE + 2 = BROWN i.
+
3 =RED + 3 = YELLOW GREEN nor
+
4 = CYAN t
+ 5 = PURPLE Qe +5 = BLUE GREEN
+
6 = GREEN "fi +6 in LIGHT BLUE
+
7 = BLUE
17. + 7 = DARK BLUE
AMU
+
8
-
YELLOW + 8 En LIGHT GREEN f
I
I
Graphic Keys
Each letter key (and a few other symbol keys) on your Commodore 16 has two boxes on the front of the key, each with a different line,
Squiggle. ci symbol. TheSe are the graphic keys. When first turned on, your Commodore 16 prints capital letters. When you type one of these keys along with the
Nan
or :Cr key, you type the graphic symbols shown on the front of the key on the screen. You can type the full set of more than 60 graphics you see on the fronts of many of the keys.
' I
J
'
{
KEY + = EFFECT
11211T + A
+ A =
(GRAPHIC ON RIGHT
SIDE OF KEY)
r
OF KEY)
Cs
+A_
SHIFT
You can create pictures, charts, and designs by printing graphics side by side or on top of each other, like building blocks. You can make your graphics more interesting by using the colour keys to "draw" in different colours. Try printing with some of the graphics keys to see how they work. Chapter 6 explains more about graphics.
When you're in typing mode, you can only use the graphic symbols on the left front of the keys (by pressing At& and the appropriate key). The left side graphics are ideal for creating charts, graphs, and business forms,
•
I
24 25
Function Keys
1 f4 f2
/
f 5
\
f3
/ f6
HELP f7
Tne lour keys on the right side of your keyboard (apart from the rest of the keys) are specie) function keys that let you save time by performing repetitive tasks with the stroke of Just one key. The top of each key reads
, 12. t3, and HELP. You can gel these functions by Just pressing the key by itself. The fronts of the keys read f4, f5, f6 and ft Press
SHIFT
and It, f2, f3 and HELP. respectively. to get these functions
Here's what each key does .
KEY 1 enters one of the GRAPHICS modes when you supply the number of the grapnics area and press
Ur= .
The
GRAPHICS command is necessary for giving graphics commands such as CIRCLE or PAINT More on GRAPHICS in
Chapter 6
KEY 2 prints DLOAD" on me screen. All you do is enter the program name to load a program from disk and hit
Car
instead of typing out DLOAD" yourself.
KEY 3 lists a DIRECTORY of files on the disk in the disk drive.
KEY 4 clears the screen using the SCNCLR command.
KEY 5 prints DSAVE" on the screen. All you do is enter the program name to save the current program on disk and press .juntiet .
KEY 6 RUNs the current program
KEY 7 displays a LISTing of the current program.
KEY 8 (the HELP key) highlights errors in program statements in flashing print.
You can redefine any of these keys to perform a function that suits your needs. Redefining is easy. using the KEY command. You can redefine
26 the keys from BASIC programs, or change them at any firne in direct mode A situation where you might want to redefine a function key Is when you use a command frequently, and want to save time instead of repeatedly typing in the command. The new definitions are erased when you turn off your computer. You can redefine as many keys as you want and as many times as you want.
The Help Key
When you make an error in a program, your computer displays an error message to tell you what you did wrong These error messages are further explained in the Appendices in the back of this manual
You can get more assistance with errors by using the HELP key. After an error message. press HELP to locale your error exactly. When you press HELP, the line with the error is displayed on the screen with the error flashing on and off. For example
?SYNTAX ERROR IN LINE 10
HELP
10 PRONT "COMMODORE
COMPUTERS"
Your computer displays this
You press HELP
•
The mistake is displayed flashing on and off
27
28
I I
CHAPTER 3
SOFTWARE
• Introduction
• Cartridges
• Cassettes
• Diskettes
I r r Ir
I
f
I f
I f
29
INTRODUCTION
A computer without software is like a glass without orange juice. Well, maybe not, but software does add to the usefulness of your computer and the tun and diversion it enacts you. Software is all the programs that can be entered and run on a computer. The hardware (In mis case, your Commodore 16) can use software in many Jorms. plug-in cartridges. pre-recorded tapes and diskettes. The family of software available for your Commodore 16 is growing quickly Your dealer can keep you up-10date on new products and inform you about Me features of software that's currently available
Your Commodore 16 can use software on CARTRIDGE. CASSETTE
TAPE. and DISKETTE form, available from your Commodore dealer. All you do is load them into your Commodore 16. You can also create and store your own programs on cassette tapes or floppy disks.
CARTRIDGES
Commodore produces a full assortment of cartridge software lor your
Commodore 16. There is a variety of personal. education, and business programs, as well as exciting games available for your
Commodore 16. You don't need any additional equipment to use cartridge software; all you do is plug the cartridge into the back of your computer and power on Here are the steps to follow to use cartridges .
Loading Cartridges
STEP 1 Turn OFF your Commodore 16.
IMPORTANT: YOU MUST TURN OFF YOUR COMPUTER BEFORE
YO' INSERT OR REMOVE CARTRIDGES. IF YOU DON'T. YOU
MAY DAMAGE THE CARTRIDGE AND THE COMPUTER.
STEP 2 Hold me cartridge with the label lacing UP, and insert the cartridge firmly in the cartridge slot (labelled 'memory expansion') in the back of your computer.
STEP 3 Turn ON your Commodore 16.
STEP 4 Begin the game or program according to the instructions that come with the software.
30
I
CASSETTES
CARTRIDGE SLOT
A variety of software for the Commodore 16 is available on cassette tape. These cassette tapes are similar to the music cassettes that you play on your tape deck or stereo. Software on tape works In the same fashion as cartridge software. but you have to have an additional piece of equipment (called a peripheral) to load cassette software into your computer. To use cassettes, you need a Dalassette tape recorder, available Irom your Commodore dealer .
You can also use cassette tapes and the Dalassette to store programs you write yourself. The next section explains how to save programs on tape.
31
The steps for loading a program on cassette tape we the same, whether you're using pre-recorded software or programs you saved yourself.
Loading Cassette Tapes
STEP 1 Insert the cassette into your Datassette and close the door.
STEP 2 Rewind the tape to the beginning by pressing the REWIND button on the Datassette.
STEP 3 Press STOP when the tape is rewound to the beginning. type
LOAD and press the Int key. Inc computer responds with the following message:
PRESS PLAY ON TAPE
STEP 4 Press the PLAY button on the Datassette. The screen goes blank as the Datassette starts. When a program Is found, the screen displays this message:
SEARCHING
FOUND program name
STEP 5 Press the Commodore key "e ► - to load the program that was
FOUND. If there is more than one program on the tape, and the program your Commodore 16 found isn't the one you want, do nothing. Your computer will continue searching after a brief interval.
When the program is leaded, the word READY appears. If you want to stop the loading before it's complete, press vaillifirlitab on the keyboard, and then the STOP button on the Datassette. After the software is loaded, type RUN to start the program. You can also LIST the program or change it. if it Is a BASIC program.
Loading A Specific Program
To LOAD a specific program on the tape, use the LOAD "program name Wm of the LOAD command. The instructions are the same as typing LOAD with no name, with just a few differences.
32
STEP 1 If the program you want is called "BASES-, you would type:
LOAD "BASES" and press
Your computer responds with:
PRESS PLAY ON TAPE
STEP 2 Press the PLAY button on your Datassette to get your computer to start looking. After searching on the tape for the program called BASES, the message should appear.
FOUND BASES
LOADING
The screen goes blank while your computer then "reads" the program
Into its memory. If the entire tape goes by without the FOUND message, rewind the tape and try again. Once your computer has digested the entire program, your Commodore 16 tells you:
READY.
I
STEP 3 At the cursor, you instruct it to
RUN and press At this point, your Commodore 16 runs
(executes) the program "BASES".
Saving Programs on Cassette Tape
When you write a program yourself and you want to keep it for later use or modification, you can SAVE that program. When you SAVE a program, you are in effect recording it on a form of software (tape or disk) that allows you to recall the program so you can RUN II, make changes, etc. When you want to save a program on cassette tape, follow these steps:
STEP 1 Type:
SAVE "program name"
33
The program name you use can be anything you want. but can be no more than 16 letters and/or numbers long .
STEP 2 Press the
MORN key The computer displays this message:
PRESS PLAY & RECORD ON TAPE
STEP 3 Press tne RECORD and PLAY buttons on your Datassette. The screen goes blank. When your program is saved, the word
READY appears on the screen .
Examples of SAVE Commands for Cassette Tape:
SAVE "THE DAY"
SAVE "YOURSELF"
This name is the specific name of the program being saved
NOTE: When saving a program onto a cassette tape. always be aware of where the tape is positioned.
DISKETTES
cassettes, you only have to put the disk into the disk drive and type the commands to LOAD or SAVE programs: there are no buttons to push.
There are a couple of small lights on the front of the disk drive. The green light is the power light, telling you whether the disk drive is turned on or off. The red light tells you two things. During normal disk drive use, when a program is being LOADed or SAVEd, it is it while the disk is spinning in the drive. If there is a problem with the diskette or drive, the red light flashes on and off, even after the disk stops spinning in the drive.
Loading Programs From Diskette
STEP 1 Make sure that your disk drive is plugged in and the serial cable is connected. Then turn the power ON.
STEP 2 Insert the disk into the disk drive The label side of the disk must face up. Insert the disk Into the opening so that the labelled end goes in last. Look for a little notch on the side of the disk (it might be covered with a sticker). This notch should be to your left as you put in the disk, assuming that you're facing your disk drive. Be sure the disk is in all the way. eillSO:renesseanallitelithl
—
Disks are last aria easy to use Be sure to handle your disks and your disk drive carefully Disks may be referred to as diskettes, floppy disks. or floppies interchangeably: they are all the same thing. Unlike
34 35
STEP 3 Close the protective "door" on the disk drive after you Insert the disk.
STEP 4 Type:
DLOAD "program name"
4-
Specific name of the program to be LOADS .
(To save lime, you could press FUNCTION KEY 2 and type in the program name and me second quote marks.)
STEP 5 Press the MGM key. The disk spins and your screen says:
SEARCHING FOR program name
FOUND program name
LOADING
READY.
Cursor
STEP 6 Your software is now ready to use. Type RUN and press the
UMW key to start the program.
II the red light on the disk drive blinks atter the DLOAD is finished, something went wrong. Type:
?DSS (and hit 1M101111 to find out what went wrong.
Examples of DLOAD commands:
DLOAD
DLOAD FILES
DLOAD "SOP"
LOADS the 1st program on the disk.
LOADs a disk program called FILES.
LOADs the first program on the disk that begins with the letters SOF.
Headering A Diskette
Headering prepares a new BLANK disk for use Any blank disk must be formatted before it may be used. by using the HEADER command.
36 r
I
IMPORTANT: 00 NOT HEADER A DISK THAT HAS ANYTHING ON
IT UNLESS YOU WANT TO ERASE THE ENTIRE DISK. HEADERING
ERASES EVERYTHING ALREADY ON A DISK.
The format for the HEADER command Is:
HEADER "disk name -
• The name you use is the name of the entire disk. Give the disk any name up to 16 characters.
• Udevice // specifies which peripheral device number (which disk drive unit), and defaults to 8 (primary disk drive).
• The i.d. is the letter I and any two letters and/or numbers, like I21,
IRS, etc Give the disk any i.d. you want, but you should give every disk a different i.d to avoid contusion. (Note. the first character must riot be F).
• if you have a dual drive (a disk drive with two slots for disks), you should specily the drive number with a 0 or 1. Drive number is
ALWAYS included in the command. even with a single drive (DO).
ARE YOU SURE?
As soon as you press IMMIX after typing the HEADER command, your Commodore 16 asks ARE YOU SURE? This is to give you a last chance to change your mind. It you want to go ahead and header the disk. type YES or Y and press =VW. If you decide not to header the disk. type NO or N and press :WOW.
Here are some examples of HEADER commands
HEADER "LETTERS",107,D I
HEADER "FINANCES",U8,1S3,D0
NOTE: If you want to erase all files on a disk (as opposed to formatting a blank disk), use the HEADER command without an i.d. number. This in effect scratches (erases) all the tiles mat were on mat disk.
Now that you know how to HEADER a disk, you're ready to use disks to write and save programs on your Commodore 16 (or any other
37
Commodore computer). The BASIC Encyclopedia in the back of this manual has more information about the HEADER command.
Saving Programs on Diskette
When you want to reuse a program you've written, be sure to SAVE it before you LOAD another program or turn off the Commodore 16.If you don't, you'll lose the program
When you change a SAVEd program. you have to SAVE it again if you want to keep the new version
When you reSAVE a program. you are replacing the old version with the new one. If you want to keep both the old and the changed versions, you have to give the new one a different name when you
SAVE it
Follow these steps to save a program on disk .
STEP 1 Type DSAVE "program name"
STEP 2 Press MOM . The computer displays this message when the program is saved:
SAVING 0: "program name"
READY.
I
Example .
DSAVE "MYPROGS" The program name can be up to 16 characters long
II the red light on the disk drive blinks after the DSAVE finished. something went wrong. Type .
?DSS (and nit UMW ) to learn what went wrong.
If you try to SAVE a program on a write-protectea disk (a disk that does not accept your output) you must turn The drive OFF, then ON again
38
1
1
The Directory Command
When you SAVE programs on disk, the computer keeps a listing of all the files saved on that disk. You can display the listing as a table of contents to see what's on a disk by using the directory command .
Type.
DIRECTORY then press
(or press FUNCTION KEY 3)
HEMS
As soon as you press MOBS , your Commodore 16 displays everything on your disk.
You can also display just part of the table of contents:
DIRECTORY "MY*"
DIRECTORY =PRG"
DIRECTORY "*= SEQ"
Lists every file on the disk that starts with the letters MY.
Lists every program file.
Lists every sequential tile_
39
40
CHAPTER 4
THE
FIRST
STEPS
• Introduction
• The screen display
• Reverse printing and changing colours
• The first step
• Correcting mistakes
• Screen windows
41
INTRODUCTION
The purpose of this chapter is to begin to acquaint you with some of the characteristics and capabilities of your Commodore 16, and how to take the first steps toward programming with your computer.
The Screen Display
Your Commodore 16's comings and goings are seen on your TV or monitor display screen. Whatever you type, whatever your computer has to say about what you type, whatever programs you load . it all shows up on your monitor screen, whether you're hooked up to a colour or black and white TV, or a Commodore colour monitor. Your
Commodore 16 screen, no matter what type of monitor or TV you're using, is 40 columns wide. That means that you can type 40 characters frOrn the left edge of the screen to the right. There_ are 25 rows, so that an entirety fulled screen can contain spaces for 1000 (25 X 40) characters. The Commodore 16's screen display is made up of three elements' the characters (the fetters. numbers and graphic symbols), the background, and the border When you first turn your computer on. the characters are black. the background is white, and the border is light blue You've already seen how to change the colour of the characters using the number keys along with a Or 0 in Chapter
2. You can make the characters any of 16 different colours in this fashion. There are a few other things you can do to make printing characters more interesting
42
Reverse Printing and Changing Colours
Not only can you change the colour M the cursor and characters you type (and your computer displays) on your monitor screen, you can also reverse the character and background colours. That means that if you have brook characters on a white background and you turn reverse printing on (by typing MIL and 9), everything that appears on the screen is reversed: the characters are M white, white the background behind those characters is black. You can experiment with changing the character colour and using reverse printing, by following these instructions'
STEP 1 Hold down the CTRL key and press the MON key . r
I
CTRL
STEP 2 Release me keys and nold down the space bar
STEP 3 Hold down the space bar as tong as you want. While you hold down the space bar, a line the same colour as the letters on your screen should get longer. II me line gets to the end of the row, it continues on the next row
STEP 4 Release the space bar (but don't press the AMIN key).
STEP 5 Hold down the CTRL key and press one of the colour keys
(not a colour that's already on your screen). As soon as you do this, the cursor changes to the colour of the key you pressed.
STEP 6 Hold the space bar down again. Now your computer draws a or .0 keys and the colour keys. Then hold down the space bar to make more different coloured lines.
STEP 7 Turn off reverse print by holding down all and pressing the
UM, key. Pressing the HENN key also turns off reverse printing.
43
BRIEF INTERLUDE: You can type letters. numbers and punctuation in reversed print Reverse letters make excellent headlines. You can also use them to highlight special words and numbers. You can type graphic symbols in reverse for the same effect. To put a racing stripe on your screen, select a colour you like and type the symbol
— (by pressing .1111OFT and E) across an entire line. Then turn on reverse printing: fill the next line with the samesymbot only reversed. On the next line, type MUT and R (still in reversed print).
Then turn off reverse, and fill the last line with BEM and R (no longer reversed). Now your screen has a racing stripe in whatever colour you chose; perhaps it is a humble acheivement, but it does give your screen a certain flair .
THE FIRST STEP
What is a program, anyway? An experienced programmer might tell you that a program is a series of ordered statements organised to direct the computer to perform a sequence of steps toward some purposeful result. What you may learn from this is not to ask an experienced programmer what a program is.
The following, although it is only two lines long, qualifies as a program
Type it exactly as it appears here. Don't leave out the numbers at the beginning of each line, since they are the line numbers: they ten your computer what order to read and perform the lines of the program. Be sure to press the itiMilt key at the end of each line you type.
10 PRINT"FIRST TRY"
20 GOTO 10
RUN
This line tells your computer to print the words FIRST TRY on your screen.
This line tells your computer to go back to line ' 0 and print FIRST TRY again .
When you type this and press RETURN your computer does what each hne lets it to do.
Press the 1111X/STOP key to stop the program.
Why did your computer print FIRST TRY so many times? PRINT is a
command that tells your computer to PRINT what appears between the quote marks on the screen. When your computer reads this line. it
44
executes (carries out) that command. GOTO tells your computer to go back to line 10 and execute the command (PRINT "FIRST TRY"). Each time your computer got to line 20, It executed the GOTO command, returning to line 10 again and again. This repetition is called a loop.
The
nowarcw
key breaks into whatever program the computer is running, and returns control of the keyboard back to you.
TIP: Want to slow down this program (or any other) without stopping it? Just hold down the key.
Now type the following, pressing MUM after each entry.
NEW
4—
This tells the computer to forget the last program and get ready for a new one.
The computer responds with the message .
READY You don't type this: this is your computer letting you know that it's READY for new commands or programs.
10 PRINT
..N--Press CTRL and RYE OFF
Notice what happens when you type MS ON and RVS On. inside the quote marks. They appear on the screen as reversec characters. Now type RUN and press XXII= to see the program. When the program is RUN, your Commodore 16 reads these reverse characters as what you typed in, and carries out the reverse print as instructed. The same principle holds true (a reversed character appearing on the screen as a representation for what you type) for doing other things in a PRINT statement. like moving the cursor and changing colours, when you RUN a program.
45
Now try me same line. but replace -MS ON and IWS OFF with
PUSH ON and PLASH 017 (the < and > keys)
10 PRINT Mi COMMODORE =16ess CTRL ana FLASH ON
\--Press ern and FLASH OFF
When you RUN this. It PRINTS out COMMODORE 16 just once. But tne word COMMODORE flashes continuously, even though your program has already been RUN. When you use flashing print, it will flash continuously Both of these one-line programs show how to use things like reverse printing and flashing letters in the line of a program You would do other things (change colours, etc.) in the same manner .
Entering Commands
You might have noticed that you typed some things in as just a single word (such as NEW). while on other lines you had to type in line numbers followed by commands and statements within quote marks.
That's because there are two 'modes' that you can use to communicate with your computer. Both are based on a language made up of terms that your computer understands. The most straight-forward (and the one built in to your Commodore 16) is called BASIC. Your Commodore
16 understands a version called Commodore BASIC 3.5. The BASIC terms (or keywords) are the heart of both modes. The first type,
IMMEDIATE MODE, tells your computer to execute the BASIC command immediately. You enter the command to be carried out by your computer when you press the loon key. This is also known as
DIRECT MODE. The alternate mode is known as PROGRAMMING, or
INDIRECT MODE Programming mode features line numbers, and each line contains BASIC commands. The entire program is executed when you type the command RUN, carrying out the commands of the lines according to line number (lowest lines first). Obviously, programming mode is what you use to write computer programs.
CORRECTING MISTAKES
Mistakes are a way of life witn computers. Mistakes in programming must be searched for and remedied for a program to run correctly.
That's what the HELP key is for. A more practical kind of mistake—the typing error—can mess up programs Just as badly. Not only will computing improve your typing skills. you'll make great strides in spotting and correcting typing errors as well. There are several ways to fix up typing errors. Remember that to enter any changes (or anything,
46 tor that matter) either for your computer to execute or into your computers memory. you must press the BMW key
1. YOU CAN EDIT A LINE by overtypIng.
Use the CURSOR KEYS to move to the place in the line that you want to change. Now just type over what you want to change. Press
IIHRIHN. when you finish.
EXAMPLE
10 PRINT IT IS ONE O'CLOCK"
If you want to change the time to TWO. move the cursor to the 0 in
ONE.
10 PRINT "IT !SONE O'CLOCK"
And now just type TWO over ONE and press MOW
10 PRINT IT IS TWO O'CLOCK"
NOTE: When working with numbered program lines. you don't have to be at the end of the ime to press REMUS Your Commodore 16 remembers the whole line even if you press REHM In the middle of the line.
2. YOU CAN OPEN UP SPACES IN A WORD OR LINE with the MST key (press fat along with the trarrOFl key). Hold the keys down until you open up as many spaces as you need. (Notice that the cursor stays in the same place while spaces open up to the right.)
Then just type what you want to insert.
10 PRINT "CORE"
To change this to COMMODORE. move the cursor to the '0' and press the UMW and 'INT keys until enough space opens up. Don't bother to count out the spaces. You can just guess and then open up more if there aren't enough
10 PRINT "C I ORE" cursor
47
Now ado the other letters
10 PRINT "COMMODORE"
3. YOU CAN ERASE CHARACTERS AND CLOSE UP SPACE with the
DEL Key (get delete by pressing the INSTfaRL key by itself). This key erases characters or spaces immediately to the
Cursor
LEFT of the
10 PRINT "AFTERNOON SCHEDULE"
You can change this to WEEKLY SCHEDULE by moving the cursor to the E in AFTERNOON. pressing the INSTM key three times, and typing
10 PRINT "AFTEIRNOON SCHEDULE" and press INST/DEL three times
10 PRINT "IARNOON SCHEDULE" Type in WEEKLY to replace
ERNOON and press MUM
4. YOU CAN RETYPE A LINE anytime, even atter you've RUN the program Your Commodore 16 automatically replaces the old line with the new one when you press RETURN to enter the new line. The old line still appears on the screen, but your computer ignores it. When you nave two statements with the same line number, your Commodore 16 only uses the last one entered. For example, in a brief program using the COLOR command to change the colour of the screen background. a mistake might occur:
10 COKOR 0,3
20 PRINT "COMMODORE 16" mistake
Press the RETURN key to get to a fresh line. and just retype line 10 correctly'
10 COLOR 0,3
Now the first fine 10 is replaced by the second line 10. You can check
48 this by typing LIST which displays a fine-by-line LISTing of your program as it is stored in the computer's memory. When you LIST a program, all lines appear in correct order and the replaced lines don't appear
LIST
The screen reads 10 COLOR 0,3
RETURN
20 PRINT "COMMODORE 16"
You can see what the COLOR command does in this example. For a more complete explanation, see Chapter 6, or look up COLOR in the
BASIC Encyclopedia.
Replacing lines in a program is also a good way to experiment with your computer When you replace a line, the new one doesn't have to be anything like the old line. For example, instead of correcting the spelling of COLOR, you can enter this line:
10 PRINT"COMMODORE 4 TIMES COMMODORE 4 = space
Now RUN the program anc see what happens
5. YOU CAN ERASE AN UNWANTED LINE lust by typing the number of the line and pressing RETURN . The computer ignores the line even though it still appears on the screen Type LIST to get tne program LISTing to make sure the line is gone from the program
10 PRINT "COMMODORE 4 TIMES COMMODORE 4 w "
20 PRINT "COMMODORE 16"
Now type
10
LIST
RETURN
The result, according to your computer
20 PRINT "COMMODORE 16"
49
CLEARING THE SCREEN
There will be times when your screen is too crowded, or you want to reorganize what you've typed. or you're just plain unhappy wan what's on the screen and want to banish it to wherever it is that print goes once a leaves the monitor screen. There are a few ways to accomplish this, leaving the programs in your computer's memory intact or clearing the memory as well as the screen
One way to clear the screen is to hold the SPACE SAP down, until it clears the 1000 spaces on the screen (for a couple minutes or so) If you've read this far into the User's Manual, chances are that you have the patience to clear the screen like this. but also the intelligence to realise trtat there has to be a better way. Here are some better ways'
1. Hold the DOWN CURSOR key + until everything on the screen scrolls off the top of the screen
2. Press the SEIPP and C131/110111E keys together This clears the screen and repositions the cursor at me top left-hand corner. (the
'home position)
3. Type
SCNCLR and press MEOW
This is a BASIC language command teal your computer interprets as instruction to clear the screen
4. Press the RESET BUTTON. Tnis resets the machine, bringing back the starling Screen and clearing all programs out of your computer's memory.
If you want to clear the computers memory but not the screen, type:
NEW and press AMIE
This is a BASIC language command that tells the computer to empty its memory. The 16 in the Commodore 16 refers to the amount of space
(16K) mat your computer has to store programs, known as the memory.
When you clear the screen with any of the first three methods, you clear the characters on the screen, but whatever is in your computers memory stays there. This means you have less space for new programs. The last two methods erase what is held in your computer's memory, so that you again have the full amount of space available for new programs.
50
SCREEN WINDOWS
VYT(S
COMMOI Ff. It fiCADV
wypE
'140Per,
ilth
r°X.V1
221 mailt dCH IIIMPV4V
Windows let you define a specific area of the screen as your workspace. Everything you type (lines you typo. LISTings of programs, etc.) after setting a window appears within the window's boundaries. not affecting the screen outside the window area. You can set up a window anywhere on the screen.
To set a window, follow these steps
STEP Move Me cursor to the screen position you want as the top left corner of the window.
STEP 2 Press the ESC' key and release it, and then press 'T.
STEP 3 Move the cursor to the position you want to be the bottom right corner of the window
STEP 4 Press ESC_ and release. then '8' Your window Is now set.
All screen output is confined to the 'box' you have defined. To cancel the window. press the 4:11MUZ011a key twice. The window is then erased, and the cursor is positioned in the top left corner of the screen.
You can manipulate the window and 1he text inside using the PSC key.
Screen editing functions, such as Inserting and deleting text, scrolling, and changing the size of the window, can be performed by pressing tit: followed by another key. To use a specific function, press the appropriate key after pressing ESC
51
52
L
•
N
O
P
•
•
T
✓
W
X
I
C
•
J
K
KEY FUNCTION
A
8
Automatic insert
Set the bottom right corner of the screen window
(at the current cursor location)
Cancel automatic insert
Delete current line
Insert a line
Move to the beginning of the current line
Move to the end of the current line
Turn on scrolling
Turn off scrolling
Return to normal screen display size
Cancel Insert. quote. reverse, and flash modes
Erase everything from the beginning of the line to the cursor
Erase everything from the cursor to the end of the line
Reduce screen display
Set the top lett corner of the screen window
Scroll screen up
Scroll screen down
Cancels the previous Escape function
CHAPTER 5
NUMBERS
AND
CALCULATIONS
• Introduction
• Numbers and operations
• Calculations
• More about screen PRINTing
• Variables
• Numeric functions
• User defined functions
53
INTRODUCTION
You Cont have to be a mathematics genius to understand and make use of the mathematics capabilities of your Commodore 16. In addition
Co the straight-forward operations like addition, subtraction. multiplication and division, you can use your computer to figure out advanced functions like square roots and sines. you'll learn about the different types of variables. and how to use them. Your computer can handle single digit whole numbers or complex numbers of up to 38 places expressed in exponential notation with equal efficiency. You can do your calculations directly or as part of programs Finally. this chapter gives you a brief explanation of how to set up your own functions for your computer to evaluate.
NUMBERS AND OPERATIONS
You can use your computer like a simple calculator. Besides the standard + and — operation signs, your Commodore 16 uses the • sign for multiplication and the / sign for division and fractions.
(Computers use the • sign nstead of an X for multiplication because a computer can't tell the difference between me letter X and the mathematical symbol X.) You can use these operators and numbers in
Immediate mode (no line numbers) or In program lines. Type In numbers and operators in PRINT statements WITHOUT QUOTES if you want your computer to perform the math involved If the numbers and operators are in quotes (as in PRINT "2 + 2"). your computer will PRINT exactly that on the screen. Instead of performing tne addition. You can get Your computer to put !wo and two together by typing PRINT 2 + 2
BASIC MATHEMATICAL
OPERATORS
Addition
Subtraction
Division and fractions I
Multiplication
•
Exponentiation
(press SHIFT and 0)
BASIC RELATIONAL OPERATORS
Greater than
Less than
Equals
Greater than or equal
Less than or equal
Not equal to
=> or > —
< or gai <
< > Of > <
NOTE: Your computer doesn't accept commas as part of a number.
For example, you have to type 30359 instead of 30.359.11 you put a comma in a number, your computer thinks you mean two numbers
(separated by the comma). and would read it as 30 and 359 instead of 30359.
54
Fractions and Decimals
You can write a fraction like this 5 or like this: 112 Your computer Is actually performing the division
If you put a fraction in a PRINT statement, your answer is always returned as a decimal or whole number. For example:
PRINT 139/493 + 5
5.28194726
ISMS
41" THE PI KEY
Here's an example that uses pi (3.14159265 ). which represents the ratio of the circumference of a circle to its diameter. Use this value by just pressing the IT key (G and
PRINT Tr /374
8.39998036E-03
Scientific Notation
RETURN
What dra your computer mean by the E-03 part of the above answer?
Your computer displays decimal numbers in the range -999.999.999 to
999,999.999 in standard numerals. Numbers beyond this range (with more than nine digits) are automatically displayed in scientific notation.
You can enter numbers in yourself in this form and your computer will read tem with no trouble (certainly less trouble than you had converting them!). Scientific notation is often useful, since this special notation lets your computer display large numbers In fewer digits.
Here is how the number 198.505.478 would be written in scientific notation
Only ONE digit is shown to the lett of the decimal point
98505478E + 8 This number is the number of digit places the decimal point is moved
55
For a number less than one with several decimal places, the second number would be a — instead of a +, indicating that the decimal point is moved to the right.
For example:
.0003359 = 3.359E — 4
Other examples.
20 = 2E + 1 the decimal point is moved 1 digit left
105000 = 1.05E + 5 the decimal point is moved 5 digits left
.0666 = 6.66E — 2 the decimal point is moved 2 digits right
PERFORMING CALCULATIONS
To perform a calculation, type PRINT and then the math problem without quotes, as in the following:
10 PRINT 1+2, 2-1
20 PRINT 2'2, 4/2
RUN
1 3
4 2
For the first lime. PRINT dic) t print exactly what you typed in the statement. Instead, your computer solved the calculations and PRINTed only the answers. All you have to do to use PRINT to calculate is omit the quotation marks. Now try this:
NEW
10 PRINT "2001/2010"
20 PRINT 2001 — 17
RUN
2001/2010
1984 one space is left here for the answers sign
Since line 10 is in quotes. your computer just PRINTs the problem as if
It were regular text: exactly as it appears between the quotation marks.
Notice that no space is left for the numbers sign from line 10. as a is in the printout for line 20. Now move the cursor back to line 10 and change the line to this:
56
I
10 PRINT "2001/2010=";
2001/2010
RUN
2001/20 W = 995522388
1984 fr don't forget the semicolon this space G left for the answers sign the answer for line 20 stays the same
If you want to both PRINT the problem AND solve it you have to type it twice: once in quotes and once out of quotes, as line 10 snows.
Order of Calculation
You can perform more than one calculation In one line. Try typing this:
PRINT 200'50+5
Is the answer what you expected? Try this:
PRINT 50+51'200
Your Commodore 16 always performs calculations in a certain order.
Problems are solved from left to right: within that general rule, some types of calculations are solved first The order that your computer evaluates expressions is called the order of precedence.
FIRST: Your computer checks for negative numbers (not subtrac- tion. just negative numbers).
SECOND: Your computer solves any exponents.
THIRD: Your computer solves all multiplication and division, from left to right.
FOURTH. Your computer solves addition and subtraction• from left to right.
NOTE: Your Commodore 16 always solves any pad of the problem that's surrounded by parentheses first You can even put parentheses within parentheses: 36 • (12 + (A / 3)). The contents of me innermost parentheses are solved first
Sometimes its a good idea to out negative numbers in parentheses for clarity. For example, if you want to multiply 45 by -5. type it like this:
45*(-5) Your computer can understand it with or without parentheses.
57
MORE ABOUT PRINTING ON THE SCREEN
You've probably noticed that certain programs had you type commas in certain places, while in others there were semicolons. Your computer interprets commas and semicolons as instructions for the spacing of the printout
The effect of punctuation on the spacing of PRINT statements works the same with spacing of both text in quotes (called "text strings") and numbers being calculated. Try typing this brief program
NEW
10 PRINT "0","K"
20 PRINT "0";"K"
Notice that the punctuation appears OUTSIDE of me quote marks.
When you RUN the program. the screen looks like this:
0
OK
line 10 PRINTed this line 20 PRINTed this
If line 10 and line 20 are nearly identical, why is there such a difference in what they PRINT on the screen? The only difference is due to the punctuation between the items this program PRINTs.
When you use a comma to separate items in a PRINT statement. the items are PRINTed several spaces apart. When you use a semicolon, the items are PRINTed right next to each other.
As you recall, your computer's screen has 40 columns across. These columns are divided into four 10 space areas, ceded PRINT ZONES.
When you use a comma to separate PRINTed items, your Commodore
16 PRINTs the first item in the first print zone. tne second item in the second print zone, etc. The commas work like tabs on a typewriter.
PRINT ZONE I
: • • 0
PRINT ZONE 2 PRINT ZONE 3 PRINT ZONE 0
It 11.•11'? '1 1 1 l•
IC tInIsix 71277:i It 7;145:7 :11:6 103.1 t2 11 34 IS 14137 la Tr 4 ■ CO.ukt45
II you try to PRINT more than four items separated by commas. your computer automatically goes to me next line to PRINT. For example:
1
f
I
58 spaces the letters like this on your screen:
ROW 1
1 I1 21 31 40 COLUMN
A B C D
2 E F
When you use semicolons to separate items in a PRINT statement, your
Commodore 16 ignores the print zones and PRINTS all the items one alter another
PRINTs this .
ABCDEF
II the first PRINT item is 12 letters long and the second item is separated by a comma. here's what happens:
PRINT "ABCDEFGHIIKL","M"
PRINTS this:
ZONE 1 ZONE 2
ABCDEFGHIJKL
ZONE 3
NOTE: Sometimes you'll type a particularly long line on your computer, such as this:
10 PRINT "I LIKE YOUR TOUCH ON MY KEYBOARD. DO YOU
COME HERE OFTEN?"
You'll notice that as you type this. you run out of room on one row. But keep typing: the Commodore 16 automatically moves on to the next row and continues printing there until your line is finished. You can type as many as 80 characters on one program line (up to two full 40-column rows) .
Now try RUNning this one iine program. The message is printed on two
59
I rows. If your line is longer than one row, your Commodore 16 lets it spill over to the next row Your computer considers the line ended when you press the
anon
key, not when you type to the end of the row. You'll gel used to this as you use your Commodore 16.
USING VARIABLES
The example 36*(12+(A/3)) shows one of the most powerful features of a computer. When you have a letter instead of a number in a mathematical problem, you're using a VARIABLE. A variable represents a value:
10 A = 3
20 PRINT "TOTAL' ;A • 4
II you RUN this program, the screen result is.
TOTAL: 12
There are three types of variables you can use
TYPE
Floating point
Integer
Text string
SAMPLE
SYMBOL DESCRIPTION EXAMPLES VALUES
%
S real (decimal) or whole
X. AB, T4 23.5, 12. numbers 1.3E+2 whole numbers X %. Al % 15, 102, 3 letters. numbers, and all other characters in quotes
XS. MS$ "TOTAL",
"DAY 1", "CBM"
Every time you want a variable to be read as a whole number, the symbol for that variable would include the % sign. A variable that contains text MUST end with a $ as part of the variable. If It doesn't have that symbol, your computer expects a floating point number. A variable without either of the symbols (% or $) is read as a floating point number (a "regular" number). Integer variables (whole numbers) are a subset of floating point variables: they are numbers with no cecimat places. so
Make sure that you always use the right variable type. II you try to do something like assign a word to an integer variable. your program won't work. This program shows you what variable can or can't be used in a given s'tuation, and you can find out what happens when you try out different types of data
10 PRINT "ENTER A NUMBER"
20 INPUT X% this asks you to enter a number for the variable
30 PRINT "I READ YOUR NUMBER AS"; X%
40 PRINT "NICE GOING, ACE!"
50 END
When you RUN this program, try to enter these values (one each time you RUN it) when you're asked and see what happens
ONE FIFTH
043
10
I
I
I
I 'I I
NUMERIC FUNCTIONS incuaeo at your computer s BASIC language are numeric functions. which are like the advanced calculations found on most scientific calculators (such as sine. cosine, tangent, etc.)
Most of the functions can be used by typing tne name of the function and the number to be operated by the formula in parentheses. like this .
FUNCTION(X)
For example, to find out the sire of a variable you would type
PRINT SIN(X) with X as any number you want to input.
61
You could also include one of the functions in a program line. as the following example shows:
10 FOR Xn 110 5
20 PRINT "THE SQUARE ROOT OF"; X; "IS"; SQR(X)
30 NEXT X
You'll find a complete listing of the numeric functions in the BASIC
Encyclopedia in the back of this manual.
NOTE: Most commands have an abbreviation that you can type instead of typing out the entire BASIC name. Your Commodore 16 interprets the abbreviation exactly as It would read the full name. An example of an abbreviation is as follows.
L then
an
r on your screen
Your computer reads this as if you'd typed out LOAD. Abbreviations are useful as a timesaver. There is a complete list of the accepted abbreviations in the BASIC Encyclopedia.
User Defined
Functions
An effective way to use your computer's math capability is to create user defined functions. User defined functions are extremely useful in calculations, and easy to implement using your Commodore 16. User defined functions allow you to program a formula, and then let your computer plug in values to be calculated. This can be used for many different purposes.
Here Is a statement utilizing the user defined function for calculating the value of a secant:
10 DEP' FNS(X) —
This figures out the value of the secant of any number entered for X.
FNS is the name of the function defined by this statement. Appendix C contains a table of mathematical functions not included in your computer's BASIC language.
User defined functions save memory space when you would use a function more than once, and make your programs easier to read and understand.
62
I I
I 1 I
I I
I I
CHAPTER 6
GRAPHICS
AND
COLOUR
• Graphics characters
• Character animation
• Controlling colours
• High resolution graphics
• Points, lines. and labels
• Squares, circles, polygons, and painting
• Multi-colour graphics
I f
I I
I I
63
GRAPHICS CHARACTERS
You should remember from Chapter 2 that each letter key contains 2 different graphic characters, as do the
a. - *,
and f keys for a total of 62 different graphic characters To print these graphic characters, you graphics symbol you want.
When your Commodore 16 is not in typing mode, hold down SEPT and press a letter key to print the graphics character on the right side of that letter key. These characters include the playing card suits, a solid and a hollow ball, and a set ol lines and connecting characters that you can use to draw many different pictures on your screen.
The
a
key pressed with a letter key always produces the graphic character pictured on the left front ol the key. The lett side graphics are an assortment of bars, squares, lines and blocks, useful in drawing charts and graphs.
Pick a Card, Any Card
Here is an example to help give you a better idea 01 how to use the graphic characters to create representations. Follow these instructions to create a playing card, in this case the six of hearts,
First, change the cursor colour to red. Hold down the with the "3" key to change the cursor colour.
crm,
Rey along
U C
Now it's time to draw the top edge of the card: Press the SIMPT1OCK key so that it stays down Press "U". followed by the "C" key 5 times, and then the "I''.
B
64
To draw the lett side: Keeping the ifillniLOCat down, go to the space directly beneath the curved edge (where you pressed the "U" in the last step. Press the "B" key, then cursor to the space directly beneath the line segment you lust drew and press "8" again. Do this until you've pressed the "8" key a total ol 7 times. (Using the cursor keys will be tough at first: you'll get better with practice.) r
1
-1-1
J C K
To draw the bottom edge: Similar to the top edge, you press "J" once and then press the "C" key 5 times, finishing off with the "K" key.
To draw the right edge: Draw this in the same fashion as the left edge, pressing the 'B' key a total of 7 times (while cursoring to the appropriate place)
65
Release the SEM LOCI by pressing it once In the upper ieft corner
(one space down and one space over from the rounded edge) press the
'6' Go to me bottom right corner, position the cursor one space up and space to the left and type another '6'
SHIFT S
6 \
•
•
6
Now to get down to the heart of the matter-6 of them lo be exact.
Press the EMT TANS down again. Go one space down from and one space to the right from where you typed the 6. Press the 'S' key. hit the
SPACISAA., and press the 'S' again. Cursor down two rows and repeat the 'S-SPACE -S' sequence. Add the last two hearts two more rows down. You now have an official six of heals playing card This won't do you too much good in a game of blackjack, however. If you want to improve your hand. create a couple of cards of your own
I
I
I
I
NOTE: When the .8Wireleat is down, you can press =FROM and not gel a SYNTAX ERROR from your computer as a response. Even though you had characters on the line that weren't commands that the computer can understand, your computer interprets the MMUS key as just an instruction to return to the beginning of the next line when the 'SIM key is held down. Your computer does not try to read or interpret what has been typed as BASIC language commands when NOT or SEM LOCI is down.
You can use the graphic keys to enhance your printout For example, here's how to underline a word or column:
First. move the cursor to the line below what you want to underline.
Then hold down the :6- key and the "T“ key, which prints an underline space. Hoid these two keys down until the entire portion of text is underlined
The purpose ol this section is to show you how the graphic symbols of your Commodore 16 can be manipulated to create different shapes and figures and used in a more practical sense. In addition to the 62 graphic characters available to you, you can also use the reverse of these characters. (Remember the racing stripe!) Now that you have a good idea of what is involved in using the graphic symbols to build different forms. you should experiment with them yourself, and see what you come up with.
CHARACTER ANIMATION
Movies are really a sequence of still pclures Eacn picture is a little different from the one that came before. The projector shows each picture for a very short time. then goes on to the next one. The scene becomes animated.
Computer animation works the same way. F irst the computer draws one picture. then it changes the picture slightly. Your Commodore 16 is fast enough to move objects smoothly around the screen in your games and practical programs. A movie is animated at a rate of 30 pictures per second. The changes are fast enough to fool the eye and create the illusion of movement. The only way you can attain the speed to create
67
66
this illusion on your computer is to use a program to draw a picture. wait for a split second. then change to a new picture.
To get the program to create pictures you would use the PRINT statement with the graphic characters. The simplest type of animation involves aternating Iwo characters to get the effect of movement.
This program simulates animation by alternating the circle (WWI & 0) and heart Can & S) symbols. If you use your imagination, you could consider this a heartbeat of sorts
IMPORTANT TO NOTE: Each time
mon
or -0 is referred to, if snould be typed at the SAME TIME as the key following it when entering the program. since nothing happens when either is typed by
Itself.
Remember to type NEW and preSs -MOW before entering each new
Program. and press
arms;
to enter each line in all these programs.
10 PRINT " HOME SMUT
20 FOR L=1 TO 100
30 NEXT L
40 PRINT " BONE SHIFT S"
50 FOR M=1 TO 200
60 NEXT M
70 GOTO 10 type these keys simultaneously
You'll see the obvious limitation of animation alternating two characters when you RUN this program To stop it. press the itifilititop key.
To get a more interesting effect you can build a small picture from several graphic characters. then change a few of the characters while leaving others in the same pace This gives the effect of pan of a larger object moving, as in the following program:
68
10 PRINT " HOME SHIFT M SHIFT W SHIFT N "
20 PRINT " SPACE 0 + SPACE "
30 PRINT " SHIFT N SPACE SHIFT M
40 FOR L =1 TO 300: NEXT L.
50 PRINT " SOME SPACE SHIFT W SPACE "
60 PRINT " Cr T 0 +
70 PRINT " SPACE
T "
0
G 0 G"
80 FOR L =1 TO 300: NEXT L
90 GOTO 10
\o/
• • • •
• • • •
•
• • • •
• • • •
• • • •
• • • •
• • •
Type RUN and press wuaa
..
In both examples of animation so far, the figure has been stationary in one area on the screen. The next step is to move the animated figure around. The TAB function helps when you want to move objects from the left edge. (The TAB function is explained in detail in the BASIC
Encyclopedia.) The following program portrays a snake crawling on the screen.
Remember that
sain
and the following key are stile typed together.
S FOR A=0 TO 30
10 PRINT " SHIFT CUt "
20 PRINT TAB (A) " stun U girt I SETT U Sri I "
30 PRINT TAB (A) " SHIFT K SHIFT J SHIFT K SHIFT I SHIFT 0"
40 FOR L=1 TO 100: NEXT I.
50 PRINT " SHIFT cut "
60 PRINT TAB (A+1) stun I SHIFT U senrr I Sinn U SHIT
70 PRINT TAB (A+1) " stun I
80 FOR L=1 TO 100: NEXT L
SHIFT K SHIFT J SHIFT K
90 NEXT A
W"
Lines 20 and 30 should look like this when typed in
Lines 60 and 70 will look like this:
69
Using characters like the ball (SHIFT 0), you can play video games on the screen. To move a ball, just erase the ball and replace it at a new position, as in this program
10 PRINT " SHIFT CLH "
20 PRINT " SPACE SW F QOM".
30 FOR L=1 TO 50: NEXT L
40 GOTO 20
Left cursor arrow when you want to stop moving the bail
CONTROLLING COLOURS
Separate colours can be put into each part of the screen The border can be one colour, the background a different one, and each character can have its own colour You already know how to set the Character colours using the keyboard. You can change the colours of the other screen areas using the BASIC language command COLOR
For example. you can turn the border of your screen red by typing the command COLOR
4,3 and
pressing the
anus.
key. The number 4 in the command stands for the border area. and colour number 3 Is red
(the same number as on the key marked RED).
Try typing COLOR 0, 7 and hitting
arm.
The screen background now turns biue. The number 0 stands for the background, while the 7 Is blue (also the same as the keyboard)
.
The first number after the word COLOR specifies the area on the screen you want lo change. This table lists what each screen area number controls: you'll learn about areas 2 and 3 when you get into multi-colour graphics later in this
chapter
.
Screen Area Numbers
AREA is
0
2
3
4
AREA NAME
Background
Character
Multi-colour
Multi-colour 2
Border
CHARACTERS
BACKGROUND
BORDER
71.)
I
I
I
I
1
I I
I I
I f
I I
(
I
I
I
I I
I I
I I
I I
The second number after COLOR selects the colour you want to put on
the
area of the screen you've specified. The colour numbers correspond to the colour keys on the
keyboard.
Colour Numbers
COLOUR //
5
6
7
8
1
2
3
4
COLOUR
BLACK
WHITE
RED
CYAN
PURPLE
GREEN
BLUE
YELLOW
N
9
10
11
12
13
14
15
16
COLOUR
ORANGE
BROWN
YELLOW GREEN
PINK
BLUE GREEN
LIGHT BLUE
DARK BLUE
LIGHT GREEN
Each colour also has an adjustable brightness level, called the luminance You can add a number train 0 (darkest) through 7 (brightest) after the colour number to vary the colour. Type COLOR 4 ,3, 0 and press WWI The border becomes a dark red. Type COLOR 4, 3, 7 and the border changes to a bright red.
In short. the COLOR command looks like this.
COLOR area. colour, luminance
Here is a quick program to show you all your Commodore 16's colours:
First type NEW and press
moan
10 COLOR 0, 7, 7
20 FOR M=0 TO 7
30 FOR N= I TO 2
40 FOR L=1 TO 16
50 PRINT " CTRt SVS ON type these keys together
60 READ A
70 COLOR 1, A, M
80 PRINT " SPACE SPACE
90 NEXT L
100 PRINT
110 RESTORE
120 NEXT N,14
130 COLOR 1, 2, 4
200 DATA 7,14,4,13,6,16,11,8,10,9,3,12,5,15,2,1 c www.commodore.ca
May Not Reprint Without Permission
71
When you RUN this program, the screen background changes to a light blue, and the spectrum of Commodore 16 colours is shown at each luminance level. You'l notice that black is the same at all luminance levels.
NOTE: Like most of the BASIC graphic terms reviewed in this chapter. COLOR may be referred to as a statement or command interchangeably
.
THE GRAPHIC COMMAND
The graphics you've seen so far use only the keyboard without really taking advantage of your computers capabilities. The BASIC language of your Commodore 16 contains commands to draw shapes and forms through programs. To use the graphics-related commands of your computer, you must enter a new mode, the GRAPHIC mode. Graphic mode can be considered the drawing mode, since all the drawing commands are "activated". You can't use these commands until you specify exactly what graphics mode you want to use you specify which type of graphics mode you want by using the GRAPHIC command. There are three different modes: normal text, high- resolution graphic and multi-colour graphic modes. With the
GRAPHIC command, you can even have part-text, pail-graphic screens that !el you can write on one part of the screen and draw on the rest.
The command to enter this new mode is GRAPHIC.
In general tne GRAPHIC command looks like this:
Mode number Effect
0
1
2
3
4
Text
High-resolution graphics
High-resolution graphics + text
Multi-colour graphics
Mullicolour graphics + text
Clear number Effect
0
1
Don't clear screen
Clear screen
I I
I I
I I
I I
I
I
I 1
I I
I ' 1
I
I f
I I
I I
I I
I.
(
I f
I
I
I I
To switch from the normal graphics (of text mode) to high-resolution, just type the command GRAPHIC 2,1 and press
irrupt
The screen goes blank and the cursor reappears near the bottom of the screen.
Your Commodore 16 screen is divided into 2 separate sections: the top for graphics and the bottom five lines for text. If you don't want the bottom live lines for text, you can use the command GRAPHIC 1,1, but you won't be able to see any commands you type. You can switch back and forth from graphics to text using the GRAPHIC command
The command GRAPHIC 0 switches the screen back to text, while
GRAPHIC 2 switches back to high-res without erasing the screen
Adding ,1 after the command erases the screen.
There is another way to clear the high-resolution screen. The command SCNCLR erases the screen without changing the graphic mode Once you use kgh-resolution graphics, the computer sets aside
10K of memory for your nigh-res screen, This memory is taken from the BASIC program area. When you are through using graphics, you can reclaim this memory by using the command GRAPHIC CLR.
HIGH RESOLUTION GRAPHICS
Your Commodore 16 screen contains 25 rows of 40 characters each, or 1000 total character positions on the screen Each character is formed out of single dots, with 8 rows of 8 dots each making an entire character. Your screen has a total of 320 dots on each row, and 200 rows of dots. or 64.000 dots all together The high resolution graphics on your Commodore 16 give you control over every single dot
Using normal graphics, you have limited control over the individual dots. Drawing a racing stripe or a playing card is a nice little exercise, but your creation is limited to using the characters (letters, graphic symbols, etc.) on your computer keyboard. You can still create all kinds of shapes and figures. but just a fraction of what you could do if you could control each dot by itself. The high resolution graphics capability of your Commodore 16 lets you do just that. Resolution
73
refers to the precision and controi you have in drawing; with nigh resolution graphics, you can use commands that let you draw and erase dots, lines, circles, and other shapes.
There is one limit to high-resolution (hi-res for short) graphics. Your computer can only use Iwo colours in each 8 x 8 character position.
That is, each 8 x 9 space on the screen (where a single character would fit) is limited to two colours (foreground and background colour for that square). You can use different colours for each different character position, but only two colours within mat position. Another graphic mode that will be covered later in this section, multi-colour mode, allows up to four different CC:PIC/WS per character position at the cost of the resolution available in the high-resolution mode
Here is a program that utilizes some of the high resolution graphics capability of your computer and the GRAPHIC command in particular.
Clear the computer's memory with the NEW command so you're sure that tnere are no left-over program fines, and Then type.
10 COLOR 0,1
20 GRAPHIC 1,1
30 FOR L=2 TO 16
40 COLOR 1,L,2
50 DRAW 1,0,1.'12 TO 319,1.4 12
60 DRAW 1,1;18,0 TO L•18,199
70 NEXT L
80 FOR L=1 TO 5000:NEXT
90 COLOR 1,2,7
100 GRAPHIC 0
Notice that the colours change near the intersections. This is due to the limitations of hi-res graphics, with too many colours too close together.
Points. Lines and Labels
Type the commands GRAPHIC 2,1: DRAW 1,0,0 and press arm
Look closely at the upper left corner of the screen. Your Commodore
16 drew a white dot there Tne DRAW command can be used to draw a singe dot anywhere on the screen, a line. or a shape.
74
Some forms of the DRAW command are
COMMAND RESULT
DRAW colour source. column, row
DRAW colour source. column, row TO column. row
DRAW colour source TOcolumn, row
POINT
LINE
LINE DRAWN FROM
LAST POINT
Colour source Is 0 for the background. I for the foreground. Anything drawn in the background colour (0) is the same as erasing the foreground colour at that spot.
In the DRAW command, the first number is either 1 (draw a dot) or 0
(erase a dot). The next two numbers are for the column and row positions for the dot. So if you wanted to draw a dot at column 1 7, row
20, you would type DRAW 1,17,20. To erase Me same dot, you'd type
DRAW 0,17,20
The DRAW command can also draw a line between any two points.
Just add the word TO and the coordinates of the other end, like this.
DRAW 1.1,1 TO 100,1 00. This draws a line from the dot at 1.1 to
100,100. You can erase this line by typing the same command, just substituting a 0 for the I immediately after DRAW
.
If you are used to drawing graphs in math, you might get a little confused at first while using the computer. The coordinate system in your Commodore 16 is different from what you've used before. In math the 0.0 point would either be at the centre or the lower left corner of the screen, but on your computer Ills the upper left corner. You'll get used to this system as you practice.
Once you nave put a point or line on the screen, you can draw a line from it to any other point like this: DRAW 1 TO 150,50. This draws a line from the last point drawn to column 50 row 150. If your program uses a lot of DRAW TO commands, you could place the first dot at a position on the screen by using the LOCATE command. as in
LOCATE 100,100, to immediateiy return to the first position .
75
I his program draws a curve based on the sine function.
NEW
10 COLOR 0,1
20 COLOR 1,2
30 GRAPHIC 1.1
40 LOCATE 0,100
50 FOR X=1 TO 319
60 Y = INT (100+99 • SIN(X120))
70 DRAW I TO X,Y
80 NEXT X
90 FOR L=1 TO 5000
100 NEXT L
110 GRAPHIC 0
Don't type NEW after RUNnIng the last program To plot the program differentlychange line 7010'.
70 DRAW 1, X, Y
This program plots the same curve using points instead of lines .
The Char Command
Graphs are more easily understood and useful it you label them. You can use the CHAR command to mix text right into a high resolution drawing. For instance tne statement CHAR 1,0,5,"HELLO" puts the word HELLO into the sixth row at the left edge of the screen (the first row is '0'). The first number after the word CHAR is either 1 (for draw) or 0 (for erase). The next two numbers are the column and row where the text appears.
Leave the last two programs in the computer: don't type NEW. Add these lines:
76
I
I I
f
I I
I (
I
I
81 CHAR 1,0,0,"GRAPH OF":CHAR 1,0,1,"FORMULA"
82 CHAR 1,0,2,"Y=SIN(X)"
83 DRAW 1,0,100 TO 319,100,189,0 TO 189,199
84 CHAR 1,0,12,"X-AXIS": CHAR 1,22,0,"Y"
85 CHAR 1,22,2,"A": CHAR 1,22,3,"X"
86 CHAR I,22,4,"I": CHAR I,22,5,"S" a r t
SQUARES, CIRCLES, POLYGONS AND PAINTING
Using me DRAW command. you can draw pictures by plotting many dots or lines. To draw a square. you can use the commanc DRAW
1,0,0 TO 100,0 TO 100,100 TO 0,100 TO 0,0 to connect four dots with four lines (plotting each endpoint of the square) or you can just use the
BOX command.
Drawing Rectangles
One of the graphic commands of your Commodore 16 makes It easier to draw squares and other rectangular shapes. The BOX command lets you pick the points of 2 opposite corners of the square. To duplicate the same box as in tne above example, just use BOX
1,0,0,100,100. The number I again means that you want to draw and not erase. The next four numbers are me coordinates of the box's opposite corners, (0.0) at the upper-left corner and (100.100) near the middle of the screen.
The BOX command can form any rectangle just by changing the corners. You can even rotate the box by specifying an angle (in degrees) after the last coordinate, like this: BOX 1,50,50,100,100,45.
The box is rotates 45 degrees clockwise so that it resembles a diamond shape.
If you would like to draw a solid box instead of just the outline, you just add a corrima 1 alter me angle. A solid box at the centre of the screen is shown as BOX 1,100,50,220,150„1. Notice that you need a comma
77
to take the pace of the angle, even though you don't want the box rotated. This Is so your computer reads the comma as the DEFAULT value, which means that it interprets your lack of response as an instruction. If you don't include the comma, the 1 at the end of the line
Is read as the angle for the box to be rotated.
Some typical forms of the BOX command are: '
Command
BOX on. column 1, row 1, column 2. row 2
BOX on, col 1, row 1, col 2, row 2. angle
BOX on. col 1, row 1. col 2, row 2. , fill
BOX oft, col 1. row 1, col 2, row 2, angle,
Effect
Outline
Rotated
Solid box
Erase area of screen
Column 1, row 1, etc. are screen positions of endpoints that you specify. Column 1, row 1 is the upper left corner of the box. while row and column 2 is the bottom right corner
Here Is a program that illustrates the BOX command (line 60)
10 COLOR 0,1
20 COLOR 1,2
30 GRAPHIC 2,1
40 A us AND(1)* 20+ 10
SO FOR L-0 TO 359 STEP A
60 BOX 1, 100, 30, 220, 130, L
70 NEXT L
80 FOR Loot TO 2000: NEXT L
90 GRAPHIC 0,1
Drawing Circles
Your Commodore 16 also nas commands for drawing circles. Like the
BOX command, you can vary the shape of the circle (to form an oval or an ellipse), and you can rotate the oval. You can also just draw a section of the shape (called an arc).
78
The usual forms of the CIRCLE command are:
Command
CIRCLE on. centre column. centre row, radius
CIRCLE on, ocol, c-row, width, height
CIRCLE on, c-col, c-row, wid, ht, Start, finish
CIRCLE on, c-col, c-row, width, height...angle
CIRCLE on, c-col, c-row, wid, ht,,.,point angle
Effect circle oval arc rotated oval
Polygon
This commano draws a circle in the centre of the screen: CIRCLE
1,160,100,50. This tells your computer to draw a circle with its centre at column 160 and row 100. with a radius of 50. This may actually produce an oval, since the dots on some TV's and monitors (American ones, for example) are taller than they are wide. To change this to a real circle you must add a separate number to tell that the height is different from the width, like this: CIRCLE 1,160,100,50,42.
Drawing Polygons
Your Commodore 16 can also draw a square, triangle or other polygon using the CIRCLE command. Just tell the computer how many degrees to go between points on the circle, like this: CIRCLE
1,160,100,50,42,,,,120. This command draws a triangle, since each side is 120 degrees. (Remember that omitting number values while including commas in a graphic command causes your computer to read standard default values for the missing number.) A simple formula to get the angle for a polygon with N sides is 360/N.
Here's a quick program for drawing polygons:
10 GRAPHIC 2,1
20 INPUT"HOW MANY SIDES";A
30 IF A<2 OR A> 100 THEN PRINT "DONT BE RIDICULOUS":
GOTO 20
40 CIRCLE 1,160,80,40,33„„360/A
50 GOTO 20
You can choose to draw only an arc Instead of a whole circle. The
CIRCLE command accepts the starting and ending angles in degrees,
79
right alter the height number The command CIRCLE
1,160,100,50,42,90,180 displays only the lower right section of the circle. To rotate an oval, add the angle of clockwise rotation after the command, like this example: CIRCLE 1,160,100,100,20,,,30.
Here's a program that uses CIRCLE commands for an interesting effect. Don't forget to clear your computer's memory by typing in NEW if you entered the last program
10 COLOR 0,1
20 COLOR 1,2
30 GRAPHIC 1,1
40 A = RND(1)• 20+ 10
50 FOR L=0 TO 359 STEP A
60 CIRCLE 1, 160, 100, 80, 40„,
70 NEXT L
80 FOR L=1 TO 2000: NEXT L
90 GRAPHIC 0,1
This program will be slightly different each time you RUN it.
The Paint Command
To make a circle or other shape more than just an outline. you can use the PAINT command The PAINT command fills In any enclosed area up to the boundaries formed by lines drawn on the screen. If there are no lines drawn, the screen is filled right to the edge. The BOX command has a fill option that colours in boxes and rectangles. The
PAINT command can colour in irregular shapes and other non-uniform areas on the screen that can't be filled with other commands.
To see what the PAINT command does, add this line to the last program:
80 I
75 PAINT 1, 160, 100
MULTI-COLOUR GRAPHICS
The Commodore 16 high resolution graphics give you control over every single dot or "pixel" on the screen, but you have seen that the ability to pat colours close together is limited. Most hires programs can use only one or two colours. For including more different colours. your computer has a special "In-between" graphics mode called multicolour graphics. In multicolour graphics. you control half as many dots on each row as in hi-res because each dot is twice as wide. You get
160 dots on each row, while still getting 200 rows. There is a trade-off for the use of multiple colours, which is slightly lower resolution.
To begin using multicolour graphics. review the GRAPHIC command earlier in this chapter. You'll see that the multi-colour screen without text is GRAPHIC 3 and the multi-colour screen with 5 lines of text is
GRAPHIC 4.
Now look at the table listing the COLOR command. There are two areas that we haven't used yet, areas 2 and 3. These areas hold two extra colours. You can use any of the three colours (1. the text colour;
2. an extra colour: and 3, another extra colour) These colours do not interfere with each other on the screen the way the hi-res colours do in some previous programs in this chapter.
This program makes use of multi-colour graphics, showing a "neon sign" effect.
81
82
NEW
10 COLOR 0,1
20 GRAPHIC 3,1
30 COLOR 3,1
40 TRAP 200
50 DRAW 3,10,10 TO 10,100: DRAW 3,10,55 TO 30,55
60 DRAW 3,30,1010 30,100: DRAW 3,50,10 TO, 80,10
70 DRAW 3,65,10 TO 65,100: DRAW 3,50,100 TO 80,100
80 FOR L=0 TO 7
90 COLOR 3,2,L
100 FOR M=1 TO 100: NEXT M
110 NEXT L
120 COLOR 3,1
130 FOR M=1 TO 100: NEXT M
140 GOTO 80
200 GRAPHIC 0: COLOR 1,2,7
Colour area 3, the second of the multicolour areas, has a special ability that none of the others has. Once you have drawn on the screen using area 3, you can change that colour everywhere it appears on the screen by using the COLOR command. If you set the colour with
COLOR 3,5 and draw using that colour, your graphics appear In purple. II you then change the colour with COLOR 3,6, all the purple areas would change to green. This doesn't work with any other area.
The Series 264 Programmers Reference Guide contains more information about graphics.
CHAPTER 7
SOUND
AND
MUSIC
• Introduction
• Volume command
• Sound command
• Creating sound effects
• Making some music
• The Music Machine
83
INTRODUCTION
Here is a short program to make music on your Commodore 16. After you've typed it in, when you RUN it, a question mark will appear on your screen Type any number from 0 to 1015 as your response and press RETURN To stop the program, enter a zero as your value.
10 VOL 8
20 DO
30 INPUT X
3S IF X >1015 OR X <0 THEN PRINT "0 TO 1015, PLEASE": GOTO 30
40 SOUND 1, X, 10
50 LOOP UNTIL X=0
Pressing the RUN/STOP key also stops the program
.
Here's how to play a sing* note on your Commodore 16
First. Type VOL 8 and press RETURN
Second Type SOUND 1,266,60 and press RETURN
You should hear a note play for about a second and then stop. You might cons:der this an unfinished symphony in the most extreme sense of the word (one note down, 3,500 to go). If you don't hear anything. turn up the volume of your teievision or monitor and try it again
These two steps are the only commands that you need to know to play music on your Commodore 16. Both commands are easy to understand and easier to use
.
The Volume Command
The VOL command controls the VOLume of the notes that your
Commodore 16 plays. The number that comes after VOL is the setting for the volume. This command works pretty mucn like the volume knob on your TV. When it is set at zero (VOL 0), the volume is off and you won't hear anything. When you set it at 8 (VOL 8), the volume is turned up all the way, and your computer plays as loud as it can.
84
Try the first example again and use a different number after the VOL command. The larger the number, the louder the note is played.
The Sound Command
The SOUND command tells your computer everything it needs to know about the sound you want to play. The SOUND command is followed by three numbers that describe the note
SOUND voice, note value, duration
The first number in the sound command refers to voice. The number
for voice can be a 1,2 or 3 The Commodore 16 sound Is produced by
Iwo different "voices". I for the first voice and 2 for the second voice.
The third voice option applies to voice 2's capacity to produce either a tone or noise.
Voice 1 - This voice plays only tones. Select this voice with a 1 after the SOUND command
Voice 2 - This voice is like voice but can be used to play tones or noise for sounds. Type a 2 in the command to use this voice for tones, or a 3 to use this voice for noise, to make sound effects like thunder and rain
The second number after the word SOUND is the note value
(frequency). This can be any number from 0 to 1015. It tells your
Commodore 16 how low- or high-pitched a note to play. As the numbers get larger, the notes get higher. The highest values (in the
1015 neighborhood) are not audible to the human ear.
Note: Wan voice 3, noise is "white" only in the range of 600-940
You can use register values outside this range to create interesting sound effects.
This displays all of the notes in one scale, along with the note value to use There is a complete chart of notes for the Commodore 16 n the appendix.
85
1
I o A BCDEPOWDEFGA 8 cDEP
Ifi
!
Middle
C
NOTE
VALUE
A B C D E F
770 798 810 834 854 864 881
ACTUAL FREQUENCY 440.4 494.8 522.7 588.7 658 699 782.2
(HZ)
Try the following program:
NEW
10 VOL 8 c sets VOLume
20 X = 0
30 DO
40 SOUND 1,X,5 c
50 X = X + 5 plays note
60 LOOP UNTIL X = 1015
70 VOL 0 c
80 END turns off VOLume
This program shows off some of your Commodore 16's musical range .
The third number after the word SOUND controls the duration (length) of the note This tells your computer how long to play the note. This number can be anything from 0 to 65535. This number sets a timer,
86 which counts time in sixtieths of a second. A duration or 60 keeps the note on for one second. The rule of thumb for duration is the larger the number, the longer the note stays on. In fact, if you use 65535, the note stays on for over 16 minutes. To turn a sound off, use a zero duration, which does not allow the sound to be produced .
A Musical Sound Effect
Sound effects can oe created using either musical tones or noise.
Combining simple BASIC programs and sound commands can generate unusual and entertaining effects. For instance, the FOR . .
NEXT . STEP loop can be used creatively in sound effects. This command sets up a loop: each time the computer reads FOR, it changes the counter variable (S in this example). When it reads NEXT, it goes back to the FOR statement. This program uses a FOR .
NEXT loop with a negative STEP. to count down from a high number to a lower one by 25 at a time
10 VOL 8 sets VOLume at 8
20 FOR 5=1000 TO 700 STEP —25 -4-- creates loop, with
30 SOUND 1, S, 1 downward STEPs
40 NEXT S
Type RUN ano press
moan
to hear the sound effect. The key is line
20. which selects a number range from 1000 to 700 going down the scale. STEPping down 25 numbers at a time. Finally, line 30 instructs your Commodore 16 to play each note for just an instant by setting the
DURATION to 1, which is 1160 of a second. Experimenting with different number and duration values can give you some very interesting effects.
Creating a Noise Sound Effect
Using a value of 3 when selecting a voice in the SOUND command specifies noise. This is used to create sound effects with noise rather than tone. The following program uses voice 3 to create the sounds of a windstorm.
10 VOL 2 -lc— sets VOLume level
20 R=INT(RND(0)•10)+1 .-rt— selects RaNDom number from 1
30 FOR X=1 TOR
40 SOUND 3, 600+30.X, 10 to 10
(continued on next page)
87
50 NEXT X
60 FOR X =R TO I STEP -1
70 SOUND 3, 600+30•X, 10
80 NEXT X
90 T =INT(RND(0)6 100)+ 30
100 SOUND 3, 600, T
110 GOTO 20
Lines 30 and 60 set up FOR . . . NEXT ioops for the note value
(frequency) of the sound, one increasing and one decreasing. based on the random number from line 20. It Is important to have variation in pitch, since windstorms have different forces of gusts of wind. Lines 40 and 70 are the SOUND commands that create the noise. Lines 90 and
100 set up a random delay to recreate the uneven nature of a windstorm with time lapses between howls. The program selects a
RaNDom number that is used for the duration of another SOUND command. This SOUND command stays at the same pitch and provides a consistent background noise that serves as a counterpoint to the gusts of wind. This may seem pretty compiicated. like you need to be an experienced programmer to be able to do it. But it's really nothing more than experimenting, trying different things, and seeing what noise comes out. Creating sound effects using noise IS challenging, trying to capture the right elements of the sound you want exactly. To be good at it. you have to be willing to experiment.
Making Some Music
You may not understand everything that's going on in these programs, but type them in anyway and see what happens.
This program simulates a piano using the keys from 1 through 8
S SCNCLR
10 FOR X=1 TO 8: READ N(X): NEXT X
20 VOL 8
30 DO
40 GET A$: IF A5-="" THEN 40
50 A=ASC(A$): IF A <49 OR A > 56 THEN 90
60 N=A-48
70 SOUND I, N(N), 5
80 COLOR 4, N, 3
90 LOOP UNTIL A=32
100 VOL 0: COLOR 4, 2, 7
110 DATA 169, 262, 345, 383, 453, 516, 571, 596
88
•
I
Press numbers 1 through 8 to play notes. The screen border even changes colours with the different notes. Wnen you finish playing, press the space bar to stop the program.
Now that your Commodore 16 can be used like a piano. you might feel the urge to play a popular song. Here are the numbers to press to play a well-known song that surely must be considered a classic.
1 1 5 5 6 6 5
4 4 3 3 2 2
1
5 5 4 4 3 3 2
5 5 4 4 3 3 2
1 1 5 5 6 6 5 47
4 4 3 3 2 2 1 r r
S S 6 6 5
This next program Ways a song by reading a list of DATA statements
Your computer READs the numbers contained in the DATA statement as values for variables (in this case X and Y). changing the values with each loop. The DATA statements are in pairs. The first number is the note value for the SOUND command and the second number is the duration for the SOUND command.
Row Boat
10 VOL 8
20 DO
30 READ X, Y
40 SOUND 1, X, Y
45 FOR D=1 TO Y•16+30:NEXT
50 LOOP UNTIL X=0
60 END
100 DATA 169. 45, 169, 45, 169, 30
110 DATA 262, 15, 345, 45, 345, 30
120 DATA 262, 15, 345, 30, 383, 15
130 DATA 453, 60, 596, 45, 453, 45
140 DATA 345, 45, 169, 45, 453, 30
150 DATA 383, 15, 345, 30, 262, 15
160 DATA 169, 60
200 DATA 0, 0
This loop creates a brief delay between notes
89
THE GREAT COMMODORE 16
MUSIC MACHINE
The last program is a little longer. This is the "GREAT COMMODORE
16 MUSIC MACHINE". When you press a key from 1 through 9, the note is played. and a note appears on the staff on the correct line.
5 GOSUB 1000
6 FOR X =1 TO 9: READ N(X): NEXT X
8 CHAR 1, 8, 1,"•THE GREAT MUSIC MACHINE•"
10 VOL 7
20 DO
30 GET A$: IF AS= 'f" THEN 30
35 A =ASC(A5): IF A <49 OR A> 57 THEN 50
36N=A-48
40 SOUND 1, N(N), 4
45 GSHAPE N$, 150, 8 • (6+(9-N)), 4 no space
46 FOR Z=1 TO SO: NEXT Z
47 GSHAPE 14$, 150, 8 • (6+(9-N)), 4
50 LOOP UNTIL A=32
55 VOL 0: GRAPHIC 0: SCNCLR
60 END
100 DATA 345, 383, 453, 516, 571, 596, 643, 685, 704
1000 GRAPHIC 1,1
1010 FOR Y=60 TO 124 STEP 16
1020 DRAW 1, 100, I TO 200, Y
1030 NEXT Y
1040 A$="FEDCBAGFE"
1050 FOR X=I TO 9: C=13
1060 IF INT(X/2)= X/2 THEN C=14
1070 CHAR 1, C, X+6, MID$ (A$, X, 1), 0
1075 CHAR 1, C+10, X +6, RIGHTS (STR$ (1M), 1)
1080 NEXT X
1090 FOR X=1 TO 8: FOR Y=11 TO 16: DRAW 1, X, Y: NEXT Y, X
1100 Y=1: X-8: DRAW 1, 8, 16 TO X, Y
1110 SSHAPE N$, 1, 1, 8, 16
1120 GSHAPE N$, 1, 1, 4
1130 RETURN
90
As you can see, music and sound can be used to enhance programs or be the focus of the program Itself, The examples in this chapter just give you a taste of the music capabilities of your Commodore 16. Don't be afraid to try new sounds and noises and create your own masterpiece.
By now, you've begun to get a handle on some of the things you can do with your Commodore 16. The aim of this manual has been to give you a taste of computing, to have you try new things and see what happens, to learn about your computer and to have fun In the process .
But there's still so much more . . programming, for example. This manual has touched on how to begin to use BASIC, but is not a tutorial or BASIC textbook by any means. The BASIC Encyclopedia
(immediately following this chapter) gives a complete listing of ALL the
BASIC commands on your Commodore 16, with explanations and examples. In many of the programs in the last couple of chapters. you may not have understood exactly what steps were doing what. To learn more about programming with the BASIC language, you should read books that were written to teach BASIC. A list of these books appears in the appendix. If you are really interested in programming, you might want to gel the Series 264 Programmer's Reference Guide, which focuses on the hows and whys of programming. revealing the secret and not-so-secret tricks of the programming trade. Now that you've finished reading this manual. you might think that you're on your own, but not entirely. You can read any of the many computer magazines, some of which are entirely devoted to Commodore computers, peripherals and software. You can also become part of a group of people near you who share your interest in Commodore computers: a Commodore User's Group. For more Information on these groups, contact the CBM Information Centre.
91
92 f
I
;
1
I r
I f
BASIC 3.5
ENCYCLOPEDIA
• Introduction
• Commands
• Statements
• Functions
• Variables and operators
• Abbreviation and reference chart
93
INTRODUCTION
You've seen in this manual an assortment of exercises using the BASIC language. to give you a feel for computer programming and some of the vocabulary involved. This encyclopedia gives a complete fist of the rules and terms (SYNTAX) of the BASIC 3.5 language, along with a concise description of each. Experiment with tnese commands, and remember that you can't damage your Commodore 16 by typing in programs, and that the best way to learn computing Is by doing
The encycropedia provides formats and brief explanations and examples of the BASIC 3.5 commands and statements. It is not intended to teach BASIC. If you are Interested in learning BASIC,
Appendix G lists tutorial books that will help.
Commands and statements are listed in separate sections. Within the sections, the commands and statements are listed in alphabetical order.
Commands are used mainly In direct mode. while statements are most often used In programs. In most cases, commands can be used as statements in a program :1 you prefix them with a line number. You can use many statements as commands by using them in direct mode (i.e
.. without fine numbers) II you are unsure where a term is located, they are all listed in Inc reference chart.
The BASIC Encyclopedia is organized along the lines of the following.
• COMMANDS: the commands used to work with programs, edit, store. and erase them.
• STATEMENTS: the BASIC program statements used in numbered lines of programs.
• FUNCTIONS: the string, numeric, and print functions.
• VARIABLES AND OPERATORS: the different types of variables. toga: variable names. and arithmetic and logical operators.
A fuller explanation of BASIC 3.5 commands is provided in the Series
264 Programmer's Reference Guide. available from your Commodore dealer or your local bookstore.
COMMAND AND STATEMENT FORMAT
The commands and statements presented in this section of the encyclopedia follow consistent format conventions to make them as clear as possible. In most cases, there are several examples to illustrate what the actual command looks like. The following example shows some of the format conventions that are used in the BASIC commancs and statements:
94
f r I
EXAMPLE LOAD"program name",DO. U8 keywords rgument additional arguments
(possibly optional)
The parts of the command or statement that you must type In exactly as they appear are highlighted in a darker type in the formal listing, while the name of the command is in capital letters. The words that you don't type in exactly, such as the name of a program, are printed In lighter italic type. When quote marks (- ") appear (usually around a program or file name), you should include them in the command or statement, like in the format example
• KEYWORDS appear in uppercase letters and boldface type. YOU
MUST ENTER THESE KEYWORDS EXACTLY AS THEY APPEAR
.
However, many keywords have abbreviations that you can also use
(see the reference chart).
Keywords are words that are part of the BASIC language that your computer knows. Keywords are the central part of a command or statement. They tell the computer what kind of action you want it to take. These words cannot be used as variable names.
• ARGUMENTS (also called parameters) appear in lowercase letters.
Arguments are the parts of a command or statement that you select; they complement keywords by providing specific information about the command or statement. For example, a keyword tells the computer to load a program, while an argument tells the computer which specific program to load and a second argument specifies which drive the disk containing the program is in Arguments include filenames, variables. line numbers, etc.
• SQUARE BRACKETS (I show OPTIONAL arguments You select any or none of the arguments listed. depending on your requirements.
• ANGLE BRACKETS < > indicate that you MUST choose one of the arguments listed.
• VERTICAL BAR I separates items in a list of arguments when your choices are limited to those arguments listed, and you can't use any other arguments. When the vertical bar appears in a list enclosed in
SQUARE BRACKETS. your choices are limited to the items in the list. but you still have the option not to use any arguments
95
• ELLIPSIS . . a sequence of three dots. means that an option or argument can be repeated more than once.
• QUOTATION MARKS " " enclose character strings, filenames, and other expressions. When arguments are enclosed in quotation marks In a formal, you must include the quotation marks in your command or statement. Quotation marks are required parts of a command or statement.
• PARENTHESES 0 When arguments are enclosed in parentheses In a format, you must include the parentheses in your command or statement. Parentheses are also required when they appear 'n a command or statement description.
• VARIABLE refers to any valid BASIC variable name, such as X. AS, or T%
• EXPRESSION means any valid BASIC expression. such as A4-9+2 or .5*(X+3)
BASIC COMMANDS
AUTO
AUTO
jline$1
Turns on the automatic line numbering feature which eases the job of entering programs by typing the line numbers for you. As you enter each program line and press RETURN the next line number is printed on the screen. with the cursor in position to begin typing that line. The
[line#) argument refers to the increment between line numbers. AUTO with NO ARGUMENT turns off auto line numbering, as does RUN This statement is executable only In direct mode.
EXAMPLES
AUTO 10
AUTO SO
AUTO automatically numbers line in increments of ten automatically numbers line in increments of fifty turns OFF automatic line numbering
96
BACKUP
BACKUP Ddrrve4' TO Ddrive$ (, ON Uunit$1
This command copies all the files on a diskette to another diskette on a dual drive system. You can copy onto a new diskette without first using the HEADER command to format the new diskette because the
BACKUP command copies all the information on the diskette, including the format. You should always BACKUP important diskettes in case the original is lost or damaged
Because the BACKUP command also HEADERS diskettes, It destroys any information on the diskette onto which you're copying Information.
So if you're backing up onto a previously used diskette, make sure it contains no programs you wish to keep. See also the COPY command
NOTE: Tnis command can only be used with dual disk drive.
EXAMPLES:
BACKUP DO TO
Dl
BACKUP DO TO Dl, ON U9
Copies all files from the disk In drive
0 to me disk in drive 1
Copies all files from drive C to drive
1 in disk drive unit 9
COLLECT
COLLECT IDdrive$1
LON
Uunht#I
Use this command to free up space allocated to improperly closed files and deletes references to these files from the directory
97
EXAMPLE
COLLECT DO
CONT
CONT (Continue)
This command is used to re-start the execution of a program that has been stopped by either using the STOP key. a STOP statement, or an
END statement within the program. The program will resume execution where it left off. CONT will not work if you have changed or added lines of the program (or even just moved the cursor to a program line and hit Rtruitm without changing anything), if the program stopped due to an error, or if you caused an error before trying to re-start the program. The error message in this case is CAN'T CONTINUE ERROR.
COPY
COPY [Ddrive#I "source file" TO [DdriveW.1"other file" [,ON Uunitfri
COPYs a file on the disk in one drive (the source file) to the disk in the other on a dual disk drive only, or creates a copy of a file on the same drive (with a different file name).
EXAMPLES-
COPY DO,"NOON" TO DI,"NIGHT"
COPY DO, "STUFF" TO Dl, "STUFF"
COPY DO TO Dl
Copies NOON from drive 0 to drive 1, renaming it NIGHT
Copies STUFF from drive 0 to drive 1
Copies all files from drive 0 to drive 1
98
COPY "CATS" TO "DOGS" Copies CATS as a program called DOGS on the same drive.
DELETE
DELETE [first Iine#J I- last line,/
Deletes lines of BASIC text. This command can be executed only in direct mode.
EXAMPLES:
DELETE 75
DELETE 10 50
DELETE - 50
DELETE 75-
Deletes One 75.
Deletes lines 10 through 50 inclusive.
Deletes all lines from the beginning of the program up to and including line 50.
Deletes all lines from 75 on to the end of the program.
DIRECTORY
DIRECTORY [DdriveM]
Displays a disk directory on the Commodore '6 screen Use CIRL to pause the display (any other key restarts the display after a pause).
Use tne 0- key (the Commodore key) to slow II down. The
DIRECTORY command cannot be used to print a hard copy. You must toad the disk directory (destroying the program currently in memory) to do that.
99
EXAMPLES
DIRECTORY List all files on the disk.
DIRECTORY DI, U9, "WORK" Lists the file on disk drive unit 9 (8 is the default), drive 1. named
WORK
DIRECTORY "AB•" Lists all files starting with the letters
"AB", like ABOVE. ABOARD. etc.
DIRECTORY DO, "FILE ?.BAK" The ? is a wild-card that matches any single character in that position: FILE 1BAK, FILE 2.BAK,
FILE 3.BAK all match the string.
NOTE: To print out the DIRECTORY of drive 0, unit 8, use the following.
LOAD"$0",8
OPEN4,4:CMD4:LIST
PRINT#4:CLOSE4
DLOAD
DLOAD "filename" r,Ddrive#1 hUunit#1
This command loads a program from disk into current memory. (Use
LOAD to load programs on tape.) You must supply a program name.
EXAMPLES:
DLOAD "DTRUCK"
DLOAD (A$)
Searches the disk for the program
"DTRUCK" and LOADs it.
LOADs a program from disk whose name is in the variable AS. You will get an error if AS is empty.
100
I
I I
I 1
I I
I I
I
1 I
I I
I I
I
I
I I
1 I
I
I I
I 1
1
I
I I
1 I
1 I
I I
The DLOAD command can be used within a BASIC program to find and
RUN another program on disk. This Is called chaining.
DSAVE
DSAVE "filename [,Ddrive#j LUunit01
This command stores a program on disk. (Use SAVE to store programs on tape.) You must supply a program name.
EXAMPLES
DSAVE "DDAY"
DSAVE (As)
DSAVE "PROG 3",DO,U9
SAVEs the program "DDAY" to disk.
SAVEs to disk program whose name is In the variable A$.
SAVES the program "PROG r to the disk drive with a unit number of 9.
HEADER
HEADER "diskname" ,Ddrlve# Ladd/ILION Uunitifj
Before you can use a new diskette for the first time you must formal it with the HEADER command. If you want to erase an entire diskette for re-use you can use the HEADER command. This command divides the disk into sections called blocks, and it creates a table of contents, caned a directory or catalog, on the disk. The diskname can be any name up to 16 characters long. The i.d. number is any 2 characters.
Give each disk a unique i.d. number. Be careful when you HEADER a disk because the HEADER command erases all stored data. Giving no i.d. number al;ows you to perform a quick header. The old i.d. number
Is used You can only use the quick header method If the disk was previously formatted, since the quick header only clears out the directory rather than formatting the disk.
101
EXAMPLES:
HEADER "MYDISK", 123, DO
HEADER "THEBALL", 145, Dl, U8
HELP
HELP
The HELP command is used after you get an error in your program.
When you type HELP, the line where the error occured is listed, with the portion containing the error displayed in flashing characters.
KEY
KEY [key #, string]
There are eight (8) function keys available to the user on your
Commodore 16 computer: four unshifted and four shifted. Your
Commodore 16 allows you to define what each key does when pressed. KEY without any parameter specified gives a fisting displaying all the current KEY assignments. The data you assign to a key is typed out when that function key is pressed. The maximum length for all the definitions together is 128 characters. Entire commands or a series of commands) can be assigned to a key. For example:
KEY 7, "GRAPHICO" + CHR$(13) + "LIST" + CHR$(13) causes the computer to select text mode and list your program whenever the 'FT key is depressed (in direct mode). The CHR$(13) is the ASCII character for intlitig . Use CHR$(34) to incorporate a double quote into a KEY string.
102 i
The keys may be redefined In a program. For example:
10 KEY 2,"TESTING" + CHR$(34):KEY3, "NO"
10 FOR I tc 1 TO 8: KEY I,
CHRS(I+132):NEXT defines the function keys as they are defined on the
Commodore 64 and VIC 20
I
I I
To restore all function keys to their default values, reset your
Commodore 16 by turning it off and on. or press the RESET button.
I I
I I
I
I iI
I
I
I
I
I I
I i I
I I
I I
I I
I I
I
.1 f
LIST
LIST f irst linelI • [last line])
The LIST command lets you look at lines of a BASIC program that have been typed or LOADed into the Commodore 16's memory. When LIST is used alone (without any numbers following it), you get a complete
LISTing of the program on your screen. which may be slowed down by holding down the G. key, paused by
CT!!.
-S (unpaused by pressing any other key), or STOPped by pressing the '201#11TIBE key. If you follow the word LIST with a line number, your Commodore 16 only shows that The number. 11 you type UST with two numbers separated by a dash, the Commodore 16 shows all lines from the first to the second line number. If you type LIST followed by a number and just a dash, it shows all the lines from that number to the end of the program.
And if you type LIST, a dash, and then a number, you get all the lines from the beginning of the program to that line number. Using these variations. you can examine any portion of a program, or easily bring lines to the screen for modification.
EXAMPLES:
LIST
LIST 100-
Shows entire program.
Shows from line 100 until the end of the program.
103
LIST 10
LIST-100
LIST 10-200
Shows only line 10.
Shows lines from the beginning until line 100
Shows tines from 10 to 200, inclusive.
LOAD
LOAD ("filename" 1.device#3[.relocate flag])
This IS the command to use when you want to use a program stored on cassette tape or on disk. If you type lust LOAD and hit the at key, the Commodore 16 screen goes blank. Press play, and the
Commodore 16 starts looking for a program on the tape When it linds one. the Commodore 16 prints FOUND "filename" You can hit the
0 key to LOAD, if you don't press the key, the computer resumes searching on the tape after a brief interval. Once the program is
LOADed, you can RUN, LIST, or change it.
You can also type the word LOAD followed by a program name, which is most often a name in guotes("program name"). The name may be followed by a comma (outside of the quotes) and a number (cc numeric variable), which acts as a device number to determine where the vogram is stored (disk or tape). If there Is no number given, your computer assumes device number 1, which Is the cassette tape recorder.
The other device commonly used with the LOAD command is usually the disk drive, which is device number
EXAMPLES:
LOAD
LOAD "BASES"
LOAD AS
Reads in the next program on tape
Searches tape for a program called
BASES, and LOADS it d it is found
.
Looks for a program whose name is in the variable called AS.
104
LOAD "BRIDGES",8 Looks for the program called BRIDGES on the disk drive, and LOADS it if found.
The LOAD command can be used within a BASIC program to find and
RUN the next program on a tape. This is called chaining.
The RELOCATE FLAG determines where in memory a program is loaded. A relocate nag of 0 tells the Commodore 16 to load the program at the start of the BASIC program area. and a flag of 1 tells it to LOAD from the point where it was SAVEd. The default value of the relocate flag is 0. This is generally used only when loading machine language programs.
NEW
NEW
This command erases the entire program in memory and clears out any variables that may have been used. Unless the program was stored somewhere, it s lost until you type n in again. Be careful when you use this command
The NEW command can also be used as a statement in a BASIC program. When your Commodore 16 gets to this line, the program is erased and everything stops. This is not especially uselul under normal circumstances.
RENAME
RENAME [Ddrive #4 "old name" TO new name [,Uunit #]
Used to rename a file on a diskette.
EXAMPLE
RENAME DO,"ASSET" TO
"LIABILITY"
Changes the name of the file from
ASSET to LIABILITY
105
RENUMBER
RENUMBER [new starling line N [increment [sold starling line Nil )
The new starting line is the number of the first line in the program after renumbering. It defaults to 10.
•
The increment is the spacing between line numbers. i.e. 10. 20. 30 etc.
It also defaults to 10.
The old starling line number is the line number in the program where renumbering is to begin This allows you to renumber a portion of your program. It defaults to the first line of your program
.
This command can only be executed from direct mode
EXAMPLES
RENUMBER 20, 20, 1
RENUMBER, 65
Starting at line 1, renumbers the program
Line 1 becomes line 20. and other lines are numbered in Increments of 20.
Starting at line 65. renumbers in increments of 10. Line 65 becomes line
10 (unless there are already lines numbered 10-64, in which case the command Is not carried out).
RUN
RUN pine NJ
Once a program has been typed into memory or LOADed, the RUN command makes it start working. RUN clears all variables in the program before starling program execution If there is no number following the command RUN, the computer starts with the lowest numbered program line. If there is a number following the RUN command execution starts at that line. RUN may be used within a program.
106
EXAMPLES:
RUN
RUN 100
Starts program working from lowest line number.
Starts program at line 100.
1
I
1
1
1
I
I
SAVE
SAVE ["filename" Icevice# I.EOT flag)/
This command stores a program currently in memory onto a cassette tape or disk. If you lust type the word SAVE and press MOAN . your
Commodore 16 attempts to store the program on th6cassette tape. It has no way of checking it there is already a program on the tape in that location, so be careful with your tapes. If you type the SAVE command followed by a name in quotes or a string variable name. the
Commodore 16 gives the program that name, so it may be more easily located and retrieved in the future. If you want to specify a device number for the SAVE. follow the name by a comma (after the quotes) and a number or numeric variable. Device number 1 is the tape drive. and number 8 G the disk. Atter the number on a tape command, there can be a comma and a second number, which is betWeen 0 and 3. second number is 2. the Commodore 16 puts an END-OF-TAPE marker
(EOT flag) after your program. If you are trying to LOAD a program and the Commodore 16 finds one of these markers rather than the program you are trying to LOAD, you get a FILE NOT FOUND ERROR.
EXAMPLES'
SAVE
SAVE "MONEY"
SAVE AS
SAVE "YOURSELF",8
Stores program to tape without a name.
Stores on tape with the name MONEY
Stores on tape with name en variable AS
Stores on disk with name YOURSELF
107
SAVE "GAME", 1, 2 Stores on tape with name GAME and places an END-OF-TAPE marker atter the program.
SCRATCH
SCRATCH "file name" ID drive ill ID unit #1
Deletes a file from the disk directory. As a precaution, you are asked
"Are you sure?' before your Commodore 16 completes the operation.
Type a Y to perform the SCRATCH or type N to cancel the operation.
Use this command to erase unwanted files, to create more space on the disk.
EXAMPLE:
SCRATCH "MY BACK", Dl Erases the file MY BACK from the disk in drive 1
VERIFY
VERIFY "filename" I.deviceiii (,relocate flag]
This command causes your Commodore 16 to check the program on tape or disk against the one In memory. This is proof that the program you lust SAVEd is really saved, to make sure that nothing went wrong
This command is also very useful to position a tape so that your computer resumes writing following the end of the $ast program on the tape. Ail you do is tell the Commodore 16 to VERIFY the name of the last program on the tape. It will do so, and tell you that the programs don't match (which you already knew) Now the tape is where you want it, and you can store the next program without fear of erasing an old one.
108
VERIFY without anything alter the command causes the Commodore
16 to check the next program on tape, regardless of as name. against the program now in memory. VERIFY followed by a program name (in quotes) or a string variable searches the tape for that program and then checks. VERIFY followed by a name and a comma and a number checks the program on the device with that number (1 for tape, 8 for disk) The relocate flag is the same as in the LOAD command.
EXAMPLE
VERIFY
VERIFY "REALITY"
VERIFY "ME",8,1
Checks the next program on the tape.
Searches for REALITY on tape, checks against memory.
Searches for ME on disk. then checks.
BASIC STATEMENTS
BOX
BOX (colour source #1, al , bl . [a2, b2] [,angle] ',paint] colour source at , bl .. a2, b2 angle paint ..
Colour source (0 3): default is 1 (foreground colour)
Corner coordinate (scaled)
Corner opposite al . bl (scaled): default is the PC
Rotation in ciockwise degrees: default is 0 degrees
..Paint shape with colour (0:off. 1:on): default is 0
This command allows you to draw a rectangle of any size anywhere on the screen To get the default value, include a comma without entering a value. Rotation is based on the centre of the rectangle. The Pixel
Cursor (PC) is lett at a2. b2 after the BOX statement is executed.
EXAMPLES:
BOX 1, 10, 10, 60, 60 Draws the outline of a rectangle
109
BOX , 10, 10, 60, 60, 9S, 1
BOX , 30, 90, 45, 1
CHAR
CHAR (colour source Allx.y. "string" [,reverse flag]
Colour source x y
"string" reverse
Colour source (0 - 3)
Character column (0 - 39)
Character row (0 - 24)
Text to be printed
Reverse field flag (0 = off, 1 w on)
Text (alphanumeric strings) can be displayed on any screen at a given location by the CHAR command Character data is read from the
Commodore 16 character ROM area. You supply the x and y coordinates of the starling position and the text string you want to display. Colour source and reverse imaging are optional.
The string is continued on the next line if it attempts to print past the right edge of the screen. When used In TEXT mode the string printed by the CHAR command works just like a PRINT string, including reverse field, cursors, flash on/off, etc. These control functions inside the string do not work when the CHAR command Is used to display text in GRAPHIC mode.
I I
CIRCLE
Draws a filled, rotated box (a diamond)
Draws a filled, rotated polygon
CIRCLE (es] Ja.b]. xr I, [yr] [. [se] teal [angle) [.inc] 131) cs a.b xr yr .
Colour source (0 - 3)
Centre coordinate (scaled)
(defaults to the Pixel Cursor IPCI)
X radius (scaled)
Y radius (default is xr)
110 t
I
I
( sa ea .. . angle
Inc
Starting arc angle (default 0)
Ending arc angle (default 360)
Rotation in clockwise degrees
(default is 0 degrees)
Degrees between segments
(default is 2 degrees)
I
I I
I
I I
I I
I
I
I
I I
With the CIRCLE command you can draw a circle, ellipse, arc, triangle or an octagon The final coordinate is on the circumference of the circle at the ending arc angle. Any rotation is about the centre. Arcs are drawn from the starting angle clockwise to the ending angle. The segment increment controls the coarseness of the shape, with lower values for inc creating rounder shapes.
EXAMPLES
CIRCLE, 160,100,65,10
CIRCLE, 160,100,65,50
CIRCLE , 60,40,20,18„„45
CIRCLE , 260,40,20 90
CIRCLE , 60,140,20,18„„120
Draws an ellipse.
Draws an oval.
Draws an octagon.
Draws a diamond
Draws a triangle.
I
I
111
CLOSE
CLOSE file 0
This command completes and closes any files used by OPEN statements. The number following the word CLOSE is the file number to be closed .
EXAMPLE.
CLOSE 2 Logical file 2 is closed.
CLR
CLR
This command erases any variables in memory, but leaves the program itself intact. This command is automatically executed when a RUN or
NEW command is given. or when any editing is performed
CMD
CMD file # (,write list)
CMD sends the output which normally would go to the screen (i.e.
PRINT statement, LISTS, but not POKEs into the screen) to another device instead. This could be a printer, or a data file on tape or disk.
This device or file must be OPENS first. The CMD command must be
'allowed by a number or numeric variable referring to the file.
EXAMPLES:
OPEN 1,4
CMD I
LIST
OPENS device #4, which is the winter.
All normal output now goes to the printer
The LISTtng goes to the printer. not the screen - even the word READY
112
1
I
1
1
1
1
1
PRINT41
CLOSE 1
1
Set output back to the screen.
Close the file .
COLOR
COLOR source W. colour 0 (,luminance 01
Assigns a colour to one of the 5 colour sources:
Number
0
1
2
3
4
Source background foreground multicolour 1 multicolour 2 border
Colours you can use are in the range 1 - 16 (1 is black, 2 is white, 9 Is orange, etc. from your keyboard colour keys). As an option, you can
Include the luminance level 0 - 7. with 0 being lowest and 7 being highest. Luminance defaults to 7 Luminance lets you select from eight levels of brightness for any colour except black.
DATA
DATA list of constants separated by commas
This statement is followed by a list of items to be used by READ statements. The items may be numbers or words, and are separated by commas. Words need not be inside of quote marks. unless they contain any of the following characters: SPACE, colon, or comma. If
Iwo commas have nothing between them, the value will be READ as a zero for a number, or an empty string. The DATA statement must be part of a program, otherwise it will not be recognized Also see the
RESTORE statment, which allows your Commodore 16 to reread data
113
EXAMPLE
DATA 100, 200, FRED, "WILMA"„ 3, 14. ABC123
DEF FN
DEF FN name (var.anle) = expression
This command allows you to define a complex calculation as a function.
In the case of a long formula that is used several times within a program, this can save a lot of space.
The name you give the numeric function begins with the letters FN, followed by any legal numeric variable name. First you must define the function by using the statement DEF followed by the name you've given the function. Following the name is a set of parentheses () with a numeric variable (in this case, X) enclosed. Then you have an equal sign. followed by the formula you want to define. You can "call" the formula, substituting any number for X, using the formal shown in line
20 of the example below:
EXAMPLE.
10 DEF FNA(X)=12*(34.75-X/.3 +X
20 PRINT FNA(7)
The number 74s inserted each pace X Is located in the formula given in the DEF statement.
NOTE: DEF FN can only be used with standard numeric functions. not integer or string functions.
114
DIM
DIM variable (subscripts) (.variable(subscripts))
Before you can use an array of variables, the program must first execute a DIM statement to establish the DIMensions of that array
(unless there are 11 or fewer elements in the array). The statement DIM is followed by the name of the array, which may be any legal variable name. Then, enclosed in parentheses, you put the number (or numeric variable) of elements in each dimension. An array with more than one dimension is called a matrix You may use any number of dimensions, but keep in mind that the whole list of variables you are creating lakes up space in memory, and it is easy to run out of memory it you gel carried away. To figure the number of variables created with each DIM, multiply the total number of elements in each dimension of the array
(Each array starts with element 0.)
NOTE: Integer (single-digit) arrays take up 2r5ths of the space of floating point arrays.
EXAMPLE
10 DIM A5(40).B7(15).CC%(4, 4,4)
41 Elements 16 Elements 125 lements
You can dimension more than one array in a DIM statement by separating the arrays by commas If the program executes a DIM statement for any array more than once, you'll get a re'DIMed array error message. It is good programming practice to place DIM statements near the beginning of the program
DO (LOOP) WHILE (UNTIL EXIT)
DOHINTIL boolean argument I
WHILE bootean arguernentj statements (EXIT)
1 1 5
LOOP[UNTIL boolean argument ' WHILE boolean argument]
(An example of a boolean argument is A=I or H> =57 )
Performs the statements between the DO statement and the LOOP statement. II no UNTIL or WHILE modifies either the DO or the LOOP statement, execution of the intervening statements continues indefinitely. If an EXIT statement is encountered In the body of a DO loop, execution is transferred to the first statement following the LOOP statement DO loops may be nested. following the rules defined for
FOR-NEXT loops.
If the UNTIL parameter is used, the program continues looping until the boolean argument is satisfied (becomes TRUE). The WHILE parameter
Is basically the opposite of the UNTIL parameter. the program continues looping as long as the boolean argument is TRUE.
EXAMPLE
DO UNTIL X =0 OR X .=1
LOOP
DO WHILE AS="":GET AS:LOOP
DRAW
DRAW [colour source #11. al . bl I a2. b2.11 . .
With this command you can draw individual dots, lines, and shapes
You supply colour source (0-3), starting (al , b1) and ending points (a2 b2).
EXAMPLES a dot'
Ilnes:
DRAW I. 100, 50 — no endpoint specified. defaults to al ,b1 value for a2.b2 to create a dot
DRAW , 10,10, TO 100,60
DRAW TO 25,30 a shape: DRAW , 10,10 TO 10,60 TO 100,60 TO 10,10
116
END
END
When the program executes an END statement, the program stops
RUNning immediately. You may use the CONT command to re-start the program at the statement following the END statement
FOR . . . TO . STEP
FOR variable = start value TO end value [STEP Increment!
This statement works with the NEXT statement to set up a section of the program that repeats for a set number of times. You may lust want your computer to count up to a large number so the program pauses for a few seconds, in case you need something counted, or something must be done a certain number of times (such as printing).
The loop variable is the variable that Is added to or subtracted from during the FOR/NEXT loop. The start value and the end value are the beginning and ending counts for the loop variable.
The logic of the FOR statement is as follows. First, the loop variable Is set to tne start value. When the program reaches a line with the command NEXT, it adds the STEP increment (default = 1) to the value of the loop variable and checks to see if it is higher than the end of loop value. If it is not higher, the next line executed is the statement immediately following the FOR statement. If the loop variable is larger than the end of loop number, then the next statement executed Is the one following the NEXT statement A STEP value can be positive or negative. See also the NEXT statement.
EXAMPLE
10 FOR L = 1 TO 20
20 PRINT L
30 NEXT L
40 PRINT "BLACKJACK , L = "L
117
This program prints the numbers from one to twenty on the screen, followed by the message BLACKJACK! L = 21.
The end of loop value may be followed by the word STEP and another number or variable. In this case, the value following the STEP is added each time instead of one. This allows you to count backwards. by fractions, or any way necessary.
You can set up loops inside one another. This Is known as nesting loops. You must be careful to nest loops so that the last loop to start is the first one to end.
EXAMPLE OF NESTED LOOPS
10 FOR L = 1 TO
100
r 20 FOR A = 5 TO 11 STEP 2
L 30 NEXT A
40 NEXT L
This FOR NEXT loop is "nested' Inside the larger one.
GET
GET variable list
The GET statement is a way to gel data from tne keyboard one character at a time. When me GET is executed, the character that was typed is received If no character was typed. then a null (empty) character is returned, and the program continues without waiting for a key. There is no need to press the 110H1RIM- key, and in fact the
IIETIBUI key can be received with a GET
118
The word GET is followed by a variable name. usually a string variable.
If a numeric were used and any key other than a number was hit, tne program would stop with an error message. The GET statement may also be put into a loop, checking for an empty result. which waits for a key to be struck to continue. The GETKEY statement could also be used In this case. This command can only be executed within a program.
EXAMPLE.
10 GET A$:IF AS < > "A" THEN 10 This line waits for the
'A' key to be pressed to continue
.
GETKEY
GETKEY variable list
The GETKEY statement is very similar to the GET statement. Unlike the GET statement, GETKEY waits for the user to type a character on the keyboard This lets it be used easily to wail for a single character to be typed.
This command can only be executed within a program.
EXAMPLE:
10 GETKEY AS This line waits for a key to be struck. Typing any key will continue the program .
GET
GET/ file numoetvariable :1st
119
Used with a previously OPENed device or tile to input one character at a time. Otherwise. it works like the GET statement
This command can only be executed within a program.
EXAMPLE
GET#1,A$
GOSUB
GOSUB tine #
This statement is like the GOTO statement, except that your
Commodore 16 remembers where it came from. When a line with a
RETURN statement is encountered, the program jumps back to the statement immediately following the GOSUB The target of a GOSUB statement is called a subroutine. A subroutine is useful it there is a routine in your program that can be used by several different portions of the program. Instead of duplicating the section of program over and over, you can set it up as a subroutine, and GOSUB to it from the different parts of the program See also the RETURN statement.
EXAMPLE
20 GOSUB 800 means go to the subroutine beginning at line 800 and execute
1.
800 PRINT "HI THERE":RETURN
GOTO or GO TO
GOTO line #
After a GOTO statement is executed. the next tine to be executed will be the one with the line number following the word GOTO. When used
120
In direct mode. GOTO line # allows you to stars execution of the program at the given line number witnout clearing the variables.
EXAMPLE
10 PRINT "REPETITION IS THE MOTHER OF LEARNING"
20 GOTO 10
The GOTO in line 20 causes line 10 to be run continuously, until the
111/N/STOP. key is pressed
GRAPHIC
GRAPHIC mode (clear option]
This statement puts your Commodore 16 in one of its 5 graphic modes mode description
0 normal text
1
4 high-resolution graphics
2 high-resolution graphics. split screen
3 multicolour graphics multicolour graphics. split screen
When executed, GRAPHIC 1 - 4 allocates a 10K bit-mapped area. and the BASIC text area is moved down below the hi-res area. This area remains allocated even if the user returns to TEXT mode (GRAPHIC 0).
If 1 is given in the GRAPHIC statement as the second argument, the screen is also cleared.
EXAMPLES:
GRAPHIC 1,1
GRAPHIC 4,0
Selects hi-res graphic mode and clears the screen
Selects multicolour graphics with an area for text, without clearing the screen
121
GRAPHIC CLR
GRAPHIC CLR
This is actually a lorm of the GRAPHIC statement instead of specifying a mode to use graphics. this statement clears the 10k of memory allocated to the graphic area. and that memory space becomes available for BASIC once again .
IF . THEN . . :ELSE
IF expression THEN then-clause (:ELSE else-clausel
IF . THEN lets the computer analyze a BASIC expression preceded by IF and take one of two possible courses of action. H the expression is true, the statement following THEN is executed. This expression may be any BASIC statement. If the expression is false, the program goes directly to the next brie. unless an ELSE clause is present. The expression being evaluated may be a variable or formula. in which case it is considered true if nonzero, and false if zero. In most cases. there is an expression involving relational operators (-, C. >. < =, > =. < >,
AND. OR, NOT).
The ELSE clause, if present, must be in the same line as the IF-THEN part. When an ELSE clause is present it is executed when the THEN clause isn't executed. In other words, the ELSE clause executes when the IF expression is FALSE
Then
I
I
I I,
I
I
I
I
I
I
I
I
T
I I
EXAMPLE
50 IF X > 0 THEN PRINT"OK":
ELSE END
Checks the value of X. II X is greater than 0, the THEN clause is executed, and the ELSE clause isn't If X is not greater than 0. the ELSE clause is executed and the THEN clause isn't.
!
I I
INPUT
INPUTI"prompt string") variable list
The INPUT statement allows the computer to ask for data from the person running the program and place it into a variable or variables.
The program stops, prints a question mark 0) on the screen, and wails for the person to type the answer and press the RETURN key.
The word INPUT is followed by a variable name or list of variable names separated by commas. There may be a message inside quotes before the list of variables to be input. If this message (called a prompt) is present, Mere must be a semicolon (,) after the closing quote of the prompt. When more than one variable is to be INPUT, they should be separated by commas when typed in. If not, the computer asks for the remaining values by printing two question marks ('n). II you press the RETURN key without INPUTtIng values, the INPUT variables retain the values previously held for those variables. This statement can only be executed within a program
EXAMPLE.
10 INPUT "WHAT'S YOUR NAME";AS
20 INPUT AND YOUR FAVORITE COLOR";13$
30 INPUT "WHAT'S THE AIR SPEED OF A SWALLOW";A
122 C ot
www.commodoresca
May Not Reprint Without Permission
123
INPUT
INPUT# file number, variable list
This works like INPUT, but takes the data from a previously OPENed file or device. No prompt string is allowed. This command can only be used In program mode.
EXAMPLE
INPUT#2, AS, C, DS
LET
(LET) variable a expression
The word LET is hardly ever used in programs, since it is not necessary, but the statement itself is the heart of all BASIC programs.
Whenever a variable is defined or given a value. LET is always implied.
The variable name which is to get the result of a calculation is on the left side of the equal sign, and the number or formula is on the right side.
EXAMPLE
10 LET A = 5
20 B = 6
30 C = A • B + 3
40 DS = "HELLO"
LET is implied (but not necessary) in lines 20, 30 and 40.
1/4
I
I
1 I
I
I f
I
I
I
I
I
I
LOCATE
LOCATE x-coordinate, y-coordinate
The LOCATE command lets you put the pixel cursor (PC) anywhere on the screen. The PC is the current location of the starting point of the next drawing. Unlike the regular cursor. you can't see the PC. but you can move it with the LOCATE command. For example.
LOCATE 160, 100 positions the PC in the centre of the high resolution screen. You won't see anything until you actually draw something. You can find out where the PC is at any time by using the RDOT(0) function to get the Xcoordinate and RDOT(1) to get the Y-coordinate. The colour source of the dot at the PC can be found by PRINTing RDOT(2). (In all drawing commands where a colour option is available, you may select a value from 0 to 3, corresponding to the background, foreground, multicolour
1, or multicolour 2 as the colour source.)
I
MONITOR
MONITOR
This command takes you out of BASIC into the built-in machine language monitor program The monitor G used to develop. debug. and execute machine language programs more easily than from BASIC.
See the section on monitor commands for more Information. (When in the monitor, typing an 'X' and pressing
run
gets you back to
BASIC.)
NEXT
NEXT (variable, ,variable)
124 125
The NEXT statement is used with the FOR statement. When the computer encounters a NEXT statement, It goes back to the corresponding FOR statement and checks the loop variable. (See FOR statement for more detail.) If the loop is finished. execution proceeds with the statement after the NEXT statement. The word NEXT may be followed by a variable name. a list of variable names separated by commas, or no variable names. It there are no names listed. the last loop started is the one being completed. If the variables are given, they are completed in order from left to right.
EXAMPLE:
10 FOR L = 1 TO 10:NEXT
20 FOR L = 1 TO 10:NEXT L
30 FOR L= 1 TO 10:FOR M = 1 TO 10: NEXT M, L
ON
ON expression <- GOTO/GOSUB> line Al I, fine #2, . ]
This command can make the GOTO and GOSUB statements into special versions of the IF statement The word ON is followed by a formula, then either GOTO or GOSUB. and a list of line numbers separated by commas. If the result of the calculation of the formula
(expression) is 1, the first line in the list is executed. If the result is 2. the second line number is executed, and so on. If the result is 0, or larger than the number of ;ine numbers in the fist. the next line executed is the statement following the ON statements. If the number is negative. an ILLEGAL QUANTITY ERROR results.
126
EXAMPLE -
10 INPUT X:IF X < 0 THEN 10
20 ON X GOTO 50, 30, 30, 70
25 PRINT "FELL THROUGH":GOTO 10
30 PRINT "TOO HIGH":GOTO 10
50 PRINT"TOO LOW":GOTO 10
70 END
When X = 1. ON sends control to the first line number in the list (50). When X = 2,
ON sends control to the second line (30), etc.
{
V
I I f 1 f I
(
I
I
I f f
I
I
, f
I f
'
' r r
I f
OPEN
OPEN file # (.device #1.secondary address rfilename, type, mode'.111
The OPEN statement allows your Commodore 16 lo access devices such as the Datassette recorder and disk for data, a printer, or even the monitor screen. The word OPEN is followed by a logical file number. which is the number to which all other BASIC statements will refer. This number is from Ito 255. There is normally a second number after the first called the device number. Device number 0 is the Commodore 16 keyboard. 3 Is the screen, 1 is the Datassette recorder (default), 4 Is the printer. 8 is usually the disk. A zero (0) may be included in front of the device number digit (e.g . 08 for 8. which are interchangeable as far as your Commodore 16 is concerned). It Is often a good idea to use the same file number as the device number because it makes it easy to remember which is which. Following the second number may be a third number called the secondary address. In the case of tne cassette, this can be 0 for read. 1 lw write, and 2 for write with end-of-tape marker at the end. In the case of the disk, the number refers to the channel number. In the printer, the secondary addresses are used to set the mode of the printer. See the Commodore 16 Programmer's
Reference Manual or the manual for each specific device for more information on secondary addresses. There may also be a string following the third number, which could be a command to the disk drive or the name of the file on tape or disk. The type and mode refer
127
to disk files only. (File types are prg.seq, rel, and usr: modes are read and write.)
EXAMPLES:
10 OPEN 3,3
10 OPEN 1,0
20 OPEN 1,1,0,"UP"
OPEN 4,4
OPEN 15,8,15
OPENs the SCREEN as a device.
OPENs the keyboard as a device.
OPENS the cassette for reading. file to be searched for is named UP.
OPENS a channel to use the printer.
OPENS the command channel on the disk.
5 OPEN 8,8,12,"TESTFILE,SEO,WRITE" creates a sequential disk file for writing.
See also CLOSE, CMD, GET#, INPUT*. and PRINT* statements, system variable ST, DS and DS$.
PAINT
PAINT /colour source! ila,b1I,mode]
Colour source a.13
(0-3); (default is 1, foreground colour) starting coordinate, scaled (default is at the PC)
128 mode 0 = paint an area defined by the colour source selected
1 ei paint an area defined by any non-background source
The PAINT command lets you fill an area with colour. It fills in the area around the specified point until a boundary of the same colour (or any non-background colour, depending on which mode you have chosen) is encountered. The final position of the PC will be at the starting point la, b)
NOTE: if the starting point is already the colour of colour source you name (or any non-background when mode 1 Is used), there is no change
EXAMPLE:
10 CIRCLE , 160,100,65,50
20 PAINT , 160,100 draws outline of circle fills in the circle with colour
POKE
POKE address, value
The POKE command allows you to change any value in the
Commodore 16 RAM memory. and lets you modify many of the
Commodore 16 Input/Output registers. POKE is always followed by two numbers, (or equations). The first number is a location inside your computers memory. This could have any value from 0 to 65535. The second number is a value from 0 to 255. which is placed in the location. replacing any value that was there previously. This command can be used to control anytning on the screen, from placing a character at that location to changing the colour there.
EXAMPLE'
10 POKE 1 6 00 0,8 Sots Location 16000 lo 8
129
20 POKE 16 . 1000,27 Sets iodation 16000 to 27
Note. PEEK. a function related to POKE is listed under FUNCTIONS.
PRINT printlist
The PRINT statement is the major output statement in BASIC. While the PRINT statement is the first BASIC statement most people learn to use, there are many subtleties to be mastered nere as well. The word
PRINT can be followed by any combinations of these items, which is considered the printlist:
Characters inside of quotes
Variable names
Functions
Punctuation marks
("text lines")
(A, B. AS, X$)
(SIN(23). ABS(33))
(: .)
Tne characters inside of quotes are often called literals because they are printed exactly as they appear. Variable names have the value they contain (ether a number or a string) printed Functions also nave their number values printed. Punctuation marks are used to help format the data neatly on the screen. The comma divides the saeen into 4 columns for data. while the semicolon doesn't add any spaces. Either mark can be used as the last symbol In the statement. This results in the next PRINT statement acting as if it is continuing the last PRINT statement.
EXAMPLE:
RESULT
10 PRINT "HELLO"
20 A$= THERE":PR1NT "HELLO,"AS
30 A=4:B=2:PRINT A+B
501=41:PRINT ];:PRINT 1-1
60 C=A+B:D=A-B:PRINT A;B;C,D
See also: POS( ). SPC( ). and TAB( ) FUNCTIONS
HELLO
HELLO.THERE
6
41 40
4 2 6 2
130
I
(
PRINT# file #. Print list
There are a few differences between this statement and the PRINT.
First of all. the word PRINT# is followed by a number, which refers to the device or data file previously OPENed. The number is followed by a comma, and a list of things to be PRINTed. The semicolon acts In the same manner for spacing as it does in the PRINT statement The comma will send 10 spaces to most printers and can be used as a separator for disk files (see the Programmer's Reference Guide and the
Disk Drive Manual). Some devices may not work with TAB and SPC.
EXAMPLE
100 PRINT#1,"HELLOITIERE!",A$,BS,
I
I
I I
I
I
I I
PRINT USING
PRINT (#filenumber.) USING formal list; print Ilst
These statements let you define the format of string and numeric items you want to print to the screen, printer, or another device. Put the format you want in quotes. This is the format list. Then add a semicolon and a list of what you want printed in the format for the print list The list can be variabes or the actual values you want printed
.
For example'
$ X=32: Y =100.23: AS="CAT"
10 PRINT USING "S#A1 ./0";13.25,X,Y
20 PRINT USING "###>#";"CBM",AS
Wnen you RUN this, line 10 prints out
$13 25 532.00 S prints instead of Y value because Y has 5 digits, which does not conform to format list (as explained below)
I I
131
Line 20 prints this:
CBM CAT leaves three spaces before printing "CBM" as defined in formal list
CHARACTER
Hash Sign (#)
Plus (+)
Minus (-)
Decimal Point (.)
Comma C)
Dollar Sign ($)
Four Carets (*tin
Equal Sign (=)
Greater Than Sign (>)
NUMERIC STRING
X
The hash sign (#) reserves room for a single cha:acter in the output field. If the data item contains more characters than you have 41 in your format field, the following occurs: f i f
For a numeric item, the entire field is filled with asterisks (*). No numbers are printed.
For example:
10 PRINT USING "####"tX
For these values for X. this formal displays:
A = 12.34
A = 567.89
A = 123456
12
568
• it • •
For a STRING item, the string data Is truncated at the bounds of the field. Only as many characters are printed as there are hash signs (#) in the format item. Truncation occurs on the right.
The plus (+) and minus (-) signs can be used in either the first or last position of a format field but not both. The plus sign is printed if the number is positive. The minus sign is printed if the number is negative.
132
If you use a minus sign and the number is positive a blank is printed in the character position indicated by the minus sign.
If you don't use either a plus or minus sign in your formal field for a numeric data item, a minus sign is printed before the first digit or dollar symbol if the number is negative and no sign is printed If the number is positive. This means that you can print one character more if the number is positive. II there are too many digits to fit into the field specified by the # and + 1- signs, then an overflow occurs and the field is filled with asterisks VT
A decimal point (.) symbol designates the position of the decimal point in the number. You can only have one decimal point in any format field. If you don't specify a decimal point in your format field, the value is rounded to the nearest integer and prinled without any decimal places.
When you specify a decimal point, the number of digits preceding the decimal point (including the minus sign, if the value is negative) must not exceed the number of # before the decimal point. If there are too many digits an overflow occurs and the field is filled with asterisks (*).
A comma (.) lets you place commas in numeric fields. The position of the comma in the format list indicates where the comma appears in a printed number. Only commas within a number are printed. Unused commas to the left of the first digit appear as the filler character. At least one # must precede the first comma in a field.
If you specify commas in a field and the number is negative, then a minus sign is printed as the first character even if the character position is specified as a comma.
EXAMPLES
FIELD
N0 . N+
## # -
NW
EXPRESSION
1
0 I
-100.5
Mak -1000
RESULT
0 01-
1.0
-101
* •
COMMENT
Leading zero added.
Trailing zero added.
Rounded to no decimal places.
Overflow because four digits and minus sign cannot fit in field.
133
10
1
10
SI
Decimal point added.
Leading $ sign
A dollar sign (5) symbol shows that a dollar sign will be printed in the number. If you want the dollar sign to float (always be placed before the number), you must specify at least one # before the dollar sign. If you specify a dollar sign without a leading #. the dollar sign is printed in the position shown In the format field.
If you specify commas and/or a plus or minus sign in a format field with a dollar sign, your program prints a comma or sign before the dollar sign.
The four up arrows or carets (i lit) symbol is used to specify that the number is to be printed in E + format. You must use # ;n addition to the tilt to specify the field width. The tilt must appear after the 0 in the format field.
You must specify tour carets t ft) when you want to print a number in
E -format (scientific notation). If you specify more than one but fewer than four carets. you get a syntax error. If you specify more than four carets only the first four are used. The fifth caret (and subsequent carets) are interpreted literally as no text symbols
An equal sign (a) is used to centre a string in the field. You specify the field width by the number of characters (0 and =) in the format field. If the string contains fewer characters than the field width, the string is centreed in the field. If the string contains more characters than can be fit into the field. The right-most characters are truncated and the string fills the entire field.
A greater than sign (>) is used to right justify a string in a field. You specify the field width by the number of characters (# and =) In the format field. If the string contains fewer characters than the field width. the string is right justified in the field. If the string contains more characters than can be fit into the field. the right-most characters are truncated and the string fills the entire field
PUDEF
PUDEF "1 through 4 characters"
134
PUDEF lets you redefine up to 4 symbols in the PRINT USING statement. You can change blanks. commas decimals points, and dollar signs into some other character by placing the new character in the correct position in the PUDEF control string.
Position 1 is the filler character. The default is a blank. Place a new character here when you want another character to appear in place of blanks.
Position 2 is the comma character. Default is a comma.
Position 3 is the decimal point.
Position 4 is the dollar sign.
EXAMPLES
10 PUDEF
20 PUDEF " &"
30 PUDEF " .7
40 PUDEF
pace
space
PRINTs * in the place of blanks.
PRINTs & in place of commas.
PRINTs decimal points in place of commas, and commas in place of decimal points.
PRINTs English patine sign in place of $. decimal points in place of commas and commas in place of decimal points.
READ
READ variable list
This statement is used to get information from DATA statements into variables. where the data can be used. The READ statement variable list may contain both strings and numbers. Care must be taken to avoid reading strings where me READ statement expects a number, which produces an ERROR message
EXAMPLE.
READ A$, GS, Y
135
REM
REM message
The REMark is just a note to whoever is reading a LIST of the program
It may explain a section of the program, give information about the author. etc. REM statements In no way effect the Operation of the program, except to add to its length (and therefore slow it down) The word REM may be followed by any text, although use of graphic characters gives strange results.
EXAMPLE
10 NEXT X: REM THIS LINE IS UNNECESSARY
RESTORE
RESTORE [line 01
When executed in a program, the pointer to the item in a DATA statement which is to be read next is reset to the first item in the list
This gives you the ability to re-READ the information. If a (line #) follows the RESTORE statement, the pointer is set to that line.
Otherwise the pointer is reset to the first DATA statement in the program.
EXAMPLE.
RESTORE 200
RESUME
RESUME [line w NEXT]
136
Used to return to execution atter TRAPping an error. With no arguments. RESUME attempts to re-execute the line In which the error occurred. RESUME NEXT resumes execution at the next statement foilowing the statement containing the error; RESUME line # will GOTO the specific line and begin execution there.
RETURN
RETURN
This statement is always used with the GOSUB statement. When the program encounters a RETURN statement. it goes to Me statement immediately following the last GOSUB command executed. If no
GOSUB was previously issued, then a RETURN WITHOUT GOSUB
ERROR message is delivered. and program execution is stopped. f
SCALE
SCALE < I /0>
The scaling of the bit maps in multicolour and high resolution modes can be changed with the SCALE command. Entering:
SCALE 1 turns scaling on. Coordinates may then be scaled from 0 to 1023 in both X and Y rather than the normal scale values, which are: multicolour mode. high resolution mode
X e
Scaling can be turned off by entering 'SCALE 0'.
0 to 319 0 to 199
137
SCNCLR
SCNCLR
Clears the current screen, whether graphics, text, or both (split screen).
SOUND
SOUND voice fr, frequency control, duration
This statement produces a SOUND using one of three voices with a frequency controi in the range 0. 1023 for a duration 01 0 - 65535 60ths of a second.
V
2
3
Voice
Voice 1 (tone)
Voice 2 (tone)
Voice 2 (white noise)
If a SOUND for voice N is requested, and the previous SOUND for the same N is still playing, BASIC waits for the previous SOUND to complete. SOUND with a duration of 0 is a special case. it causes
BASIC to turn oft the current SOUND for that voice immediately, regardless of the time remaining on the previous SOUND See the
MUSIC NOTE TABLE in the appendix for the frequency control values that correspond to real notes.
EXAMPLE
SOUND 2, 800, 3600
Plays a note using voice 2 with frequency set at 800 for one minute
138
SSHAPE/GSHAPE
SSHAPE and GSHAPE are used to save and restore rectangular areas of multicolour or high resolution screens using BASIC string variables
The command to save an area is:
SSHAPE string variable, al ,b1 La2.b21 string variable String name to save data in at ,b1 a2,b2
Corner coordinate (scaled)
Corner coordinate opposite (al )(default is the
PC)
Because BASIC limits siring lengths to 255 characters the size of the area you may save is limited. The string size required can be calculated using one of the following (unsealed) formulas:
L(mcm) = INT ( (ABS(a1-a2) + 1)/4 + .99) • (ABS(b1 -b2) + 1) + 4
L(h-r) = INT ( (ABS(al-a2) + 1) / 8 + .99) • (ABS(bl-b2) + 1) + 4
(mcm) refers to multi-colour mode; (h-r) Is high resolution.
The shape is saved row by row. The last four bytes of the string contain the column and row lengths less one (i.e.: ABS (al -a2) ) in low/ high byte formal (if scaled divide the lengths by 3.2 (X) and 5.12 (Y) ).
The command to display a saved shape on any area of the screen
GSHAPE string variable name [, [a,b1l.mode.1] string ..... al) mode
:Contains shape to be drawn
Top left coordinate telling where to draw tee shape
(scaled - the default is the PC)
Replacement mode;
0: place shape as is (default)
1: place field inverted shape
2: OR shape with area
3: AND snape with area
4: XOR shape with area
139
EXAMPLES
SSHAPE "VARIABLES", 0, 0
GSHAPE "VARIABLEr„,1
Saves screen area from the upper left corner to where me cursor is positioned under the name
VARIABLES.
Displays VARIABLES shape with background and foreground colours reversed, with the too lett of tne shape positioned at the cursor. f I
'
TRAP
TRAP fline41
When turned on. TRAP intercepts all error conditions (including the
7lUIV1ITOP key) except "UNDERD STATEMENT ERROR" In the event of any execution error, the error flag is set, and execution is transferred to the line number named in the TRAP statement. The line number in which the error occurred can be found by using the system variable EL.
The specific error condition G contained in system variable ER. The string function ERRS(ER) gives the error message corresponding to any error condition ER.
NOTE: An error in a TRAP routine cannot be trapped. The RESUME statement can be used to resume execution. TRAP with no MO' argument turns oft error TRAPping.
STOP
STOP
This statement halts the program. A message. BREAK IN LINE A', where the 4' is the line number containing the STOP. The program can be re-started at the statement following STOP It you use the CONT command. The STOP statement is usually used while debugging a program.
TRON
TRON
TRON is used in program debugging This statement begins trace mode. When you are in trace mode, as each statement executes, the line number of that statement is printed.
SYS
SYS address
The word SYS is followed by a decimal number or numeric variable in the range 0 to 65535. The program begins executing the machine language program starting at that memory location. This is similar to the USR function, but does not pass a parameter. See the
Programmer's Reference Guide for information about machine language programs.
TROFF
TROFF
This statement turns trace mode off.
140
141
VOL
VOL volume levet
Sets the current VOLume level for SOUND commands. VOLume may be set from 0 to 8. where 8 is maximum volume, and 0 is off. VOL affects both voices
WAIT
WAIT address, value I [. value 2)
The WAIT statement is used to halt the program until the contents of a location in memory changes in a specific way. The address must be in the range from 0 to 65535. Value 1 and value 2 must be in the range from 0 to 255.
The content of the memory location is first exclusive-ORed with value 2
(if present), and then logically ANDed with value 1. If the result is zero. the program checks the memory location again. When the result is not zero the program continues with the next statement.
Additional Graphic Statement Information
There are a few concepts that apply to all of the bit map graphics statements First is the concept of the Pixel Cursor (PC). The PC Is similar to the cursor in text mode: it is the position where the next dot 5 to be drawn. Unlike the text cursor, the PC is Invisible. All drawing commands use the PC. In addition, the locate command aliows you to reposition the PC without drawing anything.
Wherever you would use X Y coordinates in a drawing comm.and, you can use RELATIVE coordinates instead. Relative coordinates are based on the current value of the PC. To use relative coordinates. just place a
+ or - in front of your coordinates. A plus sign before me X value moves Me PC to the right. A minus sign before the X value moves the
PC to the left. Similarly, a minus sign before the Y coordinate moves the PC up. while a plus sign moves the PC down. For example:
142
LOCATE +100,-25 moves the PC right 100 pixels and up
25
.
DRAW!, +10, +10T0100,100 draws a line 10 pixels right and 10 pixels below the current value of the
PC to the absolute point 100,100
You can also specify a distance and and angle relative to the current
PC by separating the two parameters by a semicolon
.
For example.
LOCATE 50;45 moves the PC from its current location by a distance of 50 dots at an angle of
45 degrees.
FUNCTIONS
Numeric Functions
Numeric functions are classified as such because they return numbers.
The functions they perform range from calculating matnemattcal functions to specifying a screen location Numeric functions follow the form:
FUNCTION (argument) where the argument can be a numerical value. variable, or string
.
ABS(X) (absolute value)
The absolute value function returns Me magnitude of the argument X.
ASC(X$)
This function returns the ASCII code (number) of the first character of
X$
143
ATN(X) (arctangent)
Returns the angle whose tangent is X, measured in radians.
COS(X) (cosine)
Returns the value of the cosine of X. where X is an angle measured in radians
DEC (hexadecimal-string)
Returns decimal value of hexadecimal-string (0< hexadecimalstring < FFFF)
EXAMPLE:
N=DEC("F4")
EXP(X)
Returns the value of the mathematical constant e (2.71828183) raised to the power Of X.
FNxx(x)
Returns the value of the user-defined function xx created in a DEF FNxx statement
144
INSTR (string 1, string 2 (,starting-position))
Returns position of string 2 in string 1 at or after the (starting-position) .
The starting-position defaults to the beginning of string 2. It no match is found. a value of 0 is returned.
EXAMPLE
PRINT INSTR("THE CAT IN THE HAT", "CAT") the result is 5, because CAT starts at the fifth cnaracter in string I
INT(%) (integer)
Returns the integer portion of X. with all decimal places to the right of the decimal point removed. The result is always less-than or equal to
X. Thus, any negative numbers with decimal places become the integer less-than their current value (e.g. INT(-4.5)c-5).
If the INT function is to be used for rounding off, the form is INT(X + 5) or INT(X - .5).
EXAMPLE:
XaINT(X•100 + .5)/100 Rounds to the next highest penny
JOY (n)
When n 1 n = 2
Position of joystick #1
Position of joystick #2
Any value of 128 or more means the fire button is also depressed. The direction is indicated as lolows.
145
fire = 128 +
LEFT 7
UP
1
8
0
6
5
DOWN
2
4
EXAMPLE:
3 RIGHT
JOY(2) with value of 135 fires joystick #2 to the left
LOG(X) (logarithm)
This returns the natural log of X The natural log is log to the base e
(see EXP(X)) To convert to log base 10. divide by LOGO 0/
PEEK(X)
This function gives the contents of memory location X, where X is located in the range of 0 to 65535, returning a result from 0 to 255. This is often used in conjunction with the POKE statement.
RCLR(N)
Returns current colour assigned to source N (0 = < N = < 4)
(0=background, 1 =foreground, 2=multicolour 1. 3=multicolour 2,
4—border)
RDOT(N)
Returns information about the current position of the pixel cursor (PC) at
XPOS/YPOS.
146
N - 0 for XPOS
1 for YPOS
2 colour source
RGR(X)
Returns current graphic mode (X is a dummy argument and can be any value.)
RLUM(N)
Returns current luminance level assigned to colour source N
RND(X) (random number)
This function returns a random number between 0 and 1. This is useful in games. to simulate dice rolls and other elements of chance, and is also used in some statistical applications. The first random number should be generated by the formula RND(-TI), to stan things elf differently every time. After this. the number in X should be a 1. or any positive number. (X represents the seed, or what the RaNDom number is based on.) If X is zero, RND is re-seeded from the hardware clock every lime RND is used. A negative value for X seeds the random number generator using X and gives a random number sequence. The use of the same negative number for X as a seed results in the same sequence of random numbers. A positive value gives random numbers based on the previous seed.
To simulate the rolling of a die, use the formula INT(RNDO ) 4.
6+1). First the random number from 0-1 is multiplied by 6, which expands the range to 0-6 (actually, greater than zero and less then six). Then 1 is added. making the range 1 to under 7 The INT function chops off all the decimal places, leaving the result as a digit from 1 to 6
To simulate 2 dice, add two of the numbers obtained by the above formula together_
147
EXAMPLE
100 X=INT(FIND(1)*6)+INT(END(1)*6)+2
100 X=INT(RND(1)•1000)+
100 X+INT(END(1) 4150)+100
Simulates 2 dice.
Number from 1-1000.
Number from 100-249.
SGN(X) (sign)
This function returns the sign, as in positive, negative, or zero, of X. The result is + 1 if positive. 0 if zero, and - 1 if negative
SIN(X) (sine)
This Is the trigonometric sine function. The result is the sine of X. where X !s an angle In radians.
SQR(X) (square root)
This function returns the square root of X, where X is a positive number or 0. If X is negative. an ILLEGAL QUANTITY ERROR results.
TAN(X) (tangent)
This gives the tangent of X. where X Is an angle in radians.
148 r
USR(X)
When this function is used. the program lumps to a machine language program whose starting point is contained in memory locations 1281 and 1282. The parameter X is passed to the machine language program in the floating point accumulator. Another number is passed back to the BASIC program through the calling variable In other words, this allows you to exchange a variable between machine code and BASIC. See the Programmer's Reference Guide for more details on this, and on machine language programming
VAL(X$)
This function converts the string X$ into a number. and is essentially the Inverse operation from STR$. The string is examined from the leftmost character to the right, for as many characters as are in recognizable number format. If the Commodore 16 finds illegal characters, only the portion of the string up to that point is converted
EXAMPLE
10 X=VAL("123.456")
10 X= VAL("3E03")
10 X=VAL("12A1313")
10 X=VAL("RIU017"")
10 X =VAL("-1.23.23.23")
X=123.456
X=3000
X=12
X=0
X=-1.23
149
String Functions
String !unctions diner from numeric functions in that they return characters, graphics or numbers from a string (defined by quotation marks) instead of a number
CHYME)
This function returns a string character whose ASCII code is X.
ERRS(N)
Returns string describing error condition N (see TRAP)
HEXS(N)
Returns a 4 character string containing Me hexadecimal representation of value N (0 < N < 65535)
LEFTS(X$,X)
This returns a string containing the leftmost X characters of X$.
LEN(X$)
Returns the number of characters (including spaces and other symbols) in me string X$
150
MIDS(X$,N,X)
This returns a string containing X characters, starting from the Nth character in XS M1D$ can also be used on the left side of assignment statement as a pseudo-variable as well as a function. MID$ (string variable. starting position, length) = source string.
This function reassigns values of positions (starting position) through
(starting position + length) of source string to me characters of string variable in corresponding locations. Length defaults to the length of string variables. and an error results if (starting position + length) is greater than the length of the source string.
EXAMPLE
10 A$ ."14HE LAST GOODBYE":
20 PRINT AS
30 MIDS(AS,6,3)="ONG"
40 PRINT AS
R1GHTS(X$,X)
This returns the right-most X characters In XS.
STAVE)
This returns a string which is identical to the PRINTed version 01 XS.
EXAMPLE'
AS=STII$(X)
15'
Other Functions
FRE (X)
This function returns the number of unused bytes available in memory.
X is a dummy argument.
POS (X)
This function returns the number of the column (0-39) where the next
PRINT statement begins on the screen X is a dummy argument
SPC (X)
This is used in the PRINT statement to skip over X spaces. X can have a value from 0-255
TAB (X)
This is used in the PRINT statement. The next Item to be printed is in column number X. X can have a value from 0 to 255.
Tr (PI)
The pi symbol, when used in an equation, has the value of 3.14159265.
VARIABLES & OPERATORS
Variables
Your Commodore 16 uses three types of variables in BASIC. These are: normal numeric, integer numeric. and string (alphanumeric) variables.
152
Normal NUMERIC VARIABLES, also called floating point variables, can have any value from X18 to +18 with up to nine digits of accuracy.
When a number becomes larger than nine digits can show, as in
10 -I° or 10 ''° . your computer displays it in scientific notation form, with the number normalized to 1 digit and eight decimal places. followed by the letter E and the power of ten by which the number is multiplied. For example. the number 12345678901 is displayed as
1.234356789E+10.
INTEGER VARIABLES can be used when the number is from +32767 to -32768, and with no fractional portion. An integer variable is a number like 5, 10. or -100. Integers take up less space than floating point variables when used in an array.
STRING VARIABLES are those used for character data which may contain numbers. letters, and any other character that your Commodore
16 can make An example of a string variable is "COMMODORE 16"
VARIABLE NAMES
Variable names may consist of a single letter, a letter followed by a number, or two letters. Variable names may be longer than 2 characters, but on:y the first Iwo are significant
An integer variable is specified by using the percent (%) sign after the variable name. String variables have the dollar sign ($) after their names
EXAMPLES:
Numeric Variable Names: A, A5, BZ
Integer Variable Names: A%, A5%. BZ%
String Variable Names: AS. A5S. B2$
ARRAYS are lists of variables with the same name, using an extra number (or numbers) to specify an element of the array. Arrays we defined using the DIM statement, and may be floating point, integer, or string variables arrays. The array variable name is followed by a set of parentheses ( ) enclosing the number of the variable in the list
153
EXAMPLES: A(7),BZ %(11).A$(87)
Arrays may have more than one dimension. A two dimensional array may be viewed as having rows and columns, with the first number identifying the column and the second number in the parentheses
Identifying the row (as if specifying a certain grid on a map).
EXAMPLES: A(7,2)13Z % (2.3,4). Z$(3.2)
RESERVED VARIABLE NAMES
There are seven variable names which are reserved for use by the
Commodore 16. and may not be used for another purpose. These are the variables DS, Mt ER. EL, ST,TI, and Ti$. You also can't use
KEYWORDS such as TO and IF, or any names that contain
KEYWORDS. such as SRUN. KNEW. or XLOAD as variable names.
ST is a status variable for input and output (except normal screen/ keyboard operations). The value of ST depends on the results of the last input/output operation. A more detailed explanation of ST is in the
Series 264 Programmers Reference Guide. but in general, if the value of ST is 0 the operation was sucessful
TI and 715 are variables that relate to the real-time clock built into your
Commodore 16 The system clock is updated every 1/60th of a secono. It starts at 0 when your Commodore 16 is turned on. and is reset only by changing the value of 71$. The variable TI gives you the current value of the clock in 1 /60ths of a second.
71$ is a string that reads the value of the real-time clock as a 24 hour clock. The first two characters of 71$ contain the hour. the 3rd and 4th characters are the minutes, and the 5th and 6th characters are the seconds. This variable can be set to any value (so long as all characters are numbers). and will be automatically updated as a 24 hour clock.
EXAMPLE: TI$ = "101530" sets the clock to 10.15 and 30 seconds
(AM)
The value of the dock is lost wnen your Commodore 16 is turned off It starts at zero when your computer is turned on. and Is reset to zero when the value of the clock exceeds 235959 (23 hours. 59 minutes and
59 seconds).
154
The variable DS reads the disk drive command channel, and returns the current status of the drive. To get this information in words, PRINT
DS$. These status variables are used after a disk operation, like a
DLOAD or DSAVE, to find out why the red error light on the disk drive is blinking.
ER. EL. and ERR$ are variables used in error trapping routines. They are usually only useful within a program. ER returns the last error encountered since the program was RUN. EL is the line where the error occured. ERRS is a function which allows your program to print one of the BASIC error messages. PRINT ERR$(ER) prints out the proper error message.
BASIC OPERATORS
Tne ARITHMETIC operators include the following signs.
• addition subtraction multiplication division raising to a power (exponentiation)
On a line containing more than one operator, there is a set order in which operations always occur. If several operators are used together, the computer assigns priorities as follows: First. exponentiation. then multiplication and division, and last, addition and subtraction. If two operations have the same priority, then calculations are performed in order from left to right. If you want these operations to occur in a different order. Commodore 16 BASIC allows you to give a calculation a higher priority by placing parentheses around it. Operations enclosed in parentheses will be calculated before any other operation. You have to make sure that your equations have the same number of left parentheses as right parentheses, or you will get a SYNTAX ERROR message when your program is run
There are also operators for equalities and Inequalities. called
RELATIONAL operators. Arithmetic operators always take priority over relational operators.
Is equal to is less than is greater than
< = Or = < is less than or equal to
155
> or => is greater than or equal to
< > or > < is not equal to
Finally, there are three LOGICAL operators. with lower priority than both arithmetic and relational operators:
AND
OR
NOT
•
These are used most often to join multiple formulas in IF . . THEN statements. When they are used with arithmetic operators, they are evaluated last (i.e., after + and -).
EXAMPLES:
IF A=B AND C=D THEN 100
IF A=B OR C=D THEN 100
A=S:B=4:PR1NT A=B
A =5:B=4:PRINT A>B
PRINT 123 AND 15:PRINT S OR 7 requires both A=B & C=D to be true allows either A=B or C=D to be true displays a value of 0 displays a value of -1 displays 11 and 7
156
(
BASIC Abbreviation and Reference Chart
COS
DATA
DEC
DEF FN
DELETE
DIM
DIRECTORY
DLOAD
DO
DRAW
DSAVE
END
ERR$
EXP
FOR
FRE
GET
GETKEY
GET#
GOSUB
GOTO
GRAPHIC kerwOnD
ABS
ASC
ATN
AUTO
BACKUP
BOX
CHAR
CHR$
CIRCLE
CLOSE
CLR
CMD
COLLECT
COLOR
CONT
COPY
ABBREVIATION a SMFT a MOT S a 88MT T a SMPT U b
satyr
A b ch
SHIT
0
Sin
A c 881IT H c
start
cl San 0 c SEIM L c SHIFT M col MUM L co MUFF L c SHWT 0 co
sant
P none d SMUT A rove d air E de
saner
L d SHIFT I di
sant
R d =FT L none cl SHIFT R d MOT S e MUT N e SMET R e MUTT X f MOT 0 f SEWS R g an getk S
E
E none go .SIXPT S g Mr 0 g
Oftt
R
TYPE function—numeric function—numeric function—numeric command command statement
Statement function—string statement statement statement statement command statement command command function—numeric statement function—numeric statement command statement command command statement statement command statement function —string function—numeric statement function—numeric statement statement statement statement statement statement
157
KEYWORD
GSHAPE
HEADER
HEX$
IF ...GOTO
IF...THEN. ELSE he
INPUT
INPUT,
INSTR
INT in
JOY
KEY
LEFTS
LEN
LET
UST
LOAD
LOCATE
LOG
LOOP
MID$
MONITOR
NEW
NEXT le to to
ON ...GOSUB on...go
ON...GOTO on g
OPEN
PAINT
PEEK
POKE
POS
PRINT #
PRINT USING ?us
PUDEF
RCLR
RDOT
READ
REM
ABBREVIATION
S
Et
A
'IMPF E none none none
Wt N
Alirt S none
—. 0
Wmt
E
Set
F none
ELF
E
Tom;
I
Ian
0
C none gar• 0
Ian I et 0 none
girt
E
seer
S art 0
Set
P
SW'S A
E et 0 none
SEPT R
SEEt' I
SEME, C
4012It D
MIT E none
TYPE statement command function—string
Statement statement statement statement function—numeric function—numeric function—numeric command function—string function—numeric statement command command statement function—numeric statement function—string statement command statement statement statement statement statement function—numenc statement function—numeric statement statement statement statement function—numeric function—numeric statement statement
158
F f
I
: f
( f
I r
I I-
I
I
I f
( if f f I
I f I f I
I I f
I
KEYWORD
RENAME
RENUMBER
RESTORE
RESUME
RETURN
RGR
RIGHTS
RLUM
RND
RUN
SAVE
SCALE
SCNCLR
SCRATCH
SGN
SIN
SOUND
SPC(
SQR
SSHAPE
STatus
STOP
STR$
SYS
TAB(
TAN
TI
TRAP
TROFF
TRON
UNTIL
USR
VAL
VERIFY
VOL
WAIT
WHILE
I
I
I
I
ABBREVIATION re ren re S
N
U
S res .Ser U re Mit T r
EMT
G r EMIT I r LIFT L ann N
AST U
S SEWS A sc -SENT A s Sir C
Sc SUM R
$ MET G s SEWS I
S SENT 0
s EENT P none
S
T st mat
R s Y none none
I
SRO? R
Ito
man
F tr Sian 0
u
art N u Man v
.saurr
E v SWF? 0
w SHIT
HA
TYPE command command statement statement statement function—numeric function—string function—numeric function—numeric command command statement statement command function—numeric function—numeric statement function—special function—numeric statement reserved—numeric variable statement function—string statement function—special function—numeric reserved—numeric variable reserved—string variable
Statement statement statement statement function—special function—numeric command statement statement statement
159
160
I- V
I f f • I
( .1(
I
I r f •
I r r -
(
1
I
I 7
APPENDICES
f • Error messages
I
• Disk error messages
I
I
• Deriving mathematical functions
• Musical note table
(
• Screen display and ASCII codes
(
I f
• Book list
I f
I
(
161
APPENDIX A
Error Messages
These error messages are printed by BASIC You can also PRINT the messages through the use of the ERRS() function. The error number refers only to the number assigned to the error for use with this function
ERROR # ERROR NAME
1
2
3
4
5
6
7
8
9
10
TOO MANY FILES
FILE OPEN
FILE NOT OPEN
FILE NOT FOUND
There is a limit of 10 files
OPEN at one time
An attempt was made to open a file using the number of an already open file.
The file number specified in an I/O statement must be opened before use.
No file with that name exists
(disk)
DEVICE NOT PRESENT The required I/O device not available.
NOT INPUT FILE An attempt made to GET or
INPUT data from a file that was specified as output only.
NOT OUTPUT FILE An attempt made to send data to a file that was specified as input only
MISSING FILE NAME
ILLEGAL DEVICE
NUMBER
An OPEN, LOAD, or SAVE to the disk drive generally requires a file name.
An attempt made to use a device improperly (SAVE to the screen. etc.)
NEXT WITHOUT FOR Either loops are nested in- correctly. or there is a variable name in a NEXT statement that doesn't correspond with one in a FOR
SYNTAX A statement is unrecogniza- ble by BASIC This could be
162
12
13
14
15
17
18
19
20
21
RETURN WITHOUT
GOSUB
OUT OF DATA
ILLEGAL QUANTITY because 01 missing or extra parenthesis, misspelled keyword, etc.
A RETURN statement en- countered when no GOSUB statement was active.
A READ statement en- countered, without data left unREAD
A number used as the argument of a function or statement is outside the allowable range.
OVERFLOW
OUT OF MEMORY
The result of a compu- tation is larger than the largest number allowed
(1.701411833E+38)
Either there is no more room for program and program variables, or there are too many DO. FOR, or GOSUB statements in effect.
UNDEF'D STATEMENT A line number referenced doesn't exist in the program.
BAD SUBSCRIPT The program tried to refer- ence an element of an array out of the range specified by the DIM statement
REDIM'D ARRAY
DIVISION BY ZERO
ILLEGAL DIRECT
An array can only be DIMen- sioned once. If an array is referenced before that array is DIMd. an automatic DIM (to
10) is performed.
Division by zero is not allowed.
INPUT or GET statements are only allowed within a program.
163
27
28
29
30
31
32
33
34
35
22
23
24
25
26
TYPE MISMATCH
STRING TOO LONG
FILE DATA
FORMULA TOO
COMPLEX
CAN'T CONTINUE
UNDEF'D FUNCTION
VERIFY
LOAD
BREAK
CAN'T RESUME
LOOP NOT FOUND
LOOP WITHOUT DO
DIRECT MODE ONLY
NO GRAPHICS AREA
This occurs when a number is used in place of a string or vice-versa
A string can contain up to 255 characters.
Bad data read from a tape file.
Simplify the expression
(break into 2 parts or use
fewer parentheses)
The CONT command does not work if the program was not RUN. there was an error, or a line has been edited.
A user defined function referenced that was never defined.
The program on tape or disk does not match the program in memory.
There was a problem loading.
Try again
The stop key was hit to halt program execution.
A RESUME statement en-
countered without TRAP statement in effect .
The program has encountered a DO statement and cannot find the corresponding LOOP
I OOP encountered without a
DO statement active.
T his command is allowed only in direct mode, not from a program
A command (DRAW, BOX. etc.) to create graphics encountered before the
164 r
I
I
I
I f f
I
f
I
.
f
r r r
:
36 r r r
I , f
E
I I-
f
I
BAD DISK
GRAPHIC command was executed.
An attempt failed to HEADER a diskette, because the quick header method (no ID) was attempted on an unformatted diskette, or the diskette is bad.
165
APPENDIX B
Disk Error Messages
These error messages are returned through the DS and DS$ reserved variables
NOTE: Error message numbers less than 20 should be ignored with the exception of 01, which gives information about the number of files scratched with the SCRATCH command
20
21
22
23
24
READ ERROR
(block header not found)
The disk controller is unable to locate the header of the requested data block. Caused by an illegal sector number, or the header has been destroyed
READ ERROR
(no sync character)
The disk controller is unable to detect a sync mark on the desired track. Caused by misalignment of the read/writer head, no diskette is present, or unformatted or improperly seated diskette. Can also indicate a hardware failure.
READ ERROR
(data block not present)
The disk controller has been requested to read or verify a data block that was not properly written. This error message occurs in conjunction with the BLOCK commands and indicates an illegal track and/or sector request
READ ERROR
(checksum error
En data block)
This error message indicates that there is an error in one or more of the data bytes The data has been read Into the DOS memory, but the checksum over the data is in error This message may also indicate grounding problems.
READ ERROR
(byte decoding error)
The data or header has been read into the DOS memory, but a hardware error has been created due to an invalid bit pattern in the data
166
25
26
27
28
29
30
WRITE ERROR
(wweverify error)
WRITE PROTECT ON
READ ERROR
(checksum error in header)
WRITE ERROR
(long data block)
DISK ID MISMATCH
SYNTAX ERROR
(general syntax) byte. This message may also indicate grounding problems.
This message is generated it the controller detects a mismatch between the written data and the data in the DOS memory.
This message is generated when the controller has been requested to write a data block while the write protect switch is depressed.
Typically, this is caused by using a diskette with a write protect tab over the notch
The controller has detected an error in the header of the requested data block. The block has not been read into the DOS memory This message may also indicate grounding problems.
The controller attempts to detect the sync mark of the next header after writing a data block. if the sync mark does not appear within a pre-determined time. the error message is generated. The error is caused by a bad diskette format
(the data extends into the next block), or by hardware failure.
This message is generated when the controller has been requested to access a diskette which has not been initialized. The message can also occur if a diskette has a bad header
The DOS cannot interpret the command sent to the command channel. Typically, this is caused
tit www.commodore.ca
May Not Reprint Without Permission
167
32
33
34
31
39
50
5'
SYNTAX ERROR
(invalid command)
SYNTAX ERROR
(invalid command)
SYNTAX ERROR
(invalid file name)
SYNTAX ERROR
(no file giver) by an illegal number of file names. or patterns are illegally used. For example. two Me names may appear on the left side of the
COPY command
The DOS does not recognize the command The command must start in the first position.
The command sent is longer than
58 characters
Pattern matching is invalidly used in the OPEN or SAVE command
The file name was left out of a command or the DOS does not recognize it as such. Typically. a colon() has been fell out of the command
.
SYNTAX ERROR
(invalid command)
This error may result if the command sent to command channel
(secondary address 15) is unrecognized by the DOS
.
RECORD NOT PRESENT Result of disk reading past the last record through INPUTS, or
GETS commands This message will also occur after positioning to a record beyond end of Me in a relative file II the intent is to expand the Me by adding the new record (with a PRINTS command), the error message may be ignored INPUT or GET should not be attempted after this error is detected without first repositioning
OVERFLOW IN RECORD PRINTS statement exceeds record boundary. Information is truncated. Since the carriage re-
168
52
60
61
62
63
64
FILE TOO LARGE
WRITE FILE OPEN
FILE NOT OPEN turn which is sent as a record terminator is counted in the record size. this message will occur it the total characters in the record (including the final carriage return) exceeds the defined size.
Record position within e relative
Me indicates that disk overflow will result.
This message Is generated when a write liie that has not been closed is being opened for reading
This message is generated when a file is being accessetl that has been opened in the DOS.
Sometimes. in this cast. a mesquest is simply ignores.
FILE NOT FOUND
FILE EXISTS
The requested file does not exist on the indicated drive.
The file name of the file being created already exists on the diskette.
FILE TYPE MISMATCH
NO BLOCK
The file type does not match the file type in the directory entry for the requested file.
This message occurs in conjunction with the B-A command It indicateS that the block to be allocated has been previously allocated. The parameters indicate the track and sector available the parameters are zero (0). then all blocks higher in number are in use
169
66
67
70
71
72
73
ILLEGAL TRACK
AND SECTOR
ILLEGAL SYSTEM
TORS
NO CHANNEL
(available)
DIRECTORY ERROR
DISK FULL
DOS MISMATCH (73,
CBM DOS V2.6 1541)
The DOS has attempted to access a track or block which does not exist in the format being used
This may indicate a problem reading the pointer to the next block
This special error message indicates en illegal system track or sector.
The requested channel is not available, or all channels are in use. A maximum of five sequential files may be opened at one time to the DOS. Direct access channels may have six opened files .
The BAM does not match the internal count. There is a problem in the BAM allocation or the BAM has been overwritten in DOS memory To correct this problem reinitialize the diskette to restore the BAM in memorY. Some active files may be terminated by the corrective action. NOTE: BAM =
Block Availability Map
Either the blocks on the diskette are used or the directory is at its entry limit. DISK FULL is sent when two blocks are available on the 1541 to allow the current file to be closed.
DOS 1 and 2 are read compatible but not write compatible. Disks may be interchangeably read with either DOS, but a disk formatted on one version cannot be written upon with the other version because the format is different This error is displayed whenever an
170
74 DRIVE NOT READY attempt is made to write upon a disk which has been formatted in a non-compatible format. (A utility routine is available to assist in converting from one format to another.) This message may a:so appear after power up.
An attempt has been made to access the Floppy Disk Drive without any diskette present
171
APPENDIX C
Deriving Mathematical Functions
Functions that are not intrinsic to BASIC 3.5 may be calculated as follows:
FUNCTION
SECANT
COSECANT
COTANGENT
INVERSE SINE
INVERSE COSINE
INVERSE SECANT
INVERSE COSECANT
INVERSE COTANGENT
HYPERBOLIC SINE
HYPERBOLIC COSINE
HYPERBOLIC TANGENT
HYPERBOLIC SECANT
HYPERBOLIC COSECANT
HYPERBOLIC COTANGENT
INVERSE HYPERBOLIC SINE
INVERSE HYPERBOLIC COSINE
INVERSE HYPERBOLIC TANGENT
INVERSE HYPERBOLIC SECANT
INVERSE HYPERBOUC COSECANT
INVERSE HYPERBOLIC COTANGENT
BASIC EQUIVALENT
SEC(x)- MOS(%)
C,SC(x)- uStN(x)
COT(x)- UTAN(X)
ARCSIN(x)=ATignoSOR(- x•x 1))
ARCCOS(X)- -ATN(x•SOR
N X•X 111.77,2
ARCCSC(X)-ATN(x/SOR(X•X - I ))
ARCCSC(X)=ATN(X/SOR(K• X -1))
+(RONDO-1'7722)
ARCOT(X)-ATN(X) • w/2
SINH(X)-(EXP(X)-EXP(- 012
COSH(X)=(EXP(X)- +EXP( ^ X)Y2
TANH(X)..EXPI-XY(EXP(x)a.EXP
( - X))•2+
SECH(X)s21(EXP(X)+EXP( -X))
CSCH(X).2/(E XP(X)- E XP( - X))
COTH(X)=EXP( - Xy(EXP(X)
- EXP(-)0)•2+
ARCS1NH(X)- LOGO( FSOR(X•X *1/1
ARCCOSH(X)-LOG(X4-SOR(X•X- I))
ARCTANH(x)= LOGO I
♦
Xy( I - X)y2
ARCSECH(x)-LOG8SOR
( - X*X41)+ 1}‘X)
ARCCSCH(X)”LOGICSCIN(X1'SOR
(x•x+
¶)/x))
ARCCOTH(X)- LOGRX • I X - Hy2
A
B
C
0
E
F
A
B
C
D
E
F
APPENDIX
D
Musical Note Table
NOTE SOUND REGISTER VALUE ACTUAL FREQUENCY (HZ)
A
B
C
E
F
A
C
E
F
G
7
118
169
262
345
383
453
516
571
596
643
685
704
739
770
798
810
834
854
864
881
897
911
917
929
939
944
953
110
123.5
130.8
146.8
164.7
174.5
588.7
658
699
782.2
880.7
989.9
1045
1177
1316
1398
1575
195.9
220.2
246.9
261.4
293.6
330
349.6
392.5
440.4
494.9
522.7
The above table contains the sound regis er values of four octaves of notes. The sound register values are used as the second parameter of the SOUND command To use the first note in the table (A—sound
172 173
register value 7) use the 7 as the second number after the SOUND command—SOUND 1,7,30
Use the following formula to find the sound register values for frequencies other than those in the table:
SOUND REGISTER VALUE – 1024 --(111860.781/FREOUENCY)
Both the table of sound register values and the above formula are for
NTSC televisions This is the television standard used throughout the
United States and all of Canada. If you are in a country where PAL is the television standard, you should use the following formula to calculate new sound register values for the entire table
SOUND REGISTER VALUE = 1024—(111840.45/FREQUENCY)
I
I
APPENDIX E
Screen Display Codes
The following chart lists all of the characters built into the Commodore character sets It shows which numbers should be POKEd into screen memory (locations 3072 to 4095) to get a desired character. (Remember to set color memory-2048 to 3071) Also shown is which character corresponds to a number PEEKed from the screen.
Two character sets are available, but only one set at a time. This means that you cannot have characters from one set on the screen at the same time you have characters from the other set displayed. The sets are switched by holding down the
f!
► 1fQ!
and _0 keys simultaneously.
From BASIC, PRINT CHR$(142) will switch to upper-casergraphicS mode and PRINT CHR$(14) switches to upper: sower-case mode.
Any number on the chart may also be displayed in REVERSE The reverse character code may be obtained by adding 128 to the values shown
I
174 175
L
M
N
I
J
K
61
A
8
C
D
E
F
G
H
0
P
CI
R
S
SET 1 SET 2 POKE SET 1 SET 2 POKE SET 1 SET 2 PINE
I k
I rn n
0 p c1 r s e
1 g h i a b c a
8
9
10
11
5
6
7
12
13
14
15
16
17
18
19
0
1
2
3
4
I i
..—
SPACE
I
'
#
$
%
8
X
Y
Z
I
C
T
U
V
W i u v w x y z
(
)
+
.
32
33
34 6
35
7
36 8
9 37
38
39
/
0
1
2
3
4
5
25
26
27
28
29
30
31
20
21
22
23 .
24
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
SET 1 SET 2 POKE SET 1 SET 2 POKE SET 1 SET 2 POKE
7
60
61
62
[21
•
U
V
W
84
85
86
87 63
64 X 88 w
A
8
C
If] D 68 1/0 92
E 69 93
F 70
011 71
1
CD H 72
SPACE
11;
94
95
96
97
❑
73
111
El J 74 98
K 75 99
❑
❑
76 ❑ L
N
M 77 ❑
1111
❑ N 78
❑ O 79
100
101
102
103
P
O
R
65
66
67
80
81
82
0
El
89
90
91
104 al
105
106
1:2
S 83 107
Codes from 128.255 are reversed Images of codes 0-127.
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
177 176
APPENDIX F
ASCII and CHIN Codes
This appendix shows you what characters will appear if you PRINT
CHR$(X). for all possible values of X. It will also show the values obtained by typing PRINT ASC("X"), where Xis any character you can type. This is useful in evaluating the character received in a GET statement, converting upper/lower-case, and printing character based commands (like switch to upper/lower-case) that could not be enclosed in quotes
PRINTS let
ENABLES fLosi
aii
g
10
11
12
UDR 13
SWITCH TO
LOWER CASE
14
15
16
CHAS
0
1
2
3
4
5
6
7
PRINTS
+:
*1
CMS PRINTS
17
18 0
CHRS PRINTS CHRS
34
35
3
4
51
52
Ze 19 $ 36 5 53
A
20 % 37 6 54
21 8 38 7 55
22 39 8 56
23
24
(
)
40
41
9 57
58
25
26
Wie
27
5 ft 28
•
+
.
-
42
43
44
<
59
60
044;
29 46 7 63
WA 30 ! 47 @ 64
31 0 48 A 65 lifriii
32 1 49
8
66
I
33 2
45
50
-
>
C
61
62
67
r Ir
I
I
I
I
I
(
I
I [
I
I
J
K
L
M
N
0
P
O
S
T
U
V
W
X
V
Z
PRINTS
E
F
H
(E1
85
86
87
88
89
81
82
83
84
90
91
92
93
94
95
96
76
77
78
79
80
CHRS
68
69
70
71
72
73
74
75
PRINTS m
CHM PRINTS
97
98
99
100 CI
CHAS
126
127
128
129
❑
❑
CO
❑
El
❑
N z
CI
111
101 W 130
102 Al 131
103
104
M
105 gir
132
133
134
106
107
108
109 iff
rib se
ig
135
136
137
138
110 Se 139
111 = 140
112
war m•••
i41
SWITCH TO
113
UPPER CASE
142
114 143
144
E
[2
•
115 Mt
116
-1
117 11P
118 a
119
are
120 11
CU
121 Z
•
122
EH 123 a m
124
125
DI
I
145
146
147
148
149
150
151
152
153
154
PRINTS CHRS
EH
8,F
155
156
.10.
■ );
ItiC
157
158
%In
MN
159
160
C g
0
0
0
II
0
® r
El
OR
161
162
163
164
165
166
167
168
169
170
171 tli
El
Eil
1;1 t72
173
174
175
176
177 EB
El
El
U
178
179
180
181 El
01
171
182
183
178 179
APPENDIX G
Books For Commodore Products
The following lists include a sampling of the computer and programming books available. The title of the book is listed first. followed by the author and publisher.
Commodore Books
VIC 20 Programmer's Reference Guide
Commodore 64 Programmer% Reference Guide
Commodore Plus/4 Programmer's Reference Guide
Mastering Your VIC 20
Four VIC 20 Computer Books.
VIC Revealed, Nick Hampshire
VIC Games. Nick Hampshire
VIC Graphics, Nick Hampshire
Stimulating Simulations for the VIC. C.W Engel
Introduction to BASIC. Part 1 and 2. Andrew Cohn
Commodore Software Encyclopedia, Third Edition
BASIC Programming
Armchair BASIC: An Absolute Beginner's Guide to Programming in BASIC. Fox & Fox, OsbomelMcGraw-Hill
BASIC Handbook. Second Edition. Lien, Compusoft
Basic Commodore 64 BASIC. Coen. Hayden
Elementary BASIC. LeOgard & Singer. SRA
How to Build a Program, Emmerichs, Dilithium Press
Instant Freeze-Dried Computer Programming in BASIC. Brown
My Computer Likes Me When I Speak in BASIC, Albrecht.
Dihthium Press
Nailing Jelly to a Tree, Willis & Danley, Dilithium Press
The Programmers Book of Rules, Ledin & Ledin. Lifetime
Learning Publishers
Technical BASIC. Kassab, Prentice-Hall
Machine Language Programming
Machine Language for Beginners, Mansfield, COMPUTE! Books
Programming the 6502. Zaks. Sybex
6502 Assembly Language Programming. Leventhal. Osborne/
McGraw-Hill
6502 Micro Chart, Micro Logic Corp.
6502 Software Design. Scanlon. Sams
The 6502 Software Gourmet Guide & Cookbook, Findlay. Hayden
180 f
I
I f
I II
I II f I
I II
I I r
,17- r r r 1-
I f f I
INDEX
A
Abbreviations 62, 157.159
Addition 54
Animation 6740
Atrays 153.154
ASCII Codes APPENDIX F
AUTO Command 96
B
BACKUP Command 97
BASIC Encyclopedia 93-156
BASIC Abbreviation and Reference Chart
157.169
BOX Statement 77-78. 109-110
I I f f
I
( f
I f
I f
I ,f
C
Caleurations 54. 56-57
Order of Calcurabons 57
Parentheses 57
Cartridges 30-31
Loading Cartridges 30-31
Memory Expansion Pon 8
Cassettes 31-34
Cassette Porl 8, 9
Loading Cassettes 32-33
Saving on Cassette 33-35
CHAR Statement 7477. 110
CHRS Codes APPENDIX F
CLEAR/HOME Key 21, 50. 51
Clearing the Screen 21, 50 73
CLOSE Statement 112
CLR Statement 312
CMD Statement 112-113
COLLECT Command 97-98
Colour
Changtng Colours 44-44. 70-72
COLOR Statement 70-71, 113
Colour Keys 23-25. 43A4
Luminance 71
Muth-colour Mode 81-82
PAINT Statement 80-81, 128-129
Reverse Printing 22,43-44
COLOR Statement 70-71 113
Connect ng the Computer 941
COPY Command 9849
Correcting Mistakes
Erasing the Screen 50 line Eatmg 46-49.51.52
D
DATA eatemem 113-114
Drosses° Tape Recorder, 13. 3142
DEF FN Statement 114
DELETE Commend 99
Deleting Letters 20-21, 47-48
Deliving Mathematical Functions
APPENDIX C
DIM Statement 115
Direct Mode 46
DIRECTORY Command 26,
39,99-
'0O
Disk Eva Ma-sages APPENDIX B
Diskettes 34.38
DIRECTORY Command 27, 39, 99400
Heade/mg 3648, 101.102
Loading 3536, 104.105
Saving 38. 107-108
Division 54
DLOAD Command 26, 36-38, 100-101
DO/LOOP/WHILFJUNT1IJEXIT 115-116
DRAW Statement 74-75, 116
°F rit:Ni
Lines 74-76
Points 74-75
Polygons 79-80
Rectangles 77-78
DSAVE Command 26, 38, 101
E
Editing 1See Screen Editing)
END Statement 117
Entering Commands 46
Erasing Crearacters (See Screen Editing)
Erasing Lines (See Screen Editing)
Error Messages 36, 38. APPENDIX A
ESC Key 23. 51
Exponentiation 55
F
Floating Point Variables 60-61, 153
FOR ... TO . .. STEP Statement
117-118
181
Formatting a Diskette 36-38 101
Fractions 55
Functions
Numeric-61-62 143.149
Special 152
String 150-151
User Defined 62
Function Keys 26-27
0
GET Statement 11 8-119
GETKEY Statement 119
GET,. Statement 119-120
GOSUB Statement 120
GOTO Statement 44, 120-121
Graproc Modes
High Resolution 72-82
Multi-coon 81-82
GRAPHIC Statement 72-73. 121
GRAPHIC CLR Statement 122
ONO/Cs
Anenaten 67-70
BOX Statement 77-78
CHAR Statement 76-77
CIRCLE Statement 78-80
DRAW Statement 74.75
Hen Resolution 73-82
Multi-Colour 81-82
PAINT Statement 80-81
Pants. Lines and Labels 74-76
Soares. Circles and Polygons 77-80
Using GrapNc Keys 25. 64-67
GSHAPE Statement 139-140
H
HEADER Command 36-38, 101-102
HELP Command 102
HELP Key 27
Kr Resolution Graphics 73-82
IF THEN
122-123
. ELSE Statement immediate Mode 46 inerect Mode 46
INPUT Statement 123
INPUT* Statement 124
Inserting Letters 20-21. 47-48
INST/DEL Key 20-21, 47-46 integer Variables 60-61, 152-153
J
Joysticks 7
K
KEY Command 102.103
Keys
Key 22, 45
CLEAR/HOME Key 21.53. 51
Colour Keys 23
CTRL Key 21
Cursor Keys 20
ESC Key 23. 51
CLASH ON/OFF Keys 23, 46
Function Keys 26-27
Graphics Keys 25-26, 64-67
HELP Key 27
INST/DEL Key 20-21. 47-48
RETURN Key 19, 47
RUN/STOP Key 19
RVS Chi/OFF Keys 22. 43-46
SHIFT Key 19-19
SHIFT LOCK Key 19
Typing Mode 18
LET Statement 124
UST Command 27, 103-104
LOAD Command 32-33. 104.105
Loading
Cartridges 30
Cassettes 31-33
Diskettes 35-36
LOCATE Statement 125. 142-143
Luminance 71
M
Mathemattal Operators 54. 155-156
PAernory Expansion Po-18. 30
MONITOR Statement 125 monitors 10. 14
Mutt colour Graphics 81-82
Multeication 54
Music 87. 88-91 (See also Sound)
MusiCel NoN Table APPENDIX 0
N
NEW Command 50, 105
NEXT Statement 125.126
182
Numbers
Decimals 55
Deriving MalbernatIcat Functions
APPENDIX C
Fractions 55
Numeric Functions 61-62, 143.149
Operators 54. 155-156
Order of Precedence 57
Parentheses 57
Performing Caculations 54. 56-57
Scientlic Notation 55-56
User-Defined Functions 62
Variables 60-61. 152-155
RETURN Key 19
Reverse Printing 22 43-46
RF Jack 8. 10
RUN Command 106-107
RUN/STOP Key 19
RVS ON/OFF Keys 22, 43-46
0
ON Statement 126-127
Ori011 Switch 7
OPEN Statement 127-128
Operators
Logical 155-156
Mathematical 54. 155-156
Relational 54. 155-156
PAINT Statement 80-81, 128-129
Peripherals 12-15
Pi 19. 55
Pixel Curso- (PC) 142.143
POKE Statement 129-130
Power Supply 7.10
Primers 15
Printing on the Screen 43-49. 58-60
PRINT Statement 130
PRINT./ Statement 131
PRINT USING Statement 131-t 34
Print Zones 58-60
Programming Mode 48
PUDEF Statement 134-135
R
READ Statement 135
Relational ()pintas 54. 155-156
REM Statement 136
RENAME Command 105
RENUMBER Carina/Kt 106
Reserved Vat aNe Names 154-155
Reset Button 7, 50
RESTORE Statement 136
RESUME StatemeN 136-137
RETURN Statement 137
S
SAVE Command 33-34 38. 107-108
Saving vograms
On Cassette 33-34
On Diskette 38
SCALE Statement 137
Seentilc Notal on 55-56
SCNCLR Command 50. 73, 138
SCRATCH Command 108
Screen Deploy 42
Screen Display Codes APPENDIX E
Screen Editing
Correcting Mistakes 46-49
CLEAR/HOME Key 21 50, 51
Clearing the Screen 50
ESC Key 23. 51
INST/DEL Key 20-21, 47-48
Printing On the Screen 58-60
Screen Winoows 51-52
Serial Socket 9
Setting Up the Computer 9-12
Software
Cartridge 30-31
Cassette 31-34
Diskette 34.38
Scone
Musica' Note Table APPENDIX D
SOUND Stalemonl 85-87
VOL Statement 84
Sound Ettems
Music 87 88
Noise 87.88
SOUND Statement
Duration 86-87
Note Frequency 85-86, APPENDIX D
Yokes 84.87
SSHAPE Statement 139.140
STOP Statement 140
Subtraction 54
Switches are Sockets
Cassette Port 8-9
High/Low Switch 8
183
Switches and Sockets—corn
Joystick Sockets 7
Memory Expansion Port 8. 30
On/Off Switch 7
Power Socket 7.9
Reset Sutton 7, 50
RF (TV) Jack 8. 10
Serial Socket 6-9
Video Socket 8, 9, 11
SYS Statement 140
Text String Vailables 60-61, 153
TRAP Statement 141
TROFF Statement ¶ 41
IRON &tenant 141
Troubleshoct ng Chad 11.12
TV Cabe 6. 10
User Defined Functions 62
V
Variables
Foaling Pant Numeric 60-81. 153
Integer 60-61. 153
Text String 60.61. 153
Variable Names 152-153
VERIFY Cornrrand 108-109
Video Socket 8.9, 11
VOLume Statement 8445, 142 w
WAIT Statement 142
Windows 5I-52 c
• www.commodore.ca
May Not Reprint Without Permission
18:
دانلود
تبلیغات