The Master Memory Map for the Commodore 64 | Subroutine | Computer Data Storage

MASTER

MEMORY
MAP
FOR THE
COMMODORE 64
A GUIDE TO THE INNER
WORKING OF THE
COMMODORE 64's BRAIN CELLS
by
PAUL PAVELKO
and
TIM KELLY
PrentiCe Hall 8-=1
Englewood Cliffs, NJ London New Delhi Rio de Janerio
Singapore Sydney Tokyo Toronto Wellington
ISBN 0-13-574351-6
~ (C) Copyright 1983 by Educational Software, inc.
Commodore 64 is a trademark of Commodore Business Machines.
Professor von Chip and Prototype are trademarks of
Educational Software, inc.
All rights reserved. No part of this book
may be reproduced, in any way
or by any means, without permission in writing from the publisher.
10 9 8 7 6 5 4 3 2
Printed ;n Great Britain by A. Wheaton & Co. Ltd., Exeter
TABLE OF CONTENTS
PRELUDE ............................................... 1
SOURCES ............................................... 2
GLOSSARy .............................................. 3
How to PEEK and POKE .................................. 6
BYTES and BITS ........................................ 10
LOWER ADDRESSES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 15
GRAPHICS ADDRESSES ............................... 63
SOUND ADDRESSES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 82
COMPLEX INTERFACE ADAPTER (CIA) # 1 ........... 95
COMPLEX INTERFACE ADAPTER (CIA) #2 .......... 101
APPENDICES ......................................... 105
A RECONFIGURING THE MEMORY MAP ............ 106
B. ROM MEMORY MAP ................................ III
C. THE KERNAL ...................................... 113
D. BASIC ROM ROUTINE STARTING ADDRESSES .... 117
E. THE SERIAL BUS ................................... 126
F. THE COMPLEX INTERFACE ADAPTERS (CIA) . . . .. 128
G. BEING AN ARTIST WITH COMMODORE 64 GRAPHICS. . . . . .. 130
H. GRAPHICS PROGRAMMING ....................... 133
VIDEO BANK SELECTION. . . . . . . . . . . . . . . . . . . .. 133
PROGRAMMABALE CHARACTERS. . . . . . . . . . .. 134
A PROTO EXAMPLE .......................... 134
ASCII and CHR$ CODES ....................... 137
SCREEN DISPLAY CODES. . . . . . . . . . . . . . . . . . . .. 139
I. HOW TO CREATE SPRITES ......................... 141
DESIGN THE SPRITE .......................... 141
STORING THE SPRITE IN MEMORY ........... 142
SETTING THE SPRITE POINTERS ............. 143
CHOOSING THE COLOR ...................... 144
MULTICOLOR SPRITES ....................... 145
SPRITE ALGORITHM OUTLINE ............... 150
J. COMPOSING MUSIC ............................ 154
SOUND PROGRAMMING TECHNIQUES ..... 154
OUTLINE FOR SINGLE VOICE .............. 156
VOICE FLOW CHART ....................... 158
SOUND EXAMPLES:
SCALES ................................. 159
PUMP ................................... 161
BOMB ................................... 163
BUSY SIGNAL ............................ 165
SIREN ................................... 166
DRIPPING ............................... 168
PLANE .................................. 170
MULTIPLE VOICE PROGRAMMING ........ 171
OUTLINE FOR MULTI-VOICE ....... , ., .. , .. 173
ADVANCED SOUND
PROGRAMMING TECHNIQUES ........... 176
MUSIC NOTE VALUES ...................... 177
INDEXTOMEMORYLOCATIONS ................. 180
PRELUDE
TO THE COMMODORE 64 MASTER MEMORY MAP
Welcome alL beginning or expert programmer, to ESI's
COMMODORE 64 MASTER MEMORY This book will be
your guide into the inner working of the Commodore 64's 'brain cells'.
This is truly a map, a guide to the special places inside the operating
system of the computer. These places will help you add new features to
the programs you write, making them really come
Along the way, you have the hwnor of Professor Von Chip and the
friendly alien Prototype to help make the journey a productive one.
The Master Memory Map is divided into sections to aid you. Each
section deals with a particular part of the memory. There are lots of
programming examples, too, because sometimes it's easier to under-
stand an example when you see it on the screen instead of just re ading it.
Some of the programming examples add a useful utility to BASIC like
the RENUMBER routine. Others serve as useful programming 'tricks'.
In every case, you should study the listings and play with the code to see
what happens.
The appendices go into more detaiL showing how to do something like
create sprites or produce a sound. They give longer programming
examples and show you some of the advanced things you can do with the
Commodore 64.
This book really isn't a novel, so you can start reading anywhere. But
sometime you should read it from cover to cover; sooner or later you'll
see new ways to use the computer. This moment of enlightenment - a
creative flash - is what makes working with a computer so much
We've worked hard to make the Master Memory Map easy to read
and use. Look in the upper right hand page corner for a guide that will
show you which locations are covered on those pages. Just flip through
the book until you come to the locations you need. The appendix sections
are also marked in a similar way.
Prototype, sometimes just called Proto, will help you find locations
and routines that the beginning or intermediate programmer will use
most often. Look for him in the margin as you flip through the book.
A COpy OF THE PROGRAMS
The programs in this book are used as illustrations for techniques and
ideas. You will gain a lot of knowledge if you type in the programs
yourself. But if you don't want to tire your fingers, send $9.95 to:
Educational Software, inc.
4565 Cherryvale Ave.
Soquel, CA 95073
A BONUS!
If you discover a new. unpublished use for one of the memory
locations send it to Educational Software. In return, we'll send you some
software. free.
SOURCES
A few of the program examples in the Master Memory Map come
from other sources. The source is identified in the text by using these
symbols.
C::: COMMODORE 64 PROGRAMMER'S REFERENCE
GUIDE, Commodore Business Machines, Inc., Computer Systems
Division. 487 Devon Park Drive, Wayne, PA 19087.
C!: Magazines, Copyright 1982, Small System Service,
Inc., Reprinted by permission from Magazine, P.O. Box
5406. Greensboro NC 25403, 12 Issue, Subscription $20.00.
2
GLOSSARY
ASCII: The American Standard Code for Infonnation Interchange.
This is one standard for assigning numbers to the letters and
characters on the keyboard. Commodore computers do not follow
a true ASCII (pronounced 'ASK KEY') but have their own code
instead.
Accumulator: The results of logic and arithmetic operations are stored
here temporarily. It acts as a busy bus stop, nobody stays here long!
Address: The number of a given location. It's just like a street address.
Attack: The rate a note or sound changes from 'off to its highest
volume.
Baud: This is the rate of transmittion of information conveyed over a
line. This rate is determined by the bits per second that are being
transfered. You encounter this term if you are using a modem or
some device that requires special interfacing (RS-232).
Bit The smallest piece of infonnation the computer can handle. There
are eight bits in a byte.
Buffer: A storage place. For example. the keyboard bufler stores your
keystrokes and allows you to type faster. The information in a
buffer eventually goes somewhere else to be acted upon.
Bus: A bus is a system of electrical lines shared by all devices that are
connected to it. This is a convenient way for these devices to share
addressing and data. It works just like a party line telephone.
Decay: A musical term meaning the rate of change from the highest
level to the sustaining level of sound.
/ ~
3
Default The beginning value of a memory location especially when the
power is turned on or other operations are done.
Disable: Tum otT. By disabling the RUN/STOP key, you can prevent
anyone from accidentally stopping your program.
Enable: To tum on; the opposite of disable.
Flag: A signal that something has happened. Flags can be used in your
own programs. For example:
If A$ = "ouch" then B = I
B is the flag in that statement
Floating Point Arithmetic operations using decimal numbers.
Immediate Mode: Using the computer without running a program.
For example:
10 PRINT 3 + 2
is a program and must be run to get an answer.
PRINT 3 + 2
will answer '"5" when you prcss R E T U R . ~ .
Jump: To go from one location to another. In BASIC, the equivalent
terms are GOTO and GOSUB.
KERNAL: This is Commodore's word for a series of machine lar.guage
subroutines that operate the computer. See the Appendix for more
information.
Nybble: Pronounced 'nibble'. A nybble is half a byte. Really. The low
nybble is composed of bits 0 to 3. The high nybble has bits 4 - 7.
Operating System: Sometimes this is referred to as the OS. Part of this
is the KERNAL described above. Its job is to make the computer
run.
4
Page: A page is 256 bytes of memory. The computer often keeps track
of different blocks of memory in terms of pages since it is easier for
the computer to store.
Pointer: It does just what it says, it acts as a signpost, telling the
computer where to look for information.
RAM: Random Access Memory. This type of memory can be easily
changed. Your programs are stored in RAM, and when the
computer is turned off any information in RAM is lost.
ROM: Read Only Memory. This type of memory does not change when
the power to the computer is turned off. Examples of ROM
memory include BASIC and the KERNAL.
Register: Another name for memory location. Registers can be more
than one byte long.
Release: A musical term describing the rate of fall from the sustain level
to zero volume.
Reserved Word: Letters that can't be part of your program. Examples
of reserved words are the status word, ST, and the time words, TI
and TI$. To save yourself from trouble, don't use any variables in
your programs that have the same starting letters of any BASIC
command or have BASIC words in them.
Sustain: Another musical term used with the sound capabilities of the
computer. This extends the sound, like the pedals of a piano.
Sustain __ - - - - - - - --'-___
Waveform: This term is a description of the type of sound produced.
The computer has four different waveforms; triangle, sawtooth,
pulse and noise. Each type produces a different kind of sound.
Vector: This is another kind of pointer. It refers to the starting address of
a routine. The computer needs to know where to look for things.
5
How to
PEEK and POKE
This part is for those who have yet to learn how to use a memory map.
Basically, a memory map is a list of valuable locations within the
computer (in this case a COMMODORE 64), that you can directly use
for various purposes. These locations are called bytes (memory loca-
tions) of memory at a specific place. With 64K of memory, there are
64*1024 memory locations that you can work with. Although some of
these bytes arc used for the computer's Operating System, most of them
are blank for you to use in your programs. This manual will tell you about
the ones that you can do something with.
For example, you can quickly look down this list to find that location
650 controls the repeating of certain keys, like the space bar. By
following the included hints, you can change the "normal" value in that
location, so that when you press any key it will repeat as long as you hold
it down. Please note that any of the changes that you make are only
temporary and will go away when the computer is turned off.
Now to explain how to make changes from BASIC. Say you look
down the list and decide to change location 650 (all numbers are decimal
unless marked with a $ symbol, which denotes a HEX-adecimal
number. or in a column marked ·'hex"). 650 is called RPTFLG by
Commodore. Its function is to decide which keys on the keyboard to
repeat. So, if you would like all the keys to repeat as long as you hold the
key down, you simply look up the correct value to POKE into location
650.
In this example, the memory map says to use the number 255 to repeat
all keys. The BASIC instruction to put a number into memory is called
"POKE". After all this long-winded explanation, you can now see how
simple it is to make this change:
POKE 650,255
6
- HINT-
Always use the decimal numbers with a POKE statement. This means
that sometimes you will have to convert between binary, hexadecimal
and decimal. Also, anyone memory location can only hold a number up
to 255. Why? ... remember that the COMMODORE uses eight bits per
word (memory location), and eight bits in binary counts from 0 to 255
(internally, the machine uses binary). You may want to study the next
section of the manual, .. Bytes and Bits" to learn about binary. Because of
this limitation, sometimes you must POKE numbers into two locations
in a row.
For example, look at memory locations 643 & 644 which are called
MEMSIZ. These locations hold a number that corresponds to the top of
your available memory (called RAM - Random Access Memory). Since
the top of memory can be up to 40960. a number well above the limit of
256 for anyone memory location, the computer will need two locations
to store the value. Yes, I know 256 for the first location plus 256 for the
second doesn't seem to add up to a large enough number to hold 64K, but
the computer takes each number in the second location and multiplies it
by 256. Examples:
11 stored in the low byte
+ I stored in the high byte
267
The computer "sees" 256*1 +11 which equals 267.
Another example:
121 in the low byte
+7 in the high byte
1913
Since 7*256 +121=1913.
Sometimes it is desirable to fool the COMMODORE 64 into thinking
that the top of memory is lower than it actually is. perhaps to keep it from
usi ng the last thousand bytes of memory, thus reserving them for Sprites.
You do the same type of POKE here as in the first example, except that
you have to do it twice: once for the" LOW" part of the number and once
for the "HIGH" part.
7
I said the LOW part of the number is placed in the first memory
location and the HIGH part is next. Although it seems backwards. this is
really not hard to understand. The COMMODORE (and most other
micro-computers) store multiple part numbers this way. Occasionally
this rule is broken. so please don't call me up if you find an exception.
Here's what you do. We want to change the value ofMEMSIZ to be
I K less than it currently is.
I) Find current val ue ...
10 A -= PEEK(643)+PEEK(644) * 256
LOW Part HIGH Part
This number will be 40960, which is the value of MEMSIZ, when
the 64 is turned on.
2) Subtract 1 K from this value ...
20 A = A-(1 * 1024)
Remember that one K is actually 1024 bytes.
(You don't have to use 1. you can can change the size by any
numbeL)
3) Break the new value up into LOW and HIGH parts ...
30 B = INT(N256): C = A-(B * 256)
B would . ~ 156, C would = 0
What this does is make C the LOW part of the number and B the
HIGH part.
EX: 40960-IK = 39936
Line 30, when run, will give you 156 for the HIGH part and 0 for the
LOW part.
4) POKE these values into memory ...
40 POKE 643,C: POKE 644,B (#'s in decimal!!)
EX: POKE 643.0:POKE 644,156
8
!! FINAL WORDS OF WISDOM!!
1) Feel free to POKE and PEEK all you want, trying out ideas or
testing the effects mentioned in the Master Memory Map. The
explanations are only the most basic part of how to do the various
effects possible on the COMMODORE. Watch for EDUCA-
TIONAL SOFTWARE'S series of TRICKY TUTORIALS'"
that will take you step by step through Sprites, Page Flipping,
Sound, Animation and other uses of the computer. These are the
techniques that the best programs use, and all of our Tutorials are
done in BASIC, although we do sometimes include a machine
language subroutine to offer you some advantage like speed.
2) Remember that two numbers are required to tell the computer the
value for some locations, and these arc stored LOW part first,
HIGH part second. This is opposite of what you might think.
3) All of the memory locations are here, but many are for advanced
users only. Don't feel bad if you have noidea what they are for. The
idea is to experiment and learn.
4) You can usually press Run/Stop and Restore if trouble occurs.
This will restore the original (default) values of many locations.
5) Some locations in the Master Memory Map are used to read from
only; that is, you can PEEK to see what is there, but you can't
POKE your own number in. This is because part of memory is a
type called "ROM" which means "READ ONLY MEMORY'".
This type is permanent and can't be changed by POKEing, but
Commodore has thoughtfully provided a way for you to put a copy
of the ROM into memory so you can change it if you wish.
Go back and re-read the last section at least a few hundred times.
There are only four lines in the program that both read the old value of
MEMSIZ and store a new value. These lines don't have to be part of a
program. You could enter them directly.
9
BYTES and BITS
To PEEK & POKE you need to understand what a byte is and how it
is structured. It isn't too hard to understand - and you can use the Master
Memory Map without learning too much about them - but the more you
know about Bytes and Bits the more you'll learn about controlling your
Commodore.
A BYTE is really not complicated at all. A BYTE is simply a group of
eight BITS. When eight BITS are structured into a BYTE then each of
those BITS have special significance. You look puzzled! What, you say,
is a BIT!
A BIT is the smallest piece of information a computer can deal with. In
fact, the computer only deals with BITs at the most fundamental level. It
may be helpful '0 imagine the microprocessor as a bus station. This bus
station has only one single lane road attached to it. That means a bus can
only travel in one direction at a time as there is not enough room for two
busses to pass each other. Therefore, a bus may either be arriving at the
station or departing. The microprocessor, or bus station, can schedule its
bus with a signal light that says "I AM ACCEPTING ARRIVALS" or
"1 AM SENDING DEPARTURES".
In fact. in real computer hardware architecture, the wires that carry
information to and from a microprocessor are called the DATA
BUSSES. We don't need eight separate INPUT and eight separate
OUTPUT wires because, like the single lane road connected to the bus
station, the wires are bi-directionaL that is, information can either be
arriving (INPUT) or departing (OUTPUT). The microprocessor also
has a signal of its own that determines whether it will receive (INPUT) or
send (OUTPUT) information.
10
WHO'S RIDING THE BUS?
Let's take a closer look at that bus. It is known as the BYTE express,
has eight seats, and always carries eight passengers. Those passengers
are little messengers known as BITs, and, as a group, they are known as a
BYTE. These messengers, or BITs, are rather moody. They are either
turned "ON" or they are turned "OFF". That is called BINARY as they
are BI- ST ATE signals, ON being a " 1" state or OFF being a "0" state.
Their vocabulary is just as limited ... the only thing they are willing to tell
you is their mood. Now how do we get any meaningful information out of
a group of eight little monsters standing in front of us, each screaming
"ON" or "OFF" at one time?
Well, when the bus arrives, we could have the whole BYTE stand in
front of us and count everyone who is turned "ON". That would give us
the capability of counting to eight. Seems pretty limited, doesn't it?
Hmmm, the group really needs a leader. That leader will be the first BIT
on the left. We'll call that BIT the Most Significant Bit, or the MSB. The
last BIT on the right will be the Least Significant Bit, or LSB. T e r r i f i c ~
Now that we have a group leader and group follower, then all the BITs
should have a rank.
Handing out ranks is a serious matter and much thought should be
given to it. We can start with the LSB and assign that BIT the rank of
" 1 ", since it is the Least Significant Bit. We can be easy on everyone if
II
we just double that rank for the next BIT in line. So, why not just keep
doubling the rank for the next BIT in line and so on until we get to the
MSB or Most Significant Bit. Now out BYTE looks something like this:
BYTE
MSB LSB
BIT [2J GJ [J Q GJ [J Q 0
RANK §J [B ~ GJ 0 0 [2] ~
MESSAGES WITH MEANING!
What have we gained? More than meets the eye! When the BYTE gets
ofT the BYTE express and each BIT starts telling us what their mood for
the day is, we can make a different and more meaningful interpretation
out of the ignorant little beasts. If everyone is turned" OFF" except the
fourth BIT from the right we can check the rank of that BIT and fmd it is
eight (8). Unknown to the BITs, they have brought us a message and the
message is "8".
Computers are very efficient and do not like to waste information,
therefore, computer related numbers usually start at BASE ZERO (0)
since zero is unique. We usually like to start counting with one ( 1 ) for the
convenience of our thinking process. That way, the number we arrive at
when we have counted the last item actually represents the number of
items we counted. Normally, we would count the BITs as one (1)
through eight (8). The computer thinks a little more efficiently than
mortals and sees BITs zero through seven as representing eight (8)
individual BITs.
VALUE 12H 64 32 16 8 4 2
DD DO. DDD=8
BIT 7 6 5 4 2 o
It you SET or turn "ON" only the fourth BIT (BIT #3) from the right
you will observe a value of eight (8) in the val ue box. That was the
message we received!
Aha. we now want the BITs to get on the bus and carry a message back
to the sender. We want them to tell the sender "9". Oops, a small
12
problem, there is no BIT with the rank of nine in the BYTE. What to do,
what to do? I guess the next best thing is to be very nice to the LSB, pat it
on the head, and tum it "ON", then when the sender receives our
message from the return BYTE he will find BITs with the rank of" 1" and
"8" turned "ON". Adding those ranks together gives us a numerical
range of 0 to 255. That is a total of 256 cases if you count 0 as a case.
VALUE 128 64 32 16 8 4 2 1
DDDD.DOfM=9
DD D.
0.=45
D.ODD.
D =162
BIT# 7 6 5 4 3 2 0
Well, that's how you get the numbers to POKE into the locations in
the Memory Map. Let's just take one more example. If Proto was a
Sprite, he would have a number from 0 to 7. Sound familiar? To let Proto
be Sprite number 0, tum on the zero BIT in location 53269.
POKE 53269,1
BIT# 7 6 5 4 3 2 0
DDDDODOB
VALUE 128 64 32 16 8 4 2
For Proto to be Sprite number 3, tum on BIT 3.
POKE 53269,8
VALUE 128 64 32 16 8 4 2 1
DDDO.DOD
BIT# 7 6 5 4 3 2 o
'1>U·l-f\ 13
To have 4 different Sprites on the screen, tum on the BIT for each Sprite.
VALUE 128 64 32 16 8 4 2 1
00 O. DO
BIT# 7 6 5 4 3 2 o
Turns on Sprites #5, 3, 2 and 1.
Confusing? Just read this a few thousand times and play, play, play
with the locations in the Master Memory Map. The more you play, the
more you learn!
14
-:, -.
• • •
LOWER ADDRESSES
LABEL
Hexadecimal Decimal
Location Location
Decription and
How to Use
If you' re interested in programming only in BASIC, the first two
locations won' t be of much interest. Later, when you want to try machine
language programming, take a good look here.
D6510
0000 o This is the place on the computer's
main processor (the 6510) or
"brain", that monitors or " looks at"
the information going in and out of itself. This location is not useful if you
program only in BASIC. If you are interested in writing machine
language programs this is what you need to know:
NAME BIT DIRECTION DESCRIPTION
LORAM 0 OUTPUT Control for RAMJROM at
$AOOO-$BFFF (BASIC)
HIRAM 1 OUTPUT Control for RAMJROM at
$EOOO-$EFFF
(KERNAL)
CHAREN 2 OUTPUT Control for I/O/ ROM at
$DOOO-$DFFF
3 OUTPUT Cassette write line
4 INPUT Cassette switch sense
5 OUTPUT Cassette motor control
15
. " -'-
If the bit is set to 0, input is coming from the memory block. If the bit is set
to 1, the processor is sending information to the routine. Normally this
location is set to 47.
R6510
0001 This location is a little more useful to
the BASIC programmer. It is respon-
sible for dividing the memory into
pieces the computer can handle.
In addition to 64K bytes of RAM memory, the Commodore 64 has
20K bytes of ROM containing the Kernal, screen editor and BASIC
interpreter plus another 4K for the character generator ROM. Another
4K to 8K is available in expansion cartridges. This effectively allows the
microprocessor to look at 92K bytes of memory! However, only 64K is
accessible to the 6510's address space at anyone time.
Before we go too much further, here's a practical use of this location.
Using this address and others you can create your own character sets for
graphics or animation. To do this you must move the character generator
ROM into RAM so you can change an .. A" into a tiny Proto' See the
appendix for an example of creating your own characters.
If you are interested in what happens when each bit is turned on or off.
here's a handy list of the locations and the different kinds of memory
configurations that can be made.
Bit#
o LORAM SIGNAL (0 = switch BASIC ROM OUT)
1 HIRAM signal (0 = switch KERNAL ROM OUT)
2 CHAREN signal (0 = switch character ROM IN)
3 Cassette data output line
4 Cassette switch sense 1 = switch closed
5 Cassette motor control 1 = ON, 0 = OFF
Bits numbers 6 and 7 are not used.
16
MAP # BITS 2-1-0 FUNCTION
Map - 0 III 38K BASIC
Map - 1 XOI 60K RAM & I/O
Map - 2 110 Z-80 CP/ M Cartridge
Map - 3 100 64K free memory
Map - 4 III Expansion count
Map - 5 110 Assembler/wordprocessor
Map - 6 III No BASIC
Map-7 lXX MAX machine games
Note: X = not available for user
The " Max Machine" is a game machine that Commodore hasn't
released in the U. S. yet. The game's cartridges will also work on the 64.
If the Max Machine game cartridge is plugged in, map 7 is not available
to you.
Ifit isn't fun figuring out the values for this location, remember that it is
affected by different cassette operations (see the appendix ,. Recon-
figuring the Memory Map" for diagrams of the different map possibil-
ities). If you think you really have problems
POKE 1,255
and your ROMs will reset and the system will be its good old self again.
This is one place where pressing RUN/STOP and RESTORE won' t
work.
0002
ADRAYI
0003-0004
ADRAY2
0005-0006
2
3-4
5-6
This is used by the computer to tem-
porarily store information it needs.
Don't use this address, it could upset
the machine.
Jump vector: convert floating-point
real numbers to integer.
Jump vector: convert integer numbers
to floating-point numbers.
17
CHARAC
0007
ENDCHR
0008
TRMPOS
0009
VERCK
OOOA
COUNT
OOOB
DIMFLG
OOOC
VALTYP
OOOD
INTFLG
OOOE
GARBFL
OOOF
SUBFLG
0010
7
8
9
10
11
12
13
14
15
16
Search character. This location
stores the ASCII value for a quote
(34 ).
Flag: scan for quote at end of string.
Screen column from last TAB.
Flag: 0 = Load 1 = Verify
The value changes with the last disk
or tape operation.
Input buffer pointer number of sub-
scripts.
Flag: default array DIMension
This location holds the value of the
first letter of the most recent dim-
ensioned array.
This shows the type of data being
read. 255 ifitis string data and 0 ifit is
numeric.
This shows data type for numbers.
128 for integer and 0 for floating
point
Flag: DATA scan for LIST and gar-
bage collection. Normal value: 4.
Flag: Subscript reference and user
function call. This location doubles
as flag register for these two func-
tions.
18
INPFLG
0011 17 Flag: BASIC input types.
o = INPUT, 64 = GET,
152 = READ
This shows 0 when power is turned
on. The value will change as the input
type changes.
TANSGN
0012 18 Flag: TAN sign/comparison results.
This flag tests SIN/COS division
results to verify the tangent sign. The
normal value is O. This value be-
comes 255 when TAN argument is
greater than 259.1.
0013 19 Flag: input prompt.
LINNUM
0014-0015 20-21 Temporary storage of integer value.
BASIC stores integer variables used
in calculations here. The routines in
locations 3 - 4 and 5 - 6 use the
number stored here.
TEMPPT
0016 22 Pointer: temporary string stack.
Normally points to TEMPST (25).
LASTPT
0017-0018 23-24 Last temporary string stack.
TEMPST
0019-0021 25-33 Stack for temporary strings.
INDEX
0022-0025 34-37 The addresses stored here point to
machine subroutines stored in the
BASIC ROM.
RESHO
0026-002 A 38-42 This holds the results of floating point
multiplication. These locations are
used by the system ROM multiply
19
TXTIAB
002B-002C 43-44
routines whenever very large positive
or negative numbers are multiplied.
Pointer: start of BASIC text.
Normal value: $0801(2049).
.. Now here's a location everyone can use! These addresses point to the
.. place the computer looks for your programs. You can fool the computer
into thinking it has less room than it really has so you can "hide" a
program. This location combined with others gives you:
AN APPEND ROUTINE
With an append routine you can load one program after another and
keep both programs in memory! Why would you want to do this? Here is
an example. If you include ajoystick routine in every program you write,
then typing in the same lines time after time is something you can give up.
First, just save the joystick routine separately. Give it high line numbers
like 20000 or 30000. Then, whenever you need it, use the append routine
to add it to any program you want! The high line numbers should keep
your joystick routine above the rest of your program so you won't need to
renumber them.
The programs for this location were printed using Midwest Micro
Associates printer interface program .. Smart ASCII". Each
Commodore cursor control character or color character is translated into
English and printed within parentheses.
(CLR) means the CLEAR/HOME key and will look like a reversed
heart when you enter the program. (DN) means cursor DOWN, (LF)
means cursor LEFT, and (HM) is cursor HOME (without clearing the
screen). Two color controls are used, (BLU) for blue and (WHT) for
white. Use the appropriate keys to produce these colors.
20
If you use a cassette to save programs,
1. Enter the following program:
1 A=F'EEf:: ( 44 J
:::: F'Fd NT" (BLLJ) (eLf::;:) (o1\l) (ON) (ON) (ON)
(ON) (DN) (ON) <DN) <DN) !UN;' (DN) (ON;' (LF;; (1._
F;' (L F) (L_ F ) F' eWE 4 " 1 : F Ci t:E 4 .:). , " ; (i; " (h ,'I;' (tIJ H T) "
3 FORI=631T0636:POKEI,13:NEXT
i). POkE 1 98 , .s
5 IFPEEK(45)<2THENPOKE43.PEEK(45 )-2+255:
POKE44,PEEK(46)-i:ENO
6 POKE43,F'EEK(4S)-2:F'OKE44,PEEK(46):END C
2. Put the cassette with the first program you want to add into the
cassette drive.
3. Run the append program and follow the directions given on the screen.
When the word "READY" appears, type LIST and you will see the
second program listed AFTER line 6. To add another, put the new
program in the cassette and type RUN again. When you have added all
the programs you want, delete lines 1 through 6.
If you have a VIC-1S41 disk drive, make the following changes and
additions to the program:
1 INPUT 11 ADD WH I CH F'ROf3RAM"; Ft
2 A=PEEk(44):Q$=CHR$(34)
3 F'RINT" (BLU) (ClR) (ON) (ON) (oN)LOAD";D:t;F$;
Q:t; ", 8 (ON) CON) (ON) (Ot'n (ON) (ON) <Dl'n
(ON) CO 1\1 ) (LF) (LF) (I_F:' (I_F) F'Of::E4:: , 1: F'OI :E44 ,
" ; rei; " (Hr'1) ( WH T) "
4 FORI=631T0640:F'OKEI,13:NEXT
5 F'Of::E 1 98 , 1 <)
6
F'OkE44
l
PEEk(46)-1:ENO
7 POkE43.F'EEK(45)-2:POKE44,F'EEK(46) :END C
Type Run and follow the directions given on the screen. When you
finish, be sure to delete lines 1 to 7. If you have programs with the same
21
line numbers, you will have to renumber both programs. For a handy
renumbering program, see address 2040. You can see how the program
works by POKEing your screen to a light gray (POKE 53281 ,12) so all
the commands will show.
Briefly, this is what happens. First, adjustments are made in locations
43 to 46 to move this program safely out of the way of the program you
are about to add.
Then in line 3, two things happen. First the LOAD command is
printed, then the POKE commands that will be needed later to find our
hidden program. In line 4, you put carriage returns in the keyboard buffer
(locations 631-640) and tell location 198 how many you put there. Line
5 "hides" any program in memory from the computer so the program
isn't lost when you add the new one. Then the program ends.
Ending the program causes the computer to act on anything in the
input buffer, which we have conveniently stuffed with carriage returns
(CHR$ (13)). Since the program has already printed commands on the
screen, the caniage return enters these commands just as if you did it
yourself. That's a lot for only 7 lines of ccxie!
Here's a scrolling routine that uses some of the same concepts. This
routine will let you see one line of program at a time.
63000 REM** +1- LIST **
63001 SA=PEEK(44)*256+PEEK(43)-1
63002 LN=PEEK(SA+3)+PEEK(SA+4)*256
6:3003 I NT II (CLr=;:) (BL.U) Goro 6:3010": F'R I NT
"LIST";
63004 POKE631,19:POKE632,17:POKE=33,5:
POKE634,13:POKE635.19:POKE636.13
63005 POKE198,6:END
63010 IF PEEK(197)=43 THEN 63100:REM TEST
FOR 11._" f:::EY
6:3020 IF F'EEf ( 197) =40 THEN 63200: S:El1 TE3T
F!Jr;.' "+" f:::EY
63030 GOTO 63010
63100 IF PEEK(SA+S)<>O THEN
63100
63110 SA=SA+5:GOTO 63002
63200 SA=SA-l: IF PEEK(SA)=O AND PEEK(SA-4)
<>0 AND PEEK(SA-3)<>0 THEN 63002
63210 GO TO 63200
22
C!
., ....
Here' s how to use it.
1 ) Load the program you want to scroll.
2) Enter the following BASIC without using line numbers (this is
called the immediate mode).
CLR POKE 43,PEEK(45)-2:POKE 44. PEEK (46) .
This makes BASIC think it has less memory for the next step.
3) Load the scrolling program.
4) Enter the following in the direct mode.
POKE 43, I :POKE 44,8
5) Type 'RUN' and press return.
6) Press the minus (-) key to scroll down to the next line. Press the
plus ( +) key to scroll up one line. You must scroll down at least one line
before you scroll up or the program will end.
VARTAB
002o.002E
ARYTAB
002F-0030
STREND
0031-0032
45-46
47-48
49-50
Pointer: Stan of BASIC variables.
Pointer: Stan of BASIC arrays.
Pointer: End of BASIC arrays( + 1).
These locations are similar to location 43-46. These give the area
where arrays are stored after they are DIMentioned in your program.
Being able to find the starting addresses of your string arrays will be
needed if you're storing short machine language subroutines in them.
23
This sample program creates 3 different types of arrays then allows
you to see how the computer stores them. Press any key to look at each
location. Press RUN/STOP to end.
100 REM **** ARRAY SAMPLES ************
1 1 0 D I1'1 I \ ( :=;. 5)" C 1i ( 5). (:'.1
120
130 REM **** ARRAY POINTER FN *********
140 OEF
150
16n r;:EI1 .JHH:* THE {.';F:nAYS ***·*-I\-IH.**
170 FOR I = 1 TO 5
1 r-=< ( I ) I
l'y(J C$': I CHR$ (.S5+ I)
FOR J = 1 TO 5: I%(I.J)=J:NEXT
210
REM **** FIND ARRAYS IN MEMORY ***-1\
230 AS FNARRAY(47): REM ARRAYS START*
:::' 4!:Zi AE AV ': 47') 1--c.:Er·1 :c") DID*·l<'l<'

260 REM .*** PRINT ARRAY ELEMENTS *****
270 FOR T= AS TO AE
280 PRINT T,PEEK(T)
::::90 I T 1 en .64,64: F:EI'I ?)NY I<:EY-IH
,::'0(' NEXTT
-:::: lIZ; CLR
320 REM **** RUN/STOP TO END ****
GClTCJ :330
FRETOP
0033-0034
FRESPC
0035-0036
51-52
53-54
Pointer. Bottom of string storage.
Utility string pointer.
These two locations point to the end of the Random Access Memory,
(RAM), used to hold strings like "Hello" or "My name is Prototype".
24
Often, programmers use these locations and the next two in a com-
bination that allows them to hide part of the memory from the
computer. Typically, you may want to reserve a large portion of your
memory for keeping things like longer machine code subroutines, bindry
data files, or fonts (modified character sets) resident but not accessible
by BASIC interpreter routines.
The next two locations show how this is done.
MEMSIZ
0037-0038 55-56 Pointer: Highest address used by
BASIC. In other words, your
programs won't be stored beyond
the value shown in these 2 bytes.
Normally this is set to 40960 but
you can change that if you want.
To set aside 4 K of memory for machine programs, graphic
characters or sprites in the program mode, use this routine in the
'immediate mode'.
POKE 51,0:POKE 52,144:POKE 55,0:POKE 56, 144:CLR
This will save the area from 36864 to 40960. (9000-9FFF 10
hexadecimal notation)
POKE 51,0:POKE 52,160:POKE 55,0:POKE 56,160:CLR
This will restore the machine to normal.
25
CURLIN
0039-003 A
OLDLIN
003B-003C
57-58
59-60
Current BASIC line number.
Previous BASIC line number.
These address registers point within memory used by BASIC where
the program line numbers are stored. You can determine these line
numbers by
PRINT PEEK(57)+256*PEEK(58)
OLDTXT
003D-003E
DATLIN
003F-0040
61-62
63-64
1un DII"1
200 FOR I = 1 TO 3
I ( I )
'lOO l\lEXT
This contains the address where
BASIC code is to resume after the
program has been STOPped. It is
used with the BASIC command,
CONT. This is normally set at the
beginning of BASIC (2048) when
there is no program resident.
Current DATA line number. These
locations store the line number of
either the first DATA statement in a
program or the current DATA state-
ment being read.
5U':;; FRIIH (F'EEI< (6:::::) (64))
6kHJ DATA .[,
Running this program will show the number 600 as the current DAT A
line. By using a routine like this while you're de-bugging your program,
you'll be able to see if all of your DATA statements are being read.
DATPTR
0041-0042 65-66 Pointer: This is the address of the
current DAT A item. When no
26
I
57· ..
DATA statements are encountered,
this location defaults to 2048.
Did you know that each type of DATA needs a different amount of
memory to store each part? Whole numbers take 2 bytes, characters take
3 bytes and floating point numbers take 4 bytes.
INPPTR
0043-0044 67-68 This address shows where the
INPUT statement temporarily stores
its data, which is the system INPUT
buffer starting from locations 512 to 600 (78 bytes). You can't POKE
this location to change the size of the INPUT buffer. By the way, trying
to put more information in the buffer than it will hold will cause the first
78 characters to be lost.
VARNAM
0045-0046
VARPNT
0047-0048
FORPNT
0049-004 A
004B-0060
69-70
71-72
73-74
75-96
Current BASIC variable name.
When a single letter variable has been
used, this location returns its ASCII
value.
Pointer: Current BASIC variable
data. This is just another location
which points to base address of the
BASIC variable table (normally
2084).
Pointer: Index variable for FORI
NEXT. loops.
Temporary pointer / data area.
The 16 locations from 97 to 112 are arguments for the floating-point
arithmetic routines stored in the KERNAL ROM. They can be used in
BASIC, but they provide the assembly language programmer with the
ability to perform any arithmetic operations on two numbers (accum # 1
and #2) without writing those routines BASIC uses.
These locations are also very useful for machine language subroutines
that are called from BASIC. See locations 784-787.
27
If you are interested in mastering machine level programming, take a
look at Rodnay Zak's books on 6502 programming. They are concise
and thorough.
FACEXP
0061
FACHO
0062-0065
FACSGN
0066
SGNLG
0067
BITS
0068
ARGEXP
0069
ARGHO
006A-006D
ARGSGN
006E
ARISGN
006F
FACOV
0070
FBUFPT
0071-0072
97
98-101
102
103
104
105
106-109
110
111
112
113-114
Floating-point accumulator # 1: ex-
ponent.
Floating accumulator # 1: mantissa.
Floating accumulator # 1: sign.
Pointer: Series evaluation constant.
Floating accumulator # 1: overflow
digit.
Floating-point accumulator #2: ex-
ponent.
Floating accumulator #2: mantissa.
Floating accumulator # 2: sign.
Sign Comparison Result Accum. # 1
vs #2.
Floating accumulator 1. Low-order
(rounding).
Pointer: cassette buffer.
28
Locations from 115 to 138 are part of the computer's operating system
that are deliberately put in RAM for the user to be able to change it. For
instance, you could add commands to BASIC.
CHRGET
0073-008A 115-138 This machine language subroutine is
what the computer uses to get char-
acters or tokens from the
keyboard, cassette, disk or modem.
Here is what it looks like disassembled:
, \ . . Il)
.'
f '. b / f:':; 1 NC ¥
J(
./
).:..: :
Du l !
...
L:NF :!lil! 1

"
l J . ..I .::.
' I
007 7 Ei:.) l B 1 hIe: :!: 7
) l
( )(
i ,I
q
6U
[
A L.Ui.:;
'*' [f2l i:,
(
.
!
"
, OU7C I ..
:-::;
C; 1'1 F' #

,
( )( j
7
[ FlO HCb ¥OUDA
, 0080 C 9 C 1"1 F' #$,:0
, F
( i FF BELt ,lOU /
, (lOU 4 hEC

E 9
. (
.
i bE{C ttl
( .I ,
, 0087 :::- fJ SET
, O()D8 [9 DO #''1:". DO
, 008{\ 60 i S
The next two locations are checked by the CHRGET routine.
CHRGOT
0079
TXTPTR
007 A-007 B
RNDX
008B-008F
STATUS
0900
121
122-123
139-143
144
Entry to get same byte of text again.
Pointer: current byte of BASIC
text.
Floating RND function seed value.
Kemal I/O status word (ST).
Normal = O. ST is a reserved word
in BASIC. you can't use it as a
variable (like" A" or"B2") in your program. The value of ST will
change if there is a problem loading a program from tape or disk.
29
.1(;1 FElltd)!) lHI':; I:QTUr,y fH,IY IIH'tJIH 111<
;,:(1 S T[I F'F<['.,,![I'lT I,
::(1 r;'Ell--F'Fdl()F,(d'l !T((JI'I IIIC', niT r I I ill.
/1\21 r;:['JI-IJi::n D?HUt'l BEFJI
F;[I-l- rHE fP;I:'E DH D I F J I r
60 IF Sf = 64 THEN 90
7(1
fJ (21
ch21 FR I NT" END [IF "
ST ST
Bit Numeric
Position Value
write 1
0
read 2
I
2
4
3
8
4
16
5
32
6 64
I 7
128
*Evaluate or Input
STKEY
0091
SVXT
0092
VERCK
0093
145
146
147
1
Tape
Cassette Verify
Read SeriaVRW or Load
Time out
Time out
Short block Short block
Long block Long block
Unrecoverable Any
read error mismatch
Checksum Checksum
error error
End of file *EOI line
End of tape Device not End of
present tape
Flag: STOP key and RVS key.
Normal: 255
POKE 145,127 will act as a RUN/
STOP key.
Timing constant for tape.
Flag: 0 = LOAD, 1 = VERIFY
Stores the last tape or disk LOAD or
VERIFY operation.
30
C3PO
0094
BSOUR
0095
SYNO
0096
0097
LDTND
0098
148
149
150
151
152
1M ·114
Flag: Serial Bus, output character
buffers.
Buffered char. for serial bus.
Cassette synchronization number.
Temporary data area.
Number of open files and index to
file table. Only 10 files are allowed
open. If you try to open more than
10 files at any time your program will stop and show a '"too many files
open" error. If you're opening close to ten files in a program, add lines
like these to prevent the problem.
2 i ;jO I FEEl·:' ( :[ ::::[ THEI\l
llF'EN 1, 1 1
': 1 U (?,ClTU :3i:i\}j: F<Etl-- -[ UtH I I\!UE
4(}1(1 FF:HH" 1U r TL.ES ClF'EI\1, 1\
/I. 1. m F'F? I NT II DC) VUU TU II
I NF'UT II ANY" F:1o
DFLTN
0099
DFLTO
009A
153
154
Default input device normally set
to the keyboard (0).
Default ouput (CMD) device
normall y set to the scree n (3).
When you tum the power to the computer on, the screen is where
you see information. The BASIC command CMD changes that if
you use an open statement. For example, to have a printer send a
listing of a program you already have in memory, do this:
OPEN 1 A:CMD 4:LIST
31
Here's a list of the different numbers used.
PRTY
009B
DPSW
009C
MSGFLG
009D
PTRI
009E
PTR2
009F
TIME
00 AO-OOA2
155
156
157
158
159
160-162
DEVICE
NUMBER PERIPHERAL
0 Keyboard
1 Cassette
2 Modem
3 Screen
4 or 5 Printer
8 to II Disk Drive(s)
Tape character parity.
Flag: Tape byte-received.
Flag: 128 = > Direct mode 0
Program mode.
Tape pass 1 error log.
Tape pass 2 error log.
This is the "JIFFY" clock. A jiffy is
l/60th of a second. The computer
uses this to help time the different
operations it performs. Here's what these locations do: every 1 /60th of a
second 1 is added to the number in 162 until it reaches 255. Then, 162
turns to zero and 1 is added to 161 until it reaches 255. Then 161 turns to
zero and 1 is added to 160. When 160 reaches 255 all 3 locations are set
to zero. You can use this location to make a stopwatch to check your
reaction time.
32
154· 161
100 PRINTCHR$(147)
11 I NT" I [ill I J I'IE."
120
130 PHJNT
1 lll:;! PH I 1\ll
1 PH I NT" V,II'IEI,j YOU THE BU .. IC
16111 PFU HT" T HE: AI\ID
170 Pf.: I NT" RE{)CT I UI\j r HIE \,JI Lt .. BE E)I·lm'.)I\I."
180 S=INT(10*f.:ND(1)}
n:m :I TO
200 FOR D=1 TO 3:PRINTCHR$(17):NEXl
210 FORR=l TO 12:PRINTCHR$(29);:NEXI
220 PRINTCHR$(115)
230
240 IFPEEK(197)=64 THEN 240
250 PRINTCPEEK(160)*65536+PEEK(161l
F'E.FI; ( 1 h,'?) ) ./ 6!2!
This will show how quickly you can hit a key. This routine will allow
you to read time in amounts less than 1 second! In BASIC, time is kept in
the string TI$ and in ajiffy counter, TI. TI starts at "000000" when you
turn the computer on. The computer uses a "24 hour clock" which means
that one 0' clock in the afternoon is called 13 :00. You can reset the clock
to zero by entering TI$ = "000000" or set it to the correct time of day
(right to the second) by saying, for example TI$ = "041325" for 4
o'clock, 13 minutes and 25 seconds AM while 4 PMis "161325". As for
TI, well it's a counter based on the information in locations 160-162.
Both TI$ and TI will reset to zero by POKEing these locations with a
zero.
For I = 160TOI62:POKEI,0:NEXT
Try substituting this for line 270
33
Here's an example of using TI$ to produce a clock on your screen.
lO;;1 r-r: I t,ITC:llh 1; ( J 47)
1 1 U 1 : F'UfC:':;::.2D 1 1 :: F'[lf [",,1',. ()
12U "I IUim:::;" " "1'llt'IUIE:3". "
1 :::(1 II;: T l'nCHr< 1; ( 1 fJ) ;
1 4 I J 1·1 T , I'll Df, (I'll;, 1 , , 1'1 I J)$ ( TIt;. '.
\
.. ,
III I' ,: I If, ',,:; ",')
1 [,UTD
TI$ and TI are also reserved words used by BASIC. Don't use these
names for your variables.
OOA3-00A4 163-164 Tempory data area.
CNTDN
00 AS 165 Cassette sync. coutdown.
BUFPNT
OOA6 166 Pointer. tape I/O buffer.
These are the zero-page memory locations for the RS-232. The
system's software allows compatability with any RS-232 device (prin-
ter, modem, etc.). This allows RS-232 programming accessible in
BASIC through the Kemal routines. These locations are used directly
by the RS-232 device through the system routines and are not controlled
by the programmer. See the appendix on the RS-232 in back. During
cassette or any other serial bus activities, data can NOT be received
from RS-232 devices. This is how temporary cassette data locations can
be shared with RS-232 locations.
INBIT
OOA7
BITCI
OOA8
167
168
RS-232 input bits/cassette tempor-
ary.
RS-232 input bit count/cassette
temporary.
34
RINONE
00A9
RIDATA
OOAA
RIPRTY
OOAB
SAL
00 AC-OOAD
EAL
OOAE-OOAF
169
170
171
172-173
174-175
162 ·112
RS-232 flag: Check for start bit.
RS-232 input byte buffer/cassette
temporary.
RS-232 input parity/cassette short
count.
Pointer: Tape buffer/ screen scrolling.
When you LOAD or SAVE, the
computer looks at a part of memory to
read from or write over. If you or
your program changes the start of BASIC variable pointers (lacs. 45-46)
so you can store more BASIC text, your cassette or disk drive won't be
aware of the change and will lose some text. Whenever you change
locations 45-46, and you want to SAVE or LOAD a program on
cassette. Make sure you POKE these locations with the same values as
locations 45 and 46. This will make sure you save all of your program.
CMPO
00 BO-OO B 1
TAPEI
OOB2-00B3
BITTS
00B4
176-177
178-179
180
Tape timing constants.
Pointer: start oftape buffer. This can
be used as an indirect zenrpage jump
routine in the buffer.
RS-232 out bit count/cassette teml>"
orary.
Locations 180 thru 182 act the same as 166 thru 171.
NXTBIT
OOB5
RODATA
00B6
181
182
RS-232 next bit to send/tape EOT
(End-Of-Tape) flag.
RS-232 out byte buffer.
35
FNLEN
00B7
LA
OOB8
SA
OOB9
DEVICE
Cassette
Modem
Printer
Disk
For example:
183
184
185
DEVICE
NUMBER
1
2
4 or 5
8 to 11
Length of current file name. The
nwnber of characters in the file name
itself. Same as PRINT(LEN
(FILE$» where FILE$ is the name
of your file.
Current logical file number.
Current secondary address. In
BASIC, the secondary address is
used with the OPEN command. The
secondary address tells the other
device what to do after it is opened.
SECONDARY
ADDRESS DESCRIPTION
0= Input file name
1 = Output
2= Output end of tape
0 control register
0= uppercase/ PRINT text
graphics
7 = upper/lower
2-14 data drive#, file type,
channel read/write
15=command command
channel
OPEN 1,4,7
This OPENS a channel to the printer (device 4) and tells the printer to
type upper/lower case letters.
If you want to write some data about your debts on a cassette tape,
OPEN 3, 1, 2, "DEBTS"
36
.8l· .97
tells the computer that file #3 (it could be any number you choose
between 1 and 255) will be written as a cassette file (the number 1 after
the 3), and, besides writing the data on the tape, put an "End Of Tape"
notice (the number 2). The "End Of Tape " (EOT) will tell the computer
to stop looking for more data on this tape. Only use the EOT mark on
the last data file or program you put on a cassette. "DEBTS" will be
the name of the file.
FA
OOBA
FNADR
OOBB-OOBC
ROPRTY
OOBD
FSBLK
OOBE
MYCH
OOBF
CASI
OOCO
STAL
OOCl-00C2
MEMUSS
OOC3-00C4
LSTX
OOC5
186
187-189
189
190
191
192
193-194
195-196
197
Current device number.
Pointer: current file name.
RS-232 out parity/cassette temp.
Cassette read/write block count.
Serial word buffer.
Tape motor interlock.
I/O start address.
Used for temporary storage of in-
formation while information is load-
ing from the cassette.
Current key pressed. The last key
put into the keyboard buffer. There
will be a 64 here if a key isn't held
down. The "stopwatch" program under location 160-162 uses this
address to see if any key has been pressed.
If more than 1 key is held down at the same time, the key with the
highest priority will appear on the screen.
37
This program will give you a list of the keys and their priority.
:I i!li2! (:;[T
11 0 /'1$::: "" T 1!/.1(1
L?O F'n I NT F'EEf ( l'in
13121 GelTO 112hJ
PRIORITY / KEY CHART
# KEY # KEY # KEY # KEY

o INST
1 RET
2
3 f7
4 fl
5 f3
6 f5
7 t + CRSR
8 3
9 W
10 A
11 4
12 Z
13 S
14 E
15
NDX
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
5
R
D
6
C
F
T
X
7
Y
G
8
B
H
U
V
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
9
I
J
o
M
K
o
N
+
P
L
[
(d;
48
49
50
51
52
53
54
55
56
*
1
CLR
t
/
1
57 -
58
59
60
61
62
63
2
SPC
Q
OOC6 198 Number of characters presently in the
keyboard buffer. Normal value: O.
Poking this location with a zero
will empty the buffer. This is very useful III games or other
applications where keys will be struck quickly. You should always empty
the buffer before using the GET statement
1 Ql(2! pm:::E 198. 0
1ii2! PRINT"F'RESS ANi' [:E',' TCJ cmHn.IUE"
GET R$
13i21 IF "" THEN 120
38
.,.,. 213
1 C3ET F::1O
1 -:n I F.'$
The first program checks for any key. The second will continue if only
one key is pressed.
RVS
OOC7 199 Reverse character switch. Normal: O.
The value switches to 18 when
reversed characters are printed.
POKE with 1 or 18 before every PRINT to reverse characters. It's
easier to use the RVS ON and RVS OFF keys.
INDX
OOC8 200 Pointer: end of the logical file for
INPUT. This location returns the
screen column number of the end of
the INPUT record. Unless you use a semicolon or the cursor keys inside
a string, the computer will put the input question mark in the third column
of the screen.
Here are some examples of how to change the position of the INPUT.
INPUT" NAME" N15
1 INPUT" HELLO DC) YOU NEED HELP" N$
1 (I INPUT" ADDF:E5S" I'H
LXSP
OOC9-00CA 201-202 Cursor X-Y poSitIOn at start of
INPUT. These two bytes store the X,
Y coordinates respectively where the
INPUT statement accepts data. POKEing these locations has no affect
on the screen positioning of INPUT records.
SFDX
OOCB 203 Flag: Print shifted characters. Nor-
mal value is 64. This location will
show the value listed in 197 when
characters are printed.
39
CURSOR LOCATIONS
Use these locations to produce a cursor during a GET statement.
BLNSW
OOCC 204 Flag: Cursor blink toggle.
O=cursor on I =cursor off.
10
2U I H ..d;:=:" "THEN 1 U
30 PF: I NTA$
40 IFA$=CHR$(13)THEN70
B$=Ei$+{H
b!2i GOTO:[
FRHHB$
BLNCT
OOCD
GDBLN
OOCE
BLNON
OOCF
205
206
207
Timer: Countdown to toggle cursor.
Nonnal value: 2.
Character under cursor in ASCII.
Nonnal value is 32.
Flag: Last cursor blink on! off.
Nonnal value is O.
Here's how a sample program to add a cursor might look:
100 REM--CURSOR WITH GET
2!ZIO B$==" 11
300 POKE204,0:POKE207,0:GET A$
IF A'i;:=:"" THEN 30!21
50125 PFIINTA$;
600 IFA$=CHR$(13) THEN 900
7i!h2i B:p=B$+A$
8(iO GaTa
9(!U PF: I NTB$
40
104 ·110
If you want the cursor to blink during a GET, you should have the
POKEs on the same line as the GET command. If you press return while
the cursor is on it will stay on the screen as a square. This won't change
the value of your input. Run the demonstration program and press
RETURN while the cursor is on. Notice the variable B$ ignores the
cursor.
CRSW
00 DO
PNT
OODl-OOD2
For example:
208
209-210
llZJ pm:::E 2QJ9 m
2(21 POKE 21 (:1 4
30 F'RINT "HERE I
Flag: INPUT or GET from key-
board. Normal value: O.
Pointer: Current screen line address.
POKEing this address can position
word output on the screen. This is
similar to using cursor controls, but
not as easy.
will print the string in Line 20 at the top left part of the screen.
Here's another program example that will show you the screen
address .
. l ::::
150 PRINl
[;'i r:.Ci'l
J (,i r;: 'r
:;:::1(:j hEll
:2 t"1
41
.; j
.1. .j
"'! ...:;.:
',::4!1
HEli F IlolL CL.IF;;I;[); r :.:,[1<:;:: E. {·I
200 SA = PEEK(209) +
i';1 j"·"Il.Ji·.,/F: [:L.Jf .. ": r F;: J L'jj-j T
" ii!::i h:C::diT "'; h: EdlT i(; + hit;
::'+ ()
I\IE j,T .l
PNTR
OOD3
QTSW
0004
LNMX
OOD5
211
212
213
Cursor column on current line. This
location stores the number of spaces
on a printed line, just like using the
BASIC command TAB(X) where X
would be the number of spaces you
want to move forward.
Flag: Editor in quote mode. 0 means
you are not in the quote mode.
Physical screen line length. Normal
default value: 39. POKEing this loca-
tion with a value less than 39 will
limit printed items on a line to that number by truncation and will NOT
be wrapped around.
42
210·214
This program is a demonstration. Line 20 makes a 40 character string
by adding the word to itself 4 times.
100 REM *** CONCATENATION ***
1 HI
120 PRINT CHR$CI47): REM - CLEAR SCREEN
130 REM - CONCATENATE A STRING
140 C$="BLIZZARD"
150 C$=C$+C$+C$+C$
16(21
170 REM - TRUNCATE STRING IN LOOP
180 FOR I = 32 TO 8 STEP -1
19!21 :
200 REM - SHORTEN PHYSICAL LINE LENGTH
21121 POKE213, I
22121
230 REM - EXAMINE STRING CONTENTS
24121
250 FOR C = 1 TO LENCC$)
26121
270 PRINTMID$(C$,C,I);
280
290 REM - PAUSE A MOMENT
300 FOR PAUSE = 1 TO 30: NEXT
320 REM - GET NEXT VALUES
33121 NEXT C
335 PRINT
34!2! NEXT I
TBLX
00D6 214 Current cursor physical line number.
Normal values: 0-24. POKE this
location with values from 0 to 255 to
move the cursor's vertical position.
43
This program will make two words, "SELECT' and "'LINE" scroll
up and down over each other.
'\ ~ t i
. .)
~ - : 1 .I.' ,.'
;'t ::, -(" )':......
,
.i I. J t:
rc:
;""l
, ,
1 ,'·t
... C ;: I i
!',,:!,
! 11.. ..
,I '.'
)'" I ,,) 1 ;---; i (:::.: 'i; .1.1 \ "
" I
1 ' . ~ ' .)
I ,
L .. L.I ...
~ - ;
• 1'-.-'1
I I_ .. ! I {\;'.!: , ! i ir:r" ..
.;r ;. J "J. , ,t· T I':
· . ..11-- 1 r C.l .i ;; f' !., l ;·.i i
.. L l,
iiI
i' ;
\, ' I l
I ,i. .1..31 ....
<i.
I-·IL.
I LJ ..::.1. ! .. ' I
44
,
....
i'.: ! ...
·i·:'i· '
'i-·-il... L!\
; :-: '!
'1 ,! I
0007
INSRT
0008
LDTBI
00 D9-OOF 2
215
216
217-242
214·254
Temporary data area.
Flag: Insert mode or the number of
inserts from u'le left on a given
PRINTed line. POKEing with a 0
turns off insert mode.
Screen line link table and also
temporarily used as a single editor
buffer in the immediate mode.
There are two ways of talking about lines in most computers. The line
you just worked with each time after pressing the RETURN key is the
logical line. Each line you see on the screen is a physical line. When a
logical line takes up more than that one physical line, those lines are
"linked" together and stored in a link table. The computer treats them as
if they were all one long line. These locations are where those links are
stored. To demonstrate how links can be used in a program, see the
'Alternate Screens' example under location 648.
USER
OOF3-00F4
KEYTAB
OOF5-00F6
RIBUF
OOF7-OOF8
ROBUF
00 F9-OO FA
FREKZP
OOFB-OOFE
243-244
245-246
247-248
249-250
251-254
Pointer: Current screen color RAM
location. This address points to the
area used to hold the colors for each
locations on the screen (see 55296 for
more information).
Vector: Keyboard decode table.
RS-232 input buffer pointer.
RE-232 output hutTer pointer.
Free zero-page space for user pro-
gram. This is a COMMODORE
f r e e b e e ~ These locations provide
four bytes out of the first page of memory so you can write your assembly
language routines in the zero-page indexed mode.
4"
""
BASZPT
OOFF 255 BASIC temporary data area.
Locations 256 to 511 are used by the microprocessor stack. If you're
programming in BASIC, you won't be using these locations.
01 00-0 10 A
BAD
0100-013E
013F-OIFF
BUF
0200-1258
256-266
256-318
319-511
512-600
Floating to string work area.
T ape input error log.
This area is used by the stack and
other system operations and is un-
available for other uses.
System INPUT buffer. This is where
the information goes when you type
on the computer. It only stays here
until the information is needed else-
where.
These next 3 locations also aren't that useful to the BASIC pro-
grammer. They store the parameters for channels OPENed and
accessed by Kemal routines. These behave in the same way as locations
184-186 except that they store all the file information and not just that of
the most recently opened channel. They each take up 10 bytes. This is
the limiting number of files you are allowed open at anyone time. More
on the Kema1 is shown in "Addressing the KERN AL".
LAT
0259-0262
FAT
0263-026C
SAT
0260..0276
601-610
611-620
621-630
Kemal table: Active logical file
numbers.
Kemal table: Device number for each
file.
Kemal table: Second address each
file.
46
KEYD
0277-0280 631-640
255·644
Keyboard buffer queue. This area is a,.
where characters typed in from the
keyboard are temporarily stored. If
characters are POKEd in here and location 198 (which holds the
number of characters in the buffer) is changed, it will be as if the
characters were typed from the keyboard.
The append routine at location 43 uses this location to make the
computer think something has been typed in.
MEMSTR
0281-0282
MEMSIZ
0283-0284
641-642
643-644
Pointer: Bottom of memory opera-
ting system. Normal value is 2048.
Pointer: Top of memory for operat-
ing system. Normal value is 40960.
These are important places! They control the amount of space you a
have to write programs. These values are set by the INPUT/OUTPUT ....
control register (location 1) during power-up and may be different with
each memory map configuration. Don't confuse these locations with the
ones that locate parts of the BASIC text (locations 43 thru 56).
There are lots of pointers used by BASIC to find out where the
computer stores the different parts of your program. Often, it's good for
you to know where, too. If you write programs that modify different
places in memory, this little program could be of help. It keeps track of
these pointer values.
100 PRINTCHR$(147l
1. .l iii DET FNT (>: ) Xi +:<:5,';H' tTl: ( X + 1"
12!::! Ph T ITT" STfihf til i'j'<:)::iFPd< " FI\iT ,li.:)
:.'" F'F: I [['ii) Oi FhClC.,j'.f<;l"i (,;'1D'
i. 4 U J" r:; I I\IT ., ;:', ;i. T LI i 'i II I . II C, L .. ..... .. .. ,j : : i: (,i::j)
['.:.:U f:'r;: I N'T" i .. EtjCiTH UF :',;CiC:,hf,i'j II
:l is ':i' F' h I 1\1 T .; F hi T ( 4 . FliT ( .:; :::::) J :; "UlT C ":::; "
1 ':';'(il F'J:;; I NT
1 I j,lT" [ND CF \)(IF: I (,bL..C:.. "
.[ 9;1i F'f\ I i'-lT" l=.Ii' j'-iF;Y(\'y:,
.. :UU I hiT
47
:::',".
, ~ : , '
TIM OUT
0285
COLOR
0286
, i i
1-1'·) i
645
646
>1 J '" ,- t ;- !'
~ ! \'''; 1 i·.':'i .' .'
.t:: ..{
Flag: Enable-disable serial IEEE
T.O.
Current character color ccxle. Nor-
mal power-up value: 14 (light
blue). Poke with values from 0 to
15, the character color code, to see cursor and characters change
color. Using this location is like using the color keys on the
keyboard.
GDCOL
0287
lllBASE
0288
647
648
Background color under cursor.
Bottom of screen memory (page).
This shows the normal location of the
screen in "pages", that is 256 byte
chunks. Normally set to 4. This is the top left comer of the screen. 4 x
256 = 1024 which is the beginning of the memory area for the screen.
You can use this information to create alternate screens and switch
back and forth. This program is a sample of what two screens could look
like.
48
100 ml'l DUAL. t3ChEFI'J bY ,J J Ivl BUTTF:FW I E:L .. D
105 REM TRANSL.ATED 64 BY PAUL PAVELKO
110
1 20 D I f1 L .. "I; i. ,?:::)
1 :30 GUSUH4,)(J: F'r;" 11',ITI,J-lfd ( 147) : hCihIIF{/j')()
140 Z ::)',::::CI'IF:t· ( 1
200 GETX$: IEX!=i$lHENGOSU8400
? .10 E'h' J I'n l:$; : CJIT\ U'?c)(,
4(H) f;:F1"1 SW JI CH
ill n J
420 IFS=4THENS=3?:
j'''l (,,:
440 SlOP:REM ERROR
::;,',.11' F'IJI<'E:f>4H. f-:'i'lf:::I::',: :, ::' /? '. F'F fJ F?) (IND 1 L. 1 .'
Uf;:T
1 0 CJ I;: ,)
\j:::::F'F:Ff:.: (,J +? j /) : I'IJI f ,j I::' J; • I. Z ",1 )
Nt :xT,J
F'F< 1 NT:
C!
Enter the program and run it. The screen will momentarily fill with
random characters. You are actually looking at a bit of memory! The
screen will clear and return to the original screen, Type in '"This is screen
one". Now press the f 1 key on the right side of the keyboard and the
screen will blank. Type "This is screen two". Press f1 and you're back to
screen one. This is called "Page Flipping". It is used for such things as
word proccessors and games.
XMAX
0289 649 The size of keyboard buffer, nor-
mally 10. POKEing this with values
from 0 to 255 controls the
number of characters the butTer can hold before it loses characters. This
isn't like location 198. If you POKE a zero here, the butTer can't hold any
letters. Nothing will print on the screen. Pressing RUN/STOP and
RESTORE will get you back to normal.
POKE 649,0
will disable the keyboard. Use this if you only want someone to use the
joystick or paddles for input.
49
POKE 649,10
returns the buffer to the standard size.
RPTFLG
.028A
650 Flag: REPEAT key used. POKE
650, 100: disables repeat of all keys.
POKE 650,255: enables repeat of
all keys. POKE 650,0: return to normal operation. Use this location
to help write graphics programs. As soon as you turn the computer on.
POKE 650,255 and drawing pictures becomes a lot easier when every
key repeats.
KOUNT
028B
DELAY
028C
SHFLAG
0280
651
652
653
Key Pressed
Shift
Commodore ( C:: )
CTRL (control)
Repeat speed counter. Normal value:
4 POKEing with values from 0 to 255
varies the time before keys repeat.
o and 255 will give the longest delay
times.
Repeat delay counter.
Flag: Keyboard shift key, CTRL key,
Commodore key (C:: ). This location
shows if these keys are being held
down.
Value in 653
I
2
4
If all 3 keys are pressed at the same time the value in 653 would be 7.
Since it would be unusual for all 3 keys to be down at the same time,
you could use this as safety stop.
See how this location changes with,
1m GET A $ ~ F'RINT PEEK (653) : IF Ali -- ,,/I THEN 1U
50
......
You can use the WAIT command to detect changes in these keys in the
same fashion as in location 197. Try these,
1. WAIT 653, 1,0 = > wait for shift
2. WAIT 653,2,0 => wait for C= key
3. WAIT 653,4,0 = > wait for CTRL key
; ' \:,.} I'h' T "/1.1 DL :,ThTlyT H J:, l'htJC3h:(:;I'I.,"
.,:: 1 () F·r;.: 1 hIT II HULi) ))IJl...Jl\i Till:: :3H I FT, 1:;CmTF;:DI. ,
220 F'h: I r" i2IND I III [IH'I!"ICJiJCih:F 1< t'r' h"
F=' R I r
F'R I NT "Tel f·'hCJI ...:)Riil"l, DU NIITI-111'Ki,,"
300 FOR PAUSE=j TO 300
::,1 Co IF f='FEf ::07 I HEN i ')(10
':.20 NEXT
F'h: 1 "F'RUC';FUil"j II
EhlD
1 noo F'f( J In
1010 F'h: I NT )'I-:.bl hell' FL'"
1 «:2 (0 N E:lLJ
LSTSHF
028E
KEYLOG
028F-0290
MODE
0291
AUTODN
0292
654
655-656
657
658
Last keyboard shift pattern.
Vector. keyboard table setup. Nor-
mal value: 60232
Flag: 0 = disable shift key, 128 =
enable. This doesn't tum the shift key
off and on, but will show a 128 if
CHR$(8) is entered and a 0 if
CHR$(9) is entered.
Flag: Auto-scroll down 0 = ON.
51
RS-232 LOCATIONS 659-670
Locations 659-670 will be used if you write programs that need to
communicate through the RS-232 port to other computers, printers etc.
Most BASIC programmers won't use these locations. Skip them if you
wish. If you do use these locations, remember the OPENing of an RS-
232 channel automatically allocates 512 bytes of memory for two
buffers which help prevent the loss of data when transmitting or receiving
RS-232 information.
If there is not enough free space beyond the end of your program, part
of your program will be destroyed to make room for the buffers. Be
careful!
MSICTR
0293
M51CDR
0294
MSIAJB
0295-0296
RSSTAT
0297
BITNUM
0298
659
660
661-662
663
664
RS-232: 6551 control register image.
RS-232: 6551 command register
image.
RS-232: Non-stantard BPS(time/2-
100). 661 and 662 contain the baud
rate for the start of the bit test during
the interface activity. This is used to
calculate baud rate.
RS-232: The RS-232 status register.
RS-232: Number of bits left to send.
52
BAUDOF
0299-029A
RIDBE
029B
RIDBS
029C
RODBS
0290
RODBE
029E
IRQTMP
029F-02AO
665-666
667
668
669
670
671-672
.....
. '
RS-232: Baud rate of full bit time.
Two bytes that are equal to the time of
one bit cell. (Based on system clock!
baud rate)
RS-232: Index to end of input buffer.
The byte index to the end of the
receiver FIFO buffer.
RS-232: Start of input buffer (Page).
The byte index to the end of start of
the receiver FIFO buffer.
RS-232: Start of output buffer
(Page). The byte index to the start of
the transmitter FIFO buffer.
RS-232: Index to end of output
buffer. The byte index to the end of
the transmitter FIFO buffer.
This temporarily holds IRQ vector
during INPUT or OUTPUT with a
cassette. If maskable interrupt is
generated during tape operation, this location holds the vector address
until the operation is over before servicing the interrupt.
ENABL
02Al 673 RS-232 Enables.
02A2 674 TOO Sense During Cassette I/O.
02A3 675 Temporary storage for cassette read.
02A4 676 Temporary DlIRQ indicator for
cassette read.
02A5 677 Temporary for line index.
02A6 678 P AL/ NTSC flag, 0 = NTSC, 1 =
PAL.
53
02A7-02FF 679-767 Unused.
IERROR
0300-0301 768-769 Vector: Print BASIC error message.
These address registers from 770 - 779 vector directly into the BASIC
ROM memory and run these routines to handle important interpreter
functions.
IMAIN
0302-0303
ICRNCH
0304-0305
IQPLOP
0306-0307
IGONE
0308-0309
IEVAL
030A-030B
SAREG
030C
SXREG
030D
SYREG
030E
STREG
030F
770-771
772-773
774-775
776-777
778-779
780
781
782
783
Vector: BASIC wann start.
Vector: Tokenize BASIC text
Vector: BASIC text LIST.
POKE 77 5 ,200 will prevent some-
one from LISTing your program after
it has been run. To restore LIST
POKE 775,167.
Vector: BASIC character dispatch.
Vector: BASIC token evaluation.
Storage for 6502 .A register. A,
Accumul ator.
Storage for 6502 .X register.
Storage for 6502 . Y register.
Storage for 6502 .SP register .SP,
Stack pointer.
54
.79· 7IJ
These locations shadow the 6502 internal registers. They are loaded
with values prior to a SYS command for passing infonnation on to
machine language routines or are at the system ROM routines in order to
achieve non-standard results. Here is an effective method for recording
and updating the current cursor positions. This can be used as a 'PLOT'
subroutine.
10 X=781 :Y=782 :P=78 3 :PLOT=65520
20 POkE P, 1 : REI-l SET CARRY FU·iG
30 SYS PLOT :REM KERNAL PLOT SUBROUTINE
40 F'R I t'H" CLJFmENT F'(]S I T I UN IS:"
50 PRINT PEEK(X);PEEk(Y)
10 X=781 :Y=782 :P=783 :PLOT=65520
20 I NF'I.JT" \.1m J n:: LU\::;: ::=3QF;: F'fY3. ( X, Y) " ;xp, YF'
::;:0 F'CifE F', 0 : h:EI '1 CLF{.ih: FLIiC..,
4 0 POkE X,XP :POkE Y,YP
::!U F'l_C)T : F;'[,"I F'I ... iJT T I Nt
hi) I NT" HI"
1 00 (1 ,,07 8U : X ::::'/fll : \= / [-32
110 PL.or h:E}1 f. [ f-;:t'-l (::;L F'Lor SLiB.
120 CI-lF';:UlJI:::-ct./:::;iF) (J: r';:Er-1 CI-IHCH.JT
Ph: I NT II II : F'OI:E X, (,
140 FOR YP :::: OT025
150 POkE P , O:REM CLEAR CAHRY FLAG
i t,O F'UI<F 'I, YF'
1 7 U Y j='L UT
i HC' F'O/:F. A REI"! hEN!) [lUTF'LIT CHAr:;: •
.1 90 C;HRUUT
;:'O(J hlE:X T YP
1 () {-i ::::: /bu
; :u : hit" f:.lh'hl?'iL bU\lKF,,' hULl,!
() := U 8 j.,: F: 1"1 '-_ (:-; F: T r 1\1 h: f::) IJ T E
,q. (! l' :,1" . ; H 1.3 L.
I F'FTf: . t. ,i ) .. I (\'FL.f:. ((,) J ,
,':-,(, I:;C:II ' . . 1 :,?u
55
The next three bytes store the information set by the USR(X)
command in BASIC. Altering their contents may be useful for passing
arguments in assembly routines.
USRPOK
0310
USRADD
0311-0312
0313
784
785-786
787
This byte stores the 6502 O{Tcode for
the jump instruction (JMP). Normal
value: 76 (4C-hex).
This is the low and high byte of the
USR(X) staliing address.
UNUSED
CINV
( ~ , 0314-0315
...
788-789 Vector: Hardware IRQ vector.
Default starting address where IRQ
(interrupt request) routines are ser-
viced. Normal value: 59953.
The stop key is in a safe place and isn't usually pressed by mistake. But
if you don't want people to accidentally stop your program while it's
running, you can turn off, (it's called "disable"), the RUN/ STOP key
this way:
POKE 788,52
This also stops the clock(TI$ and TI) so don't use this POKE if you need
the time functions in your program. POKE 788,49 turns on the clock and
will enable the RUN/STOP key. See location 808 for more information.
CBINV
0316-0317
NMINV
0318-0319
790-791
792-793
Vector: BRK instruction in terru pt
Vector: non-maskable interrupt.
Default starting address where the
56
: . ~ .. ~ . ~ . . ...-
" ";;1: , ' .
NMI routine is to be service. Normal
value 65095 .
This is the jump table to the starting address of the above Kemal
routines within the 8 K of Kemal. See in the appendix" Addressing the
Kemal " for a more detailed explanation of the Kernal operating system.
You can intercept these vectors for home made machine language
subroutines.
IOPEN
031 A-031 B 794-795 Kernal OPEN routine vector.
ICLOSE
031 C-031 D 796-797 Kernal CLOSE routine vector.
ICHKIN
031E-031F 798-799 Kernal CHKIN routine vector.
ICKOUT
0320-0321 800-801 Kernal CHKOUT routine vector.
ICLRCH
0322-0323 802-803 Kernal CLRCHN routine vector.
IBASIN
0324-0325 804-805 Kernal CHRIN routine vector.
IBSOUT
0326-0327 806-807 Kernal CHROUT routine vector.
ISTOP
0328-0329 808-809 Kernal STOP routine vector.

POKE 808,239
will disable the RUN/ STOP key without stopping the clock.
POKE 808,237
will enable the RUN/ STOP key.
57
POKE 808,225
will disable the RUN/STOP and RESTORE keys. Once your program
starts, there isn't any way to break out unless the program ends or this
line,
POKE 808,237
is run as part of the program.
IGETIN
032A-032B
ICLALL
032C-032D
USRCMD
032E-032F
810-811
812-813
814-815
KERNAL GETIN routine vector.
KERNAL CLALL routine vector.
User-defined vector. How this useful
address is used is completely up to
you! Here is an automatic line num-
bering routine using a defmed vector.
63993 INPUT"(CLR)STARTING LINE
INCREMENT";B:POKE815.B:PRINT"(CLR)"
63994 B=A/256:POKE784. (B-INT(B»*256:POKE
814.B:PRINTA;
63995 GETAS:PRINTAS;:IFAS<>CHRS(13)THEN63995
63996 PRINT"G063998":FORA=631T0634:POKEA.
145:NEXT
63997 POKEA.13:POKE636.13:POKE198.6:END
63998 PR INT" (uP) (uP) ": FORA= 1 T03: PRINT
":NEXT:PRINT" (UP) (UP) (UP) ";
63999 A=PEEK(784)+PEEK(814)*256+PEEK(815)
: GOT063994
When you run this, the words "starting line#" appear on the screen.
Enter the number you want for the first line number of your program.
1 000 would be a good start. Press return. Next, "increment" means how
many numbers between each line. 10 would be good here. Press return
and your program lines will be automatically numbered.
58
ILOAD
0330-0331
ISAVE
0332-0333
0334-033B
TBUFFR
033C-03FB
816-817
818-819
820-827
828-1019
"·1024
Kemal LOAD routine vector. Using
the SYS command and this location's
address starts LOAD operation on a
serial device. It automatically
LOADs the first program.
Kemal SAVE routine vector. Same
as above location except it works with
the SAVE command.
Unused.
Tape VO buffer. This is the first place
your cassette programs go when they
are being loaded.
It is also storage area #13,14 and 15 for sprite data. If you have a
sprite on the screen while loading another program from tape, expect
your sprite to look strange. This happens because the incoming data from
the tape changes the data for the sprite. The sprite must be redefmed. If
you use a cassette to save programs, sprite areas # 192 - 198 would be a
better place to put them. They will not be changed by using the cassette.
For information on storing sprites, see the appendix "Making a Sprite".
03 FC-03 FF
VICSCN
0400-07E7
1020-1023 Unused.
SCREEN DATA AREA
1024-2023 This is where data must be put to be ..
seen on the screen. The computer
does this automatically. You can do
this, too by using the POKE command. POKE 1024,81 will put a heart
in the upper left comer of the screen. POKE 55296,7 will make the heart
turn yellow. Each screen location from 1024 to 2023 has a matching
color location from 55296 to 5 6295. To make things you POKE onto the
screen any color you want and you must also POKE the color locations.
The screen is made up of 1000 locations, 25 rows of 40 columns. To
print a specific row and column, use this formula.
59
POSITION = 1024+-COLUMN NUMBER+40*ROW NUMBER
Here's a sample program that will print a cyan heart in the 4th row,
15 th column.
l ;:i,j :=:::;: I inCHI::;:!; .' i. ,+ -;)
l r::;:E;'1---1 U:>1. E; THE
120 OF
REM--SCREEN
1 5 t: ]"1-- == C.? [:-3 T ;'-IF:
"i (.J F\ E:: T T 0 f·=- [:F: E j'\1
.1 I)ATP,.
On the early 64's, any character POKEd to the screen would
automatically be white. It's been reported that this has been changed to
blue an newer machines. That means the POKEd characters would be
the same color as the backround. To make POKEs to the screen visible
POKE the color location too. Use:
COLOR POSITION = 55296+COLUMN NUMBER+40*ROW
NUMBER
.07F8-07FF
2040-2047 Sprite data pointers.
The sprite pointers tell the sprite-making part of the computer where to
go to get the information to make a sprite.
For example:
POKE 2040,13
This tells the computer that the data for sprite 0 can be found in the
13th block.
60
POKE 2043,192
This means data for sprite 3 is in the 192nd block. See the appendix
"How to Create a Sprite" for more information.
0800-9FFF 2048-40959 Your BASIC programs are stored
here. You can make the space smaller
by using locations 43 - 46.
This handy renumber routine checks the area inside this memory to
see where the line numbers are stored. Then it goes through and changes
all of them to make your program look neater.
Beware though, it doesn't change the line numbers after a GOTO or
GOSUB command. You will have to go back and do it by hand.
To renumber a program you have in memory, use the append routine
(locations 43-46) or follow these instructions.
1) Type in POKE43,PEEK(45)-2:POKE44,PEEK(46):CLR
2) Load in the renumber routine
3) POKE43,1 :POKE44,8
4) Type in RUN 10000 and press RETURN
9'19Qi END
10000 REM RENUMBER
10010 V6=2048:Y7=10
10020
10030 Yl3= I NT (Y7;' 2::;t.) : Y'?:::::'!'7 -2:=:;6*/8
:POKEY6+3,Y9:POKEY6+4,Y8
:[0(,40 I FP(::: EI< ':Y6+5) <OTHEI\I'{('::,=f6+1: CCJTD1U';i 4G
10050 Y7=Y7+10:Y6=Y6+5:80T010020
The next program is a" cruncher", that is, it combines man y program
lines into as few lines as possible. This could mean your program would
run a bit faster and take up less room in memory. It will also make your
program less readable. If you "crunch" a program, always save an
expanded version, too. It's much easier to find errors and make
corrections on an "un-crunched" program.
61
1 11\IFUT" eOl-m I NE L I rlES FFDI'1 TO"; L, U: :::>=2;;14'-;'
:S=256:E=PEEk(45)+B*PEEK(46)-4
2 :PRINTLT:
..:;, I FLT L TliENC=F'EH (C) +B*PEEi 1) : COTD:
4 I FL_ L>L THENPFd NT" LINE NOT FClijNO":: DID
5 L I i·ji=C C=C+4
60=PEEk(C).IFO:>0THENC=C+l:GOT06
I FPEEf (C +-1) +F'Ei:::i< (C +-2) =UTI-iErlEi'lIj
8
9 IFLT UTHENC=C+l:POkELINk,C-INT(C/8)
.8:POKELINK+l.C/B:GOT05
10 F'OI<EC. ( " " ) =C+ 1 TOE; Q=F'EEI< (c) +4)
11 POkEJ.G:NEXT:E=E-4:GOT06 a
To use this program, first load it in then use the method explained
above to hide it. Next, load in the program you want to "crunch".
Then POKE43,1 :POKE44,8 will allow you to see and use the
crunch program.
To save yourself time and trouble use the append routine.
8000-9FFF 32768-40959 VSP (Video/Sound Package) cart-
ridge ROM = > 8192 bytes.
The "Video/Sound Package" is a cartridge Commodore plans to
release that will make programming of sound and sprites easier. The
penalty is a loss of 8192 bytes of memory.
AOOO-BFFF 40960-49151 BASIC ROM => 8192 bytes (or
8K RAM).
This is where BASIC sits. By using location 1, it is possible to have the
computer temporarily pretend BASIC isn't around any more. Most of us
will never do something like that, but machine language programs might,
in order to have more room for longer programs.
So, in a way, we've come full circle from location 0 to 49151 which
points us back to the beginning again. OUf next section emh:l.rks on an
exploration of new territory - the powerful regions of Graphics and
Sound.
62
f f J [ [ J ~
U [ f J ~ ' -<'2
GRAPHICS
If you' re not familiar with bytes and bits, please read the very helpful
section on page 10 to 13. Sound and Graphics on the 64 require some
knowledge of bytes in order to control the power of the machine.
Hexadecimal
Decimal Loc. Bits Description
IX)()O- IX) 0 F
53248 Sprite 0 X position
53249 Sprite 0 Y position
53250 Sprite 1 X position
53251 Sprite 1 Y position
53252 Sprite 2 X position
53253 Sprite 2 Y position
53254 Sprite 3 X position
53255 Sprite 3 Y position
53256 Sprite 4 X position
53257 Sprite 4 Y position
53258 Sprite 5 X position
53259 Sprite 5 Y position
53260 Sprite 6 X position
53261 Sprite 6 Y position
53262 Sprite 7 X position
53263 Sprite 7 Y position
63
These are magic By changing them you can move up to eight
sprites across the screen with a FOR/NEXT loop.
:10\ Look at the description for sprite #0. The term "X position" means
the movement from left to right (or right to left) on the screen. "Y
position'" is movement up and down.
Here's a way to make programming easier. By calling the first address
by a variable name (V) for example, all the other graphic addresses can
be reached by adding an appropriate number. That makes it easy to
remember. For example, to move sprite #7 you could use V + 14 and
V+ 15 instead of 53262 and 53263.
This program creates a solid sprite. By setting V equal to 5 3 248 in line
140, all the other references to the graphics can be easily written. This
method of using variable names (like V or S or AI) for frequently used
numbers, will also speed up your program.
...... .....,' , .. - .- .'"
:.. \,.:r") )._ ._. I' -J::.:.:. 1"-';
- ._, --, ._.
;.,-_11", 1"-11"- , I 1. , __ -.;::. !,;"'!:..:...;' -, "
.-
i. -'T'-:.; J _.- ... • f_ ,:.1
:'._! -:. :-::.-- ,'"
\ .. ,"- ! ,';-, ! ,": \ .. 'i i <:.;'--i
... -. ,- "' "' , ..
C: .. :_. ::> -"-j- "
'L.:.I ; ---1 _ j"' __ l..:.j' .. j ! !. __•
i::'OI:E'/ +::::.l , i
•• ",1 r ':'
:.-' I.... L .1...'
"I,
"," ... : -,
RG1--SFF<In:: H(:'U=-(>JA\ AU:;lJi:;S SCFEEi·j.
F' 0 1 6
251) REM--SPRITE HALFWAY DOWN SCREEN.
::'60 F'OfE) + 1, 15U
The position of sprite is calculated from the top left comer of the 24 x
21 dot area that make up the unexpanded sprite. Even if only one dot is
used as a spri te, and you happen to want it in the middle of the screen, you
must still calculate the positioning by starting at the top left comer
location.
64
ro1O
53264 (V+ 16) Sprites 0 to 7 X position past position
256
Positioning in the horizontal direction is a little complicated. Even
though you have a 320 pixel wide screen for your sprite, if it moves past
the 256th pixel from the left (about eight-tenths of the way across the
screen) you need a ninth bit to describe the sprite's position, because a
byte can only hold a number up to 255.
When a sprite crosses the 256 dot "seam", the proper bit in this
location must be turned on. When crossing back, the bit must be turned
off.
For example when sprite 0 moves across the seam to the right:
POKE V+16, PEEK (V+16) OR 1
If sprite 4 crosses then
POKE V+16, PEEK (V+16) OR 16
To cross sprite 0 back to the LEFT
POKE V+16, PEEK (V+16) AND 254
Another thing to consider when positioning sprites is that they are
visible within certain limits even if you want to move them off screen.
These border parameters vary with dimensions of your display and
change when your sprites are expanded or unexpanded.
The best way to find the limits is to create a solid sprite and move it
back and forth. See the appendix "How To Create A Sprite".
roll
53265 (V+17)
7
6
5
4
3
2-0
VIC control register.
register compare: (8 bit) see 53266
extended color text mode: 1 = enable
bit-map mode: 1 = enable
blank screen to border color: I =
blank
select 24/25 row text display: 1 = 25
rows
smooth scroll to Y dot-position (0-8)
65
Most beginning programmers can skip this location. This description
will interest intermediate or advanced programmers. Think of this
register as the main control box for your graphics where each bit acts as
an on/otT switch for the graphics modes.
BIT 6 - EXTENDED COLOR MODE
In this mode, each character takes on a background color in addition to
the color of the character itself. Your screen color may be different, so for
example, you could have a white character with a green background on a
yellow screen. There is an important limitation in this mode. Since
memory out of your character code is used to determine this extra
background color, you are limited to the first 64 characters. See location
53270 for information on extended color modes.
BIT 5 - BIT MAP MODE
If you take a magnifying glass to your screen you'll see the countless
phosphor dots that comprise the pixels used to fill the screen with color.
This is the smallest increment of resolution that is available for graphics,
the bit map mode. The standard bit map mode gives you a 320 horizontal
dot by 200 vertical dot resolution, with a choice of two colors in each 8 by
8 bit character.
ENABLE HIGH-RESOLUTION BIT MAP MODE:
POKE 53265, PEEK(53265) OR 32
DISABLE HIGH-RESOLUTION BIT MAP MODE:
POKE 53265, PEEK(53265) AND 233
This example of bit mapping is a spiral drawn against a plain
background, First the screen \\rill go black, then slowly, the screen will
clear. Then a cyan background is produced and the spiral is plotted.
When it's finished a black square appears in the top left corner. Press
RUN/STOP and RESTORE to return to a normal screen.
66
1000 PRINT CHRt(147l
1 0 1 0 F' F: J hi T
10:,?() F'F: I hiT
1 (J:"!;O F'R I NT
1 040 F' F' J ("I T " l'.1 t 1 [N F I f( f:i I.. C,- J I' V 1 I:; [1.-( i'l I' L F T F., H
r:'hIhiT"BL(l[;t,: bl.iX lJ,jII. L (1F'I'Ef·,h' THE"
1 ()t,O F'h: I I'JT" UFPFT;.' LTTT I;CIHI,jFT',,"
1 010 1
1 i)UO F'F, 1 hIT" F:I . [UP f;.'C;I·UhE: ru"
J (')90 II'IT" F'E rei :;CHUJ,I"
1100 PCWE 1 9H , '., :: h'Ft'j HI (,c:!o
1 110 F'r:;: I NT
1 1'::::,) F'R I
1 1 PH 1 NT "PFI'!. {iI,I'y I L:Jru BU.:; I t-l"
11 "il) [JET (d,: : IF ?-'1:.1::::="" THEN 1140
1150 PRINT CHRt(147)
1160 REM-->PUT BIT MAP AT 8192
1170 BASE=2*4096:POKE53272,PEEK(53272)UR8
1180 BIT MAP MODE
1190 POKE 53265,PEEK(5326S)OR32
1200 • BIT "1AF
1210 FORI=BASE TO
1220 REM -)SET BACK. AND BORDER COLORS
1230 POKE 53280,3:REM BORDER TO CYAN
1240 FOR 1=1024 TO 2023:POKEI,1:NEXT
1 :::":=;O HEI·'I·CUH')E WI L .. L. i: 1 L I.. TilE:
1260 FOR B = OT017 BTE/30
1. Z70 x :0:; 1 :.=:; 0 + I T ( I. ",; un,.,.Y ( _.- I;: 0 ) I hi U:;; / ii >,
1280 Y=90-INT(120*EJP(-S!10)*LOS(S/2)!
1290 CH - INTeX/8)
I :300 FdJ 1 NT ('y / [) )
y (,I,ln;
j: I', (::' E' + h' U .• 2 U: I: 'f :.. i i + L N
1330 81 7-IX AND 7!
1 "(JI<[- F:Y, F EEi (F;y ! [ii.' J, :.3 I)
1 (": U hi r: J 1,
1360 FnKF 1024,16
"'/ 0 C; Ci'r [I j (I
Here's a fonnula to turn on and off individual pixels on the screen.
Keep in mind that the screen dimensions are 25 rows by 40 columns.
That means 1000 (25 X40) characters can be printed on the screen. Lets
call each one of these places a CHARACTER POSITION. Then this
fonnula is used to plot which pixel to turn on.
67
The character position nwnber is found this way:
CHARACTER POSITION = INT(XJS)*S+INT(Y/S)
X and Y are the horizontal and vertical positions of the pixel you want
to turn on. X will be number between 0 and 320. Y will be a number
between 0 and 190.
The row is found by:
ROW = (Y/S - INT(Y/S»*S
Therefore, the byte in which character memory dot (X, Y) is located is
calculated by,
BYTE = 1023 + CHAR*S + ROW
The bit to be modified is ..
BIT = 7 - (X-(INT(XJS)*S)
Finally, to turn on any bit...
POKE BYTE,PEEK(BYTE)OR(2t BIT)
BIT 4 - SCREEN BLANKING
You can hide anything printed on the screen by:
POKE 53265, PEEK(53265) AND 239
The screen will turn the same color as the border.
POKE 53265, PEEK(53265) OR 16
will make the screen visible again.
With this location you could turn off the screen then have
messages or graphics printed on the screen. Then "pop" the screen into
view all at once.
This program will:
1) Blank the screen
68
2) Print a message
3) Turn the screen back on
10 PRINTCHR$(147)
2i25 PR HH" HERE I At'l I "
PRINT"NOW l"LL GO
40 FOR PAUSE = 1 TO 1000: NEXT
50 POKE53265.PEEK(53265)AND 239
,Si25 F'R I NT
70 PRINT" I'M BAn: I"
80 FOR PAUSE = 1 TO 1000: NEXT
90 16
BIT 2-0 - SCROLLING
You can scroll screen information by moving the screen display in any
of four directions, moving as slow as 1 pixel ata time or as fast as 8 pixels.
When you do this, shrink your screen size from 40 to 38 columns wide
or from 25 to 24 rows tall depending on the direction you want to scroll.
This gives the computer a place to assemble the information before it
scrolls onto the screen.
To do truly fine scrolling you'll need a machine language routine.
Without that routine, scrolling can only be done with text or keyboard
characters.
1000 REM *****************************
1010 REM * PROTO SCROLL ROUTINE *
1020 REM *****************************
1iZ530
1040 DIM C(8,Sl:REM CHARACTER MATRIX
H550
1060 F:Ei1 SHRINK THE SCREEN
1070 POKE 53265.PEEK(S3265) AND 247
1080
1090 REM ») STORE CHARACTER INFO.
1100 FOR I = IT08
1110 FOR J = 1TOS
1 12iZ, READ C'; I • ,J )
11::::0 NEXT J, I
114U
69
CLEAR SCREEN/WHITE CURSOR
[160 PRINT CHR$(147) :CHR$(S)
l180 REM MOVE CURSOR TO BOTTOM
1190 FOR X = IT024:PRINTCHRs(17):NEXT
POSITION FOR 1ST SCROLL
1220 POKE53265.
1 :2:::-;)j
.[ :24!2i ;;,f::::'1
1:260 FOR L = lTOS
FOR- = OTO?
).;.
. ...: .. .:- '.':' ._' ....... ",;,..:.:"" .. ..:' ...::." .. ..:'.,:.:.
.[<:;',"U
:OAT?:'j
-:""'-, -: .. "'-.
.•.> . ...:- 'i .. ..:, .•::. 'I
..: .... :.. ,/
""":""l .••• ' .. :...."
-r.,--,
-'''':'':' 'f ".':' ...:... "
. -.... -., -,- ,-..
,._'",:"-,, ...•'....;... ..
'':1' :-', -:: ,,-:,
'-' . .:-" ',-' ,.:.. 'f
":r-.-,
. .... r- .......... , '":"" .-.., '-r "-',
.-'.':" 'i .. ' .,;,.". 'I .. ..:, •..::. ... ' ..:.. .... ' .. :..
._' .. :.. 'i ...• ' .. :.... 'I
.-'''':- "
..• '.L- -'""- <{ - -' '- q
':-r:-, -:r.-.
"-'.':"
.... , ... - ...... ,... ,.... "",:,,''''-, :"'" .-', -:r '-',
•..: •. >; . ..;, •• .. ..:, . .:..:.. ....:...::.
-r .--. .. .... - .
-'.':'" ., ', .. ' .,;.. ,-,...:.... "._' . ..:..
-:"" ,-". -7"" ''') '':'" ,'-, .. ..... ,
. ..:.. .;:. I, .. . ...:•. .:_ If '.":' ...:;' '! .-'''':- " .... ,..:...
-.. .-', ,"-:
-'.":'" .. . .:...., ..... ...:... ..
70
...,:' .. :...
IDII·... .
BIT 3 - 24/25 ROW SELECT
By POKEing this bit off you will make the screen 24 rows from top to
bottom, instead of the normal 25. This is used in the fine scrolling mode.
Half a row is taken from both the top and bottom of the screen. To see this
work
POKE 53265, PEEK (53265) AND 247
To get 24 rows
POKE 53265, PEEK (53265) OR 8
will return you to 25 rows.
ru12
53266 (V+18) Read/write raster value for compare.
Lower 8 bits out of9 bits (see location
53265).
The raster register is a dual purpose register. When you read this
register it returns the lower eight bits of the current raster position. The
raster position of the most significant bit is in location 53265. You use
the raster register to set up timing changes in your display for vertical and
horizontal band scrolling, mix-moded display (hi-resolution with char-
acters) and other kinds of interrupts.
The changes of your screen should be made when the raster is not in
the visible postion of the display area. The visible positions are those
between 5 I and 251.
rul3
53267 (V+19)
ru14
53268 (V+20)
Light-pen latch X position.
Light-pen latch Y position.
These locations return the light-pen X, Y positions across the screen
from 0 to 255. Interrupts can be generated when the pen is triggered.
rul5
53269 (V+21) Sprite display
When you want to make a sprite visible, this is the place!
71
~
....
Each bit handles a sprite, Sprite 0 is controlled by bit 0, sprite # 1 by
bit # 1 and so forth,
Here's how to make sprite #4 show on your screen:
POKE 53269, PEEK (53269) OR 16
POKE 53269, PEEK (53269) AND (255-16)
'Will make sprite #4, and only sprite 4, disappear.
POKE 53269, PEEK (53269) OR 170
will put sprites # 1, 3, 5, and 7 on the screen.
POKE 53269, PEEK (53269) AND (255-170)
will take them off.
IXl16
53270 (V+22)
7-6
5
4
3
2-0
VIC control register
unused
unused
multi-color mode: 1 = enable (text!
map)
select 39/40 column text: 1 =40 cols.
smooth scroll to X position
Here is another place that is used mainly by advanced graphics users.
It is an interesting location, but if you program in BASIC only,just take a
look at the changes you can make in the scrolling Proto. (Location
53265)
BIT 4 . MUl TICOlOR MODE
The multi-color mode for text is turned on by:
POKE 53270, PEEK (53270) OR 16
Turn it off with
POKE 53270, PEEK (53270) AND 239
72
II. • IJ270
Nonnally, each of the 1000 screen positions or " blocks" can have
only two colors, a background color and a text color. For example, when
the computer is turned on the background of each block is dark blue and
the text color is light blue.
POKEing this location gives you four colors to play with: screen color
(Ioc. 53281), and background colors 1 to 3 (Ioc. 53282-53284). But
there is a penalty, multi-color mode will work for only the first 64
characters in the character set, and it needs two bits to describe any of the
colors.
Like this:
. 0 000 •••
7 6 5 432 1 0
Each letter printed on the screen is really an 8x8 block of pixels with
some turned on and some off. The ones turned on are the letter you see. In
the sample row of pixels above, # 1, 4, 6 and 7 are on.
In the multi-color mode they are in pairs.
1eOl1oOl1oel1eil
~ ~ ~ ~
ABC D
The pattern" A" tells the computer to get the color from the back-
ground #2 (Ioc. 53283). B gets its information from background #0
(Ioc. 53281) which is the screen color). C indicates the color comes from
background # 1 (Ioc. 53282) and D gets its information from the color
memory area from 55296 to 56295 - different for each screen location.
Because of this "two-bit" reading of the data, your resolution will be
less than nonnal but you have more color available.
MULTICOLOR BIT MAP MODE
This uses two locations (53270 and 53265). The same principles of
"BIT PAIRS" are used here as in the mode described above.
Enable this with:
POKE 53270, PEEK (53270) OR 16
73
POKE 53265, PEEK (53265) OR 32
Remember, horizontal resolution is decreased.
BIT 3 - SELECT 38 OR 40 COLUMN MODE
1 = 40 COLUMN
POKE this bit to zero to narrow the screen area. That gives you space
on each side of the screen to assemble the characters before you scroll.
Doing this will keep the scrolling smooth.
BIT 2 . FINE SCROLLING
By adding
1365 POKE 53270, (PEEK (53270) and 248) + P
to the program in location 53265, you can make Proto scroll diagonally.
Again, to do truly fine scrolling you need a machine language routine.
The example under location 53265, written in BASIC, allows you to
scroll text and keyboard graphic characters only.
( ~
.. D017
53271 (V+23) Sprites 0 to 7 expand sprite 2 times
(vertically)
This location will make your sprites twice as large vertically. This has
a one-to-one correspondence, that is, turning on bit #0 expands sprite
#0.
POKE 53271, PEEK(53271) OR 1
To return sprite # to normal size:
POKE 53271, PEEK(53271) AND (255-1)
To expand sprites #7 and #1:
POKE 53271, PEEK (53271) OR 130
Also see location 53277.
74
D2Jt·SDft
IXl18
53272 (V+24)
~
VIC memory control register ...
7-4
3-1
video matrix base address (inside
VIC)
character dot-data base address (in
VIC)
This location is responsible for the location of both screen memory
and character memory.
POKE 53272,23
will convert the screen display to lower case.
POKE 53272,21
will change the screen display back to upper case.
Another example of the use of this address is seen in location 648, screen
flipping.
SCREEN MEMORY LOCATION
Screen memory location is controlled by the last four bits (most
significant nybble) of 53272. To move the screen, use the following:
POKE 53272, (PEEK(53272) AND 15) OR A
A must be one of the decimal values on this chart.
75
Location
A Decimal Hexadecimal
0 0 $0000
16 1024 $0400
32 2048 $0800
48 3072 $0 COO
64 4096 $1000
80 5120 $1400
96 6144 $1800
112 7168 $1 COO
128 8192 $2000
144 9216 $2400
160 10240 $2800
176 11264 $2 COO
192 12288 $3000
208 13312 $3400
224 14336 $3800
240 15360 $3 COO
Nonnally, A's value is 16, and the screen begins at 1024.
To create your own character set you modify bits 3 to l.
POKE 53272, (PEEK(53272) AND 240) OR B
where B is the decimal value from this chart.
VALUE
ofB DEC HEX
0 0 $0000-$07 FF
2 2048 $0800-$OFFF
4 4096 $1000 -$17FF
6 6144 $1800-$1 FFF
8 8192 $2000-$27 FF
10 10240 $2800-$2 FFF
12 12288 $3000-$37FF
14 14336 $3800-$3FFF
B is nonnally set to 4.
76
am·SIDS
See the appendix "Being an Artist on the Commodore 64" for an
example of creating your own character set.
IX)l9
53273 (V+25)
7
3
2
I
°
VIC interrupt flag register (bit= l:
IRQ)
set on any enable VIC IRQ condition
light-pen triggered IRQ flag
sprite vs sprite collision IRQ flag
sprite vs background collision IRQ fl
raster compare IRQ flag
This location is best handled with machine language since the values
here can change rapidly.
rolA
53274 (V+26) IRQ mask register: 1 = interrupt
enabled.
This location is set the same way as the location above. Unless the
corresponding bit in the interrupt enable register is set to a l, no interrupt
from that source will take place. Practice your machine code before using
thi
'
s.
rolB
53275 (V+27) Sprite vs background display priority: ...
1 = sprite.
With this location you can make a sprite pass in front or behind of
printed characters.
POKE 53275,2 PEEK(53275) OR 2
means sprite # 1 will pass behind text or graphics on the screen.
POKE 53275,7 PEEK (53275) OR 7
will do the same for sprites #0, 1 and 2.
POKE 53275, PEEK (53275) AND (255-7)
will put sprites #0, 1 and 2 in front of the text.
77
DOIC
53276 (V + 28) Sprites 0-7 multi-color mode select:
1= M.C.M.
You can create a sprite with up to 3 colors by PO KEing on this location.
POKE 53276,1
puts sprite #0 in the multicolor mode. The three color choices come from
the sprite color locations (53287 to 53294, depending on the sprite
number you're working with), and the sprite multicolor locations, 53285
and 53286,
See the appendix "How to Create a Sprite" for more i nfonnati on.
, / ~ ! L()ID
.-. 53277 (V+29) Sprites 0-7 expand sprite 2X (hori-
zontally).
Like 53271, this is the place used to expand a sprite, horizontally,
POKE 53277, PEEK (53277) OR I
will expand sprite 0, making it twice as wide.
POKE 53277, PEEK (53277) OR 18
will expand sprites 4 and 1. Also see location 53271.
DOlE
53278 (V+30) Sprite vs sprite collision detect.
If a sprite is touching another sprite, the bit for that sprite is turned on.
IF PEEK (V+30) = 1 THEN ACTION
is a typical use of this location. It asks if sprite 0 has bumped into another
sprite.
78
DDt·51211
Once you PEEK here, this register resets itself to zero. It's a good idea
to save the value here by putting it in a variable.
If PEEK (V+30) = 1 THEN B = 1
00IF
53279 (V+31) Sprite vs background collision detect.
This works just like the previous location, checking to see if a sprite has
bumped into some text or graphics. This register also resets to zero after
being read so if you need to save the value, use a variable.
If you PEEK (V + 31) and read 128 that means sprite #7 has bumped
into some characters.
0020
53280 (V+32) Border color. Normally set to 14
Poking the numbers from 0 to 15 here will change the border color. .-
This chart shows the number to POKE to get each color.
o
1
2
3
4
5
6
7
BLACK
WHITE
RED
CYAN
PURPLE
GREEN
BLUE
YELLOW
8 ORANGE
9 BROWN
10 Light RED
11 GREY 1
12 GREY 2
13 Light GREEN
14 Light BLUE
15 GREY 3
These numbers are used any time you work with colors.
53281 (V+33) Background color O.
True, this is called a background color, but it is also the screen color.
This location shows a 6 when the computer is turned on or RUN/STOP
and RESTORE are pressed.
This program will show you all the combinations of screen and border
colors.
79
..
100 PRINTCHR$(147)
110 FOR A= 0 TO 15
120 FOR B= 0 TO 15
1. 30
140 B
1.50 C:0:8
160
170 F'OfT646, c:+ 1
180 PRINTCHRt(19)
190 FOR D = 1 TO 12:PRINTCHRS(17);:NEXT D
200 F'Fi I NT" HEU.)]! "
210 FOR E =1 TO 300: NEXT E
220 NEXTB
T::t) NEXTA
53282 (V+34)
53283 (V+35)
53284 (V+36)
Background color 1.
Background color 2.
Background color 3.
These are the color registers used with the multi-color modes in
locations 53265 and 53270. POKE the numbers on the colors you want
to use. See location 53270.
IX)25-IX)26
53285 (V+37)
53286 (V+38)
Sprite multi-color register O.
Sprite multi-color register 1.
When the sprite multi-color mode (loc. 53276) has been selected the
colors in these registers are used in addition to the usual sprite color (loc.
53287-53294). See the appendix "How to Create a Sprite" for more
information .
IX)27-IX)2E
53287 (V+39) Sprite 0 color.
53288 (V+40) Sprite 1 color.
53289 (V+41) Sprite 2 color.
53290 (V+42) Sprite 3 color.
53291 (V+43) Sprite 4 color.
80
53292 (V+44)
53293 (V+45)
53294 (V+46)
Sprite 5 color.
Sprite 6 color.
Sprite 7 color.
These are the color registers for each sprite.
53281 • 53294
Each sprite has a "default" color, that is, if you don't POKE a color
for your sprite, the 64 will automatically give it a color.
Sprite Default Colors
0 White
1 Red
2 Cyan
3 Purple
4 Green
5 Blue
6 Yellow
7 Grey 2
81
SOUND
If you are new to sound programming, get ready to be amazed! The
Commodore 64 has sound capabilities unheard in other computers.
You need to use the BASIC commands PEEK and POKE to produce
sound, so if you're not sure what these commands do, just re-read the
sections "How to PEEK and POKE" and "BYTES and BITS" on
pages 6 to 13.
By calling the first address by a variable name (S), all other sound
addresses can be reached by adding all appropriate number,
10 LET S = 54272
It is also a good idea to clear the voices by POKEing all the sound
locations to zero, That keeps unwanted settings out of your program,
(") ( : ~ \.:.-1..:) F: I C' 'r C.J . , ~ ' : r : ~
: ~ \ n' F'ClI':T: C"I i. ~ \ .1
4 ' jl) I\IE \'1 J
VOICE # I REGISTERS
D400
54272 (S=54272)
D401
54273 (S+ 1)
Voice 1: frequency control, low-byte,
Voice 1: frequency control, high-
byte.
The values to POKE here to produce musical notes are in the note
table on page 175,
An example of values to POKE:
82
542n·54275
1 t, i () F·o\ 1.:.1!·:. r:: '/ _':::: '1 '/
,:' '.! " I:· i . .J r,. i: "I",:' .7 .,:', 'I 4
Produces a C note in the 5th octave. Not every sound you want to
make will be a musical note. To produce a frequency not on the musical
note table, use this program. It will give the numbers to POKE in the high
and low bytes.
10 PRINTCHR$(147)
:::0 I NF'UT II WH?-Yf DClYUU W(HH "; F 1
F 1 (F:t )
40 REM--COMPUTE HIGH BYTE
50 F2=INT(Fl!256)
60 REM--CUMF'UTE LOW BYTE
/ \' f=::';""F 1·· .. · (F2·"i-:2':.':.i6)
:=:0 II F'UkE: l...C)W ByTL
')c' I'h 11\1 r" F'CJhF HI C3H n'lTI:
D402
u •• ! J ; r" -"t'
..... _.-... !! ; F .:::
54274 (S+2) Voice 1: pulse waveform width, low-
byte
D403
54275 (S+3)
7-4
3-0
Voice 1: pulse waveform width.
unused
high-nybble
Another quality that is given to any frequency of the voice is how
distinct sound peaks are. This is how you produce tonal textures such as
vibrato (the vibrating aspect of sound that gives it a singing quality). This
is done with pulse waveform. The different types of waveforms are
discussed in the next register.
In location 54274, POKE a number in the range 0-255.
In location 54275, POKE a number between 0-15.
See the "airplane" program in the appendix for an example of pulse
waveform manipulation.
83
0404
54276 (S+4)
7
6
5
4
3
2
1
o
Voice 1: control register.
select random noise waveform
ON
select pulse waveform 1 =ON
select sawtooth waveform 1 = ON
select triangle waveform 1 = ON
test bit: 1 = disable oscillator 1
ring modulate osc. 1 with osc. 3
output 1 = ON
synchronize osc. 1 with osc. 3
frequency 1 = ON
gate bit: 1 = start attldec/sus
o = start release
This is the place! Here you can decide what kind of note you want to
create, from the muted sound of a violin to the crash of ocean surf. It all
depends on the type of waveform you choose.
Take a look at all the bits in this location. Bits 0,4,5,6 and 7 will be
used often by everyone. Bits 1, 2 and 3 are used for advanced sound
techniques.
Bit 0: This is the ON/OFF switch of voice one, but it should be used in
union with one of the waveform bits. When this bit is set to 1, the attack,
decay and sustain cycle begins. When it is poked with a 0, the release of
the note starts.
POKE 54276,17
will begin the ND/S cycle for the triangle waveform.
POKE 54276,16
will start the Release cycle.
The waveforms are designed to be used one at a time. You should try to
add two or more together to experiment.
Bit I: This bit, when turned on, will allow the interaction of voice 1 and
voice 3, blending both waveforms. To hear this, the frequency of voice
three should be lower than voice 1.
84
· ~
54176
Bit 2: The ring modulation effect creates the sounds of bells or gongs. It is
also used with voice 3. In order to hear the ring modulation, voice 1 must
use the triangle waveform and voice 3 must be set to a frequency higher
than zero.
Bit 3: This bit, if turned on, will reset voice 1 until it is POKEd back to
zero.
Bit 4: The triangle waveform is smooth and flute-like. The sound is made
by POKEing this bit and the gate bit on.
ON: POKE 54276,1 7
OFF: 54276,16
Bit 5: Listen to the brass sound of the sawtooth waveform.
ON: POKE 54376,33
OFF: POKE 54276,36
/1/1/1/1.
7 V V V V
Bit 6: The pulse waveform can be changed by using location 54275 to
vary the width of the pulse. You can create sounds from a piano to a
clarinet.
ON: POKE 54276,65
OFF: POKE 54276,64
FFfllr
85
Bit 7: The noise bit. Use this to make rocket blasts to surf sounds.
D405
54277 (S+5)
7-4
3-0
ON: POKE 54276,129
OFF: POKE 54276,128
Envelope generator 1: att/dec cycles.
select attack cycle duration: 0-15
select decay cycle duration: 0-15
The attack cycle is one of 4 parts that make up any note played by an
instrument. In the attack, the volume of the note rises to its highest
volume. Then it begins to 'decay' or fall in volume to lower level. Decay
is the second part of a note.
Some instruments, like a trumpet, have a fast attack. Others, like the
violin, have a very slow attack!
Here's an example of how to set both attack and decay.
1 () 0 h: F j-1 (\ I f.; r H t. {i T T Ii i. i Fi: T E: •
110 REM - IT CAN BE ANY NUMBER FROM
j 2(' m:J-I U TU 1
1 1+0 /)[1'1
.I :.:;() h: F: ,'1
D IS IHE DFCAY RATE .
IT CAN DE ANY NUMBER FRUM
1,,') h.i:::!"'1 _. (; Til i c;" -I e" i.
1 Hi,
:? J Ii F'I ..1f F ';-r,';, / l F' CE I:. ( ::.::i 4 2/ + D
This sets a medium attack and decay.
D406
54278 (S+6) Envelope generator 1: sus/reI cycles.
86
54276 • 54278
7-4
3-0
select sustain cycle duration: 0-15
select release cycle duration: 0-15
Sustain and release are the other parts of a sound. When a sound
decays, the volume falls to the sustain level. The volume stays at this
level until the release cycle begins.
Use bits 7-4 to set the sustain level from 0 to 15, zero would be the
lowest sustain, 15 is the highest sustain.
The release cycle starts the fall in volume from the sustain level to
zero. The release cycle follows an exponential curve that mimics the way
instruments that are blown or bowed actually respond.
Here's a sample program to produce a single tone.
j (l() f',Ft1
1 J (i I D:: 7."
I. Lt .. (, h' I H l I,' l. t .. > I ;::,'1 f. f ': :.' •
I':,;' fUh' .I" u Iii .• "
140 F'UI<I.. :3 J 1'+ J ,
1 ':'ie, NF>zT
J. b(l r':FI'i '-;I T 1111- ::1 i:i!I[c.:,j \'Cil L:I'IL •
1. 7()
lHO
1"7(;
F'Cif:..I:" I [H .• 4, 1. '.'
Fi:I' 1"1 [I H J : ... ; H .Ur T I ?iI'li)
iiI iT:iLI:
'?O(J F::tll UNE.
1. <) D 1 ::::Jj.
Z.:O I l).+ 1 1
.fll;.: f;yTL
I.: III \'(J 1
- THE .•
240 REM > A ATTACK; D DECAY
260 D:::: 1:: ..
27<) POKESID+5,A*16+D
280 -- t::ETTHI :3LJC;rrllN/F:FLEfY3C
2"70 REM > 6 = SUSTAIN; R = RELEASE
1
310 h:c""t(
320
::;30 PErl r 111:_ ,,{-:,( ... I T(JCJHI wr\')[TUF;:i'1
340 REM - AND TURN IT ON.
3'.:'10 F'OIE;-:; 1 1)+·4 ;:::.:::
87
360 REM > HOLD THE NOTE A WHILE
370 FOR PAUSE = 1 TO 128: NEXT
380 REM - START THE RELEASE CYCLE
390
The registers of voices 2 and 3 are handled in the same manner as
voice 1. There are a few differences in the voice control for ring
modulation and syncronization. The changes are marked in bold.
D407-D40D
54279 (S+7)
54280 (S+8)
54281 (S+9)
54282 (S+ 10)
54283 (S+ 11)
54284 (S+12)
7-4
3-D
7
6
5
4
3
2
o
7-4
3-D
VOICE #2 REGISTERS
Voice 2: frequency control, low-byte.
Voice 2: frequency control, high-
byte.
Voice 2: pulse waveform width, low-
byte.
Voice 2: pulse waveform width.
unused
high-nybble
Voice 2: control register.
select random noise waveform
l=ON
select pulse waveform 1 = ON
select sawtooth waveform 1 =ON
select triangle waveform I=ON
test bit: 1 =disable oscillator 1
ring modulate osc. 2 with osc. 1
output 1 = ON
synchronize osc. 2 with osc. 1
frequency 1 = ON
gate bit 1 = start att/dec/sus
O=start release
Envelope generator 2: att! dec
select attack cycle duation: 0-15
select decay cycle duration: 0-15
88
54285 (S+13)
D40E-D414
54286 (S+ 14)
54287 (S+ 15)
54288 (S+ 16)
54289 (S+18)
54290 (S+18)
54291 (S+19)
54292 (S+20)
54293 (S+21)
7-4
7-4
3-0
7
6
5
4
3
2
1
o
7-4
3-0
7-4
3-0
54278 • 54293
Envelope generator 2: sus/rei
select sustain cycle duation: 0-15
VOICE #3 REGISTERS
Voice 3: frequency control, lOW-byte.
Voice 3: frequency control, high-
byte.
Voice 3: pulse waveform width, low-
byte
Voice 3: pulse waveform width.
unused
high-nybble
Voice 3: control register.
select random noise waveform
l=ON
select pulse waveform l=ON
select sawtooth waveform 1 =ON
select triangle waveform 1 = ON
test bit: 1 =disable oscillator 1
ring modulate osc. 3 with osc. 2
output 1 = ON
synchronize osc. 3 with osc. 2
frequency 1 = ON
gate bit 1 = start attldec/sus
o = start release
Envelope generator 3: att/dec
select attack cycle duration: 0-15
select decay cycle duration: 0-15
Envelope generator 3: sus/rei
select sustain cycle duration: 0-15
select release cycle duration: 0-15
Filter cutoff frequency: low-nybble.
(bits 2-0)
89
54294 (S+22) Filter cutoff frequency: high-byte.
These locations set the cutoff frequency used by the filters.
For example, to make 1000 Hz the cutoff frequency:
POKE 54293,3
POKE 54294,232
In other words, (3 * 256) + 232 = 1000. Only numbers from 0 to 7 can
be POKEd in location 54293. The filtering location at 54296 will look
here to find the frequency to work with.
D417
54295 (S+23)
7-4
3
2
1
o
Filter resonance/voice input control.
select filter resonance: 0-15
filter external input: 1 = YES 0= NO
filter voice 3 output: 1 = YES 0= NO
filter voice 2 output: I=YES O=NO
filter voice 1 output: 1 = YES 0= NO
This is the switch box that turns on and off the filter for the voices you
select. To tum on the filter if "V" is the voice number:
POKE 54295. PEEK (54295) OR 2 t V
Example:
POKE 54295, PEEK (54295) OR 4
will tum on the filter for voice 2.
POKE 54295, PEEK (54295) AND (255-Vt 2)
turns off the filter.
POKE 54295, PEEK (54295) AND 251
turns off the filter for voice 2.
90
54294 • 54296
You can filter more that one voice at a time by turning on the proper
bits. The filter resonance area, bits 4-7, can make the voice sound either
sharp or dull. There are 15 possible resonance settings. To enter them let
R = the resonance desired.
POKE 54295, PEEK (54295) + (R * 16)
D418
54296 (S+24) Select filter mode and volume.
cut-off voice 3 output: 1 =OFF
select filter high-pass mode: 1 =ON
select filter band-pass mode: =ON
select filter low-pass mode: 1 =ON
select output volume:
7
6
5
4
3-D
o (off) - 15(max)
The volume of the sound is controlled here. Poke a number between 0
and 15.0 is off, 15 is the loudest volume. The volume is set the same for
all voices, so if you want one voice to sound louder than another, this
register will have to be rePOKEd every time you change the volume.
POKE 54296,15
sets the highest volume.
Bit 4: You tum on the low pass filter at bit 4 with:
POKE 54296, PEEK (54296) AND 16
This passes any frequency lower than the cut off set in location 54293
and 54294. The frequencies above the cut off are reduced in volume. The
higher the frequency, the greater the reduction in volume.
Bit 5: The high pass filter will pass on frequencies higher than the cut off.
Low frequencies will be lower in volume.
POKE 54296, PEEK (54246) AND 32
will start the high pass filter.
POKE 54296, PEEK (54296) AND 48
will start both the high pass and low pass filters. This is called a notch
91
reject filter. All frequencies except those near the cut oil will pass
through.
Bit 6: The bandpass filter is the opposite of the notch reject filter. It will
pass only frequencies near the cut oil.
POKE 54296, PEEK (54296) AND 64
\ViII tum it on.
Bit 7: Voice 3 can be set so its voice can't be sent to a speaker. This is
useful if you want to use the output of voice 3 in modulation with other
voices.
POKE 54296, PEEK (54296) AND 128
will tum off the output of voices.
D419-D41A
54297 (S+25)
54298 (S+26)
ND converter: game paddle 1 (0-
255).
NO converter: game paddle 2 (0-
255).
Games using paddles must use a machine language paddle routine
because of the complexity of the conversion from reading these
locations. See location 56320 for a machine language game paddle
routine.
D41B
54299 (S+27) Oscillator 3 random number gener-
ator.
This location produces a random number from 0 to 255 when voice 3
is set to the noise waveform.
D41C
54300 (S+28) Envelope generator 3 output.
If voiee 3 is turned on, this location will have digital output of the
NO/S/R "envelope" for voice 3. This can be added to the filter
frequency, for example, to produce a range of interesting sounds.
92
D500-D7FF
54528-55295
54296 - 56319
RESERVED FOR FUTURE VO
EXPANSION
Commodore has plans for this area ... someday. But until they do, this
would be a great place to put machine language programs.
D800-DBFF
55296-56319
SCREEN COLOR AREA
SCREEN COLOR CONTROL
RAM
(ONLY BITS 3-0 USED)
This area parallels the screen memory area 1024 to 2023. If you are
POKEing characters to the screen then you must also POKE the color of
the character here.
POKE 1024,83
puts a heart in the top left corner of the screen.
POKE 55296,2
will make it a red heart.
Here are the values to POKE into a color memory location to change a
character's color:
0 BLACK 8 ORANGE
1 WHITE 9 BROWN
2 RED 10 Light RED
3 CYAN II GREY I
4 PURPLE 12 GREY 2
5 GREEN 13 Light GREEN
6 BLUE 14 Light BLUE
7 YELLOW 15 GREY 3
This program will fill the screen with hearts, then use all the colors
available on the computer.
93
100 REM ******************************
110 REM * RANDOM COLOR HEARTS *
120 REM ******************************
13U
140 REM CLEAR SCREEN
150 PRINT CHR$(147)

170 REM START OF COLOR MEMOR\
:l80 I'HN = PET;: (243) + 2SI:J1"F'EEk (24Cl·)
190 MAX - MIN + 999
2i2ji2i
210 REM }} POKE HEARTS ONTO SCREN <
220 FOR H=1024 TO 2023:POkE H
240 REM }} TOGGLE THROUGH COLORS «
250 FOR CO=0 TO 15
26(j
270 REM }} POKE COLORS IN WITH
RANDOM INCREMENTS
31(,
NE/T COLOR TO PUKE IN
NE/ T Ci'i. CD

:::Si:i ,.:;: E ,'1 .'. FETUF:i·j TO
.. GO T!J :21 (J
94
56'It·56DI
COMPLEX INTERFACE ADAPTER
(CIA) #1
This is a pretty technical area. But in this high-tech world are the
controls for joysticks and paddles. See location 56321 if you wantto add
these routines to the programs you write.
DCOO
56320
DCOI
56321
7--0
7-6
4
3--0
7--0
7
6
4
3--0
PEEK at this address to read the
joystick at control port 2.
Data port A: keyboard, joystick,
paddles
write keyboard column values for
keyboard scan.
select paddle input port:
01=port A, lO=port B
joystick 2 fire button: 1 = fire
joystick 2 direction (0-15)
PEEK here to read the joystick
values at control port 1.
Data port B: keyboard, joystick,
paddles and lightpen
read keyboard row values for key-
board scan
timer B toggle/pulse output
timer A toggle/pulse output
joystick 1 fire button/lightpen trigger
(l = fire)
joystick 1 direction (0-15)
95
These two locations have a lot of work to do like scanning the keyboard
to see if a key has been pressed, and checking to see if a joystick, paddle
or lightpen is in use.
Plug your joystick into control port 1 and run this program.
110 READDR$(K):NEXT
12QJ DATA" II 71 !lSI! /II! 1I1\IW"
13Ql /I II IIEI), liSE"
140 PRINT"GOH.lG ••• ";
1 50 GOSUB2i21!2l
160 IFDR$ (JV) =""THEN 18iJ
17Ql F'RINTDR$(JV);" ";
180 IFFR=16THEN 150
19i21 PR I NT" ***F *** I ***R***E ***" : GOTO 15k":1
200 JV=PEEK(56321)
21Q1 FR=JVAND 16
220 JV=15-(JVAND15)
RETUF:r,1
Moving the joystick will print out the direction you're headed on the
screen. Press the fire button too.
Since the keyboard is scanned, these 4 keys will act as a "mock
joystick": the back arrow ( .... ), the CTRL, 1 and 2.
Run the program again and try these keys instead of the joystick. Some
combinations aren't allowed, like trying to go east and west at the same
time.
This is the compass rose that shows which direction the joystick is
pointed. Check these values for movement in your subroutines.
9
4 -
1..... -8
10
2
96
C::
56321· 563n
A machine language routine is needed to check the paddles because of
the complexity of reading them.
The values in each location range from 0 to 255 depending on the
rotation of the paddles.
100 PRINTCHR$(147)
11 C= .12*4(196
120 FORI=0T063:READA:POKEC+I,A:NEXT
1 SYS C
140 P1=PEEK(C+257l
150 P2=PEEK(C+2581
160 P3=PEEK(C+259)
170 P4=PEEK(C+260)
180 W1=PEEK(C+261):W2=PEEk(C+262)
190 PRINTP1,P2,P3.P4
PR I NT: PF: IIH" F I F:E A" Wi, "F I RE B";
210 FORW=IT050:NEXT
220 PRINTCHR$(19):GOTO 130
230 DATA 193
240 DATA
25kl

DATA
DATA
128.141.0.220.160,128,234,136
300 DATA 141.2.220.173
310 DATA 1.220. 19 3.88.96
When plugged into port 1, the paddles are read at (C+257) and
(C+259) and the fire button is read at (C+262). The value in (C+ 262)
will change depending on which fire button is pressed or if both are
pressed at the same time.
Paddles in port 2 are read at (C + 258) and (C + 260). The fire button is
(C+261). It is read the same way indicated above.
D0)2
56322 Data direction register, port A
97
C::
Dan
56323 Data direction register, port B
Nonnal values for each, 241
These are the data direction bytes for the control port registers. When
a bit is set to one, that means that the port is receiving input. A zero turns
on that bit for output.
Bit 5 is not counted because line five carries voltage. These data
direction registers must be POKEd before you set the proper values of
the control registers.
DC04
56324 Timer A low-byte
DC05
56325 Timer A high-byte
DC06
56326 Timer B: low-byte
DC07
56327 Timer B: high-byte
Both CIA chips have two powerful 16-bit timing devices. They can be
used to time various waveforms, pulse widths and frequencies for
internal and external signal generation. These timers can be used
individually or linked together to expanded timing durations. These
registers are read in BCD (binary-coded decimal), each nybble describes
a digit in the timer value. BCD fonnat is faster for VO operations.
DC08
56328
DC09
56329
DCOA
56330
DCOB
56331
7
Time-of-day clock: 1/10 seconds
Time-of-day clock: seconds
Time-of-day clock: minutes
Time-of-day clock: hours
AM/PM flag
98
56123· S63ll
These four registers store a real-time AMIPM TOO, time-of-day clock.
This is another programmable CIA timing feature which, when read,
returns the respective TOO values. When written to (via setting bit 7 in
control register 56335), these values latch on the ALARM. This
programmable alarm allows the CIA to generate an interrupt at a
specified time. Only the MSB (most significant bit) ofthe hours register
is used to specify AM or PM. The values must be latched in one at a time
starting with the hours register and the clock will not start until the 1/ 10
sec. register is set. This ensures that the proper time is specified.
DCOC
56332 Synchronous serial I/O data buffer.
This register stores the values of the serial port which is a buffered, 8-bit
synchronous shift register system. With every eight clock counts (eNT),
the shift register deposits a value in this register. The clock counts are
generated by TIMER A which is also used as a baud rate generator.
After eight clock counts an interrupt is enabled to send for more data.
This constitutes a double-buffered I/O system where the micro-
processor stays one byte ahead of the shift register which stays a byte
ahead of the serial port buffer. This lets you load new data on the serial
bus before the shift register clears.
DCOD
56333
7
4
3
2
1
o
CIA interrupt control: read IRQsI
write mask (to IRQ)
IRQ flag (l=IRQ occurred)/set-
clear flag
FLAG 1 IRQ (cassette read! serial
IEEE SRQ input)
serial port interrupt
time-of-day clock alarm interrupt
timer B underflow interrupt
timer A underflow interrupt
This is the register that contains the interrupt and masking information
for the five sources of interrupts from the 6526. These interrupts are the
underflow from TIMER A, the underflow from TIMER B, TOD
ALARM, FLAG and serial port fulVempty conditions. When read, this
location becomes a data register which accepts the interrupts being
generated. When written to, this location creates a mask for the IRQ line
which provides selective control over the interrupt system. If bit 7 is
99
zeroed, any mask bit which is on (1) is cleared while off bits are sent
through.
DCOE
56334
7
6
5
4
3
2
o
CIA control register timer A
time-of day clock frequency:
1 =50Hz, 0=60Hz
serial port I/O mode: 1 = output,
O=input
timer A counts: 1 = CNT signals,
0= system 02 clock
force load timer A: 1 = Yes
timer A run mode: 1 =one-shot,
0= continuous
timer A output mode to PB6:
I =toggie, O=pulse
timer A output on PB6: l=Yes,
O=No
start! stop timer A; 1 = start, 0= stop
This is the control register for the internal TIMER A and the TOD
clock talked about under locations 56324 thru 56331.
(BIT 0) START - This bit enables and disables TIMER A. When an
underflow condition occurs in the one-shot mode, this bit is auto-
matically reset.
(BITt) PBON - When on, this bit allows the timer output of A to appear
on Port B.
(BIT 2) OUTMODE - This allows the ouputofPORT B to eithertoggie
(flip on and oft) or pulse singly over one cycle duration.
(BIT 3) RUNMODE - This chooses the one-shot or continuous modes.
In the one-shot mode, the timer will count down to zero from the value
latched into it, enable an interrupt, and then stop. In continuous mode,
the value is re-Iatched and done again.
(BIT 4) INMODE - This bit controls which clock is used to decrement
the timer; either the 02 clock pulses or the external pulses applied to the
count (CNT) pin.
100
56»]·56577
(BIT 6) SPMODE - This bit controls how TIMER A clocks the serial
bus. When one, the timer writes out to the serial bus. When zero, the
serial bus provides input.
(BIT 7) TODIN - Sets the TOD pin for accurate time.
DCOF
56335
7
CIA control register timer B
set alann/TOD clock
1 = alarm, O=clock
This is the same register for TIMER B with the exception of bits 5 and
6. These bit pairs are used for timer count transitions and extended timer
use (using both timers together).
COMPLEX INTERFACE ADAPTER
(CIA) #2
DDOO
56576
7
6
5
4
3
2
1-0
Data port A (serial IEEE, RS-232,
VIC memory control).
serial IEEE data input
serial IEEE clock pulse input
serial IEEE data output
serial IEEE clock pulse output
serial IEEE A TN signal output
RS-232 data output (user port)
VIC chip system memory bank select
This multi-functional register controls video bank-select, and is the
control register when an IEEE-488 interface is present on the expansion
port. This register must be set in correspondence with its data direction
register (56578).
DDOI
56577
7
6
5
Data port B (user port, RS-232)
user / RS-232 data set ready
user / RS232 clear to send
user
101
4
3
2
1
o
user / RS-232 carrier detect
user / RS-232 ring indicator
user / RS-232 data tenninal ready
user / RS-232 request to send
user / RS-232 received data
user / RS-232 receive: start-bit (IRQ
flag)
Similar to location DDOO, this register returns values of user PORT B.
It also handles the RS-232 connection. This register, too, must be
POKEd in conjunction with its data direction register(56579) to achieve
results.
The following registers behave the same as on CIA #1. Both 6526
chips have identical timing and clock capabilities.
DD02
56578
DD03
56579
DD04
56580
DD05
56581
DD06
56582
DD07
56583
DD08
56584
DD09
56585
THE FOLLOWING LOCATION DECRIPTIONS
APPLY FROM CIA # I
Data direction register, port A
Data direction register, port B
Timer A low-byte
Timer A low-byte
Timer B: high-byte
Timer B: high-byte
Time-of-day clock: 1/10 seconds
Time-of-day clock: seconds
102
DDOA
56586
DDOB
56587
DDOC
56588
DDOD
56589
7
4
3
2
1
0
DDOE
56590
DDOF
56591
DEOO-DEFF
56832-57087
DFOO-DFFF
57088-57343
56577· 57M3
Time-of-day clock: minutes
Time-of-day clock: hours
AM/PM flag (bit 7)
Synchronous serial VO data buffer.
CIA interrupt control: read NMIs/
write mask (to IRQ)
IRQ flag (1 = > IRQ occurred) / set-
clear flag
FLAG 1 IRQ: cassette read! serial
IEEE SRQ input
serial port interrupt
time-of-day clock alarm interrupt
timer B underflow interrupt
timer A underflow interrupt
CIA control register A, same as CIA
1
CIA control register B, same as CIA
1
RESERVED FOR FUTURE VO
EXPANSION
RESERVED FOR FUTURE VO
EXPANSION
103
104
APPENDICES
105
RE-CONFIGURING
THE MEMORY MAP
With the COMMODORE 64 you get more than one kind of machine.
You have the ability to rearrange sections of memory into eight different
memory maps.
Admittedly, this isn't for the novice, but if you are the kind of
programmer that can make a computer dance, the 64 will do a fine jig.
There are 8 memory map possibilities. Here's a chart:
£000
DOOO
COOO
AOOO
8000
4000
0000
Map #1
8K KERNAL ROM
4K 110
4K RAM (BUFFER)
8K BASIC ROM
8KRAM
16K RAM
USER
RAM
16K RAM
f-----------
LOWER ADDRESS
SYSTEM
106
x = Don't Care
0= OFF
1 = ON
110 expansion (disk)
110 expansion (CP/M)
CIA #2 memory
CIA # I memory
Color RAM
SID memory
VIC memory
Normal power up memory
map. It gives the user 38K for
programming.
LORAM= 0
lllRAM= 1
GAME = 1
EXROM= X
EOOO
DOOO
COOO
8000
4000
0000
EOOO
DOOO
COOO
8000
4000
0000
Map #2
8KRAM
4K I/O
4KRAM
16K RAM
16K RAM
16K RAM
Map #3
8K KERNAL ROM
4K I/O
4KRAM
16K RAM
16K RAM
16K RAM
107
60K RAM for VO devices w/o
system routines.
LORAN = 1
lllRAM=O
GAME = 10rO
meROM = x
52K for VO devices and other
languages including CP/M.
LORAM= 0
lllRAM= 1
GAME = 1
EXROM= X
cooo
8000
4000
0000
EOOO
0000
cooo
AOOO
8000
4000
0000
Map #4
16K RAM
16K RAM
16K RAM
16K RAM
Map #5
8K KERNAL ROM
4K VO
4K RAM (BUFFER)
8K BASIC ROM
8K ROM CARTRIDGE
(BASIC EXP)
16K RAM
16K RAM
108
Full 64K free RAM. No VO
operators can be done here.
LORAM= 0
IDRAM= 0
GAME = 1 or X
EXROM= XorO
32K RAM for BASIC user
with 8K taken up for expansion
cartridges.
LORAM = 1
IDRAM= 1
GAME = 0
EXROM= 0
EOOO
DOOO
COOO
AOOO
8000
4000
0000
EOOO
DOOO
COOO
8000
4000
0000
: LI1:'1 - H
Map # 6
8K KERNAL ROM
4KUO
4K RAM (BUFFER)
8K ROM CARTRIDGE
_ .
8KRAM
16K RAM
16K RAM
Map #7
8K KERNAL ROM
4KUO
4K RAM (BUFFER)
16K ROM (CARTRIDGE)
16K RAM
16K RAM
109
40K of user RAM with 8K of
expansion ROM that does not
reduce BASIC.
LORAM= 0
HIRAM = 1
GAME = 0
EXROM= 0
Same as Map #6 except that
32K is for the user and 16K
ROM for expansion.
LORAN = X
HIRAM = X
GAME = 0
EXROM= 1
EOOO
DOOO
AOOO
1000
Map #8
8K CARTRIDGE ROM
4KVO
4K OPEN
8K OPEN
8K CARTRIDGE ROM
16K OPEN
12K OPEN
4KRAM
This configuration is used for
the UL TIMAX video game
cartridges so that they are com-
patible on the Commodore 64.
You have the capability of flipping some of these memory sections in
and out, freeing that area for other uses such as free RAM for
programming. Second, you can internally re-locate some smaller
sections such as screen and character memories (see loco 648). This
gives flexibility to several kinds of programming environments.
For example, locations 0 and 1 in the memory show how to switch the
3 important ROMS, the KERNAL, BASIC and the Character Gener-
ator in and out. This is done by the lower three bits of location 1. This
location is actually the control register for some of the processor's (6510)
addressing lines.
You can even move BASIC into RAM and make your own modi-
fications to it
There are other addressing lines monitored by location 1 which are
connected to the expansion port that you have no control over (at least
not with software). These lines automatically reconfigure the memory
map to the specifications determined by what expansion cartridge is in
use. The cartridge could be a game or word processor, for example.
110
ROM MEMORY MAP
To start out with, the BASIC and KERNAL ROMs share the 64K
addressing space. This means that while your ROMs are present upon
turning on the computer, there is still the RAM hidden 'behind' it. When
you read this area, you get the contents of the ROM routines. If, however
you write to it. your information is stored in the RAM behind it. This is
convenient if you want to store something in this RAM, but how can you
get to it? The solution is to flip out any or all of the ROMs present in the
overall memory configuration using the Commodore 64's impressive
'bank-switching' feature (see loc. 1). You can free up to 16K ROM
memory this way and this amount of memory for extra RAM.
WHAT IS INSIDE THE BASIC
AND KERNAL ROMS?
Let's start with the BASIC interpreter which everyone gets auto-
matically when they tum on their Commodore 64. An interpreter is a
large library of routines and subroutines which break down the BASIC
commands (tokens) and execute the proper functions in machine code.
An interpreter is different from a compiler which must methodically
break down the 'source code' several times (passes) to be reconstructed
in another binary 'object code' file. An interpreter, while not as efficient
as a compiler, is certainly a lot easier to use because you don't need
to wait each time for a compilation process (which can take several
III
minutes) each time you debug your program. In addition, the interpreter
accepts and processes most of the commands that you execute directly
into the computer in the 'immediate mode'.
The Kemal is a similar bag of tricks. It is a miniature operation system,
not as versatile as the BASIC interperter, but built for speed and
efficiency of operation. This is useful if you need to write machine
routines and you do not want to re-invent the wheel, that is, constantly
writing the same input or output routines. Just use the built-in KERNAL
subroutines.
When you use BASIC, the computer "automatically" knows what to
do with what you wrote and where to go to get the information. The
KERNAL, however, isn't so automatic. There are certain "calling"
procedures that must be followed. "'Calling" means setting up the
information the KERNAL routine needs to have before the routine can
be used. See Commodore's "Programmers Reference Guide" for the
correct calling procedures for each KERNAL routine.
The list of locations in this section contain the starting address of all
the BASIC Interpreter and Kemal operating system routines. They are
important to know because you can change them or at least alter their
inputs to non-standard results. You can map all or just a section of these
ROM routines with this FOR/NEXT loop. For instance, to map
BASIC into RAM:
FOR 1= 40960 TO 49151: POKE I,!: NEXT I
That's right. Youjust POKE an area with its own c o n t e n t s ~ Remember
you must take out the ROM when you are done so that you can read the
RAM. Take the ROM out of operation. You can change the ROM
routines if you wish. You can modify or even create your own BASIC.
A few last things to note. First, the sharp-eyed reader will take notice
of the fact that a number of BASIC ROM routines are in the Kemal8K
section. As a result, if you rid yourself of the Kemal, your BASIC will
not function normally. Second, the ROM memory map locations are not
all in chronological order. This is to consolidate certain routines which
are used together.
112
THE KERNAL
The Kemal is Commodore's name for a table of standard subroutines.
Everything that goes in or out of the computer uses these routines.
If you write programs in machine language, the list of routines here will
enable you to use some of the power of the machine instead of writing
your own. These locations can be called by BASIC using the 'SYS'
command after loading locations 780-783 with necessary inputs. (see
program)
The Kemal is like a wall between you and the inner workings of the
operating system. These routines are like doors in the wall, allowing you
to use different parts of the system. Advanced programmers may want to
cut some windows in the wall to get to some of the subroutines that the
Kemal uses. Don't do this. Commodore is noted for ROM upgrades,
which means they will rebuild that wall. They promise to keep the doors,
but the windows will be gone!
Here is a brief summary of the Kemal routines.
Label
Hex. Addr. Dec. Loc. Description
ACPTR
FFAS 65445 Input byte from serial port.
CHKIN
FFC6 65478 Open channel for input.
CHKOUT
FFC9 65481 Open channel for output.
CHRIN
FFCF 65487 Input character from channel.
CHROUT
FFD2 65490 Output character to channel.
ClOUT
FFA8 65448 Output byte to serial port.
CINT
FF81 65409 Initialize screen.
113
CLALL
FFE7 65511 Close all channels and files.
CLOSE
FFC3 65475 Close a specified logical file.
CLRCHN
FFCC 65484 Close input and output channels.
GETIN
FFE4 65508 Get character from keyboard butTer.
IOBASE
FFF3 65523 Returns base address of 1/0 device.
IOINIT
FF84 65412 Initialize input! output.
LISTEN
FFBl 65457 Command serial bus device to
LISTEN.
LOAD
FFD5 65493 Load RAM from a device.
MEMBOT
FF9C 65436 Read/set the bottom of memory.
MEMTOP
FF99 65433 Read/set the top of memory.
OPEN
FFCO 65472 Open a logical file.
PLOT
FFFO 65520 Read/set X,Y cursor position.
RAMTAS
FF87 65415 Initialize RAM, allocate tape butTer.
set screen $0400.
RDTIM
FFDE 65502 Read real time clock.
114
~ ~ _ ...... c
. -
READST
FFB7 65463 Read I/O status word.
RESTOR
FF8A 65418 Restore default 110 vectors.
SAVE
FFD8 65496 Save RAM to device.
SCNKEY
FF9F 65439 Scan keyboard.
SCREEN
FFED 65517 Return X, Y organization of screen.
SECOND
FF93 65427 Send secondary address after
LISTEN.
SETLFS
FFBA 65466 Send logical-file, device, secondary
address.
SETMSG
FF90 65424 Control Kernal messages.
SETNAM
FFBD 65469 Set file name.
SETTIM
FFDB 65499 Set real time 'jiffy' clock.
SETTMO
FFA2 65442 Set timeout on serial bus.
STOP
FFE1 65505 Scan stop key.
TALK
FFB4 65460 Command serial bus device to
TALK.
TKSA
FF96 65430 Send secondary address after TALK.
liS
UDTIM
FFEA 65514 Increment real time clock.
UNLSN
FFAE 65454 Command serial bus device to
UNLISTEN.
UNTLK
FFAB 65451 Command serial bus device to
UNTALK.
VECTOR
FF8D 65421 Read/set vectored I/O.
116
BASIC ROM ROUTINE
STARTING ADDRESSES
D 0
This list of ROM addresses was published by Commodore in the
October/November 1982 issue of their magazine. According to some
sources, a few of the routines listed here have been changed. Try these
first to see if what you want to do will work. For detailed information, you
should contact customer service at Commodore either through regular
mail or electronic mail on Compuserve.
One location you should try is 64738. By using the command SYS
64738, the 64 will reset itself and display the same message as if you had
just turned on the computer. This is called a 'cold start'. It's just like
turning the computer off and then on again. Everything is set to its default
value and any program in the computer is destroyed. This SYS will save
wear and tear on the switch and the power supply.
HEX DEC. ROUTINE
AOOO 40960 ROM control
AOOC 40972 Keyword action vectors
A052 41042 Function vectors
A080 41088 Operator vectors
A09E 41118 Keywords
A19E 41374 Error messages
A328 41768 Error message vectors
A365 41829 Misc. messages
A38A 41866 Scan stack for FOR/GOSUB
A300 41912 Move memory
A3FB 41979 Check stack depth
A408 41992 Check memory space
A435 42037 *out of memory*
A437 42039 Error routine
A469 42089 BREAK entry
A474 42100 *ready*
A480 42112 Ready for BASIC
A49C 42140 Handle new line
A533 42291 Re-chain lines
A560 42336 Receive input line
A579 42361 Crunch tokens
A613 42515 Find BASIC line
A642 42562 Perform [NEW]
117
A65E 42590 Perfonn [CLR]
A68E 42638 Backup text pointer
A69C 42654 Perfonn [LIST]
A742 42818 Perfonn [FOR]
A7ED 42989 Execute statement
A81D 43037 Perfonn [RESTORE)
A82C 43052 Break
A82F 43055 Perfonn [STOP)
A831 43057 Perfonn [END]
A857 43095 Perfonn [CONT]
A871 43121 Perfonn [RUN]
A883 43139 Perfonn [GOSUB]
A8AO 43168 Perfonn [GOTO]
A8D2 43218 Perfonn [RETURN]
A8F8 43256 Perfonn [DATA]
A906 43270 Scan for next statement
A928 43304 Perfonn [IF]
A93B 43323 Perfonn [REM]
A94B 43339 Perfonn [ON]
A96B 43371 Get fixed point number
A9AS 43429 Perfonn [LET]
AA80 43648 Perfonn [INPUT#]
AA86 43654 Perfonn [CMD]
AAAO 43680 Perfonn [PRINT)
ABlE 43806 Print string fonn (y.a)
AB3B 43835 Print fonnat character
AB4D 43853 Bad input routine
AB7B 43899 Perfonn [GET]
ABAS 43941 Perfonn [INPUT# 1
ABBF 43967 Perfonn [INPUT]
ABF9 44025 Prompt & input
AC06 44041 Perfonn [READ]
ACFC 44284 Input error messages
ADIE 44318 Perfonn [NEXT]
AD78 44408 Type match check
AD9E 44446 Evaluate expression
AEA8 44712 Constant - Pi
AEFI 44785 Evaluate within brackets
AEF7 44791
* ) *
AEFF 44799 comma ..
AF08 44808 Syntax error
AF14 44820 Check range
AF28 44840 Search for variable
118
AFA7 44967 Setup FN reference
AFE6 44790 Perfonn [OR]
AFE9 45033 Perfonn [AND]
B016 45078 Compare
B081 45185 Perfonn [DIM]
B08B 45195 Locate variable
Bl13 45331 Check alphabetic
B11D 45341 Create variable
B194 45460 Array pointer subroutine
BIAS 45477 Value 32768
B1B2 45490 Float-fixed
B1D1 45521 Set up array
B245 45637 *bad subscript*
B248 45640 *illegal quantity*
B34C 45900 Compute array size
B37D 45949 Perfonn [FRE]
B391 45969 Fix-float
B39E 45982 Perfonn [POS]
B3A6 45990 Check direct
B3B3 46003 Perfonn [DEF]
B3E1 46049 Check FN syntax
B3F4 46068 Perfonn [FN]
B465 46181 Perfonn [STR$]
B475 46197 Calculate string vector
B487 46215 Set up string
B4F4 46324 Make room for strings
B526 46374 Garbage collection
B5BD 46525 Check salvageability
B606 46598 Collect string
B63D 46653 Concatenate
B67A 46714 Build string to memory
B6A3 46755 Discard unwanted string
B6DB 46811 Clean descriptor stack
B6EC 46828 Perfonn [CHR$]
B700 46949 Perfonn [LEFT$]
B72C 46902 Perfonn [RIGHT$]
B72C 46892 Perfonn [RIGHT$]
B737 46903 Perfonn [MID$]
B761 46945 Pull string parameters
B77C 46972 Perfonn [LEN]
B782 46978 Exit string-mode
B78B 46987 Perfonn [ASC]
B79B 47003 Input byte parameter
119
B7AD 47021 PeIform [V AL]
B7EB 47083 Parameters: POKE/WAIT
B7F7 47095 Float-fixed
B80D 47117 PeIform [PEEK]
B824 47140 PeIform [POKE]
B82D 47149 PeIform [W AIT]
B849 47177 Add 0.5
B850 47184 Subtract-from
B853 47187 PeIform [subtract]
B86A 47210 PeIform [add]
B947 47431 Complement F AC# 1
B97E 47486 * overflow *
B983 47491 Multiply by zero byte
B9EA 47594 PeIform [LOG]
BA2B 47659 PeIform [multiply]
BA59 47705 Multiply-a-bit
BA8C 47756 Memory to FAC#2
BAB7 47799 Adjust FAC#I/#2
BAD4 47828 Underflow/overflow
BAE2 47842 Multiply by 10
BAF9 47865 + lOin floating point
BAFE 47870 Divide by 10
BB12 47890 PeIform [divide]
BBA2 48034 Memory to F AC# 1
BBC7 48071 F AC# 1 to memory
BBFC 48124 FAC#2 to FAC#1
BCOC 48140 FAC#1 to FAC#2
BClB 48155 Round FAC#1
BC2B 48171 Get sign
BC39 48185 PeIform [SGN]
BC58 48216 PeIform [ABS]
BC5B 48219 Compare FAC#1 to memory
BC9B 48283 Float-fixed
BCCC 48332 PeIform [INT]
BCF3 48371 String to F AC
BD7E 48510 Get ASCII digit
BDC2 48578 Print *IN .. *
BDCD 48589 Print line number
BDDD 48605 Float to ASCII
BF16 49818 Decimal constants
BF3A 48954 TI constants
BF71 47089 PeIform [SQRJ
BF7B 49019 PeIform [power]
120
APPENDIX D
BFB4 49076 Perform [negative]
BFED 49133 Perform [EXP]
E043 57411 Series evaluation 1
E059 56433 Series evaluation 2
E097 57495 Perform [RND]
EOF9 57593 ?? breakpoints ??
E12A 57642 Perform [SYS]
E156 57686 Perform [SAVE]
E165 57702 Perform [VERIFY]
E168 57704 Perform [LOAD]
E1BE 57790 Perform [OPEN]
E1C7 57799 Perform [CLOSE]
E1D4 57812 Parameters for LOAD/SAVE
E206 57862 Check default parameters
E20E 57870 Check for comma
E219 57881 Parameters for OPEN/CLOSE
E264 57956 Perform [COS]
E26B 57963 Perform [SIN]
E2B4 58036 Perform [TAN]
E30E 58126 Perform [A TN]
E37B 58235 Warm restart
E394 58260 Initialize
E3A2 58264 CHRGET for zero page
E3BF 58303 Initialize BASIC
E447 58439 Vectors for $300
E452 58451 Initialize vectors
E45F 58463 Power-up message
E500 58624 Get I/O address
E505 58629 Get screen size
E50A 58634 Put/get row/column
E518 58648 Initialize I/O
E544 58692 Clear screen
E566 58726 Home cursor
E56C 58732 Set screen pointers
E5AO 58784 Set I/O defaults
E5B4 58800 Input from keyboard
E632 58930 Input from screen
E694 59012 Quote test
E691 59025 Setup screen print
E6B6 59062 Advance cursor
E6ED 59117 Retreat cursor
E701 59127 Back into previous line
E716 59158 Output to screen
i21
E87C 59516 Go to next line
E891 59537 Perform [RETURN]
E8Al 59553 Check line decrement
E8B3 59571 Check line increment
E8CB 59595 Set color code
E8DA 59610 Color code table
E8EA 59626 Scroll screen
E965 59749 Open space on screen
E9C8 59848 Move a screen line
E9EO 59872 Sync. the color transfer
E9FO 59888 Set start-of-line
E9FF 59903 Clear screen line
EA13 59923 Print to screen
EA24 59940 Sync. color pointer
EA31 59953 Interrupt - clock etc.
EA87 60039 Read keyboard
EB79 60281 Keyboard select vectors
EB81 60289 Keyboard 1 - unshifted
EBC2 60354 Keyboard 2 - shifted
EC03 60419 Keyboard 3 - COMMODORE
EC44 60484 Graphics/text control
EC4F 60495 Set graphics/text mode
EC78 60536 Keyboard 4
ECB9 60601 Video chip setup
ECE7 60647 Shift/run equivalent
ECFO 60656 Screen In address low
ED09 60681 Send *ta1k*
EDOC 60684 Send *listen*
ED40 60736 Send to serial bus
EDB2 60850 Serial timeout
EDB9 60857 Send listen SA
EDBE 60862 Clear ATN
EDC7 60871 Send talk SA
EDCC 60876 Wait for clock
EDDD 60893 Send serial deferred
EDEF 60911 Send *untalk*
EDFE 60926 Send *unlisten*
EE13 60947 Receive from serial bus
EE85 61061 Serial clock on
EE8E 61070 Serial clock off
EE97 61079 Serial output * 1*
EEAO 61088 Serial output *0*
EEA9 61097 Get serial in & clock
122
EEB3 61107 Delay 1 ms.
EEBB 61115 RS-232 send
EF06 61190 Send new RS-232 byte
EF2E 61230 No-DSR error
EF31 61233 No-CTS error
EF3B 61243 Disable timer
EF4A 61258 Compute bit/count
F8IX> 63696 Check tape stop
F8E2 63714 Set read timing
F92C 63788 Read tape bits
FA60 64096 Store tape characters
F8BE 64398 Reset pointers
FB97 64407 New character setup
FBA6 64422 Send transition to tape
FBC8 64456 Write data to tape
FBCD 64461 IRQ entry point
FC57 64599 Write tape leader
FC93 64659 Restore normal IRQ
FCB8 64696 Set IRQ vector
FCCA 64714 Kill tape motor
FCDI 64721 Check R/W pointer
FCDB 64731 Bump R/W pointer
FD50 64848 Initialize sys. constraints
FCE2 64738 Power reset entry
FIX> 2 64770 Check 8K-ROM
FDlO 64784 8K-ROM mask
FCDB 64731 Bump R/W pointer
FCE2 64738 Power reset entry
FIX>2 64770 Check 8K-ROM
FD15 64789 Kemal reset
FD1A 64794 Kemal move
FD30 64816 Vectors
FD9B 64923 IRQ vectors
FDA3 64931 Initialize I/O
FDDD 64989 Enable timer
FDF9 65017 Save filename data
FEOO 65024 Save file details
FE07 65031 Get status
FE18 65048 Flag status
FEtC 65052 Set status
FE21 65067 Set timeout
FE25 65061 Read! set top of memory
123
FE27 65063 Read top of memory
FE2D 65069 Set top of memory
FE34 65076 Read! set bottom of memory
FE43 65091 NMI entry
FE66 65126 Warm start
FEB6 65206 Reset IRQ & exit
FEBC 65212 Interrupt exit
FEC2 65218 RS-232 timing table
FED6 65238 NMI RS-232 in
FF07 65287 NMI RS-232 out
FF43 65347 Fake IRQ
FF48 65352 IRQ entry
FF81 65409 Jumbo jump table
FFFA 65530 Hardwire vectors
FE59 65113 RS-232 receive
EF7E 61310 Setup to receive
EFC5 61381 Receive parity error
EFCA 61386 Receive overflow
EFCD 61389 Receive break
EFDO 61392 Framing error
EFEI 61409 Submit to RS-232
FOOD 61453 Send to RS-232
FOOD 61453 No-DSR error
F017 61463 Send to RS-232 buffer
F04D 61517 Input from RS-232
F086 61574 Get from RS-232
FOA4 61604 Check serial bus idle
FOBD 61629 Messages
F12B 61739 Print if direct
F13E 61758 Get.
F14E 61774 .. from RS-232
F157 61783 Input
F199 61849 Get. tape/ seriaVRS-23 2
FICA 61909 Output..
FIDD 61917 .. to tape
F20E 61966 Set input device
F250 62032 Set output device
F291 62097 Close file
F30F 62223 Find file
F31F 62239 Set file values
F32F 62255 Abort all files
F333 62259 Restore default I/O
F34A 62282 Do file open
124
APPENDIX D
F3D5 62421 Send SA
F409 62473 Open RS-232
F49E 62622 Load program
F5AF 62895 *searching*
F5C1 62913 Print filename
F5D2 62930 *loadinglverifying*
F5DD 62941 Save progrram
F68F 63119 Print *saving*
F69B 63131 Bump clock
F6BC 63164 Log PIA key reading
F6DD 63197 Get time
F6E4 63204 Set time
F6ED 63213 Check stop key
F6FB 63227 Output error messages
F72D 63277 Find any tape header
F76A 63338 Write tape header
F7DO 63440 Get buffer address
F7D7 63447 Set buffer pointers
F7EA 63466 Find specific header
F80D 63501 Bump tape pointer
F817 63511 *press play .. *
F82E 63534 Check tape status
F838 63544 *press record*
F841 63553 Initiate tape read
F864 63588 Initiate tape write
F875 63605 Common tape code
125
THE SERIAL BUS
The 64 communicates with a printer or disk drive through the serial
port, the six-pin socket on the back of the computer. This connects the
peripheral device to the serial "Bus". A "Bus" is a collection of
communication lines shared by such things as disk drives and printers.
Imagine youself as a switchboard operator in a train station. Your job
is to tell when and how the trains are to enter and exit the station. It is
obvious you must be able to monitor each train's course and in tum, each
train engineer must notify you of his intentions. Among other things,
your most critical function is to make sure that trains are not on the same
track at the same time. The consequences may be disastrous.
Back to the Commodore 64. It has the role of being the switchboard
operator of the serial bus. Devices on the serial bus can either 'talk' or
'listen', that is, send or receive information but never at the same time or
else all the data would be scrambled. You know how hard it is to
understand two people speaking at the same time! The 64 not only talks
and listens but 'controls' who will talk and who will listen. Only the
computer has this privilege.
The bus has three input lines that bring in data and three output lines
that send. Of each three, one line wakes up the device, one line controls
the timing of data sent on the serial bus, while the third conveys the data.
Recall the train station analogy. In serial transmission, each car of the
train is a bit of information.
126
Here's two more points to keep in mind. First, each device on the serial
bus must be recognized by its device address. That is the second number
used in the BASIC OPEN statement. For example,
OPEN 1,4
tells the printer, device number 4, to get ready to do some work. The
second thing the bus can do is set the device into its selective mooes as
specified by the third number in the OPEN statement.
OPEN 1,4,7
tells the printer to print in upper and lower case letters.
Using BASIC or machine language you can use the serial bus to
control other devices.
127
THE COMPLEX
INTERFACE ADAPTERS (CIA)
TillS CIA is not secret, but it is complex. Ask yourself this question:
Why is a separate chip required to handle communication tasks? There is
no obvious answer. Let's start by saying that there are a number of tasks
that the computer must perform in the right sequence in order to 'talk' and
'listen' to another device such as the printer, drives and modem
(modulator-demodulator). Each device shares a number of lines with
other devices; when one device 'talks' all others 'listen'. These shared
lines of communication are known as the serial bus.
Another dilemma facing communications is that these devices may
speak in different 'dialects' at different rates to one another. Whenever
communications are not dependent on each other's timing, then a
method for coordinating their operations are required. This is known as
'asynchronous communication'. It requires special software and/or
hardware support.
COMPLETELY CONFUSED?
Now, pretend you are the computer. You have data you transmit to one
of the peripherals, say the printer. But the printer is busily chattering
away, printing something else that you told it and hasn't finished. The
printer tells you that it is not ready to print what you have, but to 'wait'
until it is ready. So you, the computer, put your 'task' on what is known as
a 'queue' which tells the printer what it has to do next. Meanwhile, you
periodically ask the printer if it is ready to accept the information you
want it to process. When the printer responds positively, you can now
128
empty the queue and process your task. This is what is known as a
'handshaking' protocol and there are several kinds which are constantly
occuring in a system which interfaces one or more devices.
This computer has two dedicated CIA chips. They handle the required
memory locations in the 64K user-accessible memory space which the
computer or user needs to interrogate and modify. When a device or any
one of the internal dedicated chips need processing from the 651 0 central
processor, a signal is sent to one of the CIA chips to request the processor
to give some of its time to the task. The CIA has the special privilege of
telling the 6510 what it can do with its time on certain occasions. So a big
part of the CIA's task is to process the information from these other
devices.
129
BEING AN ARTIST
WITH COMMODORE 64 GRAPHICS
Often the creative mind has limited channels to express itself. Suppose
you tried to paint a masterpiece or write a symphony with no prior
training in those skills and only conventional tools at your disposal. It
may take years of time and labor to achieve your aim. Lots of us have
found, in micro-computers, direction in our creativity that we could not
achieve elsewhere. With the Commodore 64 you may find for yourself a
whole new dimension beyond paintbrush and manuscript for creating
graphics and sound. The extentions of your creati vity need only conform
to understanding the practices for constructing programs that sing and
paint
Now the key to all of this, or at least the graphics end of things is the
6567. In other circles it is called the VIC-II chip. If you wondered what
ever happened to the VIC-I chip, it was put in the VIC-20. Remember
V. I. C. stands for Video Interface Controller. The VI C-lor 6560 used in
the VIC-20 is used for both graphics and sound without the powerful
ability to handle things like Sprites like the Commodore 64 can. There is
a lot of stuff to play with here, such as the ability to build your own
characters and even write new alphabets. That is only the beginning! You
can control the destinies of eight different movable objects called Sprites.
You control how they move, what they do when they hit other objects, or
what they do when they hit each other.
LErS GET TECHNICAL FOR A MOMENT ...
First of all, the VIC-II is, in fact, a two chip processor. The companion
chip is the 6566 chip. About the only difference between them is how
130
they access the system's address busses. Other than that, normal
operations between the two are completely transparent to the system and
for all practical purposes they can be considered as a single functional
unit The VIC-II, like other dedicated graphics chips on the market, has
direct memory access (DMA) to the central processor (6510). This
means that when the VIC-II needs to get something done it has to ask the
65 10 if it can use the system's 8-bit bi-directional data busses to convey
information to the 64 K of RAM. The 6510 has to give up machine cycles
to comply with the request, thereby slowing down processing.Inci-
dentally, the user can disable the DMA to speed up the system's proces-
sing through screen blanking (see location 53265) and disable the
interrupts along the address busses so that graphics processing won't
interfere with the rest of the system (see location 56334). For those who
insist on seeing a simple hardware overview:
PIN CONFIGURATION PIN CONFIGURATION
6566
6567
(MultIplexed addresses In parentheses)
131
In addition, the chip takes care of test display, high resolution
graphics, sprites, sprite priorities and sprite collision direction. All of the
Commodore 64's graphics are available in multi-color mode which give
your display objects more colors to chose from. A rule of thumb is what
you gain in colors you lose in resolution. That's because the 8 bits in the
byte are read in 'bit pairs'
1 e O l 1 o O l ~ 1 e i l
~ ~ ~ ~
A B c D
A gets color from location 53281 - the screen color.
B gets color from location 33282 - background # 1 color.
C gets color from location 53283 - background #2 color.
D gets color depending on where it is located on the screen. This comes
from the color RAM area 55296 to 56295.
132
MODIFIED
CHARACTER
SET
GRAPHICS
PROGRAMMING
VIDEO BANK SELECTON
APPENDlXH
!., tt
$X&' (! C
) <>=+;
: ... -t A.
STANDARD
CHARACTER
SET
With the computer, we think that all the memory is available at the
same time. 64K is 64K, right? To the VIC-II chip's addressing lines,
only 16K chunks of memory can be considered at anyone time. There
are four sections of 16K banks to choose from when changing the starting
locations. The VIC-II chip, however does not have control over what
section of memory it sees. This is accomplished by the 6526 Complex
Interface Adapter #2 (CIA #2). Two bits used out of control PORT A
are used to select the start address location. Here is how to modify these
bit selections:
To change video bank:
POKE 53272, PEEK (53272) AND 15 OR A
The values of' A' control the following values:
Value Starting VIC-II
Of A Bits Bank Location Chip Range
0 00 3 49152 ($COOO-$FFFF)*
1 01 2 32768 ($8000-$BFFF)
2 10 1 16384 ($4000-$7 FFF)*
3 11 0 0
($0000-$3 FFF)
(DEFAULT VALUE)
*NOTE: The Commodore 64 character set is not available to the VIC-II
chip in BANKS 1 and 3.
133
The only part of graphics memory that is not relocatable is screen
color memory. It always starts at location 55296 ($DBE7) and ends at
location 56295 ($DBE7). Actual color is determined by the nybbles in
each color byte since a nybble can describe sixteen colors. Whenever a
character is POKEd onto the video matrix with the proper screen color
code (see screen color code table at the end of this section), its color is
determined by the values in the color memory.
PROGRAMMABLE CHARACTERS
Perhaps one of the most versatile techniques in modern graphics
programming is the ability to create custom characters for anyone
variety of purposes. With this technique you can create an entirely new
character set, different from the one found in the character generator
ROM. Think of the possibilities! An entirely new alphabet, or font, of
special characters used for building certain kind of displays. Fonts are
particularly useful for writing arcade style games or creating several
characters to animate. Fonts are a kind of portfolio for the re-defined
character information employed in these more advanced programming
techniques.
A PROTO EXAMPLE
This example changes 4 characters: the 2, <, 7 and = into Prototype.
The steps followed here will work with any characters you want to
modify from the standard character set
The first step is to turn off the keyboard and alI input and output Then
move the characters from ROM (Read Only Memory) to RAM
(Randam Access Memory - memory you can modify) so you can make
the changes. Lines 1040 to 1260 do just that.
1040 REM }> TURN OFF 110. BRING IN ROM
1050 POKE 56334.PEEK(56334) AND 254
:l OhO F'mE 1. PEEl'; .; Ii At.Jl) 251
107i2i
1080 F:El'1 >:> NO. OF BITS FR01'1 D 1 ~ j F : . r;:or·1
1090 FOR 1=0 TO 63
11 1'.1(21
1110 REM » RANGE OF BYTES/CHARACTER
1120 FOR J=0 TO 7
134
APPENDIX H
1 1
1140 REM COPY BYTE OVER INTO RAM
115(l POlE 1228(3+ I H3+J , FEEl: (53248+ 1*-8+.])
117U I::;;EI-1 > ••. NEXT BYTE OF CHP,i::;;ACTEF
118U NEXT
1200 REM TURN ON liD AND ROM OUT
1210 POKE 1, PEEK(1)OR4
1220 POKE 56334, PEEK(56334) OR 1
1 23iZi
124!2j REl-1 > > RESET CHARACTER MEI"lORY ..... .
1250 REM » POINTER TO 12288 (:
1260 POKE 53272. (PEEK(53272)AND240)+12
1270
Next, modify the character. Each one is stored in 8 bytes. That is the
job of these lines.
NES1ED LOOFS 310RE
BITE::; F'EF:
1300 FOR CHAR = 60 TO 63
1310 FOR BYTE = 0 TO
READ FE-DEFINED
REP,:O \\iLlivt

1 STORE NEW DATA INTO CHAR.
1370 POkE 12288+(8*CHAR)+BYTE. NUM
1380
139!2j

14Hl
REM » NEXT BYTE OR NEXT CHAR.
NEXT BYTE. CHAR
This puts the redefined character on the screen. By pressing any key
the characters will change back to the standard character set
1420 REM }> PUT RE-DEFINED CHAR ON «
1430 PRINTCHR$(147)TAB(255)CHR$(60);
1440 REM }> USER PRESSES KEY TO SEE ((
1450 PRINTCHR$(61)TAB(55)CHR$(62)CHR$(63)
1460 REM}> NORMAL CHARACTERS «
135
147121 GETA$: IF A$="II THEN GOTO 147121
1480
1490 REM » RESET CHAR MEM POINTER «
1500 REM >) TO NORMAL «
1510 POKE 53272,21
152121 :
This last section is the data necessary to change the standard
characters into Proto.
1530 REM' » NEW CHAR. DATA ~ ,
1540 DATA 7 ~ 7 , 3 0 , 3 0 ~ 1 2 7 ~ 1 2 7 , 3 1 , 3 1
1550 DATA 224.224,120.120.225.225.248.248
1560 DATA 24,24,24,24,24,24,102.102
1570 DATA 24,24,24,24,24,24.102.102
158121 END
Character Graphics is a powerful tool for programmers who want to
customize programs. It gives added dimension to games, too.
136
APPENDIX H
ASCII and CHR$ CODES
PRINT CHRS PRINT CHRS PRINT CHRS PRINT CHRS
0 RED
28 8 56 T 84
1
CURSOR
29 9 57 U 85
RIGHT
2 GREEN 30
58 V 86
3 BLUE 31 59 W 87
4 SPACE 32 C 60 X 88
WHITE 5 ! 33 = 61 Y 89
6 "
34
:::> 62 z 90
7
# 35
? 63 [ 91
DISABLES

@ 64 £ 92
SHIFf $ 36
ENABLES

SHIFf % 37
A 65
1
93
10
& 38
B 66
i
94
11
39
C 67
--
95
12
( 40
0 68
6
96
RETURN 13
) 41
E 69

97
SWITCH TO 14
LOWER CASE
.
42
F 70
rn
98
15
+
43
G 71
6 99
16
44
H
,
72
El
100
CURSOR
17
45
I 73
U
101
OOWN
-
REVERSE ON 18
46
J 74 g
102
HOMF 19
I 47
K 75 []
103

20 a 48
DELETE
L 76
OJ
104
21 1 49
M n
EJ
105
22
2 50
N 78 [3 106
23 3 51
0 79
EJ 107
24 4 52
P 80 0 108
25 5 53 Q 81
LSl
109
26 6 54 R 82

110
27 7 55 S 83
C
111
137
PRINT
0

C
f¥1
D
[L
~
D
[±J
[]
[l]
EE
IJ
OJ
~
~
ORANGE
CODES
CODES
CODE
CHRS
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
PRINT CHRS
132
f1 133
f3 134
f5 135
f7 136
f2 137
f4 138
f6 139
f8 140
SIDFT
141 RETURN
t ~ ~ ~ H c r ~ E 142
BLACK
CURSOR
UP
REVERSE
OFF
CLEAR!
HOME
INSERT
DELETE
BROWN
LT. RED
GREY 1
192-223
224-254
255
143
144
145
146
147
148
149
150
151
PRINT CHRS
GREY 2 152
L T. GREEN 153
LT. BLUE
GREY .1
PUIU'Ll:
CURSOR
LEFT
YELLOW
CYAN
REVERSE
SPACE
lJ
~
D
c=
0
II
D
~
~
0
rn
SAME AS
SAME AS
SAME AS
138
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
PRINT
r--.
~
1 ~
~
~
OJ
~
.,.j
r->
La
r.:u
L-J
E2
ED
D
IJ
[)
~
LJ
~
~
:::J
;]
~
'-------'
2J
~
~
96-127
160-190
126
CHRS
172
173
174
175
176
1n
178
179
180
181
182
183
184
185
186
187
188
189
190
191
SCREEN DISPLAY CODES
SET! SET2 POKE SETI SETl POKE SET 1 SET2 POKE
@ 0 £ 28 8 56
A a 1
1 29 9 57
B b 2
i 30 58
C c 3
--
31 59
0 d 4 SPACE 32
< 60
E e 5
I
33
= 61
F f 6
"
34
> 62
G
9
7
# 35 ?
63
H h 8 $ 36
B
64
I i 9
0/0
37
~
A 65
J j 10
& 38
OJ
B 66
K k 11 39
B
C 67
L I 12 ( 40
E
0 68
M m 13 ) 41
D
E 69
N n 14
.
42 D
F 70
0 0 15 + 43
[] G 71
P
P
16 44
OJ
H 72
Q q 17 - 45
El
I 73
R 18
46
~
J 74
r
S s 19
/ 47
EJ
K 75
T t 20
0 48 [J L 76
U 21
1 49
LSJ
M 77
u
V 22
2 50
0
N 78
v
W w 23
3 51
0
0 79
X x 24
4 52
0
P 80
y
y 25
5 53

Q B1
Z z 26
6 54
bJ
R 82
( 27
7 55 [!] S 83
139
SET! SET2 POKE SET! SET2 POKE SETI SET2 POKE
0
-
99
~
T 84
L :::rJ
114
:a
U 85
n
W
100
ED
'15
~
V 86 D
101
0
116
D
W 87 II
102
[J
117
[±] X 88 0
103
[]
118
OJ
y
89 ~
104
U
119
[1J
Z 90 ~ ~
105
~
120
ttl
91
0
106
~
121
IJ
92
rn
107
D 0
122
[JJ 93
C.
108
~
123
ffIl
§ 94
[g 109 r--.
L-I
124
~ ~
95
@ 110
2J
125
SPACE 96
~
111
~
L.J
126
IJ
97
ca
112
~
127
.-
98
E1
113
140
~
HOW TO CREATE SPRITES
Sprites are special movable objects you can design yourself. After the
design work - and it is a bit of work - the computer will help you easily
move them, check for collisions with other sprites, with text or other
graphics, and even keep track of priorities, in other words, which sprites
will pass in front of the others.
DESIGN THE SPRITE
A sprite is designed using 63 bytes of memory - 21 rows with 3 bytes
in each row. With eight positions in each byte, you have 24 (3 times
8) spaces in each row.
Mark off a 24 x 21 section of graph paper. This is the grid needed to
represent your sprite.
Row I
Row 2
Row)
Row.
\
Now draw lines dividing the grid into 3 equal columns of 8 squares
each.
M M ~ l - J
141
"""2
"""l
\
These markings are used later to calculate the byte values needed for
the data statements. The first row and first column looks like this:
US 64 32 16 8 .. 2 I 128 64 32 16 • .. 2 I 128 64 Jl 16 • .. 2 I
I
\ ~
Of course, all the 62 other pieces of the graph look like this, too. To
turn on the parts of the sprites marked, you would write a data statement
for each of the 63 bytes needed. To have a first row that looked like this
would need a DATA statement like this:
DATA 63,255,192
Finish designing your sprite then calculate the value of the 63 bytes
needed for each sprite.
STORING THE SPRITE IN MEMORY
After building the sprite and calculating the DATA statements, you
must POKE the data into memory. You can put sprites safely in the
locations shown on the following chart Other places can be used,
too, but require that you reserve space in the computer. See locations
55 and 56 for a routine to do this.
142
LOCATION DATA
(L) POINTER
832 13
896 14
960 15
12288 192
12352 193
12416 194
12480 195
12544 196
12608 197
12672 198
If you use a cassette to store programs, then remember location 13, 14
and 15 are used by the cassette for temporary data storage when loading
or saving programs. The two operations will cause the sprite data stored
there to be changed. The sprites should be redefined by reading the spite
data again and rePOKEing it into memory.
Use a FOR/NEXT loop to POKE in the data; for example;
100 REM ** L = THE START OF BRITE DATA
1 HI L=12288
120 FOR I = 0 TO 62
130 REM ** SO = SPRITE DATA ELEMENT
14i2! READ SO
15i21 pm::E L + I , SO
16i21 NEXT
170 REM ** SAMPLE DATA
180 DATA 63,255,192,35,170,85,120, ETC
1 9 ~ !
2 ~ : ! i 2 1
SETTING THE SPRITE POINTERS
Each sprite has a location that tells the computer where to go to get
the data necessary to put the sprite on the screen. The sprite pointers
are locations 2040 to 2047 and they point for sprites 0 to 7,
respectively. If you POKE for information for sprite 0 in location
960 then:
143
POKE 2040,15
See the chart above to fmd the right data pointer. If you don't want to
use the chart, just divide the location address by 64 to get the pointer
number.
960/64 = 15
If you want 4 sprites to look exactly the same, just POKE the data
once and set the pointers for the 4 sprites to the same area. This makes
sprites 0, 1, 2 and 3 look exactly alike.
100 FOR I = 2040 TO 2043
11!21 POKE I ~ 15
12QI NEXT I
CHOOSING THE COLOR
Once you have the sprite data in memory then decide on the color the
sprite will be. Each sprite has a default color, that is, a color already set
by the computer. If you want, choose a color from this chart and POKE it
into the sprite color locations (55287-55294).
Sprite Default Colors
0 White
1 Red
2 Cyan
3 Purple
4 Green
5 Blue
6 Yellow
7 Grey 2
144
MULTICOLOR SPRITES
A mulitcolored sprite is a more advanced technique. In this mode, the
computer reads your sprite data in a slightly different way, in bit pairs.
Two bits are read as one piece of data.
I,
ABC D
Bit pair' A' tells the computer to get the color for the area from the
sprite color register (from 55287-55294, depending on the sprite you're
working on).
B is screen color, so it will look like a blank space.
C is the color value POKEd into location 53285, multi co lor register #0.
D is the color in multicolor register # 1, 53286.
The program below switches a sprite from standard mode to multi-
color mode.
VARIATIONS ON A THEME OF PROTO
1060 REM INITIALIZTION<
1070 REM }} CLEAR SCREEN/BLUE CURSOR
1080 PRINT CHR$(147) :POKE 214, 6
1090 GO TO 1390
1112lld
1110 REM» SUBROUTINES GO ON TOP
1120 REM » RESET SWITCH SUBROUTINE
1130 IF N=1 THEN N=0 :RETURN
114U N=l : RETURN
115yj
1160 EXFr'.:Jr.lD :3UBRCiUTINE <:
1170 REM )} CHECK FOR 'Fl' KEY FIRST!
1180 IF PEEK(197)<:>4 THEN RETURN
1190 POKE 53265,11 :REM BLANK SCREEN
1200 POKE VIC+23.N :POKE VIC+29,N
145
1210 POKE 53265.27 :REM SCREEN ON
1220 GOSUB 1130
1230 RETURr,1
1240
:REM SWITCH SUBR.
1250 REM » SINGLE/MULTI-COLOR SUBR. «
1260 REM » CHECK FOR 'F2' KEY FIRST
1270 IF PEEK(197) <>5 THEN RETURN
1 :·2E:'Zi FtjiT 1 .l: I::;:E!'! :C?L?·;j"·H: :-3CFEEII
1 2 q F' [l t::: J,) 1 C= .. \- 2 [-j" l' ·.1 ;: F.: E J-"-J Iv! If C: n ;"';" F' _
1 PfJ}:::E 42"7· :
131!i1 GOSUE 1 J.3:::; :;.Ei1 I TCH3UI3F;:.
F<ETUI:;:!·.!
133U
1 II E 1"1 11[(iLILH I lilt]" 11,1[
F<EJ'dJ 110+ HFd; F'r;; J I'n HDi;"
1 F:E TUld'!



14(itj
l<liiii
/(r:: 1'1 :>:>
f'r; 11'11 L. Till.
l /j·::;U I" I TC)::' :. fH( I'll CI ( 17) C I Wh; (2'j') :;
1440 NFi< r 1
1
146d
14/U 1<[11 ... I L T liE Tel C:i(J Uhl
lilflU HJh 1" 1 fe)::.: F'r;: 11'IT (1Ifd; ( 17 ) (',;:l;,;)
1 '1 '?(j I\IL j(·1 T
I FfJH I" F'F;: I l'ITCfHH; ( >:'/) • liE X·I J
1 ;31 ["f( I In "II II 1:,11'1' IT'/ 1T.I CDI,n I riLl!:"
1;::;:::0 (iET (, '*':. I I "TIIEI'I J :;::;;:U
:[ FF: Ilrf CHI;: I; ( 147) :
l ;, /1 <:J
1 :'j',.!U HEll :::;[·r hF'h 1 TC C[III':;r;\I,!T:;
.l (i t) T C: .,- :::: 4 E: t·, I E: ('j C: (j F' I,.) I c: i --I I F'
I ;j/U ILll- J:: I<EIl ell ULLIL I:;
1 I'ILII :::c (>I;(IHl._:: 1;:1:1'1 LtiC. [IF '.IH (T L::)
I. t;l'il'} HEI'I IUF:hl UFF ::JCF::I:TJI
1 (, .l ;!) HE 1'1 F' CJI[ :2 ;:; 1 1
1
146
APPENDIX I
I. I:L.II
I (;bi> hEI'1 1 IE DP,TPI IU 11,1-I'LI,:
l,i,/(i F'UIE ',;O'IU
1;_,;](1
I {) 'hi! 1< [ i'11 U Id',1 U :; FT, IT v.!
l/UU POll.: '"I I C+Z 1
I. 1.,('1 r::EI'I; ;;EI I IE U' I'CY; 1 T 1 ClI',i
1730 PUkE VIC. 160 :PUK[ VILli, 120
j /oll(-)
17':,0 Id:11 ITF LULU!,)
I c.") I'UI<[ './1[+;:7" :,?:F;:[I'I 11"[.1'1,, REb.HI
,.I lUI; I ',,I 1(;+"','7" 4 1,;[11 :3FF: Ifi.lh>i CUi (JF:
,.J J.: LII (WI I U I,IT U [>; f' I:d \1 I) I' F: IT [11;:1
;.::;:.,.:(j F'C.li<L: I..) I 1\1 :: -,.---- ,," >:
i ,_II') I\II':.E ',) I L'j :;)" II : F:l:.11 [\ Fi:,I'ID ,
I :,:,.'::i
i ,: .. '" hl ... I'1 i;[LFC. r 1'1" C" II" I:UI: IT [Ihi>
, ,,'i'" ,'UI;.[ \i I C+2El" II
READ SPRITE DATA WITH A
( 1 .1 i2j 1 i. !:2j ) E< I 'r i'''j
1880 FOR I = 0 TO 23
1890 READ P p AND 170
1900 NEXT I
1920 REM )) READ DATA W/(01010101) MASK
1930 FOR J = 24 TO 55
1940 hEAD P p AND 85
1 1\11:: X T J
1970 REM )} READ DATA W/(10101010) MASk
1990 READ P :POkECMFM+K). P AND 170
1 U
':: n,;: (I r;: 1'1
'?kl:; .. ,O 1::[11 :;[1 11CII./ VJII J TF CLi!::::3UH
Ij:.:; 1 : F[lIE 6;lb" U
,;:0),::>
147
1-:[1'1 :>:> TII[:II VJti l'r
F'r( I til [I jh:li ( :147:; F::[I'I [LLic,f( bCF:E::r:rl
ijd FUn 1 ::: 1 TU.I 0 PI;: I I\ITUIH I; ( 171 CHrd; (:c:c; i :;
",: 1:1 U I\IL:XT I
.;:: 1 :;::: (I F' F: II\IT " F' IdJT (.J " F (J tlj' U T U ::, 0 : 1,1 E )<1 VJ
2130 F'RINTCHR$(147):FOR W=0T050:NEXT W
:?:Li.I·i!.i
.... -'.
'.:lhU lIeu: hE:I"1 EXI'(,I\IU iii >;;:'/
;: 1/ U C:;Uf:iU H 1 )'!>1 : I:: E 1"1 I 1\1 Ci L.I.:. / l'IL.ll_T I ····C (I J . uri
flU co TCl,;('i'/U
.,;:':1 ci'Qi
?:>;jQJ F:LYI ::>:>:>:> IH:iYOUi I hIFU" LliiTP, ::::: ...
2210 DATA HIT 'Fl' 10 EXPAND OR
2220 DATA UN-EXPAND SF'RITE
DIYTf::', H IT' I:::' 1[1 J'IUI.T J CClLUI;:
224d LlATA SF'RI1L
REM F'ROTO'S DA1A
2270 DA1A 0,60,0,1,255,128,7,255,224,31

2276 DATA 7,255,240.U,255,128,0,255, 128
, : ',O:"/'J :U {"iT ri 0:, I () '::::, :I:;:: U , I c;:o 1 ',,? U , d, I (.i'::, J
," .,:)' H D (',T A!';, 1 1 ::: Ei 1 cr:;::, :I d , 1 9 :::, 1: U
,.:/ ''; D nl J C?:::, H , J (j'c: (3:, I 'I::, 'I J./ n
';,,;j lliiTA l:; I 1 :?EL, :.:04/ , L24 :,.:::, :.;4:, ,?t.'
The other parts of sprite programming such as priorities and collision
detection are rather straight forward. Just refer to the necessary location
for more details on their use, With priorities, just remember that they are
set automatically with sprite 0 having the highest priority. Sprite 0 will
pass in front of sprites 1 to 7. Sprite 1 will pass behind #0 andinfrontof2
to 7. Sprite # 2 will pass behind #0 and # 1 and in front of 3 to 7 . You can
see the pattern. All sprites have priority over background data. If you
want to change any particular sprite's priority with respect to the
background and make the sprites pass behind the text, the proper bit in
the sprite priority register must be set (see loco 53275).
Collision detection is no harder to use. The sprite collision registers
are "read only" registers whose' bits change to 1 whenever a collision has
occurred (see locs. 53278 and 53279). It is easy to test for the collision,
but that test must be done strategically in your code such as in a main
motion loop. Collisions can be determined by one line of code.
148
APPENDIX I
FOR SPRITE-TO-SPRITE COLLISIONS USE:
IF PEEK(V+30) AND X THEN [ACTION]
FOR SPRITE-TO-BACKGROUND COLLISIONS USE:
IF PEEK(V+31) AND X THEN [ACTION]
where 'X' is the decimal value of the bit in the collision register.
SPRITE # BIT VALUE
0 0 1
1 1 2
3 2 4
3 3 8
4 4 16
5 5 32
6 6 64
7 7 128
In a very brief outline form, here's how to create a sprite. Part I (A) is
true for all programs you write, the remainder deals with only the sprites.
Those marked with an * are optional depending on your level of ability
and how you want the sprites to look. You can create and move sprites
without them.
149
SPRITE ALGORITHM OUTLINE
1. PROGRAM INITIALIZATION
A) Declare Program Parameters
1. Dimension arrays
a. integer
b. string
c. real
2. Set constants and variables (same items as under arrays)
B) Declare Sprite parameters
1. Set constants and variables pertinant to sprites
a. VIC=53248 => start address of the VIC-II
*2. Turn off screen (POKE VIC+ 17,11)
3. Store sprite data
a. set data pointers (locs. 2040 - 2047)
b. use FOR/NEXT loop to read in data
4. Enable Sprites (VIC+21)
5. Set sprite color registers
a. single color sprites (POKE locs.
VIC+39 + VIC+46)
*b. multi-color sprites (POKE locs.
VIC+37 + VIC+38)
*6. Enable sprite color mode
a. Tum bit four on in multi-color register (VIC+22)
*7. Select expanded sprites (VIC+23 and VIC+29)
*8. Turn screen back on (POKE VIC+ 17,27)
2. MAIN PROGRAM LOOP
A) Set sprite motion FOR/NEXT loop
1. PEEK at sprite positions (VIC + VIC+ 16)
a. call them X and Y
2. Determine how far you want to move
a. call the amount of motion DX and DY
3. Determining direction of motion
*4. Monitor sprite collision registers (DX = - DX,
DY=-DY)
a. sprite-sprite collision
.. b. sprite-data collision
5. Check X positions of sprites whether to POKE MSB in
VIC+16
a. Check position border constraints (see sprite pos. locs.)
6. Add offsets to original position: X=X+DX,
Y=Y+DY
7. Exit position update loop
150
-
... . ......
B) Evaluate multiple sprite displays
1. POKE VIC+ 16 with the value determined by the sprites
whose X position is greater than 256.
*2. Check raster register for special interrupt conditions
a. mix-moded displays (character wi bit-map mode)
b. moving more than eight sprites
c. light-pen
3. POKE updated position (X,Y) back into position registers
4. Go back to II-A) ify
Determine
Offsets and
Direction of
Motion
Sprite
(' A)llision
Routine
Yes
-----

Program
Initialize
Spnte(s)
Are
Spnte(s)


Yes
Are
Spnte(s)

____ .......{No
Yes
Yes

No
Check Sprites
X·Pos. > 255
Check. Raster
Rt:gtster for
Interrupt
Conditions
Anv-
thirig
Else Wltb

151
No
Ched Sprites
X-Pos. > 256
This last program contains a machine language routine to move sprites
quickly across the screen. The speed range is from 1 to 5. Press
RUN/STOP to end the program.
1000 REM ******************************
1010 REM * THEME ON A VARIATION OF *
1020 REM * PRO T 0 *
1030 REM * MOVING PROTO WITH JOYSTICK *
1040 REM * ALGORYTHM BY SHELDON LEEMON*
1050 REM ******************************
1 i216!21
1070 PRINTCHR$(147);CHR$(5):SP=53248
11218121 INPUT" SPEED (1 -5) "; S: GO TO 1191Z1
1l219!21
1100 REM }}}}} SELECT SPEED {{«<
1110 ON S GO TO
1120 SYS(49409) :GOTO 1120
1130 SYS(49406) :GOTO 1130
1140 SYS(49403) :GOTO 1140
1150 SYS(49400) :GOTO 1150
1160 SYS(49413) :GOTO 1160
1171Z1
1180 REM }}}}} STORE SPRITE DATA ««<
1190 FORI=871T0895:POKE
1200 FORI=832T0894:READ A:POKE
121121
1220 REM }}}» SET SPRITE PARAMETERS «
1230 POKE :POKE
1240 POKE :POKE SP+29.1
1250 POKE :POKE SP+l.100
1260 POKE SP+32,0 :POKE SP+33,0
1270 PRINT CHR$(147)
128121
1290 REM }}}}} PLACE STARS IN ««<
13121121 FOR I = 1 T05121
1310 : POKE 1024+INT(RND(0)*1000),46
132121 NEXT
133(21
1340 REM }}})} PROTO"S DATA ««<
1350 DATA 1.255,128,7,255,224.31
1360 DATA
1370 DATA 7,255,240,0,255.128,0.255,128
1380 DATA
152
1390 DATA
1400 DATA
1410 DATA
1420
STORE
MACHINE LANGUAGE
ROUTINE
1430 REM »»>
1440 REM »»>
1450 REM »»>
1460 FORI=ITOI01
1470 : READ A:POKE
1480 NEXT

1490
1500 FORI=IT019
1510 : READ A:POKE 49399+I,A
1520 NEXT
1530
1540 REM »»> RETURN TO UPDATE
1550 REM »»> POSITION
1560 GO TO 1110
1570
««<
" .' " " "

««<
««<
««<
1580 REM »»> MACHINE LANG. DATA .:««
1590 DATA
1600 DATA
1610 DATA 173,0,208,208,15,173,16,208
1620 DATA
1630 DATA
1640 DATA
1650 DATA 142,0,208,96,74,176,32,238
1660 DATA
1670 DATA
1680 DATA
1690 DATA 141,16,208,142,O,208,96,173
1700 DATA
1710 DATA
1720 DATA
153
COMPOSING MUSIC
Rattle off a quick tune in yOUT head. Now think for a moment all the
variations of pitch, volumn and tonal qualities that go into just a few bars
of it. If you pick up the manuscript of a fully scored symphony, you may
fmd overwhelming amounts of description for all the sounds that each
instrument is responsible for. little wonder how much training a modem
composer or conducter must have to to attain mastery over musical
expression.
With the advent of electronic synthesizers in the mid-1970's, key-
board musicians were introduced to new vista of musical performance
with a wide range of dynamics, phrasing and articulation. The resulting
explosion of creativity has lead to altogether new musical forms and
ideas. And now in the 80's this has taken another step with the
introduction of musical synthesis in home computers.
SOUND PROGRAMMING TECHNIQUES
The nice thing about programming sound on the Commodore 64 is that
all its given features can be programmed in BASIC up to three voices.
The 3 voices are just like having 3 musicians ready to make any sound
you want The only difficulty involved in sound programming consists of
closely watching which values have been POKEd into the sound
registers.
154
· APPENDIX J C
Needless to say, BE PATIENT. You will fmd after sound program-
ming experimentation that even your mistakes may produce useful
sound.
Let's get to some basic techniques. For practical purposes, there are
only two ways to provide the information you need to make sounds. You
can generate the sounds by POKEing in numbers one at a time, or put
this information in data statements to be read as the program runs.
Before a sound can be made, be sure to do these things first
1) Clear the SID chip to get rid of any unwanted values in the registers.
A FOR/NEXT loop will do the job.
:I. F<[J-.'l ,'-- c.;"·( I ;\1[, /I
.l 1 iii ':; I U:::: ·4.:;;' :;,
130 FOR I = 0 TO L0
J 4!:25 F:(Jl<E: ':31 {) .. j. I (J
1 :':;(i hiE>: T
2) Tum on the volume control on the chip.
170 POKE3ID+24.15
is the highest volume.
3) Set the frequency you want Check the note table at the end for the
values you need.
H 1 C,fi LitlE ; HyrE
TC) F'I::;UCUCC i'i I DI>L.:: c. [II \/l} I CE
>:20 I D+ 1 " 7'5
These are the values for C in the 5th octave, middle C.
155
4) Set the Attack, Decay, Sustain and Release values.
230 REM - SET THE AT1ACK/OECAY RATE.
240 POKESID+5.16
250 REM SET THE SUSTAIN/RELEASE RATE.
260 POKESID+6,249
With those steps taken care of, you can now work with filtering,
modulation and syncronization or just enter all the above lines and turn a
specific waveform on.
F<Et-1 "- THE:
280 REM - AND TURN IT ON.
290 POKESID+4.33
and off
REM - START THE RELEASE CYCLE
310 POKESID+4,32
OU'nINE FOR SINGLE VOICE
This short outline contains all the steps necessary to produce a sound
with a single voice. Part I (A) is true for all programs. You write,
156
I. PROGRAM INITIALIZATION
A) Declare Program Parameters
1. Dimension arrays
a. integer
b. string
c. real
APPENDIXJ
2. Set constants and variables for the other parts of your
program.
B) Declare Sound Parameters
1. Assign constants and variables pertinent to sound
a. SID=54272, the start address of SID chip. See location
54272 for an example of using this method.
2. Clear the sound chip
a. use FOR/NEXT to POKE zero into the SID chip
registers (SID to SID+24)
II. MAIN PROGRAM LOOP TO PLAY NOTES
A) FOR/NEXT loop for voice production
1. Define functions for anyone or all of the voice parameters
a. Defme frequency (SID + voice frequency used)
b. Defme waveform (SID + voice control register)
c. Defme ND/S/R (SID + ND/S/R registers)
d. Defme filter (SID + filter control register)
e. Defme filter (SID + filter control register bits 0-3)
2. Define sound duration
3. GATE ON voice control bit for specified duration
4. GATE OFF voice control bit for specified duration (rest)
B) FOR/NEXT loop for voice production stored in DATA state-
ments
1. Store above voice parameters in DATA statements
a. Store one or more parameters individually or,
b. consolidate more than 1 parameter per given DATA
element.
2. READ voice information into voice parameter variables
3. POKE voice information into respective voice parameter
register
III. DATA STATEMENTS OR NEXT PART OF PROGRAM
157
VOICE
Set Pulse
W,dtb &
Filters
Set Ring
ModulatlOD
& Hannofllc
ModulauoD
R<se,
Filters
ModulauoD( s)
Yes
lruuahz.e
Program
Initialize
VOlCe(S}
Parameters
Additive
Modulations
No
Ali Voices
,
Yes
R<ad Stored
Music Data
158
Decode
Dynarrucs
Frequency
PhraslDg
ArtlculatlOn
No
More
Than I
Voice
?
No
Gate
VOIce(S)
All
Done With
M ~ c
Yes
All
Done With
Sound
No
Yes
No
No
APPENDIXJ
The programs below are samples of single voice programming. Play
\-vith these as much as possible, POKEing different values into the sound
registers. Even your mistakes will lead you down new paths.
i l'! l) f,: F:.I'-i ;t'"1\- .",. * * .;>1. '>(.* ",. -li' -j{. **.* '!i- ,)Ii, *"11' -!t .. Io(•• j!- * ·lI· -iI. * * *
1 1 (! REI1* f. E # J SL:{.:JL *
120 REM *******************************
j (.1
140 SlD=547!2:REM -- START OF SOUND
150
160 F.'EM SUUND CH JF' '., < < <
170 FOR S=SIDTOSID+24:POKE S.O:NEXT S
18<)
190 REM SET VOICE VOLUME
200 POkE I D+24. 79: REM ----,. I-lAX T MLlt1
::: 1 (>
::::20 F,El'l .. ',,;,;,> SET !'Yel E . ., <.,-:
230 POKE SID + 5,9: REM SID + 6, 65
?40
250 REM READ FREO. DATA
260 READ HF, IF :REM HI FREQ .• LOW FREQ.
::::80 m'I'1 ,.,.
290 IF HE ': I)
:5t)()
F'fJt:E I D+'l, U: Et·JD
::; 1 0 PEI'I
F'IlVF J Ii,

Fr,'[D .. " <.
F: POkE SID+l, HF
'::AO F.:EJ·'I , .. ,. , .. ' G':l IT \)0 I C:F 1. W ;,' <' ::' <' .:'
FE't1 .":::::-., S(iLlJ rDO f H j;.lf2j\.)FF:DRI·1 ... ' <' ., .;
:;::bO
7(!
::' fJ(! R U-l
:390
DD AY L ClCW FOR
N01E DURATION
159
. :: . .:: ':"
<: <: '.
400 FOR DUR = 1 TO 250: NEXl DUR
410
420 F.:EM :> > > >:> TURN OF VO I CE 1. .:. <" <: -::-::
430 POKE SID + 4. 32
440
450 REI"I »»>
460 GOTD 230
470
GET NEXT NOTE ««
480 REM ~ » » MUSIC DATA ««<
490 DATA 34,75,38,126,43.52,45,198,51
500 DATA 97,57,172,64,188,68,149
510 DATA 76,252,86,105,91.140,102,194
520 DATA 115,88,129,120,137,43,-1,-1
160
APPENDIXJ
This example uses a high-pass filter and volume manipulation to
produce the sound of an old water pump.
100 REM *******************************
1 10 REI"l * SOUND EX l4t1FLF #2 F'I.H1F' *
120 REM *******************************
j
140 SID=54272:REM START OF SOUND
150
160 F,'FI'" ;. >.:, >"> CLEAR CH I F' ... :' .. '
170 FOR S
lBC!
190 REM »»> SET VOICE VOLUME ««
195 REM »»">& HIGH PASS FIlTER
200 PCH:E E: I D+ / ,+ • 79: REI"I ""_.: l'iA X. 'JDL.
210
? ::' ,) R EJ'I . '., '.:' > 5 F T Pi! D / / n CYCLE ':'. <. -:: <:
230 POKE SID + 5,148: POKE SID + 6. 26
2'/,0
310 REM »»> POKE IN FREQ.
320 POKE SID. 240: POKE SID+l. 33
340 REM »») GATE VOICE 1 WI
350 REM NOISE WAVEFORM
360 POKE SID + 4, 131
370
. " -:: <.
::;80 REl"l :>;: ):. DECF-:EASE 'JljLllt1F '. :: .
390 FOR VOL=15 TO 0 STEP -]
400 POKE SIn + 24, VOL
410
F<Ft1
" :.
bUE;TA I hi 'v'OI I 420
430 REt1
: :. :.
DEI LCiUF'
161
TH
.: : : .:" ,
:
., :
.;<
440 FClF DUF -- 0 : NEXT [tlJR
450
4·60 REM
.,
",lEx 1 \jOt UME
470 T
480
490 »>., OFF ',)0 I CE 1
500 POKE SID + 4. 0
1 \-j
520 REM RETURN 10 REPEAT .
162
APPENDIXJ
A low pass filter plus the interaction of voices 2 and 3 for the falling
bomb effect - complete with explosion.
I. (II) F' [:I-I ·j\IHh" ii *IHHi iHtJ( ·li· .** kIHH( illI<li· .J\ .j(. iI· .)1 it .* .JoI.l\.
1 1 (l :::;:Et'1 * SOUND r:-:< [:OI'1)-! *
J .2 \! r:;: F t-1 -j.\. -1(* iI-1l -1(ji)i.J\ ltli··)i ji·lt iii;': X *11· * *
1 :30
1. 4\) T Dc"':A27 :7:: r-.-r:::tl
1
lri() F'E.t'-1 ":.::, .:.):: C;HIF' <::. < .. <.::
1 /0 r-:--UR S·<; J I D+,'4: PUf:E (,: hiE X T S
t8u
1 9 0 E. 1"1 :.: »,> 'Vi 0 I r:; E:!. A./ D / 8 / R· . .:
200 POKE 8ID+19,20:POKE SID+20,20
.? 10
-::·:20 h:Ft'1 >::. FTLTEh: C;IJTOFF FRED.
230 POKE SID+21,1:POKE SID+22. 110
::'40
.' ...
250 h:rcM '. '.: ....... : > \)[) T C:E!; F I L T[R .,.: .:.
260 POKE 81D+23, 4

':::80 h:EI"1 >:.... 8FT \JCi T CE= IvlClUJME .,..,. .:.
290 REM WI LOW-PASS FILTER
3(H) h:EM .: .... '> 9., CIJTllFF .. : .. <.
310 POKE 81D+24, 15q

330 REM GAlE VOICE 3 WITH
:340 .:. > .:.... Th' J ANGL E tJJA
I
·.)EFDRI'1 .... : •..
3:=; () F' rHo· E SID + 1 F! , I ;
::',60
163
:380 HEt1 FRt:;CilJFNCr
3'-:;'(J FOR rEP-I
400 FOR
4 10 penn:: S 1 0+ 1 4 , IF: F'DfF i::; I 0+ 1. ,::; , HE
420 l'lEx T I. F
430 IF IF<O THEN NEXT
44CJ
450 Fi'EM :: > > >:. TURN OFF Vi) I CE .:: -::: :'. '.
460 POKE SID+18,16:REM RELEASE
470
480 REM PAUSE A MOMENT :
490 FOR OUR = 1 TO 100:NEXT DUR
500
1 (I REi"l
REM ::
SET UP VOICE 2 FUR
::- SyNC. W J TH ::!:: ..
530 POKE SID+8,5:REM ----> FRED.
540 POf:::E A/I)/
550 POKE SIR eYCI E
560
570 REM »»> GATE VOICES 2 & 3 {{{{
S T D+ 1 1. 1:: 1: F'OhE S I D+ I 8, 1
590
60t) REI-I EXFI (Y3TD!'1
61 <) .. : .. : loJ/ '/OICF .:.
6':;::0 RFt-1 .. :.: OF '..Ien LlI-IE:
630 FOR L co 1 ilT IJI' Sl E.F'- . (:0.1
640 PUKE BIG 24, l
650 IJEer 1 ..
66('
67(i F\:E::1"1 .:'.' TtJF,'N [IFF '1[1 I LE 2 <:".
1.:,f30 PDKE 81D+11 ,'J:fC;.FII --: F;'ELEI' ..
f.,9U EhlD
164
APPENDIXJ
An example of ring modulation
using voices 1 and 3 produces
this sound.
100 REM ***************************.**
110 * SOUND EXAMPLE 4 BUSY SIGNAL*
120 FEI1 ***·)!-*It··iof-****·ij··ji·lI-·)j·***********·it*·it*
150
1 4 () C3 T [) <1:2 / .';:0: f;: 1'1 .. -:. ART DF SOUt·"D
150
16,) f;'EI'\ : > ::: > > CLEf.)f;· CH I F··.·. : .. -::
170 FOR S=SIDTOSID+24:POKE S,O:NEXT S
180
1 (:;'0 r;'Et"l :> ::-::' r FT;'FCi. ')[1 r u;::: 1. <: <' -: ".
200 POKE 81D+]. 75
?lO
220 REM VOICE 1 A/D'S/R
230 F'Clf::F CJ I D+ ,:::0: P[WE S J Ilt·(·, ,:,:'0')
:::':'"+0
SET FRED. VOICE
260 POKE S10+15,
?7c'
::'8() '. : SFT \'!oI. UI'IE .. ' .
. :'90 PiJVE SID+24,lc:.;:f;:EI-1 -_ .. > l"li;Xlt-1Ut-l
.:!;(>O
31(> REM »»> SEl DELAY LODP
FOR OUR::::: 1 rCl 1 (1('): NE" T DUR
RE]'I > ":::-:: c.:;rlTE \)() I iE 1. l.J/ :: <:::::-::
350 REM »»> TRIANGLE WAVEFORM
360 REM .' & RING MODULATION -:-:: .
370 POkE 81D+4, 21
:::;80
390 REM >,. ANOTHER DELAY LOOP «<
4·00 FOR DUR:::1TOI00:NEXT DUR
41 (.
4::::0 hEt'l::: TURN OFF '-.,)(J I CF I.
430 POKE SID + 4. O:hEM REI EASE
440
45() REYI >-::- >-:>::. TO -::: .... <::::-::
460 (3D TO 290
165
Two voices, one siren with hard syncronization.
lOO REM
1 1 0 REI'1 .iI- 5I',IUI'.!!) F X A 1·1F' I E;"i S I FE!-I '*
120 REM *****************************
1
140 SID=542f2:REM STARr OF <:;CJUND
150
16n F;:EI'I.' » CI,EI)R CHIP' «{::
170 FOR S=SIDTOSID+24:POkE S,O:NEXT S
180
1QO REM >}»> VOICE 1 AIDISIR
200 POkE 5ID+5,100: POkE 81D+6,100
'21 ()
7:2(J F\:E:M ";'.> ,,:' .:. SF:T v'C)t IJI'1E . <- .:. .::
230 POkE 8ID+24,lS:REM MAXIMUM
240
250 REM »» SET FREQ. VOICE 3
260 POkE 81D+15,30
270

291)
::!;OO
REM
REM
REI'1
GATE VOICE 1 WI
;:. >, .::m I ANGL F WAVEFORI"I
.> > ::- > ::-
310 POkE 81D+4, 19
:y.;:'o
':" .:. :
-:: <. <.':: .:"
Fi:Et-1 :.:: I NCRE(lSE v'I1I 1 ':,' <'.; <:
340 ". ':, ;:. > FHEC'lJENC. I Ff,:l ':, < " •. '.
FOR
360 ['OR
31(1
HF
L F
.-
-'"
3(
..
( ;
)
Tel 40
TO
._, r=.- r='
...:: .•. ,.,. __ 1
STEP ',?('
POkE 81D+l, HF: POkE SID. LF
390 POkE POkE SIO+14,LF
40(0
166
410 NElT I.F,HF
4·;:'0
(' f=;' F 1'1 . :.:.
45()
4f,C> PEtvl
470 F.Er"1 .:.:.
4BO FelF,' HF
490 LF
VI] I
:: FhEf)UEI\JC I ES
40 TO
255TO () STEP-20
APPENDIXJ
'. ".
510 POKE 8ID+1, HF:POKE SID,LF
520 POKE SID+15.HF:POKE SID+14,lF
:::i40 I'-IE)( T LF. HF

I=\'FI-I ::- >: .. : .. ' ':'",FT DE L. tOy) LOOF' ., -<-:
570 FOP DUI;-::::ITCl.,?'SO:NFlT lJUP

RETURN TO REPEAT ,;<{
6C)() f;U TD
167
The 'drip' uses a pulse wavefonn and ring modulation.
1121121 REM *****************************
11121 REM * SOUND EXAMPLE 6 DRIPPING *
12121 REM *****************************
13121
14121 SID=54272:REM --> START OF SOUND
15QI
16121 REM »»> SET FOR/NEXT STEP ««<
17121 SP = 121.1
18121
19121 REM »»> CLEAR SOUND CHIP ««<
2121121 FOR S=SIDTOSID+24:POKE S
21Q1
22121 REM »»> SET VARIABLE DELAY ««
23121 FOR DUR=ITOI000 STEP SP+0.1
25121 REM }}}» SET VOICE 1 FREQ. ««<
26121 POKE SID+l, RND(I)*20121+1
27121
28121 REM »}» VOICE 1 A/D/S/R ««<
29121 POKE POKE SID+6,255
3121121
31121 REM >}}» SET VOICE 3 FREQ. ««<
32121 POKE 51D+15, RND(1)*200+1
330
340 REM }>}» SET VOLUME ««<
350 POKE --> MAXIMUM
36121
37121 REM »»> GATE VOICE 1 WI ««<
38121 REM >}>}> SQUARE WAVEFORM ««<
39121 REM »»> & RING MOD. ««<
4121121 POKE SID+4, 69
168
APPENDtKJ
410
420 REM »»> SET VARIABLE DELAY ««
430 FOR T=ITOI000/DUR: NEXT T
440
450 REM »»> GATE VOICE 1 WI ««<
460 REM }»» TRIANGLE WAVEFORM ««<
470 REM »»> & RING MOD. ««<
480 POKE S I O + 4 ~ 21
490
500 REM »»> INCREMENT STEP VALUE «
510 SP = SP + 0.9
520
530 REM »»> NEXT DURATION
540 NEXT OUR
169
... " ." .' "
~ ~ ~ ~ ~
If you put
this airplane
example with the bomb you're halfway to some game sound effects.
i '''-' fd 1'1 jllHlilHI·ji· .. ,.. *.Ji .• ' -J\)t-lHHI' -IHHI'
1 1 () REI'1 * SUllhi'I' r: x lil"IF'I, EJ PI. (H\II:: .lI-
t;? 0 Fi' F:: r-I x * .1iE- *j(. *;':i<i- * -j(.j(l( -jI .. )(ji.i\1iE- .1(. ,J;- -'j"11- ,)(.) ''''''j( *
1 ()
14() PFf"\-- ;:,T?'iF'T iJF SUIJND
15()
160 REM CLEAR SOUND CHIP
170 FOR S=SIDTOSID+24:POkE S,O:NEXT S
180
190 REt1':" '.iO I CF 1 ;::1./ D i L / F;::., .:
200 POKE (3 I • 20: F'CHE b I D+6. '2<.)
210
220 REM »»> SET VOLUME
230 POkE SID+24,lS:REM --) MAXIMUM
240
250 REM )}' SET CONSTANT FRED.
260 LF = 255: HF = 7
270
280 REM »») GATE vOICE 1 Wi ««
290 REM »»> SQUARE WAVEFORM ««<
300 POkE 51D+4. 65
1 0
REt'1 ':: .:.. : ,:.,. T NCREASF PiILf;E '.: ",'
.330 REI'1 ',: .: :: WIDTH 11UDI,JL AT Ion:,
:340 FOP PH = 0 TO
350 FOR PL = 0 TO 255 STEP 10
360 POVE S I D"I--,? PI.: POVE fIT PH
:310
::mo Fi'Et·\ ',:",:. SET 1)0 T C;[ I FriEO. :, -::
390 POkE SID, LF:POkE SIO+l. HF
400
<. <: <' < ",
L..F :::;: L f= =J
1.'\.:30 IF L.F<O Tf·IU'-I HI=- = HF-'l
440
LJ·50 NE)( T F>L, PH
170
MULTIPLE VOICE PROGRAMMING
Consider for a moment what might be involved in programming more
that one voice. Here again, plan well or you may run into complications.
In setting up a multi-voice program, you should introduce more variables
and arrays for easy storage and computation os each separate element of
voice information.
This presents a problem if you are getting all your information from
data statements. Think of how long your data statements might be if you
had to store the frequency, waveform, ND/S/R cycle, duration, or any
other involved voice information sepaprately for each voice! If nothing
else, it would take forever for it to be READ into arrays.
For long sound program, this time to load your voice information
cannot be avoided. However, there are several ingenious methods for
using a given data element for describing more that one voice parameter.
This cuts down on DATA elements, hence the time it takes to read them
in. Here is just one such method provided in Commodore's "Prcr
grammer's Reference Guide". It lets you write a multi-voice program by
creating proper DATA tables for all your sound information. These are
the steps:
1) Take each note's duration (the number of 1/16ths which it constitutes)
and multiply it by 8.
2) Add the result of step 1 to the octave (0-7) from the note table.
3) Take this result and multiply it by 16
4) Take this result and add your note to it from the note table
171
Another way of saying this is to have D, 0 and N represent duration,
octave and note respectively. The result of this little formula is one
DA T A element for one voice's information:
Data Element = (((D*8)+O)*16)+N)
Now all that your code has to do is disassemble this information to be
POKEd into the correct registers.
The next thing to consider is to coordinate the two or three voices
together. In other words we must determine the durations and rests of
multi-voices at one time.
1) Divide each musical measure into 16 parts.
2) Store the events that occur in each 1/1 6th measure interval in three
separate arrays.
3) Process array information using the waveform control byte as a
starting signal for beginning a note or continuing a note that is already
playing.
172
APPENDIXJ
The multi-voice outline is more complex than the single voice, but it
really does more.
OUTLINE FOR MULTI-VOICE
I. PROGRAM INITIALIZION
A Declare program parameters (same as the single voice outline)
B. Declare multi-voice parameters
1. Dimension arrays to contain activity of music
a. 16th measure per location
2. Dimension array to contain the base frequency for each note
II. MAIN PROGRAM LOOP FOR MULTI-VOICES
A FOR/NEXT loops for storing into 3-voice information arrays
1. frequency start address array
2. waveform control byte array
a. one element/voice
B. Set parameters inherent of all three voices
1. Set voice registers that do not change in rest of program
a. filter values
b. pulse-width values
c. etc.
2. Special modulations
a. ring modulation or hard sync.
b. harmonic modulation (see S+28)
c. any other additive modulations
C. Nested FOR/NEXT loops for actual music execution
1. Set pointer to 3-voice activity array
2. Begin decode loop for each voice's parameter:
a. assign variables to each decoded parameter.
3. POKE in respective values into respective voice control
register
4. Increment 3-voice activity pointer
5. Go to II. C-l to process next measure
III. DATA STATEMENTS
A Set up DATA tables
1. Put starting frequencies per voice in one table
2. Put encoded voice information in another table
3. Use an element(s) to delimit end of program
IV. GO ON TO NEXT PART OF PROGRAM OR END
173
If you can think of any brilliant alternative algorythms for multi-
voices, you may have poineered a whole new approach, so please tell the
world. About the only limitation using multi-voices is that you don't have
the diversity of special modulation you have with one voice because all
voices are dedicated to their assigned waveforms and are not free to be
added to others to produce some desired blends. However, you probably
won't fmd this to be a problem for programming sound ideas.
This sample program from Commodore's Programmers Reference
Guide is afme example ofamulti-voice song. After you type 'RUN', the
program will take 30 seconds to set up the data arrays necessary for the
voices.
10 S=54272:FORL=STOS+24:POKEL,0:NEXT
20 ,C(2,200)
30 DIMFQ(11)
40 V(0)=17:V(1)=65:V(2)=33
50 POKES+l0,8:POKES+22,128:POKES+23,244
60 FORI=OT011:READFQ(I) :NEXT
lOt) FORK=OT02
110 1=0
120 READNt1
130 IFNM=OTHEN250
140 WA=V(K):IFNM{OTHENNM=-NM:WA=1
150 DR%=NM/128:0C%=(NM-128*DR%)/16
160 NT=NM-128*DR%-16*OC%
170 FR=FQ(NT)
180 IFOC%=7THEN200
190 FORJ=6TOOC%STEP-l:FR=FR/2:NEXT
200 HF%=FR/256:LF%=FR-256*HF%
210 IFDR%=ITHENH(K,I)=HF%:L(K,I)=LF%:C(K,I)
=WA:I=I+l:GOTOI20
220 FORJ=ITODR%-I:H(K,I)=HF%:L(K,I)=LF%:C
(K,I)=WA:I=I+l:NEXT
230 H(K,I)=HF%:L(K,I)=LF%:C(K,I)=WA-l
240 I=I+l:GOTOI20
250 IFI)IMTHENIM=I
260 NEXT
500 POKES+5,0:POKES+6,240
510 POKES+12,85:POKES+13,133
520 POKES+19,lO:POKES+20,197
530 POKES+24,31
174
APPENDIXJ
540 FORI=OTOIM
550 POKES,L(0,I):POKE5+7,L(I,I):POKE5+14,
L(2,I)
560 POKES+l,H(0,I):POKES+8,H(1,I):
p m ~ E S + 1.5, H (2, I)
570 POKES+4,C(0,I):POKES+l1,C(1,I):
POKES+18,C(2,I)
580 FORT=lT080:NEXT:NEXT
590 FORT=lT0200:NEXT:POKES+24,O
600 DATA34334,36376,38539,40830
610 DATA43258,45830,48556,51443
620 DATA54502,57743,61176,64814
1000 DATA594,594,594,596,596
1010 DATA1618,587,592,587,585,331,336
1020 DATAI097,583,585,585,585,587,587
1030 DATA1609,585,331,337,594,594,593
1040 DATA1618,594,596,594,592,587
1050 DATA1616,587,585,331,336,841,327
1060 DATA1607
1999 DATAl)
2000 DATA583,585,583,583,327,329
2010 DATA1611,583,585,578,578,578
2020 DATA196,198,583,326,578
2030 DATA326,327,329,327,329,326,578,583
2040 DATA1606,582,322,324,582,587
2050 DATA329,327,1606,583
2060 DATA327,329,587,331,329
2070 DATA329,328,1609;578,834
2080 DATA324,322,327,585,1602
2999 DATAO
3000 DA TA567 , 566,567, .304,306,308,310
3010 DATA1591,567,311,310,567
3020 DATA306,304,299,308
3030 DATA304,171,176,306,291,551,306,308
3040 DATA310,308,310,306,29 5,297,299,304
3050 DATA1586,562,567,310,315,311
3060 DATA308,313,297
3070 DATA1586,567,560,311,309
3080 DATA308,309,306,308
3090 DATA1577,299,295,306,310,311,304
3100 DATA562,546,1575
3999 DATAl)
175
ADVANCED SOUND PROGRAMMING TECHNIQUES
Advanced techniques center on the use of modulation, filtering and
variations of the ND/S/R envelope. Here are some sample programs
using these special features. The rest is up to your ability to POKE
different values in to appropriate locations to hear the differences. Have
a fun time programming sound!
Sound in the commodore 64 lives in the MOS 6581 chip called SID.
SID stands for Sound Interface Device and is a single-chip 3-voice full
electronic music synthesizer/ sound effects generator. This chip provides
all pitches, tonal qualities and dynamics that you can dream of in a
computer. Specialized control circuitry has reduced the overhead in
software required to produce wide sound variations. Here is a brief
description of SID's chip specifications and pin configuration:
3 TONE OSCILLATORS
Range: 0-4 kHz
4 WAVEFORMS PER OSCILLATOR
Triangle, Sawtooth, Variable Pulse, Noise
3 AMPUTUDE MODULATORS
Range: 48 dB
3 ENVELOPE GENERATORS
Exponential response
Attack Rate: 2mS-8S
Decay Rate: 6mS-24S
Sustain Level: O-peek volume
Release Rate: 6mS-24S
OSCILLATOR SYNCHRONIZA nON
RING MODULATION
PROGRAMMABLE FILTER
Cutoff range: 30 Hz-12 kHz
12 dB/octave Rolloff
Low pass, Band pass,
High pass, Notch outputs
Variable Resonance
MASTER VOLUME CONTROL
2ND POT INTERFACES
RANDOM NUMBER/MODULATION GENERATOR
EXTERNAL AUDIO INPUT
176
PIN CONFIGURATION
6581
SID
APPENDIXJ
MUSIC NOTE VALUES
MUSICAL NOTE OSCILLATOR FREQ
NOTE OCTAVE OECIMAl HI LOW
0
i
C-O 268 1 12
1 C#-O 284 1 28
2 0-0 301 1 45
3 0#-0 318 1 62
4 E-O 337 1 81
5 F-O 358 1 102
6 F#-O 379 1 123
7 G-O 401 1 145
8 G#-O 425 1 169
9 A-O 451 1 195
10 A#-O 477 1 221
11 B-O 506 1 250
16 C-l 536 2 24
17 C#-1 568 2 56
18 0-1 602 2 90
19 0#-1 637 2 125
20 E-l 675 2 163
21 F-l 716 2 204
22 F#-1 758 2 246
23 G-l 803 3 35
24 G#-1 851 3 83
25 A-I 902 3 134
26 A#-1 955 3 187
27 1 1012 3
244
32 C-2 1072 4 48
I
33
C#-2
1136 4 112
34 0-2 1204 4 180
35
0#-2
1275 4 251
36 E-2 1351 5 71
37 F-2 1432 5 152
38
F#-2
1517 5 237
39
G-2 1607 6 71
40
G#-2
1703 6 167
41 A-2
1804 7 12
42 A#-2
1911 7 119
43 B-2
2025 7 233
48 C-3
2145 8 97
177
MUSICAL NOTE OSCILLATOR FREQ
NOTE
-L OCTAVE
DECIMAL HI LOW
49
I
C#--3
2273 8
225
50
D-3
2408 9
104
51
D#-3
2551 9
247
52 E-3
2703 10
143
53 F-3
2864 11
48
54 F#-3
3034 11
218
55
G-3
3215 12
143
56 G#-3
3406 13
78
57 A-3
3608 14
24
58 A#-3
3823 14
239
59 B-3
4050 15
210
64 C-4
4291 16
195
65 C#-4
4547 17
195
66 D-4
4817 18
209
67 D#-4
5103 19
239
68 E-4
5407 21
31
69 F-4
5728 22
96
70 F#-4
6069 23
181
71 G-4
6430 25
30
72 G#-4
6812 26
156
73 A-4
7217 28
49
74
,
A#-4
7647 29
223
75 B-4
8101 31
165
80 C-5
8583 33
135
81 C#-5
9094 35
134
82 D-5 9634 37 162
83 D#-5 10207 39 223
84 E-5 10814 42 62
85 F-5 11457 44 193
86 F#-5 12139 47 107
87 G-5 12860 50 60
88 G#-5 13625 53 57
89 A-5 14435 56 99
90 A#-5 15294 59 190
91 B-5 16203 63
75
96 C-6 17167 67 15
97 C#-6 18188 71 12
98 D-6 19269 75 69
99 0#-6 20415 79 191
100 E-6 21629 84 125
178

OCTAVE
I 101 I F-6
102 F#-6
I G-6
I
G#-6
103
104
105 A-6
106 A#-6
107
112
113
114
115
116
117
118
119
120
121
122
123
8-6
C-7
C#-7
D-7
D#-7
E-7
F-7
F#-7
G-7
G#-7
A-7
A#-7
8-7
DECIMAL
22915
24278
25721
27251
28871
30588
32407
34334
36376
38539
40830
43258
45830
48556
51443
54502
57743
61176
64814
179
OSCILLATOR FREQ
I
HI
89
94
100
106
112
119
126
134
142
150
159
168
179
I 189
I 200
i 212
I 225
238
253
131 I'
214
121
115
199
124
151
30
24
139
126
250
6
172
243
230
143
248
46
j
INDEX TO MEMORY LOCATIONS
Because of the uni4ue way that this book presents its information, we ha\e
grouped the memory locations by major topic, and then alphabeti/ed
them within the groupings. are givcn to locations as they arc
commonly called by either Commodore or a consensus of the literature.
Many locations have not been named. Also, many locations do not have a
simple common usc that they could be listed hereby. If you don"t see what
you arc looking for under a topic such as "Input Output", then look at the
locations without descriptions. You may, of course, "fill in the blanks" as
you discover uses for locations.
DESCRIPTION
Basic ROM routines
BASI(' VARIABLES
Address of current data item
BASIC mode nag
BASIC program storage area
Character dispatch
Current BASIC line number
Current BASIC variable data
Current BASIC variable name
Current byte of BASIC text
Current DATA line number
Error Message
Index variable for FOR NEXT loops
Input prompt nag
Previous BASIC line number
Temporary data area
Temporary pointer data area
Text LIST
Token evaluation
Tokeni/e text
Warm start
Bytes and Bits
clock
180
MEMORY
LOCATION
Pages
117-125
16
65-66
157

776-777

71-72
122-123
6.1-64

7.1-74
19
59-60
255
75-96
774-775

772-77.1
770-771
17
.14-.17
61-62

Pages 10-14
160-162
NAME
SUBFI.G
DATPTR
MSGFLG
IGO:\E
CtJ RUN
VARP:\T
TXTPTR
DAILI!\
IERROR
FORP:\T
OLDLI:\
BASZPT
IQPLOP
IEVAL
ICR:\CH
IMAI!\
I;'\PFLG
I:\DEX
OLDTXT
I]\;PPTR
DESCRIPTION
COMPLEX INTERFACE
ADAPTER (CIA)
General Description
CIA I
Control register
Control register timer A
Data direction register port A
Data direction register port B
I/O
Interrupt control
Joystick I fire button light pen trigger
Joystick 2 direction
Joystick 2 fire button
Read keyboard row values
Time-of-day clock: hours
Time-of-day clock: minutes
Time-of-day clock: seconds
Time-of-day clock: I 10 seconds
Timer A high-byte
Timer A low-byte
Timer B high-byte
Timer Blow-byte
Write keyboard column values
CIA 2
Control register A
Control register B
Data direction register Port B
Data direction register Port B
Data port A:
serial IEEE RS-232 output
Data port B: RS-232
Future I 0 expansion
Future I 0 expansion
1,0
Time-of-day clock: hours
Time-of-day clock: minutes
Time-of-day clock: seconds
Time-of-day clock: I 10 seconds
Timer A high-byte
Timer A low-byte
Timer B high-byte
Timer Blow-byte
181
MEMORY
LOCATION
56334
56322
56323
56332
56333
56321
56320
56320
56321
56331
56330
56329
56328
56325
56324
56327
56326
56320
56590
56591
56576
56579
56576
56577
56832-57087
57088-57343
56588
56587
56586
56585
56584
56581
56580
56583
56582
NAME
Pages 128-129
DESCRIPTIO:"
ClH.SOH.
Charactn L1nlkr cur"H III .,\SCII
Clluntd(l\\11 to tngglL' cur,lll
Cur,llr olink !lag
Cur'>llr blink toggle
(;lossar)
\:\PlT/Ol Tl'l'T
Buller ,tart poillter
lhte lecl'i \ cd !lag
Character pant\
Current deVice numon
Current file name
Current '>econdan addre"
Ddault Illput dn ice
Default Illput dC\ice
I () oujjer pointn
I 0 ,tart addrl'"
Input error log
length oj current filL' Ilame
load ,a\c llH:lllor" pointn,
load \ aif" flag
logical filL' 1l1l1110er
:\lImon of ullt:n file,>
I'a'>'> I crror log
Pas, 2 error log
Read \\rite olod: count
Serial word ouller
Svnc, eOllntdo\\ n
SYnc. numoer
lape I 0 oufjer
rape l11Lltor interlock
remporarv data area
I empurar" D II RQ indicator lor
ea"l't tc read
Tcmpolary storage for cas,ette read
Timing constants
TOD during cassette I 0
182
ivlEVIORY
LOCATION
2()()
205
207
204
17X-179
156
155
1t<6
I t<7-1 t<t<
1t<5
15.1
154
166
19J-194
256-JIt<
It<J
174-175
147
1t<4
152
1St<
159
190
191
165
150
t<2t<-1029
192
151
676
176-177
674
o
14il
149
172-173
lilO
1t<1
:\AME
GDBI:\
HI:\('I
HI:\O\'
BI\,S\V
TAPEI
DSPW
PRTY
fA
F:\ADR
SA
DFLT:\
DFLTO
BUFP:\T
SIAL
BAD

EAt
VERCK
LA
tDT,\D
PTRI
PTR2
FSBLK
MYCH
C\'Tf)'\
SY,\O
CASI
CMPO
D65 10
C]PO
BSOUR
SAL
BITTS
NXTBIT
MEMORY
DESCRIPTION LOCATION NAME
llQ RODATA
195-196 MEMUSS
200 INDX
645
I:\iTERNAL REGISTERS
Storage for 6502 .SP register 783 STREG
Storage for 6502 .X register 781 SXREG
Storage for 6502 . Y register n2 SYREG
Storage for 6502 .A register no SAREG
KERNAL
Acti\e logical file numbers 601-610 LAT
BRT instruction interrupt 790-791 CBINV
CHKIN routine vector 798-799 ICHKIN
CH KOUT routine vector 800-801 ICKOUT
routinc \cctor 804-/W5 !BASIN
CHROOUT routine vector 806-807 IBSOUT
(,[ALI routine vector 812-813 ICLALL
CLOSE routine vector 796-797 ICLOSE
CLRCHN routine \cctor 802-803 ICLRCH
])c\ icc number for each file 611-620 FAT
CiFIl:\ routine vector 810-811 IGETIN
Kernal Pages IlJ-116
LOAD routine vector 816-817 ILOAD
:\ on-mas kable i nterru [1t 792-793 NMINV
OPE:'''; routine vector 794-795 IOPEN
SAVE routine vector 818-819 ISAVE
Sl'cond address each file 621-630 SAT
STOP routine vector 808-809 ISTOP
KEYBOARD
Current key 197 LSTX
I!'iPUT GET from keyboard 208 CRSW
Keyboard decode table 243-244 KEYTAB
Keyboard shift key flag 653 SHFLAG
Keyboard table setu[1 vector 655-656 KEYLOG
Last keyboard shift pattern 654 LSTSHF
,'\ umber of characters in
keyboard buffer 198 NDX
Repeat delay counter 652 DELAY
Repeat speed counter 651 KOUNT
REPEAT key flag 650 RPTFLG
Shift key flag 657 MODE
183
DESCRIPTIO:\
Sill' ell hoarJ hulkl
S I O!' RVS I\C\ Ilag
'LHH
I\\[) lunctl()ll \l'l'd \aiuc'
'IDWRY 'IA:\.\(.I\JE:\T
Blltt(lill III 1ll1'1llOr\ Illl
(lpcrating ,\ \tl'tl1
Bllttlllll oj 'trillg ,torat!l'
fnJ 01 Il\SIC all"a\\ (+1)
Highl',t addrl'" lhell h\ BASI('
I (lad ...a\l' tl1l'IlWI\- pointl'r,
Start oj BASIC array,
Start ld B.\SIC tl',l
Start ul BASIC \arlahk,
lop Olllll'lllOr\ lor operallllg ,\,((:111
l ttlit\ ,tring poinll'r
\lISCELL\:\EOlS
Il'mpman data al-l'a
t ' lllhCd
t- llu,cd
184
ME:vIORY
LOCATION
(,"-I')
145
1.'L)-14\
.1-4
5-6
I.,
14
11\
::'0-::' I


%-111 I
102
IOJ
1()4

106- I OL)
1 i ()
III
II::'
1 1J-114
::'56-::'66
MI-64::'
51-5::'
49-

174-175

43-44
4:"-4(,
64J-644
:".1-54
15
146
16_,-164
679- 7 (,7
71\7
:\I A:\1 E
X1\lA\,
SIKFY
R,\DX
ADRAYI
A[)RA Y2
VAITYP
I,\TFUj
TA\Sej\
I 1\\liM
RFSHO
I-ACT\!'
FACHO
I ACSCi'\
S(j\l(;
HITS
ARCilXI'
,\R(iHO
ARCiSCi,\
ARIS(i\
I ACO\
IHl I-PI
SIR\lEM
IRFTOP
STRE\\)
MFMSII.
I. A I
ARYIAB
IXTTAB
VARI AB
\lI\lSIZ
FRFSPC
(iARHII.
SVXI
MEMORY
LOCATIO:"i NA:\lE
Unused 820-827
Unused 1020-IOn
671-672 IRQTrvlP
Peek and Poke Pages 6-9
Reconfiguring the memory map Pages 106-110
RS-232
Enables 673 E0:ABL
I ndex to end of input buffer 667 RIDBE
I ndex to end of output buffer 670 RODBE
Input bit count 168 BITel
Input bits 167 IT\HII
I nput byte buffer 170 RIDATA
1 nput parity 171 RIPRTY
:'\In.t bIt to send 1r;1 NXTHIT
Nonstandard BPS 661-662 M51 AJR
l\ umber of bits left to send 664 HITNUM
Out bit count 180 BITTS
Out b\te buffer IR2 RODATA
Out parity Ig9 ROPRTY
RS-n2 status register 663 RSTAI
Start bit nag 169 RINONE
Start of input buffer (Page) 668 RIDBS
Start of output buffer (Page) 669 RODBS
6551 command register image 660 M51CDR
6551 control register image 659 M51CTR
SCREEN
Background color 647 GDCOL
Background color 53281
Background color 1 53282
Background color 2 53283
Background color 3 53284
Border color 53280
Bottom of screen memor) 648 HIBASE
Character color code 646 COLOR
Current cursor line number 214 THLX
Cursor column on current line 21 I P.'\iTR
Cursor X- Y position 20 I -202 LXSP
Editor in quote mode nag 212 QTSW
Insert mode nag 216 INSRT
Print shifted characters nag 203 SFDX
Programmable characters Page 134
185
DESCRIPTIO;'\;
RAM start
Rncrse character s\\itch
Screen color
Screen color area
Screen data area
Screen display codes
Screen line length
Start of screen data area
\'ideo bank selection
VIC control register
Serial bus
SOliND
Adl<lnced programming techniljul's
Multiple voice
:Vlusic note I al ues
Programming techniljlles
Single \OIce
V ()ICC I register,
Control register waveform oscillator
Lmelope generator Cycle duration
Frcljucnc\ control
Pul,e lIan'forlll IIldth
Voice 2 registers
Control regi\ler wa\'e!orm oscillator
Fnvelope general0r cycle duration
Frequency control
Pube \\a\eforrn \Iidth
\' oice 3 rcgisters
A [) converter: game paddle
A [) comerter. game paddk 2
Cuntrol generator waveform oscillator
Fmelopc generator
Envelope generator output
Filter cutoff freljuency
Filll'r re,onance loice input contl'ol
Freljllenc\ control
Oscillator random number generator
Pu\,e I\a\ctorm width
Select filter mode volume
186
MEMORY
LOCATION
243-244
IY9
55296-319
1024-2023
Pages 139-140
213
209-210
Pages 133-134
53265
217-242
Pages 126-7
Pag 176
Pages 171-175
Pages 177-179
Pages 154-156
Pages 156-170
54276
54277-27S
54272-273
54272-273
54274-275
542S3
54277-27S
5427S-2S0
542S 1-2S2
54297
5429S
54290
54291-292
54300
54293
54295
542S6-2S7
54299
542SS-2S9
54296
NAME
l'SER
RVS
V ICSC\'
L,\;MX
1':\1
LDTH!
MEMORY
DESCRIPTION
LOCATIO'"' NAME
SPRITES
Algorithm outline
Pages 150-151
color
Page 144
Designing
Page, 141-142
Light-pen X
53267
Light-pen Y position
532611
f ... 1 ulticolor
Page 145
M ulticolor register 0
53285
M ulticolor register I
53286
pointers
Pages 143-144
Sprite background display priority
53275
Sprite collision detect
53278
Sprite collision detect
53279
Sprite colors 0-7
53287-294
Sprite display
53269
Sprite positions
53248-264
Sprite 0-7 color mode select
53276
Sprites 0-7 expand sprite
53277
Pages 142-143
STRING MANIPULATIONS
Last temporary string stack
23-24
LASTPT
Search character
7
CHARAC
Temporary string stack
25-33
TEMPST
Temporary string stack pointer
22 TEMPPT
II
E\'DCHR
II
COUNT
USER COMMANDS/ROUTINES
Hardware IRQ \ector
781\-789 CINV
\' on-maskabk interrupt
792-793
l\iMINV
User-defined vector
814-815
USRCMD
USR (X) starting address
7R5-786
LJSADO
187

Sign up to vote on this title
UsefulNot useful