Commodore 64 Personal Computers User Guide
বিজ্ঞাপন
বিজ্ঞাপন
INTRODUCTION
Now that you've become more intimately involved with your Commodore 64, we want you to know that our customer support does not stop here. You may not know it, but Commodore has been in business for over 23 years.
In the 1970's we introduced the first self-contained personal computer (the PET). We have since become the leading computer company in many countries of the world.
Our ability to design and manufacture our own computer chips allows us to bring you new and better personal computers at prices way below what you'd expect for this level of technical excellence.
Commodore is committed to supporting not only you, the end user, but also the dealer you bought your computer from, magazines which publish how-to articles showing you new applications or techniques, and
. . .
importantly
. . .
software developers who produce programs on cartridge, disk and tape for use with your computer.
We encourage you to establish or join a Commodore "user club" where you can learn new techniques, exchange ideas and share discoveries.
We publish two separate magazines which contain programming tips, information on new products and ideas for computer applications.
(See Appendix N).
In North America, Commodore provides a "Commodore Information
Network" on the CompuServe Information Service
. . .
to access this network, all you need is your Commodore 64 computer and our low cost
VICMODEM telephone interface cartridge (or other compatible modem).
The following APPENDICEScontain charts, tables, and other information which help you program your Commodore 64 faster and more efficiently. They also include important information on the wide variety of Commodore products you may be interested in, and a bibliography listing of over 20 books and magazines which can help you develop your programming skills and keep you current on the latest information concerning your computer and peripherals.
106
APPENDIX A
COMMODORE 64 ACCESSORIES
AND SOFTWARE
ACCESSORIES
The Commodore
64 will
support Commodore VIC 20 storage devices
and accessories-DATASSETTE recorder, disk drive, modem, printer
so your system can expand to keep pace with changing needs.
· Datasette Recorder-This low cost tape unit enables programs and data t~ be stored on cassette tape, and played back at a later time. The data sette can also be used to play pre-written programs.
· Disk-The single disk unit uses standard SIf4-inch floppy diskettes, about the size of a 45 RPM record, to store programs and data.
Disks allow faster access to data and hold up to 170,000 characters of information each.
Disk units are "intelligent," meaning they have their own microprocessor and memory. Disks require no resources from the Commodore 64, such as using part of main memory.
· Modem-A low-cost communication device,the VICMODEM allows access to other computers over ordinary telephone lines. Users will have access to the full resources of large data bases such as The
Source, CompuServe, and Dow Jones News Retrieval Service (North
America only).
· Printer-The VIC printer produces printed copies of programs, data, or graphics.
This 30 character per second dot-matrix printer uses plain tractor feed paper and other inexpensive supplies. The
printer attaches directly to the Commodore
64
without any addi-
tional interfaces.
.
Interface Cartridges-A number of specialized cartridges will be available for the Commodore 64 to allow various standard devices such as modems, printers, controllers, and instruments to be attached to the system.
107
With a special IEEE-488 Cartridge, the Commodore 64 will support the full range of CBM peripherals including disk units and printers.
Additionally, a Z80 cartridge will allow you to run CP/M* on the
Commodore 64, giving you access to the largest base of microcomputer applications available.
SOFTWARE
Several categories of software will be offered for the Commodore 64, providing you with a wide variety of personal, entertainment, and educational applications to choose from.
BUSINESS AIDS
.
An Electronic Spreadsheet package will allow you to plan budgets, and perform "what in" analysis.
And with the optional graphic program, meaningful graphs may be created from the spreadsheet data.
.
Financial planning, such as loan amortization, will be easily handled with the Financial Planning Package.
.
A number of Professional Time Management programs will help manage appointments and work load.
.
Easy-to-use Data Base programs will allow you to keep track of
information . . . mailing lists . . . phone lists . . . inventories . . .
and organize information in a useful form.
.
Professional Word Processing programs will turn the Commodore 64 into a full-featured word processor.
Typing and revising memos, letters, and other text material become a breeze.
ENTERTAINMENT
.
The highest quality games will be available on plug-in cartridges for the Commodore 64, providing hours of enjoyment.
These programs make use of the high resolution graphics and full sound range possible with the Commodore 64.
.
Your Commodore 64 allows you all the fun and excitement available on MAX games because these two machines have completely compatible cartridges.
.CP/M is a registered trademark of Digital Research Inc.
108
EDUCATION
.
The Commodore 64 is a tutor that never tires and always gives personal attention.
Besides access to much of the vast PET educational programs, additional educational languages that will be available for the Commodore 64 include PILOT, LOGO and other key advanced packages.
109
APPENDIX B
ADVANCED
CASSETTE OPERATION
Besides saving copies of your programs on tape, the Commodore 64 can also store the values of variables and other items of data, in a group called a FilE. This allows you to store even more information than could be held in the computer's main memory at one time.
Statements used with data files are OPEN, CLOSE, PRINT#, INPUT#, and GET#.
The system variable ST (status) is used to check for tape markers.
In writing data to tape, the same concepts are used as when displaying information on the computer's screen.
But instead of PRINTing information on the screen, the information is PRINTed on tape using a variation of the PRINT command-PRINT#.
The following program illustrates how this works:
10 PRINT "WRITE-TO-TAPE-PROGRAM"
20 OPEN 1,1,1,"DATA FILE"
30 PRINT "TYPE DATA TO BE STORED OR TYPE STOP"
50 PRINT
60 INPUT "DATA",A$
70 PRINT #1, A$
S0 IF A$ <:>"STOP" THEN 50
90 PRINT
100 PRINT "CLOSING FILE"
11 0 CLOSE
1
The first thing that you must do is OPEN a file (in this case DATA FilE).
Line 10 handles that.
The program prompts for the data you want to save on tape in line
60. Line 70 writes what
you
typed-held in A$-onto the tape.
And the process continues.
If you type STOP, line 110 CLOSES the file.
110
To retrieve the information, rewind the tape, and try this:
19 PRINT "READ-TAPE-PROGRAt1"
29 OPEN 1,1,9,"DATA
39 PRINT "FILE OPEN"
49 PRINT
FILE"
59 INPUT#l, A$
69 PRINT A$
70 IF A$ = "STOP" THEN END
89 GOTO 49
Again, the file "DATA FILE"first must be OPENed. In line 50 the program INPUTs A$ from tape and also PRINTs A$ on the screen. Then the whole process is repeated until "STOP" is found, which ENDs the program.
A variation of GET-GET#-can also be used to read the data back from tape.
Replace lines 50-80 in the program above with:
59 GET#l, A$
69 IF A$ = "" THEN END
79 PRINT A$, ASC(A$)
89 GOTO
59
111
APPENDIX C
COMMODORE 64 BASIC
This manual has given you an introduction to the BASIC languageenough for you to get a feel for computer programming and some of the vocabulary involved.
This appendix gives a complete list of the rules
(SYNTAX) of Commodore 64 BASIC, along with concise descriptions.
Please experiment with these commands.
Remember, you can't do any permanent damage to the computer by just typing in programs, and the best way to learn computing is by doing.
This appendix is divided into sections according to the different types of operations in BASIC. These include:
1. Variables and Operators:
describes the different type of variables, legal variable names, and arithmetic and logical operators.
2. Commands: describes the commands used to work with programs, edit, store, and erase them.
3. Statements: describes the BASIC program statements used in numbered lines of programs.
4. Functions: describes the string, numeric, and print functions.
VARIABLES
The Commodore
64 uses three types of variables in BASIC. These are real numeric, integer numeric, and string (alphanumeric) variables.
Variable names may consist of a single letter, a letter followed by a number, or two letters.
An integer variable is specified by using the percent (%) sign after the variable name.
String variables have the dollar sign ($) after their name.
EXAMPLES
Real Variable Names: A, AS, BZ
Integer Variable Names: A%, AS%, BZ%
112
String Variable Names: A$, A5$, BZ$
Arrays are lists of variables with the same name, using extra numbers to specify the element of the array. Arrays are defined using the DIM statement, and may contain floating point, integer, or string variables.
The array variable name is followed by a set of parentheses ( ) enclosing the number of variables in the list.
A(7), BZ%(11), A$(50), PT(20,20)
NOTE: There are three variable names which are reserved for use by the Commodore 64, and may not be defined by you. These variables are: ST, TI, and TI$. ST is a status variable which relates to input/output operations.
The value of ST will change if there is a problem loading a program from disk or tape.
TI and TI$ are variables which relate to the real-time clock built into the Commodore 64. The variable TI is updated every 1/60th of a second.
It starts at 0 when the computer is turned on, and is reset only by changing the value of TI$.
TI$ is a string which is constantly updated by the system. The first two characters contain the number of hours, the 3rd and 4th characters the number of minutes, and the 5th and 6th characters are the number of seconds.
This variable can be given any numeric value, and will be updated from that point.
TI$
= "101530" sets the clock to 10:15 and 30 seconds AM.
This clock is erased when the computer is turned off, and starts at zero when the system is turned back on.
OPERATORS
The arithmetic operators include the following signs:
+ Addition
-
Subtraction
* Multiplication
/ Division i
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 operations are used together
113
on the same line, the computer assigns priorities as follows: First, exponentiation.
Next, multiplication and division, and last, addition and subtraction.
You can change the order of operations by enclosing within parentheses the calculation to be performed first. Operations enclosed in parentheses will take place before other operations.
There are also operations for equalities and inequalities:
=
Equal To
< less Than
> Greater Than
<= less Than or Equal To
>= Greater Than or Equal To
<> Not Equal To
Finally, there are three logical operators:
AND
OR
NOT
These are used most often to join multiple formulas in IF . . . THEN statements.
For example:
IF A
=
BAND C
=
D THEN 100 (Requires both parts to be true)
IF A
=
B OR C
=
D THEN 100 (Allows either part to be true)
COMMANDS
CONT (Continue)
This command is used to restart the execution of a program which has been stopped by either using the STOP key, a STOP statement, or an
END statement within the program.
The program will restart at the exact place from where it left off.
CO NT will not work if you have changed or added lines to the program (or even just moved the cursor), or if the program halted due to an error, or if you caused an error before trying to restart the program.
In these cases you will get a CAN'T CONTINUE ERROR.
114
LIST
The LIST command allows you to look at lines of a BASIC program in memory. You can ask for the entire program to be displayed, or only certain line numbers.
LIST
LIST 10-
LIST 10
LIST -10
LIST 10-20
Shows entire program
Shows only from line 10 until end
Shows only line 10
Shows lines from beginning until 10
Shows line from lQ to 20, inclusive
LOAD
This command is used to transfer a program from tape or disk into memory so the program can be used.
If you just type LOAD and hit
RETURN, the first program found on the cassette unit will be placed in
memory.
The
command may be followed by a program name enclosed
within quotes.
The name may then be followed by a comma and a number or numeric variable, which acts as a device number to indicate where the program is coming from.
If no device number is given, the Commodore 64 assumes device # 1, which is the cassette unit. The other device commonly used with the
LOAD command is the disk drive, which is device #8.
LOAD
LOAD "HELLO"
LOAD A$
LOAD " HELLO",8
LOAD "*",8
Reads in the next program on tape
Searches tape for program called
HELLO, and loads program, if found
Looks for program whose name is in the variable A$
Looks for program called HELLOon the disk drive
Looks for first program on disk
NEW
This command erases the entire program in memory, and also clears out any variables that may have been used.
Unless the program was
SAVEd, it is lost.
BE CAREFULWHEN YOU USE THIS COMMAND.
The NEW command can also be used as a BASIC program statement.
When the program reaches this line, the program is erased.
This is useful if you want to leave everything neat when the program is done.
115
RUN
This command causes execution of a program, once the program is loaded into memory. If there is no line number following RUN, the computer will start with the lowest line number.
If a line number is designated, the program will start executing from the specified line.
RUN
RUN 100
RUN X
Starts program at lowest line number
Starts execution at line 100
UNDEFINED STATEMENT
ERROR. You must always specify an actual line number, not a variable representation
SAVE
This command will store the program currently in memory on cassette or disk. If you ju;t type SAVEand RETURN,the program will be SAVEdon cassette.
The computer has no way of knowing if there is a program already on that tape, so be careful with your tapes or you may erase a valuable program.
If you type SAVEfollowed by a name in quotes or a string variable, the computer will give the program that name, so it can be more easily located and retrieved in the future. The name may also be followed by a device number.
After the device number, there can be a comma and a second number, either a or 1. If the second number is 1, the Commodore 64 will
put an END-OF-
TAPE
marker after your program.
This signals the
computer not to look any further on the tape if you were to give an additional LOAD command.
If you try to LOAD a program and the computer finds one of these markers, you will get a FILENOT FOUND ER-
ROR.
SAVE
SAVE "HELLO"
SAVE A$
SAVE "HELLO",8
SAVE "HELLO", 1, 1
Stores program to tape without name
Stores on tape with name HELLO
Stores on tape with name in A$
Stores on disk with name HELLO
Stores on tape with name
HELLO
and follows program with
END-OF-
TAPE marker
116
-.
VERIFY
This command causes the computer to check the program on disk or tape against the one in memory.
This is proof that the program is actually SAVEd, in case the tape or disk is bad, or something went wrong during the SAVE. VERIFY without anything after the command causes the
Commodore 64 to check the next program on tape, regardless of name, against the program in memory.
VERIFY followed by a program name, or a string variable, will search for that program and then check. Device numbers can also be included with the verify command.
VERIFY
VERIFY "HELLO"
VERIFY "HELLO",8
Checks the next program on tape
Searches for HELLO, checks against memory
Searches for HELLO on disk, then checks
STATEMENTS
CLOSE
This command completes and closes any files used by OPEN statements. The number following CLOSE is the file number to be closed.
CLOSE 2
Only file #2 is closed
CLR
This command will erase any variables in memory, but leaves the program itself intact.
This command is automatically executed when a
RUN command is given.
CMD
CMD sends the output which normally would go to the screen (i.e.,
PRINT statements, LISTs, but not POKEs onto 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 OPENed first.
The CMD command must be followed by a number or numeric variable referring to the file.
117
OPEN 1,4
CMD 1
LIST
OPENs device #4, which is the printer
All normal output now goes to printer
The program listing now goes to the printer, not the screen
To send output back to the screen,
CLOSE the file with
CLOSE1.
DATA
This statement is followed by a list of items to be used by
READ statements.
separated
Items may be numeric values or text strings, and items are by commas.
String items need not be inside quote marks unless they contain space, colon, or comma.
If two commas have nothing between them, the value will be READ as a zero for a number, or an empty string.
DATA 12, 14.5, "HELLO, MOM", 3.14, PARn
DEF FN
This command allows you to define a complex calculation as a function with a short name. In the case of a long formula that is used many times within the program, this can save time and space.
The
function name will be FN and any legal variable name (lor
2 characters long). First you must define the function using the statement
DEF
followed by the function name. Followingthe name is a set of pa-
rentheses enclosing a numeric variable.
Then follows the actual formula that you want to define, with the variable in the proper spot. You can then "call" the formula, substituting any number for the variable.
1
~ DEF FNA(X)
=
2~ PRINT FNA(7) t
12*(34.75 - X/.3)
J 7;. ;n.orted who.e
X is in the formula
For this example, the result would be 137.
DIM
When you use more than 11 elements of an array, you must execute a
DIM statement for the array. Keep in mind that the whole array takes up
118
..room
in memory, so don't create an array much larger than you'll need.
To figure the number of variables created with DIM, multiply the total number of elements in each dimension of the array.
10 DIM A$(40), B7(15), CC%(4,4,4) t t t
41 ELEMENTS 16 ELEMENTS 125 ELEMENTS
You can dimension more than 'one array in a DIM statement.
However, be careful not to dimension an array more than once.
END
When a program encounters an END statement, the program halts, as if it ran out of lines. You may use CO NT to restart the program.
FOR. . .TO. . .STEP
This statement works with the NEXT statement to repeat a section of the program a set number of times. The format is:
FOR (Var. Name)=(Start of Count) TO (End of Count) STEP(Count By)
The loop variable will be added to or subtracted from during the program.
Without any STEP specified, STEPis assumed to be 1. The start count and end count are the limits to the value of the loop variable.
10 FOR L
=
1 TO 10 STEP
.
1
20 PRINT L
30 NEXT L
The end of the loop value may be followed by the word STEP and another number or variable.
In this case, the value following STEP is added each time instead of 1. This allows you to count backwards, or by fractions.
GET
The GET statement allows you to get data from the keyboard, one character at a time. When GETis executed, the character that is typed is assigned to the variable.
If no character is typed, then a null (empty) character is assigned.
119
..-
GET is followed by a variable name, usually a string variable.
If a numeric variable was used and a nonnumeric key depressed, the program would halt with an error message.
The GET statement may be placed into a loop, checking for any empty result. This loop will continue until a key is hit.
1" GETA$: IF A$ ="" THEN1"
GET#
ThfW:ZEJ...# statement is used with a previously OPENed device or file, to input one character at a time from that device or file.
GET #1 ,A$
This would input one character from a data file.
GOSUB
This statement is similar to GOTO, except the computer remembers which program line it last executed before the GOSUB. When a line with a RETURN statement is encountered, the program jumps back to the statement immediately following the GOSUB. This is useful if there is a routine in your program that occurs in several parts of the program.
Instead of typing the routine over and over, execute GOSUBs each time the routine is needed.
2" GOSUB8""
GOTO OR GO TO
When astatement with the GOTO command is reached, the next line to be executed will be the one with the line number following the word
GOTO.
IF. . .THEN
IF. .
.THEN
lets the computer analyze a situation and take two possible courses of action, depending on the outcome.
If the expression is
true, the statement following
THEN
is executed. This may be any BASIC
statement.
If the expression is false, the program goes directly to the next line.
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 (=, <, >,
<=, >=, <>, AND, OR, NOT).
120
I
:::-
10 IF X
>
10 THEN END
INPUT
The INPUT statement allows the program to get data from the user, assigning that data to a variable.
The program will stop, print a question mark (?) on the screen, and wait for the user to type in the answer and hit RETURN.
INPUT is followed by a variable name, or a list of variable names, separated by commas.
A message may be placed within quote marks, before the list of variable names to be INPUT. If more than one variable is to be
INPUT, they must be separated by commas when typed.
10 INPUT "PLEASE ENTER YOUR FIRST NAME ";A$
20 PRINT "ENTER YOUR CODE NUMBER"; : INPUT B
INPUT#
INPUT# is similar to INPUT, but takes data from a previously OPENed file or device.
10 INPUT#l, A
LET
LET is hardly ever used in programs, since it is optional, but the
statement is the heart
of all BASIC programs.
The variable name which is to be assigned the result of a calculation is on the left side of the equal sign, and the formula on the right.
10LETA=5
20 LETD$ = "HELLO"
NEXT
NEXTis always used in conjunction with the FOR statement.
When the program reaches a NEXTstatement, it checks the FOR statement to see if the limit of the loop has been reached.
If the loop is not finished, the loop variable is increased by the specified STEP value.
If the loop is finished, execution proceeds with the statement following
NEXT.
121
NEXT may be followed by a variable name, or list of variable names, separated by commas.
If there are no names listed, the last loop started is the one being completed.
If variables are given, they are completed in order from left to right.
10 FOR X
=
1 TO 100: NEXT
ON
This command turns the GOTO and GOSUB commands into special versions of the IF statement.
ON is followed by a formula, which is evaluated.
If the result of the calculation is one, the first line on the list is executed; if the result is 2, the second line is executed, and so on. If the result is 0, negative, or larger than the list of numbers, the next line executed will be the statement following the ON statement.
10 INPUT X
20 ON X GOTO 10,20,30,40,50
OPEN
4
8 o
1
The OPEN statement allows the Commodore 64 to access devices such as the cassette recorder and disk for data, a printer, or even the screen.
OPEN is followed by a number (0-255), to which all following statements will refer. There is usually a second number after the first, which is the device number.
The device numbers are:
Screen
Cassette
Printer
Disk
Following the device number may be a third number, separated again by a comma, which is the secondary address.
In the case of the cassette, this is 0 for read, 1 for write, and 2 for write with end-of-tape marker.
In the case of the disk, the number refers to the buffer, or channel, number.
In the printer, the secondary address controls features like expanded printing. See the Commodore 64 Programmer's Reference Manual for more details.
122
\,
10 OPEN 1,O
20 OPEN 2,1 ,0,"D"
30 OPEN 3,4
40 OPEN 4,8,15
OPENs the SCREEN as a device
OPENs the cassette for reading, file to be searched for is D
OPENs the printer
OPENs the data channel on the disk
Also see: CLOSE, CMD, GET#, INPUT#, and PRINT#, system variable
ST, and Appendix B.
POKE
POKE is always followed by two numbers, or formulas.
The first location is a memory location; the second number is a decimal value from 0 to 255, which will be placed in the memory location, replacing any previously stored value.
10 POKE 53281,0
20 5=4096* 13
30 POKE 5+29,8
The PRINT statement is the first one most people learn to use, bUJ there are a number of variations to be aware of. PRINT can be followed by:
Text String with quotes
Variable names
Functions
Punctuation marks
Punctuation marks are used to help format the data on the screen.
The comma divides the screen into four columns, while the semicolon suppresses all spacing.
Either mark can be the last symbol on a line.
This results in the next thing PRINTed acting as if it were a continuation of the same PRINT statement.
10 PRINT
"HElLO"
20 PRINT
"HElLO"
,A$
30 PRINT A+ B
123
4~ PRINT J;
6~ PRINT
A,B,C,D
Also see: POS, SPC and TAB functions
PRINT#
There are a few differences between this statement and PRINT.
PRINT# is followed by a number, which refers to the device or data file previously OPENed. This number is followed by a comma and a list to be printed.
The comma and semicolon have the same effect as they do in
PRINT. Please note that some devices may not work with TAB and spc.
1~~ PRINT#I,"DATA VALUES"; A%, Bl, C$
READ
READ is used to assign information from DATA statements to variables, so the information may be put to use. Care must be taken to avoid READing strings where READ is expecting a number, which will give a TYPE MISMATCH ERROR.
REM
(Remark)
REMark is a note to whomever is reading a LIST of the program.
It may explain a section of the program, or give additional instructions.
REM statements in no way affect the operation of the program, except to add to its length.
REM may be followed by any text.
RESTORE
When executed in a program, the pointer to which an item in a DATA statement will be READ next is reset to the first item in the list. This gives you the ability to re-READ the information.
RESTOREstands by itself on a line.
RETURN
This statement is always used in conjunction with GOSUB. When the program encounters a RETURN, it will go to the statement immediately following the GOSUB command.
If no GOSUB was previously issued, a
RETURN WITHOUT GOSUB ERROR will occur.
124
STOP
This statement will halt program execution. The message,
BREAK
IN
xxx will be displayed, where xxx is the line number containing STOP. The program may be restarted by using the CO NT command.
STOP is normally used in debugging a program.
SYS
SYS is followed by a decimal number or numeric value in the range
0-65535. The program will then begin executing the machine language program starting at that memory location.
This is similar to the USR function, but does not allow parameter passing.
WAIT
WAITis used to halt the program until the contents of a memory location changes in a specific way. WAITis followed by a memory location
(X) and up to two variables.
The format is:
WAIT X,Y,Z
The contents of the memory location are first exciusive-ORed with the third number, if present, and then logically ANDed with the second number.
If the result is zero, the program goes back to that memory location and checks again.
When the result is nonzero, the program continues with the next statement.
NUMERIC FUNCTIONS
ABS(X) (absolute value)
ABS returns the absolute value of the number, without its sign (+ or
-). The answer is always positive.
ATN(X) (arctangent)
Returns the angle, measured in radians, whose tangent is X.
125
COS(X) (cosine)
Returns the value of the cosine of X, where X is an angle measured in radians.
EXP(X)
Returns the value of the mathematical to the power of X.
constant
e(2.71827183)
raised
FNxx(X)
Returns the value of the user-defined function xx created in a DEF
FNxx(X) statement.
INT(X)
Returns the truncated value of X, that is, with all the decimal places to the right of the decimal point removed. The result will always be less than, or equal to, X. Thus, any negative numbers with decimal places will become the integer less than their current value.
LOG(X) (logarithm)
Will return the natural log of X. The natural log to the base e (see
EXP(X». To convert to log base 10, simply divide by LOG(10).
PEEK(X)
Used to find out contents of memory location X, in the range 0-65535, giving a result from 0-255.
PEEK is often used in conjunction with the
POKE statement.
RND(X) (random number)
RND(X) returns a random number in the range 0-1. The first random number should be generated by the formula RND(-TI) to start things off differently every time.
After this, X should be a 1 or any positive number.
If X is zero, the result will be the same random number as the last one.
126
A negative value for X will reseed the generator.
The use of the same negative number for X will result in the same sequence of "random" numbers.
The formula for generating a number between X and Y is:
N = RND(l)*(Y-X)+X where,
Y is the upper limit
X is the lower range of numbers desired.
SGN(X) (sign)
This function returns the sign (positive, negative, or zero) of X. The result will be + 1 if positive, 0 if zero, and -1 if negative.
SIN (X) (sine)
SIN(X) is the trigonometric sine function. The result will be the sine of
X, where X is an angle in radians.
SQR(X) (square root)
This function will return the square root of X, where X is a positive number or O. If X is negative, an IllEGAL QUANTITYERROR results.
TAN(X) (tangent)
The result will be the tangent of X, where X is an angle in radians.
USR(X)
When this function is used, the program jumps to a machine language program whose starting point is contained in memory locations. The parameter X is passed to the machine language program, which will return another value back to the BASIC program.
Refer to the Commodore
64 Programmer's Reference Manual for more details on this function and machine language programming.
127
STRING FUNCTIONS
ASC(X$)
This function will return the ASCII code of the first character of X$.
CHR$(X)
This is the opposite of ASC, and returns a string character whose
ASCII code is X.
LEFT$(X$,X)
Returns a string containing the leftmost X characters of $X.
LEN(X$)
Returned will be the number of characters (including spaces and other symbols) in the string X$.
MID$(X$,S,X)
This will return a string containing X characters starting from the Sth character in X$.
RIGHT$(X$,X)
Returns the rightmost X characters in X$.
STR$(X)
This will return a string which is identical to the PRINTed version of X.
VAL(X$)
This function converts 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.
128
10 X
=
VAL("123.456")
10 X = VAL("12A13B")
10 X = VAL("RIUfij17")
10 X = VAL("-1.23.45.67")
X = 123.456
X = 12
X = fij
X = -1.23
OTHER FUNCTIONS
FRE{X)
This function returns the number of unused bytes available in memory,
regardless of the value of X. Note that FRE(X)
will
read out n negative
numbers if the number of unused bytes is over 32K.
POS{X)
This function returns the number of the column (0-39) at which the next PRINT statement will begin on the screen.
X may have any value and is not used.
SPC{X)
This is used in a
PRINT statement to skip X spaces forward.
TAB{X)
TABis also used in a PRINT statement; the next item to be PRINTed will be in column
X.
129
APPENDIX D
ABBREVIATIONS FOR
BASIC KEYWORDS
As a time-saver when typing in programs and commands, Commodore 64 BASIC allows the user to abbreviate most keywords.
The abbreviation for PRINT is a question mark. The abbreviations for other words are made by typing the first one or two letters of the word, followed by the SHIFTed next letter of the word. If the abbreviations are used in a program line, the keyword will LISTin the full form.
Command
Abbreviation
Loolcslik.
this on screen
Command
Abbreviation
Loolcslik.
this on screen
ABS
CLR
A_B
AND
ASC
A_N
A BIIiI S
A0
A
ATN
A_T
A[J
CHR$
CIIIIIIH c[]
CLOSE ClI1lDDO
CLD
C 11IIII L
Am cD
CMD
C
BIIiI
M cIS]
CONT
COS
C I1IDD 0
NONE cD
COS
DATA
DEF
DIM
END
EXP
FN
E
BIIiI
N
E0
ElmiIx
E
NONE FN
FOR
F
BIIiI
0
FRE
FBllDR
GET
GBIIDE
GET#
NONE
FO
F
GEj
GET#
GOSUB
GO
BID
S
GO
GOTO
G BIIiI 0
IF
NONE
GO
IF
D
BIIiI
A
D[!]
DEmlE
D_I
INPUT
NONE
INPUT
DE!
INPUT#
I_N
I 0
DfJ
INT
NONE
INT
,
130
Command
LEFT$
LEN
Abbreviation
LE
IDIIII
F
NONE
LET
L18E
LIST
LEDIIiII
LOAD
LIDIIII 0
LOG
NONE
MID$
MBIIDI
NEW NONE
NEXT
NOT
ON
NIDIIIIE
N
Emil
0
NONE
OPEN
OR
o IIIIiI P
NONE
PEEK
POKE
POS
PRINT ?
P IIIIiI E
P BIIiI 0
NONE
PRINT#
READ
PImDR
RImDE
REM NONE
RETURNREEDIiIT
Looks this on screen
like
Command
Abbreviation
LEbJ
LEN
LO
L
LO
LOG
MEJ
NEW
RIGHT$
RND
R
IIIIiI
I
R
BIIiI
N
RUN
RBllDu
SAVE
S Emil A
SGN
SIN
S IIIIiI G
SBIIDI
SPC{
slIDiIp
SQR
S BID Q
STATUS
ST
NEj
NO
ON
00
OR
STEP
ST" E
STOP
S"T
STR$
STIIIIiI R
SYS
S IIIIiI Y
?
PEl
TAB(
T BID A
TAN
pO
NONE
POS
THEN
TIDIIII H
ITIME
TI
PbJ
REI
REM
RE
RE[]
TIME$ TI$
USR ulmDs
VAL
VIIIIiIA
VERIFY
VBIIiIE
WAIT
WBIIiIA
T[]
TI
TI$
U vI!!
vEJ wI!!
Looks like this on screen
R
RIZI
RGj
S
SID sl;] sO
S.
ST
STE] sID
STQ s[]]
T
TAN
131
APPENDIX E
SCREEN DISPLAY CODES
The following chart lists all of the characters built into the Commodore
64 character sets. It shows which numbers should be POKEd into screen memory (locations 1024-2023) to get a desired character.
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 taneously.
Emil and
[I keys simul-
From BASIC, POKE 53272,21 will switch to upper case mode and
POKE 53272,23 switches to lower case.
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.
If you want to display a solid circle at location 1504, POKE the code for the circle (81) into location 1504: POKE 1504,81.
There is a corresponding memory location to control the color of each character displayed on the screen (locations 55296-56295).
To change the color of the circle to yellow (color code 7) you would POKE the corresponding memory location (55776) with the character color: POKE
55776,7.
Refer to Appendix G for the complete screen and color memory maps, along with color codes.
SCREEN CODES
SET1 SET2 POKE SET1
SET2 POKE SET1
SET2 POKE
@
A
B a b
0
1
2
C
D
E c d e
3
4
5
F
G
H f
9 h
6
7
8
132
SET1 SET2
POKE SET1 SET2 POKE SET1 SET2 POKE
9
%
37
I i
J j
10 &
38
[JJ
K
L
M
N
0
P k
0
I m n
P
11
12
13
14
15
16
,
(
)
*
+
39
40
41
42
43
44
Q
$ q
17
-
I
45
#
18
34
I
46
EJ
I 73
J 74
R r
S
T s t
19
20
/
0
47
48
21
1
49
EJ
K 75
0
L 76
M 77
[SJ
U u
22
2
50
0
V v
W w 23
3
51
0
24
4
52
0
X x
Y
25
5
53
II Q 81
Y
Z z
26
6
54 bJ
R 82 t
[
£
]
+-
27
28
29
30
31
7
8
9
,
55
56
57
58
59
D
[lj
-
32
< 60
X 88
S
T
U
V
83
84
85
86
C W 87
33
=
>
61
62
[]]
Y 89
[J]
Z
90
P 80
0
79
N
78
63
?
EE
IJ
91
B
64
92
36
I
B
C 67
D
68
EJ
Ej
E 69 bJ
F 70
D
G
71
72
OJ
H
B 66
A
65
133
0
II
0
0
0
-
SET 1 SETZ POKE SET 1 SET Z POKE SET 1 SETZ POKE rn
ITB
IJ
93
IB
105
[] 117
.
94
[]
106 []
118
95
107
LI
119 rn
96
97
98
[g
6J
108
109
110
120
121
0 0
122
99
CJ
111 123
100 ca
112 124
101 113
125
102 114 126
EI3
103
HJ
115 127
116
104
IJ
Codes from 128-255are reversed Images of codes 0-127.
134
APPENDIX F
ASCII AND CHR$ 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 ASq"x"), where x is 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 CHR$
PRINTS
CHR$
PRINTS CHR$ PRINTS
CHR$
0
1
.
2
3
4
5
6
.
.
..
34 3
II
..
17
18
# 35 4 52
51
19
20
21
$
%
&
36
37
38
5
6
7
53
54
55
22
23
(
39
40
8
9
56
57
7
DISABlES..Cl8
"14
..
13
11
12
15
10
16
24 41
:
)
,
III
.
.
II
29
*
46
.
25
26
27
+
,
42
43
44
C
=
-
28
-
45
:>
62
60
61
?
59
63
30
31
/
0
1
47
48
49
@
A
B
64
65
66 i
C 67
32
I
2 50
58
135
Q
R
S
T
U
V
W
X
Y
Z
r
[
]
£
E3
P
0
N
M
K
L
J
I
E
F
G
H
PRINTS CHR$ PRINTS
CHR$ PRINTS CHR$
PRINTS
CHR$
D 68
97 ffD
126
.
156
69
70
71
72
CD
E3
98
99
D
100
Ej
101
C!II
127
128
129
.
B3
-
II
157
158
155
159 lID
160
73
74 g
102
0
103
130
131
132
IJ
161
..
162
75
76
OJ
104 f1 133
EJ
105 f3 134
D
163
77
106 f5 135 0 164
78
107 f7
136
0
108 f2 137
D
165
79
11III
166
95
93
80
[SJ
109 f4 138
D
167
81
110 f6 139 0
82
111 f8
140
0
91
83
84
85
86
87
D
0
112
__141
[] 170
.
113
1llliJ142 rn
171
D
116
88
Cd
89
90
114
115
117
118
C
119
.
143
144
[Ij
172
[g
173
III
145
ElJ
174
..
146
175
II
147 ca
176
II
148
177
149
Cd
53
178
120
92
OJ 121
150
8J
179
169
168
[I]
122
C
151
[]
180
94
B3 123 152
[]
181
IJ
124
OJ
153
[]
182
96 rn
125
[I]
154
U
183
136
PRINTS
CHRS PRINTS
CHR$
PRINTS CHRS
PRINTS CHRS
184
185
D 186
187 f!]
188
189
190
191
CODES
CODES
CODE
192-223
224-254
255
SAME AS
SAME AS
SAME AS
96-127
160-190
126
137
APPENDIX
G
SCREEN AND COLOR MEMORY MAPS
1624
1664
1704
1744
1784
1824
1864
1904
1944
1984
1024-
1064
1104
1144
1184
1224
1264
1304
1344
1384
1424
1464
1504
1544
1584
The following charts list which memory locations control placing characters on the screen, and the locations used to change individual character colors, as well as showing character color codes.
SCREENMEMORYMAP
10
COLUMN
20 30
'"
10 ~
20
24
138
The actual values to POKE into a color memory location to change a character's color are: f/!
1
BLACK
WHITE
2 RED
3
CYAN
4 PURPLE
5 GREEN
6 BLUE
7
YellOW
8
9
ORANGE
BROWN
If/!
Light RED
11 GRAY 1
12 GRAY 2
13
Light GREEN
14
Light BLUE
15
GRAY 3
55856
55896
55936
55976
56016
56056
56096
56136
56176
56216
56256
55296-
55336
55376
55416
55456
55496
55536
55576
55616
55656
55696
55736
55776
55816
For example, to change the color of a character located at the upper left-hand corner of the screen to red, type: POKE 55296,2.
COLOR MEMORY MAP
10
COLUMN
20
30 39
55335
~
10
20 t
56295
24
~
139
APPENDIX H
DERIVING MATHEMATICAL FUNCTIONS
Functions that are not intrinsic to Commodore 64 BASIC 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 HYPERBOLIC COSECANT
INVERSE HYPERBOLIC COTAN-
GENT
BASIC EQUIVALENT
SEC(X)= I/COS(X)
CSC(X)= I/SIN(X)
COT(X)= I/TAN(X)
ARCSIN(X)=ATN(X/SQR(- X.X + 1»
ARCCOS(X)= -ATN(X/SQR
(-X.X
+1»
+7T/2
ARCSEC(X)=ATN(X/SQR(X.X
- 1»
ARCCSC(X)=ATN(X/SQR(X.X -1»
+(SGN(X)-I.7T/2
ARCOT(X)=ATN(X)+7T/2
SINH(X)= (EXP(X)- EXP(- X»/2
COSH(X)= (EXP(X)+ EXP(
TAN H(X)= EXP(
-
X»/2
-
X)/(EXP(x)+ EXP
(- X».2+ 1
SECH(X)= 2/(EXP(X)+ EXP(
-
X»
CSCH(X)= 2/(EXP(X)- EXP(- X»
COTH(X)= EXP(
-
X)/(EXP(X)
-EXP(-X».2+1
ARCSINH(X)= LOG(X+ SQR(X. x + 1»
ARCCOSH(X)= LOG(X+SQR(X.X -1»
ARCTANH(X)= LOG« 1+ X)/(1- X»/2
ARCSECH(X)= LOG«SQR
(-X.X+ 1)+ I/X)
ARCCSCH(X)= LOG«SGN(X). SQR
(X.X+l/x)
ARCCOTH(X)= lOG«X + 1)/(x-l »/2
'140
APPENDIX I
PINOUTS FOR INPUT/OUTPUT DEVICES
This appendix is designed to show you what connections may be made to the Commodore 64.
1) Game I/O
2) Cartridge Slot
3) Audio/Video
4) Serial I/O (Disk/Printer)
5) Modulator Output
6) Cassette
7) User Port
Control Port 1
Pin
1
Type
JOYAO
7
8
5
6
9
2
3
4
JOYAl
JOYA2
JOYA3
POT AY
BUTTON A'LP
+5V
GND
POT AX
Note
MAX. 50mA
1 o o
6
2 o o
7
3 o
4 o o
8 o
9
5 o
Control Port 2
Pin
1
Type
JOYBO
2
3
JOYBI
JOYB2
4
5
6
7
JOYB3
POT BY
BUTTON B
+SV
8
9
GND
POT BX
Note
MAX. SOmA
141
Cartridge Expansion Slot
Pin
18
19
20
21
22
15
16
17
12
13
14
TVDe
BA i5MA
D7
D6
DS
D4
D3
D2
D1
DO
GND
Pin
S
T
U
V
N
P
R
W
X
Y
Z
Type
A9
A8
A7
A6
AS
A4
A3
A2
Al
AO
GND
22 2120 1918171615 U 13 12 1110 9 8 7 8 5 4 3 2 1
IV XWVUTSRPNMLKJHFEOCBA
Audio/Video
IT
SerialI/O
Type
LUMINANCE
GND
AUDIO OUT
VIDEO OUT
AUDIO IN
Pin
1
2
3
4
5
6
SERIALSRQIN
GND
SERIALATN IN/OUT
SERIALCLK IN/OUT
Type
SERIAL DATA IN/OUT
RESET
Note
142
Pin
D
E
F
H
A
B
C
J
K
L
M
Pin
3
4
S
1
2
8
9
10
6
7
11
. Type
GND
ROMH
REsEr
NMI
S 02
A1S
A14
A13
A12
All
Al0
Type
GND
+SV
+SV
IRQ
R/w
Dot Clock
I/O 1
GAME
EXROM
I/O 2
ROML
Cassette
Pin
A-I
B-2
C-3
D-4
E-S
F-6
GND
+SV
CASSETTEMOTOR
CASSETTE READ
CASSETTE WRITE
CASSETTESENSE
Type
User I/O
Type
GND
+SV
RESET
CNTI
SPI
CNT2
SP2
PC2
SER. ATN IN
9 VAC
9 VAC
GND
PB4
PBS
PB6
PB7
PA2
GND
GND
FLAG2
PBO
PBI
PB2
PB3
Type
Pin
I
2
3
4
S
6
7
8
9
10
11
12
Pin
A
B
C
D
E
F
H l
M
N
J
K
Note
MAX. lOa mA
MAX. lOa mA
MAX. lOa mA
1 2 3 4 5 6 7 8 9 10 11 12
Note
ABC D E F H J K L M N
143
123458
..---.
ABC D E F
APPENDIX
J
PROGRAMS TO TRY
We've included a number of useful programs for you to try with your
Commodore 64. These programs will prove both entertaining and useful.
-~.
-,
144
580
590
600
610
620
630
640
650
660
670
680
690
700
710
720
730
740
750
800
810
820
200
210
220
250
260
270
280
290
300
310
320
330
340
400
410
420
100
120
130
140
150
160
170
180
190
430
440
450
500
510
520
530
540
550
560
570 print"~jotto Jim butterfi~ld" input"~want instructions"i;$:ifasc(;.)=78got0250 pr nt"~try to gu~ss the mystery 5-1etter word" pr nt"~you must gu~ss only legal 5-1etter" pr nt"words, too..." pr nt"you will b~ told th~ number of matches" pr nt"(or 'jots') of your guess." pr nt"~hint: the trick is to vary slightly" pr nt" from one guess to. the next, so that" pr nt" If you guess 'batch' and get 2 jots" pr nt" you might try 'botch' or 'chart'" pr nt" for the next guess..." data bxbsf,ipcc;,dbdif,esfbe,pggbm data hpshf,ibudi,djwjm,kpmm;,lb;bl data sbkbi,mfwfm,njnjd,boofy,qjqfs data rvftu,sjwfs,qsftt,puufs,fwfou data xfbwf,fyupm,nvti;,afcsb,gjaa; data uijdl,esvol,gmppe,ujhfs,gblfs data cppui,mzjoh,trvbu,hbvaf,pxjoh data uisff,tjhiu,bymft,hsvnq,bsfob data rvbsu,dsffq,cfmdi,qsftt,tqbsl data sbebs,svsbm,tnfmm,gspxO,~Sjgu n=50 dim n$(n),z(5),y(S) for j=1ton:readn$(j):nextj t=ti t=t/1000:ift>=1thengot0440
;=rnd(-t) g=0:n$=n$(rnd(1)*n+1) print "~i have a five letter word:":ifr>Ogot0560 print "guess (with legal words)" print "and i'll tell you how many" print "'jots', or matching letters," print "you hav~ " g=g+1:input "your word",z' if len(;$)<>5thenprint"you must guess a
S-l~tt~r word!":gotoS60 v=O:h=O:m=O forj=1t05 z=asc(mid$(z',j,1»:y=asc(mid$(n$,j,1»-1:lfy=64theny=90 if;(650rz>90thenprint"that's not a word!":got0560 ifz=650rz=690rz=730rz=790rz=850rz=89thenv=v+1 ifz=ythenm=m+1 z(j)=z:y(j)=y:nextJ ifm=5got0800 ifv=00rv=5thenprint"come on..what
kind of a word is that?":got0560 for j=1t05:y=y(j) for k=lt05:ify=z(k)thenh=h+l:z(k)=0:got0700 next k next j print"DDDDDDDDDDDDDDDDDDDD",H,"JOTS" ifg(30got0560 print"i'd.better
tell you.. word was '", forj=1t05:~rintchr$(y(j»i:nextj print"'":got0810 print"you got it in onlY"ig,"guesses." input"~another word",z$ r=1:ifasc(;$)(>78gotoSOO
145
1 rem *** seQuence
2 relR
3 rem ***
I, rem *** from pet user group software exchange
5 reM ***
po box 371
6 rem *** montgomeryville, pa 18936
7 rem
50 dllR a$(26)
100 z$="abcdefghijklmnopqrstuvwxyz"
110 21$="12345678901234567890123456"
200 print"'~~enter length of string to be sequenced~"
220 Input "maximum length is 26 "~s%
230 if s%(1 or s%)26 then 200
240 s=s%
300 for i=1 to s
310 a$(i)=mid$(z$,i,l)
320 next i
400 rem randomize
420 for 1=1 to s
430 k=int(rnd(I)*s+l) string
440 t$=a$ ( I )
450 a$(
i )=a$(k)
460 a$(k )=U
470 next i
480 Qosub
595 t=O
950
600 rem reverse substring
605 t=t+l
610 input "how many to reverse ";r%
620 if r%=O goto 900
630 if r%)O and r%(=s goto 650
640 print "must be between 1 and "IS: go to 610
650 r=int(r%/2)
660 for i=1 to r
670 U=a$( i)
680 a$(i)=a$(r%-i+l)
690 a$(r%-i+l)=t$
700 next i
750 gosub 950
800 c=l: for i=2 to s
810 if a$(i»a$(i-l)
820 c=O
830 ne>:t i
840 if c=O go to 600 goto 830
850 print "~you did it in "it;" tries"
900 rem check for another game
910 input "~want to play again ";y$
920 if
930 end left$(y$,I)="y" or y$="ok" or y$="I" goto 200
950 print
960 print left$(zl$,s)
970 for 1=1 to s: print a$(i)~:next
980 print "~"
990 return
This program courtesy of Gene Deals
146
1:~0
19')
2(10
211)
22(1
23"~1
241)
.250
9(1
REM F'l At.m KE'T'E:OAF;D
10C'
110
12')
PRINT"~ ~ g ~ I U ~ ~ I ~ n I ~ ~ "
PRINT" ~ M ~ I ~ ~ ~ i ~ M I ~ ~
PR HIT" ..1~ I!J I ~J i!JI it~ I
" i!JI
I!J I I!II
I!J
1 :-::"~1
PFUNT" ~ I I I I I I I I I I I I "
141)
15')
16')
PRINT" ;:11) IR IT I','IU 1110
PRUIT":!j'-SPACE'- FOR SOLO
IP II] I;+; I.t"
OR POL','PHO~UC"
PRINT":!j'F1 ,F~'3._F5..F7'SELECTIClt~"
1(1)
PR I ~IT" :!j'F 4._
F6._
F8'1..IA' EFClRt.1~..
/
PRHIT"HAt'IG ()N._SETTIt~G UP FREClUEI..jC',' _ _"
S_13*41)96+1024:DIMF(26):OIMKC255)
FOR I ",\)TCI2:~ : POKE:;+ I. <) : t.jE;".:T
Fl_7040:FORI_1T026:F(27-I)_F1;+;5.8+30:F1_F1/2~C1/12):NEXT
K$="1)2W3ER5T6Y7UI900P@-*£~"
FC'PI~l TOU::N(K$> : I.::(F'f;:;C( rHO:t(Kt._
I» )-1 :NE:,:T
PRItH":J
AT =1) : DE") : SU= 15 : PE-9 : :;:; '''':;1)* 16+RE : AV=AT;+;16+0E :
~N= 16 : 1.,=0 : 1'1=1 : OC=4 : H8=256 : Z=':'
.
261.)
FIJR I ",')T'J2 : PCtKES+5+ I *7.. AT;+;16+0E : PCIKES+6+ I;+;7._ SU;+;16...RE
2713
POKES+2+ 1;+;7._40CII)At.10255
: POI(ES+3+ 1;+;7,4000/256: t.jE:.<:T
POKES+24,15:REM+16+64:POKES+23.7
3~30
31e
GETA$: IFA$=" "THEt.1301)
FR.F(K(ASI:::CA,'P) ),..t'1 :T-'./;+;7 :CR-S+T+4: IFFR-ZTHEH50')
321)
:325
33&.)
341)
350
361.)
:365
3713
375
3813
POI<:ES+6+T,Z :REI'1 FItHSH
POKES+5+ T ._2 :REt'1 FItH:;H
POKECR,8:POKECR,O:REM
DEC.":3US
ATT REL
FIX ClFF
POKES+T..FR-H8;+;HITCFR/HB)
PClKES+l+T..FP,'HB:REt'1
:REI1
:;ET HI
$ET LO
POKES+6+T,SV:REM
POKES+5+ T._
SET OEC/SUS
REI'1 :;ET ATT /REL
PPKECR,WV+l:FORI_1T(51)*AT:NEXT
POKECR,WY:REM PUL$E
IFP-1THENV=V+1:IFY=3THENY=1)
4 ell)
t3IJTIJ3a.)I.)
501.)
I FA$=" iiii"THEt'U'1=1 : OC=4 : GOT03CII)
51')
IFA$'-"!!!"THEHI'1=2 :IJC-~: : GOTO:3CII)
IFA$="I!I"THEt~~1=4 :OC-2 :130TO:::o)C,
53')
540
IFA$="ill"THEt.H'1=::;.
:OC=l :GOT03')')
IFA$="9"THEt~I.J-C' :.1' =16 : GOT'J:::O')
'550
560
I FA$_" JG"THEHI.I- 1 : 1.1'.,1=32: GOTO:3')O
IFA$=":i!"THEt.n.I=2 :W =64 : GOT03.:II)
570
581)
IFA$=" "THEHP=1-P:GOT0309
59(1
61.3(1
:3(.1)
:::1(1
I FA$ -":J" THE~j2'30
O(ITCI3(1(\
PRHIT"HIT A KE','"
1 C,:I.IA
FOR A I.:E','
:32a.~ PRHJTA$ :RETUF:N
NOTES:
Line 100 uses (SHIFT CLR/HOME).
(CTRL 9),(CTRL ]),(SHIFT B).
Line 150 uses (CRSR DOWN)
Line 240 uses (CRSR UP)
Line 500 uses (11)
Line 510 uses (13)
Line 520 uses (15)
Line 530 uses (17)
Line 540 uses (12)
Line 550 uses (14)
Line 560 uses (16)
Line 570 uses (18)
Line 590 uses (SHIFT CLR/HOME)
147
APPENDIX K
CONVERTING STANDARD
BASIC PROGRAMS TO
COMMODORE 64 BASIC
If. you have programs written in a BASIC other than Commodore
BASIC, some minor adjustments may be necessary before running them on the Commodore-64.
We've included some hints to make the conversion easier.
String Dimensions
Delete all statements that are used to declare the length of strings. A statement such as DIM A$(I,J), which dimensions a string array for J elements of length I, should be converted to the Commodore BASIC statement DIM A$(J).
Some BASICs use a comma or ampersand for string concatenation.
Each of these must be changed to a plus sign, which is the Commodore
BASIC operator for string concatenation.
In Commodore-64 BASIC, the MID$, RIGHT$, and LEFT$functions are used to take substrings of strings. Forms such as A$(I) to access the Ith character in A$, or A$(I,J) to take a substring of A$ from position I to J, must be changed as follows:
Other BASIC
A$(I)
=
X$
A$(I,J) = X$
Commodore 64 BASIC
A$
= LEFT$(A$,I-1)+X$+MID$(A$,I+1)
A$ = LEFT$(A$,I-1)+ X$+MID$(A$,J+ 1)
Multiple Assignments
To set Band C equal to zero, some BASICs allow statements of the form:
19) LET B=C=9)
148
Commodore
64 BASIC would interpret the second equal sign as a logical operator and set B
=
-1 if C
=
O. Instead, convert this statement to:
1!11C=0 : B=!II
Multiple Statements
Some BASICs use a backslash (\ ) to separate multiple statements on
a line. With Commodore
64 BASIC, separate all statements by a colon
(:).
MAT Functions
Programs using the MATfunctions available on some
BASICs
must be
rewritten using FOR. . .NEXT loops to execute properly.
149
APPENDIX
L
ERROR MESSAGES
This appendix contains a complete list of the error messages generated by the Commodore-64, with a description of causes.
BAD DATA
String data was received from an open file, but the program was expecting numeric data.
BAD SUBSCRIPT
The program was trying to reference an element of an array whose number is outside of the range specified in the DIM statement.
CAN'T CONTINUE
The CO NT command will not work, either because the program was never RUN, there has been an error, or a line has been edited.
.
DEVICE NOT PRESENT
The required I/O device was not available for an OPEN, CLOSE, CMD, PRINT#, INPUT#, or GET#.
DIVISION BY ZERO
Division by zero is a mathematical oddity and not allowed.
EXTRA IGNORED
Too many items of data were typed in response to an INPUT statement.
Only the first few items were accepted.
FILENOT FOUND
If you were looking for a file on tape, and END-OF-
TAPE marker was found.
If you were looking on disk, no file with that name exists.
FILENOT OPEN The file specified in a CLOSE, CMD, PRINT#, INPUT#, or GET#, must first be OPENed.
FILEOPEN
An attempt was made to open a file using the number of an already open file.
FORMULA TOO COMPLEX
The string expression being evaluated should be split into at least two parts for the system to work with, or a formula has too many parentheses.
ILLEGALDIRECT The INPUT statement can only be used within a program, and not in) direct mode.
ILLEGALQUANTITY
A number used as the argument of a function or statement is out of the allowable range.
150
lOAD
There is a problem with the program on tape.
NEXT WITHOUTFOR This is caused by either incorrectly nesting loops or having a variable name in a NEXTstatement that doesn't correspond with one in a FOR statement.
NOT INPUT FilE
An attempt was made to INPUT or GET data from a file which was specified to be for output only.
NOT OUTPUTFILE An attempt was made to PRINT data to a file which was specified as input only.
OUT OF DATA A READ statement was executed but there is no data left unREAD in a DATAstatement.
OUT OF MEMORY There is no more RAM available for program or variables.
This may also occur when too many FOR loops have been nested, or when there are too many GOSUBs in effect.
OVERFLOW The result of a computation is larger than the largest number allowed, which is 1.70141884E+38.
REDIM'DARRAY An array may only be DIMensioned once. If an array variable is used before that array is DIM'd, an automatic DIM operation is performed on that array setting the number of elements to ten, and any subsequent DIMs will cause this error.
REDO FROM
START Character data was typed in during an INPUT statement when numeric data was expected.
Just re-type the entry so that it is correct, and the program will continue by itself.
RETURN WITHOUT GOSUB
A RETURN statement was encountered, and no GOSUB command has been issued.
STRING TOO lONG
A string can contain up to 255 characters.
?SYNTAX ERROR A statement is unrecognizable by the Commodore
64. A missing or extra parenthesis, misspelled keywords, etc.
TYPEMISMATCH This error occurs when a number is used in place of a string, or vice-versa.
UNDEF'D FUNCTION
A user defiried function was referenced, but it has never been defined using the DEF FN statement.
UNDEF'D STATEMENT
An attempt was made to GOTO or GOSUB or
RUN a line number that doesn't exist.
VERIFY
The program on tape or disk does not match the program currently in memory.
151
APPENDIX M
MUSIC NOTE VALUES
This appendix contains a complete list of Note#, actual note, and the values to be POKEd into the HI FREQ and LOW FREQ registers of the sound chip to produce the indicated note.
MUSICAL
NOTE
OCTAVE
C-O
A-O
A#-O
B-O
C-1
C#-l
D-1
D#-l
E-1
F-1
F#-l
G-1
G#-l
A-1
A#-l
B-1
C-2
C#-O
D-O
D#-O
E-O
F-O
F#-O
G-O
G#-O
NOTE
22
23
24
17
18
19
20
21
10
11
16
8
9
2
3
4
5
0
1
6
7
25
26
27
32
DECIMAL
268
284
I
301
318
337
358
379
401
425
451
477
506
536
568
602
637
675
716
758
803
851
902
955
1012
1072
152
OSCILLATOR FREQ
HI LOW
125
163
204
246
35
24
56
90
83
134
187
244
48
102
123
145
169
195
221
250
12
28
45
62
81
1
1
1
1
1
1
1
1
2
1
1
1
1
3
3
3
2
3
3
4
2
2
2
2
2
MUSICAL NOTE
NOTE OCTAVE
A-2
A#-2
B-2
C-3
C#-3
D-3
D#-3
E-3
F-3
F#-3
G-3
G#-3
A-3
A#-3
B-3
C#-2
D-2
D#-2
E-2
F-2
F#-2
G-2
G#-2
C-4
C#-4
D-4
D#-4
E-4
F-4
F#-4
G-4
G#-4
A-4
A#-4
B-4
C-5
C#-5
40
41
42
43
36
37
38
39
48
49
50
51
52
59
64
65
66
67
53
54
55
56
57
58
33
34
35
68
69
70
71
72
73
74
75
80
81
DECIMAL
OSCILLATORFREQ
HI
13
14
14
15
16
9
9
10
11
11
12
8
8
21
22
23
17
18
19
25
26
5
6
5
5
6
7
7
7
28
29
31
33
35
4
4
4
1804
1911
2025
2145
2273
2408
2551
2703
2864
3034
3215
3406
3608
3823
4050
4291
4547
4817
5103
5407
5728
6069
6430
6812
1136
1204
1275
1351
1432
1517
1607
1703
7217
7647
8101
8583
9094
LOW
167
12
119
233
97
225
104
247
143
48
218
143
78
24
239
210
195
112
180
251
71
152
237
71
195
209
239
31
96
181
30
156
49
223
165
135
134
153
MUSICAL
NOTE
OCTAVE
NOTE
98
99
100
101
102
103
104
90
91
96
97
82
83
84
85
86
87
88
89
105
106
107
112
113
114
115
116
117
118
119
120
121
122
123
C-O
C#-O
D-O
F-5
F#-5
G-5
G#-5
A-5
A#-5
6-5
C-6
C#-6
D-6
D#-6
E-6
F-6
F#-6
G-6
G#-6
A-6
A#-6
6-6
C-7
C#-7
D-7
D#-7
E-7
F-7
F#-7
G-7
G#-7
A-7
A#-7
6-7
OSCILLATOR FREQ
HI
100
106
112
119
126
134
142
150
159
168
179
189
200
212
225
238
253
67
71
75
79
84
89
94
50
53
56
59
63
37
39
42
44
47
DECIMAL
30588
32407
34334
36376
38539
40830
43258
45830
48556
51443
54502
57743
61176
64814
9634
10207
10814
11457
12139
12860
13625
14435
15294
16203
17167
18188
19269
20415
21629
22915
24278
25721
27251
28871
LOW
121
115
199
124
151
30
24
12
69
191
125
131
214
139
126
250
6
172
243
230
143
248
162
223
62
193
107
60
57
99
190
75
15
46
154
Location
54293
54294
54295
54296
FILTER SETTINGS
Contents
Low cutoff frequency (0-7)
High cutoff frequency (0-255)
Resonance (bits 4-7)
Filter voice 3 (bit 2)
Filter voice 2 (bit 1)
Filter voice 1 (bit 0)
High pass (bit 6)
Bandpass (bit 5)
Low pass (bit 4)
Volume (bits 0- 3 )
155
APPENDIX
N
BIBLIOGRAPHY
Addison-Wesley
Compute
Cowboy Computing
Creative Computing
Dilithium Press
Faulk Baker Associates
Hayden Book Co.
"BASIC and the Personal Computer", Dwyer and Critchfield
"Compute's First Book of PET/CBM"
"Feed Me, I'm Your PET Computer", Carol Alexander
"looking Good with Your PET", Carol Alexander
"Teacher's swers"
PET-Plans, Quizzes, and An-
"Getting Acquainted With Your VIC 20",
T. Hartnell
"BASIC Basic-English Dictionary for the PET", lorry Noonan
"PET BASIC", Tom Rugg and Phil Feldman
"MOS Programming Manual", MOS Technology
"BASIC From the Ground Up", David E. Simon
"I Speak BASIC to My PET", Aubrey Jones, Jr.
"Library of PETSubroutines", Nick Hampshire
"PET Graphics", Nick Hampshire
"BASIC Conversions Handbook, Apple, TRS-
80, and PET", David A. Brain, Phillip R.
Oviatt, Paul J. Paquin, and Chandler P. Stone
156
Howard W. Sams
,Little, Brown & Co.
McGraw-Hili
Osborne/ McGraw-Hili
P. C. Publications
"The Howard W. Sams Crash Course in Microcomputers", louis E. Frenzel, Jr.
"Mostly BASIC: Applications for Your PET",
Howard Berenbon
"PET Interfacing", James M. Downey and Steven M. Rogers
"VIC 20 Programmer's Reference Guide", A.
Finkel, P. Higginbottom, N. Harris, and M.
Tomczyk
"Computer Games for Businesses, Schools, and Homes", J. Victor Nagigian, and William
S. Hodges
"The Computer Tutor: learning Activities for
Homes and Schools", Gary W. Orwig, University of Central Florida, and William S. Hodges
"Hands-On BASIC With a PET", Herbert D.
Peckman
"Home and Office Use of VisiCalc", D.
Castlewitz, and L. Chisauki
"PET/CBM Personal Computer Guide", Carroll
S. Donahue
"PET Fun and Games", R. Jeffries and G.
Fisher
"PET and the IEEE", A. Osborne and C.
Donahue
"Some Common BASIC Programs for the PET",
L. Poole, M. Borchers, and C. Donahue
"Osborne CP/M User Guide", Thom Hogan
"CBM Professional Computer Guide"
"The PET Personal Guide"
"The 8086 Book", Russell Rector and George
Alexy
"Beginning Self-Teaching Computer lessons"
157
Prentice-Hall
Reston Publishing Co.
"The PET Personal Computer for Beginners",
S. Dunn and V. Morgan
"PET and the IEEE488 Bus (GPIB}", Eugene
Fisher and C. W. Jensen
"PET BASIC-Training Your PET Computer",
Ramon Zamora, Wm.
F. Carrie, and B.
Allbrecht
"PET Games and Recreation", M. Ogelsby, L.
Lindsey, and D. Kunkin
"PET BASIC", Richard Huskell
"VIC Games and Recreation"
Telmas Courseware
Ratings
Total Information Services
"BASIC and the Personal Computer", T. A.
Dwyer, and M. Critchfield
"Understanding Your PET/CBM, Vol. 1, BASIC
Programming"
"Understanding Your VIC", David Schultz
Commodore Magazines provide you with the most up-to-date information for your Commodore 64. Two of the most popular publications that you should seriously consider subscribing to are:
COMMODORE-The Microcomputer
Magazine
is published bi-monthly and is available by subscription ($15.00 per year, U.S., and $25.00 per year, worldwide).
-The
Home Computer Magazine is published quarterly
and is available by subscription ($10.00 per year, U.S., and $15.00 per year worldwide).
158
APPENDIX 0
SPRITE REGISTER MAP
Register #
Dee Hex 087
0 0 SOX7
086
1
8
9
6
7
10
II
12
13
14
18
19
20
4
5
2
3
15
16
17
085 084
083 082 081 080
1
SOY7
:
.
SOXO SPRITE 0 X
Component
SOYO SPRITE 0 Y
Component
SIXO
SPRITE I X
SIYO SPRITE 1 Y
2
S1X7
3 SIY7
4 S2X7
5
'S2Y7
S2XO SPRITE 2 X
52 YO
SPRITE 2 Y
S3XO
SPRITE 3 X
6 !S3X7
7
8
!s3Y7
S4X7
S3YO SPRITE 3 Y
S4XO
SPRITE 4 X
S4YO
SPRITE 4 Y
9 S4Y7
A S5X7 S5XO
SPRITE 5 X
S5YO
SPRITE 5 Y
B
5Y7
C S6X7
S6XO SPRITE 6 X
S6YO
SPRITE 6 Y
D S6Y7
E
S7X7
S7XO SPRITE 7 X
Component
F
12
7Y7
RC7 RC6 RC5
S7YO SPRITE 7 Y
Component
10
11
7X8 S6X8 S5X8 S4X8
S3X8 S2X8 SIX8
SOX8 MSB of X
COORD.
RC8
ECM
BMM
BlNK RSEl
YSCl2 Y5Cll YSClO
Y SCROll
MODE
RC4 RC3 RC2 RCI RCO RASTER
13 PX7
14 PY7 lPXO LIGHT PEN X lPYO LIGHT PEN Y
159
I
Register
#
Dee Hex DB7
DB6 DBS DB4 DB3 DB2 DBI DBO
21
22
23
24
IS SE7 SEO SPRITE
ENABLE
(ON/OFF)
16 N.C. N.C.
RST MCM CSEl XSCl2 XSClIXSClO
X SCROll
MODE
17 SEXY7
.
SEXYOSPRITE
EXPAND Y
18 VS13 VS12
VSlI VSIO CBI3 CBI2 CBII N.C.
SCREEN
Character
Memory
25
26
27
28
29
30
31
19
IA
IB
IRQ
N.C.
BSP7
IC SCM7
N.C.
N.C.
N.C.
lPIRQ
ISSC
ISBC
RIRQ
Interupt
Request's
N.C.
N.C.
N.C.
MlPI MISSC MISBC MRIRQ Interupt
Request
MASKS
BSPO
Background-
Sprite
PRIORITY
SCMO MUlTICOlOR
SPRITE
SelECT
ID SEXX7
IE SSC7
IF
SBC7
SEXXO SPRITE
EXPAND
X
SSCO
Sprite-Sprite
COLLISION
SBCO
Sprite-
Background
COLLISION
160
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
26 6
27 7
28 8
29 9
2A 10
2B 11
2C 12
2D
13
2E 14
15
20 0
21 1
22
2
23 3
24 4
25 5
COLOR CODES
0 BLACK
WHITE
1
2
3
4
5
RED
CYAN
PURPLE
GREEN
6
7
8
9
A
B
C
D
E
F
BLUE
YellOW
ORANGE
BROWN l T RED
GRAY 1
GRAY 2
LT GREEN
IT BLUE
GRAY 3
SMC 1
SOCOl
SICOl
S2COl
S3COl
S4COl
S5COl
S6COl
S7COl
DEC
HEX COLOR
EXT 1 EXTERIORCOl
BKGDO
BKGDI
BKGD2
BKGD3
SMC 0
SPRITE
MUlTiCOlOR 0
1
SPRITE0 COLOR
1
5
6
7
2
3
4 lEGEND:
ONLY COLORS 0-7 MAY BE USED IN MUlTICOlOR CHARACTERMODE
161
APPENDIX P
COMMODORE 64 SOUND CONTROL
SETTINGS
This handy
table gives you the key numbers you need to use in your
sound programs, according to which of the Commodore 64's 3 voices you want to use. To set or adjust a sound control in your BASIC program, just POKE the number from the second column, followed by a comma (,) and a number from the chart.
. . like this: POKE 54276,17
(Selects a Triangle Waveform for VOICE 1).
Remember that you must set the VOLUME before you can generate sound. POKE54296 followed by a number from 0 to 15 sets the volume for all 3 voices.
It takes 2 separate POKEs to generate each musical note
. . .
for example POKE54273,34:POKE54272,75 designates low C in the sample scale below.
Also.
. . you aren't limited to the numbers shown in the tables.
If 34 doesn't sound "right" for a low C, try 35. To provide a higher SUSTAIN or ATTACKrate than those shown, add two or more SUSTAIN numbers together.
(Examples: POKE54277,96 combines two attack rates (32 and
64) for a combined higher attack rate
.
. . but. . .
POKE54277,20 provides a low attack rate (16) and a medium decay rate (4).
162
SETTING VOLUME-SAME
FOR ALL3 VOICES
TO PLAY A NOTE C C#
(0 to 15
. . .
or
. . .
0 to 255 depending on range)
D
D#E
F
F# G G#
A
A# B C C#
HIGH FREQUENCY
54273 34 36 38 40 43 45
48 51 54
57
61 64 68 72
WAVEFORM POKE
54276
172 126 188 149 169
LOW FREQUENCY 54272 75 85 126 200 52
198 127 97 111
TRIANGLE
17
SAWTOOTH
33
I
PULSE NOISE
I
65 129
PULSE RATE(Pulse Waveform)
HI PULSE
LO PULSE
54275
54274
I
A value of 0 to 15 (for Pul.e waveform only)
A value of 0 to 255 (for
Pul.e waveform only)
ATTACK/DECAY
I
POKE ATK4
ATK3
ATK2
ATKI DEC4
DEC3
2
DEC2
I
DECI
54277
128 64 32 16
8 4
SUSTAIN/RELEASE
.-
I
POKE
SUS4
SUS3
SUS2 SUSI REL4 REL3
54278 128 64 32 16 8
4
o
REL2
I
REL1
TO PLAY A NOTE C
C# D D# E F F# G
HIGH FREQUENCY
54280 34 36 38
40 43 45 48 51
LOW FREQUENCY
54279 75 85 126 200 52
198 127 97
G#
54
111
WAVEFORM POKE
54283
TRIANGLE SAWTOOTH PULSE
17
33 65
A A#
NOISE
B
129
C C#
57 61 64 68 72
172 126 188 149 169
PULSE RATE
HI PULSE
LO PULSE
ATTACK/DECAY
SUSTAIN/RELEASE
I
54282
54281
I
POKE
5-428-4
POKE
54285
A value of 0 to 15 (for Pul.e waveform only)
A value of 0 to 255 (for
Pulse waveform only)
ATK4
ATK3 ATK2 ATKI DEC4
DEC3 DEC2 DECI
128
64 32 16
SUS4 SUS3
SUS2 SUSI
128
64 32
16
8 -4 2 1
REL4
REL3 REL2 REL1
8 4 2
1
163
I
D'
" ocm
D'
E
.
..
F FII.
G
GII.
I TOop.LAYA
NOoTE C
CII
HIGH FREQUENCY 54287 34
36 38 40 43
45 48 51 54
LOW FREQUENCY 54286 75 85 126 200 52 198 127 97 111
WAVEFORM POKE
54290
TRIANGLE SAWTOOTH
17 33
PUL5E
65
A All
, ..
B'
C
II
57 61 64 68 72
172 126 188 149 169
NOISE
129
PULSE RATE
HI PULSE
LO PULSE
ATTACK/DECAY
54289
54288
POKE
54291
A value of 0 to 15 (for Pul.e waveform only)
A value of 0 to 255 (for Pul.e waveform only)
ATK4
128
ATK3
64
ATK2
32
ATKI
16
DEC4
DEC3
DEC2 DECI
8 4 2 I
SUSTAIN/RELEASE POKE
54292
SUS4
SUS3 SUS2 SUSI REl4
128 64
32
16 8
REl3
4
RE12 RELI
2
I
TRY THESE SETTINGS TO SIMULATE DIFFERENT INSTRUMENTS
Instrument Waveform
Sustain/Release Pulse Rate
Piano
Flute
Harpsichord
Xylophone
Organ
Colliape
Accordion
Trumpet
Pulse
Triange
Sawtooth
Triangle
Triangle
Triangle
Triangle
Sawtooth
Attack/Decay
0
102
96
9
96
9
9
0 240
240
0
0
0
0
0
0
Hi-O, Lo-255
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
MEANINGS OF SOUND TERMS
ADSR-Attack!Oecay/SustainlRel8Gse
Attack-rat.
sound rises to peak volume
D.coy-rat.
50und falls from peak volume to Sustain level
Sustain-prolong note at certain volume
Releas.-rote at which volume foU. from Sustain level
Waveform-".hape"
Pulse-tone quality oflOund waye of Pulse Waveform
NOTE: Attack/Decay and Sustain/Release settings should always be POKEd in your program
BEFORE the Waveform is POKEd.
164
INDEX
A
Abbreviations, BASIC commands, 130,
131
Accessories, viii, 106-108
Addition, 23, 26-27, 113
AND operator, 114
Animation, 43-44, 65-66, 69-75, 132,
138-139
Arithmetic, Operators,
113-114
23, 26-27,
Arithmetic, Formulas, 23, 26-27, 113,
120, 140
Arrays, 95-103
ASC function, 128, 135-137
ASCII character codes, 135-137
B
BASIC abbreviations, 130-131 commands, 114-117 numeric functions, 125-127 operators, 113-114 other functions, 129 statements, 117-125 string functions, 128 variables, 112-113
Bibliography, 156-158
Binary arithmetic, 75-77
Bit, 75-76
Business aids, 108
Byte, 76
C
Calculations, 22-29
Cassette tape recorder (audio), viii, 3,
18-20,21
Cassette tape recorder (video), 7
Cassette, port 3
CHR$ function, 36-37, 46-47, 53,
58-60, 113, 128, 135-137, 148
CLR statement, 117
CLR/HOME key, 15
Clock, 113
CLOSE statement, 117
Color adjustment, 11-12
CHR$ codes, 58 keys, 56-57 memory map, 64, 139
PEEKS and POKES, 60-61 screen and border, 60-63, 138
Commands, BASIC, 114-117
Commodore key, (see graphics keys)
Connections optional, 6-7 rear, 2-3 side panel, 2
TV/Monitor, 3-5
CO NT command, 114
ConTRL key, 11, 16
COSine function, 126
CuRSoR keys, 10, 15
Correcting errors, 34
Cursor, 10
D
DATASSETTE recorder, (see cassette tape recorder)
Data, loading and saving (disk), 18-21
Data, loading and saving (tape),
18-21
DATAstatement, 92-94, 118
DEFine statement, 118
Delay loop, 61, 65
DELete key, 15
DIMension statement, 118-119
Division, 23, 26, 27, 113
Duration, (see For
. . .
Next)
E
Editing programs, 15, 34
END statement, 119
Equal, not-equal-to, signs, 23, 26-27,
114
Equations, 114
Error messages, 22-23, 150-151
Expansion port, 141-142
EXPonent function, 126
Exponentiation, 25-27, 113
F
Files, (DATASSETTE), 21, 110-111
Files, (disk), 21,110-111
FOR statement, 119
FRE function, 129
Functions, 125-129
G
Game controls and ports, 2-3, 141
GET statement, 47-48, 119-120
GET# statement, 120
Getti n9 sta rted, 13-29
GOSUB statement, 120
GOTO (GO TO) statement, 32-34, 120
165
Graphic keys, 17, 56-57, 61, 132-137
Graphic symbols, (see graphic keys)
Greater than, 114
H
Hyperbolic functions, 140
I
IEEE-488Interface, 2-3, 141
IF . . . THEN statement, 37-39, 120-
121
INPl/T statement, 45-47, 121
INPUT#, 121
INSert key, 15
INTeger function, 126
Integer variable, 112
I/O pinouts, 141-143
I/O ports, 2-7, 141-143
J
Joysticks, 2-3, 141
K
Keyboard, 14-17
L
LEFT$function, 128
LENgth function, 128
Less than, 114
LETstatement, 121
LIST command, 33-34, 115
LOAD command, 115
LOADing programs on tape, 18-20
LOGarithm function, 126
Loops, 39-40, 43-45
Lower case characters, 14-17
M
Mathematics formulas, 23-27 function table, 140 symbols, 24-27, 38, 114
Memory expansion, 2-4, 142
Memory maps, 62-65
MID$ function, 128
Modulator, RF, 4-7
Multiplication, 24, 113
Music, 79-90
N
Names program, 18-21 variable, 34-37
NEW command, 115
NEXT statement, 121-122
NOT operator, 114
Numeric variables, 36-37 o
ON statement, 122
OPEN statement, 122
Operators arithmetic, 113 logical, 114 relational, 114 p
Parentheses, 28
PEEK function, 60-62
Peripherals, viii, 2-8, 107-109
POKE statement, 60-61
Ports, I/O, 2-3, 141-143
POS function, 129
PRINT statement, 23-29, 123-124
PRINT#, 124
Programs editing, 15, 34 line numbering, 32-33 loading/saving (DATASSETTE),18-21 loading/saving (disk), 18-21
Prompt, 45
Q
Quotation marks, 22
R
RaNDom function, 48-53, 126
Random numbers, 48-53
READ statement, 124
REMark statement, 124
Reserved words, (see Command statements)
Restore key, 15, 18
RESTOREstatement, 124
Return key, 15, 18
RETURN statement, 124
RIGHT$ function, 128
RUN command, 116
RUN/STOP key, 16-17
5
SAVEcommand, 21, 116
Saving programs (DATASSETTE),21
Saving programs (disk), 21
Screen memory maps, 62-63, 138
SGN, function, 127
Shift key, 14-15, 17
SINe function, 127
Sound effects, 89-90
SPC function, 129
166
SPRITE EDITOR, vii, 69-76
SPRITE graphics, vii, 69-76
SQuaRe function, 127
STOP command, 125
STOP key, 16-17
String variables, 36-37, 112-113
STR$ function, 128
Subscripted variables, 95-98, 112-113
Subtraction, 24, 113
Syntax error, 22
SYS statement, 125
T
TAB function, 129
TAN function, 127
TI variable, 113
TI$ variable, 113
Time clock, 113
TV connections, 3-7 u
Upper/Lower Case mode, 14
USR function, 127
User defined function, (see DEF)
V
VALue function, 128
Variables array, 95-103, 113 dimensions, 98-103, 113 floating point, 95-103, 113 integer, 95-103, 112 numeric, 95-103, 112 string ($), 95-103, 112
VERIFYcommand, 117
Voice, 80-90, 162-164
W
WAIT command, 125
Writing to tape, 110
Z
Z-80, vii, 108
167
Commodore hopes you've enjoyed the COMMODORE
64
USER'S GUIDE.
Although this manual contains some programming information and tips, it is NOT intended to be a
Programmer's Reference Manual.
For those of you who are advanced programmers and computer hobbyists Commodore suggests that you consider purchasing the COMMO-
DORE 64 PROGRAMMER'S REFERENCE GUIDE
available through your local Commodore dealer.
In addition updates and corrections as well as programming hints and tips are available in the COMMODORE and POWER
PLAY magazines, on the COMMODORE database of the
COMPUSERVE INFORMATION NETWORK, accessed through a VICMODEM.
SIMPLE VARIABLES
Type
Nam~ Range
Real XY ::1.701411183E+38
~2.93873S88E-39
Integ~r
String
XY" ~32767
XY$ 0 to 255 charaCters
X is a tener (A-Z), Y is a Jener ar number (0.9). Variable names can be more than 2 choracters. but only the firsl two are recog.
niud.
ARRAY "'RIAlLES
Type
Singl~ Dimension
Two-Dimension
Three-Dimension
COMMODORE 64 QUICK REFERENCE CARD
Name
XY(S)
XY(5,S)
XY(S,5,S)
Arrays of up 10 eleven .Iements (subscripts 0.10) can be used where n.ed~d. Anay$ with more Ihan eleven er~m.nts need 10 be DIMens;on.d.
SPC(X)
POS(X)
ClR/HOME
SHIFT CLRlHOME
SHIFT INST/DEL
INST/DEL
CTRL
CRSR Keys
Commodore Key
PRINTs X blanks on line
Relurns currenl cursor position
Posilions cursor to left comer of scr~~n
CI.ars
"Home" scr.en
position and places cursor in
Inserts spac.
at current cursor position
Deletes character at currenl cursor position
When us.d
wilh numeric color key, sel.cts
text color.
May b~ used in
PRINT slatement.
Moves cursor up, down.
left, righl
When used with SHin s.lects
betw..n
upperllower case and graphic display mod..
When us.d wilh numeric color key, selects oplional lext color
AlGEBRAIC OPERATORS
= Assigns ...alu.
10 variabl.
-
"'egalion
Exponentiation
· Multiplication
I
Division
+ Addition
-
Sublraction
RELATIONAL AND LOGiCAl OPERATORS
Equal
<> NOl Equal 10
< Less Than
<
>
>
Greol~r Than
=
Less Thon or Equal To
=
Grealer Thon or Equal To
NOT logical "Nor"
AND logical "And"
OR logical "Or"
Expr.ssion..quals
1 if true, 0 if fals~.
SYSTEM COMMANDS
LOAD
"NAME"
SAlE "NAM£'"
LOAD "NAME" ,8
SAlE "NAME" ,8
. VERIFY "NAME"
RUN
RUN xxx
STOP
END
CONT
PEEK(X)
POKE X,Y
SYS xxxxx
WAIT X. Y.Z
USR(X) loads
Sav.s
a program a program from tope on lope loads a program from disk
Sa s a program 10 disk
Verifies Ihal program was SAlEd wilhoul ~rrors
Execules a program
Execules program storting
"""
Holts execution
Ends execution at line
Continues program lin.
where program
R.lums
location conlents
X execution from was halted of memory
Chang.s
contenls
10 ...alue
Y of 10cOlion X
Jumps program,
Program location to .xecule
X, when a machine starting at JCXXXX wafts until conlents
FORed with language of'
Z and
ANDed with Y, is nonzero.
Posses value of X 10 a machine language subrouline
EDITING AND FORMAJTlNG COMMANDS
LIST
UST A-.B
REMMessage tAB(X)
Lisn entire program
Usts from line A to line B
Comment message can be listed but is ignored
Used pasltions during on screen program
In PRINT stotements.
execution
Spaces X
ARRAYS AND STRINGS
DIM A(X. Y.Z)
LEN(XS)
STRS(X)
UX$)
CHRS(X)
ASC(X$)
LEFT$(AS.X)
RIGHTS(A$,X)
MIDS(AS,X, Y)
Sets maximum subscripts for A; reserves space for (X+1)-(Y+1)-CZ+1) eJem.nts starting 01 A(O,O,O)
Returns number of characters in X$
Re",rns numeric value of X.
con rt.d 10 a string
Returns num.ric value of AS, up 10 first nonnumeric character
Returns ASCII character whose code is X
Returns ASCII cod. for fir" character of XS
Retums leftmost X characlers of AS
Relurns rightmost X characters of AS
Relurns Y characters of AS
Slorting at character X
INPUT/OUTPUTCOMMANDS
INPUTAS OR A PRINTs'?' on screen and waits for
INPUT"ABC";A
GETA$ or A
DATAA,"B",C
READA$ or A
RESTORE
PRINT"A-";A us.r to enter a sIring or value
PRINTsmessage and waits for user to ent.r value. Can also INPUTAS
't'Ibits for user 10 type onecharacter value; no RETURNneed.d
Initializes a s.t of values thol can be used by
READ statement
Assigns nexl DATAvalue 10 AS or A
Res~Is dOlo pointer to start
READingthe DATAlist again
PRINTsSIring 'A= ' and value of A
./ suppresses spac.s -': tabs data to next field.
PROGRAM ROW
GOTO X Branche. 10 line X
If A=3 THEN 10 If assertion is Irue THENexecute following port of statement.
If fal...
execute next line number
FOR A= 1 TO 10 Executes all statements betw.en
FOR
STEP2 : NEXT
NEXTA
GOSUB 2000
RETURN and corresponding NEXT.with A going from 1 10 10 by 2. SI.p size is 1 unless s~jfied
Defines .nd of loop. A is optional
Branches 10 subroutine slarting at line 2000
Marks end of subroutine. R~turns to stat.ment
following mosl recent
GOSUB
ON X GOTO A,B Bronches 10 xth line number on list. If X-I branches 10 A, elc.
ON X GOSUB A,B Bronches 10 subroutine at Xth line number in list
(::
commodore
COMPUTER
Commodore Business Machines. Inc.-Computer Systems Division.
487 Devon Park Drive. Wayne. PA 19087
DISTRIBUTEDBY
Howatd W. Sams & CO., Inc.
4300 W.
62nd Street,
Indianapolis, Indiana
46268 USA
ISBN:
0.672.22010.5
$12.95/22010
ডাউনলোড
বিজ্ঞাপন