Computes All About The Commodore 64 Vol2
Computes All About The Commodore 64 Vol2
V •O •L•U •M •E T-W-O
Craig Chamberlain
V • O ♦L • U • M • E T- W- O
Craig Chamberlain
COMPUTE!' P ib f c a t io n s j n c ®
O ne of the ABC Publishing Com panies
ISBN 0-942386-45-0
10 9 8 7 6 5 4 3 2 1
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 trademark of Commodore
Electronics Limited.
Contents
Acknowledgments..........................................................................................vii
Foreword ....................................................................................................... ix
Introduction.................................................................................................. xi
P a r t 1 : A d v a n c e d B A S I C ....................................................... l
Chapter 1. Numbers and Mathematics .................................................3
Numerical Values for C on d ition s....................................................... 3
Precision and Scientific N o tatio n .................... 8
Integer Variables .................................................................................. 11
Random Number Seeding and Sequencing ................................ 15
Chapter 2 ♦ More F u n ctio n s.................................................................. 19
Print Formatting Fun ction s................................................................ 19
Transcendental F u n ctio n s.................................................................. 22
User-Defined Functions with the DEF Statem en t....................... 26
Chapter 3. File In p u t/O u tp u t.................................................................37
Introduction to I / O .............................................................................. 37
The OPEN and CLOSE S tatem en ts................................................ 38
The Printer and the CMD Statement ............................................ 45
Files on Tape ......................................................................................... 50
Disk Files ................................................................................................ 58
The Modem and Other RS-232 Devices ....................................... 71
P a r t 2 : B i t m a p p e d G r a p h i c s .................................................95
Chapter 5. The Bitmapped Graphics U tility ..................................... 97
Introduction to the Bitmapped Graphics Utility ......................... 97
The New Statements ......................................................................... 97
Graphics Modes and Point P lo ttin g .............................................. 106
Changing Colors ................................................................................ 110
Line D raw ing....................................................................................... 112
Area Filling ......................................................................................... 115
Multicolor Modes .............................................................................. 119
P a r t 3 : S i d p l a y e r ......................................................................... 183
Chapter 7. Introduction to Music and the Sidplayer ................ 185
Electronic Music ................................................................................ 185
The Sidplayer ..................................................................................... 186
Let the Music Play ............................................................................ 190
Fundamentals of Music Theory ..................................................... 206
Appendices ...................................................................................................465
A. A Beginner's Guide to Typing In Programs ......................... 467
B . How to Type In Programs ......................................................... 469
C. Using the Machine Language Editor: M L X ........................... 471
D. The Automatic Proofreader ....................................................... 478
E. Program Merge Utility ................................................................ 482
Index .............................................................................................................. 487
Acknowledgments
vii
Foreword
IX
them on the screen at incredible speeds. The computer will
move them for you, or you can control them with the joystick.
In a matter of minutes you can have sprites bouncing, dis
appearing, reappearing, crawling, and flying through your
own programs. Even though you may know how to program
just in BASIC, you can create impressive arcade-quality games
with the Control System.
Each of these utilities can be used separately, or in any
combination. They let you control, through your own BASIC
programs, some of the most advanced features available on
any home computer.
There's even more information in All About the Com
modore 64, Volume Two. An entire section is devoted to ad
vanced BASIC programming techniques. It picks up where
Volume One left off. You'll learn about advanced functions,
file input/output, and the little-known, but powerful, WAIT
statement.
All the programs in Volume Two are ready to type in.
Error-checking programs make typing them in easy.
If you prefer, you can purchase all the programs from
Parts 2, 3, and 4 on disk for $12.95 plus shipping by calling
toll free 1-800-334-0868.
With the information and utilities included in this book,
you can turn your 64 into the computer you've always hoped
it would become. Powerful features become convenient
enough to use. Everything is clearly documented and illus
trated, from the simplest technique to the most advanced.
With All About the Commodore 64, Volume Two, you can have a
new computer. It may look like your old 64, but it's not. It's a
machine that's opened up hundreds of new doors into per
sonal computing.
x
Introduction
xi
understand this book, both are necessary to completely ex
plore the capabilities of your computer.
Advanced BASIC
Part 1 picks up where All About the Commodore 64, Volume
One left off. The advanced features of BASIC are explored, de
fined, and illustrated.
Chapters 1 and 2 cover subjects such as user-defined
functions and how to simplify IF-THEN statements. Chapter 3
discusses peripherals, such as printers and modems. The ad
vanced topic of tape and disk files is presented with numerous
examples. A simple terminal program is even included for
those of you who have a modem. Finally, Chapter 4 covers
several miscellaneous items (how to call machine language
from a BASIC program, for instance).
Since the topics in this section are somewhat advanced
and may not be immediately applicable, you might want to
skip over these chapters and move to the graphics and sound
utilities first. However, there is a wealth of information in
cluded in this section— it's nice to know that it's there when
you need it.
Bitmapped Graphics
This collection of machine language routines lets you work
with high-resolution and multicolor graphics. To make them
as accessible as possible, they're written in the form of state
ments which can be added to BASIC. Even more important,
the routines don't take up a single byte of BASIC's free
memory.
New BASIC statements like GRAPHICS and DRAW are
used to clear the bitmap screen and do high-resolution plot
ting, while others let you quickly draw lines and fill in areas.
The SHAPE statement lets you draw a complete object at any
place on the screen. There's even a program— “Shapedit"—
that helps you create a library of shapes.
Sidplayer
The SID (Sound Interface Device) chip built into your 64 is a
rather complex integrated circuit. However, “Sidplayer," the
music editing program included here, has been carefully de
signed so that everyone can use it. No particular musical
knowledge is required; in fact, it's so easy to use that you can
xii
enter a song without knowing how to read sheet music.
As well as detailing Sidplayer's advanced features, this
section offers a discussion of the fundamentals of music
theory.
Sidplayer is capable of emulating a wide variety of in
struments, and any music you create with it can be merged
with other BASIC programs. The music will play while the
program is doing something else. Several demonstration tunes
are even provided.
X lll
Part 1
Advanced
BASIC
Chapter 1
3
Chapter 1
4
Chapter 1
5
Chapter 1
Instead, one line was saved by writing the code this way:
240 IF X<0 OR X>39 THEN X=-39*(X<0)
Summary
• The values true and false have corresponding numerical val
ues, —1 and 0.
6
Chapter 1
7
Chapter 1
8
Chapter 1
9
Chapter 1
10
Chapter 1
Summary
• Commodore 64 BASIC uses a maximum of nine digits to
represent any number. If a number is made up of more than
that, the nine most significant digits (leftmost digits) are
used. The remaining digits are dropped.
• When digits have to be dropped, the nine-digit number is
rounded up or down (depending on the tenth digit). If the
tenth digit is 5 or more, the number is rounded up; other
wise, it's rounded down.
• Values need not have more than nine digits for the computer
to have trouble representing them. Examples showed how
the 64 has difficulty handling the number 0.01.
• The computer's internal representation of a number may be
slightly different from the printed form. The result of 1.01 —
.01 prints as 1, but is not equal to 1 in IF-THEN comparisons.
• Sometimes it's possible to rewrite a line or lines to reduce the
problems associated with precision.
• Scientific notation can be used to represent numbers with
more than nine digits to one side of the decimal point. Any
number can be represented as a number from 0 to 9 times 10
raised to a power. The number 1234567890 is represented as
1.23456789E + 09 in scientific notation. The 1.23456789 is
called the mantissa, the E means times 10 to the ..., and the
+ 09 is called the exponent.
• In practical terms, E + n , where n is a number, means that the
decimal point should be moved n places to the right, with
zeros added if necessary.
• Scientific notation makes it easier to read numbers with lots
of digits and reduces the chance of error.
• If a value exceeds 1.70141183E + 38, BASIC will stop with an
OVERFLOW error.
• All numbers of magnitude less than 0.01 are represented in
scientific notation. The number 0.00123 becomes 1.23E —03,
with E —03 meaning that the decimal point should be moved
to the left three places.
• Numbers less than 2.93873588E —39 are converted to 0. No
error occurs when this happens.
Integer Variables
In All About the Commodore 64, Volume One, the concept of
type was introduced. The variable type helps describe what
11
Chapter 1
1-1. Notice that the largest integer less than —5.4 is not —5,
but —6.
- 5 .4
13
Chapter 1
Summary
• Numeric variables used up to now are more accurately called
floating-point variables.
• Type describes what kind of information is being conveyed
by a variable. The two types of variables used thus far have
been floating-point and string variables.
• Integer numbers include the counting numbers 1, 2, 3, ...,
their negative counterparts, and 0. A fraction cannot be ex
pressed by an integer.
14
Chapter 1
15
Chapter 1
Summary
• The random function, RND, returns a random decimal num
ber between 0 and 1.
• When RND is called with an argument of 0, the value re
turned is based on a hardware timer. However, only a few of
the possible numbers are ever returned. In other words, the
numbers are not very dense.
• Calling RND with an argument greater than 0, such as 1,
makes the function return a value based on a repeating se
ries. Values returned by RND(l) are dense. The only problem
with RND(l) is that it returns values in the same order every
time the computer is turned on.
• The random number generator can be "seeded" by calling
RND with a negative argument. For each negative number,
or seed, the values returned by RND(l) start at a different
place in the series.
• To get truly random numbers (dense and different each time
the computer is turned on), the random number generator
should be seeded with a random value as part of a program's
initialization. Using RND( —TI) should be satisfactory.
17
Chapter 2
More Functions
19
Chapter 2
20
Chapter 2
Summary
• A physical line is one of the 25 rows on the screen.
• A logical line can consist of one or two contiguous rows. A
logical line becomes two rows long when typing at the right
edge of the screen wraps around to the next row at the left
edge.
• BASIC program lines are one logical line long, which is why
they cannot be longer than 80 characters.
• When RETURN is pressed, the cursor moves to the begin
ning of the next logical line.
• Logical lines also affect screen scrolling.
• The POS function returns the current position (columns
0-79) of the cursor within a logical line. Columns 40-79 in
dicate the second row of a logical line. Unfortunately, POS
has few applications.
• TAB and SPC are special kinds of functions which can be
used only in a PRINT statement. They control cursor
21
Chapter 2
Transcendental Functions
This section presents a group of functions that are used mainly
in mathematics-oriented applications.
The SQR function returns the square root of its argument.
The square root of number N is the number that, when mul
tiplied by itself, produces N. Thus, the square root of 9 is 3,
because 3*3 is 9; the square root of 16 is 4. The square root of
12 is somewhere between 3 and 4, but the decimal representa
tion for this number continues indefinitely. With nine digits
the value can be approximated as 3.46410162. Square roots of
negative numbers are undefined, so using a negative argument
with SQR causes an ILLEGAL QUANTITY error.
Finding the square root of a number is the same as raising
the number to the power of 1/2. Square roots can also be cal
culated by using the exponentiation operator— the up-arrow
key on your Commodore 64 (t)— with the value 0.5. That's
why both the following lines produce the same result.
PRINT SQR(12)
PRINT 12T.5
The only advantages to using SQR instead of the
exponentiation operator are that SQR is easier to read, and it
executes just a little faster.
22
Chapter 2
23
Chapter 2
24
Chapter 2
25
Chapter 2
Summary
• The SQR function returns the square root of its argument.
The argument must be greater than or equal to zero, or an
ILLEGAL QUANTITY error occurs. The function is used in
stead of raising a number to the power 0.5 because it's easier
to read and executes slightly faster.
• The EXP function raises the natural number e, approximately
equal to 2.71828183, to the power indicated by its argument.
If the power is greater than 88.0296919, the OVERFLOW er
ror occurs. If the power is less than —88.0296919, EXP will
return 0. EXP is used instead of exponentiation because it's
easier to read and it executes significantly faster than raising
e to a power.
• The function LOG returns the natural logarithm, the log to
the base e, of its argument. The argument must be greater
than zero to prevent the ILLEGAL QUANTITY error.
• The 7r symbol can be used to represent the value 3.14159265,
an approximation of the mathematical constant pi.
• The SIN and COS functions return the sine and cosine,
respectively, of the angle specified (in radians) as the argu
ment. Extra multiples of 2* x (360 degrees) are removed
from the angle. The value returned is a decimal number from
- 1 to 1.
• It's possible to convert radians to degrees, and vice versa. To
convert n degrees to radians, multiply n by x /1 8 0 . To con
vert n radians to degrees, multiply n by 1 8 0 / x .
• The TAN function returns the tangent of the angle (expressed
in radians) given by the argument. TAN is not defined for
the angles x /2 , 3* x /2 , and equivalent angles. Using any of
these causes the DIVISION BY ZERO error.
• The ATN function is used to calculate the arctangent (inverse
tangent). It returns the angle in radians which has the tan
gent specified as the argument. ATN will always return val
ues from — x / 2 to x /2 .
• Formulas can be used to obtain other trigonometric functions,
such as the remaining inverses and the hyperbolics.
26
Chapter 2
The value 1.234 becomes 1.23, but 1.235 will become 1.24.
Other computers may have a rounding process included
in their BASIC. It's usually implemented in the form of a func
tion, so that rounding a number can be as easy as saying
PRINT ROUND(N). Since Commodore 64 BASIC has no
rounding function, the formula will have to be placed in a
program wherever a number has to be rounded. If rounding
was necessary in several parts of the program, this could take
a fair amount of typing. The formula is somewhat com
plicated, and every time you enter it, you increase the chance
of error. One solution is to use a subroutine instead, some
thing like the program segment which follows.
10 INPUT N:GOSUB 60:PRINT A
20 GOTO 10
60 A=INT(N*100+.5)/100:RETURN
27
Chapter 2
The keyword DEF, the function name prefix FN, the function
name, parentheses containing a variable, an equal sign, and fi
nally an expression. The restrictions which apply to variable
names apply to function names (only the first two characters
are significant, the first character must be alphabetic, and the
remaining characters are optional and must be alphanumeric).
The expression should be defined in terms of the variable in
the parentheses. This is rather complicated, so here's an
example.
10 DEF FNR(N)=INT(N*100+.5)/100:REM DEFINES FUNCTI
ON ’R ’
To call the newly defined function, the function name pre
fix FN should be followed by the function name R, with
parentheses containing an argument.
You don't even have to use a variable. Make sure the two-line
program from above (with either version of line 20) is loaded
and run, hit the RUN/STOP-RESTORE key combination, then
type this line in immediate mode (without a line number).
PRINT FNR(5.118)
You'll see 5.12 returned as the result.
The purpose of the variable in the definition is to show
the relationship between the argument and the expression.
The statement DEF FNR(N) = INT(N*100 + .5)/100 really
28
Chapter 2
29
Chapter 2
20 PRINT FNG(0)
30
Chapter 2
31
Chapter 2
10 DEF FNDP(A)=PEEK(A)+256*PEEK(A+l)
The "double PEEK" function PEEKs the two locations and
returns the address they contain. If you type in and run the
line above, then enter PRINT FNDP(«), where n is the low
byte location, the function will calculate the address and dis
play it.
You may have noticed that part of the definition for func
tion L is the same as that for function H. Can one defined
function call another? Certainly. Take a look at this line.
10 DEF FNH(N)=INT(N/256):DEF FNL(N )=N-256*FNH(N )
The only thing you don't want a function definition to do
is call itself. BASIC won't know how to deal with that and in
dicates its confusion by printing the OUT OF MEMORY error
if the function is called.
10 DEF FNB(X)=3+FNB(X ) : REM WRONG
If there are any SYNTAX ERRORS in the expression for
the function definition, they won't be detected until the func
tion is actually called. It's also possible for an error to occur
within a defined function, such as ILLEGAL QUANTITY, DI
VISION BY ZERO, or OVERFLOW. In all these cases, when
BASIC stops and prints the error, the line number indicated is
the line of the function call, not the definition.
Another error associated with user-defined functions is
UNDEF'D FUNCTION. This happens whenever a program
tries to call a function not yet defined. The most common
causes are either forgetting to define the function or using dif
ferent names for the function definition and call.
Once a function has been defined, it doesn't have to keep
that definition. If a function name is already in use, but placed
in another DEF statement, the old definition will be replaced
with the new. This also means that it's okay for the same DEF
statement to be executed more than once. No error will occur.
Defined functions are erased by the CLR statement.
The argument in a DEF statement must be a floating-point
variable. Using a string variable or an integer variable leads to
a SYNTAX ERROR.
Finally, like the GET and INPUT statements, the DEF
statement can be executed only in a program. Attempting to
define a function in the immediate mode only causes the
ILLEGAL DIRECT error.
32
Chapter 2
Summary
• Sometimes you'll find yourself entering the same expression
again and again. Often the expression performs some process
on a value. Repeatedly typing the same expression should be
avoided, not only to eliminate extra work, but also to lessen
the chance of error.
• The ideal way to handle such an expression is to implement
it as a function. The value used by the expression could be
the argument, and the number produced by the expression
could be the value returned by the function.
• One of the best features of Commodore 64 BASIC is that it
lets you create new functions through the DEF statement.
Functions defined with DEF behave just like standard BASIC
functions. They have a name, take an argument, and return a
value.
• The syntax for the DEF statement is: DEF, the function
name prefix FN, the function name, parentheses containing a
floating-point variable for an argument, an equal sign, and
an expression.
• Function names follow the same syntax rules as variable and
array names. The first character must be alphabetic and the
remaining characters, which are optional, must be alpha
numeric. Only the first two characters are significant.
• The variable in parentheses is called the argument variable.
The expression is defined in terms of this argument variable.
Every occurrence of the argument variable name in the ex
pression is used to represent the value passed as the
argument.
• The argument variable is used only as a place holder, to
show the relationship of the argument to the expression. Any
variable name can be used, even one that does not appear
elsewhere in the program.
• The DEF statement can be used only in program mode.
• To call a defined function, use the prefix FN followed by the
function name, then parentheses containing an argument that
is passed to the function.
• When the function is called, BASIC refers to the expression
in the definition and substitutes the argument passed for ev
ery occurrence of the argument variable. BASIC then eval
uates the expression and returns the result as the function
value.
33
Chapter 2
• When the low and high bytes of an address are POKEd into
memory locations, two very important rules must be fol
lowed: First, the locations must be contiguous. Second, the
low byte is always POKEd into the first location, and the
high byte is always POKEd into the second location.
• An address can be reconstructed after it has been broken
down into low and high bytes and POKEd into locations. To
get the original value, PEEK the second location, multiply it
by 256, and add the result to the value found in the first
location.
• A common application of defined functions is to calculate
low and high bytes, and to reconstruct addresses. In this
book, functions L and H are always used to take an address
and return the low and high byte, respectively. Function DP
will always take a location number, PEEK the location and
the one that follows, and return a reconstructed address.
35
Chapter 3
File Input/Output
Introduction to I/O
A computer is a communications device— it moves information
from one place to another. The most common example is
when the computer accepts information from a user through
the keyboard, and presents information by displaying it on a
screen. This process of communicating is referred to as
input/output, and is often abbreviated as I/O .
The keyboard and screen are not the only parts of a com
puter system that can be involved in input/output. Other
peripherals, such as a printer, tape recorder, disk drive, or
modem, can also be used to transfer information. With a
printer, you can get a permanent copy of a program listing or
program results on paper. The Datassette recorder and the
disk drive can be used to load and save programs and other
kinds of information. By using a modem and a telephone, you
can connect your computer to other similarly equipped
computers.
Collectively, the keyboard, screen, printer, Datassette, disk
drive, and modem are called devices. The transfer of infor
mation takes place between the computer and one of these de
vices. An important aspect of this information exchange is the
direction in which the information is traveling. The direction
describes whether information is being sent or being received,
and is always described from the point of view of the com
puter. If the computer is receiving information from a device,
the term input is used. When the computer is sending infor
mation to a device, it's termed output. Sometimes the terms
reading and writing are used to mean receiving and sending.
With some devices, only one direction is possible. For ex
ample, the keyboard can be used only to input information.
The keyboard is not capable of displaying information, and it
would be ridiculous to try to make the computer send infor
mation to the keyboard. On the other hand, the printer is an
output-only device. Information cannot be entered into the
computer through the printer. Devices such as the Datassette,
disk drive, and modem, however, support both input and
output.
The purpose of this chapter is to show you how BASIC
can be used to make the computer communicate with other
37
Chapter 3
Summary
• The process of the computer communicating is called
input/output, abbreviated I/O . A typical example is when the
computer receives information from the keyboard and trans
mits information to the screen.
• Those parts of the computer system which can be used for
input or output— the keyboard, screen, printer, Datassette,
disk drive, and modem— are called devices. The transfer of
information takes place between the computer and a device.
• The direction of the transfer is described from the point of
view of the computer. When the computer accepts infor
mation from a device, the term input is used. Output applies
to information sent from the computer to a device.
• Some devices are capable of communicating in only one
direction. The keyboard can be used only to input infor
mation, for instance, and the printer can be used only to out
put information. Other devices, including the Datassette, disk
drive, and modem, can communicate in both directions.
• The rest of this chapter will show how to use variations of
GET, INPUT, and PRINT to communicate with all devices,
not just the keyboard and screen.
file works will become clearer as you explore its function and
use.
A file is created by the OPEN statement, which has the
following syntax:
OPEN file number, device number, command number, filename
The file number, sometimes also called the logical file number,
can range from 1 to 255. Numbers greater than 127 may have
special significance and normally should not be used. The ac
tual value is chosen by the programmer, but the most com
mon is 1. The file number will later be used by the GET,
INPUT, and PRINT statements.
Since it's possible for several devices to be active at the
same time, the file number is needed to distinguish one cur
rently active file from another. For example, a program could
print a prompt on the screen, wait for a response on the key
board, print a status message on the printer, and read in some
information from the disk. For each device that's used, a new
file must be created with a different file number. In the ex
ample above, the screen might have been opened as file 1, the
keyboard as file 2, the printer as file 3, and the disk as file 4.
The device number is needed to specify which device is
associated with the file. Each device is identified by its own
number.
Number Device
0 Keyboard
1 Datassette
2 RS-232 (modem)
3 Screen
4 Printer
5,6,7 Other devices
8 Disk drive
As long as the file is open, the device indicated by the device
number will correspond with the file. All references to the file
will be directed to the specified device.
The command number is also called the secondary ad
dress. It's not needed when using the keyboard or screen, and
will be discussed in a later section.
The filename is needed when working with devices such
as tape or disk drive. Like the command number, the filename
will be dealt with later.
39
Chapter 3
10 OPEN 1,0
40
Chapter 3
see, INPUT used with a file is different from the INPUT with
which you're already familiar.
The explanation of these differences is that the plain IN
PUT is a special form of INPUT#. Because INPUT is always
used with the keyboard, features like prompt messages and er
ror handling are helpful. However, since INPUT# may be
used to fetch information from a device other than the key
board, such as a data file on tape, features like prompt mes
sages would not be appropriate or even desirable.
Let's try using the screen for output. Erase the old pro
gram by typing NEW, and enter this one.
10 OPEN 1,3 : REM 3 IS FOR SCREEN
20 PRINT#1,34
30 PRINT#1,"HAPPY BIRTHDAY"
40 PRINT#1,64,46
41
Chapter 3
If you run this, you'll not see a FILE OPEN error. That's
because the CLOSE statement closed file 1 after it was used.
At this point you may be wondering why it's even nec
essary to bother with a file at all. Instead of a file number after
PRINT# and INPUT#, why not just use the device number?
The answer lies in the fact that with some devices, other infor
mation besides a device number is needed. Input/output with
the disk or cassette requires that a filename be specified.
Entering the filename in an OPEN statement once, and then
using the corresponding file number in each subsequent
PRINT# or INPUT# statement is a lot easier than typing the
filename every time those statements are used.
Another reason is that some devices (such as the disk
drive) permit more than one file to be open at the same time.
The computer could input information from two different disk
42
Chapter 3
files. Since the device number for both these files would be 8,
just using a device number in an INPUT statement would not
be enough— the computer couldn't tell them apart. File struc
ture using OPEN and CLOSE provides an organized means of
communicating with all types of devices, and has proven to be
a good method for general input/output.
There are a few other errors which can appear when
using file input/output. You've already seen the FILE OPEN
error when you tried to open an already opened file. The FILE
NOT OPEN error occurs when you try to access a file that has
not been opened. You'll see this error when you run this next
program.
10 OPEN 1,3
20 PRINT#3 : REM FILE 3 NOT OPENED YET
43
Chapter 3
Summary
• The OPEN statement is used to create a file through which
input/output will be done. A file is the programming link
between the computer and a device.
• The full syntax for the OPEN statement is the keyword
OPEN, a file number, a comma, a device number, another
comma, a command number, one more comma, and then a
filename.
• The file number, also called the logical file number, is used to
distinguish one active file from another. It's necessary be
cause there may be several different files open at the same
time.
• The file number is chosen by the programmer and may range
from 1 to 255. File numbers greater than 127 are reserved for
special purposes. File numbering usually starts at 1.
• The file number will later be used in the PRINT#, GET#,
and INPUT# statements.
• The device number is used to identify the device associated
with a file.
• A file can use only one device.
• The command number, also called the secondary address, and
the filename are optional, and are covered in a later section.
• To make the INPUT statement read from a file instead of the
keyboard, use INPUT#, the file number, a comma, and then
a variable list, as in INPUT#1,N. No space is allowed be
tween INPUT and the # symbol.
• The INPUT statement is actually a special form of INPUT#
which is always set for keyboard input.
• Features like REDO FROM START and EXTRA IGNORED
warning messages are not available with INPUT#. If IN
PUT# is expecting a numeric variable and gets characters,
BASIC stops with a FILE DATA error. There's no warning if
extra information is available. Also, INPUT# does not sup
port an optional prompt string.
44
Chapter 3
45
Chapter 3
You can also use a variable for the device number in the
OPEN statement and let the person running the program de
cide where the information will be sent. This technique is
demonstrated by the next program.
10 INPUT "OUTPUT DEVICE NUMBER"?DN
20 OPEN 1, DN
30 PRINT#1,"MUSIC FILE LISTING"
The program user could enter either 4 for printer output
or 3 for the screen. Using the OPEN statement like this means
that you don't have to worry about where the printing will be
sent. You can write the program just like any other, and as
long as you use PRINT# wherever you would normally use
PRINT, it will have the ability to send output to the printer,
screen, or any other device.
There are just a few minor differences between printing
on the screen and printing on paper. One obvious difference is
that the printer will not know what to do with special CHR$
codes which move the cursor, change the current character
color, or clear the screen. Printers usually do not have
backspacing capability and cannot erase anything that's al
ready been printed.
A more subtle difference has to do with the print format
ting functions, POS and TAB. Both of these depend on the
current location of the screen cursor. The POS function returns
that value, and TAB uses it to determine how many spaces the
cursor should be moved to the right. Since the screen cursor
does not move when information is sent to the printer, these
functions will not work correctly with printer output. This is
not a major inconvenience, though, because the SPC function
will still work and can be used to simulate TAB. The comma
used for far spacing and printing in columns will also work
differently for printer output.
The combination of OPEN and PRINT# can be very
powerful. Nevertheless, there are some instances when it
would be nice to send output to the printer which is not
46
Chapter 3
47
Chapter 3
program which uses PRINT statements, but you want the out
put to be sent to a device different from the screen.
You might wonder why PRINT# has to be used at all if
CMD is available. As it turns out, there are some reasons why
it's better to use PRINT#. The major reason applies when you
want your program to communicate with more than one de
vice. If you use CMD to send output to one device and then
switch to another, output may in some cases end up going to
both. Also, CMD can sometimes turn itself off even when the
file has not been closed.
PRINT# is more reliable and is usually the better choice.
CMD is best used in the immediate mode when you want to
do something that can't be done with PRINT#, such as listing
a program to the printer. When using CMD in a program,
make sure the program is sending output to only one device.
The remaining topics concerning the printer have to do
with special modes of operation.
The file number in OPEN should normally be in the
range 1-127. File numbers greater than 127 have a special
meaning when used with the printer, because they instruct the
computer to send a linefeed character after every carriage re
turn. The linefeed character makes the printer advance the pa
per one line. Most printers do this automatically when they
receive a carriage return. A printer which does not have this
feature will keep printing on the same line. If your printer
doesn't have the automatic linefeed feature, or if it does and
you want the printer to use double-spacing, use a file number
from 128 to 255.
If you're using a Commodore printer, the third parameter
of the OPEN statement, the command number, can be used to
select a character set. When no command is specified, the
printer assumes that the command number is 0, which means
that the uppercase and graphics character set will be used.
OPEN 1,4 : REM UPPERCASE/GRAPHICS
or
OPEN 1,4,0 : REM UPPERCASE/GRAPHICS
If you want the printer to use the uppercase/lowercase
set, use 7 as the command number.
OPEN 1,4,7 : REM UPPERCASE/LOWERCASE
Remember, this applies only to Commodore printers.
48
Chapter 3
Summary
• To send program output to the printer, open a file to device 4
and use PRINT#.
• When sending output to the printer, the formatting functions
POS and TAB, and comma spacing, will not work correctly.
• To send computer-generated output (such as a program list
ing) to the printer, open a file to device 4 and use the CMD
statement. The statement's syntax is the keyword CMD, the
file number, and an optional comma and string.
• The file must already be open, or the FILE NOT OPEN error
will occur.
• If a string is included with the CMD statement, it will be sent
to the file. A typical use of this feature is to title a program
listing.
• When executed, CMD redirects all output that normally de
faults to the screen to go to the file instead. This includes
output from PRINT, as well as messages generated by the
computer, such as the READY, prompt.
• CMD has no effect on printing sent to a file by PRINT#,
even if the device associated with the file is the screen.
• When CMD is being used with a device other than the key
board or screen, it's a good practice to send an empty print
line to the file before closing it.
• CMD stays in effect until the file is closed or an error occurs.
In either case, printing reverts back to the screen.
• It's best to use CMD only in situations where PRINT#
49
Chapter 3
Files on Tape
Thus far you've probably used the Datassette only for storing
and retrieving programs. This storage and retrieval is nec
essary because the computer can hold only one program in
memory at a time— anything in memory is erased when the
computer is turned off. It's much easier to load a program
than it is to retype it every time you want to use it!
When a program is saved to tape, it's stored as a file
consisting of program lines. That doesn't mean tape files can
contain only program lines. They can contain other infor
mation, such as numbers and character strings, just as easily.
Just as a program is lost when the computer is turned off, so is
the data maintained by that program. You may want a pro
gram to save this data to tape for future reference.
An example is a word processing program which saves a
document on tape for later changes and reprinting. Or a game
might maintain a high-score file that would have to be peri
odically updated. A mailing list program is of little value if it
can't save the names and addresses on tape or disk. A long
and complex adventure game may have an option to stop play
and continue later, in which case the current character status
would have to be saved. These are all excellent applications of
data files on tape.
50
Chapter 3
51
Chapter 3
52
Chapter 3
53
Chapter 3
(These programs only demonstrate the method, and are not in
tended to be practical applications.)
54
Chapter 3
56
Chapter 3
Summary
• A tape file is not limited to storing only the lines of a pro
gram. Tape files can also contain data, in the form of num
bers and strings, which can be used by a program.
• The Datassette can be used for both input and output, but
can handle only one direction at a time. The direction (input
or output) must be specified when the file is opened.
• Opening a tape file uses the full syntax of the OPEN state
ment: OPEN file number, device number, command number,
filename.
• The device number for the Datassette is 1.
• A command number of 0 opens the file for input; 1 opens
the file for output. Using 2 also opens the file for output, but
marks the file as the last on the tape when it's closed. The
command number is optional— by default, the file will be
opened for input.
• A filename is optional but recommended. If none is specified
when the file is created, none can later be used when the file
is opened for reading.
• It's a good idea not to use a variable list after PRINT#. Com
mas in PRINT statements are used to format the screen dis
play into columns, which is not necessary with tape files.
Instead, output the items one at a time so that a carriage re
turn will be printed after each. If you do use a variable list,
print a CHR$(13) between each item.
57
Chapter 3
Disk Files
The type of file just described for cassette is often referred to
as a sequential file, one in which the information can be read
back only in the order it was written. It's not possible to re
read just one item in the file; you have to use OPEN again
58
Chapter 3
and start at the beginning. With a sequential file it's also not
possible to skip some items to read one later on. If a file has
just been opened and you want to read only its last item, you
have to read past all the other items first.
Sequential files are the simplest and most commonly used
type of file. They are well-suited to the Datassette, because the
computer cannot control the REWIND and F.FWD buttons.
The nature of tape means that the Datassette can handle only
sequential files.
But sequential files can also be used with the disk drive.
There are a couple of differences in the OPEN statement, but
otherwise the procedure is the same.
OPEN file number, device number, secondary address, string
Any file number from 1 to 127 is acceptable. The device
number for the disk drive is usually 8, although it can be
changed to 9 when a second drive is used. The command
number, also called the secondary address, serves a different
purpose when using disk files. It will be explained in a mo
ment. For now, just use 2. The string is required, and indicates
the filename, type of file, and direction. The filename can be
up to 16 characters, and is sometimes followed by the type of
file (indicated by an S representing sequential) and perhaps a
letter R or W, reading or writing. Commas are necessary to
separate the filename, the type, and the direction. You must
specify the type of file if you're writing to the disk— if you're
only reading the file, you can omit the S designation. If no
direction is indicated, the computer will open the file for read
ing. Here are some examples.
OPEN 1,8,2,"DOODLE,R" : REM READING, NO TYPE NEEDED
OPEN l,8,2,"POEM,S,W" : REM WRITING, TYPE SPECIFIED
OPEN 1,8,2,"GAME" : REM READING ASSUMED
With minor changes, the high-score demonstration from
the "Files on Tape" section can be used with a disk file. Type
in both programs below. Load and run the first (make sure
there's a disk in the drive). This creates a sequential file on
disk. Now load and run the second. It reads the file from disk
and displays the items on the screen.
100 OPEN 1,8,2,"HI SCORES,S,W"
110 PRINT#1,"KEVIN" CHR$(13) 80
120 PRINT#1,"CHRISTINE" CHR$(13) 90
130 PRINT#1,"ALISDAIR" CHR$(13) 91
59
Chapter 3
Examine the directory of the disk you just used. You'll no
tice that beside the filename HI SCORES is a three-letter code,
normally PRG for a program file, but now SEQ. This is to re
mind you that it's a sequential file, contains data, and should
not be loaded as a program.
The method of reading and writing a sequential file is
pretty much the same for both tape and disk. A major dif
ference between these two devices, though, is in the number
of files that can be open at one time. While the Datassette can
read or write only one file at a time, the disk drive can handle
several files simultaneously. Files 1 and 2 could be open for
reading, while file 3 would be open for writing. The only
restriction when using multiple disk files is that each file must
have a different secondary address. Secondary address num
bers can range from 2 to 14.
100 REM PAYROLL PROGRAM
110 OPEN 1,8,2,"EMPLOYEES,R"
120 OPEN 2,8,3,"HOURS,R"
130 OPEN 3,8,4,"PAYCHECKS,S,W"
This program might read an employee's name and Social
Security number from the first file, get the hours and wage
information from the second, do whatever processing is nec
essary, and then send the results to the third. This last file
would be used later to print paychecks. The example may not
be practical, but it does illustrate how several disk files can be
managed. Most applications don't require as many files open
at the same time.
Another capability of the disk drive is that it can allow
two open files to read from the same disk file.
60
Chapter 3
This will not work when a disk file is written. Once a disk
file has been opened for output, it cannot be opened by a dif
ferent file number for either input or output until it's closed.
A complication when using multiple files is that the status
variable (ST) must serve for all files. ST always reflects the sta
tus of the most recently accessed file. This means that if a pro
gram reads from file 1, then from file 2, ST indicates the status
of file 2— file l's status information is lost. The solution is to
assign ST to a temporary variable before accessing file 2. This
variable can then be used to determine the first file's status.
This next program illustrates the procedure.
100 REM READ ONE FILE TO ANOTHER
110 OPEN 1,8,2,"SOURCE,R"
120 OPEN 2,8,3,"DESTINATION,S,W"
130 INPUT#1,S$
140 A=ST
150 PRINT#2,S$
160 IF A=0 GOTO 130:REM BASED ON FILE 1 STATUS
170 CLOSE 1
180 CLOSE 2
190 END
62
Chapter 3
63
Chapter 3
use, BASIC would not print an error message, but the drive
light would flash. Run the above program, and you'll see the
message 63 FILE EXISTS 0 0. Error number 63 tells you that
an attempt was made to create a new disk file with an existing
filename. Other error numbers and their descriptions can be
found in the disk drive user's manual.
(The status numbers returned in variables C and D are for
advanced applications, and can be ignored.)
There are a couple of differences between normal disk
files (which use secondary addresses 2-14) and a file opened
to the command/error channel (secondary address of 15). No
direction is specified when the file is opened, and it's possible
to use both PRINT# and INPUT# without having to close and
reopen the file.
The other difference is that when the command/error
channel is closed, the disk drive closes all the other disk files
as well. BASIC may think that the files are still open, but an
error will occur when the program tries to read from them.
Thus, if a program is going to use the command/error channel
while other disk files are open, it's best to open the channel
during initialization and leave it open until the program ends.
Many people set aside file 15 for this purpose.
Sometimes it would be handy if a program could read the
disk directory. This is easy to do, but several things must be
done differently. First, the OPEN statement should use “$0:"
(or just "$ ") as the filename. Also, because of the structure of
the directory file, INPUT# cannot be used. The file has to be
read a character at a time. Fortunately, this can be done by the
GET# statement.
GET#'s syntax is the keyword GET#, followed by a file
number, a comma, and then a variable list. Something like
GET#1,A$ retrieves the next character from the file and as
signs it to A$. Only string variables should be used with
GET# to avoid the FILE DATA error.
The following demonstration shows how to read a
sequential file character by character.
10 OPEN 1,8,2,"HI SCORES"
20 GET#1,A$SPRINT A$;:IF ST=0 GOTO 20
30 CLOSE 1
The directory file contains characters for block lengths
and filenames. The first two characters in the file can be ig
64
Chapter 3
nored. The first line in the file is the directory header, giving
the disk name, identification, and DOS (Disk Operating Sys
tem) version. Several lines follow, one for each entry. Again,
the first two characters of each line can be ignored. The next
two form the low-byte and high-byte number which indicates
the file's block length. A few spaces precede the opening
quotation mark, which begins the filename. After the filename
and the closing quotation mark, there are several more spaces
and then the three-letter file type. Each line ends with a
CHR$(0), interpreted by GET# as a null string. This format re
peats for each line in the directory. The block length for the
last line shows the number of free blocks on the disk, with the
filename BLOCKS FREE.
The end of the directory file is detected by checking ST
after reading the block length. This program illustrates how
it's done.
The directory file can only be read and cannot be opened for
output.
A handy trick with reading the directory is to put a
filename after the $0:, as in "$0:POEM ". This makes the disk
drive search the directory for the filename POEM and list it if
it's on the disk. If there's no file named POEM, there'll be no
directory lines read after the header. This is useful when you
want a program to check if a file already exists. If the directory
is opened with the filename after the $0: and no filename lines
are read, the file isn't on the disk.
A variation on this technique is to use wild cards in the
filename. If you use a question mark (?) as one of the charac
ters in the filename, the disk drive will ignore that character
position when searching for filenames. Let's say a disk con
tains the following files.
65
Chapter 3
DOODLE
GAME1PLAYER
GAME2PLAYER
POEM
GMINUET
AMINUET
SONATA1
SONATA22
SONATINA1
SONATINA3
DMINUET
66
Chapter 3
Summary
• In a sequential file, data must be read in the same order as it
was written. It's not possible for reading to back up or skip
ahead.
• With a few changes to the OPEN statement, sequential files
can be used with disks. The syntax to open a disk file is
OPEN file number, device number, secondary address, string.
• File numbers should range from 1 to 127. The device number
for the disk drive is usually 8, but can be 9. Secondary ad
68
Chapter 3
dresses 0 and 1 are reserved for use by the LOAD and SAVE
commands. The numbers 2-14 are used for data files. Each
open file must have a different secondary address. A second
ary address of 15 is used to access the command and error
channel of the disk drive.
• The string consists of a filename, a file type, and a direction.
The filename is required and can be up to 16 characters. The
file type is optional when reading, mandatory when writing.
File type can be SEQ, USR, PRG, or REL (abbreviated as S,
U, P, and R, respectively). If no file type is specified, SEQ is
assumed. The direction is optional, and can be reading or
writing (or R or W). If no direction is given, the file is
opened for reading.
• Unlike the Datassette, several different files can be opened to
the disk drive simultaneously. Some can be set for input,
others for output.
• Two or more files can be opened for input from the same
disk file at the same time. However, once a disk file has been
opened for output, it cannot be read or written by any other
file until it is closed.
• The disk drive command and error channel is accessed by
opening a file with a secondary address of 15 and no string,
as in OPEN 1,8,15. No filename or direction has to be
specified.
• While the file is open, PRINT# can be used to send com
mands to the drive, and INPUT# can be used to get status
information. Unlike normal disk files, the file does not have
to be closed and reopened to switch between input and
output.
• The Scratch command is used to erase one or more files on a
disk. The command string is "SO-.filename". The S represents
the Scratch command, the 0 is the drive number, and the
filename indicates which file is to be erased. If the filename
contains wild card characters, more than one file may be erased.
• Do not use the @ character in the filename of an OPEN or
SAVE to replace and save a file on a disk. This feature is not
reliable and can damage the contents of a disk.
• The New command is used to format a disk and clear the
directory. The command string is "NO:diskname,id”.
• The Rename command is used to change the name of a file.
The command string is "RO:new filen am e= old filenam e”. The
contents of the file are not altered in any way.
69
Chapter 3
70
Chapter 3
71
Chapter 3
M o d em ~ ^ In p u t — ► G e t#
B u ffer
P rin t# — O u tp u t ► M od em
B uffer
73
Chapter 3
74
Chapter 3
75
Chapter 3
77
Chapter 3
Keyboard Transmit
0-64 0-64 (punctuation)
65-90 97-122 (lowercase)
91-96 91-96
148 127 (backspace)
193-218 65-90 (uppercase)
The fastest way to translate is with arrays. Arrays T% and
R% have been set up for this purpose (line 20 in Program 3-2).
There are a couple of restrictions in using an RS-232 de
vice. First, only one such device can be used at a time. Sec
ond, an RS-232 device should not be used while another
peripheral, such as the Datassette or disk drive, is in use.
The last topic concerns receiving a CHR$(0). If the
modem receives a CHR$(0), it stores it in the buffer properly,
but the GET# statement interprets it as a null string. This
means a null string can indicate either that the input buffer is
empty or that the character is a zero character. To determine
which, check bit 3 of ST after the GET# is executed. If the bit
is set (has a value of 8), the input buffer is empty. If the bit is
clear (value of 0), the character is a CHR$(0).
IF ST AND8 THEN input buffer is empty
IF (ST AND8) = 0 THEN it's a CHR$(0)
The CHR$(0) normally is not used in ASCII communica
tion and can just be ignored. It's important, though, in such
activities as transferring a program file by modem, in which
case every character is important.
Summary
• RS-232, like ASCII, is one of the few standards in the com
puter industry. It specifies how computers and devices
communicate.
• The RS-232 convention applies to serial communication,
where bits of a byte are sent one at a time. Parallel commu
nication, the other method of data transmission, transfers all
eight bits at the same time.
• The modem is used to convert bits into tones that can be car
ried by telephone lines to another computer which converts
the tones back into bits. This process is called modulation
and demodulation.
• The modem can transmit and receive at the same time. No
direction has to be specified as part of the OPEN statement.
78
Chapter 3
79
Chapter 4
81
Chapter 4
Since you started the program with the normal RUN com
mand, the variable A is 0, and the condition is true. Variable
A is set to 1, and the machine language program is loaded
from disk. After the LOAD is complete, BASIC automatically
does another RUN, this time without clearing the variables.
Variable A keeps the value of 1, so this second time the sec
tion after the THEN is not executed. Execution falls through to
line 20, the SYS statement, which starts the machine language
program.
SAVE. Last but not least, the SAVE command, when
used in a program, saves the current BASIC program to tape
or disk. This could be useful if you want a program to make a
copy of itself when it runs.
Summary
• RUN can be used as a substitute for the END statement to
make a program rerun when it ends.
• NEW, when used in a program, ends and erases the
program.
• If LIST is included in a program, execution stops after the
LIST is executed, even if there are lines yet unexecuted.
• CONT causes BASIC processing to enter an infinite loop
83
Chapter 4
84
Chapter 4
85
Chapter 4
86
Chapter 4
10 IF PEEK(56320)AND16 GOTO 10
20 PRINT "FIRE 1";
30 IF (PEEK(56320)AND16)=0 GOTO 30
40 GOTO 10
or
10 IF PEEK(56320)AND16 GOTO 10
20 PRINT "FIRE 1";
30 ON (PEEK(56320)AND16)/16+1 GOTO 30,10
87
Chapter 4
The file TAPE FILE is still opened, but the prompt fails to
appear.
Summary
• The WAIT statement makes BASIC halt execution until se
lected bits in a designated location are set or cleared.
• The syntax is WAIT, location number, comma, mask, and op
tional comma and mask.
• The bit set in the first mask tells which bit is to be mon
itored. For instance, if BASIC is to monitor bit 4, then 16
(that bit's value) would be used as the mask number.
• The second bit mask tells whether BASIC is to wait for the
selected bit to go from clear to set, or from set to clear. If
there is no second bit mask, BASIC will wait until the bit
goes from clear to set. To reverse the condition, the value
associated with the bit should be used for the second bit
mask.
• More than one bit can be monitored in the same location. To
make BASIC monitor both bits 4 and 5, the associated values
of 16 and 32 would be added and used as the first mask
number. BASIC would then wait until either bit 4 or bit 5
went from clear to set.
• The second bit mask can also be used with several bits. The
statement WAIT 1,164-32,16 makes BASIC wait until either
bit 4 of location 1 goes from set to clear, or bit 5 goes from
clear to set.
• While BASIC is waiting, it does not check the RUN/STOP
key, so RUN/STOP-RESTORE has to be used to stop
execution.
• Here are several example applications of WAIT: Halt execu
tion until the joystick button is pressed or released; force a
program to wait until the PLAY button on the Datassette is
pressed so that no PRESS PLAY ON TAPE message appears;
and freeze a program until a key is pressed.
88
Chapter 4
89
Chapter 4
91
Chapter 4
92
Chapter 4
Summary
• Of all the parts of a computer, the one that provides the real
"brains" is the CPU, or central processing unit. In micro
computers, the CPU is called a microprocessor. The Com
modore 64's microprocessor is the 6510, which for all
practical purposes is identical to the 6502.
• Machine language is the language of the microprocessor. Ma
chine language consists of instructions (rather than state
ments) which are directly executed by the microprocessor.
• Each machine language instruction is very simple and limited
in what it can accomplish. But though it takes a number of
them to get anything done, each instruction can be executed
very quickly.
• The BASIC language on the Commodore 64 is one large ma
chine language program.
• A BASIC program is not machine language and cannot be di
rectly executed by the microprocessor. Rather, it's treated as
data read by the BASIC interpreter program.
• The process of BASIC reading statements and executing the
appropriate machine language routines is called interpreting.
Interpreted BASIC programs are relatively slow because
things like syntax checking are done as the program is
running.
• A BASIC program can be compiled into machine language,
which can then be directly executed by the microprocessor.
The advantage of compiling is that things like syntax check
ing are done as part of the compiling step, so the program
runs much faster. The disadvantage is that a program has to
be recompiled every time it's changed.
• BASIC is a high-level language because each statement can
do a lot. Machine language is a low-level language.
• The SYS statement is used to start the execution of machine
93
Chapter 4
94
Part 2
Bitmapped
Graphics
Chapter 5
97
Chapter 5
99
Program 5-2. BMGLOADER Tape Version 51332 :096,072, 138 ,072,152,072,222
100
51338 :165,001, 009 ,002,133,001,193
10 IF A THEN SYS 52506sNEW 51344 :169,200, 072 ,169,157,072,215
20 A=1:LOAD "BMG.OBJ",1,1 51350 :008,072, 072 ,072,108,020,246
Chapter 5
102
51896 :005,075, 240 ,001,200,132,069 52082 :134,101, 174 ,002,205,134,096
51902 :087,162, 001 ,160,000,132,220 52088 :102,172, 254 ,204,190,232,250
51908 .-091,165, 075 ,197,076,165,197 52094 :204,134, 100 ,041,001,240,078
Chapter 5
104
52640 :178,206, 198 ,206,032,115,071 52826 :231,206, 208 ,226,032,138,107
52646 s000,032, 250 ,174,032,235,121 52832 :173,032, 247 ,183,140,013,116
52652 :183,142, 232 ,206,032,247,190 52838 :205,141, 014 ,205,032,121,052
Chapter 5
106
Chapter 5
199
0-"------------------------------------------------------------------------------------------ *-319
points that are displayed, the higher the resolution and the
smaller each point is.
Mode 0, used in the demonstration above, supports the
highest resolution (320 X 200 points). Mode 2 cuts that
resolution in half in each direction (only 160 X 100 points),
but each point is four times the size as before. Change the
mode number in the demonstration from 0 to 2, and run it
again to see this effect.
There are a total of four different resolutions available.
Here's a list showing the number of columns and rows in each
mode.
MODE RESOLUTION
0 320 X 200
2 160 X 100
4 80 X 50
6 40 X 25
There are four other modes, numbered 1, 3, 5, and 7,
which are reserved for special purposes. These will be ex
plained later. Using a mode number outside the range 0 -7 will
result in an ILLEGAL QUANTITY error.
The following program may not be very exciting, but it
does show how plotting with the DRAW statement is much
faster than using the old method of POKEing data to create
something on the bitmap screen.
10 GRAPHICS 4
20 DRAW RND(1)*80,RND(1)*50:GOTO 20
10 GRAPHICS 0
20 FOR X=0 TO 319
30 DRAW X ,100+20*SIN(X/10)
40 NEXT X
10 GRAPHICS 0
20 RX=55:RY=40
30 FOR A=0 TO 2*t_ STEP ] V 180
40 DRAW 160+RX*COS(A),100+RY*SIN(A)
50 NEXT A
108
Chapter 5
If you make the values for RX and RY too large, the co
ordinates for plotting will be off the screen. The program will
stop, the screen will change back to text mode, and an IL
LEGAL QUANTITY error message will be printed. This error
indicates that the coordinates used in a DRAW statement are
out of range for the current graphics mode. For example, try
ing to plot a point at —1, —1 causes this error.
A useful analogy to help understand bitmapped graphics
is to imagine that the drawing is done by a pen. The co
ordinates position the pen on the screen, and the DRAW state
ment tells the pen to press down and make a dot. The color of
the ink is light green. A pen with a fine point draws thin lines
and is used for detailed drawing; this is similar to a high-
resolution screen mode. A dull point creates broad strokes
which cover more area, something similar to low-resolution
modes.
In modes 0, 2, 4, and 6, there are actually two pens avail
able. Pen 1 is used for plotting. It's the default pen and has
been used in all the previous examples. Pen 0 is used for
unplotting. This erases points plotted by pen 1. When a point
is erased, the color of the background shows through.
The DRAW statement supports an optional third number
that's used to change the current pen number.
DRAW X coordinate, Y coordinate, pen number
When the GRAPHICS statement is used to switch from
text to graphics mode, the current pen number is set to 1. The
statement DRAW 5,6,1 is thus the same as DRAW 5,6. Both
statements plot a point at position 5,6. To erase the point, just
use pen 0. DRAW 5,6,0 erases the previously drawn point.
Once you've switched to pen 0, all future drawing is done
with that pen, at least until you change it back to pen 1.
The following program plots three points, waits for a
keypress, erases the points, waits for another keypress, and
then plots one more point. Type it in and try it out.
100 GRAPHICS 4
110 DRAW 3,4:REM DEFAULTS TO PEN 1
120 DRAW 7,9
130 DRAW 4,20
140 WAIT 198,15 :GET K$ :RF.M WAIT FOR KEYPRESS
150 DRAW 3,4,0:REM NOW IN PEN 0
160 DRAW 7,9:REM STILL PEN 0
109
Chapter 5
10 GRAPHICS 4
20 X=INT(RND(1)* 78)+1:Y=INT(RND(1)* 48)+1:DX=1:DY=1
30 DRAW X,Y,0 :X=X+DX:Y=Y+DY:DRAW X,Y,1
40 IF X=0 OR X=79 THEN DX=-DX
50 IF Y=0 OR Y=49 THEN DY=-DY
60 GOTO 30
Changing Colors
Thus far, plotting has always been done in light green (color
13). With a normal pen, you can change the color by replacing
the ink with a different refill. Likewise, the color associated
with a graphics drawing pen can be changed to any of the 16
colors available on the Commodore 64. The format for altering
colors is:
SETPEN pen number, color number
When using modes 0, 2, 4, and 6, only pen 1 should be
used with SETPEN. The color number can range from 0 to 15.
(Refer to the Commodore 64 User's Guide for the color values.)
Of course, if the pen is changed to color 0 (black), the plotting
won't be visible because it then matches the background color.
The next program is a modified version of the bouncing
ball program. The points are never erased, so the ball leaves a
trail. Pressing any key makes the program restart with a dif
ferent color for pen 1.
10 GRAPHICS 4
20 X=INT(RND(1)*78)+1:Y=INT(RND(1)*48)+l:DX=1:DY=1
30 SETPEN 1,RND(1)*15+1
40 X=X+DX:Y=Y+DY:DRAW X,Y
50 IF X=0 OR X=79 THEN DX=-DX
60 IF Y=0 OR Y=49 THEN DY=-DY
70 GET K $ :IF K$="“ GOTO 40
80 GOTO 10
110
Chapter 5
10 GRAPHICS 4
20 CLS 2
30 FOR K=5 TO 40
40 DRAW K,K
50 NEXT K
60 GOTO 60
Ill
Chapter 5
Line Drawing
Given a starting point and an ending point, the DRAW state
ment draws a straight line by plotting all the points between
them. All you have to do is use the keyword TO.
10 GRAPHICS 2
20 DRAW 10,10 TO 70,40
30 GOTO 30
10 GRAPHICS 6
20 DRAW 10,10 TO 30,10 TO 30,20 TO 10,20 TO 10,10
113
Chapter 5
30 GOTO 30
Area Filling
The next logical step after plotting points to draw a line is to
plot points that fill in an area. That is done by the statement
FILL.
The syntax for the FILL statement works the same as
DRAW'S.
FILL X coordinate, Y coordinate
In fact, FILL X,Y plots one point at X,Y, just like DRAW
X,Y. The difference is when a destination point is used. The
statement FILL X,Y TO X I,Y l, after plotting an initial point at
X,Y, starts drawing a line to X I,Y l. But as each point of the
line is plotted, all points on the same row, to the left and right
of the line, are also plotted.
10 GRAPHICS 6
20 DRAW 10,10 TO 30,10 TO 30,20 TO 10,20 TO 10,10
30 FILL 20,10 TO 20,20
40 GOTO 40
115
Chapter 5
that's filled. The brush fills in the background and stops when
it comes to a point that's already been plotted. This is why the
fill stayed inside the rectangle; the brush stopped when it hit
the left or right side of the shape.
FILL is normally used to fill in an area that's been out
lined by DRAW. If nothing has been previously drawn to stop
a fill, the filling continues until it reaches the edge of the
screen. There it stops, without causing a range error. Remove
line 20 of the previous example and run it again to see this
happen.
Notice that the fill does not begin at the starting point.
Rather, it begins on the next row.
The FILL statement is handy because it can cover large
areas quickly. FILL can also be used to erase a large area.
There's an optional third number after the X and Y co
ordinates for the destination point in a FILL statement. This
number identifies the drawing pen that's to be covered up
when the fill is performed. When no pen number is given, pen
0 is assumed. Since pen 0 corresponds to the background, this
means that the area to be filled in is the background, and the
filling should stop as soon as it hits anything else (pen 1 or
the screen edge). Here are some examples.
FILL X,Y,1 TO XI,Y1
or
FILL X,Y,1 TO X1,Y1,0
Both of these statements indicate that pen 1 should be used to
fill in the background.
However, this statement specifies that pen 0 should be
used to erase all points plotted in pen 1.
FILL X,Y,0 TO X1,Y1,1
Keep in mind the fact that the pen number in a destina
tion point has a different meaning than the pen number for a
starting point. In a starting point, the pen number is used to
change the current pen, to determine whether the pen will be
used for drawing (pen 1) or for erasing (pen 0). If the number
is omitted, the current pen is used.
The pen number in the destination point specifies which
points are to be covered up by the fill. If no number is given,
116
Chapter 5
117
Chapter 5
118
Chapter 5
Multicolor Modes
What happens when two lines of different colors cross each
other? This presents a problem. In modes 0, 2, and 4, when
pen 1 is used to plot points in several colors, if the points in
one color come too close to the points in another color, the
colors interfere with each other. The following program illus
trates this problem.
10 GRAPHICS 4
20 DRAW 25,5:D=15
30 FOR Y=10 TO 40 STEP 5
40 DRAWTO 40+D,Y
50 D=-D:NEXT
60 SETPEN 1,2:DRAW 43,5 TO 43,40
70 GOTO 70
The cause of the problem is that no matter which bitmap
resolution is used, the color resolution is always 40 X 25. The
bitmap portion of the screen may allow 320 X 200 points, but
the color portion is always divided into 40 X 25 “color
squares." Each color square is the same size as a text charac
ter, and all the points in a square have to share the same
color. If the first color square on the screen is red, then all
points plotted in that area will appear red. Points drawn in the
next color square could have a different color, but again they
119
Chapter 5
would all have to be the same color. This next program gives
a better view of what actually happens when two colors come
too close to each other.
10 GRAPHICS 4
20 DRAW 20,40 TO 20,10 TO 60,10:LFILLTO 60,40
30 SETPEN 1,2:DRAW 19,5 TO 59,45
40 GOTO 40
The parts of the line outside the box appear in the correct
resolution. Inside the box, though, you get a perfect picture of
the color squares. As the points forming the line were plotted,
the color squares for those points were changed to red, the
new pen color. The problem is that the color squares were also
used by other points not in the line, and those points changed
to red as well.
To help get around this limitation, the VIC-II chip sup
ports a multicolor bitmap mode. This mode allows three colors
in each color square, not just one. Now, when three points are
plotted in the same color square, each can have a different
color.
The multicolor mode has been implemented in the BASIC
extensions as graphics modes 1, 3, 5, and 7. They are prac
tically the same as modes 0, 2, 4, and 6, except that there are
now three drawing pens (pens 1, 2, and 3) for plotting, not
just one. You can use pen 1 to draw a line in one color, then
use pen 2 to draw a line with a different color crossing the
first line. There will be no conflict at the intersection.
10 GRAPHICS 5
20 DRAW 25,5:D=15
30 FOR Y=10 TO 40 STEP 5
40 DRAWTO 40+D,Y
50 D=-D:NEXT
60 SETPEN 2,2:DRAW 43,5,2 TO 43,40
70 GOTO 70
The program with the line passing through the box has
been modified to use all three drawing pens.
10 GRAPHICS 5
20 DRAW 20,40 TO 20,10 TO 60,10:LFILLTO 60,40
30 SETPEN 2,2:DRAW 19,5,2 TO 59,45
40 GOTO 40
120
Chapter 5
121
Chapter 5
A=INT(RND(0)*15)+1
30 B=INT(RND(0)*15)+1:IF B=A GOTO 30
40 C=INT(RND(0)*15)+1:IF C=A OR C=B GOTO 40
50 SETPEN 1,A :DRAW X,Y,1 TO X,Y+20 TO X+15,Y+20:LF
ILLTO X+l5,Y:SETPEN 2,B
60 DRAW X+16,Y-l,2 TO X+21,Y-11:LFILL X+21,Y-9 TO
{SPACE}X+21,Y+9 TO X+16,Y+19
70 SETPEN 3,C:DRAW X+20,Y-11,3 TO X+5,Y-l1 :RFILLTO
X+l,Y-l
80 NEXT:NEXT:WAIT 198,15:GET K$:GOTO 10
Shapedit
124
Chapter 6
125
Chapter 6
126
Chapter 6
49278 5067,083,067,083,067,211,192
49284 5083,067,091,067,075,067,070
49290 5115,115,115,099,083,083,236
49296 5075,131,179,179,179,171,034
49302 5163,163,147,014,017,163,049
49308 5163,163,179,227,083,099,046
49314 5083,099,083,099,099,083,196
49320 5012,025,227,243,243,243,137
49326 5227,211,211,211,219,243,216
49332 5243,243,243,243,227,211,054
49338 5211,211,211,211,219,243,212
49344 5243,243,243,243,243,243,114
49350 5227,211,211,211,211,211,200
49356 5211,211,227,024,031,018,158
49362 5099,029,031,163,179,179,122
49368 s179,006,067,115,115,025,211
49374 5095,026,025,255,061,000,172
49380 5083,219,211,203,203,211,078
49386 5067,123,083,083,067,115,004
49392 5115,179,139,147,147,155,098
49398 5000,013,227,219,219,211,111
49404 s075,008,243,243,243,227,011
49410 5211,211,211,243,243,243,084
49416 5243,219,211,211,163,179,210
49422 5179,163,147,147,163,163,208
49428 5163,163,227,051,243,131,230
49434 5131,131,131,147,018,033,105
49440 ;.255,013.013,013,013,013,096
128
Chapter 6
49152 s010,007,000,067,115,075,018
49158 s067,091,099,255,006,000,012
49164 s067,123,067,075,091,255,178
49170 s008,000,067,033,099,067,036
49176 5099,091,083,255,013,000,053
49182 5067,004,009,075,115,099,143
49188 5006,017,067,067,006,021,220
49194 s255,014,000,067,008,017,147
49200 s075,107,018,001,083,115,191
49206 5004,017,067,067,255,011,219
49212 s000,067,008,017,067,115,078
49218 5067,014,025,067,067,255,049
49224 s008,000,081,067,115,067,154
49230 s083,083,099,255,007,000,093
49236 s067,089,119,187,147,147,072
49242 s255,016,000,119,000,105,073
49248 s147,179,147,147,026,109,083
49254 s024,097,179,147,179,179,139
49260 s255,015,000,067,004,105,042
49266 s119,163,163,131,131,155,208
49272 s139,155,139,163,163,255,110
49278 s001,000,255,013,013,013,165
129
Chapter 6
T h e Shapedit Program
Now that you've seen a small sampling of what the SHAPE
statement can do, you ought to try creating a few shapes of
your own. You'll be glad to know that making a shape is as
easy as using a joystick. "Shapedit,” Program 6-8, simplifies
the task of defining a shape table. This program makes it easy
to create and edit up to 100 shapes in any graphics mode. It
also has options to save shape files to tape or disk. Shapedit
has been carefully designed to make shape creation as simple
as possible.
Shapedit uses graphics statements, so be sure that
the BASIC extensions have been installed (by running
"BMGLOADER") before you enter, save, load, or run the
program.
It's set to use the disk drive. Again, to make it work with
the Datassette, change the statement DN = 8 in the first line to
D N = 1.
Save the program using the filename SHAPEDIT before
you run it. This is a wise precaution whenever you run a pro
gram for the first time, in case the computer crashes due to a
typing mistake.
Plug a joystick into port 2 and type RUN. The program
takes a moment to initialize and then displays a black screen
with a five-line text window at the bottom. The first line re
ports status information, including the current drawing pen,
the current origin, and the current pen position. The next four
rows have items which are accessible by moving the joystick.
Items are selected by pressing the joystick button. The screen
above the text window is graphics mode 7.
100 DN=8:X=0:Y=0:XX=0:YY=0:JS=56320:SA=780:SX=781:
SY=782:SP=783:GOTO 800 srem 82
110 POKE 214,19:PRINT:F$=STR$(X):PRINT TAB(31) RIG
HT$(F?,LEN(F$)-1) ","? :rem 219
120 F?=STR?fY):PRINT RIGHT?(F ? ,LEN(F ? )-1) LEFT?(BL
?,39-POS(0)):K=FRE(0):RETURN :rem 13
130 SYS 49345:T1=MX(MD):T2=MY(MD) :rem 164
140 SYS 49391,X,Y:GOSUB 110 :rem 243
130
Chapter 6
131
Chapter 6
132
Chapter 6
133
Chapter 6
134
Chapter 6
135
Chapter 6
136
Chapter 6
Once you have Shapedit entered, saved, and run, you can
begin experimenting with it. To help you familiarize yourself
with the program, take time to read through the following
explanations, trying out each feature.
EDIT. To begin, press the joystick button while on EDIT.
A white cursor appears, indicating you're in the positioning
mode. The purpose of this mode is to establish the origin.
Move the cursor by pushing the joystick. If you go past a
screen boundary, the cursor wraps around to the other side.
Once you've moved the cursor to the place where you
want the shape to start, press the button. The cursor dis
appears, and the border changes to match the color of the cur
rent drawing pen. You're now in the editing mode. The cursor
reappears as soon as you push the stick in any direction. By
pushing the stick in different directions, you can move the
137
Chapter 6
138
Chapter 6
ton. If you want to change the pen color to yellow (color 7),
for instance, keep pushing the joystick until 7 appears, then
press the button. The instruction is added to the shape table,
and the prompt jumps back to EDIT.
Return to the editing mode by pressing the button when
EDIT is highlighted. The program bypasses the positioning
mode and goes right to the editing mode, using the same ori
gin as before. Editing continues from the last point. Use f7 to
change the current pen to the one which will have the new
color, and plot a point. The point appears in the new color
and the border color changes to match the current drawing
pen.
As with the SETPEN statement, the SETPEN instruction
must be used with a drawing pen other than pen 0. The only
color associated with pen 0 is the color of the background.
CLS. If you want to change the background color, use
the CLS command. Return to the menu, move to CLS, and
press the button. The number after CLS is the current back
ground color number, and can be changed by pushing the
stick left or right. Press the button when you've chosen the
new color. The screen will clear, and the background is set to
the new color. As an example, the background color can be
changed to red by changing the number after CLS to 2 and
pressing the button.
The program does not let you change the background
color to 15. That's the color used for text; using that color as
the background would make the text disappear. CLS is a com
mand used for editing purposes only, and is not an instruction
that can be included in a shape table.
Now that the screen has been cleared, press the button
while on EDIT. This time there is a positioning mode, and the
cursor appears at the old origin. If you don't want to change
the origin, just press the joystick button again. The shape is
redrawn, and editing continues from the last point.
The CLS command has another application. Perhaps
you're editing a shape, but can't complete it because it would
go out of bounds. What you need to do is change the origin to
allow more room for the drawing. Move to the CLS command
and press the button twice to clear the screen without chang
ing the background color. Now press the button on EDIT.
You'll be in the positioning mode, and the cursor will appear
at the old origin. Move the cursor to the new origin by
139
Chapter 6
pushing the stick, and then press the button. The shape is re
drawn, starting at the new position, and you're back in the
editing mode.
Care must be taken when choosing a new origin, because
having the origin too close to a screen edge can make the
shape drawing go out of bounds. This can happen when you
press the button to go from the positioning mode to the
editing mode. If this happens, the message ERROR: OUT OF
RANGE shows in the top line of the text window, and the
program waits until you acknowledge the error by pressing
any key. The next time you select EDIT, be sure to use a dif
ferent origin.
MODE. Sometimes you may find that the screen is sim
ply not big enough to draw a particular shape, and a higher
resolution is needed. Use the MODE command to change the
current graphics mode. As a demonstration, change the mode
from 7 to 5, and go back to EDIT. Like clearing the screen,
changing the mode causes a positioning mode. The cursor ap
pears at the same coordinates as before, but it's smaller and
displays in a different position on the screen because of the
new resolution.
Once you choose the origin and press the button, the
shape is drawn. However, since MODE does not clear the
screen, the shape is drawn on top of the old one in the lower
resolution. In other words, the MODE command lets you see
the same shape in different resolutions. Sometimes you may
want to clear the screen by using CLS to get rid of old shapes.
Be aware that if you draw a shape in a high-resolution
mode, it may not fit on the screen in a low-resolution mode
and may cause the OUT OF RANGE error. Also, all points
drawn by the same drawing pen must have the same color
within the same color square. This is not a concern in modes 6
and 7, because the points are the same size as the color
squares. However, it can be a problem in the other modes.
Furthermore, the problem may not be detected until you
switch to a higher resolution mode.
If you're creating a shape that will be drawn in a high
resolution, it's more convenient to do the editing in a low-
resolution mode. Just periodically change to a higher resolu
tion to check for color-square conflicts.
When you switch between normal and multicolor modes,
140
Chapter 6
141
Chapter 6
142
Chapter 6
143
Chapter 6
144
Chapter 6
145
Chapter 6
shapes, you can exit the program by using the QUIT com
mand. Press the button on QUIT and type Y to end the pro
gram. Type N if you accidentally chose the QUIT command.
The next time you run Shapedit, be sure that the BASIC
extensions have been installed.
146
Chapter 6
Next, assign the name of the shape file to the variable F$.
The string should consist only of the main part of the filename
and should not include the .SHP extension.
W = “filenam e"
To complete the preparation, call the subroutine at line
56500.
GOSUB 56500
The subroutine loads the shape file into memory and then
determines how many shapes have been loaded. The number
of the last shape is assigned to the variable NS. For example,
if the file contained four shapes, numbered 0 to 3, the variable
NS would be assigned the value 3.
The subroutine then dimensions an array named AS, using
the value of NS. A loop from 0 to NS is executed to store the
address of each shape in the array. Once that's been done, the
subroutine ends and returns to the main program.
The program is now ready to use the SHAPE statement.
Remember that this statement needs the address of the shape
that you want to display. The address can be found by using
the corresponding shape number as the subscript of the array
AS. The numbers used for the X and Y coordinates depend on
where you want to display the shape and are comparable to
the origin used in the Shapedit program.
SHAPE AS(shapc number), X coordinate, Y coordinate
The following two lines select graphics mode 5 and draw
shape 0 at position 40,30.
GRAPHICS 5
SHAPE AS(0),40,30
Any of the shapes in the file can be drawn by changing
the subscript of AS. Just make sure that the subscript never ex
ceeds the value of NS or the program will stop with a BAD
SUBSCRIPT error.
Another restriction is that a program can load only one
shape file. If you attempt to load a second set of shapes, you'll
get a REDIM'D ARRAY error, because array AS has already
been dimensioned. A shape file merging utility is provided
later so that you can combine two or more shape files into
one file.
One last restriction is that, if possible, you should avoid
assigning string variables once the shapes have been loaded.
147
Chapter 6
148
Chapter 6
49152 :000,100,000,083,075,075,077
49158 :075,075,075,075,075,075,200
49164 :075,091,091,091,091,091,030
49170 :091,091,091,091,091,091,052
49176 :091,091,091,091,091,107,074
49182 :107,107,107,107,107,107,160
49188 :107,107,123,123,123,123,230
49194 :123,123,123,123,123,123,012
49200 :123,123,123,123,123,131,026
49206 :139,139,139,139,139,139,120
49212 :139,075,155,155,155,155,126
49218 :155,155,155,155,155,155,228
49224 :155,155,155,155,155,099,178
49230 :163,171,171,171,171,171,072
49236 :171,171,115,179,187,187,070
49242 :187,187,187,187,187,187,188
49248 :187,187,187,187,187,187,194
49254 :255,013,013,013,013,013,166
149
Chapter 6
Rotation
The plotting process used by shape tables is fairly straight
forward. Each instruction moves the pen to one of eight ad
jacent positions and plots a point. These directions are
numbered, starting at 0 for up, and moving clockwise around
an imaginary circle. Thus, 1 is up and to the right, 2 is right
only, and so on, up to 7, which indicates up and to the left.
The directional numbers are illustrated by Figure 6-1. Each
instruction consists of a direction number from 0 to 7, and a
pen number from 0 to 3.
150
Chapter 6
When you run this program, you'll notice that the shape
deteriorates when it's rotated to one of the diagonal angles.
That's why these four angles are not frequently used. But the
four main angles (0, 90, 180, and 270 degrees) can be useful,
often in some surprising ways. The next program rotates a
small shape to draw a continuous border around the screen.
Type in Program 6-12, "BRAID," after loading SHP.BAS
so that the latter becomes part of Program 6-12. Then use
MLX to enter Program 6-13. Be sure to use the filename
BRAID.SHP for this.
100 PRINT CHR$ (147 ) :PRINT " BRAID" .-PRINT " BY CRAI
G CHAMBERLAIN":PRINT srem 98
110 DN=8 sSA=780 sSX=781:SY=782:SP=783 srem 133
120 F$="BRAID":LA=PEEK(49)+256*PEEK(50 )+1000 sGOSUB
56500:REM LOAD SHAPES srem 60
300 GRAPHICS 2 sS=AS(0) srem 245
310 SHAPE S,20,15 srem 120
320 FOR K=1 TO 11:SHAPE S,0:NEXT srem 13
330 FOR K=1 TO 7:SHAPE S,2sNEXT srem 229
340 FOR K=1 TO 12:SHAPE S,4sNEXT srem 20
350 FOR K=1 TO 7sSHAPE S,6:NEXT srem 235
360 SHAPE S ,70,50 srem 129
370 WAIT 198,15 sGET K$ srem 140
380 END srem 114
49194 :083,083,083,099,099,099,076
49200 :099,099,099,099,099,255,030
155
Chapter 6
156
Program 6-17. WEATHER.SHP 49290 :179,163, 179 ,163,179,163,140
To enter this program, you must use "The Machine Language 49296 :179,163 ,255 ,090,000,083,146
Editor (MLX)," a program found in Appendix C. 49302 :083,083, 099 ,115,115,014,147
49308 s001,083, 099 ,099,099,083,108
Starting Address: 49152 49314 :067,091, 067 ,123,083,067,148
Ending Address: 50081 49320 s115,075, 115 ,115,067,083,226
Filename: WEATHER.SHP 49326 :083,075, 067 ,075,067,075,104
49332 :067,012, 009 ,001,099,031,143
49152 :012,054,000,083,059,031,238 49338 :149,031, 004 ,089,002,115,064
49158 5067 ,056,031,067, 058,031,060 49344 :067,123, 067 ,123,067,026,153
49164 5123 ,016,031,075, 083,083,167 49350 5061,083, 083 ,083,099,115,210
49170 5083 ,024,005,002, 115.020.011 49356 :115,004, 013 ,099,099,091,113
49176 5031 ,067,018,031, 067,012,250 49362 :099,091, 099 ,012,099,099,197
49182 5031 ,067,083,083, 083,012,133 49368 s000,049, 115 ,099,107,099,173
49188 s053 ,083,054,031, 107.008.116 49374 :107,099, 006 ,073,099,067,161
49194 5036 ,031,091,018, 031,107,100 49380 :099,099, 099 ,083,083,083,006
49200 511 5 ,115,115,022, 001,083,243 49386 :083,067, 067 ,067,255,064,069
49206 5010 ,031,255,026, 000,026,146 49392 :000,034, 063 ,006,083,010,180
49212 5017 ,147,147,179, 187.147.116 49398 :031,017, 031 ,008,031,067,175
49218 5147 ,147,139,179, 179.179.012 49404 :115,075, 010 ,031,002,013,242
49224 5179 ,139,147,147, 179,147,242 49410 :099,099, 002 ,005,063,002,016
49230 ;147 ,187,179,179, 171,163,080 49416 5083,033, 031 ,083,037,031,050
49236 s255 ,032,000,006, 037,091,249 49422 5010,031, 033 ,031,083,037,239
49242 5099 ,083,067,006, 083,099,015 49428 5031,002, 063 ,002,083,033,234
49248 5083 ,067,006,083, 099,083,005 49434 5031,018, 037 ,031,033,031,207
49254 5067 ,029,107,099, 115,067,074 49440 5115,037, 031 ,008,017,031,015
49260 5004 ,115,099,115, 067,004,000 49446 5067,067, 037 ,031,002,025,011
49266 5115 ,099,115,067, 255,026,023 49452 5091,123, 014 ,029,255,073,117
49272 5000 ,042,021,179, 179,155,184 49458 5000,034, 063 ,002,083,033,009
49278 5179 ,163,179,163, 179,163,128 49464 5031,010, 021 ,031,010,017,176
49470 5031,037, 031 ,115,033,031,084
157
49284 5147 ,147,147,163, 179,163,054
49476 :004,013, 031 ,004,009,031,160 49662 :083,006,009,031,008,017,152
8SL
49482 :037,031, 022 ,063,002,075,048 49668 :031,107,029,031,018,063,027
49488 :017,031, 075 ,010,031,037,025 49674 :002,083,033,031,018,037,214
49494 :031,008, 031 ,025,031,010,222 49680 :031,033,031,115,037,031,038
49500 :083,021, 031 ,002,005,063,041
Chapter 6
49686 :008,017,031,067,067,037,249
49506 :002,083, 033 ,031,018,037,046 49692 :031,002,025,091,123,014,058
49512 :031,033 ,031 ,115,037,031,126 49698 :029,063,002,083,033,031,019
49518 :008,017 ,031 ,067,067,037,081 49704 :018,031,013,115,008,031,000
49524 :031,002, 025 ,091,123,014,146 49710 :067,029,031,014,031,002,220
49530 :029,255, 070 ,000,022,063,049 49716 :063,006,083,010,031,017,006
49536 :010,083, 033 ,031,083,037,149 49722 :031,008,031,067,115,075,129
49542 :031,004, 033 ,115,018,031,110 49728 5010,031,002,013,099,099,062
49548 :002,037, 063 ,002,083,033,104 49734 :002,005,255,097,000,010,183
49554 :031,083, 037 ,031,010,031,113 49740 5063,010,083,033,031,083,123
49560 :033,031, 083 ,037,031,002,113 49746 5037,031,004,033,115,018,064
49566 :063,002, 083 ,033,031,018,132 49752 5031,002,037,063,002,083,050
49572 :031,013, 115 ,008,031,067,173 49758 5033,031,083,037,031,017,070
49578 :029,031, 014 ,031,002,063,084 49764 s083,083,009,083,037,031,170
49584 :006,083 ,010 ,031,017,031,098 49770 5083,033,031,002,037,063,099
49590 :008,031, 067 ,115,075,010,232 49776 5002,083,033,031,083,037,125
49596 :031,002, 013 ,099,099,002,178 49782 5031,010,031,033,031,083,081
49602 :005,255, 131 ,000,063,002,138 49788 5037,031,002,063,002,083,086
49608 :083,033, 031 ,083,037,031,242 49794 5033,031,014,031,037,031,051
49614 :006,009, 031 ,006,013,031,046
49800 5083,008,115,025,031,010,152
49620 :033,031, 083 ,037,031,008,179
49806 5083,099,004,005,031,115,223
49626 :017,031, 107 ,018,013,063,211 49812 5091,010,005,063,006,083,150
49632 :002,083, 033 ,031,018,031,166
49818 5010,031,017,031,008,031,026
49638 :013,115, 008 ,031,067,029,237
49824 5067,115,075,010,031,002,204
49644 :031,014, 031 ,002,063,002,123
49830 5013,099,099,002,005,255,127
49650 :083,063, 033 ,031,010,031,237
49656 :006,013, 031 ,008,021,031,102 49836 5060,000,034,063,002,083,158
49842 5033,031,018,031,013,115,163
49848 :008,031, 067 ,029,031,018,112 50034 :017,031,006,009,031,083,035
49854 2063,002, 083 ,033,031,014,160 50040 :107,083,083,029,031,083,024
49860 1031,037, 031 ,083,008,115,245 50046 :017,031,012,001,099,021,051
49866 :025,031, 010 ,083,099,004,198 50052 s031,001,083,083,010,005,089
49872 :005,031, 115 ,091,010,005,209 50058 :063,010,083,017,031,115,201
49878 :063,002, 083 ,018,031,008,163 50064 :067,067,115,099,006,005,247
49884 :067,025, 031 ,004,031,018,140 50070 5083,021,031,017,083,067,196
49890 :031,004, 099 ,021,031,010,166 50076 5067,083,099,002,029,255,179
49896 :005,255, 104 ,000,010,063,157
49902 :006,083, 010 ,031,017,031,160
49908 :008,031, 067 ,115,075,010,038 Program 6-18. CHSETA.SHP
49914 :031,002, 013 ,099,099,002,240 To enter this program, you must use "The Machine Language
49920 :005,063, 002 ,083,017,031,201 Editor (MLX)," a program found in Appendix C.
49926 2006,009, 031 ,083,107,083,069
49932 2083,029, 031 ,083,017,031,030 Starting Address: 49152
49938 2012,001, 099 ,021,031,001,183 Ending Address: 50447
49944 2083,083, 0 1 0 ,005,063,010,022 Filename: CHSETA.SHP
49950 2083,033, 031 ,083,037,031,072
49956 2004,033, 115 ,018,031,002,239 49152 :058,003,000,063,022,255,145
49962 2037,063, 002 ,083,033,031,035 49158 :013,000,006,083,001,067,176
49968 2083,037, 031 ,010,031,033,017 49164 :017,031,083,021,031,005,200
49974 2031,083, 037 ,031,002,063,045 49170 :099,006,255,018,000,006,146
49980 :002,083, 033 ,031,014,031,254 49176 :009,067,067,067,083,099,160
49986 2037,031, 083 ,008,115,025,109 49182 :099,002,083,067,067,083,175
49992 2031,010, 083 ,099,004,005,048 49188 :099,099,002,021,255,025,025
49998 2031,115, 091 ,010,005,255,073 49194 :000,067,026,031,107,033,050
50004 2076,000, 063 ,002,083,063,115 49200 :031,115,037,031,012,025,043
50010 2033,031, 010 ,031,006,013,214 49206 :063,067,037,031,083,033,112
50016 2031,008, 021 ,031,083,006,020 49212 j 031,191,115,026,031,002,200
50022 2009,031, 008 ,017,031,107,049 49218 :029,255,022,000,002,075,193
Chapter 6
163
Chapter 6
164
Chapter 6
165
Chapter 6
Suggested Applications
Redefined (custom) characters. A popular way to draw
shapes is to use redefined characters, but this method has
some drawbacks. The major restriction is that character defi
nitions must fit within an 8 X 8 grid. To create a shape larger
than 8 X 8 points, several characters must be used. Another
166
Chapter 6
167
Chapter 6
168
Chapter 6
169
Chapter 6
PEEK them). These are the only blocks available from BASIC
when using the bitmapped graphics routines.
To calculate the beginning address of a definition block in
bank 3, use this formula:
Block address = 49152 + 64 * Block number
For most applications, 18 definition blocks should be suf
ficient. If you need more, you'll have to relocate the bitmap.
It's also necessary to move the bitmap when the RAM under
the Kernal is needed by another utility. Relocating the bitmap
is as easy as four POKE statements. The difficulty lies in
choosing where you want to relocate the bitmap.
The memory on the Commodore 64 is divided into four
banks of 16K each. A bitmap requires 8K, or half a bank, so it
would seem that there is a total of eight different places in
memory where a bitmap can be placed. Actually, three of
these places are not available, either because they conflict with
character-set images, or they are needed by the system.
Besides the 8K for the bitmap, IK for screen memory
must also be allotted. Screen memory is used to provide color
information in the bitmap mode. Since the VIC-II chip can ac
cess only one bank at a time, the screen memory must be
placed somewhere in the other half of the bank that contains
the bitmap. Depending on which bank is being used, there
may be from one to eight different places to put the screen
memory.
Bank Address Supports Possible Locations for
Bitmap? Screen Memory
0 0 No
0 8192 Yes 1024, 2048, 3072
1 16384 Yes 24576, 25600, 26624, 27648,
28672, 29696, 30720, 31744
1 24576 Yes 16384, 17408, 18432, 19456,
20480, 21504, 22528, 23552
2 32768 No
2 40960 Yes 32768, 33792, 34816, 35840
3 49152 No
3 57344 Yes 49152, 50176
In bank 3, the bitmap may be placed only in the second
half of the bank, starting at location 57344. The screen can be
placed either at address 49152 or at address 50176. The de
fault arrangement of the bitmapped graphics routines is to put
171
Chapter 6
174
Chapter 6
175
Chapter 6
or
P O K E 52492,255 If F = 1 in m o d es 0, 2, 4, 6
or
P O K E 52492,85 If F = 1 in m o d es 1, 3, 5, 7
or
P O K E 52492,170 If F - 2
or
P O K E 52492,255 If F - 3
S Y S 51831 P erfo rm d r a w /f ill
IF P E E K (S P )A N D 1 T H E N R an g e erro r
L FIL L T O X ,Y,F P O K E S A ,2 S et fo r left fill
P O K E S X ,X A N D 255 X co o rd in ate low b y te
P O K E S P ,- ( X > = 2 5 6 ) X co o rd in ate h ig h b y te
P O K E S Y ,Y Y co o rd in ate
P O K E 52492,0 If F = 0 (fill o v e r
b ack grou n d )
or
P O K E 52492,255 If F = 1 in m o d es 0, 2, 4, 6
or
P O K E 52492,85 If F = 1 in m o d es 1, 3, 5, 7
or
P O K E 52492,170 If F = 2
or
P O K E 52492,255 If F = 3
S Y S 51831 P erfo rm d r a w /f ill
IF P E E K (S P )A N D 1 T H E N R an g e e rro r
S H A P E A ,X ,X R PO K E
52493, A -2 5 6 * IN T (A /2 5 6 ) S h ap e ad d ress low b y te
P O K E 52494,A /2 5 6 S h ap e ad d ress h ig h b y te
P O K E 52495,X A N D 255 X co o rd in ate low b y te
P O K E 52496,~ ( X > = 2 5 6 ) X co o rd in ate h ig h b y te
P O K E 52497,Y Y co o rd in ate
P O K E S A ,R R o tatio n v a lu e
S Y S 52166 D raw sh ap e
IF P E E K (S P )A N D 1 T H E N R an g e e rro r
P E N A ,B P O K E 52501 + A ,B S et p en in d irectio n
L O O K (X ,Y ) P O K E S X ,X A N D 255 X co o rd in ate low b y te
P O K E S P ,- ( S X > —256) X co o rd in ate h ig h b y te
P O K E S Y ,Y Y co o rd in ate
S Y S 51462 L ook at p o sitio n
IF P E E K (S P )A N D 1 T H E N R an g e e rro r
o th e rw ise
P en n u m b e r = P E E K (S A )
176
Chapter 6
177
Chapter 6
178
Chapter 6
179
Chapter 6
180
Chapter 6
Function
LOOK 168-70
Command
KILL 99
181
Part 3
Sidplayer
Chapter 7
Electronic Music
When your ear hears a sound, it is actually detecting vibra
tions. The rate of vibration is called the frequency and deter
mines the pitch of a sound. In a musical instrument, a metal
string, reed, stretched membrane, or air in a tube is what
vibrates. The player usually has a method for changing the
pitch.
But sounds are not so simple. There are many different
kinds of vibrations. When viewed with an oscilloscope, vibra
tions have another characteristic, called waveform. Square, tri
angle, and sawtooth are common waveforms. The waveform
helps distinguish the sound produced by one instrument, such
as a flute, from the sound produced by another instrument,
such as a violin.
There's just one more essential characteristic remaining—
volume. As a string is plucked or air is blown, the volume
changes over a short period of time. This pattern of changing
volume levels is called an envelope, and is usually divided into
four parts called the attack, decay, sustain, and release. In the
185
Chapter 7
first three parts, the volume rises to a peak level and then falls
to a sustain level. When the note is released, the volume fades
away to silence.
The frequency, waveform, and envelope are all essential
parts of a note. A sequence of notes creates music. Electronic
music is merely a method of producing these qualities of
sound by electronic means. A device which does this is called
a synthesizer. Theoretically, it's possible for a synthesizer to
imitate any musical instrument or to produce sounds never
heard before.
The Sidplayer
The SID chip contains three oscillators. Each oscillator acts as
one "voice" and can produce a tone in a range of eight oc
taves, using one of four basic waveforms. The tone is passed
through an envelope generator which regulates the volume of
that voice. All three voices are then combined into one audio
signal, which is controlled by the master volume and sent to
the television or monitor speaker.
186
Chapter 7
187
Chapter 7
the listing in this book. (Tape users who have a copy of MLX
which does not have a line 763 must use the version of MLX
from this book.)
189
Chapter 7
190
Chapter 7
191
49517 :192,169, 004 ,157,111,192,166 49703 :240,025, 189 ,217,192,133,011
49523 :189,020, 193 ,157,138,192,236 49709 :251,189, 005 ,192,160,000,074
49529 5189,217 f192 ,133,253,169,250 49715 :145,251, 189 ,008,192,200,012
49535 :000,160, 002 ,145,253,169,088 49721 :145,251, 189 ,120,192,160,090
Chapter 7
194
50267 s087, 192, 157 ,008,192,189,148 50453 :113,074, 074 ,176,031,074,051
50273 :036, 192, 010 ,208,066,189,030 50459 :176,015, 157 ,099,192,160,058
50279 :090, 192, 240 ,019,189,096,161 50465 :003,145, 251 ,104,157,096,021
Chapter 7
195
50813 5077,028, 192 ,144,107,077,238 50999 :240,018, 222 ,138,192,168,009
51005 :136 185.153.192, 240,007,206 49170 :038,001, 024 ,155,024,158,162
51011 s133 254,185,141, 192,133,081 49176 :024,145, 024 ,159,024,155,043
51017 :253 096,169,032, 141,000,252 49182 s024,159, 024 ,146,038,014,179
51023 :192 096.173.000, 192,093,057 49188 5020,145, 020 ,147,020,093,225
Chapter 7
197
49536 49722
Chapter 7
198
49734 s024,000, 001 ,047,001,006,149 49920 s024,159, 024 ,146,024,148,013
49740 1024,155, 024 ,158,024,145,094 49926 2024,147, 024 ,145,024,147,005
49746 s024,159, 024 ,155,024,159,115 49932 :024,149, 024 ,148,024,147,016
Chapter 7
200
50478 :024, 165, 024 ,163,024,175,109 50664 2038,010, 020 ,163,020,101,072
50484 :024, 173 ,024 ,175,030,014,236 50670 2020,167, 020 ,101,020,163,217
50490 :038, 010, 020 ,171,020,163,224 50676 2020,175, 020 ,109,020,171,247
Chapter 7
201
49284 5024,159,020,158,020,000,001
Chapter 7
49476 :024,157, 024 ,157,020,145,083 49662 ,
s001,007, 0 0 1 ,004,001,144,156
202
49482 :020,145, 020 ,145,024,145,061 49668 :001,132, 001 ,152,038,001,073
49488 :024,145, 020 ,159,020,159,095 49674 :166,012, 006 ,128,022,005,093
49494 -.020,159, 030 ,016,024,157,236 49680 :054,002, 004 ,153,004,153,130
Chapter 7
203
Chapter 7
204
50226 :020,000,020,000,030,017,137 50412 5013,070,073,070,069,044,063
50232 :004,000,004,000,004,000,068 50418 5032,084,085,066,065,044,106
50238 :020,165,020,000,020,000,031 50424 5032,065,078,068,032,080,091
Chapter 7
205
49404 2001,079, 0 0 1 ,,118,118,026,083 49590 2 166,179,118,000,134,000,011
Chapter 7
49596 :054,002,030,003,052,141,214
49602 :020,138,020,141,024,138,163
49608 :052,140,020,137,052,149,238
49614 :052,141,020,138,052,141,238
49620 5024,140,024,141,052,142,223
49626 5052,140,052,141,020,138,249
49632 s052,141,052,207,020,142,070
49638 5052,140,008,141,001,015,075
49644 5008,076,001,114,001,079,003
49650 5001,134,166,108,001,039,179
49656 5001,059,019,176,001,002,250
49662 5001,051,001,071,003,000,125
49668 5166,012,030,002,054,002,014
49674 5020,154,048,231,080,166,197
49680 5024,166,020,164,080,162,120
49686 5024,162,020,162,048,239,165
49692 5052,227,016,161,080,162,214
49698 5024,162,001,015,001,047,028
49704 5016,174,166,179,086,000,149
49710 s001,212,066,176,054,002,045
49716 5030,003,052,151,020,149,201
49722 5052,146,016,150,024,149,083
49728 5052,159,052,151,020,149,135
49734 5020,146,024,159,052,145,104
49740 5020,148,052,150,052,151,137
49746 5020,149,052,146,052,156,145
49752 5020,153,052,158,008,159,126
49758 5001,015,008,158,001,130,151
49764 5001,079,034,069,084,032,143
49770 5065,076,034,013,066,089,193
49776 5032,072,065,082,082,089,022
49782 5032,066,082,065,084,084,019
49788 5013,013,013,000,020,153,080
206
Chapter 7
207
Chapter 7
208
Chapter 7
D 587.33 Hz
C 523.25 Hz
B 493.88 Hz
A 440.00 Hz
G 392.00 Hz
F 349.23 Hz
E 329.63 Hz
D 293.66 Hz
C 261.63 Hz (Original C)
B 246.94 Hz
A 220.00 Hz
G 196.00 Hz
F 174.61 Hz
E 164.81 Hz
D 146.83 Hz
C 130.81 Hz
B 123.47 Hz
The scale repeats with each C. By examining one se
quence, from one C to the next, you can see that it consists of
eight pitches. Collectively, these eight pitches are called an oc
tave. To distinguish this set of pitches from the next, the first
set is said to occur one octave lower than the second.
Just as the different pitches in an octave are labeled, so
are the different octaves. However, instead of using a letter of
the alphabet, a number is used. The piano key for the original
C is found at about the middle of the keyboard. This C is
called middle C, and begins octave 4. Other octaves are num
bered relative to the octave containing middle C. The octave
immediately above octave 4 is octave 5. The octaves which are
of the most use musically are octaves 1 to 7.
In music notation, the pitch value of a note is represented
by its vertical position when drawn on a staff. Thus, C5 (C of
the fifth octave) is indicated by placing the note between the
second and third lines of the treble staff. The next higher
pitch, D5, is indicated by placing the note above the position
for C5, except that this time the note is placed on the line. The
positions for all notes alternate between being on a staff line
or between staff lines, for the entire grand staff. See Figure 7-3
for an illustration.
209
Figure 7^3. Grand Staff
Chapter 7
Chapter 7
By using the grand staff and leger lines, eight octaves (octaves
0-7) can be displayed.
Sharps and flats. Eight octaves, each containing 7 dif
ferent pitches, would seem to make a total of 56 pitches. Ac
tually, there are some intermediate pitches between some of
these notes. These are called sharps and flats.
C
B
A-sharp B-flat
A
G-sharp A-flat
G
F-sharp G-flat
F
E
D-sharp E-flat
D
C-sharp D-flat
C
211
Chapter 7
U L J i i i
FTTv ___ M ...tm
Vf
■ - _d ___J_
W _ _____m_______________
212
Chapter 7
A
G#
F#
E
B
A (Start here)
213
Chapter 7
215
Chapter 7
-y J *J J----
J f);
/ >1
J#J J=j= ^/ _ aL#L J J
J J J J= 7frVrJ-J..| [z =ft=f=t=H=
*
4 .. J J
G# A B Cft Dft E Fft Gft F G A bI>
-Jit* J J /f^i,>J1_Jr!..=
_§) ^ Q
/j!^
) b^t*="*....
f+
E^ D C Bl> E^ Al> C e!> d!> F B^
-=«^.J
yv =J * =j A j ~*T; »J..
•V -J —W..J.
tM .Jf J 1
216
Chapter 7
, 1J J 1 1 1 11-H-k-
=*F=zt2t=FjF3= 4 &4 --1
&J J r J-----
218
Chapter 7
r l- 4 . H h. i 1j j j } } H
J ---w-- ^ dm d d* m m
rn i1 ?}
a J . a J a J 1 1
d* d W W V
W Wrn zdin jmotzMZ
'"V"
first measure second measure
219
Chapter 7
220
Chapter 7
221
Chapter 7
the second staff line. A half rest looks the same except that the
block is placed on top of the third staff line. A quarter rest is a
symbol that defies description. Eighth, sixteenth, and thirty-
second rests are all drawn as slanted stems with the proper
number of flags to the left of the stem. Figure 7-9 shows the
rest symbols.
V V
■i --- ---- -----
A | y
.:.j ______ m. ^ __ t __ m __ f___
V V *
The reason for using ties is that the effect of a tie can ex
tend across one measure or beat into another. In the following
two sequences of notes, each sequence sounds the same when
played, but the first one cannot be divided into measures.
222
Chapter 7
iiii £
22. M.
224
Chapter 7
Summary
• Notes are shown on a grand staff which consists of the treble
and bass staves. Each staff has its own clef symbol.
• The most important characteristics of a note are its pitch and
duration.
• Pitches occur in groups called octaves. Each octave contains
the pitches labeled C, D, E, F, G, A, and B, plus five inter
mediate pitches called sharps and flats.
• Only some of the pitches in each octave are used, depending
on the key in which the music is written.
• Pitch is indicated by the vertical position of a note on the
grand staff. The note may be drawn on a staff line or be
tween staff lines.
• An accidental (a sharp or flat symbol) may be placed im
mediately before the note to indicate that the note is a sharp
or a flat.
225
Chapter 7
226
Chapter 8
The Editor
22 7
Chapter 8
228
Chapter 8
229
Chapter 8
231
Chapter 8
232
Chapter 8
235
Chapter 8
237
Chapter 8
239
Chapter 8
241
Chapter 8
242
Chapter 8
245
Chapter 8
Once the Editor has been saved, load the "MLX" program
from Appendix C. MLX is the same program you used to cre
ate "BMG.OBJ” and “SID.OBJ.” If you already have a copy of
MLX from another COMPUTE! publication, you can use it to
enter the listings in this book. Tape users using another ver
sion of MLX must change line 763 to match the MLX listing in
this book. (Tape users who have a copy of MLX which does
not have a line 763 must use the version of MLX from this
book.)
In order to avoid retyping the same data you entered for
SID.OBJ, you'll reload the SID.OBJ file through MLX and ap
pend the additional data (actually, you'll be overwriting about
72 bytes and adding more than 650 others). Be sure to follow
these directions carefully in order to get a working copy of the
Editor.
Load and run MLX, and answer the prompts as follows:
Starting Address: 49349
Ending Address: 51736
If you're using a Datassette, insert the tape which contains
a copy of SID.OBJ, created in Chapter 7, and fast-foward past
the Sid Loader program to the beginning of SID.OBJ (you
should have earlier noted the tape counter number for the
start of this file).
If you're using disk, just insert the disk containing
SID.OBJ in your drive.
The cursor should be waiting for input on line 49349.
Press the L key while holding down the SHIFT key. When
you see the prompt for a filename, enter SID.OBJ and press
RETURN. Next, respond with T or D for tape or disk. SID.OBJ
will load into memory.
When MLX has finished loading SID.OBJ and the prompt
returns for line 49349, press the N key while holding down
the SHIFT key. You'll be asked for a new address: Enter 51041
and press RETURN.
Using the listing of Program 8-2, enter in the data as you
would any other MLX listing. When you're finished, save the
program using the filename EDITOR.OBJ. Tape users should
save the program immediately following program 8-1, EDITOR.
(The Editor uses most of the memory space from 49152 to
53247. For this reason you cannot run other utilities which use
this memory, such as the DOS wedge, when using the Editor.)
246
Program 8-2* EDITOR.OBJ 51203 5007,002, 086 ,051,035,118,046
To enter this program, you must use "The Machine Language 51209 5134,003, 010 ,166,030,083,179
Editor (MLX)," a program found in Appendix C. Be sure to read 51215 5070,079, 182 ,255,255,014,102
the directions above before entering this program. 51221 s246,255 ,254 ,014,014,254,034
51041 s096,120,169,127,141,013,251 51227 5030,255, 014 ,246,255,031,090
51047 :220,169,001,141,026,208,100 51233 5246,134, 014 ,134,014,255,062
51053 :169,049,141,018,208,169,095 51239 5030,015, 255 ,246,246,255,062
51059 :027,141,017,208,169,147,056 51245 5255,003, 015 ,255,063,246,114
51065 :141,020,003,169,004,141,087 51251 5255,254, 255 ,160,000,177,128
51071 :021,003,088,096,173,025,021 51257 5251,205, 114 ,005,208,009,081
51077 :208,141,025,208,041,001,245 51263 5200,177, 251 ,136,205,115,123
51083 5240,020,172,191,004,185,183 51269 5005,240, 023 ,165,251,024,009
51089 5192,004,141,033,208,185,140 51275 s105,002, 133 ,251,144,002,200
51095 5200,004,141,018,208,206,160 51281 5230,252, 205 ,112,005,208,069
51101 5191,004,048,006,104,168,166 51287 5224,165, 252 ,205,113,005,027
51107 5104,170,104,064,160,007,004 51293 5208,217, 096 ,0 0 0 ,0 0 0 ,0 0 0,102
51113 5140,191,004,076,000,000,068 51299 5000,170, 010 ,042,042,041,148
51119 5007,002,014,006,001,006,211 51305 5003,168, 138 ,041,007,208,158
51125 5002,002,002,050,246,222,193 51311 5009,169, 255 ,141,001,208,126
51131 s208,106,082,076,064,160,115 51317 5141,005, 208 ,096,133,253,185
51137 s255,200,185,034,005,170,018 51323 5198,253, 010 ,201,008,233,002
51143 5041,001,069,252,208,245,247 51329 5000,024, 121 ,008,006,168,200
51149 5138,009,001,170,037,251,043 51335 5185,012, 006 ,072,185,028,111
51155 5217,254,004,208,234,132,236 51341 5006,133, 251 ,138,041,056,254
51161 5252,138,073,255,037,251,199 51347 2074,074, 074 ,133,254,170,158
51167 5133,251,138,160,255,200,080 51353 5104,202, 048 ,009,192,015,211
51173 5074,176,252,070,251,136,164 51359 5102,251, 106 ,024,202,016,092
51179 5208,251,096,006,022,014,064 51365 5249,141, 000 ,212,165,251,159
51185 5003,054,015,002,006,047,112 51371 2141,001, 212 ,169,065,141,132
51191 5023,150,010,019,102,014,053 51377 5004,212, 185 ,044,006,170,030
Chapter 8
247
51197 5067,004,000,132,008,038,246
51389 :144,141, 001 ,208,138,041,094 51575 :173,006, 133 ,252,173,174,006
248
51395 :254,010, 141 ,000,208,169,209 51581 :006,133, 254 ,169,000,133,052
51401 :000,042, 141 ,016,208,169,009 51587 :251,133, 253 ,032,006,004,042
51407 ;007,056, 229 ,254,133,254,116 51593 :165,001, 009 ,002,133,001,192
Chapter 8
ED IT Music
Press the 2 key to select EDIT, and then the 1 key to choose
voice 1. The display changes to show the editing screen.
The first thing you'll notice is that it's divided into dif
ferent levels. The top level shows the current voice number
and the amount of free memory remaining. The next level dis
plays the current key signature and tells whether the measure
feature is on or off. The level below that has one of the three
accidental symbols highlighted.
The next level is the main level, where notes are selected.
The main level displays the current pitch in three different
forms: as a note on the grand staff, as a piano key, and as a
letter and octave number. The current duration is indicated by
a symbol and a word. The level below this main level is used
for entering rests and ties. The bottom level contains a box in
which entered notes appear.
In the main level, the method of using the joystick is:
1. Push the stick up or down to change the current pitch.
2. Push the stick left or right to change the current duration.
3. Press and release the joystick button to enter a note.
While you're in the main level, pushing the stick up or
down changes the pitch. The quarter note on the grand staff
moves, the next key on the piano is indicated, and the written
display changes. A full eight octaves is available by pushing
the joystick.
249
Chapter 8
250
Chapter 8
251
Chapter 8
t sharp
b flat
ft natural
D E F-sharp G or D E F-sharp G
This means that you should enter the note with the pitch
F-sharp instead of just a natural F. To do so, use the joystick to
move to pitch F, then press the + key (it's on the top row of
the keyboard) to select the sharp before you press the button
to enter the note.
A sharp increases the pitch of a note. The pitch F-sharp is
halfway between pitches F and G. A flat, on the other hand,
decreases a note's pitch. To make a pitch flat, press the — key
(right beside the + key). If you see a flat symbol before a
note, you must move to the pitch, hit the — key, then press
the button to enter the note.
To cancel a sharp or flat, press the English pound sign (£)
to select the natural pitch.
Key signature. Sometimes you'll find one or more sharp
or flat symbols at the left edge of the staff, next to the clef
symbol. They might look like this:
252
Chapter 8
o # !I
Jr
r\
* If ___w__m * 7—
!•___________ k____ m
C " »----------------
rtttf = a 1 -/ l
Special Options
In addition to notes, the Editor lets you enter commands to
control things like tempo, volume, waveform, and envelope.
Since quite a variety of commands are supported, there's no
room to display the choices on the editing screen, so a sepa
rate screen is used. Press the function key f3 to switch from
the editing screen to the special option screen.
The commands are organized by headings like TEMPO
and WAVEFORM. Each command has its own three-letter
abbreviation. One of the commands is displayed inside a box,
which you can move by pushing the joystick. If the box is
moved off the end of one row or column, it wraps around to
the other side.
The window in the upper-right corner of the screen dis
plays the full name of the current command. This display
changes as the box is moved from one command to another.
To enter a command, first press the joystick button. The
window then shows the number range for the selected com
mand. All commands require that a number be entered from
the keyboard. Once a number is typed and the RETURN key is
pressed, the command is actually entered. The command
name and the number show up in the bottom row, the com
mand and the previous notes scroll to the left, and the display
returns to the editing screen. If you want to enter another
command, you have to press f3 again.
There'll be times when you'll want to enter two or more
commands— having to return to the special option screen each
time can be inconvenient. Fortunately, there's a way to enter a
command without having the display switch back to the
editing screen. After you press the button and type the num
ber, press SHIFT-RETURN instead of RETURN. The command
is entered, but the screen doesn't change.
If you accidentally press the button on the wrong com
mand, press only RETURN without typing a number. The
command is not entered, and you'll be able to choose another.
Commands can be scrolled, inserted, and deleted, just like
notes. The INST/DEL key can also be used while you're in the
special options screen.
255
Chapter 8
256
Chapter 8
M.M. 163. If that was the case, the tempo value 150 would
have to be used.
If you try to use durations like sixteenth notes in a tempo
which does not support them, the Editor prints the error mes
sage ILLEGAL DURATION when the voice is played. If this
should happen, press any key to acknowledge the error, and
then change the tempo to one that does support the duration.
Sometimes a word like adagio or allegro is used in place of
a number. In these situations, you have to choose the appro
priate tempo value based on the information given in Chapter 7.
257
Chapter 8
If the sheet music does not specify any tempo at all, just
use whichever tempo sounds best to you. If you don't enter a
TEM command, M.M. 100 is used.
Volume. Like tempo, the general volume level (dynamics)
of a song is also usually indicated at its beginning. The level is
specified with the letters p for piano (soft) and / for forte
(loud).
The master volume of the SID chip can range from 0 to
15, with 15 being the loudest and 0 being off. This volume
level is set by the VOL command.
Here are the suggested volume levels for various dynam
ics markings.
Dynamic Volume
fff 12
ff 11
f 10
mf 8
mp 7
P 5
PP 4
PPP 3
It's recommended that you not use volume levels above
12, because they can cause notes to distort. If the sheet music
does not specify a volume, do not enter a VOL command. The
default volume level of 8 (mf) will then be used.
Measures. Notes are organized into groups called mea
sures. Measures help the performer keep in time with other
players and are convenient when trying to locate a particular
note in a song.
258
Chapter 8
259
Chapter 8
Entering a Melody
Now that you know something about how the Editor works,
how about trying to enter a short song? Just follow this step-
by-step example, and you'll have one. Use the sheet music
shown as Figure 8-8.
J J J J J J . 1III 1 1 11
260
Chapter 8
261
Chapter 8
Error Checking
Sometimes a few mistakes may be made when entering a
song. The Editor can find some, like the use of a sixteenth
note in a tempo that does not support sixteenth notes, but it
cannot find others, such as wrong pitches. Fortunately, the
Editor has some features that make it easy to track down mis
takes and correct them.
Autostop. If you're playing a voice and the Editor stops
with the ILLEGAL DURATION error, the Editor points to the
note which caused the error. This means that when you switch
to the editing screen, the notes move so that the one with the
illegal duration appears in the box.
Manual stop. Playing can also be stopped at any time by
pressing the f7 key. When you then go to the editing screen,
the note in the box will be the one playing at the moment you
hit the key. This feature can be convenient when you're play
ing a song and you hear a ''bad'' note.
If you press any key other than f7 while a song is playing,
the playing stops, but the Editor leaves the voice alone and
doesn't move to the note being played.
Fast forward. Another feature is a fast forward mode.
This can be useful when you're entering a long song. Perhaps
the beginning of the song plays fine, but some later parts need
work. When you choose PLAY from the main menu, playing
always starts at the beginning of the song. There's no way to
start somewhere in the middle.
With the fast forward mode, you still have to start at the
beginning, but you can make it play much faster. If you hold
the joystick button down while playing a song, the song plays
at three times the normal speed. Playing will return to normal
as soon as you release the button.
262
Chapter 8
Loading a Song
This main menu item is used to load a music file from tape or
disk into memory. Type the filename of the desired file
(excluding the .MUS extension), and press RETURN. Tape
users will not be prompted to press PLAY. The Editor loads
the song, replacing the one currently in memory.
Note that loading a song erases the one in memory. If you
want to preserve the song currently in memory, save it to disk
or tape before loading a new one.
If you're using disk and the requested file is not on the
disk, the Editor will report the FILE NOT FOUND error.
If you're using tape and enter an incorrect filename, or if
you position the tape past the beginning of the data, the pro
gram will fail to locate the song. If you believe you entered a
filename that is on the tape, but the program fails to find the
song, stop the tape and rewind it to a position before the
beginning of the data and press PLAY again. The only other
way to recover from an incomplete LOAD from tape is to turn
the computer off, reload the Editor, and start over.
After the song is loaded, the text lines in the window are
updated. The Editor is ready for you to select another item.
If you accidentally choose LOAD, don't type a filename
and just press RETURN. The song in memory will not be
erased.
264
Chapter 8
49182 :016,000,016,147,016,159,128
49188 :016,146,030,004,016,147,139
49194 :016,147,016,147,016,146,018
49200 :030,005,016,145,016,145,149
49206 :016,157,016,158,030,006,181
49212 :020,145,020,145,020,145,043
49218 :020,081,030,007,016,146,110
49224 :016,146,016,158,016,159,071
49230 :030,008,080,146,080,145,055
49236 5080,159,080,158,030,009,088
49242 5012,157,012,000,001,079,095
49248 s006,080,001,071,001,012,011
49254 5001,160,001,132,001,008,149
49260 5030,001,054,016,020,173,146
49266 5001,015,030,003,054,016,233
49272 5020,171,001,015,030,005,106
49278 5054,011,020,169,001,015,140
49284 5020,105,030,007,054,016,108
49290 5020,170,001,015,030,009,127
49296 5012,181,012,000,001,079,173
49302 5006,080,001,007,001,004,249
49308 5001,096,001,132,001,104,235
49314 5038,001,030,001,001,006,239
49320 5016,000,016,141,016,000,101
49326 5016,141,016,000,020,141,252
49332 5020,141,020,000,020,141,010
49338 5020,141,020,000,001,047,159
49344 5030,003,001,002,030,005,007
49350 5016,000,016,141,016,000,131
49356 5016,141,030,006,020,000,161
49362 5020,141,020,141,020,141,181
49368 5030,007,001,002,001,079,080
49374 5066,076,085,069,083,013,102
49380 5067,082,065,073,071,032,106
49386 5067,072,065,077,066,069,138
49392 5082,076,065,073,078,013,115
49398 5013,013,000,013,013,013,055
W Whole
H Half
Q Quarter
8 Eighth (E is used for a note name)
S Sixteenth
T Thirty-second
• Press the period (.) key if you want a dotted note. Press the
key again to cancel the dot.
• Press the RETURN key to enter a note. This is like pressing
the joystick button.
• In the special options screen, use the letters I, /, K, and M to
move the box up, left, right, or down. Press RETURN to se
lect a command.
267
Chapter 8
Move to the bottom level and push the stick left or right
to scroll the notes. Be aware that keyboard items, including the
INST/DEL key, do not work when you're in this level. Press
the button to return to the main level.
268
Chapter 8
SIDPLAYER
UNSHIFTED SHIFTED
1. 2.
MAIN BEGINNING
MENU OF
VOICE
3. 4.
SPECIAL END
OPTIONS OF
SCREEN VOICE
5.
MEASURE
SEARCH
7.
MEASURE
MARKER
269
Chapter 9
Making Music
Waveforms
The timbre of a sound is what distinguishes a middle C played
on a saxophone from a middle C played on a cello. The main
thing that controls a sound's timbre is the type of vibration
which produces the sound. There are a few basic types of
vibrations, or waveforms. These types are named according to
their shape when viewed with an oscilloscope.
Triangle waves (Figure 9-1) produce soft, mellow tones.
The flute is an example of an instrument which produces tri
angle waves.
271
Chapter 9
272
Chapter 9
273
Chapter 9
274
Chapter 9
276
49278 :0 2 0 , 157, 004 ,156,092,158,201 49464 :016,211, 020 ,211,020,211,233
49284 :020,157, 020 ,156,001,212,186 49470 :088,211, 088 ,146,088,145,060
49290 :088,148, 024 ,145,088,148,011 49476 :088,223, 088 ,158,088,157,102
Chapter 9
277
49824 5024,147,024,146,024,145,158
50016 :024,166, 024 ,153,024,231,206 50202 s084,164, 084 ,163,020,164,193
278
50022 :024, 153, 024 ,166,024,153,134 50208 :030,008, 001 ,071,084,153,123
50028 :024, 231, 024 ,153,024,166,218 50214 5084,166, 084 ,163,012,162,197
50034 :024, 153, 016 ,000,024,164,239 50220 5084,163, 084 ,231,084,165,087
Chapter 9
279
Chapter 9
280
49188 :084, 167 ,0 2 0 ,165,076,153,189 49374 :016,154, 016 ,154,012,154,216
49194 :084, 167, 084 ,166,084,167,026 49380 :016,157, 016 ,159,012,146,222
49200 :084, 153 ,016 ,166,020,154,129 49386 :016,146, 016 ,146,012,159,217
Chapter 9
Envelopes
Dynamics describe the general volume of a song, as set by the
master volume, but do not describe the changes in volume
which occur while an individual note is playing. These
changes in volume over the course of a note are referred to as
the envelope of the note.
When a note first starts playing, the volume must increase
from no volume to the peak volume established by the
dynamics. The speed at which the volume rises is called the
attack rate.
The volume then diminishes slightly until it reaches an
intermediate volume level called the sustain level. The rate at
which the volume falls from the peak level to the sustain level
is called the decay rate.
Toward the end of a note, the note will be released and
the volume will begin to fade away, at a speed called the re
lease rate.
A good way to understand the four stages of the envelope
is to graph them as shown in Figure 9-7.
Time -* ■
283
Chapter 9
284
Chapter 9
600 24 12 6 3 - - -
450 32 16 8 4 2 1 -
360 40 20 10 5 - - -
300 48 24 12 6 3- -
257 56 28 14 7 - - -
225 64 32 16 8 4 2 1
200 72 36 18 9 - - -
180 80 40 20 10 5- -
163 88 44 22 11 - - -
150 96 48 24 12 6 3 -
138 104 52 26 13 - - -
128 112 56 28 14 7- -
120 120 60 30 15 - - -
112 128 64 32 16 8 4 2
105 136 68 34 17 - - -
100 144 72 36 18 9- -
94 152 76 38 19 - - -
90 160 80 40 20 10 5 -
85 168 84 42 21 - - -
81 176 88 44 22 11 - -
78 184 92 46 23 - - -
75 192 96 48 24 12 6 3
72 200 100 50 25 - - -
69 208 104 52 26 13 - -
66 216 108 54 27 - - -
64 224 112 56 28 14 7 -
62 232 116 58 29 - - -
60 240 120 60 30 15 - -
58 248 124 62 31 - - -
56 256 128 64 32 16 8 4
The number of jiffies for a whole note is different for each
tempo. This number is repeatedly cut in half to give durations
like half note, quarter note, and so on. After a certain point,
some numbers cannot be evenly divided by two, which is why
some tempos do not support sixteenth or thirty-second notes.
The PNT command determines how many jiffies from the
end of a note the volume should be released. For an example,
let's say that the release point is set at 6 and the current
tempo is M.M. 100. A quarter note in this tempo is 36 jiffies
long. For the first 30 jiffies, the volume goes through the at
tack, decay, and sustain phases of the envelope. Then the
285
Chapter 9
voice will be released, and for the last 6 jiffies the volume falls
from the sustain level to no volume.
The range of the PNT command is 0-255, but usually
only very small values are used. Values like 3, 4, and 5 work
best. It's preferable not to set the release point too high, or
notes of short duration won't be heard. For instance, in M.M.
100, an eighth note is 18 jiffies long. If the release point was
set at 20 jiffies, an eighth note would be released as soon as it
started playing. The volume would never have a chance to
rise, and the note would not be heard.
For best results, always make sure that the release point is
less than the duration of the shortest note in the song.
If you're using a nonsustaining envelope, the PNT com
mand must be used to set the release point at 1.
Here are the default values for the envelope. This
configuration produces an organ effect.
ATK 2
DCY 0
SUS 15
RLS 5
PNT 4
If some default settings are satisfactory but others are not,
you have to change only the ones that need new values.
Also, remember that you can change the envelope at any
point in a song. For example, a voice may briefly switch to a
nonsustaining envelope to play a few notes and then switch
back.
Each voice can have its own envelope, but it's recom
mended that the attack rate be nearly the same for all three
voices.
Experiment with different envelopes. Load BLUES and try
different envelope settings on the first voice.
Envelope Example
The following song, "Theme and Variation" by Beethoven,
uses a wide variety of envelopes.
287
49278 :001,152, 001 ,015,012,000,051 49464 :001,015, 001 ,079,006,192,094
288
49284 :054,002, 001 ,086,001,004,024 49470 :001,052, 054 ,002,001,038,210
49290 :001,144, 001 ,132,001,152,057 49476 :084,154, 0 2 0 ,090,016,155,075
49296 5038,001, 024 ,000,024,146,121 49482 :020,000, 0 2 0 ,153,020,167,198
Chapter 9
The Filters
Sometimes it's not enough to set the waveform and envelope
of a voice in order to imitate the sound of a particular in
strument. It may also be necessary to control the harmonic
content of the voice by using the filter.
When an oscillator generates a tone, it produces not only
the requested pitch, but some harmonics as well. Harmonics
are frequencies related to the main pitch. The first harmonic is
the frequency of the main pitch and is also called the fun
damental frequency. The second harmonic has a frequency
twice the fundamental frequency. The frequency of the third
harmonic is three times that of the fundamental frequency,
and so on.
Because the volume of the fundamental frequency is al
ways greater than the volume of the other harmonics, the
main pitch detected by your ear is that of the fundamental fre
quency. The harmonics, however, give the tone its timbre.
Since each instrument has its own characteristic timbre,
the ability to control the harmonic content of a voice can be
helpful in emulating a particular instrument. The filter is used
to remove selected frequencies from a tone. This enables you
to emulate a whole new variety of instruments.
The SID chip's filter has three main control parameters
that must be set before the filter can be used. These param
eters are the mode, the cutoff frequency, and the resonance.
Filter mode. The filter mode determines which types of
frequencies are removed from a tone. The most commonly
used mode is the low-pass mode. This mode allows only the
frequencies below a certain frequency, called the cutoff fre
quency, to pass through the filter. Any frequencies above the
cutoff are attenuated (greatly reduced in volume) so that they
are seemingly removed from the tone.
The low-pass filter mode (illustrated by Figure 9-9) pro
duces full-bodied tones. The opposite of the low-pass mode is
the high-pass mode, in which frequencies below the cutoff are
suppressed while frequencies above the cutoff are passed
through unaltered.
The high-pass mode causes tones to sound tinny or
buzzy.
290
Chapter 9
High
frequencies
Cutoff
Low
frequencies
Low-pass filter
High
frequencies
Cutoff
Low
frequencies
High-pass filter
High
frequencies
Cutoff
Low
frequencies
Band-pass filter
291
Chapter 9
Use the F-M command to set the filter mode. This com
mand works similarly to the WAV command. When you press
the joystick button for F-M, the window displays a number for
each filter mode.
1 L Low p ass
2 B B an d p ass
4 H H ig h p a ss
293
Chapter 9
294
Chapter 9
295
Chapter 9
Three Demonstrations
Three demonstration songs have been provided. In the first
one, a theme is played by a trumpet, a trombone, then a tuba.
The other two demonstrations emulate a koto and a sitar.
49290 :079,066,069,082,084,032,038
49296 :072,073,071,071,073,078,070
49302 :083,013,000,151,024,147,056
297
Chapter 9
49176 :038,007,001,135,050,232,231
49182 :086,010,006,096,030,001,003
49188 :054,002,016,163,016,165,196
49194 :012,153,044,161,001,015,172
49200 :030,002,054,002,028,145,053
49206 :028,145,028,159,028,159,089
49212 :028,158,028,1^8,(^28,157,105
49218 :028,157,028,156,028,156,107
49224 :028,155,028,155,028,154,108
49230 5028,154,028,167,012,167,122
49236 5003,020,012,153,001,015,032
49242 5020,153,020,153,024,153,101
49248 5024,153,028,153,028,153,123
49254 5028,153,028,153,016,153,121
49260 5001,079,001,079,001,079,092
49266 5083,073,084,065,082,032,021
49272 5068,069,077,079,078,083,062
49278 5084,082,065,084,073,079,081
49284 5078,013,067,079,085,082,024
49290 5084,069,083,089,032,082,065
49296 5079,066,069,082,084,032,044
49302 5072,073,071,071,073,078,076
49308 5083,013,013,013,000,137,159
Repetition
As you listen to a song, you can sometimes hear a group of
measures played more than once. Repetition occurs often in
music, especially in contemporary songs.
The simplest form of repetition is when a group of mea
sures is repeated immediately after being played. So that the
repeated measures do not have to be written twice, special
symbols are used in sheet music to indicate when a sequence
of measures should be repeated. The symbol that marks the
beginning of a repeat consists of two vertical lines followed by
two dots (shown in Figure 9-13). The end of a repeat is
marked by a symbol that looks almost the same, except that
the dots come before the double lines, instead of after them.
When the music is played and the first repeat symbol is
reached, the playing continues as usual. Upon reaching the
end of the repeat, however, playing does not continue to the
next measure. Instead, playing jumps back to the measure
which had the beginning repeat symbol and continues from
that point. When playing comes to the end repeat mark the
second time around, it's ignored and playing continues with
the next measure.
298
Chapter 9
299
Chapter 9
repeat. Each voice can have its own repeat, however, so each
voice can repeat independently of the others.
When repeats are used properly, there should be one re
peat end for every repeat beginning. If a voice is playing and a
TAL command is encountered with no previous HED com
mand, playing will repeat forever back to the most recent
HED command. If no HED command has been used at all on
the current voice, playing will repeat forever back to the
beginning of the voice.
Phrases. Occasionally, you'll find that a repeat has a first
and a second ending. This means that one set of notes should
be played at the end of the sequence the first time through,
and a different set should be played the second time. The
simple repeat structure of the HED and TAL commands can
not handle this— in this case, you have to use phrases.
If you consider that a repeat is a loop, then a phrase is
like a subroutine. A phrase allows the same sequence of notes
to be played at different places in the music. The first time the
phrase is played, the beginning and end are remembered by
Sidplayer. This is called defining the phrase. Later in the music
when the notes have to be played again, playing can be made
to jump back to the beginning of the phrase by the use of a
single command. This is known as calling the phrase. When
the end of the phrase is reached, playing continues with the
rest of the song.
It's important to understand that there are some dif
ferences between Sidplayer phrases and BASIC subroutines. In
BASIC, a subroutine is usually put at the end of a program.
Every time the subroutine has to be executed, it's called by the
GOSUB statement. With Sidplayer, the notes and commands
that form the phrase are placed in the song at the first in
stance where the phrase must be played. After the phrase has
played once, and is thereby defined, it can be played again by
use of the phrase call.
To define a phrase, first enter the DEF command. This
command needs a number in the range 0-15. For now, just
enter the command with 0, then enter the notes which form
the phrase.
After the last note in the phrase, enter the command
END. Like the TAL command, the END command has no data
value, so it should be entered by typing the 0 and pressing
RETURN.
300
Chapter 9
301
Chapter 9
The 16 phrases are shared among the three voices. For ex
ample, even though phrase 7 may be defined on voice 1, it
can also be called on voice 2 or 3. This means that playing can
temporarily jump to another voice.
This can cause a problem when you are playing individ
ual voices. For example, if you play only voices 2 and 3, and
voice 2 contains a call defined in voice 1, playing will stop
with the UNDEFINED PHRASE CALL error.
It's even possible for one phrase to call another. Phrase
calls can be nested to a limit of four levels on each voice. If
you try to exceed the limit, the Editor stops and reports the
STACK OVERFLOW error. You can also define one phrase in
side another. Be aware that a phrase definition counts as one
nesting level. The only thing a phrase definition cannot do is
call itself. If the definition of phrase 3 directly or indirectly
contains a call to phrase 3, an infinite loop results. Playing
will eventually stop with a STACK OVERFLOW error.
Phrases can be redefined. If a phrase is no longer needed,
the phrase number can be used in the DEF command of a new
phrase. This lets you use more than 16 phrases during the
course of a song.
The STACK UNDERFLOW error occurs if DEF and END
commands are not properly matched and playing comes across
an END command with no previous DEF command.
Da capo, dal segno, and coda. Repeats are not the only
kind of repetition. Other forms include da capo and dal segno.
Da capo is indicated in sheet music by the letters D.C., and
means that the playing should jump back to the beginning of
the voice and continue from there, this time ignoring all re
peats. The playing may be stopped before the end of the song
by the use of the word fine.
Dal segno, identified by the letters D.S., means that play
ing should jump to the measure marked by a special sign. This
sign looks like a slash with dots to either side, passing through
a fancy letter S. Playing continues from this point, and stops
either at the end of the song or at a fine, whichever comes
first.
There's one other symbol often encountered when da
capo or dal segno has been used. After playing has jumped
back to the beginning of the voice or to a particular measure,
you may encounter the message To Coda, followed by a coda
symbol. The coda symbol looks like a letter O with a cross
302
Chapter 9
- f t - J - l 1 1? t - 4 4 - f - J | J | , | J iU - n
^ m 1 1J _ m ^ __1 • m___J _____ J _J _0 _
jaia
\U)__ u m ^
• w m • m ^ 0- 1 ~ ^
M._____________
•
303
Chapter 9
304
Chapter 10
Sophisticated Sounds
305
Chapter 10
306
Chapter 10
307
Chapter 10
Q_ 1 1
-Jr E*— J --- j . j ..... —-J—
— m 0 —0 .. & —J J--J
note is only two beats long, and a half note is one beat long.
The quarter note plays for only half a beat. When the number
on the bottom is 8, a quarter note plays for two beats, and the
note for one beat is now an eighth note. The tempo stays the
same; the number of beats per minute remains unchanged. It's
the number of beats per note that's different.
Sidplayer is designed to expect a whole note to always be
four beats so that a quarter note is always one beat. There's no
way to change the number of beats for these standard dura
tions. Time signatures which have a number other than 4 on
the bottom can be used indirectly, however, by fooling
Sidplayer into thinking that a whole note is longer or shorter
than it actually is.
Consider the time signature 2 /2 , in which a whole note is
two beats, compared to four beats in 2 /4 . A whole note is
seemingly reduced to half its normal duration. This can be
achieved on Sidplayer by doubling the tempo. At faster tempo
selections, more beats per minute means that each beat takes
less time, so whole notes are shorter. Therefore, when the
tempo is M.M. 100, 2 /2 time can be simulated by actually
using M.M. 200. To use a time signature where the bottom
number is 8, as in 3 /8 , the tempo should be cut in half, mak
ing whole notes play twice as long as normal.
There's another way to show a time signature without
using numbers. The letter C placed where the time signature
belongs indicates 4 /4 time. The C stands for common time. If
the C has a vertical line passing through it, it indicates 2 /2
time, also known as cut time.
One last word about time signatures— they can change
while a song is playing. Such changes are indicated by double
bars followed by a new fraction or symbol.
Accidentals. In any octave, there are 12 different pitches,
including naturals, sharps, and flats. Earlier you saw that a
song will use only 7 of these pitches, according to the current
key. Let's retract that now. Once in a while a song may have
to play a note using a pitch not in the key. The “BLUES''
piece is written in the key of G, meaning that only one note is
sharp (F-sharp), but the melody line had to play a C-sharp at
one instance.
Special exceptions like this are handled by placing an ac
cidental sign immediately before the note that is to be sharp or
flat. This accidental overrides the current key signature for that
particular pitch.
309
Chapter 10
310
Chapter 10
Bb C Bbk=A A
The double sharp and double flat signs, along with the
sharp, natural, and flat signs, give a total of five different ac
cidental signs.
The Editor does not support double sharps and double
flats. When you see a note with a double sharp or flat, you
must calculate the pitch that should be entered. For example,
if you encounter a C-double-sharp, you should enter a D-
natural.
Double dots. A dot placed after a note means that the
duration should be increased by one-half. Adding a second
dot means that the value of the first dot should be increased
by one-half. Thus, a double-dotted half note is equal in dura
tion to a half note, plus a quarter note, plus an eighth note.
Double dots can be used on other durations as well.
Because double-dotted notes are very rare, they're not di
rectly supported by Sidplayer. You can simulate them, how
ever, by entering the appropriate single-dotted note and tying
it to another note of the same pitch. For example, a double-
dotted C4 half note could be simulated by entering a dotted
C4 half note tied to a C4 eighth note.
Triplets. All the durations, from whole note to thirty-
second note, are based on the number two. These durations
allow notes to be played for one, two, or four beats, half a
beat, and so on. This system works very well, except that it's
difficult to handle durations based on the number three. To
311
Chapter 10
play a note for three beats, a dotted half note can be used. But
how do you play a note for one-third of a beat? Using dots
will not help there. Instead, you need to use a new kind of
duration called a triplet.
A triplet consists of three notes played for the amount of
time normally allotted to two notes. An eighth triplet is equal
in duration to two eighth notes. Because two eighth notes
form one beat, each of the three notes in a triplet is one-third
of a beat long.
313
Chapter 10
4 ~ = JJJJ^ l
Repeat loops can be useful in entering trills. To enter the
trill shown in the example, a pair of thirty-second notes, in the
pitches F and G, could be entered between a HED and TAL.
The loop would be repeated four times.
315
Program 10-1. ALBUMLEAF.MUS 49290 5020,092, 020 ,146,020,092,016
316
To enter this program, you must use "The Machine Language 49296 5030,012, 020 ,000,020,157,127
Editor (MLX)," a program found in Appendix C. 49302 5020,000, 020 ,157,030,013,134
Starting Address: 49152 49308 5020,000, 020 ,157,020,000,117
Chapter 10
317
5020,167, 02 0 ,166,030,016,155
Chapter 10
318
49854 5030,004, 020 ,000,020,167,175 50040 :020,167, 030 ,027,020,000,128
49860 :020,000, 020 ,167,030,005,182 50046 :020,167, 020 ,000,020,167,008
49866 5020,000, 020 ,167,020,000,173 50052 :030,028, 02 0 ,000,020,167,141
49872 5020 ,089, 030 ,006,020,000,117 50058
Chapter 10
:020,000, 0 2 0 ,089,030,029,070
49878 :020,167, 020 ,000,020,167,096 50064 :020,000, 020 ,167,020,000,115
49884 s030,007, 020 ,000,020,167,208 50070 :020,167, 030 ,030,020,000,161
49890 :020,000, 020 ,167,030,075,026 50076 :020,167 ,020 ,000,020,167,038
49896 5020,000, 020 ,167,016,000,199 50082 :030,031, 020 ,000,020,167,174
49902 5001,015, 030 ,008,054,002,092 50088 :020,163, 020 ,000,001,015,131
49908 5076,173, 030 ,009,016,173,209 50094 :001,079, 065 ,076,066,085,034
49914 5016,000, 030 ,010,020,000,070 50100 :077,076 ,069 ,065,070,013,038
49920 :020 ,153 ,020 ,000,020,153,110 50106 :069,068, 086 ,065,082,068,112
49926 5030,011, 020 ,000,020,153,240 50112 :032,071, 082 ,073,069,071,078
49932 5020 ,000, 020 ,153,030,012,247 50118 :013,085, 083 ,069,083,032,051
49938 5076,173, 030 ,013,016,173,243 50124 :080,079, 082 ,084,065,077,159
49944 5016,000, 030 ,014,020,000,104 50130 :069,078, 084 ,079,013,067,088
49950 :020, 155 ,020 ,000,020,155,144 50136 :079,085, 082 ,084,069,083,186
49956 5030,015, 016 ,000,020,000,117 50142 5089,032, 066 ,079,066,032,074
49962 :020,162, 030 ,016,076,173,007 50148 5082,069, 084 ,069,076,076,172
49968 :030, 017 ,016 ,173,016,000,044 50154 5069,013, 0 0 0 ,239,024,164,231
49974 5030,018, 020 ,000,020,153,039
49980 :020,000, 020 ,153,030,019,046
49986 :020,000, 020 ,153,020,000,023
49992 :020, 153 ,030 ,020,076,171,030
49998 :030,021#016 ,171,016,000,076
50004 , ,
:030 0 2 2 012 ,161,030,023,106
50010 :012,175, 030 ,024,020,000,095
50016 :020,167, 020 ,000,020,089,156
50022 1030,025, 020 ,000,020,167,108
50028 :020,000, 020 ,167,030,026,115
Program 10-2. K.C.O.MUS 49290 :048,149, 020 ,215,020,150,228
To enter this program you must use "The Machine Language
, 49296 :084,148, 038 ,255,001,200,102
Editor (MLX)," a program found in Appendix C. 49302 :044,148, 001 ,072,038,001,198
49308 :048,000, 088 ,149,024,148,101
Starting Address: 49152 49314 :048,211, 020 ,149,020,148,246
Ending Address: 49469 49320 :084,146, 001 ,200,038,255,124
Filename: K.C.O.MUS 49326 :044,146, 038 ,001,001,072,220
49332 :048,000, 088 ,211,024,146,185
49152 :220,000,040 ,000,002,000,006 49388 :048,145, 020 ,211,016,158,016
49158 :001,142,118 ,012,134,003,160 49344 :084,148, 001 ,200,038,255,150
49164 :001,044,001 ,072,038,001,169 49350 :076,148, 020 ,148,001,072,151
49170 :001,071,001 ,006,048,000,145 49356 :038,001,022 ,013,004,142,168
49176 2088,153,024 ,219,048,157,201 49362 :001,094, 022 ,026,068,140,049
49182 2088,156,024 ,219,088,156,249 49368 5038,255, 001 ,200,008,140,090
49188 2088,153,084 ,153,038,255,039 493 74 5016,000, 001 ,079,001,039,102
49194 2001,216,044 ,153,038,001,239 49380 5001,068, 054 ,002,008,169,018
49200 2001,072,048 ,000,088,153,154 49386 5001,020, 008 ,172,008,169,100
49206 2024,219,048 ,157,088,156,234 49392 5008,247, 072 ,169,008,169,145
49212 2024,219,048 ,156,088,157,240 49398 5166,126, 001 ,015,030,002,074
49218 2024,156,048 ,231,020,154,187 49404 5008,173, 008 ,172,008,235,088
49224 2001,047,080 ,153,108,153,102 49410 5008,170, 008 ,169,008,172,025
49230 2038,255,001 ,216,008,153,237 49416 5001,079, 001 ,079,075,046,033
49236 2038,001,001 ,072,166,097,203 49422 5067,046, 079 ,046,013,086,095
49242 2001,002,166 ,014,080,165,006 49428 5073,066, 082 ,065,084,079,213
49248 2080,153,038 ,255,001,200,055 49434 5032,068, 069 ,077,079,078,173
49254 2012,153,038 ,001,001,072,123 49440 5083,084, 082 ,065,084,073,247
49260 2001,039,022 ,013,004,147,078 49446 5079,078, 013 ,066,089,032,139
49266 2022,026,068 ,145,038,255,156 49452 5072,065, 082 ,082,089,032,210
49272 2038,072,001 ,200,044,145,108 49458 5066,082, 065 ,084,084,013,188
49278 2038,001,001 ,072,030,002,014 49464 5013,000, 020 ,151,020,151,155
49284 2048,000,088 ,215,024,150,145
319
Chapter 10
Chapter 10
D etuning
The DTN command is used to detune a voice. Detuning is
accomplished by adding a constant number, specified by the
DTN command, to the frequency number of each note played.
Detuning a single voice is not very useful. All it does is
make the voice play slightly out of tune. When used with two
voices, however, with both voices playing the same notes but
one slightly detuned, the result is a "chorus" effect. This effect
was used in the "COMMODORE" demonstration song and
has some interesting applications.
What's the easiest way to make two voices play the exact
same notes? The answer is to use phrases. A phrase defined
on voice 1 can be called simultaneously on voice 2 or 3. You
don't have to wait for playing to reach the END command
before calling the phrase; the phrase is available as soon as
Sidplayer has processed the DEF command.
This means that you can define the phrase on voice 1 and
call it on voice 2 after having set the detune value.
V o ic e 1 : D E F 0 P l a y N o t e s E N D
V o ic e 2 : D T N 5 0 C A L 0
320
Chapter 10
321
Chapter 10
49326 :001,066,030,009,001,050,075
49332 :001,079,166,065,001,002,238
49338 :008,157,008,157,008,157,169
49344 :008,157,008,157,008,157,175
49350 5008,157,001,079,001,002,190
49356 5001,018,001,034,001,018,021
49362 s001,050,001,066,001,082,155
49368 5001,066,001,050,001,079,158
49374 5084,072,069,032,082,069,118
49380 5068,067,079,065,084,083,162
49386 5032,065,082,069,032,067,069
49392 5079,077,073,078,071,033,139
49398 5033,033,013,066,065,071,015
49404 5080,073,080,069,032,068,142
49410 5069,077,079,078,083,084,216
49416 5082,065,084,073,079,078,213
49422 5013,085,083,069,083,032,123
49428 5068,069,084,085,078,073,221
49434 5078,071,032,065,078,068,162
49440 s032,084,082,065,078,083,200
49446 5080,079,083,073,084,073,254
49452 5079,078,013,067,079,085,189
49458 5082,084,069,083,089,032,233
49464 5082,079,066,069,082,084,006
49470 5032,072,073,071,071,073,198
49476 5078,083,013,000,020,151,157
Transposing
Detuning works by adjusting the pitch of each note so that it's
slightly sharp or flat. Transposing also changes the pitch of
each note, but in quite a different way.
When a voice is transposed, the pitch of each note is
shifted up or down a designated number of half steps. For ex
ample, if a voice is being transposed up one half step, all
notes entered as C play as C-sharps, all C-sharps play as D,
every D plays as D-sharp, and so on. If the voice is being
transposed down one half step, D notes play as C-sharps, C
sharps as C-naturals, C-naturals become B-naturals, and so on.
You can check these alterations by tracing the transposing
using Table 10-1.
322
Chapter 10
with the correct pitches would require too many leger lines,
and the notes would be difficult to read.
The easiest way to handle an octave offset is to enter the
notes as written, and then insert a TPS 12 or TPS —12 com
mand at the beginning of the offset.
An interesting effect is created by having two voices play
the same note, while one of the voices is transposed up one or
two octaves. This produces a rich, warm tone. The effect was
used in the COMMODORE demonstration song. Another
possibility is to use transposing with detuning. While one
voice plays a series of notes, the other plays the same notes,
but is detuned and transposed up one or two octaves. Pro
grams 10-4 and 10-5 use the technique to imitate a calliope
and an accordion.
Synchronization
In the previous section, it was mentioned that a rich, warm
tone can be created when two voices play the same notes and
the second voice is transposed up by 12 or 24 half steps. But if
you try this technique with the second voice transposed up by
other numbers of half steps, like 6, 11, or 13, the resulting
tone sounds less than desirable.
The reason that the pleasant tone is produced only when
the second voice is transposed up an octave or two is because
the voices become synchronized. Remember that the fre
quency of a note is doubled when it's played an octave higher.
When two voices play the same notes, one an octave higher,
the direct relationship between the frequencies causes the
tones to be synchronized.
The tone produced by two synchronized voices sounds
rich and warm because it contains more harmonics than usual.
The second voice augments the harmonics of the first one.
This method of adding harmonics to a tone is called additive
synthesis. (Filtering is called subtractive synthesis because the
filter removes harmonics from a tone.)
Synchronization occurs naturally at intervals of 12 half
steps, but it can be made to occur at any half-step interval if
the synchronization mode of the SID chip is turned on. The
advantage to using the synchronization mode is that different
half-step intervals produce different harmonic patterns.
Synchronization, therefore, lets you produce many new types
of tones.
The SNC command is used to control the synchronization
324
Chapter 10
326
To enter this program,you must use "The Machine Language 49296 5020,159, 020 ,146,044,145,166
Editor (MLX)," a program found in Appendix C. 49302 5001,079, 001 ,039,030,001,045
49308 s001,006 ,020 ,165,020,153,009
Starting Address: 49152
Chapter 10
327
49284 5020,146,016,145,020,146,113
49476 5073,065,078,032,068,069,197 49230 5084,157,084,211,084,223,153
328
49482 :077,079,078,083,084,082,045 49236 5030,004,020,157,088,223,094
49488 :065,084,073,079,078,013,216 49242 5088,222,088,157,088,222,187
49494 :067,079,085,082,084,069,040 49248 5084,223,084,219,084,157,179
Chapter 10
49782 5088,157,088,158,088,223,152
329
49596 5001,047, 001 ,135,050,232,142
49788 .*088,158,020,157,020,145,200 49974 5001,002, 166 ,012,001,002,238
330
49794 :088,219,088,154,088,153,152 49980 s166,124, 001 ,002,166,058,065
49800 :088,154,020,219,030,032,167 49986 5001,002, 166 ,090,001,002,072
49806 5016,154,016,000,020,000,092 49992 sl66,106, 001 ,002,166,190,191
49812 5001,047,001,006,130,000,077 49998
Chapter 10
331
50340 2084,162, 084 ,239,084,165,214 50526 :030,029, 0 2 0 ,227,088,165,141
50532 :088,166, 088 ,231,088,166,159 50718 :020,174,088, 161 ,088,239,032
332
50538 :020,165, 020 ,153,088,227,011 50724 :088,174,088, 239 ,084,161,102
50544 :088,162, 088 ,161,088,162,093 50730 :084,172,084, 174 ,084,169,041
50550 z 0 2 0 , 2 2 1 , 030,,030,020,162,095 50736 5084,235,030, 038 ,020,170,113
50556 :088,164, 088 ,165,088,166,115 50742 5088,239,088, 161 ,088,162,112
Chapter 10
Ring Modulation
A ring modulator takes two frequencies and produces two new
frequencies in their place. The new frequencies are the sum
and difference of the originals. For example, if a ring modu
lator is given frequencies of 200 and 300 Hz, it will produce
the frequencies of 100 and 500 Hz, but not 200 or 300 Hz.
Sometimes it can be hard to discern the pitch of a ring-
modulated tone. The two frequencies may be interpreted by
your ear as a single pitch, but the frequency corresponding to
that pitch is not one of the two produced by the ring modula
tion, so it does not really exist.
Ring-modulated tones are useful for creating percussion
effects. Bells, chimes, steel drums, and various instruments
made of metal, wood, or glass can be approximated.
When used simultaneously with synchronization, a whole
new set of tone colors (timbres) is available.
To use ring modulation, a definite procedure must be fol
lowed. Two voices must play the same sequence of notes, just
like when using the synchronization mode. With ring modula
tion, however, only voices 1 and 3 can be used.
Voice 1 is used to supply the waveform and envelope of
the ring-modulated tone, plus one of the two frequencies
needed for the process. The first thing voice 1 should do is se
lect the triangle waveform. This waveform must be used in or
der for ring modulation to work.
Since ring-modulated tones are used mainly for percus
sion effects, a nonsustaining envelope should be selected.
Finally, enter the command RNG with the value for Yes
to turn ring modulation on. Voice 1 is now ready to start play
ing notes. These notes should be put in a phrase definition so
that they can be called by voice 3.
Voice 3 is used only to supply the second frequency
needed for ring modulation, so the waveform and envelope of
voice 3 do not have to be set. In fact, it's best to turn off the
output from this voice completely, by using the 3 - 0 (3 OFF)
command. Enter this command with the value for Yes at the
beginning of voice 3. The frequencies of notes played by voice
3 are still used in the ring-modulation process, but the output
from voice 3 itself is not heard. Voice 3 can now call the
phrase defined in voice 1.
Here's an example sequence of commands that could be
entered to use ring modulation.
333
Chapter 10
Voice 1
WAV T
ATK 0
DCY 9
SUS 0
RLS 9
PNT 1
RNG Y
DEF
Voice 3
3-0 Y
CAL
As with synchronization, different tone types can be pro
duced by using the TPS command. With ring modulation,
however, transposing one voice can cause the resulting pitch
to be out of tune, so it's often necessary to transpose the other
voice as well to bring the pitch back in tune.
Table 10-2 is a chart ordered by increasing half-step inter
vals. For each interval, the appropriate transpose values for
voices 1 and 3 are given.
-1 6 6 -1 0 F7
-1 5 6 -9 F7
-1 4 6 -8 F7
-1 3 -
-1 2 0 12 B7
-1 1 - -
-1 0 2 -8 A7
-9 4 -5 G7
-8 2 -6 A7
-7 7 0 E7
-6 10 4 017
-5 0 -5 B7
-4 2 -2 A7
-3 - -
-2 - -
-1 - —
334
Chapter 10
0 0 B7
-1 0 B7
OvOOOMONOl^U)K)MOvOOOS10Nairfi>U)K)MO^)OONiaNai4^WhOMOvOOONiavCjl^U)N)
0 4 G7
-5 0 B7
4 10 C87
0 7 E7
-5 4 G7
4 14 A6
0 12 B6
-4 10 C87
-5 10 C8 7
0 16 G6
-5 12 B6
1 19 E6
0 19 E6
-2 20 E 1>6
4 27 G85
0 24 B5
0 26 A5
1 28 G5
0 28 G5
-5 25 Bb5
0 31 E5
-5 27 G85
1 34 Ctt5
0 34 C#5
0 35 C5
0 36 B4
0 37 B b4
0 38 A4
0 39 G#4
0 40 G4
The transpose values for some of these intervals are close
approximations and don't produce a distinct pitch, which is
why they're best used for percussion effects. Those intervals
335
Chapter 10
336
Chapter 10
before from the SID chip. Some intervals to try are the inter
vals with —7, 28, and 38 half steps.
One remaining possibility is to use synchronization and
ring modulation at the same time. This technique yields yet
another set of timbres.
To use both modes simultaneously, follow this procedure.
Voice 1
WAV T
SNC Y
RNG Y
TPS
DEF
Voice 3
3-0 Y
CAL
The triangle waveform is still required, but now any en
velope can be used. Also, every half-step interval produces a
usable tone, so you can disregard Table 10-2. The transposing
always stays in tune, so it has to be done only on voice 1. As
with synchronization, however, negative transpose values are
not very useful.
To turn ring modulation off, enter the command RNG N
on voice 1. Enter the command 3 - 0 N on voice 3 to reenable
the output of that voice. The command TPS 0 should be en
tered on those voices that were being transposed. If you were
also using the filter, enter the commands FLT N and AUT 0
on voice 1. Or, if you were using synchronization, enter the
command SNC N on voice 1.
Whether used alone, with the filter, or with synchroniza
tion, the ring-modulation feature of the SID chip can produce
some very interesting sounds. Program 10-8 is just one more
example of the techniques.
Advanced Techniques
This section explores some new uses for the commands in
troduced in the previous chapters. The techniques suggested
here should give you an idea of just what's possible with
Sidplayer.
Waveform. Probably the most overlooked waveform is
the noise waveform. Although this waveform does not have a
definite pitch quality, its character does change as the pitch is
337
Chapter 10
338
Program 10-7. HOLST.MUS 49290 5016,149,020, 148 ,020,211,190
To enter this program, you must use "The Machine Language 49296 5016,148,016, 149 ,012,215,188
Editor (MIX)/' a program found in Appendix C. 49302 5001,047,166, 042 ,001,018,169
49308 5001,079,001, 079 ,001,091,152
Starting Address: 49152 49314 5166,179,020, 000 ,001,018,034
Ending Address: 49415 49320 5001,034,166, 014 ,001,018,146
Filename: HOLST.MUS 49326 5001,079,084, 072 ,069,077,044
49332 5069,032,070, 082 ,079,077,077
49152 sl52,000,002 ,000,016,000,170 49338 5032,084,072, 069 ,032,074,037
49158 s001,043,001 ,039,166,044,044 49344 5085,080,073, 084 ,069,082,153
49164 2001,004,001 ,144,001,132,039 49350 5032,077,079, 086 ,069,077,106
49170 :001,152,038 ,001,020,000,230 49356 5069,078,084, 013 ,079,070,085
49176 :001,02 2,020 ,157,020,223,211 49362 5032,034,084, 072 ,069,032,021
49182 s016,145,020 ,145,020,211,075 49368 5080,076,065, 078 ,069,084,156
49188 :052,146,024 ,223,020,211,200 49374 5083,034,013, 066 ,089,032,027
49194 :020,148,016 ,211,016,146,087 49380 5071,085,083, 084 ,065,086,190
49200 5020,145,020 ,146,016,145,028 49386 5069,032,072, 079 ,076,083,133
49206 5016,223,012 ,157,020,157,127 49392 5084,013,067, 079 ,085,082,138
49212 5020,223,016 ,145,020,145,117 49398 5084,069,083, 089 ,032,072,163
49218 5020,211,052 ,146,024,223,230 49404 5065,082,082, 089 ,032,066,156
49224 5020,211,020 ,148,016,149,124 49410 5082,065,084, 084 ,013,000,074
49230 5016,149,020 ,149,020,148,068
49236 5016,211,016 ,148,012,211,186
49242 5001,047,001 ,038,020,215,156
49248 5020,149,016 ,148,016,148,081
49254 5020,211,020 ,149,016,148,154
49260 5016,223,020 ,215,020,149,239
49266 5016,148,016 ,148,020,149,099
49272 5020,215,012 ,137,020,137,149
49278 5020,138,016 ,203,016,138,145
339
49284 5016,137,016 ,215,016,203,223
Program 10 8. PROMENADE.MUS 49290 5001,047, 001 ,130,016,148,225
340
To enter this program you must use "The Machine Language
, 49296 5016,146, 020 ,145,020,223,202
Editor (MIX)," a program found in Appendix C. 49302 5016,156, 0 3 0 ,007,001,051,155
Starting Address: 49152 49308 sl66,179, 001 ,034,016,219,003
Chapter 10
u>
4^
Chapter 10
Chapter 10
342
Chapter 10
343
Chapter 10
344
Program 10-9. COURANTE.MUS 49290 5020,154, 0 2 0 ,154,024,153,151
To enter this program,you must use "The Machine Language 49296 5024,154, 02 0 ,155,020,153,158
Editor (MIX)/' a program found in Appendix C. 49302 s020,153, 030 ,007,024,167,039
49308 5024,153, 0 2 0 ,154,020,154,169
Starting Address: 49152 49314 5052,154, 024 ,153,020,167,220
Ending Address: 49679 49320 5016,165, 030 ,008,020,154,049
Filename: COURANTE.MUS 49326 5020,167, 016 ,165,020,157,207
49332 5020,155, 024 ,154,024,153,198
49152 s190,000,090,000, 132 ,000,156 49338 5020,165, 030 ,009,020,167,085
49158 5006,128,001,039,001,028/209 49344 5020,153, 001 ,079,006,128,067
49164 5001,000,001,244,001,072,075 49350 5001,135, 00 2 ,100,001,004,185
49170 5038,001,166,010,030,001,008 49356 5001,000, 001 ,188,001,072,211
49176 5024,155,024,156,020,157,048 49362 5038,001, 166 ,179,030,001,113
49182 5020,157,052,157,024,156,084 49368 5020,000, 012 ,165,112,161,174
49188 5020,155,016,153,030,002,156 49374 5030,002, 020 ,161,012,172,107
49194 5024,156,024,157,020,158,069 49380 ;112,161, 030 ,003,020,161,203
49200 5020,156,020,156,024,155,067 49386 5012,165, 1 1 2 ,161,030,004,206
49206 5024,156,020,157,020,155,074 49392 5020,161, 012 ,165,112,161,103
49212 5020,155,030,003,020,155,187 49398 5030,005, 0 2 0 ,161,012,172,134
49218 5020,154,020,154,020,154,076 49404 5112,161, 030 ,006,020,161,230
49224 5024,153,024,154,020,155,090 49410 5012,165, 1 1 2 ,161,030,007,233
49230 5020,153,020,153,030,004,202 49416 5020,161, 012 ,173,112,173,147
49236 5024,155,024,156,024,157,112 49422 5030,008, 076 ,173,020,173,238
49242 5024,158,024,157,024,158,123 49428 5016,161, 020 ,173,030,009,173
49248 5024,157,024,158,024,157,128 49434 5012,161, 00 1 ,079,006,128,157
49254 5024,156,020,155,020,153,118 49440 5001,039, 001 ,004,001,080,158
49260 5020,153,030,005,024,156,240 49446 5001,132, 001 ,008,038,001,219
49266 5024,157,020,158,020,156,137 49452 sl66,181, 030 ,001,001,070,237
49272 5020,156,024,155,024,156,143 49458 5054,002, 020 ,000,020,137,027
O s)
49278 5020,157,020,155,020,155,141 49464 5020,000, 020 ,137,024,137,138
On 49284 5030,006,020,155,020,154,005 49470 5024,137, 020 ,137,020,137,025
Chapter 10
49476 :020, 137 ,001 ,015,030,003,018 49662 5032,082,079,066,069,082,152
346
49482 5020,000, 0 2 0 ,137,024,137,156 49668 5084,032,072,073,071,071,151
49488 :024,137, 020 ,137,024,137,047 49674 5073,078,083,013,000,149,150
49494 5024,137, 024 ,137,024,137,057
49500 5024,137, 024 ,137,020,137,059
Chapter 10
347
Chapter 10
Chapter 10
348
Table 10-3* Sidplayer Instrument Parameters
P -S F -M A U T R ES FLT F -S F -C SN C RN G V D P V R T TP S DTN
I n s tr u m e n t A TK D C Y SU S R LS P N T W AV P -W
4 P 2048 0 0 0 N 0 N N 0 0 0
D E FA U LT 2 0 15 5
4 P 800 30 2 12
V IO L IN 0 0
4 4 P 2048 20 2 -1 2
CELLO 5 0 12
10 1 P 1800 L -1 0 9 Y -1 2
B A S S (plu ck ) 1 10 0
0 9 0 0 1 T LB -1 15 Y
HARP
1 8 0 0 1 P 100 B 3 12 Y 5
B A N JO
M A N D O L IN 1 8 0 0 1 P 500 H -2 0 12 Y
1 10 0 0 1 P 1000 H -2 0 12 Y 5
BAZOO KI
LUTE 0 8 0 0 1 T L -4 0 15 Y
0 8 0 0 1 P 300 L -1 0 15 Y 20
KOTO
2 10 12 12 7 P 100 10 H -2 0 15 Y 5
SITA R
FLU T E 3 0 14 4 1 T
3 0 14 4 1 T 12
P IC C O L O
R E C O R D E R — A LT O 3 0 14 4 1 T
C L A R IN E T 3 0 14 P 2048
O BO E 7 0 15 2 1 P 700 B -2 0 15 Y
7 8 14 4 1 P 700 B -2 0 15 Y -1 2
BASSO O N
2 0 15 5 1 P 200 70
B A G P IP E
5 0 8 4 4 P 2048 20 2
H A R M O N IC A
2 0 15 4 4 S 70
A C C O R D IO N
SH A W M 2 2 14 2 1 P 100 B 5 15 Y
TR U M PET 5 0 15 4 1 S L 20 15 Y 1
TRO M BO NE 9 0 15 4 1 S L 1 15 Y
TU BA 9 0 15 4 1 S L 10 15 Y
H A R P S IC H O R D 4 ' 0 12 8 9 8 P 100
H A R P S IC H O R D 8 ' 0 12 8 9 8 P 300
O R G A N : FL U T E 3 0 14 4 1 T
O R G A N : P R IN C IP A L 3 2 10 4 1 P 2048
O R G A N : R EE D 3 0 14 4 1 P 200
O RG A N : TRU M PET 3 0 15 4 1 S
C A L L IO P E 0 12 13 5 4 P 2048 12 70
FIN G E R D R U M 0 9 0 0 1 T
B ELLS 0 10 0 10 1 T Y 7 ,1 6
C H IM E S 0 10 0 10 16 P 2048 70
W O O D BLO CK 0 2 0 T
Chapter 10
Chapter 11
This subroutine loads the "SID.OBJ” file, and also assigns the
variables SS, HK, PL, and DP. These four variables are used
later in the program. If you're using tape, be sure to position
the tape to the spot where SID.OBJ begins. Disk users must
have the proper disk in the drive.
Before you can load a song into memory, the music file
name and the LOAD address must be set. Assign the name of
the music file to the variable F$ (line 200). Do not include the
.MUS extension as part of the filename.
F$= "COMMODORE"
Now calculate the LOAD address (line 200).
L A = PEEK(49)+ 256*PEEK(50)+1000
The LOAD address is the address of free memory, plus
1000 bytes for a safety margin. This is the address in memory
where the music file will be stored.
Call the subroutine at line 57500 to actually load the song
(line 200). Again, be sure the proper disk is in the drive or that
the tape is positioned properly. If you assigned F$ as above for a
demonstration, make sure that the "COMMODORE.MUS” file
is on that disk or tape.
GOSUB 57500
Besides loading the requested music file, the subroutine at
57500 also assigns the variables LO and HI to be the low and
high bytes of the LOAD address. These variables are used
later in the program.
At this point, everything has been loaded into memory.
There's still a little bit of preparation which must be done
before the playing can begin.
SYS HK
This statement (line 210) calls the Sidplayer HOOK rou
tine, which installs Sidplayer as part of the normal interrupt
processing that's done every 1/60 second.
POKE SX,LO:POKE SY,HI:SYS PL
The PLAY (SYS PL) routine tells Sidplayer where the
song begins in memory, and sets all the default values, such
as tempo and volume. It also returns the address of the text
lines in locations SX and SY. It's not necessary to print the text
lines in order to play the song, so the next two program lines
(lines 230 and 240) are optional. If you do want to print the
text lines, the program should start displaying characters at the
returned address and stop when it reaches a CHR$(0). -co
Chapter 11
354
Chapter 11
355
Chapter 11
356
Chapter 11
49164 1001,006,030,001,116,154,064
49170 :024,155,030,002,070,001,044
49176 :001,2 52,012,092,070,002,197
49182 :012,158,030,003,070,003,050
49188 :044,146,001,2 28,070,004,017
49194 :080,155,030,004,116,092,007
49200 :088,157,116,158,088,159,046
49206 :080,158,116,157,088,092,233
49212 :030,005,044,15 5,001,047,086
49218 :001,022,080,158,030,006,107
492 24 :070,005,116,159,088,081,079
49230 :080,146,080,081,080,159,192
49236 :030,007,076,158,012,157,012
49242 :001,047,030,008,116,092,128
49248 :088,155,116,154,088,157,086
49254 :080,092,116,155,088,154,019
49260 :030,009,044,154,001,094,184
49266 :080,084,030,010,070,000,132
49272 :080,147,080,146,084,081,226
49278 :084,146,080,147,030,011,112
49284 :076,158,012,157,030,012,065
49290 :080,092,084,157,084,092,215
49296 :080,155,080,154,030,013,144
49302 :044,158,080,147,030,014,111
49308 .-116,159,088,158,116,159,184
49314 :088,081,080,159,080,158,040
49320 :030,015,044,159,080,081,065
49326 :030,016,080,146,084,081,099
49332 :084,159,080,081,116,159,091
493 38 -.088,158,030,017,044,158,169
49344 :016,157,030,018,001,003,161
49350 :070,001,116,092,088,155,208
49356 s116,092,024,157,016,092,189
49362 :016,155,030,019,001,003,178
49368 :012,157,012,092,030,020,027
49374 :001,003,016,159,016,158,063
49380 :016,157,016,092,030,021,048
49386 :001,003,044,155,001,174,100
49392 :016,158,030,022,070,000,024
49398 5116,159,088,081,016,146,084
49404 5016,081,016,159,030,023,065
49410 -.012,158,012,157,030,024,139
49416 5116,092,088,155,116,154,217
49422 5088,157,080,092,116,155,190
49428 5088,154,030,025,044,154,003
49434 5001,142,001,002,001,003,176
49440 5001,018,001,174,116,092,178
49446 5088,155,006,128,116,154,173
4945 2 s088,157,080,092,006,160,115
49458 sll6,155,088,154,044,154,249
357
Chapter 11
358
Chapter 11
359
Chapter 11
360
Chapter 11
361
Chapter 11
362
Chapter 11
363
Chapter 11
U tility P rogram s
Here are four utility programs to help with song debugging
and music file management. Although they may look similar
to those utilities offered in the bitmapped graphics and sprite
sections of this book, they are for use only with Sidplayer mu
sic files.
Each program, as listed, is set to work with the disk drive.
To make a program work with tape, find the statement DN = 8
near the beginning of the program and change it to DN = 1.
Lister. The bottom level of the editing screen can display
only a few notes at a time. Sometimes it would be helpful to
see more notes at one time. This would make it easier to
search for a particular note or command, such as a phrase
definition, and would also make it easier to find mistakes,
such as a measure with the wrong number of beats.
"Lister,” Program 11-4, is used to list the notes and com
mands of the three voices in a music file. Although the notes
are not displayed in the grand staff format, the program does
let you see one or two full measures at a time when the listing
is shown on the screen. The listing can also be sent to a
printer for permanent reference.
364
Chapter 11
366
Chapter 11
367
Chapter 11
skip voice 1 or voice 2. Enter the number of the first voice you
want to list, or just press the RETURN key to start at voice 1.
The program loads the requested file and begins the listing.
Each note is listed by its name, accidental, octave number,
and duration.
C S 4 Q (C sharp, octave 4, quarter note)
The first letter specifies the note name, and can be a letter
A through G or the letter R for rest. If the note is sharp or flat,
S or F is displayed after the note name. The octave number,
0-7, comes next, followed by a letter for the duration. The
duration can be W, H, Q, E, S, T, or U. Respectively, these let
ters stand for whole, half, quarter, eighth, sixteenth, and
thirty-second notes. U represents the utility duration.
If the note is dotted, a D shows after the duration. If the
note is tied, the note listing ends with a T.
C S 4 Q D T (C sharp, octave 4, quarter note, dotted, and tied)
Commands are listed with their full names. If a command
has a data value, such as a number or yes/no indication, the
value is placed after the command name.
TEMPO 90
WAVEFORM T
Measure numbers are displayed at the left edge of the list
ing, separate from the notes and commands. This makes it
easy to find a particular measure. At the end of each measure,
the total jiffy count for that measure is printed. This number is
affected by the tempo and the time signature. For example,
COMMODORE.MUS is written in 4 /4 time and is played in
M.M. 90. If you refer to Table 9-1, four beats at tempo 90 give
a total of 160 jiffies. That's why the measure duration for each
measure in COMMODORE.MUS is 160 jiffies.
If you're listing a song and one of the measures has a dif
ferent jiffy count from the others, it could be an indication that
the measure doesn't have the correct total number of beats.
Either a duration is wrong, a note is missing, or there's an ex
tra note.
The measure duration feature won't work properly when
repeats or phrases are used. Also, the total number of jiffies
for a measure may change from one voice to another if the
TEM command is not used on each voice.
368
Chapter 11
If the listing goes by too fast, you can make the screen
scroll slower by pressing the CTRL key. If that's still too fast,
or if you want to stop the listing, just hit the RUN/STOP key.
Enter CONT to make the listing continue.
To send the listing to the printer, enter 4 in response to
the OUTPUT DEVICE prompt. Make sure that the printer is
connected and turned on.
If you have an RS-232 printer instead of a parallel printer,
you may have to change the OPEN statement in line 805 of
the Lister.
Merge. The Editor has a limited amount of memory avail
able for editing a song. Some songs may be just too long for it
to handle. The solution is to edit the song in sections, and
then merge the sections together.
“Merge," Program 11-5, is used to combine two or more
music files into one larger file. This file can then be played by
the Player. Another use of Merge is to copy a music file from
one tape to another tape or from one disk to another disk. The
program can also be used to transfer a song from tape to disk.
Tape users must change line 120 so that DN = 1.
369
Chapter 11
370
Chapter 11
371
Chapter 11
372
Chapter 11
When you run the program, the first prompt asks for the
name of the file to load. After you enter the filename, the pro
gram loads the song.
The program requests a starting measure number. Type
the number of the first measure that should be extracted. If
you want the extraction to start at the beginning of the file in
stead of at a later measure, just press RETURN.
When prompted for the ending measure number, type the
number of the measure at which the extraction should stop.
For example, if you want to extract measures 26 through 50
inclusive, the ending measure should be 51. Press RETURN by
itself if you want the extraction to go to the end of the voice.
The program displays the message PROCESSING VOICE
1 while it searches for the starting measure marker. If the
measure marker is not found in the voice, the program stops
with the message ERROR:STARTING MEASURE NOT
FOUND.
Having found the starting measure marker, the program
continues to search until it comes to the ending measure
marker or the end of the voice. If the searching reaches the
end of the voice, the program prints the warning NOTE:RAN
TO END OF VOICE.
The program repeats this procedure for voices 2 and 3.
Finally, the program asks for the filename to use in saving
the new music file.
One use of the Extract program is to break a large music
file into parts. Another application is to copy a sequence of
notes in a song to the end of the song. For example, a song
may repeat a chorus, but the chorus might be played a little
differently the second time. Repeats or phrases cannot be used
if there are minor changes when the notes are repeated. In
stead of entering all the notes in the chorus again, just extract
the notes which form the chorus, use Merge to merge them to
the end of the song, and make the necessary changes.
373
Chapter 11
374
Chapter 11
375
Chapter 11
376
Part 4
Sprite
Control
System
Chapter 12
So far, you've seen utilities that let you access the Commodore
64's excellent bitmapping and sound capabilities. There's one
more area to cover. One of the most widely used features of
your computer is sprites, the movable object blocks of the 64.
Games especially make wide use of sprites.
This last part of this book deals with sprites and sprite
animation. In the pages which follow, you'll see how easy it
can be to define a sprite and make it move across the screen.
Just as you were provided with utilities to help you use
the bitmap screen and create sophisticated sound, so you'll
have a Sprite Editor at your disposal. The Editor lets you use
the joystick to create sprite definitions. You'll also find several
machine language routines you can use to make it easier to
move the sprites you create. You'll be able to get up to eight
sprites moving at the same time, each with its own shape,
color, size, direction, and speed. Best of all, you'll be able to
do all of this from a BASIC program, without using a single
POKE!
Before you see how to define and animate sprites, how
ever, it's important to understand the basic characteristics of
animation, and the advantages of sprite graphics over charac
ter and bitmapped graphics.
Principles of Animation
There are two ways in which an object can be animated. The
object can change its position or it can change its appearance.
Motion, which occurs when the position of an object is
changing, is probably the more common type of animation.
Two important characteristics of a moving object are its direc
tion and its speed.
But an object can be animated even when it's not moving,
simply by changing its appearance in some way. This can be
done by altering the shape of the object, but it can also be
done by changing its color or size.
To create effective animation on the Commodore 64, you
379
Chapter 12
Character Graphics
There are many reasons why it's preferable not to use charac
ter graphics for animation. New character shapes can be cre
ated by redefining the character set, but each character is
always limited to an 8 X 8 grid. This size is often too small to
be useful.
Another problem is in motion. A character can be moved
to another place on the screen by just a couple of POKE state
ments, but the positioning is limited to 40 columns X 25
rows, so motion appears jerky.
Bigger shapes can be created by using several characters,
but motion is then more difficult because each character
comprising the large figure has to be moved.
Thus, for many applications, character graphics are simply
unsuitable for animation.
Bitmapped Graphics
With bitmapped graphics, there are no size or positioning
restrictions. A shape of any size can be drawn, starting at any
of 64,000 (320 X 200) positions. Sometimes these shapes can
be redrawn fast enough so that they appear to change shape.
(Refer back to the shape demonstrations in Part 2 for a few
examples.)
The only drawback to using bitmapped graphics is that
motion is impossible in BASIC. Moving an object means eras
ing each point in the shape and replotting it at an adjacent po
sition. Bitmapped graphics shapes usually contain too many
points to be erased and redrawn quickly. If a shape is moved
like this, it moves very slowly, with considerable flicker.
These problems are magnified when you want the shape
to move without disturbing other things already on the screen.
For instance, you may want to make a figure walk in front of
a building. As the points in the figure are plotted in new po
sitions, they may be placed in the same positions as points
used to display the building. Those points must be restored
after the figure has walked past. Motion is not as simple as
just plotting and erasing points. For each point, the original
contents must be remembered before the position is plotted so
that the contents can later be restored.
380
Chapter 12
Sprite Graphics
This graphics system combines the best features of character
and bitmapped graphics. A sprite is a super character, because
it can be defined on a grid of 24 X 21 points, about the size
of eight characters. This size is large enough to create detailed
shapes. Positioning is allowed on any of the 320 X 200
points, so a sprite can be placed anywhere on the screen. It
also means sprite motion is smooth.
The best feature, however, is that the sprite definition is
stored in memory separate from screen memory. This means
you can use sprites at the same time as character graphics or
bitmapped graphics. Also, the screen memory is not changed
when the sprite is moved, so the background does not have to
be restored.
The fact that a sprite is completely independent of the
screen greatly simplifies its display and movement. Only three
POKE statements are needed to move a whole sprite. Just one
changes its shape, size, or color.
If this were all the Commodore 64 did, it would be an ex
cellent system. What makes it even better is that the 64 sup
ports up to eight sprites. Each sprite can have its own shape,
color, size, and position. Other features, such as multicolor
mode and priority, will be discussed later.
381
Chapter 12
382
Chapter 12
384
To enter this program, you must use "The Machine Language 49832 5002,096, 032 ,253,174,032,245
Editor (MIX)," a program found in Appendix C.
49838 5138,173, 032 ,155,188,165,001
49844 5101,164, 100 ,166,002,096,041
49664 s076,012,195,076,177,195,219
Chapter 12
50378 5194,013,088,194,141,088,152
50384 :194,096 032 , 1 6 0 , 1 9 4 , 1 6 8 , 0 2 8 50570 :101,020, 1 6 8 ,104,153,100,016
386
50390 :240,022 201 , 0 0 3 , 1 7 6 , 0 5 8 , 1 4 6 50576 :003,096, 0 3 2 ,160,194,168,029
50396 :009,001 133 , 0 2 0 , 0 3 2 , 1 2 1 , 0 2 4 50582 :240,017, 1 3 6 ,136,152,041,104
50402 : 0 0 0 , 240 011 , 0 3 2 , 1 7 0 , 1 9 4 , 1 0 5 50588 :007,009 ,1 2 8 ,157,116,003,064
Chapter 12
387
50936 :042,133, 2 5 4 51122 2255,032, 170 ,194,133,251,189
Chapter 12
,165,253,153,224
51128 :132,252, 056 , 233,012 f133 #234
388
51134 :253,152, 233 ,195,133,254,130
51140 s160,081, 185 ,254,193,024,069
51146 s101, 253, 153 ,254,193,185,061
Chapter 12
389
Chapter 12
Program 1 2-3. D E M O #l
For error-free program entry, be sure to use "The Automatic Proofreader," Appendix D.
391
Chapter 12
Now type in and save the sprite definition file. It's in ma
chine language, so you'll need MLX to enter it. These are the
responses you need to give:
Starting Address: 49152
Ending Address: 49217
Filename: BUNNY.DEF
Make sure the filename is BUNNY.DEF, or the "D E M O #l''
program will not be able to load it properly. If you're using
disk’, place this on the same disk as the previous two pro
grams. If you're using tape, make sure BUNNY.DEF follows
D EM O #l.
Load and run DEM O #l. If you're using disk, the SCS.OBJ
and BUNNY.DEF files are automatically loaded. All eight
sprites then appear on the screen.
However, if you're using the Datassette, you'll have to do
some tape switching. Once DEM O#l is run, you'll see the
prompt POSITION TAPE TO THE BEGINNING OF SCS.OBJ
AND PRESS RETURN. Take the tape containing DEM O#l out
of the Datassette and insert the tape you made earlier which
has SCS.OBJ on it. (Make sure this second tape is rewound to
the beginning of the SCS.OBJ file.) Press RETURN, then the
PLAY button on the recorder. The machine language file will
load. Once it's finished, you'll see another prompt, this time
POSITION TAPE TO THE BEGINNING OF BUNNY AND
PRESS RETURN. Insert the first tape (don't rewind it— leave it
where it ended after loading DEM O#l). Press RETURN, and
then PLAY. The machine language sprite definition file now
loads. When that's completed, you'll see the eight sprites
392
Chapter 12
Getting Fancy
The second example demonstrates some of the more advanced
features of the Sprite Control System. Enter the following pro
gram and save it with the filename DEMO#2. Again, if you're
using tape, change line 120 so that DN = 1.
396
To enter this program, you must use "The Machine Language 49326 :000,000, 001 ,255,128,007,053
Editor (MLX)," a program found in Appendix C. 49332 5255,224, 015 ,255,240,031,176
49152 :011 ,054,000,000 ,000,000,065 49338 5255,248, 063 ,255,252,061,040
Chapter 12
397
49686
Chapter 12
Hi, Guy
This final program demonstrates a few other features of the
Sprite Control System. Enter Program 12-7 and save it with
the filename DEMO#3. Remember to change the value of DN
in line 120 to 1 if you're using the Datassette.
398
Chapter 12
399
Chapter 12
49152 s001,063,000,085,000,000,149
49158 :085,000,001,085,064,001,242
49164 s255,064,001,255,064,003,142
49170 s060,192,003,255,192,000,208
49176 :195,000,000,255,000,000,218
49182 5060,000,002,170,128,010,144
49188 :170,160,042,170,168,042,020
49194 s170,168,040,170,040,040,158
49200 s170,040,040,170,040,040,036
49206 s170,040,040,170,040,040,042
49212 :170,040,060,170,060,048,096
49218 :060,085,060,002,170,128,059
49224 s002,170,128,002,170,128,160
49230 5002,170,128,002,170,128,166
49236 5002,130,128,002,130,128,092
49242 5002,130,128,002,130,128,098
400
Chapter 12
49248 5002,130,128,002,130,128,104
49254 5002,130,128,003,195,192,240
49260 5015,195,240,063,195,252,044
Loading from tape is identical to the previous two exam
ples. Make sure you have the tape with the SCS.OBJ file
handy.
A joystick plugged into port 2 controls the figure on the
left. The figure actually consists of two sprites, one above the
other. The sprites are synchronized so that they move together
to create the appearance of one large object.
Also notice that the figure doesn't stop moving when you
stop pushing the joystick. Instead, it keeps moving in the cur
rent direction. Another feature is that only four directions are
allowed. The joystick is ignored when it's pushed in a diag
onal direction.
To make the other guy move, plug the joystick into port
1. The Sprite Control System can control sprites through either
joystick port, or even both at the same time. This second fig
ure does not wrap around the screen, but simply rebounds off
the edges.
One other feature demonstrated by this program is the
foreground/background priority feature. The first figure (ini
tially on the left) moves in front of the drawing on the screen,
while the second moves behind the drawing.
Press the joystick button to end this program.
These three demonstration programs have illustrated
many of the things possible with the Sprite Control System.
But this has been only an introduction. The next chapters will
show you how to design your own sprites using the Sprite
Editor, how to use the Sprite Control System in your own
BASIC programs, how to control sprites with joysticks, how to
automatically change their shapes, even how to detect sprite-
to-sprite collisions. You've just started. But as promised, you'll
find the Control System simple to use, easy to learn, and a
tremendous aid when it comes to anything dealing with
sprites.
401
Chapter 13
You've just seen how the Sprite Control System can quickly
and easily move and animate sprites on your Commodore 64's
screen. But before you can use the Control System, you have
to have some sprites. "The Sprite Editor" is a utility which
helps you design and create sprites, without the tedious task
of plotting on graph paper, counting up bit values, or even
retyping the sprite definition into the computer. The Editor
does all this for you. With this program and a joystick, it's
easy, even fun, to design sprite shapes.
Here's the listing for the Sprite Editor. Remember to
change DN = 8 in line 110 to D N = 1 if you're using tape.
403
Chapter 13
404
Chapter 13
405
Chapter 13
406
Chapter 13
407
Chapter 13
408
Chapter 13
409
Chapter 13
Joystick Editing
The cursor is displayed in the grid as a small box with thick
edges. Push the joystick in any of the eight directions to move
the cursor from one grid square to another. If you move the
cursor off one side of the grid, it wraps around to the other
side.
Press the joystick button to fill a square. To fill an area or
draw a line, hold down the button while you push the joy
stick. Erasing is just as simple; move the cursor to the desired
square and press the button again. If you hold the button
down and move the cursor over filled areas, you can erase en
tire sections.
As you edit on the large grid, you'll notice that the shape
is displayed as an actual sprite in the black square at the top-
right corner of the screen. This can give you an idea of what
the sprite will look like in a BASIC program.
The remainder of this chapter explains each of the Sprite
Editor's features and commands. As you read, try them out
with a shape you've drawn on the editing grid.
Scrolling. Use the cursor keys (along with the SHIFT key
to move up or left) to scroll the shape in any of four
directions.
Insert. Sometimes it's necessary to expand or contract a
sprite definition. To expand it, move the cursor to the row
where you want the expansion to occur and press the SHIFT
and INST/DEL keys at the same time. The row on which the
cursor is positioned, and all the rows below it, will scroll
down one row to create a gap. The bottom row will scroll off
the grid and will not be recoverable.
Delete. This contracts a sprite definition. Press the DEL
key (unSHIFTed INST/DEL) to delete the row on which the
cursor is currently positioned. All the rows below the cursor
will scroll up one row to fill in the gap.
Erase. To clear the editing grid, press SHIFT-CLR/HOME
and then hit the Y key in response to the ERASE? prompt. If
you accidentally hit SHIFT-CLR/HOME, press the N key to
cancel the clear.
Change color. You can change the color of the sprite at
any time. This color, however, does not necessarily have to be
the same color that will be used to display the sprite in
BASIC.
To change the current color, press the f2 key (SHIFT and
fl together). When the prompt ENTER COLOR: appears, type
a color number from 0 to 15. The color numbers are listed in
the Commodore 64 User's Guide. The color changes as soon as
you press the RETURN key. Notice that the color changes in
both the editing grid and in the shape box in the upper-right
corner.
If you decide not to change the color, just press the RE
TURN key without entering a number. The color will not be
changed.
You can also change the background color of the box in
the upper right. Press the f8 key (SHIFT and f7 keys) and en
ter the number of the desired color. This feature shows you
how a sprite will look on different background colors.
To set the box background back to black, press the f8 key
and enter 0.
Width and Height. Press the W key to make the sprite
shown in the upper right alternate between normal and double
width. Press the H key to alternate the sprite between normal
and double height. You can use these keys in combination to
411
Chapter 13
413
Chapter 13
414
Chapter 13
415
Chapter 13
416
Chapter 13
417
Chapter 13
418
Chapter 14
Sophisticated
The Sprite Control System, sophisticated as it is, requires you
to follow a very specific procedure when you use it with a
BASIC program. Because of the Control System's power, this
may seem complicated at first. It can be a bit involved. But
with some practice, you'll soon find it second nature.
This procedure consists of calling two subroutines in
BASIC and using several SYS statements. To help you learn
this procedure, we'll go through it step by step in the immedi
ate mode (without using line numbers). As you become more
familiar with them, the steps will seem both simple and
logical.
419
Chapter 14
Variable Assignments
The first step is to perform the standard assignments that have
been used throughout this book in preparation for SYS calls
and disk and tape file input/output (I/O). Enter the following
statement. As always, change the DN = 8 to DN = 1 if you're
using the Datassette.
DN= 8:SA = 780:SX= 781:SY= 782:SP=783
Load Definitions
You also need to load a definition file. For this demonstration,
use the bunny definition from Chapter 12. To load the defi
nition file, you must assign the filename to a string variable,
specify a LOAD address, and call a subroutine.
Assign the name of the definition file to the variable F$.
Do not include the .DEF extension as part of the filename.
Assuming that you called the file BUNNY, you'd type:
F $="B U N N Y "
420
Chapter 14
Define Block
To make a sprite appear, you have to give it a shape. Unfortu
nately, it's not possible to directly assign one of the definitions
loaded from the definition file to a sprite. Instead, you have to
copy a definition into a definition block, and then assign the
definition block to the sprite.
421
Chapter 14
422
Chapter 14
423
Chapter 14
()
n ^ x - <1-10
I S >9
_______________________________________
319,199
424
Chapter 14
426
Chapter 14
SYS MO,0,7,7
It's almost out of control!
A delta value of 0 prevents a sprite from moving in the
corresponding direction. Let's try it out. The next statement
sets the delta Y value at 0, so the sprite never moves verti
cally, no matter which direction number is used. All the sprite
does is bounce back and forth across the screen.
SYS MO,0,3,0
Slow the sprite down by typing:
SYS MO,0,1,1
This is pretty slow, but for some applications this speed
may still not be slow enough. To make the speed even slower,
add a ,1 to the end of the SYS MO statement. This selects the
half-speed option.
SYS MO,0,1,1,1
When the half-speed option is in effect, a sprite moves
every other frame. For the best results, use this option only
with delta X and delta Y set to 1. Motion appears too jerky
when other delta values are used.
To return to normal speed, either remove the ,2 or change
it to 0.
SYS MO,0,1,1
or
SYS MO,0,1,1,0
Though it might be easier to remember the variable name
SP (for SPeed), that variable is already used for tape and disk
I/O SYS calls. The variable name MO, representing MOtion,
is used instead.
428
Chapter 14
Review
Here's a quick review of the whole procedure. You might find
this checklist useful as a reminder once you're actually trying
to place the SYS calls in your own program.
1. Make sure the lines from the SCS.BAS file (Program 12-1)
are included as part of your BASIC program.
2. Assign variables and load the SCS.OBJ file and a definition
file.
429
Chapter 14
Errors
Some errors in SYS calls are detected. If you forget one of the
required parameters, BASIC will report a SYNTAX ERROR.
This also occurs if you try to use SYS DF before loading a
definition file.
The ILLEGAL QUANTITY error may occur when a value
is out of range. Using a sprite number out of the range 0 -7 is
one way of causing this error.
Multiple Sprites
Now that you've seen how to animate one sprite, let's see how
easy it is to animate several.
430
Chapter 14
431
Chapter 15
434
Chapter 15
Base+ 3 Down
Base + 4 Up and left
Base+ 5 Up and right
Base + 6 Down and left
Base+ 7 Down and right
The number of the first block being used is called the
Base, so if blocks 240-247 are being used, block 240 must con
tain the definition for left, block 241 must contain the defi
nition for right, and so on.
To turn on the autoshape feature, use the following state
ment format (in program or immediate mode).
SYS AV,SN,direction code,base block number
Direction code specifies whether two, four, or eight direc
tions are to be supported. The values 2, 4, or 8 indicate the
number. In the example above, eight directions are supported,
and the base block number is 240, so the SYS statement
would look like this:
SYS AU,SN,8,240
The sprite shape will now automatically change to reflect
the direction in which it's moving.
The autoshape feature does not always have to work with
all eight directions. Only two directions, left and right, may be
supported. The direction code for this is 2, and the order in
which the blocks must be defined is:
Block Definition Direction
Base + 0 Left
Base+1 Right
To enable the autoshape feature using only these two
directions (and assuming the Base is still block definition 240),
you'd enter:
SYS AU,SN,2,240
Now, whenever the sprite moves in a leftward direction,
whether it's left, up and left, or down and left, the shape for
left displays. The shape for right appears when the sprite
moves rightward. If the sprite moves straight up or down, the
shape does not change from its previous shape.
To support only the four cardinal directions, use 4 for the
direction code and define the blocks like this:
435
Chapter 15
436
Chapter 15
Multicolor Mode
When a sprite is displayed in multicolor mode, it can consist
of three different colors. The trade-off is that the sprite's hori
zontal resolution is reduced from 24 to 12 pixels. (For help in
creating multicolored sprites, take a look at the Sprite Editor in
Chapter 13.)
To turn the multicolor mode on or off, use these
statements:
SYS MU,SN,0 Turn off multicolor mode (default)
SYS MU,SN,1 Turn on multicolor mode
The sprite's main color, the one displayed when the
multicolor mode is turned off, is used as the first of the three
colors. To set the additional colors, use the following variation
of the SYS CO format:
SYS CO,SN,first color,second color,third color
Any combination of sprites may select the multicolor
mode. When two or more are displayed in multicolor mode,
however, there's one restriction. All sprites in multicolor mode
must share the same second and third colors. If you change the
second and third colors on one sprite, those colors will change
on all the other sprites displayed in multicolor mode.
Each sprite has its own default color, the color which it
shows if it's not changed.
Sprite Color
0 1 (White)
1 2 (Red)
2 3 (Cyan)
3 4 (Purple)
4 5 (Green)
5 6 (Blue)
6 7 (Yellow)
7 12 (Medium Gray)
When in multicolor mode, the second and third colors
also have default settings. Normally, the second color is 4
(purple) and the third color is 0 (black).
Priority
Sprites are completely independent of the normal screen dis
play, and except for sharing colors in multicolor mode, they're
independent of each other. This independence is handy, be
cause it lets you use several sprites on one screen, and it lets
437
Chapter 15
Joystick Control
Up to now, the direction of a moving sprite has been set in the
immediate mode or in a program by the SYS DI call. With the
Sprite Control System, a sprite's motion can also be controlled
by a joystick. This is the general form of the statement to
switch from program control to joystick control.
SYS JS,SNjoystick port number
Thus, to make sprite 0 move under control of a joystick
plugged into port 2, you'd use:
438
Chapter 15
SYS JS,0,2
Sprite 0 now moves in the same direction that the joystick
is pushed. The sprite will not move when the joystick is not
being pushed.
Speed. When a sprite is being moved by a joystick, its
speed is still controlled by the delta values. The following
statement makes sprite 0 move very quickly whenever the joy
stick is pushed.
SYS MO,0,5,5
For slow movement, use this statement.
SYS MO,0,1,1
In other words, simply use the usual SYS MO call, as you
did earlier for setting sprite speed under program control.
Note that you don't have to set the speed with a SYS MO,
since the default values are 2 for delta X and 1 for delta Y.
However, if you want a different speed, do use the SYS MO.
Limiting directions. If you want a sprite to move in only
two directions, set one of the delta values to 0. In this line, the
delta Y value is 0, so sprite 0 won't move up or down even
when the joystick is pushed in those directions.
SYS MO,0,3,0
How about limiting the sprite's movement to up and
down? It's just as simple— set the delta X value to 0, as in:
SYS MO,0,0,3
(Reset the delta X value by entering SYS MO,0,2,1 before go
ing on.)
To limit a sprite's movements to just the four cardinal
directions, you can use a special option of the SYS JS call. If a
,1 is added to the end of the call, the diagonal directions of the
joystick will be ignored. This is what the format should look
like:
SYS ]S,SN,joystick number,1 (Allows only four directions)
An interesting effect is to force the sprite to continue to
move, even when the joystick isn't being pushed. With the
Sprite Control System, this effect is just a matter of adding ,2
to the end of the SYS JS call. When this is used, the sprite will
keep moving in the last direction the joystick was pushed. It's
sort of a ''momentum'' effect.
SYS JS,SN,joystick number,2 (Turn on momentum)
439
Chapter 15
Chase Mode
One more way to make a sprite move is to have it chase after
another sprite. The Sprite Control System includes a SYS call
format which allows you to do this. It looks like:
440
Chapter 15
441
Chapter 15
Sprite Number
0 1
1 2
2 4
3 8
4 16
5 32
6 64
7 128
Freezing sprites 2 and 3 requires this line:
SYS FR ,4+8
or
SYS FR,12
Once the motion of these sprites is stopped, any values,
such as position, direction, and speed, can be set without the
sprites going anywhere. After the desired values have been
set, the sprites can be unfrozen with:
SYS UN,sprite number total
To unfreeze sprites 2 and 3, you'd use:
SYS UN,12
Both sprites will now start moving, with the new motion val
ues in effect.
This feature helps you get sprites traveling together, but if
you want several sprites to move side by side, a couple of
other things must be done. First, the boundaries for the dif
ferent sprites must be set differently. Let's say you want two
sprites to move together. One displays the left half of an ob
ject, the other displays the right half. Each sprite is defined as
a full 24 pixels wide. Here are the left and right boundaries
that should be used.
Left sprite
Left boundary: 0
Right boundary: 319 —24 —24
Right sprite
Left boundary: 0 + 24
Right boundary: 3 1 9 —24
All these boundary settings do is limit the movement of
each sprite. The leftmost sprite can go all the way to the left
edge, but it can only move as far right as position 271. It's
442
Chapter 15
Enable /Disable
The display of a sprite can be turned off or on.
SYS EN,SN,0 Disable (default)
SYS EN,SN,1 Enable
When a sprite is disabled, it can continue to move, change
shape, and so on. It just isn't displayed.
All sprites are initially disabled. The SYS BL call enables a
sprite when it assigns a block number.
Disabling a sprite is an easy way (even easier than placing
the sprite off the screen) to make a sprite disappear. Other
than that, this SYS call has very few uses.
443
Chapter 16
Miscellaneous Topics
T h e Merge Utility
Once in a while you may want to add the definitions in one
file to those in another. Program 16-1, "Merge," lets you com
bine two or more sprite definition files to create one larger file.
It's simple to use and can save you considerable redefining.
With Merge, you can combine as many definition files (which
you create with the Sprite Editor) as you want.
As with almost all other programs in this book, make sure
you change the DN = 8 to DN = 1 if you're using tape. That
variable value is assigned in line 110.
445
Chapter 16
When you run this program, it first asks for the name of a
file to load. Enter the name of the first file (you don't have to
type in the .DEF suffix placed on the end of the filename by
the Editor) and wait a few moments.
Next, you'll need to enter the name of the file to be ap
pended to the end of the file just loaded. After you type in the
name of the second file, it loads, then is added to the end of
the first file. Merge requests the name of another file to ap
pend. You can combine several if necessary.
When you're through appending files, just press RETURN
instead of entering another filename. The program asks for
one last filename— the one used to name the composite file.
After that's typed in, the merged definitions are saved to tape
or disk as a new file.
You can even use Merge as a quick and easy way to copy
a definition file from disk to disk or tape to tape. Just run
446
Chapter 16
447
Chapter 16
Once you run Extract, you're asked for the name of the
file which contains the definitions to be extracted. Enter the
filename and wait for the file to load.
The next two prompts ask for the numbers of the first and
last definitions in the sequence that you want to pull out of
this file. Type in the appropriate numbers.
Finally, the program requests a filename to use in saving
the extracted definitions. After you enter the filename, the pro
gram saves the specified range of definitions as a new file. The
original file has not been changed, however. The definitions
you extracted are still there.
To completely break up a definition file, then, you have
to perform two extractions. If the original file contains defi
nitions 0-5, for instance, and you want two three-definition
files, first extract definitions 0-2, save those to a new filename,
then extract definitions 3-5, saving them out under a different
name. Then, if you want, you can scratch the original file from
disk or overwrite it on tape.
Chapter 16
Sprite-to-Sprite Collisions
In games it's often necessary to know when a sprite has col
lided with another sprite or some other screen data. There's an
easy way, using a PEEK and the AND operator, to tell if a
sprite has been involved in a collision.
Location 53278 is a hardware location in the VIC-II chip.
The eight bits in this location, one for each sprite, are nor
mally clear (0). When two sprites overlap, a collision is said to
occur, and the bits in location 53278 which correspond to the
colliding sprites are set to 1. The bits remain set even after the
sprites stop overlapping. To determine if a particular sprite has
been involved in a collision, all a BASIC program has to do is
PEEK location 53278 and examine the appropriate bit.
The general procedure is to PEEK the location, assign the
value to a variable, and then use the variable with the AND
operator and sprite numbers to check individual bits. Some
thing like this:
P=PEEK(53278):IF P AND N THEN sp rite was involved in
collision
The value for N, the bit value, is determined from the table
below. (This is the same table used for freezing and unfreez
ing sprites.)
Sprite Number
0 1
1 2
2 4
3 8
4 16
5 32
6 64
7 128
For example, the numbers which correspond to sprites 2
and 3 are 4 and 8, respectively.
100 P=PEEK(53278)
110 IF P AND 4 THEN sp rite 2 co llid ed
120 IF P AND 8 THEN sp rite 3 co llid ed
Actual program statements would be placed after each
THEN. In the example below, execution jumps to line 300 if
sprite 5 is involved in a collision.
100 P=PEEK(53278):IF P AND 32 THEN 300
449
Chapter 16
Sprite-to-Screen-Data Collisions
Location 53278 only reports sprite-to-sprite collisions, in
which one sprite hits one or more other sprites. To check if a
sprite has overlapped any screen data, such as characters or
bitmapped graphics, use the same technique with location 53279.
P=PEEK(53279):IF P AND N THEN sp rite hit screen data
To check, for example, if sprite 6 hit a character-drawn barrier,
use a line like the following.
P= PEEK(53279):IF P AND 64 THEN 500
As with priority, the multicolor bit pair 01 is a special
exception. No collision is detected when a sprite overlaps any
thing displayed by the bit pair 01 in character or bitmapped
graphics mode.
450
Chapter 16
451
Chapter 16
Run the program and you'll see the same end result. No
tice, however, that if you're using tape, you have to load only
one additional file, “SCS.OBJ," not two as you did before.
Reading definitions from DATA is especially efficient when
you have to use tape.
When using this method, be careful if the program con
tains DATA statements for other purposes.
One drawback to using this method is that DATA state
ments make a program grow quickly. For large definition files,
then, this method is impractical.
454
Chapter 16
455
Chapter 16
To use bank 3:
• Define a character set at location 53248 if one is needed.
• Follow the standard procedure to use the Sprite Control Sys
tem, but insert the statement SYS RL,200 before SYS IN to
relocate screen memory.
• At the end of the program (after SYS RE), use SYS RS to re
set the screen.
Bank 1 supports the most blocks, from INT((LA—16384)/
64) + 1 6 to 207, but like bank 3, it does not contain a character
set.
To use bank 1:
• Define a character set at location 30720 if one is necessary.
• Follow the standard procedure, but perform a SYS RL,116
before SYS IN.
• Use SYS RS after SYS RE at the end of the program.
Whenever any of these three banks is used, the LOAD ad
dress is no longer set as L A = 16384, but is calculated by the
formula:
LA= PEEK(49)+ 256*PEEK(50) +1000
If the screen has been relocated to one bank and you
want to place it back in bank 0, just use SYS RL,4. Be sure
that the Sprite Control System is not installed when you do
this.
456
Chapter 16
sign the LOAD address and call the subroutine at 58100, in
stead of calling the subroutine at 58000. The subroutine at
58100 loads the SCS.OBJ file, moves it to free memory starting
at LA, and advances LA to point to the first byte of free mem
ory after the SCS.OBJ file. The line in your BASIC program
might look like this:
130 LA=16384:GOSUB 58100
When you load the definitions, just set the filename and
call the subroutine at 58500. Do not reassign LA. The LOAD
address should be set only once.
140 F$="BUNNY":GOSUB 58500
457
Chapter 16
458
Chapter 16
560 ...
570 SYS RE:REM REMOVE SPRITE CONTROL SYSTEM
580 SYS RSsREM RESET SCREEN
590 END
459
Chapter 16
460
Chapter 16
461
Chapter 16
58040 TB=49712:BB=49715:FR=49718:UN=49721sPR=49724
:MU=49727:EN=49730:JS=49733 :rem 149
58050 AU=49736:CH=49739sRETURN :rem 14
58100 GOSUB 58000:SYS 51123,LA:LA=LA+1191:RETURN
:rem 11
58400 POKE 49749,LA-256*INT(LA/256)sPOKE 49750,INT
(LA/256) srem 182
58410 READ J :POKE 49751,JsFOR K=0 TO J :READ JsPOKE
LA,J:LA=LA+1 srem 16
58420 IF J THEN FOR LA=LA TO LA+J-1s READ IsPOKE LA
,IsNEXT LA srem 92
58430 NEXT KsRETURN srem 168
58500 POKE SA,1 sPOKE SX,DNsPOKE SY,0sSYS 65466sF$=
F$+".DEF"sGOSUB 59000 srem 24
58510 POKE SA,0 sPOKE SX,LA-256*INT(LA/256)sPOKE SY
,INT/LA/256) srem 78
58520 SYS 65493sIF PEEK(SP)AND1 GOTO 59100 srem 44
58530 LA=LA+1sPOKE 49749,LA-256*INT(LA/256)sPOKE 4
9750,INT(LA/256) srem 167
58540 POKE 49751,PEEK(LA-l)sLA=PEEK(SX)+256*PEEK(S
Y)sRETURN srem 31
59000 FOR K=1 TO LEN(F$)sPOKE 584+K,ASC(MID$(F$,K)
)sNEXT srem 88
59010 POKE SA,LEN(F$)sPOKE SX,73sPOKE SY,2sSYS 654
6 9 sRETURN srem 6
59100 P=PEEK(SA)SPRINT " ERRORS ";sIF P=4 THEN PRI
NT "FILE NOT FOUND"sEND srem 200
59110 IF P=5 THEN PRINT "DEVICE NOT PRESENT"sEND
srem 36
59120 PRINT ST SEND srem 70
Final Comments
The Sprite Control System makes it possible to animate sprites
in ways that are otherwise not possible in BASIC. If applica
tions don't seem readily apparent, it's probably because you're
not used to having such capabilities available.
The two biggest areas of potential use are probably educa
tional programs and games. An effective use of animation can
greatly enhance educational software, and action games and
adventures are made more feasible by the Sprite Control
System.
462
Chapter 16
463
Chapter 16
JS (joystick) 438-40
LB (left boundary) 428-29
MO (speed and motion) 427-28
MU (multicolor) 437
PO (position) 423-25
PR (set priority) 437-38
RB (right boundary) 428-29
RE (remove) 429
RL (relocate screen memory) 453-54
RS (reset screen memory) 455
TB (top boundary) 428-29
UN (unfreeze) 442-43
WI (width) 423
WR (wraparound) 426-27
464
Appendix A
A Beginner’s Guide to
Typing In Programs
W hat 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. Many 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 the letter O for the nu
meral 0, a lowercase l for the numeral 1, or an uppercase B for
the numeral 8. Also, you must enter all punctuation, such as
colons and commas, just as it appears in the book. Spacing
can be important. To be safe, type in the listings exactly as
they appear.
467
Appendix A
A Quick Review
1. Type in the program, a line at a time, in order. Press RE
TURN 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.
468
Appendix B
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 control. 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
469
Appendix B
■ SK ER iigii ::n>nEisBin
{C L R }
{H O M E }
i
SH IFT
E
I [ C L R /H O M E
J L ...... ... J
I C L R /H O M E £ 3
£
£
1
^
1
1
COM M ODORE
COM M ODORE
[ 1
2
i ...... ......j
{U P } [ s h if t ]
□[ I C R SR 1 I £ 3 ^ COM M ODORE 3
{D O W N } J Ej f C R SR ] £ 4 1 COM M ODORE 4
{L E F T }
■
[ SH IFT ! [*«— C R SR — ►] £
sl CO M M O DO RE . 5
{R I G H T } < a — C R SR —► £
sl COM M ODORE 6
{R V S} CTRL
E 9
■
B
£
7l CO M M O DO RE 7
00
{O F F } CTRL 0 CO M M O DO RE 8
{B L K } CTRL
■ 1 t FI } fl
{W H T }
i
CTRL
m 2 { F2 } SH IFT fl
{R E D } CTRL
e |i 3 { F3 } f3
{C Y N }
l01111]L4 ] m { F4 } SH IFT f3
{P U R } [ j CTRL i 5 { F5 } f5
{G R N } [ j CTRL □ 6 ! F6 } SH IFT f5
{B L U } f ’' B
CTRL 7 i F7 } f7
{Y E L } [ CTRL m 8 { F8 } SH IFT f7
470
Appendix C
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 again, proofread, corrected a
few typing errors, ran again, crashed again, rechecked your
typing . . .
Frustrating, wasn't it?
Now, "M LX" comes to the rescue. MLX makes it easy 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, and it checks your typ
ing 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.
Using M LX
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,
471
Appendix C
run MLX. MLX will ask you for two numbers: the starting ad
dress and the ending address. Then you'll get a prompt show
ing the specified starting address; that tells you to type in the
corresponding first line of the program.
Subsequent prompts will ask you to type in subsequent
lines from the MLX 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 accept only numbers as input. If you make a
typing error, press the INST/DEL key; the entire number 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 automatically prints the comma and goes on to
accept the next number. If you enter less than three digits, you
can press either the space bar or RETURN key to advance to
the next number. The checksum automatically appears in
reverse video for emphasis.
To make it even easier to enter these numbers, MLX re
defines part of the keyboard as a numeric keypad (lines
581-584). The keypad can be used only to enter the data; you
must use the regular number keys to enter the starting and
ending addresses.
472
Appendix C
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, a full
disk, or a typo in MLX. 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 commands:
SHIFT-S: Save
SHIFT-L: Load
SHIFT-N: New Address
SHIFT-D: Display
Hold down SHIFT while you press the appropriate key.
You will 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. Remember what address you stop
on. Then, the next time you run MLX, answer all the prompts
as you did before and 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.
Tricky Stuff
You can use the Save and Load commands to make copies of
the complete machine language program. Use the Load
473
Appendix C
475
Appendix C
582 AV=-(A$="M")-2*(A$=",")-3*(A$=".")-4*(A$="J")-
5*(A$="K")-6*(A$ = "L") :rem 41
583 AV=AV-7*(A$="U")-8*(A$="I")-9*(A$="0"):IFA$="H
"THENA$="0" :rem 134
584 IFAV>0THENA$=CHR$(48+AV) :rem 134
585 PRINTCHR$(20);:A=ASC(A $ ):IFA=130RA=440RA=32THE
N670 :rem 229
590 IFA>128THENN=-AsRETURN srem 137
600 IFA< >20 THEN 630 srem 10
610 GOSUB690:IFI=1ANDT=44THENN=-1:PRINT"{OFF}
{LEFT} {LEFT}";:GOTO690 :rem 62
620 GOTO570 :rem 109
630 IFA<480RA> 57THEN580 :rem 105
640 PRINTA$;:N=N*10+A-48 :rem 106
650 IFN>255 THEN A=20:GOSUB1000:GOTO600 srem 229
660 Z=Z+1:IFZ<3THEN580 srem 71
670 IFZ=0THENGOSUB1000:GOTO570 srem 114
680 PRINT",";sRETURN srem 240
690 S%=PEEK(209)+256*PEEK(210)+PEEK(211) srem 149
691 F0RI=lT03sT=PEEK(S%-I) srem 67
695 IFT<>44ANDT<> 58THENPOKES%-1,32 sNEXT srem 205
700 P R I N T L E F T $ ( " { 3 L E F T } " , 1 - 1 ) ; sRETURN srem 7
710 P R I N T " { C L R } { R V S } * * * SAVE * * * { 3 DOWN}" s r e m 2 3 6
715 P R I N T " { 2 DOWN}(PRESS { RVS} RETURN{ O F F } ALONE TO
CANCEL SAVE) { DOWN} " srem 1 0 6
720 F$=""sINPUT"{D OW N} FILENAME"; F $ sIF F $= ""T H E N P R I
NTs P R I NT ; G O T O 3 1 0 sr e m 71
730 PRINT S PR I NT " { 2 D O W N } { R V S } T { O F F } A P E OR { R V S } D
{OFFjlSKs (T/D)" srem 228
740 GETA$ sIFA$ <>"T"ANDA$ <>"D"THEN7 40 srem 36
750 DV=1-7*(A$="D")sIFDV=8THENF$="0s"+F$sOPEN15,8,
15,"S"+F$ sCLOSE15 srem 212
760 T$=F$ sZK=PEEK(53)+256*PEEK(54)-LEN(T $ )sPOKE782
,ZK/256 srem 3
762 POKE781,ZK-PEEK(782)* 256 sPOKE780,LEN(T $ )sSYS65
469 srem 109
763 POKE780,1 sPOKE781 ,’DV s POKE782,0 sSYS65466 srem 68
765 K=Ss POKE254,K/2 56 sPOKE253,K-PEEK(2 54)* 2 56 sPOKE
780,253 srem 17
766 K=E+1s POKE782,K/2 56 sPOKE781,K-PEEK(782)*256 sSY
S65496 srem 235
770 IF(PEEK(783)AND1)OR(191ANDST)THEN780 srem 111
775 PRINT"{DOWN}DONE.{DOWN}"SGOTO310 srem 113
780 PRINT"{DOWN}ERROR ON SAVE.{2 SPACES}TRY AGAIN.
"sIFDV=lTHEN720 srem 171
781 OPEN15,8,15s INPUT#15,El$,E2$ sPRINTE1$;E2$ sCLOS
E15 SGOTO720 srem 103
790 PRINT"{CLR}{RVS}*** LOAD ***{2 DOWN}" srem 212
476
Appendix C
477
Appendix D
478
Appendix D
Hidden Perils
The Proofreader's home in memory is not a very safe haven.
Since the cassette buffer is wiped out during tape operations,
479
Appendix D
FORX=886TO1018:A$=A$+CHR$(PEEK{X )):NEXTX
OPEN1,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.
You now have a new version of the Proofreader. Turn
your computer off and on, then load the program you were
working on. Put the cassette containing the Proofreader into
the tape unit and type:
OPENl:CLOSEl
You can now start the Proofreader by typing SYS 886. To
test this, entering PRINT PEEK (886) should return the num
ber 173. If it does not, repeat the steps above, making sure
that A$ (“PROOFREADER.T") contains 13 characters and that
B$ contains 10 spaces.
You can now reload the Proofreader into memory when
ever the LOAD or SAVE command destroys it, restoring your
personal typing helper.
480
Appendix D
481
Appendix E
482
Appendix E
483
Appendix E
484
Appendix E
485
Index
ADR envelope. See envelopes, "BUNNY.DEF" 392
nonsustaining instructions for use 392-93
ADSR envelope. See envelopes, "CALLIOPE.M US" 326
sustaining chaining, definition of 82, 84
"ALBUMLEAF.MUS" 316-18 "C H D EM O l" 165-66
animation. See also Sprite Control System "C H D E M 02" 166
principles of 379-80 "CHSETA.SHP" 159-63
use of bitmapped graphics 380-81 CLOSE statement 42, 43-44, 45, 57
use of character graphics 380 syntax of 42, 45
use of sprite graphics 381 CMD statement
"ANTIMUNCH" 154 summary of 49-50
argument variable. See DEF statement syntax of 47
ATN functions 25, 26. See also transcen use of 47-48
dental functions coda. See repetition
attack 185-86 command number 39, 44, 59, 61-62
attack rate 282. See also envelopes with an RS-232 device 73, 79
"The Automatic Proofreader" 481 commands, use of in programs 81-83
instructions for use 478-80 summary of 83-84
"BASIC Doodle" 91 "COMMODORE.MUS" 196-200
"BISTRO.M US" 327-28 conditions, numerical values for 3 -6
bitmap, relocation of 170-74 summary of 6-8
bitmapped graphics 97, 106-22 CONT command 81
illustration of coordinate system 107 use of in program mode 81, 83-84.
mixing text and graphics 164-66 See also commands, use of in
multicolor modes 119—22 programs
POKE equivalents for graphics state conversion of mathematical formulas
ments 175-77 23-24
SYS equivalents for graphics state COS function 25, 26. See also transcen
ments 175-77 dental functions
Bitmapped Graphics Utility "COURANTE.MUS" 345-46
command 98 "Cross File Merge" 374-75
command index 181 explanation of 374-75
function 98, 168-70 cutoff frequency. See SID chip, filter
line drawing 112-15 controls
multicolor modes 119-22 da capo. See repetition
statements 98, 106-17, 123, 149, dal segno. See repetition
153-54, 164 decay 185-86
bit mask 85, 86, 88. See also WAIT decay rate 282. See also envelopes
statement DEF statement 27-32
"BLU ES" 265-66 purpose of a variable 28-29
"BMG Demonstration" 106 summary of 33-35
"BMGLOADER Disk Version" 99 syntax of 27-28, 33
"BMGLOADER Tape Version" 100 use of function calls 28-32
"BM G.OBJ" 100-05 "D E M O # l" 390-91
explanation of use 98-99 instructions for use 392
instructions for making copies 389 "D EM O #2" 393-95
"BRAID" 152 instructions for use 395
"BRAID.SHP" 152-53 "D EM O #3" 398-400
"BRA SS.M U S" 296-97 dense. See random function
"BROTHERHOOD" 127 DEVICE NOT PRESENT error 43, 45, 70.
buffer 71-73, 79. See also See also file input/output
telecommunications device number 39, 44, 59. See also OPEN
illustration of 72 statement, syntax of
487
with an RS-232 device 73, 79 FILE OPEN error 42, 45. See also file
"Directory Reader" 65 input/output
disk directory filters 290-91, 342. See also music theory
reading of 64-67, 70 illustrations of 291
use of wild cards 65-67, 70 "Flags" 118-19
disk drive commands 61, 62, 63. See also flats. See pitch
disk files floating-point variables 12, 13, 14, 15
disk files 58-71. See also sequential files frequency 185
program files (PRG) 67, 69, 70-71 "FSONATINA.MUS" 275-79
relative files (REL) 68, 69, 71 fundamental frequency. See filters
replacement of a file 62 GET# statement 64, 70
summary of 68-71 syntax of 64, 70
USR files 67, 69, 70 "GOBBLER.DEF" 396-97
dotted notes. See music theory, duration instructions for use 395
of notes grace notes. See music theory, duration of
double dots. See music theory, duration notes
of notes graphics character set, use with a printer
dynamics. See music theory, volume 48
"Editor" 226-45. See also Sidplayer 'GSONATINA.MUS" 279-81
Editor "GUY.DEF" 400-401
instructions for use 246 instructions for use 401
"EDITOR.OBJ" 247-48 half note. See music theory, duration of
instructions for making copies 389 notes
eighth note. See music theory, duration harmonics. See filters
of notes "HOLST.MUS" 339
envelopes 185-86, 282-83, 333, 338, IF-THEN statement 7
342. See also music theory simplification of 3
illustration of 282, 284 input 37, 38, 69
nonsustaining 283 statements 38
sustaining 283 summary of statements 44-45
"ETAL.MUS" 204-206 INPUT# statement 40-41, 44
EXP function 24-25, 26. See also syntax of 40, 44
transcendental functions I/O devices
syntax of 24 kinds of 37, 38, 51
exponent. See scientific notation identification numbers 39, 42-43, 57
"EXTRACT," Bitmapped Graphics 179 integer variables
explanation of 178-79 computation of 13-14, 15
"Extract," Sidplayer Editor 372-73 in FOR-NEXT loops 13, 15
explanation of 371-73 range of 12, 15
"Extract," Sprite Control System 447-48 summary of 14-15
explanation of 447 syntax of 12-14, 15
instructions for use 448 use of 11-14, 15
"FAMILY.SHP" 127-28 use of with negative numbers 12-13
file creation 38 use of with positive numbers 12
FILE DATA error 43, 44, 58. See also file "JOKE.MUS" 346-47
input/output "K.C.O.MUS" 319
file input/output 37-45, 57 "KOTO.MUS" 297
error messages 42, 43 LIST command. See also commands, use
filename 39 of in programs
FILE NOT OPEN error 43, 45. See also use of in program mode 81, 83
file input/output "Lister" 365-67
file number 39, 44, 59. See also OPEN explanation of 364, 367-69
statement, syntax of LOAD command. See also commands,
range of 48, 50 use of in programs
with an RS-232 device 73, 79 secondary address 81, 82, 84
488
syntax of 81-82, 84 dynamics 306-307
use of in program mode 81, 82 illustrations of grand staff 207, 210
LOG function. See also transcendental key 213-16, 226
functions key changes 307-308
syntax of 24 measures 219-20, 226
logical lines 19, 21 notation 206-207
machine language portamento 314-15, 342-43
explanation of 88-90 repetition 298-99
summary of 93-94 rests 221-22, 226
"Machine Language Doodle" 91-92 ring modulation 333-37
"The Machine Language Editor: MLX" slurs 223, 226
474-77 summary of 225-26
instructions for use 471-74 synchronization 324-25, 344
mantissa. See scientific notation tempo 220-21, 226
mathematical calculations, using BASIC tempo changes 305-306
limitations of 9 ties 222-23, 226
precision of 8 time signatures 308-309
summary of 11 transposing 322-24, 343-44
"MAZE" 169 trills 314
"MERGE," Bitmapped Graphics 180-81 vibrato 315, 320, 343
explanation of 180 voice 224-25, 226
"Merge," Sidplayer Editor 369-71 volume 223-24, 226
explanation of 369, 371 NEW command 62-63. See also com
"Merge," Sprite Control System 445-46 mands, use of in programs; disk
explanation of 445 drive commands
instructions for use 446-47 syntax of 62-63, 69
"Merge Demo 1" 485 use of in program mode 81, 83
instructions for use 483 noise waves 273. See also waveforms
"Merge Demo 2 " 485 illustration of 273
instructions for use 483 nonrelocatable LOAD 82, 84
"Merge Demo 3 " 485 NOT INPUT FILE error 43, 45, 56-57,
instructions for use 483 58. See also file input/output
"Merge Utility" 483-84 NOT OUTPUT FILE error 43, 45, 56, 58.
explanation of 482 See also file input/output
instructions for use 482-83 octave. See pitch
mode. See SID chip, filter controls ON-GOTO statement
mode number 107-108. See also bit examples of 6, 7
mapped graphics simplified use of 6, 7
modem 71, 73-77, 78 OPEN statement 39, 40-41
baud rate 73 syntax of 39, 44, 48, 50, 51, 57, 59,
command character 75 67, 68, 73
control character 73, 74 use of with a printer 46
duplex 75 with an RS-232 device 73, 79
handshaking 75 output 37, 38, 69
word length 73 statements 38, 41
"Modem" 77 summary of statements 44-45
explanation of 77-78 OVERFLOW error. See scientific notation
"MODERNART" 177-78 parallel communication, definition of 71, 78
"Munchkins" 125 "Parts" 20
"MUNCHKIN.SHP" 126 physical lines 19, 21
music theory 206-25, 271-73, 282-83, "PINBALL" 170
290-91, 305-49 "PIPERS.MUS" 321-22
accidentals 309-11 pi symbol, location of the keyboard 25
detuning 320-21, 343 pitch 185, 208-13, 225, 309-11, 314-15,
duration of notes 217-19, 225, 226, 320, 322-25, 333-38, 342-44. See
311-14 also music theory
489
"PLAYER," disk version 188-89 "SCS.OBJ" 384-88
explanation of 187, 190-91 instructions for making copies 389
"PLAYER," tape version 189-90 secondary address. See command number
explanation of 187, 190-91 seed value. See random function
POS function 19-20, 21. sequential file 58-59, 60, 67, 68, 69. See
print formatting functions 19-21 also disk files; tape files
summary of 21-22 reading of 59-60
printing writing of 59-60
to a printer 45, 46, 48 serial communication, definition of 71, 78
to the screen 45, 46 Shapedit 130-37
PRINT statement 3-4, 7, 45 combining sprites with bitmapped
PRINT# statement 41, 45, 49 graphics 167
syntax of 41, 45 features of 137-46
"PROMENADE.MUS" 340-41 instructions for use 130
pulse waves 272. See also waveforms reference chart 145
illustration of 272 use of to redefine custom characters
quarter note. See music theory, duration 166-67
of notes shape tables 123-29
radians 25, 26 plotting process 150-51
random function (RND) 15-17 using shapes in BASIC programs
kinds of 16 146-48
summary of 17 sharps. See pitch
Register Storage Area 92. See also SYS "SHP.BAS" 124
command "SID.BAS" 351-52
relational operator 3 SID chip 185, 186-87, 344, 348
relative positioning. See Shapedit, fea filter controls 290-96
tures of illustration of 186
release 185-86 "SIDDEMO" 360-62
release rate 282. See also envelopes "SID.OBJ" 191-96
relocatable LOAD 82, 84 instructions for making copies 389
RENAME command 62, 69. See also disk Sidplayer Editor
drive commands command index 375
syntax of 62, 69 commands 255-59, 273-75, 283-87,
repetition 298-99, 302-3. See also music 290-94, 299-302, 306-307, 310,
theory 312-13, 315, 320-21, 323, 324-25,
resolution 107-8, 109. See also bitmapped 333, 342-44, 355-56, 362
graphics DROP routine 354
resonance. See SID chip, filter controls error checking features 262-63
rounding function, of a number 26-27 function key summary 260
adding it to BASIC 27 HOOK routine 353-54
RS-232 communication. See also modems illustration of instrument parameters
definition of 71 349
summary of 78-79 joystick editing 267-68
RUN command, use of in program mode keyboard note entry 266-67
81, 83. See also commands, use of in merging with BASIC programs
programs. 351-63
SAVE command, use of in program PLAY routine 353-54
mode 83, 84. See also commands, relocating of 363-64
use of in programs. use of with advanced music theory
sawtooth waves 271. See also waveforms 305-49
illustration of 271 using the program 249-68
scientific notation, explanation of 9 -1 0 ,1 1 SIN function 25, 26. See also transcen
"SCIPIO.MUS" 356-59 dental functions
SCRATCH command 61-62, 69. See also "SITAR.MUS" 297-98
disk files sixteenth note. See music theory, duration
"SCS.BAS" 382-83 of notes
490
SPC function 20, 21, 22. See also print advanced feature of 56
formatting functions importance of CLOSE statement 57,
sprite collision 4 58
Sprite Control System input 51, 52, 53
autoshape features 434-36 output 51, 53
available definition blocks 433-34 prevention of running off the end of
chase mode 440-41 a file 54-55, 58
command index 463 summary of 57-58
disabling the display of a sprite 443 telecommunications
enabling the display of a sprite 443 definition of 71
explanation of 381-82 demodulation 71, 78
instructions for use 389-90 explanation of 71-77
joystick control of a sprite 438-40 modulation 71, 78
multiple sprites 430 tempo terminology. See music theory,
relocation of screen memory 452-56 tempo
relocation of Sprite Control System "Theme and Variation" 287-89
4 5 6 - 57 timbre. See filters
setting priority of each sprite 437-38 "TOWERS" 148
synchronization of sprite motion "TOWER.SHP" 149
441-43 "TOWER II" 154-55
SYS calls 421-30 "TPI#14.M US" 328-32
use of in BASIC programs 419-43, transcendental functions
445-63 summary of 26
use of multicolor mode 437 use of in mathematical-oriented
use of with Bitmapped Graphics applications 22-25
4 5 7 - 59 triangle waves 271. See also waveforms
use of with Bitmapped Graphics and illustration of 271
Sidplayer Editor 460-62 trigonometry. See transcendental
use of with Sidplayer Editor 459-60 functions
"The Sprite Editor" 403-10. See also triplets. See music theory, duration of
Sprite Control System notes
joystick editing 410 "TULIPS" 128-29
editing commands 410-17 "TULIPS.SHP" 129
explanation of 381-82 "TWIST" 151-52
sprites 380, 381. See also Sprite Control type. See integer variables, use of
System underflow error. See scientific notation
animation of multiple sprites 430 uppercase character set, use with a
designing of 403-18 printer 48
illustration of direction numbers 426 USR function 93, 94
SQR function 22-23, 26. See also VALIDATE command 63, 70. See also
transcendental functions disk drive commands
syntax of 23 WAIT statement 84, 88. See also
square waves 271-72. See also waveforms Sidplayer Editor, merging with
illustration of 272 BASIC programs
string 59. See also disk files summary of 88
with an RS-232 device 73, 79 syntax of 88
STRING TOO LONG error 53, 58. See use of in program mode 84-88
also tape files, input waveform 185, 333, 337-38. See also mu
sustain 185-86 sic theory
SYS command 88, 92, 93-94 types of 271-73, 337-38
TAB function 20-21, 22. See also print "WEATHER" 155-56
formatting functions "WEATHER.SHP" 157-59
use of to justify text 20-21 whole note. See music theory, duration of
TAN function 25, 26. See also transcen notes
dental functions "WSOLDIER.MUS" 201-204
tape files 5 0 -57 "YOY.MUS" 347
491
To order your copy of the All About the Commodore 64,
Volume Two Disk, call our toll-free US order line: 1-800-334-
0868 (in NC call 919-275-9809) or send your prepaid order
to:
A ll A b o u t the C o m m o d o re 64, Volume Two Disk
COMPUTE! Publications
P.O. Box 5406
Greensboro, NC 27403
All orders must be prepaid (check, charge, or money order). NC
residents add 4.5% sales tax.
Send ____ copies of the All About the Commodore 64, Volume
Two Disk at $12.95 per copy
Subtotal $__________
'Outside US and Canada, add $3.00 per disk for shipping and handling. All
payments must be in US funds.
□ Payment enclosed
Charge □ Visa □ MasterCard □ American Express
Name _____________________________________________
Address ____________________________________________
75 3106 B
If you've enjoyed the articles in this book, you'll find
the same style and quality in every monthly issue of
COMPUTEI’s G azette for Commodore.
COMPUTED G azette
P.O. Box 5406
Greensboro, NC 27403
My computer is:
□ Commodore 6 4 □ VIC-20 □ Other____________
□ $24 One Year US Subscription
□ $45 Two Year US Subscription
□ $65 Three Year US Subscription
Subscription rates outside the US:
□ $30 Canada
□ $65 Air Mail Delivery
□ $30 International Surface Mail
Name
Address
C i t y S t a t e Z i p
Country
Payment must be- in US funds drawn on a US bank, international
money order, or charge card. Your subscription will begin with the
next available issue. Please allow 4-6 weeks for delivery of first is
sue. Subscription prices subject to change at any time.
□ Payment Enclosed □ Visa
□ MasterCard □ American Express
Acct. N o . E x p i r e s /
ISBN 0-942386-45-0
This was brought to you
http://retro-commodore.eu