0% found this document useful (0 votes)
155 views300 pages

Compute!s Second Book of Commodore 64

Uploaded by

Jonah Hex
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
155 views300 pages

Compute!s Second Book of Commodore 64

Uploaded by

Jonah Hex
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 300

re COMPUTE!

’s

7 [Cvelaalovymo]ele)|(e
ola
e] SauliliiieomivielielSaelate lalfolsaateliela
7" for users of the Commodore 64° home computer,
ror elKole slate AWielcerm(enel(q\elilare foley s4liale Ke|xo]o)alexy
the best from COMPUTE! Publications.

A COMPUTE! Books Publication Ska


Seth Go lob
SECOND
COMPUTE!’s

BOOK
COMMODORE
O4

COMPUTE! Publications nc.


Greensboro, North Carolina

Commodore 64 is a trademark of Commodore Electronics Limited.


The following articles were originally published in COMPUTE! magazine, copyright
1983, COMPUTE! Publications, Inc.:
“Working with SID” (October).
“SuperBASIC 64” (December).

The following articles were originally published in COMPUTE!’s Gazette magazine,


copyright 1983, COMPUTE! Publications, Inc.:
“VIC/64 Mailing List’ (August).
“Wordspell’”’ (August).
“Using the Function Keys” (September).
“Merging Programs on the 64” (November).
“NIC /64 Program Lifesaver’ (November).
“Martian Prisoner” (November).
““Munchmath” (November).
“Introduction to Custom Characters for VIC and 64” (November).
“How to Make Custom Characters on the 64” (November).
“Spike” (December).
“The Note Name Game” (December).
“Sprites Made Easy’’ (December).
“Educational Games: A Kid’s View’’ (December)
“SpeedScript” (January 1984).
The following article was originally published in COMPUTE!’s Gazette magazine, copy-
right 1984, COMPUTE! Publications, Inc.: “How to Use Arrays” (February).
Copyright 1984, COMPUTE! Publications, Inc. All rights reserved.
Reproduction or translation of any part of this work beyond that permitted by Sec-
tions 107 and 108 of the United States Copyright Act without the permission of the
copyright owner is unlawful.
Printed in the United States of America.
ISBN 0-942386-44-2

10987654321

COMPUTE! Publications, Inc., Post Office Box 5406, Greensboro, NC 27403, (919)
275-9809, is one of the ABC Publishing Companies, and is not associated with any
manufacturer of personal computers. Commodore 64 is a registered trademark of
Commodore Electronics Limited.
Contents
Foreword * 54 2s czech
est, Sr ee eal V

Chapter 1: Recreations and Applications ............ I


SpeedScript
Charles Bravnod 3) ete S fed Fe ROS oe cata ee 3
Spike
Evie’ Braedon 3. ici Ole cae Ort aes ne ee ee 41
Martian Prisoner
Alar PoOle 5 ses sicncsitids cecataidsien eae ee ee 60
64 Mailing List
Joseph J. Shaughnessy 0. cos besa Jun <a) 6 aA 66
64 Spreadsheet
Michael*Tinglof 3. ©0°0 Wore Ue es ws ees Cea 72

Chapter 2: Kid Stuff—Educational Games .......... 85


Educational Games: A Kid’s View
Revin Deus a om seg ahs nce eae aa a ek es ae er 87
Wordspell
Richard. Herrneania x: als Scusiu, rc Beakalin ch cual Ae 92
Munchmath
Gerald ‘R: Andérsoniwcs.. Ww ho TOS ee 96

Chapter-3: Sound scam.) fon eee


a 535 aan 103
Working with SID
JOT MO TRES Oca ee haan ee Cee On yak ee Ee 105
Sound Editor 64
Daniel LRieeale aes res ca renee eee er Crete 119
SYS Sound
Micheal StGi ~ohcrstess iaazitct thw teks Phones a ae ea 126
The Note Name Game
Jeff: Behrens sch SA eB patie Bey ees a5 132

Chapter 4: Colors, Characters, and Motion ........ 137


Introduction to Custom Characters for the 64
Tort By Fim ilies 5 a aig wise eee tha eee ce teased 139
How to Make Custom Characters on the 64
GAG DGUIS raises tarde sect ale oe OU AE I oa 146
SuperBASIC Sprite Editor
IMGT RECS aeig Cusine nites ars Na edt ti or 155
Sprites Made Easy
Pip) CES CWO Na ee i dacs ea as ASC a 9 aa 166
Chapter 5: Inside Your 64... 02. 225. . S 177
Using the Function Keys: A BASIC Tutorial
CHianles Baan nedcwn ta scattede in: ils:chsShe re) ve dalone £79
How to Use Arrays
DDOMISIGTTET fests Mirena apes ahemeee aE 185
Adding New Keywords to BASIC
SNECLH OFRECETIION: ettoryai.viaua Naik tectdla aces a ep nee eae 194

Chapter Gy UG ties rey a a gohan s eee a23


SuperBASIC 64
VCR RITTER SASSER ep S05 ee OSEAT a Sey eee 215
Copyfile
GhEQOT LEDUSOT eS a rca taahticte ts Witte: Ban rn Kot ia Mea oa tiaeed 250
Merging Programs on the 64
FORTRANAAIIRIe Cana, Rb twins eee ha... 4gSeaete ahs 253
64 Program Lifesaver
WETIE UA GIsoF Aico cyst aretha Aaa cece eR OR 256

ADDON ICES fa hc ied ost cane ie hey teas cosa ar ne 259


A: A Beginner’s Guide to Typing In Programs ........ 261
BY sHowsto Type*In: Programs 2 ins sss ane arse e316) «1 263
Crrisceréen- hocationc Table glx scies eatin aa tetsu wae eas 265
D;..screen Color. Memory Table v.00 Gacy cs Maayences 266
Fi... Screen (Color, COdeS iils. cuit aiken Wop ales, \ nea inate 267
BiG ASGI, Codes vis,555: sisi crs Myakayalennnayepaotggs Meee ¢ 269
Gio Screen Codes: ire. 2)clesc)sad. wiaed are tia a tae 273
Hs ‘Commodore 64-Keycodes iin sn. 4yinscse diaiusste ree nessa 275
I; Using the Maching Language Editor: MLX
CHATS BIGHHOM acies cnn Ogee ras ate cians Oe keen 276
J: The Automatic Proofreader
Chasles Brannon ka ye pun aoe acravs Sec arana te cern a 283
Foreword
Since its introduction in the fall of 1982, the Commodore 64
computer has become one of the most popular home comput-
ers available. Hundreds of thousands of beginning and experi-
enced programmers have learned to use its remarkable
graphics, sound, and game-playing capabilities. And more and
more professional programmers have been writing software
for the 64, giving users a wider choice of applications for their
computer.
COMPUTE! Books has been active in its support of the
Commodore 64. COMPUTE!'s First Book of Commodore 64
continues to be a bestseller among computer books. Maintain-
ing this tradition of presenting high quality programs and de-
tailed information, COMPUTE!’s Second Book of Commodore 64
offers a wide range of games, applications, tutorials, and util-
ities. Of the articles and programs which originally appeared
in COMPUTE! magazine or COMPUTE!’s Gazette, many have
been enhanced since first published. Other articles and pro-
grams appear here for the first time anywhere.
There’s something for computer users at any level of
experience in this book. If you're just starting to use custom
characters, sprites, or arrays, you'll find excellent articles
which will introduce you to those techniques. If you’re a more
experienced programmer, you'll enjoy the articles on how to
create new BASIC keywords, how to best use the 64’s SID
chip, and how to merge, copy, or retrieve programs easily.
Do you like to write? Then “SpeedScript,”” a machine lan-
guage word processor, is something you'll find particularly
impressive. Interested in writing games on the 64? There are
utilities and information here which will help you as you pro-
gram. From a sprite editor to a sound editor, you'll find what
you need in Second Book of Commodore 64.
If you like to just sit back and play arcade-quality games
on your computer, then you'll find “Spike,” “Martian Pris-
oner,”” and others well worth the time it takes to type them in.
There’s even a complete section of games written especially
for children. Not only are these games fun to play, but they'll
teach your children something at the same time. ‘“Wordspell”
offers practice in spelling, while ““Munchmath” makes a game
out of mathematics.
No matter what your programming experience or interest,
you're certain to find that Second Book of Commodore 64 has
plenty to offer.
Recreations Ever!
aX ojo)iteriateyate
Recreations and Applications 1

SpeedScript
Charles Brannon

“SpeedScript,” is a word processing program


written entirely in machine language. Fast,
powerful, and easy to use, it includes almost all
the major features found in professional word
processor programs for personal computers. It
approaches commercial-quality programs costing
$50 or more. It runs on the Commodore 64,
leaving a huge 45K free for text. SpeedScript
will considerably amplify the utility of your
computer.
[elas SES Rae Saas ee ee een REG RR Noni eee ours SAE]

A current advertising campaign extols the virtues of a ball-


point pen that can erase like a pencil, dubbing it the “portable,
personal word processor.” It can even plot graphics. Like a
word processor, the pen can edit, change, and erase. It can
produce flawless hard copy. And, indeed, you can draw
circles, squares, and bar graphs. But can the pen move para-
graphs? Put a 100-page book on a 5% inch disk? Turn a rough
draft into final copy with only a few changes? Can it truly edit
without a trace of correction and produce formatted, double-
spaced, automatically page-numbered text?
Maybe we’re not being fair to the erasable pen, but it
should be made clear that a word processor is more than just
a computerized typewriter. Such a “word processor” would be
a few lines long:
10 OPEN 1,4
20 INPUT A$
30 PRINT #1,A$
40 GOTO 20
When RUN, the program flashes the cursor and waits for
a line to be typed. When you hit RETURN, the line is sent to
the printer. You can move the cursor left and overstrike or use
the DEL key to make changes to the line before you hit
RETURN and print it out. But once it’s on paper, it’s committed.

3
1 Recreations and Applications

Too late to make any changes.


With a true word processor, you type everything in first,
then print the whole thing out. Before you print, you can
make as many changes as you want. A good word processor
lets you change any line, swap paragraphs, and manipulate
your text in numerous other ways. You can buy such a word
processing program for your 64 for $40 to more than $100,
depending on the features.
Or you can type in “’SpeedScript.”” Even if you already
own a commercial word processor for your 64, you'll be pleas-
antly surprised. SpeedScript offers all the standard features,
plus others you may not have seen before.
Entering SpeedScript
First, you'll need to type in SpeedScript. Programs 1 and 2
look long, but they are only about 4.5K, shorter than most
BASIC games. The mass of numbers are machine language.
Only with machine language do you get such power, speed,
and compactness. Unfortunately, machine language isn’t as
easy to enter as a BASIC program. To aid with all the typing,
we've developed MLX, the machine language editor. Be sure
to read and understand Appendix I before you begin typing in
SpeedScript.
Type in and SAVE the MLX program. When you are
ready to enter SpeedScript, turn your machine off and on (to
clear it out), then enter this line before you load MLX:
POKE 44,27:POKE 6912,0:NEW
You can then load MLX from tape or disk, and enter
RUN. MLX will ask for the starting and ending addresses. The
starting address is the first number in the listing, 2049. The
ending address is the last number plus five, or 6860. After you
enter this, follow the instructions in Appendix I to enter the
listing. It takes only a few hours (you can stop, save your
work, and continue typing in several sessions). No matter
what your typing speed is, rest assured that it will be well
worth your effort.
Getting Started
After you enter SpeedScript with MLX, you can just LOAD it
like a BASIC program. As a matter of fact, you can make
copies of it with the SAVE command, as usual (SAVE
“SPEEDSCRIPT” or SAVE “SPEEDSCRIPT”,8 for disk). After

4
Recreations and Applications 1

you LOAD, enter RUN.


The screen will be light gray or white with black (or dark
gray) lettering. The top line of the screen is highlighted.
The blinking cursor shows you where text will appear
when you begin typing. You cannot type on the top line of the
screen. This is the command window, and is used by
SpeedScript to ask questions and display messages. When a
message is displayed, it will remain until you begin typing
again.
. To get started, just begin typing. If a word you’re typing
won't fit on the screen line, the word and the cursor are
moved to the next line. This is called word wrap, or parsing. It
makes your text much easier to read on the screen, as words
are never split across the margin. Another thing to notice is
that a back-arrow appears if you press RETURN. This marks
the end of a paragraph or line. It is not necessary to press
RETURN at the end of each screen line, as you must do when
reaching the end of a line on a typewriter.
Most of us, being human, are not infallible, so you may
need to correct your typing mistakes. This is a big advantage
of a word processor. You fix your errors before you print, so
there’s no messy fluids or special ribbons. (Did you ever have
to manually erase on a typewriter?—ugh!)
If you want to backspace, press the INST/DEL key in the
unSHIFTed position. The cursor backs up and erases the last
letter you typed. You can press it as many times as necessary
to back up to the error, then retype the rest of the sentence.
But this is clearly not the best way to do things. Instead,
you can move the cursor nondestructively. The cursor control
keys are in the lower-right corner of the keyboard (see Figure
1: Keyboard Map). The CRSR left/right key moves the cursor
to the right, and when SHIFTed moves the cursor left. Before
you can correct the error, you have to move the cursor to the
word in question. For example, to correct this line:
Now is the rime for all good men§

The cursor is moved to the (cursor-left 21 times):


44g
r

Now is the ime for all good men

The letter “t’’ is typed:


Now is the tHme for all good men
1 Recreations and Applications

And the cursor is moved to the end:


Now is the time for all good meni

Resume typing:
Now is the time for all good men to
come to the aid of they're country.

Another error! We typed “‘they’re” instead of “their.” No


problem.
In the above example, of course, you don’t have to press
the cursor-left key 21 times. You can just hold down the
cursor-left key. It will repeat, and keep moving until you let
go.
English Cursor Controls
You can also move the cursor in ways that make sense in
plain English. For example, if you hold down SHIFT and press
the f1 function key, (which is how you get f2), the cursor
jumps back to the previous word. To correct the error in the
first example above, just press f2 five times. You can then
press f1 five times to go back to the end of the sentence and
resume typing. Here is a list of what the function keys do:
f1: Move cursor to next word.
f2: Move cursor to previous word.
£3: Move cursor to start of next sentence.
f4: Move cursor to start of previous sentence.
£5: Move cursor to start of next paragraph.
f6: Move cursor to start of previous paragraph.
SpeedScript recognizes a sentence by the ending punctua-
tion (. or ? or !), or by a RETURN mark (back-arrow). A para-
graph is any sequence of characters that ends in a RETURN
mark. (Refer to Figure 2, after the program listing, for a clip-
out function key overlay.)
Since you’re working with English, the cursor up-down
keys do not move up or down exactly one screen line. Instead,
they act like f3 and f4. Cursor-down moves to the next sen-
tence, and cursor-up moves to the previous sentence. This is
easier to understand for many people, but it takes some get-
ting used to for others.
As you begin to move the cursor around, you'll notice
that you cannot move the cursor past the end of text. There is
an invisible marker, sometimes called End Of File (EOF) at the

6
Recreations and Applications 1

end of the document. You can add text to the end of your
document, but you cannot move past it, since there’s nothing
there. Very rarely, you may see some text past the end of file,
but you can’t move to it, so ignore it.
Many of the other keys behave predictably. The CLR/
HOME key in the unSHIFTed position moves the cursor to the
top of the screen. If you press it twice, it brings you to the top
of your document (in case the document is longer than one
screen). The insert key (SHIFT-INST/DEL) inserts a space at
the cursor position. You can press it as many times as nec-
essary to make space for inserting a word. You can also go
into insert mode, where every letter you type is automatically
inserted. In insert mode, it is not possible to overstrike. You
enter or leave insert mode by pressing CTRL-I.
Normally when you type a key, that letter or symbol
appears. Certain keys, such as CLR/HOME, however, perform
a function. SpeedScript extends this idea and places all the
command keys in an easy-to-remember order. For example,
insert mode is turned on or off by pressing CTRL-I. (To use a
control key, hold down CTRL while you type the other key.)
When you enter insert mode, the command window
changes color to remind you. If you press CTRL-I again,
you're back in normal overstrike mode, and the command
window reverts to its usual color.
CTRL-Z moves you to the bottom of your document (end
of file). It’s useful for adding text to the end. If you want to
check how much memory you have left for typing, press
CTRL and the equals (=) key. You have about 45K of text
memory on the 64. SpeedScript takes advantage of all the
available RAM on the 64.
To accommodate personal taste and video clarity, you can
change the screen and text colors to any combination you
want. CTRL-B (think “background”) changes the screen color.
You can keep pressing it until a color you like comes up.
CTRL-L (“letters”) changes the text color. If you have a color
monitor, you can get some really interesting combinations.
The RUN/STOP key is like a TAB key. It inserts five
spaces at the cursor position. You can use it for indenting, or
to add indentation to a paragraph previously typed.
If you want to change the case of a letter or word, po-
sition the cursor on the letter and press CTRL-A. It will switch
from lower- to uppercase or vice versa. CTRL-A moves the
1 Recreations and Applications

cursor to the right, so you can hold it down to change more


than one letter. Another handy command is CTRL-X, or
Transpose. It will switch two adjacent letters. My most com-
mon typing mistake is to wsitch (switch) two letters while I’m
typing fast. With CTRL-X, it’s easy to exchange the two letters
without overstriking (which is useful in insert mode).

Text Deletion
With a typewriter, if you don’t like what you've typed, you
can tear the paper out, crumple it up, and dunk it into “file
13.” With a word processor, this satisfying act is accomplished
with but a few keystrokes.
With the DEL key, you can erase the last letter typed. If
you're in the middle of text and press it, you'll notice that the
character the cursor is sitting on is pulled on top of the pre-
vious character, and the rest of the text follows along. It
sounds a little confusing, but it’s easy:
The quick brown fox juunmped over
Cursor is moved to error:
The quick brown fox juun{iped over
DEL is struck twice, deleting the erroneous characters:
The quick brown fox juufped over
The quick brown fox jufped over
If you don’t want the text to be pulled back, you can
press the back-arrow key. It will just backspace and blank out
the previous character without pulling the adjacent characters
backward. Another way to delete is with CTRL-back-arrow.
The cursor does not move, but the following text is “sucked
into” the cursor. It is like a tiny black hole.
If you want to strike out a whole word, sentence, or para-
graph, it’s time for a more drastic command: CTRL-E. When
you press CTRL-E, the command window turns red (to instill
fear and awe). You see the message:
Erase (€5,W,P3; to exit
Each time you press one of the three keys, a sentence,
word, or paragraph is pulled toward the cursor and deleted.
You can keep pressing S, W, or P until all the text you want to
Recreations and Applications 1

remove is gone. Then press RETURN to exit the Erase func-


tion and resume writing. Erase will remove text to the right of
the cursor. If you are at the end of a sentence, word, or para-
graph, you can use Delete (CTRL-D) to erase backward. CTRL-
D displays:
Delete (5,W,P)

and immediately returns to the normal mode after its work is


done. CTRL-Delete is like the DEL key, and CTRL-Erase is
like CTRL-back-arrow.
What if you press one key too many in the Erase com-
mand? What if you change your mind? Oh, no! What if you
accidentally erase the wrong paragraph? On most word
processors, you're out of luck. But with SpeedScript, you can
retrieve the crumpled-up piece of paper and “uncrumple”’ it.
Within certain limitations, SpeedScript remembers and stores
the text you Erase or Delete. If you change your mind, just
press CTRL-R.
Here’s how it works. When you Erase text, the text is
moved from the main screen into a failsafe buffer, a reserved
area of memory. SpeedScript reserves 12K for the failsafe
buffer.
There’s another valuable use for the buffer, too. You can
move text by putting it in the buffer and recalling it at the
destination. Just Erase the paragraphs, words, or sentences you
want to move, then place the cursor where you want to insert
the text and press CTRL-R (think ‘Restore,’ “Retrieve,” or
“Recall’”’). In a flash, the text is inserted. If you want to copy
(rather than move) a word, sentence, or paragraph, you can
restore the deleted text with CTRL-R, then move the cursor
and press CTRL-R to insert the deleted text again. You can
retrieve the buffer contents as often as you like. For example, if
you use a long word or phrase often, just type it once, Erase
it, then use CTRL-R to have the computer type it out for you.
You should be aware that CTRL-E and CTRL-D will clear
the previous buffer contents. When you move one paragraph,
then go back to move another, you don’t want to have both
paragraphs merged together the second time. Also, if CTRL-
Delete added text to the buffer instead of replacing the buffer,
CTRL-R would insert the text entries out of order, since CTRL-
D deletes “backward.”
If you want to move two paragraphs at the same time
1 Recreations and Applications

instead of separately, you can override the replacement and


cause CTRL-Erase to add to the end of the buffer. Just hold
down SHIFT with CTRL as you press E. If you want to force
the buffer to be cleared, you can use CTRL-K (Kill) to clear the
buffer. If you try to delete more than the length of the buffer
(12K on the 64), you'll see “Buffer Full”. Stop and move the
text, or use CTRL-K to clear the buffer to erase some more.
Finally, if you really want to wipe out all your text, there
is a way. (Beware: You cannot recover from a total clear.)
Press SHIFT-CLR/HOME. You will see:
ERASE ALL TEXT: Aare you sure? (CY/N3
If you really want to erase all the text, press Y. Any other
key, including N, will return you to your text unharmed. You
should use this command only when you want to start a new
document, as it is one of the few ways to lose text beyond
recovery.
Search Feature
When you are lost in the middle of a big document and want
to find a particular word or phrase, the Hunt command comes
in handy. Press CTRL-H and you'll see:
Hunt for:@

Enter the word or phrase you want to find, then press


RETURN. SpeedScript will locate the word and place the
cursor on it, scrolling if necessary. If the phrase is not found,
you'll see a ‘Not Found” message in the command window.
The first time you use Hunt, SpeedScript will search for
the phrase from the top of the document. Pressing CTRL-H
again will find the next occurrence of the search phrase after
the cursor position. You can search for a new phrase without
waiting to get ‘“Not Found” for the previous phrase by hold-
ing down SHIFT while you press CTRL-H.
There are some tricks to using Hunt. For example, if you
search for the word “‘if,”” SpeedScript will match it with the
embedded “‘if’’ in a word like “specific.” Should you just want
to find the word “if,” search for “if” followed by a space.
Also, searching for “if” will not match with the capitalized
sa bg

10
Recreations and Applications 1

Saving and Loading


What makes a word processor truly great is that you can save
your typing to tape or disk. Say you're writing a term paper.
You type it in and save it to disk. Your teacher returns the
rough draft with suggested corrections. Without retyping the
entire paper, you just load the original, make some changes,
and print it out. A 5% inch disk can hold more writing than a
briefcase! You can also write in stages: save your work as you
go along, then come back to it at another time. Saving and
loading alone elevates word processing far above any other
means of writing.
To save your work, press £8 (SHIFT-f7). You will see:
save:

Enter the name you want to use for the document. Follow
the standard Commodore filename rules, such as keeping the
name to 16 characters or less. Press RETURN, then press ei-
ther T or D, answering the prompt TAPE OR DISK?
After the Save is completed, you'll see NO ERRORS
(hopefully). If there was an error during the save, such as no
disk in the drive, or a disk full error, SpeedScript will read the
error channel and display the error message. You'll get the
error ‘file exists” if you try to save using a name that’s al-
ready on the disk. If you want to replace the file, prefix the
name with the characters “@:’’, such as “@:Document’’. This
is called “Save with Replace.” You can also press CTRL- ff (up
arrow, explained below) and scratch the file before you save.
Press f7 to load a file. You may want to use SHIFT-CLR/
HOME to erase the current text first. The Load feature will ap-
pend text starting wherever the cursor is positioned. This lets
you merge several files from tape or disk into memory. If the
cursor is not at the top of the file, the command window will
change color to warn you that you are performing an append.
You should add text only to the end of the file, as the end-of-
file marker is put wherever the load stops. Also, beware that
you can crash SpeedScript if you try to load a file and don’t
have enough room (a file longer than available memory). You
can use CTRL-= (equals sign) to check the available memory
space before merging files to avoid a crash.
You can use CTRL-V to Verify a saved file. Verify works
like Load, but compares the file with what’s in memory. It’s
most useful with tape, but you can use it with disk files, too.

11
1 Recreations and Applications

SpeedScript files appear on the directory as PRG, program


files. The documents certainly aren’t programs, but since the
operating system has convenient Save and Load routines, the
text files are just dumped from memory. This is also more reli-
able for tape. You can load files created on some other word
processors, such as WordPro or PaperClip, but you may have to
do some reformatting. If the upper- and lowercase come out
reversed, you can hold down CTRL-A to transform the entire
file.
Other Disk Commands
Use CTRL-4 (think CTRL-$, as in LOAD’$”,8 from BASIC) to
look at the disk directory. You will not lose whatever text you
have in memory. While the directory is being printed on the
screen, you can press CTRL to slow down the printing, or the
space bar to freeze the listing (press the space bar again to
continue).
You can send any other disk command with CTRL-f (up-
arrow). It may not seem easy to remember, but I think of the
arrow as pointing to the disk drive. The command window
shows a greater-than sign (>). Type in the disk command and
press RETURN. By referring to your disk drive manual, you
can do anything the commands permit, such as Initialize,
New, Copy, Rename, Scratch, etc. If you press RETURN with-
out entering a disk command, SpeedScript displays the disk
error message (if any). (Table 1, near the end of this article, is
a clip-out reference card for all the editing commands.)
PRINT!
At last, we get to the whole point of word processing—the
printout. Actually, you can use SpeedScript without a printer.
If you and a friend each have a copy of SpeedScript, you can
exchange letters on tape or disk, ready to load and view. You
can get a lot of text on one tape or disk. And if you have a
friend with a printer and a 64, you can bring SpeedScript and
your files.
Before your text can be printed, it must be formatted. The
text must be broken into lines with margins, and there has to
be a way to divide the output into pages. For those with
pinfeed paper, we also need to skip over the perforation. Of
course, it would be nice to be able to automatically number all
pages. And why not let the computer center lines for you, or
block them edge right? You should be able to change the left

2
Recreations and Applications 1

and right margin anytime, as well as line spacing. Headers


and footers at the top and bottom of each page would add a
really nice touch.
SpeedScript does all that and more. But with that power
comes the responsibility to learn more commands. These com-
mands do not act directly on the text, but control how the text
is printed out. Some commands do things like change the left
margin, while others let you do things with the text like
centering or underlining. Remember, the formatting com-
mands will not change how the text on the screen looks. They
affect only the hard copy (what’s on paper).
Thanks to several default settings, you can print right
away without using any printer commands. If you press
CTRL-P, SpeedScript will make several assumptions and begin
to print. A few of these assumptions are: left margin of five
spaces, right margin at 75 (meaning a line length of 70 charac-
ters), and double spacing. If you want to change these settings,
you'll need to use the formatting commands.
Entering Format Commands
The format commands are single letters or characters that ap-
pear on the screen in reverse video. To get a reverse video let-
ter, press CTRL and the English pound sign (next to the CLR/
HOME key). The command window will prompt ‘’Key:”. Now
press one of the format letters, such as “’r” for right margin, or
“c’”’ for center. That letter will appear in reverse video (within
a “box,” with its colors switched). SpeedScript recognizes only
lowercase letters and some symbols as commands.
Changing Printer Variables
The printer variables are values such as left margin, right mar-
gin, line spacing, top and bottom margins, and so on. They are
called variables because they can change. For example, to
quote a passage within your text, you may indent it by
increasing the left margin, and also change to single spacing to
set it apart. You would then want to switch back to normal
margins and double spacing for the rest of the paper.
To change a printer variable, just follow the reverse video
letter with a number. Do not leave a space between a letter
and a number. You can put the format commands anywhere
in text, though I prefer to group them together on a line of
their own. Here is an example setting:

13
1 Recreations and Applications

Hiss ebinishse<
To set off these format commands, I'll show here that
they are in reverse video by enclosing them in brackets. You'll
enter them with CTRL-English pound sign.
[s] Spacing, default 2. Line spacing. This is set to 2 to des-
ignate double spacing. For single spacing, enter 1, for triple
spacing, enter 3, and so on.
[l] Left margin, default 5. The left margin is the number of
spaces to indent for each line.
[r] Right margin, default 75. This must be a number less
than 80, which is the number of characters that can fit on a
line. Add the line length you want to the left margin to get
the right margin.
[t] Top margin, default 5. How many blank lines to skip
from the top of the page to the first line of printing. Should be
at least 5.
[b] Bottom margin, default 58. A number less than 66,
which is the number of lines on an 8¥2 inch x 11 inch sheet of
paper or pinfeed paper. Do not use a bottom margin more
than 59.
[h] Define header. The header is printed at the top of each
page, if you specify one. To define the header, begin a line
with [h], enter the header text, then press RETURN. Example:
faccounting Procedurest
You can embed a format [c] after the [h] to center the
header, a format [e] to block the header edge right, and a
format [#] any place you want a page number to appear.
Examples:
A centered page number with a dash on each side:
¥ePage ~-i-¢
The header used when this article was written:
Tabrannon/s'5peedscript/@e

[f] Define footer. Just like header, but appears at the bot-
tom of each page. A centered page number within parentheses:
cha
[n] Next page. This command forces the printer to skip to
the next page, regardless of the position on the current page.
Recreations and Applications 1

Other Commands
These commands do not change printer variables, so they are
usually embedded within a line.
[u] Underline—place on each side of a word or phrase to
underline. It works by backspacing and overstriking an under-
line symbol on top of each character. Some printers, including
the VIC 1525, do not support the backspace command, so
underlining will not work on these printers.
[c] Center—place this at the start of a line you wish to
center. Remember to end the line with RETURN.
[e] Edge right—like center, but will block the line to the
edge of the right margin.
[#] Page number—When SpeedScript encounters this
symbol, it prints the current page number.
User-Definable Codes
Many printers use special so-called escape sequences to con-
trol printer functions such as automatic underlining, boldface,
italics, super/subscripting, elongated, condensed, etc. These
codes are either ASCII numbers less than 32 (control codes) or
are triggered by an ESCape character, CHR$(27), followed by
a letter or symbol. For example, for the Epson MX-80 with
Graftrax, italics is turned on with ESC 4. You should study
your manuals to learn how to use these codes. Since most of
the control codes and the escape character are not available
from the keyboard, SpeedScript lets you define the format
commands 1-9.
If you enter [1]=65, then every time the reverse video [1]
is encountered during printing, that character (65 is the letter
A in ASCII) is sent to the printer. For example, SpeedScript
uses the back-arrow for a carriage return mark, so you can’t
directly cause a back-arrow to print on the printer. Instead,
you can look up the ASCII value of the back-arrow, which is
95. You would enter [1]=95, say, at the top of your document.
Then, any place you want to print a back-arrow, just embed a
[1] in your text. Refer to Appendix F, “ASCII Codes”, for the
ASCII values of the 64’s characters and graphics symbols. The
first four numbers are predefined so that you don’t have to set
them, but you can change their definition:
[1]=27 (escape), [2]=14 (elongated, most printers),
[3]=15 (elongated off), [4]=18 (condensed).
A fascinating possibility is to trigger the bit graphics

15
yuaumno0q
ydeisereg JO PU eSIIA JIA d
sadeds
IojoD Jojo),
eT aouajuag nse dyisiQ —-Suzzayja‘]— punoi8ypeg ( Se aeaiostan OL 05) IO ‘1aM0T ¢ Hesuy
cae snorAalg OL, 05 eIdeIeg puq a8ueys ee P: za OL aaaan . hay
on M ue
*LIIHS/M soury) {pueurw05)
wysTy 39U9}UIG 1X9N siayeIeYD jonuo>
pOsthS) ‘:peLAIHSuUN esodsues], 1aj}uq OL
*?PeLAIHSUN umog PIOH
1 Recreations and Applications

dei3ere, JosmpD Jepu


GF Aen POL IV esesq era iayng Aroparq
Josin> puryag *LaTHS/™ a iitghiy ate O/UOQ (2A21}2yY) Hesuy ASIC ‘piom aserq TAL WIM
JapereyD ajajaq 9219S JO doy, ASIC PUSS =apo Hasul ‘goedsypeg
LATHSUN
‘PS
:PaLAIHSuN
pesajuqWIM TAL
spueurus0D poiay27]

16
dey
pseoghoy *[
e1ns17
Recreations and Applications 1

capability of your printer. For example, you could define spe-


cial characters. On the VIC 1525, you could send a graphic
box (for a checklist perhaps) with:
N= SF-1SK=Z55L=193
iuaaasss Toothpaste
This would appear on the printer as:
O Toothpaste

Printer Compatibility
SpeedScript works best, of course, with a standard Com-
modore printer. However, we have used it with several other
printers such as the Epson MX-80, an Okidata Microline 82A,
and the Leading Edge Prowriter (NEC 8023), via an appro-
priate interface. The interfaces I’ve used are the Cardco Card/
Print and the Tymac Connection. Any interface that works
through the Commodore serial port should be fine.
SpeedScript will probably not work with an RS-232 printer
attached to the modem/user port. SpeedScript may operate
with some interfaces which emulate a Centronics port on the
user port via software, as long as the software does not con-
flict with SpeedScript. If you can get your printer to work fine
with CTRL-P, skip the next few paragraphs to avoid confusion.
The Commodore printers and most interfaces use a device
number of 4. (Other device numbers are 1 for the tape drive
and 8 for the disk drive). If you have more than one printer
attached with different device numbers, you can enter this
number by holding down SHIFT while you press CTRL-P.
You'll be asked to enter the device number and the secondary
address. Incidentally, you can get a rough idea of page breaks
before printing by using a device number of 3, which causes
output to go to the screen.
The secondary address is a command number for the
printer. For Commodore printers or interfaces which emulate
the Commodore printer, the secondary address should be 7,
which signifies lowercase mode. The default device number, 4,
and the default secondary address, 7, are automatic when you
press CTRL-P without holding down SHIFT.
If your interface cannot even partially emulate a Com-
modore printer, you will have a few problems. First of all, the
numbers Commodore uses to describe characters, called

17
1 Recreations and Applications

PETASCII by some, do not correspond with standard ASCII,


which most non-Commodore printers use. The result is usually
that upper- and lowercase come out switched. SpeedScript lets
you get around this if you place a format [a] at the top of your
file.
You also need to use the [a] if you want to bypass the
emulation offered by the interface. You may do this to be able
to activate your printer’s special function codes which are of-
ten intercepted and interpreted by the interface. You will also
have to use a different secondary address. I'll have to bow out
and suggest you scrutinize both your printer’s manual and
that of the interface.
Pinfeed Versus Single Sheet
The pinfeed or tractor feed is the cheapest and most common
paper delivery system for printers. Some printers, however,
have a platen like a typewriter and can accept single sheets of
paper, such as stationery or company letterhead paper. Nor-
mally, SpeedScript prints continuously, skipping over the
perforation that divides continuous pinfeed paper.
If you are using single sheets of paper, you need
SpeedScript to stop at the end of each page, tell you to insert
a new sheet, then continue. If you place a reverse video [w]
(for Wait) at the top of your file (again, use CTRL-English
pound sign to do this), SpeedScript will do just that. When
you get to the end of the page, insert a new sheet, then press
RETURN to continue printing.
Table 2, after the program listing, provides a quick-
reference card for all formatting commands.
As you can tell, SpeedScript is a truly comprehensive
word processor. Although it’s ultimately easy to use, it may
take you a while to master all the features and variations. I
hope your adventure will prove to be fascinating and fruitful.

SpeedScript
2049 :811,908,919,908,158,058, 238
2055 :048,054,049,808, 080,800,158
2061 :832,1983,009,876,193,809,179
2067 :165,251,141,851,988,165,832
2073 :252,141,952,008,165, 253,128
2079 :141,954,008,165, 254,141,026
2085 :055,908,166,181, 248,032,207

18
Recreations and Applications 1

2091 :169,800,141,195,026,168,222
2697 2900,185,914,939,153,813,197
21983 2039, 200, 204,195,826, 208,159
2189 :244,238,052,008, 238,955,128
2115 2808, 224,008, 240,987, 202,236
2121 ?208,224,165,180, 268,222,800
2027 :996,165,181,178,005,188,188
2:11.33 :208,001,8096,924,138,101,141
239) 2252,141,123,988,165, 251,887
2145 2141,122,008,924,138,191,119
Paalyoy 2254,141,126,908,165, 253,826
257 2141,125,008,232,164,188,191
2163 2208, 904, 248,013,168,255,227
2169 :185,080,028,153,981,8028,984
2275 2136,192, 255, 2808, 245, 206, 989
2181 :123,908,206,126,908, 202,838
2187 2208, 234,096,169,048,133,251
2193 2195,133,020,169,904,133,931
299 311 96)5:169;,216, 1337,02i%,, 17/3 7,,035
2265 319170267, 133,055), 173), 92,003
22 :026,133,156,162,901,173,946
2219 :194,026,133,912,173, 284,143
2223 2@26,141,032, 208,168,880, 2308
2229) :173,203,026,145,820,177,157
2235 155,153, 205,826, 208,841,199
2241 2127,201,031,248,819,192,235
2247 2940, 208, 235,136,177,155,126
2253 2@41,127,201,032,240,9005,983
2259 2136, 208, 245,160,939, 298,175
2265 :132,167,136,185,2805,826,044
2:145,195,136,016, 248,164,193
2167,024,152,191,155,1337,,193
2155,165,156,105,000,133, 181
:156,152,157,960,083,192,193
2940, 240,008, 169,032,145,113
2195,200,076, 246,008,024, 234
2:165,195,195,840,133,195,968
2133,020,144,004,230,196,224
22308,021, 232,224,625, 246,219
:903,076,179,008,165,155,995
:141,201,026,165,156,141,989
:202,026,096,169,008,133,147
:155,141,191,026,1417, 197,122
:926,133,938,169,929,133,961
:156,141,192,926,141,198,137
2926,133,039,169,932,162,196
2179,,160,255,, 198,156), 145),,1:32
2155, 290, 239,156,145,155,886
2208, 208, 251,230,156, 282,842
:208,246,145,155,996,133,848

19
1 Recreations and Applications

2391 :167,132,168,168,968,177,123
2397 2167,248,006,932,2198,255,235
2463 :200,208,246,996,169,912, 086
2499 :141,204,926,169,938,133,9848
2415 :@01,169,811,141, 283,626,150
2421 2932,036,909,169,8900,141,248
2427 :194,826,832,115,815,169,162
2433 2255,141,138,002,832,245,174
2439 :@12,032,158,889,169,169,164
2445 :169,025,032,086,099,238,179
2451 :193,026,996,932,166,009,157
2457 :169,898,168,025,032,886, 283
2463 :8@89,169,009,141,193,926,185
2469 :996,162,039,169,932,157,052
2475 2880 ,004,262,016,250,169,644
2481 :919,076,210,255,072,941,882
2487 2128,074,133,167,194,641,862
2493 :863,905,167,096,160,908,168
2499 :177,838,133,8002,168,008,193
2585 :177,038,073,128,145,638,832
25 2032,142,008,9032,228, 255,136
2517 :208,013,165,162,041,016,9059
2523 2248,245,169,900,133,162,144
2529 :876,199,909,170,160,900,071
2539 2165,9802,145,8038, 224,695,132
2541 :208,9812,032,160,911,169,961
2547 :932,160,0900,145,9038,876,182
2553 :193,089,173,193,826,248,959
2559 :007,138,8072,832,158,009,151
2565 :194,178,138,201,013,208,871
2572 20@02,162,895,138,041,127,964
PAU :201,032,144,078,224,160, 680
2583 :208,002,162,032,138,072,125
2589 :173,194,926,240,0903,032,185
2595 2149,914,194,932,181,889, 983
2681 :160,009,145,038,832,142,946
2687 :0@08,956,165,9038, 237,197, 236
2613 2026,133,167,165,939, 237,852
2619 :198,826,005,167,144,914,191
2625 :165,038,195,008,141,197,199
2631 :926,165,939,195,000,141,035
2637 :198,826, 238,938, 208,902,811
2643 2238,039,032,231,018,076,189
2649 2193,009,138,174,125,918,226
2655 2221,125,0108, 248,686, 262,131
2661 2208,248,076,193,009, 282,813
2667 :138,910,178,169,80809,972,163
2673 :169,192,8972,189,162,919,139
2679 :072,189,161,819,872,896, 207
2685 :935,829,157,137,133,802,196

20
Recreations and Applications 1

2691 2912,138,134,920,148,084,875
2697 2819, 889,147,135,139,985,979
2783 2136,149,022,145,817,159,258
2769 2818,924,826,816,028,030,935
215 :086,881,811,988, 031,083,215
2721 2159,011,159,911,178,@11,161
2727 :227,811,054,812,966,912,037
2733 2080,012,179,812,231,813,188
21359 :139,814,914,814, 983,014, 281
2745 :201,814,225,814,253,014,138
2751 :@24,815,185,815,222,817,157
2757 :205,016,843,8018,088,912,959
2763 :179,@12,111,918,118,919,148
2769 2823 ,028,8028,912,198,829,164
2/75 :186,917,112,023,002,014,957
2781 2839,028,244,012,215,923,906
2787 2057,8@25,122,814,832,071,936
293 2011,056,165,8038, 237,191,163
2799 :826,133,167,165,839, 237,238
2895 2192,026,905,167,176,030,873
2811 :@56,173,191,826, 233,000,162
2817 :133,167,173,192,926, 233,157
2823 2829,985,167,249,813,165,114
2829 2938,141,191,926,165,939,191
2835 :141,192,026,032,142,088,948
2841 2956,173,201,026, 229,038,236
2847 :133,155,173,202,926,229,181
2853 2039,133,156,005,155, 248,253
2859 :@02,176,024,824,173,191,121
2865 :926,199,861,903,141,191,968
2871 :@26,173,192,8926,195,8900,965
2877 2141,192,8026,932,142,008,990
2883 :076,825,011,996,956,173,248
2889 :197,026,233,008,133,167,961
2895 :173,198,826, 233, 287,805,153
2961 :167,144,018,169,908,141, 204
2967 :197,826,169, 207,141,198,995
2913 2026 ,956,165,8038, 233,008,193
2919 2133, 167,165,839, 233,929,191
2925 :805,167,176,909,169,909,123
2932 :133,038,169,929,133,039,144
2937 2096 ,056,165,938, 237,197,142
2943 :826,133,167,165,839,237,126
2949 :198,926,905,167,176,901,194
2955. :996,173,197,826,133,938,034
2961 :173,198,926,133,039,8996,842
2967 :238,8938, 208,002, 230,039,130
2973 :076,231,918,165,938, 208,117
2979 :802,198,039,198,038,976, 262

21
1 Recreations and Applications

2985 :231,010,165,038,133,155,133
29 On: :165,939,133,156,198,156, 254
2997 2160,255,177,155,2801,932,137
3683 2240,004, 201,831,208, 803,1986
3669 2136, 298,243,177,155, 201,833
3815 :@32,240,008, 201,031,248,183
3821 2@04,136, 208, 243,8996,132,8808
3827 :167,0956,165,155,181,167, 254
3833 2133,038,165,156,195,008,946
3839 2133,039,076,231,910,160,184
3645 :900,177,038,201,032,248,149
3851 2888, 201,031,240,004, 208,151
3657 2208,243,096,290,240,025,229
3963 2177,038, 201,032,249, 247,158
3869 :201,031,248,243,024,152,120
3875 :181,938,133,938,165,939, 695
3881 2105,900,133,8039,076,231,981
3887 :010,173,197,926,133,638,989
3893 2173,198,626,133,039,076,154
3699 :@13,012,169,000,141,191,941
3185 2826,173,198,026,956, 233,233
splot :@84,201,8029,176,982,169,198
3117 2029,141,192,826,932,142,995
3123 :088,076,016,012, 238, 204,993
3129 2926,173,204,8026,041,815,030
3135 2141, 2904,026,9096, 238, 203, 283
3141 :826,173,203,026,941,015,941
3147 2141,203,026,076,142,008,159
3153 2165,038,133,155,165,939,868
B59 2133,156,198,156,160, 255,121
3165 2177,155,201,946, 240,812,156
SyilgAl :201,933,240,008, 201,063,877
SLT. :240,004,201,031,208,904,8025
3183 2136, 208,235,996,177,155,994
3189 :201,046, 240,026, 201,833,996
395 2240,9022, 201,063, 240,018,139
3281 2201,031,240,914,136,208,191
3267 :235,198,156,165,156, 201,222
3213 2008,176,227,076,169,812,833
3219 :132,167,198,167, 200,248,227
3225 218,177,155, 281,032, 248, 208
3231 :247,136,076,219,811,164,235
3237 2167,8076,115,812,169,009,192
3243 2133,038,169,029,133,039, 200
3249 2976,231,018,160,009,177,963
3259 2838, 201,946, 248,829, 201,178
3261 2033,249,025,201,9063, 248,223
3267 2@21,281,031,248,817, 208,137
3273 2208,235,238,839,165,8639,093
3279 2205,198,826,249,226,144,222

22
Recreations and Applications 1

:224,976,916,912, 200,240, 213


:258,177,838, 201,032, 248,133
:247,281,8046, 248, 243,201,123
2033,248, 239, 201,963,248, 223
:235,281,9031,248,231,8976,227
:6@81,012,169,900,141,059,113
2028,169,208,141,069,928,115
:@32,166,009,169,129,168,152
2625,032,086,8009,169,801,071
2141,193,026,096,956,165,176
2938,233,000,133,167,165,241
2939,233,929,885,167,2808,192
:0@63,104,194,996,165,938,9827
2133, 251,165,839,133,252,249
:696,056,165,938,133,253,814
:@73,255,181,251,141,963,163
2628,165,939,133,254,973,233
:255,191,252,141,964,928,132
2165,251,141,065,928,165,112
2252,141,966,828,165, 253, 298
2141 ,967,928,133,251,165,994
:254,141,968,928,133,252,191
2624,173,964,928,1899,8960,935
2:@28,201,255,144,8020,032,087
:166,9609,169,144,168,025,906
:@32,086,009,169,001,141,933
:193,026,169,908,133,198,964
:096,173,059,928,133, 253,993
2173,060,028,133,254,173,178
:063,028,133,180,024,199,156
:959,028,141,059,628,173,113
2964,028,133,181,169,960, 206
2:928,141,060,028,169,8908, 963
:141,026, 208,169,032,133,9096
:901,032,019,908,169,038,172
:133,001,169,961,141,026,126
:208,173,065,928,133,251,097
:173,966,928, 133, 252,173,236
2967,028,133,253,173,068,139
:@28,133,254,056,173,197,008
3926, 229, 253), B33 USS, h//3,67
2198,026,229, 254,133,181, 289
2:932,019,008,056,173,197,182
2026, 237,963,928,141,197,139
:026,173,198,8026,237,964,177
:828,141,198,926,996,032,236
2@15,813,032,168,011,932,248
2@42,013,056,173,059,928,098
:233,081,141,059,028,173,112
3579 :869,028, 233,000,141,8969,095

23
1 Recreations and Applications

3585 2828,096,032,151,9811,032,995
3591 2@15,013,032,168,811,076,958
3597 3@42,013,032,245,012,169,914
3683 2@62,133,012,032,166,009,117
3689 :169,156,160,025,032,886,141
3615 2009,032,228,255, 249,251,922
3621 2072,032,150,089,104,041,189
3627 2191, 201,023, 208,809,032,195
3633 :915,013,032,171,011,976,111
3639 :842,913,201,919, 208,009,835
3645 20@32,015,8913,032,9081,812,246
3651 2876,942,813, 201,016, 288,111
3657 2089,032,015,013,032,825,199
3663 2815,976,942,013,996,056,121
3669 2165,938,237,191,026,133,107
3675 2167,165,039,237,192,026,149
3681 :005,167,248,011,173,191,116
3687 :826,133,938,173,192,026,179
3693 2133,939,996,169,988,133,167
3699 2@38,169,829,133,0939,876,687
3785 :231,9010,160,905,140,985, 240
3711 2928,032,140,014,172,885,886
3717 :028,136,208,244,076,228,929
3723 :011,924,165,638,133, 251,249
3729 :105,981,133,253,165,939,973
3735 2133,252,105,900,133, 254,904
3741 2956,173,197,826,229,253,067
3747 :133,188,173,198,826,229,878
3753 :254,133,181,201,255, 208,121
3759 :986,169,001,133,188, 239,126
3765 2181,932,988,908,169,900,130
3771 2169,032,145,938, 238,197,238
3777 2026,208,003,238,198,026,124
3783 :076,9813,012,173,194,826,181
3789 :073,@14,141,194,026,996, 237
3795 :169,171,168,825,032,986,886
3801 :009,0932,228,255,240,251,288
3807 :201,989,896,169,002,133,145
3813 :912,932,166,909,169,194,943
3819 :169,925,832,886,009,932,067
3825 :211,014,240,903,076,158,167
3831 :889,162,255,154,076,813,148
3837 :998,160,009,177,838,281,869
3843 :031,248,015, 200, 208,247,176
3849 :230,839,165,839,205,198,117
3855 2:026,144,238,076,016,812,015
3861 :200,876,001,012,165,938,801
3867 2133,155,165,839,133,156,0498
3873 2198,156,160,255,177,155,119

24
Recreations and Applications 1

3879 :201,031,248,016,136,192,887
3885 2255,2808,245,198,156,165, 248
3891 2156, 201,029,176,237,976,158
3897 2169,012,056,152,191,155,198
3983 :133,155,169,8890,181,156,899
3989 :133,156,056,165,155,229,195
3915 :838,133,167,165,156,229,195
3921 2039,005,167,288,918,132,138
3927 :167,024,165,155,229,167,226
3933 2133,155,165,156,233,908,167
3939 2133,156,976,043,915,165,175
3945 :155,133,038,165,156,133,117
3951 2839,876,231,818,120,169,244
3957 :127,141,013,228,169,927,846
3963 :141,817,208,169,146,141,177
3969 :820,083,169,815,141,021,242
3975 :963,169,001,141,926,298,171
3981 :141,818,268,988,896,169,993
3987 :@58,164,812, 295,018, 208,044
3993 2208,905,169,901,172,204,144
3999 2826,148,833, 288,141,818, 213
4965 :208,281,801,240,9898,169,224
4911 :@@1,141,9025, 208,076, 188,942
4817 :254,169,981,141,8025, 2088, 207
4923 :076,849,234,173,141,902, 699
4629 :841,081,2808,003,032,245,207
4935 :@12,032,166,889,169, 289,824
4941 :168,025,032,0986,0609,160,161
4647 :908,177,838,9073,128,145,980
4653 2938 ,032,142,988,169,908,081
4959 :177,038,8073,128,145,838,8508
4865 :169,992,133,012,832,228,933
4071 2255,248,251,089,864, 201,227
4077 :987,288,809,032,822,016,999
4983 :032,228,011,8976,937,916,131
4689 :281,883,288,009,032,022,036
4695 :016,932,189,812,976,937,096
4161 :816,291,988,288,989,8032,039
4187 :022,816,032,254,814,8976,169
4113 :037,816,976,158,009,165,214
4119 :938,133,253,141,054,827,157
4125 2165 ,039,133,254,141,055,948
4131 :027,996,056,165,938,133,938
4137 :251,237,054,8027,141,963,046
4143 :028,165,939,133, 252,237,133
4149 :055,027,141,864,828,032,144
4155 2965,013,173,054,827,133,912
4161 :038,173,955,927,133,839,9818
4167 :932,142,0988,876, 296,815,838
4173 :169,938,229,211,141,199,949

25
1 Recreations and Applications

4179 2626,169,900,141,988,928,923
4185 2160,990,169,156,032,219,948
4191 :255,169,918,932,219,255,010
4197 :169,032,9032,210,255,169, 280
4283 2157,032,210,255,148,28998,9077
4269 2026,832,228,255, 240,251,121
4215 2172, 208,026,133,167,169,218
4221 2146,932,210,255,169,932,201
4227 :@32,218,255,169,157,032, 218
4233 2219,255,169,155,032,210,144
4239 2255,165,167, 281,913,240, 160
4245 2846,281,028,208,8015,136,987
4251 2816,004, 200,076,091 ,816,846
4257 :169,157,032,210,255,076,836
4263 :991,016,9041,127, 201,032,163
4269 2144,172,204,199,826, 240,134
4275 :167,165,167,153, 245,926,978
4281 :032,2180,255,169,899,133,216
4287 2212, 2908,876,091,916,932,9050
4293 :218,255,169,008,153,245, 205
4299 :@26,152,696,032,166,989,172
4305 :169,246,168,925,032,086,159
4311 :0@89,032,051,817,176,931,9819
4317 2169,900,133,155,169,929,168
4323 :133,156,174,197,026,172,961
4329 :198,826,169,155,832,216,005
4335 :255,176,910,032,183, 255,126
4341 :041,191,208,003,976,8028,024
4347 2018, 240,039,173,059,9017,8208
4353 :201,9608,144,006,032,174,9054
4359 2823,076,028,617,173,958,118
4365 2917,201,001,240,249,832,241
4371 :166,009,169,252,160,825,9632
4377 2632,886,009,932,115,915,858
4383 2169,001,141,193,926,996,145
4389 2932,166,909,169,007,168,868
4395 2826,032,8086,089,076,928,044
4491 2817,008,032,9077,8016,248,183
4497 2024,169,038,160,026,032,248
4413 2986 ,999,032,228,255,249,143
4419 2251,162,008, 201,968,248, 229
4425 2012,162,001,201,084,248,005
4431 2986,032,158,009,184,184,228
4437 :996,142,058,917,169,901,948
4443 :169,000,032,186,255,168,116
4449 2980 ,224,001,240,042,185,9021
4455 :245,026, 201,064, 208,007,886
4461 2185,246,026,201,058, 248,841
4467 :028,169,048,141,029,927,045
4473 :169,958,141,030,8027,185,219

26
Recreations and Applications 1

2245,026,153,9031,027, 200,041
2204,200,026,144,244, 249,167
2242, 200,876,156,917,185,247
2245 ,026,153,029,8027, 200,957
2284,200,026, 208, 244,149,149
2953,027,032,166,969,169,181
:245,1608,8926,832,886,8989, 209
:173,053,827,162,829,160,065
2027,8032,189,255,169,813,992
:032,218,255,076,886,618, 090
:@32,166,089,169, 241,160,196
2825,032,8986,069,032,228,093
2255,248, 251,032,181,0809,143
:909,128,8972,173,194,026,039
2240 ,6063,032,140,014,932,1608
2158,009,1894,076,9841,8010,095
256,165,838, 233,008,133,889
2167,165,939,233,8029,005,899
:167,240,084,169,005,133,185
2012,032,166,009,169,058,175
:160,026,032,886,009,032,8808
2951,017,165,912,281,005,192
248,003 ,8932,036,009,169,236
:090,166,838,164,039,8032,192
:213,255,144,003,076, 252,190
:916,142,197,826,149,198,228
2@26,032,231,255,8032,166,981
:009,169,928,160,826,832,281
:886,809,8976,928,8017,832,831
:166,8909,169,964,169,026,127
:832,086,089,8032,051,817,022
:169,001,162,000,168,829,066
2832, 213, 255,032,183, 255,999
:941,191,240,211,032,166,182
2909,169,015,160,826,032, 230
7986 ,089,0976,928,817,128,161
:169,900,141,826, 208,141,904
2033, 208,169,849,141,928, 201
:@03,169,234,141,021,993,158
:169,255,141,013,220,888,223
:996,169,147,832,218, 255,252
:169,8913,032,218,255,932,860
:886,018,032,162,918,169,996
2013,032,210,255,169,972,112
2160 ,8926,032,886,009,032,224
3228,255, 201,013,208, 249,015
2@32,115,815,8976,158,089,032
2032,204,255,169,961,032,078
2195,255,896,032, 231,255,199
:169,001,162,908,168,0900,153

27
1 Recreations and Applications

4779 232,186, 255,169,092,162, 209


4785 2087,168,626,032,189,255,158
4791 £932,192, 255,176, 221,162,197
4797 20@01,032,198,255,832,207,146
4863 2255,032,2807,255,032,207,159
4809 2255,032,183,255,208, 202,056
4815 3@32,207,255,249,197,8032,146
2204,255,032,228,255,281,198
2832,208,905,032,228,255,211
:246,251,162,001,932,198,985
2255,032,207,255,972,032,0869
:207,255,168,184,178,152,813
:169,055,132,001,932,205,860
:189,160,954,132,001,169,186
232,032,210, 255,8032,207,255
2255,240,006,032,219,255,235
:076,003,8019,169,813,932,967
2219,255,076,199,818,162,169
:8@60,142,056,027,142,057,191
2027,142,058,827,056,177,904
2155,233,048,144,042,281,890
2910,176,038,014,056,927,196
:846,057,8027,014,8056,927,918
2@46,057,827,014,056,027,8024
2:846,057,927,014,856,9027,83G
2846,957,027,913,056,827,935
:141,956,027, 200, 208,212,147
:230,156,976,033,919,248,971
2173,056,027,813,057,027,180
2240,023,956,173,056,927,152
2233,001,141,956,827,173,214
2057,827,233,900,141,057,184
2827,238,958,027,976,083,194
:@19,173,058,027,216,096,190
2056,173,959,028, 233,000,156
2141 ,@61,028,173,968,928,1904
:233,208,141,062,028,013,048
2961,028,208,8016,032,166,136
:009,169,097,169,026,932,124
2986 ,909,169,901,141,193,236
2926,996,924,165,038,133,125
2251,199,061,928,133,253,228
:165,039,133,252,1809,962,159
2928,133,254,056,173,197,246
2026, 229, 251,133,180,173,147
2198,026,229,252,133,181,189
:0@24,101, 254,201, 207,144,998
2:916,932,166,989,169,989,166
:160,026,032,886,909,169,173
2:901,141,193,926,996,832,186
Recreations and Applications 1

59879 :@88,808,824,173,961,828,677
5885 :133,188,199,197,026,141,239
5691 :197,826,173,962,028,133,978
5897 :181,189,198,026,141,198,962
5193 2026, 165,838,133, 253,165,251
5169 :839,133,254,169,008,133,205
5 E15 3251,169, 208,133, 252,169,153
5121 :8@00,141,026,208,169,932,665
5127 3133,901,032,019,0908,169,113
5133 2038,133,0801,169,001,141, 240
5139 2826, 208,976,231,019,1608,218
5145 2:900,177,838,178,200,177,819
5151 :038,136,145,038, 200,138,214
5USa 2145,038,996,160,009,177,141
5163 :038,041,063,240,0190,201,124
5169 :027,176,906,177,8038,073,934
DE75 :@64,145,038,976,151,9011,928
5181 2133,167,041,964-919,005,225
5187 :167,841,191,133,167,841,9839
5193 2032,073,032,018,995,167,136
D199 2896,885,875,866,885,858,128
5205 2002 ,001,027,255,6015,918,147
5211 2000 ,900,000,000,000,832,123
52 :166,999,169,141,160,926, 980
5223 2876,086,8009,976,129,021,244
5229 :169,0984,141,989,928,168,188
5235 :@87,173,141,002,041,001,224
5241 2246 ,054,032,166,099,169,023
5247 :116,168,926,032,886,009,8044
D203 2032,228,255,249,251,056,171
5259 :233,048,201,003,144,217,217
5265 2201 ,088,176,213,141,089,285
5271 2828,932,166,009,169,125,168
5277 :160,026,032,086,989,032,246
5283 2228,255, 248,251,056, 233,146
5289 2048 ,948,198,201,810,176,974
5295 :186,168,169,001,174,889,194
5361 2028,032,186,255,169,900,9883
5307 :@32,189,255,632,996,8920,843
5313 2032,192,255,162,901,032,9899
5319 :201,255,144,083,076,129,239
5325 :@21,169,900,133,155,169,984
5331 :829,133,156,162,000,142,965
5337 :070,028,142,069,028,142,184
5343 2998 ,8928,142,891,028,142, 232
5349 2983 ,028,189,980,020,157,818
5355 075,928, 232,224,087, 208,241
5361 2245,169,255,141,984,028,139
5367 :160,908,177,155,816,8983,246
5373 2876 ,068,022,201,831,248,123

29
1 Recreations and Applications

5379 2034,153,859,927, 200,238,202


5385 2982,828,173,882,028,205,095
539) :976,028,144,230,136,140,901
5397. :196,826,177,155,201,832,9498
5493 2248,909,286,9882,9828,136,216
5499 3208,244,172,196,926,148,251
5415 2196,826,152,956,101,155, 213
5421 2133,155,165,156,195,808, 247
5427 2133,156,168,900,173,084,245
5433 2@28,201,255,208,9093,932,016
5439 :236,021,832,833,022,173,968
5445 :196,826,141,195,826,169,954
5451 :959,133,169,169,627,133,253
5457 2170,032,1809,924,8032,048, 240
5463 2:022,173,9084,028, 285,079,166
5469 2628,144,803,032,148,021,213
5475 256,165,155, 237,197,826,167
5481 2133,167,165,156, 237,198,137
5487 :@26,885,167,240,029,144, 219
5493 :027,169,900,141,869,928,839
5499 :141,978,028,032,148,021,059
55@5 232,225,255, 248,251,169,921
55 EL 2@@01,032,195, 255,032,204, 886
5517 2255,076,150,009,976,247,186
5523 2:8@20,956,173,8977,8028,
237,226
5529 :084,028,168,136,136,240,177
5535 2819,048,008,169,013,932,183
5541 2218,255,136,298,248,173,115
5547 :870,028,249,019,141,195,896
5553 2026,173,073,028,133,169,811
5559 2173,974,928,133,170,032,9825
5565 20@33,022,032,1909,024,169,9066
S571 2013,032,2190,255,032,218,179
SS ile 2255,032,210,255,173,081,183
5583 2928, 208,026,032, 204,255,192
5589 2032,166,969,169,1580,168,131
5595 2826,032,086,009,032,228,120
5681 2255,240,251,832,096,820,095
56087 2162,001,032,201,255,238,096
5613 2083 ,828,173,869,028,240, 090
5619 2:019,141,195,926,173,071,100
5625 :928,133,169,173,072,028,084
5631 2133,178,032,033,022,032,165
5637 :199,924,169,813,9032,210,050
5643 :255,172,878,028,149, 084,900
5649 728,136,136, 240,010,048,183
5655 2:988,169,013,032,210,255,198
5661 :136,288,248,096,169,932,150
5667 :172,975,9828,148,082,028,948
5673 :032,210,255,136,208, 250,108

30
Recreations and Applications 1

5679 :896,172,080,028,024,152,887
5685 2199,084,028,141,984,928,015
5691 2169,013,932,219, 255,136,196
5697 :208,250,096,141,087,028,107
5763 2@41,127,8032,061,920,201,041
5769 2:849,144,007,201,958,176, 208
57E5 2@03,076,089,023,174,158,985
Son: 2022,221,158,822, 240,012,252
52 2202, 208,248, 206,082,8028,945
5733 :173,987,028,076,900,021,230
i: :2802,138,910,170,140,985,884
5745 :6@28,169,6022,072,169,128,189
Siow: 2072,189,170,922,072,189,965
af SS4/ :169,022,072,096,956,173,281
5763 :@85,028,101,155,133,155,02¢
5769 :165,156,105,099,133,156,984
Sia :076,247,820, 200,177,155,250
5ISE 2201 ,031,249,001,136,149,130
5787 2085,828,096,010,087,965,014
57.93 2076,882,084,066,983,9078,118
SUES) 20@72,078,188,9022,197,9022,226
5885 2205 ,022,215,022,225,022,116
5811 2235,022,245,922, 255,022,212
5817 2014,023,051,023,169,080, 289
5823 :141,9081,028,200,076,146,995
5829 2022,169,001,141,090,028,136
5835 :076,146,822,200,032,022,189
5841 :019,141,075,028,076,146,182
5847 2822, 200,032,022,819,141,139
5853 :976,928,076,146,8022,200,001
5859 :032,022,019,141,8978,928,935
5865 2976,146,022,200,6032,922,219
5871 :819,141,979,028,076,146,216
ei) 7/ 2022,200,932,022,019,141,169
5883 2:989,028,076,146,922,149,231
5889 :986,928,032,148,021,172,232
5895 :886,828,140,885,828,976,194
5981 :146,022,056,152,181,155,133
5987 :141,971,8028,165,156,1985,173
5913 :0@00,141,072,028,032,843,985
5919 :823,056,152,237,985,028,190
5925 :141,969,928,8976,146,922; 907
5931 : 208,177,155, 201,831,288, 247
5937, :249,136,996,956,152,191,871
5943 2155,141,073,8028,165,156,80085
5949 2105,000,141,074,028,032,185
5955 2943,023,056,152,237,085,151
5961 :028,141,0708,028,976,146,950
5967 2922, 200,177,155, 201,961,127
5973 2249 ,004,136,076,191,922,152

31
1 Recreations and Applications

SES: 2290 ,032,022,819,872,173,897


5985 2087,828,041,915,170,202,128
5991 2184,157,987,928,932,146,137
5997 2022 ,076,129,822,032,231,199
6983 2255,169,608,832,189,255,247
6889 2169,915,162,8008,160,815,138
6615 2032, 186, 255,032,192,255,055
6821 :144,001,8096,032,166,909,969
6027 :169,962,032,219,255,9832,131
6833 2077 ,016,248,025,162,915,168
6839 232,201, 255,176,012,169,228
6845 2245,168,626,9032,986,909, 203
6051 2169,013,032,210,255,932,106
6057 2231,255,876,150,8809,932,154
6963 :231,255,169,800,032,189,927
6869 :255,169,915,162,988,169,182
6075 2@15,032,186,255,932,192,131
6881 2255,176,228,032,166,999,935
6887 2162,915,9032,198,255,9832,125
6693 2077,@16,932,231,255,169,217
6999 :901,141,193,026,996,173,973
6195 2141 ,002,201,005,248,905,043
6111 2173,988,028,208,037,9032,821
6117 :166,909,169,171,160,026,162
6123 2@32,086,089,032,077,016,231
6129 :208,8803,0976,150,009,169,888
6135 :901,141,088,928,141,193,071
6141 :026,169,000,133,155,169,137
6147 :029,133,156,976,022,024,187
6153 2165,938,133,155,165,039,192
6159 :133,156,160,001,976,024,953
6165 2024,160,000,162,000,189,9044
6171 2245,026,032,181,909,209,217
6177 2155,240,002,162,255,2800,923
6183 :268,011,230,156,165,156,197
6189 :205,198,026,240,002,176,124
6195 235,232,236, 208,026, 208,220
6281 :224,024,152,1801,155,133,878
6207 :@38,165,156,105,000,133,148
6213 2039,056,165,938,237,200,936
6219 :926,133,038,165,039, 233,197
6225 2088 ,133,039,8076,231,818,958
6231 2832,166,009,169,181,169,936
6237 2026 ,032,086,909,169,8901,160
6243 :141,193,926,169,080,141,991
6249 2088,028,996,896,160,900,961
6255 2204,195,026,240,248,177,177

32
Recreations and Applications 1

6261 :169,848, 038,832,861 ,028,229


6267 :032,026,825,032,219,255,191
6273 :173,891,628,240,018,169,872
6279 : 088,832,218, 255,169, 895,136
6285 :032,218, 255,832,225, 255,126
6291 :288,085,104,184,076,129,905
6297 :021,200,076,111,824,148,213
6383 :085 ,028,041,127,832,861,021
6369 :926,261,049,144,017, 281,829
6315 :058,176,813,041,015,170,132
6321 :202,189,087,820,032,218,149
6327 :255,076,154,024, 261,867,192
6333 2208, 826,056,169, 888,237,197
6339 :195,826,874,956, 237,875,998
6345 :028,168,169,032,832, 218,872
6351 :255,136, 208, 258,172,885,033
6357 2028 , 076,154,824, 261,869,253
6363 :208,017,856,173,076,828, 909
6369 :237,195,826, 956, 237,075,927
6375 :028,168, 169,032,876, 205,141
6381 :024,281,885,208,008,173,168
6387 :891,0628,873,061,141,891,156
6393 2028, 281,035,248,0803,076,964
6399 2154,924,148,885,828,174,992
6495 :083,928,169,000,168,955,244
6411 :132,081,032,285,189,168,218
6417 :054,132,801,172,885,928,233
6423 :076,154,824,174,098,628,9857
6429 :248,026,133,167,041,127,251
6435 :201,865,144,018, 281,991, 243
6441 :176,814,178,165,167,041,206
6447 :128,073,128,874,074,133,145
6453 :167,138,805,167,096, 932,146
6459 2166, 989,856,169, 908,237,184
6465 2197,026,170,169, 207,237,047
6471 :198,826,168,055,132,881,131
6477 :032,205,189,168,054,132,081
6483 :081,169,801,141,193,826,182
6489 :096,814,088,155,211,088,141
6495 2069, 969,268, 211,867, 882,149
6581 :073 , O80 ,084,832,049,846, 209
6507 :849, 008,832,066, 089, 832,119
6513 :195,072,065,982,076,069,160
6519 : 083, 832,194,682,865,078,141
6525 :078,879,078,008,194,985,127
65351 :070,078, 869, 082,032,195,137
6537 276,869,265, 082,969, 968,054

33
1 Recreations and Applications

6543 :8@00,194,085,876,970,969,119
6549 :082,032,198,085,976,876,186
6555 :@00,196,869,876,069,984,137
6561 2869,032,040,211,0944,215,904
6567 2844, 208,041,900 ,958,932,838
6573 :193,982,969,032,089,879,205
6579 2985,032,083,985,982,969,183
6585 2963 ,032,940,217,847,206,822
6591 2@41,958,008,197, 219,193,122
6597 :211,197,932,193,204,204,214
6693 :@32,212,197,216, 212,888,848
6689 2197,082,065,983,869,032,225
6615 2@40,211,044,215,944, 288, 209
6621 2041 ,958,032,018,219,197,889
6627 :212,213,218,206,146,032,222
6633 2984 ,9079,032,069,988,973,146
6639 2084,000, 203 ,969,089,058, 236
6645 :@09,211,065,8986,969,958,222
6651 2800, 212,8065,988,869,032,197
6657 2197,219,210,207,210,000,811
6663 :211,984,979,088,080,069,9898
6669 2868 ,000,214,969,082,073,907
6675 2070 ,089,032,197,082,982,959
6681 2079,982,900,286,879,032,247
6687 :869,882,082,079,082,983,252
6693 :000,147,032,018,212,146,989
6699 :965,988,869,032,8079,082,194
6785 2932,018,196,146,973,083,985
6711 :875,863,008,204,079,8965,029
6717 :068,058,000,214,969,082,8408
6723 :873,9708,089,058,8088, 208,853
6729 2982,069,083,083,832,018,184
6735 2210,197, 212,213,219, 206,947
6741 2146 ,900,036,848, 206,079,988
6747 2832,218,979,079,877,000,856
6753 :206,079,032,084,069,088,143
6759 :084,8032,073,078,032,8966,212
6765 :885,078,070,069,982,046,819
6771 :800,196,869,986,073,067,894
6777 2969,032,8035,900,211,8069,8625
6783 :867,079,878,068,846,932,241
6789 2193,868,968,082,046,032,119
6795 :035,0080,208,082,073,978,193
6891 2084,073,078,071,000,206,145
6887 2969 ,988,984,032,083,072,967

34
Recreations and Applications 1

6813 :069,869,084,944,032,018,217
6819 2210, 197), 212, 2137, 210, 206,131
6825 :146,000,200,085,978,084,250
6831 :032,970,079,8082,058,800,240
6837 :206,8079,084,032,198,079,091
6843 :085,078,0968,0900,0990,9029,191
6849 7900 ,000,0904,194,005,6029,879
6855 :@36,013,192,032,011,012,239

35
a8we

»
*
Table 1. Clip-Out Quick Reference Card—Editing
Commands

CTRL-A: Change case


CTRL-B: Change background color
CTRL-D: Delete
CTRL-E: Erase
CTRL-H: Hunt
CTRL-I: Insert Mode
CTRL-K: Clear buffer
CTRL-L: Change lettering color
CTRL-P: Print
CTRL-R: Recall buffer
CTRL-V: Verify
CTRL-X: Transpose characters
CTRL-Z: End of document
CTRL-4: Disk directory
CTRL- ft: Send DOS command
CTRL-£: Enter format key
CTRL-=: Free memory
: Next word
: Previous word
: Previous sentence
: Next paragraph
: Previous paragraph
: Load
SIKRKGowMe
: Save
Load
=

Cursor Up: Previous sentence


Cursor Down: Next Sentence
Cursor Left/Right: As implied
SHIFT-CLR/HOME: Erase all
CLR/HOME: Top of screen/top of document
Back-arrow: Backspace
CTRL-Back-arrow: Delete character
RUN/STOP: Insert 5 spaces
nana
nennnnannnn
nna
enna
nn
nnn
ween
ewenn
eee
esses
cee
es
ence
eee
Perr

37
cd saterieth
pot‘aot

nts
¥SAGA.

ea
‘.
a
s
2.)
OP
t
J

4*
.
+

i

";
-,
H
2
a 5
ay
:

+f
,

*
*

:%
:
3
;:

oe
ae

A
Be
eA
Oe
1

1
1

'


1
'
'

1

'
i

1
1
J
'
'
i
1
i
1
1
1

1
1

1
'
'
'

J
a
'
'

i}
i}

iy

Le
sans]
°*7 NCE-dyD UOWIUNY
Avy AejiaaC ‘ s
t ste tsven
ta Qiu ne Ola
: eee
oe pee
an aeydan aictodns leaeinewca
at coadna |
t 1 H tha)
' i] '
‘ ry r
| | LaIHS
H PON i a5! stax jAHPLovvsb
A
| SPE EPL eRe |EPSsTS
iS
Commands
: pi0mM H STSy"ogv! FeGsea.
1S
eae a ey! reas yvSQa ey Bish
| snotaaig
WN ' ES: PSSSR
KU gmh2s
Z|
| PIOM sg} soe yen esse iS|Sbas
:
wees!8 Base
lig t . a

ON H a 6D om
;
' 30
Ppa nee 4 2 o.
ap 7)
3
| snolAalg t =e :
! aouajuag : 2} i
: H ' H
yeN { Ss!
: ydeiseieg
i os! N 292
:
inline
[77.

| snotAalg 1 vues is
|
: ydesereg HH % 1
‘ :
1t U 1
rT
LCCC
TTrrrrrrrrereetete
eCLLLCLL
LLL
LLL!
'Ct
6 T Pp '
; *
H i
‘ dArsg H
' ‘

= °
Table 2. Clip-Out Quick Reference Card—Format

Format commands in column one are entered with CTRL-£.

39
aig secirnne res na Rea
' ae ‘aut *
nearneoe tigi ~ ‘

mises WE res

ae
3 $

vi =
4 *.

-=
-_ -3
6 “63 ;
Pea CASK USE
*
eA, set |
ee ‘eiaoet extivetms i
pas fhe)
‘ 7
ie id Ll
? :
$
teinsr oat
a +S my i
gray oe send z 4

Saal See set age it ®


; sacbeibes ee S bn
ars ?
>
cS)
thins ooed eye tid inésiteb-yeans
tice ee
me
4a
COE
Or
pK araperyyaye Oe ene ee ee ee eeerr ed on at

~
a
piewieansmnatedn
¥ wamitinn wuininninwenomanale ere<< mn latin wien a — rs
* ‘
4
ote nye
Faye oe . ~4
as _

+E
oe

Seuss

somes
an
eee

aioe
Recreations and Applications 1

SPIKE
Eric Brandon

An all-machine-language game, “Spike” pits


you against deadly power spikes on the Grid as
you search for your hidden Commodore 64. The
game is fast-paced, and approaches commercial-
quality software—a game you might expect to
pay $30 or more for.
SS EE EN

It is a dark and stormy night, and you are diligently typing


games into your Commodore 64.
Suddenly, just outside, you see a dazzling flash of light
and almost at once hear the deafening retort of thunder. The
lights dim, flicker, and wink out. A wave of dizziness over-
comes you.
When you regain consciousness, you cannot recognize
your surroundings. ‘This isn’t my computer room,” you think.
A thousand theories about your situation fly through your
head, but none is even close to the terrible truth.
You are trapped inside the Power Grid.
To return to your own world, you must find and encircle
your Commodore 64 computer. It’s not visible from where you
are, but you know it is hidden inside one of the many grid
nodes. Fortunately, you are carrying your pocket sonar, which
always tells you how far from the 64 you are. The shorter the
line displayed by your sonar, the closer you are to escaping.
You soon discover that the Grid is a dangerous place to
be. Deadly power spikes travel up and down the wires.
Touching one of the spikes results in a terrible shock. These
shocks, though powerful, are very short, so you can endure up
to four collisions with the spikes and still stand a chance to
make it home.
Unfortunately, should you successfully reach your 64, you
will find that the magnetic disturbance which trapped you on
the Grid in the first place is worse than ever. You end up on
the Grid again, but now it is coursed by even more power
spikes.
Is there no escape?
41
1 Recreations and Applications

Playing Spike
The recommended way to travel on the Power Grid is with a
joystick in port two. The joystick may seem a bit awkward at
first: Since the Grid is tilted 45 degrees, the four cardinal
directions (up, down, left, right) are likewise tilted. To better
orient yourself, it may help to turn the joystick base to the
same angle.
When “Spike” first starts, you will have to make some
decisions. You must decide the speed of the game and
whether you want the Easy or Hard option. Pressing the RE-
TURN key or the joystick button automatically chooses the
Hard option and a speed of 5. If you want some other option,
press the number of the speed you want (1 to 9) and the E key
for an Easy game.
Another handy feature of Spike is the pause option.
Pressing a SHIFT key pauses the action. Pressing SHIFT/
LOCK freezes the game until SHIFT/LOCK is released.
You start each game with five lives. An indicator at the
top of the screen, labeled STAMINA, keeps track of your
remaining lives, not counting the one currently in play.
Another indicator, SONAR, shows your proximity to your
invisible goal, the hidden Commodore 64 computer. The
shorter the line, the closer you are to the 64.
The LEVEL indicator displays flags to show how many
times you've found the 64 and advanced to a more difficult
power grid.
When you start a new game, the Grid is patrolled by two
power spikes. Another spike joins them on each succeeding
level, up to a maxmium of seven spikes.
To develop a winning strategy, it’s vital to understand
how the scoring works. The screen is divided into 112 grid
nodes (diamond-shaped blocks). Your goal, the Commodore
64, is hidden in one of them, leaving 111 empty nodes. You
gain survival points for traversing the Grid—ten points for
each new side of a node you cross. If you box in a node by
leaving your trail along all four of its sides, the node is colored
blue. You'll want to box in as few nodes as possible, because
it costs you bonus points later.
When you find the Commodore 64 by locating it with
your sonar and encircling its node, you win bonus points and
advance to the next level. The bonus is figured by multiplying
the number of unboxed nodes times the bonus value for the

42
Recreations and Applications 1

current level. The bonus value starts at 40 for level one and
increases by five for each additional level. For instance, if you
find the 64 on level three after boxing in 11 nodes, you would
win 5000 bonus points (100 unboxed nodes x bonus value of
50 = 5000). This would be added to the survival points you
gained while searching the Grid.
A HIGH SCORE indicator keeps track of the best game
played during the current sitting.

Typing Spike
Unavoidably, Spike is a long program—more than 4K of pure
machine language. Normally, it is very difficult to type in such
a program without making a mistake. Also, in the past, a ma-
chine language monitor was necessary to enter such a program
from a published listing in a book or magazine.
However, to make the typing as easy and as foolproof as
possible, ‘“MLX,” a machine language entry program, was
written by Program Editor Charles Brannon to greatly simplify
the task of typing ML programs from listings. It includes an
instant checksum feature which does not let you continue un-
til you’ve typed a line correctly. It also automatically types
commas and lets you break up the job into several sittings.
Please read the directions in Appendix I for using MLX.
And be sure to save MLX, because it will be needed for other
machine language programs in this book.
You'll need to type in a POKE statement in direct mode
(without a line number) before you begin entering Spike. This
line will move down the top of memory to below the Spike
program so that BASIC will not write over Spike as you type
it in.
POKE 52,128:POKE 56,128:CLR
You'll use this statement only while you enter Spike using
MLX. You don’t need it when you enter other machine lan-
guage programs.
This line must be entered before you load and run MLX.
Then you can begin typing in the Spike program. If you enter
Spike in several sessions, turning the computer off in between,
you must type in the above POKE statement each time you
begin entering Spike’s data.
Here is the information you'll need to enter Spike with
MLx:

43
1 Recreations and Applications

Starting address—32768
Ending address—37295
Once Spike is saved on disk or tape, a special procedure
is required to load the program.
For disk, enter:
LOAD”’SPIKE’’,8,1
For tape, enter:
LOADGI5U1
When the program is loaded, run it by entering SYS
32768.
Spike
32768 :169,065,141,198, 207,169,113
32774 :972,141,189,207,9632,919,145
32780 :144,169,907,141,201, 207,113
32786 :169,949,141,200, 207,169,176
32792 :912,141,199,207,169,998, 240
32798 :141,039,208,162,924,157,249
32804 :900,212,202,224,255, 208,113
32819 :248,169,979,141, 254,207,197
32816 :169,120,141, 253, 207,169,983
32822 :255,141,915,212,141,182,232
32828 :207,169,128,141,918, 212,167
32834 :169,964,141,136,902,169,235
32848 :001,141,246, 207,169,919, 987
32846 :932,219,255,169,900,141,117
32852 :932,208,173,014,220,941,984
32858 :254,141,9014,229,165,981,117
32864 :941,251,133,901,160,999,178
32878 :185,889,208,153,900,980, 216
32876 :185,999,2809,153,9089,981,224
32882 :185,900,219,153,9899,982,232
32888 :185,909,211,153,909,983,240
32894 :185,900, 212,153,909, 984,248
32988 :185,900,213,153,9008,985,900
32986 :185,889,214,153,909,086,988
32912 :185,009,215,153,000,987,916
32918 :200,208,205,165,001,909,170
32924 :904,133,961,173,814,220,189
32938 :899,901,141,014, 220,169, 294
32936 :198,141,000,221,169,998,137
32942 :141,924,208,032,183,128,122
32948 :876,219,128,120,169,127,251
32954 :141,913,229,169,001,141,1983
32968 :926,208,169,900,141,018,242

44
Recreations and Applications 1

32966 :208,173,917,208,941,127, 284


32972 :141,917,208,169,119,141,231
32978 :820,903,169,140,141,8621,192
32984 2903 ,988,096,032, 225,128,829
329908 2976, 249,128,169,089,133,042
32996 2252,168,008,133,251,169,169
33682 2:900,145, 251, 208, 208, 251,889
33988 2230,252,166, 252, 224,128,212
330614 2208, 243,996,169,916,160,114
33820 :800,153,900,964,153,008,119
33926 :965,153,8899,066,153,088,183
33832 2967, 298, 208, 241,169,922,147
33838 2141, 248,967,169,906,153,930
33844 :8@60,216,153,008, 217,153, 247
33650 2980, 218,153,908, 219,208,848
33856 2208, 241 ,932,182,137,932,996
33862 2@43,129,8976,187,129,032,122
33868 2133,139,169,981,133,982,189
33874 2169,959,141, 255, 207,172,829
338898 2255, 207,162,009,932, 239,183
339886 2139, 232,224,151,249,985,829
33092 2136,192,9038, 208, 243,173,026
33698 2255,207,024,1985,920,141,958
33164 2255,207,201,200,144,225,932
33118 :169,019,141,255,207,174,018
33116 2255,287,160,290,032,239,161
33122 2139,136,232,224,151,288,164
33128 2247,173,255,2807,9024,185,991
33134 2:920,141,255, 207, 201,151,961
33146 :144,229,169,190,141,255, 220
33146 3207,172,255,207,162,999,181
33152 2932, 239,139,232, 224,151,121
33158 2240,005, 200,192, 200,208,155
33164 :243,173,255, 207,956, 233,927
33178 :820,141,255, 207, 201,022,224
33176 :176,225,169,920,141, 255,114
33182 :207,174,255, 267,168,030,167
33188 :932,239,139, 200,232,224, 206
33194 2151,208, 247,173,255, 207,131
33200 2@24,195,820,141,255, 207,169
33266 2201,151,144,229,896,169,148
33212 :996,133,252,169,932,133,235
33218 :254,169,000,133,251,133,191
33224 :253,177,251,145, 253,209,199
33238 2 208,249,238, 252, 238,254,993
33236 2166, 252,224,127, 208, 239,148
33242 2177,251,145, 253, 208,192,156
33248 2964, 208, 247,932,155,139,9845
33254 :032,166,135,032,145,143,115

45
1 Recreations and Applications

33260 2169,007,141,621,288,173,187
33266 2930,208,976,212,149,173,857
33272 2900, 220,141,252, 267,041,885
33278 2981, 208,843,032,038,139,195
33284 :240,0903,932,186,138,173,988
33299 2253,2807,201,8030, 208,903,144
33296 :076,173,138,173,254, 207,985
33382 :201,158,298,8003,076,173,965
33368 2130, 238,254, 2807, 206, 253,936
33314 :207,173,252, 207,141, 249, 239
33326 :207,976,173,130,173,252,927
33326 :207,041,9062, 208,937,932,961
33332 2930,139,249,903,832,186,170
33338 3138,173,253,207, 201,209, 286
33344 2240,107,173,254, 207,201,222
33350 2000, 249,109, 238, 253,207,084
33356 2206, 254, 207,173,252, 207,095
33362 2141, 249,287,976,173,130,934
33368 2173,252,207,041,904, 298, 285
33374 3:937,032,950,139, 249,083,983
33389 :932,186,138,173,253,207,965
33386 : 201,030, 249,963,173, 254,943
333.92 :207,201,090,248,956, 206,254
33398 :254,207, 206, 253, 207,173,138
33464 3252,207,141,249, 207,976, 232
33416 :173,130,173,252,207,041,9082
33416 2008, 208,934,932,958,139,095
33422 3249,003,032,186,138,173,146
33428 2253,207,201,208, 249,019,244
33434 2173,254, 207,201,158, 249,999
33449 :912,238, 254, 207, 238, 253,882
33446 2207,173,252, 207,141, 249,115
33452 2207,032,155,139,162, 255,998
33458 :169,008, 200, 208, 253,232, 207
33464 2208, 258,932,8024,136,832,H98
33476 2144,136,032,036,137,932,195
33476 :829,135,832,030,139,208,001
33482 ?908,032,058,139, 208,903,130
33488 2032,181,133,932, 217,130,165
33494 2:076,247,129,173,038, 208,953
33566 :041,001,208,901,096, 206,985
33506 :199,207,194,184,932, 200,948
33512 2143,174,199, 207, 232,169,976
33518 3032,157,849,964,876,212,051
33524 :148,173,241,207,0190,141,132
33530 :287,207,176,988,169,988, 249
33536 2141, 296, 207,976,011,131,904
33542 :169,001,141,206,297,173,135
33548 :207,207,824,105,913,141,197

46
Recreations and Applications 1

33554 2914, 208,173,206, 207,195,163


33568 :@00,024,196,196,141, 206,995
33566 :287,173,816,208,941,127,934
335;7/2 2913, 286,207,141,916,208,959
33578 :173,249,2807,024,195,041,964
33584 :141,915, 208,169,901,141, 211
33598 2846, 208,169,023,141,255,128
33596 :967,162,254,154,173,921,123
33602 :208,141, 205, 207,169,129,101
33688 2141,9021,288,032,081,143,186
33614 :@32,081,143,032,981,143,978
33628 2169,008,141,282,207,169, 204
33626 2904,141, 203,207,173, 283,253
33632 2207,074,144,088,169,818,196
33638 2141, 264, 2807,076,113,131, 286
33644 2169,020,141, 204, 207,173,254
336508 :203,2807,141,245, 207,169, 996
33656 :919,141, 244, 207,032,252, 238
33662 2135,172, 242,207,174, 204,236
33668 :207,204, 249, 2897,208,908,182
33674 236,241,207, 208,983,876,985
33680 2154,131,932,055,134, 298,998
33686 2963, 238, 202,287,173, 204,153
33692 :207,024,195,020, 281,160,105
33698 2240,618, 201,159, 249,906,241
33784 2141, 204, 207,8076,113,131,916
33716 2238, 203,207,172, 203,207,124
33716 :192,020,208,166,160,909,158
33722 2185,195,132,032,219, 255,171
33728 :206,192,821,288, 245,169, 293
33734 29008,174, 202, 207,032,205, 250
33740 :189,169,832,032,219,255,067
33746 :169,042,932, 219,255,169, 963
3357 D2 2032,032,218,255,169,8980,146
337/53 2174, 200, 287,032,285,189,285
33764 2169,932,9032,219,255,169,971
33778 2:961,032,219,255,169,932,225
33776 2932,218,255,173, 208, 207,937
33782 £141,245, 207,173,202,207,141
33788 2141, 244, 207,832,252,135,239
33794 2174,242,287,173,243,287,224
33800 :932,205,189,169,932,032,155
33806 2219,255,169,146,932, 219,812
33812 2255,173,200,287,201,878,1802
33818 :249,006,924,195,005,141,935
33824 3200,207,173,242, 207,956,993
33830 :233,019,141,242,287,141,244
33836 2221,207,173,243, 287,233,848
33842 :966,141,243,2807,813,221,1987

47
1 Recreations and Applications

33848 3207,248,929,144,818,162,9879
33854 2253,168, 808, 209, 208, 253,112
33869 2232, 208, 250,162,911,032,195
33866 2935,134,8976,934,132, 234,287
33872 2169,988,141,021, 208,169,928
33878 :996,133,252,169,932,133,133
33884 2254,160,000,133, 251,133,255
33899 2253,177,253,145,251, 299,997
33896 $208, 249,238, 252,230,254, 247
33982 2166, 252,224,127, 208,239,046
33988 3177,253,145, 251, 200,192,854
33914 2964, 208, 247,169,997,141,199
33928 2046, 208,173,254,867,141, 249
33926 2255,967,162,039,169,032,990
33932 2157,120,964, 262, 224,907,146
33938 2208, 248,168,906,185, 216,145
33944 2132,153,955,138,185, 223,814
33958 2132,153,962,138,136,192, 293
33956 2255, 208, 239,032,145,143,162
33962 2173,205,207,956,042,141, 226
33968 3921, 208,032,166,135,169,139
33974 :@00,174, 201, 2867,157,988, 233
33986 2964, 238,201, 207,8076, 212,162
33986 2146,159,019, 917,9017,017,651
33992 229,929,929 ,929,929,829,118
33998 :829,8029,829,918,866,979, 280
34994 :978,985,983,932,019,838,918
34819 2849, 968, 888,119,138,040,166
34616 :880,178,950,890,148,160,146
34822 :142,217,207,1498, 216,287,879
34828 :206,032,055,134, 201,983,993
34934 2 249,093, 232,032,955,134,884
34949 :201,9062, 208,085,202, 202,124
34846 2932,955,134, 201,0082,2908,118
349852 :976,173,216, 207,824,105,937
34858 :@19,168,932,955,134, 281,197
34964 2962, 208,962, 232,232,932,816
34978 :955,134, 201,982, 208,953,163
34876 2173, 217, 207,824,195,969, 251
34682 2178,173,216,207,024,105,161
34988 :909,168,032,055,134, 201,127
34994 £062, 208,032, 200,290,832, 208
34196 :955,134, 291,002, 208,823,163
34196 2173,217,287,8656, 233,969,185
34112 2178,032,055,134, 201,902,146
34118 :208,009,136,136,832,955,134
34124 3134,201,002, 240,001,096, 238
34136 3174, 217, 207,172,216, 2807, 251
34136 2236, 241,207, 208,012,152,128

48
Recreations and Applications 1

34142 2924,195,818, 205, 249,207,117


34148 :208,003,9076,245,130,162,156
34154 2911,932,035,134,169,083,234
34160 :133,902,169, 255,141, 246,934
34166 2267,141,214, 207,172, 216,251
34172 3207,208,238, 246, 207,173,115
34178 3246, 207,261,919, 248,044,963
34184 2201,018,144, 006, 206, 214,149
34199 :207,976,149,133, 238,214,135
34196 :207,173,217,207,924,1809,061
34262 2214, 207,141,215, 207,173,931
34268 3217,297,9056, 237,214, 207,818
34214 2170, 202,232,032, 239,139,156
34220 2236,215,207, 208,247,076, 881
34226 2125,133,996,172,253,287,148
34232 174,254, 287,192,940, 248,811
34238 2916,192,830, 249,012,224,136
34244 2150, 248,908,152,956, 233,911
34250 :820,168,032,230,132,172,188
34256 :253,207,174, 254, 207,192,215
34262 2838,249,021,224,990, 248, 201
34268 :917,224,819, 240,9013,152,198
34274 :@56,233,019,168,138,956,119
34280 :233,910,178,032, 230,132,015
34286 :172,253, 207,174,254, 287, 225
34292 2192,038,240,821,224,158,977
34298 2240,017,224,140, 240,813,199
34364 :152,056, 233,9108,168,138, 245
34319 2824,1805,919,176,632, 238,965
34316 :132,172, 253,207,174, 254,188
34322 :207,192, 208, 249,8011,192,836
34328 :198,248,907,224,158,249,951
34334 :803,032,230,132,996,189, 289
34348 2029 ,964,201,957, 249,984,898
34346 2254,008,064,996,169,848,161
34352 2157,988,964,202,876,035,978
34358 :134,152,072,138,072,169,923
34364 :996,133,252,169,8000,133,975
34379 2251,138,072,074,974,179,877
34376 2152,072,8074,974,074,168,174
34382 :202,224,255,248,014,165,154
34388 :251,024,105,008,133,251,988
34394 2144, 242, 238,252,8976,078,888
34460 :134,136,192,255, 248,016,945
34466 2165,251,024,1895,964,133,976
34412 :251,165,252,185,961,133,247
34418 :252,8976,997,134,194,041,850
34424 :007,168,136,192, 255, 249,994
34438 :909,230,251, 208,247, 230,821

49
1 Recreations and Applications

34436 3252,8976,122,134,104,941,993
34442 :9@03,178,169,192,141, 247,836
34448 :207,202,224,255, 240,989,901
34454 3@78,247,287,8078, 247,207,198
34460 :976,145,134, 200,173, 247,197
34466 :207,049,251,141,221, 207,214
34472 2173, 247, 207,041,001, 208,021
34478 $915,978, 247,207,978, 247,022
34484 :207,978,221,2807,878, 221,168
3449 :207,076,168,134,194,179,921
34496 :104,168,173,221,207,996,137
345982 :169,000,141, 220, 207,169,088
34568 2255,141, 219,207,174, 220,148
34514 2207, 232,236,219, 207,249,815
34526 261,173,220, 207,924,199, 242
34526 3219, 207,196,141, 218, 297,840
34532 2141, 245,207,141, 244, 207,133
34538 2@32,252,135,173, 242,287,251
34544 2956,237,222,2807,141,221,944
34556 2207,173,243, 207,237, 223,980
34556 :207,013,221,287,249,826,142
34562 :144,909,173,218, 207,141,126
34568 :219,207,976,208,134,173,001
34574 3218, 207,141,229, 207,076,859
34580 :208,134,173,228, 207,141,979
34586 3218,207,096,173,241,207,144
34592 :9@56,237,254, 207,144,903,165
34598 :876,048,135,173, 254, 287,163
34694 2956,237, 241,207,141, 245,147
34619 :207,141,244,287,032,252,1989
34616 2135,173, 242,207,141, 236,166
34622 :207,173,243,207,141,237,246
34628 :207,173,248,207,056, 237,164
34634 2253,207,144,993,976,988,077
34648 2135,173,253,287,956, 237,117
34646 2249,207,141,245, 207,141,243
34652 2244,207,032,252,135,173,111
34658 2242,207,024,189, 236,287,899
34664 2141, 222,207,173, 243,207,917
34670 2189, 237,207,141, 223,207,219
34676 :932,198,134,173, 218,207,954
34682 2974,074,974,170,168,169,983
34688 :160,157,127,964, 202,224,838
34694 2255,208, 248,173,218, 207,163
34780 :841,007,178,189,158,135,972
34766 2153,128,964,169,032,153,877
34712 2129,964,153,130,864,996,8020
34718 2101,116,117,997, 246,234,945
34724 2231,160,173,827, 212,041,240

50
Recreations and Applications 1

34736 2815, 201,013,176, 247,024,878


34736 2105,901,141,241,207,173,929
34742 2827,212,041,097,024,185,986
34748 :901,141, 245, 297,169,829, 263
34754 3141, 244, 207,9032,252,135,181
34766 :173,242,207,141, 249,207,130
34766 2173,241,207,941,001, 268,953
34772 :909,173,248, 207,956, 233,106
34778 210,141,249, 207,173,241, 286
34784 2207,141,245,207,169,919,179
34796 2141,244,287,032,252,135,217
34796 2173,242, 207,141, 241,207,167
34882 2173,248,207,924,195,039, 253
34898 :141,248,207,096,169,980,977
34814 :141,242,207,162,098,978, 868
34826 2245,207,144,9004,924,189,225
34826 :244,207,1906,119, 242,207,182
34832 2202,208, 240,141, 243, 207,233
34838 :996,096,162,906,932,986, 244
34844 2136, 298,949,032,196,136,183
34859 2208,044,173,027, 212,291,131
34856 :964,176,908,169,914,157,116
34862 :183,207,876,088,136,281,161
34868 2128,176,908,169,913,157,191
34874 :183,207,976,980,136, 201,173
34886 :192,176,908,169,011,157,909
34886 :183,207,876,989,136,169,153
34892 207,157,183, 2607, 202,224,932
34898 2255, 208,197,096,189,955,9858
34964 :138,924,125,962,138,141, 204
34918 :250,207,008,184,041,901,193
34916 :141,251,2807,8976,985,139, 231
34922 2189,055,138,056, 253,962,091
34928 2138,144,9811,141, 258,287,235
34934 :169,000,141,251,2807,976,194
34940 :985,139,189,962,138,956,825
34946 :253,955,138,141, 250,207,158
34952 2169,000,141,251,207,976,212
34958 :885,139, 238,182, 207,173,142
34964 2182, 207,205,181, 207,248, 890
34978 :981,8996,169, 255,141,182, 230
34976 :207,162,906,189,183, 287,699
34982 :841,001,2808,929,189,862,184
34988 :138,281,030,2898,903,076,860
34994 :938,137,189,955,138, 201,160
35809 2150,288,8903,976,8938,137,620
35886 :254,055,138,222,962,138,835
35812 :976,038,137,189,183,207,250
35818 241,902, 208,023,189,062,215

51
1 Recreations and Applications

35624 2138, 281,200, 248,073,189, 225


35838 :955,138, 201,900, 249,066,146
35836 :254,962,138,222,955,138,965
35942 2976,0938,137,189,183, 207,024
35948 3941,004, 208,8623,189,862, 247
35654 2138, 281,939, 248,043,189,955
35969 2955,138, 201,909, 240,036,146
35866 2222,955,138,222,962,138,063
35872 :876,838,137,189,183, 207,054
35878 :841,908, 208,820,189,962,822
35084 2138, 201,200, 240,913,189, 225
35898 2955,138, 201,159, 249,986,049
35896 :254,055,138, 254, 962,138,157
35162 3202, 224,255, 208,128,996,119
351468 2162,9006,169,128,141, 247,121
35114 3207,189,955,138,919,176,949
35120 3959,195,914,008,9072,138,188
35126 :0@19,170,164,157,082, 208,193
Jo3/2 2138,074,176,940,173,247,134
35138 :287,073,255,045,016, 208,182
35144 2144,9003,913,247,207,141,9859
3515d 2916, 208,189,962,138,924, 283
35156 2195,941,9072,138,019,178,188
35162 :194,157,8903, 298,138,974, 6896
35168 178,978, 247, 287, 202,224, 208
35174 2255, 208,194,076,134,137,882
35188 2924,195,914,072,138,919, 215
35186 :179,104,157,062, 208,138,125
35192 2074,179,173,916,2908,913,986
35198 :247,207,141,816, 208,976, 253
35204 3980,137, 206, 246, 207, 208,192
35219 2835,169,819,141, 246,287,178
35216 2173,248, 207,201,021, 248,218
35222 :998,169,921,141,248, 207,176
35228 :8976,164,137,169,928,141,695
35234 3248, 207,162,0906,157, 249,167
35246 3967, 282,224,255, 208, 248, 892
35246 2173,141,002,2061,001,249,164
35252 2249,996,162,906,169,907,101
35258 2157,840,208,169,8928,157,169
35264 3249,967, 282,224,255, 298,117
35278 :241,162,936,169,993,157,198
35276 2120, 216,282, 224,255, 208,149
35282 :248,162,039,169,032,157,249
35288 :909,964,157,949,964,157,186
35294 :120,964,157,989, 864, 202,141
35389 3224, 255, 208,239,169, 909,934
35386 2185,969,138,032, 219,255,999
35312 :200,192,011, 208, 245,168,232

52
Recreations and Applications 1

35318 :90%,185,9088,138,032, 219,131


35324 2255,290,192,043, 288,245,115
35330 :169,9807,185,989,138,153, 213
35336 :900,988,136,192,255, 208,111
35342 2245, 208,185,131,138,9032,177
35348 :210,255, 200,192,848, 208,191
35354 :245,168,909,185,179,138,156
35360 :@32,218,255,208,192,8016,169
35366 :2808,245,169,0909,185,888,148
Se /7 2142,153,089, 969, 200,208,848
35378 2247,173,838, 208,096,919, 846
35384 2930,840,069,0980,118,138, 250
35396 :040,988,178,959,690,1480,1208
35396 :160,158,819,817,017,9817, 280
35482 :983,979,078,965,082,958,887
35468 :126,126,126,126,996,996, 988
35414 :896,096,154,819,8017,917, 229
35429 :976,069,886,969,976,958,914
35426 :8@32,032,0932,032,032,032,934
35432 2932,032,032,032,032,032,848
35438 2@32,032,032,032,032,032,8046
35444 2932,032,032,832,032,932,052
35458 :8@32,032,8032,032,8932,8032,058
35456 2@32,032,032,005,919,983,075
35462 :967,979,082,969,058,032,909
35468 2948,048,948,948,948,948,172
35474 :832,032,032,032,032,9832,082
35480 :@72,073,8071,972,032,983,843
35486 :867,979,082,869,658,832,833
35492 2948 ,948,048,048,848,848,196
35498 2153,019,817,083,084,965,079
35564 :077,073,8078,965,958,932,847
35518 218,218, 218, 218,173,249,196
30D :207,041,001,208,909,238,124
35522 3254,207, 206, 253, 207,976,117
35528 :247,138,173,249, 207,941,231
35534 3902, 208,069, 238, 253,287,899
35546 :286,254,2807,076, 247,138,969
35546 2173,249,207,041,984, 298,876
35552 :869,206, 254, 207, 206, 253,879
35558 :267,076, 247,138,173, 249,940
35564 :207,041,008, 208,006, 238,176
35576 2254, 207, 238, 253, 207,032,153
35576 2155,139,162,255,168,990,695
35582 2200, 208, 253,232, 208,259,869
35588 :932,024,136,032,144,136,252
35594 :932,036,137,032,217,138,082
35689 :0@32,039,139,288,165,932,119
35686 :858,139,288,160,932,181,924

53
1 Recreations and Applications

35612 2133,996,173,254, 207,824,147


35618 2109, 253,287,141,2598, 287,177
35624 :0@08,194,941,001,141, 251,974
35639 :267,076,085,139,173,254,212
35636 2207,056,237,253, 207,144,132
35642 :@11,141, 258, 207,169,889, 068
35648 2141,251,207,8076,985,139,195
35654 2173,253,2807,856,237, 254,226
35660 :207,141,259,287,169,988,926
35666 £141,251, 207,173,259, 297,931
35672 2956, 233,919,141,250, 207, 217
35678 2173,251, 207, 233,000,141,975
35684 2251,207,948,928,173, 258,833
35699 :267,013,251,20607, 249,020,920
35696 2173, 258,207,956, 233,928,9827
35782 2141, 259,207,173,251,2807,967
35788 2233,90090,141,251,207,976,908
35714 :102,139,996,169,9902,133,083
357208 :9@602,162,159,168,931,032,170
35726 2239,139, 200,192, 289,268,840
35732 2248, 202,224,156, 208, 241,141
35738 2:996,173,254,207,018,176,946
35744 2@29,105,915,141,989, 208,146
35750 :173,016, 208,041, 254,144, 234
35756 2062,009,901,141,916, 208,837
35762 2173, 253,297,024,195,941, 213
35768 :141,001, 298,976, 297,139,188
35774 2024,1805,015,141,990, 208,171
35788 :173,916,208,909,901,141, 232
35786 2916, 208,876,178,139,169, 229
35792 :9@02,133,002,174,254, 207,212
35798 2172,253,287,032,055,134,843
35804 :201,901,208,905,162,012,9041
35819 2@32,035,134,174, 254, 207,838
35816 2172, 253,207,932, 239,139,250
35822 :996,072,152,072,138,972,872
35828 :169,096,133,252,169,099,039
35834 2133,251,138,072,974,974,224
35840 2170,152,072,974,974,074,1904
35846 2168, 202,224,255, 249,014,085
35852 2165,251,024,195,908,133,186
35858 2251,144,242,238,252,976,189
35864 :007,148,136,192, 255, 248, 226
35879 2@16,165,251,924,1805,964,143
35876 2133,251,165,252,195,001,175
35882 2133,252,8676,626,146,164,005
35888 :841,007,168,136,192, 255,979
35894 2246,009, 238,251,208, 247,215
35960 2230,252,076,951,140,194,145

54
Recreations and Applications 1

35986 :041,003,170,169,863,141,141
35912 2247,207,165,982,010,918, 281
35918 2910,918,9180,619, 202, 224,832
35924 2255,248,912,074,074,056,627
35938 2118,247,287,118, 247,207,194
35936 2976,082,148,298,8972,173,971
35942 3247,207,849,251,145,251,228
35948 :164,017,251,145,251,194, 212
35954 :170,104,168,194,996,173,161
35968 2@25,208,141,925, 208,941, 808
35966 :881,249,8977,169,9012,168,917
3507 2 2959,162,024,142,022, 268, 237
35978 2141,033,2808,149,917, 208,117
35984 2141,024, 208,173,918, 298,148
35998 :201,081,144,916,169,00%, 249
35996 2141,918,208,173,017,208,153
36882 :@41,127,141,917, 288,076,994
36988 :206,149,169,900,141,933,989
36814 : 208,169, 200,141,922, 208,998
36920 :169,027,141,817, 208,169,143
36826 :004,141,024,268,169,081,845
368632 2141,918,298,173,817,298,189
36838 :@41,127,141,917, 288,076,840
36844 2949, 234,104,168,104,178,989
36850 :184,964,169,970,141, 254,244
36856 :207,169,129,141,253, 287,933
36862 :162,039,169,032,157,129,133
36968 2964, 202,224,007, 208,248,157
36874 :@32,155,139,032,929,135,244
36880 :173,199,207, 261,807,248, 243
36886 :957,032,248,141,932,024,9812
36692 :136,032,144,136,032,936, 900
36998 3137,162,255,168,900, 200,148
36164 2208, 253,232,208, 250,162,841
36116 2249,169,098, 2600, 208, 253,860
36116 2232,208, 250,173,980, 228,879
36122 :@41,916, 208, 229,162,013,174
36128 :169,932,157,948,964, 232,214
36134 :224,039, 208, 248,173,038,192
36146 :288,976,247,129,162,939,137
36146 :169,913,157,848, 216, 202,879
36152 2224,255, 208, 248,160,908,127
36158 :162,900,189,941,964,157,163
36164 2940, 964, 232,224,837, 208,1085
36179 2245,185,937,142,141,977,133
36176 2:964,152,80972,169,09009,162,178
36182 2908, 209, 208, 253, 232, 208,163
36188 :250,194,168,173,908, 2208, 239
36194 :841,816, 249,819, 200,192,929

55
1 Recreations and Applications

36280 2943, 208, 211,169,900,976,934


36286 2:962,141,162,990,189,887,159
36212 2964, 221,031,064, 249,918,242
36218 :144,021,162,905,189,997,138
36224 :964,157,931,864, 202,224,192
36236 3255, 208, 245,976,145,141,188
36236 2232,224,006, 208, 225,162,173
36242 :905,189,031,964,157,192,916
36248 3207, 202,224,255, 208, 245, 213
36254 2173,8000,220,041,816, 249,080
36269 3:249,932,973,145,932,182,199
36266 2137,162,9005,189,192, 287,838
36272 2157,931,964,202,224,255,985
36278 ?208,245,169,8096,133,252,985
36284 :169,032,133,254,169,999,168
362908 2133,251,133, 253,177, 253,114
36296 2145, 251, 208, 208, 249, 238, 283
36362 2252,238,254,166, 252,224,848
36388 3127, 208, 239,177, 253,145,981
36314 3251, 200,192,964, 208,247,190
36329 :@32,145,143,169,987,141,993
36326 2921,208,141,201,287,169,153
36332 :840,141,2900, 207,169,912, 237
36338 2141,199, 207,976, 212,148,193
36344 :162,908,189,986,142,932,911
36350 2219,255, 232,224,932, 298,135
36356 :245,096,905,919,817,9029,159
36362 2929,829,8929,929,029,029,184
36368 2929,029,829,929,929,829,1908
36374 2829,829,829,889,082,969,984
36380 :983,983,932,966,085,984, 205
36386 2:984,079,978,135,129,141,168
36392 :133,160,143,158,133,146,137
36398 3032,8046,046,032,916,918, 236
36464 2905 ,919,019,832,002,%921,150
36419 3829,928,015,9814,932,929,179
36416 2915,932,916,012,901,8025,165
36422 3032,881,907,001,909,014,134
36428 :0@32,9046,%46,032,900,080, 232
36434 2900 ,00D,900,G00,990,909,982
36449 3900 ,900,800,908,200,900,988
36446 28D, JOD, GVO, VOW, DOS, GBB, G94
36452 :900,920,048,0900,900,948,196
36458 2809, 80%, 252,0008,009,252,898
36464 2008, 908,848,000 ,0990,048, 208
36478 2900 ,0900,900,008,9008,0980,118
36476 2200, GOD, BOO, BOB, BWW, GVO, 124
36482 2800, 900,000,000, 008,000,130
36488 2000, 000, 90D, 000,060, 900,136

56
Recreations and Applications 1

36494 22GB, 000,000,009, 069,000,142


36588 2000 ,909,900,008,000,909,148
36586 289,000,098 ,000,800,000,154
36512 2800 ,909,900,800,900,801,161
36518 :140,0099,8090,216,89099,000,9819
36524 :112,000,000,112,8000,900,148
36530 :216,009,081,149,909,909,923
36536 :000,000,600,980,0900,900,184
36542 2089 ,000,900,0008,009,890,1908
36548 : G00, 900, G00, GOW, BOW, BOW, 196
36554 : 000,000,000, 000,008,008, 282
36568 2000 ,0008,2000,9008,000,960, 208
36566 2860 ,000,000,0900,009,008,214
36572 :900,900,900, 900,008,900, 228
36578 :G0D,089,000,0008,096,098, 066
36584 2908, 240,0008,061,248,800, 289
36596 2009, 249,000,000,896,989, 062
36596 2900 ,008,000,009,800,900, 244
366982 :000,009,600,000,0908,880,250
36668 2900 ,0908,900, 000,808,000, 908
36614 : 880,005,800 ,9008,0909,898, B86
36629 2909 ,000,0900,900,900,909,8012
36626 2069 ,000,0009,000, 000,898,818
36632 :900,009,900,000,8015,255,938
36638 :255,023,224,049,8016,989,985
36644 :@01,035,192,951,102,219,934
36659 :851,075,108,183,199,254,864
36656 :102,128,000,914, 255,255,034
36662 :252,255,255, 248,980,989, 848
36668 :900,008, G00, 900, BOB, GOW, 6B
36674 290,009, 000,09008,009,000, 866
36689 2000 ,960,900,000,2008,908,072
36686 :800,900,165,162,007,169,869
36692 :908,157,009,212, 202,224,111
36698 2255, 208, 248,169,141,141,228
36784 2924, 212,169,905,141,905,140
36719 212,169, 218,141,006, 212,936
36716 :169,158,141,081,212,169,182
36722 2139,141,9009,212,169,917,924
36728 2141,904, 212,168,140,162,171
36734 2900, 232, 208,253, 200,208, 263
36746 2250,169,916,141,904, 212,156
36746 2232,208,253, 200, 208,259,289
36752 :996,168,800,169,999,153,219
36758 :808,212,298,192,988, 208, 262
36764 2246,169,143,141,924,212,067
36770 :169,008,141,905, 212,169,898
36776 2 243,141,906, 212,169,129,944
36782 :141,904,212,162,255,142,966

57
1 Recreations and Applications

36788 :9@01,212,202,168, 255,136,122


36794 2192,001,208,251,224,001,939
36808 2208, 241,169,128,141,904,959
36866 2212,096,162,900,169,999, 869
36812 2157,088, 212,232,224, 988, 913
36818 2208, 248,169,143,141,024,119
36824 3212,169,017,141,965, 212,204
36836 2169, 213,141,906, 212,169,198
36836 :@02,141,903,212,169,190,987
36842 :141,002,212,169,005,141,136
36848 :901,212,169,135,141,969,138
36854 3212,169,8965,141,904, 212,025
36869 :169,252,168,909,162,900, 227
36866 3209, 208, 253,232,208, 250,073
36872 :024,105,001,208, 245,169, 248
36878 :@64,141,904, 212,996,162,181
36884 200,142,033, 208,142,932,065
36896 2 208,189,206,144, 249,907,252
36896 :932,210,255,232,876,827,096
36962 2144, 234,173,198, 207,185,967
36988 :@48,9032,218,255,169,157,147
36914 :832,219,255,032,228,255,9838
36920 :208,918,173,000,228,941,196
36926 :@16,208, 244,076,091,144,973
36932 2201 ,913,249,919, 201,049,923
36938 2144, 233,291,058,176,229,9891
36944 2972,856,233,948,141,198,052
36959 3207,194,032,218, 255,162,032
36956 :900,160,800, 232, 298,253,177
36962 2200, 208,258,173,009, 228,125
36968 2041,016,240,249,189,958,121
36974 2145,248,007,032,219,255,231
36988 :232,076,108,144,173,180,895
36986 :207,032,219,255,169,157,128
36992 2032,2190,255,832,228,255,116
36998 :208,010,173,008, 228,841,818
37904 3916, 208, 244,076,167,144, 227
37818 3201,013,240,017, 201,969,119
37816 :240,007, 201,072, 249,903,147
37822 :876,131,144,141,189, 287,813
37828 :932,218,255, 234,056,169, 996
37034 :919,237,198,207,818,073,129
37848 :255,024,1805,002,141,177,112
37846 130,141, 251,138,141,984,219
37852 2141,173,189,207,956, 233,154
37858 :969,8074,973,901,141,181,221
37864 :207,169,001,133,204,896,242
37678 :914,147,017,917,159,8018,866
37876 :829,029,029,8029,8929,829,138

58
Recreations and Applications 1

37882 2829,0932,0932,032,032,932,151
37988 2932,032,8017,157,157,157,988
37894 :157,157,157,157,632,211,9877
37189 :208, 201, 203,197,932,146,199
37186 :832,045,8032,995,032,194,978
37112 2889, 032,197,982,973,967,8208
37118 3832,194,982,965,878,968, 995
37124 :8979,878,013,929,8929,929,905
37138 :829,829,829,8029,159,918, 847
37136 :932,032,932,932,932,032,288
37142 :032,813,013,8013,913,813,119
37148 :829,929,629,9829,029,929, 282
37154 2158,211,988,969,969,968,177
37166 :832,948,849,845,957,941,948
37166 :863,032,159,008,813,013,979
eli? :8913,029,9629,829,829,029,2198
37178 :929,158,197,865,983,989,167
37184 2047 ,209,965,982,968, 963,977
37196 :032,159,990,126,173,013,055
37196 2226,009,129,141,813, 220,949
37262 :169,000,141,026, 288,169,627
37268 :234,141,021,993,169,949,193
37214 :141,029,0083,988,169,921,924
37228 :141,924,288,169,927,141,942
37226 2817, 208,169,199,141,909,8072
37232 2221,169,004,141,136,982,9817
37238 :169,088,141,621, 208,032,177
37244 2019,144,169,964,141,136,929
37258 :862,169,198,141,899, 221,893
37256 2169,998,141,924, 208,169,987
37262 :216,133,252,169,999,132,011
37268 :251,169,006,145, 251, 208,146
37274 :208,251,238, 252,166, 252, 233
37289 2224,220, 298, 243,932,183, 246
37286 :128,169,255,141,182,207,224
37292 2996,000,255,913,813,813,958

59
1 Recreations and Applications

Martian Prisoner
Alan Poole

“Martian Prisoner” is a mini-adventure game


for the Commodore 64. If you’ve never played
an adventure game before, this is a good in-
troduction. Unlike most computer games, text
adventures have no graphics and do not require
fast reflexes—instead, they test the player’s
patience and cunning.
SS Sa te ENE OEM ea aa Nt

Without warning, the Martians have suddenly started a dev-


astating war against Earth. They have captured you and are
holding you prisoner in a cell on a Martian space cruiser headed
toward Earth. The cruiser also carries a secret weapon that can
neutralize all of Earth’s defenses. Your task is to destroy the
Martian ship and escape in a lifecraft before the Martians can
complete their sinister mission.
Like Radio Dramas
“Martian Prisoner” is a mini-adventure game, using only a lit-
tle more than 3K of memory. Adventure games require you to
solve puzzles and explore a simulated world inside the com-
puter. The computer will describe what you see and what
happens, and you tell the computer what you want to do.
Instead of using screen graphics, adventure games rely on text
descriptions and your imagination. It’s like the difference
between old-time radio dramas and television; despite the
visual impact of video, the mind can still imagine a scene
more exciting than a camera can picture.
In Martian Prisoner, you start off in the prison cell of the
Martian space cruiser. Besides the cell, the cruiser contains
several other rooms. It’s up to you to explore the rooms and
find a way to destroy the ship. In each room, the computer
will describe your surroundings and list the objects in the
room. The computer then waits for you to type a command,
consisting of one or two words.
For example, you would type GO NORTH to move north.

60
Recreations and Applications 1

If there is a book in the room, you would type GET BOOK to


pick it up. Type INVENTORY at any time to see a list of the
objects you are carrying. All commands and nouns can be
abbreviated to the first three letters. You can list your IN-
VENTORY by typing INV, for instance.
The commands you can use, with the abbreviations cap-
italized, are:
North INVentory
East REAd
South OPEn
West WEAr
GO EAT
GET KILI
DROp HIT
Although Martian Prisoner is a short adventure game, you
must solve several puzzles to win. It’s a good way to prepare
for the more elaborate adventure games available commer-
cially for Commodore 64s.
If you haven't played a text-adventure game before, it
may be a good idea to draw a map of the cruiser as you
explore its rooms. Using the map, you can easily backtrack if
you run into a dead end or want to explore a side passage
you earlier passed by.
Martian Prisoner doesn’t award points for accomplishing
tasks, as some other adventure games do. Because of its short
length, you simply win by destroying the cruiser and escaping,
or lose by getting your character killed. Of course, you can
always try again!
Typing In
Take a look at the program listing for Martian Prisoner. You'll
notice the characters :rem xxx on the far right of each line.
These are not characters you will type in. They have to do
with ‘“Automatic Proofreader,” in Appendix J, and are in effect
checksums. Be sure to read Appendix J before you begin to
type in Martian Prisoner. The Automatic Proofreader program
will make mistake-proof entry a snap.

61
1 Recreations and Applications

Martian Prisoner
For mistake-proof program entry, be sure to use “Automatic Proofreader,” Appendix J.

19 G OSUB5009 :rem 166


190 GOSUB190@ : IFR=6ANDU=@THENR=1:GOTO196 :rem 232
116 GOSUB29@@@:PRINT srem 155
129 ONVGOSUB398@9 , 39099, 3099, 39099, 3199, 3209, 3300, 349
9, 3588,3698, 37080, 3800, 3990 srem 42
125 IFV=14THEN3 900 srem 26
136 GOTO19@ srem 94
1968 PRINT: ONRGOSUB1199,1200,1390,1409,1500,1600,1
708,18600 srem 87
1963 IFW1=299THEN1@19 :rem 173
1965 IFI(4)=-1ANDI (6)=-1ANDW1=299THENPRINTNSS
srem 185
1910 PRINT: PRINT" {CYN}{6 RIGHT}OBJECTS: {WHT}"
srem 240
1826 FORL=1T08
: IFI(L)=RTHENPRINT"{6 RIGHT}";NS(L)
¢rem 117
1036 NEXT: PRINT: RETURN :rem 228
1189 PRINT"{6 RIGHT}YOU ARE IN A PRISON CELL."
srem 23
1116 IFRND(1)>.25THENRETURN srem 154
1126 G=1:PRINT"{6 RIGHT}A GUARD HAS TURNED OFF THE
FORCE{8 SPACES}FIELD "; srem 94
1125 PRINT"AND ENTERED THE CELL." :rem 163
1136 C%(1,1)=2:RETURN srem 149
1260 PRINT"{6 RIGHT}YOU ARE IN A N/S HALL.":RETURN
srem 40
1366 PRINT"{6 RIGHT}YOU ARE IN THE ENGINE ROOM.":R
ETURN srem 293
1486 PRINT"{6 RIGHT}YOU ARE IN A SMALL ROOM. A LAR
GE{8 SPACES}SIGN IS ON THE WALL." srem 42
1416 IFI (4)=-1THENPRINTNSS$ srem 63
1426 IFI(6)=-1THEN4509 srem 185
1439 RETURN srem 168
1506 PRINT"{6 RIGHT}YOU ARE IN THE SUPPLY ROOM.":R
ETURN srem 4
1600 PRINT"{6 RIGHT}YOU ARE IN THE NORTH{2 SPACES}
SIDE OF THE{7 SPACES}HALL." :rem 8
1610 IFU=1THENPRINT"{6 RIGHT}THE GUARDS DON'T NOTI
CELYOU..- srem 184
1626 IFU=@THENPRINT"{6 RIGHT}THE GUARDS TAKE YOU B
ACK TO THE{9 RIGHT}CELL.":G=@ srem 193
1630 RETURN s:rem 170
1760 PRINT"{6 RIGHT}YOU ARE IN A LARGE ROOM.":RETU
RN srem 228
1899 PRINT"{6 RIGHT}YOU ARE IN A STRANGE GARDEN WH
ERE{7 SPACES}FOOD IS "; srem 52

62
Recreations and Applications 1

PRINT"GROWN FOR THE CREW." srem 83


IFI(4)=-1THENPRINTNSS :W1=299 srem 230
RETURN srem 171
CS=""sN=8:V=0:
PRINT: INPUT"{6 RIGHT }COMMAND
{GRN}";C$:PRINT"
{WHT }":IFCS=""THEN2900
srem 144
P=@: IFLEN(CS$) <2THEN205@ srem 73
FORL=2TOLEN(CS$)-1 s:rem 254
IFMIDS(CS$,L,1)=" "THENP=L srem 194
NEXT srem 5
IFP=9THENVS=CS$ :NS="" srem 141
IFP>@ANDP=LEN (C$ ) THENVS=CS :NS="" srem 134
IFP>SANDP<LEN(C$
) THENVS=LEFTS(CS$,P-1) :N$=RIGH
TS(cS,LEN(CS)-P) sren 86
FORL=1T014: IFLEFT$(V$,3)=V$(L)THENV=L srem 23
NEXT: FORL=1T08: IFLEFTS (N$,3)=A$ (L)THENN=L
srem 55
NEXT : [LFN>SANDV>S@THENRETURN srem 47
IFN=8ANDV >9ANDNS=""THENRETURN srem 124
IFN=8ANDV=5THENRETURN srem 191
PRINT:PRINT"{6 RIGHT}I DON'T UNDERSTAND.":GOT
02800 srem 13
NS=VS :GOTO311@4 s:rem 36
NS=LEFTS (NS$,1) s:rem 226
IFR=1LANDNS="E"ANDG=OTHENPRINT"{6 RIGHT}THE FO
RCE FIELD STOPS YOU.":RETURN srem 230
IFR<>1lORNS<> "E"ORG=0THEN 31398 srem 179
PRINT"{6 RIGHT}AS YOU LEAVE THE CELL THE FORC
E{9 SPACES}FIELD IS ACTIVATED, "; srem 149
PRINT" TRAPPING THE{7 SPACES}GUARD." :rem 133
IFR=2ANDN$="E"ANDC3(2,1)=@ANDI(8)>-1THENPRINT
"{6 RIGHT}DOOR LOCKED." srem 173
IFR=2ANDNS$="E"ANDC3(2,1)=@ANDI
(8) >-1THENRETUR
N :rem 255
IFR<>20RNS<>"E"ORC% (2,1) >OTHEN315B srem 186
PRINT"{6 RIGHT}YOU UNLOCK THE DOOR WITH THE K
EY.":C%$(2,1)=5:N$(7)="OPEN DOOR" srem 189
IFN$="N"THEND=0 s:rem 121
IFNS="E"THEND=1 srem 114
IFNS$="S"THEND=2 srem 134
IFNS="W"THEND=3 s:rem 135
IFC$(R,D)=@THENPRINTCNS : RETURN srem 219
PRINT"{6 RIGHT }OK":R=C$(R,D) :RETURN srem 67
IFN=10RN=20RN=30RN=7THENPRINT"{6 RIGHT}YOU CA
N'T LIFT IT!1":RETURN s:rem 47
IFI(N)<>RTHENPRINT"{6 RIGHT}IT'S NOT HERE.":R
ETURN srem 45
IFN=5THEN3729 srem 20
PRINT"{6 RIGHT }OK":1I(N)=-1:RETURN srem 182

63
1 Recreations and Applications

3300 PRINT" {6 RIGHT }OK":I(N)=R: RETURN srem 179


34008 PRINT"{6 RIGHT}YOU ARE CARRYING:" srem 180
3419 FORL=1T08:IFI(L)=-1THENPRINT"{6 RIGHT}";NS(L)
srem 134
3428 NEXT : RETURN srem 34
35868 IFN<>30RR<> 4THENPRINTCNS : RETURN srem 126
3516 PRINT"{6 RIGHT}ATOMIC FUEL NEARBY. DON'T BRIN
G{9 SPACES}ANY RADIO-ACTIVE" srem 46
35268 PRINT"{6 RIGHT}MATERIALS INTO THIS ROOM.":RET
URN srem 226
3699 IFN<>7ORR<>2O0RI(8) >—-LTHENPRINTCNS : RETURN
srem 144
3619 NS="E":GOTO3145 srem 66
3786 IFI (5) <>RTHENPRINTCNS : RETURN srem 127
37208 PRINT" {6 RIGHT}YOU ARE NOW WEARING A UNIFORM.
":I(5)=-1:U=1:RETURN srem 197
38008 IFN<>6THENPRINTRIS : RETURN s:rem 237
3819 PRINT"{6 RIGHT}YOU QUICKLY BECOME SICK AND DI
E.":GOTO46990 srem 79
3986 PRINT"{6 RIGHT}THE GUARD SHOOTS YOU.":GOTO469
4) srem 231
3916 PRINTCNS : RETURN srem 41
4588 PRINT srem 86
45@5 PRINT"{6 RIGHT}THE RADIOACTIVE PLANT EMITS EN
OUGH{6 SPACES}NEUTRONS TO START A" srem 16
4519 PRINT"{6 RIGHT}CHAIN REACTION. THE SHIP EXPLO
DES." srem 214
4515 PRINT"{6 RIGHT}YOU ESCAPE IN A LIFE-CRAFT."
srem 191
4526 PRINT:PRINT"{PUR}{6 RIGHT}YOU WIN!":GOTO4619
srem 247
4608 PRINT: PRINT"{PUR}{6 RIGHT}YOU LOSE!" srem 253
4619 PRINT: PRINT: PRINT"{6 RIGHT}{GRN}PLAY AGAIN?"
srem 293
4628 GETKS : IFK$="Y"THENRUN zsrem 81
4636 IFKS="N"THENEND srem 168
4648 GOTO04629 s:rem 211
5996 PRINT" {HOME } {CLR}":POKE36879,8:PRINT"{4 DOWN}
{10 RIGHT}{GRN}{RVS}MARTIAN PRISONER{OFF}":PR
INT srem 146
5980 DIMVS(14),C%(8,3),1(8),NS(8),A$(8) srem 146
5898 R=1 : FORL=1T014:READVS (L) :NEXT srem 87
51608 FORL=1T08: READC$(L,8),C%(L,1),C%(L,2),C%(L,3)
:NEXT srem 31
5116 FORL=1TO8:READNS(L),A$(L),1(L) sNEXT :rem 97
5115 CNS="{6 SPACES}YOU CAN'T":RIS="{6 SPACES}DON'
T BE SILLY!" zrem 87
5128 NS$="{6 SPACES}GEIGER COUNTER IS CLICKING.":R
ETURN srem 9

64
Recreations and Applications 1

6096 DATAN,E,S,W,GO,GET,
DRO, INV, REA, OPE, WEA, EAT, KI
L,HIT z:rem 217
6619 DATAGD,9,9,9,6,9,3,9,2,4,9,09,9,9,9,3,9,9,9,2,7
,9,2,9,6,8,6,9,9,9,9,7 srem 193
6626 DATAFORCE FIELD, FOR, 1,GUARDS,GUA,6,SIGN,SIG,4
,GEIGER COUNTER, COU,5,UNIFORM s:rem 13
6930 DATA UNI,5, PLANT, PLA,8,LOCKED DOOR,DOO, 2,MAGN
ETIC KEY,KEY, 3 srem 151

65
1 Recreations and Applications

64 Mailing List
Joseph J. Shaughnessy

Keeping track of your mailing list (or other kinds


of files) is simple when you use this program on
your Commodore 64. One alteration lets you use
tape instead of a disk drive, and you can even
print labels from your list.
SR
eR A

“64 Mailing List’’ is a modified and expanded version of a


utility program called ““Addresses” from the Toronto PET
Users Group. It was originally written in Dutch by Andy
Finkel. The program has been translated into English and a
printer option added. Using a Commodore printer, it can print
the entire list or individual mailing labels.
The program is for the Commodore 64 and 1540/1541
disk drive, but it can easily be modified to operate with the
cassette recorder by changing line 500 to:
508 PRINT" {CLR}":SAVERS:END

How to Use Mailing List


Once you've typed in and SAVEd the program, RUN it. You'll
see a display of eight functions. They are:
1. Add Name. For adding new names and other informa-
tion to your mailing list. After pressing the 1 key, you'll see
another display. It will take you through a step-by-step proc-
ess of entering information you want. Enter the person’s
name, last name first. Don’t use commas to separate last name
from first name. Next you enter the street address, city, state,
zip code, and telephone number. If the person has a place of
business, you can enter that also, along with the work tele-
phone number. If any information requested is unknown,
enter 0 for that category.
2. Removal. You can remove all information under one
name using this function. Pressing the 2 key clears the screen
and then asks for the item to be removed, or erased. Enter the
data item number and the name, and all information under

66
Recreations and Applications 1

that number will disappear from your mailing list.


3. Search. Use this to search through your entire list,
looking for a particular name, address, zip code, or phone
number. The screen clears after you press this key, and asks
for the information you want the computer to search for. If it’s
in the mailing list, it will appear on the screen. If it’s not in
the list, the message “Field Not Found” displays.
4, Examine. You can look at any name and its
accompanying information with this function. You can’t
change anything (see the next function), and when you’re
ready to move back to the main menu, hitting any key will re-
turn you there. This function is best used to check that
information is entered correctly.
5. Change. Perhaps the function you'll use most often,
this function allows you to update any name and its informa-
tion, simply by specifying the item number. (You can locate
the item number of the information you would like to change
by first using the search function. Once the item is found,
you'll see its item number at the top of the screen.) After
you've specified the item number, the information will appear
on the screen, in the order you entered the data. All you have
to do is move down to the line you want to change by hitting ~
the RETURN key the correct number of times. Make sure you
use the RETURN key to move the cursor down, not the cursor
control keys. If you use the latter, you may accidentally insert
unwanted characters into the data. After making your changes,
use the RETURN key to cursor down through the rest of the
data. Hitting the RETURN key when the cursor is on the last
line of data returns you to the main menu.
6. Save Update. When you're finished adding new data
items or changing existing ones, simply press the 6 key. Make
sure that you have a tape in the Datassette or a disk in the
drive before you use this function, for the program will im-
mediately begin to save out to tape or disk. Your new
information is now included in the program.
7. Print. If you have a printer connected to your 64, you
can use this function to print mailing labels from your list.
You'll see the screen clear after you press the 7 key, and you'll
be offered five choices, ranging from printing the entire list to
printing individual mailing labels. You can return to the main
menu by pressing the 5 key from this display.

67
1 Recreations and Applications

8. End. Pressing the 8 key ends the program, showing the


READY message on the screen. Make sure you SAVE any new
information before you use this function.
Each address field is set up to receive eight items of
information, as shown in lines 120 and 130. These items can
be changed to anything you want (for instance, to set up a fil-
ing system instead of a mailing list), but you are limited to
eight items because of the size of the keyboard buffer (line
230). Also, since the DATA statements are printed on the
screen as part of the procedure for adding them to the pro-
gram, you must be careful not to make your items of informa-
tion so wordy that printing eight DATA statements would
cause the first few lines to scroll off the screen and thereby be
lost. Also, make sure that the statement DATA’ END” follows
all the name and information entries.
Search, Space, and Print
At one point, I had a version of this program that used upper-
and lowercase letters, but I found this too inconvenient when
using the “search” function. I often forgot to use appropriate
capital letters either when entering the original information or
when inputting the search value.
To aid in searching, names are entered and stored last
name first, but they are sent to the printer first name first. Do
not use commas when entering your mailing list items.
This program will easily fit into the 64. For instance, I
have 65 names stored, and it takes about 12K of memory. If
you need space for more names just add more DATA state-
ments to the end of the program.
The program prints mailing labels in a single column. Fur-
ther work could be done to print the labels two or three across
the width of the paper, and the formatting could be changed
to match the layout of adhesive labels.
I addressed my Christmas cards with this program (tape
version) and found it a big timesaver, even though I had to
use scissors and tape to put the labels on the envelopes.
A disk drive or printer will certainly enhance the pro-
gram’s usefulness, but neither is essential. The program can
probably be modified to run on other computers, depending
on the size of the keyboard buffer.

68
Recreations and Applications 1

64 Mailing List
For mistake-proof program entry, be sure to use “Automatic Proofreader,” Appendix J.
160 C=53280:REM 64 MAILING LIST PROGRAM-—DISK VERSI
ON srem 1190
118 POKEC, 5: POKEC+1,5:READRS,
R: FORI=1TOR: READOS (I)
:NEXT:DATA"64{2 SPACES}MAILING{2 SPACES}LIST
srem 222
129 DATA8, "NAME(LAST NAME FIRST)", "STREET ADDRESS"
PiCGETY. OSTATE 7 he CODE. :rem 9
130 DATA"HOME PHONE NO.", "COMPANY NAME", "WORK PHON
ENO. srem @
149 PRINT" {CLR} {BLK}{9 RIGHT} KAJ **¥**RRRKKKKKKKKKE
**RSJ"sPRINT"{9 SPACES}B "RS" -" ~srem 144
PRINT"{9 RIGHT } £29 HHKKKKKREKKEKEKEREKEE XS
150
srem 244

166 PRINT"{DOWN} 1. ADD NAME":PRINT"{DOWN} 2. REMO


VAL{4 SPACES}" srem 84
165 PRINT" {DOWN} 3. SEARCH":PRINT"{DOWN} 4. EXAMIN
E srem 248
176 PRINT" {DOWN} {SHIFT-SPACE}5. CHANGE":PRINT"
{DOWN} 6. SAVE UPDATE" srem 149
7S PRINT" {DOWN} 7. PRINT OPTION":PRINT"{DOWN} 8.
{SPACE } END srem 129
1808 RESTORE: PRINT"{2 DOWN}WHICH DO YOU WANT?"
srem 192
196 GETAS : l[FAS="""THEN19G@ :rem 87
26D IFAS<"1]1"ORAS>"8"THEN19@ srem 192
210 READBS: I1FBS$<>"K-j"THEN219 srem 160
228 A=VAL(AS ) sONAGOTO240, 299,320, 428,498,508,520,5
19 srem 235
239 POKE198, 19: FORI=@TO9 : POKE631+1,13:NEXT:END
srem 55
248 READAS : IFAS <>"+3 "THEN24@ srem 110
250 READA:PRINT"{CLR}INPUT @ FOR UNKNOWNS {DOWN}"
srem 2905
266 PRINT"ITEM : "A"{DOWN}":FORI=1TOR:PRINTOS(I):I
NPUTWS (1) :PRINT: LFWS(1)=""THEN14@ srem 186
2708 NEXT: WS (@)="XX"+CHRS (34)+", "+STRS(A) :Z=A*19+91
@:K=0:PRINT"{CLR}{2 DOWN}" srem 172
288 FORI=ZTOZ+R:PRINTI;
"DATA"CHRS (34)WS(K) sK=K+1:N
EXT: PRINT "RUN {HOME }":GOTO239 srem 81
298 BS=""":PRINT"{CLR}WHICH ITEM TO REMOVE ":INPUTB
$:IFVAL(BS )=@8THEN149 srem 247
388 PRINT"{CLR}{2 DOWN}":Z=VAL(BS)*19+910:PRINTZ"D
ATA"CHRS (34) "K+3"CHRS$(34)", "VAL(BS) zrem 185
3196 FORI=Z+1TOZ+R: PRINTI :NEXT: PRINT"RUN{ HOME }":GOT
0230 :rem 213

69
1 Recreations and Applications

326 INPUT"{CLR}SEARCH FOR ";BS$:IFBS=""THEN1L4@


srem 174
336 H=@ s READAS srem 6
335 IFAS="END"THENPRINT" {CLR} {RIGHT} {DOWN}FIELD NO
T FOUND":FORT=@TO 2000:NEXT:GOTO14@ srem 65
348 IFAS="{+] "THENREADA:GOTO33@ srem 71
359 READA: FORI=1 TOR: READAS (1): IFLEFTS(A$(1),LEN(BS$
) )=BSTHENH=1 srem 201
369 NEXT : [FH=@THEN3 39 srem 27
378 PRINT" {CLR}ITEM :"A"{2 DOWN}":FORI=1TOR: PRINT"
{2 SPACES}"AS$(I):NEXT: IFW=1THENRETURN :rem 251
388 PRINT"{2 DOWN}HIT ANY KEY TO PROCEED" srem 233
390 GETAS : IFAS=""THEN390 srem 91
490 IFQ=1THENRETURN srem 241
419 GOTO14@ srem 99
420 AS=""s INPUT" {CLR}WHICH ITEM";AS$:A=VAL(AS):IFAS$
=""ORA<1THEN149 srem 114
436 READAS : IFAS="END"THEN14@ srem 98 .
446 IFAS <>"XX"THEN43@ srem 192
456 READAS : IFA<>VAL (AS ) THEN43@ srem 253
460 READAS (1): IFAS(1)="K+3"THEN149 srem 56
476 FORI=2TOR: READAS (1) :NEXT: Q=1 : GOSUB37@:Q=@:IFW=
1THENRETURN srem 223
489 GOTO149 srem 196
496 W=1 :GOSUB429
:W=0: PRINT" {HOME}{2 DOWN}":FORI=1T
OR: INPUTWS (1) :GOTO279 srem 168
586 PRINT"{CLR}"sSAVE"@@:"+RS,8:END srem 182
519 END srem 199
526 PRINT"{CLR}{2 DOWN}{RVS}{3 SPACES}PRINTER OPTI
ONS{3 SPACES}" srem 127
530 PRINT" {DOWN} {RVS}1{OFF} ENTIRE LIST" srem 82
548 PRINT" {DOWN} {RVS}2{OFF} MAILING LABELS" :rem 5
558 PRINT" {DOWN} {RVS}3{OFF} INDIVIDUAL DATA"
srem 86
560 PRINT"
{DOWN} {RVS}4{OFF} SINGLE MAILING LABEL"
srem 129
576 PRINT" {DOWN} {RVS}5{OFF} RETURN TO PROGRAM"
srem 242
588 GETZ$ : IFZS=""THEN58@ srem 143
596 Z=VAL (ZS) srem 231
69D IFZ<1ORZ>5THEN5 29 srem 32
619 OPEN1,4:RESTORE srem 184
628 ONZGOT0649, 740,819,819 srem 179
638 CLOSE1 :GOTO14@ zrem 72
648 READBS : IFB$<>"f-9"THEN649 srem 174
658 READBS : IFBS="{ +3 "THENCLOSE1 :GOTO14@ srem 81
669 IFBS$="XX"THENREADA: PRINT#1,CHR$(18)CHRS$(10)"IT
EM";A:GOSUB699 :GOTO659 srem 81
670 PRINT#1,B$ srem 16

70
Recreations and Applications 1

689 GOTO65G srem 114


698 READBS : FORI=1T059 z:rem 1
788 IFMIDS(BS,1I,1)="_ "THENX=I:1I=59 srem 96
716 NEXTI srem 32
728 N2S=LEFTS(BS$,X)
:N1S=RIGHTS (BS$,LEN(BS$)-X):PRINT
#1 srem 217
736 PRINT#1,N1$S;" ":N2$:RETURN s:rem 194
746 READBS : IFBS$<>"-j"THEN74@ srem 176
758 READBS : IFBS="«+]j "THENCLOSE1 :GOTO149 srem 82
76 IFBS<>"XX"THEN759 srem 263
776 READA: PRINT#1,CHRS$ (19) s GOSUB699 : GOSUB789 :GOTO7
59 srem 182
780 FORI=1T04:READAS (1) sNEXT srem 226
79 PRINT#1,A$(1):PRINT#1,A$(2):", "“sA$(3):"
{3 SPACES}";A$(4) srem 54
88D RETURN srem 129
819 INPUT" {CLR} {DOWN }WHICH ITEM":Q:RESTOREsrem 157
8208 READBS : IFB$<>"K-3"THEN829 srem 174
839 READ BS srem 29
840 IFBS="€+3"THENPRINT"NO SUCH ITEM ON FILE":FO
=9TO1599:NEXTX:CLOSE1:GOTO 149 srem 125
858 IFBS="XX"THENREADA: I FA=QTHEN879 :rem 181
868 GOTO839 srem 114
876 PRINT #1,CHRS(10)CHRS(18) "ITEM" ;A:GOSUB699
srem 99
889 IFZ=4THENIGD srem 194
899 FORX=1TO R-1:READBS :PRINT#1,B$S:NEXT:CLOSE1:GOT
0528 srem 119
98D GOSUB789 : CLOSE1 :GOTO529 srem 163
9198 DATA" K-3" srem 212
929 DATA"XX", 1 s:rem 6
921 DATA"SMYTHE RANDY srem 48
922 DATA"5998 STATE STREET srem 246
923 DATA"SOMECITY srem 71
924 DATA" SOMESTATE srem 144
925 DATA" B899BD srem 294
926 DATA"111-—555-5555 srem 61
927 DATA“WIDGETS INC. srem 253
928 DATA"111-555-5551 z:rem 59
936 DATA"K+]", 2 srem 254
949 DATA"K+3",3 srem @
958 DATA"K+3",4 srem 2
966 DATA"K+3",5 srem 4
976 DATA"k+3",6 srem 6
989 DATA"K+3",7 srem 8
998 DATA"k+3",8 srem 19
1988 DATA"K+}",9 z:rem 42
1918 DATA"K+3",19 s:rem 83
1026 DATA"END" srem 248

71
1 Recreations and Applications

64 Spreadsheet
Michael Tinglof

Ever wanted to calculate your return on various


investments, each with several interest possibil-
ities? Or tried to figure the best way to organize
your tax deductions, or even your small business
operation? If so, you'll find this spreadsheet pro-
gram invaluable. And it’s not expensive like
some commercial software. Tape or disk can be
used.
(RSET A A

Spreadsheet analysis is one of the most common and useful


microcomputer applications. With this powerful tool, you
can easily evaluate your options and ask what if? questions.
VisiCalc is one of the most widely used and well known
spreadsheet programs. Many people have bought a computer
just to use this kind of program.
If your budget doesn’t enable you to purchase a com-
prehensive package like VisiCalc, but you’d like to do simple
financial models, then you'll find this spreadsheet program
will fit your needs. It’s useful for small spreadsheet problems,
such as for a small business or the home.
Spreadsheet Analysis
What is spreadsheet analysis? Basically, it’s a program that
enables you to set up a financial model in which you can
simulate your options. This usually involves setting up a table
of numbers with defined interrelationships. Once set up, you
can experiment with what if? questions by altering the given
values. Based on the defined relationships, the program auto-
matically recalculates all the values in the table.
For example, consider this model of four different
investments.
(Note that the yields of the respective options are simply
approximations, and the total of the Yield column is
meaningless.)

72
Recreations and Applications 1

In applying this model to the spreadsheet program, four


columns are defined (Principal, Yield, Net, and Earning), and
five rows (Passbook, Treasury Bills, U.S. Bonds, All Saver
Certificate, and Total). Several mathematical relationships are
defined as well: the Net column is defined as the product of
the Yield and the Principal, added to the Principal; the Earn-
ings column is defined as the product of the Yield and Prin-
cipal; and the Total row is defined as the sum of the numbers
in each column.
Once these definitions are set up, you can experiment by
simply changing the given values. The spreadsheet program
will then automatically recalculate the other values. For in-
stance, if you were to change the Principal in this example,
the program would then recalculate the Earnings, the Net, and
the Totals.
Operating 64 Spreadsheet
Using the spreadsheet program is not difficult—in most cases
the program prompts you for the data it needs. The only com-
plicated part is setting up the model at the start. The best way
to learn is by doing, so we'll demonstrate by setting up a
working model of the example shown in the figure.
The first step is to type in LOAD and RUN the
spreadsheet program. When run, the screen clears and a list of
commands appears at the bottom of the screen. This is the
normal operating mode. If a model were set up, it would be
displayed above the command list, and you could experiment
with it by changing values. However, if you’re just starting
out, or beginning a new model, you need to program a model.

73
1 Recreations and Applications

Programming the Model. To do this you must enter the


Program mode, which is the first option in the command list.
Simply hit the P key. The screen again clears, a list of num-
bers appears on the left side of the screen, and a new list of
commands appears in the bottom three rows. The list of num-
bers on the side are line numbers; on these lines the definition
for the model will be stored.
To do this, use the Insert command (the first option now
on the screen) by typing I. The computer will then ask which
line the inserted text should be placed before. Type 1—this line
now contains an END statement which should be the last
statement of the model definition. Next, the computer asks
how many lines are to be inserted; in this case, enter 12.
Row and Column. Beginning with line 1 and continuing
to line 12, the computer will prompt you for each line. In
response, type the following lines, which will be explained as
we go along.
1 NAME RA=PASSBK
(The line numbers don’t have to be typed; the program
supplies them.) This line gives the first row of our example the
name PASSBK, representing passbook savings, which will be
displayed on the left side of the screen in the normal operat-
ing mode. In the designation RA, the R indicates that we are
naming a row, and the A indicates the row A, or the first row.
Only six characters or less are allowed for a row name. There
are 20 rows, each designated by a single letter. Now enter:
2 NAME RB=TRSBIL
3 NAME RC=USBOND
4 NAME RD=ALSAV
5 NAME RE=TOTAL

These are the same as line 1, except they name rows B, C,


D, and E. To name the columns, you could begin by typing:
6 NAME C1l=PRNCPL,6
This names the first column, column 1, PRNCPL. In this
case, the C indicates that it’s a column, and the 1 indicates col-
umn 1. In addition to their names, columns must also be given
a width—in this example, a width of 6. If no width is given,
the program defaults to five characters. Every element in the
column, including the column name itself, must have a length
equal to or less than the given width.

74
Recreations and Applications 1

7 NAME C2=YIELD,5
8 NAME C3=NET,6
9 NAME C4=EARN,6

These are similar to line 6 except that they name columns


2, 3, and 4, respectively.
DEFINE. The next line might be hard to understand at
first. It’s the first mathematical expression used, and its pur-
pose is to set the NET column equal to the product of the
PRINCIPAL column and the YIELD column added to the
PRINCIPAL column. To understand the command, you must
understand the designations used. Enter line 10 as follows:
18 DEFINE @3=@1*@2+@1

First of all, every element in the matrix of rows and col-


umns has its own designation, which is simply the element’s
row letter followed by its column number. That is, element C2
is row C, column 2.
The DEFINE command then sets an element equal to an
expression containing other elements, and possibly constants
such as 2 or .56. Any of the four basic operations of addition,
subtraction, multiplication, and division can be used. How-
ever, no hierarchy of operations is followed.
In a definition command, it might be useful to consider
more than one element at a time. You can use the @ symbol
to do this. It can be used to replace either the column or row
designation. For example, in the DEFINE command above,
@3 indicates all rows in column 3. Note that in the use of @,
each element will still be considered separately. The whole
statement can thus be translated to each row in column three
equals each row in column one times each row in column two,
plus each row in column one. Make sure the @ symbol precedes
the column number and follows the row letter.
When this command is processed, the element to which
the statement is being assigned is considered first. If an @ sign
is present, a loop is executed so that each row or column,
depending on the format, is considered one at a time. For
example, when executing @3, the program takes each column
in turn as the current column, evaluates the expression, and
assigns the value to the current column. On the other hand,
when an @ designation appears in the expression, it is
replaced by the current value. For example, if @1 appeared in
the expression, it would be replaced by the current column
number. Although this designation might appear complicated
75
1 Recreations and Applications

at first, it is really quite simple, yet allows complicated


mathematical relationships to be constructed easily. If you
don’t understand it yet, don’t worry. For now, you can make it
easier by using only absolute designations, such as A2.
1l DEFINE @4=@1*@2
12 DEFINE E@=A@+B@+C@+D@

These follow the same rules as the first definition.


If you make a mistake, don’t worry. During line entry, the
delete key is functional. If you made a mistake on a previous
line, use the Change command later to replace it; if you forgot
a line, use Insert to put it in the program.
Note that the order in which elements are DEFINEd is
important because one definition statement can involve values
computed by other definitions.
To experiment with the model once it is set up, return to
the normal operating mode by using the E key, for Exit option.
The screen clears, the columns and rows named are displayed,
and zeros are printed. The next step is, of course, to replace
the zeros with applicable numbers.
Entering Data. The Change command allows you to
change any value on the screen. To use it, simply type C. The
program will then ask you for the row and column—use the
same designations used in the program mode, such as A3, and
so on. It will then ask you for the value to be entered into the
matrix.
Next, the number will be displayed in the appropriate row
and column. However, the other values are not recalculated.
Because this spreadsheet program is written in BASIC, it is not
very fast—so you can change/input as many values as nec-
essary. When you are finished entering numbers and wish to
see the results, use the Redraw screen command by hitting the
R key. The spreadsheet program will then recompute all the
values, as expressed in the DEFINE commands.
The first step is to enter the yield values in column 2. Use
the Change command to enter .06 for row A, column 2; .09
for row B, column 2; and so on until all yield values seen in
the figure have been entered. Then enter trial investment val-
ues into the Principal column (column 1) for each row.
Finally, type R to have the computer calculate your earnings.
You've just created your first financial model. Experiment
with it by changing values with the C command and redraw-

76
Recreations and Applications 1

ing the screen. Design other models, and implement them


using the spreadsheet program.
Saving. There is one final step before you finish using the
spreadsheet—saving it. If you wish to use it again, use the
Save worksheet command to store it. At a later date you can
use the Load worksheet command to restore it.
When you want to save a worksheet, just enter a
filename, which can be up to ten characters long. You don’t
have to specify the disk drive using ,8; just the filename. If
you want to load a worksheet, simply type L, and then the
filename when the prompt appears.
If you want to save and load worksheets using tape in-
stead of disk, you will have to make a few changes in the 64
Spreadsheet program. Modify the following lines:
519 OPEN1,1,1,1$ s:rem 76
6198 OPEN1,1,9,1S:IFST<>S9THEN679 srem 50
1619 OPEN1,1,1,1$:FORX=1TO19@ srem 153
1719 OPEN1,1,9,1IS:IFST<>OTHEN175@ srem 148

Reference Guide
The following is a list of the instructions and a brief descrip-
tion for each.
Change Value. Allows you to change the value of any
element of the screen. Uses the standard row/column designa-
tion to indicate the desired element.
Redraw Screen. Clears the screen and recalculates every
value based on the DEFINE statements.
Save Worksheet. Saves the worksheet, including all en-
tered data and the instructions set in program mode.
Load Worksheet. Loads a worksheet saved by the above
command.
Exit. Exits the program to BASIC.
Program Mode. Enters the program mode for which the
following commands are used:
e Insert—inserts a line(s) into the instruction list starting
at the line you select.
e List—lists a specified part of the program. Accepts a
line number, clears the screen, and lists from the given line to
the given line plus 20.
e Change—accepts a line number and allows you to
reenter that program line.

WL
1 Recreations and Applications

@ Save—saves the instruction lines, but not the numbers


in the worksheet.
@ Read—reads an instruction set, saved as above, into
memory.
e Exit—returns to the normal operating mode.
Instructions in Program Lines
@ NAME—names a column or row, sets column length.
ex: NAME C3=TEST,4
e@ DEFINE—sets an element equal to an expression. ex:
DEFINE A3=C3+B1

Plus and Minus


This spreadsheet program will probably be most useful for
home and small business applications. Although limited to a
table with 20 rows and, depending on column width, 5 or 6
columns, it’s a powerful tool. It allows experimentation with
financial models, and replaces error-prone and time-consuming
paper and pencil exercises. This type of experimentation and
recalculation enables you to explore various options and select
the best one.
Program Notes
This command will clear the worksheet:
e DEFINE @@=0
e@ Remember that constants can be used in expressions, as is
the zero in the above statement.
®@ The Load command in the program mode can be used to
load a program saved in the normal mode without loading
the numeric data.
e If the program exits to BASIC type ‘GOTO 100’ to return
without losing your data.

64 Spreadsheet
For mistake-proof program entry, be sure to use “Automatic Proofreader,” Appendix J.
1@ REM COMMODRE 64 SPREADSHEET srem 61
29 REM srem 79
38 DIMPC%(118),PC$(118),WK(28,9),RN$(28),CNS$(9),CW
(9),CP(9) srem 43
48 X=6:SL=0:LL=0:L=0 :CC=0:CR=0 srem 14
45 R$(1)="DEFINE":RS$(2)="NAME":R$(3)="END":PC$(1)=
3 srem 219
58 S$="{39 SPACES}" zrem 93

78
Recreations and Applications 1

6@ CS$="{HOME}{23 DOWN}" srem 232


65 POKE53280,15:POKE53281,1:PRINT"K59" srem 154
76 PRINT" {CLR}"LEFTS(C$,8)TAB(18)"SPREADSHEET ANAL
YSESia srem 159
88 REM srem 76
98 PRINTLEFTS(CS,24)TAB(8)"HIT RETURN TO CONTINUE
{ SPACE }"; :GOSUB19009 srem 230
198 GOSUB59899 srem 214
195 GOSUB699G srem 228
116 PRINT"{RVS}P{OFF}ROGRAM MODE {RVS}C{OFF}HANGE
{SPACE}VALUE {RVS}R{OFF}EDRAW SCREEN" :rem 52
120 PRINT"{RVS}S{OFF}AVE WORKSHEET [{RVS}L{OFF}OAD
{SPACE}WORKSHEET {RVS}E{OFF}XIT" zrem 81
138 GOSUB199B9 srem 5
168 IFXS="R"THEN1OO :rem 53
170 IFXS="E"THENPRINT"{CLR}":END:GOTO199 srem 17
188 IFXS="S"THEN52@ :rem 60
198 IFXS="L"THEN600 zrem 55
200 IFXS="P"THEN1OGOS srem 94
218 IFXS="C"THEN4GO srem 37
228 GOTO185 2 srem 99
480 GOSUB6999:PRINT"CHANGE WHICH ROW: "; :GOSUB19GOG
:PRINT srem 221
418 CR=ASC(X$)-64:I1FCR<1ORCR>20THEN1@5 srem 8
415 PRINT"CHANGE WHICH COLUMN:";:GOSUB1990@:
PRINT
srem 57
428 CC=VAL(X$) : IFCC=@THEN1@5 :rem 138
430 PRINT" INPUT VALUE: "; : 1=20:GOSUB9090:WK(CR,CC)=
VAL(IS) srem 225
448 GOSUB579@:GOTO195 :rem 237
588 GOSUB690G:PRINT"SAVE WORKSHEET AS:";:I=1%:GOSU
B90: IFIS=""THEN1@5 srem 250
518 OPEN1,8,2,1S+",S,W" :rem 197
515 FORX=1TO10@:PRINT#1,PC%(X)CHRS$(13)CHRS$
(34) PCS (
X)CHRS (13); srem 228
52@ IFPC%(X)<>3THENNEXT :rem 162
53@ FORCR=1T02@:FORCC=1T0O9: PRINT#1,WK(CR,CC)CHRS$(1
3);:NEXT:NEXT srem 229
546 PRINT#1,CHRS$(13);:CLOSE1:GOTO199 zrem 124
6G GOSUB6808:PRINT"LOAD WORKSHEET: "; :I1=10:GOSUB9G
OG: IFIS=""THEN1O5 srem 88
618 OPEN1,8,2,1$+",S,R":1FST<>STHEN679 :rem 167
628 FORX=1TO100: INPUT#1,X$,PCS$(X) :T=ST: PC%(X)=VAL(
XS): IFT<>OTHEN679 srem 88
630 IFPC%(X)<>3THENNEXT srem 164
648 FORCR=1T0O20:FORCC=1T09: INPUT#1,X$:T=ST:WK(CR,C
C)=VAL(XS$) : IFST<>S@THEN67 :rem 249
658 NEXT:NEXT:CLOSE1 :RC=1:GOTO10@ srem 117
670 PRINT"TAPE ERROR.":PRINT"HIT ANY KEY TO CONTIN
UE "“;:GOSUB1OGOD srem 255

79
1 Recreations and Applications

688 CLOSE1:RC=1:GOTO 199 srem 134


19990 FL=1 srem 193
1818 PRINT"{HOME}">;: FORX=FLTOFL+29:PRINTSS : PRINT"
{UP}"X;RS(PC3(X))" "PCS$(X):NEXT :rem 157
1828 GOSUBE6GBO srem 9
1930 PRINT"{RVS}I{OFF}NSERT {RVS}L{OFF}IST {RVS}D
{OFF}ELETE {RVS}C{OFF}HANGE {RVS}S{OFF}AVE
{RVS}R{OFF}EAD" srem 34
1935 PRINT"{RVS}E{OFF}XIT" srem 120
1848 GOSUB1290G srem 54
1958 IFXS="E"THENRC=1:GOTO19@ :rem 205
1960 IFXS="I"THEN1290 srem 142
1978 IFXS="L"THEN1 3980 srem 147
1988 IFXS="D"THEN149@ srem 141
1990 IFXS="C"THEN1590 srem 142
1108 IFXS="S"THEN1600 srem 151
1118 IFXS="R"THEN179@ srem 152
1128 GOTO1929 srem 192
1208 GOSUB6990:PRINT" INSERT BEFORE LINE:";:GOSUB89
90:SL=VAL (IS) srem 132
1218 IFSL=O0THEN19206 srem 81
1228 PRINT"NUMBER OF LINES: "; :GOSUB8998:N=VAL(IS):
N1=190-N: IFN=OTHEN1 920 zrem 86
1238 FORX=N1TOSLSTEP-1 : PC% (X+N)=PC3(X) sPCS(X+N)=PC
$(X):NEXT srem 120
1235 N=N-1:FORL=SLTOSL+N:GOSUB8000:NEXT srem 1
1248 GOTO1910 srem 194
1300 GOSUB6900:PRINT"START AT WHICH LINE:";:GOSUB8
990 srem 2206
132Q@ IFVAL(I$)=G8ORVAL(IS$)>88THEN1G29 :rem 61
1338 FL=VAL(IS) :GOTO1016 srem 108
1490 GOSUB6800:PRINT"DELETE FROM LINE: "; :GOSUB8999
:SL=VAL(1IS$) : 1FSL=@THEN1 920 srem 172
1418 PRINT"TO LINE:"; :GOSUB8999:LL=VAL(I$):IFLL=0T
HEN192@ srem 219
1428 N=LL-SL+1:FORX=SLTO100-N: PC%(X)=PC% (X+N) : PCS (
X)=PCS$ (X+N) :NEXT srem 241
1438 GOTO191¢ srem 195
1588 GOSUB68908:PRINT"CHANGE LINE NUMBER:"; :GOSUB89
90:L=VAL(IS) srem 27
1518 GOSUB8909:GOTO1919 srem 68
1608 GOSUB690G:PRINT"SAVE PROGRAM AS:";:I=1@:GOSUB
9900: IFIS=""THEN1G20 srem 181
1618 OPEN1,8,2,1S$+",S,W":FORX=1T0O109 srem 18
1620 PRINT#1,PC%(X)CHRS$(13)CHRS$(34)PCS$(X)CHRS$(13);
srem 247
1638 IFPCS(X)<>3THENNEXT zrem 213
1648 CLOSE1:GOTO19O@O :rem 166

80
Recreations and Applications 1

1786 GOSUB688G:PRINT"LOAD PROGRAM:"; :I=1%9:GOSUB90G


@: I FIS=""THEN1O20 srem 19
1716 OPEN1,8,2,1S$S+",S,R":IFST<>OTHEN1 756 srem 9
1722 FORX=1T0O100: INPUT#1,X$,PCS(X):PC%(X)=VAL(XS)
srem 133
1738 IFPC$%(X) <>3THENNEXT srem 214
1749 CLOSE1 :GOTO199@ :rem 167
1756 PRINT"TAPE ERROR":PRINT"HIT ANY KEY TO CONTIN
UE ";:GOSUB1OGOD srem 1
1766 CLOSE1 :GOTO199@ srem 169
4999 END s:rem 182
5866 IFRC=9THEN549@6 srem 78
5865 FORX=1T09:RNS(X)=""sCNS (X)=""sCW(X)=0:CP(X)=0
:NEXT :rem 218
5697 FORX=19T0O290:RNS(X)=""sNEXT srem 79
5619 RC=@ : FORL=1 T0190: IFPC$(L)=3THEN5319 srem 93
5828 IFPC3(L) <>2THEN5 390 :rem 78
5830 XS=LEFTS(PCS(L),1):NS=MID$(PCS(L),2,1)srem 25
5848 IFXS="C"THEN5100 srem 141
5850 IFXS="R"THEN5200 zrem 158
5860 GOTO5900 srem 210
5190 FORX=4TOLEN(PCS(L)):IFMIDS(PCS(L),X,1)<>",
"TH
ENNEXT: LN=5 :GOTO512@ srem 195
5118 LN=VAL(MIDS(PCS(L),X+1)) srem 85
5126 N=VAL (NS ) : LFN=9THEN59@0 srem 122
5130 CNS$(N)=MIDS(PCS(L),4,X-4) :CW(N)=LN srem 140
5148 GOTO5300 srem 203
5290 N=ASC(NS )-64: I FN<1ORN> 20THEN599G s:rem 147
5216 RNS (N)=MIDS$(PCS$(L),4) srem 107
5386 NEXTL srem 83
5316 CP(1)=@:FORX=2T09:CP(X)=CP(X-1)+CW(X-1)+ABS(C
W(X)>@):NEXT srem 164
54008 PRINT" {CLR} {RVS}"; :FORX=1T09: PRINTTAB(CP(X)+8
) RIGHTS (SS+CNS(X),CW(X)); srem 104
5419 NEXT: PRINT srem 288
5426 FORX=1T020:PRINT"{RVS}"LEFTS (RNS (X),6) :NEXT
srem 130
5456 FORL=1 T0190: IFPC%(L)=3THEN5 700 srem 44
5460 IFPC$(L)<>1THEN5699 srem 97
5476 XS=LEFTS (PCS$(L),2):AC=VAL( RIGHTS (X$,1)):IFAC<
1ORAC > 9THENAC=0 s:rem 76
5489 AR=ASC(XS$ )-64: IFAR<1ORAR> 2@THENAR=9 srem 168
5496 CC=AC : IFAC=@THENRC=1 : FORCC=1T0O9 srem 246
5495 CR=AR: ILFAR=@THENRR=1 : FORCR=1 T0290 srem lll
55808 IFMIDS(PCS(L),3,1)<>"="THEN590@ srem 176
55198 XS=MIDS(PCS(L),4) sOPS="+":S=1:T=0 srem 38
5529 FORX=STOLEN (XS) :NS=MIDS(X$,X,1):IFNS="+"ORNS=
"-"ORNS="/"ORNS="*"THEN5550 srem 166
5549 NEXTX srem 191

81
1 Recreations and Applications

5558 NS=MIDS(XS$,S,X-S) :S=X+1 s:rem 74


5560 IFNS="0"ORVAL (NS ) <>@THENV=VAL (NS ) sGOTO5619
srem 26
5565 IFLEN(NS ) <>2THEN5900 srem 175
5576 TRS=LEFTS(NS,1):TCS=RIGHTS(NS,1) s:rem 59
5586 TR=ASC(TRS )-64: IFTR<LORTR> 2OTHENTR=CRsrem 168
55968 TC=VAL (TCS) : IFTC<1ORTC>9THENTC=CC srem 155
5698 =WK(TR,TC) srem 186
5616 IFOPS="+"THENT=T+V srem 95
56206 IFOPS="—-"THENT=T-V srem 190
5630 IFOPS="/"THENT=T/V srem 195
5640 IFOPS="*"THENT=T*V srem 96
5656 IFX<LEN (XS ) THENOPS=MIDS (X$,X,1):GOTO552G
srem 185
5669 WK(CR,CC)=T srem 156
5676 IFRR=1THENNEXTCR srem 118
5680 IFRC=1THENNEXTCC srem 89
56908 RR=9 : RC=0 : NEXTL srem 230
5786 PRINT" { HOME} { DOWN} "; s:FORCR=1T0O2@: I1FRNS$(CR)=""
THEN5795 srem 34
S7LO FORCC=1T09:PRINTTAB(CP(CC)+8); srem 123
5729 XS=MIDS$(STRS (WK(CR,CC)),2) srem 220
5736 IFLEN (XS ) <=CW(CC) THEN579@ srem 248
57408 FORX=1TOLEN (X$):IFMID$(X$,X,1)<>"."THENNEXT:G
OTO579G srem 227
5750 NS=LEFTS (X$,X-1) srem 126
5760 IFLEN (NS ) <CW(CC) THENNS=NS+MIDS(X$,X,CW(CC)-LE
N(NS) ) srem 230
5786 XS=N$ srem 255
5798 PRINTRIGHTS (S$+X$,CW(CC))+::NEXTCC srem 74
5795 PRINT:NEXTCR srem 117
5886 RETURN srem 173
59608 GOSUB6900:PRINT"SYNTAX ERROR IN LINE"L
srem 155
5916 PRINT"HIT ANY KEY TO CONTINUE ";:GOSUB1OO9O
srem 68
5926 RETURN s:rem 176
6806 PRINTLEFTS (CS, 22)S$:PRINTSS:PRINTSS:PRINTLEFT
$(CS$,22): srem 118
6919 RETURN srem 167
809 GOSUB69809:PRINTL; srem 92
8819 I=35 :GOSUB9099: IFIS=""THEN89OD srem 232
8820 FORX=1TOLEN(IS$):IFMIDS$S(I$,X,1)<>"
"“THENNEXT
rem 73
8830 PC$(L)=MIDS$(I$,X+1):PC$(L)=0 srem 244
8040 XS=LEFTS (1I$,X-1) :FORX=1T0O3:IFXS=RS
(X) THENPC$ (
L)=xX srem 235
895d NEXT: RETURN srem 38
89968 I=3 : GOSUB99GG srem 22

82
Recreations and Applications 1

8992 IFVAL(IS)<1lORVAL(IS$)>190@THENIS="" srem 167


8995 RETURN srem 191
8999 I=3 srem 156
9960 IS=""s;POKE294,98:POKE205,
20 srem 160
9918 GETXS:IFXS=""THEN9G19 srem 229
9820 C=ASC(XS$)
s:IFC=20THENIG6G srem 152
9825 IFC=13THENPOKE2904,1:PRINT" ":RETURN srem 185
9930 IF(C>31ANDC<95)OR(C>192ANDC<219 ) THENIG4G
srem 74
9835 GOTOIG1G srem 212
9949 IFLEN(IS$)=ITHEN9010 srem 120
985G PRINTXS; : IS=1$+X$:GOTO9G19 srem 71
9860 IFIS=""THENIG1G srem 69
9878 PRINTXS; :IS=LEFTS(1I$,LEN(I$)-1):GOTO9919
srem 105
180GG@ POKE2904,9:POKE295,20 srem 160
189019 GETXS:I FXS=""THEN1GO10 srem 53
18828 POKE204,1:PRINTXS; : RETURN srem 173

83
‘eg eepeer te Va
Sein we
2

Kid Stuff—
|
Seibre-taleyet-l merheslec
Kid Stuff—Educational Games 2

Educational
Games:
A Kid’s View

Here’s a kid’s-eye view of educational computer


games—what they should do, how they should
teach, and why they should entertain. The writer
concludes his article by presenting “BLAM!,” a
game for the Commodore 64 that demonstrates
his concepts. A joystick is required.
i
a

Have you ever tried to write an educational game? If you


have, chances are you found it pretty hard. Sure, it’s easy to
make a simple addition and subtraction program, but educa-
tion doesn’t stop there.
There are many other areas to cover. I know. I’m only 12
and in the seventh grade. We have computers in our school
and a variety of educational games. But, unfortunately, some
of the games aren’t too good. The main flaw that I see in
them, and a lot of my classmates agree, is that they are too
easy.
Take, for instance, a math program we had last year.
There was only one skill level, and it was just basic multiplica-
tion with zeros on the end of the numbers to make it seem
harder. The game itself had a very good concept but didn’t
teach you a thing (unless you're in the third grade, and the
game was supposed to be sixth-grade level).
Educational Guidelines
Now, if that is what comes from experts, how are ordinary
people supposed to write good educational games? Pro-
grammers should keep in mind the following things:
1. You should make your game one that teaches someone

87
2 Kid Stuff—Educational Games

something. After you’ve thought of your idea, ask yourself, ‘Is


this truly educational or just a near miss?” This will help very
much.
2. Your game should have varying skill levels. It should
have levels to challenge the slowest to the fastest student.
3. Use good graphics so your game will be appealing to
look at.
4, Have good sound effects. It’s good for the player to get
a rewarding sound or song if he or she is correct.
5. Most of all, make your game interesting and fun. How
many kids want to sit and play a boring game, no matter how
educational it is? Not many. It’s good, in some cases, to make
your game half-arcade and half-educational.
Those are the five essential elements of good educational
games. Try to include them when writing one.
Now, here’s a game I’ve made: I call it “BLAM!” It’s
educational and fun, and I hope you enjoy it.
Game Description
BLAM! is a half-arcade and half-educational game. You must
maneuver your player around a building filled with bombs,
while trying to disarm all the explosives. You move your player
with the joystick and, once you've run into a bomb, disarm it
with the keyboard.
You disarm bombs as follows: there is a number at the
top of the screen next to the time clock. When you run into a
bomb, another number appears at the bottom of the screen,
under the blue line. You subtract this number from the one at
the top and type your answer. If you’re correct, the bomb dis-
appears and you have one less bomb to disconnect. But if you
subtract wrong, the bomb explodes! You can survive the
explosions, but after three, the whole place falls apart. When
you give a wrong answer, the correct answer appears at the
top of the screen.
You get only five minutes to clear each story of bombs,
because they are time bombs. When you clear a story, you go
on to the next, which has ten more bombs than the one be-
fore. There are six stories in the building and, if you clear
them all, you win the game.
There are also variable skill levels. At the beginning of
the game, you choose a skill level from 1 to 100. Skill level 1
uses only numbers through 100, level 2 uses numbers through

88
Kid Stuff—Educational Games 2

200, and so on. Only very, very smart people should play on
level 100.
Ways to Change BLAM!
You can raise the possible skill levels by changing the 100’s in
lines 5 and 6. You can vary the number of stories in the build-
ing by changing the 70 in line 131 to the number of stories
you want multiplied by ten, plus ten. For example, to make a
four-story building, change the 70 to 50.

Blam!
For mistake-proof program entry, be sure to use “Automatic Proofreader,” Appendix J.

2 POKE53281,4:POKE53289,14 srem 192


3 GOTO59B srem 1
4 SC=53281:B0=53280: POKESC, 1: POKEBO,1@:PRINT" {CLR}
{9 DOWN}"TAB(15)"{RVS}{RED}SKILL LEVEL" :rem 37
5 PRINT" {DOWN}"TAB(15)"(1-108) ";:INPUT A :rem 111
6 IFA<1lORA>1O@0THEN4 <rem 135
7 PRINT"{2 DOWN}"TAB(11)"USE JOYSTICK PORT 2":FORT
=1T0O20090:NEXT: Y=RND(@) : B=A*109:H=19 srem 151
8 W=54272:FORT=WTOW+24: POKET, 0: NEXT: POKEW+24,15:PO
KEW+5, 17: POKEW+6, 241:GOTO25 srem 75
9 J=INT(RND(1)*1I):PRINT"{HOME}{22 DOWN}{9 RIGHT}("
:J;") BLAM NO. "; s:rem 229
19 POKE198,@:INPUTKS
: K=VAL(KS) srem 44
11 IFK+J=ITHENPRINT"{RVS}{DOWN}{15 RIGHT}CORRECT! !
{OFF}"; srem 46
12 IFK+J<>ITHENPRINT"{DOWN}{16 RIGHT}{RVS}WRONG...
": sGOTO8D srem 149
13 POKEC, 32:M=M+1:IFM=HTHEN119 srem 48
14 FORT=1T025 : POKEW, 71: POKEW+1, 71 : POKEW+4, 33: FORQ=
1TO5@:NEXT: POKEW+4, 32:NEXT srem 87
15 FORN=19190T02015: POKEN, 32:NEXTN :rem 29
16 GOTO38 srem ll
25 C=1524:D=55796 srem 126
27 PRINT" {CLR}":POKEBO,
4: POKESC,1:FORF=1TOH:rem 67
28 G=INT(RND(1)*760)
+40: V=PEEK(G+1924) :IF(V<>32)OR
(G=58@ ) THEN28 srem 85
29 POKEG+55296,@: POKEG+1924, 66 srem 173
38 NEXTF: PRINT" {HOME}{2@ DOWN} {BLU }DDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDDDDDDDDDDD" ; srem 84
34 RESTORE :rem 139
35 FORF=1T0O3@:READL,Q: POKEW, L: POKEW+1,Q: POKEW+4,17
: FORT=1T0O59 : NEXT: POKEW+4, 16 srem 194
36 POKEW+1,L-29: POKEW, Q: POKEW+4, 17:FORT=1T059:NEXT
: POKEW+4, 16:NEXT srem 299
37 TIS="G8000G":I=INT(RND(1)*B):PRINT"
{HOME }
{9 RIGHT}TIMER" srem 62
89
2 Kid Stuff—Educational Games

38 POKED,4:POKEC,
65 srem 129
49 JS=PEEK(56329) :JS=15-(JSAND15):JS=JS+1:REM READ
JOYSTK srem 173
41 KD=C:ONJSGOTO51,42,43,51,44,45,46,51,47,48,49
srem 87
42 POKEKD, 32:C=C-—4@:D=D-49:GOTO51:REM NORTH:rem 85
43 POKEKD, 32:C=C+4@:D=D+48:GOTO51:REM SOUTH:srem 98
44 POKEKD, 32:C=C-1:D=D-1:GOTO51:REM WEST :rem 169
45 POKEKD, 32:C=C—-41 :D=D—41:GOTO51:REM NW :rem 116
46 POKEKD, 32:C=C+39 :D=D+39:GOTO51:REM SW :rem 132
47 POKEKD, 32:C=C+1:D=D+1:GOTO51:REM EAST :s:rem 146
48 POKEKD, 32:C=C-39:D=D-39:GOTO51:REM NE :rem 115
49 POKEKD, 32:C=C+41:D=D+41:GOTO51:REM SE :rem 1983
5@ POKEKD, 32:C=C-49:D=D-49:REM NORTH srem 123
51 DV=DV+1 : IFDV=19THENPOKEW+4,
129: POKEW+4, 128:DV=0
srem 55
52 IFPEEK(C)=68THENC=C-16@:D=D-169 srem 211
53 IF C<1964 THEN C=C+4@:D=D+4¢d srem 89
54 IFPEEK(C)=66THEN9 srem 194
55 TS=RIGHTS(TIS,3):PRINT"{HOME}{15 RIGHT}";TS;"
{18 RIGHT}"-;I srem 219
56 IFTS>"500"THEN20@ srem 74
68 GOTO38 srem 19
88 POKEC, 67:FORT=199TOILSTEP—2:
POKEW+1,T: POKEW+4,12
9:POKED, 2 srem 179
81 POKED,5:NEXTT:FORTT=1T0O50:NEXTTT
: PRINT" { HOME }
{RVS}{2 RIGHT}CORRECT{OFF} BLAM! {RVS} NO.=";I-J
:NN=NN+1 srem 213
82 POKEW+4,128:IFNN=3THEN209 srem 172
83 FORT=1T04909:NEXTT:
PRINT" {HOME}{31 SPACES}"
srem 102
84 M=M+1:IFM=HTHEN11@4 srem 251
85 FORN=1919T02915: POKEN, 32:NEXTN:GOTO37 srem 1
119 PRINT"{CLR}{DOWN}{14 RIGHT}GOOD WORK! !":M=0
srem 63
119 ER=28 srem 217
120 FORU=8TO3 : POKEW+1, ER*U: POKEW, 49: POKEW+4,17:FOR
T=1TO19000:NEXT:NEXT srem 181
130 POKEW+4, 16:H=H+19 srem 159
131 IFH=79THEN600 s:rem 213
132 PRINT"{6 DOWN}{3 RIGHT}YOU GOT ALL THE BOMBS O
UT OF THAT" srem 246
133 PRINT"STORY, BUT THE TERRORISTS PUT EVEN MORE"
srem 124
135 PRINT"IN THE NEXT.":PRINT"{4 DOWN}{13 RIGHT}SE
E YA AGAIN!" srem 15
139 ER=28 srem 219
148 FORU=0TO3: POKEW+1, ER*U: POKEW, 49: POKEW+4,17:FOR
T=1TO1990:NEXT:NEXT srem 183
145 POKEW+4,16 s:rem 18

90
Kid Stuff—Educational Games 2

150 FORI=1 T0300 : NEXT: GOTO25 srem 237


286 FORT=19@TOOSTEP—2 : POKEW+1,T: POKEW+4,129
srem 149
282 POKESC, INT(RND(1)*16):POKEBO, INT(RND(1)*16):PR
INT" {CLR}" srem 175
284 NEXT : POKEW+4, 128 srem 187
210 PRINT" {CLR}":POKEBO,@:POKESC, 9:PRINT"{5 DOWN}
{1l RIGHT}{WHT}THE PLACE BLEW UP|" srem 132
215 PRINTTAB(14)"GAME OVERI!" srem 142
218 PRINT"{7 DOWN}"TAB(11)"PLAY AGAIN (Y/N)?"
srem 173
228 GETAS : LFAS=""THEN229 srem 75
225 IF AS="Y" THEN M=@:GOTO4 srem 247
2308 SYS2948 srem 98
469 DATA5®,58,50,509,50,50,50,50,58,50,50,50,50,50,
58,58,58,59,58,58,50,50 zrem 248
463 DATA5®@,58,58,58,50,50,50,508 srem 13
494 DATA7@,70,70,70,10,70,10,70,10,70,70,70,78,7@,
68,66,64,62,60,58,56,54 srem 67
465 DATA52,59,48, 46,44, 42,498, 38 srem 38
59D PRINT"{CLR}{11 DOWN}"TAB(11)"{WHT}A FEW MOMENT
Sisrenenes srem 179
55 POKE52, 48: POKE56, 48:CLR: POKE56334, PEEK(56334)A
ND254 srem 216
596 POKE1, PEEK(1)AND251 : FORN=8T02047 : POKEN+12288,P
EEK (N+53248) sNEXTN srem 84
519 FORF=1T0O6@ : READX : NEXT: FORF=9T0O31 : READX: POKEF+1
2898 ,X:NEXT srem 196
528 POKE 1,PEEK(1)OR4:
POKE56334, PEEK(56334)OR1
:rem 134
523 POKE 53272, (PEEK(53272)AND249)+12 srem 185
525 DATA56, 56,144, 254,58,56,48,198, 28,16,56,124, 25
4,254,124,56 srem 52
535 DATA215, 254,124,255, 255, 223,147,161 srem 184
548 DATA255, 255, 255, 255, 255, 255,9,98 srem 239
5698 GOTO4 srem 8
689 REM YOU WIN! srem 134
695 PRINT"{6 DOWN}{3 RIGHT}YOU CLEARED THE BUILDIN
G OF BOMBS." srem 123
619 PRINT" {DOWN}{3 RIGHT}YOU ARE A VERY GREAT PERS
ON.":PRINT"{3 DOWN}"TAB(13)"PLAY AGAIN?"
srem 135
612 GETAS : IFAS=""THEN612 srem 85
626 IF AS="Y" THEN PRINT"{CLR}":M=0:GOTO4 srem 148
636 SYS 2948 srem 182

91
2 Kid Stuff—Educational Games

Wordspell
Richard Herrmann

With your own list of words, you can use


“Wordspell” to help your children practice
spelling. This educational program for grades 1
through 9 can be used with tape or disk.

“Wordspell” makes good use of what is called the “dynamic


keyboard” technique. This allows a program to modify itself
as it is running. In Wordspell, the practice spelling words you
enter become part of the program. At the beginning of the
program, you are prompted to enter 20 words. After the words
are entered, the dynamic keyboard routine merges them into
the program as line-numbered DATA statements. This permits
you to SAVE the program with the words included so they
will not have to be reentered for the next practice session.
Once the spelling list is entered, it is presented one word
at a time. The words are quickly spelled letter by letter and
then disappear. You then type in the word, and you are told if
it is correct—or you're shown the correct spelling if it is
wrong. At the end of the program, a score is displayed, as well
as a list of the misspelled words. The user now has the option
of quitting the program, running the same words, or entering
new words.
Notes on the Program
REM statements point out major routines.
DATA statements are created as lines 1, 5, 9, 13, and 17.
Main variables are:
A$() - DATA array
B$( ) - Create word list array
W$() - Misspelled words array
A$ - INPUT of user spelling
With a little work, the program could be modified to
accept more or fewer than 20 words.
Timing loops (lines 37 and 46) for viewing letters and

92
Kid Stuff—Educational Games 2

responses may be easily altered to adapt Wordspell to dif-


ferent age groups. My nine-year-old son finds the default val-
ues suitable.
Wordspell
For mistake-proof program entry, be sure to use ‘‘Automatic Proofreader,” Appendix J.

@ PRINT" {CLR}":PRINTCHRS
(14) : POKE53289,7:POKE53281
1:GOSUB61 srem 282
2d PRINT" {CLR} {BLK}{4 DOWN}{3 RIGHT}{3 SPACES}CREA
TE NEW LIST":INPUT"{2 DOWN}{4 RIGHT}{2 SPACES}(
Y OR N)";RS: IFRS="Y"THEN5G srem 1983
IFRS <>"N"THEN21 srem 7
DIMAS(19),WS(19) zrem 194
FORP=@TO19:READAS(P) :NEXT srem 237
FORP=6TO19 srem 25
PRINT" {CLR}" srem 205
PRINT"{9 DOWN}" srem 212
PRINTTAB( INT (4@-LEN(AS(P)))/2) srem 132
GOSUB35 srem 75
GOSUB4@ srem 72
NEXT srem 164
GOTO71 srem 7
REM PRINT OUT WORDS :rem 95
FORX=1TOLEN(AS(P)) :rem 238
PRINTMIDS(AS(P),X,1); srem 103
FORT=1TO30@0 : NEXT srem 194
NEXT :rem 174
RETURN srem 76
PRINT" {CLR}":PRINT"{9 DOWN}" srem 188
PRINTTAB( (INT (49-LEN(AS(P)))/2)-2)
: INPUTAS
srem 93
IFAS=AS (P)THENPRINT"{CLR}":PRINTSPC(
215)"
{5 DOWN}CORRECT !":GOSUB9@:GOTO46 :rem 18
ws (P)="W":GOSUB81 srem 126
PRINT" {CLR}":PRINT"{4 DOWN}"SPC(17);"WRONG !":P
RINT"{2 DOWN}"SPC(9)" CORRECT{ SHIFT-SPACE }SPELL
ING{SHIFT-SPACE}IS:" :rem 78
PRINT: PRINT: PRINT: PRINTTAB( INT (48-LEN(AS(P)))/2
)AS (P) :K=K+1 srem 70
FORT=1TO2900 :NEXT srem 241
POKE 53289,7 z:rem 255
RETURN :rem 76
REM CREATE WORD DATA :rem 91
PRINT" {CLR}":DIMBS$(19) srem 254
FORI=9TO19: PRINT"WORD";I+1l1;:INPUTBS(I):NEXT
:rem 181
PRINT"{CLR}{2 DOWN} {WHT}" srem 242
FORI=98TO1L9YOSTEP4 z:rem 130

93
2 Kid Stuff—Educational Games

54 PRINT1+I;"DA"CHRS (34)BS$(1I)CHRS$(34);","CHRS$(34)B
$(I+1)CHRS (34); srem 69
55 PRINT", "CHRS$ (34) BS$(I+2)CHRS$(34);","CHRS(34)BS(I
+3) :NEXT srem 113
56 PRINT"GOTO1": PRINT" {HOME }" srem 196
57, POKE198,1@ srem 202
58 FORI=9TO5 : POKE631+1,13:NEXT srem 98
59 END srem 69
60 REM INSTRUCTIONS srem 255
61 PRINT" {BLK}{3 DOWN}{6 SPACES}USE THIS PROGRAM F
OR SPELLING":PRINT" PRACTICE.{2 SPACES }WHEN";
trem 119
62 PRINT" REQUESTED, ENTER THE":PRINT" SPELLING WO
RDS AND {RVS}PRESS RETURN{OFF}.{2 SPACES }WHEN"
:rem 59
63 PRINT" ALL (2@) OF THE WORDS HAVE BEEN": PRINT"
{SPACE}ENTERED, THEY WILL BE PLACED"; srem 36
64 PRINT" INTO THE":PRINT" PROGRAM AS DATA STATEME
NTS.{2 SPACES }RE-SAVE-" srem 253
65 PRINT" ING THE PROGRAM AT THE END OF THE":PRINT
" SESSION WILL SAVE THE"; srem 136
PRINT" ENTERED":PRINT" WORDS FOR USE AT THE NEX
T PRACTICE." srem 224
PRINT"{5 DOWN}{12 RIGHT}{RVS}PRESS RETURN{OFF}"
srem ©
GETRS : IFRS=""THEN68 srem 33
IFRS=CHR$ (13) THENRETURN srem 118
GOTO68 srem 14
PRINT: PRINT" {CLR}{RVS}MISSPELLED WORDS: {OFF}":P
RINT:REM PRINT OUT MISSPELLED WORDS,SCORE:rem 5
FORP=8T0O19: 1FWS(P)="W"THENPRINTTAB(4)AS$(P)
srem 245
NEXT s:rem 169
PRINT" {HOME}{19 DOWN}{RVS}SCORE ="100-K*5
srem 69
PRINT: PRINT"{3 SPACES}AGAIN ? (Y OR N) srem 154
GETRS : IFRS=""THENGOTO76 srem 88
IFRS="Y"THENRUNL :rem 162
IFRS <>"N"THEN76 :rem 28
POKE36869, 248: POKEV, @: POKES ,@ srem 164
GOTO59 srem 15
PRINT" {CLR}": POKE5328@, 2:S=54272:FORE=STOS+28:P
OKEE, 9: NEXT zrem 104
POKE54296, 15 :POKE54277, 18 :POKE54278, 242
srem 116
POKE 54276, 33 :POKE 54273, 4 :POKE54272, 48
srem 9
87 FORT=1TO 300 :NEXT:POKE54276, 32:FORT=1TO 400 :
NEXT srem 92

94
2 Kid Stuff—Educational Games

89 RETURN:REM{14 SPACES }FORE=STOS+28:


POKEE, 9:NEXT:
RETURN srem 83
98 S=54272:FORE=STOS+28:
POKEE, 9:NEXT srem 1
199 POKE54296, 15 :POKE54277, 42 :POKE54278, 2590
srem 159
118 POKE 54276, 33 :POKE 54273, 23 :POKE54272, 181
srem 141
129 FORT=1TO 200 :NEXT:POKE54276, 32:FORT=1TO 590
{SPACE} :NEXT :rem 128
138 FORE=STOS+28:POKEE,
9:NEXT srem 94
148 RETURN srem 117

95
2 Kid Stuff—Educational Games

Munchmath
Gerald R. Anderson

“Munchmath” is a math drill program that


entertains as it teaches. Because of its multiple
difficulty levels, it is suitable for a wide range
of ages.

“Munchmath” presents an arcade-style character that relies on


the player's correct answers to math problems to stay ahead of
a ghost that is trying to gobble him up.
The program begins by asking for the player’s name, the
type of problems wanted (addition, subtraction, multiplication,
or division), and the starting level of difficulty. Problems are
then presented on the screen for the player to answer. Each
correct answer scores ten points and moves ““Munchie” one
step closer to the power prize. The ghost, however, stays in
hot pursuit only three steps behind. After 15 correct responses,
Munchie eats the power prize and the tables are turned.
Munchie chases the ghost across the screen, eventually catch-
ing him and scoring a bonus of 100 points. The difficulty level
then advances one notch higher and new problems are
presented.
The ghost moves into action when the player gives a
wrong answer. First, the correct answer is displayed for the
player to study. Then the ghost advances one step closer to
Munchie. Three incorrect answers and the ghost catches poor
Munchie and gobbles him up. This results in a loss of 50
points and a return to the next lowest level of difficulty.
If a Q is typed in response to a problem instead of a num-
ber, the game stops. A scoreboard is printed which shows the
number of problems the player has been given, the number
answered correctly, the number answered incorrectly, and the
percentage of correct answers. The player may then choose to
resume the game or to end play.
The program has been extensively tested by my six- and
eight-year-old daughters, as well as the neighborhood chil-
dren, and its appeal holds up very nicely.

96
Kid Stuff—Educational Games 2

Program Description
Here’s a breakdown of the program:
Lines 100-170: Initialization and delay subroutines.
Lines 190-240: Answer-checking.
Lines 260-270: Print titles computer-style.
Lines 290-460: Generate problem and print it in proper
format.
Lines 480-540: Ghost catches Munchie. Generate sound
effects, subtract 50 points, and reduce difficulty level.
Lines 560-690: Munchie reaches the power prize and
chases the ghost. Bonus of 100 points, advance to next level.
Lines 700-730: Move Munchie and ghost.
Lines 740-780: Print level and score. Clear old answer
from screen.
Lines 800-880: Print scoreboard at end of game. Restart or
end program.
Lines 900-910: Special characters created.
Lines 930-1070: Titles
Lines 1080-1280: Get player’s name, choice, and level.
Lines 1300-1410: DATA statements for custom characters.
Munchmath
For mistake-proof entry, be sure to use “Automatic Proofreader,” Appendix J.

10@ POKE56,48:CLR:
PRINT" {CLR}":SM=1973 :CM=55345:L=
1:BC=3 srem 142
118 FORI=9TO27 : POKE54272+1,0:NEXT: POKE54296,15:POK
E54277,18:POKE54278,165 srem 56
120 SS="{HOME}{21 DOWN}":SF=54272:WV=54276 :rem 67
138 JS$="9999999999999999999999":
P=3 : GOTOIGD
srem 11ll
148 : :rem 297
150 FORT=1TO300:NEXT:
RETURN srem 8
160 FORT=1T04@
:NEXT: RETURN :rem 218
179 FORT=1T0O990:NEXT:
RETURN srem 224
188 3: s:rem 211
198 D=VAL(ANS):IFASC(ANS )=81ANDPR>1THEN8@@:rem 247
200 IFINT(D)<>INT(C)THEN23@ srem 94
218 P=P+1:R=R+1:M=M+1:SC=SC+19:
POKESF, 223: POKESF+1
,29:POKEWV,17 srem 67
220 FORT=1T0O5:NEXT:
POKEWV, 16:GOTO799 srem 65
230 M=M+1:W=W+l:PRINTLEFTS (S$,198)SPC(28-LEN(CS$))"
{RVS}{RED}"cS"{5 SPACES}" srem 46
240 POKESF+1,8:POKESF,
199: POKEWV, 33:GOSUB159: POKEW
V,32:GOTO729 srem 136
258 : srem 299

97
2 Kid Stuff—Educational Games

260 POKESF+1,48: POKEWV,17 srem 246


278 GOSUB169 : POKEWV, 16: GOSUB169: RETURN srem 196
280 : srem 212
298 PR=PR+1:A=INT(RND(1)*5*L)+1 srem 3
388 B=INT (RND(1)*5*L)+1:IFB>ATHENA=A+B srem 202
310 E=INT(A*B) :AS=STRS (A) :BS=STRS(B) srem 23
320 IFQ=1THENC=A+B: X=43 :GOTO36@0 srem 130
339 IFQ=2THENC=A-B : X=45 : GOTO369 srem 136
346 IFQ=3THENC=A:CS=STRS$(C):GOTO419 srem 110
359 C=E:X=88 srem 156
36 CS=STRS(C):PRINTLEFTS (S$, 7)SPC(20-LEN(AS))"
{RVS}"A zrem 33
378 PRINTLEFTS (S$,8)SPC(18-LEN(BS))"{RVS} "CHRS(X)
B"{OFF}{DOWN}{3 LEFT}999" srem 176
380 PRINTLEFTS (S$,1@0)SPC(19-LEN(CS$)):GOSUB123@:IFA
NS=""THEN380 srem 120
390 D=VAL (ANS ) :GOTO196 srem 17
466 $ srem 296
416 PRINTLEFTS$(S$,12)SPC(16)"{9 SPACES}" :s:rem 172
429 PRINTLEFTS(S$,18)SPC(18)"{8 SPACES}" :rem 171
436 PRINTLEFTS (S$,11)SPC(19)"7777":PRINTSPC(18) "8"
srem 199
446 PRINTLEFTS(SS$,12)SPC(18-LEN(BS))"{RVS}"B;E
srem 79
456 PRINTLEFTS (S$,19)SPC(19-LEN(CS$)):GOSUB1230:IFA
NS=""THEN450 srem 116
466 GOTO198 s:rem 199
476 $ srem 213
486 POKEWV, 17: FORI=4T0O33 : POKESF+1,1I:GOSUB16@
:NEXT:
POKEWV, 16 srem 54
496 POKECM+P, 2:GOSUB169 : POKECM+P, 5: GOSUB164
s:rem 172
588 POKESF+1,14:POKEWV, 33: POKESM+P, 69: FORI=1T023@:
NEXT srem 154
519 POKESM+P, 64: FORI=1T0O25@:NEXT srem 1
520 POKESM+P, 32: POKEWV, 32:SC=SC-5@: IFSC<@THENSC=9
srem 75
536 L=L-1 : IFL=@THENL=1 srem 54
540 P=3:M=0: PRINT" {CLR}":GOTO1219 srem 34
558 : srem 212
569 POKESM+M-1 , 32: FORI=1T0O6 : POKECM+M, 3: POKESM+M, 69
: POKECM+P, 5 srem 58
576 POKESF+1,14:POKEWV, 129 srem 47
589 POKESM+P, 62:GOSUB169: POKESM+P, 58: POKECM+M, 6: PO
KESM+M, 61:GOSUB169 s:rem 33
5968 POKESM+M, 32: POKESM+P, 32: POKEWV, 128: P=P—1 :M=M-1
:NEXT srem 197
606 FORI=12TO9STEP-—1 : POKECM+I1, 5: POKESM+1,62: POKECM
+9,6: POKESM+9 , 69:GOSUB169 srem 282

98
Kid Stuff—Educational Games 2

619 POKESF+1,14:
POKEWV, 129: POKECM+9, 3: POKESM+1,58
srem 252
626 GOSUB169: POKEWV, 128: POKESM+1, 32:NEXT :rem 19
639 FORI=1T05: PRINT" {HOME} {RVS}{DOWN}{RED}"TAB(15)
"kk 198 **": POKESF+1,15:POKEWV,33 :rem 15
646 GOSUB15@: POKEWV, 32 srem 87
656 PRINT" {HOME} {DOWN} {RVS}"TAB(15)"{9 SPACES}":GO
SUB15@ :NEXT:L=L+1 :rem 168
669 SC=SC+190: P=3 :M=9 : BC=BC+1 : IFBC> 31THENBC=7
:rem 164
6768 REM SETUP :rem 18
689 POKE5328@, BC: POKE53281,1:PRINT"
{CLR} {BLU}":PRI
NTLEFTS (S$,3)SPC(9)JS$ :rem 33
696 POKE53272, 28: PRINT" {HOME }"SPC(13)"{DOWN} {PUR}?
2222222222? 2?2?{RVS}{RED}S" srem 132
78@ POKESM+P~1 , 32: POKECM+P, 5: POKESM+P, 59:GOSUBL5@:
POKESM+P,58 srem 48
719 IFSM+P=SM+18THEN56@ :rem 125
728 POKESM+M-1 , 32: POKECM+M, 2: POKESM+M, 61 :GOSUB15@:
POKECM+M, 6: POKESM+M, 6 zrem 232
73 IFPEEK(SM+M)=PEEK(SM+P ) THEN48@ :rem 80
746 PRINTLEFTS(S$,16)SPC(16)"{RVS}{CYN}LEVEL: "L"
{BLU}" srem 198
756 PRINTLEFTS(S$,17)SPC(9)J$ srem 178
760 PRINTLEFTS(SS,19)"{RVS}"SPC(12)NS"'S SCORE: "SC
srem 67
778 PRINTLEFTS(SS$,7)SPC(17)"{4 SPACES}":PRINTSPC(1
7)"{4 SPACES }":PRINTSPC(13)"{DOWN}{8 SPACES}"
:rem 233
78 GOTO296 srem 115
¢ srem 218
809 POKE53272, 21: POKE53280,6:POKE53281,7 srem 245
819 PRINT" {CLR} {DOWN} {RVS}"SPC(13-LEN(NS$)/2)NS"'S
{SPACE }SCOREBOARD" srem 255
820 PRINTSPC(14)"{2 DOWN}PROBLEMS: "PR-1 :rem 199
830 PRINTSPC(12)"{2 DOWN}{GRN}RIGHT ANSWERS: "R:PRI
NTSPC(12)"{2 DOWN}{RED}WRONG ANSWERS:"W
s:rem 151
835 RP=PR-1:QQ=ABS(R/RP*19G):Ql=INT(QQ+.5) :zrem 2
849 PRINTSPC(14)"{2 DOWN}{BLK}GRADE:"Q1"%" :rem 67
859 PRINTSPC(12)"{2 DOWN}PLAY AGAIN (Y/N)?":POKE19
8,B s:rem 141
860 GETAS : IFAS<>"Y"ANDAS <> "N"THEN86@ srem 57
876 IFAS="Y"THENPR=0: R=0 :W=0:SC=@:GOTO119@ :rem 29
889 END s:rem 119
898 $ :rem 219
989 FORF=55T0O63 : FORI=9TO7 : READA: POKEF*8+1+12288,A:
NEXT:NEXT s:rem 213
918 FORI=@TO7 : POKE32*8+1+12288,9:NEXT s:rem 186

99
2 Kid Stuff—Educational Games

920 : s:rem 213


936 POKE53281, 2: POKE53281,7 zrem 251
946 PRINTLEFTS(S$,1%8)SPC(11)"{BLU}M {GRN}U{RED} N
{SPACE}{BLU}C {BLK}H {GRN}M {RED}JA {BLU}T
{GRN}H" :rem 207
959 POKE56334, PEEK (56334) AND254: POKE1, PEEK(1)AND25
1:Z=13312:Y=53248 zrem 96
960 FORI=9T0519: POKEI+Z, PEEK(I+Y) :NEXT: FORI=664T06
71:POKEI+Z, PEEK(I+Y):NEXT :rem 68
970 POKE1, PEEK(1)OR4: POKE56334, PEEK(56334)OR1
srem 143
986 POKE53272, 28: PRINTLEFTS (S$,18)SPC(11)"{RVS}
{BLU}M {GRN}U{RED} N {BLU}C {BLK}H [GRN}M
{RED}A {BLU}T {GRN}H" 231 srem
998 $ srem 229
1899 READF,G: LFF=-1 THEN1 940 srem 52
1919 POKESF+1,F:POKESF,G:POKEWV,
33:GOSUB1686 : POKEWV
, 32:GOSUB169 srem 190
1929 GOTO19090 srem 189
1930 3 srem 254
1649 GOSUB15@:FORI=4T024: PRINTLEFTS$(S$,18)SPC(I)"
{SPACE}{CYN}= {RED}<{2 SPACES}{GRN}:";:GOSUB1
79 srem 7
1956 PRINTLEFTS(S$,18)SPC(I)" {BLU}< {PUR}=
{2 SPACES}{GRN};" :rem 72
1969 POKESF, 195: POKESF+1,17:POKEWV, 17:GOSUB17@:POK
EWV, 16:NEXT srem 196
1876 PRINTLEFTS$(S$,18)SPC(24)"{8 SPACES}" srem 218
1080 POKE53289,5:POKE53281,7:POKE53272,21 :rem 37
1898 PRINT" {CLR}"SPC(8)"{3 DOWN}{BLU}WHAT IS YOUR
{SPACE }NAME"; :GOSUB26@: INPUTNS srem 60
1168 PRINT" {CLR} {BLU}"SPC(13)"{5 DOWN}WHAT WOULD Y
OU" :GOSUB268 srem 135
1119 PRINTSPC(11)"{DOWN}LIKE TO PRACTICE, {DOWN}":G
OSUB269 srem 224
1129 PRINTSPC(2@-LEN(NS$)/2)NS":"s:GOSUB26@ :rem 92
1136 PRINTSPC(14)"{DOWN}
{RED}1) {GRN}ADDITION" :GOSU
B260 srem 117
1146 PRINTSPC(14)"{DOWN}{RED}2) {GRN}SUBTRACTION":G
OSUB26@ srem 121
1159 PRINTSPC(14)"{DOWN}
{RED}3) {GRN}DIVISION":GOSU
B26 srem 146
1166 PRINTSPC(14)"{DOWN}{RED}4) {GRN}MULTIPLICATION
{BLU }":GOSUB269 srem 124
1179 GETAS :Q=VAL (AS): IFQ<1ORQ>4THEN117& srem 82
1186 PRINTLEFTS (S$,Q*2+18)SPC(14)
"{RVS} "MIDS (STRS(
Q) 72) srem 49
1196 PRINTLEFTS(S$,28)SPC(14)"LEVEL (1-9)?"
srem 124

100
Kid Stuff—Educational Games 2

1298 GETAS :L=VAL(AS) : IFL<1ORL>9THEN1 209 srem 69


1210 GOTO680 srem 155
1220 $ srem 255
1230 PRINT"{RVS}? "; sANS=""3POKE198,@ srem 248
1246 GETZAS : IFZAS=""THEN124@ srem 191
1258 ZL=LEN (ANS ) : IFZAS=CHRS (28)ANDZLTHENPRINTZAS; ¢
ANS=LEFTS (ANS, ZL-1) srem 227
1260 IFZAS=CHRS (13) THENPRINT: RETURN srem 224
1278 IFZAS <>"Q"AND(ZAS<"@"ORZAS>"9")
ORZL=5THEN1 240
srem 132
1286 PRINTZAS : :ANS=ANS+ZAS : GOTO124@ srem 83
1290 : srem 6
1300 DATA @,9,8,9,98,0,255,255 srem 196
1319 DATALS Soro rone re :rem 171
1328 DATA 8,8,255,255,255,255,9,0 srem 68
1338 DATA 24,60,110,126,126,126,60, 24 srem 10
1346 DATA 56,124,95,248, 224, 248,127,56 srem 95
1356 DATA 69,126,255, 219, 255,255,169,169 :s:rem 198
1369 DATA 69,126,255, 219, 255, 255,998,180 srem 137
1378 DATA 120,116,30,14,38,124,120,9 srem 201
1388 DATA 9,9,9,14,14,14,9,@8 srem 57
1396 2 srem 7
1490 DATA 165.509.5722 7960, 2607 49 7 Sone poole Soy les
B33 7125 s:rem 195
1418 DATA 28,49,28,49,28,49,22, 96, 28,49, 22,96,16,1
95,-1,9 srem 16

101
Nleyetatel
Sound 3

Working with SID


Jerry M. Jaco

In this unique approach to the Commodore 64’s


SID chip, the author discusses the SID chip’s
anatomy and capabilities in the context of its
essential similarity to the design of music
synthesizers.
TSLe RE

If you've decided you want to make music on your Com-


modore 64, but don’t know where to begin, perhaps a look at
how an analog synthesizer is used in an electronic music stu-
dio will clarify many aspects of the 64’s amazing sound
capabilities. Once we have covered the physical aspects of a
synthesizer, we can begin to understand some of the tech-
niques used to create sounds artificially.
Electronic music studios usually have at least one analog
synthesizer. Most synthesizers have a modular design which
allows the synthesizer to be built and expanded according to
the dictates of budget, space, and ability. Each module on the
synthesizer has a different function and the builder-user is free
to duplicate or omit any of them.
Each module on the synthesizer is independent of all others.
The only way to connect them is either by a panel of fancy
selector switches or via the more common patch cords. Patch
cords are simply pieces of electrical cable of varying lengths
which have standard plugs attached on each end. Plugging
one end of a patch cord into the output socket of one module
and the other end of the patch cord into the input socket of
another module creates an electrical pathway called a patch.
If a patch leads from a source module, such as an os-
cillator, to an output module, such as a mixer, the-resulting
sound will be audible to the outside world. (See Figure 1.) The
term signal is used to describe the electrical current being
passed from one module to another. A source signal is one that
will eventually be heard as a real sound. A control signal is a
varying voltage used to electronically control another module.
It does not contain sound information per se.
105
3 Sound

yno
[o13U09

ul yno yno
[ozU0D yeusis 1a3311y
‘NdD ddOTSANA

WADONLL
133311}

ul jeuSts
aysulg ad1nOg [eusig

OIdNV

Tit)Id
OUI NV
WaT
WHXTIA T-O.L-€
BuUIssad0Ig
&

SUsaIIGOW
SaOUNOS
JINsLJ
*[

LNdLNO

106
BINS
*7 SuUIssad0Ig
VoIY_T, BdINOg s[eUBIC

SHOUNOS

‘Nao
ddOTHANA
SULT

WAOORLL

LAdLNO
WAX
T-OL-€
OIGNV

107
Sound 3

NV Td Wald
3 Sound

A Patch for the SID Chip


In Figure 1, there is only one source signal being processed by
the mixer. A mixer can handle up to three source signals on
our hypothetical system, which it combines into one compos-
ite signal that gets sent on to the speakers, and so to your
ears. (See Figure 2.) On the 64, Program 1 accomplishes exactly
what the analog synthesizer does in Figure 2.

Program 1. Three Voices—or a Chord


For mistake-proof program entry, be sure to use “Automatic Proofreader,” Appendix J.
10 FORI=0TO24:POKE54272+1,%9:NEXT srem 189
15 POKE54278, 249: POKE54285, 249: POKE54292,249:REM S
US/REL VALUES FOR ALL OSC'S srem 259
28 POKE54272,37:POKE54273,17:REM OSC1 srem 97
38 POKE54279, 229: POKE54289,22:REM OSC2 srem 151
49 POKE54286, 214: POKE54287,28:REM OSC3 srem 158
5@ POKE54276,17:POKE54283,17:POKE54299,17:REM TRIA
NGLE WAVE FOR ALL OSC'S zrem 250
69 POKE 54277,17:POKE 54284,17:POKE 54291,17:REM A
TT/DECAY VALUES FOR ALL OSC'S zrem 195
7@ POKE54296,15:REM MASTER VOLUME ON srem 145
75 FORT=1T0500:NEXT:REM CHORD DURATION zrem 186
88 POKE54276,16:POKE54283,16:POKE54299,16 :rem 52
9@ FORT=1T045@:NEXT:REM REL. DURATION zrem 92
95 POKE54296,9:REM TURN OFF VOLUME :rem 29
96 END srem 79

This is a very basic patch for the Sound Interface Device


(SID) chip on the 64. Lines 20, 30, and 40 set the frequencies
of the three oscillators. Line 20 POKEs the values for middle C
into voice 1. Line 30 POKEs the values for F into voice 2, and
line 40 POKEs the values for A into voice 3. This gives us a
“chord,”” which is simply three notes (voices) sounding
simultaneously. Line 50 selects a triangle wave output for all
three voices. Line 70 is the mixer volume control. When the
value 15 is POKEd into this location, the master volume con-
trol is turned all the way up. When 0 is POKEd, the volume
control is turned off, as in line 95. The other lines will become
clearer as we go along.
On an analog synthesizer, pots (potentiometers) are con-
trols that do things such as raise and lower the volume of a
sound signal or change the frequency (pitch) of af oscillator.
Pots are also the main components of game paddles and TV

108
Sound 3

volume controls. To make new sounds on an analog syn-


thesizer, the user twists pots on each module and listens for
the resulting effect. When the desired sound is found, it can be
recorded on tape or the patch written down on a patch chart,
marking the pathways made by the patch cords and the po-
sitions of the pots for future reference. Analog synthesizers are
very useful in this way because drastic changes in a sound can
be quickly made by simply twisting a knob or plugging a
patch cord into something else.

Turning Knobs with POKEs


A digitally-controlled synthesizer, such as our SID chip, uses
numbers POKEd into control registers to accomplish the same
things that knob-twisting and patch-cord-plugging do on an
analog synthesizer. For example, if you POKE a 16-bit value
into the first two registers of the SID chip (54272 and 54273),
you've set the frequency value for oscillator 1. POKE a four-bit
number into the high nybble of the sixth register on the chip,
and you've set the attack value of the envelope for oscillator 1.
POKEing different values into other registers will activate
them in the same way that turning the pots or setting switches
will activate the analog synthesizer modules.
Envelope Generation
Look at Figure 1 again. It shows a direct path from a voltage-
controlled oscillator (VCO1) to the mixer. If we were to break
that path, sending the output of VCO1 to the input of the am-
plifier module (VCA), we would then need to send the output
of VCA to the mixer so that the sound from VCO1 could still
be heard. The patch shown in Figure 3 would be the result.
Now we can make VCO1 signal even louder by adjusting the
pot on VCA or on the mixer. The real reason for taking this
route is that the envelope generator can be brought into play,
since it directly controls the VCA.
There are four pots on the envelope generator module.
The first controls the attack time; the second, the decay time.
The third sets the sustain level, and the fourth controls the re-
lease time. On the SID, two registers in high-low nybble for-
mat control these functions. Perhaps the most important
function is the sustain level. It’s not a timing value, but rather
the level at which the amplifier’s volume control is set while
the note is being sounded. If the sustain level is zero, no

109
Wad NV
OIGNV
WHOORLL WAXIW T-OL-€
LNdLNO

s[eusis

ur
3 Sound SHOUNOS

110
VOA oY} Buise¢) :¢ eansiy
Sound 3

sound will be heard after the attack and decay phases have
ended.
The envelope generator puts out an electrical signal which
tells the amplifier when to turn up the volume and how long
it should take, as well as how high to set the volume, and
when to turn it all the way off again. This is why the amplifier
module in the diagramsis called ‘“VCA.” This stands for Volt-
age Controlled Amplifier and means that the amplifier can be
controlled by an incoming variable voltage, such as the one
supplied by the envelope generator.
ADSR Values
On the SID chip, each voice has its own envelope generator.
Within the group of seven registers (0-6) that control the three
oscillators, register 5 contains the attack and decay values in
high-low nybble format, and register 6 contains the sustain/
release values. All values are four-bit numbers (nybbles). The
attack value determines how long the amplifier should take to
reach peak amplitude (maximum volume).
The decay value determines how long the amplifier
should take to go from peak amplitude to the level specified
by the sustain value. The release value is the time the am-
plifier will use to return to the lowest amplitude level (‘off’)
from the sustain level.
Remember, though, that on the analog synthesizer as well
as on the SID chip, the envelope will not go into effect until it
is “triggered.” The lowest order bit (bit 0), the gate bit, trig-
gers each envelope on the SID chip. On the analog syn-
thesizer, triggering of the envelope is accomplished through
the use of an attached keyboard module. When a key is
pushed down (and as long as it is held down), the attack,
decay, and sustain values will go into effect in order. When
the key is released, the release phase is triggered, and the
VCA will close down the volume of the signal it is operating
on over the length of time specified by the release value.
Program 2 demonstrates the effect of the various ADSR
values:

Program 2. Effects of the ADSR Values


100 FORI=0T0O24: POKE54272+1,98:NEXT srem 237
138 POKE54277,249:REM SLOW ATTACK/PASTEST DECAY RA
TE srem 132

111
3 Sound

148 POKE54278,249:REM HIGHEST SUSTAIN LEVEL/FASTES


T RELEASE RATE srem 297
145 POKE54272,37:POKE54273,17:REM OSC1 srem 153
15@ POKE54276,129:REM NOISE WAVE OSC1 srem 122
155 POKE54296,15 srem 162
16@ FORT=1T04500:NEXT:REM DURATION FOR ATTACK, DECA
Y, AND SUSTAIN srem ©
178 POKE54276,128:REM BEGIN RELEASE CYCLE :rem 138
1806 FORT=1T045900:NEXT:REM REL. DURATION srem 188
199 END srem 113

In line 130, the attack value is all the way on, and the decay
value is all the way off. In line 140, the sustain value is all the
way on, and the release value is off. Each value is a four-bit
number, 0 to 15. With the attack and sustain setting, the actual
POKE value is shifted to the high nybble; thus, 240 is actually
the attack value equal to 15 (for slowest attack) multiplied by
16. The sound generated is a random noise that gradually gets
louder and then suddenly stops. It stops suddenly because we
have set the release value to 0, allowing no time for a gradual
decrease in volume.
Change the value 240 in line 140 to 255 and run the pro-
gram again. The sound should slowly fade away. The high
nybble of 54278 (sustain) is now 240 and the low nybble (re-
lease) 15, making a total of 255, the value we just POKEd into
54278. Try lowering the sustain value by two or three (2*16 or
3*16); that is, POKE 54278 with either 223 or 207 and see
what happens. The sound should build up as before but
should then fall off markedly. Change the decay value from 0
in line 130 to about 8 (POKE 54277,248) and hear how the
drop-off is now smoothed out. Similarly, shorten the attack
time to vary the start of the sound the same way the sustain
value was altered. The results should be vastly different from
those we started with, and we’ve been working with only two
registers!
Look now at line 170. Notice that we subtracted one from
the value we originally POKEd into 54276 in line 150. This
zeros the gate bit in 54276, and it is the same as taking your
finger off the keyboard on the analog synthesizer: the release
cycle gets triggered. Of course, it works only if the VCA sus-
tain level has been previously raised high enough to hear the
tone. The delay loop in line 180 is also necessary to allow the
release cycle to reach its lowest level.

VEZ:
Sound 3

For more explanation about the ADSR values, as well as a


sound editor program that lets you alter the values and im-
mediately hear the result, take a look at “Sound Editor 64,”
another article in this book.

Using Filters to Color Sound


Let’s add a filter to the path in Figure 3. The path from the
VCA to the mixer is broken so that filtering the modulated sig-
nal will be more easily heard. In our diagram, we have a
choice of a high-pass or low-pass filter. On the SID chip, we
can also utilize a band-pass filter.
The pot on each filter is used to adjust the cutoff fre-
quency, which is the frequency above which a high-pass filter
allows frequencies in the sound spectrum to be heard and be-
low which the filter suppresses them. The low-pass filter is the
opposite of the high-pass filter in that it suppresses the fre-
quencies above the cutoff value and allows those below it to
sound. A band-pass filter allows frequencies to be heard
within a narrow band surrounding the cutoff frequency (called
a center frequency in this case), while suppressing all the rest.
Use of filters constitutes a technique called subtractive syn-
thesis, which selectively eliminates available frequencies of the
sound spectrum, producing widely varying sound colors.
Figure 4 indicates that we’ve decided to filter VCO1
through a high-pass filter. VCO1 is set to produce a sawtooth
wave. The path of the patch runs out of VCO1 into the VCA,
and from the VCA into the high-pass filter. From there, the
signal heads to the mixer and out to the speaker. Program 3 is
a routine that does the same thing.
Program 3. Filtered Sound
200 FORI=0TO24:POKE54272+1,@:NEXT zrem 238
210 POKE54272,37:POKE54273,17:REM OSCl srem 146
238 POKE54277,12@:REM MED. ATTACK/MED. DECAY
srem 255
248 POKE54278,245:REM HIGHEST SUSTAIN/MED. RELEASE
srem 27
245 POKE54293,49:POKE54294,5:REM CUTOFF FREQ. FOR
{SPACE}HIGH-PASS FILTER :rem 165
258 POKE54295,129:REM MED RES'NCE AND OSCl TO BE F
ILTERED srem 212
253 POKE54276,33:REM SAWTOOTH WAVE OSC1 zrem 67
255 POKE 54296,79:REM FULL VOL AND CHOOSE HI-PASS
{SPACE}FILTER srem 2

113
WadTd NV
OIGNV

COT
TTT)
WHOOMLL WHXIW T-OL-€
LAdLNO

eusis
ur
3 Sound
JL sseq-ysrpy & Suisc) +p oINsL]

114
Sound 3

268 FORJ=1T025@: POKE54294,J:NEXT:REM SWEEP CUTOFF


{SPACE}FREQ. UPWARDS srem 188
270 POKE54276,32:REM{2 SPACES}BEGIN RELEASE CYCLE
srem 85
288 FORT=1T0500:NEXT:REM REL. DURATION srem 137
298 POKE54296,%8:REM TURN OFF VOLUME srem 74
295 END :rem 119

To hear the effect of the filter, we will sweep the value of the
cutoff frequency in line 260 from low to high. This will allow
less and less of the available sound spectrum to be passed by
the filter. Listen carefully to the richness of the tone as it is
diminished. Switch the wave form to noise in line 253 by
POKEing 129, instead of 33, into 54276 to hear a different
version of the effect. Many effects are possible using filters.
Frequency Modulation
Figure 5 introduces another technique called frequency
modulation. Notice now that the signal from VCO1 is entering
the control input of VCO2, and that the signal from VCO2 is
going through the VCA and on to the mixer. The frequency of
VCO2 is now being controlled automatically by the output
voltage of VCO1 instead of manually by the pot. This is an-
other example of voltage control. The envelope generator con-
trolled the VCA before and an oscillator now controls a VCO
(Voltage Controlled Oscillator).
Frequency Modulation (FM), along with filtering and en-
velope control, is one of the most significant techniques of
sound synthesis. Using one signal source to alter the sound
quality of another provides incredibly powerful and varied
tools for sound manipulation. Program 4 is one simple ex-
ample of the FM technique.
Program 4. Siren
300 FORI=0TO24: POKE54272+1,8:NEXT s:rem 239
395 POKE 54278,249:REM FULL SUSTAIN/FASTEST RELEAS
E RATE :rem 129
318 POKE54276,33:REM SAWTOTH WAVE OSCl srem 238
328 POKE54286,3:REM CONTROL FREQ. OSC3 srem 223
338 POKE54299,16:REM TRIANGLE WAVE OSC3 srem 27
348 POKE54296,175:REM FULL VOL. & SELECT BAND-PASS
& DISC. OSC3 FROM AUDIO s:rem 157
35@ POKE54295,1:REM NO RES'NCE & CHOOSE OSCl FOR F
ILTER s:rem 121
36@ POKE54293,255:POKE54294,78:REM CUTOFF FREQ.
srem 228

115
al oinBi4
:¢ Aouenbel4 uoypinpow

‘Oo
SHOUNOS SUsaIIGOW
[orju05
3 Sound

yno

Ud
sjeusis
133311}

WAXIA T-O.L-€

IndLno
Id
NV
OIGNV

Wald
Sound 3

375 FORT=1TO390 :rem 126


380 F=20000+PEEK(54299)*2@:REM ADD OSC3 OUTPUT TO
{SPACE}BASE FREQ. srem 84
398 HF=INT(F/256):LF=F-256*HF:REM SPLIT NEW FREQ.
{SPACE}INTO HIGH/LOW BYTES :rem 129
48@ POKE54272,LF:POKE54273,HF:REM SET NEW OSC1 FRE
Q srem 229
418 NEXT:POKE 54276,32:POKE54296,@ srem 165
428 END :rem 199

The third oscillator on the SID chip is our control os-


cillator, as VCO1 is in Figure 5. We get access to a value
corresponding to the wave shape of oscillator 3 in register 27
(54299). If oscillator 3 is set to a triangle wave, the value in
register 27 will go up from 0 to 255 and then down from 255
to 0 in a symmetrical rhythm.
This is a nice shape for a siren sound, which is what Pro-
gram 4 creates. Notice that the frequency of oscillator 3 in line
320 is very low. This value allows the tracing of the waveform
to be heard as a siren. The range of frequencies under approxi-
mately 32 hertz is called the subaudio range and refers to the
fact that the actual waveform at these frequencies is discern-
ible as individual pulses instead of as a continuous tone.
When oscillator 3’s frequency is increased into the audio range
(above about 29), the quality of the resulting tone becomes
enjoyably less predictable.
Try POKEing 220 into 54286 at line 320 and running the
routine. Note how the information in register 27 (54299) is uti-
lized in line 380. It is increased by a factor of 20 and then
added to the base frequency of 20000. Program 4 also uses a
band pass filter, but for no particular reason other than simply
to stick one in. Try a different value for the waveform in line
330. If you use 64 as your value, be sure to add a line to set
oscillator 3’s pulse width.

Synthesized 64
The techniques of sound manipulation described above, as
used with an analog synthesizer, have perhaps given you a
better picture of the working of the SID chip. As you learn
more about the internal registers which control other func-
tions, you'll discover others just as interesting as those
discussed here.

117
3 Sound

Get a copy of the Commodore 64 Programmer’s Reference


Guide and read about ring modulation, filtering, and other ad-
vanced techniques. Sound effects are the most directly useful
sound patches to work with at the start. Program 5 is an
example of one I used for a Hangman program: it’s the sound
of nails being driven into wood. Imagine the other sound
effects you can create for new game ideas.
The User’s Guide and Programmer’s Reference Guide have
suggested patches for you to try out. Put some FOR-NEXT
loops in, as we did in line 260 of Program 3, to have the com-
puter ‘adjust the pots’’ for you, as it alters individual registers.
Once you've found a patch you like, save the register values
for future reference. As you become more acquainted with the
way that sounds can be altered, you will find yourself noticing
the subtler shades of sound color. You'll also begin to under-
stand how the sounds on a TV commercial, videogame, or sci-
ence fiction movie are created.
Program 5. Driving Nails into Wood
70@ FORI=0TO24:POKE54272+1,0:NEXT srem 243
718 CT=0 srem 156
72@ POKE54278,5:REM SUSTAIN /RELEASE s:rem 168
730 POKE54277,5:REM ATTACK/DECAY srem 158
748 POKE54276,129:REM NOISE WAVEFORM srem 157
75@ POKE54295,241:REM RES'NCE & VOICE srem 56
76@ POKE54293,54:POKE54294,28:REM CUTOFF srem 84
77@ READA:REM INPUT HI BYTE FREQ.VALUE srem 71
789 READB:REM INPUT LO BYTE FREQ.VALUE srem 83
79@ IFB=-1THEN90@:REM BRANCH ON END OF DATA
srem 195
898 POKE54273,A:POKE54272,B:REM SET FREQ. s:rem 122
819 FORT=1T035: POKE54296,79:NEXT:REM TURN ON VOLUM
E & FILTER s:rem 157
829 POKE54276,128:REM RELEASE CYCLE rem 39
838 GOTO730:REM GET NEW NOTE s:rem 149
S4A0SDATAL Tf SviGlogOs; flip koa, 2o p22) ¢ 20 pl 1,2, 24,32
7 94,34,175, 34,255 srem 35
85@ DATA -1,-1 srem 159
9908 CT=CT+1:IFCT+1<6THENRESTORE: FORT=1TO19@0*CT :NEX
T:GOTO770 srem 67
910 POKE54296,8:REM TURN OFF VOLUME :rem 73

118
Sound 3

Sound
Editor 64
Daniel L. Riegal

The SID chip in the Commodore 64 is certainly


versatile, but it can be confusing and difficult to
use. Here’s a program that will help—‘Sound
Editor 64.” With it, you can experiment with
sound on the 64 and even have it write BASIC
sound routines for you.
i

Perhaps the most outstanding, and confusing, feature of the


Commodore 64 is the Sound Interface Device (SID). Many
sounds can be produced by the SID chip that are not possible
on other home computers, with a quality that is truly amazing.
However, it takes understanding and patience to coax just the
right sounds from the SID.
While other home computers only require settings of fre-
quency and duration to produce sound or music, the Com-
modore 64 has several parameters used to shape, modulate,
and filter the sound. Unless you understand the basics in-
volved in setting these parameters, you can expect little more
than pops, clicks, or beeps. ‘Sound Editor 64” allows input of
the various parameters in a straight-forward manner so that
you will not only become familiar with them, but will also be
able to try various combinations to see the impact that each
has on the sound.
Attack, Decay, Sustain, and Release
The SID chip has three voices which can act independently or
in combination. Sound Editor 64 uses voice 1 as its primary
sound source. There is one register, at location 54296, which
controls the volume of all three voices. It must be set with a
value from 1 to 15 for sound to occur. This program uses the
maximum volume setting, 15.
The volume of a sound passes through four phases, called

119
3 Sound

the envelope. These phases consist of Attack, Decay, Sustain,


and Release (ADSR). Each voice has a gate, or switch, that is
used to initiate the attack phase when set to 1, or initiate the
release phase when reset to 0. The attack rate specifies the
time allowed to reach maximum volume, as determined by the
setting at location 54296. An attack value of 0 is very short,
and 15 is very long. Explosions and percussion instruments
have a low Attack value.
The decay rate is the time allowed for the volume to fall
from the maximum to the sustain volume. As in attack, a value
of 0 is short, and 15 is long. The sustain parameter determines
the volume at which the sound is maintained until the voice
gate is reset to 0, when the release phase begins. A sustain
value of 0 is minimum volume, 8 is half of maximum volume,
and 15 is the maximum volume attained during the attack
phase. The release rate determines how fast the volume falls
to 0 from the sustain volume after the voice gate is reset to 0.
A value of 0 is fast, while a value of 15 is slow.

Duration
Duration, another parameter used with the SID chip registers,
is the amount of time between turning the voice gate on and
resetting it to 0. The values for duration used by Sound Editor
64 are intervals of 60 per second. Thus a value of 60 is 1 sec-
ond and a value of 6 is .1 second (or 100 milliseconds). As
you can see, the envelope is closely related to time. Each
phase takes an amount of time as specified for each parameter.
The duration time must be long enough to allow attack and
decay to complete before the voice gate is reset. Otherwise
sound distortions may occur. For this reason, very short
sounds usually require ADSR values of attack 0, decay 0, sus-
tain 15, release 0, as well as a small duration.
The SID chip can produce eight octaves (0-7) of tones.
Sound Editor 64 dynamically generates and stores the tone
settings of octave 7 using the highest note, B, as a base. The
octave is divided into 12 tones, where each tone’s frequency is
2 (1/12) lower than the next higher tone (A#=B/2 f!(1/12)).
The frequency of a tone is also half that of the same note in
the next higher octave (octave 6=octave 7/2). Therefore, the
program can generate the scale for any octave N (where N is
0-7) by using the formula OCTAVE N=OCTAVE 7/2 ft (7-N).
This saves memory by eliminating the need for an array of 96

120
Sound 3

frequency settings to define eight octaves of 12 tones each; in-


stead, it uses one octave and an array of 12 tones to calculate
the settings.
Waveform
A sound’s waveform determines its harmonic content, or
“color.” The SID chip provides triangle (17), sawtooth (33),
pulse (65), and noise (129) waveforms. These can produce
sounds of many different qualities, and the best way to learn
about them is to just experiment with Sound Editor 64. When
the Pulse waveform is selected, you also have to provide a
value for the Pulse Width (0-4095). A value of 2048 produces
a square wave, which creates a clear, hollow sound. Other val-
ues produce varying degrees of ‘body.’ Waveform values 19
and 21 combine the frequencies of voices 1 and 3 to produce
more complex sounds. Value 19 synchronizes the two fre-
quencies to produce complex harmonic structures, while value
21 modulates voice 1 with voice 3 to produce ringing sounds
such as bells or gongs. Sound Editor 64 uses note C for voice
3’s frequency, one octave lower than that specified for voice 1.
Sound Experimentation
Sound Editor 64 operates very simply. After you’ve typed it in
and SAVEd it, RUN it. You'll see a title, and then the first
prompt will appear. As each parameter prompt shows on the
screen, enter the a value which falls in its range, then press
RETURN. The parameters you'll need to fill, and the range of
possible values listed in parentheses are:
Attack value (0-15)
Decay value (0-15)
Sustain value (0-15)
Release value (0-15)
Octave value (0-7)
Duration loop value (0 on up)
Waveform (17,19,21,33,65, or 129)
Pulse width value (0-4095) (Only used when waveform value
65 is entered.)
When you're entering values, make sure that you only use
numerals. If you use any other characters, such as letters or
other symbols on the keyboard, you'll have to start over again.
Each parameter must have a value from the stated range
entered when the prompt appears.

121
3 Sound

The duration loop value changes the speed at which the


tones are played. If you want to hear each note more clearly,
increase this value. The waveforms and their values are:
Triangle (17)
Synchronized voices 1 and 3 (19)
Modulated voices 1 and 3 (21)
Sawtooth (33)
Pulse (65)
Noise (129)
After you’ve entered the various parameter values, you
can choose one of the four options using the appropriate func-
tion key. The functions, and the appropriate keys, are:
BASIC (f1). This option will list the BASIC program lines you
would add to a program of your own to produce the sound for
note C of the octave you selected.
Change (f3). You can modify the existing parameters with this
option. After pressing f3, use the RETURN key to move to the
line you want to change. Enter the modification, making sure
you erase any unwanted numerals that may extend beyond
the value you now desire, and hit RETURN.
Scale (£5). This option plays the 12 tones of the octave you’ve
specified. Use this to hear what the sound is like.
Quit (f7). This terminates the program.
Sound Starts
Sound Editor 64 is best used to experiment with the various
parameters of the SID chip’s registers. To begin with, try out
some of the following values. Varying the duration and octave
values will change the sound you hear, making it more or less
like the instrument listed.

122
Sound 3

Table 1. Instrument Values

Sound Attack Decay Sustain Waveform Pulse Width*


Trumpet 6 0 8 oe 33 N/A :
Violin 10 3. 0 a N/A
Xylophone 0 9 oe, N/A
Piano 0 g 65 1000
Flute 9 10 17 N/A
Harpsi-
chord 0 2) 33 N/A
Organ =0 0 ey: N/A
Clarinet 8 4 Fe N/A
Chimes 0 11 19 N/A

*NA=Not Applicable

Sound Editor 64
For mistake-proof program entry, be sure to use “Automatic Proofreader,” Appendix J.
1906 REM SOUND EDITOR :rem 197
118 PRINT"{CLR}", "SOUND EDITOR{3 DOWN}" :rem 233
115 DIMF(11):F(11)=64814:FORF=10TOSSTEP-1:F(F)=INT
(1/2+F(F+1)/2T(1/12)):NEXT zrem 37
12@ SD=54272:V=SD+24: FORI=SDTOV: POKEL, 9: NEXT: POKEV
Aas) :rem 111
130 DIMNS(11):NS(@)="C ":NS(1)="C#":NS(2)="D ":NS(
3)="D#e"sNS(4)="E “"2NS(5)=S"F °°” srem 149
140 NS(6)="F#":NS(7)="G “:NS(8)="G#":NS(9)="A ":NS
(10)="A#":NS(11)="B ":GOTO20G srem 246
159 PRINT" {HOME}{2 DOWN}ENTER OPTION [F1] BASIC
{2 SPACES}[F3] CHANGE" srem 91
152 PRINTTAB(13)"[F5] SCALE{2 SPACES}[F7] QUIT"
srem 8
153 GETOPS:IFOPS=""THEN153 :rem 17
155 IFOPS="{F7}"THENPRINT"{CLR}"; :POKEV,@:END
srem 248
160 IFOPS="{F3}"THEN200 :rem 177
165 IFOPS="{F1}"THEN59@ :rem 184
168 IFOPS="{F5}"THEN49G :rem 188
178 GOTO1L5S srem 103

123
3 Sound

298 INPUT" {DOWN}ENTER{2 SPACES}ATTACK VALUE (@-15)


"oA :rem 186
205 IFA<@ORA>15THENPRINT"{3 UP}":GOTO289 :rem 17
210 INPUT"ENTER{3 SPACES}DECAY VALUE (@-15)";D
srem 91
215 IFD<@ORD>15THENPRINT" {2 UP }":GOTO219 srem 136
226 POKESD+5 ,A*16+D srem 39
230 INPUT"ENTER SUSTAIN VALUE (@-15)":S srem 45
235 IFS<@ORS>15THENPRINT" {2 UP}":GOTO23G srem 179
248 INPUT“ ENTER RELEASE VALUE (@-15)":R srem 7
245 IFR<9ORR>15THENPRINT"{2 UP}":GOTO24@ srem 174
POKESD+6 ,S*16+R srem 75
266 INPUT"ENTER{2 SPACES}OCTAVE VALUE{2 SPACES}(9-
DT) si0C srem 219
261 IFOC<QGOROC>7THENPRINT"{2 UP}":GOTO268 :rem 251
280 INPUT"ENTER DURATION LOOP{2 SPACES}VALUE"; DU
srem 221
285 IFDU<1THENPRINT"{2 UP}":GOTO28@ rem 99
290 INPUT"ENTER WAVEFORM 17 19 21 33 65 129";W
srem 136
294 RS=4 :H3=9 :L3=0 : LFW=190RW=21THENRS=1 srem 154
295 IFRS=1THENSC=INT(F(@)/2f(8-OC) ) :H3=INT(SC/256) .
:L3=SC-H3* 256 :rem 217
296 POKESD+15,H3: POKESD+14,L3 :rem 218
38D IFW=65THEN310 srem 228
383 PRINT" {38 SPACES}":GOTO15Z srem 112
319 INPUT"ENTER PULSE WIDTH VALUE (9-4995)";PW
:rem 296
SUD IFPW<GORPW> 4095THENPRINT"{2 UP}":GOTO319
:rem 188
328 PH=INT( PW/256) : PL=PW-PH* 256 zrem 95
3308 POKESD+2, PL: POKESD+3, PH: GOTOL5@ :rem 172
400 FORF=9TO11:SC=INT(F(F)/2f(7-OC) ) :X=INT(SC/256)
: POKESD+1,X: POKESD, SC-256*X :rem 186
410 TD=TI+DU : POKE53280,F:PRINT"{HOME}{23 DOwN}
{3 RIGHT}";NS(F):POKESD+4,W :rem 292
420 IFTI<TDTHEN42@ srem 91
430 POKESD+4,W-1 :NEXT: POKESD+4, @: POKE53280,14:PRIN
T"{UP}{5 SPACES }":GOTO15@ :rem 114
58 PRINT" {HOME}{14 DOWN}1@ SD=54272:V=SD+24"
s:rem 149
562 PRINT"15 FORI=SDTOV: POKEL,@:NEXT: POKEV,15"
srem 163
504 SC=INT(F(@)/2T(7-0Cc) ) :rem 117
595 H=INT(SC/256) :L=SC-256*H :rem 82
519 PRINT"2@ POKESD,";MIDS(STRS$(L),2);":POKESD+1,"
;MIDS(STRS(H),2);"{4 SPACES}" srem 129
5208 PRINT"30 POKESD+5,";MIDS$(STR$(16*A+D),2);
srem 239

124
Sound 3

525 PRINT": POKESD+6,";MID$(STRS$(16*S+R),2);"


{6 SPACES}" :rem 48
530 IFW=65 THENGOSUB6 30 srem 110
IFRS=1THENGOSUB65@ :rem 137
546 PRINT"4@ TD=TI+";MIDS(STRS(DU),2);":POKESD+4, "
;MIDS(STRS(W),2);"{9 SPACES}" s:rem 144
545 PRINT"5@ IFTI<TDTHEN5@{17 SPACES}" srem 194
556 PRINT"6@ POKESD+4,9{28 SPACES}" srem 82
566 PRINT"{26 SPACES}" :rem 1088
690 GOTOL5@ srem 1961
636 PRINT"35 POKESD+2,";MIDS(STRS$(PL),2); :rem 78
648 PRINT": POKESD+3,";MIDS(STRS(PH),2);"
{18 SPACES}":RETURN :rem 124
656 PRINT"35 POKESD+15,";MIDS(STRS(H3),2); srem 99
660 PRINT": POKESD+14, ";MIDS(STRS(L3),2);"
{7 SPACES }":RETURN :rem 151

125
3 Sound

SYS Sound
Michael Steed

POKEing the SID chip’s registers produces


sounds on the 64. But that can become com-
plicated and discouraging, especially to the
beginning programmer. “SYS Sound” is a
machine language program that will help you
create sound in your own programs, without
using those cumbersome POKEs.
SRE RS ES Si a es Te

The Commodore 64 has an amazing sound chip, as you’ve


probably already discovered. However, to really make the SID
chip sing, you've got to go through the laborious process of
POKEing in values to various registers. If you’ve tried to use
sound in your own programs, you know how difficult this can
be. That is, until now. ‘SYS Sound” will make creating sound
much easier, and you won’t have to use a single POKE.
Careful Entering
Type in Program 1, SYS Sound, taking special care as you
enter the DATA statements. It’s a good ‘idea to save a copy
before you run the program, for one error can cause it to
crash. SYS Sound includes a total checksum, which will tell
you if you’ve entered all the DATA correctly, as well as in-
dividual line checksums if you use ‘“Automatic Proofreader,”
found in Appendix J. You can even SAVE this program on a
machine language monitor such as ‘“Supermon.”” Other mon-
itors, such as ‘““Micromon,” will not work, however, because
both the program and monitor will try to use location 49152.
The program displays the directions to save it with a monitor.
After you’ve got a working copy of SYS Sound, type
RUN. You'll have to wait for a moment while the DATA is
loaded into the computer’s memory. Now you're ready to use
SYS Sound in your own programming.

126
Sound 3

SYSing Sounds
To use SYS Sound, all you need to do is type SYS 49152, fol-
lowed by any of several possible parameters. The parameters
must be separated by commas. The number 49152 could (and
probably should) be defined as a variable, such as S or
SOUND. You can then call SYS Sound directly from your own
program, as long as it’s still in memory. Once you've turned
the computer off, however, SYS Sound disappears. You’d have
to load it again to use it.
The parameters used in SYS Sound, and their meanings
are:
@ Vx, where x is the voice number used for the note (1, 2,
or 3). More than one voice may be used at the same time (see
Program 2).
@ Ax, where x is the attack rate of the note. This is the
time it takes the sound to reach its highest volume. The larger
the number, the longer it takes. (See the figure for a graphic
description of attack, decay, sustain, and release.)
e Dx, where x is the decay rate of the note. This is the
time it takes the sound to soften to the sustain volume.
e@ Sx, where x is the sustain level of the note. The sound
remains at this volume until the release starts.
@ Rx, where x is the release rate of the note. The release
rate is the time it takes the sound to drop from the sustain
volume to silence.
e@ Wx{[y], where x is the letter representing the waveform
used for the sound. This can be N (noise), S (sawtooth), T (tri-
angle), or P (pulse). If the chosen waveform is pulse, then a
pulse rate (0 to 4095) must be entered after the waveform let-
ter, such as WP2048 for a square wave.
e Fx, where x is the frequency of the note (0 to 65535).
Higher frequencies produce higher notes.
e@ Lx, where x is the volume (loudness) of the note (0 to
15). Note that this is the overall volume, so all the voices will
be affected by it.
e C clears the sound chip. This is equivalent to the
following in BASIC:
1@ S=54272:FOR I=@ TO 24:POKE S+I,@:NEXT

127
3 Sound

ADSR Envelope

leattackdbeDecaydeSustain—ple Release—y

|
3
eS
a
E
<

Once certain parameters have been set, they need not be en-
tered the next time the routine is used. For example, if all your
sound effects were going to be done with voice 1, at volume
15, with the sawtooth waveform, attack 0, decay 9, and sus-
tain and release 0, you could set all these at the beginning of
your program by:
18 S=49152:SYS S,C,V1,L15,WS,D9

All parameters default to 0 initially, so A, S, and R needn’t be


entered. Then all that would need to be done to play a note
would be:
28 SYS S,F500G
Any valid numeric expression may be used after the parameter
letter. Also, if a parameter is entered more than once, only the
last case will be considered. For example, SYS S,WS,WT,
A0,A6 is effectively the same as SYS S,WT,A6.
To clear up any possible confusion, Program 2, ‘’Circus
Sounds,” provides a simple example of a sound created with
SYS Sound and its various parameters.

Program 1. SYS Sound


For mistake-proof program entry, be sure to use “Automatic Proofreader,” Appendix J.
106 DATA 32,121,98,208,3,76,241,192,201 srem 52
11@ DATA 44,248,3,76,67,193,32,115,9 srem 224
128 DATA 162,8,221,76,193,248,6,202,16 srem 68

128
Sound 3

130 DATA 248,76,67,193,138,18,178,189 srem 46


148 DATA 853,193,133), 2515,189),86), 093 3 3 srem 96
DATA 252,32,59,192,76,8,192,108, 251 srem 121
160 DATA ®@,32,55,193,201,1,144,4, 201 srem 299
176 DATA 4,144,3,76,72,193, 202,142,114 srem 79
18 DATA 193,96,32,55,193,19,10,19,19 srem 15
19% DATA 141,123,193,173,128,193,41,15 srem 71
286 DATA L3G 2 SiO Syl Aly, L201 19.3 9 Oise srem 17
219 DATA 55;, 193), J41 7.1237, 193, 1-/3,,120,193 srem 124
226 DATA 41,248,13,123,193,141,120,193 srem 58
236 DATA 96,32,55,193,19,19,19,19,141 srem 4
246 DATA L235, 193517 3 pl 21193140 pl Dy, 3 srem 18
256 DATA 123,193), 141,121 193 £9679 24,55 srem 29
260 DATA 1937, 141,023,193, 173,421,893 srem 236
276 DATA 41,249,13,123,193,141,121,193 srem 64
286 DATA 96,32,115,9,162,3,221,1983,193 srem 65
296 DATA 249,6,202,16,248,76,67,193,224 srem 137
388 DATA 1,249,6,32,115,9,76,196,192 srem 223
318 DATA 32,44,193,192,16,144,3,76,72 srem 29
328 DATA 193,142,117,193,148,118,193 srem 237
338 DATA 162,1,189,197,193,141,119,193 srem 83
348 DATA 96,32,44,193,142,115,193,148 :rem
356 DATA 116,193, 96,32,55,193, 141,122 srem 33
369 DATA 193,96,169,9,162,24,157,8, 212 :rem
378 DATA 262,16, 259,169,08,141,115,193 :rem
DATA 1419,116),193, 76, 015,09, bisigl 5 srem 26
DATA 193, 208,5,173,116,193, 240, 37 s:rem 38
DATA 174,114,193,189,111,193,133 srem 238
DATA 251,169, 212,133, 252,160,6,185 srem 75
DATA 115,193,145, 251,136,16, 248,169 srem 128
DATA 4,173,119,193,9,1,145,251, 173 srem 79
DATA 122,193,141, 24, 212,96,165,122 s:rem 73
DATA 298, 2,198,123, 198)71227176, 10 20 srem 35
DATA 8,32,166,173,32,247,183,166 srem 246
DATA 20,164, 21,96,32,44,193,152, 288 srem 128
DATA 11,224,16,176,7,138,967,162, 11 srem 82
DATA 76,58,164,162,14, 298, 249,86 s:rem 5
DATA 65,68,83,82,87,79,76,67,53,192 s:rem 157
DATA 72,192,94,192,112,192,134,192 :rem 86
DATA 152,192, 203,192,213 ,192,229 s:rem 228
DATA 192,78,80,83,84,128,64,32,16 s:rem 45
DATA 0,7,14,9,0,9,9,9,0,0,0,9,G s:rem 111
PRINT" {CLR}{DOWN}PLEASE WAIT..." :rem 136
FORI=49152T049531:READJ: POKEI ,J:K=K+d: PRINT"
{HOME}";SPC(54);J:NEXT srem 247
IFK<>44621THENPRINT"ERROR IN DATA STATEMENTS":
STOP s:rem 188
PRINT" {CLR}{3 DOWN}SYS SOUND"SPC(31)"K9 TJ":
QS$=CHR$ (34) srem 251

129
3 Sound

598 PRINT"TO SAVE IN MONITOR: ":PRINT"{DOWN}.S "QS"


SYS SOUND"Q$",@1,C80@,C17C srem 85
688 PRINTSPC(15)"fTT":PRINTSPC(15)"{DOWN}@1 FOR TAP
E,":PRINTSPC(15)"@8 FOR DISK srem 23

Program 2. Circus Sounds


198 REM *** SYS SOUND EXAMPLE *** srem 5
119 REM PARENTHESES IN 188, 198, 2900 srem 198
12@ REM ARE JUST FOR CLARITY srem 148
130 REM srem 120
149 REM * EXPERIMENT!!! * srem 49
159 S=49152:SYS S,C,L15:T=TIME srem 254
16@ READ D:IF D=@ THEN SYS S,C:END srem 114
178 READ F1,F2,F3 srem 116
188 SYS S,V1,F(F1),WS,AG,D9,S9,RO srem 81
198 SYS S,V2,F(F2),WS,A2,D4,S2,R2 srem 85
200 SYS S,V3,F(F3),WT,Al,D2,S19,R19 s:rem 171
210 T=T+18*D:REM DURATION srem 246
220 IF T>TIME GOTO 220 srem 177
238 GOTO 169 srem 191
308 DATA 2,6430,3215,1697 srem 201
SIO DATA 2, 7217, 3215, 1.402 srem 282
320 DATA 2,81901,4950, 2498 srem 198
338 DATA 2,8583,5728,3215 srem 223
348 DATA 1,9994,4547, 2498 srem 222
358 DATA 1,9634,4817, 2468 srem 223
36@ DATA 2,12869,8181,2864 z:rem 8
378 DATA 2,3215,9,@ srem 149
389 DATA 2,19814,8101, 2864 srem 7
398 DATA 2,9634,6438, 2145 s:rem 219
490 DATA 2,2145,1697,1351 srem 200
419 DATA 2,8583,5487,1607 srem 219
420 DATA 2,1697,1351,1607 z:rem 204
430 DATA 2,2145,1972,536 srem 155
448 DATA 2,8583,2793,1607 srem 218
458 DATA 2,8191,2793,883 srem 154
46@ DATA 2,7217,5497,3215 srem 214
479 DATA 2,8191,5728,2498 srem 217
488 DATA 2,28025,16907,8983 :rem 158
490 DATA 2,11457,8191,1697 :rem 7
5@8 DATA 2,2925,1607,8983 srem 151
518 DATA 2,3608,2864,1432 srem 213
52@ DATA 2,7217,5728, 2864 srem 226
538 DATA 2,8191,5728,4817 srem 220
548 DATA 2,6438,3215,1697 z:rem 207
55@ DATA 2,7217,5487, 2145 s:rem 215
56@ DATA 2,3215,2783,9 srem 5@
57@ DATA 2,18814,3215,16907 srem 3

130
Sound 3

586 DATA 2,2145,1607,1351 srem 299


596 DATA 2,1972,536,6 s:rem 6
606 DATA 1,6430,1687,8 srem 48
619 DATA 1,6438,1687,0 srem 49
6209 DATA 2,6439,1607,9 srem 51
630 DATA 2,6438,1687,893 srem 159
6408 DATA 2,6438,3215,1607 srem 288
656 DATA 2,7217,3215,1432 srem 269
DATA 2,8101,4958, 2498 srem 205
670 DATA 27 8983,5728, 3215 srem 230
689 DATA 1,9894,4547, 2488 s:rem 229
DATA 1,9634,4817, 2488 srem 230
7186 DATA 2,12868,81901, 2864 s:rem 6
710 DATA 2,6438,8,0 srem 149
720 DATA 2,10814,8101, 2864 srem 5
736 DATA 2,9634,6438,2145 srem 217
746 DATA 2,1072,1687,1351 srem 295
75@ DATA 2,8583,54897,1687 srem 226
766 DATA 2,1697,1351,1697 z:rem 21i
776 DATA 2,2145,1972,536 srem 162
786 DATA 2,8583,2763,1607 srem 225
796 DATA 2,8101,5728, 2488 srem 222
88 DATA 2,7647,6438, 2763 :rem 217
816 DATA 2,7217, 3688, 2864 srem 223
820 DATA 2,11457,7217, 2488 s:rem ll
836 DATA 2,10814,7217,2783 srem 6
840 DATA 2,4817,7217, 2864 :rem 229
850 DATA 2,12860,6438, 893 srem 214
860 DATA 2,10814,6439,4291 s:rem 9
870 DATA 2,9634,64308,803 srem 173
880 DATA 2,8583,4291,3215 srem 227
8908 DATA 2,9634,8181,5728 srem 231
98D DATA 2,1607,3215,9 srem 58
DATA 2,9634,5728,1804 srem 227
928 DATA 2,2625,4050,8 srem 45
936 DATA 6,8583,5407,1972 srem 226
946 DATA 4) srem 231

131
3 Sound

The Note Name


Game
Jeff Behrens

“The Note Name Game” is an educational pro-


gram which makes learning the notes of the
musical scale easy and fun.

Musical notation is like anything else—it’s easy once you


learn it, but learning it is not always easy.
Sight-reading of notes is vital for anyone who wants to
play a musical instrument, because instant note recognition is
a must. That’s the idea behind ‘’The Note Name Game.” My
daughters, who are taking piano lessons, love playing it. Al-
though it does not teach everything about musical notation, it
does help students to practice quick recognition of notes in the
treble and bass clefs.
Treble or Bass
The program begins by asking whether you want to practice
notes on the treble clef (enter a T), the bass clef (B), or a mix-
ture of both (M). The program then selects a note at random
and places it on the appropriate clef.
Next, the program asks for the letter name of the note
displayed. If your response is correct, you are told so, and the
next note is displayed. If your response is wrong, the correct
answer is highlighted on the screen and the next note is
shown. The program constantly updates your score and dis-
plays it on the screen.
Notes are shown in sets of ten. If you wish to quit before
finishing a set, type Q instead of the answer. Whether you fin-
ish or not, the score is printed and you are asked if you want
to play again.
Customizing the Program
Depending on personal preference, there are some changes
you might want to make. I find the TV picture is sharpest
132
Sound 3

when the screen and border are black and the cursor blue dur-
ing the game. You may, of course, specify any screen/border
combination by substituting the appropriate number for the 0
in the POKE statement on line 185 for the background and the
value in the POKE V+32 statement in line 5 for the border
color. You can even change the background color for the title
screen by altering the POKE V+33 statement in lines 5 and
325. (See Appendix E for possible combinations).
The variables R and W, respectively, are the number of
right and wrong answers. The string variable N$(2,24) is a
string array containing the note names and the POKE values
for the sound registers.
The Note Name Game
For mistake-proof program entry, be sure to use “Automatic Proofreader,” Appendix J.
5 PRINT" {CLR}":V=53248:SD=54272: POKE646, 14: POKEV+3
2,0:POKEV+33,7:DIM NS$(2,24) :SC=0 :rem 78
6 NO%$=25:POKEV+21,0 :rem 69
8 FORI=SDTOSD+28:POKEI,@:NEXTI srem 219
10 FOR I=@TO24:READNS(@,1):NEXTI :rem 135
15 FOR I=@TO24:READNS(1,1):NEXTI s:rem 141
28 FOR I=0@TO24:READNS(2,1):NEXTI :rem 138
25 :::REM READ SPRITE DATA srem 6
38 FOR I=OTO62: READQ: POKE832+1I,Q: NEXTI :rem 138
35 FOR I=OTO62: READQ: POKE896+1,Q: NEXTI :rem 153
49 FOR I=OTO62: READQ: POKE969+1I,Q: NEXTI :rem 141
45 :::REM TELL COMPUTER WHERE SPRITE IS srem 137
5@ POKE2@42,13:POKE2043,14:POKE2044,15 s:rem 116
55 :::REM POSITION SPRITE ON SCREEN srem 165
69 POKEV+4, 160: POKEV+5, 7 srem 191
65 POKEV+6,158: POKEV+7,119 srem 250
7G POKEV+8,158:POKEV+9,171 :rem 1
75 :::REM COLOR SPRITES :rem 167
78 POKEV+41,1:POKEV+42,1:POKEV+43,1 srem 60
88 :::REM EXPAND SPRITES srem 228
85 POKEV+29, 28: POKEV+23,28 s:rem 3
98 :::REM SET SOUND PARAMETERS srem 102
95 POKESD+24,15:POKESD+5, 4: POKESD+6, 179: POKESD+2,9
: POKESD+3, 9: POKESD+12, 2 srem 164
96 POKESD+13,243:POKESD+19,@:POKESD+29,245:rem 206
198 PRINT" {CLR}{2 DOWN}";TAB(11);"{RVS}THE NOTE NA
ME GAME{OFF}" srem 81
195 PRINT"{5 DOWN}{6 RIGHT}I WILL PLAY A NOTE FOR
{SPACE}YOU AND" srem 79
119 PRINT"{DOWN}{3 RIGHT}THEN SHOW YOU A NOTE ON A
STAFF." s:rem 47

133
3 Sound

115 PRINT" {DOWN}{3 RIGHT}I WANT YOU TO TELL ME THE


NAME OF":PRINT"{DOWN}{3 RIGHT}THE NOTE."
srem 5
126 PRINT"{3 DOWN}{4 RIGHT}INPUT{2 SPACES}{ RED}
{RVS}B{OFF} FOR BASS, {RVS}T{OFF} FOR TREBLE,"
srem 162
125 PRINTTAB(13);"{DOWN}OR{2 SPACES}{RVS}M{OFF} FO
R MIXED." srem 95
128 POKE198,90 srem 200
13 GETES: 1 FES=""THEN13@ :rem 83
135 IFES <>"T"ANDES<>"B"ANDES<>"M"THEN13@8 :rem 233
185 POKE V+33,9 srem 16
196 FOR L=1TO19 :rem 63
280 POKEV+21,@8:PRINT"{CLR}K73{2 DOWN}{RIGHT }WHAT
{2 SPACES }NOTE":PRINT"{DOWN}{2 RIGHT}IS THIS?
{ HOME }" srem 94
205 M=25:S=@: IFES="B"THENM=13 srem 148
216 IFES="T"THENM=13 :S=12 srem 178
245 RN3$=INT (RND(@)*M+S) srem 48
217 IFRN%=NO%$THEN215 srem 188
218 NOZ=RNZ srem 95
226 GOSUB459@ srem 221
225 POKEV+21, 28: PRINT" { HOME} { DOWN} ":GOSUB75@
srem 199
230 FORZ=1TO2:PRINT"{16 RIGHT}{24 SPACES}"; sNEXTZ
srem 2
235 GOSUB75@:PRINT" {HOME}" srem 212
245 IFRNS=24THENPRINT" {HOME}{29 SPACES }***
{HOME }" ~~ srem 248
256 IFRN%=12THENPRINT"{HOME}{12 DOWN}{29 SPACES}
*** {HOME }" srem 189
255 TFRN3=OTHENPRINT"{HOME}{23 DOWN}{3@ SPACES}
*** {HOME } :rem 40
266 POKE2@14+54272-RN%*4@,
1: POKE2@14-RN3*49, 81
srem 223
265 PRINT" {HOME}{2@ DOWN}('Q' TO QUIT) {HOME}"
srem 1908
268 PRINT" {HOME}{18 DOWN}{RVS}SCORE{OFF} :";SC;"
{LEFT}%{2 SPACES} {HOME }" srem 53
276 PRINT"{7 DOWN}{2 RIGHT}> "; srem 148
273 POKE198,@ z:rem 201
2 GETGUS : IFGUS=""THEN275 srem 21
280 IF(ASC(GU$)<65 OR ASC(GUS$)>71)AND ASC(GUS)<>81
THENPRINT"{8 UP}":GOTO27@ :rem 196
285 PRINTGUS srem 236
IFGUS="Q"THEN 3198 srem 127
295 IFGUS=NS (@, RN% ) THENGOSUB49@ :rem 83
3808 IFGUS <>N$ (0, RN%) THENGOSUB58G srem 132

134
Sound 3

365 IFR+W<>OTHENSC=INT((R/(R+W)
)*190+.5) sNEXT
srem 156
316 POKEV+21,0:PRINT"{CLR}" srem 161
315 PRINT"{7 DOWN}{9 RIGHT}YOUR SCORE WAS";SC;"
{LEFT }3" srem 174
318 POKE198,9 srem 2901
328 PRINT"{5 DOWN}{4 RIGHT}WOULD YOU LIKE TO PLAY
{ SPACE }AGAIN"; : INPUTYS srem 151
325 IFLEFTS (Y$,1)="Y"THENR=9 :W=0:SC=0:POKE V+33,7:
GOTO19G srem 93
336 SYS2048:REM END OF PROGRAM zrem 5
400 :::REM CORRECT srem 56
419 POKESD+11,129 :rem 176
420 FORI=536TO9094STEP256:PRINT"{3 DOWN} {RIGHT}
{WHT}{RVS} CORRECT {OFF} {WHT}"sHI=INT(1/256):L
O=I-HI* 256 srem 71
436 PRINT" {UP}{2 SPACES}CORRECT {4 UP}&7]3":POKES
D+8,HI:POKESD+7, LO:NEXTI z:rem 244
446 FORT=1T01@:NEXT: POKESD+11,128:FORT=1TO900:NEXT
:R=R+1: RETURN srem 59
588 :::REM INCORRECT srem 208
5@5 POKESD+18,33:POKESD+16,@:POKESD+15,6 :rem 193
516 PRINT" {DOWN}SORRY, THAT'S":PRINT"
{DOWN} INCORRE
Cre srem 225
515 PRINT" {DOWN}IT WAS: ";:NS$(@,RN3) zrem 94
520 FORT=1T0O1009 : NEXT: POKESD+18, 32: FORT=1T0O98@ : NEX
T:W=W+1: RETURN :rem 117
756 FORX=1T05 srem 33
diap PRINT TAB(16);:FORI=1T024:PRINT CHRS(99);:NEXT
srem 24
768 PRINT"{16 RIGHT}{24 SPACES}"; sNEXTX:RETURN
srem 100
786 PRINT"THE NOTE WAS:";NS$(@,RN3) zrem 283
785 W=W+1:RETURN :rem 5
1899 :::REM TELL COMPUTER WHERE SPRITE IS :rem 225
185 POKE2042,13: POKE2043,14:POKE2044,15 :s:rem 213
1819 :::REM POSITION SPRITE ON SCREEN srem 253
1615 POKEV+4, 160: POKEV+5, 72 srem 32
18208 POKEV+6, 158: POKEV+7,119 :rem 82
1825 POKEV+8, 158: POKEV+9,171 srem 98
1839 :::REM COLOR SPRITES srem 255
1635 POKEV+41,1: POKEV+42, 1: POKEV+43,1 s:rem 159
1846 :::REM EXPAND SPRITES IN BOTH DIRECTIONS
srem 249
1845 POKEV+29, 28: POKEV+23, 28 :rem 96
1659 :::REM TURN ON SPRITES zrem 1064
1855 POKEV+21, 28 srem 116
1999 END :rem 179
28608 PRINT:GOSUB 4979 srem 221

135
Sound 3

20065 FORZ=1T02:PRINT"{16 RIGHT}{24 SPACES}"; sNEXTZ


srem 52
2016 GOSUB497@: PRINT" { HOME }" srem 53
4500 POKE SD+1,VAL(NS$(2,RN$%))
: POKESD, VAL(NS$(1,RN$)
)s POKESD+4, 65 srem 198
4510 FORT=1TO 6090 :NEXT:POKESD+4, 64 srem 26
4520 RETURN srem 171
4976 FORX=1T05 srem 89
4989 PRINT TAB(16);: FORZ=1T024: PRINT CHRS(99);:3
EXTZ srem 183
4996 PRINT"{16 RIGHT}{24 SPACES}"; :NEXTX: RETURN
srem 157
5606 DATAE,F,G,A,B,C,D,E,F,G,A,B,C,D,E srem 68
581 DATAF,G,A,B,C,D,E,F,G,A srem 22
5826 DATA7A 1524 /iGL2 srem 48
5930 DATA233,97,194,143 srem 155
5946 DATA48, 143, 24, 219 srem 190
5056 DATA195, 2909, 31,96 :rem 117
5860 DATA39@,49,165,135 srem 119
58708 DATA162,62,193,69,99 srem 12
5886 DATA5,5,6,7,7 srem 165
5898 DATA8,9,18,11,12 srem 47
5186 DATA14,15,16,18,21 srem 142
5116 DATA22, 25, 28, 31, 33 srem 144
5126 DATA37,42,44,59,56 srem 154
5146 DATA®D, 224,9,9,208,9,9,216,09,0,204,9,8 trem 5
5145 DATA296,9,9,199,9,8,199,9,9,199,9,%0,206,0
srem 238
5156 DATAGD, 294,9,0,216,9,0,249,9,9,224,9,1 srem 3
5155 DATA192,9,3,192,9,6,192,9,12,192,0,24,192
srem 248
5168 DATA, 48,192,9,96,192,0,224,192,8 srem 121
5179 DATA48,111,128,97,248,192,195,96,96,198,96,48
,195,194,48,193 srem 246
Sr7D DATA232, 48,96, 248,96 s:rem 27
5186 DATA112,96,224,56,96,192,28,99,192,7 :rem 52
5185 DATA111,9,1,248,9,9,96,9,0,9,09,9,9,9,9,9,9
srem 238
51908 DATAY,9,9,9,9,9,09,9,0,9,9,9,0,9,9 srem 33
5200 DATA 9,248,9,3,6,9,6,3,128,6,9,198,3,192,198,
3,192,192,9,98,198,0,1,134,9,1 srem 8
5210 DATA128,9,3,9,9,3,0,9,6,9,9,12,%9,0,24,0,9,112
,9,1,192,9,3,9,9,9,9,9,9,08,0 :rem 142
5220 DATAG,9,9,9,9,9 srem 223

136
4

Oe) Leyacy
Olttelars eyelets
AY,Cosatore!
Colors, Characters, and Motion 4

Introduction to
Custom Characters
for the 64
Tom R. Halfhill

What are “custom characters”? Why might you


want them? Are they hard to program? How do
they work? This introduction to the concept of
custom characters answers all these questions
and more. Another article in this book, “How to
Make Custom Characters on the 64,” shows you
exactly how to program custom characters.
ES
EEE Sa a

Perhaps you've admired the screen graphics of a favorite


arcade-style game, or the Old English letters of a Gothic text
adventure. These kinds of shapes and special characters are
not built into the computer itself. Maybe you’ve wondered
how these effects are achieved and if they are difficult to
program.
The secret is a technique called custom characters, also
known as redefined characters or programmable characters. The
terms are almost self-explanatory—with programming, you
can design your own shapes and special characters to display
on the TV screen. They can be almost any shapes you want:
spaceships, aliens, animals, human figures, Old English letters,
anything. In effect, you are customizing or redefining the
characters already built into the computer.
For instance, if you redefine the letter A to look like an
alien creature, every time you PRINT A on the screen you'll
get the alien instead of the letter. Animation is as easy as eras-
ing the character—by PRINTing over it with a blank space—
and then PRINTing it in the next position. When this process
is repeated rapidly, the alien seems to move across the screen.

139
4 Colors, Characters, and Motion

Custom characters are especially useful to game pro-


grammers, but also are fun to experiment with for anyone
interested in programming.
Character Sets
First, let’s clarify exactly what a character set is. Briefly, it is
the complete set or collection of characters that a particular
computer can display on its video screen. Characters include
letters of the alphabet (both upper- and lowercase), numbers,
punctuation marks, symbols, and—on the Commodore 64—
the 64 special graphics characters that are pictured on the
front of the keys. In all, your 64 has a standard character set
of 256 characters. This is the total set of characters which the
computer is capable of displaying.
The character set is built into the computer, permanently
stored in Read Only Memory (ROM). ROMs are memory chips
that retain important information even when power is turned
off between sessions. The character set is stored in ROM as a
list of numbers. The numbers describe to the computer how
each character is formed from a pattern of tiny dots.
You may be able to see these dots if you look very closely
at your computer screen. (The dots might be too small to dis-
cern on some ordinary TV sets, but they are much more vis-
ible on a monitor.) All the characters in the character set are
made up of these dots. The dots for each character are part of
an 8-by-8 grid, for a total of 64 dots per grid . This method of
forming characters is familiar to anyone who has seen the
large time/temperature clocks on banks, or the scoreboards in
sports stadiums. A computer displays characters the same
way, except instead of light bulbs, the dots are very small pin-
points of glowing phosphor on the TV picture tube. (Figure 1
shows the dot pattern for the letter A on a Commodore 64.)
Figure 1. Dot Pattern for Character A

140
Colors, Characters, and Motion 4

The character set is always kept in ROM, ready for the


computer to use. Let’s say you display a character on the
screen—for instance, the uppercase letter A. The computer re-
fers to the character set in ROM to see how it should display
the A on the screen, much as you would refer to a dictionary
to see how to spell a word. Once it looks up the dot pattern
for an A, the computer displays the character. The whole proc-
ess takes only a few microseconds, and happens every time a
character is displayed, either by typing on the keyboard or
using a PRINT statement in BASIC.
When the computer’s ROM chips are preprogrammed for
you at the factory, these dot patterns for each character are
permanently burned into the chips so the computer will al-
ways display the same character set. Short of replacing the
ROM chips themselves, there is nothing you can do to change
this preprogramming. Normally, this would limit you to the
built-in character set. Indeed, on some computers there is no
alternative.
Fooling the Computer
However, on the 64—and on many other home computers—
there is a way to modify the character set to suit your own
needs. The technique requires fooling the computer.
Here’s how it’s done. The first obstacle to overcome is the
preprogrammed ROM chips. It’s not possible to erase or
change information in ROM. But remember, there are two
types of memory chips in computers: ROM and RAM.
RAM (Random Access Memory) is temporary memory
that can be erased and changed. Programs loaded from disk or
tape, or which you write yourself, are stored in RAM while
they run. They can be changed at any time from the keyboard,
or even erased altogether by typing NEW or switching off the
computer. RAM is the computer’s workspace.
So, the first step toward custom characters is to copy the
list of numbers representing the character set from ROM into
RAM.
This is a relatively simple programming task. You find out
exactly where in ROM the character set is stored by looking at
a memory map, a list of memory addresses inside the computer.
(Memory maps are often found in reference or owner’s man-
uals or magazine articles.) Once you know the beginning
memory address of the ROM character set, you can write a

141
4 Colors, Characters, and Motion

short routine which reads the list of numbers in ROM and


then copies it into RAM. In BASIC, this is done with PEEKs
and POKEs within a FOR-NEXT loop. One or two program
lines are all it takes.
Now there’s a copied image of the ROM character set in
RAM. Again using POKEs, you can freely change the list of
numbers to customize the characters any way you want (we'll
cover this in detail in a moment).
OK so far, but there’s one catch. The computer doesn’t
know you've relocated the character set. It still expects to find
the character set where it always has, in ROM. It will continue
to refer to ROM and will ignore your customized set in RAM.
That’s why you have to “fool’’ the computer. The 64 con-
tains a memory location, called a pointer, which points to the
character set in ROM. Luckily, the pointer itself is in RAM.
With a single POKE statement, you can change the number in
this location to point to your custom character set in RAM,
thereby fooling the computer into referring there for its
information instead of ROM. The computer goes through its
usual process of looking up the dot pattern for each character
and displaying it on the screen, except it looks up your modi-
fied pattern instead of the pattern preprogrammed at the
factory.
Clever, eh?
Character Patterns
Basically, if you’ve made it this far, you’ve got the picture. But
there are still a few details to clean up.
For example, exactly how are characters customized?
Recall that the character set is defined by a list of num-
bers which describes the dot patterns for each character, and
that each character is formed by dots within an 8-by-8 grid.
By changing these numbers, you change the shape of the dot
pattern, and therefore the shape of the character.
It helps at this point to know something about the binary
number system. Each byte of memory in your 64 is made up
of eight bits. These bits can be set to 1 or 0, hence the term
binary. A bit that is set to 1 is often referred to as being on,
while a bit set to 0 is said to be off. The pattern of on and off
bits in a byte creates a particular value, ranging from 0 to 255.
Within a byte, each bit has an individual value assigned
to it. The bit on the far right represents a value of 1 when it is

142
Colors, Characters, and Motion 4

on. The bit next to it, to the left, represents a value of 2 when
it is on. This pattern continues, each bit to the left represent-
ing a value double that of the previous bit. Look at Figure 2 for
a moment to see this pattern.

Figure 2. Binary Number Values


Bit Number 7. (6) SHCA GS M201 0
Bit Value 128 64 32 16 8 4 2 1

For instance, if the left-most and right-most bits were


both on, while all the rest were off, the byte’s total value
would be 129. You arrive at that value by simply adding to-
gether the on bits’ values. 128+ 1=129. To show the pattern
of a character, whether it’s a standard character or a custom
character, binary values have to be added together. It’s not
difficult. Figure 3 shows the standard character A as an
example.
The eight numbers running vertically along the right side
of Figure 3 are the numbers which define the dot pattern for
an A on a Commodore 64. These are the same eight numbers
which the computer refers to when it looks up A in the
character set. They are also the numbers you must change to
customize the character. These numbers are decimal versions
of the binary dot patterns.

Figure 3. Dot Pattern for A


128643216 8 4 2 1
24 (16+8)
60 (32+ 16+8+4)
102 (64+ 32+4+2)
126 (64+ 32+16+8+4+2)
102 (64+32+4+42)
102 (64+ 32+4+2)
102 (64+ 32+4+2)
0

143
4 Colors, Characters, and Motion

Along the top of Figure 3, running horizontally from right


to left, are the bit values.
Now, this is important: to understand how the numbers
in the vertical column were determined, simply add up the
numbers in the horizontal row which correspond to colored
dots in the 8-by-8 grid. For example, the top row of the grid
has two colored dots which form the peak of the A. (These are
the same dots which will be lit up when the letter is displayed
on the TV screen.) These two dots fall beneath the 8 and 16 of
the top row of numbers. Because 8+ 16=24, the number in
the right-hand column for that row is 24.
Likewise, the next number in the right-hand column is 60,
because the colored dots in the second row of the grid fall be-
neath the 4, 8, 16, and 32, which add up to 60. And so on
down to the very last row, which has no colored dots. This is
represented by a 0 in the right-hand column. When the A is
displayed on the screen, no dots will be lit up on this row of
the grid. (All patterns for letters and numbers allow a blank
line for the last row, and for the extreme right and left-hand
columns, in order to keep the characters from running into
each other on the screen.)
Customizing Characters
Once you understand how character patterns work, it’s easy to
customize them at will.
First, take some graph paper and mark off an 8-by-8 grid,
or draw your own grid on a blank sheet. Along the top, write
down the horizontal row of numbers as seen in Figure 3: 1, 2,
4, 8, 16, 32, 64, and 128. Be sure to list them from right to left.
Second, design your custom character by coloring in dots
on the grid. Figure 4 shows a sample design for a Space
Invaders-type creature.
Third, add up the colored dots in each row, starting from
the top. Write down each sum in a vertical column along the
right, as seen in the figures.
You have now designed your own custom character. You
can design as many of these as you'll need—up to the limit of
256 characters in the character set.
The only remaining step is to take the new series of eight
numbers for each custom character and substitute them for the
numbers in the standard character set. Remember, that’s why
you relocated the character set from ROM to RAM. Now that

144
Colors, Characters, and Motion 4

Figure 4. Dot Pattern for a Customized Character


(Space Invaders-Type Alien)
128
64 3216 8 4 2 1

| | 24 (16+8)
126 (64+32+16+8+4+2)
219 (128+ 64+16+8+2+4+1)

219 (128+ 64+16+8+2+1)


153 (128+16+8+1)

the list of numbers spelling out the patterns for the standard
character set is in RAM, it can be changed to use your own
numbers with POKE statements.

Specific Details
Up to now, this article has been fairly general in its explana-
tions. The basic technique for customizing characters is the
same for almost any computer on which the character set can
be relocated and redefined. But the specific details vary for
each computer: the character set’s memory address in ROM,
how to safely copy it to RAM, the memory address of the
character set pointer, the order of characters within the charac-
ter set, and so on.
For these details, as well as example programs and util-
ities, turn to the next article ““How to Make Custom Characters
on the 64.”

145
4 Colors, Characters, and Motion

How to Make
Custom Characters
on the 64
Gary Davis

Before reading this, be sure to see “Introduction


to Custom Characters for the 64” in this book,
especially if you’re unfamiliar with the concepts
of redefined characters. The following article in-
cludes “Chred 64,” a character-editing utility
that makes the task of customizing characters
easy and fun.
LL
Le LE AES 8

The Commodore 64 allows you to change any character in the


character set to suit your own needs. In order to understand
how this is done, it is first necessary to understand how the 64
(and most other computers) store the character set.
If you look closely at the letters the computer puts on the
screen, you'll notice that each character is made up of little
dots in an 8 x 8 grid (see the figure).
Since there are 64 possible dots, or pixels, that can be
either on or off, we need 64 “switches” for each character. This
is done by using eight memory locations for each character.
Since one memory location, or byte, is divided into eight bits,
using eight bytes gives us the 64 switches we need for each
character.
The bytes for each character are stored consecutively, with
the first byte for each character representing the top row of
dots in the character, the second byte the second row of dots,
and so on. For a pixel to be on, the bit at its location must be
set; for a pixel to be off, the bit must be clear. This is not as
complicated as it sounds. The figure shows how the bit pat-
terns of sets and clears are converted into the numbers that
represent the character. When you make a series of bytes for

146
Colors, Characters, and Motion 4

every character and store them in a computer, you have what


is known as a character generator.
Relocating the Character Set
The character generator in most computers, including the
Commodore 64, is stored in Read Only Memory (ROM). This
way the computer is ready to display characters on the screen
as soon as it is turned on.
Unfortunately, when the character generator is in ROM,
you can’t change the characters to suit your needs. When you
can’t change the existing character set, the simplest way to
customize a new character set is to move it to Random Access
Memory (RAM), and then tell the computer to use your
character set rather than the one it has in ROM.

Pixel Pattern for Letter A


128 643216 8 421
16+8=24
32+16+8+4=60
64+ 32+4+2=102
64+ 32+16+8+4+2=126
644+ 32+4+2=102
644+ 32+4+2=102
644+ 32+4+2=102
=0

Telling the Commodore 64 where the new character set is


located is relatively simple to do. Within the video controller
chip (sometimes known as the VIC-II chip) is a special mem-
ory location that allows you to set a new character pointer (the
location of the first byte of your character set).
Now let’s try an experiment. Type POKE 53272,19 and
press RETURN. Your screen will be filled with strange charac-
ters, but don’t worry. You have told the 64 to use a RAM
character generator, but you haven’t supplied one yet. To re-
turn your screen to normal type POKE 53272,21 and press RE-
TURN. You won’t be able to read what you are typing until
you press RETURN, but the computer understands. If this
doesn’t work, you can always restore the screen by pressing
the RESTORE and RUN/STOP keys at the same time.

147
4 Colors, Characters, and Motion

When you are designing a new character set, it is nice to


have the normal one loaded into RAM to start with. Then you
can make changes to it. Program 1 copies the 64’s character
set from ROM to RAM.
Before you type in this program, you must enter:
POKE 8192,0: POKE 44,32: NEW
This saves a place in RAM memory for your new charac-
ter set and protects it from being overwritten by a BASIC
program.
Now, type in the program and RUN it. After about 45
seconds the computer will come back and say READY. Now
type POKE 53272,19 and press RETURN. Nothing appears to
happen, but the characters you are now seeing on your screen
are coming from your RAM character generator, not from
ROM as usual.
To test this, type POKE 2056,255. The top of all the letter
A’s on the screen should now be a solid line. Try POKEing
different numbers into memory locations between 2048 and
6143 and watch the results on the characters.
Using a Character Editor
By sketching an 8 x 8 grid as seen in the figure, it’s possible to
map out the entire character set on graph paper and convert
your new characters to numbers to POKE into memory.
This method, however can be both time-consuming and
frustrating. A far better way is to create your new characters
on the screen and let the computer do all the calculations.
With this thought in mind, I wrote a character editor called
“Chred 64.” With this utility (Program 2), you can redefine
any of the text or graphics symbols and save them on tape or
disk. This can then be loaded and used with any program.
In order to reserve memory for the alternate character set,
it is necessary to set the start of BASIC pointer to 8192. This
will leave you with 32K of RAM free for your BASIC program.
To do this, you must type in the following:
POKE 8192,0
POKE 44,32
NEW
Now the memory from 2048 to 8191 is free to hold your
new character set. You may type in or load Chred 64. After
typing Chred 64 for the first time, be sure to save it on tape or

148
Colors, Characters, and Motion 4

disk before you run it. If you have made a typing error, it is
possible that the computer will “crash” and you'll have to
type it all over again if you haven’t saved a copy.
When you run Chred 64, the program first copies the res-
ident character set from ROM to RAM and resets the character
base to point to the RAM character set. The program then ex-
pands the current character being edited to eight times its nor-
mal size.
To edit the current character being displayed, you may
use the cursor control keys, the asterisk, and the space bar.
To turn on a pixel, position the cursor and press the as-
terisk. To turn off a pixel, press the space bar. To clear the
entire character, press CLR.
To edit a different character, press f1. You will be asked
to supply a row and column. This refers to the block of
characters displayed on the lower right corner of the screen.
Just type a row number followed by the column number or
letter. The character you selected will now be displayed, ready
for you to edit.
More Editing Features
An interesting feature of the 64 is that, unlike the Commodore
PET, the reverse-field (inverse video) characters are stored as
part of the character set. This allows 256 redefined characters.
To edit a character not being displayed, press f3. This will se-
lect and display the next block of 64 characters. Rest assured
that you may mix characters from any of the blocks; only 64
characters are shown at a time for the purpose of editing.
Sometimes you may wish to edit more than one character
at a time to make a larger shape. This can be easily accom-
plished by pressing f5. Instead of a single character, you will
be able to edit a block of four characters. To go back to single
character mode, just press f5 again.
After you have redefined several characters, the text on
the screen may become unreadable as your new characters re-
place the existing ones. To restore the character set to normal,
without destroying your new character set, press f7. To return
to your new character set, press f7 again.
When you are done working with a character set, you can
restore the font to the normal character set by pressing R. You
will be asked ‘Are you sure?” Now is your last chance to save
your character set. If you are really done, press Y; otherwise,
press N.
149
4 Colors, Characters, and Motion

Saving and Loading


After you have gone to the effort of creating a new character
set, you will probably want to save it on disk or tape for use
in other programs. To save your character set, press S. Follow
the directions given on the screen. After the character set is
saved, you will be returned to the editor. (When typing Chred
64, omit line 225 for use with tape.)
Sometimes you may wish to alter a character set that you
have already created and saved. To load another character set,
press L and follow the directions given on the screen. Be care-
ful—the new character set is loaded on top of the current
character set, so be sure to save it if you want to use it later.
OK, you’ve developed your new character set. To use it
with another program, you will have to type POKE 8192,
0:POKE 44, 32: NEW, just as you do when you load Chred
64. To load in the character set, place the cassette containing
your new character set in the recorder, or the disk in the drive.
For tape, type LOAD ” filename’’, 1,1 where “filename” is the
name you gave when you saved the character set. For disk,
type LOAD “filename”, 8,1. To use the new character set,
POKE 53272, 19. To return to the normal character set, POKE
5S27 2,00:
I hope you have as much fun using this program as I had
writing it.

Program 1. Character Set Transfer to RAM


For mistake-proof program entry, be sure to use “Automatic Proofreader,” Appendix J.

1@ POKE 56334,98:REM TURN OFF INTERRUPTS srem 83


20 POKE 1,51:REM TURN OFF VIDEO CHIP TO EXPOSE CHA
RACTER GENERATOR srem 229
3@ FOR ADDRESS = 2048 TO 6143 srem 204
49 POKE ADDRESS, PEEK (ADDRESS + 51200):{3 SPACES}
REM COPY CHARACTERS TO RAM srem 32
5@ NEXT ADDRESS s:rem 179
68 POKE 1,55:REM TURN ON VIDEO CHIP :rem 251
7G POKE 56334,129:REM TURN ON INTERRUPTS :rem 135
88 END srem 63

Program 2. Chred 64
198 REM "CHRED 64" srem 137
128 POKE53280,11:POKE53281,@:PRINT"£59" srem 189
130 V=53248:SC=1024:CB=2948 :CC=SC+490*21+9 srem 222
148 SZ=7:FP=0:FO=0:TP=0:TY=9:SL=0:RS="0"sCcS="G"
srem 199

150
Colors, Characters, and Motion 4

158 cos="* {RIGHT}{LEFT}


{DOWN} {UP} {HOME}{CLR}{F1}
{F3}{F5}{F7}SLRQ" srem 85
169 DNS="{HOME}{17 DOWN}" srem 2
176 BLS="{18 SPACES }" srem 2983
1868 NUS="@123456789ABCDEF" s:rem 131
198 DEFFNA (F )=SC+62+48*CY+CX srem 86
288 DEFFNB(F)=CB+( (FO+TP ) *8)+TY srem 251
218 PRINT"{CLR}{5 DOWN}{9 SPACES}{YEL}CHARACTER SE
T LOADING" srem 97
226 GOSUB158@ srem 218
225 POKE 49276,8:REM ENTER THIS LINE FOR DISK ONLY
-- OMIT FOR CASSETTE srem 94
239 SYS49152: POKEV+24,19 srem 127
240 POKE 53281,1:PRINT"{CLR}":POKE 53281,8:GOSUB1@
60 srem 12
250 CY=9 : CX=0 srem 226
260 POKEFNA(@), PEEK(FNA(@))OR128 srem 81
2708 POKE198,9 srem 198
280 GETCHS : [IFCHS=""THEN286 srem 235
296 FORCH=1 TOLEN (COS) :IFMIDS$(CO$,CH,1)=CHSTHEN319
srem 149
386 NEXTCH: GOTO27@ srem 105
3198 POKEFNA(@),PEEK(FNA(@))ANDNOT128 srem 112
3268 ONCHGOT0339,370,4190,439,450,479,490,509,598,77
G,809,1949,918,909,848,1920 srem 119
336 POKEFNA(@), 42 :rem 173
348 GOSUB55@ s:rem 177
358 POKEFNB(@),PEEK(FNB(@)
)OR2f (ABS(TX-7)):srem 288
3608 GOTO269G srem 196
378 POKEFNA(@), 32 srem 176
386 GOSUB55@ srem 181
3968 POKEFNB(@),PEEK(FNB(@) ) ANDNOT2f (ABS (TX-7) )
srem 247
409 GOTO260 :rem 191
41 CX=CX+1 3: IFCX>SZTHENCX=9 srem 234
420 GOTO269 srem 193
430 CX=CX-1 : IFCX<8THENCX=SZ srem 236
446 GOTO269G :rem 195
450 CY=CY+1: IFCY>SZTHENCY=2 srem 242
466 GOTO269G srem 197
476 CY=CY-1: IFCY<@THENCY=SZ srem 244
486 GOTO26G srem 199
496 GOTO25@G :rem 199
58D FORCY=9TOSZ : FORCX=9TOSZ: POKEFNA(@),32 :rem 158
519 GOSUB55@ s:rem 176
528 POKEFNB(@),@ srem 121
538 NEXTCX, CY srem 58
546 GOTO25@ s:rem 195
556 TP=FP :TX=CX: TY=CY:IFTX>7ANDTY<S8THENTP=TP+1
:TX=
TX-8 s:rem 177

151
4 Colors, Characters, and Motion

568 IFTX<8ANDTY > 7THENTP=TP+2:TY=TY-8 srem 134


578 IFTY> 7ANDTX> 7THENTP=TP+3 : TY=TY-8 : TX=TX-8
srem 189
580 RETURN srem 125
596 PRINTDNS"{RVS}{YEL}ROW, COLUMN?{OFF}£59 ":
srem 197
689 POKE198,@ srem 195
618 GETRS : LFRS=""THEN610 srem 115
629 IFVAL(RS$)<>@ANDVAL(RS ) <4ORRS="@"THENR=VAL(RS) ¢
GOTO64G :rem 165
636 GOTO699 srem 194
646 PRINTRS", "> srem 72
656 POKE198,@ srem 299
669 GETCS : ILFCS=""THEN66@0 srem 95
676 IFCS=CHRS (20)THENPRINT"{2 LEFT}{2 SPACES}";:GO
T0599 srem 19
68D IFASC(CS$)>64THENC=ASC(CS$)-55:IFC>1L5THEN60G
s:rem 174
699 IFVAL(CS$)<>@ORCS="@"THENC=VAL(C$) srem 118
788 IFC>15THEN65@ srem 215
710 PRINTCS srem 149
728 FP=R*16+C srem 189
738 IFSZ=15ANDFP >69THENFP=60:CS="C":C=12 srem 112
748 GOSUB129@ srem 231
758 PRINTDNS; BLS srem 294
768 GOTO25@ srem 199
778 IFFO<191THENFO=F0+64 : GOTO79@ srem 215
780 FO=0 s:rem 161
796 FP=9:RS="90":CS="@0":GOSUB1240:GOTO25@ :s:rem 225
88S IFSZ=15THENSZ=7 :GOTO839@ srem 213
819 IFFP>69THENFP=69 :CS="C":C=12 srem 76
829 SZ=15 srem 234
839 POKE 53281,1:PRINT"{CLR}":POKE 53281,8:CX=0:CY
=9 : GOSUB1 969 : GOTO259 srem 168
846 PRINTDNS;"{RVS}{YEL}ARE YOU SURE? "; :rem 156
856 POKE198,9 srem 282
868 GETCHS : IFCHS="N"THENPRINTDNS;"{OFF}£59";BLSs:
GOTO25G srem 134
876 IFCHS <>"Y"THEN860 srem 193
889 PRINT"YES {OFF} £59" srem 140
898 SYS49152:GOSUB13190:PRINTDNS ; BL$ :GOTO25@
srem 152
98D SL=1 srem 166
918 PRINTDNS;
:INPUT"{RVS}{YEL}FILE NAME";NAS:rem 5
926 POKE253, LEN(NAS ) srem 115
936 IFLEN (NAS )=O8THEN97@ srem 74
949 FORL=1TOLEN (NAS) srem 196
958 POKE49359+L,ASC(MID$(NA$,L,1)) srem 125
9608 NEXT srem 222

152
Colors, Characters, and Motion 4

978 SYS49269 srem 173


988 PRINTDNS;BL$;DNS$;"{6 UP}" srem 167
998 IFSL=O0THENSYS49292:GOTO1G19 srem 170
1988 sys49310 srem 193
1918 POKE 53281,1:PRINT"{CLR}£59":POKE 53281,9:G
OSUB1969:SL=9:GOTO25@ srem 32
192@ POKEV+24,21 srem 104
1938 PRINT"{CLR}{3 DOWN}":END :rem 198
1940 IFPEEK(V+24)=19 THEN POKEV+24, 21:GOTO269
srem 55
1950 POKEV+24, 19:GOTO26@ srem 125
1060 PRINT" {HOME}{RVS}{YEL}CHARACTER EDITOR{OFF}"
srem 65
1876 PRINT" {DOWN} {RVS}{YEL}F1{OFF}£53 EDIT NEW C
HAR." srem 87
1080 PRINT"{RVS}{YEL}F3{OFF}&59 NEXT CHAR. BLOCK
3 srem 227
1990 PRINT"{RVS}{YEL}F5{OFF}K59 BLOCK SIZE"
srem 150
1100 PRINT"{RVS}{YEL}F7{OFF}K59 FLIP CHARACTER S
Er? s:rem 142
1119 PRINT" {RVS}{YEL} R{OFF}&5] RESTORE FONT": rem27
1120 PRINT"{RVS}{YEL} S{OFF}&53 SAVE CHAR. SET"
srem 41
1130 PRINT"{RVS}{YEL} L{OFF}53 LOAD CHAR. SET"
srem 20
1148 PRINT"{RVS}{YEL} Q{OFF}£5]9 QUIT" :rem 5
1150 PRINT"{HOME}{19 DOWN}{RVS}"TAB(21);" ";NUS;"
{SPACE} {OFF}" :rem 29
1169 FORL=1T04:PRINTTAB(21)"{RVS}"MIDS$(NUS$,L,1);SP
C(16);" "“sNEXT ; srem 164
1170 PRINTTAB(21)"{RVS}{18 SPACES}{OFF}{2 uUP}"
srem 235
1188 PRINT" {HOME}"TAB(21); srem 116
1198 PRINT"{RVS} ";MID$(NUS$,1,SZ+1);:PRINT" {OFF}"
srem 195
1208 FORL=1T0SZ+1 srem 16
1218 PRINTTAB(21)"{RVS}"MID$(NU$,L,1);SPC(SZ+1) ;"
{OFF}" :rem 169
1228 NEXTL srem 89
1238 PRINTTAB(21)"{RVS}"; :FORL=O@TOSZ+2:PRINT" "“;:N
EXT: PRINT" {OFF }" srem 82
1248 CH=FO srem 36
1258 FORY=1T04 srem 77
1268 FORX=1TO16 srem 128
1278 POKESC+781+X+Y*4@,CH:CH=CH+1 srem 143
1288 NEXTX,Y srem 231
1299 PRINT" {HOME}{19 DOWN}{5 SPACES}{RVS}EDITING "
7;RS","CS"{OFF}":POKECC,FP+FO srem 216

153
4 Colors, Characters, and Motion

1380 IFSZ=15THENPOKECC+1,
FP+FO+1 : POKECC+4@, FP+FO+2
: POKECC+41 , FP+FO+3 srem 125
1316 X= 3 Y=0 : CX=0 : CY=9 srem 15
1320 GOSUB13908 srem 19
1330 IFSZ<>15THEN138@ srem 222
1346 X=8 : Y=0: FP=FP+1 :GOSUB1390 srem 27
1356 X=6 : Y=8 : FP=FP+1 : GOSUB1399 srem 28
1360 X=8: Y=8 : FP=FP+1 :GOSUB13994 srem 37
1376 FP=FP-3 srem 148
1386 RETURN srem 172
1398 TP=FP :TX=CX: TY=CY: IFTX> 7ANDTY <8THENTP=TP+1
: TX
=TX-8 srem 228
1496 IFTX<8ANDTY > 7THENTP=TP+2:TY=TY-8 srem 176
1416 IFTY> 7ANDTX> 7THENTP=TP+3
: TY=TY-8 : TX=TX-8
srem 231
1420 TE=8* (FO+TP)+CB:REM CHAR. POINTER srem 239
1436 POKE251,TE-INT(TE/256)*256 srem 233
1440 POKE252, INT(TE/256) srem 94
1458 TE=FNA(@)+X+40*Y:REM SCREEN LOC. srem 117
1460 POKE253, TE-INT(TE/256) *256 srem 238
1478 POKE254, INT (TE/256) srem 99
1489 SYS49299 srem 212
149 RETURN srem 174
1580 FORL=49152T049319 srem 232
1518 READD: POKEL, D: NEXT srem 197
1526 RETURN srem 168
1530 REM FONT COPIER ROUTINE srem 294
1546 DATA12@,169,51,133,1,169,1,141,13,220,169,9,1
33,251,133,253,169, 208,133 srem 189
1556 DATA252,169,8,133,254,169,0,177, 251,145, 253,2
30,251,230, 253,208, 246, 230 srem 205
1569 DATA252, 230, 254,165,252, 201,225,208, 236,169,1
29,141,13,220,169,55,133,1 srem 205
1576 DATA88, 96 srem 242
1588 REM CHAR EXPAND AND DISPLAY srem 121
1596 DATA169,9,162,9,169,128,133,259,177, 251,37, 25
9,208,4,169,32,208,2,169,42 srem 3
1606 DATA145, 253, 24,102,250, 249,8, 239, 253, 2098,2,23
@,254, 208, 229, 239,251,298,2 srem 2390
1616 DATA239, 252,165, 253, 24,195,33,133, 253,165,254
,195,0,133,254, 232,224,8, 208 srem 33
1626 DATA2@1,96 srem 17
1630 REM SAVE AND LOAD ROUTINES srem 73
1646 DATA169,128,133,157,169,1,162,1,169,1,32,186,
255,165, 253,162, 208,160,192 srem 11
1650 DATA32,189,255,96,169,8,133,251,169,8,133,252
,169,251,162,16,160,25 rem 33
1669 DATA32, 216, 255,96 srem 116
1676 DATA169,9,162,0,160,8,32,213,255,96 :srem 226

154
Colors, Characters, and Motion 4

SuperBASIC Sprite
Editor
Martin C. Kees

Adding sprites to your programs, especially to


games, can make them graphically impressive.
But designing the sprites and creating the nec-
essary DATA statements is time-consuming if
you have to do it on graph paper. “SuperBASIC
Sprite Editor” makes designing sprites easy and
fun. Using SuperBASIC, a powerful program
that adds 41 new commands to your 64's BASIC,
this sprite editor is versatile, yet simple to use.
SuperBASIC is necessary to run this program.
EL
DE ETE Te

Sprites, those graphics blocks that you can sculpt into any
shape you want, are a powerful feature on the Commodore
64. They’re very useful when you're designing games, for they
move quickly and smoothly. It’s even quite easy to create
animation using sprites. However, drawing sprite patterns on
graph paper and then calculating the DATA statements to
place in your program can be tiresome, especially when you
have several sprite patterns to create.
That’s where a sprite editor comes in handy. A good edi-
tor should make it easy and fun to design sprites. It should
allow you to change colors at will, create multicolored or sin-
gle colored sprites, show the sprites’ final shape, and create
the DATA values you'll need later. If it’s even more powerful,
it should let you move the sprites on the screen, animate
them, and store and load them to and from tape or disk.
“SuperBASIC Sprite Editor’ gives you all these functions,
and more. It’s easy to use, fast in its execution, and includes a
variety of commands.
Sprite Creation
Maybe you've already designed your own sprites. In that case,

155
4 Colors, Characters, and Motion

you can type in SuperBASIC Sprite Editor and use it immedi-


ately. If you’re just starting to learn about sprites, however, it’s
a good idea to first read another article in this book, “Sprites
Made Easy.” Included in that article is a section called “Sprite
Creation,” which will explain the rudiments of sprite design.
After reading through that, you should have a good idea of
what a sprite is, and how its DATA numbers are calculated.
You'll be relieved to know that you won’t have to calculate
those values yourself if you use SuperBASIC Sprite Editor.
The program can do that for you. All you'll have to do is type
those values into your own program.
SuperBASIC
SuperBASIC Sprite Editor is written in SuperBASIC, a power-
ful addition to the BASIC in your 64 which adds 41 new com-
mands and enhances 8 existing commands. You type it in and
save it as you would any other BASIC program. However to
use this editor, you first need to have a copy of SuperBASIC
loaded into your computer. SuperBASIC makes writing pro-
grams like Sprite Editor easier, and makes such programs
much more powerful. If you haven’t already, read the article
on SuperBASIC and type in the program before you begin
entering SuperBASIC Sprite Editor. Remember that you can't
use this program unless you've got SuperBASIC LOADed and
RUN on your 64.
As you type in SuperBASIC Sprite Editor, you'll come
across strange-looking commands, such as [DLCS or [FCOL.
Don’t worry, the program listing is correct; this is how
SuperBASIC notes its new commands. Every time you see the [
symbol in the program, just press the SHIFT and colon keys
together. This will give you the bracket symbol on the screen.
Type in the rest of the command (DLCS, for instance) as you
would any other command on the 64. Typing in SuperBASIC
Sprite Editor will take some time, but it will be worth the
effort. Once you've entered it, SAVE it to be safe. You’re now
ready to design up to 127 sprite patterns.

Functions and Command Keys


Although the program is for the most part self-explanatory,
especially if you've used or seen other sprite editors at work, a
few details may be helpful to you. Once the program is run,
it will take a few moments to set up. A menu display then

156
Colors, Characters, and Motion 4

appears, showing you all the functions and command keys


that SuperBASIC Sprite Editor uses. Briefly, they are:
f1 Selects the background color that shows on the screen.
Pressing the f1 key repeatedly will cycle through all 16 colors
available on the 64.
f2 Selects the border color of the screen. Works just as the
background color selection does.
£3 Selects the color for multicolor 0 when you're designing a
multicolor sprite. As with the previous commands, pressing
this key will cycle through all the available colors.
f4 Selects text color.
£5 Selects sprite color, either in multicolor, or normal mode.
£7 Selects multicolor 1 when the editor is in multicolor mode.
1, 2, 3 These keys set the pixel the cursor is presently on when
you're using the single-color mode. It’s like setting that bit on.
When you're using the multicolor mode, the keys work a bit
differently. The 1 key sets pixels on for multicolor 0, the 2 key
sets pixels on in the sprite color, and the 3 key turns on pixels
for multicolor 1.
SPACE The space bar turns off any pixel(s) at the present
cursor position.
Cursor Keys The normal cursor keys move the blinking cursor
around the sprite pattern so that you can set and clear indivi-
dual pixels. Remember that you have to use SHIFT/CRSR
DOWN to move up, and SHIFT/CRSR RIGHT to move left.
CLR/HOME You can clear an entire sprite display pattern by
pressing the SHIFT key along with this key. It’s a handy com-
mand if you decide to start over as you're designing a sprite
pattern.
R This key shifts the sprite pattern one pixel horizontally. You
can only move in one direction (towards the left), but it will
wrap around if you press the key several times.
V This key will shift the sprite pattern one pixel vertically. It
moves upward, but will wrap around.
L You can flip the sprite pattern laterally using this key. If the
sprite points towards the right, for instance, using this key will
make it point to the left.
F Similar to the previous key, this flips the pattern vertically.
What once pointed up will now point down.
C This key toggles the multicolor mode. Press it once, and
you're in single-color mode; press it again, and you can design
multicolored sprites.
157
4 Colors, Characters, and Motion

S You have a choice of storing an edited sprite in any of 127


blocks. Once you’ve created a sprite to your satisfaction, you
can store it by pressing this key. The program will ask for the
block to assign the sprite to, and you should enter a number
from 1 to 127. Note that this does not permanently store the
sprite pattern. If you turn your computer off, then on again,
the pattern will disappear. You need to use the O key com-
mand to store a pattern to disk or tape. However, if you’re
editing more than one pattern in a session, the S key com-
mand is quite useful.
U You can recall any sprite pattern with this key. Again, the
program will ask for the block number; respond with a num-
ber from 1 to 127. That sprite will then display on the screen.
P Using the Preview command, you can look at all the sprite
pattern blocks, one at a time, at your own leisure. Pressing the
key displays the next sprite pattern.
O Stores the sprite pattern information permanently. You'll be
asked from which block you want to save and to which block,
the filename you'd like to call that pattern, and the device
number (1 for tape, 8 for disk). The sprite pattern will then
SAVE out to tape or disk, with your selected filename.
I Loads previously created sprite pattern files from tape or
disk.
M This is perhaps the handiest command key, for as you learn
to use the sprite editor, you'll find yourself constantly wanting
to look at the list of command key options.
A Sprite animation is also handled by this editor. When you
use this key, you'll be asked to provide several parameters.
Start block asks for the sprite pattern block number you'd like
to begin the animation with. End block asks the last block to
animate. If you’ve designed three sprites to show a human fig-
ure in motion, for example, you could designate Block 1 as the
starting block, and Block 3 as the ending block. As the sprite
is animated, then, it will cycle through all three patterns.
Horizontal and vertical shift refer to the speed you want
the sprite to move in those directions. If you want the sprite to
move only horizontally, for instance, enter a value in the third
parameter, and then hit RETURN for the fourth. Placing val-
ues in both shift parameters will move the sprite diagonally on
the screen. Time delay sets the speed at which the sprite is
animated. Higher values increase the animation speed. You
can expand the sprite in the X-direction, the Y-direction, or

158
Colors, Characters, and Motion 4

both. The last two parameters ask for the starting X and Y co-
ordinates of the sprite. Refer to the Commodore 64 Pro-
grammer’s Reference Guide for the coordinates which will show
on the screen.
D Using this command key, you can see the DATA statements
you would include in your own program. The program will
ask for the block to be displayed, and the beginning line num-
ber of the DATA statement. The computer will calculate the
values you would need to create that sprite pattern. You will,
however, have to type these values into your own programs
yourself. SuperBASIC Sprite Editor does not allow you to
merge sprite DATA files with your own programs.
Drawing Sprites
The best way to discover how to use SuperBASIC Sprite Edi-
tor is to simply experiment. Use it to create as many sprites as
you need, and then use the D command key to display the
DATA statement values. This eliminates much of the work
you would have to do with paper and pencil; all that remains
for you to do is to enter those lines within your own game or
program.
When you first use this program, you'll probably find that
there are sprite patterns already in each block. Use the U com-
mand key to call a block, type 1 and RETURN. You’re in
Block 1 now. If it’s filled, use SHIFT CLR/HOME to erase the
sprite pattern. You’ve now got an empty pattern to work with.
If you switch from the sprite pattern display to the menu
(by pressing the M command key), and then back again to the
display (by pressing any key from the menu screen), you'll no-
tice that your single-colored sprite has changed colors. To get
back to the original color, just hit the C toggle key twice.
You'll find SuperBASIC Sprite Editor a valuable addition
to your programming library. It’s a utility you'll often use as
you discover the power of sprites on the 64. Moreover, it
makes creating sprites fun, instead of the chore it once was.

SuperBASIC Sprite Editor


For mistake-proof program entry, be sure to use “‘Automatic Proofreader,” Appendix J.
1 REM SUPERBASIC SPRITE EDITOR srem 164
2 REM EDIT SPRITES INTO BLOCKS @-127{18 SPACES}IN
{SPACE}BANK 1 :rem 57
3 REM FILES CREATED CAN BE LOADED TO{198 SPACES}BAN
K 1 BY LOAD"NAME",8,1 :rem 85

159
4 Colors, Characters, and Motion

5 GOTO TA+19 srem 143


19 POKE55,@:POKE56,64:CLR:CB=7*
4996 srem 11
15 DIMBP(8),FSS$(1) srem 198
20 [BANK1:[DLCS@,CB:[CB2K6:[VS1K11:PRINT"{YEL}
{CLR}PATIENCE? {HOME }"; srem 161
25 [BKG498,1,12,15:[ECGR1 srem 95
38 GOSUB 58908:SYSCA:128 srem 58
48 FORJ=8TO7 : POKECB+J , 96 : POKECB+J+224,@:
POKECB+J+2
32,8: POKECB+264+J, 255:NEXT srem 72
50 POKECB+225, 255: POKECB+226, 255: POKECB+232, 96: POK
ECB+233, 224: POKECB+234, 224 srem 86
68 FORJ=1T021:PRINT"{24 SPACES}@":NEXT zrem 207
70 PRINT" ££LLELLLELLLLLLLLLLELELLELE|" srem 53
88 GOSUB2900 srem 172
198 MC=1:[FCOL7:POKE658,128 srem 83
195 B=@:SK=12:MO=1:M1=15:TC=7
:EX=14 srem 4
206 [VS1K11:SYSUP:MC,128:SYSCA:@:GOSUB790 :rem 91
218 R=0:C=0:SC=27648:SW=-1 :GOTO229 :rem 218
215 POKESP, PEEK(SP)AND254: IFMCTHENPOKESP+1 , PEEK(SP
+1)AND254 srem 226
216 SW=-1 srem 222
220 SP=SC+40*R+C: SW=-SW: POKESP, PEEK(SP)+SW: IFMCTHE
NPOKESP+1, PEEK(SP+1)+SW srem 205
230 GET AS:IFAS=""THEN22@ srem 76
235 IFAS<>"P"THENPRINT"{HOME}{25 RIGHT}{11 SPACES}
":s:3PL=0 srem 2
249 IFAS="{ RIGHT} "THENC=C+1+MC
: IFC> 23THENC=@:GOTO2
15 srem 202
250 IFAS="{ LEFT} "THENC=C-1-MC
: IFC<@THENC=23-MC:GOT
0215 srem 10
268 IFAS="{DOWN}"THENR=R+1
: LFR> 20THENR=9:GOTO215
srem 62
270 IFAS="{UP}"THENR=R-1
: LFR<@THENR=26 : GOTO215
srem 191
288 IFAS="{HOME}"THENR=@:C=0:GOTO215 srem 5
285 IF(AS="1"ORAS="2")ANDMC=@THENAS="3" srem 1983
299 IFAS="1"ORAS="2"ORAS="3"THENPOKESP, VAL(AS$) *64+
32 : srem 158
295 IFAS="1"ORAS="2"ORAS="3"ANDMCTHENPOKESP+1
, VAL (
AS)*64+32 :rem 98
296 IF AS=" "“ANDMCTHENPOKESP,32: POKESP+1, 32:AS="
{RIGHT }":GOTO24@ srem 74
297 IF AS=" "THENPOKESP, 32:AS="{RIGHT}":GOTO249
srem 239
308 IFAS="R"ANDMCTHENPOKESP, PEEK(SP)AND254:POKESP+
1,PEEK(SP+1)AND254 srem 232
302 IFAS="R"ANDMCTHENSYSRO:SYSRO:GOTO5@@ :rem 112
385 IFAS="R"THENPOKESP, PEEK(SP)AND254:SYSRO
srem 237

160
Colors, Characters, and Motion 4

316 IFAS="V"ANDMCTHENPOKESP, PEEK(SP) AND254: POKESP+


1,PEEK(SP+1)AND254 srem 237
3r3 IFAS="V"ANDMCTHENSYSVR: GOTO599 srem 163
ejb) IFAS="V"THENPOKESP, PEEK(SP)AND254:SYSVR
srem 249
326 IFAS="{CLR}"THENSYSUP:MC,128 srem 1
336 IFAS="L"ANDMCTHENPOKESP, PEEK(SP)AND254: POKESP+
1, PEEK(SP+1)AND254 srem 229
335 IFAS="L"ANDMCTHENSYSLA: GOTO59@ :rem 128
335 IFAS="L"THENPOKESP, PEEK(SP)AND254:SYSLA
srem 214
348 IFAS="F"ANDMCTHENPOKESP, PEEK(SP) AND254: POKESP+
1, PEEK(SP+1)AND254 zrem 224
342 IFAS="F"ANDMCTHENSYSFL: GOTO59@ srem 127
345 IFAS="F"THENPOKESP, PEEK(SP)AND254:SYSFL
srem 214
356 IFAS="{F2}"THENTC=TC+1 :TC=TCAND15:[FCOLTC
srem 186
360 IFAS="{F1}"THENB=B+1 : B=BAND15:[ BKGDB srem 2
378 IFAS="{F3}"THENMO=M9+1
:MO=MGAND15 : GOTO629
srem 10
389 IFAS="{F5}"THENSK=SK+1
: SK=SKANDL5 : GOTO680
srem 144
398 IFAS="{F7}"THENM1=M1+1 :M1=Ml1AND15:GOTO69@
srem 18
480 IFAS="{F4}"THENEX=EX+1
: EX=EXAND15 : [EXTCEX
srem 229
419 IFAS="U"THEN61G zrem 37
426 IFAS="S"THEN649 :rem 39
430 IFAS="P"THENPL=PL+1
: PL=PLAND127 : GOTO679
srem 136
446 IFAS="C"THENMC=ABS (NOT (MC=1) ) sSYSUP:MC, @:C=INT
(C/2)*2:GOTO68D z:rem 182
45 IFAS="0"THENGOSUB82 zrem 164
IFAS="I"THENGOSUB838 zrem 162
476 IFAS="M"THEN258@ :rem 83
489 IFAS="A"THEN3900 :rem 68
498 IFAS="D"THEN1OGO :rem 79
586 SYSCA:%9:GOTO215 srem 141
606 IFMC=@THEN[ BKG4B, SK, SK, SK: GOSUB79@ : GOTO58@
:rem 173
695 [BKG4B,M9,SK,M1:GOSUB79@: GOTO599 srem 182
616 PRINT" {HOME}{22 DOWN}";: INPUT"BLOCK";8L
:rem 110
626 PRINT" {HOME}{22 DOWN}{15 SPACES}"; zrem 45
636 SYSUP :MC, BL: GOTO50@ :rem 281
640 PRINT" {HOME}{22 DOWN}"; : INPUT"BLOCK"; BL
srem 113
659 PRINT" {HOME}{22 DOWN}{15 SPACES}"; :rem 48

161
4 Colors, Characters, and Motion

660 SYSCA:BL:GOTO215 ; srem 242


670 PRINT" {HOME}{26 RIGHT}BLOCK";PL;"{LEFT}
{2 SPACES}";:SYSUP:MC, PL:GOTO56@ srem 132
796 [DSPRO,8,1,1,278,68,MC,SK,M9,M1 srem 161
7@5 [DSPR1,9,9,1,284,115,MC,SK,M@,M1l zrem 220
710 [DSPR2,9,1,8,270,175,MC,SK,M9,M1 :rem 218
715 [DSPR3,0,9,8,284,218,MC,SK,MZ},M1 zrem 218
720 RETURN srem 121
800 PRINT" {HOME}{22 DOWN}";:INPUT"SAVE FROM BLOCK"
7 BL srem 210
885 PRINT" {HOME}{22 DOWN}{35 SPACES}"; srem 5
810 PRINT" {HOME}{22 DOWN}";:INPUT"SAVE TO BLOCK";:B
E srem 59
826 PRINT" {HOME}{22 DOWN}{35 SPACES}"; :rem 47
825 IFBE<GORBL<OTHENRETURN srem 293
830 PRINT" {HOME}{22 DOWN}";:INPUT"FILE NAME ";FSS(
1) s:rem 249
835 PRINT" {HOME}{22 DOWN}{35 SPACES}"; srem 53
840 PRINT" {HOME}{22 DOWN}";:INPUT."DEVICE NUMBER";B
P(B) srem 6
841 PRINT" {HOME}{22 DOWN}{35 SPACES}"; srem 58
845 IFAS="I"THENIGOD i srem 39
850 FORJ=43T046 :BP(J-42 )=PEEK(J) :NEXT trem 239
860 SB=4* 4996 :BL=64*BL+SB: BE=64* (BE+1)+SB:BP(5)=BL
AND255 :BP(6)=INT(BL/256) srem 192
865 BP(7)=BEAND255:BP(8)=INT( BE/256) srem 17
870 POKE43,BP(5):POKE44,BP(6):POKE45,BP(7):POKE46,
BP(8) srem 193
880 SAVEFSS(1),BP(@),1:POKE43,BP(1):POKE44,BP(2):P
OKE45,BP(3):POKE46,BP(4) srem 246
890 RETURN srem 129
98D TA=499:LOADFSS(1),BP(@),1 srem 61
918 END srem 113
999 END srem 130
1989 [VS1K9 srem 122
1985 INPUT"{CLR}DATA FOR BLOCK";BL srem 98
110 INPUT"START LINE NUMBER";X srem 168
1195 Y=4* 4996+64*BL:BL=0:NL=14:PRINT"{CLR}"srem 36
1116 FORJ=9T03:[KSPRJ:NEXT srem 207
1115 PRINTX"DATA"; : FORJ=1TONL:VS=STRS ( PEEK(Y) )
srem 138
1126 PRINTRIGHTS(VS,LEN(VS$)=-1)",
"3; sY=Y+1 :NEXT:X=X+
10 :rem 78
1139 PRINT" {LEFT} ":BL=BL+1 :rem 34
1140 IFBL<5THEN1115 srem 75
1158 IFBL=5THENNL=7:GOTO1115 srem 286
PUS5 GETAS : IFAS=""THEN1155 srem 187
TVS7 FORJ=@TO3:[ESPRJ:NEXT srem 212
1160 [VS1K11:GOTO50@ srem 178

162
Colors, Characters, and Motion 4

[VS1K1@:[FCOL12:[BKG4@0,1,12,11:PRINT"{CLR}
{RVS}SPRITE{ SHIFT-SPACE }EDITOR{ SHIFT-SPACE }ME
NU{OFF} " srem 91
PRINT" FKEJ BACKGROUND COLOR " zrem 110
PRINT" FKRJ BORDER COLOR " srem 73
PRINT" FKW3 SPRITE MULTI 9" srem 160
PRINT" FKHJ TEXT COLOR " :rem 212
PRINT" FKJI3J SPRITE COLOR" srem 194
PRINT" FRY} SPRITE MULTI 1" zrem 168
PRINT" KE} £RI KwI{2 SPACES}SETS PIXEL
{SPACE }ON" srem 13
PRINT" SPACE CLEARS PIXEL" srem 194
PRINT" CURSOR{SHIFT-SPACE}KEYS MOVE EDIT CURS
OR" srem 148
PRINT" CLR/HOME CLEARS DISPLAY" :rem 41
PRINT" R HORIZONTAL SHIFT" srem 245
PRINT" V VERTICAL SHIFT" srem 74
PRINT" L LATERAL FLIP" zrem 144
PRINT" F VERTICAL FLIP" srem 224
PRINT" C SINGLE/MULTICOLOR TOGGLE" srem 26
PRINT" S STORE EDIT SPRITE" zrem 243
PRINT" U RECALL STORED SPRITE" srem 199
PRINT" P PREVIEW STORED SPRITES" srem 133
PRINT" O STORE SPRITES IN FILE" :rem 214
PRINT" I LOAD SPRITE FILE" srem 122
PRINT" M DISPLAY MENU" :rem 179
PRINT" A ANIMATE MODE" srem 129
PRINT" D DATA LIST" srem 187
GETAS : IFAS=""THEN219@ srem 187
RETURN zrem 164
[VS1K1@:[FCOL12:[BKG4@,11,11,15 :rem 63
GETAS : IFAS=""THEN2519 srem 179
[VS1K11:[BKG4B,M@,SK,Ml:[FCOLTC:
GOTO50G
srem 255
FORJ=@T03:[KSPRJ :NEXT srem 2907
ZZ=53265 sWV=128:[VS1K9:
PRINT" {CLR}";:INPUT"ST
ART BLOCK":;BL srem 22
INPUT"END BLOCK":BE srem 168
INPUT"HORIZ SHIFT";HS zrem 129
INPUT"VERTICAL SHIFT";VS srem 85
INPUT"TIME DELAY"; TD :rem 11
INPUT"X EXPAND @/1";XE :rem 27
INPUT"Y EXPAND @/1";YE srem 39
INPUT"X POSITION";XP :rem 77
INPUT"Y POSITION"; YP :rem 8
PRINT" {CLR}" :rem 47
FORJ=0T03:{[KSPRJ:NEXT :rem 220
FORJ=BLTOBE:WAITZZ,WV:[DSPRO,J,XE,YE,XP,YP,MC
»SK,MO,M1 srem 119

163
4 Colors, Characters, and Motion

3196 XP=XP+HS : YP=YP+VS srem 189


3110 IFXP>348THENXP=0 srem 29
3126 IFXP<OTHENXP=349 srem 20
3136 IFYP<Q9THENYP=255 srem 28
3146 IFYP>255THENYP=@ srem 31
3145 FORGX=1TOTD:NEXT srem 117
3159 NEXT srem 8
3166 GETAS : ILFAS=""THEN3990 srem 185
3165 FORJ=90TO3: [ESPRJ:NEXT: [DSPRO,8,1,1,270,60,MC,
SK,M9,M1 rem 25
31708 ([VS1K11:[FCOLTC:GOTO5@@ srem 5
5 O96 Y=32768:RESTORE 5892@0:CA=Y
: RO=CA+97 : UP=CA+16@:
VR=CA+31@:LA=CA+384:FL=33221 srem 47
5885 READV: LFV<@THENRETURN srem 214
5918 POKEY , V: Y=Y+1 :GOTO590@5 srem 146
5928 DATA32,0,192,24,169,9,162,6,6,
20,42, 202,208, 2
58,24 srem 168
5830 DATA195,64,133, 21,173,136,2,133,79,169,9,133,
Lo pls oneoS :rem 185
5840 DATA133,255,160,9,162,4,24,177,78,41,128, 244,
1,56,38 srem 35
5650 DATA2, 200, 24,177,78,41,64, 249,1,56,38,2,200,2
G2,288 srem 226
5960 DATA231,132, 254,164, 255,165,2,145, 20, 230, 255,
164, 254,192,24 srem 126
5878 DATA208, 213, 24,165,78,105,49,133,78,144,2,2308
779,238,253 srem 238
5980 DATA165, 253,201, 21, 298,192, 96,173,136,2,133,7
9,133,21,169 srem 49
58908 DATA1,133,29,169,9,133, 78,133, 255,162,21,16@,
@,177,78 srem 84
5180 DATA133,2,177,29,145, 78, 209,192, 23,208, 247,16
Pye i: Loh 3 srem 188
5118 DATA24,165,20,195,49,133,20,144,2, 239, 21,165,
Zils olS. s:rem 105
51208 DATA165, 20,133, 78,198, 78, 202, 208, 213, 96, 32,90,
192,165,290 srem 193
5136 DATA133,2,32,9,192,24,169,9,162,6,6,20,42, 202
, 298 z:rem 118
5146 DATA25@, 24,195,64,133,21,173,136,2,133,79,169
porliss, Lo srem 135
5156 DATA133, 254,133, 251,133, 252,169,9,133, 253,164
pie aya ae leylay BWPA4Snipe 4) srem 168
5160 DATA251,133,80,165,2,298,25,169,8,6,80,42,179
, 189,48 srem 46
5176 DATA129,164,252,145,78, 239, 252, 239, 253,165, 25
3,201,8, 298, 233 srem 184
5180 DATA249,30,169,9,6,88,42,6,89,42,170,189,58,1
29,164 srem 247

164
Colors, Characters, and Motion 4

51968 DATA252,145,78, 200,145, 78, 299,132,252, 238,253


,165,253,201,4 srem 123
52608 DATA2@8, 226, 239, 254,165, 254, 201,3, 208,177,169
70,133,252, 133 erem 122
5219 DATA254, 24,165, 78,195,40,133,78,144,2,239,79,
165,251,261 srem 237
5226 DATA63, 208,154, 96,32, 224, 32, 96,169, 224,173,13
6; 2,33, 21 srem 184
5236 DATA133,79,169,9,133, 29,169,40,133,78,169,9,1
77,280,153 srem 135
5246 DATA®, 144, 200,192, 24, 208, 246,162, 20,169,9,177
,78,145, 20 srem 172
5256 DATA200,192, 24, 208, 247,165, 79,133, 21,165,78,1
33,280,24,195 rem 31
5260 DATA4@,133,78,144,2, 239,79, 202, 208,225,169,9,
185,909,144 srem 126
5270 DATA145, 20, 200,192, 24, 208, 246, 96,9,173,136,2,
US See ZL Oo srem 182
5280 DATA®, 133, 20,133,2,169,9,133, 251,169, 23,133,2
52,164,251 srem 170
52908 DATA177, 20,133, 253,164, 252,177,298, 72,165,253,
145,20,184,164 srem 132
5306 DATA251,145, 20,230, 251,198, 252,165, 251,201,12
,208,226,24,165 srem 166
5318 DATA2@,105,40,133,20,144,2, 230, 21,239,2,165,2
,201,21 rem 238
5326 DATA268,199,96,169,9,168,133,251,169,9,133,2,
133,280,173 srem 195
5330 DATA136,2,133,21,24,195,3,133, 79,169, 32,133,7
8,24,165 srem 86
5340 DATA251,1901,290,133,20,144,2,239,21,24,165,251
TLOLy (Syts3 s:rem 200
5350 DATA78,144,2,239,79,177, 20,72,177,78,145,28,1
@4,145,78 srem 169
5360 DATA24,165,20,195,49,133,20,144,2,230,21,56,1
65, 78,230 srem 129
5376 DATA4@,133,78,176,2,198, 79, 239,2,165,2, 201,10
, 208,216 srem 89
5388 DATA23@0, 251,165,251,
201, 24, 208,166, 96,-1
erem 212

165
4 Colors, Characters, and Motion

Sprites Made Easy


Paul F. Schatz

If you've always wanted to create sprites on


your Commodore 64, but have been put off by
all the complicated POKEs, this article is your
answer. It lets you modify BASIC to add three
new sprite commands to make the job much eas-
ier. An accompanying side article also explains
the rudiments of sprite design.
a RN BEL RE EET PIE OLE ea aS aes

One of the most powerful features of the Commodore 64 is its


sprite animation ability. Sprites, also called MOBs (for Mov-
able Object Blocks), are in effect graphics blocks which you
can sculpt into any shape and move about the screen. Since
they move independently of the screen image and move more
smoothly than custom characters, they are often used when
creating games or demonstrating animation.
Sprites are accessed from BASIC by a series of POKEs.
The Video Interface Controller (VIC-II chip) holds several reg-
isters which you manipulate to create and move sprites on
your screen. Manipulating these VIC-II registers can get com-
plicated, however, especially for the beginning programmer,
because the routines require numerous POKEs for each sprite.
Turning on and off various sprite functions can become
confusing. Crossing the invisible seam on the 64’s screen is
especially cumbersome.
A solution is to add some new commands to BASIC to
control the sprites. This article provides a method for adding
three new commands to BASIC which will allow you to con-
trol sprites more easily.
If you’re unfamiliar with the methods used to design and
create sprites on the 64, refer to the accompanying section,
“Sprite Creation,”” before you continue.
Modifying BASIC
The Commodore 64 is a flexible computer and it’s possible to
use the Random Access Memory (RAM) under the BASIC

166
Colors, Characters, and Motion 4

Read Only Memory (ROM) for a modified BASIC. You make a


duplicate of BASIC, place it in RAM, and then modify “RAM
BASIC” to suit your needs. The technique was outlined by Jim
Butterfield in his article “Commodore 64 Architecture,’”” which
appeared in the January 1983 issue of COMPUTE! magazine. It
was also used in my article “Commodore 64 Hi-Res Graphics
Made Simple,” which appeared in the August 1983 issue of
COMPUTE!’s Gazette. Refer to these two articles for other uses
of this same process.
“Sprite BASIC,” which I'll call my BASIC modification
program, replaces three old keywords, LET, WAIT, and
VERIFY, with three new keywords, OFF, MOVE, and SPRITE.
Notice that the new keywords are the same length as the ones
they replace. A new keyword has to be mapped exactly into
the old keyword’s spot in the keyword lookup table. Program
1 is the BASIC program which moves the BASIC ROM code to
RAM, modifies it, and loads the new machine language
routines into a safe area of memory. Machine language is an
excellent method of programming sprite movements, since it is
both very fast and very efficient. (Sprite BASIC extends from
$C000 to $COE2.)
Sprite BASIC is loaded into the Commodore 64 by typing
in and running Program 1. When typing it in, be as accurate
as possible, since an incorrect number may cause the computer
to crash when you type RUN. To clear this, you’d have to
switch it off and on again, erasing anything you’d already en-
tered. To be safe, SAVE the program before running it for the
first time, and use the ‘“Automatic Proofreader” in Appendix J.
It will take the computer a minute or so to run the pro-
gram. Be patient. When the READY prompt appears again,
type in:
POKE 1,54
This switches on Sprite BASIC. If you want to return to
Commodore (your original) BASIC, simply type in:
PORE 130
Since you can switch from the old BASIC to Sprite BASIC
within programs with these POKEs, your program can contain
both the old and new BASIC command words.
Sprite BASIC is also switched off by pressing the RUN/
STOP and RESTORE keys simultaneously. Because the new
BASIC tokenizes the new keywords, make sure you have
4 Colors, Characters, and Motion

Sprite BASIC turned on as you enter your own program. The


old keywords that were replaced cannot be used unless the
old BASIC is switched back on.
The New Commands
After you’ve entered and switched on Sprite BASIC, you'll
have three new commands available while you program
sprites.
OFF <number>
This statement disables (turns off) the sprite designated by
the number. Sprites are numbered from 0 to 7, so a number 8
or greater will give an ILLEGAL QUANTITY ERROR.
MOVE <number>, <number>, <number>
This new keyword enables (turns on) a sprite and places
it at the desired location on the screen. The first number is the
sprite’s number (0-7). The next two numbers are the X and Y
coordinates, respectively, of the sprite’s upper left corner. Be-
cause the sprite display area is larger than the screen area, the
X coordinate must be 24 or greater, while the Y coordinate
must be 50 or greater for the sprite to be fully visible. Allowed
values for the X coordinate range from 0 to 511, although
those greater than 344 are totally off the screen. Y values can
range from 0 to 255, but numbers greater than 250 are com-
pletely off the screen. Any number greater than the accepted
range will cause an ILLEGAL QUANTITY ERROR message.
SPRITE <number>, <number>, <number>, <number>
This new statement defines a sprite. The first number is
the number of the sprite being defined. The second number is
the 64-byte data block where the values used to actually draw
the sprite are stored. This number can have values from 0 to
255. For example, sprite data stored in memory locations 832
to 895 (cassette buffer) is block 13 (832/64=13). The third
number in this command is the color of the sprite. The color
codes are:
0 Black 4 Purple 8 Orange 12 Med Gray
1 White 5 Green 9 Brown 13 Light Green
2Red 6Blue 10Light Red 14 Light Blue
3 Cyan /7 Yellow 11 Dark Gray 15 Light Gray
The fourth number determines the size of the sprite. If the
number is 0, the sprite is normal size. A 1 entered here doubles
168
Colors, Characters, and Motion 4

the sprite’s width. If the number is 2, the sprite is doubled


in height. Entering a 3 doubles both the width and the
height.
Some Sample Programs
You’re now ready to enter and run a couple of simple pro-
grams using Sprite BASIC. Both demonstrate how this new
BASIC can be used for easy animation. The first program ani-
mates a sprite which looks like a butterfly by moving it as it
changes its shape. Actually two sprites are used. The program
displays first one, then the other, to simulate movement. To
see this, LOAD and RUN Sprite BASIC, type NEW, switch on
the new BASIC by typing POKE 1,54, and enter Program 2.
Before you run it, SAVE it on tape or disk.
A peculiarity of the Commodore 64 concerning sprites is
that there are actually two separate sections of the screen for
the X, or horizontal, coordinates. An invisible seam runs all
the way down the screen immediately after the 255th X co-
ordinate. Normally, you would have to POKE a value into an
additional register each time a sprite moved across this seam.
Notice, however, that you don’t have to do this when you use
Sprite BASIC. After you enter Program 2 and type RUN, it
moves the sprite smoothly across the seam from left to right.
This is one of the advantages of using something like Sprite
BASIC, for the computer does as much as possible for you.
To see a joystick-driven sprite, type in NEW and enter
Program 3. Make sure that Sprite BASIC is loaded and en-
abled before you run Program 3. Plug a joystick into port 2
and you'll be able to maneuver the tie fighter-shaped sprite
across the screen.
Just Starting
Using Sprite BASIC, you can create and move your own
sprites with much more ease than if you had to POKE each
register on your own. All you really have to do is design a
sprite, calculate the DATA numbers, which allow the 64 to
display it properly, and the new BASIC does all the rest.
This lets you concentrate on creating unique sprites, or in
using them to your program’s advantage. A game, for exam-
ple, would be much easier to program, with sprites, using this
new programming tool. Try some of your own sprites, perhaps
simply replacing the DATA numbers in the sample programs
with your own sprite information.
169
4 Colors, Characters, and Motion

Sprite Creation
Gregg Keizer

Drawing Sprites
Creating a sprite is much like creating a custom character—it
must be drawn. The 64 does not do this for you; you have to
place the data information within a program for the computer
to look at, and then draw the sprite on the screen.
A sprite is much larger than a custom character, consisting
of a graphics block 24 pixels wide by 21 pixels high. A custom
character is only an 8-by-8 pixel block. The information to
draw a sprite uses more memory than a custom character be-
cause of its size, so fewer sprites can be displayed at a time.
Eight sprites are available to you on the Commodore 64.
Just as when you create custom characters, you can use
graph paper to design your sprites. Take a piece of graph pa-
per and outline an area 24 blocks wide by 21 high. Simply fill
in the blocks in the pattern to create a sprite. Figure 1 shows a
sample sprite drawn in this way.

Figure 1. Graphing a Sprite


Column
0123 4 56 78 910111213
1415 16 17 18 19 20 21 22 23

0
sf alGale
2
ae
rs fied
5 Oea
Ch A
7 ee
3 eSa aa)
ie Es
1 | a ES
3b Fa Lal
re
613 Res
2S elfn ala]
15. (a).|3
16 | | | |
17 Fie}
Agnes ay
WC es

170
Colors, Characters, and Motion 4

The blocks that are filled in will be on, or displayed in the


color you later select for your sprite, while the empty blocks
will be off, or shown in the screen’s background color.
Drawing sprites is not enough for the computer, however.
It cannot just look at something and display it on the screen.
Instead, it needs numbers it can refer to which fell it what to
create. You have to do this.
Bit Values
To come up with the numbers the 64 needs to draw your
sprites, you'll have to do some addition. As when creating
custom characters, to show some of a sprite’s pixels on and
others off, bits have to be set. It’s not as hard as it sounds. Fig-
ure 2 shows you how it’s done.

Figure 2. Sprite Worksheet


BlockA Block B | Block C
7 6 5 42° O20 FEOF DE ae Oe 2 10 VAG Seas
2, 1
Block
Totals
B. Cc

This is similar to the graph paper you used to design your


sprite, only bit values have been assigned to each pixel. As in
Figure 1, there are 24 columns and 21 rows. Each box repre-
sents one pixel in your sprite.
The similarity with custom characters ends here. Instead

171
4 Colors, Characters, and Motion

of only one eight-bit block in each row, a sprite has three.


These have been named Block A, Block B, and Block C in Fig-
ure 2. When the 64 looks at the numbers to create a sprite, it
starts with the eight-bit block in the upper left corner, moves
across the first row, and then jumps down to the left-most
block on the next row. The last number it reads to create a
sprite represents the bottom right corner of Block C.
Calculating the bit values to show a sprite is only a matter
of adding together the values of the bits you want on. Figure 3
shows the same sample sprite, but with its bit values
computed.

Figure 3. Sprite Computation


BlockA Block B | Block C
7 6054-32)
27:0 7654321076543
240) piock
Totals

BitBit#
Values

a aE
+ ttt
cae scat oeameee

The first row has none of its pixels on, so the bit value for
all three bytes is 0. Row 2, however, has six bits in the Block B
byte turned on. These bits, numbers 1 through 6, have a total
bit value of 126 (2+4+8+16+32-+ 64). The other two bytes,
represented by Blocks A and C, are 0, since neither has any
bits on.
Each byte is calculated in this same way. Remember that
each row of a sprite consists of three bytes, and that each

172
Colors, Characters, and Motion 4

must be figured separately. Figure 2 makes this simple, for


each byte has its own total column at the far right.
When you've finished computing the bit values for a
sprite, you should have 63 numbers. These are the numbers
the Commodore 64 will look at to display your sprite. Nor-
mally, you would insert them in a program in several DATA
statements and have the computer READ from this table. For
instance, using the numbers for the sample sprite, the DATA
statements would look like this:
DATA 0,0,0,0,126,0,0,255,0
DATA 1,255,128,3,255,192,3,255,192
DATA ’3,153,19273,153,192,3,153,192
DATA 3,255,192,1,255,128,0,255,0
DATA 0,255,0,0,66,0,0,66,0
DATA 0,66,0,0,231,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,-1
(The -1 is used to fill up the 64-byte block each sprite occu-
pies in memory. Without that additional number, you may get
an error message.)
Every sprite you design is created like this. But once you
have it designed, you have to POKE other values into the 64
to make it appear.
Normally, you would have to POKE values into the com-
puter to do such things as enable the sprite (turn it on), locate
the sprite’s DATA in an available memory address, set its
color, and finally, place it on the screen. This is where sprite
creation becomes tedious. By modifying BASIC, you can get
the Commodore 64 to do much of this for you. ‘Sprites Made
Easy” gives a detailed description on how to make sprite
control easier.

Program 1. Sprite BASIC


For mistake-proof program entry, be sure to use “Automatic Proofreader,” Appendix J.
19 A=8: REM INITIALIZE CHECKSUM srem 114
2@ REM MOVE BASIC ROM TO RAM srem 88
3Q@ FORI=499690T049151:POKEI,PEEK(I):NEXTI :rem 217
48 REM CHANGE LET TO OFF srem 81
5@ FORI=41159T041152:READN: POKEI ,N:A=A+N:NEXTI
srem 113
69 READL,H: POKE49988, L: POKE49989,H:A=A+L+H:rem 254
70 DATA 795790; 198). 2, 292 srem 129

173
4 Colors, Characters, and Motion

8@ REM CHANGE WAIT TO MOVE srem 1


98 FOR 1=41189T041192:READN:
POKEIL ,N:A=A+N:NEXTI
srem 133
190 READL, H:POKE419@8, L: POKE41909,H:A=A+L+H srem 9
PLOEDATAI S200 9 8 (OO uk OW nro, cb Oi? srem 123
126 REM CHANGE VERIFY TO SPRITE srem 198
13@ FORI=41201T041206:READN:
POKEI ,N:A=A+N:NEXTI
srem 157
148 READL,H: POKE41914, L: POKE419015,H:A=A+L+H :rem 7
15@ DATA 83,80,82,73,84,197,96,192 srem 163
160 REM READ IN NEW ROUTINES srem 145
170 FORI=49152T049384:READN:
POKEI ,N:A=A+N:NEXTI
s:rem 189
180 IFA<>3078@THENPRINT"ERROR IN DATA STATEMENTS"
srem 48
198 END srem 113
208 DATA 88, 79, 83, 32,158,183,224, 8,176, 31,189
7,219,192, 45, 21,208,141 srem 237
210 DATA 21,208, 96, 32,158,183,224, 16,176, 14,13
{iN Phi ASIA PAS Shr STE SINR PASI srem 222
226" DATALS3;, 165, 24,201, 2, 144,53, 76, ~-/2,178, 138,
TO ploGin 2 koa LOL oe srem 79
230 DATA189,219,192, 45, 16,298,141, 16,288, 78, 2
1,244, 97189 72217192) 13 srem 28
240 DATA 16,208,141, 16,298,138, 18,1798,194,157, 1
, 208,165, 26,157, 8,208 srem 255
256° DATAL66y 62,189, 2117192, 13.,. 21,2087, 141, 21,298
, 96, 32,158,183,224, 8 srem 228
260 DATA176,193,134, 2,169,248,133,251,173, 24,268
4, 240 OF e338), 2D 2 srem 79
278 DATA173, 9,221, 73,255, 74,102,252, 74,162,252
Pee yee ayes asWA ARG ye an isi) srem 65
280 DATAI3S, O41 2el4op 2b S22, cose 46 32,227,192
,224, 16,176,146,138,153 s:rem 179
290 DATA 39,2808,185,219,192, 72, 45, 29,208,141, 2
9,208,184, 45, 23,208,141 srem 86
300" DATA’ 23),208), 82,253,074, 32,227,192,224, 4,176
7223, 134, 25 1D, 2,144 s:rem 160
318 DATA 9,185,211,192, 13, 29,208,141, 29,208, 70
, 2,144,..9,185,211,192 s:rem 178
S20] DATA Ss pi2on20e, Lol, 237200, 96, 1,2 4. So, 2
6, 32, 64,128, 254,253 srem 171
338 DATA251,247,239,223,191,127 srem 43
348 DATA 32,158,183,164,2,96 srem 194

174
Colors, Characters, and Motion 4

Program 2. Butterfly
10 READ SB: IF SB<@ THEN 189: REM READ SPRITE DATA
srem 297
LO= SB*64: FOR I= @ TO 62 srem 69
READ SD: POKE LO+I,SD: NEXT I srem 19
GOTO 10 srem 254
DATA 13: REM SPRITE DATA BLOCK 13 srem 193
DATAY W4yer3 25. Ones > ol 28 Oe OS. 2 780, 6 OS), So
7 @ srem 235
DABAML Zip ee Wiig Colm eodpm eu One OS ee ideals
{SPACE}63, 254, 9 :rem 111
80 DATA GS ieee D 2h Sek leO Ge Oise Dea Ono oven 2
4, @ srem 31
96 DATA S15,0 O25 Ol ele Oly Oink OCsO uO Oly Og ae,
srem 230
1986 DATA, 0i,,-0i,- 9, On. Oe GO, Or, OO, Or Or, CO, Oe
@ srem 227
118 DATA 14: REM SPRITE DATA BLOCK 14 srem 249
129 DATA 8, 8, 8, BO, BO, BO, OB, OB, BD, B, 58, DWsrem 6
130 Dy Wy ayajar bed. alate. waley/, key 5 esi
aikenba yale sasisy,
825571 230 srem 48
146 DATA 255 pnecD
4) lO shee Di paEL D2 ae pO DE Oy ae
Te PAG MG) srem 41
156 DATA=63),,0224 7,5 Opn ids, LOZ pO O25Oign Og ale, Oi
@ srem 189
168 DATA 9, 9, 8, ©, BO, GB, GB, BG, GG GD, OG, OG, BG, DB,
4) srem 233
176 DATA -l: REM END OF DATA srem 180
189 PRINT" {CLR}": POKE 53281,1: REM WHITE SCREEN
srem 37
198 X=@: Y=@: REM STARTING POSITION srem 94
206 POKE 1,54: REM TURN ON SPRITE BASIC srem 196
216 VERIFY @, 13, 11, @: REM DEFINE SPRITE:rem 178
220 WAIT ©, X, Ys: REM PUT SPRITE 8 ON SCREEN
s:rem 125
236 FOR T = 9 TO 19@: NEXT T: REM DELAY LOOP:rem 5
246 VERIFY @, 14, 11, @: REM REDEFINE SPRITE
:rem 77
256 FOR T = @ TO 1900: NEXT T: REM DELAY LOOP:rem 7
260 X=X+3: Y=Y+ 3*(INT(RND(1)*3)-1) srem 66
276 IF X>345 THEN X=@ srem 78
286 IF (Y<39) OR (Y>250) THEN Y=159 srem 237
296 GOTO 210 srem 1983

175
4 Colors, Characters, and Motion

Program 3. Tie Fighter


1 READ SB: IF SB<@ THEN 120: REM READ SPRITE DATA
srem 201
26 LO= SB*64: FOR I= 8 TO 62 srem 69
30 READ SD: POKE LO+I, SD: NEXT I srem 19
46 GOTO 19 srem 254
58 DATA 13: REM SPRITE DATA BLOCK 13 srem 193
66 DATA 192, 0, 3, 192, 8, 3, 192, 49, 3,
192, 171
ree srem 253
78 DATA 194, 171, 195, 194, 155, 195, 194, 98, 195
, 194, 98, 195 srem 95
8B DATA, 194, 196, 195, 250, 270, 230. 254,270. e2o
9,254, 178; 255 rem 163
968 DATA 194, 171, 195, 194, 175, 195, 195, 191, 19
Se Loge yo srem 202
186 DATA ¥95,7°255, 195; 192," 255, 37 192, 00,735 Te
92, 9, 3 srem 8
110 DATA 192, 8, 3, -l: REM END
DATA OF SPRITE
srem 8
126 X= 184: Y= 15@: REM POSITION IN MIDDLE OF SCRE
EN srem 89
13 PRINT"{CLR}":POKE 53281,3: POKE53280,3: REM CY
AN SCREEN AND BORDER srem 39
146 POKE 53276,1: REM MULTICOLOR SPRITE @ s:rem 87
159 POKE 53285,15: POKE 53286,1l: REM AUX COLORS
srem 59
1668 POKE1,54: REM TURN ON SPRITE BASIC srem 291
176 VERIFY @, 13, 12, 1: REM DEFINE SPRITE @
srem 233
186 WAIT @, X, Y: REM POSITION SPRITE srem 113
198 GOSUB 300: IF J=15 THEN 190 srem 44
2808 GOTO 18@:REM MOVE SPRITE srem 144
38D REM READ JOYSTICK srem 3
318 J= PEEK(56329) AND 15: REM PORT 2 srem 95
320 IF (J AND 8)=@8 THEN X=X+l: REM MOVE RIGHT
srem 130
338 IF (J AND 4)=@ THEN X=X-1l: REM MOVE LEFT
srem 46
346 IF (J AND 2)=@ THEN Y=Y+l: REM MOVE UP:rem 167
358 IF (J AND 1)=@ THEN Y=Y-1: REM MOVE DOWN
srem 60
3668 IF Y<5@ THEN Y=5@: REM STAY IN RANGE srem 175
3708 IF Y>229 THEN Y=229 srem 191
380 IF X<24 THEN X=24 srem 78
398 IF X>295 THEN X=295 :rem 197
499 RETURN srem 116

176
5

Inside Your 64
Inside Your 64 5

Using the Function


Keys:
A BASIC Tutorial
Charles Brannon

Perhaps you've pressed those function keys to


the right of the keyboard and were dismayed to
find they did nothing. Don’t worry, they work
fine; they just need a program to “come alive.”
With this tutorial, you'll find it’s easy to write
your own programs using function keys.
LEE
LFEPA
LE EE NE TT

One day, somebody had a good idea. There were dozens of


programs: word processors, spreadsheets, data bases, and they
all required you to press certain keys to perform the various
functions. For example, a word processor would save your text
to disk with CTRL-S (meaning to hold down a special Con-
TRoL key while you press S). The arrow keys that move the
cursor were among the first “function keys”; they replaced
various CTRL-keys that did the same thing.
Mystery Keys
So someone added a number of mysterious keys to a com-
puter keyboard. Dedicated (used only for one task) word
processors have special labelled keys to cut, paste, copy, edit,
etc. Since computers are general-purpose, the keys had to be
unlabelled so every application could do something different
with the keys. The idea caught on. These days, function keys
are the rage. You can hardly buy a computer without them.
Special, set-aside, unlabelled function keys are defined by
whatever program is currently running. Frequently, pro-
grammers assign powerful functions to the keys. It’s a gim-
mick of sorts; it would be just as easy to assign the function to
the normally unused CTRL keys (and link them in an easy-to-

179
5 Inside Your 64

remember fashion, such as CTRL-Q for Quit, CTRL-E to Erase,


etc.). There is undeniable convenience, however, in having
your own special “programmable” keys.
The Sad Truth
Fundamentally, the function keys are no different from any
other key on the keyboard, so it is as unrealistic to assume
they'll always do something as it is to think that pressing the
fire button on the joystick will always fire a shot. If you’ve
used the joystick, you know that it tells you only which way
the player is pushing (north, south, east, west, or diagonal)
and whether the fire button is pressed or not. Period. You
have to write (or buy) special programs that move a figure
based on the position of the joystick.
The function keys on the Commodore 64 are the same.
When you run commercial software, the keys do everything
from changing border colors to shifting the screen, selecting
difficulty, or restarting a game. But the real power of the func-
tion keys comes when you understand how to use them in
your own programs.
GETting to the Point
The primary BASIC command used to read the keyboard is
GET. When you type GET followed by a variable name (GET
A$ or GET XZ), the computer looks at the keyboard and puts
whatever key is being pressed into the variable. But it looks
only once, and if you didn’t press a key, the computer merrily
goes on to something else. GET will not wait for a key to be
pressed. This is a good feature; but if you do want to wait for
a key, you would do something like:
18 GET A$
26 IF AS="" THEN 16
or

19 GET N
29 IF N=0 THEN 19

The phrase: IF A$=“’ means: if A-string equals the null


string (nothing is between the quotes; it’s just two quotes in a
row), then go back to line 10. So as long as no key is pressed,
line 20 will keep sending the computer back to line 10 to
check again. The second example is waiting for you to press a
number key from 1-9 (it uses 0 to mean no key pressed, so

180
Inside Your 64 5

pressing 0 won’t make it stop waiting). This type of GET com-


mand used with a numeric variable (instead of a string) is
dangerous, though. If the user presses any other key, the pro-
gram will crash (stop running and return to BASIC) with a
?2SYNTAX ERROR message. It’s just as easy to convert a string
into a number with the VAL command, so the second state-
ment could be rephrased:
18 GET N$
26 IF NS$="" THEN 19
38 N=VAL(NS$)

It’s easy to improve; if you wanted to accept only num-


bers above, you could change line 20 to:
26 IF N$<"@" OR N$>"9" THEN 10
which means: if N-string has an ASCII value (a code used in
your computer to order characters—A, which has an ASCII
value of 65 is “less than’”’ Z, which has an ASCII code of 90)
less than that of ‘0’ or greater than that of the character “9”
then loop back to line 10.
Incidentally, the ASCII code for the null string (quote-
quote) is zero, which is less than 48, the code for “0”, so the
loop will also wait for a key. If you’re curious about ASCII,
check out the BASIC commands ASC and CHR$ in your man-
ual. You'll also find the ASCII codes and their character
equivalents in Appendix F at the back of this book.
Strictly Logical?
So if you just want to accept a yes or no answer (Y for Yes, N
for No), then this will work just fine:
16 GET AS:IF AS<>"Y" AND AS<>"N" THEN 19
Computer logic with IF-THEN, AND, OR, and NOT can get a
bit tricky, so let me explain this line. The computer will GET a
key and put it into A$. Remember that the user may not have
pressed the key yet, so A$ could be any key, or it could be the
null string (’’”). In the latter case, the null string is not equal
to ““Y” and it is not equal to “N,” so it will loop back to 10. If
you pressed ‘’X,” it will also loop. But if you pressed “Y,” A$
would be equal to “Y’” (meaning A$<>“Y” is false) but it
would not equal “N” (A$<>’N” is true). Since both con-
ditions are not true, AND fails, and the program continues. A
common mistake would be:

181
5 Inside Your 64

1@ GET AS$:IF AS<>"Y" OR AS<>"N" THEN 19

This would loop back to line 10 no matter what key was


pressed. If either A$ did not equal “Y” or A$ did not equal
“N,” then the computer would loop. The only way for the test
to fail would be for A$ to be “not equal” to “Y” and “not
equal’’ to ““N”; in other words, it would have to be both equal
to ““Y” and equal to “N.” I told you it was tricky! By the way,
another common mistake is something like:
19 GET AS:IF A$<>"Y" AND <>"N" THEN 14

This will give you a ?SYNTAX ERROR, but it seems to read all
right in English. It’s just that the computer requires you to
repeat the variable for each symbol such as <>, <,>, or =.
If you've tried some of the examples, you'll find that GET
only changes the value of the variable. It does not print the
key on the screen. This is also handy; you don’t want a bunch
of keys printed out just to move your spaceship using the key-
board. To make a simple ‘video typewriter,” try this (remem-
ber the semicolon on line 20):
19 GET X$:IF XS="""THEN 10
28 PRINT X$;:GOTO 194

On to Great Frontiers
We're nearly ready to use the function keys. Try this: press the
quote (SHIFT-2) and then press the function keys (SHIFT to
get the even-numbered keys). What magic is this? Each key
now seems to print some cryptic symbol! The computer can
read the function keys just like any other key, but PRINTing
them won’t display anything unless you are in quote mode
(where you can program cursor controls into PRINT state-
ments). But you can take advantage of the symbols to easily
interpret the function keys. You use GET to read them, of
course. Try this program:
18 GET FS:IF FS="" THEN 10
20 IF FS="{F1}" THEN PRINT"FUNCTION ONE"
30 IF FS="{F2}" THEN PRINT"FUNCTION TWO"
4@ IF FS="{F3}" THEN PRINT"FUNCTION THREE"
50 IF FS="{F4}" THEN PRINT"fFUNCTION FOUR"
60 IF FS="{F5}" THEN PRINT"FUNCTION FIVE"
70 IF FS="{F6}" THEN PRINT"FUNCTION SIX"
80 IF FS="{F7}" THEN PRINT"FUNCTION SEVEN"
99 IF FS="{F8}" THEN PRINT"FUNCTION EIGHT"

182
Inside Your 64 5

The {F1}, {F2}, and so on, mean for you to press the
appropriate function key inside the quotes. You'll get the
aforementioned symbols. See Appendix B for the symbols
printed on the screen when you press each function key.
What will you do with the function keys? It’s really up to
you. For example, to restart a game, you might do something
like this:
538 PRINT"PRESS Fl TO PLAY AGAIN"
548 GET A$:IF A$<>"{F1l}" THEN 549
You could also organize a bunch of subroutines, one for each
key, that does something associated with the key (maybe eight
sound effects):
16 GET RQ$:IF RQS="" THEN 19
28 IF RQ$="{F1}" THEN GOSUB 598
96 IF RQS="{F8}" THEN GOSUB 1000
Each function key also has a corresponding ASCII num-
ber. Try this program. It prints out the ASCII (ordered) value
for any key pressed:
18 GET AS:IF AS="" THEN 19
20 PRINT CHRS$(34);A$;CHRS$(34),ASC(AS)
38 GOTO 19
The CHR$(34) puts the computer in quote mode so that if
you press CLR/HOME or something, you'll see its symbol
instead of the screen clearing.
Here is a summary of the ASCII values for the function
keys:
PISS3. E2ss137
f3:134 f4: 138
£5: 135... | £63,139
f7:136 £8: 140
They’re in order from f1-f7, and f2-f8, separately. So you
could use a statement like this to check for f6:
342 IF FS=CHR$(139) THEN PRINT "FUNCTION SIX"
659 IF ASC(F$)=139 THEN GOSUB 4153

See how CHR$ and ASC work?

You Take It from Here


Now that you've got the word on function keys, you can start
making your programs “‘user friendly’ too. And you can share

183
5 Inside Your 64

a double feeling of power: not only does pressing one key


raise your garage door, put out the cat, and make coffee in the
morning, but you also know that you're the one that made the
computer do it.

184
Inside Your 64 5

How to Use Arrays


Don Stauffer

Using arrays is a handy BASIC programming


technique. This tutorial explains what they are
and how to use them when programming on
your 64.

Arrays, sometimes called subscripted variables, are an im-


portant feature of Microsoft BASIC, but there is little docu-
mentation on what they are and how to use them. This is
particularly true of the 64.
Some time ago, a friend of mine, a new computer owner,
called with a programming problem. He was working on a
program in which he needed to generate random numbers for
a variable (R). However, he wanted ten different values for R
and wanted to save them for later use in the program, in state-
ments where he would use these R values in calculations. I
told him that was a perfect spot to use an array. After he
looked up arrays in all the reference books he had on the ma-
chine, he wasn’t much better off than when he first called, so
we Spent a session going over arrays. It seemed to me that the
best way to know how to use arrays was to start with the
basics.
What is an Array?
An array is a type of variable which can have a number of
values at any one time. For instance, let’s look at a variable, T,
which might stand for the maximum temperature for a
particular day. T(1) might be the temperature of day 1, T(2)
the temperature of day 2, and so on. The number in the
parentheses is called the subscript. In fact, arrays are some-
times called subscripted variables. Although the best way to
understand arrays is through examples, which we’ll get to
shortly, we should first learn a little about how the computer
stores and uses arrays.
Since an array is a set of several values, it obviously takes

185
5 Inside Your 64

more memory than a normal variable. In fact, unless the com-


puter knows how many values your variable will have, it does
not really know how much memory to set aside for that vari-
able. We tell the computer this information with a DIMension
statement:
DIM X(15),Y(20)
In this example, we told the program we were going to
use two arrays, X and Y, and that X would have a maximum
of 16 values, and Y would have a maximum of 21. Notice that
the number of values set up is always one greater than the
number specified in the DIM statement. Although it’s confus-
ing, this is because the computer starts counting with 0, not 1.
To avoid confusion, some programmers simply ignore the 0
and treat X(15) as an array of 15 values. This wastes a tiny
amount of memory, but it usually doesn’t matter.
With the 64, the DIMension statement is optional unless
you are going to use more than 11 values. I recommend, how-
ever, that you always DIMension arrays, even if they will
have less than 11 values. It is good programming practice, and
it will save considerable memory since the computer will not
set aside unnecessary memory space. Also, the DIM statement
initially sets all array values to zero. Good programming prac-
tice dictates that the array should be DIMensioned in one of
the first statements of the program, and it obviously must oc-
cur before any reference to the array. The DIM statement must
not be executed more than once, however, or an error results.
A particular value of an array is called an element. Each
element is referred to by a subscript, which is why the array is
sometimes called a subscripted variable. In the following
statement:
LET X(5)=27.3
element 5 of the X array is set to 27.3. Whenever the com-
puter comes across a set of parentheses with a number en-
closed following a variable name, it knows you are indicating
an array. From now on, we will call each separate value in an
array an element. In our previous DIMension statement, we in-
dicated that X would have 16 elements, and Y would have 21.
In the assignment statement, we set element 5 of the X array
to22 7.3:
As an example of the use of arrays, let’s take a look at
Program 1, which is part of my friend’s program.

186
Inside Your 64 5

Program 1. Arrays and Average Values


For mistake-proof program entry, be sure to use “Automatic Proofreader,” Appendix J.
18 PRINT"{CLR}":DIM R(10) srem 221
198 FOR N=1 TO 190 srem 56
110 R(N)=INT(RND(1)*190+1) srem 73
120 NEXT N srem 32
138 REM MAIN PART OF{6 SPACES}PROGRAM FOLLOWS
srem 167
148 GOSUB 580 :rem 172
15@ PRINT:PRINT"PRESS A KEY TO COMPUTE"; :PRINT"
{3 SPACES}ANOTHER AVERAGE" :rem 247
160 GETAS:IF AS=""THEN 160 :rem 81
170 PRINT" {CLR}":GOTO19@ :rem @
50@ REM SUBROUTINE FOR{4 SPACES}COMPUTING AVERAGE
{5 SPACES}R :rem 115
510 SM=0 :rem 163
515 PRINT:PRINT"{RVS}ARRAY{OFF}{2 SPACES}{RVS}VALU
ES{OFF}":PRINT srem 145
528 FOR N=1 TO 16 :rem 62
530 SM=SM+R(N) srem 49
535 PRINT"R(":N3")="7R(N) srem 130
540 NEXT N srem 38
558 AV=SM/19 srem 158
56@ PRINT:PRINT"AVERAGE =";{5 SPACES }AV srem 61
576 RETURN srem 124

Line 10 contains the DIMension statement. Lines 100-120 as-


sign ten random numbers to the ten locations or variables of
the R array. The main part of the program is irrelevant to our
discussion of arrays, but the subroutine starting at line 500
uses the array further and is a good example. The program is
written to find the average value of the ten numbers. The sum
is first set to zero in line 510. The FOR-NEXT loop (lines 520-
540) recalls the values stored previously in line 110 and com-
putes the sum, which is divided by ten to compute the
average in line 550.
Two-Dimensional Arrays
Arrays can have more than one dimension. The arrays we’ve
seen so far are one-dimensional. We can visualize the one-
dimensional array as a line of boxes or pigeonholes, as in Fig-
ure 1, in which to place values, or a list of values like a list on
a piece of paper.

187
5 Inside Your 64

Figure 1. One-Dimensional Array


A one-dimensional array can be thought of as a row of boxes or pigeonholes.

PAVAVAW AWA

oof
| DIMX(S)

The one-dimensional array is probably the most common,


but the two-dimensional array is used often, too. The two-
dimensional array is often visualized as a table of rows and
columns. For instance, an array DIMensioned by the
statement:
DIM X(4,3)
would be visualized as a table of five columns by four rows, as
shown in Figure 2. Again, notice that DIM X(4,3) actually sets
up a 5x4 table because the elements are numbered starting
with 0. As with one-dimensional arrays, you may choose to
ignore the 0 column and row, spending a few bytes of mem-
ory to eliminate a possible source of confusion.

Figure 2. Two-Dimensional Array


A two-dimensional array is frequently visualized as a table of rows
and columns.
Column Column Column Column Column
0 1 2 3 4

Row 0 X(2,0)
ee Ca
Row 2 X(1,2)
Row 3 X(2,3)
188
Inside Your 64 5

Frequently, a particular problem can be solved by either a


one- or a two-dimensional array, and the choice is strictly a
matter of style, up to the programmer. Programs 2 and 3 illus-
trate a similar problem, the first with a one-dimensional array,
and the second with a two-dimensional array.
In Program 2, the problem is to record the high tem-
perature for each day, and then find the average high
temperature for the week.

Program 2. One-Dimensional Array


26 DIM TM(7) srem 181
38 REM ENTER DATA srem 223
49 INPUT "{CLR}ENTER DAY NUMBER";N srem 121
5@ PRINT:PRINT “ENTER HIGH TEMPERATURE FOR DAY":IN
PUT TM(N) srem 184
69 IF N<7 THEN 40 srem 73
78 REM srem 75
86 REM A SUBROUTINE, NOT SHOWN HERE, WOULD STORE T
HE ARRAY TO TAPE srem 222
199 REM srem 117
128 GOSUB 1890 srem 212
136 END srem 197
10908 REM ROUTINE FOR FINDING AVERAGE HIGH TEMPERAT
URE srem 26
1919 REM A ROUTINE FOR READING THE TAPE, NOT SHOWN
, WOULD BE INCLUDED HERE srem 79
1038 PRINT srem 81
1940 SM=0 srem 219
1058 FOR N=1 TO 7 srem 67
1868 SM=SM+TM(N) srem 175
1965 PRINT"DAY";N; "TEMP=";TM(N) srem 113
1978 NEXT N srem 85
1688 AV=INT(SM/7) srem 223
1999 PRINT:PRINT"AVERAGE HIGH":PRINT"TEMPERATURE F
OR WEEK=";AV;" DEGREES srem 84
1198 RETURN srem 162

The one-dimensional array TM is DIMensioned to 7. An actual


application program would have some sort of data file
routines, but since tape or disk file handling is another subject
altogether, let’s leave the storage and retrieval out. Lines 40
and 50 assign the value of the high temperature to the appro-
priate box in the array. The average high temperature is then
found in the subroutine starting at line 1000, in the same
manner as in the preceding problem.

189
5 Inside Your 64

Program 3 handles a similar problem using a two-


dimensional array.

Program 3. Two-Dimensional Array


28 DIM TM(52,7) srem 248
38 REM ENTER DATA srem 223
46 INPUT" {CLR}ENTER WEEK NUMBER ":WK srem 27
5@ INPUT"ENTER DAY OF WEEK ":;DY srem 46
6@ PRINT"ENTER HIGH TEMPERATURE"sINPUT TM(WK, DY)
srem 74
65 IF WK<52 THEN 40 srem 210
76 REM srem 75
898 REM SUBROUTINE 5@9, NOT SHOWN HERE, WOULD STORE
srem 5
98 REM DATA ON TAPE srem 46
1890 REM GOSUB 5@@ TO TAPE ROUTINE HERE srem 161
118 GOSUB 19090 srem 211
120 END srem 196
1080 REM READ TAPE AND COMPUTE AVERAGE srem 214
1019 REM A TAPE READ ROUTINE, NOT SHOWN, WOULD BE
{SPACE}FOUND HERE srem 221
1930 REM s:rem 168
1940 S1=0 srem 182
1658 FOR W=1 TO 52 srem 124
1968 S2=0 srem 185
1078 FOR D=1 TO 7 srem 59
1988 S1=S1+TM(W,D) srem 242
1998 S2=S2+TM(W,D) srem 245
1198 NEXT D srem 69
1110 WA=S2/7 :rem 131
112@ PRINT"WEEK ";:W; "AVERAGE IS ":WA; "DEGREES"
srem 186
1130 NEXT W srem 91
1148 YA=S1/365 zrem 238
115@ PRINT" YEARLY AVERAGE HIGH TEMP" srem 191
1168 PRINT"IS ":YA;" DEGREES" srem 136
1178 RETURN srem 169

In this version, we store the temperatures week by week and


day by day in a table of 52 rows of 7 columns (line 20). We
have a column for every day of the week, and a row for every
week of the year. The first part of the program stores our data
in the array by week number and the number of the day in
the week. The subroutine starting at line 1000 again figures
the average, but with a new twist (as an advantage of using

190
Inside Your 64 5

the two-dimensional array). Now we can find the average


temperature for each week as well as for the year.
Another Use of Arrays
Another handy use of arrays is to relate two sets of values to
one another. This can easily be done if each set of values is an
array, and these values can then be related by the subscript. A
common use of arrays for this purpose is relating a set or sets
of values to people’s names. The names are held in a string ar-
ray, such as N$(X), while the values are held in numeric arrays
(having the same dimensions as N§, of course). Program 4
illustrates the use of arrays in a teacher’s gradebook program.

Program 4. Arrays and Grades


2 DIM N$(15),T1(15),T2(15),HW(15),FS(15) :rem 52
30 PRINT"{CLR}" :rem 199
49 REM DISPLAY MENU srem 147
5@ PRINT"{4 SPACES}{RVS}SELECT OPTION{OFF}"
srem 115
6@ PRINT:PRINT"1-ENTER NAMES IN FILE" srem 5
7@ PRINT:PRINT"2-ENTER SCORES, FIRST{3 SPACES}TEST
“ srem 159
8@ PRINT:PRINT"3-ENTER SCORES, SECOND{2 SPACES}TES
Te srem 213
96 PRINT:PRINT"4-ENTER SCORES,{9 SPACES }HOMEWORK"
srem 71
198 PRINT: PRINT"5-COMPUTE FINAL SCORE" srem 142
110 PRINT: INPUT"ENTER NUMBER";:Q zrem
128 ON Q GOSUB 190@, 2002, 3000,4900,5288 :rem 128
130 END srem 107
1800 REM INITIALIZE{7 SPACES}STUDENT NAME FILE
srem 255
1818 FOR N=1 TO 15 srem 110
1628 INPUT"ENTER LAST NAME";NS(N) srem 182
1938 NEXT :rem 3
1848 OPEN 1,1,2,"NAMES" srem 199
1858 FOR N= 1 TO 15 srem 114
1868 PRINT#1,NS(N) :rem 229
1970 NEXT N srem 85
1888 CLOSE 1 s:rem 112
1899 RETURN :rem 170
2608 REM ENTER TEST SCORES srem 51
2018 OPEN 1,1,9, "NAMES" srem 195
2626 FOR N=1 TO 15 :rem 112
2638 INPUT#1,NS$(N) srem 230

191
5 Inside Your 64

2048 NEXT N srem 83


2845 CLOSE 1 srem 114
2658 REM ENTER DATA BY{5 SPACES }NAME srem 255
20668 FOR N=l1 TO 15 srem 116
2876 PRINT"ENTER SCORE FOR ";NS(N) srem 199
2988 INPUT T1(N) srem 126
28908 NEXT N srem 88
2186 REM NOW SAVE T1{7 SPACES}ARRAY AS FILE TO
{6 SPACES
}TAPE srem 79
2119 OPEN 2,1,2,"TEST1" srem 196
2128 FOR N=1 TO 15 srem 113
2130 PRINT#2,T1(N) srem 248
2148 NEXT srem 6
2159 CLOSE 2 srem 112
2160 RETURN srem 169
3908 REM NOW WOULD{9 SPACES}FOLLOW TWO MORE:rem 38
3619 REM SUBROUTINES
{7 SPACES}LIKE THE ONE
{18 SPACES}ABOVE, EXCEPT | srem 85
39208 REM REPLACE T1{8 SPACES }WITH T2 IN SUB-
{7 SPACES}ROUTINE STARTING srem 44
3830 REM AT LINE 3008,{5 SPACES}AND CALL THE FILE
{5 SPACES }}"TEST2". srem 42
3846 REM THEN USE HW{7 SPACES }AND FILENAME
{9 SPACES}"HMWRK" FOR THE srem 15
3656 REM ROUTINE AT 40900 srem 43
4828 REM HOMEWORK FILE{5 SPACES } HERE srem 88
58068 REM READ TAPE{9 SPACES }FILES AND COMPUTE
{5 SPACES}SCORE srem 296
5816 OPEN 1,1,98,"NAMES" s:rem 198
5826 FOR N=1 TO 15 srem 115
5630 INPUT#1,NS(N) srem 233
5848 NEXT srem 8
5956 CLOSE 1 srem 113
58608 OPEN 2,1,98,"TEST1" srem 2901
5878 FOR N=1 TO 15 srem 129
5986 INPUT#1,T1(N) s:rem 1
58908 NEXT srem 13
5190 CLOSE 2 srem 110
5185 INPUT"HIT RETURN TO CONTINUE";Q srem 248
5116 OPEN 3,1,9,"TEST2" srem 199
5129 FOR N=1 TO 15 srem 116
5136 INPUT#3,T2(N) srem @
5146 NEXT srem 9
5158 CLOSE 3 srem 116
5155 INPUT "HIT RETURN TO CONTINUE":Q srem 253
51608 OPEN 4,1,9, "HMWRK" srem 228
5170 FOR N=1 TO 15 s:rem 121
5189 INPUT"4,HW(N) srem 30
51968 NEXT N srem 92

192
Inside Your 64 5

5288 CLOSE 4 srem 113


5218 REM NOW COMPUTE{7 SPACES}FINAL SCORE :rem 163
5228 FOR N= 1 TO 15 srem 117
5230 FS(N)=T1(N)+T2(N)+HW(N) :rem 28
5240 NEXT N srem 88
5258 REM NOW PRINT OUT{5 SPACES}SCORES srem 248
5269 OPEN 1,4,7 srem 243
5270 PRINT"1, "NAME", "SCORE" srem 43
5288 FOR N = 1 TO 15 s:rem 123
5298 PRINT#1,NS(N),FS(N) srem 82
5388 NEXT N srem 85
5318 RETURN srem 169

For demonstration purposes, this program is not a com-


plete program as it stands, and contains no error trapping or
user prompts. It could, however, be expanded into a useful
gradebook program with some fill-in work. It is instructive of
the use of arrays to relate variables. The main program, up to
line 130, creates a menu selection which sends the program to
the appropriate subroutine.
The first routine, starting at line 1000, is used at the
beginning of the school term to enter the students’ names in a
string array, N$(N). The DIMension statement in line 20 of the
main program, and all of the FOR-NEXT loops, would have to
be adjusted to the actual number of students in the class. Sub-
routine 2000 would be used to enter the scores of the first test.
By reading the N$§ array in lines 2010 to 2045, the program
prompts the teacher with the student’s name for data entry
(line 2070). A similar subroutine would be used for each test
and maybe a homework score.
Subroutine 5000 puts it all together at the end of the
term. After reading the grades from all the files, line 5230 fig-
ures the grade for every student. In effect, the variable N is a
student number which relates each element of each of the four
files. This illustrates how N can still be used as a separate
variable, even when you've set up a numeric array N(X) or a
string array N$(X).
These examples of the use of the array are general but
easy to expand on. Arrays can be used in a variety of ways.
I’m sure that after using them for a while, you can come up
with many more applications on your own.

193
5 Inside Your 64

Adding New
Keywords to
BASIC
Sheldon Leemon

There are lots of programs available which will


enhance your Commodore 64 by adding new
keyword commands to BASIC. But learning how
to program these additions yourself is rarely ex-
plained. This article, for programmers familiar
with machine language, includes examples and
the source code used to create five new
keywords, and shows you how to program new
BASIC commands yourself.
SACRA NBER SN TRIS NRE SII TE SR ca

While Commodore 64 BASIC is a useful all-purpose language,


it does have some limitations. There are no special graphics or
sound commands to support the machine’s bitmap or sprite
graphics, or its superior musical abilities. It lacks error trap-
ping, so that any error causes the program to stop. In fact,
after a little thought, almost any programmer could come up
with a “wish list” of new commands that he or she would like
to see added to BASIC.
To overcome these limitations, some programmers devise
machine language subroutines which allow them to simulate
new BASIC commands. Often, however, they have problems
integrating these new routines into the framework of the exist-
ing BASIC. The USR and SYS commands are most often used
to add machine language routines to BASIC, but these com-
mands do not easily pass values to the machine language
program (if you were creating a DRAW command for hi-res
graphics, for example, you would have to specify the screen
position each time you used the command). And these com-
mands are not always convenient, for their syntax is often

194
Inside Your 64 5

strange and their use requires you to know the address of each
routine.
Wedges?
On the old Commodore PET machines, there was a way to
add new commands to BASIC using what was called a
“wedge.” This is a routine that intercepts the part of the
BASIC interpreter program that reads the program text. The
wedge routine is designed to read the text before BASIC does,
and compare that text to a list of new commands (like the
short disk commands of the DOS support program). If one of
these commands is spotted, the wedge executes the new rou-
tine. If not, control is handed over to the normal BASIC
routines.
There are a couple of problems with this technique, how-
ever. The most important one is execution speed. Since the
BASIC routine which the wedge diverts has to read every sin-
gle character of the program being executed, the time that the
wedge takes to check for each character for new commands
can drastically slow down your program. The more commands
added, the greater this slowdown. To counteract this effect,
wedge commands are often set up to execute only in direct
mode (that’s why you can’t call the DOS wedge from a pro-
gram while it’s running). Even so, a wedge as efficient as the
DOS support program still slows down program execution a
little. Another problem is that adding new commands with a
wedge is hard to do in a way so they can be used simulta-
neously with DOS support and other wedge programs.
Fortunately, the 64 isn’t limited to the wedge method of
adding new commands. The 64 was designed to allow the
addition of new commands which function exactly like regular
BASIC commands, and which do not slow program execution.
To explain how this is possible, however, first requires an
explanation of how Commodore's Microsoft BASIC operates.
Microsoft BASIC
When you enter a line of BASIC program text, a tokenization
routine scans the line to see if any of the words match its list
of command keywords. When it finds such a word (like
PRINT, for example) the routine replaces the ASCII characters
of the keyword with a single character, called a token. Each
token has a value of 128 or higher, and represents a single
BASIC command. These tokens are interpreted by BASIC
195
5 Inside Your 64

when the RUN or LIST command is entered. When a pro-


gram is RUN, the BASIC interpreter starts to read the program
text. Each time it comes to a character with a value of 128 or
greater (that isn’t in quotes, or in a DATA or REM statement),
it tries to execute the command which corresponds to that
token. When you LIST the line, a detokenization routine
expands the token from a single character back to its ASCII
equivalent.
Therefore, in order to add new tokenized keywords to
BASIC, and to be able to LIST and RUN them, you must have
a way of intercepting the BASIC interpreter routines that
tokenize, detokenize, and execute keywords. At first that
might seem impossible, because the BASIC interpreter is in
ROM, which cannot be changed. Nonetheless, it is possible to
gain access to these routines via the BASIC Indirect Vector
Table, which is in RAM. This table, which starts at location
768 ($300) and continues to 779 ($30B), contains the addresses
of six crucial BASIC routines. They are IERROR (768-769),
which prints BASIC error messages; IMAIN (770-771), the
main program loop of BASIC which waits for you to enter a
line after the READY prompt; ICRNCH (772-773), the rou-
tine that crunches the text of keywords into single-character
tokens; IQPLOP (774-775), which expands those tokens back
into ASCII characters; IGONE (776-777), which executes
BASIC statement tokens; and IEVAL (778-779), which among
other things evaluates tokenized BASIC functions (like INT
and ASC). Whenever BASIC wants to execute one of these
routines, it does not go directly to its ROM location, but rather
jumps to the address indicated in the Indirect Vector Table. At
power-on time, these vectors are set to the addresses of the
normal ROM BASIC routines. However, it’s possible to change
these vectors so that when BASIC wants to perform one of
these functions, it first goes to your routine. In this way, you
can create new tokenized commands with their own error
messages, and LIST or execute them. You can even change the
function of normal BASIC commands.
Making New Keywords
The first step is to design a routine to tokenize your new
keywords. Since BASIC 2.0 only uses keyword tokens from
128-204, you can use numbers 205-254 for fifty new com-
mands (255 is used for PI). If you need more than that, you'll

196
Inside Your 64 5

have to go to a two-character token system, such as the one


used by Simon’s BASIC. The tokenization process is somewhat
tricky, because you not only have to check the text input
buffer starting at location 512 for your new keywords, but you
must also be sure not to tokenize those words when they
appear in a DATA statement, a REMark, or as a literal string
in quotes. The method used in Program 1, ‘64 Keywords,”
closely parallels the normal BASIC tokenization routine. It first
calls the regular tokenization routine, and then looks for new
keywords. Since the normal keywords will be tokenized first,
your new keywords cannot contain any of the old keywords.
For example, the new tokenization routine will not recognize
the keyword COLOR, because by the time it looks for it, the
OR will have been changed to the single-character token for
the BASIC keyword OR. Once the new tokenization routine is
installed, lines containing these new tokens will not LIST cor-
rectly until a new detokenization routine is installed. The
token conversion routine used in Program 1 is also based on
the normal BASIC detokenization routine. It looks for token
numbers 204 and up, and when it finds one, it expands that
token to the ASCII equivalent. Otherwise, control is passed
back to the old tokenization routine.
Once the new tokens are in place, the method for execut-
ing them is pretty straightforward. Statements such as PRINT
are executed by the routine GONE, which is pointed to by the
vector IGONE at location 776-777. That routine reads the next
character, and determines whether it is a token. If it is, it looks
up the execution address in a table, and passes control to it.
Our new execution routine needs only to check if the character
is a token numbered 204 or higher. If it is, its address is
looked up in the table, and the routine is executed. If not, con-
trol passes back to the old routine. Functions, like INT and
SGN, are evaluated by the routine EVAL, which is pointed to
by the RAM vector IEVAL at address 778-779. New functions
can be added by intercepting this routine, and checking for
one of our new token characters. When such a token is found,
the function is evaluated, and the result is placed in the Float-
ing Point Accumulator. In all other cases, control is passed
back to the old routine. Notice that in Program 1 the way in
which numbers are passed to the new commands is modeled
on the old BASIC commands. Therefore, if your new com-
mand needs two inputs, you can study a BASIC command

197
5 Inside Your 64

such as PEEK or POKE to see how it gets its inputs.


Though it’s not necessary, you can add new error mes-
sages if you want. The easiest way to do this is to set locations
34-35 ($22-23) as a pointer to your new error message text,
and enter the normal BASIC error handler routine at 42055
($A447)
Program 1 gives a practical demonstration of how to
implement these new commands. After you type in and RUN
the program, the additional commands FILL, FCOL, LOOK,
PAUSE and KILL will become available. Make sure you SAVE
the program before you try to RUN it; a single error in the
DATA statements could cause the computer to lock up. If that
happens, you'll need to turn off your computer, and the pro-
gram will be lost if it hasn’t been SAVEd. A brief description
of the syntax of these commands follows:
FILL character,color. This command fills the entire screen
with 1000 repetitions of one character. The parameter charac-
ter refers to the POKE value (0-255) of the character used to
fill the screen, and color refers to the foreground color used for
the fill character. If a character number from 256-65535 is
used, a NOT A VALID CHARACTER error message will ap-
pear. If a color value from 16-256 is used, you will get a NOT
A VALID COLOR error message.
FCOL color. This command is similar to FILL, but
changes only the foreground color of text on the screen, and
not the actual characters.
LOOK(address). This is a new BASIC function. It returns
the value of the two-byte word address and address+1 (in
BASIC, the equivalent formula is PEEK(address) + 256*
PEEK(address)+ 1). As with PEEK, the format should be
PRINT LOOK(address).
PAUSE /jiffies. This command pauses execution of the
program from 0 to 65535 jiffies (each jiffy is 1/60 second).
KILL. Finally, KILL disables all our new commands, and
restores the old BASIC. The new commands can be
restored with a SYS 12*4096 (49152) statement.
After you have run Program 1, type in Program 2. This
program demonstrates the use of FILL, FCOL, and PAUSE.
Remember, the computer will not understand and tokenize
these new commands until after you have installed them with
Program 1.

198
Inside Your 64 5

Using the Source Code


FILL and FCOL, though dramatic when used on the low-res
text screen, are most helpful for changing the color map of the
high-res screen. Like the other new commands presented here,
they were selected more for their brevity than their inherent
usefulness. The real purpose of Program 1 is to show how a
machine language programmer can hook in new BASIC com-
mands. The source code of this program, which follows, can
be used as a framework for adding your own commands. To
do this, you must:
1) Place the text of your new keywords in the table
labeled KEYTXT. The last letter of each keyword should have
its high bit set (in other words, use the ASCII value+ 128).
Functions should all be put at the end of the table. Keep in
mind that the text of these words should not include any of
the old keywords. COLOR for example will not tokenize cor-
rectly, because it contains OR.
2) Place the address of the routines in the order in which
their keywords appear in the KEYTXT table in the statement
vector table STVEC and the function vector table FUNVEC.
Note that the correct vector for a statement is its address
minus one.
3) If you wish to add error messages, replace the text in
the table starting with ERMSGO with your own text. As with
keywords, the last letter of each message should have the high
bit set. You can also replace the labels CHRERR and COLERR
with new labels, indicating the nature of your new error
messages.
The BASIC Indirect Vector Table gives you the power to
add new commands, or alter existing commands. This
explanation can allow machine language programmers to up-
grade the capabilities of Commodore 64 BASIC to match the
rest of the machine.
Source Code for 64 Keywords
;ZERO PAGE EQUATES

ENDCHR = $08 ;TEMP FLAG


COUNT = $8B ;TEMP FLAG
VALTYP = $QD ;VARIABLE TYPE FLAG
GARBFL = $@F ;TEMP FLAG
LINNUM = $14 ;UTILITY POINTER
INDEX = $22 ;UTILITY POINTER

199
5 Inside Your 64

FORPNT $49
JMPER $54 ;JMP TO FUNCTION
FACHO $62 ;FLOATING PT. ACC.
FBUFPT $71 ;TEMP SAVE AREA
CHRGET $73 ;BASIC READS TEXT
CHRGOT $79 ;READ TEXT AGAIN
TXTPTR $7A ;PNTR TO CURRENT TEXT
TIME $A@ ;SOFTWARE CLOCK (MSB)
LDTB1 |1 $D9
| ;LINE LINK TABLE

7PAGE TWO EQUATES

BUF $200 ;TEXT INPUT BUFFER


HIBASE $288 7 SCREEN MEMORY PAGE
VECSAV $2A7 ;VECTOR SAVE AREA

?BASIC INDIRECT VECTORS

IERROR $388 ;PRINT ERROR MESSAGE


IMAIN $382 ;MAIN 'READY.' LOOP
ICRNCH $384 7 TOKENIZE KEYWORDS
IQPLOP $306 7PRINT KEYWORDS
IGONE $388 ; EXECUTE STATEMENTS
IEVAL $30A 7;EVALUATE FUNCTIONS

?BASIC ROM ROUTINES

ERROR $A437 7? ERROR MESSAGES


MAIN $A483 ;MAIN ‘READY' LOOP
CRNCH $A57C ; TOKENIZE KEYWORD
PLOOP SAGF3 ;LIST NON-TOKEN
PRIT4 SA6EF ;PRINT LAST CHAR
QPLOP SA71A 7;PRINT KEYWORDS
NEWSTT SA7AE ;NEXT STATEMENT
GONE SA7E4 7 EXECUTE A TOKEN
OUTDO S$AB47 7PRINT A CHAR
FRMNUM SAD8A 7;GET NEXT PARAMETER
CHKNUM SAD8D ;CHECK VAR. TYPE
EVAL SAE86 ;FUNC. EVALUATION
PARCHK SAEF1 ;GET VALUE IN ( )
GETNUM $B7EB ;ADR IN 14,INT IN X
GETADR SB7F7 ;CONVERT FP TO INT
FLOATC nea
db
donb
bn $BC49
Vuinrid
db CONVERT INT TO FP

7 PROGRAM VARIABLES & CONSTANTS

MAXCOL SOF ;MAXIMUM COLOR #


NEWTOK $CC ;1ST NEW TOKEN #
DATTOK $49 ;"DATA' TOKEN-':'

200
Inside Your 64 5

REMTOK = $55 ;'REM' TOKEN-':'


°

* = $COBD
e

7 INSTALL NEW INDIRECT VECTORS


7A SYS TO 'INSTAL' ACTIVATES OUR
7NEW KEYWORD COMMANDS

INSTAL 7;INSTALL NEW VECTORS


LDX #$87 74 TWO-BYTE VECTORS
INSTL1
LDA ICRNCH,X
STA VECSAV,X ;SAVE OLD VECTORS
LDA IVECS,X ;INSTALL NEW VECTORS
STA ICRNCH,X
DEX
BPL INSTL1 ;KEEP GOING TIL DONE
INSTL2
RTS

IVECS
eWORD TOKNIZ
eWORD PRTOK
eWORD EXEST
«WORD EXEFUN

KEYTXT ;TEXT OF KEYWORDS


-BYTE 'PAUS',S$C5 ;PAUSE
~BYTED YFCOS, SCCa + FCOL
-BYTE “FILC, SCC shins
-BYTE ‘KIL',S$CC ;KILL
-BYTE 'LOO',S$CB ;LOOK
-BYTE @ ;END OF TABLE

STVEC ;STATMENT DISPATCH VECTORS


-WORD PAUSE-1 ;PAUSE
eWORD FCOL-1 ;FCOL
eWORD FILL-1 ;FILL
eWORD KILL-1 ;KILL

FUNVEC ;FUNCTION DISPATCH VECTORS


«WORD LOOK

FUNTOK = FUNVEC-STVEC/2+NEWTOK

;PATCH TO TOKENIZATION ROUTINE


; ALLOWS US TO TOKENIZE OUR OWN
;KEYWORDS USING THE UNUSED TOKEN
;NUMBERS 294-254

201
5 Inside Your 64

TOKNIZ
JSR CRNCH ;TOKENIZE AS USUAL
CRUNCH ;DO 2ND TOKENIZATION
LDX #$80 ;SET READ INDEX
LDY #$94 7SET WRITE INDEX
STY GARBFL ;CLEAR 'DATA' FLAG
CRN1
LDA BUF,X ;GET NEXT CHARACTER
7BMI MOVE ;WRITE IF A TOKEN
CRN2
STA ENDCHR ;FOR END QUOTE TEST
CMP #$22 7IS THIS A QUOTE?
BEQ SKQUOT ;YES, SKIP TO NEXT "
BIT GARBFL ;IF IN "DATA STATEMENT
BVS MOVE ;WRITE THE CHARACTER
CMP #'A' ;< THE LETTER 'A?
BCC MOVE 7;YES, WRITE IT
CMP #S5B 7> THE LETTER 'Z
BCS MOVE 7YES, PASS IT THROUGH
STY FBUFPT ;SAVE WRITE INDEX
LDY #NEWTOK-$8@ ;# OF 1ST TOKEN
STY COUNT ;SET TOKEN COUNTER
LDY #SFF
STX TXTPTR ;SAVE READ INDEX
DEX 7TO OFF?SET THE INX
CRN3
INY ADVANCE WRITE INDEX
INX 7;ADVANCE READ INDEX
CRN4
LDA BUF,X ;GET BUFFERED CHAR
SEC
SBC KEYTXT,Y ;= NEXT TABLE CHAR?
BEQ CRN3 ;YES, KEEP GOIN'
CMP #$80 ;LAST KEYWORD CHAR?
BNE NEXTKW ;NOPE, TRY NEXT WORD
ORA COUNT ;YEP, GET TOKEN NO.
CRN5
LDY FBUFPT ;RESTORE WRITE INDEX
MOVE
INX ;ADVANCE READ INDEX
INY ;ADVANCE WRITE INDEX
STA BUF-5,Y ;WRITE CHARACTER
LDA BUF-5,Y ; TO TEST FOR EOL
BEQ EXIT ;A ZERO ENDS THE LINE
SEC
SBC #':' ; sSTATEMENT TERMINATOR?
BEQ MOVE] ;YEP, CLEAR 'DATA FLAG
CMP #DATTOK ;TOKEN FOR 'DATA?

202
Inside Your 64 5

BNE MOVE2 ; DON'T CLEAR FLAG


MOVE1
STA GARBFL ;CLEAR 'DATA FLAG
MOVE2
SEC
SBC #REMTOK ;TOKEN FOR 'REM?
BNE CRN1 7;NO, NEXT CHARACTER
STA ENDCHR ;YES, FALL THRU
SKIP1
LDA BUF,X ;GET NEXT CHARACTER
BEQ MOVE ;KEEP GOIN‘ TIL EOL
CMP ENDCHR ;OR TERMINATOR
BEQ MOVE
SKQUOT. ;SKIP TEXT IN “2
INY ;ADVANCE WRITE INDEX
STA BUF-5,Y ;WRITE CHAR
INX ;ADVANCE READ INDEX
BNE SKIP1 ;ALWAYS--KEEP GOIN'
NEXTKW ;TRY NEXT KEYWORD
LDX TXTPTR ;RESTORE READ INDEX
INC COUNT ;ADVANCE KEYWORD CNTR
NEXT1
INY ;ADVANCE TABLE INDEX
LDA KEYTXT-1,Y ;GET TABLE CHAR
BPL NEXT1 ;SKIP 'TIL NEXT WORD
LDA KEYTXT,Y ;GET 1ST CHAR
BNE CRN4 ;TRY AGAIN
LDA BUF,X ;END OF TABLE
BPL CRN5S ;ALWAYS
EXIT
STA BUF-3,Y ;SET END OF LINE
LDA #S$FF ;RESTORE TXTPTR
STA, TXEPTR + TO START OPPBUE
RTS
e

:;THIS PATCH TO THE 'LIST' ROUTINE


7;ALLOWS US TO EXPAND OUR TOKENS
;BACK TO ASCII TEXT, ‘SO THAT ‘THEY
LIST OUT CORRECTLY

PRTOK ;PRINT OUR NEW TOKENS


BPL PRINT1 ;<128, NOT A TOKEN
CMP -£SPR ES PETE Le
BEQ PRINT1 ;YES, PRINT IT
BIT GARBFL ;ARE WE IN QUOTES?
BMI PRINT1 ;YES, PRINT ANYTHING
CMP #NEWTOK ;IS IT A NEW TOKEN?
BCC OLDPR ;NO, USE OLD ROUTINE
SEC

203
5 Inside Your 64

SBC #NEWTOK-1 ;GET TOKEN NUMBER


TAX ;TO USE AS INDEX
STY FORPNT ;SAVE STATEMENT INDEX
LDY #$FF
PRTOK1
DEX ;NEXT KEYWORD
BEQ PRLOOP ;THIS IS THE ONE
PRTOK1
DEX ;NEXT KEYWORD
BEQ PRLOOP ;THIS IS THE ONE
PRTOK2
INY ;GET NEXT LETTER..
LDA KEYTXT,Y ;IN KEYWORD
BPL PRTOK2 ;END OF KEYWORD?
BMI PRTOK1 7NO, NEXT LETTER

PRLOOP
INY 7;GET NEXT LETTER...
LDA KEYTXT,Y ;IN KEYWORD
BMI PRINT2 7END OF KEYWORD?
JSR OUTDO 7NO, PRINT CHAR...
BNE PRLOOP 7;AND REPEAT

PRINT1
JMP PLOOP ;PRINT ONE CHARACTER
PRINT2
JMP PRIT4 ;PRINT LAST CHARACTER
OLDPR
JMP QPLOP ;USE OLD ROUTINE
°
4

7;THIS PATCH TO THE STATEMENT


7;EXECUTION ROUTINE ALLOWS US TO
;CHECK FOR OUR NEW STATEMENT
;TOKENS, AND TO EXECUTE THEM.

EXEST
JSR CHRGET ;GET NEXT CHARACTER
CMP #NEWTOK ;IS IT A NEW TOKEN?
BCC OLDEXE ;NO, USE OLD ROUTINE
JSR EXE1 ; EXECUTE STATEMENT
JMP NEWSTT ;AND START OVER

EXE1 ;EXECUTE OUR NEW TOKEN


; (CARRY IS ALREADY SET)
SBC #NEWTOK ;GET TOKEN #
ASL A ;2*TOKEN #..-
TAY 7IS OUR INDEX TO..
LDA STVEC+1,Y ;THE VECTOR TABLE
PHA ;PUSH ADDRESS-1...

204
Inside Your 64 5

LDA STVEC,Y ;ONTO STACK...


PHA 7FOR RTS...
JMP CHRGET 7AT END OF CHRGET

OLDEXE
JSR CHRGOT ;GET CHARACTER AGAIN
JMP GONE+3 ;AND USE OLD ROUTINE

7;THIS PATCH TO THE EVALUATION


; ROUTINE ALLOWS US TO CHECK FOR
7;OUR NEW FUNCTION KEYWORDS, AND
7TO EVALUATE THEM, LEAVING THE
7RESULT IN THE FLOATING POINT
7 ACCUMULATOR

EXEFUN
LDA #$86
STA VALTYP ;SET TO NON-STRING
JSR CHRGET ;GET EVAL. CHAR.
CMP #SFF ;IS IT PI?
BEQ OLDFUN ;YES, DO OLD EVAL.
CMP #FUNTOK ;IS IT A NEW FN?
BCC OLDFUN ;NO, DO OLD EVAL.
;GET TOKEN #
SEC
SBC #FUNTOK
ASL A ;USE AS INDEX
PHA ;SAVE ON STACK
JSR CHRGET ;GET EVAL. CHAR.
JSR PARCHK ;GET EXPRESSION IN ()
PLA ;GET INDEX BACK
TAY
LDA FUNVEC,Y
STA JMPER+1
LDA FUNVEC+1
STA JMPER+2 ;FORM POINTER
JSR JMPER ;EVALUATE FN
JMP CHKNUM ;CHECK VAR. TYPE & RTS

OLDFUN
JSR CHRGOT
JMP EVAL+7 ;OLD ROUTINE

7THIS SECTION CONTAINS MY NEW


;COMMANDS. THIS IS WHERE YOU WILL
7;INSTALL YOUR OWN CODE.

;LOOK (X) FUNCTION PEEKS 2 BYTES


e

205
5 Inside Your 64

LOOK ;
LDA LINNUM+1
PHA
LDA LINNUM
PHA ;SAVE LINNUM ON STACK
JSR GETADR ;INTEGER IN 14/15=ARG
LDY #$006 ;SET INDEX
LDA (LINNUM),Y ;GET LOW BYTE
STA FACHO+1
INY
LDA (LINNUM),Y ;GET HIGH BYTE
STA FACHO
PLA
STA LINNUM
PLA
STA LINNUM+1 ;RESTORE LINNUM
LDX #$99 ;SET EXPONENT
SEC
JSR FLOATC ;CONVERT INT TO FP
RTS
°
v

;'KILL* DISABLES THE NEW COMMANDS

KILL
LDX #$87 ;NUMBER OF VECTORS
KILL1
LDA VECSAV,X ;GET SAVED VECTORS
STA ICRNCH,X ;RESTORE THEM
DEX
BPL KILL1 ; DONE?
RTS
°

;'FILL'=--FILL X,Y FILLS THE SCREEN


;WITH CHARACTER X IN COLOR Y

FILL
JSR GETNUM ;GET ADDR, INT IN X
LDA LINNUM+1 ;CHAR >255?
BNE CHRERR ;YES, ERROR
STA FACHO ;CLEAR POINTER
CPX #MAXCOL+1 COL > U5?
BCS COLERR ;YES, ERROR
TXA ;SAVE COLOR
PHA
LDA LDTB1+23 ;FORM POINTER..
AND #63 DOM TOR ctex.
ORA HIBASE 7;OF SCREEN
STA FACHO+1
LDA LINNUM ;GET FILL CHAR

206
Inside Your 64 5

JSR FILL1
PLA ;GET COLOR

FCOL1 ;FILL COLOR RAM

LDX #S$DB ;POINTER TO..


STX FACHO+1 ;SCREEN RAM
e
a

7FILL LOOP

FILL1
LDX #$83 ;DO 3 PAGES
LDY #SE7 ;AND MOST OF 4TH
FILL2
STA (FACHO),Y ;FILL 'ER UP
DEY ;NEXT BYTE
BNE FILL2
STA (FACHO),Y ;DON'T FORGET ZERO
DEC FACHO+1 7;NEXT PAGE
DEX
BPL FILL2 DONE YET?
RTS
°
a

;OUR NEW ERROR MESSAGE ROUTINE


;STARTS HERE

CHRERR
LDA #$0@ ;CHARACTER ERROR NO.
-BYT $2C ;SKIP NEXT INSTRUCTION
COLERR
LDA #$01 ;COLOR ERROR NO.
ASL A ;ERROR NO. * 2
TAX 71S USED AS AN INDEX
LDA ERRVEC,X ;TO VECTOR TABLE
STA INDEX ;SET UP TEXT POINTER
LDA ERRVEC+1,X
STA INDEX+1
JMP ERROR+16 ;PRINT ERROR MSG

ERRVEC
-WORD ERMSG@
eWORD ERMSG1

ERMSG@
-BYT 'NOT A VALID CHARACTE',S$D2
ERMSG1
-BYT 'NOT A VALID COLO',$D2
e
,

;'"FCOL'--FCOL X FILLS COLOR RAM

207
5 Inside Your 64

:;WITH COLOR X

FCOL
JSR FRMNUM ;GET COLOR #
JSR GETADR ;CONVERT FP TO INT
CMP #80 ;COLOR>255?
BNE COLERR ;YES, ERROR
STA FACHO
CPY #MAXCOL+1 7 COLOR>15?
BCS COLERR ;YES, ERROR
TYA ;COLOR TO .A
JMP FCOL1
°

;'PAUSE'--PAUSE X PAUSES PROGRAM


;EXECUTION FOR X JIFFIES (1/698 OF
7A SECOND)

PAUSE
JSR FRMNUM ;GET # OF JIFFIES
JSR GETADR ;CONVERT FP TO INT
TAX ;HIGH BYTE IN .X, LOW IN .Y
PAUSE1
CPY #$0@ ;LOW BYTE DONE?
BEQ PAUSE4 ;YES, TRY HIGH BYTE
PAUSE2
DEY
LDA TIME+2 ;SOFTWARE CLOCK...
PAUSE3
CMP TIME+2 ;ON THE SAME JIFFY?
BEQ PAUSE3 ;YES, TRY AGAIN
BNE PAUSE1 ;NO, ONE JIFFY DOWN
PAUSE4
CPX #$80 =e HIGH BYTE DONE?
BEQ PAUSE5 ;YES, EXIT
DEX 7NO, COUNT DOWN HIGH BYTE
JMP PAUSE2 ;AND DO NEXT LOW BYTE
PAUSE5
RTS
°

- END

Program 1. 64 Keywords
For mistake-proof program entry, be sure to use “Automatic Proofreader,” Appendix J.
1@ B=@:FOR I=49152 TO 49685:READA: POKEIL,A:B=B+A:NE
XT
20 IF B<>64356 THEN PRINT"CHECKSUM ERROR--CHECK YO
UR TYPING":END

208
Inside Your 64 5

38 SYS49152:PRINT"NEW BASIC COMMANDS INSTALLED"


srem 176
49152 DATA 162; te 189, 4,9 3,00 57 s:rem 113
49158 DATA L6%ay 225 189, ,1 8, 292, LSy/ srem 21
49164 DATA 4, 3, 202, 16, 241, 96 srem 1902
49170 DATA 58), 92) 90 e928 2437, 192 srem 111
49176 DATA 21), "1937 5.80),, 65 85, 383 srem 172
49182 DATA 197, 76, 67, 79, 204, 78 srem 224
49188 DATA 73, 46, 204, 755 73, 16 srem 1890
49194 DATA 264, 76, 79, 79, 283, @ srem 169
49200 DATA 248, 193, 228,, 193, 115, 193 srem 157
49206 DATA LO355193—e 7 lye dl93,6 S32 eel 24 srem 45
49212 DATA 165, 162.0, 60, 4, 132 srem 190
49218 DATA 15), 189, 8, 2752335 8 srem 55
49224 DATA 201, 34, 248, 79, 36, 15 srem 202
49230 DATA 112, 38, 201, 65, 144, 34 srem 245
49236 DATA 201 2901, A76 039, 132, 6403 srem 39
49242 DATA 160, 76, 132, 11, 160, 255 srem 42
49248 DATA 134, 122, (202, 200,5:232,¢ 189 srem 141
49254 DATA O, 2, 56, 249, 26, 192 srem 119
49260 DATA 248, 245, 201, 128, 208, 48 srem 96
49266 DATA 5, ll, 164, 113, 232, 2980 srem 241
49272 DATA L5Speceolye Lad 85 pre al s:rem 199
49278 DATA 248, 54, 56, 233, 58, 248 s:rem 9
49284 DATA 4, 201, 73, 208, 2, 133 srem 149
49296 DATA 1544 5676:233,085, 208,179 srem 15
49296 DATA 133, 8, 189, 0, 2, 240 srem 199
49362 DATA 223, 197, 8, 248, 219, 200 s:rem 44
49388 DATA 153, 251, 1, 232, 298, 249 srem 39
49314 DATA 166, 122, 230, 11, 200,.- 185 ° srem 84
49320 DATA 25, 192,¢ 16,5258, 185, 26 srem 255
49326 DATA 192, 208, 188, 189, @, 2 srem 209
49332 DATA 16, 190521535 253, as, 169 srem 8
49338 DATA 255, 133, 122, 96, 16, 42 s:rem 5
49344 DATA 201, 255, 248, 38, 36, 15 srem 253
49350 DATA 48, 34, 201, 204, 144, 36 srem 249
49356 DATA 56 ym essa cOsge llOye SZ, wo srem 49
49362 DATA 160, 255, 202, 248, 8, 200 s:rem 37
49368 DATA 185, 26, 192,.16, 258, 48 srem 16
49374 DATA 245, 208, 185, 26, 192, 48 s:rem 60
49380 DATA 8, 32, 71, 171, 208, 245 srem 299
49386 DATA 76, 243, 166, 76, 239, 166 srem 79
49392 DATA 16, 26, E67, 325 2154) 0 srem 169
49398 DATA 201, 204, 144, 21, 32, @ srem 193
49494 DATA 193, 76, 174, 167, 233, 264 srem 199
49410 DATA 16, 168, 185, 49, 192, 72 srem 8
49416 DATA 185) 48) LOZ) 125070, 125 s:rem 17
49422 DATA Dee s2y leg el Once L s:rem 87
49428 DATA 1677, 269," 9;,.2133;,,, 13, 32 srem 207

209
5 Inside Your 64

49434 115, @, 201, 255, 246, 33 srem 240


49449 281, 268, 144, 29, 56, 233 srem 47
49446 288, US 25. 32, LS, 10 srem 145
49452 32, 241, 174, 104, 168, 185 srem 194
49458 56, LOZ LOS Clan Lior, OW, srem 22
49464 192, 133, 86, 32, 84, @ srem 163
49476 76, 141, 173, 32, 121, @ srem 197
49476 76, 141, 174, 165, 21, 72 srem 11
49482 VG655 .202, 32, 247, Ss srem 6
49488 169, 8, 177, 28, 133, 99 srem 216
49494 200, 177, 20, 133, 98, 104 srem 52
49560 133, 28, 194, 133, 21, 162 srem 25
49596 144, 56, 32, 73, 188, 96 srem 225
49512 G2), iO par OU metal Or srem 218
49518 4, 3, 202, 16, 247, 96 s:rem lll
49524 327, 2357 183%, 165, 21, 208 srem 5@
49530 44, 133, 98, 224, 16, 176 srem 8
49536 41, 138, 72, 165, 248, 41 srem 2
49542 Ein ANS ESO Ae pedbsisine 9) srem 196
49548 165, 28, 32, 156, 193, 104 srem 47
49554 162, 219, 134, 99, 162, 3 srem 12
49560 160, 231, 145, 98, 136, 2608 srem 196
49566 251, 145, 98, 198, 99, 282 srem 79
49572 16, 244, 96, 169, 9, 44 srem 169
49578 169, 1, 18, 178, 189, 187 srem 19
49584 1937, 133, 34,) 189, 188, 198 srem 127
49596 133, 35, 76, 71, 164, 191 srem ll
49596 193, 212, 193, 78, 79, 84 srem 33
49602 32, 65, 32, 86, 65, 76 srem 118
49688 73, 68, 32, 67, 72, 65 srem 127
49614 82, 65, 67, 84, 69, 210 srem 174
49620 78, 79, 84, 65, 32 srem 123
49626 86, 65, 76, 68, 32 srem 132
49632 67, 79, 76, 219, 32 srem 176
49638 138, 1273, 32,. 247, 183," 201 srem 188
49644 0, 208, 187, 133, 98, 192 srem 15
49658 16, 176, 181, 152, 76, 146 s:rem 61
49656 1935-32, 138, 173, 32, 247 srem 63
49662 183, 178, 192, 8, 246, 9 srem 2908
49668 136, 165, 162, 197, 162, 246 srem 166
496074 252, 208, 243, 224, 8, 240 srem 46
49686 4, 202, 76, 4, 194, 96 srem 119

210
Inside Your 64 5

Program 2. FILL, FCOL, and PAUSE


16 POKE 53281, s:rem 239
20 FOR I=l1 TO 26 srem ll
38 FILL I,1:PAUSE29 srem 74
46 FCOL 15:PAUSE 20 srem 8
5@ FCOL 12:PAUSE 20 srem 6
6@ FCOL 11:PAUSE 26 srem 6
78 FCOL @:PAUSE 208 srem 213
80 NEXT:PAUSE 298:PRINTCHR$ (147) :rem 118

211
Piast
Malis
fog hietage

a hee ss
‘bakg” bs
-: » 7
LOfilttetss
Utilities 6

SuperBASIC 64
Martin C. Kees

How would you like to be able to access 41


valuable new commands when you're program-
ming in BASIC? “SuperBASIC 64” adds sprite,
color, graphics, sound, and memory management
features and enhances eight BASIC commands.
It’s been made even more powerful than the
version which originally ran in COMPUTE!
And it’s designed to work as easily and as
quickly as any ordinary BASIC instruction. Typ-
ing it into your computer is foolproof, for you'll
use the Machine Language Editor (MLX) in
Appendix I. Once you try SuperBASIC, you'll
wonder how you programmed without it—it’s
an especially valuable addition to any owner’s
library of programs. As a bonus, the author has
included additional sample programs which use
SuperBASIC, including “SuperBASIC Sprite Edi-
tor,” found in another section of this book.
2 RAE PEA EE AS

“SuperBASIC 64’’adds commands to BASIC using a special


technique. BASIC is automatically copied to its matching RAM
and modified to change the STOP command to a wedge vec-
tor (similar to Apple’s ampersand (&) wedge). The character
chosen was the left bracket ((). Then, using four-letter
mnemonics following the wedge character, you can select
which SuperBASIC command you want to execute.
These machine language routines make it very easy to
control virtually all the VIC-II chip special features. Sprites
and hi-res graphics can be controlled from BASIC without
having to POKE or use Boolean functions to enable special
graphics modes. Since BASIC was moved to RAM to imple-
ment the [ wedge, this made it convenient to enhance a few
BASIC commands. I added the use of variable expressions for
GOTO and GOSUB, and RESTORE by line number. These

215
6 Utilities

changes to BASIC in RAM don’t slow execution as they would


have if CHRGET wedging techniques had been used.
SuperBASIC Command Format
The commands can be used in either direct or program mode.
The general format is [xxxx <exp>,<exp>... where xxxx repre-
sents the four-character mnemonic and <exp> is a number,
variable, or a valid BASIC expression. Specific syntax for each
command is listed in Table 1, “SuperBASIC Command Sum-
mary.” When a color is selected, use the standard value ordi-
narily POKEd to the VIC chip. I’ve used the same coordinate
system for sprite positions as given in Commodore docu-
mentation. The hi-res upper left corner is 0,0 and the lower
right is 319,199. Commands that switch a function on or off
use 0 for off and 1 for on.
SuperBASIC includes two types of changes to normal
BASIC, enhanced commands and new commands. Enhanced
commands include GOTO and GOSUB and variants with IF
and ON. You can use a line number expression for these com-
mands. This can help in program readability, allowing instruc-
tions such as GOTO KEY when KEY=1000. This would
transfer control to line 1000. RESTORE can also be followed
by a line number expression. RESTORE KEY would cause the
next READ to use the first DATA statements encountered at or
after line 1000. This allows DATA statements to be selected
under program control. Small files could be maintained in
DATA statements and accessed by line number. When LIST-
ing a program, the SHIFT key pauses the list until released.
The ASC function will return a value of zero for null strings.
The new commands can be divided into five categories:
sprite, sound, color control, VIC memory mapping, and graph-
ics control. A convenience command [CATA is also included.
This lists to the screen all mnemonics defined in SuperBASIC.
(I use it to test if SuperBASIC is enabled.)

Loading the Program


To type in SuperBASIC 64 (Program 1) you must use the
““MLX Machine Language Entry Program,’ found in Appendix
I. Be sure you read the explanation in Appendix I and under-
stand how to use MLX before attempting to enter
SuperBASIC.
The numbers you type in create a low memory loader for

216
Utilities 6

SuperBASIC which can be loaded and run as if it were a


BASIC program. Because the data for the SuperBASIC loader
must go into the same area of memory where BASIC normally
resides, a special tactic must be used to prevent the
SuperBASIC data from overwriting MLX as it is entered. First,
turn the computer off and back on to reset memory pointers to
their normal values. Next type in the following line in direct
mode (without a line number) and hit RETURN:
POKE 44,22: POKE 642,22: POKE 5632,0: NEW
This moves up the start of the memory area used by
BASIC so that all of the data for SuperBASIC will fit below
MLX without interference. Now LOAD and RUN the MLX
program in the normal manner. When MLX asks for the start-
ing and ending addresses for SuperBASIC, give 2049 as the
start and 5330 for the end. When you finish typing in the data
for SuperBASIC, use the MLX Save command to store a copy
of the SuperBASIC loader on disk or tape. Be sure to give
MLX a unique name for the SuperBASIC program as it won't
replace a file. If you do not type in all the data for
SuperBASIC in one session, you must repeat the procedure for
moving up the start of BASIC before loading MLX to complete
your entry.
When you have a complete copy of the loader, you must
reset memory to its normal conditions before loading and run-
ning SuperBASIC. You can do this by turning the computer
off and back on, or with the command SYS 64738. When you
run the SuperBASIC loader, it first copies BASIC from ROM
into the underlying RAM and makes modifications to certain
commands. Then it copies the machine language for the rest
of the SuperBASIC routines into memory at $C000-$CC00.
No other machine language subroutines which use memory
starting at $C000 can be used with SuperBASIC 64, but the
DOS Wedge program can be used without conflict. Some of
the graphics commands use memory at $02B0-$02C0 for data
storage. The loader erases itself from the BASIC memory area
after it is run.
The SuperBASIC commands will be enabled until you hit
RUN/STOP—RESTORE or POKE 1,55. Once loaded,
SuperBASIC can be reenabled with POKE 1,54. The programs
you write with SuperBASIC commands are loaded and saved
in the normal manner. The only conflict with normal BASIC is

217
6 Utilities

the use of the STOP command. It is not available; use END


instead. When SuperBASIC commands are listed while
SuperBASIC is disabled, the [|character will print as STOP. If
the [ character is printed and SuperBASIC is disabled, it indi-
cates that the line was entered while SuperBASIC was not in
force. That command will appear correct but will produce a
syntax error on execution.
Sprite Commands
[DSPR [MOVE [KSPR [ESPR [BSPP. These commands
are used in defining sprite characteristics and controlling sprite
movement. [DSPR (Define Sprite) is a general setup command
that initializes a sprite for the VIC-II chip. The ten arguments
in the parameter list (see Table 1) specify most options avail-
able for sprite control. [DSPR enables the selected sprite num-
bered 0-7, stores block address (blk) in current screen pointer
table, expands if xexp or yexp=1, determines initial display
position (xpos,ypos), and sets sprite color registers (sprcolor).
Multicolored sprites are selected by setting multi=1, single
color by multi=0. McO and Mcl are optional arguments in the
list which set up multicolor 0 and 1. [MOVE moves the se-
lected sprite to xpos,ypos. Horizontal values greater than 255
are handled automatically. [KSPR and [ESPR kill or enable the
selected sprite respectively. [BSPP sets the background/sprite
priority for the selected sprite (sel=1 sets background in front
of sprite).
Sound Commands
[SSND [PLAY. These commands access some of the fea-
tures of the SID chip. [SSND (set up sound) produces a sound
from one of the three voices of the SID chip. Voice (1-3)
selects the voice, ad and sr control the attack/decay and sus-
tain/release registers of the selected voice. Wave controls the
waveform, gating, and special effects functions of the sound
chip. Wave, ad, and sr use the same values that would nor-
mally be POKEd to these registers. Freq controls the frequency
of the voice but is a 16-bit value in the range 0-65535. Pwidth
is the pulsewidth value for the pulse waveform and is needed
only when wave=65. Pwidth is a 12-bit value in the range 0-
4095. [SSND sets the volume register to 15. [PLAY is a short
form of [SSND that assumes AD/SR values have been set pre-
viously. Waveform and voice values are coded into the first
parameter argument by wave*256+ voice. Freq and Pwidth are
218
Utilities 6

used the same as in [SSND. [PLAY can be used to silence a


voice; for instance, [PLAY 1,0 would silence voice one.

VIC Color Control


[BKGD [BKG4 [EXTC [FCOL. These commands control
background, border, and text character color. [BKGD sets the
background to the selected color. [BKG4 sets all four back-
ground color registers (used in extended color and multicolor
bitmap modes). [EXTC sets the exterior border to the selected
color. [FCOL (fill color memory) fills the color memory block
with the selected color. This causes all text on the current
screen to be displayed in the selected color. [FCOL is also use-
ful in multicolor bitmap mode to set multicolor pixel color.
VIC Memory Mapping
[BANK [VS1K [CB2K. The VIC-II chip views memory
differently than does the 6510 chip. VIC-II sees only 16K at a
time and maps the ROM character set into part of this 16K
bank at times. These commands allow changes to the normal
locations of the screen and character sets. [BANK selects which
one of the four banks (0-3) the VIC-II chip sees. Normally this
is bank 0. [BANK resets the pointer BASIC uses to locate the
screen. [VS1K (Video Screen 1K block) determines which 1K
block of the 16 available is used for the text screen.
The blocks are numbered 0-15. The BASIC screen pointer
is reset for this location. [CB2K (Character Base 2K block) con-
trols which 2K block of the eight available is used for the
character set. The blocks are numbered 0-7. In banks 0 and 2
the ROM set is located at 2K blocks 2 and 3. [CB2K is also
used to select which 8K block is used for the bitmap screen.
Values 0-3 select the lower 8K block, values 4—7 select the up-
per 8K block.
These three commands must be used in coordination to
smoothly relocate the screen. Caution must be exercised in
selecting locations since a system crash will result if the screen
overwrites important RAM such as page zero. Banks 2 and 3
must be used with great care. More on bank 3 usage later.
Program 7 demonstrates relocation to PET standard loca-
tions for the screen and BASIC.
Graphics/Text Control
[ECGR [MCGR [BMGR. These commands select
extended color, multicolor, or bitmap graphics mode. A value of
219
6 Utilities

0 turns the mode off and a value of 1 turns the mode on.
Only multicolor and bitmap work in conjunction with each
other to form a combined mode. When extended color and
bitmap are both on, the screen will appear blank. This effect
might be useful for temporarily hiding the screen.
[MXGR [KMXG [CMXV. These commands set up a sim-
ple interrupt routine that allows mixed modes to appear in
two sections of the screen. [MXGR will change the contents of
one VIC register (reg) or part of the contents (the bits OFF in
mask) each time the raster counter equals one of the two ras-
ter select values (rastl and rast2). The values in vall or val2
will be stored into the selected VIC register. You must deter-
mine the appropriate value for the particular register. For
example, [MXGR 33,240,152,6,252,1 will cause screen lines 49
to 151 to be displayed with background white (color=1) and
lines 152 to 250 with background blue.
The visible portion of the screen extends from raster 49 to
raster 250 (Commodore documentation says 51-251). [KMXG
will kill the interrupt and leave the selected register in an un-
known state. [CMXV (Change Mixed-mode Values) allows
changing vall and val2 while mixed mode is in force. By set-
ting them equal, a known state will be in effect after [KMXG.
You should not attempt tape or disk I/O while [MXGR is in
force. [|MXGR mode shouldn’t be used in bank 3 VIC mapping
if hi-res graphics commands are to be used.
It’s possible to set up a text window at the bottom of a hi-
res screen using [MXGR. The difficulty is that [MXGR only can
change one VIC register. Thus the character base pointer can’t
be changed as well as the bitmap select bit by [MXGR. This
can be solved by locating the character set within the hi-res
screen, and putting a text window over the top of the charac-
ter set.
A six line text window at the bottom of the hi-res screen
can easily be created using this technique. In bank 0, using the
upper 8K hi-res block, you would first use [CB2K 7 to select
both the upper 8K hi-res block and the seventh 2K character
set block. Then clear the hi-res screen with [FBMS 0 and
download a character set to starting location 7*2048. [MXGR
17,223,0,32,201,0 will complete the setup.
[SIZE [XYSC. These commands help use the smooth
scroll registers of the VIC-II chip. [SIZE selects 40 or 38 col-
umns for the text display chosen by setting colsel to 1 or 0

220
Utilities 6

(colsel=1 selects 40 columns) and sets the number of lines to


25 or 24 (rowsel=1 selects 25 lines). [XYSC moves the entire
text screen horizontally or vertically up to seven pixels. By set-
ting xpos and ypos to a value in the range 0-7, the screen can
be stepped up a pixel at the time to produce a smooth scroll.
When used in conjunction with a machine language scroll rou-
tine or the automatic scroll up, text can be scrolled smoothly
across or up the entire screen.
[DLCS. [DLCS (Download Character Set) assists in using
banks without ROM character set images and in designing
custom character sets. You can copy the uppercase graphics
set, upper- and lowercase set, or both by setting the set equal
to 0, 1, or 2 respectively. This is followed by the address of
the first location in memory where you wish the ROM set
copy to be positioned. This should be on a 2K boundary un-
less you wish to change the order of the set. When the ad-
dress is 53248, the set will be copied into the RAM beneath
the ROM set for use in bank 3.
[FBMS [FSCR. The current hi-res screen (determined by
the last [CB2K command) can be filled with any byte value
with [FBMS (Fill Bitmap Screen). [FSCR works in a similar way
with the current text screen. The entire screen is filled with a
byte value. Since the text screen is used for color control in hi-
res mode, [FSCR can be used for hi-res color control.
[PLOT [FLIP [CLPX [MCPL. These commands are used
in plotting pixel points in hi-res graphics modes. The first
three plot in 320 x 200 resolution two-color mode, the last in
160 x 200 resolution four-color mode. [PLOT sets the selected
pixel on, [CLPX turns the pixel off, and [FLIP changes the
pixel to the opposite state. [MCPL (Multicolor Plot) accepts
horizontal coordinates in the range 0-159.and plots in one of
four colors determined by sel with sel in the range 0-3. A
value of 0 selects background color, 1 selects text screen low-
nybble color, 2 selects text screen high-nybble color, and 3
selects color memory color. Before you execute any of the
plotting commands, [CB2K must be used to select the appro-
priate 8K block and [BMGR 1 must be in force for the plot to
be seen. Remember that y coordinates increase as you go
down the screen.
[DRAW [UNDR [FLLN [DRW2 [SETP. These commands
are used to draw and erase lines to and from the hi-res screen.
[DRAW, [UNDR, and [FLLN require a parameter list containing

221
6 Utilities

the start and end points of a line segment. The line is


drawn from x1,y1 toward x2,y2. These commands plot the line
in three modes. [DRAW turns on the pixels of the line, [UNDR
turns off the pixels of the line, and [FLLN flips the state of the
pixels of the line. The three commands also set the mode of
drawing for the [DRW2 command and save the last plotted
point position in a pen position register. [DRW2 (Draw to)
only uses an end point in the parameter list. The starting point
is obtained from the pen position register contents set by a
previous [DRAW, [FLLN, [UNDR, or [SETP command. [DRW2
will plot, flip, or erase the line depending on which line draw-
ing mode was last used. [SETP stores the given x1,y1
coordinate in the pen position register.
[HRCS [CHAR [CHRX [CODE. These commands make it
easy to put text on the hi-res screen. [HRCS (Hi-Res Character
Set) stores the address for the character set to be used. It need
not be located on a 2K boundary or even be the same set as
used on the text screen. The address supplied is of the first
byte of the set. A value of 53248 will select the ROM set
(upper/graphics). [CHAR and [CHRX plot an 8 x 8 character
to a selected position on the current hi-res screen.
The character code (char) to select which character to plot
corresponds to the screen POKE codes listed in Appendix G.
Example: [CHAR 1,100,100 would plot the letter A with po-
sition 100,100 being the upper left corner of the 8 x 8 charac-
ter cell. [CHAR plots the cell to the hi-res screen absolutely
while [CHRX uses the exclusive OR function to flip the cell
pixels. So [CHRX can be used to unplot a previously plotted
character. [CODE helps in translating to the screen POKE code
used by [CHAR and [CHRxX in character selection.
The argument for [CODE must be the name of a defined
string variable. Upon execution, the ASCII values stored in the
string will be converted to screen POKE codes. The RVS ON
and RVS OFF control characters can be used within the string
to select the upper 128 or lower 128 characters of the set. All
other control characters will produce unpredictable results.
Once the string is converted using [CODE, use the ASC func-
tion and MID$ function to read the codes. The ASC function
will give correct results for the 0 character of the set. Be care-
ful when using strings not built to high memory because
[CODE will modify the actual string data stored within the
BASIC text area.

222
Utilities 6

[HRAM [LOOK [STUF. These commands make use of


[BANK 3 possible from BASIC. When bank 3 is selected, the
VIC-II chip uses RAM from $C000 to $FFFF and ignores ROM
located at the same addresses, including the ROM character
set. SuperBASIC allows the location of one text screen ([VS1K
3 located at $CCO00) in bank 3. RAM from $D000 to $FFFF can
be used for character sets, sprites, and a hi-res screen.
The main problem confronting the bank 3 user is the
switching required to read and write to these RAM locations.
All plotting commands need to read, as well as write, to RAM.
These commands can be preceded by [HRAM to accomplish
this in bank 3. No embedded banks are allowed following
[HRAM and the selected mnemonic. For example,
[HRAMDRAW 1,0,100,100 would be used to draw a line to
the hi-res screen at $E000 under the Kernal ROMs. [HRAM
should be used in this manner with [PLOT, [FLIP, [CLPX,
[MCPL, [DRAW, [UNDR, [FLLN, [DRW2, [CHAR, and [CHRX
in bank 3. Using the first 3K of bank 3 will crash SuperBASIC,
so make sure the text screen is relocated by [VS1K 3. When
the transition to bank 3 is made, the 1K block at $0400 can be
reclaimed for BASIC program storage. [LOOK and [STUF are
PEEK and POKE equivalents that can be used with [HRAM to
examine and change RAM. [LOOK is different from PEEK in
that a defined variable name is used in the parameter list to
return the value read from memory. [STUF works the same as
POKE and is primarily useful for storing to block $D000 RAM
(for example, [HRAMSTUF 53248,255 writes to RAM under
the VIC chip).

Using the Commands


Errors in SuperBASIC commands will give the syntax error
message. One difficult error to detect occurs when an embed-
ded BASIC keyword is constructed by part of the command
mnemonic and the following parameter. [KSPR INT(X) looks
like a valid command but BASIC will find the PRINT ({KSPR
INT(X)) and tokenize it. Syntax errors are particularly frustrat-
ing if you are in hi-res mode when the error occurs. The mes-
sage will appear as a set of colored blocks on the screen and
you will have to type blindly to get back to text mode. It helps
to include a line in your programs that restores text mode so
that you only need to type a GOTO xxx.
RUN/STOP—RESTORE will kill SuperBASIC. It can be

223
6 Utilities

reenabled with POKE 1,54 most of the time. You should be


careful when you have changed banks and screen locations. A
RUN/STOP—RESTORE will not reset the default video map
so you might wipe out page zero or other important RAM.
SuperBASIC Creations
Using SuperBASIC’s powerful functions, you can create com-
plex programs much more easily than you thought possible.
The following programs demonstrate SuperBASIC in action.
Some, such as Programs 2 through 7, are simple BASIC pro-
grams which show how you can use SuperBASIC to create
impressive graphic displays, joystick-controlled sprites which
draw patterns on the screen, or animated sprites. Another pro-
gram which uses SuperBASIC, “SuperBASIC Sprite Editor,” is
more complicated, and thus longer. The program is included
in another section, “Colors, Characters, and Motion.” All are
worth the time it will take you to type them in.
Remember that all the following demonstration programs
will only work if SuperBASIC has already been loaded and
run. As you type these programs in, you'll come across
strange-looking commands, such as [DLCS or [FCOL. Don’t
worry, the program listing is correct; this is how SuperBASIC
notes its new commands. Every time you see the [|symbol, just
press the SHIFT and colon keys together. This will give you
the bracket symbol on the screen. Type in the rest of the com-
mand (DLCS, for instance) as you would any other command
on the 64.
Although most of these programs can be used without
much explanation, since prompts appear frequently on the
screen, ‘Type 64’ does need some further description to enter
and run properly. Remember, all of these programs require
SuperBASIC in memory to operate. If you haven’t entered and
saved a copy of SuperBASIC, Program 1, do that first.

Type 64
Using these two programs, you can turn your 64 into a 64-
column display. No hardware adjustment is necessary; the
programs create a new character set that is smaller than the
one usually seen on the 64. The letters are still easy to read,
and actually look quite nice, especially when you change the
background color so that it contrasts with the new set.
224
Utilities 6

This is a two-part program. Type 64, Program 8, is in


SuperBASIC, and actually loads and operates the character set.
Program 9, “64SET,” is the new character set which turns your
screen into a 64-column display.
First, type in Program 10. Since it’s in SuperBASIC, you
shouldn't have any problem if you’ve read and understood
this articie. In the listing, you'll come across SuperBASIC com-
mands which always begin with the bracket symbol ([). When-
ever you see this character, press SHIFT and the colon keys at
the same time; that will produce a [ symbol on the screen. The
rest of the command (FCOL for instance) you can enter nor-
mally, of course. Once you’ve SAVEd the program, you can
begin entering 64SET. You'll notice that it’s in machine lan-
guage, so you'll be using the MLX program from Appendix I
again. The starting and ending addresses for 64SET are:
Starting address: 32768
Ending address: 34819
Before you LOAD MLX and begin typing in 64SET, enter the
following line in direct mode (without line numbers). This
moves BASIC and ensures that it will not interfere with the
entry of 64SET. If you type in 64SET in several sessions, make
sure you enter this line before loading and using MLX.
POKE 56,128:CLR
Enter 64SET as you would any other program which uses MLX.
When you’re through, SAVE it to disk, using the filename
64SET. Make sure that this is the filename you use (no spaces
between 64 and SET—SET in uppercase); if you name it
something else, Program 8 won't be able to load and use it. Be
sure that both Program 8 and Program 9 are on the same disk.
When both programs are on one disk, type LOAD’’ TYPE
64’’,8 and then RUN it. It will load the character set automati-
cally. All you have to do is type on your new 64-column
display.

225
6 Utilities

Tablel. SuperBASIC Command Summary


Enhanced BASIC Commands
RESTORE <exp>
GOTO <exp>
IF <exp> GOTO <exp>
IF <exp> GOSUB <exp>
ON <exp> GOTO <exp1>,<exp2>....
ON <exp> GOSUB <exp1>,<exp2>.,...
LIST (Shift Key halts list)
ASC(str$) returns 0 for null string
New SuperBASIC Commands
Sprite Commands
[DSPR spr,blk,xexp,yexp,xpos,ypos,multi,sprcolor,Mc0,Mc1
[MOVE spr,xpos,ypos
[KSPR spr
[ESPR spr
[BSPP spr,sel
Sound Commands
[SSND voice,ad,sr,wave,freq,pwidth
[PLAY 256*wave + voice,freq,pwidth
VIC Color Control
[BKGD col
[BKG4 col0,col1,col2,col3
[EXTC col
[FCOL col
VIC Memory Mapping
[BANK sel
[VS1K sel
[CB2K sel
Graphics/Text Control
[ECGR sel
[MCGR sel
[BMGR sel
[MXGR reg,mask,rast1,val1,rast2,val2
[KMXG
[CMXV vall,val2
[SIZE colsel,rowsel
[XYSC xpos,ypos
[DLCS set,address
[FBMS byte
[FSCR byte
[PLOT x,y
[FLIP x,y
[CLPX x,y

226
Utilities 6

[MCPL x,y,sel
[DRAW x1,y1,x2,y2
[UNDR x1,y1,x2,y2
[FLLN x1,y1,x2,y2
[DRW2 x2,y2
snip xy?
[HRCS address
[CHAR char,x,y
[CHRX char,x,y
[CODE str$
[LOOK address,variable
[STUF address,byte
[HRAM <SuperBASIC mnemonic> <parameter list>

Program 1. SuperBASIC 64
2649 :811,008,008,0090,158,058, 228
2055 2848 ,8956,948,009,900,900,159
2861 : 900,060,000 ,900,899,899,813
2867 2900 ,000,000,0900,900,800,919
2873 2009 ,000,009,009,080,809,9825
2879 :900,169,039,133,901,169,830
2285 :890,133,020,133,878,169,058
2091 :8899,133,021,169,192,133,188
2097 :979,162,012,160,990,177,127
2183 2920,145,078, 200, 208,249,187
2189 2230,021,230,8979, 202,208,007
25 3242,160,988,169,104,9032,914
2020. :830,171,169,013,141,119, 204
2127 :002,141,120,902,169,982,9083
2133 2133,198,169,133,141,001,992
21539 :908,169,020,141,902,908,183
2145 :076,128,088,080,808,009,845
2151 2960 ,031,147,017,017,048,107
2S) :@17,157,982,085,878,819,835
2163 2900 ,9080,0909,89008,800,169,828
2169 :969,133,0929,169,169,133,224
2175 :921,162,032,168,000,177,167
2181 :020,145,8020,136, 208, 249,143
2187 3230,021,202,208,244,162,182
2193 :900,168,003,185,224,169,199
2199 2157,224,160, 232, 200,224,968
2265 2199, 208, 244,169,983,141,888
Zonal :161,168,169,192,141,162,132
PAPI | :168,169,074,141,219,166,973
VAP APNE 2169,193,141,211,166,141,172
2229 :837,168,169,884,141,036,8049
6 Utilities

2235 :169,169, 219,141, 223,160,235


2241 :169,255,141,044,169,169,197
2247 2194,141,945,169,169,038,178
2253 2133,001,169,0905,141,143,829
2259 :183,169,976,141,943,169,224
2265 :141,087,169,169,193,141,993
2271 :045,169,141,989,169,169, 237
2277, :200,141,988,169,169,227,199
2283 2141,844,169,896,908,800,173
2289 2960 ,0008,890,009,09090,008, 241
2295 2900, 008,800,000 ,8900,800,247
2381 2860,009,9909,032,115,900,144
23987 2832,158,173,932,247,183,960
2313 :896,032,139,192,8032,000, 244
2319 2192,165,920,166,902,157, 205
2325 2248,007,032,008,192,165,153
2331 29@20,162,029,032,162,192,112
2337 2032,000,192,165,9290,162,092
2343 :6@23,032,162,192,032,997,965
2349 :192,032,000,192,165,929,134
2355 2972.,162,928,932,162,192,187
2361 2032,000,192,165,829,166,126
2367 :902,157,039,208,184, 248,645
2373 2117,032,009,192,165,928,983
2379 :141,037,208,032,008,192,173
2385 :165,029,141,938, 208,169,954
2391 :901,162,021,032,162,192,145
2397 3896,032,139,192,832,900,872
2493 2192,165,921,072,165,920, 222
2499 2972,032,000,192,165,982,056
2415 :918,179,232,165,920,157,9897
2421 2 869,208, 202,1984,157,989,029
2427 2208,104,162,916,932,162,939
2433 2192,169,6009,141,9030,298,191
2439 :141,031,208,896,932,9090,131
2445 :192,165,929,041,007,133,187
2451 :002,170,169,901,224,800, 281
2457 :249,094,019, 202, 208,252,845
2463 :133,078,096,164,078,201,141
2469 2@690,248,806,152,929,880,080
2475 2208, 208,006,152,073,255,849
2481 :961,008,208,157,889, 208,943
2487 2896, 008,007,914,8032,819,895
2493 2199, 249,158,032,000,192,234
2499 2165,920,941,9803,178,189,9815
2585 2183,192,133,978,169,212,144
2511 2133,079,032,000,192,165,949
2517 2:020,168,895,145,0978,832,141
2523 :900,192,165,820,169,896, 2508

228
Utilities 6

2529 2145,078,032,828,193,165,998
2535 :928,133,902,160,904,145,183
2541 2878,932,037,193,169,815,249
2547 2141,024,212,996,032,800, 236
2553 2192,165,029,8941,003,179,8072
2559 3189), 188), 192),833),Olio. LOLs
2565 :212,133,879,165,021,133, 236
2571 :902,169,988,168,984,145,235
250i, 2078,%932,037,193,165,082,812
2583 :168,984,145,978,996,169,163
2589 :800,168,004,145,878,976, 236
2595 :800,192,8032,8900,192,165,164
2681 :@21,169,001,145,078,165,999
2607 38@20,136,145,978,165,9092,981
2613 :201,965, 208,816,932, 090, 863
2619 :192,165,621,041,015,160,141
2625 :903,145,978,165,929,136,1980
2631 2145,878,996,173,141,992,194
2637 :208,251,8976,044,168,976,132
2643 2929,168, 248,251 ,932,003,938
2649 2192,032,019,166,056,165, 207
2655 2995,233,801,164,996,176,892
2661 :901,136,133,965,132,966,122
2667 :996,032,008,192,160,808,975
2673 :177,028,133,002,032,115,880
2679 :890,032,048,175,164,902, 820
2685 :169,960,932,145,179,166,048
2691 :@71,164,072,932,215,187,194
2697 :896,032,000,192,165,820,139
2763 2133,078,165,921,133,979, 2408
2789 :832,000,192,165,928,160, 296
275ES :980,145,978,996,173,014,149
2724 2220,041,254,141,014, 220,027
2727 2165,901,941,253,133,881,249
2733 :169,193,972,169,184,972,988
2739 2:0@32,115,8000,8976,809,195,985
2745 2:165,001,909,902,133,801, 240
275 2173,814,220,009,9001,141,237
20D, 2@14,228,8996,165,181,133,158
2763 :254,194,133,802,198,254,124
2769 2208,005,165,002,976, 239,136
2075 :167,032,8909,192,032,121,247
2781 2960, 201,944, 248, 237,996,815
2787 :032,121,808,201,137,208,158
2793 2:083,076,055,169, 201,141,119
2/99 2249, 249,076,8050,169,932,831
2865 2115,000,076,245,196,849,158
2811 :0@00,060,129,800,900,077,201
2817 :879,8086,969,993,192,868,976

229
6 Utilities

2823 :983,988,882,1801,196,083,120
2829 :083,8978,068,191,192,889,193
2835 2076,965,889, 246,192,966, 241
2841 :875,071,968,956,195,969,847
2847 2988 ,984,967,965,195,975,993
2853 :983,988,082,974,195,869,198
2859 2983 ,088,982,984,195,966,121
2865 :083,088,880,992,195,983,158
2871 :984,985,070,137,193,969,181
2877 :967,071,082,125,195,8077,166
2883 :967,971,082,159,195,866,186
2889 :977,871,8082,175,195,083, 244
2895 :973,098,869,187,195,988,813
2981 :@89,083,867,211,195,967,929
29087 265,984,965, 258,195,066, 048
2913 :965,978,975,053,196,986,138
2919 2983 ,049,975,113,196,967,174
2925 :866,959,875,151,196,968, 283
2931 :976,067,983,172,196,977,818
2937 :888,071,882,965,197,975,187
2943 :077,9088,071,180,197,967,939
2949 :877,988,986, 208,197,879, 083
2955 :867,979,876,217,197,888,987
2961 :976,079,984,130,198,979,014
2967 :076,073,080,122,198,967,255
2973 :076,088,888,138,198,977,046
2979 :967,088,876,148,198,979,934
2985 :083,967,082,197,198,979, 898
2991 266,977,083, 232,198,968,131
2997 :@82,965,887,023,203,072,201
3903 :082,967,983,968,201,8967,235
3989 :872,965,082,134, 202,967,047
3015 :972,082,088,142, 292,967,884
3021 :079,068,869,159, 202,976,681
3027 2079,079,875,197,193,866,042
3833 :875,071,052,195,195,8072,919
3039 2982,965,077,158,193,879,180
3045 :976,076,078,029, 203,985,255
3051 :978,068,982,047, 283,868,813
3057 :982,987,950,078, 203,083,848
3963 2969,084,980,187,203,255,821
3269 2255,255,255,162,9890,134,934
3075 :992,160,9000,177,122,221,173
3681 :0@09,194, 298,626, 232,298,101
3987 3192,004,208,243,189,001,9884
3893 :194,972,189,900,194,072,230
3099 :165,122,024,195,993,133,967
3185 2122,144,902, 230,123,996, 238
3111 2165,902,024,105,8996,133,218

230
Utilities 6

3117 :002,178,189,8000,194, 201,033


3223 :255,208,206,996,009,08080,848
3129 :032,099,192,165,929,141,995
3135 :933,298,896,032,909,192,112
3141 :165,020,141,9832, 208,996,219
3147 2932,139,192,169,900,162,801
3153 :021,876,162,192,832,139,191
3159 2192,162,921,876,162,192,124
3165 :932,139,192,032,008,192,168
S72 :165,820,162,027,976,162,199
3177 :192,162,008,134,902,032,115
3183 :000,192,165,920,166,902,144
3189 2157,033,208,232,224,004, 287
3195 2288, 239,996,932,980,192,122
3281 2165,020,162,017,168,9064,295
3267 2:932,164,192,165,920, 240,180
3243 2239,169,800,162,022,169,125
3ZU9 :916,876,164,192,932,000,115
3225 :192,165,820,162,922,1690,196
3231 2@16,832,164,192,165,928, 236
3237 :249,214,169,000,162,017,199
3243 :160,964,076,164,192,032,9091
3249 :990,192,165,920,162,017,221
3255 :160,032,076,164,192,832,971
3261 2:@99,192,165,020,162,922, 238
3267 :160,988,032,164,192,832,915
3273 28@00,192,165,929,162,917,245
3279 :160,088,976,164,192,032,971
3285 2960,192,165,029,041,007,126
3291 :133,920,173,022,208,941,048
3297 2248,905,8020,141,9022,208,191
3383 2932,800,192,165,6208,8041,169
3309 :097,133,029,173,9017,208,927
3305 :941,248,905,028,141,817,283
3321 :208,996,169,032,141,989,127
332i% :062,162,908,142,0905,802,856
33:33 2134,902,173,141,002, 208,153
3339 :251,160,8008,189,909,194,037
3345 :153,801,002,232, 200,192,829
3351 2904, 208,244,169,909,160,942
3357 :902,032,030,171,165,082,175
3363 :024,195,896,133,082,170,219
3369 :189,060,194,201,255,208,864
3375: 2215,032,115,808, 208,251,100
3381 :996,173,002,221,89899,883,845
3387 :141,902,221,8032,900,192,135
3393 :165,820,041,003,872,9073,183
3399 :983,133,820,173,980,221,189
3465 2941,252,085,8020,141,900,924
6 Utilities

:221,104,024,106,196,196, 238
2133,928,173,136,902,041,082
:963,005, 020,141,136, 002, 206
:096,173,136,902,924,185,125
:093,141,022,192,876,818, 939
:192,032,000,192,165,828, 202
:041,863,919,010,133,928,140
:173,136,002,041,192,005,162
:920,141,136,902,165,028,193
:018,819,133,020,173,924,251
:208,941,015,985,928,141,961
2024, 208,096,173,824, 208,114
:941,241,133,882,932,900,092
:192,165,829,041,007,019,084
2985 , 802,141,824, 208,096,131
:173,814, 226,041, 254,141,248
:014,220,165,901,941,251,183
:133,0881,032,800,192,165,196
:020,0841,003,162,808, 201,114
: 002, 288,002,162,816,168, 235
:208, 201,001, 208,002,160,215
:216,132,079,160,800,132,1608
:978,134,002,932,000,192,141
:166, 882,168, 800,177,078,036
:145,020, 200,208, 249, 230,255
2021, 238,879, 202, 208, 242,191
:165,981,009, 004,133,001, 040
2173,814, 220, 809,081,141,935
2014, 228,096,920, 998,154,223
: 000, 826, 252,009,906, 089,009
2033, 240,234, 234,173,006,159
:197,873,983,141,996,197,118
:178,189,258,193,141,964, 902
:197,172,087,197,185, 009,015
2298, 045 ,008,197,829,002, 008
:197,153,809,208,173,917,817
:208,041,127,829,901,197,134
:141,817, 208,189, 888,197,833
:141,818,208,169,001,141,221
2025, 208,076,129, 234,128,085
:169,000,141,814, 220,032,131
:200,192,165,920,141, 007,986
:197,032,000,192,165,820,173
:141,008,197,932,0828,192,143
:165,920,141,903,197,165,914
:021,841,001,248,002,169,959
:128,141,004,197,032,000,993
:192,165,020,141,902,197,0858
:032,908,192,165,828,141,153
Utilities 6

3785 :900,197,165,921,941,901,934
sigue :240,002,169,128,141,981,840
3717 :197,032,000,192,165,026, 227
3723 2141,905,197,173,017,208,112
B29 :941,127,8013,004,197,141,156
3735 2917,208,173,903,197,141,122
3741 :@18,208,169,903,141,906,199
3747 2197,169,241,141,926,298,121
17/58) :169,811,141,929,993,169,170
S/S) :197,141,921,0803,088,896, 209
3765 :120,169,949,141,929,003,171
3771 2169, 234,141,921,003,169,156
S714 2249,141,926, 288,988,976, 284
3783 :244,193,032,900,192,165,901
3789 2920,141,002,197,032,0800,085
3795 2192,165,920,141,905,197,163
3861 2996,832,9060,192,165,029, 219
3807 2941,015,162,098,157,988, 886
3813 :216,157,908,217,157,8608, 208
3819 :218,157,008,219,232,208,245
3825 ?241,141,134,002,996,932,119
3837 2900,192,165,820,041,907,160
3837 :133,902,165,8020,041, 248,094
3843 TUBS 291 PLOS JO2 pls, 22 plow:
3849 2032,008,192,165,8929,133,939
3855 :078,8041,248,133,9290,133,156
3861 3253,169,009,133,254,024,986
3867 2906, 253,038,254, 996,253,869
3873 2838,254,165,020,101, 253,996
3879 2133,253,144,002, 239,254,031
3885 2024,6006, 253,038, 254,906,114
3891 2253,938,254,996, 253,938,125
3897 :254,165,078,041,9087,905,995
3983 3253,133, 253,924,165, 251,118
3989 2101,253,133, 251,165,252, 200
S915 2191,254,133,/252,173;,136,7100
so20 :@62,041,192,0805,252,133,194
S227 2252,173,024,208,941,988,925
3933 219,019,005, 252,133, 252,243
3939 :166,902,189,107,198,168,153
3945 :909,096,128,964,932,816,185
3951 :908,964,002,901,192,948,118
3957 :@12,003,000,885,179, 255,130
3963 2032,246,197,981,251,145,9851
3969 2251,096,032, 246,197,817, 22808
3975 2251,145,251,996,932, 246,132
3981 2197,973,255,8049,251,145,887
3987 2251,896,032,000,192,165,115
3993 2920,941,093,024,185,068,998

233
6 Utilities

2133,962,906,028,838,921,123
2@32,255,197,133,982,032,9848
:980,192,165,020,041,803,980
:170,189,119,198,837,902,124
2133,820,165,062,073,255,963
:160,0909,949,251,005,920,162
2145, 251,096,932,900,192,143
:173,136,002,133,252,169,942
:900,133,251,168,162,983,156
2165,029,145,251, 299,288,178
2251,238,252,202, 208,246,972
2145, 251,209,192, 232,288,173
2249,096,8932,9809,192,173,295
2136,002,041,192,133,252,225
2173,024,208,841,888,918,195
2910,005, 252,133, 252,169,046
:900,133,251,162,932,168,225
:609,165,09208,145, 251,209,918
2208, 251,238,252, 282,208,982
2246,096,032,121,909, 208, 298
:901,096,1904,104,976,978,218
:192,169,000,141,176,902,197
2141,178,002,141,179,002,166
2173,167,902,9013,168,962,854
2298,982,056,996,162,024,083
2846,176,002,946,177,902, 246
2946,178,902,946,179,962,989
:056,173,178,982,237,167,118
:902,168,173,179,982,237,864
3168,902,144,9086,140,178, 2983
2002,141,179,802,202, 208,949
2219,8946,176,002,046,177,243
2962 ,024,8996,832,900,192,185
2165,920,141,193,002,165,9819
2921,141,194,902,932,000,241
:192,165,020,141,197,902,962
:932,900,192,165,020,141,157
:195,002,165,021,141,196,077
2902 ,032,000,192,165,928,939
2141,198,802,169,900,141,020
:202,002,956,173,198,8082, 9088
:237,197,082,141,199,902,159
:176,014,169,255,141, 202,888
:082,077,199,002,141,199,813
2082, 238,199,802,169,908,909
2141, 203,002,056,173,195,175
3082, 237,193,062,141,208,186
2962,173,196,082, 237,194,221
28@02,141,201,962,176,927,228
Utilities 6

2169,255,141, 203,982,077,820
:200,002,141,200,002,169,149
2255,077, 201,082,141, 201,962
:802,238,28080,8002,2808,0083,190
:238,281,002,169,900,141, 204
2204,982,173,199,882,205, 244
:200,002,169,8000, 237,201,818
:@82,176,076,173,199,002,999
:208,005,141, 205,002, 248,022
2:105,141,177,902,173,200,025
3:0@02,141,167,062,173,201,175
:902,141,168,002,169, 255,232
2141,205,002,032,038,199,119
:144,983,9076,058,201,173,162
3176,002,013,177,9802, 208,991
3@20,169,255,141,176,002,626
:141,177,002,169,866,141,155
:298,9862,169,025,141,289,829
:862,2808,049,169,909,141,196
:208,962,141,209,902,240,989
:839,169,255,141, 204,902,193
2173, 200,002,8024,189, 281,008
:962,248,171,173,199,982,092
2141,167,902,169,900,141,187
:168,092,173,209,962,141,9983
:177,962,169,255,141,205,016
:0@02,876,816, 200,238, 208,9061
:062,238,199,002,173,193,142
:8@82,041,007,133,962,173,211
2193,002,041,248,133,251,215
2173,194,002,133,252,173,924
:197,002,032,014,198,017,875
2251,145,251,173,284,0802,135
:208,895,173,283,0982,248,036
:816,056,173,193,982,233,958
:901,141,193,982,176,913,165
:206,194,002,144,908, 238,181
2193,882,208,083,238,194, 233
:862,056,173,200,062,233,067
2901,141,200,002,176,9003,186
2206, 201,0902,024,173, 280,219
2902,189,281,802, 248,128,993
2173,205,002,248,165,024,234
2173,176,802,1809, 208,902,181
:141,208,082,173,177,002,140
2199,299,062,141,209,902,115
7144,144,173, 202,902,248, 998
20906, 286,197,902,076,197,949
:200,238,197,082,876,197,825

235
6 Utilities

2200,173,2802,002,240,8096,934
:206,197,8002,076, 259,208,148
3238,197,082,206,199,802,867
2249,958,173,205,082, 246,147
2940,024,173,176,002,199,015
:208,002,141,208,982,173,231
:177,982,199,209,8902,141,143
2289,002,144,019,173,283,083
3@02,246,817,956,173,193,196
:@02,233,001,141,193,982,093
:176,903,206,194,002,076,184
:107,209, 238,193,902, 208,225
2248, 238,194,802, 208, 243,160
:896,198,122,8096,932,889,9089
2192,165,920,141,975,201,989
2165,021,141,976, 201,996,001
:143,183,000,169,000,141,199
:193,062,141,196,9092,932,135
:900,192,165,920,141,197,034
3002,0932,000,192,169,956,932
:197,020,169,001,229,821,224
2176,905,169,255,141,193,820
2002,165,8920,041,007,133,223
:962,165,0920,941, 248,133,214
2251,165,921,133, 252,932,209
:808,192,169,192,197,829,131
2176,965,169,255,141,196,953
:@62,165,820,041,007,141,905
2194,002,141,195,982,165,978
:820,032,014,198,165, 251,965
2941, 248,133,251,173,197,178
:002,133,920,169,000,133,1190
2021 ,086,620,938,821,906,027
2620,038,021,086,09209,938,064
2921,924,173,975,201,191,010
:@20,133,020,165,021,109,145
2976, 201,133,021,024,165,947
2251,105,008,141,177,902,117
2165,252,195,000,141,178,024
:@02,165,021,041, 208,201,083
:208,288,007,128,165,981,169
2841,251,133,801,169,009,052
:141,176,992,166,902, 240,199
:005,056,106, 202, 208,251,041
2141,179,062,172,176,902,147
:177,920,166,002, 240,004,990
2074, 202,288,252,932,077,9876
2202, 208, 238,944,193,8902,124
2948,956,856,169,908, 229,965
Utilities 6

4881 :902,133,002,201,908, 240,091


4887 2:845,173,177,962,133,251,936
4893 2173,178,002,133,252,169,168
4899 :@00,141,176,902,173,194,299
4965 :902,141,195,002,173,179,221
4911 2902,8073,255,141,179,802,187
4917 :172,176,902,177,820,166,254
4923 2902 ,9010,202,208, 252,032,253
4929 2077,202,208,249,169,004,197
4935 2905 ,901,133,901,088,996,139
4941 :172,195,902,944,977,201,090
4947 2948,012,133,254,173,179,114
4953 :082,849, 251,005, 254,876,214
4959 :999,202,081,251,145, 251,180
4965 :200,148,195,002,192,0908,879
4971 2208,917,160,964,140,195,123
4977 :002,230,252,944,196,082,071
4983 :916,805,169,087,141,176,121
4989 2:902,238,176,002,173,176,124
4995 :902,201,008,096,169,900,895
5061 2141,077,261,976,878,201,143
5867 2169, 255,141,877, 201,076,938
5813 :978,201,032,115,989,032,995
5819 :9@48,175,234, 234, 234,234,926
5925 2234,234,165,971,133,0286,258
5831 :165,972,133,021,160,900, 206
5637 2177,9029, 249, 213,956,165,820
5843 2020, 233,002,133,028,176,251
5649 :9602,198,021,177,829,197,832
5855 2969, 208,196, 200,177,028, 037
5861 :197,078, 208,189,169,003,900
5667 :177,020,133,251, 200,177,137
5973 :020,133,252,169,8800,133,148
5679 2253,133,002,133,254,160,126
5985 2:969,177,071,170,164,902,937
5691 :177,251,201,918,2988,907,865
5997 :169,128,133,253,976,069, 233
5193 :203,201,146, 208,90807,169,149
5199 :900,133,253,8976,069, 203,151
SS 2941,191,816,902,973,192,254
plat :005,253,164,254,145, 251,049
DIZ), 2230,254,230,002, 202,208,199
5133 :211,165,254,160,0909,145,180
5139 :971,896,169,981,044,169,137
5145 2017,141,132,209,976,998,177
spdsyl :199,169,949,141,132, 298,153
opspy 2169,065,141,139, 290,169,143
5163 2203,141,131,200,096,032,978
5169 2@32,203,032,998,199,169,914

237
6 Utilities

5175 :914,141,130,200,169,198,139
5181 :141,131,200,996,032,014,163
5187 :198,973,255,996,173,195,933
5193 :002,141,193,0902,173,196,812
5199 :902,141,194,992,173,198,9821
5285 :902,141,197,002,173,132,229
5211 :200,291,949,208,999,932,922
5217 :@37,203,032,119,199,076,251
5223 :054,203,076,119,199,832,818
5229 :008,192,165,9298,141,195,954
5235 :002,165,9021,041,901,141,230
5241 :196,902,032,009,192,165,196
5247 :820,141,198,002,8996,989,8072
5253 :163,929,019,909,153,034,001
5259 :154,147,983,985,880,069,245
5265 :982,966,865,083,973,967,969
5271 :8@32,986,951,932,848,9849,193
5277 :849,948,856,052,034,000,140
5283 :187,820,015,8000,153,034,968
5289 :866,089,032,977,965,882,068
5295 :984,973,878,8932,967,932,829
5381 :075,969,869,983,034,089,255
5307 2:208,920,020,8009,153,034,119
5313 :891,967,965,984,965,934,087
5319 :858,144,967,865,984,065,179
5325 :8@58,162,0909,008,909,013,182

Program
2. Moiré Pattern
For mistake-proof program entry, be sure to use “Automatic Proofreader,” Appendix J.
1 REM MOIRE TITLE PAGE DEMO :rem 85
5 [EXTc@ srem 244
19 [CB2K4:[BMGR1:[FBMS9 :[FSCRI1 srem 193
15 FORJ=@ TO318 STEP2 :rem 177
26 [DRAWJ,198,168,190 :NEXT srem 252
22 FORJ=@ TO318 STEP2 srem 175
23 [DRAWJ,%,160,100 :NEXT zrem 141
24 FORJ=@ TO198 STEP2 :rem 183
25 [DRAW160,190,318,J{3 SPACES}:NEXT srem 251
26 FORJ=@ TO198 STEP2 :rem 185
27 [DRAW161,190,9,3{3 SPACES}:NEXT zrem 146
29 [EXTC4 srem 46
30 MS="SUPERBASIC": [HRCS53248:MS=MS+"" srem 217
48 X=120:Y=80: GOSUB5@ srem 227
45 MS="{RVS}BY MCSOFT":MS=MS+"":X=124:Y=12@:GOSUB5
4) srem 132
47 [CHRX54,152,89:[CHRX52,169,89 srem 86
48 FORJ=1TO8@@:NEXT zrem 191
49 [FSCR16:{5 SPACES}GOTO10@ srem 97
Utilities6

58 [ CODEMS : FORJ=1 TOLEN (M$ ) srem 195


60 [CHRXASC(MIDS(MS$,J,1)),X,Y srem 186
79 X=X+8 :NEXT srem 48
8 RETURN srem 72
188 GETAS : IFAS=""THEN19@ srem 69
110 [BMGR@:[CB2K2 srem 14

Program 3. Stars
1 REM STAR DEMO srem 116
10 PI=2*T srem 146
28 INPUT" {CLR}STAR POINTS WANTED (@ TO END)";PW
srem 128
21 IFPW=9THENEND srem 12
22 INPUT"SKIP TRY VALUE CLOSE TO HALF # POINTS)";S
K srem 33
INPUT"RADIUS <198 "sR :rem 91
P=P1/PW srem 95
[BMGR1:[CB2K4:[FBMS#:[FSCR1 srem 197
X=169:Y=109-R:TL=0 s:rem 185
FORJ=1TOPW srem 89
TH=TL+SK s:rem 179
TL=TH : TH=TH*P-(PI/4) :rem 133
X2=COS (TH) *R+160 srem 194
Y2=SIN(TH) *R+1909 srem 105
[DRAWX,Y,X2,Y2 srem 192
X=INT (X2) :Y=INT(Y2):NEXT srem 255
GETAS : IFAS=""THEN14@ :rem 77
15 [BMGR@ : [CB2K2: PRINT" {CLR}":GOTO29 :rem 133

Program 4. Circles
5 REM CIRCLE DEMO srem 244
19 INPUT"CENTER X,Y";A,B srem 189
20 INPUT"RADIUS";R srem 139
49 CFSCR1:[CB2K4:[BMGR1:[FBMS@ z:rem 196
52 PH=9 :Y1=0:X1=R srem 237
68 PY=PH+Y1+Y1+1 srem 170
70 PX=PY-X1-X1+1 s:rem 189
8 [PLOT A+X1,B+Y1 srem 26
96 [PLOT A-X1,B+Y1l :rem 29
188 [ PLOTA+X1 , B-Y1 s:rem 69
1198 [PLOTA-X1,B-Y1l srem 72
129 { PLOTA+Y1,B+X1 srem 69
1398 [ PLOTA-Y1,B+X1l srem 72
148 [ PLOTA+Y1,B-X1 :rem 73
158 [ PLOTA-Y1,B-X1 s:rem 76
169 PH=PY:Y1=Y1+1 srem 252
179 IFABS ( PX) <ABS ( PY ) THENPH=PX :X1=X1-1 :rem 149

239
6 Utilities

186 IFX1>=Y1THEN6G srem 75


286 GETAS : LFAS=""THEN20@ srem 71
210 [ BMGR®:[ CB2K2 srem 15
226 INPUT" {CLR}CENTER X,Y 2A, 8 srem 131
230 INPUT"RADIUS":;R srem 190
246 [FSCR1:[CB2K4:[BMGR1 :GOTO5@ srem 225

Program 5. Joystick-Controlled Sprites


1 R EM DOODLE srem 204
5G OSUB90@:[DSPR1,13,9,0,169+16,1900+44,9,8:GOSUB14
4) srem 65
1 [BANK@ :[ CB2K4:[BMGR1:[FBMS@:[FSCR1:[BSPP1,1
srem 259
26 E=1 :X=160:Y=10@:C=-1 : FORQ=1TO19@:NEXT :rem 129
308 IFPEEK( 203 )=69THEN1 30 s:rem 99
31 IFPEEK( 203 )=4THENE=-E: IFE>OTHEN[ DSPR1,13,9,9,9,
G,8,B s:rem 186
32 IFE<O@THEN[ DSPR1,13,0,0,X+16,Y+44,0,12:[CLPXX,Y
srem 163
35 JV=PEEK (56320) : FR=JVAND16 srem 164
49 JV=15-(JVAND15) srem 254
56 IFJV=GANDFR=16THEN39 srem 162
60 IFJV=1ORJV=50RJV=9THENY=Y-1
: LFY<@THENY=199
s:rem 223
76 IFJV=20RJV=60RJV=190THENY=Y+1
: LFY> 199THENY=9
srem 16
8 IFJV>=4ANDJV <=6 THENX=X—-1 : IFX<@THENX=319:rem 2908
98 IFJV>=8ANDJV <=10THENX=X+1:I1FX>319THENX=6 :rem @
186 IFFR=GANDJV=O0THENC=-C: E=1 : FORQ=1TO10@:NEXT: IFC
>@THEN[KSPR1 : POKE53288,9 srem 226
185 IFE<@THEN[ ESPR1:[MOVE1,X+16,Y+44:[CLPXX,Y:GOTO
30 srem 117
116 IFC>O@THEN[ PLOTX, Y: GOTO32 :rem 78
126 IFC<@THEN[ESPR1: [MOVE] ,X+16,Y+44:GOTO39
srem 199
130 [ BANK®: [ BMGR@: [CB2K2:POKE198,@:PRINT"{CLR}":[K
SPR1:END :rem 13
149 PRINT" {CLR}DOODLE 64" srem 26
158 PRINT" {DOWN}USE JOYSTICK IN PORT 2" srem 227
160 PRINT"BUTTON TURNS INK ON/OFF" :rem 105
PRINT"F1l TURNS ERASE MODE ON/OFF" :rem 188
178 PRINT"HIT A KEY TO START" srem 169
186 PRINT"HIT {RVS}SPACE{OFF} TO STOP" srem 72
185 PRINT"THE BLACK + IS YOUR CURSOR WHEN INK=OFF"
srem 205
186 PRINT"THE GREY + IS YOUR CURSOR WHEN ERASE=ON"
: [BKGD1 : [ FCOL@ srem 191
196 GETAS : IFAS=""THEN19Z srem 87

240
Utilities 6

206 IFAS="" "THENRETURN srem 22


218 RETURN srem 115
99G X=13*64 srem 38
918 READY: IFY<@THENRETURN srem 172
920 POKEX,Y:X=X+1:GOTO919 srem 55
19@@ DATA1,192,9,1,192,9,1,192,0,1,192,9,1,192,@0
srem 52
1018 DATAG,128,9,126,63,9,9,128,9,1,192,0,1,192,9
s:rem 182
1926 DATA1,192,0,1,192,9,1,192,9,89,9,9,9,9,@G
srem 92
1038 DATAG,8,0,0,9,9,9,09,9,9,9,08,8,9,@G srem 22
1848 DATAG,0,9,-1 srem 81

Program 6. Sprite Animation


1 REM FALLING SHAMROCKS srem 189
2 REM HIT A KEY TO STOP PROGRAM srem 38
5 [EXTC13:[CB2K4:[BMGR1:[FSCR5:[FBMS171 srem 47
19 X=832:V=53265:R=128 srem 291
2@ READA: IFA<@THEN35 srem 204
38 POKEX,A:X=X+1:GOTO29 srem 175
35 FORJ=8TO7 srem 224
4@ [DSPRIJ,13,1,1,9,9,9,5+J{2 SPACES}:NEXT :rem 239
5@ FORJ=1T0256:FORK=1TO8:
[ MOVEK-1 ,J+K*K,J*K+K:NEXT
:WAITV,R:[FSCRJ/2 srem 9G
55 GETAS:IFAS<>""THEN3@@ srem 93
56 NEXT srem 17@
6@ X=PEEK(8192)+1:[FBMSX:GOTO5@ srem 142
199 DATAG,102,9,9,255,0,1,255,128,3,255,192:rem 81
11@ DATA3,255,192,25,255,152,60,126,60,126,126,126
srem 198
L295 DATA2 55,60, 2554 200 2 OO COD pe pl pee, 2D Dy 2D
PLS) 25> srem 112
138 DATA24, 255,126, 24,126,690, 24,69, 24,24,24,8,24,8
7%9,24,9,9,0,9,0,0,0,9,0,0,-1 srem 199
308 [CB2K2:[BMGRO:FORJ=9TO7:[KSPRJ:NEXT srem 89

Program 7. Simple PET Emulator


19 REM ROUTINE TO SET BASIC MEMORY AND SCREEN TO P
ET STANDARD LOCATIONS :rem 81
REM SCREEN AT 32768 zrem 165
REM BASIC 1824 TO 32767 :rem 28
REM ASSUME IN C-64 STANDARD MAP zrem 182
[FSCR @:£VS1K @ :[BANK 2 :PRINT"{CLR}" :rem 137
POKE44,4:POKE 45,3:POKE46,4 srem 193
POKE55,@:POKE56,128 :rem 247
NEW srem 82

241
6Utilities

Program 8. Type 64
2 IFA=@THENA=1:LOAD"64SET",8,1 srem 2
3 PRINT" {CLR}USE Fl TO END PROGRAM":PRINT"HIT ANY
{SPACE}KEY TO BEGIN" :rem 86
4 GETAS: IFAS=""THEN4 srem 139
5 POKE56,128:POKE55,8:CLR srem 224
1@ [BMGR1:[CB2K4:[FBMS@:[FSCR1 srem 193
20 [HRCS32768 srem 247
25 X=0:Y=@0:W=5:RV=0 srem 126
38 BL=9 srem 94
35 FORJ=1T030:GETKS : IFKS=""THENNEXT srem 189
49 IFJ=31ANDBL=@THEN[ CHRX169,X,Y:BL=1:GOTO35
srem 28
42 IFJ=31THEN[CHRX16@,X,Y:GOTO3@ srem 21
44 J=31:NEXT: IFBL=1THENBL=@ : [CHRX160,X,Y s:rem 37
50 IFKS="{CLR}"THEN[ FBMS8:GOTO25 srem 51
55 IFKS=CHRS(13)THENX=0: Y=Y+8:GOTO14@ srem 227
60 IFKS="{HOME}"THEN25 srem 142
65 IFKS="{RVS}"THENRV=128:GOTO3@ srem 129
66 IFKS="{OFF}"THENRV=9 : GOTO32 srem 151
78 IFKS=" { DOWN} "THENY=Y+8 : Y=-Y* (Y<193)
:J=31:GOTO49
srem 119
88 IFKS="{ UP} "THENY=Y-8 : Y=-Y* (Y>=@) :J=31:GOTO4@
srem 204
96 IFKS="{ RIGHT } "THENX=X+W: X=-X* (X<316) sJ=31:GOTO4
4) srem 156
106 IFKS="{ LEFT } "THENX=X-W: X=-X* (X>=0) :J=31: GOTO4
4) srem 27
195 IFKS="{F1}"THEN280 srem 91
106 IFKS=" "THEN[CHAR32+RV,X,Y:GOTO120 srem 5
11@ [CODEKS$ :CR=ASC(K$):[CHRX CR+RV,X,Y :rem 85
120 X=X+W: X=-xX* (X>=@ANDX< 316) : I1FX=OTHENY=Y+8
srem 228
148 Y=-Y*(Y<193) :rem 94
158 GOTO39 srem 5@
208 [BMGR®@:[CB2K2:PRINT"{CLR}" srem 172

Program 9. 64Set
32768 :000,224,176,916,208, 298,964
327 74 2112,0908,096,249,144, 249,079
32788 :144,144,144,000, 224,144,944
327, 86 :144,224,144,144, 224,800,130
327 92 :996,144,128,128,128,144,924
3277 98 :896,000,192,160,144,144,254
328 O04 :144,160,192,900, 240,128,132
328 16 :128,224,128,128, 240,900,122
328 16 :248,128,128,224,128,128,908
328 22 :128,000,096,144,128,176,214

242
Utilities 6

32828 :144,144,996,908,144,144, 220


32834 2144, 249,144,144,144,900,114
328408 2112,9032,032,932,032,9032,988
32846 :112,800,848,016,016,916,930
32852 :144,144,996,0900,144,144,244
32858 :160,192,169,144,144,908,122
32864 2128,128,128,128,128,128,996
32879 2249,969,144, 240, 248,144,886
32876 2144,144,144,906,144, 208,124
32882 :208,208,176,176,144,908, 902
32888 :996,144,144,144,144,144,168
32894 2896,900,224,144,144, 224,190
329068 :128,128,128,900,996,144, 244
32906 2:144,144,144,996,048, 800, 202
32912 3224,144,144,224,144,144,144
32918 2144,800,0996,144,128,996, 246
32924 216,144,996 ,900, 240,964, 204
32930 :064,064,964,064,964, 899,226
32936 2144,144,144,144,144,144,998
32942 :896,000,144,144,144,144,978
32948 :144,996,096,800,144,144,936
32954 2144,144, 248, 240,144,800,974
32968 2144,144,996,996, 240,144,832
32966 2144,008,144,144,144, 249, 246
32972 2996,996,8096,8900,240,9016, 236
32978 2032,064,128,128, 249,800,934
32984 :192,128,128,128,128,128,924
32998 :192,008,224,112,964, 249,930
32996 2:@64,112,224,980,048,9816,180
33862 :816,916,816,816,948,800, 696
33868 2900 ,896,896, 240,896,996, 996
33814 2:996,096,816,032,964, 249,022
330208 :964,032,916,89090,9020,800,168
33826 : 800,000 ,000,89060, 096,600,082
33632 2932,032,032,932,832,8900,168
33838 2032,0008,000,144,144,809,878
33044 2900, 000,908 ,G00,112,996,228
33058 2896, 249,896,996, 224,889,016
33056 2@32,996,144,192,048,144,176
33662 :996,032,128,144,032,8964,022
33868 2144,916,000,900,224,168,076
33974 2192,169,144,144,112,980,934
33088 2996,192,128,990,9609,9080,216
33886 :0@00,009,096,192,128,128,994
33892 2128,192,996,8908,192,996,964
33898 2848,048,948,896,192,989, 259
331964 2G00,144,9096, 249,996,144,932
33119 :@G0,009,0900,964,064, 224,182
33116 264,964,998 ,900,990,800,228

243
6 Utilities

33122 289,000,800 ,096,896,192,226


33128 :000,9000,800,2408,200,008,888
33134 3200, 0008,0880,09008,999,009,118
33146 2900 ,996,8996, 800,900,809 ,9852
33146 :968,016,932,964,128,900,114
33152 :996,144,176,144, 208,144,916
33158 :896,008,896,632,632,032,166
33164 29@32,032,112,800,9096,144,844
33178 2916,032,964,128, 240,008,114
33176 :@96,144,916,696,916,144,152
33182 :996,000,632,160,160,168, 254
33188 3240,032,032,900, 249,128,968
33194 2128,224,816,144,896,989,019
33200 2996,128,128,224,144,144,916
33206 :696,000,240,616,016,932,870
33212 2932,032,032,900,096,144,912
33218 3144,096,144,144,896,0099,050
33224 2996,144,144,112,916,916, 216
33230 2096, 008,880,008 ,896,080,142
33236 2000 ,996,000,900,000,9008,852
33242 :996,098,009,996,996,192,186
33248 :916,032,964,128,964,932,948
33254 2016,0908,8090,000, 240,800, 230
33260 2248, 000,000,800,128,964,156
33266 :832,016,832,064,128,009,802
33272 2896,144,816,832,032,900,956
33278 2032,800,000,224,176,816,190
33284 2208, 288,112,960,996, 248,189
33290 3144,249,144,144,144,889,658
33296 2224,144,144,224,144,144,916
33362 3224,000,996,144,128,128, 239
333088 :128,144,996,900,192,160, 236
33314 2144,144,144,160,192,900,950
33320 :249,128,128, 224,128,128, 248
33326 2249,908, 249,128,128, 224, 238
33332 2128,128,128,809,996,144,164
33338 :128,176,144,144,896, 908, 234
33344 2144,144,144,249,144,144, 980
33358 2144,098,112,8032,032,832,166
33356 3932,032,112,909,9048,916,8608
33362 2@16,016,144,144,996, 800, 242
33368 :144,144,169,192,168,144,908
33374 :144,908,128,128,128,128, 238
33386 :128,128, 248,000,144, 248,212
33386 3249,144,144,144,144,800,154
33592 2144, 208, 208, 208,176,176, 288
33398 :144,000,996,144,144,144,922
33484 2144,144,996,900,224,144,198
33416 :144,224,128,128,128,960,114

244
Utilities 6

33416 2:896,144,144,144,144,096,136
33422 :848,008,224,144,144, 224,158
33428 :144,144,144,900,096,144,952
33434 :128,996,816,144,8696,900,122
33440 :240,064,964,964,064, 964, 298
33446 :964,000,144,144,144,144,838
33452 2144,144,8096,900,144,144,076
33458 2:144,144,144,996,996, 809,834
33464 :144,144,144,144, 240, 240,216
334708 :144,0900,144,144,896,896, 946
33476 :240,144,144,000,144,144, 244
33482 2144, 248,096,896,996, 008,186
33488 2249,016,932,964,128,128,948
33494 2249,008,192,128,128,128, 086
335986 :128,128,192, 990,224,112, 236
33586 2964, 248,964,112, 224,909,162
33512 :948,016,916,916,016,916,1904
33518 2948,009, 000,896,096, 248, 286
33524 :996,996,996,996,016,832,164
33530 2964, 249,964,032,816,900,154
33536 2900, 000,900,000, 000, G00, BOO
33542 :989,008,032,032,8032,832,134
33548 :932,000,932,900,000,144, 220
33554 2144,900,000,090,000,000,162
33568 :112,096,996, 248,996,896, 248
33566 2224,008,8032,096,144,192, 206
33572 2948,144,996,032,128,144,116
33578 2:032,0964,144,816,000, 080,942
33584 :224,160,192,160,144,144,948
33596 :112,908,996,192,128,0890,976
33596 :800,8900,0900,000,996,192,892
33662 :128,128,128,192,996,909, 226
33668 :192,096,048,948, 848,996,888
33614 :192,009,000,144,996, 248, 238
33628 :996,144,008,800,800,964,132
33626 2964,224,964,864, 808,009, 250
33632 2900 ,900,9000,900,000,896,192
33638 :896,192,8980,8000, 009,249,118
33644 2900 ,900, 000, 900,800, 900,108
33650 2080 ,000,000,896,996, 900,858
33656 2900, 960,0908,816,032,964, 248
33662 :128,008,8096,144,176,144, 046
33668 :208,144,996,900,096,932,196
33674 :032,032,032,032,112,9800,122
33689 :9@96,144,916,932,064,128,112
33686 2248, 009,096,144, 816,096, 239
33692 :916,144,996,000,932,168,992
33698 :169,168, 240,032,032,9009,8018
33764 2249,128,128,224,916,144,924

245
6 Utilities

33719 :996,0900,896,128,128, 224,978


33716 2144,144,996,990, 240,916,952
33722 :916,932,032,032,032,0900,074
33728 :@96,144,144,996,144,144,192
33734 :696,899,996,144,144,112,922
33746 :916,9016,096,000,900,000,076
33746 296,000, 900,996,000,000,146
33752 2900 ,090,996,908,900,096,152
33758 :996,192,916,032,964,128, 238
33764 2964,6032,916,000,000,009,984
33770 2240 ,000,240,090,9099, 008, 202
33776 :128,964,632,016,032,964,964
33782 :128,000,8996,144,916,032,159
33788 2932,000,032,900, 248,824,876
33794 3072, 232,040,040,136, 248, 962
338008 2152,008,1904,008,194,194, 232
33886 3104, 248,024,104,194,924,119
33812 2104,104,024, 248,152,104, 244
33818 2120,129,120,194,152,248,122
33824 2056,988,194,164,104,088,964
33830 2056, 248, 908,1280,120,924,1982
33836 :120,120,968,248,9008,120,156
33842 :120,024,129,120,120, 248,934
33848 3152,184,120,072,1894,1904, 200
33854 :152,248,194,194,194,908,914
33860 :104,194,194, 248,136,216, 212
33866 2216, 216, 216, 216,136, 248,042
33872 2200, 232, 232,232,194,104,160
33878 2152, 248,194,194,088,056,076
33884 2988,194,104,248,129,120,198
338908 :120,120,120,129,9008, 248, 966
33896 :194,008,998,104,194,184,924
33982 :194,248,194,048,049,840,174
33988 28@72,072,194,248,152,104,129
33914 2194,104,194,194,152,248,179
33920 :024,104,1904,9024,120,120,112
33926 2120,248,152,194,104,194,198
33932 3104,152,200, 248,024,184, 204
33938 :194,9024,194,104,104, 248,966
33944 2152,1904,120,152,232,104, 248
33950 :152,248,008,184,184,184,994
33956 :184,184,184,248,104,194,148
33962 :104,1904,194,104,152, 248,218
33968 2104,194,194,194,1904,152,080
33974 :152,248,104,194,1904,1904,230
33989 :988,008,104, 248,194,104, 252
33986 2152,152,9008,1904,104, 248,194
33992 :104,194,104,988,152,152,056
33998 2152,248,008, 232, 216,184,222

246
Utilities 6

34904 :120,120,008,248,956,120,116
34919 2120,120,120,120,056, 248, 234
34816 :024,136,184,008,184,136,128
34822 2024,248, 200, 232, 232,232,118
34928 :232,232, 200,248, 248,152,012
34634 2152,008,152,152,152,152,242
34040 :232,216,184,908,184, 216,988
34946 2232, 248, 248, 248, 248, 248,190
34652 2248, 248, 248, 248, 216,216,148
34658 2216, 216,216, 248, 216, 248, 690
34964 2248,104,164, 248, 248, 248,192
34076 2248, 248,136,152,152,888,198
34076 2152,152,024, 248, 216,152,204
34882 :104,056,200,184,152,216,998
34088 :120,104, 216,184,104, 232,232
34994 2248, 248,024,888, 056,988, 939
341908 :104,104,136,248,152,056,984
34166 2129, 248, 248, 248, 248, 248,138
34112 2152,056,120,120,128,956,176
34118 2152,248,056,152, 208,290,954
34124 :200,152,956, 248, 248,194, G69
34130 2152,008,152,104, 248,248, 226
34136 :248,184,184,924,184,184,072
34142 2248, 248, 248, 248, 248, 248, 046
34148 :248,152,152,956, 248, 248,186
34154 248,008,248, 248, 248, 248,974
34169 2248, 248, 248, 248, 248,152,224
34166 2152,248, 248, 248, 248, 232,214
34172 2216,184,128, 248,152,104,124
34178 :072,1804,048,104,152, 248,882
34184 2152,216, 216,216, 216, 216,888
34190 2136, 248,152,104, 232,216, 206
34196 2184,120,008,248,152,104,196
34262 :232,152,232,194,152,248, 258
34268 :216,088,988,988,988, 216,896
34214 2216, 248,908,120,129,024,134
342208 2232,104,152,248,152,120,156
34226 :120,024,104,104,152,248,162
34232 2008, 232,232,216, 216,216,824
34238 :216,248,152,194,104,152,142
34244 3104,184,152,248,152,104,936
34258 2104,136,232,232,152,248,826
34256 2248, 248,152,248, 248,152,224
34262 2248, 248,248, 248,152,248,878
34268 2248,152,152,056,232,216, 252
34274 :184,120,184, 216, 232,248,130
34289 2248, 248,908, 248,998, 248, 216
34286 2248, 248,120,184, 216,232, 286
34292 :216,184,128,248,152,194,244

247
6 Utilities

34298 2232,216,216, 248, 216, 248,990


34364 2248,924,972,232,849,040,144
34319 2136,248,152,008,194,908,1598
34316 :104,194,104, 248,924,104,188
34322 2194,9024,194,194,9024, 248,114
34328 2152,194,120,120,120,104, 232
34334 2152, 248,956,988,194,194,9014
34348 :194,088,956,248,908,120,148
34346 :120,024,120,129,908, 248,170
34352 :@08,120,120,024,120,120,948
34358 :120,248,152,194,129,9072,1982
34364 2:104,194,152,248,104,194,198
34378 :104,908,194,194,104, 248,226
34376. 2136, 216, 216, 216, 216, 216, 088
34382 2136, 248, 200, 232, 232,232,978
34388 2104,104,152,248,1804,194,132
34394 :088,056,988,194,104, 248,019
34400 :120,120,120,120,128,120,948
34496 2968, 248,104,808,908,104,970
34412 2104,194,194,248,194,049,044
34418 2840,048,072,072,104, 248,178
34424 :152,194,104,104,194,194,824
34430 2152,248,924,194,194,024,914
34436 2120,120,120,248,152,104, 228
34442 :104,104,194,152, 209,248,626
34448 :924,194,104,024,104,184,996
34454 2104, 248,152,194,120,152,9006
34460 3232,194,152,248,008,184,960
34466 :184,184,184,184,184, 248,950
34472 3194,1904,194,104,104,104,924
34478 2152,248,104,104,194,164,222
34484 £164,152,152, 248,194,104, 020
344968 :194,194,098,098,104, 248,259
34496 2194,104,152,152,908,104,948
34562 2104, 248,1904,104,194,968,1902
34568 2152,152,152,248,908, 232,124
34514 3216,184,1290,120,908, 248,082
34529 :956,120,120,120,120,120,184
34526 2056, 248,024,136,184,968,119
34532 :184,136,024, 248, 200, 232,228
34538 3232, 232,232,232, 200,248,974
34544 :248,152,152,008,152,152,880
34550 2152,152,232,216,184,988,166
34556 2184, 216,232,248, 248, 248,992
34562 2248, 248, 248, 248, 248, 248, 219
34568 :216,216, 216, 216, 216, 248, 956
34574 2216, 248, 248,104,104, 248,158
34586 2248, 248, 248, 248,136,152,029
34586 2152,008,152,152,024,248,256

248
Utilities 6

34592 2216,152,194,956, 200,194,996


34598 2152,216,120,194, 216,184,906
34604 2194,232,248, 248,824,988, 22
34619 2:956,988,194,194,136,248,818
34616 2152,956,120, 248, 248, 248,104
34622 2248, 248,152,956,120,129,238
34628 :120,056,152,248,956,152,984
34634 2209, 208, 200,152,056, 248,196
346408 2248,194,152,908,152,104,980
34646 2248, 248, 248,184,184,024,198
34652 2184,184, 248, 248, 248, 248,172
34658 2248, 248, 248,152,152,9056,178
34664 2248, 248,248,908, 248, 248,872
34672 2248, 248, 248, 248, 248, 248,962
34676 2248,152,152,248, 248, 248,132
34682 2248, 232,216,184,128, 248,990
34688 2152,184,072,194,048,104,192
34694 2152,248,152, 216, 216,216,054
34766 :216,216,136, 248,152,184,188
34786 2232,216,184,129,968, 248,139
34712 2152,104,232,152,232,104,194
34718 2152,248,216,988,088,988,914
34724 2908, 216,216, 248,988,120, 212
34730 2120,024, 232,104,152, 248,826
34736 :152,120,120,024,104,1904,932
34742 2152,248,008, 232,232,216, 246
34748 :216,216, 216, 248,152,104, 869
34754 :104,152,104,194,152,248,034
34768 2152,104,104,136, 232,232,136
34766 :152,248, 248,248,152, 248, 222
34772 2248,152,248, 248, 248, 248, 968
34778 2152,248,248,152,152,956, 202
34784 2232,216,184,120,184, 216,896
347968 2232,248, 248, 248,008, 248,182
34796 2008, 248, 248, 248,1290,184,912
34802 2216,232,216,184,129, 248,178
34898 2152,104, 232,216,216, 248,136
34814 2216, 248,9013,013,913,913,902

249
6 Utilities

Copyfile
Gregor Larson

Copying files—both BASIC and machine lan-


guage programs—is simple and fast when you
use this program. A short machine language
routine, “Copyfile” allows you to make file
copies using only one disk drive.
ELIE LOE TEMELO LT SS

One drawback of a single disk drive is its inability to copy


files from one disk to another. BASIC programs can be copied
by loading them into the computer, then saving them out to
another disk, but sequential files, such as user or machine lan-
guage program files, can be difficult to copy with just one
drive.
“Copyfile” allows you to duplicate these files. It reads the
whole file into the machine and then waits until you press the
C key. Then it writes the entire file back to another disk. The
program is written in machine language, so it’s fast. It also
makes good use of the 64’s memory, and can copy a file of
more than 170 blocks.
Enter and Use
To enter Copyfile, use the MLX program in Appendix I. MLX
makes it easier to enter the sometimes complicated machine
language code. Before you begin to type in Copyfile, read
Appendix I.
Because Copyfile and MLX use some of the same memory
area on the 64, you'll have to enter a POKE statement in di-
rect mode (without a line number) before you use MLX to
type in Copyfile. This statement moves BASIC, and is:
POKE 44,PEEK(44) + 2:POKE(PEEK(44))*256,0:NEW
If you enter Copyfile in more than one session (which is un-
likely, since it’s so short), you would have to type in the
above statement each time before beginning to use MLX with
this program.
Once you've typed in the POKE statement and loaded

250
Utilities 6

MLX, RUN it. It will ask you for the beginning and ending
addresses of Copyfile. They are:
Beginning address: 2049
Ending address: 2300
You can then begin to type in the numbers you see in the
Copyfile listing at the end of this article. Once you’ve finished,
SAVE it to disk or tape using the MLX program. Now you're
ready to make copies of any file.
To use Copyfile, simply LOAD it and type RUN. With the
proper disk in the drive, enter the name of the file to be
copied. The filename should be in the form:
filename for PRG (program) file
filename, S for SEQ (sequential) file
filename, U for USR (user) file
You don’t need to place the filename within quotation marks,
as when you load a BASIC program. If you don’t specify the
type of file using a comma and appropriate letter, Copyfile by
default will create it as a program file.
If there is any kind of error in reading the file into mem-
ory, an error message will display and the program will stop.
If there is no error, the file will read into the computer. When
the drive stops, remove the source disk and place the destina-
tion disk into the drive. Press the C key. The file then writes
to the destination disk, using the original name of the file. An
error at this point will show on the screen, and the program
will wait for another press of the C key to try to read the file
again, or a press of the RUN/STOP key to quit the program.
If all’s gone well, you’ve now got a copy of your original,
ready to use.
You can even make multiple copies of the same program
to different disks, simply by pressing the C key again (once
another destination disk has been placed in the drive). Using
this function, you can make as many copies of a file as you
want. Pressing the RUN/STOP key at any time stops the pro-
cess and lets you begin copying another file. Just type RUN,
and you're ready to start again.

Copyfile
2849 :829,0908,919,900,158,958, 990
2055 :948,055,957,8058,949,867,976
2061 :941,8032,949,957,956,951,643

251
6 Utilities

2067 :832,967,879,077,889,985,183
2873 2984 ,969,933,00809,900,000,211
2879 2169,954,133,001,160,009,836
2085 2@32,207,255,281,013,2408, 217
2991 :@66,153,880,902, 200, 208,190
2097 2243,132,963,832,210,255, 216
2193 2160,002,632,179,908,032,212
2109 :207,908, 208,965,162,962,201
2115 2032,198,255,169,909,032, 232
2021 2183,255,941,964, 298,912,068
2127 :932,228, 255,145,251, 208,166
2133 2208,902,238,252,208, 237,198
2139 :132,961,165,252,133,062,128
2145 :164,963,169,944,153,800,178
2151 2862, 208,169,087,153,088, 282
2157 2802,2980,132,063,032, 207,233
2163 :908,032,249,008,032,228,151
2169 2255,2801,967,240,014, 201,875
2175 2893, 208, 245,832,249,088,995
2181 :169,955,133,901,1898,902,989
2187 :160,168,001,032,179,9008,167
2193 2932,287,8008, 208, 219,162,213
2199 :082,032, 201, 255,160,000, 633
2205 2177, 251,932,218, 255, 200,982
2211 2208,902, 238, 252,196, 961,988
2247 3208, 242,165,962,197,252,815
2223 2208, 236, 249,199,169, 002,196
2229 2162,988,032,186, 255,165,221
2235 :963,162,000,169,002,032,994
2241 2189, 255,932,192, 255,169,985
2247 2249,133,251,169,908,133,118
2253 3252,096,169,908,932,188,174
2259 :255,169,111,032,158, 255,159
2265 :@32,165,255,201,048, 240,134
2271 2815, 298,903,032,165, 255,133
2277 2972,032,219,255,104, 201,079
2283 3013, 208, 244,168,996,169,109
2289 :902,032,195,255,932,231,220
2295 :255,996,013,013,913,013,138

252
Utilities 6

Merging Programs
on the 64
John A. Winnie

For intermediate programmers, “Merger” allows


you to build up large programs by working on
smaller portions separately and then linking
them together later. This approach is used by
many professionals.
LLL TE EE IE

If you do much BASIC programming, sooner or later you'll


need to merge two short programs to form a larger one. Or
perhaps you'll need to append onto a program a series of
DATA statements—DATA for sprites, redefined characters,
sound and music, or whatever. Here is a quick and easy way
to add those DATA statements—or any other BASIC state-
ments—onto the end of your programs.
Of course, various techniques for merging programs have
been around for some time. When all that is needed is a sim-
ple append, however, the method presented here does the job
nicely. The program below, ‘’Merger,” is designed to merge
with any programs which are appended to it, and it allows
you to keep on appending indefinitely.
Using Merger
After typing and saving Merger, load it in the usual way.
Next, run Merger, and then load in your main program. Now,
as Merger instructs, POKE locations 43 and 44 with 1 and 8,
respectively. Your main program is now appended to Merger
and ready for any DATA statements you may want to add
later.
Remember, Merger allows you to append programs only,
not to insert them. So to prepare for using Merger later, begin
your programs with a line number greater than five. For the
same reason, all DATA statements to be added should begin
with a line number higher than those already present in the

253
6 Utilities

program. When you have finished, just erase Merger by delet-


ing lines 1 through 5.
How Merger Works
First, clear out your Commodore 64 by typing NEW and
pressing RETURN. Then enter the following simple program:
10 REM
Press RETURN, and the one-line program is now entered
into memory beginning at address 2048 and running on up-
ward. To see just how the program is stored, enter:
FOR I= 2048 TO 2056:PRINT PEEK (I):NEXT I
If all this has been done correctly, you now should see a
list of memory contents which looks like this:
0,7,8,10,0,143,0,0,0
The 0 in address 2048 is invariable: all BASIC programs
begin with zero. They also always end with a zero; in fact,
they always end with exactly three zeros—which is just what
we see here in memory locations 2054 through 2056. From
this point on in memory, BASIC will store any variables and
other information that it may need to execute the program.
In general, when a BASIC line is stored, it will end with a
single zero, not three zeros. When a new line is appended to
the program, its code begins immediately after that single
zero. So in the example above, if the line
20 REM
were now added to our sample program, the (link of the) new
line would now come in at address 2055—the address of the
middle zero in the triplet; a new triplet of zeros would appear
later in memory, signaling the end of line 20 and the new end
of the program. (Try this later to see for yourself.) So, to
merge programs, we simply have to make sure that we load
the new section at the address of the middle zero (2055,.in our
example) within the three zeros which signal the end of our
original program. What we need to do is raise the floor of
BASIC to this new address, load the section to be merged, and
then lower the floor to its original value (here, 2049).
Tinkering with BASIC
Raising the floor of BASIC is easy. The new address is simply
POKEd into addresses 43 and 44 in low-byte, high-byte order.

254
Utilities 6

(HI=INT (ADDRESS#/256) :LO=ADDRESS#-256*HI.) Find-


ing this new address is another matter, but fortunately, this
turns out to be easy as well.
As I mentioned above, BASIC needs to know where it is
safe to begin to store its variables. In other words, BASIC
needs to know the first address to come after the three zeros
which end the program. Hence, the computer stores this ad-
dress in a pair of memory locations in the usual low-byte,
high-byte form. In the 64, these locations are addresses 45 and
46.
To see this, enter PRINT PEEK(45),PEEK(46), and out
should come the pair 9,8. Since the address 2057 is the first
address to follow our sample program, and 2057=256*8+9,
we have the expected result.
Now that we have the address of the first location after
the end of the program, the rest is easy. The new program is
simply loaded into memory two places before this location. In
our example, we load at location 2055 (2057-2). And that’s all
there is to it.
The basic idea behind Merger should now be clear. Every-
thing of interest is packed into line 5. First, for any program
which begins with these lines, the new floor for BASIC is
computed using the contents of locations 45 and 46, as
described above. Next, the floor of BASIC is raised to the new
location. As a result, any new program now loaded will start
right at the tail end of the previous program—just where we
want it.
64 Merger
For mistake-proof program entry, be sure to use “Automatic Proofreader,” Appendix J.
1 C=53280:POKEC, 6:POKEC+1,8 srem 45
2 INPUT "{BLU}{CLR}{4 DOWN}{8 RIGHT}MERGE (Y/N)";A
$ z:rem 27
3 IFAS$<>"Y"THENEND srem 68
4 PRINT"{1@ DOWN}{3 RIGHT}LOAD YOUR ADDITION":PRIN
T"{3 RIGHT}THEN POKE 43,1 AND 44,8." srem 18
5 E=256*PEEK(46)+PEEK(45)-2:H=INT(E/256)
:L=E-256*H
: POKE43,L: POKE44,
H: END srem 181

255
6 Utilities

64 Program
Lifesaver
‘““UNNEW’”’ Rescues Lost
Programs
Vern Buis

If you have ever lost a BASIC program by ac-


cidentally typing NEW, then read on. This short
machine language routine for the Commodore 64
provides an easy means of recovering BASIC
programs that have been “erased’’—and it loads
and executes in only ten seconds.
SL AT RE ET EE ERT
Sooner or later—practically every programmer does it—think-
ing a program has been saved, you type NEW to clear out the
memory, and a split-second after pressing RETURN, you wind
up screaming.
But on the Commodore 64, typing NEW does not really
erase the program from memory. NEW just makes the com-
puter (and the programmer) think the program is gone. As
long as you don’t start typing another program or switch off
the machine, the program is still there. To get it back, all you
have to do is fool the computer into remembering where in its
memory the program begins and ends.
That’s what ‘64 Program Lifesaver” does. By loading and
running this short machine language utility immediately after
committing the grievous error, you can save your lost pro-
gram, save your hours of work, and even save your sanity.

Entering the Lifesaver


The Lifesaver is listed as a BASIC loader, a BASIC program
that creates a machine language program. Be sure to read the
following special instructions before typing the program. The
procedure is somewhat different from most and requires that
certain steps be followed exactly.
First, if you are using tape instead of disk, enter line 60 as
follows:
256
Utilities 6

60 CLR:SAVE’UNNEW”,1,1
After typing the listing, do not RUN it. Instead, save it on
disk or tape with a filename such as ‘“LIFESAVER/BASIC” or
“UNNEW/BASIC”. Do not use the filename ‘““UNNEW”. This
filename must be reserved.
Now enter RUN. The BASIC loader creates the machine
language program and automatically saves it on disk or tape
under the filename “UNNEW”. This is what you'll actually
use to rescue lost programs; the BASIC loader can be set aside
as a backup in case you need to create another copy.
Using the Lifesaver
OK, let’s say you've just typed NEW and wiped out hours of
valuable labor. (To test the Lifesaver, you can load a BASIC
program and erase it with NEW.) Recovering it is easy.
To load the Lifesaver from tape, enter:
LOAD” UNNEW”,1,1
To load the Lifesaver from disk, enter:
LOAD’ UNNEW”,8,1
Either way, it loads pretty fast, because the program is
short. Now, to activate the Lifesaver, enter:
SYS 525 [RETURN]
CLR [RETURN]
(Incidentally, CLR means to type the keyword CLR, not to
press the CLR/HOME key.)
That’s all there is to it. When you enter LIST, the BASIC
program you thought was forever lost is back, safe and sound.
The Lifesaver itself also remains in memory, but probably
not for long. It’s tucked away in memory which is unprotected
(locations used by the input buffer and BASIC interpreter), so
you'll have to load it again each time you want to use it. But
unless you're either very unlucky or (shall we say) prone to
inadvertent actions, the Lifesaver isn’t something you should
be needing often.
Why It Works
Instead of erasing the program in memory when you type
NEW, the 64 simply resets two key pointers in such a way
that the operating system doesn’t “see’’ that the program is
still there. These pointers keep track of where in memory a

257
6 Utilities

BASIC program begins and ends. NEW moves the top-of-


program pointer down to the bottom of BASIC memory, and
the first two bytes of BASIC memory are set to zero. These
first two bytes serve as a pointer to the address for the second
line of BASIC code. When they are set to zero, the operating
system believes that no program is in memory.
The Lifesaver works by skipping the first two bytes of
BASIC memory (the address pointer) and the next two bytes
(BASIC line number). It scans upward for a zero byte—the
end-of-line indicator. Upon finding the zero byte, the routine
POKEs its address, plus one, into the second-line-of-BASIC
address pointer. One of the erased pointers is thereby restored.
Next, the Lifesaver scans byte-by-byte through the BASIC
memory area until it finds three consecutive zero bytes. This is
the end-of-program indicator. Once it locates these zeros, the
routine POKEs the address of the third zero, plus one, into the
top-of-BASIC/start-of-variables pointer at locations 45-46.
This completely restores the erased program.
For those who might want to relocate the Lifesaver to a
safer memory area—to preserve it for frequent use or to com-
bine it with other utility routines—the machine language pro-
gram is written to be fully relocatable. It uses no absolute JMP
or JSR instructions. The area used here was chosen to make it
load easily into a 64 and to minimize the danger of it loading
atop a BASIC program.
64 Program Lifesaver
For mistake-proof program entry, be sure to use “Automatic Proofreader,” Appendix J.
18 I=525 srem 131
26 READ A:IF A=256 THEN 40 srem 54
38 POKE I,A:I=I+1:GOTO 29 srem 130
4@ POKE 43,525 AND 255:POKE 44,2:REM SET BOTTOM OF
MEMORY srem 173
58 POKE 45,578 AND 255:POKE 46,2:REM SET TOP OF ME
MORY srem 216
6@ CLR : SAVE"@:UNNEW",8 srem 79
78 REM FOR TAPE USE SAVE"UNNEW",1,1 srem 3
525 DATA 168,3,200,177,43,208, 251 srem 82
532 DATA 200,200,152,160,9,145,43 srem 64
539 DATA 165,44, 208,145,43,133,60 srem 87
546 DATA 168,0,132,59,162,8, 200 srem 231
553 DATA 208,2,230,69,177,59,298 srem 45
568 DATA 245,232,224,3,208, 242,200 srem 126
567 DATA 208,2,230,60,132,45,164 :rem 37
574 DATA 6@,132,46,96, 256 srem 220

258
Appendices
Appendix A

A Beginner’s Guide to
Typing in Programs
What Is a Program?
A computer cannot perform any task by itself. Like a car with-
out gas, a computer has potential, but without a program, it
isn’t going anywhere. Most of the programs published in this
book are written in a computer language called BASIC. BASIC
is easy to learn and is built into all Commodore 64s.
BASIC Programs
Computers can be picky. Unlike the English language, which
is full of ambiguities, BASIC usually has only one right way of
stating something. Every letter, character, or number is signifi-
cant. A common mistake is substituting a letter such as O for
the numeral 0, a lowercase | for the numeral 1, or an upper-
case B for the numeral 8. Also, you must enter all punctuation
such as colons and commas just as they appear in the book.
Spacing can be important. To be safe, type in the listings
exactly as they appear.
Braces and Special Characters
The exception to this typing rule is when you see the braces,
such as {DOWN}. Anything within a set of braces is a special
character or characters that cannot easily be listed on a printer.
When you come across such a special statement, refer to
Appendix B, ‘“How to Type In Programs.”
About DATA Statements
Some programs contain a section or sections of DATA state-
ments. These lines provide information needed by the pro-
gram. Some DATA statements contain actual programs (called
machine language); others contain graphics codes. These lines
are especially sensitive to errors.
If a single number in any one DATA statement is mistyped,
your machine could lock up, or crash. The keyboard and
STOP key may seem dead, and the screen may go blank.
Don’t panic — no damage is done. To regain control, you
have to turn off your computer, then turn it back on. This will

261
Appendix A

erase whatever program was in memory, so always SAVE a


copy of your program before you RUN it. If your computer
crashes, you can LOAD the program and look for your
mistake.
Sometimes a mistyped DATA statement will cause an error
message when the program is RUN. The error message may
refer to the program line that READs the data. The error is still
in the DATA statements, though.
Get to Know Your Machine
You should familiarize yourself with your computer before
attempting to type in a program. Learn the statements you use
to store and retrieve programs from tape or disk. You'll want
to save a copy of your program, so that you won’t have to
type it in every time you want to use it. Learn to use your ma-
chine’s editing functions. How do you change a line if you
made a mistake? You can always retype the line, but you at
least need to know how to backspace. Do you know how to
enter reverse video, lowercase, and control characters? It’s all
explained in your computer’s manuals.
A Quick Review
1. Type in the program a line at a time, in order. Press
RETURN at the end of each line. Use backspace or the back
arrow to correct mistakes.
2. Check the line you've typed against the line in the book.
You can check the entire program again if you get an error
when you RUN the program.

262
Appendix B

How to Type In Programs


To make it easy to know exactly what to type when entering
one of these programs into your computer, we have estab-
lished the following listing conventions.
Generally, Commodore 64 program listings will contain words
within braces which spell out any special characters: {DOWN}
would mean to press the cursor down key. {5 SPACES}
would mean to press the space bar five times.
To indicate that a key should be shifted (hold down the SHIFT
key while pressing the other key), the key would be under-
lined in our listings. For example, S would mean to type the S
key while holding the SHIFT key. This would appear on your
screen as a heart symbol. If you find an underlined key en-
closed in braces (e.g.,{10 N}), you should type the key as
many times as indicated (in our example, you would enter ten
shifted N’s).
If a key is enclosed in special brackets, [< >], you should hold
down the Commodore key while pressing the key inside the
special brackets. (The Commodore key is the key in the lower-
left corner of the keyboard.) Again, if the key is preceded by a
number, you should press the key as many times as necessary.
Rarely, you'll see a solitary letter of the alphabet enclosed in
braces. These characters can be entered by holding down the
CTRL key while typing the letter in the braces. For example,
{A} would indicate that you should press CTRL-A.
About the quote mode: You know that you can move the
cursor around the screen with the CRSR keys. Sometimes a
programmer will want to move the cursor under program con-
trol. That’s why you see all the {LEFT}’s, {HOME}’s, and
{BLU}’s in our programs. The only way the computer can tell
the difference between direct and programmed cursor control
is the quote mode.
Once you press the quote (the double quote, SHIFT-2), you
are in the quote mode. If you type something and then try to
change it by moving the cursor left, you'll only get a bunch of
reverse-video lines. These are the symbols for cursor left. The

263
Appendix B

only editing key that isn’t programmable is the DEL key; you
can still use DEL to back up and edit the line. Once you type
another quote, you are out of quote mode.
You also go into quote mode when you INSerT spaces into a
line. In any case, the easiest way to get out of quote mode is
to just press RETURN. You'll then be out of quote mode and
you can cursor up to the mistyped line and fix it.
Use the following table when entering cursor and color control
keys:
When You When You
Read: Press: See: Read: Press: See:
{CLR} EL £13 COMMODOR
{HOME} ey £23 COMMODOR
Fa
{uP} [sur ] k33 COMMODOR
ei
{DOWN } i £43 COMMODOR
ach
(LEFT} | | £53 COMMODOR ES
{RIGHT} | bed COMMODOR Bi
EIEIEIE
PI a
E73 COMMODOR 7 ait
tas) [om] [> ]
i £83 COMMODOR pile
eae. [> |

hie [oe|[> ] Mo ten


oon) Fee] ] fo frail Gere)
o
{RED}
So @o moo §
[cree] [5] ES| Ges) er i

oe GC] wy
{PUR}

coma] re]

mR
CTRL aE {F7)}

ts
{BLU}

ve) fo]

264
Appendix C

Screen Location Table


O 102 op et tt
roost _[ |TT | Ht tt GS SSS Se SaRasene8
Seer Lt BRSSSase Pettitt te |
rr H+ t+ RN | a Ps
veal | TTT TT So ae Ht
5 real TTT TT [| | 4 Se Rees
1264CC
(PI TESTT ea aT TE TV Tas a a
1lgg eT a PFT SSS TY sf a a a i
wea | TT TT TY aaa [| Po as H+ +H
(riba eaaases Gis SESS BSERS
wat ttt ttt t+ +++ + +++ GBS Eas EE
sol | TT TT TY ie] SRSaSs Ht BERSaa
met f a | Perce BRESeo
ge |e (Rs [| ee a a
SDE | a | fe | a i i aa a ie
ea | 5 EY a | Ys re i i a
| Ra |
v744l_|DEGEEBESSeosa Ga
ia Oees)es OY |_|
20 182 Het EE
is (PA RT Te 3 i) ela)
vos [TTT TT |Ht tt tt
seed Oc RR a) | a i i
2S lP TRE TETTSS TIE Mee Tete
0 S. 10 15 20 25 30 SAN Bech,

Column

265
Appendix D

Screen Color Memory Table


Row
Ds CR aS |S TO EY a eT
55336Protester be pe ep ee EE SES
e476 | de Ea | SENS STS Tea STi Tes TE
55416ao @
ssasol_| || Pelee HBS BEBE eS Sea eeesee
5 ssi96l__| eS 2 Ys Es RY es a ST Ea =
erg | |e eaded Pe a(R Yayead STS Te gE TRTTT Tse TTT ase fc ea]
55576 Pept p ptt Wtf |
55656Ppt HY
10 ssessl TT TTTTT | Bieta
55736PERE EE fy bt

55976 Bai
56016FEEEEEEEEEEE CEES

0 5 10 15 20 25 30 Ls he aS

Column

266
Appendix E

Screen Color Codes


Value To POKE For Each Color
Select
Low nybble High nybble multicolor
Color color value color value color value
Black
White 16 9
Red 32 10
Cyan 48 11
Purple 64 LZ
Green 80 13
Blue 96 14
Yellow 112 15
Orange 128
Brown © 144
OONHNATSPWNK
Light Red 160
Dark Gray 176
Medium Gray a©Nr 192
Light Green st 208
Light Blue 14 224
Light Gray 15 240

Where To POKE Color Values For Each Mode

Bit or
Mode* bit-pair Location Color value
Regular text 0 53281 Low nybble
1 Color memory Low nybble
Multicolor 00 53281 Low nybble
text 01 53282 Low nybble
10 53283 Low nybble
11 Color memory Select multicolor
Extended 00 53281 Low nybble
color text t 01 53282 Low nybble
10 53283 Low nybble
1} 53284 Low nybble
Bitmapped 0 Screen memory Low nybble [}]
1 Screen memory High nybble [+]

267
Appendix E

Multicolor 00 53281 Low nybble [4]


bitmapped 01 Screen memory High nybble [t]
10 Screen memory Low nybble [+]
i Color memory Low nybble

* For all modes, the screen border color is controlled by


POKEing location 53280 with the low nybble color value.
Tt In extended color mode, Bits 6 and 7 of each byte of screen
memory serve as the bit-pair controlling background color. Be-
cause only Bits 0-5 are available for character selection, only
characters with screen codes 0-63 can be used in this mode.
[t] In the bitmapped modes, the high and low nybble color
values are ORed together and POKEd into the same location in
screen memory to control the colors of the corresponding cell
in the bitmap. For example, to control the colors of cell 0 of
the bitmap, OR the high and low nybble values and POKE the
result into location 0 of screen memory.

268
Appendix F

ASCII Codes
ASCII CHARACTER ASCII CHARACTER
5 WHITE 50 2
8 DISABLE 51 3
SHIFT COMMODORE 52 4
9 ENABLE 53 5
SHIFT COMMODORE 54 6
2B RETURN 55 7
14 LOWERCASE pews 8
17 ~+CURSOR DOWN 57 9
18 REVERSE VIDEO ON 58
19 HOME - 59
20 DELETE 60 ,
28 RED 61 -
29 CURSOR RIGHT 62 >
30 GREEN 63 ?
31 BLUE 64 @
32 SPACE 65 A
33 66 B
34 : 67 G
35 # 68 D
36 $ 69 E
37 % 70 F
38 & 71 S
39 72 H
40 ( 73 I
41 ) 74 J
42 * 75 K
43 Fe 76 LE
44 77 M
45 = 78 N
O
a NX ee)Oo P
Q
> \o a ee}NO R

269
Appendix F

ASCII CHARACTER ASCII CHARACTER


83 S 120 [+]
84 1 121 [I]
85 U 122 [+]
86 V 123 ea
87 Ww 124 &|
88 x 125 oa
89 Y 126 [7]
90 Z 127 N
91 [ 129 ORANGE
92 £ 133 fl
93 ] 134 £3
94 t 135 {5
95 - 136 {7
96 Ea 137 f2
97 [4] 138 f4
98 aa 139 {6
99 = 140 £8
100 Fy 141 SHIFTED RETURN
101 5 142 UPPERCASE
102 C] 144 BLACK
103 ia 145 CURSOR UP
104 CI 146 REVERSE VIDEO OFF
105 ie 147. CLEARSCREEN
106 ‘yy 148 INSERT
107 7] 149 BROWN
108 LJ 150 LIGHT RED
109 N 151 GRAY 1
110 VY] 152 GRAY 2
111 ee 153 LIGHT GREEN
112 fe] 154 LIGHT BLUE
113 & 155 GRAY 3
14 LJ 156 PURPLE
115 Ly] 157 CURSOR LEFT
116 L] 158 YELLOW
117 Ld 159 CYAN
118 X 160 SHIFTED SPACE
ng O 161 LL

270
Appendix F

ASCII CHARACTER __ ASCII CHARACTER


162 sl 200 oO
163 ie 201 E]
164 o 202 cy
165 & 203 77
166 | 204 Oo
167 Pl 205 N
168 Cal 206 %
169 v7) 207 ie
170 Ld 208 Oo
171 (H 209 aS
172 r 210 C
173 (Y 211 [v]
174 BJ 212 ia
175 lal 213 [A
176 Ld 214 dX
77 ES 215 le
178 Ed 216 [a]
179 H] 217 CI
180 L 218 [e]
181 L 219 A
182 ( 220 |
183 Fs} 221 (0
184 oe 223
185 lal 223 he|
186 LJ 224 SPACE
187 im) 225 a
188 [™ 226 ia
189 od iy: O
190 all 228 OC
191 Aa 229 C
192 a 230 Be
193 [4] 231 O
194 an 232 =
195 = 233 |
196 A 234 Cy
197 GO 235 (H
198 E 236 ir
199 ia 237 iy
271
Appendix F

ASCII CHARACTER
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255 ASG
ODO
OSes)
OS
oF
0-4, 6, 7, 10-12, 15, 16, 21-27, 128
130-132, and 143 are not used.

272
Appendix G

Screen Codes

Uppercase and _ Lower- and Uppercase and _Lower- and


POKE Full Graphics Set Uppercase POKE Full Graphics Set Uppercase

0 @ @ 31 — Ber:
1 A a 32 -space-
Zz B b 3 ! !
8) Cc e 34 s i
4 D d 35 # #
5 E e 36 $ $
6 Is f oY % %
7 G g 38 & &
8 H h 33 f c
9 I i 40 ( (
10 j 41 ) )
i K k 42 : %
12 LE | 43 a +
43 M m Jt ; ;
14 N n 45 - -
15 O oO 46
16 P p 47 / /
17 Q q 48 0 0
18 R r 49 1 if
12 5 S 50 Bs 2
20 a t Si 3 3
21 U u 52 4 4
Pub V Vv 53 ie) 5
23 W Ww 54 6 6
24 X x 55 7 7
25 ¥ y 56 8 8
26 ra Zz oY. 9 9
27 [ 58
28 £ £ 59 : :
29 ] ] 60 < <
30 t t 61 - :

273
Appendix G

Uppercase and _Lower- and Uppercase and Lower- and


POKE Full GraphicsSet Uppercase POKE Full GraphicsSet Uppercase

62 > > 99 fe] ae


63 ? ? 100 Ea [
64 SI HH 101 [4 tl
65 [4] A 102 ES |
66 aa B 103 ay LJ
67 = G 104 bed bea
68 A D 105 |
69 A E 106 (I O
70 ic F 107 (H LH
71 C1 G 108 | Lal
72 al H 109 [q (4
73 BS I 110 Bb] B]
74 CY J 111 i =
75 EF} K 112 id id
76 fe L 113 a FY
77 NX M 114 = =
78 A N 115 A] H)
79 in O 116 L L
80 O e 117 a CL
81 ry Q 118 fa a
82 C] R 119 a 0
83 [v] S 120 a |
84 ie T 121 Se =
85 [A U 123 OQ [4]
86 X V 123 | in|
87 Ww 124 he Boy
88 [4] X 125 By EZ]
89 al Y 126 il afl
90 [+] Z 127 a a
91 oa H4 128-255 reverse video of
92 Bi] BI 0-127
93 aa LU
94 be
95 |
96 -space-
97 i a
98 I ei

274
Appendix H

Commodore 64 Keycodes
e < Keycode A Keycode

+O00nnNa®
mi
CLR/HOME
INST/DEL
=

+>

_

RETURN

SPACE
RUN/STOP
NO KEY
MIND 16 PRESSED
OPRWNPNKXXS<CHHDDAOVOZZOKMA-=LO
The keycode is the number found at location 197 for the current
key being pressed. Try this one-line program:
10 PRINT PEEK (197): GOTO 10

Values Stored at Location 653


Code Key(s) pressed
(No key pressed)
SHIFT
Commodore
SHIFT and Commodore
CTRL
SHIFT and CTRL
Commodore and CTRL
©
ND
WON
OB SHIFT, Commodore, and CTRL

275
Appendix I

Using the Machine


Language Editor: MLX
Remember the last time you typed in the BASIC loader for a
long machine language program? You typed in hundreds of
numbers and commas. Even then, you couldn’t be sure if you
typed it in right. So you went back, proofread, tried to run the
program, crashed, went back and proofread again, corrected a
few typing errors, ran again, crashed again, rechecked your
typing—frustrating, wasn’t it?
Until now, though, that has been the best way to get ma-
chine language into your computer. Unless you happen to
have an assembler and are willing to tangle with machine lan-
guage on the assembly level, it is much easier to enter a
BASIC program that reads DATA statements and POKEs the
numbers into memory.
Some of these “BASIC loaders” will use a checksum to see
if you've typed the numbers correctly. The simplest checksum
is just the sum of all the numbers in the DATA statements. If
you make an error, your checksum will not match up with the
total. Some programmers make your task easier by including
checksums every few lines, so you can locate your errors more
easily.
Nov MLX comes to the rescue. MLX is a great way to
enter all those long machine language programs with a mini-
mum of fuss. It lets you enter the numbers from a special list
that looks similar to DATA statements. It checks your typing
on a line-by-line basis. It won’t let you enter illegal characters
when you should be typing numbers. It won’t let you enter
numbers greater than 255. It will prevent you from entering
the numbers on the wrong line. In short, MLX will make
proofreading obsolete.
Tape or Disk Copies
In addition, MLX will generate a ready-to-use copy of your
machine language program on tape or disk. You can then use
the LOAD command to read the program into the computer,
just like a BASIC program. Specifically, you enter:
LOAD “program name”,1,1(for tape)
or
276
Appendix I

LOAD “program name”’,8,1(for disk)


To start the program, you need to enter a SYS command that
transfers control from BASIC to your machine language pro-
gram. The starting SYS will always be given in the article
which presents the machine language program in MLX format.
Using MLX
Type in and SAVE MLX (you'll want to use it in the future).
When you're ready to type in the machine language program
refer to the article that presents the program. Sometimes you'll
need to enter a POKE statement in direct mode (without line
numbers) to move BASIC’s pointers. For instance, in this book,
when you enter “SpeedScript’”, you must first enter this line in
direct mode:
POKE 44,27:POKE 6912,0:NEW
Not all machine language programs you'll enter need a state-
ment like this, but be sure to type it in if the article requests it.
If you enter the program in several sessions, you must type in
the POKE statement each time before LOADing MLX. Once
you've changed BASIC’s pointers (if it’s necessary), LOAD and
RUN MLX. MLX will ask you for two numbers: the starting
address and the ending address. For each machine language
program, these addresses will be listed in the accompanying
article. For example, Speedscript’s addresses should be: 2049
and 6842 respectively.
You'll then see a prompt. The prompt is the current line
you are entering from the MLX-format listing. Each line is six
numbers plus a checksum. If you enter any of the six numbers
wrong, or enter the checksum wrong, the 64 will sound a
buzzer and prompt you to reenter the entire line. If you enter
the line correctly, a pleasant bell tone will sound and you may
go on to enter the next line.
A Special Editor
You are not using the normal 64 BASIC editor with MLX. For
example, it will only accept numbers as input. If you need to
make a correction, press the INST/DEL key; the entire num-
ber is deleted. You can press it as many times as necessary,
back to the start of the line. If you enter three-digit numbers
as listed, the computer will automatically print the comma and
go on to accept the next number in the line. If you enter less
Appendix I

than three digits, you can press either the comma, space bar,
or RETURN key to advance to the next number. The
checksum will automatically appear in inverse video; don’t
worry—it’s high lighted for emphasis.
When testing it, I’ve found MLX to be an extremely easy
way to enter long listings. With the audio cues provided, you
don’t even have to look at the screen if you’re a touch-typist.
Done at Last!
When you get through typing, assuming you type your ma-
chine language program all in one session, you can then save
the completed and bug-free program to tape or disk. Follow
the instructions displayed on the screen. If you get any error
messages while saving, you probably have a bad disk, or the
disk was full, or you made a typo when entering the MLX
program. (Sorry, MLX can’t check itself!)
Command Control
What if you don’t want to enter the whole program in one sit-
ting? MLX lets you enter as much as you want, save the com-
pleted portion, and then reload your work from tape or disk
when you want to continue. MLX recognizes these few
commands:
SHIFT-S:Save
SHIFT-L:Load
SHIFT-N:New Address
SHIFT-D:Display
Hold down SHIFT while you press the appropriate key.
You'll jump out of the line you’ve been typing, so I recom-
mend you do it at a prompt. Use the Save command to store
what you've been working on. It will write the tape or disk
file as if you've finished. Note the address you stopped on.
The next time you RUN MLX (don’t forget to first enter the
POKE statement if it’s required), answer all the prompts as
you did before, then insert the disk or tape containing the
stored file. When you get the entry prompt press SHIFT-L to
reload the file into memory. You'll then use the New Address
command (SHIFT-N) to resume typing.
New Address and Display
After you press SHIFT-N, enter the address where you pre-
viously stopped. The prompt will change, and you can then

278
Appendix I

continue typing. Always enter a New Address that matches up


with one of the line numbers in the special listing, or else the
checksums won’t match up. You can use the Display com-
mand to display a section of your typing. After you press
SHIFT-D, enter two addresses within the line number range of
the listing. You can stop the display by pressing any key.
Tricky Stuff
The special commands may seem a little confusing, but as you
work with MLX, they will become valuable. For example,
what if you forgot where you stopped typing? Use the Display
command to scan memory from the beginning to the end of
the program. When you reach the end of your typing, the
lines will contain a random pattern of numbers, quite different
from what should be there. Be careful, though; you don’t want
to skip over anything you should type.
You can use the Save and Load commands to make
copies of the complete machine language program. Use Load
command to reload the tape or disk, then insert a new tape or
disk and use the Save command to create a new copy. When
resaving on disk it is best to use a different filename each time
you save. For example, I like to number my work and use
filenames such as SCRIPT1, SCRIPT2, SCRIPT3, etc.
One quirk about tapes made with the MLX Save com-
mand: when you load them, the message ““FOUND program”
may appear twice. The tape will load just fine, however.
Programmers will find MLX to be an interesting program
which protects the user from most typing mistakes. Some
screen formatting techniques are also used. Most interesting is
the use of ROM Kernal routines for LOADing and SAVEing
blocks of memory. To use these routines, just POKE in the
starting address (low byte/high byte) into memory locations
251 and 252 and POKE the ending address into locations 254
and 255. Any error code for the SAVE or LOAD can be found
in location 253 (an error would be a code less than ten).
You'll find MLX is truly a labor-saving program. Since it
has been tested by entering actual programs, you can count on
it as an aid for generating bug-free machine language. Be sure
to save MLX; it will be used for future applications in COM-
PUTE! Books, COMPUTE! magazine, and COMPUTE!’s Gazette.

279
Appendix I

Machine Language Editor (MLX)


106 PRINT" {CLR}K69";CHRS$
(142) ;CHRS$(8);:POKE53281
,1:POKE5328@,1 :rem 67
191 POKE 788,52:REM DISABLE RUN/STOP :rem 119
119 PRINT" {RVS}{39 SPACES}"; srem 176
120 PRINT" {RVS}{14 SPACES}{RIGHT}
{OFF} K*J£{RVS}
{RIGHT} {RIGHT}{2 SPACES}K*J{OFF}K*I£_
{RVS}£{RVS}{14 SPACES}"; “srem 258
130 PRINT" {RVS}{14 SPACES}{RIGHT} £G3{RIGHT}
{2 RIGHT} {OFF}£{RVS}£R*I(OFF}E*I{RVS}
{14 SPACES}"; srem 35
149 PRINT"{RVS}{41 SPACES}" srem 120
206 PRINT"{2 DOWN}{PUR}{BLK} MACHINE LANGUAGE EDIT
OR VERSION 2.98{5 DOWN}" srem 236
219 PRINT"K53{2 UP}STARTING ADDRESS?{8 SPACES }
{9 LEFT}"; srem 143
215 INPUTS : F=1-F: CS=CHR$ (31+119*F) zrem 166
220 IFS<2560R(S>499698ANDS<49152) ORS>53247THENGOSUB
3099 :GOTO21B srem 235
225 PRINT: PRINT: PRINT zrem 180
236 PRINT"K53{2 UP}ENDING ADDRESS?{8 SPACES}
{9 LEFT}"; : INPUTE:F=1-F:CS=CHRS (31+119*F)
srem 20
246 IFE<2560R(E>40968ANDE<49152 ) ORE>53247THENGOSUB
30008 :GOTO23G srem 183
256 IFE<STHENPRINTCS;"{RVS}ENDING < START
{2 SPACES }":GOSUB198@@:GOTO 230 srem 176
268 PRINT: PRINT: PRINT :rem 179
38D PRINT" {CLR}";CHRS$(14):AD=S:POKEV+21,98 srem 225
316 A=1:PRINTRIGHTS ("@GO0G"+MIDS(STRS(AD),2),5);"3"
; srem 33
315 FORJ=ATO6 srem 33
320 GOSUB579: IFN=-1THENJ=J+N:GOTO329 srem 228
396 IFN=-211THEN 710 srem 62
400 IFN=-2@4THEN 790 zrem 64
419 IFN=-296THENPRINT:
INPUT" {DOWN}ENTER NEW ADDRES
S"3ZZ 4 ~ srem 44
415 IFN=-206THENIFZZ<SORZZ>ETHENPRINT"{RVS}OUT OF
{SPACE } RANGE" : GOSUB1 909 :GOTO419 srem 225
417 IFN=-206THENAD=2Z: PRINT: GOTO31@ srem 238
426 IF N<>-196 THEN 480 srem 133
436 PRINT: INPUT"DISPLAY:FROM";F:PRINT, "TO"; :INPUTT
a < ~ grem 234
449 IFF<SORF>EORT<SORT>ETHENPRINT"AT LEAST";S;"
{LEFT}, NOT MORE THAN";E:GOT043@ :rem 159
452 FORI=FTOTSTEP6: PRINT: PRINTRIGHTS ("@GG@G"+MIDS$(S
PRS) DQ) Siew s te srem 30
451 FORK=@T05 :N=PEEK(I+K) :PRINTRIGHTS ("@@"+MIDS(ST
RSCN)G 2) eS) 6s srem 66
460 GETAS: IFA$>""THENPRINT: PRINT: GOTO319 srem 25

280
Appendix I

47@ NEXTK: PRINTCHRS (20); :NEXTI: PRINT: PRINT: GOTO319


srem 50
480 IFN<@ THEN PRINT:GOTO319 zrem 168
490 A(J)=N:NEXTJ srem 199
5@@ CKSUM=AD-INT(AD/256)*256:FORI=1T0O6 : CKSUM=(CKSU
M+A(I))AND255:NEXT :rem 20
518 PRINTCHRS (18) ;:GOSUB578:PRINTCHRS$(146);:rem 94
511 IFN=-1THENA=6 :GOTO315 srem 254
515 PRINTCHRS (20) : IFN=CKSUMTHEN532 :rem 122
520 PRINT: PRINT"LINE ENTERED WRONG : RE-ENTER":PRI
NT :GOSUB1999:GOTO319 zrem 176
538 GOSUB28909 srem 218
540 FORI=1TO6:POKEAD+I-1,A(1I) :NEXT:POKE54272,@:POK
E54273,0 :rem 227
55@ AD=AD+6:IF AD<E THEN 319 srem 212
568 GOTO 719 :rem 188
570 N=0:Z=0 srem 88
580 PRINT"K£9"3 zrem 81
581 GETAS: IFAS=""THEN581 :rem 95
582 AV=-(AS="M")-2* (AS=",")—-3*(AS=".")-4*(AS="J")—

5* (AS="K")-6* (AS="L") srem 41


583 AV=AV-7* (AS="U" )-8* (AS="I")-9* (AS="0") : ITFAS="H
"THENAS="9" :rem 134
584 IFAV>@THENAS=CHRS (48+AV) :rem 134
585 PRINTCHRS(2@);:A=ASC(AS) : IFA=130RA=440RA=32THE
N670 srem 229
59@ IFA>128THENN=-A: RETURN :rem 137
600 IFA<>20 THEN 632 :rem 10
619 GOSUB69@: IFI=1ANDT=44THENN=-1:
PRINT" {OFF}
{LEFT} {LEFT}";:GOTO699 srem 62
628 GOTO579 :rem 189
630 IFA<480RA>57THEN58@ :rem 105
649 PRINTAS; :N=N*19+A-48 :rem 186
65@ IFN>255 THEN A=28:GOSUB1@G0:GOTO69G zrem 229
660 Z=Z+1:IF2<3THEN58@ srem 71
678 IFZ=OTHENGOSUB199@:GOTO579 :rem 114
688 PRINT", ";:RETURN :rem 242
698 S$=PEEK(209)+256*PEEK(210)+PEEK(211) :rem 149
691 FORI=1T03:T=PEEK(S$%-I) :rem 67
695 IFT<>44ANDT<>58THENPOKES$-I1,32:NEXT :rem 205
709 PRINTLEFTS("{3 LEFT}",I-1);:RETURN :rem 7
716 PRINT"{CLR}{RVS}*** SAVE ***{3 DOWN}" srem 236
715 PRINT"{2 DOWN}(PRESS {RVS}RETURN{OFF} ALONE TO
CANCEL SAVE) { DOWN}" :rem 196
728 FS="":INPUT"{DOWN} FILENAME";FS$:I1FFS=""THENPRI
NT: PRINT:GOTO310 -* :rem 71
73 PRINT: PRINT"{2 DOWN}{RVS}T{OFF}APE OR {RVS}D
{OFF}ISK: (T/D)" :rem 228
748 GETAS:IFAS<>"T"ANDAS<>"D"THEN74@ :rem 36

281
Appendix I

756 DV=1-7* (AS="D") : IFDV=8THENFS$="@0:"+F$ srem 222


766 TS=FS : ZK=PEEK(53)+256* PEEK(54)—-LEN(TS$) : POKE782
,2K/256 srem 3
762 POKE781,ZK-PEEK(782)*256:POKE78@,
LEN(TS) s:SYS65
469 srem 199
763 POKE789, 1: POKE781, DV: POKE782,1:SYS65466:rem 69
765 K=S: POKE254,K/256: POKE253, K-PEEK (254) *256:POKE
788,253 :rem 17
766 K=E+1 : POKE782,K/256: POKE781,K—PEEK( 782) *256:SY
$65496 srem 235
77 IF(PEEK(783)AND1)OR(ST AND191)THEN789 s:rem 111
PRINT" {DOWN }DONE. {DOWN}":GOTO319 srem 113
788 PRINT" { DOWN}ERROR ON SAVE. {2 SPACES }TRY AGAIN.
": [FDV=1THEN7 29 srem 171
781 OPEN15,8,15:INPUT#15,E1S,E2$:PRINTE1$;E2$:CLOS
E15:GOTO72@ srem 183
796 PRINT" {CLR}{RVS}*** LOAD ***{2 DOWN}" srem 212
795 PRINT"{2 DOWN}(PRESS {RVS}RETURN{OFF} ALONE TO
CANCEL LOAD)" :rem 82
88D FS=""sINPUT"{2 DOWN} FILENAME";FS$:IFFS=""THENP
RINT:GOTO319 a srem 144
810 PRINT: PRINT"{2 DOWN}{RVS}T{OFF}APE OR {RVS}D
{OFF}ISK: (T/D)" srem 227
828 GETAS : IFAS <>"T"ANDAS
<> "D"THEN828 :rem 34
839 DV=1-7* (AS="D") s IFDV=8THENFS="@: "+FS srem 157
846 TS=FS : ZK=PEEK(53)+256* PEEK(54)—-LEN(TS ) : POKE782
,2K/256 srem 2
841 POKE781,ZK—-PEEK(782)*256: POKE789, LEN(TS) :SYS65
469 srem 1907
845 POKE789, 1:POKE781,DV:POKE782,1:SYS65466:rem 79
850 POKE78@,9:SYS65493 srem 11
860 IF (PEEK(783)AND1)OR(ST AND191)THEN879 z:rem 111
865 PRINT" {DOWN }DONE. ":GOTO31@ srem 96
876 PRINT" {DOWN}ERROR ON LOAD. {2 SPACES }TRY AGAIN.
{DOWN }": IFDV=1THEN8GQ _ srem 172
889 OPEN15,8,15:INPUT#15,E1$,E2$:PRINTE1$;E2$:CLOS
E15:GOTO89@ srem 1902
1980 REM BUZZER srem 135
19001 POKE54296,15: POKE54277, 45: POKE54278,165
srem 207
1992 POKE54276,33:POKE 54273,6:POKE54272,5 srem 42
1993 FORT=1T0O20@0 : NEXT: POKE54276, 32: POKE54273,9:POK
E54272,0:RETURN srem 292
2806 REM BELL SOUND srem 78
2001 POKE54296,15:POKE54277,9:POKE54278,
247
srem 152
2882 POKE 54276,17:POKE54273,40:POKE54272,@:rem 86
2883 FORT=1TO1909:NEXT: POKE54276,16:RETURN srem 57
3080. PRINTCS; "{RVS}NOT ZERO PAGE OR ROM":GOTO19OD
srem 89

282
Appendix J

The Automatic Proofreader


Charles Brannon

“The Automatic Proofreader” will help you type in program


listings without typing mistakes. It is a short error-checking
program that hides itself in memory. When activated, it lets
you know immediately after typing a line from a program list-
ing if you have made a mistake. Please read these instructions
carefully before typing any programs in this book.
Preparing the Proofreader
1. Using the listing below, type in the Proofreader. Be
very careful when entering the DATA statements—don’t type
an | instead of a 1, an O instead of a 0, extra commas, etc.
2. SAVE the Proofreader on tape or disk at least twice be-
fore running it for the first time. This is very important because
the Proofreader erases part of itself when you first type RUN.
3. After the Proofreader is SAVEd, type RUN. It will
check itself for typing errors in the DATA statements and
warn you if there’s a mistake. Correct any errors and SAVE
the corrected version. Keep a copy in a safe place—you'll need
it again and again, every time you enter a program from this
book, COMPUTE!’s Gazette or COMPUTE! magazine.
4. When a correct version of the Proofreader is RUN, it
activates itself. You are now ready to enter a program listing.
If you press RUN/STOP-RESTORE, the Proofreader is dis-
abled. To reactivate it, just type the command SYS 886 and
press RETURN.
Using the Proofreader
All listings in this book have a checksum number appended to
the end of each line, for example “:rem 123”. Don’t enter this
statement when typing in a program. It is just for your informa-
tion. The rem makes the number harmless if someone does
type it in. It will, however, use up memory if you enter it, and
it will confuse the Proofreader, even if you entered the rest of
the line correctly.
When you type in a line from a program listing and press
RETURN, the Proofreader displays a number at the top of
your screen. This checksum number must match the checksum

283
Appendix J

number in the printed listing. If it doesn’t, it means you typed


the line differently than the way it is listed. Immediately re-
check your typing. Remember, don’t type the rem statement
with the checksum number; it is printed only so you can check
it against the number which appears on your screen.
The Proofreader is not picky with spaces. It will not no-
tice extra spaces or missing ones. This is for your convenience,
since spacing is generally not important. But occasionally
proper spacing is important, so be extra careful with spaces,
since the Proofreader will catch practically everything else that
can go wrong.
There’s another thing to watch out for: if you enter the
line by using abbreviations for commands, the checksum will
not match up. But there is a way to make the Proofreader
check it. After entering the line, LIST it. This eliminates the
abbreviations. Then move the cursor up to the line and press
RETURN. It should now match the checksum. You can check
whole groups of lines this way.
Special Tape SAVE Instructions
When you're done typing a listing, you must disable the
Proofreader before SAVEing the program on tape. Disable the
Proofreader by pressing RUN/STOP-RESTORE (hold down
the RUN/STOP key and sharply hit the RESTORE key.) This
procedure is not necessary for disk SAVEs, but you must dis-
able the Proofreader this way before a tape SAVE.
SAVE to tape erases the Proofreader from memory, so
you'll have to LOAD and RUN it again if you want to type
another listing. SAVE to disk does not erase the Proofreader.

Hidden Perils
The proofreader’s home in the 64 is not a very safe haven.
Since the cassette buffer is wiped out during tape operations,
you need to disable the Proofreader with RUN/STOP—
RESTORE before you SAVE your program. This applies only
to tape use. Disk users have nothing to worry about.
Not so for 64 owners with tape drives. What if you type
in a program in several sittings? The next day, you come to
your computer, LOAD and RUN the Proofreader, then try to
LOAD the partially completed program so you can add to it.
But since the Proofreader is trying to hide in the cassette
buffer, it is wiped out!

284
Appendix J

What you need is a way to LOAD the Proofreader after


you've LOADed the partial program. The problem is, a tape
load to the buffer destroys what it’s supposed to load.
After you’ve typed in and RUN the Proofreader, enter the
following lines in direct mode (without line numbers) exactly
as shown:
A$=“PROOFREADER.T”: B$=“{10 SPACES}”: FOR X = 1
TO 4: A$=A$+B$: NEXTX
FOR X = 886 TO 1018: A$6=A$+CHR$ (PEEK(X)): NEXTX
OPEN 1, 1,1,A$:CLOSE1
After you enter the last line, you will be asked to press
RECORD and PLAY on your cassette recorder. Put this pro-
gram at the beginning of a new tape. This gives you a new
way to load the Proofreader. Anytime you want to bring the
Proofreader into memory without disturbing anything else, put
the cassette in the tape drive, rewind, and enter:
OPEN1:CLOSE1
You can now start the Proofreader by typing SYS 886. To
test this, PRINT PEEK (886) should return the number 173. If
it does not, repeat the steps above, making sure that A$
(‘“PROOFREADER.T”) contains 13 characters and that B$ con-
tains 10 spaces.
You can now reload the Proofreader into memory when-
ever LOAD or SAVE destroys it, restoring your personal typ-
ing helper.

Replace Original Proofreader


If you typed in the original version of the Proofreader from
the October 1983 issue of COMPUTE!’s Gazette, you should re-
place it with the improved version below.

Automatic Proofreader
160 PRINT"{CLR}PLEASE WAIT...":FORI=886T01918:READ
A:CK=CK+A: POKEL,A:NEXT
11@ IF CK<>17539 THEN PRINT"{DOWN}YOU MADE AN ERRO
R":PRINT"IN DATA STATEMENTS. ":END
128 SYS886:PRINT"{CLR}{2 DOWN}PROOFREADER ACTIVATE
D.":NEW
886 DATA 173,836,003, 201,158,298
892 DATA @01,996,141,151,903,173
898 DATA 037,993,141,152,903,169

285
Appendix J

994 DATA 159,141,936,003,169,993


918 DATA 141,837,003,169,909,133
916 DATA 254,996,932,987,241,133
922 DATA 251,134, 252,132,253,988
928 DATA 261,013,248,017, 201,032
934 DATA 246,905,024,191, 254,133
949 DATA 254,165, 251,166,252,164
946 DATA 253,948,8996,169,913,9832
952 DATA 210,255,165, 214,141,251
958 DATA 063,206, 251,983,169,900
964 DATA 133,216,169,9819,032, 219
970 DATA 255,169,918,832,218,255
976 DATA 169,958,032, 218,255,166
982 DATA 254,169,9898,133,254,172
988 DATA 151,903,192,987, 298,906
994 DATA 632,205,189,9876, 235,083
1908 DATA 932, 205,221,169,032,032
1806 DATA 210,255,932, 219,255,173
1912 DATA 251,963,133, 214,976,173
1818 DATA 083

286
Index

ADSR envelope 109,128 Commodore 64 User's Guide 118


how generated by SID 111 control signal 105
relative settings for 119-20 “Copyfile” program 250-52
ADSR values CTRL keys 179
demonstration program 111-13 custom characters 139-45
analog synthesizers 105-7 decay 109, 119-20
modular design of 105 detokenization 197
AND operator 181 DIM statement 186
arrays 185-93 DLCS command (SuperBASIC) 221
defined 185-86 DRAW command (SuperBASIC) 221-22
string arrays 191 DRW2 command (SuperBASIC) 221
two-dimensional 187-88 DSPR command (SuperBASIC) 218
DIM statement and 186 duration (sound) 120-21
“Arrays and Grades” program 191-93 dynamic keyboard 92
ASC function 183 ECGR command (SuperBASIC) 219
ASCII codes 183, 195 educational games 87-103
table 269-72 criteria for good games 87-88
attack 109, 119-20 problems with 87
“Automatic Proofreader” 283-86 erasable pen 4
background color 157 ESPR command (SuperBASIC) 218
band-pass filter 113 EXTC command (SuperBASIC) 219
BANK command (SuperBASIC) 219 FBMS command (SuperBASIC) 221
BASIC Indirect Vector Table 196 FCOL command (SuperBASIC) 219
bit values, in sprite creation 171-73 “Filtered Sound” program 113-15
BKGD command (SuperBASIC) 219 filters, sound 13
BKG4 command (SuperBASIC) 219 FLIP command (SuperBASIC) 221
“BLAM!” 88-91 FLLN command (SuperBASIC) 221-22
BMGR command (SuperBASIC) 219 frequency modulation 115-17
border color 157 FSCR command (SuperBASIC) 221
BSPP command (SuperBASIC) 218 function keys 179-84
“Butterfly” program (Sprite BASIC) 175 ASCII values 183
bytes, 8 make one character 146 CTRL keys and 179
CB2K command (SuperBASIC) 221 explanation 180
character patterns 142-44 get and 80
character set 140-41 quote mode and 182-83
relocating 141-42, 147-48 GET command 180
CHAR command (SuperBASIC) 222 VAL and 181
“Chred 64” program 148-54 high-pass filter 113
CHR$ function 183 HRAM command (SuperBASIC) 223
CHRX command (SuperBASIC) 222 HRCS command (SuperBASIC) 222
“Circles” program (SuperBASIC) 239-40 IF-THEN 181
“Circus Sounds” program 130-31 interpreter, BASIC 196
CLPX command (SuperBASIC) 221 inverse characters 149
CMXV command (SuperBASIC) 220 jiffy 198
CODE command (SuperBASIC) 222 joystick 87, 88
commas 68 “Joystick-Controlled Sprites” program
Commodore 64 BASIC, limitations of (SuperBASIC) 240-41
194-95 keycodes
Commodore 64 Programmer's Reference table 275
Guide 118 keywords, adding new ones to BASIC
194-211

287
KMXG command (SuperBASIC) 220 SETP command (SuperBASIC) 221-22
KSPR command (SuperBASIC) 218 SID chip 105, 119-20
listing conventions 273-74 patch program for 108, 126
LOOK command (SuperBASIC) 223 “Simple PET Emulator” program
low-pass filter 113 (SuperBASIC) 241
“Machine Language Editor.’” See MLX “Siren’’ program 115-17
“Martian Prisoner’ 60-65 “64 Keywords” program 198-211
MCGR command (SuperBASIC) 219 “64 Mailing List’ 66-71
MCPL command (SuperBASIC) 221 “64 Merger” program 253-55
merging programs 253-55 “64 Program Lifesaver” 256-58
Microsoft BASIC 185, 195-96 “64set’’ program (SuperBASIC) 242-49
“MLX” 276-82 “64 Spreadsheet” 72-83
MOBs. See sprites SIZE command (SuperBASIC) 220-21
modifying BASIC 167-69 skill levels, importance of in games 88
“Moire Pattern” program (SuperBASIC) “Sound Editor 64” program 119-25
238-39 Sound Interface Device. See SID chir
MOVE command (SuperBASIC) 218 source signal 105
MOVE keyword (Sprite BASIC) 167, 168 “SpeedScript’” 3-39
Movable Object Blocks. See sprites command charts 37-39
multicolor mode 157 editing features 7-10
“Munchmath” 96-101 keyboard chart 16
musical instruments program 18-35
table of sound values for 123 “Spike” 41-59
MXGR command (SuperBASIC) 220 spreadsheet analysis, concepts 72-73
NEW command, undoing 256-58 spreadsheet model 73-76
“Note Name Game, The” 132-36 “Sprite Animation” program
NOT operator 181 (SuperBASIC) 241
octave 120 “Sprite BASIC”
OFF keyword (Sprite BASIC) 168 discussion 167-69
OR operator 181 enabling 167
patch 105-9 new keywords 167-68
patch cord 105 program 173-74
pixel 146 sprite creation 170-73
PLAY command (SuperBASIC) 218 bit computation 172-73
PLOT command (SuperBASIC) 221 SPRITE keyword (Sprite BASIC) 167, 168
POKE command sprite pattern block 158
inconvenient in sound programming sprites 155-176
126 custom characters and 170
inconvenient in sprite programming sprite seam 166, 169
166 sprite worksheet 171
pot (potentiometer) 108-9 SSND command (SuperBASIC) 218
digitizing 109-11 “Stars” program (SuperBASIC) 239
pulse width 121 STUF command (SuperBASIC) 223
quote mode 182-83, 263-64 subscript 185, 191
CHR$(34) and 183 “SuperBASIC 64” 156, 215-49
RAM (Random Access Memory) 141, command format 216
142, 144, 145, 147, 166-67, 196 command summary 226-27
release 109, 119-20 syntax errors and 223
ROM (Read Only Memory) 140, 142, “SuperBASIC Sprite Editor” program
144, 145, 147, 166-67, 196 155-65
screen codes sustain 109, 119-20
table 273-74 “SYS Sound” program 126-31
screen color codes 267-68 text adventures 60
screen color memory table 266 text color 157
screen location table 265 “Tie Fighter’ program (Sprite BASIC)
176

288
tokenization 195-96, 196-97 voices, on SID chip 119
tone 120 volume 119-20
two-dimensional arrays 187-91 VS1K command (SuperBASIC) 219
“Type 64” program 224-25, 242 waveform 121
typing in programs 263-64 wedge vector 215
UNDR command (SuperBASIC) 221-22 wedges, limitations of 195
VAL command 181 word processing concepts 3-4
VIC II chip (Video Interface Controller) “Wordspell” program 92-95
166 XYSC command (SuperBASIC) 220-221

289
2)A a pte
|
Pe a)
. oo |

Coie
ck
|
», eK
P.oeaaes.
:
ie ; < Pam eelyts)
oye * oF; ;

jay

ok ionl, as
“J s at
ti
COMPUTE!’s
NY=Yoro)
gfe fmsole) @reo) MmOre)palaglole(e)g-Mey-'

COMPUTE!’s Second Book of Commodore 64 continues the popular


tradition of presenting some of the best articles and programs
from COMPUTE! magazine and COMPUTE!s Gazette, as well
as several others which have never before appeared in print.
Like the best-selling COMPUTE!'s First Book of Commodore
64, this book includes dozens of complete, ready to type in
programs. There are even utilities which make your typing of
BASIC and machine language programs mistake-proof.
Some of the articles and programs included are:
e “Speedscript,”” a machine language word processor of
commercial software quality.
® Educational games for children which are fun to play,
yet teach skills from spelling to mathematics.
© A program which adds 41 new commands to BASIC.
i Wyawe (elcali(ore enee) aipralecernme) mearene elon) 1Ulcel meme) | DAelernre ment)oF
® How to add your own new BASIC keywords.
® Arcade-style games, from the fast-paced, all-machine-
language “Spike,” to a text adventure game where you
explore an alien spaceship.
@ A sprite editor.
i charetaverta) Wayeye) iterate ceyatcrme ince cerennarearayaedexelenO)nN(ONS)okeralebe
sheet program and a program to keep track of your files
or mailing lists.
® Programs which make mistake-free entry of machine
language and BASIC programs simple and easy.
If you've purchased a COMPUTE! Book before, you already
know about the high quality programs and clear explanations.
If this is your first COMPUTE! Book, you're in for some pleasant
surprises.

ISBN 0-942386-44-2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy