Beruflich Dokumente
Kultur Dokumente
LAN UAGE
FOR
BEGINNERS
Machine Language Programming
For BASIC Language Programmers
Richard Mansfield
guQM~~a!~~~En~s?l~S9ctions/lnc.
Greensboro, North Carolina
"A fe w e ntry puints, uriginaVupgrad e ROM " a nd "Plotting With the CBM 2022 Printer"
were originally publi sh ed in COMPUTE' M,lga zin e, Jan ua ry/Feb ru a ry 1980, copy ri ght
1980, Sma ll Sys tem Services, Inc. "BASIC 4.0 Memo ry Map" and " PET 4.0 ROM
Routines" w e re origina ll y publis hed in COMPUTE! Ma gaz in e, Nove mbe r/Dece mber
1980, copyright 1980, Small System Services, In c. " More VI C Maps" was o rigina ll y published in COM PUTE' Magazi ne, March ]982, copyrig ht 1982, Sma ll Sys te m Services, In c.
"Commodore 64 Memory Map" was originall y p u bli sh ed in COMPUTE! Magazin e,
October 1982, copyright 1982, Small Sys te ill Se rvices, In c. "Shoo t" was originally published in COMPUTE' Magazin e, Septe mber 1981, copyright 1981 , Sm all Sys tc lll Sc rvices,
Inc. "S UPERMON: A Prima ry Tool For Ma chin e La nguage Programming" was origina lly
publish ed in COMPUTE' Magazin e, Deccmber 198 1, cop yrig ht 1981 , Small Sys tem
Services, In c. "MICR OMON: An Enhan ced Ma chin e La n guage Munitor" was ori gina ll y
publis hed in COMPUTE' Magazine, Ja nuary 1982, copyright 1982, Sm all Sys te m Services,
Inc. " VI C Micromon" wa s origina ll y publi shed in COMPUTE' Magazi n e, November
1982, copyright 1982, Sm a li Systcm Servi ces, Inc. "Superm on 64" was originally publish ed
in COMPUTE! Magazin e, Ja nu a ry 1983, copy ri g ht 1983, Sma ll Sys te m Services, In c.
Copyright 1983, Small System Services, Inc. All rights reserved.
Reproductio n or translatio n of any part of thi s work beyond that permitte d by Secti on s
107 and 108 of the United S tates Co pyright Act witho ut t he permission of th e co pyrig ht
owner is unlawful.
Printed in the United States of America
ISBN 0-942386-11-6
10 9 8 7 6 5 4
ii
Table of Contents
Preface .... ........ .. . .... .. ........... .. ... v
Introduction - Why Machine Language? .... . ... . .. vii
Chapter I : How To Use This Book .......... .. .
Chapter 2: The Fundamentals . . . . . . . . . . . . . . . . .
23
Chapter 4: Addressing. . . . . . . . . . . . . . . . . . . . . ..
37
Chapter 5: Arithmetic. . . . . . . . . . . . . . . . . . . . . ..
53
63
91
97
Chapter 9: ML Equivalents
Of BASIC Commands . . . . . . . . . . . . . . . . . . . ..
I 21
Appendices
A: Instruction Set. . . . . . . . . . . . . . . . . . . . . . . . ..
149
iii
Preface
Something amazing lies beneath BASIC.
Several years ago I decided to learn to program in
machine language, the computer's own language. I
understood BASIC fairly well and I realized that it was simply
not possible to accomplish all that I wanted to do with my
computer using BASIC alone . BASIC is sometimes just
too slow .
I faced the daunting (and exhilarating) prospect of
learning to go below the surface of my computer, of finding out
how to talk directly to a computer in its language, not the
imitation-English of BASIC. I bought four books on 6502
machine language programming and spent several months
practicing with them and puzzling out opcodes and
hexadecimal arithmetic, and putting together small machine
language programs.
Few events in learning to use a personal computer have
had more impact on me than the moment that I could instantly
fill the TV screen with any picture I wanted because of a
machine language program I had written . I was amazed at its
speed, but more than that, I realized that any time large
amounts of information were needed on screen in the future it could be done via machine language. I had, in effect, created
a new BASIC "command" which could be added to any of my
programs. This command - using a SYS or USR instruction to
send the computer to my custom-designed machine language
routine - allowed me to have previously impossible control
over the computer.
BASIC might be compared to a reliable, comfortable car. It
will get you where you want to go. Machine language is like a
sleek racing car - you get there with lots of time to spare .
When programming involves large amounts of data, music,
graphics, or games - speed can become the single most
important factor .
After becoming accustomed to machine language, I
decided to write an arcade game entirely without benefit of
v
vi
vii
Introduction
Introduction
These two programs both print the letter " A" 1000 times on the
screen. The ML version takes up 28 bytes of Random Access Memory
(RAM). The BASIC version takes up 45 bytes and takes about 30 times
as long to finish the job . If you want to see how quickly the ML
works, you can POKE those numbers somewhere into RAM and run
the ML program with a SYS (Commodore computers) or USR (Atari)
or CALL (Apple). In both BASIC and ML, many instructions are
followed by an argument. The instructions SYS and CALL have
numbers as their arguments. In th ese cases, th e instruction is going to
turn control of the computer over to the address given as the
argument. There would be an ML program waiting there. To make it
easy to see this ML program's speed, we'll load it into memory
without yet knowing much about it.
A disassembly is like a BASIC program's LISTing . You can give
the starting address of an ML program to a disassembler and it will
translate the numbers in the computer's memory into a readable
series of ML instructions . See Appendix 0 for a disassembler that you
can use to examine and study ML programs.
viii
Introduction
Here's what the PET/CBM version looks like when it has been
translated by a disassembler:
A Disassembly
Program I-I . Disassembly.
,
,
,
,
,
,
,
,
0360
0362
0364
0367
036A
0360
0370
0371
0373
A9
AO
99
99
99
99
CB
00
60
01
00
00
00
00
00
Fl
BO
Bl
B2
B3
LOA
LOY
STA
STA
STA
STA
INY
BNE
RTS
#$01
#$00
$BOOO,y
$Bl00,y
$B200,y
$B300,y
$0364
ix
Introduction
100
110
120
130
140
Introduction
is the variable located? How long is it? Then, it must find the proper
location on the screen to place the text. However, as we will discover,
ML does not need to hunt for a string variable. And the screen
addresses do not require a complicated series of searches in an ML
program. Each of these tasks, and others, slow BASIC down because
it must serve so many general purposes. The screen fills slowly
because BASIC has to make many more decisions about every action
it attempts than does ML.
Inserting ML For Speed
A second benefit which you derive from learning ML is that your
understanding of computing will be much greater. On the abstract
level, you will be far more aware of just how computers work. On the
practical level, you will be able to choose between BASIC or ML,
whichever is best for the purpose at hand. This choice between two
languages permits far more flexibility and allows a number of tasks to
be programmed which are clumsy or even impossible in BASIC.
Quite a few of your favorite BASIC programs would benefit from a
small ML routine, " inserted" into BASIC with a SYS, USR, or CALL,
to replace a heavily used, but slow, loop or subroutine. Large sorting
tasks, smooth animation, and many arcade-type games must involve
ML.
BASIC Vs. Machine Language
BASIC itself is made up of many ML programs stored in your
computer's Read Only Memory (ROM) or sometimes loaded into
RAM from disk. BASIC is a group of special words such as STOP or
RUN, each of which stands for a cluster of ML instructions. One such
cluster might sit in ROM (unchanging memory) just waiting for you
to type LIST. If you do type in that word, the computer turns control
over to the ML routine which accomplishes a program listing. The
BASIC programmer understands and uses these BASIC words to
build a program. You hand instructions over to the computer relying
on the convenience of referring to all those pre-packaged ML routines
by their BASIC names. The computer, however, always follows a
series of ML instructions. You cannot honestly say that you truly
understand computing until you understand the computer's
language: machine language.
Another reason to learn ML is that custom programming is then
possible. Computers come with a disk operating system (DOS) and
BASIC (or other "higher-level" languages) . After a while, you will
likely find that you are limited by the rules or the commands available
in these languages. You will want to add to them, to customize them.
An understanding of ML is necessary if you want to add new words
to BASIC, to modify a word processor (which was written in ML), or
to personalize your computer - to make it behave precisely as you
want it to.
xi
Introduction
xii
Apple, use 0300. For other computers, you'll need to know where
there are about 100 RAM memory addresses that are safe.
All through this book, the examples will start at various arbitrary
addresses (1000,2000,5000, for example). You should substitute the
addresses which are safe in your computer. Just as it doesn't matter
whether you start a BASIC program at line number 10 or line 100, it
makes no difference whether a ML program starts at address 1000 or
0340, as long as you are putting it in a safe memory zone.
So, start all of the examples you assemble for practice in the
same convenient, safe memory location for your machine. In fact, the
Simple Assembler (SA) was designed to be modified and customized.
See the introduction to Appendix C for more detailed instructions on
customizing. Because you can make the SA conform to your needs,
you might want to replace the line with the INPUT that requests the
starting address (variable SA) with a specific address. In this way,
you can work with the examples in the book without having to
specify the safe address each time.
the examples in the book are usually given in standard ASCII codes
(explained later) .
Chances are that your computer uses a particular code for the
alphabet which is not ASCII. The Commodores use what's called
"PET ASCII" and the Atari uses ATASCII, for ATari ASCII. It's not
that bad, however, since once you 've found the correct number to
show the letter " A" on screen, the letter "B" will be the next higher
number. If you don't have a chart of the character codes for your
computer's screen POKEs, just use this BASIC program and jot down
the number which is used to POKE the uppercase and lowercase
'IA."
0600 PLA
0601 LOY
0603
0605
0608
0609
LOA
STA
RTS
END
in a PLA as the first instruction before continuing with the rest of the
example if you use an Atari.
Most personal computers use Microsoft BASIC, and the PLA is
not necessary . Here's how the same example would look on a
PET/CBM after you answered 0360 as the starting address when the
SA asked for it:
0360 LDY #01
0362 LDA #41
0364 STA 8000
0367 RTS
0368 END (The word "END" isn't a 6502 ML instruction; it's
a special signal to the SA to stop constructing a
program and exit the SA program. Such special
words are called pseudo-ops.)
Then you could test it in direct mode (just typing in the
instruction onto the screen with no line number and not as part of a
BASIC program) by typing:
SYS 864 and you should see the " A" on the screen.
Notice that the Atari and PET versions are similar, but not
identical. All 6502 based computers will work with the same
"instruction set" of commands which the 6502 chip can understand.
The major differences occur when you need to specify something
which is particular to the design of your computer brand . An example
would be the location in memory of your computer's screen. The
instructions at 0605 in the Atari example and 0364 in the PET example
send the code for the letter" A" to the different screen locations for
these two computer brands. Also, the letter" A" itself is signified by
the number 41 on a PET and byJ he number 21 on an Atari.
But we'll go into these things further on. The main thing to learn
here is how to use the SA to practice the examples. If you type in 0600
4
The Fundamentals
The difficulty of learning ML has sometimes been exaggerated. There
are some new rules to learn and some new habits to acquire . But most
ML programmers would probably agree that ML is not inherently
more difficult to understand than BASIC. More of a challenge to
debug in many cases, but it's not worlds beyond BASIC in
complexity. In fact, many of the first home computerists in the 1970's
learned ML before they learned BASIC. This is because an average
version of the BASIC language used in microcomputers takes up
around 12,000 bytes of memory, and early personal computers (KIM,
AIM, etc.) were severely restricted by containing only a small amount
of available memory . These early machines were un able to offer
BASIC, so everyone p rogrammed in ML.
Interestingly, some of these pioneers reportedly fou nd BASIC to
be just as difficult to grasp as ML. In both cases, the problem seems to
be that the rules of a new language simply are" obscure " until you
know them. In general, though, learning either language probably
requires roughly th e same amount of effort.
The first thing to learn about ML is th at it reflects the
construc tion of computers. It most often uses a number system
(hexadecimal) which is not based on ten. You will find a table in
Appendix E which makes it easy to look up h ex, decimal, or binary
numbers.
We count by tens because it is a famili ar (though arbitrary)
grouping for us. Humans have ten fingers. If we h ad eleven fingers,
the odds are that we would be counting by elevens .
2 The Fundamentals
power of two (22) means 2 times 2 (4) . Two to the pow er of three (2 3 )
means 2 times 2 times 2 (8).
10 FOR 1=0 to 16
20 PRINT 2 /\ I
30 NEXT I
ML programming can be done in decimal (based on tengroupings), but usually is not. Most ML programming involves hex
numbers. This means groups of 16 rather than 10.
Why not just program in the familiar decimal numbers (as
BASIC does)? Because 16 is one of the powers of two . It is a
convenient grouping (or base) for ML because it organizes numbers
the way the computer does . For example, all computers work, at the
most elementary level, with bits . A bit is the smallest piece of
information possible: something is either on or off, yes or no, plus or
minus, true or false . This two-state condition (binary) can be
remembered by a computer's smallest single memory cell . This single
cell is called a bit. The computer can turn each bit" on" or " off" as if
it were a light bulb or a flag raised or lowered .
It's interesting that the word bit is frequently explained as a
shortening of the phrase BInary digiT. In fact, the word bit goes back
several centuries. There was a coin which was soft enough to be cut
with a knife into eight pieces . Hence, pieces of eight. A single piece of
this coin was called a bit and, as with computer memories, it meant
that you couldn't slice it any further. We still use the word bit today as
in the phrase two bits, meaning 25 cents.
Whatever it's called, the bit is a small, essential aspect of
computing. Imagine that we wanted to remember the result of a
subtraction. When two numbers are subtracted, they are actually
being compared with each other. The result of the subtraction tells us
which number is the larger or if they are equal. ML has an instruction,
like a command in BASIC, which compares two numbers by
subtraction. It is called CMP (for compare) . This instruction sets
"flags" in the CPU (Central Processing Unit), and one of the flags
always remembers whether or not the result of the most recent action
taken by the computer was a zero. We'll go into this again later. What
we need to realize now is that each flag -like the flag on a mailboxhas two possible conditions: up or down . In other words, this
information (zero result or not-zero) is binary and can be stored within
a single bit. Each of the flags is a bit. Together they make up one byte .
That byte is called the Status Register .
Byte Assignments
Our computers group these bits into units of eight, called bytes. This
relationship between bits and bytes is easy to remember if you think
of a bit as one of the " pieces of eight." Eight is a power of two also
8
The Fundamentals 2
10
11
12
13
14
15
16
17
Hex
01
02
03
04
05
06
07
08
09
(note new digits)--> OA
OB
Oc
00
OE
OF
(note new column--> 10
in the hex)
11
Binary
00000001
00000010
00000011 (1 and 2)
00000100
00000101 (4 and 1)
00000110 (4 and 2)
00000111 (4+2+ 1)
00001000
00001001
00001010
00001011
00001100
00001101
00001110
00001111
00010000
00010001
9
2 The Fundamentals
See how hex $10 (hex numbers are usually preceded by a dollar
sign to show that they are not decimal) looks like binary? If you split a
hex number into two parts, 1 and 0, and the binary (it' s an eight-bit
group, a byte) into two parts, 0001 and 0000 - you can see the
relationship.
1 HE$="01234S6789ABCDEF"
2 PRINT"{CLEAR}{03 DOWN}PLEASE CHOOSE:
4 PRINT" {03 DOWN} {03 RIGHTl1 -INP UT HEX &
GET DECIMAL BACK .
S REM NEW LINE HERE
6 PRINT"{02 DOWN}
2-INPUT DECIMAL TO G
ET HEX BACK.
7 GETK:IFK=0THEN7
9 PRINT {CLEAR}":0N KGOT0200,400
100 H$="":FORM=3T00STEP - 1:N%=DE/(16 M):DE=
DE-N%*16 M:H$=H$+MID$(HE$ ,N% +l , l)
: NEXT
101 RETURN
102 D=0:Q=3:FORM=lT04: FORW=0T015:IFMID$(H$
,M , l)=MID$(HE$ , W+1,1)THEN104
103 NEXTW
104 D1=W*(16 (Q:D=D+D1 :Q=Q-1:NEXTM
105 DE=INT(D) : RETURN
200 INPUT"{ 02 DOWN}HEX"iH$ :GOSUB102:PRINTS
PC(ll)"{UP}= {REV}" DE "[LEFT} "
210 GOT0200
400 INPUT"{02 DOWN}DECIMAL"iDE:GOSUB100:PR
I
10
100
130
140
150
DIM H$(23),N$(9):OPEN#1,4,0,"K:"
GRAPHICS 0
PRINT" PLEASE CHOOSE:"
PRINT"l- INPUT HEX AND GET DECIMAL BAC
K. "
170
180
190
300
310
320
330
IFK<490R>50THEN170
PRINTCHR$(K):ONK-48 GOTO 300,400
H$="@ABCDEFGHIIIIIIIIJKLMNO"
PRINT"HEX"~ :INPUT N$:N=0
FORI=lTOLEN(N$)
N=N*16+ASC(H$(ASC(N$(I-47-64:NEXTI
340
400
410
420
430
440
450
H$="0123456789ABCDEF"
PRINT"DECIMAL"~ :INPUTN:M=4096
PRINTN; "=$" ~
FORI=lT04:J=INT(N/M)
PRINTH$(J+1,J+1);:N=N-M*J:M=M/16
NEXTI:PRINT:PRINT:GOT0140
PRINT"$"~N$~"="~N:PRINT:PRINT:GOT0140
11
2 The Fundamentals
exercises at the end of this chapter. As you work with ML, hex will
gradually seem less and less alien.
To figure out a hex number, multiply the second column by 16
and add the other number to it. So, 1A would be one times 16 plus 10
(recall that A stands for ten) .
Hex does seem impossibly confusing when you come upon it for
the first time. It will never become second nature, but it should be at
least generally understood. What is more, you can program in ML
quite easily by looking up the hex numbers in the table at the end of
this book. You need not memorize them beyond learning to count
from 1 to 16 -learning the symbols . Be able to count from 00 up to
OF. (By convention, even the smallest hex number is listed as two
digits as in 03 or OB. The other distinguishing characteristic is that
dollar sign that is usually placed in front of them: $05 or $OE.) It is
enough to know what they look like and be able to find them when
you need them.
The Fundamentals 2
.~
13
2 The Fundamentals
Figure 22.
Like all the rest, this byte is dark. Each bulb is off. Observing this, we
know that the byte here is "holding" or representing a zero. If
someone at the computer types in POKE 1504, 1- suddenly the
rightmost light bulb goes on and the byte holds a one instead of a
zero :
Figure 23.
"'/ "
-Qj,
This rightmost bulb is in the l's column (just as it would be in our
usual way of counting by tens, our familiar decimal system). But the
next bulb is in a 2's column, so POKE 1504,2 would be:
Figure 24.
Figure 2-5.
\ I / I,
"
... '
II",.
~
In this way - by checking which bits are turned on and then adding
them together - the computer can look at a byte and know what
number is there. Each light bulb, each bit, is in its own special
14
The Fundamentals 2
position in the row of eight and has a value twice the value of the one
just before it:
Figure 2-6.
100
110
120
130
140
150
160
170
180
190
2 The Fundamentals
200
210
220
230
PRINT CHR$(C0);
P = P/2: NEXT I: PRINT
PRINT" WHAT IS THIS IN DECIMAL?"
INPUT Q: IF Q = X THEN PRINT
"CORRECT": GOTO 250
240 PRINT "SORRY, IT WAS";X
250 FOR T = 1 TO 1000: NEXT T
260 GOTO 140
This program will print out the entire table of binary numbers
from 0 to 255:
Program 2-4.
100
110
120
140
150
160
170
180
190
200
210
220
260
5. 17
6. 32
7. 128
8. 129
16
The Fundamentals 2
9. 255
10. 254
We are not making an issue of learning hex or binary . If you
needed to look up the answers in the table at the end of the book,
fine . As you work with ML, you will familiarize yourself with some of
the common hex numbers. You can write most ML programs without
needing to worry about binary . For now, we only want to be able to
recognize what hex is . There are even some pocket "programmer"
calculators which change decimal to hex for you and vice versa.
Another way to go about " hexing" is to use a BASIC program which
does the translation . A problem with BASIC is that you will be
working in ML and your computer will be tied up. It is often
inconvenient to crank up a BASIC program each time you need to
work out a hex number. However, the Simple Assembler will do the
translations for you any time you need them.
One other reason that we are not stressing hex too much is that
ML is generally not programmed without the help of an assembler.
The Simple Assembler provided in this book will handle most of your
input automatically . It allows you to choose whether you prefer to
program in hex or decimal. You make this decision by changing line
10 before starting to assemble. After that, you can put in hex or
decimal without worrying that there will be any confusion about your
intentions.
This little BASIC program is good for practicing hex, but also
shows how to change a small part and make it work for two-byte hex
numbers. It will take decimal in and give back the correct hex. It is
designed for Microsoft BASIC computers, so it will not work on the
Atari.
10 H$= "0123456789ABCDEF"
20 PRINT "ENTER DECIMAL NUMBER";:INPUT X
30 IF X > 255 GOTO 20: REM NO NUMBERS BIGGER
THAN 255 ALLOWED
40 FORI=1 TOO STEP-]
50 N%=X!(161'1): X=X-N% * 161'1
60 HE$ = HE$ + MID$(H$,N% + 1,1)
70 NEXT
80 PRINTHE$
90 GOT020
For larger hex numbers (up to two, to the power of 16 - which is
65536), we can just change the above program. Eliminate line 30 and
change line 40 to: FOR 1=3 TO 0 STEP -1. This will give us four-place
hex numbers (used only as addresses) but which will also become
recognizable after some ML practice.
17
2 The Fundamentals
18
The Fundamentals 2
10
20
30
40
50
19
2 The Fundamentals
Program 2-7.
1000 A9 02 69 05 80 AO OF 60
The third type of listing is called a disassembly. It's the opposite of
an assembly because another program called a disassembler takes
machine language (the series of numbers, the opcodes in the
computer's memory) and translates it into the words, the
mnemonics, which ML programmers use. The instruction you use
when you want to load the accumulator is called LDA, and you can
store what's in the accumulator by using an STA. We'll get to them
later. In this version of our example addition routine, it's a bit clearer
what's going on and how the program works. Notice that on the left
we have the hex numbers and, on the right, the translation into ML
instructions. ADC means ADd with Carry and RTS means ReTurn
from Subroutine.
Program 2-8.
1000
1002
1004
1007
A9 02
LOA #$02
69 05
AOC #$05
80 AO OF STA $OFAO
RTS
60
20
......
A9 02
69 05
80 AO OF
60
Object
Code
0005
0100
0110
0120
0130
0140
Line
Number
LABEL FILE:
A9 02
69 05
80 AO OF
60
ADDER =0005
TWO =0002
1000100210041007-
0005
0010
0020
0030
0040
0100
0110
0120
0130
0140
.BA
LOA
ADC
STA
RTS
.EN
$1000
2
5
$OFAO
LOA #TWO
ADC #ADDER
STA STORAGE
RTS
.EN
START =1000
START
.BA
.DE
.DE
.DE
$1000
#$02
#$05
$OFAO
STORAGE =OFAO
LOAD A WITH 2
ADD 5
STORE AT DECIMAL 4000
RETURN
END OF ASSEMBLY
(4096)
iDEFINE LABEL "TWO" AS 2.
iDEFINE "ADDER" AS A 5.
iDEFINE STORAGE ADDR.
Comments
r - - -- - - - - Source Code - - - - - - ,
Disassembly
TWO
ADDER
STORAGE
1000100210041007-
Memory
Address
::r
t-J
iii
lit
:::I
3It)
Co
:::I
r::
."
It)
2 The Fundamentals
START
.BA
.DE
. DE
.DE
$1000
2
5
$OFAO
LOA #TWO
ADC #ADDER
STA STORAGE
RTS
.E N
; START
;DEFINE
;DEFINE
;DEFINE
LOAD A WITH 2
ADD 5
STORE AT DECIMAL 4000
RETURN
END OF ASSEMBLY
Program 2-11 illustrates just the source code part. The object code has
not yet been generated from this source code. The code has not been
assembled yet. You can save or load source code via an assembler in the
same way that you can save or load programs via BASIC. When 2-11
is in the computer, you could type" ASSEMBLE" and the assembler
would translate the instructions, print them on the screen, and POKE
them into memory.
The Simple Assembler operates differently . It translates, prints,
and POKEs after you hit RETURN on each line of code. You can save
and load the object, but not the source code.
Before we get into the heart of ML programming, a study of the
instruction mnemonics and the various ways of moving information
around (called addressing), we should look at a major ML
programming aid: the monitor. It deserves its own chapter.
The Monitor
A monitor is a program which allows you to work directly with your
computer's memory cells. When the computer "falls below" BASIC
into the monitor mode, BASIC is no longer active . If you type RUN, it
will not execute anything. BASIC commands are not recognized. The
computer waits, as usual, for you to type in some instructions. There
are only a few instructions to give to a monitor. When you're working
with it, you're pretty close to talking directly to the machine in
machine language.
The PET and Apple II have monitors in ROM. This means that
you do not need to load the monitor program into the computer; it's
always available to you. (PETs with Original ROM sets do not have a
ROM monitor; you must load in the monitor from a tape or disk.)
Atari and VIC computers have a monitor as part of a larger
"Assembler Editor" plug-in cartridge. The monitor on the Atari
cartridge is called the "Debugger." That's a good name for it:
debugging is the main purpose of a monitor. You use it to check your
ML code, to find errors .
The various computers have different sets of instructions which
their monitors recognize. However, the main functions are similar, so
it is worth reading through all of the following descriptions, even if
the discussion is not specifically about the monitor for your
computer. On the PET/CBM, VIC, ang 64 you can add many of these
functions with a monitor" extension" program called Micraman or
Superman (about which more later) . These monitors are included in
Appendix F. The monitors on the Apple II and available in the Atari
Assembler Editor Cartridge do not need" extending. " They contain
most of the significant features required of a monitor. However, the
special extensions in Appendix F for the Commodore computers add
considerably to the Commodore ML programmer's repertoire .
The Apple II
You enter the Apple monitor by typing CALL -151. You will see the
"*" monitor prompt and the cursor immediately after it. Here are the
monitor instructions :
1. Typing an address (in hex) will show you the number
contained in that memory cell. *2000 (hit RETURN) will show 2000 FF (if, in fact, 255 decimal ($FF, hex) is in that location).
2. You can examine a larger amount of memory in hex (this is
23
3 The Monitor
The Monitor 3
25
3 The Monitor
26
The Monitor 3
2007
2008
2010
Instruction Field
LDY
LDA
STA
DEY
BNE
RTS (or BRK)
2004
Label
START
LOOP
Instruction
LDY
LDA
STA
DEY
BNE
Argument
#10
#33
(88), Y
LOOP
Comments
Set up counter for loop
"A" in ATASCII
Loop until zero
Notice that labels allow us to use the word LOOP instead of the
specific address we want to loop back to. In addition to all this, there
are pseudo-ops which are instructions to the assembler to perform
some task. A pseudo-op does not become part of the ML program
(it's not a 6502 instruction), but it affects the assembly process in
27
3 The Monitor
The Monitor 3
02000
2000 FF 02 60 20 FF 02 00 00
02000,2020 (would dump out memory between these two
addresses)
4. Change memory: type C2000 < 00,00 to put zeros into the first
two bytes following address 2000 .
5. Transfer (move) memory: type M1000 < 2000,2010 and you
will non-destructively copy what's between 2000-2010 down into
1000-1010.
6. Compare (verify) memory: type V1000 < 2000,2010 and any
mismatches will be printed out.
7. Disassemble (list): type L2000 and you will see 20 lines of
instructions displayed, the mnemonics and their arguments.
8. Mini-assemble: the DEBUG mode allows you to enter
mnemonics and arguments one at a time, but you cannot use labels.
(The pseudo-ops BYTE, DBYTE, and WORD are available, though.)
This is similar to the Simple Assembler and the mini-assemblers
available to Apple II and PET monitor users .
You type 2000 < LDA $05 and the computer will show you the
bytes as they assemble into this address. Subsequent instructions can
be entered by simply using the less-than sign again: < INC $05. To
return to the DEBUG mode, you can hit the RETURN key on a blank
line.
9. Go (RUN a program): type G2000 and whatever program
starts at address 2000 will run. Usually, you can stop the RUN by
hitting the BREAK key . There are cases, though, (endless loops)
which will require that you turn off the computer to regain control.
10. Trace: type T2000 and you will also RUN your program, but
the registers, bytes of ML code, and the disassembled mnemonics
and arguments are shown as each instruction is executed. This is
especially useful since you can watch the changes taking place in the
registers and discover errors. If you have an LDA $03 and you then
expect to find the accumulator to have the number three in it - you'll
notice that you made that very common mistake we talked about
earlier. Following LDA $03, you will see that the accumulator has,
perhaps, a ten in it instead of the three you thought you'd get. Why?
Because you wanted to write LDA #03 (immediate). Instead, you
mistakenly loaded A with the value in address three, whatever it is.
Seeing unexpected things like this happen during trace allows
you to isolate and fix your errors . Trace will stop when it lands on a
BRK instruction or when you press the BREAK key.
11 . Step: type S2000 and you will "step" through your program
at 2000, one instruction at a time. It will look like trace, but you move
slowly and you control the rate. To see the following instruction, you
type the S key again. Typing S over and over will bring you through
29
3 The Monitor
the program.
12. Return to EDIT mode: type X.
PET, VIC, And Commodore 64 Monitors
The resident monitor on the PET/CBM computer is the simplest of
monitors . You enter it from BASIC by typing SYS 4 when no program
is RUNning. This lands on a BReaK instruction; address 4 always
contains a zero which is the opcode for BRK. You are then in monitor
mode. Original ROM PETs, the earliest models, do not have a
monitor in ROM, but one is available on tape, called TIM. Everything
is done with hexadecimal numbers .
There are only six monitor commands:
1. Go (RUN) : type G 2000 and the program starts at address
2000. It will continue until it lands on a BRK instruction . There is no
key you can type to stop it .
2. LOAD (from tape or disk) : type L "0:NAME",08 and a
program called "name" on disk drive zero will be loaded at the
address from which it was SAVEd. There is no provision to allow you
to LOAD to a different address . L "NAME",Ol will LOAD from tape.
3. SAVE (to a tape or disk) : type S "0:NAME",08,2000,2009 and
the bytes between hex 2000 and 2008 will be saved to disk drive zero
and called "name." Important note: you should always be aware that a
SAVE will not save the highest byte listed in your SAVE instruction. You
always specify one byte more than you want to save . In our example
here, we typed 2009 as our top address, but the monitor SAVEd only
up to 2008 . S "NAME",01,2000,2009 will SAVE to tape.
An interesting trick is to save the picture on your screen . Try this
from the monitor (for a disk drive) : S "0:SCREEN",08,8000,8400
(with a tape drive: S "SCREEN",01,8000,8400) . Then, clear the
screen and type: L "0:SCREEN",08 (tape: L "SCREEN",Ol). This
illustrates that an ML SAVE or LOAD just takes bytes from within
whatever range of memory you specify; it doesn't care what those
bytes contain or if they make ML sense as a program.
4. See memory (memory dump): type M 2000 2009 and the
bytes between these addresses will be displayed on screen. To change
them, you use the PET cursor controls to move to one of these hex
numbers and type over it. Hitting the RETURN key makes the change
in the computer's memory (the same way you would change a line in
BASIC).
Machine Language Registers
5. See the registers: type R and you will see something like this
on screen (the particular numbers in each category will depend on
what's going on in your computer whenever you type R):
30
PC
IRQ
SR
AC
XR
YR
SP
2000
E62E
30
00
05
FF
FE
The Monitor 3
3 The Monitor
letter A" into your screen RAM to see what number represents the
start of your screen alphabet and use those numbers for any direct-toscreen messages in this book .
t., b.<ASCII
ATA~ j.""'lJ'itf.Jo.-J h, Ivf
1500 80 P
48 ~0 Jet,.."
1501 82 R
50
321502 69 E
37 I ~5"
1503 83 S
51
,33
1504 83 S
51)3
1505 32
0
0
1506 65 A
33
).1
1507 78 N
46
;).t
1508 89 Y
57
3"/
1509 32
0
0
150A 75 K
43 .)g
150B 69 E
37 CJ.!>
150C 89 Y
57
1500 00
255 fi(the delimiter,
the signal that the message is
finished . Atari must use
something beside zero which is
used to represent the space
character. )
We'll put the subroutine at $1000, but be warned! This
subroutine will not work as printed. There are two errors in this
program. See if you can spot them :
1000 LOY #$00
1002 LOA $1500, Y
1005 CMP $00
(is it the delimiter?)
1007 BNE $100A (if not, continue on)
1009 RTS
(it was zero, so quit and return to whatever
JSRed , or called, this subroutine)
100A STA $8000, Y (for PET)
1000 INY
100E IMP $1000
(always JMP back to $1000)
Make the following substitutions if you use one of these machines:
Atari: 1005 CMP $FF
(That's hex for 255.)
Atari: 100A STA ($88), Y
Apple : 100A STA $0400, Y
Since we haven't yet gone into addressing or instructions much,
this is like learning to swim by the throw-them-in-the-water method.
See if you can make out some of the meanings of these instructions
anyway.
II
W.
32
The Monitor 3
This subroutine will not work. There are two errors and they are
two of the most common bugs in ML programming. Unfortunately,
they are not obvious bugs. An obvious bug would be mistyping: LOS
when you mean LOA. That sort of bug would be caught by your
assembler, and it would print an error message to let you know that
no such instruction as LOS exists in 6502 ML.
The bugs in this routine are mistakes in logic. If you disassemble
this, it will also look fine to the disassembler, and no error messages
will be printed there either. But, it will not work the way you wanted
it to. Before reading on, see if you can spot the two errors. Also see if
you can figure out how this routine would execute its instructions.
Where does the computer go after the first pass through this code?
When and how does it finish the job?
3 The Monitor
The Monitor 3
3 The Monitor
36
Addressing
The 6502 processor is an electronic brain. It performs a variety of
manipulations with numbers to allow us to write words, draw
pictures, control outside machines such as tape recorders, calculate,
and do many other things. Its manipulations were designed to be
logical and fast. The computer has been designed to permit
everything to be accomplished accurately and efficiently.
If you could peer down into the CPU (Central Processing Unit),
the heart of the computer, you would see numbers being delivered
and received from memory locations all over the computer.
Sometimes the numbers arrive and are sent out, unchanged, to some
other address . Other times they are compared, added, or otherwise
modified, before being sent back to RAM or to a peripheral.
Writing an ML program can be compared to planning the
activities of this message center. It can be illustrated by thinking of
computer memory as a city of bytes and the CPU as the main post
office. (See Figure 4-1.) The CPU does its job using several tools: three
registers, a program counter, a stack pointer, and seven little one-bit
flags contained in a byte called the Status Register. We will only
concern ourselves with the "C" (carry) flag and the "Z" (it equals
zero) flags. The rest of them are far less frequently needed for ML
programming so we ' ll only describe them briefly. (See Figure 4-1 .)
Most monitors, after you BRK (like BASIC's STOP) out of a
program, will display the present status of these tools. It looks
something like this:
PC
IRQ SR AC XR YR SP
0005 E455 30 00 5E 04 F8
The PC is the Program Counter and it is two bytes long so it can
refer to a location anywhere in memory. The IRQ is also two bytes
and points to a ROM ML routine which handles interrupts, specialpriority actions. A beginning ML programmer will not be working
with interrupts and need not worry about the IRQ . You can also more
or less let the computer handle the SP on the end. It's the stack
37
~~[f~
mJ_@f1]'if
D~pf. Of
fLAGS
5TATUS REGI57BK
~&1~
CJfpr. OF
OQ
Ia.
Q.
Q.
.&:00
Addressing 4
pointer. The SP keeps track of numbers, usually return-fromsubroutine addresses which are kept together in a list called the stack.
The computer will automatically handle the stack pointer for us .
It will also deal with IRQ and the program counter. For example, each
ML instruction we give it could be one, two, or three bytes long. TYA
has no argument and is the instruction to transfer a number from the
Y register to the accumulator. Since it has no argument, the PC can
locate the next instruction to be carried out by raising itself by one. If
the PC held $4000, it would hold $4001 after execution of a TYA . LOA
#$01 is a two-byte instruction . It takes up two bytes in memory so the
next instruction to be executed after LOA #$01 will be two bytes
beyond it. In this case, the PC will raise itself from $4000 to $4002 . But
we can just let it work merrily away without worrying about it.
4 Addressing
or
1000 LDA $2500
These two, STore A and LoaD A, STA and LOA, are the
instructions which get a byte from , or send it to, the accumulator. The
address, though, is found in the numbers following the instruction.
The items following an instruction are called the instruction's
argument. You could have written the address several ways. Writing it
as $2500 tells your assembler to get it from, or send it directly to, hex
$2500. This kind of addressing uses just a simple $ and a four-digit
40
""......
Figure 4-2. The First Few Addresses On A Street With 65536 Houses.
Hfl611rs
ZERO
PAGE
la.
::::I
OQ
>
c..
c..
""til
4 Addressing
Addressing 4
(Absolute mode)
(Immediate mode)
The first example will load the accumulator with whatever
number it finds at address $2500. In the second example, we simply
wanted to put a 9 into the accumulator. We know that we want the
number 9. So, instead of sending off for the 9, we just type a 9 in
where we would normally type a memory address . And we tack on a
# symbol to show that the 9 is the number we're after. Without the #,
the computer will load the accumulator with whatever it finds at
address number 9 (LOA $09). That would be zero page addressing,
instead of immediate addressing.
In any case, immediate addressing is very frequently used, since
you often know already what number you are after and do not need
to send for it at all. So, you just put it right in with a #. This is similar
to BASIC where you define a variable (10 VARIABLE =9) . In this
case, we have a variable being given a known value. LOA #9 is the
same idea. In other words, immediate addressing is used when you
know what number you want to deal with; you're not sending off for
it. It's put right into the ML code as a number, not as an address.
To illustrate immediate and absolute addressing modes working
together, let's imagine that we want to copy a 15 into address $4000 .
(See Program 4-2.)
Implied
Here's an easy one. You don't use any address or argument with this
one.
This is among the more obvious modes. It's called implied,
since the mnemonic itself implies what is being sent where: TXA
means transfer X register's contents to the Accumulator. Implied
addressing means that you do not put an address after the instruction
(mnemonic) the way you would with most other forms of addressing.
It's like a self-addressed, stamped envelope. TYA and others are
similar short-haul moves from one register to another. Included in
this implied group are the SEC, CLC, SED, CLO instructions as well.
They merely clear or set the flags in the status register, letting you
43
:t
2000- A9 OF
2002- 80 00 40
0010
0020
0030
0040
0050
0060
0070
0080
0090
0100
0110
LOAD A WITH LITERALLY 15
STORE IT IN ADDRESS 4000
LOA #15
STA $4000
.BA $2000
ML PROGRAM IS $2000 ("BA"
OQ
m.
c.
Addressing 4
45
4 Addressing
LDX #$00
INX
BNE 1002
BRK
(The X register will count up by ones until it hits 255 decimal and
then it resets itself to zero.)
This is what you type in to create a ML FOR-NEXT loop . You are
branching, relative to address 1003, which means that the assembler
will calculate what address to place into the computer that will get
you to 1002. You might wonder what's wrong with the computer just
accepting the number 1002 as the address to which you want to
branch . Absolute addressing does give the computer the actual
address, but the branching instructions all need addresses which are
"offsets" of the starting address. The assembler puts the following
into the computer:
1000
1002
1003
1005
A2 00
E8
DO FO
00
The odd thing about this piece of code is that "FO" at 1004. How
does FO tell the computer to Branch back to 1002? (Remember that X
will increment up to 255, then reset to zero on the final increment.)
$FD means 253 decimal. Now it begins to be clear why relative
addressing is so messy. If you are curious, numbers larger than 127,
when found as arguments of relative addressing instructions, tell the
computer to go back down to lower addresses. What's worse, the
larger the number, the less far down it goes. It counts the address 1005
as zero and counts backwards thus:
1005=0
1004=255
1003=254
1002=253
46
Addressing 4
4 Addressing
Addressing 4
Indirect Y
This one is a real workhorse; you'll use it often. Several of the
examples in this book refer to it and explain it in context. It isn't so
much an address in itself as it is a method of creating an address. It
looks like this:
$4000 STA ($80), Y
49
Ul
9C409C429C449C479C4A9C4D9CSO9CS19CS3-
AO
A9
99
99
99
99
C8
DO
60
Program 4-3.
Fl
00
41
00
00
00
00
04
05
06
07
0010
0020
0030 CHAR.A
0040
0050
0060
0070 LOOP
0080
0090
0100
0110
0120
0130
0140
LOY
LOA
STA
STA
STA
STA
INY
BNE
RTS
.EN
LOOP
#$00
#CHAR.A
$0400,Y
$0500,y
$0600,y
$0700,y
.DE $41
.BA 40000
RAISE Y BY l.
IF NOT ZERO, KEEP GOING.
CHARACTER "A"
OQ
11\
:;.
11\
~
~
.,ID
IloCIo.
Addressing 4
Indirect X
Not often used, this mode makes it possible to set up a group of
pointers (a table) in page zero. It's like Indirect Y except the X register
value is not added to the address pointer to form the ultimate address
desired . Rather, it points to which of the pointers to use. Nothing is
added to the address found in the pointer.
It looks like this:
$5000 STA ($90,X)
To see it in action, let's assume that part of zero page has been
set up to point to various parts of memory. A table of pointers, not
just one:
$0090 $00 Pointer #1
$0091 $04 (it points to $0400)
$0092 $05 Pointer #2
$0093 $70 ($7005)
$0094 $EA Pointer #3
$0095 $80 (pointing to $80EA)
If X holds a two when we STA $(90,X), then the byte in A will be
sent to $7005 . If X holds a foUf, the byte will go to $80EA.
All in all, this has relatively little merit. It would be useful in rare
situations, but at least it's there if you should find you need it.
Accumulator Mode
ASL, LSR, ROL, and ROR shift or manipulate the bits in the byte in
the accumulator. We'll touch on them in the chapter on the
instruction set. They don't have much to do with addressing, but
they are always listed as a separate addressing mode.
Zero Page,Y
This can only be used with LOX and STX. Otherwise it operates just
like Zero Page, X discussed above.
There you have them, thirteen addressing modes to choose
from. The six you should focus on and practice are: Immediate,
Absolute (plus Absolute, Y and ,X), Zero Page, and Indirect Y. The
rest are either automatic (implied) or not really worth bothering with
until you have full command of the six common and useful ones.
Now that we've surveyed the ways you can move numbers
around, it's time to see how to do arithmetic in ML.
51
Arithmetic
There'll be many things you'll want to do in ML, but complicated
math is not one of them . Mathematics beyond simple addition and
subtraction (and a very easy form of elementary division and
multiplication) will not be covered in this book . For most games and
other ML for personal computing, you will rarely need to program
with any complex math. In this chapter we will cover what you are
likely to want to know. BASIC is well-suited to mathematical
programming and is far easier to program for such tasks.
Before we look at ML arithmetic, it is worth reviewing an
important concept: how the computer tells the difference between
addresses, numbers as such, and instructions . It is valuable to be able
to visualize what the computer is going to do as it comes upon each
byte in your ML routine.
Even when the computer is working with words, letters of the
alphabet, graphics symbols and the like - it is still working with
numbers. A computer works only with numbers . The ASCII code is a
convention by which the computer understands that when the
context is alphabetic, the number 65 means the letter A. At first this is
confusing. How does it know when 65 is A and when it is just 65? The
third possibility is that the 65 could represent the 65th cell in the
computer's memory.
It is important to remember that, like us, the computer means
different things at different times when it uses a symbol (like 65). We
can mean a street address by it, a temperature, the cost of a milk
shake, or even a secret code. We could agree that whenever we used
the symbol "65" we were ready to leave a party . The point is that
symbols aren't anything in themselves . They stand for other things,
and what th ey stand for must be agreed upon in advance. There must
be rules. A code is an agreement in advance that one thing
symbolizes another.
5 Arithmetic
screen - but it mainly waits in an endless loop for you to press a key
on your keyboard to let it know what it's supposed to do. There is a
memory cell inside (this, too, varies in its location) which the
computer constantly checks. On some computers, this cell always has
a 255 in it unless a key is pressed. If you press the RETURN key, a 13
will replace the 255. At last, after centuries (the computer's sense of
time differs from ours) here is something to work with! Something
has come up to the gate at long last.
You notice the effect at once - everything on the screen mov.es
up one line because 13 (in the ASCII code) stands for carriage return.
How did it know that you were not intending to type the number 13
when it saw 13 in the keyboard sampling cell? Simple. The number
13, and any other keyboard input, is always read as an ASCII number.
In ASCII, the digits from 0 through 9 are the only number
symbols. There is no single symbol for 13. So, when you type in a 1
followed immediately by a 3, the computer's input-from-thekeyboard routine scans the line on the screen and notices that you
have not pressed the "instant action" keys (the STOP, BREAK, ESC,
TAB, cursor-control keys, etc.). Rather, you typed 1 and 3 and the
keyboard sampling cell (the "which key pressed" address in zero
page) received the ASCII value for one and then for three. ASCII
digits are easy to remember in hex: zero is 30, 1 is 31, and up to 39 for
nine. In decimal, they are 48 through 57.
The computer decides the "meaning" of the numbers which
flow into and through it by the numbers' context. If it is in
"alphabetic" mode, the computer will see the number 65 as "a"; or if
it has just received an "a," it might see a subsequent number 65 as an
address to store the" a". It all depends on the events that surround a
given number. We can illustrate this with a simple example:
2000
LOA #65
A9 (169) 41 (65)
2000 STA $65
85 (133) 41 (65)
This short ML program (the numbers in parentheses are the
decimal values) shows how the computer can "expect" different
meanings from the number 65 (or 41 hex). When it receives an
instruction to perform an action, it is then prepared to act upon a
number. The instruction comes first and, since it is the first thing the
computer sees when it starts a job, it knows that the A9 (169) is
not a number. It has to be one of the ML instructions from its set of
instructions (see Appendix A) .
Arithmetic 5
5 Arithmetic
Addition
Arithmetic is performed in the accumulator. The accumulator holds
the first number, the target address holds the second number (but is
not affected by the activities), and the result is left in the accumulator.
So:
LDA #$40 (remember, the # means immediate, the $ means
hex)
ADC #$01
will result in the number 41 being left in the accumulator. We could
then STA that number wherever we wanted. Simple enough. The
ADC means ADd with Carry. If this addition problem resulted in a
number higher than 255 (if we added, say, 250 + 6), then there would
have to be a way to show that the number left behind in the
accumulator was not the correct result. What's left behind is the carnI
What would happen after adding 250 + 6 is that the accumulator
would contain a 1. To show that the answer is really 256 (and not 1),
the "carry flag" in the status register flips up . So, if that flag is up, we
know that the real answer is 255 plus the 1 left in the accumulator.
To make sure that things never get confused, always put in a
CLC (CLear Carry) before any addition problems. Then the flag will
go down before any addition and, if it is up afterward, we'll know
that we need to add 256 to whatever is in the accumulator. We'll
know that the accumulator holds the carry, not the total result.
One other point about the status register : there is another flag, .
the" decimal" flag . If you ever set this flag up (SED), all addition and
subtraction is performed in a decimal mode in which the carry flag is
set when addition exceeds 99. In this book, we are not going into the
decimal mode at all, so it's a good precaution to put a CLear Decimal
mode (CLD) instruction as the first instruction of any ML program
you write. After you type CLO, the flag will be put down and the
assembler will move on to ask for your next instruction, but all the
arithmetic from then on will be as we are describing it .
56
Arithmetic 5
57
5 Arithmetic
Subtraction
As you might expect, subtracting single-byte numbers is a snap:
LOA #$41
SBC #$01
results in a $40 being left in the accumulator.<\s before, though, it is
good to make it a habit to deal with the carry 11ag before each
calculation . When subtracting, however, you set the carry flag: SEC.
Why is unimportant. Just always SEC before any subtractions, and
your answers will be correct. Here's double subtracting that will
move the ball up the screen one line instead of down one line :
$1020 SEC
($1020 is our "take 40 from ball address"
subroutine)
1021 LOA $80
(get the LSB of ball address)
58
Arithmetic 5
1023
1026
1028
102A
1020
59
a-
1010101110141017101A10101020102310251027-
38
AD
ED
80
AD
ED
00
pO
90
BO
00
02
08
01
03
08
EO
no
DO
10
10
10
10
10
10
0005
0010
0020
0030
0040
0050
0060
0070
0080
0090
0100
0110
0120
0130
0140
0150
0160
0170
0180
0190
0200
0210
START
SEC
LOA
SBC
STA
LOA
SBC
ORA
BEQ
BCC
BCS
.EN
TESTED
SECOND
TEMP
TESTED+1
SECOND+1
TEMP
EQUAL
LOWER
HIGHER
TESTED = SECOND
TESTED < SECOND
TESTED > SECOND
.BA $1010
------- STORAGE AREAS ------TESTED
.DE $1000
SECOND
.DE $1002
TEMP
.DE $1008
II
3(I)
n'
::r
;;.-
"'I
U1
Arithmetic 5
This is a full-dress, luxurious assembler at work. With such assemblers you can use line numbers and labels, add numbers to labels (see
TESTED + 1 in line 150), add comments, and all the rest . To try this out,
type in the hex bytes on the left, starting at address $1010, which make
up the program itself. Then fill bytes $1000-100f with zeros - that's your
storage area for the numbers you are comparing as well as a simulated
"landing place" where your computer will branch, demonstrating that
the comparison worked correctly.
Now try putting different numbers into the two-byte zones called
TESTED and SECOND. TESTED, at $1000, is the first, the tested, number. It's being tested against the second number, called SECOND. As
you can see, you've got to keep it straight in your mind which number
is the primary number. There has to be a way to tag them so that it
means something when you say that one is larger (or smaller) than the
other.
When you've set up the numbers in their registers ($1000 to $1003),
you can run this routine by starting at $1010. All that will happen is that
you will land on a BRK instruction . Where you land tells you the result
of the comparison. If the numbers are equal, you land at $1005. If the
TESTED number is less than the SECOND number, you'll end up at
$1004. If all you needed to find ou twas whether they were unequal,
you could use BNE . Or you could leave out branches that you weren't
interested in . Play around with this routine until you've understood
the ideas involved.
In a real program, of course, you would be branching to the
addresses of subroutines which do something if the numbers are equal
or greater or whatever. This example sends the computer to $1004,
$1005, or $1006 just to let you see the effects of the double-compare subroutine. Above all, remember that comparing in ML is done with BCS
and BCC (not BPL or BMI) .
61
63
I. The Transporters:
LOA,
STA,
TAX,
TXA,
LOX, LOY
STX, STY
TAY
TYA
65
Registers
In ML there are three primary places where variables rest briefly on
their way to memory cells: the X, the Y, and the A registers. And the
A register (the accumulator) is the most frequently used. X and Yare
used for looping and indexing. Each of these registers can grab a byte
from anywhere in memory or can load the byte right after its own
opcode (immediate addressing) :
LOX $8000 (puts the number at hex address 8000 into X,
without destroying it at $8000)
LOX #65
(puts the number 65 into X)
LOA and LOY work the same.
Be sure you understand what is happening here. LOX $1500
does not copy the "byte in the X register into address $1500." It's just
the opposite. The number (or "value" as it's sometimes called) in
$1500 is copied into the X register.
To copy a byte from X, Y, or A, use STX, STY, or STA. For these
"store-bytes" instructions, however, there is no immediate
addressing mode. No STA #15 . It would make no sense to have STA
#15. That would be disruptive, for it would modif1j the ML program
itself. It would put the number 15 into the next cell beyond the STA
instruction within the ML program itself.
Another type of transporter moves bytes between registers TAY, TAX, TYA, TXA. See the effect of writing the following. Look at
the registers after executing this :
1000 LOA #65
TAY
TAX
The number 65 is placed into the accumulator, then transferred
to the Y register, then sent from the accumulator to X. All the while,
however, the A register (accumulator) is not being emptied. Sending
bytes is not a "transfer" in the usual sense of the term" sending."
It's more as if a Xerox copy were made of the number and then the
copy is sent. The original stays behind after the copy is sent.
LOA #15 followed by TAY would leave the 15 in the
accumulator, sending a copy of 15 into the Y register.
Notice that you cannot directly move a byte from the X to the Y
register, or vice versa. There is no TXY or TYX.
3. The Decision-Makers:
CMP, BNE, BEQ, BCC, BCS
The four "branchers" here - they all begin with a "B" - have
only one addressing mode. In fact, it's an interesting mode unique to
the "B" instructions and created especially for them: relative
addressing . They do not address a memory location as an absolute
thing; rather, they address a location which is a certain distance from
their position in the ML code. Put another way, the argument of the
"B" instructions is an offset which is relative to their position. You
never have to worry about relocating "B" instructions to another part
of memory. You can copy them and they will work just as well in the
new location. That's because their argument just says" add five to the
present address" or "subtract twenty-seven," or whatever argument
you give them. But they can't branch further back than 127 or further
forward than 128 bytes.
None of the brancher instructions have any effect whatsoever on
any flags; instead, they are the instructions which look at the flags.
They are the only instructions that base their activity on the condition
of the status register and its flags. They are why the flags exist at all.
CMP is an exception. Many times it is the instruction that comes
just before the branchers and sets flags for them to look at and make
decisions about. Lots of instructions - LDA is one - will set or
"clear" (put down) flags - but sometimes you need to use CMP to
find out what's going on with the flags. CMP affects the N, Z, and C
flags. CMP has many addressing modes available to it: Immediate,
Absolute, Zero Page, (lndirect,X), (Indirect), Y, Zero Page,X, and
Absolute,X and Y.
70
(is it a space?)
(Branch if Not Equal [if not 32] to address 200A,
which contains the first of a series of
comparisons to see if it's a wall, a paddle, etc .
On the other hand, if the comparison worked, if
it was a 32 (so we didn't Branch Not Equal),
then the next thing that happens is the
instruction in address 2004. We "fall through"
the BNE to an instruction which jumps to the
subroutine (JSR), which moves the ball into
this space and then returns to address 2007,
which jumps over the series of comparisons for
wall, paddle, etc.)
2004 JSR 3000 (the ball printing subroutine)
2007 JMP 2020 (jump over the rest of the comparisons)
200A CMP #128 (is it our paddle symbol?)
200C BNE 2014 (if not, continue to next comparison)
200E JSR 3050 (do the paddle-handling subroutine and .. . )
2011 JMP 2020 (jump over the rest, as before in 2007)
2014 CMP #144 (is it a wall ... and so forth with as many
comparisons as needed)
This structure is to ML what ON-COTO or ON-COSUB is to
BASIC. It allows you to take multiple actions based on a single LOA.
Doing the CMP only once would be comparable to BASIC's IF-THEN.
2j
A9
C5
DO
20
AD
80
99
03
10 20
00 04
2010- AD 21 00
200420062008200A2000-
Program 6-1 .
0010
0020
0030
0040
0050
0060
0070
0080
0090
0100
OllO
0120
0130
0140
0150
0160
.BA $2004
.DE $80
.DE $99
SPECIALSUBROUTINE LOA 33
; ETC. ETC.
.EN
START
; (IMMEDIATE ADORE
LDA #TESTBYTE
CMP *NEWBYTE ; (ZERO PAGE ADDRESSING)
(RELATIVE ADORES
BNE BRANCHTARGET
JSR SPECIALSUBROUTINE
BRANCHTARGET
LOA $400
; YOU CAN FREELY MIX
LABLES AND SUBROUTINES.
ALSO, COMMENTS
WILL BE IGNORED BY THE ASSEMBLER AND CAN
BE STUCK ANYWHERE, AS YOU SEE.
TESTBYTE
NEWBYTE
0-
,.,.
(I)
:::l
,.,.
c:
1/1
:::l
.,,.,.
-:r
-i
remember which to use.) The reasons for this are exotic. We don't
need to go into them. Just be warned that BPL and BMI, which sound
so logical and useful, are not. They can fail you and neither one lives
up to its name. Stick with the always trustworthy BCC, BCS .
Also remember that BNE and the other three main "B" group
branching instructions often don't need to have a CMP come in front
of them to set a flag they can test. Many actions of many opcodes will
automatically set flags during their operations. For example, LOA $80
will affect the Z flag so you can tell if the number in address $80 was
or wasn't zero by that flag. LOA $80 followed by BNE would branch
away if there were anything besides a zero in address $80. If in doubt,
check the chart of instructions in Appendix A to see which flags are
set by which instructions. You'll soon get to know the common ones.
If you are really in doubt, go ahead and use CMP.
Big Loops
How would you create a loop which has to be larger than 256 cycles?
When we examined the technique for adding large numbers, we
simply used two-byte units instead of single-byte units to hold our
information. Likewise, to do large loops, you can count down in two
bytes, rather than one. In fact, this is quite similar to the idea of
"nested" loops (loops within loops) in BASIC.
2000 LDX #10 (start of 1st loop)
2002 LDY #0 (start of 2nd loop)
2004 DEY
2005 BNE 2004 (if Y isn't yet zero, loop back to DEcrease Y
again - this is the inner loop)
2007 DEX
(reduce the outer loop by one)
2008 BNE 2002 (if X isn't yet zero, go through the entire DEY
loop again)
200A
(continue with the rest of the program . .. )
One thing to watch out for: be sure that a loop BNE's back up to
one address after the start of its loop . The start of the loop sets a number
into a register and, if you keep looping up to it, you'll always be
putting the same number into it. The DEcrement (decrease by one)
instruction would then never bring it down to zero to end the
looping. You'll have created an endless loop.
The example above could be used for a "timing loop" similarly
to the way that BASIC creates delays with: FOR T = 1 TO 2000: NEXT
T. Also, sometimes you do want to create an endless loop (the BEGIN
... UNTIL in "structured programming"). A popular "endless"
loop structure in BASIC waits until the user hits any key: 10 GET K$:
IF K$=" "THEN 10.
10 IF PEEK (764) = 255 THEN 10 is the way to accomplish this on
the Atari; it will cycle endlessly unless a key is pressed . The simplest
way to accomplish this in ML is to look on the map of your computer
76
to find which byte holds the " last key pressed" number. On Upgrade
and 4.0 CBM /PET, it's address 151. On Atari, it's 764. On Apple II,
it's -16384. On VIC and Commodore 64, it' s 203 with a 64 in that
location if no key is pressed . In any event, when a key is pressed, it
deposits its special numerical value into this cell. If no key is pressed,
some standard value stays th ere all the time . We'll use the CBM as
our model here . If no key is pressed, location 151 will hold a 255:
2000 LOA 151
2002 CMP #255
2004 BEQ 2000
If the CMP is EQual, this means that the LOA pulled a 255 out of
address 151 and, thus, no key is pressed . So, we keep looping until
the value of address 151 is something other than 255. This setup is
like GET in BASIC because not only does it wait until a key is
pressed, but it also leaves the value of the key in the accumulator
when it's finished .
Recall that a CMP performs a subtraction . It subtracts the number
in its argument from whatever number sits in the accumulator at the
time . LOA #12 CMP $15 would subtract a 5 from 12 if 5 is the number
"held" in address 15. This is how it can leave flags set for testing by
BEQ or BNE. The key difference between this" subtraction" and SBC
is that neither the accumulator nor the argument is affected at all by
it. They stay what they were . The result of the subtraction is "thrown
away," and all that happens is that the status flags go up or down in
response to the result. If the CMP subtraction causes an answer of
zero, the Z flag flips up. If the answer is not zero, the Z flag flips
down. Then, BNE or BEQ can do their job - checking flags.
78
2010 INY
2011 IMP 2002 (in this loop, we always jump back. Our exit
2014
By the way, you should notice that the Simple Assembler will
reject the commas in this example and, if you've forgotten to set line
10 to accept decimal, it will not accept the single zero in LOY #0. Also,
if you get unpredictable results, maybe decimal 2000 is not a safe
address to store your ML. You might need to use some other practice
area.
Now that we know the address which follows the loop (2014),
we can POKE that address into the "false forward branch" we left in
address 2006. What number do we POKE into 2006? Just subtract 2007
from 2014, which is seven. Using the Simple Assembler, type POKE
and you can take care of this while you remember it. The assembler
will perform the POKE and then return to wait for your next
instruction .
Both of these ways of handling messages are effective, but you
must make a list on paper of the starting addresses of each message.
In ML, you have the responsibility for some of the tasks that BASIC
(at an expense of speed) does for you. Also, no message can be larger
than 255 using the methods above because the offset and counter
registers count only that high before starting over at zero again.
Printing two strings back-to-back gives a longer, but still under 255
byte, message:
2000 LOY #0
2002 LOX #2
(in this example, we use X as a counter which
represents the number of messages we are
printing)
2004 LOA 4000, Y (get the "B" from "Ball out of. .. ")
2007 BEQ 2016
(go to reduce [and check] the value of X)
2009 STA 32768, Y (we're using the Y as a double-duty offset
again)
2012 INY
2013 IMP 2004
2016 INY
(we need to raise Y since we skipped that step
when we branched out of the loop)
20170EX
(at the end of the first message, X will be
a "1"; at the end of the second message,
it will be zero)
2018 BNE 2004
(if X isn' t down to zero yet, re-enter the loop to
print out the second message)
79
80
when you'll be several subroutines deep (one will call another which
calls another); this is not as confusing as it sounds. Your main Playerinput routine might call a print-message subroutine which itself calls
a wait-until-key-is-pressed subroutine. If any of these routines PHA
(PusH the Accumulator onto the stack), they then disturb the
addresses on the stack. If the extra number on top of the stack isn't
PLA-ed off (PulL Accumulator), the next RTS will pull off the number
that was PHA' ed and half of the correct address. It will then merrily
return to what it thinks is the correct address: it might land
somewhere in the RAM, it might go to an address at the outer reaches
of your operating system - but it certainly won't go where it should.
Some programmers like to change a GOSUB into a GOTO (in
the middle of the action of a program) by PLA PLA. Pulling the two
top stack values off has the effect of eliminating the most recent RTS
address. It does leave a clean stack, but why bother to JSR at all if you
later want to change it to a GOTO? Why not use JMP in the first
place?
There are cases, too, when the stack has been used to hold the
current condition of the flags (the Status Register byte). This is
pushed/pulled from the stack with PHP (PusH Processor status) and
PLP (PulL Processor status). If you should need to "remember" the
condition of the status flags, why not just PHP PLA STA $NN?
("NN" means the address is your choice.) Set aside a byte
somewhere that can hold the flags (they are always changing inside
the Status Register) for later and keep the stack clean. Leave stack
acrobatics to FORTH programmers . The stack, except for advanced
ML, should be inviolate.
FORTH, an interesting language, requires frequent stack
manipulations . But in the FORTH environment, the reasons for this
and its protocol make excellent sense. In ML, though , stack
manipulations are a sticky business.
2002
2003
2004
2005
2006
TXA
PHA
ITA
PHA
JSR (to the clear-the-screen routine in BASIC. The RTS
JMP
Like BASIC's GOTO, JMP is easy to understand . It goes to an
address: JMP 5000 leaps from wherever it is to start carrying out the
84
6. Oebuggers:
BRKandNOP
BRK and NOP have no argument and are therefore members of that
class of instructions which use only the Implied addressing mode.
They also affect no flags in any way with which we would be
concerned. BRK does affect the I and B flags, but since it is a rare
situation which would require testing those flags, we can ignore this
flag activity altogether.
After you've assembled your program and it doesn't work as
expected (few do), you start debugging. Some studies have shown that
debugging takes up more than fifty percent of programming time.
Such surveys might be somewhat misleading, however, because
"making improvements and adding options" frequently takes place
after the program is allegedly finished, and would be thereby
categorized as part of the debugging process.
In ML, debugging is facilitated by setting breakpoints with BRK
and then seeing what's happening in the registers or memory . If you
insert a BRK, it has the effect of halting the program and sending you
into your monitor where you can examine, say, the Y register to see if
it contains what you would expect it to at this point in the program.
It's similar to BASIC's STOP instruction:
2000 LDA #15
2002 TAY
2003 BRK
If you run the above, it will carry out the instructions until it gets
to BRK when it will put the program counter plus two on the stack, put
the status register on the stack, and load the program counter with
whatever is in addresses $FFFE, $FFFF. These are the two highest
addresses in your computer and they contain the vector (a pointer) for
an interrupt request (IRQ).
These addresses will point to a general interrupt handler and, if
your computer has a monitor, its address might normally be found
here. Remember, though, that when you get ready to CONT, the
address on the top of the stack will be the BRK address plus two.
Check the program counter (it will appear when your monitor
displays the registers) to see if you need to modify it to point to the
86
Debugging Methods
In effect, you debug whenever your program runs merrily along and
then does something unexpected. It might crash and lock you out.
You look for a likely place where you think it is failing and just insert a
BRK right over some other instruction . Remember that in the monitor
mode you can display a hex dump and type over the hex numbers on
screen, hitting RETURN to change them. In the example above,
imagine that we put the BRK over an STY 8000. Make a note of the
hex number of the instruction you covered over with the BRK so you
can restore it later. After checking the registers and memory, you
might find something wrong. Then you can fix the error.
If nothing seems wrong at this point, restore the original STY
over the BRK, and insert a BRK in somewhere further on. By this
process, you can isolate the cause of an oddity in your program.
Setting breakpoints (like putting STOP into BASIC programs) is an
effective way to run part of a program and then examine the
variables.
If your monitor or assembler allows single-stepping, this can be an
excellent way to debug, too. Your computer performs each
instruction in your program one step at a time . This is like having
BRK between each instruction in the program. You can control the
speed of the stepping from the keyboard. Single-stepping automates
breakpoint checking. It is the equivalent of the TRACE command
sometimes used to debug BASIC programs .
Like BRK ($00), the hex number of NOP ($EA) is worth
memorizing. If you're working within your monitor, it will want you
to work in hex numbers . These two are particularly worth knowing.
NOP means No OPeration. The computer slides over NOP's without
taking any action other than increasing the program counter. There
are two ways in which NOP can be effectively used.
First, it can be an eraser. If you suspect that STY 8000 is causing
all the trouble, try running your program with everything else the
same, but with STY 8000 erased. Simply put three EA's over the
instruction and argument. (Make a note, though, of what was under
the EA's so you call restore it.) Then, the program will run without
this instruction and you can watch the effects .
Second, it is sometimes useful to use EA to temporarily hold
open some space. If you don't know something (an address, a
graphics value) during assembly, EA can mark that this space needs
to be filled in later before the program is run. As an instruction, it will
87
BIT Tests
Another instruction, BIT, also tests (it does an AND), but, like CMP,
it does not affect the number in the accumulator - it merely sets flags
in the status register. The N flag is set (has a 1) if bit seven has a 1 (and
vice versa). The V flag responds similarly to the value in the sixth bit.
The Z flag shows if the AND resulted in zero or not. Instructions, like
BIT, which do not affect the numbers being tested are called nondestructive.
We discussed LSR and ASL in the chapter on arithmetic: they
can conveniently divide and multiply by two. ROL and ROR rotate the
bits left or right in a byte but, unlike with the Logical Shift Right or
Arithmetic Shift Left, no bits are dropped during the shift. ROL will
leave the 7th (most significant) bit in the carry flag, leave the carry flag
in the Oth (least significant bit), and move every other bit one space to
the left :
ROL 11001100 (with the carry flag set) results in
10011001 (carry is still set, it got the leftmost 1)
If you disassemble your computer's BASIC, you may well look
in vain for an example of ROL, but it and ROR are available in the
6502 instruction set if you should ever find a use for them. Should
you go into advanced ML arithmetic, they can be used for
multiplication and division routines.
Three other instructions remain: SEI (SEt Interrupt), RTI
(ReTurn from Interrupt), and CLI (CLear Interrupt). These operations
are, also, beyond the scope of a book on beginning ML programming,
but we ' ll briefly note their effects. Your computer gets busy as soon as
the power goes on. Things are always happening: timing registers are
being updated; the keyboard, the video, and the peripheral
connectors are being refreshed or examined for signals. To
" interrupt" all this activity, you can SEI, perform some task, and
then eLI to let things pick up where they left off.
SET sets the interrupt flag . Following this, all maskable
interruptions (things which can be blocked from interrupting when
the interrupt status flag is up) are no longer possible . There are also
89
90
94
-.0
U1
AO
B9
20
C8
CO
DO
60
200A200C200F2012201320152017-
0060
0070
0080
0090
0100
0110
0120
0130
0140
0150
0160
0170
0180
0190
COUNTER =0055
PRINTIT =FFD2
LENGTH =0008
START =200A
LOY
LOA
JSR
INY
CPY
BNE
RTS
.EN
#LENGTH
LOOP
#$00
STRING,Y
PRINTIT
START
LOOP
LOOP =200C
STRING =2000
; (COMMODORE)
.DE $FFD2
PRINTIT
.DE II
LENGTH
ENDPASS
LABEL FILE:
08
F5
00
00 20
02 FF
53 55 50
45 52 44
55 50 45
52
2000200320062009-
Program 7-1.
II~
!!!
OJ
~
.,
OQ
'TI
!.
OJ
.,.,0
-.0
a--
A9
85
AO
B9
20
E6
A9
C5
DO
60
060A060C060E0610061306160618061A061C061E-
0060
0070
0080
0090
0100
0110
0120
0130
0140
0150
0160
0170
0180
0190
0200
LENGTH =OOOB
START =060A
LOOP =060E
STRING =0600
LOA
STA
LOY
LOA
JSR
INC
LOA
CMP
BNE
RTS
.EN
START
LOOP
; (ATARI)
.DE $F6A4
PRINTIT
#00
*COUNTER
#COUNTER
STRING,Y
PRINTIT
*COUNTER
#LENGTH
*COUNTER
LOOP
. DE 11
LENGTH
ATARI VERSION
0010
0020
.BA $0600
.OS
0030
0040 COUNTER
.DE $55
.BY 'SUPERDUPER'
0050 STRING
END PASS
LABEL FILE:
COUNTER =0055
PRINTIT =F6A4
00
55
55
00 06
A4 F6
55
OB
55
FO
53 55 50
45 52 44
55 50 45
52
0600060306060609-
Program 72.
l>
tr:J
""I
"0
:::l
OQ
~.
tr:J
0
""I
""I
......
Building A Program
Using what we've learned so far, and adding a couple of new
techniques, let's build a useful program . This example will
demonstrate many of the techniques we've discussed and will also
show some of the thought processes involved in writing ML.
Among the computer's more impressive talents is searching. It
can run through a mass of information and find something very
quickly. We can write an ML routine which looks through any area of
memory to find matches with anything else. If your BASIC doesn't
have a FIND command or its equivalent, this could come in handy.
Based on an idea by Michael Erperstorfer published in COMPUTE!
Magazine, this ML program will report the line numbers of all the
matches it finds.
Safe Havens
Before we go through some typical ML program-building methods,
let's clear up the "where do I put it?" question. ML can't just be
dropped anywhere in memory. When the Simple Assembler asks
"Starting Address?", you can't give it any address you want to. RAM
is used in many ways. There is always the possibility that a BASIC
program might be residing in part of it (if you are combining ML with
a BASIC program). Or BASIC might use part of RAM to store arrays
or variables. During execution, these variables might write (POKE)
into the area that you placed your ML program, destroying it. Also,
the operating system, the disk operating system, cassette/disk loads,
printers - they all use parts of RAM for their activities. There are
other things going on in the computer beside your hard-won ML
program.
Obviously, you can't put your ML into ROM addresses. That's
impossible. Nothing can be POKEd into those addresses. The 64 is an
exception to this. You can POKE into ROM areas because a RAM
exists beneath the ROM . Refer to the Programmer 's Reference Guide or
see Jim Butterfield's article on 64 architecture (COMPUTE! Magazine,
January 1983) for details.
Where to put ML? There are some fairly safe areas.
If you are using Applesoft in ROM, 768 to 1023 ($0300 to $03FF)
is safe . Atari's page six, 1536 to 1791 ($0600 to $06FF) is good. The 64
and VIC's cassette buffer at 828 to 1019 ($033C to $03FB) are good if
you are not LOADing or SAVEing from tape.
97
8 Building A Program
Building A Program 8
six ($0600-06FF) at $IFOO and then put this address into lomem. The
LSB and MSB are reversed, of course, as the 6502 requires its pointers
to be like this :
$02E7 00
$02E8 IF
$02E7,8 is Atari's low memory pointer. You should set up this
pointer (LDA $00, STA $02E7, LDA #$ IF, STA $02E8) as part of your
ML program. Following that pointer setup, JMP $AOOO which
initializes BASIC. If you are not combining ML with a BASIC
program, these preliminary steps are not necessary .
Safe Atari zero page locations include $00-04, $CB-DO, $D4-D9
(if floating point numbers are not being used); $0400 (the printer and
cassette buffer), $0500-057F (free), $0580-05FF (if floating point and
the Editor are not being used), $0600-06FF (free) are also safe. No
other RAM from $0700 (Disk Operating System) to $9FFF or $BFFF is
protected from BASIC.
To repeat: address pointers such as these are stored in LSB, MSB
order. That is, the more significant byte comes second (this is the
reverse of normal, but the 6502 requires it of address pointers). For
example, $8000, divided between two bytes in a pointer, would look
like this:
0073 00
0074 80
As we mentioned earlier, this odd reversal is a peculiarity of the
6502 that you just h ave to get used to . Anyway, you can lower the
computer's opinion of the top-of-RAM-memory, thereby making a
safe place for your ML, by changing the MSB . If you need one page
(256 bytes) : POKE 116, PEEK (116)-1 (Apple). For four pages (1024
bytes) on the Upgrade and 4.0 PETs : POKE 53, PEEK (53) -4. Then
your BA or start of assembling could begin at (Top-of-RAM-255 or
Top-of-RAM-I023, respectively. You don't have to worry much about
the LSB here . It's u sually zero. If not, take that into account when
planning where to begin storage of your object code.
Building The Code
Now we return to the subject at hand - building an ML program.
Some people find it easiest to mentally break a task down into several
smaller problems and then weave them into a complete program.
That's how we'll look at our search program. (See Program 8-1.)
For this exercise, we can follow th e PET/CBM 4.0 BASIC version
to see how it is constructed. All the versions (except Atari's) are
essentially the same, as we w ill see in a minute. The only differences
are in the locations in zero page w here addresses are temporarily
stored, the "start-of-BASIC RAM" address, the routines to print a
99
.....
0360036303650368-
AD
85
AD
85
01 04
BA
02 04
BB
0010
0015
0016
0017
0018
0020
0030
0040
0050
0060
0070
0100
0110
0120
0121
0130
0140
0150
0160
0170
0180
0181
0182
0183
0184
DEFINE VARIABLES BY GIVING THEM LABELS.
LOA BASIC+l
;GET ADDR OF NEXT
STA *L1L
;BASIC LINE
LOA BASIC+2
STA *L1L+l
;-------------------------------------------------------0- SUBROUTINE TO CHECK FOR 2 ZEROS.
IF WE DON'T
FIND THEM, WE ARE NOT AT THE END OF THE PROGRAM.
L1L
L2L
FOUND
BASIC
PRINT
PLINE
;STORE THESE IN
.DE $BA
.DE $BC
;UNUSED ZERO PG AREA
.DE $36
.DE $0400
.DE $FFD2
PRINT A CHAR.
.DE $CF7F
PRINT LINE#
2ND CASSETTE BUFFER
.BA $0360
.OS
i----------------------------------------------------- --0- INITIALIZE POINTERS.
; -0-
,------------------------------------------------------
~"'I
"'I
."
OQ
c::
~
OJ
QI)
>-'
0
>-'
AO
Bl
DO
C8
Bl
DO
60
AO
Bl
85
C8
Bl
85
C8
Bl
85
C8
Bl
85
A5
036A036C036E0370037103730375-
BA
37
BA
BA
36
BA
BD
00
BA
BC
BA
01
00
BA
06
0190 READLINE
LOY #$00
LOA (L1L) ,Y
0200
BNE GO.ON
NOT END OF LINE
0210
INY
0220
LOA (LlL) ,Y
END OF PROG.
0230
00 00
BNE GO.ON
0240
RTS
0250 END
iRETURN TO BASIC
0251 -------------------------------------------------------0- SUBROUTINE TO UPDATE POINTERS TO THE NEXT LINE
0252
AND STORE THE CURRENT LINE NUMBER IN CASE WE
0253
FIND A MATCH AND NEED TO PRINT THE LINE #.
0254
0255
ALSO, WE ADD 4 TO THE CURRENT LINE POINTER SO THAT
0256
WE ARE PAST THE LINE # AND "POINTER-TO-NE XT-LINE"
INFORMATION.
0257
WE ARE THEN POINTING AT THE 1ST CHAR.
0258
IN THE CURRENT LINE AND CAN COMPARE IT TO THE SAMPLE.
0259
LOY #$00
0260 GO.ON
LOA (L1L) ,Y
GET NEXT LINE
0270
0280
STA *L2L
ADDRESS AND
INY
0290
STORE IT IN L2L
LOA (L1L),Y
0300
STA *L2L+l
0310
INY
0320
LOA (L1L) ,Y
0330
PUT LINE #
STA *FOUND
IN STORAGE TOO
0340
IN CASE IT
0350
INY
LOA (LlL),Y
NEEDS TO BE
0360
0370
STA *FOUND+l
iPRINTED OUT LATER
LOA *L1L
0380
00
III
""I
OQ
""I
~
."
:::I
OQ
Q:
C':I
tv
>-'
18
69
85
A5
69
85
AO
Bl
FO
CD
FO
C8
4C
038D038E0390039203940396-
0398039A039C039E03Al03A303A4-
9A 03
00
BA
lC
06 04
04
04
BA
BB
00
BB
i1
OQ
"d
OQ
::l
Q:
E.
\JJ
.....
0
A2
E8
C8
BD
FO
D1
FO
4C
20
A5
85
A5
85
4C
03A703A903AA03AB03AE03BO03B203B403B7-
03BA03BC03BE03CO03C2-
BC
BA
BD
BB
6A 03
06 04
07
BA
F5
9A 03
C5 03
00
CJ518
0519
0520
0530
0540
0550
0560
0570
0580
0590
0600
0601
0602
0603
0604
0605
0606
0607
0608
0610
0620
0630
0640
0650
0651
0652
0653
0654
0655
LDA
STA
LDA
STA
JMP
*L2L
*L1L
*L2L+1
*L1L+1
READLINE
i-------------------------------------------------------
STOPLINE
LDX #$00
COMPARE SAMPLE TO
INX
'rARGET
INY
LDA BASIC+6,X
BEQ PERFECT
LINE ENDS SO PRINT
CMP (L1L),Y
BEQ COMPARE
CONTINUE COMPARE
JMP LOOP
NO MATCH
PERFECT
JSR PRINTOUT
-------------------------------------------------------0- SUBROUTINE TO REPLACE "CURRENT LINE" POINTER
WITH THE "NEXT LINE" POINTER WE SAVED IN THE SUBROUT
STARTING AT LINE 260.
THEN JUMP BACK TO THE START WITH THE CHECK FOR THE
END-OF-PROGRAM DOUBLE ZERO.
THIS IS THE LAST SUBROUT
IN THE MAIN LOOP OF THE PROGRAM.
SAME
COMPARE
co
III
""I
OQ
""I
"0
c::
:f
OQ
DJ
>-'
BASIC =0400
FOUND =0036
L2L =OOBC
PLINE =CF7F
READLINE =036A
LABEL FILE:
03C8- A9 20
03CA- 20 02 FF
03CD- 60
03C5- 20 7F CF
COMPARE =03A9
GO.ON =0376
LOOP =039A
PRINT =FFD2
SAME =03A7
END =0375
LlL =OOBA
PERFECT =03B7
PRINTOUT =03C5
STOPLINE =03BA
OQ
."
OQ
a::
:r
DlI
S.
00
Building A Program 8
character and to print a line number, and the RAM where it's safe to
store the ML program itself. In other words, change the defined
variables between lines 20 and 100 in Program 8-1 and you can use the
program on another computer.
We will build our ML program in pieces and then tie them all
together at the end. The first phase, as always, is the initialization.
We set up the variables and fill in the pointers . Lines 20 and 30 define
two, two-byte zero page pointers. LlL is going to point at the address
of the BASIC line we are currently searching through. L2L points to
the starting address of the line following it.
Microsoft BASIC stores four important bytes just prior to the
start of the code in a BASIC line. Take a look at Figure 8-1. The first
two bytes contain the address of the next line in the BASIC program.
The second two bytes hold the line number. The end of a BASIC line
is signaled by a zero. Zero does not stand for anything in the ASCII
code or for any BASIC command. If there are three zeros in a row,
this means that we have located the "top," the end of the BASIC
program. (The structure of Atari BASIC is significantly different. See
Figure 8-2.)
But back to our examination of the ML program. In line 40 is a
definition of the zero page location which holds a two-byte number
that Microsoft BASIC looks at when it is going to print a line number
on the screen. We will want to store line numbers in this location as
we come upon them during the execution of our ML search program.
Each line number will temporarily sit waiting in case a match is
found. If a match is found, the program will JSR to the BASIC ROM
routine we're calling " PLINE, " as defined in line 70. It will need the
" current line number" to print to the screen.
Line 50 establishes that BASIC RAM starts at $0400 and line 60
gives the address of the "print the character in the accumulator"
ROM routine . Line 100 says to put the object code into the PET's (all
BASIC versions) second cassette buffer, a traditional "safe" RAM
area to store short ML programs. These safe areas are not used by
BASIC, the operating system (OS), or, generally, by monitors or
assemblers. If you are working with an assembler or monitor,
however, and keep finding that your object code has been messed up
- suspect that your ML creating program (the monitor or assembler)
is using part of your " safe" place. They consider it safe too. If this
should happen, you'll have to find a better location.
Refer to Program 8-1 to follow the logic of constructing our
Microsoft search program . The search is initiated by typing in line
zero followed by the item we want to locate. It might be that we are
interes ted in removin g all REM statem ents from a program to shorten
it. We would type O:REM and hit RETURN to enter this into the
BASIC program. Then we would start the search by a SYS to the
105
.....
'"
- ~I
End of Line
0400
040B
0411
OOOB 04 OA 00 99 22 48 49 22 00 11 04 14 00 80 00 00 00
LINE ?" HI"
LINE END
10
20
10 PRINT"HI"
20 END
Start of
BASIC
Program
Ends
OQ
.,
OQ
a:
5.
OJ
'1
....o
$88
$89
STARTP
LINE OFFSET
TOKENS
I
I
=entl
Line # 32768
Means
End of Program
LINE OFFSET
01)
OQ
..,-a
:r
OQ
c:
DJ
I:
>-'
OJ
EOL
LINE /STMT
OFFSET
II
r-
32768
00,80
II 2-N-D-O-F-F-S-ET---'-I-TO-K-E-N-S-2-N-D-S-T-M-T--'1
MULTI-STATEMENT LINES
EOL
LINE
20
LINE
10
[lS[16[
END
6 BYTES
i. i.
EXAMPLE
p,j
~ :::t;~
10 BYTES
I I
10 PRINT "HI"
20END
16
EOL
11/
""I
OQ
""I
"o
OQ
OJ
!:c::
5-
00
Building A Program 8
8 Building A Program
pointer into the "current line" pointer and the whole process of
reading a new BASIC line begins anew.
If, however, a perfect match was found (line 560 found a zero at
the end of the O:REM line, showing that we had come to the end of
the sample string) - we go to "PERFECT" and it makes a JSR to print
out the line number (line 660). That subroutine bounces back (RTS) to
"STOPLINE" which replaces the "current line" (LlL) pointer with
the "next line" pointer (L2L) . Then we JMP back to "READLINE"
which, once again, pays very close attention to zeros to see if the
whole BASIC program has ended with double zeros. We have
returned to the start of the main loop of this ML program.
This sounds more complicated than it is . If you've followed
this so far, you can see that there is enormous flexibility in
constructing ML programs. If you want to put the "STOPLINE"
segment earlier than the "SAME" subroutine - go ahead. It is quite
common to see a structure like this:
INITIALIZATION
LDA #15
STA $83
MAIN LOOP
STARTJSR 1
JSR2
JSR3
BEQ START
(until some index runs out)
RTS
(to BASIC)
SUBROUTINES
1
2
3
DATA
Table 1
Table 2
Table 3
110
Building A Program 8
You can then put th e BASIC cartridge in and enter the machine
language with the BASIC loader program, or with the L command of
DOS.
Using FIND from BASIC is simple. Say you want to search a
master string, A$ for the substring "hello". If B$ contains "hello",
the USR call would look like:
POS= USR (1536,ADR(A$),LEN(A$),ADR(B$),LEN(B$) )
POS will contain th e position of the match. It will be a memory
location within the ADRress of A$. To get the character position
within A$, just use POS-ADR(A$) + 1. If the substring (B$) is not
found, POS will be zero.
It's easy to add commands like this to Atari BASIC. Also see
"Getting The Most Out Of USR" in the November 1982 issue of
COMPUTE! Magazine (p. 100).
64, Apple, & VIC Versions
111
.....
.....
tv
00D2
00D3
00D4
00D6
00D7
00CF
00D0
00Dl
00CB
00CC
00CD
00CE
Program 8-2
0100
0110
0120
0130
0140
0150
0160
0170
0180
0190
0200
0210
0220
0230
0240
0250
0260
0270
0280
0290
0300
0310
0320
0330
=$CF
=$D0
=$Dl
=$D2
=$D3
=$D4
=$D6
=$D7
FIRSTCHAR
SINDEX
FR0
FINDEX
TADRL
=$CB
=$CC
=$CD
=$CE
FNDL
FNDH
FNDLEN
SADRL
SADRH
SLENL
SLENH
:Return
:Source index
:Temp addr
:Search address
:and
:length
:Address
:of search
:Length of
:search space
:
:Variables in zero page for speed
j========================i
FIND Utility
Substring Search
for Atari BASIC
Completely relocatable
.========================-I
OQ
.,
.,III
~
."
0
OQ
c:
S
!:.
II coD:I
>-'
>-'
v.>
0600
0601
0602
0604
0605
0607
0000
00D8
00D9
68
68
85CC
68
85cB
68
0340
0350
0360
0370
0380
0390
0400
0410
0420
0430
0440
0450
0460
0470
0480
0490
0500
0510
0520
0530
0540
0550
0560
0570
0580
0590
=$DB
=$D9
FIND
PLA
PLA
STA
PLA
STA
PLA
SADRL
SADRH
jhi byte, Source end
;Count byte
; hi byte, Source start
j-------------------------------------
;FIND:Find Text
;X=USR(FIND,A,B,C,D)
;FIND:Address of utility (1536)
; A: Where to start search
i B: Where to quit searching
; c: Search string address
; D: Length of search string
; X: Position found (=0 if no match)
*=
$0600
;Syntax documentation
TADRH
ENDLOOP
co
.,0""CI
OQ
.,III
OQ
::J
c::
D'
......
......
85CE
68
85CD
68
85D0
68
85CF
68
10614 68
0615 85Dl
106108
el6elA
el6elB
el6elD
06elE
106110
10611
10613
1061010
106110
106210
106310
06410
10650
10660
10670
106810
106910
107010
107110
107210
07310
107410
107510
107610
107710
107810
107910
1081010
108110
108210
108310
10840
FNDLEN
FNDL
FNDH
SLENL
SLENH
~lo
iwe
~If
Search string
10 byte,
Search string
hi byte,
~hi
~lo
--------------------------------
STA
PLA
STA
PLA
STA
PLA
STA
PLA
~Ignore it
PLA
STA
OQ
.,0"
.,11/
OQ
s::5
s:
OCI
D'
<.n
>-'
'"""'
E6CC
CA
3006
00E8
0639 A5CO
0632
0634
0635
0637
0620 C8
062E C409
0630 00F5
0627 B1CB
0629 C502
062B F017
0623 8509
0625 A000
0621 A9FF
0610 A6CE
061F F018
0617 A000
0619 B1CF
061B 8502
0850
0860
0870
0880
0890
0900
0910
0920
0930
0940
0950
0960
0970
0980
0990
1000
1010
1020
1030
1040
1050
1060
1070
1080
1090
1100
LOA
SHORT
LOA
INC
OEX
BMI
BNE
ino
iyes
iFound a match?
iSelect end
iSet up first
icomparison
SLENL
EXIT
NXTSRCH
SADRH
iSet up last
iyes
inope
iNext block
;Oone?
END LOOP
SEARCHLOOP icontinue
(SAORL) I Y
FIRSTCHAR
FOUNOl
ENOLOOP
#0
#255
SLENH
SHORT
LOX
BEQ
STA
LOY
SEARCHLOOP
LOA
CMP
BEQ
NOTFOUNO
INY
CPY
BNE
SEARCH2
NXTSRCH
#0
(FNOL) I Y
FIRSTCHAR
LOY
LOA
STA
co
""r
OQ
."
""r
0
OQ
:::l
tJ:I
c:
is:
......
......
a..
A900
85D4
85D5
60
84D4
84D3
A001
84D6
063D
063F
0641
0643
0644
0646
0648
064A
063B D0E6
1110
1120
1130
1140
1150
1160
1170
1180
1190
1200
1210
1220
1230
1240
1250
1260
1270
1280
1290
1300
1310
1320
1330
1340
1350
1360
LDA
STA
STA
RTS
FR!Zi+l
FR0
#13
SEARCH2
; return
; =0
,nQ strin~
; found
;scan
STY
STY
LDY
STY
FR0
SINDEX
#1
FINDEX
;Find index
;Save Y
;Source index
FOUND1
--------------------------------
EXIT
BNE
11/
..,
OQ
..,
~
"U
0
OQ
is:
:i"
I:
."
CCI
'-l
.....
......
A4D6
C4Dl
F016
B1CF
E6D6
A4D3
C8
D002
E608
0654
0656
0658
065A
065C
065E
0660
0661
0663
0665 84D3
0667 D1D7
0669 F0E9
A5CB
85D7
A5CC
85D8
064C
064E
0650
0652
1370
1380
1390
1400
1410
1420
1430
1440
1450
1460
1470
1480
1490
1500
1510
1520
1530
1540
1550
1560
1570
1580
1590
1600
1610
1620
SADRL
TADRL
SADRH
TADRH
iCOpy to
itemp addr
STY
CMP
BEQ
jComparison
SKIP INC
LDY
CPY
BEQ
LDA
INC
LOY
INY
BNE
INC
SINDEX
(TADRL),Y
CONTSRCH
failure,
SKIP INC
TADRH
FINOEX
FNOLEN
FOUN02
(FNDL), Y
FINDEX
SINDEX
;Update
iequal so far?
;yes, continue
iPast end?
i yes-matchl
iCharacter n
i no, increment
iCompare to
isource
iHit page bound?
CONTSRCH
LDA
STA
LDA
STA
(1)
"'I
OQ
"'I
"1:1
0
OQ
c::
OJ
co
'-'
'-'
SADRL
FNDL
SINDEX
TADRH
NXTSRCH
NOT FOUND
SKIPINC
18
A5D4
65CB
85D4
A5CC
691010
85D5
610
=elelCB
=elelCF
=elelD3
=elelD8
10621
el62D
0665
el67E
106710
10671
10673
10675
10677
10679
el67B
el67D
el66B A4D4
el66D 18
el66E 9elBD
16310
16410
16510
16610
16710
16810
16910
171010
17110
17210
17310
1740
17510
17610
17710
17810
17910
181010
=elIOCC
=elIODIO
=elelD4
=elelD9
10623
063D
SADRH
FNDH
FRIO
END LOOP
SEARCH2
EXIT
.END
=elelCD
=elIODl
=elelD6
1061010
10627
10654
SLENL
FNDLEN
FINDEX
FIND
SEARCHLOOP
CONTSRCH
=elIOCE
=elelD2
=elelD7
10639
10644
106710
SLENH
FIRSTCHAR
TADRL
SHORT
FOUNDI
FOUND2
OQ
.,
-g
.,
OQ
:i"
o:J
=.0:
00
Building A Program 8
8 Building A Program
828
834
840
846
852
858
864
870
876
882
888
894
900
DATAI18,165,1,24,105,4
DATAI33,1,165,2,105,0
DATAI33,2,160,0,177,1
DATA240,28,205,6,8,240
DATA4,200,76,76,3,162
DATAO,232,200,189,6,8
DATA240,7,209,1,240,245
DATA76,76,3,76,119,3
DATAI65,3,133,1,165,4
DATAI33,2,76,28,3,169
DATAI63,32,237,253,32,32
DATA237,169,160,32,237,253
DATA76,108,3
120
ML Equivalents Of
BASIC COl11rnands
What follows is a small dictionary, arranged alphabetically, of the
major BASIC commands. If you need to accomplish something in ML
- TAB for example -look it up in this chapter to see one way of
doing it in ML. Often, because ML is so much freer than BASIC, there
will be several ways to go about a given task. Of these choices, one
might work faster, one might take up less memory, and one might be
easier to program and understand. When faced with this choice, I
have selected example routines for this chapter which are easier to
program and understand. At ML speeds, and with increasingly
inexpensive RAM memory available, it will be rare that you will need
to opt for velocity or memory efficiency.
CLR
In BASIC, this clears all variables. Its primary effect is to reset
pointers. It is a somewhat abbreviated form of NEW since it does not
"blank out" your program, as NEW does.
We might think of CLR, in ML, as the initialization routine which
erases (zeros) the memory locations you've set aside to hold your ML
flags, pointers, counters, etc. Before your program RUNs, you may
want to be sure that some of these "variables" are set to zero. If they
are in different places in memory, you will need to zero them
individually:
2000 LOA # 0
2002 STA 1990 (put zero into one of the "variables")
2005 STA 1994 (continue putting zero into each byte which
needs to be initialized)
On the other hand, maybe you've got your tables, flags, etc., all
lined up together somewhere in a data table at the start or end of your
ML program. It's a good idea. If your table is in one chunk of RAM ,
say from 1985 to 1999, then you can use a loop to zero them out:
2000 LOA # 0
2002 LOY # 15
(Y will be th e counter. There are 15 bytes to zero out in
this exa mple.)
121
CONT
2004 STA 1985, Y (the lowest of the 15 bytes)
2007 DEY
2008 BNE 2004 (let Y count down to zero, BNEing until Y is zero,
then the Branch if Not Equal will let the program
fall through to the next instruction at 2010)
CONT
This word allows your program to pick up where it left off after a
STOP command (or after hitting the system break key). You might
want to look at the discussion of STOP, below. In ML, you can't
usually get a running program to stop with the BREAK (or STOP)
key. If you like, you could write a subroutine which checks to see if a
particular key is being held down on the keyboard and, if it is, BRK:
3000 LOA 96 (or whatever your map says is the "key currently
depressed" location for your machine)
3002 CMP # 13 (this is likely to be the RETURN key on your
machine, but you'll want CMP here to the value
that appears in the "currently pressed" byte for
the key you select as your STOP key. It could be
any key. If you want to use" A" for your" stop"
key, try CMP #65.)
3004 BNE 3007 (if it's not your target key, jump to RTS)
3006 BRK
(if it is the target, BRK)
3007 RTS
(back to the routine which called this subroutine)
The 6502 places the Program Counter (plus two) on the stack
after a BRK.
A close analogy to BASIC is the placement of BRK within ML
code for a STOP and then typing . G or GO or RUN - whatever your
monitor recognizes as the signal to start execution of an ML program
-toCONT.
DATA
In BASIC, DATA announces that the items following the word DATA
are to be considered pieces of information (as opposed to being
thought of as parts of the program) . That is, the program will
probably use this data, but the data are not BASIC commands . In ML,
such a zone of "non-program " is called a table. It is unique only in
that the program counter never starts trying to run through a table to
carry out instructions. Program control is never transferred to a table
since there are no meaningful instructions inside a table. Likewise,
BASIC slides right over its DATA lines.
To keep things simple, tables of data are usually stored together
either below the program or above it in memory . (See Figure 9-1.)
122
DIM
From within the p rogram, tables can be used to print messages
to the screen, update or exa mine flags, etc. If you disassemble your
BASIC in ROM, you'll find the words STOP, RUN, LIST, and so
forth, gathered together in a table. You can suspect a data table when
your disassembler starts giving lots of error messages . It cannot find
groups of meaningful opcodes wi thin tables .
Figure 91. Typical ML program organization with data tablesone at top or bottom of program .
DATA
INITIALIZATION
Bottom of Memory
Start Of M L Program
Subroutines
MAIN
LOOP
DATA
DIM
With its automatic string handling, array management, and error
messages, BASIC makes life easy for the programmer. The price you
pay for this " hand-holding" is that a program is slow when it's RUN.
In ML, the DIMensioning of space in memory for variables is not
explicitly handled by the computer. You must make a note that you
are setting aside memory from 6000 to 6500, or whatever, to hold
variables. It helps to make a simple map of this" dimensioned"
memory so you know where permanent strings, constants, variable
strings, and variables, flags, etc., are within the dimensioned zone.
A particular chunk of memory (where, and how much, is up to
you) is set aside, that 's all. You don't write any instructions in ML to
set aside the memory; yo u just jot it down so you won't later use the
reserved space for som e oth er purpose. Managing memory is left up
to you. It's not difficult, but it is your responsibility.
123
END
END
There are several ways to make a graceful exit from ML programs.
You can look for the "warm start" address on your particular
computer (in the map of its BASIC locations) and }MP to that address.
Or you can go to the "cold start" address. This results in the
computer resetting itself as if you had turned the power off and then
back on again.
If you went into the ML from BASIC (with a USR or SYS), you
can return to BASIC with an RTS. Recall that every JSR matches up
with its own RTS. Every time you use a JSR, it shoves its " return
here" address onto the top of the stack. If the computer finds another
JSR (before any RTS 's), it will shove another return address on top of
the first one. So, after two JRS's, the stack contains two return
addresses . When the first RTS is encountered, the top return address
is lifted from the stack and put into the program counter so that the
program returns control to th e current instruction following the most
recent JSR.
When the next RTS is encountered, it pulls its appropriate return
(waiting for it on the stack) and so on. The effect of a SYS or USR
from BASIC is like a JSR from within ML. The return address to the
correct spot within BASIC is put on the stack. In this way, if you are
within ML and there is an RTS (without any preceding JSR), what's
on the stack had better be a return-to-BASIC address left there by SYS
or USR when you first went into ML.
Another way to END is to put a BRK in your ML code . This
drops you into the machine 's monitor. Normally, you put BRKs in
during program development and debugging. When th e program is
finished, though, you would not want to make this ungraceful exit
any more than you would want to end a BASIC program with STOP.
In fact, many ML programs, if they stand alone and are not part
of a larger BASIC program, never END at all! They are an endless
loop . The main loop just keeps cycling over and over. A game will not
end until you turn off the power. After each game, you see the score
and are asked to press a key when you are ready for the next game .
Arcade games which cost a quarter will ask for another quarter, but
they don't end. They go into" attract mode. " The game graphics are
left running on screen to interest n ew customers.
An ML word processor will cycle through its main loop, waiting
for keys to be pressed, words to be written, format or disk
instructions to be given. Here, too, it is common to find that the word
processor takes over the machine, and you cannot stop it without
turning the computer off. Among other things, such an endless loop
protects software from being easily pirated. Since it takes control of
the machine, how is someone going to save it or examine it once it's
124
FOR-NEXT
FOR-NEXT
Everyone has used " delay loops" in BASIC (FOR T = 1 TO 1000:
NEXT T) . These are small loops, sometimes called do-nothing
loops because nothing happens between the FOR and the NEXT
except the passage of time . When you need to let the user read
something on the screen, it's sometimes easier just to use a delay loop
than to say "When finished reading, press any key."
In any case, you'll need to use delay loops in ML just to slow ML
itself down. In a game, the ball can fly across the screen. It can get so
fast, in fact , that you can' t see it. It just" appears" when it bounces
off a wall. And, of course, yo u'll need to use ioops in many other
situations . Loops of all kinds are fundamental programming
techniques.
In ML, you don't have that convenient little counter ("T" in the
BASIC FOR/NEXT example above) which decides when to stop the
loop. When Tbecomes 1000, go to the instructions beyond the word
NEXT. Again, you must set up and check your counter variable by
yourself.
If the loop is going to be smaller than 255 cycles, you can use the
X register as the counter (Y is saved for the very useful indirect indexed
addressing discussed in Chapter 4: LDA (96), Y) . So, using X, you can
count to 200 by :
2000 LOX #200 (or $C8 hex)
20020EX
2003 BNE 2002
125
FOR-NEXT-STEP
For loops involving counters larger than 255, you'll need to use
two bytes to count down, one going from 255 to zero and then
clicking (like a gear) the other (more significant) byte. To count to 512:
2000 LOA #2
2002 STAO
(put the 2 into address zero, our MSB, Most
Significant Byte, counter)
(set X to zero so that its first OEX will make it 255.
2004 LOX #0
Further OEX's will count down again to zero,
when it will click the MSB down from 2 to 1 and
then finally 0)
20060EX
2007 BNE 2006
2009 DEe 0
(click the number in address zero down 1)
2011 BNE 2006
Here we used the X register as the LSB (least significant byte)
and address zero as the MSB. We could use addresses zero and one to
hold the MSB/LSB if we wanted. This is commonly useful because
then address zero (or some available, two-byte space in zero page)
can be used for LOA (0), Y. You would print a message to the screen
using the combination of a zero page counter and LOA (zero page
address),Y.
FOR-NEXT-STEP
Here you would just increase your counter (usually X or Y) more than
once. To create FOR 1= 100 TO 1 STEP -2 you could use:
2000 LOX # 100
20020EX
20030EX
2004 Bee 2002
For larger numbers you create a counter which uses two bytes
working together to keep count of the events . Following our example
above for FOR-NEXT, we could translate FOR 1= 512 TO a STEP -2:
2000 LOA #2
2002 STA 0
(this counts the MSB)
2004 LOX # 0 (X counts the LSB)
20060EX
2007 DEX
(here we click X down a second time, for -2)
2008 BNE 2006
2010 DECO
2012 BNE 2006
126
GET
For larger STEP sizes, yo u ca n use a nested loop within the larger
one. This would avoid a wh ole slew of INX's. To write the ML
equivalent of FOR 1=1 TO 50 STEP 10:
2000 LOX #0
2002 LOY #0
2004INX
2005INY
2006 CPY #10
2008 BNE 2004
2010 CPX #50
2012 BNE 2002
GET
Each computer model ha s its own "which key is being pressed?"
address, where it h olds the va lue of a character typed in from the
keyboard . To GET, you create a very small loop which just keeps
testing the first address in th e buffer.
For Atari (in decimal):
2000 LOA 764 ("which key pressed " decimal address. In
advanced assemblers, yo u could freely mix
decimal with hex, but not in the Simple
Assembler. )
2003 CMP #255 (wh en an FF value is in this address, it means
that no key is pressed)
2005 BEQ 2000 (keep going back and looking until there is some
key pressed)
For PET (Upgrade and 4.0) (in decimal)
2000 LOA 151 ("which key pressed " decimal address)
2003 CMP #255
2005 BEQ 2000
127
GOSUB
For Apple II (hex):
2000 LOA COOO ("which key pressed" - note: this is in hex)
2003 BPL 2000
2005 STA COlO (clears the keyboard)
2008 AND #7F (to give you the correct character value)
For VI C and 64 (decimal):
2000 LOA 197
2003 CMP #255
2008 BEQ 2000
The Commodore computers have a GET routine similar to the
one illustrated by these examples, which is built in at $FFE4 which
can be used for all ROM versions (all models of CBM) because it is a
fixed JMP table which does not change address when new BASIC
versions are introduced . See your BASIC's map for Print a Byte to the
Screen, GET a Byte, and other routines in the Commodore Jump
Tables. They start at $FFBO .
The examples above do not conform to PET BASIC's GET. In
this version of BASIC, the computer does not "wait" for a character.
If no key is being held down during a GET, the computer moves on
and no GET takes place. In our ML GETs above, we loop until some
character is actually pressed.
For most programming purposes, though, you want to wait
until a key has actually been pressed. If your program is supposed to
fly around doing things until a key is pressed, you might use the
above routines without the loop structure . Just use a CMP to test for
the particular key that would stop the routine and branch the
program somewhere else when a particular key is pressed. How you
utilize and construct a GET-type command in ML is up to you. You
can, with ML's flexibility, make special adjustments to use the best
kind of GET for each different application.
GOSUB
This is nearly identical to BASIC in ML. Use JSR $NNNN and you
will go to a subroutine at address NNNN instead of a line number, as
in BASIC. ("NNNN" just means you can put any hex number in
there you want to.) Some assemblers allow you to give "labels,"
names to JSR to instead of addresses. The Simple Assembler does not
allow labels. You are responsible (as with DATA tables, variables,
etc.) for keeping a list on paper of your subroutine addresses and the
parameters involved.
Parameters are the number or numbers handed to a subroutine to
give it information it needs. Quite often, BASIC subroutines work
with the variables already established within the BASIC program. In
ML, though, managing variables is up to you. Subroutines are useful
128
GOTO
because they can perform tasks repeatedly without needing to be
programmed into the body of the program each time the task is to be
carried out. Beyond this, they can be generalized so that a single
subroutine can act in a variety of ways, depending upon the variable
(the parameter) which is passed to it.
A delay loop to slow up a program could be general in the sense
that the amount of delay is handed to the subroutine each time. The
delay can, in this way, be of differing durations, depending on what
it gets as a parameter from the main routine. Let's say that we've
decided to use address zero to pass parameters to subroutines . We
could pass a delay of "five" cycles of the loop by:
2000 LDA#5
The Main Program 2002 STA 0
2004 ISR 5000
The Subroutine
5000 DECO
5002 BEQ 5012 (if address zero has
counted all the way down
from five to zero, RTS back
to the Main Program)
5004 LOY # 0
5006 DEY
5007 BNE 5006
5009 IMP 5000
5012 RTS
A delay which lasted twice as long as the above would merely
require a single change: 2000 LOA # 10.
GOTO
In ML, it's JMP. JMP is like JSR, except the address you leap away
from is not saved anywhere. You jump, but cannot use an RTS to find
your way back. A conditional branch would be CMP #0 BEQ 5000 . The
condition of equality is tested by BEQ, Branch if EQual. BNE tests a
condition of inequality, Branch if Not Equal. Likewise, BCC (Branch if
Carry is Clear) and the rest of these branches are testing conditions
within the program .
GOTO and JMP do not depend on any conditions within the
program, so they are unconditional. The question arises, when you use
a GOTO: Why did you write a part of your program that you must
always (unconditionally) jump over? GOTO and JMP are sometimes
used to patch up a program, but, used without restraint, they can
make your program hard to understand later. Nevertheless, JMP can
many times be the best solution to a programming problem . In fact, it
is hard to imagine ML programming without it.
129
GOTO
One additional note about JMP: it makes a program nonrelocatable. If you later need to move your whole ML program to a
different part of memory, all the JMP's (and JSR 's) need to be checked
to see if they are pointing to addresses which are no longer correct
(JMP or JSR into your BASIC ROM's will still be the same, but not
those which are targeted to addresses within the ML program). This
can be an important consideration if you are going to use an ML
subroutine in other programs where the locations might well differ.
Fully relocatable ML routines can be convenient if you like to program
by drawing from a personal collection of solved problems.
2000 JMP 2005
2003 LOY #3
2005 LOA #5
This works because we set the Z flag. Then, when BEQ tests the
zero flag, it will pass the test, it will find that flag "up" and will
branch. If you load X, Y, or A with a zero, the zero flag goes up.
Various monitors and assemblers include a "move it" routine,
which will take an ML program and relocate it somewhere else in
memory for you. On the Apple, you can go into the monitor and type
*5000 < 2000.2006M (although you will have to give the monitor these
numbers in hex). The first number is the targe t address. The second
and third are the start and end of the program you want to move .
On CBM computers, the built-in monitor (the VIC-20 and the
Original 2001 ROM set do not have a built-in monitor) does not have a
Move it command. However, it is easy to add a "monitor extension"
program to the built-in monitor. Superman and Microman are such
extensions. The format for Moveit in Commodore machines is .T 2000
20065000 (start and end of the program to be moved, followed by the
target address). Again, these numbers must be in hex. The T stands
for transfer.
The Atari Assembler Editor Cartridge follows a convention
similar to Apple's: M 5000<2000,2006.
130
INPUT
IF-THEN
This familiar and primary computing structure is accomplished in ML
with the combination of CMP-BNE or any other conditional branch:
BEQ, BCe, etc. Sometimes, the IF half isn't even necessary. Here's
how it would look:
2000 LOA 57 (what's in address 577)
2002 CMP #15 (is it IS?)
2004 BEQ 2013 (IF it is, branch up to 2013)
2006 LOA #10 (or ELSE, put a 10 into address 57)
2008 STA 57
2010 IMP 2017 (and jump over the THEN part)
2013 LOA #20 (THEN, put a 20 into address 57)
2015 STA 57
2017
(continue with the program ... )
Often, though , your flags are already set by an action, making
the CMP unnecessary. For example, if you want to branch to 2013 if
the number in address 57 is zero, just LOA 57 BEQ 2013 . This is
because the act of loading the accumulator will affect the status
register flags. You don' t need to CMP #0 because the zero flag will be
set if a zero was just loaded into the accumulator. It won't hurt
anything to use a CMP, but you'll find many cases in ML
programming where you can shorten and simplify your coding. As
you gain experience, you will see these patterns and learn how and
what affects the status register flags .
INPUT
This is a series of GETs, echoed to the screen as they are typed in,
which end when the typist hits the RETURN key. The reason for the
echo (the symbol for each key typed is reproduced on the screen) is
that few people enjoy typing without seeing what they've typed. This
also allows for error correction using cursor control keys or DELETE
and INSERT keys. To handle all of these actions, an INPUT routine
must be fairly complicated. We don ' t want, for example, the DELETE
to become a character within the string. We want it to immediately act
on the string being entered during the INPUT, to erase a mistake.
Our INPUT routine must be smart enough to know what to add
to the string and what keys are intended only to modify it. Here is the
basis for constructing yo ur own ML INPUT. It simply receives a
character from the keyboard, stores it in the screen RAM cells, and
ends when the RETURN key is pressed. This version is for Upgrade
and 4.0 CBM /PETs and we'll write it as a subroutine. That simply
means that when the 13 (ASCII for carriage return) is encountered,
131
LET
we'll perform an RTS back to a point just following the main program
address which JSRed to our INPUT routine:
5000 LOY #0
LET
Although this word is still available on most BASICs, it is a holdover
from the early days of computing. It is supposed to remind you that a
statement like LET NAME = NAME +4 is an assignment of a value to a
variable, not an algebraic equation . The two numbers on either side of
the "equals" sign, in BASIC, are not intended to be equal in the
algebraic sense. Most people write NAME=NAME+4 without using
LET. However, the function of LET applies to ML as well as to BASIC:
we must assign values to variables.
In the Atari, VIC, and Apple, for example, where the address of
the screen RAM can change depending on how much memory is in
the computer, etc. - there has to be a place where we find out the
starting address of screen RAM . Likewise, a program will sometimes
require that you assign meanings to string variables, counters, and the
like. This can be part of the initialization process, the tasks performed
132
LET
before the real program, your main routine, gets started . Or it can
happen during the execution of the main loop. In either case, there
has to be an ML way to es tabli sh , to assign, variables . This also means
that you must have zones of memory set aside to hold these variables.
For strings, you can think of LET as the establishment of a
location in memory . In our INPUT example above, we might have
included an instruction which would have sent the characters from
the keyboard to a table of strings as well as echoing them to the
screen. If so, there would have to be a way of managing these strings.
For a discussion on the two most common ways of dealing with
strings in ML, see Chapter 6 under the subhead "Dealing With
Strings. "
In general, you will probably find that you program in ML using
somewhat fewer variables than in BASIC. There are three reasons for
this:
1. You will probably not write many programs in ML such as
data bases where you manipulate hundreds of names, addresses, etc.
H might be somewhat inefficient to create an entire data base
management program, an inventory program for example, in ML.
Keeping track of the variables would be a nightmare . An important
benefit of ML is its speed of execution, but a drawback is that it slows
programming down . So, for an inventory program, you could write
the bulk of the program in BASIC and simply attach ML routines for
sorting and searching tasks within the program .
2. Also, the variables in ML are often handled within a series of
instructions (not held elsewhere as BASIC variables are). FOR 1=1
TO 10: NEXT I becomes LOY #1, INY, CPY #10, BNE . Here, the
BASIC variable is counted for you and stored outside the body of the
program. The ML "variable," though, is counted by the program
itself. ML has no interpreter which handles such things. If you want a
loop, you must construct all of its components yourself.
3. In BASIC, it is tempting to assign values to variables at the
start of the program and then to refer to them later by their variable
names, as in: 10 BALL= 79. Then, any time you want to PRINT the
BALL to the screen, you could say, PRINT CHR$(BALL). Alternatively, you might define it this way in BASIC: 10 BALL$ = "0". In
either case, your program will later refer to the word BALL. In this
example we are assuming that the number 79 will place a ball
character on your screen.
In ML we are not free to use variable names except when using a
complicated, advanced assembler. With the Simple Assembler, you
w ill find it easier just to LOA #79, STA (screen position) each time.
Some people like to put the 79 into their zone of variables (that
arbitrary area of memory set up at the start of a program to hold
tables, counters, and important addresses). They can pull it out of
that zone whenever it's needed. That is somewhat cumbersome,
133
LIST
though, and slower. You would LOA lOIS, STA (screen position),
assuming you had put a 79 into this "ball" address earlier.
Obviously a value like BALL will remain the same throughout a
program. A ball will look like a ball in your game, whatever else
happens. So, it's not a true variable, it does not vary. It is constant. A
true variable must be located in your" zone of variables," your
variable table. It cannot be part of the body of your program itself (as
in: LOA #79) because it will change. You don't know when writing
your program what the variable will be. So you can't use immediate
mode addressing because it might not be a #79. You have to LOA 1015
(or whatever) from within your table of variables.
Elsewhere in the program you have one or more STA 1015's or
INC 1015's or some other manipulation of this address which keeps
updating this variable. In effect, ML makes you responsible for
setting aside areas which are safe to hold variables. What's more, you
have to remember the addresses, and update the variables in those
addresses whenever necessary . This is why it is so useful to keep a
piece of paper next to you when you are writing ML. The paper lists
the start and end addresses of the zone of variables, the table. You
also write down the specific address of each variable as you write
your program.
LIST
This is done via a disassembler. It will not have line numbers (though,
again, advanced assembler-disassembler packages do have line
numbers). Instead, you will see the address of each instruction in
memory. You can look over your work and debug it by working with
the disassembler, setting BRKs into problem areas, etc. See
Appendix D.
LOAD
The method of saving and loading an ML program varies from
computer to computer. Normally, you have several options which
can include loading: from within the monitor, from BASIC, or even
from an assembler. When you finish working on a program, or a
piece of a program, on the Simple Assmbler you will be given the
starting and ending addresses of your work. Using these, you can
save to tape or disk in the manner appropriate to your computer. To
LOAD, the simplest way is just to LOAD as if you were bringing in a
BASIC program. Unfortunately, this only works on Commodore
machines. You'll get your ML program, not a BASIC program, so it
won't start at the normal starting address for BASIC unless you wrote
and saved it at that address. You should type NEW after loading it,
however, to reset some pointers in the computer. That will not NEW
out the ML program.
134
NEW
To save from w ithin the monitor on Commodore machines:
.S "PROGRAM NAME",Ol,NNNN,NNNN* (for tape)
.L "PROGRAM NAME",Ol (for tape)
.S "O:PROGRAM NAME",08,NNNN,NNNN* (for disk)
.L "O:PROGRAM NAME",08 (for disk)
*You should add one to the hex number for the end of your
program or the SAVE will clip off the last byte. If your program exists
in RAM from $0300 to $0350, you save it like this: .S "PROGRAM
NAME" ,01,0300,0351.
On the Apple, you must BLOAD from disk . On the Atari, if you
have DOS you can use the "L" command from the DOS menu to
LOAD in an ML program. If you don't, you need to use a short
BASIC program that grabs in the bytes via a series of GETs:
10 OPEN#1,4,0, "C:"
20 GET#1,NN~GET#1,NN: REM DISCARD THE HEADER
30 GET#1,LO:GET#1,HI: REM START ADDRESS
40 START = LO+256*HI
50 GET#l, LO:GET#1,HI: REM ENDING ADDRESS
60 FIN = LO + 256*HI
70 TRAP 100
80 FORI = START TO FIN: GET#l,A: POKEI,A:NEXTI
90 GOTO 30
100 END
Note: This will not work correctly if the START and FIN
addresses overlap this BASIC program in memory. It would
then load in on top of itself.
NEW
In Microsoft BASIC, this has the effect of resetting some pointers
which make the machine think you are going to start over again. The
next program line you type in will be put at the" start-of-a-BASICprogram " area of memory . Some computers, the Atari for example,
even wash memory by filling it w ith zeros. There is no special
command in ML for NEWing an area of memory, though some
monitors have a "fill memory" option which will fill a block of
memory as big as you want with whatever value you choose.
The reason that NEW is not found in ML is that you do not
always write your programs in the same area of memory (as you do in
BASIC), building up from some predictable address. You might have
a subroutine floating up in high memory, another way down low,
your table of variables just above the second subroutine, and your
main program in the middle. Or you might not . We've been using
135
ON GOSUB
2000 as our starting address for many of the examples in this book
and 5000 for subroutines, but this is entirely arbitrary.
To "NEW" in ML, just start assembling over the old program.
Alternatively, you could just turn the power off and then back on
again. This would, however, have the disadvantage of wiping out
your assembler along with your program.
ON GOSUB
In BASIC, you are expecting to test values from among a group of
numbers: 1,2,3,4,5 .... The value of X must fall within this narrow
range: ON X COSUB lOa, 200, 300 ... (X must be 1 or 2 or 3 here) . In
other words, you could not conveniently test for widely separated
values of X (18,55,220). Some languages feature an improved form of
ON COSUB where you can test for any values. If your computer
were testing the temperature of your bathwater:
CASE
80 OF GOSUB HOT ENOOF
100 OF GOSUB VERYHOT ENOOF
120 OF GOSUB INTOLERABLE ENOOF
ENOCASE
136
ON GOTO
This is more common in ML than the ON COSUB structure above. It
eliminates the need to worry about what is in the accumulator when
you return from the subroutines . Instead of RTSing back, you jump
back, following all the branch tests .
2000 LOA 150
2002 CMP #80
2004 BNE 2009
2006 JMP 5000
2009 CMP # 100
2011 BNE 2016
2013 JMP 5020
2016 CMP # 120
2018 BNE 2023
2020 JMP 5030
2023
(print "hot")
PRINT
You could print out a message in the following way:
2000 LOY #0
2002 LOA #72
138
PRINT
up the LSB (least significant byte). If you are going to put this target
address into zero page at 56 (decimal):
2000 LOA #232
2002 STA 56
2004 LOA #3
2006 STA 57
2008 JSR 5000
(LSB, in decimal)
(MSB)
(printout subroutine)
5000 LOY #0
5002 LOA (56), Y
5004 BEQ 5013
(if zero, return from subroutine)
5006 STA 32900,Y (to screen)
5009INY
5010 JMP 5002
5013 RTS
One drawback to the subroutine is that it will always print any
messages to the same place on the screen . That 32900 (or whatever
you use there) is frozen into your subroutine. Solution? Use another
zero page pair of bytes to hold the screen address. Then, ym.u calling
routine sets up the message address, as above, but also sets up the
screen address.
The Atari contains the address of the first byte of the screen
addresses in zero page for you at decimal 88 and 89. You don't need
to set up a screen address byte pair on the Atari . We are using the
Apple II's low resolution screen for the examples in this
book, so you will want to put 0 and 4 into the LSB and MSB
respectively. The PET's screen is always located in a particular place,
unlike the Atari, Apple, VIC, and 64 screen RAM locations which can
move, so you can put a $00 and an $80 into LSB and MSB for PET.
The following is in decimal:
2000 LDA #232
2002 STA 56
2004 LOA #3
2006 STA 57
2008 LOA #0
2010 STA 58
2012 LOA #4
2014 STA 59
2016 JSR 5000
(LSB)
(set up message address)
(MSB)
(LSB for PET and Apple)
(we'll just use the next two bytes in zero page
above our message address for the screen address)
(this is for Apple II; use 128 ($80) for PET)
5000 LOY #0
5002 LOA (56), Y
5004 BEQ 5013 (if zero, return from subroutine)
139
READ
5006 STA (58),Y (to screen)
5009INY
5010 IMP 5002
5013 RTS
For Atari: 5006 STA (88), Y. You have less flexibility because you
will always be printing your messages to the first line on screen,
using address 88 as your screen storage target. To be able to put the
message anywhere on screen, Atari users will have to use some other
zero page for the screen address, as we did for Apple II and PET
above. Atari users would have to keep track of the " cursor position"
for themselves in that case.
READ
There is no reason for a reading of data in ML. Variables are not placed
into ML "DATA statements." They are entered into a table when you
are programming. The purpose of READ, in BASIC, is to assign
variable names to raw data or to take a group of data and move it
somewhere, or to manipulate it into an array of variables. These
things are handled by you, not by the computer, in ML programming .
If you need to access a piece of information, you set up the
addresses of the datum and the target address to which you are
moving it. See the "PRINT" routines above. As always, in ML you
are expected to keep track of the locations of your variables. You keep
a map of data locations, vectors, tables, and subroutine locations. A
pad of paper is always next to you as you program in ML. It seems as
if you would need many notes. In practice, an average program of say
1000 bytes could be mapped out and commented on, using only one
sheet.
REM
You do this on a pad of paper, too. If you want to comment or make
notes about your program - and it can be a necessary, valuable
explanation of what's going on - you can disassemble some ML code
like a BASIC LISTing . If you have a printer, you can make notes on
the printed disassembly. If you don't have a printer, make notes on
your pad to explain the purpose of each subroutine, the parameters it
expects to get, and the results or changes it causes when it operates.
Complex, large assemblers often permit comments within the
source code. As you program with them, you can include REMarks
by typing a semicolon, or parentheses, or some other signal to the
assembler to ignore the REMarks when it is assembling your
program . In these assemblers, you are working much closer to the
way you work in BASIC. Your remarks remain part of the source
program and can be listed out and studied .
140
RUN
RETURN
RTS works the same way that RETURN does in BASIC: it takes you
back to just after the JSR (COSUB) that sent control of the program
away from the main program and into a subroutine. JSR pushes, onto
the stack, the address which immediately follows the JSR itself. That
address then sits on the stack, waiting until the next RTS is
encountered. When an RTS occurs, the address is pulled from the
stack and placed into the program counter. This has the effect of
transferring program control back to the instruction just after the JSR.
RUN
There are several ways to start an ML program. If you are taking off
into ML from BASIC, you just use SYS or USR or CALL. They act just
like JSR and will return control to BASIC, just like RETURN would,
when there is an unmatched RTS in the ML program. By unmatched
we mean the first RTS w hich is not part of a JSR /RTS pair. USR and
SYS and CALL can be used either in immediate mode (directly from the
keyboard) or from within a BASIC program as one of the BASIC
commands.
USR is just like SYS and CALL except that you can "send" values
from BASIC to ML by attaching them to the USR ( ) within the
parentheses. In Microsoft BASIC (Apple, PET/CBM, etc.), you must
set up the location of your target ML program in special USR
addresses, before exiting BASIC via USR . For example, to "gosub" to
an ML routine located, at $0360 (hex), you want to put a $60 (hex) into
address 1 and an 03 into address 2. The 03 is obvious, just POKE 2,3.
Atari goes from BASIC to ML via USR. The USR's argument may
place several parameters on the stack along with the" count," the
number of parameters which were passed.
The hex 60 means that you would multiply 16 x 6, since the
second column in hex is the "16's" column. So you would POKE 1,
96. Recall that we always set up ML addresses to be used by "indirect
indexed addressing" (LDA (00), Y) by putting the LSB (least
significant byte) first. To set up 0360, then, you first separate the hex
number into its two bytes, 03 60. Then you translate them into
decimal since we're in BASIC when we use USR: 3 96. Then you
switch them so that they conform tg the correct order for ML:
LSB /MS B 96 3. Finally, you POKE them into memory locations 1
and 2.
If this seems rather complex, it is. In practice, Microsoft BASIC
users rarely use USR . The number which is "passed" to ML from
within the parentheses is put into the floating point accumulator.
Following this you must JSR to FPINT, a BASIC ROM routine which
converts a floating point value into an integer that you could work
141
RUN
with in ML. As we mentioned, working with floating point arithmetic
in ML is an arcane art. For most applications which must pass
information from BASIC to ML, it is far easier to use ordinary
"integer" numbers and just POKE them into some predetermined
ML variable zone that you've set aside and noted on your workpad .
Then just SYS to your ML routine, which will look into the set-aside,
POKEd area when it needs the values from BASIC.
In Atari BASIC, USR works in a more simplified and more
convenient way. For one thing, the target ML address is contained
within the argument of the USR command: USR (address) . This
makes it nearly the exact parallel of BASIC's GOSUB. What's more,
USR passes values from BASIC by putting them on the stack as a twobyte hex number. USR (address,X) does three things. 1. It sends
program controi to the ML routine which starts at "address." 2. It
pushes the number X onto the stack where it can be pulled out with
PLA's.3. Finally, it pushes the total number of passed values onto the
stack. In this case, one value, X, was passed to ML. All of these
actions are useful and make the Atari version of USR a more sensible
way of GOSUBing from BASIC to ML.
If you are not going between BASIC and ML, you can start
(RUN) your ML program from within your "monitor." The PET/CBM
and the Apple have built-in monitor programs in their ROM chips .
On the Atari, a monitor is available as part of a cartridge . On the
"Original" PET/CBM (sometimes called BASIC 2.0), there is no builtin monitor. A cassette with a program called TIM (terminal interface
monitor) can be LOADed, though , and used in the same way that the
built-in versions are on later models. Neither the VIC nor the 64 has a
built-in monitor.
To enter "monitor mode" (as opposed to the normal BASIC
mode), you can type SYS 1024 or SYS 4 on the PET/CBM. These
locations always contain a zero and, by "landing" on a zero in ML,
you cause a BRK to take place . This displays the registers of your 6502
and prints a dot all. the screen while waiting for your instructions to
the monitor. To enter the monitor on Apple II, type CALL -151 and
you will see an asterisk (instead of PET's period) as your prompt .
From within Atari's Assembler Cartridge, you would type BUG to
enter the equivalent of the Apple and PET monitor. The Atari will
print the word DEBUG and then the cursor will wait for your next
instruction.
To RUN an ML program, all five computers use the abbreviation
G to indicate "goto and run" the hex address which follows the G.
Unfortunately, the format of the ML RUN (G), as always, differs
between machines. To run a program which starts at address $2000:
Apple II,
you type: 2000G
(8192 in decimal)
PET, VIC,64, you type: G 2000
Atari,
you type : G 2000
142
STOP
One other difference: the Apple II expects to encounter an
unmatched RTS to end the run and return control to the monitor. Put
another way, it will think that your ML program is a subroutine and
2000G causes it to ]SR to the subroutine at address (in hex) 2000. The
Commodores and the Atari both look for a BRK instruction (00) to
throw them back into monitor mode.
SAVE
When you SAVE a BASIC program, the computer handles it
automatically. The starting address and the ending address of your
program are calculated for you. In ML, you must know the start and
end yoursel and let the computer know . From the Apple II monitor,
you type the starting and ending address of what you want saved,
and then "W" for write:
2000.2010W (This is only for cassette and these commands are
in hex. These addresses are 8192.8208, in decimal.)
From BASIC to disk use:
BSAVE Name,A,L (A = address, L=length)
On the VIC, 64, and PET, the format for SAVE is similar, but
includes a filename:
.S "PROGRAM NAME",Ol,2000,2010 (the 01 is the "device
number" of the tape piayer)
To save to disk, you must change the device number to 08 and
start the filename with the number of the drive you are SAVEing to:
.S "0:NAME",08,2000,2010
(Always add one to th e "finish" address; the example
above saves from 2000 to 200F .)
With the Atari Assembler Cartridge, you:
SAVE#C:NAME < 2000,2010 (do this from the EDIT, not
DEBUG, mode). The NAME is not required with cassette.
To write Atari sou rce code to cassette, type: SAVE#C. For disk,
type SAVE#D:FILENAME.EXT or use DOS.
STOP
BRK (or an RTS with no preceding ]SR, on the Apple) throws you
back into the monitor mode after running an ML program. This is
most often used for debuggin g programs because you can set
"breakpoints" in th e same way that you would use STOP to examine
variables when debugging a BASIC program .
143
ASC
String Handling
ASC
In BASIC, this will give you the number of the ASCII code which
stands for the character you are testing. ? ASC(" A") will result in a 65
being displayed. There is never any need for this in ML. If you are
manipulating the character A in ML, you are using ASCII already. In
other words, the letter A is 65 in ML programming . If your computer
stores letters and other symbols in nonstandard ways (such as
Commodore character codes for lowercase, and Atari's ATASCII),
you will need to write a special program to be able to translate to
standard ASCII if you are using a modem or some other peripheral
which uses ASCII . See your computer's manual, the Atari BASIC
Reference Manual for example, for information on your computer's
internal character code.
CHRS
This is most useful in BASIC to let you use characters which cannot
be represented within normal strings, will not show up on your
screen, or cannot be typed from the keyboard. For example, if you
have a printer attached to your computer, you could "send"
CHR$(13) to it, and it would perform a carriage return. (The correct
numbers which accomplish various things sometimes differ, though
decimal 13 - an ASCII code standard - is nearly universally
recognized as carriage return.) Or, you could send the combination
CHR$(27)CHR$(8) and the printer would backspace.
Again, there is no real use for CHR$ within ML. If you want to
specify a carriage return, just LOA #13. In ML, you are not limited to
the character values which can appear on screen or within strings .
Any value can be dealt with directly.
The following string manipulation instructions are found in
Microsoft BASIC:
LEFTS
As usual in ML, you are in charge of manipulating data. Here's one
way to extract a five-character-Iong "substring" from out of the left
side of a string as in the BASIC statement: LEFT$ (X$,5)
2000 LOY #5
2002 LOX #0
(use X as the offset for buffer storage)
2004 LOA 1000, Y (the location of X$)
2007 STA 4000,X (the "buffer, " or temporary storage area for
the substring)
2010INX
2011 DEY
2012 BNE 2004
144
RIGHTS
LEN
In some cases, you will already know the length of a string in ML.
One of the ways to store and manipulate strings is to know
beforehand the length and address of a string. Then you could use
the subroutine given for LEFT$ above. More commonly, though, you
will store your strings with delimiters (zeros, except in Atari) at the
end of each string. To find out the length of a certain string:
2000 LOY #0
2002 LOA 1000, Y (the address of the string you are testing)
2003 BEQ 2009 (remember, if you LOA a zero, the zero flag is set.
So you don't really need to use a eMP #0 here to
test whether you've loaded the zero delimiter)
2005INY
2006 BNE 2002 (we are not using a JMP here because we assume
that all your strings are less than 256 characters
long.)
2008 BRK
(if we still haven't found a zero after 256 INY's, we
avoid an endless loop by just BRKing out of the
subroutine)
(the LENgth of the string is now in the Y register)
2009 DEY
We had to DEY at the end because the final INY picked up the
zero delimiter. So, the true count of the LENgth of the string is one
less than Y shows, and we must DEY one time to make this
adjustment.
MIDS
To extract a substring which starts at the fourth character from within
the string and is five characters long (as in MID$(X$,4,5) ):
2000 LOY #5
(the size of the substring we're after)
2002 LOX #0
(X is the offset for storage of the substring)
2004 LOA 1003, Y (to start at the fourth character from within the
X$ located at 1000, simply add three to that
address. Instead of starting our LOA, Y at
1000, skip to 1003. This is because the first
character is not in position one. Rather, it is at
the zeroth position, at 1000.)
2007 STA 4000,X (the temporary buffer to hold the substring)
2010INX
2011 DEY
2012 BNE 2004
RIGHTS
This, too, is complicated because normally we do not know the
LENgth of a given string. To find RICHT$(X$,5) if X$ starts at 1000,
145
RIGHTS
we should find the LEN first and then move the substring to our
holding zone (buffer) at 4000:
2000 LOY #0
2002 LOX #0
2004 LOA 1000, Y
2007 BEQ 2013 (the delimiting zero is found, so we know LEN)
2009INY
2010 JMP 2004
2013 TYA
(put LEN into A to subtract substring size from it)
2014 SEC
(always set carry before subtraction)
2015 SBC #5
(subtract the size of the substring you want to
extract)
2017TAY
(put the offset back into Y, now adjusted to point to
five characters from the end of X$)
2018 LOA 1000, Y
2021 BEQ 2030 (we found the delimiter, so end)
2023 STA 4000,X
2026INX
20270EY
2028 BNE 2018
2030 RTS
The above does not apply to Atari since it cannot use zero as a
delimiter.
SPC
This formatting instruction is similar to TAB. The difference is that
SPC(lO) moves you ten spaces to the right from wherever the cursor
is on screen at the time . TAB(lO) moves ten spaces from the left-hand
side of the screen. In other words, TAB always counts over from the
first column on any line; SPC counts from the cursor's current
position.
In ML, you would just add the amount you want to SPC over. If
you were printing to the screen and wanted ten spaces between A
and B so it looked like this (A
B), you could write:
2000 LOA #65 (A)
2002 STA 32768 (screen RAM address)
2005 LOA #66 (B)
2007 STA 32778 (you've added ten to the target address)
Alternatively, you could add ten to the Y offset:
2000 LOY #0
2002 LOA #65
2004 STA 32768, Y
2007 LOY #10
(add ten to Y)
146
TAB
TAB
Quite similar to src, except that you don't add the offset from the
cursor position (whatever location you most recently printed).
Rather, TAB(X) moves ten over from the left side of the screen, or, if
you are using a printer, from th e left margin on the piece of paper.
There is no particular reason to use TAB in ML. You have much more
direct control in ML over where characters are printed out.
147
Appendix A
ADC
Status Flags
Addressing
Mode
Mnemonics
Immediate
Zero Page
Zero Page, X
Absolute
Absolute, X
Absolute, Y
(Indirect, X)
(Indirect), Y
ADC #Arg
ADCArg
ADCArg, X
ADCArg
ADC Arg, X
ADC Arg, Y
ADC (Arg, X)
ADC (Arg), Y
AND
Status Flags
Addressing
Mode
Immediate
Zero Page
Zero Page, X
Absolute
Absolute, X
Absolute, Y
(Indirect, X)
(Indirect), Y
Opcode
Size
In Bytes
69
65
75
60
70
79
61
2
2
2
3
3
3
2
2
71
Mnemonics
AND # Arg
ANDArg
AND Arg,X
ANDArg
AND Arg, X
AND Arg, Y
AND (Arg, X)
AND (Arg),Y
Opcode
Size
In Bytes
29
25
35
20
3D
39
21
31
2
2
2
3
3
3
2
2
149
ASL
ASL
Status Flags
Addressing
Mode
Accumulator
Zero Page
Zero Page, X
Absolute
Absolute, X
BCC
Status Flags
Addressing
Mode
Relative
BCS
Status Flags
Addressing
Mode
Relative
150
Mnemonics
Opcode
ASLA
ASL Arg
ASLArg, X
ASLArg
ASL Arg, X
Size
In Bytes
OA
06
16
2
2
OE
IE
3
3
Mnemonics
Opcode
Size
In Bytes
90
BeeArg
Mnemonics
BeS Arg
Opcode
Size
In Bytes
BO
BNE
BEQ
Branch On Zero
Status Flags
Addressing
Mode
Relative
BIT
Mnemonics
Opcode
Size
In Bytes
FO
BEQ Arg
Status Flags
Addressing
Mode
Zero Page
Absolute
BMI
Status Flags
Addressing
Mode
Relative
BNE
Status Flags
Addressing
Mode
Relative
Mnemonics
Opcode
Size
In Bytes
24
2C
BIT Arg
BIT Arg
Branch On Minus
N
Mnemonics
Opcode
Size
In Bytes
30
BMI Arg
Mnemonics
BNE Arg
Opcode
Size
In Bytes
DO
151
BPL
BPL
Branch On Plus
Status Flags
Addressing
Mode
Relative
Bve
Status Flags
Addressing
Mode
Relative
BVS
Status Flags
Addressing
Mode
Relative
152
Opcode
Size
In Bytes
10
BPLArg
Break
Status Flags
Implied
Mnemonics
BRK
Addressing
Mode
Mnemonics
Opcode
Size
In Bytes
00
BRK
Mnemonics
Opcode
Size
In Bytes
50
BVe Arg
Mnemonics
BVS Arg
Opcode
Size
In Bytes
70
elV
CLC
Status Flags
Addressing
Mode
Implied
CLD
Mnemonics
Opcode
Size
In Bytes
18
CLC
Status Flags
Addressing
Mode
Implied
CLI
Mnemonics
Implied
CLV
Implied
08
Mnemonics
Opcode
Size
In Bytes
58
CLI
Status Flags
Addressing
Mode
Size
In Bytes
CLD
Status Flags
Addressing
Mode
Opcode
Mnemonics
CLV
Opcode
Size
In Bytes
88
153
CMP
CMP
Status Flags
Addressing
Mode
Mnemonics
Immediate
Zero Page
Zero Page, X
Absolute
Absolute, X
Absolute, Y
(Indirect, X)
(Indirect), Y
CMP # Arg
CMP Arg
CMPArg, X
CMPArg
CMP Arg, X
CMP Arg, Y
CMP (Arg, X)
CMP (Arg), Y
CPX
Status Flags
Addressing
Mode
Immediate
Zero Page
Absolute
Cpy
Status Flags
Addressing
Mode
Immediate
Zero Page
Absolute
154
Opcode
Size
In Bytes
C9
C5
05
CO
DO
09
C1
01
2
2
2
3
3
3
2
2
Mnemonics
Opcode
Size
In Bytes
EO
E4
EC
2
2
CPX # Arg
CPXArg
CPX Arg
Mnemonics
CPY # Arg
CPY Arg
CPY Arg
Opcode
Size
In Bytes
CO
C4
CC
2
2
3
DEY
DEC
Status Flags
Addressing
Mode
Zero Page
Zero Page, X
Absolute
Abso lute, X
DEX
Implied
DEY
Implied
Opcode
Size
In Bytes
C6
06
CE
DE
2
2
3
3
DECArg
DEC Arg, X
DEC Arg
DEC Arg, X
Mnemonics
Opcode
Size
In Bytes
CA
DEX
Status Flags
Addressing
Mode
Mnemonics
Status Flags
Addressing
Mode
Mnemonics
DEY
Opcode
Size
In Bytes
88
155
EOR
EOR
Status Flags
Addressing
Mode
Mnemonics
Immediate
Zero Page
Zero Page, X
Absolute
Absolute, X
Absolu te, Y
(Indirect, X)
(Indirect), Y
EOR # Arg
EOR Arg
EORArg, X
EORArg
EORArg, X
EOR Arg, Y
EOR (Arg, X)
EOR (Arg) , Y
INC
Zero Page
Zero Page, X
Absolute
Absolu te, X
INX
Implied
156
Mnemonics
Opcode
Size
In Bytes
49
45
55
40
50
59
41
51
2
2
2
3
3
3
2
2
Opcode
Size
In Bytes
E6
F6
EE
FE
2
2
INC Arg
INC Arg, X
INC Arg
IN C Arg, X
3
3
Status Flags
Addressing
Mode
Status Flags
Addressing
Mode
Mnemonics
INX
Opcode
Size
In Bytes
E8
JSR
INY
Status Flags
Addressing
Mode
Implied
Mnemonics
Opcode
Size
In Bytes
C8
INY
JMP
Jump
Status Flags
Addressing
Mode
Absolute
Indirect
JSR
Mnemonics
Opcode
Size
In Bytes
4C
6C
3
3
JMP Arg
JMP (Arg)
Status Flags
Addressing
Mode
Absolute
Mnemonics
]SR Arg
Opcode
Size
In Bytes
20
157
LOA
LDA
Status Flags
Addressing
Mode
Mnemonics
Immediate
Zero Page
Zero Page, X
Absolute
Absolute, X
Absolute, Y
(Indirect, X)
(Indirect), Y
LDA # Arg
LDAArg
LDAArg, X
LDAArg
LDAArg, X
LDAArg, Y
LDA (Arg, X)
LDA (Arg), Y
LDX
Load X Register
Status Flags
Addressing
Mode
Immediate
Zero Page
Zero Page, Y
Absolute
Absolute, Y
158
Mnemonics
LDX # Arg
LDX Arg
LDX Arg, Y
LDXArg
LDXArg, Y
Opcode
Size
In Bytes
A9
A5
B5
AD
BD
B9
Al
Bl
2
2
2
3
3
3
2
Opcode
Size
In Bytes
A2
A6
B6
AE
BE
2
2
2
3
3
NOP
LDY
Load Y Register
Status Flags
Addressing
Mode
Im mediate
Zero Page
Zero Page, X
Absolute
Absolute, X
LSR
Mnemonics
Opcode
Size
In Bytes
AO
A4
B4
AC
BC
2
2
2
3
3
LDY # Arg
LDY Arg
LDY Arg, X
LDY Arg
LDY Arg, X
Status Flags
Addressing
Mode
Accumulator
Zero Page
Zero Page, X
Absolute
Absolute, X
Mnemonics
No Operation
Status Flags
Implied
Mnemonics
NOP
Opcode
Size
In Bytes
4A
46
56
4E
5E
1
2
2
3
3
LSRA
LSRArg
LSRArg, X
LSR Arg
LSR Arg, X
NOP
Addressing
Mode
Opcode
Size
In Bytes
EA
159
ORA
ORA
Status Flags
Addressing
Mode
Mnemonics
Immediate
Zero Page
Zero Page, X
Absolute
Absolute, X
Absolute, Y
(Indirect, X)
(Indirect), Y
ORA #Arg
ORAArg
ORA Arg,X
ORAArg
ORA Arg, X
ORA Arg, Y
O RA (Arg, X)
ORA (Arg), Y
PHA
Implied
PHP
Implied
160
Opcode
Size
In Bytes
09
05
15
2
2
2
OD
ID
3
3
3
19
01
2
2
11
Mnemonics
Opcode
Size
In Bytes
48
PHA
Status Flags
Addressing
Mode
Status Flags
Addressing
Mode
Mnemonics
PHP
Opcode
Size
In Bytes
08
ROL
PLA
Status Flags
Addressing
Mode
Mnemonics
PLP
Opcode
Size
In Bytes
68
PLA
Implied
Status Flags
Addressing
Mode
Z
C
From Stack
Mnemonics
Opcode
Size
In Bytes
28
PLP
Implied
ROL
Status Flags
Addressing
Mode
Accumulator
Zero Page
Zero Page, X
Absolu te
Absolute, X
Mnemonics
ROLA
ROLArg
ROLArg, X
ROLArg
ROLArg, X
Opcode
Size
In Bytes
2A
26
36
2E
3E
1
2
2
3
3
161
ROR
ROR
Status Flags
Addressing
Mode
Accumulator
Zero Page
Zero Page, X
Absolute
Absolute, X
RTI
Implied
RTS
Implied
162
Opcode
Size
In Bytes
6A
66
76
6E
1
2
2
RORA
RORArg
RORArg, X
RORArg
RORArg, X
3
3
7E
Z
C
From Stack
Mnemonics
Opcode
Size
In Bytes
40
RTI
Status Flags
Addressing
Mode
Mnemonics
Status Flags
Addressing
Mode
Mnemonics
RTS
Opcode
Size
In Bytes
60
SED
SBC
Status Flags
Addressing
Mode
Immediate
Zero Page
Zero Page, X
Absolute
Absolute, X
Absolute, Y
(Indirect, X)
(Indirect), Y
Mnemonics
Status Flags
Opcode
Size
In Bytes
E9
E5
F5
ED
FD
F9
El
Fl
2
2
2
3
3
3
2
2
SBC # Arg
SBCArg
SBCArg, X
SBCArg
SBCArg, X
SBC Arg, Y
SBC (Arg, X)
SBC (Arg), Y
SEC
Addressing
Mode
Implied
SED
Mnemonics
Implied
Size
In Bytes
38
SEC
Status Flags
Addressing
Mode
Opcode
Mnemonics
SED
Opcode
Size
In Bytes
F8
163
SEI
- -
SEI
Status Flags
Addressing
Mode
Implied
STA
Status Flags
Addressing
Mode
Zero Page
Zero Page, X
Absolute
Absolute, X
Absolute, Y
(Indirect, X)
(Indirect), Y
STX
Status Flags
Addressing
Mode
Zero Page
Zero Page, Y
Absolute
164
Mnemonics
Opcode
Size
In Bytes
78
SEI
Mnemonics
Opcode
Size
In Bytes
85
95
80
90
99
81
91
2
2
STAArg
STA Arg, X
STA Arg
STA Arg, X
STAArg, Y
STA (Arg, X)
STA (Arg), Y
3
3
3
2
2
Mnemonics
STXArg
STXArg, Y
STXArg
Opcode
Size
In Bytes
86
96
8E
2
2
TSX
STY
Status Flags
Addressing
Mode
Zero Page
Zero Page, X
Absolute
TAX
Implied
TAY
Implied
TSX
Implied
Opcode
Size
In Bytes
84
94
8e
2
2
3
Mnemonics
Opcode
Size
In Bytes
AA
TAX
Mnemonics
Opcode
Size
In Bytes
A8
TAY
Status Flags
Addressing
Mode
STY Arg
STY Arg, X
STY Arg
Status Flags
Addressing
Mode
Mnemonics
Status Flags
Addressing
Mode
Mnemonics
TSX
Opcode
Size
In Bytes
BA
165
TXA
TXA
Status Flags
Addressing
Mode
Implied
TXS
Implied
ITA
Implied
166
Opcode
Size
In Bytes
8A
TXA
Mnemonics
Opcode
Size
In Bytes
9A
TXS
Status Flags
Addressing
Mode
Mnemonics
Status Flags
Addressing
Mode
Mnemonics
TYA
Opcode
Size
In Bytes
98
Appendix B
Th ese mnps, prilllnrili; th e wo rk of filii BllItelfield, all origillally appeared in COMPUTE!
Magazille. (See the copi/ righl page for refcre llces. !
ORIG
C357
C359
C38B
C3AC
C430
C433
C480
C522
C553
C56A
C59A
C6B5
C863
C9CE
C9D2
CA27
CA20
CA49
CEll
CE13
CE1C
0079
DOA7
0278
0679
0680
06C4
073C
D8FO
09B4
OA74
DB1B
OC9F
DCA9
UPGR
C355
C357
C389
C3AB
C439
C442
C495
C52C
C55D
C572
C5A7
C6C4
C873
C90E
C9E2
CAlC
CA22
CA45
COF8
COFA
CE03
0069
D09A
0260
067B
068F
06C6
0773
0934
09EE
OAAE
OB55
OC09
DCE3
DESCRIPTION
?OUT OF MEMORY
Send BASIC error message
Warm start, BASIC
Crunch & insert line
Fix chaining & READY
Fix chaining
Crunch tokens
Find line in BASIC
Do NEW
DoCLR
Reset BASIC to start
Continue BASIC execution
Get fixed-point number from BASIC
Send Return, LF if in screen mode
Send Return, Linefeed
Print string
Print precomputed string
Print character
Check for comma
Check for specific character
' SYNTAX ERROR'
Bump Variable Address by 2
Float to Fixed conversion
Fi xed to Float conversion
Get byte to X reg
Evaluate Strin g
Ge t two parameters
Add (from memory)
Multiply by memory location
Multiply by ten
Unpack memory variable to Accum #1
Completion of Fixed to Float co nversion
Print fixed-point value
Print floating-point value
167
Appendix B
DCAF
E3EA
na
na
na
FOB6
FOB A
FI2C
E7DE
FI67
FI7A
FI7E
FI87
F2C8
F2CD
F32A
F33F
na
F3DB
F3E5
F3FF
F411
F43F
F462
F495
F504
F52A
F52D
F579
F57B
F5AE
F64D
F667
F67D
F6E6
F78B
F7DC
F83B
F87F
F88A
F8B9
F8CI
F913
FBDC
FDlB
168
DCE9
E3D8
E775
E7A7
E7B6
FOB6
FOBA
FI28
FI56
FI6F
FI7F
FI83
F18C
F2A9
F2AE
F301
F315
F322
F3E6
F3EF
F40A
F4ID
F447
F466
F494
F4FD
F52I
F524
F56E
F570
F5A6
F63C
F656
F66C
F6FO
F770
F7BC
F8I2
F855
F85E
F886
F883
F8E6
FB76
FC9B
Appendix B
FFC6
FFC9
FFCC
FFCF
FFD2
FFE4
FFC6
FFC9
FFCC
FFCF
FFD2
FFE4
0000-0002
0003
0004
0005
0006
0007
0008
0009
0-2
3
4
5
6
7
8
9
OOOA
OOOB
OOOC
0000
OOOE
0011-0012
0013
0014-0015
0016-001E
001F-0020
0021-0022
0023-0027
0028-0029
002A-002B
002C-002D
002E-002F
0030-0031
0032-0033
0034-0035
0036-0037
0038-0039
003A -003B
003C-003D
003E-003F
0040-0041
10
11
12
13
14
17-18
19
20-21
22-30
31-32
33-34
35-39
40-41
42-43
44-45
46-47
48-49
50-51
52-53
54-55
56-57
58-59
60-61
62-63
64-65
Appendix B
0042-0043
0044-0045
0046-0047
0048
004A
004B-004C
004D-0050
0051-0053
0054-0058
0059-005D
005E-0063
0064
0065
0066-006B
006C
006D
006E-006F
0070-0087
0088-008C
008D-008F
0090-0091
0092-0093
0094-0095
0096
0097
0098
0099-009A
009B
009C
009D
009E
009F
OOAO
00A1
00A3-00A4
OOA5
00A6
00A7
00A8
00A9
OOAA
OOAB
OOAC
OOAD
OOAE
170
66-67
68-69
70-71
72
74
75-76
77-80
81-83
84-88
89-93
94-99
100
101
102-107
108
109
110-111
112-135
136-140
141-143
144-145
146-147
148-149
150
151
152
153-154
155
156
157
158
159
160
161
163-164
165
166
167
168
169
170
171
172
173
174
Appendix B
OOAF
175
OOEO
176
00E1
177
00E2
178
00E4
180
00E5
181
00E7
183
00E9
185
OOEA
186
OOEE
187
OOSC
188
OOED
189
OOEE
190
OOSF
191
OOCO
192
00C1
193
00C2
194
00C3
195
00C4-00C5 196-197
00C6
198
00C7-00C8 199- 200
00C9-00CA 201-202
OOCE-OOCC 203-204
OOCD
205
OOCE
206
OOCF
207
OODO
208
00D1
209
00D2
210
00D3
211
00D4
212
OOD5
213
00D6-00D7 214-215
00D8
216
00D9
217
OODA-OODE 218-219
OODC
220
OODD
221
OODE
222
OODF
223
00EO-00F8 224-248
00F9
249
OOFA
250
OOFE-OOFC 251-252
0l00-010A 256-266
171
Appendix B
0100-013E
0100-01FF
0200-0250
0251-025A
025B-0264
0265-026E
026F-0278
027 A-0339
033A-03F9
03FA-03FB
0400-7FFF
8000-8FFF
9000-BFFF
COOO-EOF8
EOF9-E7FF
E810-E813
E820-E823
E840-E84F
FOOO-FFFF
256-318
256-511
512-592
593-602
603-612
613-622
623-632
634-825
826-1017
1018-1019
1024-32767
32768-36863
36864-49151
49152-57592
57593-59391
59408-59411
59424-59427
59456-59471
61440-65535
Decimal
0-2
3
4
5
6
7
8
9
10
11
12
13-15
16
17-1 8
19- 21
22-30
3 1- 34
35-39
40-41
42-43
44-45
46-47
48- 1-19
50-51
52-53
54-55
56-57
58-59
Description
USR jump
Searc h cha r acte r
Scan -betw een-quotes fl ag
Input buffer pointer; # of subscripts
Defa ult DIM flag
Type: FF=string, OO=numeric
Type: 80 =i ntege r, OO=floating point
Flag: DATA scan ; LIS T quote; memory
Subscript flag; FNX flag
O=IN PUT; $40 =GE T; $98 =READ
ATN sign/Comparison Evaluation flag
Disk status DS$ desc riptor
Curr ent 1/0 device for prompt-suppress
Integer value (for SYS, GOTO etc)
Pointers fo r descriptor s tac k
Desc ript or s tack(temp str ings )
Utility painter area
Product area for mul tip licati o n
Pointer: Star t- of-Basic
Pointer: S ta rt -of-Va ri ab les
Poin ter: Star t- of -Arr ays
Pointer: End-of-Arrays
Pointer: Stri ng-storage( moving down)
Utility string pOinte r
Pointer: Limit - of - memo r y
Cur rent Basic line number
Pr ev ious Basic line number
Pointer: Basic s tatement for CONT
Appendix B
003C-003D
003E-003F
0040-0041
0042-0043
0044-0045
0046 - 0047
00 4 8- 0049
004A
004B - 0050
005 1- 0053
005 4-005D
005E
005F - 0062
0063
0064
0065
0066-006B
006C
006D
006E -0 06F
0070-0087
0077 - 0078
0088-008C
008D-00 8F
0090-0091
0092-0093
0094-0095
0096
0097
0098
0099-009A
009B
009C
009D
009E
009F
OOAO
OOAl
00A3-00A4
00A5
00A6
00A7
00A8
00A9
OOAA
OOAB
OOAC
OOAD
OOAE
OOAF
OOBO
OOB l
00B2
00B3
00B4
00B5
00B7
00B9
60-61
62-63
64-65
66-67
68 - 69
70 - 7 1
72-73
74
75-80
8 1- 83
84-93
94
95-98
99
100
101
102-1 07
108
106
110-111
112- 135
119- 120
136 - 140
141-143
144- 145
146-147
148-149
150
151
152
15 3 -154
155
156
157
158
159
160
161
163-164
165
166
167
168
169
17 0
171
17 2
173
174
175
176
177
17 8
179
180
181
183
185
Appendix B
OOBA
OOBB-OOBC
OOBD
OOBE
OOBF
oOCO-OOC l
00C2
00C3
00C4-00C5
00C6
00C7-00C8
00C9 - 00CA
OOCB-OOCC
OOCD
OOC E
OOCF
OODO
OODl
00D2
00D3
00D4
00D5
00 D6-00D 7
00D8
00D9
OODA-OODB
OODC
OODD
OODE
OOD F
00EO-00F8
OOEO-OOEl
00E2
00E3
00E4
00E5
00E6
00E7
00E8
00E9-00EA
OOEB-OOEC
00F9-00FA
OOFB-OOFC
OOFD-OOFE
0 100-0 10A
0 100-0 13E
0 100 -01FF
0200 - 0250
025 1- 025A
025B-0 264
0265-026E
026F-0278
027A-0 339
033A-03F9
033A
033B
033C
033D
174
186
187- 188
189
190
19 1
192 -1 93
194
195
196- 197
198
199-200
20 1-2 02
203 - 204
205
206
207
208
209
2 10
2 11
212
2 13
214-215
2 16
2 17
2 18-219
220
221
222
223
224-248
224 - 225
226
227
228
229
230
23 1
232
233-234
235-236
249-250
25 1-252
253-254
256 - 266
256-3 18
256-5 11
5 12-592
593 -6 02
603-612
6 13-622
623-632
634-825
826-1017
826
827
828
829
Appendix B
033E
033F-0340
0341
0342-0352
0353-0380
03EE-03F7
03FA-03FB
03FC
0400-7FFF
8000-83FF
8000-87H
9000-AFH
BOOO-DFH
EOOO-E7H
E810-E813
E820-E823
E840-E84F
E880-E881
FOOO-FFFF
830
831-832
833
834-850
851-896
1006-1015
10 18-1 019
1020
1024-32767
32768-33791
32768 -34 815
36864-115055
45056-57343
57344-59391
59408-59411
59424-59427
59456-59471
59520-59521
6 1440-65 535
BOOO-B065
B066-B093
B094-BOB1
BOB2-B20C
B20D-B321
B322-B34F
B350-B392
B393-B39F
B3AO-B3CC
B3CD
B3FF-B41E
B41F-B4B5
B4B6-B4E1
B4E2-B4FA
B4FB-B5A2
B5A3-B5D1
B5D2
B5EC-B621
B622-B62F
B630-B6DD
B6DE-B784
B785-B7B6
B7B7 -B7C5
B7C6-B7ED
B7EE-B807
B808-B812
B813-B82F
B830-B85C
B85D
Description
Action addresses for primary keywords
Action addresses for functions
Hierarchy and action addresses for operators
Table of Basic keywords
Basic messages, mostly error messages
Search the stack for FOR or GOSUB activity
Open up space in memory
Test: stack too d eep?
Check available memory
Send canned error message, then:
Warm start; wait for Basic command
Handle new Basi c line input
Rebuild chaining of Basic lines
Receive line from keyboard
Crunch keywords into Basic tokens
Search Basic for given line number
Perform NEW, and;
Perform CLR
Reset Basic execution to start
Perform LI ST
Perform FOR
Execute Basic statement
Perform RESTORE
Perform STOP or END
Perform CONT
Perform RU N
Perform GOSUB
Perform GOTO
Perform RETURN, then:
175
Appendix B
BBB3-BB90
BB91
BB94-BBB2
BBB3
BBc6-BBD5
BBD6-BBF5
BBF6-B92F
B930-BAB7
BABB-BABD
BABE-BAA 1
BAA2-BB1C
BB 1D-BB39
BB3A-BB4B
BB4C-BB79
BB7 A-BBA3
BBA4-BBBD
BBBE-BBF4
BBF5-BC01
BC0 2-BC F6
BCn -BD1B
BD19-BD71
BD72-BD97
BD9B
BEE9
BEEF
BFOO-BFOB
BFBC-C046
C047-COB5
COB6-COB5
COB6 -C 11 D
C11 E-C12A
C12B-C1BF
C1CO-C2C7
C2CB-C2DB
C2D9-C2DC
C2DD-C2FB
C2FC-C4A7
C4AB
C4BC-C4CB
C4C9-C4CE
C4CF-C4DB
C4DC-C509
C50A-C51 C
C51D-C5BD
C5BE-C59D
C59E-C5AF
C5BO-C61C
C6 1D- C669
C66A-C74E
C74F-C7BB
C78C-C7B4
C7B5-C8 10
176
Appendix B
CB11-CB21
CB22-CB35
CB36-CB61
CB62-CB6C
CB6D-CB96
CB97-CBBl
CBB2-CBB7
CB BB-CBCO
CBC1-C8DO
CBD1-CBE2
CBE3-C920
C921-C92C
C92D -C942
C943-C959
C95A-C962
C963-C97E
C97F-C9B5
C9B6
C99B-CA7C
CA7D-CAB3
CAB4-CABB
CAB9-CAFl
CAF2-CB 1F
CB20
CB5E-CBC l
CBC2-CBEC
CBED-CC09
cCOA-CC17
CC1B-CC2E
CC2F-CC33
CC34
CC3D
CC45-CCD7
CCDB-CCFC
CCFD-CD31
CD32-CD41
CD42-CD50
CD51-CD60
CD6 1- CD6E
CD6F-CDBD
CD8E -CD 90
CD91-CDDO
CDD1-CE01
CE02-CE2B
CE29-CEB3
CEB 4-CEE B
CEE9-CEF8
177
Appendix B
D112
Perform power function
D14B-D155 Perform negation
D156-D183 Constants
D184-D1D6 Perform EXP
D1D7-D220 Series evaluation
D221-D228 RND constants
D229-D281 Perform RND
D282
Perform COS
D289-D2D1 Perform SIN
D2D2-D2FD Perform TAN
D2FE-D32B Constants
D32C-D35B Perform ATN
D35C-D398 Constants
D399-D3B5 CHRGET sub for zero page
D3B6-D471 Basic cold start
D472-D716 Machine Language Monitor
D717-D7AB MLM subroutines
D7AC-D802 Perform RECORD
D803-D837 Disk parameter checks
D838-D872 Dummy disk control messages
D873-D919 Perform CATALOG or DIRECTORY
D91A-D92E Output
D92F-D941 Find spare secondary address
D942-D976 Perform DOPEN
D977-D990 Perform APPEND
D991-D9D1 Get disk status
D9D2-DA06 Perform HEADER
DA07-DA30 Perform DCLOSE
DA31-DA64 Set up disk record
DA65-DA7D Perform COLLECT
DA7E-DAA6 Perform BACKUP
DAA7-DAC6 Perform COPY
DAC7-DAD3 Perform CON CAT
DAD4-DBOC Insert command string values
DBOD-DB39 Perform DSAVE
DB3A-DB65 Perform DLOAD
DB66-DB98 Perform SCRATCH
DB99-DB9D Check Direct command
DB9E-DBD6 Query ARE YOU SURE?
DBD7-DBEO Print BAD DISK
DBE1-DBF9 Clear DS$ and ST
DBFA-DC67 Assemble disk command string
DC68-DE29 Parse Basic DOS command
DE2C-DE48 Get Device number
DE49-DE86 Get file name
DE87-DE9C Get small variable parameter
** Entry points only for EOOO-E7FF **
EOOO
Register/screen initialization
EOA7
Input from keyboard
E116
Input from screen
E202
Output character
E442
Main Interrupt entry
178
Appendix B
E455
E600
**
FOOO-FODl
FOD2
FOD5
FOD7
Fl09-F142
F143-F150
F151-F16B
F16C-F16F
F170-F184
F1 85-F192
F193-F19D
F19E-F1AD
F1AE-F1BF
F1CO-F204
F205-F214
F215-F265
F266-F2Al
F2A2
F2A6-F2CO
F2Cl-F2DC
F2DD-F334
F335-F342
F343-F348
F349-F350
F351-F355
F356-F400
F401-F448
F449-F46c
F46D-F47C
F47D-F4A4
F4A5-F4D2
F4D3-F4F5
F4F6-F50C
F50D-F55F
F560-F5E4
F5E5-F618
F619-F67A
F67B-F694
F695-F6AA
F6AB-F6C2
F6C3-F6CB
F6CC-F6DC
F6DD-F767
F768-F7 AE
F7AF-F7FD
F7FE-F84A
F84B-F856
F857-F879
**
File messages
Send 'Talk'
Send 'Li sten'
Send IEEE command character
Send byte to IEEE
Send byte and clear ATN
Option: timeout or wait
DEVICE NOT PRESENT
Timeout on read, clear control lines
Send canned file message
Send byte, clear contro l lines
Send normal (deferred) IEEE char
Drop IEEE device
Input byte from IEEE
GET a byte
INPUT a byte
Output a byte
Abor t fil es
Restore default I /O devices
Find /se tup file data
Perform CLOSE
Test STOP key
Acti on STOP key
Send message if Direct mode
Test if Direct mode
Program load subroutine
Perform LOAD
Print SEARCHING
Print LOADING or VERIFYING
Get Load/Save parameters
Send name to IEEE
Find specific tape header
Perform VERIFY
Get Open/Close parameters
Perform OPEN
Find any tape header
Write tape header
Get start/end addrs from header
Se t buffer address
Set buffer start & end addrs
Perform SYS
Set tape write start & end
Perform SAVE
Update cl ock
Connect inpu t device
Connect output device
Bump tape buffer pointer
Wai t for PLAY
179
Appendix B
180
......
00
......
Hex
0000-0002
0003-0004
0005-0006
0007
0008
0009
OOOA
OOOB
OOOC
OOOD
OOOE
OOOF
0010
0011
0012
0013
0014-0015
0016
0017-001t5
0019-0021
0022-0025
0026-002A
002B-002C
14
15
16
17
18
19
20-21
22
23-24
25-33
34-37
38-42
43-44
13
12
11
Decimal
0-2
3-4
5-6
7
8
9
10
Description
USR jump
Float-Fixed vector
Fixed-Float vector
Search character
Scan-quotes flag
TAB column save
O=LOAD, 1=VERIFY
Input buffer pointer/# subscrpt
Default DIM flag
Type: FF=string, OO=numeric
Type: 80=integer, OO=floating point
DATA scan/LIST quote/memry flag
Subscript/FNx flag
0=INPUT;$40=GET;$98=READ
ATN sign/Comparison eval flag
Current I/O prompt flag
Integer value
Pointer: temporary strg stack
Last temp string vector
Stack for temporary strings
Utility pOinter area
Product area for multiplication
Pointer: Start-of-Basic
OJ
x'
c..
l>
"tJ
"tJ
tD
::::J
00
......
002D-002E
002F-0030
0031-0032
0033-0034
0035-0036
0037-0038
0039-003A
003B-003C
003D-003E
003F-0040
0041-0042
0043-0044
0045-0046
0047-0048
0049-004A
004 B- 004 C
004D
004E-0053
0054-0056
0057 -0060
0061
0062-0065
0066
0067
0068
0069-006E
45-46
47 -48
49-50
51-52
53-54
55-56
57 -51)
59-60
61-62
63-64
65-66
67-61)
69-70
71-72
73-74
75-76
77
78-83
84-86
87 -96
97
98-101
102
103
104
105-110
Pointer: Start-of-Variables
Pointer: Start-of-Arrays
Pointer: End-of-Arrays
Pointer: String-storage(moving down)
Utility string pOinter
Pointer: Limit-of-memory
Current Basic line number
Previous Basic line number
Pointer: Basic statement for CONT
Current DATA line number
Current DATA address
Input vector
Current variable name
Current variable address
Variable pointer for FOR/NEXT
Y-save; op-save; Basic pOinter save
Comparison symbol accumulator
Misc work area, pOinters, etc
Jump vector for functions
Misc numeric work area
Accum#1: Exponent
Accum#1: Mantissa
Accum#1: Sign
Series evaluation constant pointer
Accum#1 hi-order (overflow)
Accum#2: Exponent, etc.
I:P
x'
:::I
0-
"'C
"'C
.....
00
006F
0070
0071-0072
0073-00SA
007 A-007 B
OOSB-OOSF
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
009A
009B
009C
009D
009E
009F
00AO-00A2
00A3
00A4
00A5
111
165
112
113-114
115-13S
122-123
139-143
144
145
146
147
14 S
149
150
151
152
153
154
155
156
157
15 S
159
160-162
163
164
OJ
>C'
c..
:::l
~
"'C
"'C
00A6
00A7
00A8
00A9
OOAA
OOAB
OOAC-OOAD
OOAE-OOAF
00BO-00B1
00B2-00B3
00B4
00B5
00B6
00B7
00B8
00B9
OOBA
OOBB-OOBC
OOBD
OOBE
OOBF
OOCO
00C1-0uC2
00C3-00C4
00C5
00C6
189
190
191
192
193-194
195-196
197
198
1~7-188
166
167
168
169
170
171
172 - 173
174-175
176-177
178-179
180
181
182
183
184
185
186
;:0
c..
'tJ
tD
....
00
(Jl
00C7
00C8
00C9-00CA
OOCB
OOCC
OOCD
OOCE
OOCF
OODO
00D1-00D2
00D3
00D4
00D5
00D6
00D7
00D8
00D9-00FO
00F1
00F2
00F3-00F4
00F5-00F6
00F7 -00F8
00F9-00FA
00FF-010A
199
200
201-202
203
204
205
206
207
208
209-210
211
212
213
214
215
216
217-240
241
242
243-244
245-246
247-248
249-250
255-266
)C'
Co
::::I
(I)
~
"'C
"'C
>-'
0'-
00
cOOO
cOOc
c052
c080
c0ge
c1ge
c328
c365
c38a
c3b8
c3fb
c408
c435
c437
c469
c474
c480
DJ
)("
::I
Q.
tD
l>
~
~
'.J
>-'
00
c883
c8aO
c8d2
c8f8
c906
c928
c93b
c94b
c96b
c9a5
ca80
ca86
caaO
cble
cb3b
cb4d
cb7b
cba5
cbbf
cbf9
cc06
ccfc
cdle
cd78
cdge
cea8
Perform [GOSUB]
Perform [GOTO]
Perform [RETURN]
Perform [DATA]
Scan for next statement
Perform [IF]
Perform [REM]
Perform [ON]
Get fixed point number
Perf orm [LET]
Perform [PRINT#]
Perform [CMD]
Perform [PRINT]
Print message frQm (y, a)
Print format character
Bad-input routines
Perf orm [GET]
Perform [INPUT# ]
Perform [INPUT]
Prompt & input
Perform [READ]
Input error messages
Perform [NEXT]
Type-match check
Evaluate expression
Constant - PI
cefl
cef7
ceff
cf08
cf14
cf28
cfa7
cfe6
cfe9
dOl6
d081
d08b
dl13
dlld
dl94
dla5
dlb2
dldl
d245
d248
d34c
d37d
d391
d3ge
d3a6
d3b3
OJ
)C"
c..
~
~
"C
"C
...
00
00
d3el
d3f4
d465
d475
d487
d4f4
d526
d5bd
d606
d63d
d67a
d6a3
d6db
d6ec
d700
d72c
d737
d76l
d77c
d782
d78b
d79b
d7ad
d7eb
d7f7
d80d
Check FN syntax
Perform [FN]
Perform [STR$]
Calculate string vector
Set up string
Make room for string
Garbage collection
Check salvageability
Collect string
Concatenate
Build string to memory
Discard unwanted string
Clean descriptor stack
Perform [CHR$]
Perf orm [LEFT$]
Perform [RIGHT$]
Perform [MID$]
Pull string parameters
Perform [LEN]
Exit string-mode
Perform [ASC]
Input byte parameter
Perform [VAL]
Get params for poke/wait
Float-fixed
Perform [PEEK]
d824
d82d
d849
d850
d853
d86a
d947
d97e
d983
dgea
da2b
da59
da8c
dab7
dad4
dae2
daf9
dafe
db12
dba2
dbc7
dbfc
dcOc
dclb
dc2b
dc39
Perform [POKE]
Perform [WAIT]
Add 0.5
Subtract-from
Perform [SUBTRACT]
Perf orm [ADD]
Complement fac#l
'OVERFLOW'
Multiply by zero byte
Perform [LOG]
Perform [MULTIPLY]
Multiply-a-bit
Memory to FAC#2
Adjust FAC#1/#2
Underflow/overflow
Multiply by 10
+10 in floating pt
Divide by 10
Perform [DIVIDE]
Memory to fac #1
FAC#l to memory
FAC#2 to fac#l
FAC#l to FAC#2
Round FAC#l
Get sign
Perform [SGN]
0:1
)C'
c..
;:,
~
~
~
-.0
>-'
00
dc58
dc5b
dc9b
dccc
dcf3
dd7e
dddd
df16
df3a
df71
df7b
dfb4
dfed
e040
e056
e094
eOf6
e127
e153
e162
e165
elbb
elc4
eldl
e203
e20b
Perform [ABS]
Compare FAC#l to mem
Float-fixed
Perform [INT]
String to fac
Get ascii digit
Float to ascii
Decimal constants
TI co nstan ts
Perf orm [SQR]
Perform [POWER]
Perform [NEGATIVE]
Perform [EXP]
Series evaluate 1
Series evaluate 2
Perform [RND]
?? Breakpoints ??
Perform [SYS]
Perform [SAVE]
Perform [VERIFY]
Perform [LOAD]
Perform [OPEN]
Perform [CLOSE]
Parameters for load/save
Check default parameters
Check for comma
e216
e261
e268
e2bl
e30b
e378
e387
e3a4
e429
e44f
e45b
e467
e476
e4aO
e4a9
e4b2
e4bc
e500
e505
e50a
e518
e54c
e55f
e581
e587
e5bb
Parameters for open/close
Perf orm [COS]
Perform [SIN]
Perform [TAN]
Perf orm [ATN]
Initialize
CHRGET for zero page
Initialize Basic
Power-up message
Vectors for $300
Initialize vectors
Warm restart
Program patch area
Serial output '1'
Serial output '0'
Get serial input & clock
Program patch area
Set 6522 addrs
Set screen limits
Track cursor location
Initalize I/O
Normalize screen
Clear screen
Horne cursor
Set screen pointers
Set I/o defaults
OJ
XO
c..
::l
~
"0
"0
ID
cg
.....
e5c3
e5cf
e64f
e6b8
e6c5
e6ea
e7l5
e72d
e742
e8c3
e8d8
e8e8
e8fa
e9l2
e92l
e929
e975
egee
ea56
ea6e
ea7e
ea8d
eaal
eaaa
eab2
eabf
eble
ecOO
ec46
ec5e
ed2l
ed30
ed5b
ed6a
eda3
ede4
edfd
eel4
eel7
eelc
ee49
eeb7
eecO
eec5
eece
eee4
eef6
ef04
efl9
ef84
ef8d
ef96
Check keyboard
Set text mode
Keyboard vectors
Keyboard maps
Graphics/text control
Set graphics mode
Wrap up screen line
Shifted key matrix
Control key matrix
Vic chip defaults
Screen line adds low
Send 'talk'
Send 'listen '
Send control char
Send to serial bus
Timeout on serial
Send listen SA
Clear ATN
Send talk SA
Send serial deferred
Send 'untalk'
Send 'unlisten '
Receive from serial bus
Clock line on
Clock line off
Delay 1 ms
D:J
;("
~
"0
"0
ID
::l
0-
.....
.....
'"
efa3
efee
f016
f027
f036
f05b
f09d
fOa2
fOa5
fOa8
fOb9
fObc
fOed
fl16
fl4f
fl60
fl74
fle2
flf5
f205
f20e
f250
f27a
f290
f2c7
f309
f34a
f3cf
f3df
f3ef
f3f3
f40a
f495
f4c7
f542
f647
f659
f66a
f675
f728
f734
f760
f767
f770
f77e
f7af
f7e7
f84d
f854
Close
Find file
Set file values
Abort all files
Restore default I/O
Do file opening
Send SA
Open RS232
Load program
'SEARCHING'
Print file name
'LOADING/VERIFYING'
Save program
'SAVING'
Bump clock
Get time
Set time
Action stop key
File Error Messages
Find any tape header
Write tape header
Get buffer address
Set buffer start,
end pointers
Find specific header
Bump tape pointer
D:!
::s
c..
)C
"'C
"'C
>-'
-D
N
f894
f8ab
f8b7
f8cO
f8e3
f8f4
f94b
f95d
f98e
faad
fbd2
fbdb
fbea
fc06
fcOb
fc95
fccf
fcf6
fd08
fdll
fdlb
fd22
fd3f
fd52
PRESS PLAY I
Check cassette status
I PRESS RECORD
fd8d
fdfl
fdf9
fe49
fe50
fe57
fe66
fe6f
fe73
fe82
fe91
fea9
fed2
fede
ff56
ff5c
ff72
ff8a
fffa
)C.
C.
::l
/I)
"C
"C
Appendix B
SID
V1
V2
(6581)
Commodore 64
V3
VI
V2
V3
Frequency
H
Pu lse Width
0402 0409 0410
0403 040A 0411
---------- -
--,
5427454281 54288
54275 54282 54289
I
I
0 0 0 0
Voice Type
NSE PUL SAW TR I
Attack Time
2 ms - 8 sec
I
I
Key
OecayTime
6 ms - 24 sec
Release Time
6 ms - 24 sec
Vo ices
(W rite Only)
I
o 000 0
I
0415 ____________ 1
0416
Fi lter Freq uen cy
041 8
Filter Voices
V3 V2 V1
Reso nance
041 7
V3
Off
Passband
Hi Bd
I EXT
La
Maste r
Vo lum e
54293
54294
54295
54296
193
Appendix B
0419
Paddle X
54297
041A
Paddle Y
54298
041B
Noise 3 (Random)
54299
041C
Envelope 3
54300
Se nse
(Read Only)
Special vo ice fe atures (TEST, RING MOO, SYNC) are omitted from the above diagram.
CIA 2 (NMI)
$0000
$D001
Co mmodore 64
(6526)
I CTS
I
In
Clock
O ut
ATN RS-232
Out
Out I
PRA
56576
PRB
56577
I OCO*
I RI*
I DTR
I RTS*
I RS-232
Ou t
Out
In
In
In
IN
IN
Out
Out
Out
$3F
Timer A
$0006
$0007
Timer B
I RS -;32 I
I
ODRB 56579
I Timer
B I
TAL
TAH
56580
56581
TBL
TBH
56582
56583
ICR
56589
CRA
56590
CRB
56591
Timer
A
Timer
I A Start
$OOOE
$DOOF
I
*Connected but not used by sys tem.
194
DDRA 56578
Out
Out
$0004
$0005
$DOOO
Out
Timer
B Start
Appendix B
$0000
$0001
IN
Out
Tape
Motor
(6510)
IN
Commodore 64
Out
lOut
Tape
Sense
Out
Tape
Write
EF.RAM AB.RAM
Switch
Switch
D-Rom
Switch
I
CIA 1
A
$DCOO
Paddle
(IRQ)
SE~J
B
(6526)
Out
I
0
1
Commodore 64
Joystick 0
L
D
PRA
56320
PRB
56321
DDRA
DDRB
TAL
TAH
56322
56323
56324
56325
TBL
TBH
56326
56327
ICR
56333
Timer
A Start
CRA
56334
Timer
B Start
CRB
56335
----- --
DDR
PR
$DCOl
Joystick 1
--------- ------
Timer A
TimerB
$DCOD
I
I Input
Tape I
$DCOE
$DCOF
I
Timer lnterr.
A
B I
One
Shot
Out
Mode
Time
PB6
Out
One
Shot
Out
Mode
Time
PB7
Out
195
>-'
'"
""
Hex
0000
0001
0003-0004
0005-0006
0007
0008
0009
OOOA
OOOB
OOOC
OOOD
OOOE
OOOF
0010
0011
0012
0013
0014-0015
0016
0017-0018
0019-0021
0022-0025
0026-002A
002B-002C
64 Memory Map
9
10
11
12
13
14
15
16
17
18
19
20-21
22
23-24
25-33
34-37
38-42
43 -44
1
3-4
5-6
7
Decimal
Description
Chip directional register
Chip I/O; memory & tape control
Float-Fixed vector
Fixed-Float vector
Search character
Scan-quotes flag
TAB column save
O=LOAD, l=VERIFY
Input buffer pointer/# subscrpt
Default DIM flag
Type: FF=string, OO=numeric
Type: 80=integer, OO=floating point
DATA scan/LIST quote/memry flag
Subscript/FNx flag
0=INPUT;$40=GET;$98=READ
ATN sign/Comparison eval flag
Current I/O prompt flag
Integer value
Pointer: temporary strg stack
Last temp string vector
Stack for temporary strings
Utility pointer area
Product area for multiplication
Pointer: Start-of-Basic
0'
)C'
C.
:::I
"C
"C
"
-.0
,....
002D-002E
002F-0030
0031-0032
0033-0034
0035-0036
0037-0038
0039-003A
003B-003C
003D-003E
003F-0040
0041-0042
0043-0044
0045-0046
0047-0048
0049-004A
004B-004C
004D
004E-0053
0054-0056
0057-0060
0061
0062-0065
0066
0067
0068
45-46
47-48
49-50
51-52
53-54
55-56
57-58
59-60
61-62
63-64
65-66
67-68
69-70
71-72
73-74
75-76
77
78-83
84-86
87-96
97
98-101
102
103
104
Pointer: Start-of-Variables
Pointer: Start-of-Arrays
Pointer: End-of-Arrays
Pointer: String-storage(moving down)
Utility string pointer
Pointer: Limit-of-memory
Current Basic line number
Previou s Basic line number
Pointer: Basic statement for CaNT
Current DATA line number
Current DATA address
Input vector
Current variable name
Current variable address
Variable pointer for FOR/NEXT
Y-savej op-savej Basic pointer save
Comparison symbol accumulator
Misc work area, pointers, etc
Jump vector for functions
Misc numeric work area
Accum#l: Exponent
Accum#l: Mantissa
Accum#l: Sign
Series evaluation constant pointer
Accum#l hi-order (overflow)
D:I
x"
a-
::l
"tJ
"tJ
.....
-0
(7J
0069-006E
006F
0070
0071-0072
0073-008A
007A-007B
008B-008F
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
009A
009B
009C
009D
009E
009F
00AO-00A2
00A3
112
113-114
115-138
122-123
139-143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160-162
163
III
105-110
OJ
;Co
0..
:l
"'C
"'C
'-0
00A4
00A5
00A6
00A7
00A8
00A9
OOAA
OOAB
OOAC-OOAD
OOAE-OOAF
OOBO-OOBI
00B2-00B3
0084
00B5
00B6
00B7
00B8
00B9
OOBA
OOBB-OOBC
OOBn
OOBE
OOBF
OOCO
00CI-00C2
164
165
166
167
168
169
170
171
172-173
174-175
176-177
178-179
180
181
182
183
184
185
186
187-188
189
190
191
192
193-194
Cycle count
Countdown,tape write/bit count
Tape buffer pointer
Tp Wrt Idr count/Rd pass/inbit
Tp Wrt new byte/Rd error/inbit cnt
Wrt start bit/Rd bit err/stbit
Tp ScaniCnt;Ld;End/byte assy
Wr lead length/Rd checksum/parity
Pointer: tape bufr, scrolling
Tape end adds/End of program
Tape timing constants
Pntr: start of tape buffer
l=Tp timer enabled; bit count
Tp EOT/RS232 next bit to send
Read character error/outbyte buf
# characters in file name
Current logical file
Current secndy address
Current device
Pointer to file name
Wr shift word/Rd input char
# blocks remaining to Wr/Rd
Serial word buffer
Tape motor interlock
I/O start address
0:1
>co
:J
Co
II)
"C
"C
00C3-00C4
00C5
00C6
00C7
00C8
00C9-00CA
OOCB
OOCC
OOCD
OOCE
OOCF
OODO
OODI-00D2
00D3
00D4
ODDS
00D6
00D7
00D8
00D9-00F2
00F3-00F4
00F5-00F6
00F7-00F8
00F9-00FA
00FF-OI0A
195-196
197
198
199
200
201-202
203
204
205
206
207
208
209-210
211
212
213
214
215
216
217-242
243-244
245-246
247-248
249-250
255-266
>co
0:1
Q.
~
"C
"C
ID
:::l
tv
>--'
C>
0100-013E
0100-01FF
0200-0258
0259-0262
0263-026C
026D-0276
0277-0280
0281-0282
0283-0284
0285
0286
0287
0288
0289
028A
028B
028C
028D
028E
028F-0290
0291
0292
0293
0294
256-318
256-511
512-600
601-610
611-620
621-630
631-640
641-642
643-644
645
646
647
648
649
650
651
652
653
654
655-656
657
658
659
660
)CO
c..
:::l
(I)
~
"t:I
"t:I
0295-0296
0297
0298
0299-029A
029B
029C
029D
029E
029F-02AO
02Al
02A2
02A3
02A4
02A5
02CO-02FE
0300-0301
0302-0303
0304-0305
0306-0307
0308-0309
030A-030B
030C
030D
030E
030F
661-662
663
664
665
667
668
669
670
671-672
673
674
675
676
677
704-766
768-769
770-771
772-773
774-775
776-777
778-779
780
781
782
783
Bit timing
RS-232 status
# bits to send
RS-232 speed/code
RS232 receive pointer
RS232 input pointer
RS232 transmit pointer
RS232 output pointer
IRQ save during tape I/O
CIA 2 (NMI) Interrupt Control
CIA 1 Timer A control log
CIA 1 Interrupt Log
CIA 1 Timer A enabled flag
Screen row marker
(Sprite 11)
Error message link
Basic warm start link
Crunch Basic tokens link
Print tokens link
Start new Basic code link
Get arithmetic element link
SYS A-reg save
SYS X-reg save
SYS Y-reg save
SYS status reg save
OJ
)CO
0..
tD
~
~
N
0
UJ
784-785
0310-0312
788-789
0314-0315
790-791
0316-0317
792-793
0318-0319
794-795
031A-031B
796-797
031C-031D
798-799
031E-031F
800-801
0320-0321
802-803
0322-0323
804-805
0324-0325
806-807
0326-0327
808-809
0328-0329
810-811
032A-032B
812-813
032C-032D
814-815
032E-032F
816-817
0330-0331
818-819
0332-0333
828-1019
033C-03FB
832-894
0340-037E
896-958
0380-03BE
960-1022
03CO-03FE
0400-07FF 1024-2047
0800-9FFF 2048-40959
8000-9FFF 32768-40959
(B248)
USR function jump
Hardware interrupt vector (EA31)
(FE66)
Break interrupt vector
(FE47)
NMI interrupt vector
(F34A)
OPEN vector
(F291)
CLOSE vector
(F20E)
set-input vector
(F250)
Set-~utput vector
(F333)
Restore I/O vector
(F157)
INPUT vector
(FICA)
Output vector
(F6ED)
Test-STOP vector
(F13E)
GET vector
(F32F)
Abort I/O vector
(FE66)
Warm start vector
(F4A5)
LOAD link
(F5ED)
SAVE link
Cassette buffer
(Sprite 13)
(Sprite 14)
(Sprite 15)
Screen memory
Basic RAM memory
Alternate: ROM plug-in area
)C'
0:1
Q.
:::I
:J>
"'C
"'C
o:J
x"
c..
::J
"tJ
"tJ
U1
CLEAR ED ON COLD
\~ARMS T
$0008
$0009
BOOTQ
$OOOA
DOSVEC
$OOOC
DOSINI
APP~IHI
$OUOE
0008
0009
nODA
OOOC
OOOE
INTZBS
POKMS K
BRKKEY
RTCLOCK
BIJFADR
ICCOMT
DSKFMS
0010
0010
0011
0012
0015
0017
0018
RAt~LO
TRAMSZ
TSTDAT
START ONLY
;WAR~l START FLAG
;SUCC ESS FUL BOOT FLAG <WAS BOOT?>
;D I SK SOFTWAR E START FLAG
;DISK SO FTWA RE INIT ADDRESS
;APPLICATIONS MEMORY HI LIMIT
$0018
$0017
$0015
THE SE LOCATIONS
$0002
$0004
$0006
$0007
CASINI
0002
0004
0006
0007
$0000
LI NZBS
0000
D:I
)(
c..
::l
""
Ill>
N
0
0--
ZIOC B
IOCBSZ
MAXIOC
IOCBAS
ICHIOZ
ICONOl
ICCOMZ
ICSTAZ
ICBALZ
ICBAHZ
ICPTLZ
ICPTHZ
ICBLLZ
ICBLHZ
I CAX 1Z
ICAX2Z
ICSPRZ
ICIDNO
CIOCHR
STAT US
CHKSUM
BUFR LO
BUFR HI
BFEN LO
0020
0010
0080
0020
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
002A
002B
002C
002E
002F
0030
0031
0032
0033
0034
$OOlC
$0010
$OOlE
$OOlF
PTIMO T
PB PNT
PBUFSZ
PTEMP
OOlC
0010
DOlE
001F
$0030
$003),
$0032
$0033
$0034
$OOlA
OSKUTL
OOlA
0:1
)("
0-
;:,
(l)
l>
"t:I
"t:I
"
IV
0
BPTR
FTYPE
FEOF
FREQ
SOUNDR
CRITIC
0030
003E
003F
0040
0041
0042
;LEOGE
;R EOGE
TMPCHR
HOL01
0050
0051
39
$0050
$0051
$004 0
$004E
$004F
ATRACT
DRKMSK
COLRSH
0040
004E
004F
;ATRACT FLAG
; DARK ATRACT FLAG
;ATRACT COLOR SHIFTER (EOR'D WITH PLAYFIELD COLORS)
$004A
$004B
$004C
CKEY
CASSBT
OS TAT
004A
004B
004C
$0043
FMSZPG
$0030
$003E
$003F
$0040
$0041
$0042
$0035
$0036
$0037
$0038
$0039
$003A
$003B
$003C
0043
BFENHI
CRETRY
DRETRY
BUFRFL
RECVDN
XMTDON
CHKSNT
NOCKSM
0035
0036
0037
0038
0039
003A
003B
003C
)C"
IJ:I
c..
:l
't:I
ID
I
't:I
O:l
0078
007C
0052
0053
0054
0055
0057
0058
005A
0058
005D
DOSE
0060
0061
0063
0064
0066
0068
006A
0068
006C
006E
$0052
$0053
$0054
$0055
$0057
$0058
$005A
$0058
$005D
$005E
$0060
$006 1
$006 3
$0064
$0066
$0 068
$006A
$0068
$006C
$006 E
PAGE 1 -- STACK
NEWCOL
LOGCO L
ADRESS
~1L TTHP
SAVADR
RAtHOP
ElUI:CNT
8UFSTR
8ITMSK
; LOTS OF RANDOH TEHPS
S\<JP FLG
$0078
$007C
HOLDCH
NE\~ROW
LHARGN
RHARGN
ROWCRS
COLCRS
DHJDEX
SAVHSC
OLDIIOW
OLDCOL
OLDCHR
OLDADR
>
)C'
0:1
c..
::l
"C
"C
N
0
-.0
0200
0200
0202
0204
0206
0208
020A
020C
020E
0210
0212
0214
0216
0218
021A
021C
021E
0220
0222
0224
0226
0228
022A
022B
022C
022E
022F
0230
0231
0232
INTABS
VDBLST
VPRCED
VINTER
VBR EAK
VK EYBD
VSERIN
VSEROR
VSEROC
VTIMRl
VTIMR2
VTIMR4
VIMIRQ
CDTMV1
CDTMV2
CDTMV3
CDTMV4
CDTMV5
VVALKI
VVBLKD
CDTMA1
CDTMA2
CDTMF3
SRTIMR
CDTMF4
CDTMF5
SDMCn
SD LSTL
SDLSTH
SSKCTL
$0200
$0200
$0202
$0204
$0206
$0208
$020A
$020C
$020E
$0210
$0212
$0214
$0216
$0218
$021A
$021C
$021E
$0220
$0222
$0224
$0226
$0228
$022A
$0228
$022C
$022 E
$022F
$0230
$0231
$0232
; INTERRUPT RAM
;DISPLAY LIST NMI VECTOR
;PROCEED LINE IRQ VECTOR
;INTERRUPT LINE IRQ VECTOR
;SOFTWARE BREAK (00) INSTRUCTION IRQ VECTOR
;POKEY KEYBOARD IRQ VECTOR
;POKEY SERIAL INPUT READY IRQ
; POKEY SERIAL OUTPUT READY IRQ
;POKEY SERIAL OUTPUT COMPLETE IRQ
;POKEY TIMER
IRQ
;POKEY TIMER 2 IRQ
;POKEY TIMER 4 IRQ
;IMMEDIATE IRQ VEC TOR
;C OUNT DOWN TIMER 1
;COUNT DOWN TIMER 2
;COUNT DOWN TIMER 3
;COUN T DOWN TIMER 4
;COUNT DOWN TIMER 5
;IMMEDIATE VERTICAL BLANK NMI VECTOR
;DEFERREO VERTICA L BLANK NMI VECTOR
;COUNT DOWN TIME R 1 JSR ADDRESS
;COUNT DOWN TIMER 2 JSR ADDRESS
;COUNT DOWN TIMER 3 FLAG
;SOFTWARE REPEAT TIMER
;COUNT DOWN TIMER 4 FLAG
;COUNT DOWN TIMER 5 FLAG
;SAVE DMACTL REGISTER
;SAVE DISPLAY LIST LOW BYTE
;SAVE DISPLAY LI ST HIGH BYTE
;SKCTL REGISTER RAM
D:I
c..
)C.
::l
.,.,
.....
0
$26F
GPRIOR
PADDLO
PADDL1
PADDL2
PADDL3
PADDL4
PADDL5
PADDL6
PADDL7
STICKO
STICK1
STICK2
STICK3
026F
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
027A
02,6
$0278
$0279
$027A
$0276
JOYSTICKS
$0270
$0271
$0272
$0273
$0274
$0275
$0276
$0277
POTENTIOMETERS
$0234
$0235
LPENH
LPENV
0234
0235
:::s
D:!
I I >C.
c..
If
.....
.....
PTRIGO
PTRIGl
PTRIG2
PTRIG3
PTRIG4
PTRIG5
PTRIG6
PTRIG7
STRIGO
STRIGl
STRIG2
STRIG3
TXTROW
TXTCOL
TINDEX
TXTMSC
TXTOLD
ESCFLG
LOGMAP
INVFLAG
FILFL.G
027C
0270
027E
027 F
0280
0281
0282
0283
0284
0285
0286
0287
0290
0291
0293
0294
0296
02A2
02B2
0286
0287
$0290
$0291
$0293
$0294
$0296
$02A2
$0282
$0286
$02B7
;Text rowers
;Text colcrs
;Text index
;fools convert into new msc
;oldrow and oldcol for text (etc.)
;[scape flag
;Logical line start bit map
;Inverse video flag (toggled by Atari key)
;Fill flaq for draw
$0284
$0285
$0286
$0287
JOYSTICK TRIGGER
$027C
$0270
$027E
$027F
$0280
$0281
$0282
$028 3
PADDLE TRIGGER
g:,
>C.
c..
::J
tD
l>
't'
't'
r-'
$0 2F0
$02Fl
$02 F3
$OZF4
$02FD
CRSINH
KEYDEL
CHACT
CHBAS
FILDAT
02 FO
02Fl
02F3
02F4
02FD
ME~ITOP
MEMLO
DVSTAT
;PO COLOR
;Pl COLOR
;P2 COLOR
;P3 COLOR
;COLOR 0
;C OLOR 1
;COLOR 2
;COI.OR 3
;COLOR 4
RAMS IZ
GLOBAL VARIABLES
$02CO
$02C1
$02C2
$02C3
$02C4
s.D 2C5
$02C6
$02C7
$02C8
$02E4
$021:5
$02E7
$02 EA
PCOLRO
PCOLR1
PCOLR2
PCO LR3
COLORO
COLORl
COLOR2
COLOR3
COLOR4
02CO
02C1
02C2
02C 3
02C4
02C5
02C6
02C7
02C8
COLORS
$02 BB
$02BE
$0 2Br
02E4
02E5
02E7
02EA
SCRFLG
SHFLOK
BOTSCR
02BB
02BE
02BF
II
to
>co
c..
:::s
Ilf
......
I OC B
ICrtIO
ICONO
ICCOM
ICSTA
ICBAL
I CBAH
I CPTL
0340
0340
0341
0342
0343
0344
0345
0346
$0340
$0 340
$0341
$0342
$0343
$0344
$0345
$0 34 6
0300
0300
0301
0302
0303
0304
0305
0306
0308
0309
030 A
03 DB
;Atascii c haracter
;g l obal variable for keyboard
;DISPLAY fL AG: DISPLAYS CN TLS If NON ZERO;
; St art /stop flag f or pagin g (C NTL 1). Cleared by Brea
$02FB
$02fC
$02FE
$02f F
ATACHR
CH
DSPfLA
SS fLAG
02FB
02fC
02FE
02ff
0:1
)C.
Co
::l
l>
"C
"C
""
'"""'
$08E6
$D9AA
USAREA
AFP
FASC
IFP
FPI
FSUB
FAOO
0480
0800
08E6
09AA
0920
OA60
OA66
OAOB
OB28
0089
FOIV
FLOOR
H1Ul
$0800
CASBUF
03FO
(0480 thru 05FF for the user)
(except for floating point ... )
$0 920
$OA60
$OA66
$OAOB
$OB28
$0089
IF CARRY IS USED THEN CARRY CLEAR => NO ERROR, CARRY SET => ERROR
$0480
x"
D'
bytes
;four
sp~r?
::I
Q.
(1)
""
J>
$03CO
;Printer buffer (40 bytes)
(21 spare bytes)
PRNBUF
03CO
$0347
$f)3413
$0349
S034A
$034B
$034C
ICPTH
ICBll
IeBlH
ICAX1
ICAX2
ICSPR
0347
0348
0349
034A
034B
034C
....,
U1
EXP
EXPIO
LOG
LOGIO
SIN
COS
ATAN
SQR
FRO
FRI
CIX
DDCO
DDCC
DECO
DEDI
BD81
BD73
BD43
BEBl
0004
ODED
00F2
Fr~OVE
PLYEVL
FLDOP
FLDIR
FLDIP
FSTOR
FSTOP
0080
0098
DD9C
DDAI
DDAB
DDB6
0040
$BD73
$BQ43
$BEfll
$6081
(A(I) ZI)
(FLPTR)
(X.Y)
(FLPTR)
FRO
FRO
INPUT :
FRO <FRI <FRI <;FLDATING STORE REGO (X.Y) <(FLTPTR)<;FRI <- FRO
;FRO <- P(Z)
SUM(I = N TO 0)
$DDCO
$DDCC
$DECD
$DEDI
$0080
$0098
$DD9C
$DDA7
$DDAB
$DDB6
$0040
CARRY
CARRY
'"
;Co
:::J
Co
II)
"C
"C
.....
0'<
IV
INBUFF
RAOFLG
FLTPTR
LBUFF
PLYARG
POK EY
POTO
POTl
POT2
POT3
POT4
POT5
POT6
POT7
00F3
OOFB
OOFC
0580
05EO
0200
0200
0201
0202
0203
D204
0205
0206
0207
$0200
POK EY+O
PO KEY+l
POKE Y+ 2
POK EY +3
POKEY +4
PO KEY+5
POKEY +6
POKE Y+ 7
CO LLEEN MNEMONICS
; VB LA NK ACTION :
;POTO- - >PADOLO
;POT1-->PADOL1
;POT2-- >PADOL2
;PO T3-- >P AOOL3
;POT4-- >PAOOL4
;POT5- - >PAO OL5
; POTfl -- >PADDL6
; POT7-- >PAODL7
$0580
; LINE BUFFER
;PO LYNOMJ LA ARGUMENTS
LBUFF+ $60
(0 57 E to 05FF)
DESCRIPTION:
0- 227 I N RAM
0-227 IN RAM
0-227 IN RAM
0- 22 7 I N RAM
0- 227 I N RAM
0--2 27 IU RAM
0-227 IN RAM
0-2 27 IN RAM
$00F3
$O OF[l
$OOFC
CE LL
CELL
CELL
CELL
CELL
CELL
CELL
CELL
I I o:J
>eo
Q.
:J
Ilf
....N'-l
POKEY+13
POKEY+14
POKEY+15
POKEY+O
POKEY+l
POKEY+2
POKEY +3
POKEY+4
POKEY+5
POKEY+6
POKEY+7
POKEY+8
POKEY+9
POKEY+l0
POKEY+ll
POKEY+13
POKEY+14
POKEY+15
$0000
CTIA+O
CTIA+l
CTIA+2
CTIA+3
CTIA+4
CTIA+5
SERIN
IRQST
SKS TAT
AUOF1
AUOCl
AUOF2
AUDC2
AUOF3
AUOC3
AUOF4
AUOC4
AUOCT
STIMER
SKRES
POTGO
SEROUT
IRQEN
SKCTL
CTIA
HPOSPO
HPOSPl
HPOSP2
HPOSP3
HPOSMO
HPOSMl
0200
0201
0202
020 3
0204
0205
0206
0207
0208
0209
020A
D20B
0200
020E
020F
0000
0000
0001
0002
0003
0004
0005
n/a
0200
020E
020F
POKEY+8
POKEY+9
POKEY+l0
POKEY+11
ALLPOT
KACOOE
RANOOM
POTGO
0208
0209
020A
0208
SKRES<--[SIO]
;NONE
SEROUT<--[SIO]
;NON E
;POKMSK-->IRQEN (A FFE CTED BY OPEN S: OR E:)
SSKCTL<- - [SIO]
;SSKCTL-->SKCTL
;NON E
;Strobed
; ??l
OJ
)CO
Co
tD
::l
.,.,l>
N
.....
00
CTIA+6
CTIA+7
CTIA+8
CTIA+9
CTIA+l0
CTIA+ll
CTIA+12
CTIA+13
CTIA+14
CTIA+15
CTIA+16
CTIA+17
CTIA+18
CTIA+19
CTIA+20
CTIA+21
CTIA+22
CTIA+23
CTIA+24
CTIA+25
CTIA+26
CTIA+27
CTIA+Z8
CTIA+Z9
CTIA+30
CTIA+31
CTIA+O
CTIA+Z
CTIA+3
HPOSM2
HPOSM3
SIZEPO
SIZEPl
SIZEP2
SIZEP3
SIZEM
GRAFPO
GRAFPl
GRAFP2
GRAFP3
GRAFM
COLPMO
COLPMl
COLPM2
COLPM3
COLPFO
COLPFl
COLPF2
COLPF3
COLBK
PRIOR
VDELAY
GRACTL
HITCLR
CONSOL
MOPF
MZPF
M3PF
0006
0007
0008
0009
DOOA
DOOB
DOOC
000 0
DOOE
DOOF
0010
0011
0012
0013
D014
0015
0016
0017
0018
0019
D01A
D01B
DOlC
0010
DOlE
D01F
0000
D002
0003
;$08- - >CONSOL
; ETC.N
;PCOLRO-->COLPMO
>
to
;r
c..
::::l
"'C
"'C
''-0""'
IV
O~IACH
CHARCTL
OLISH
OLISTH
HSCROL
VSCROL
PMBASE
CHBASE
0401
0402
0403
0404
0405
0407
0409
ANTIC
M3PL
POPL
P1PL
P2PL
P3PL
TRIGO
TRIGl
TRIG2
TRIG3
PAL
~12PL
POPF
P1PF
P2PF
P3PF
t,10PL
M1PL
0400
0400
0004
D005
0006
0007
0008
0009
OOOA
OOOB
OOOC
DODD
oaOE
[)OOF
0010
0011
0012
0013
0014
ANTIC+4
ANTIC+5
ANTIC+7
ANTIC+9
ANTIC+3
ANTIC+2
ANTIC+l
$0400
ANTIC+O
CTIA+4
CTIA+5
CTIA+6
CTIA+7
CTIA+8
CTIII+9
CTIA+l0
CTIA+ll
CTIA+12
CTIA +-13
CTIA+14
CTIA'"15
CTIA+16
CTIA+17
CTIA+18
CTIA+19
CTIA+20
; CH[J,IISE<--CHBAS
; OLISTH<- -SOLSTH
; OLISTL<- -SOLSTL
; CHACTL<- -CHAcr
;OMACTL<--SOMCTL
;TRIGO-->STRIGl
;ETC.
ON OPEN S : OR E:
ON OPEN S : OR E:
ON OPEN S: OR E:
ON OPEN S: OR E:
ON OPEN S: OR E:
tI:I
;r
"C
"C
til
::::s
tv
tv
a
E45F
E462
E465
0001
0002
0003
0004
0005
0006
0007
D40A
D40B
D40C
D40D
D40E
D40F
D40F
E400
E410
E420
E430
E440
E459
E45C
SYSVBV
XITVBL
SIOINV
$E45F
$E452
$E465
ANTIC+10
WSYNC
ANTIC+11
VCOUNT
ANTIC+12
PENH
ANTIC+13
PENV
;NMIEN<--40
ANTIC+14
NMIEN
;STROBED
ANTIC+15
NMIRES
ANTIC+15
NMIST
; EDITOR
$E400
EDITRV
;TELE VISION SCREEN
$E410
SCRENV
;KEYBOARD
$E420
KEYBDV
; PRINTER
$E430
PRINTV
;CASSETTE
$E440
CASETV
;seria l input output routine
$E459
SIOV
;set system timers routine
$E45C
SETVBV
With respect to SETVBV, the cal l sequence is
X - MSB of vecto r /t imer
Y - LSB of vector/t imer
A - # of vector to hack
SF. TMRl
1
;Timer 1
2
SETMR2
2
3
S[TM R3
3
4
4
SETMR4
5
SETMR 5
5
;Imm8diate VBLANK
6
SET IMM
;Oeffered VBLANK
7
SETDEF
POWER ON AND [SETVBV]
D:I
>eo
c..
::l
(D
"'0
"'0
Appendix B
App le: What 's Where In Th e Apple, William Luebbert, Micro Ink,
Inc., 34 Chelmsford St., Chelmsford, MA 01824, 1981.
Atari : Mappin g Til e Atan, Ian Chadwick, COMPUTE! Books,
P.O. Box 5406, Greensboro, NC 27403, 1983. (This covers the
operating system and provides lengthy cross-referenced
explanations of Atari's memory addresses.)
Atari: Th e Atari BASIC SOllrcebook, Bill Wilkinson, COMPUTE! Books,
P.O. Box 5406, Greensboro, NC 27403, 1983. (Complete
commented source code of Atari BASIC, with explanatory text.)
221
AppendixC
Simple Assembler
Notes On Assembling
This program is written in BASIC because there is no reason not to.
Since the program runs quickly enough and there is some
complicated arithmetic involved, BASIC is the language of choice.
There are assemblers in ML which make two "passes" through the
source code and do need the extra speed . But this is a simple, "onepass" assembler. The virtue of simplicity is that you can easily and
quickly make small ML routines, test them, and debug them. An
added bonus is that modifying the Simple Assembler is easy in
BASIC. We'll see how you can customize it in a minute.
The assembler accepts your opcodes and their arguments,
translates them into the correct numeric values, and POKEs them into
RAM memory. You have a choice between using hex or decimal
during your ML programming on the Simple Assembler (SA). If you
remove line 10, the SA will accept only decimal numbers as
arguments, will print all addresses in decimal, and will display the
object code (the numbers it is POKEing) in decimal. Leaving line 10 in
the program will result in the SA accepting, addressing, and
displaying only hexadecimal numbers.
The circumflex in lines 4010 and 5030 - the character following
the number 16 - means "to the power of" and generally appears on
computer keyboards as an arrow pointing up. Since this is not a
complicated assembler, a decision had to be made concerning
whether or not to include two of the conventions which have been
traditional in ML programming. They were left out because it saves
programming time to avoid them and they are unnecessary.
The first one is the dollar sign ($). When an assembler can accept
either hex or decimal simultaneously it must have a way to tell, if you
type in "10", whether you mean decimal 10 or hex 10 (decimal 16).
The convention requires that you write decimal ten as "10" and hex
as "$10."However, this can quickly become a burden. In the SA, you
let it know which kinds of numbers you are using by setting H in line
ten. After that, just type in the numbers. No $ is used. The second
convention that is not included in the SA is the use of the comma.
Again, there is no particular reason to use commas, but it has been
the tradition to include them for certain addressing modes. They, too,
can become burdensome when you are programming. Also, each line
223
Appendix C
Addressing Mode
Conventions
Immediate
Absolute
Zero Page
LOA #15
LOA 1500
LOA 15
Accum ulator
Zero Page, X
Zero Page, Y
Absolute, X
Absolute, Y
Indexed Indirect
Indirect Indexed
ASL
LOA 15X
LOX 15Y
LOA 1500X
LOA 1500Y
LOA (15X)
LOA (15)Y
Traditional
LOA #$15
LOA $1500
LOA $15
(sometimes
LOA *$15)
ASLA
LOA$15,X
LOX$15,Y
LOA $1500,X
LOA $1500,Y
LOA ($15,X)
LOA ($15), Y
224
Appendix C
it will go back and put in the correct address for the branch. Also, you
can hand-POKE in any number in any address by typing the pseudoop "POKE". And, when you are finished with a program, type
"END" and the assembler will quit, reporting the starting and
ending addresses of your program in decimal.
A full-featured assembler can include dozens of pseudo-ops.
Let's briefly examine several popular ones to see if there are some
that you might want to add to the SA. Then we'll add a hex/decimal
pseudo-op to the SA to show how it's done.
BA - Begin Assembly. The SA asks you directly for the starting
address (variable SA$). BA signifies the location in RAM memory
where you want the object code to start. Example: BA $0400
BY - Bytes. This is for the creation of data tables. The BY is
followed by numbers or text characters which are POKEd into
memory at the current address. You put these BYtes at the start or
end of a program (it could result in havoc if it were in the middle of a
program; they would likely be meaningless as instructions). Example:
BY 46 46 48 42 12 11 or BY " THIS IS A MESSAGE"
DE - Define a label. Labels require a two-pass assembler that
goes through the source code first to create a table of labels which
would look something like this:
START
LETTER.A
PRINTROUTINE
1500
65
64422
Then, the second time through your source code, the assembler
would replace all the labels with their correct values. This is called
"resolving" the labels . DE is usually part of the initialization process.
A number of the example programs in this book start off with a series
of DE pseudo-ops, telling the assembler the meaning of various
important labels that will be used later in the source code instead of
literal numbers. Example: START DE 1500 or LETTER.A DE 65.
EN - The end of the source program. Stop assembling at this
point. The SA uses END.
MC - Move code. This interesting pseudo-op takes care of a
problem that sometimes comes up when you want your object code
to be ultimately used in an address that is now being used by the
assembler itself or cannot be directly POKEd at this time with the
object code. For instance, if your computer's RAM memory starts at
address 2048 like the Commodore 64, and you want to put your final
ML object code there, what do you do? If the SA was told to start
assembly there, it would begin to nibble away at itself. It's in RAM
starting at 2048.
225
AppendixC
245 IFMN$="HEX"THENGOT07000
246 IFMN$="DECIMAL"THENGOT07200
7000 PRINT"ENTER DECIMAL NUMBER";:INPUTDE:IFD
E>255THENSZ=3:GOT07020
7010 SZ=l
7020 GOSUB4000: PRINT"
$
"H$:GOT0230
7200 PRINT"ENTER HEX NUMBER"; :INPUTH$
7210 SX=LEN(H$):BK$="000":H$=LEFT$(BK$,4-SX)+
H$
7220 GOSUB5000: PRINT"
= "
DE:GOT0230
The Simple Assembler has a few error messages that it will print
when it can't make sense ou t of something. The primary
responsibility for finding errors, however, is yours . You can create
and save ML routines and then look at them with the Disassembler to
see if they look like they should. SA takes up about 4.SK so it will not
run on an unexpanded VIC. A 3K RAM expansion will provide 2000
bytes for storage of your ML routines.
226
AppendixC
230
IFH=lTHENDE=SA:SZ=3:GOSUB4000:PRINTH$~:G
OT0240
235 PRINTSA" "~
240 INPUTMN$:PRINT"{UP}"SPC(20)~:REM GO UP 0
NE LINE AND OVER 20 SPACES
241 REM ADD NEW PSEUDO-OPS HERE
242 IFRIGHT$(MN$,7)="FORWARD"THENFB=SA
243 IFRIGHT$(MN$,7)="RESOLVE"THENFR=SA-FB:PO
KEFB+l,FR-2:PRINT" OK":GOT0230
244 IFRIGHT$ (1Il\N$, 4) = "POKE "'rHENPRINT" ADDR, NUM
BER(DEC)"; :INPUTADR,NUM:POKEADR,NUM
:GOT0230
227
AppendixC
250 IFMN$="END"THENPRINT:PRINT"
PROGRAM
IS fROM"TA"TO"SA:END
260 L=LEN(MN$):L$=LEFT$(MN$,3)
270 FORI=lT056:IFL$=M$(I)THEN300
280 NEXTI
290 GOT0850
300 REM PRIMARY OPCODE CATEGORIES
301 TY=TY(I):OP=OP(I)
305 IFFB=SATHENTN=0:GOT02010
310 IFTY=0THENGOT01000
320 IFTY=3THENTY=1:IFL=3THENOP=OP+8:GOT01000
330 R$=RIGHT$(MN$,L-4):IFH=lTHENGOSUB6000
340 LR$=LEFT$(R$,l):LL=LEN(R$):IFLR$="#"THEN
480
350 IFLR$=" ("THEN520
360 IFTY=8THEN600
370 IFTY=3THENOP=OP+8:GOT01000
380 IFRIGHT$(R$,l)="X"ORRIGHT$(R$,l)="Y"THEN
630
390 IFLEFT$(L$,l)="J"THEN820
400 TN=VAL(R$):IFTN>255THEN430
410 IFTY=10RTY=30RTY=40RTY=5THENOP=OP+4
420 GOT02000
430 H%=TN/256:L%=TN-256*H%:IFTY=20RTY=7THENO
P=OP+8:GOT0470
440 IFTY=10RTY=30RTY=40RTY=5THENOP=OP+12:GOT
04713
450 IFTY=60RTY=9THEN470
460 GOT0850
4713 GOT03000
480 TN=VAL(RIGHT$(R$,LL-l))
490 IFTY=lTHENOP=OP+8:GOT02000
500 IFTY=40RTY=5THENGOT02000
510 GOT0850
520 IFRIGHT$(R$,2)=")y"THEN540
5 30 I FRIGHT$ (R$, 2) = "X) "'rHEN5 70
540 TN=VAL(MID$(R$,2,LL-3))
550 IFTY=lTHENOP=OP+16:GOT02000
560 GOT0850
570 TN=VAL(MID$(R$,2,LL-3))
580 IFTY=lTHENGOT02000
590 GOT0850
600 TN=VAL(R$):TN=TN-SA-2:IFTN<-1280RTN>127T
HENPRINT"'roo FAR "i :GOT0850
228
Appendix C
610
620
630
640
6 50
660
670
675
680
690
700
710
720
IFTN<0THENTN=TN+256
GOT02000
IFRIGHT$(R$,2)=")y"THEN540
IFRIGHT$(R$,1)="X"THEN720
REM *ZERO Y
TN=VAL(LEFT$(R$,LL-1)):IFTN>255THEN680
IFTY=20RTY=5THEN730
IFTY=1THEN760
GOSUB770:IFTY=1THENOP=OP+24:GOT0710
IFTY=5THENOP=OP+28:GOT0710
GOT0850
GOT03000
TN=VAL(LEFT$(R$ ,LL-1 )):I FTN>255 THENGOSUB
770:GOT0780
730 IFTY=2THENOP=OP +16:GOT07 60
740 IFTY=10RTY=30RT Y=5THENOP=OP+20:GOT0760
750 GOT0850
760 GOT02000
770 H%=TN/256:L%=TN-256*H%:RETURN
780 IFTY=2THENOP=OP+24:GOT0810
790 IFTY=10RTY=30RTY=5THENOP=OP+28:GOT0810
800 GOT0850
810 GOT03000
820 TN=VAL(R$)
830 GOSUB770
840 GOT0710
850 PRINT"(REV} ERROR ":GOT0230
1000 REM 1 BYTE INSTRUCTIONS
1010 POKESA,OP:SA=SA+1:IFH=lTHEN 1030
1020 PRINTOP:GOT0230
1030 DE = OP:GOSUB4000:PRINTH$:GOT0230
2000 REM 2 BYTE INSTRUCTIONS
2005 IFTN>256THENPRINT" INCORRECT ARGUMENT.
#5 IN HEX IS #05)":GOT0230
2010 POKESA,OP:POKESA+1,TN:SA=SA+2:IFH=lTHEN2
030
2020 PRINTOPiTN:GOT0230
2030 DE = OP:GOSUB4000:PRINTH$" "i
2040 DE = TN:GOSUB4000:PRINTH$:GOT0230
3000 REM 3 BYTE INSTRUCTIONS
3010 POKESA,OP:POKESA+l,L%:POKESA+2,H%:SA=SA+
3:IFH=lTHEN3030
3020 PRINTOPiL%iH%:GOT0230
3030 DE = OP:GOSUB4000:PRINTH$" "
229
Appendix C
3040
3050
4000
4010
DE = L%:GOSUB4000:PRINTH$" ";
DE = H%:GOSUB4000:PRINTH$:GOT0230
REM DECIMAL TO HEX (DE TO H$)
H$="": FORM=SZT00STEP-l:N%=DE/(16 M):DE=D
E-N%*16 M:H$=H$+MID$(HE$,N%+1,1)
4020 NEXT:SZ=l:RETURN
5000 REM HEX TO DECIMAL (H$ TO DE)
5010 D=0:Q=3:FORM=lT04:FORW=0T015:IFMID$(H$,M
,1)=MID$(HE$,W+l,1)THEN5030
5020 NEXTW
5030 Dl=W*(16 (Q)):D=D+Dl:Q=Q-l:NEXTM:DE=INT(
D) : RETURN
6000 REM ACCEPT HEX OPCODE INPUT AND TRANSLAT
E IT TO DECIMAL
6010 IFLEFT$ (R$, 1 ) =" # "THENH$= "00 "+RIGH'r$ (R$, 2
):GOSUB5000:R$="#"+STR$(DE):RETURN
6020 LS=LEN(R$) :AZ$=LEFT$(R$,l):ZA$=MID$ (R$,L
S,1):IFAZ$<>"("THEN6 050
6030 IFZA$="y"THENH$="00"+MID$( R$,2,2):GOSUB5
000: R$=
"+STR$ (DE) +" )y" : RETURN
6040 IFZA$=")"THENH$="00"+MID$( R$,2,2 ):GOSUB5
000: R$=" ("+STR$ (DE) +"X)": RETURN
6050 IFZA$="X"ORZA$="y"THEN60713
6060 H$=LEFT$(ZO$,4-LS)+R$:GOSUB5000:R$=STR$(
DE) : RETURN
6070 IFLS=5THENH$=LEFT$(R$,4):GOT06090
6080 H$="00"+LEFT$(R$,2)
60913 GOSUB50013:R$=STR$(DE)+ZA$:RETURN
20000 DATAADC1097,AND1033,ASL3002,BCC8144,
BCS8176,BEQ8240,BIT7036,BMI8048
20010 DATABNE8208,BPL8016,BRK0000,BVC8080,BVS8
112,CLC0024,CLD0216,CLI0088
20020 DATACLV0184,CMPl193,CPX4224,CPY4192,DEC2
198,DEX0202,DEY0136,EOR1065
20030 DATAINC2230,INX0232,INY0200,JMP6076,JSR9
032,LDAl161,LDX5162,LDY5160
20040 DATALSR3066,NOP0234,ORA1001,PHA0072,PHP0
008,PLA0104,PLP0040,ROL3034
20050 DATAROR3098,RTI0064,RTS0096,SBC1225,SEC0
056,SED0248,SEI0120,STAl129
20060 DATASTX2134,STY2132,TAX0170,TAY0168,TSX0
186,TXA0138,TXS0154,TYA0152
A
II (
230
Appendix C
~1!i~} t.:..~-1:3.:L3"3:
!!t]:C'J3:i.iO!l~
0" ;
1 h:1
120
14i21
15i-:1
15 5
177
3~1
DIM
FOR
...J "
"'"
SPACES::: L D A
1 5121
QI"
1 6 121
P R I NT" Z e r
165
1 7 121
F"'"
f
...J
177
179
18i2!
185
189
19
~I
p c3 g e {5
SPA C E S ::: L D A
15
.-
231
AppendixC
1 95
197
200
210
215
217
2 212!
225
230
T A = SA: P R I N T
{C LEA F~}
GOT 0 2 3 i2i
'7
: 7
" { BEL L::; _i!:I:l~.:iliI!TIW1f : '7 : IF
HX=1 THEN -;:. "(e.g. #5 should be
#fZ~5) II:?
IF HX=1 THEN DE =S A:S Z=3:G OSUB 4 0
12!Q!: PRINT H$ : " :
~: GOTO
24i21
PRINT SA:":
";
T RAP 2 2 5: I N PUT # 1 ; M N -0$ : '7
{U P ::;
POI< E 8 5 ~ 20: I F 1'1 N $ =
THE N -;:.
{DEL LINE } "::GOTO 23~)
REN ADD NEW PSEUDO - OP S HERE
IF LENCMN$6 THEN IF MN$(LEN(MN
$) - 6 ) = FOF~ WARD
THEN FB=SI-i
IF MN$="RESOLVE" THEN FR=SA-FB:P
o V E F B + 1 ~ F F~ - 2 : P R I N T
0 r.:
GOT 0
II
II
II
23 5
2 4 i2!
II
II
II;'
241
242
II
243
II
II
II
If
231~!
244
25 Q!
260
27121
28~!
29~~!
300
301
305
310
232
IF NN$=" pm::: E
THEN PR I I'H "ADDR _
, N
UMBER (DE C) ": : INPUT ADDR, NUM: POI<E
ADDR ~ NUM :G OTO
230
I F M i'-.I $ = .. END" THE N 8 I2H2li.2!
L=LEN(MN$):L$=MN$ ( 1 .3)
FOF~
1=1 TO 56:IF L$=M$<I:+:3-2.I:+:3
) THE N 3 i2! Q!
NE XT I
GOTO 85 i2!
REM PRINARY OPCODE CATEGORIES
TY=TY- (I ): OP=OP ( I)
IF FB=SA THEN TN =0:G OTO 2 010
IF TY=0 THEN GO TO 1000
II
Appendix C
3 2 ~I
330
l-~!
:::.40
3 5 121
360
370
38(21
LR$=R$
TYEN
I F
IF
IF
IF
LF$= "#
480
THE N 5 2 0
TY=8 THEN 600
TY=3 THEN OP=oP+8:GoTO 1000
R$(LL)="X" OR R$(LL)="Y" THEN
L P $ =" ("
630
I F L S ( 1
~ 1 ) = " J"
THE N 8 2 l~!
TN=VAL(RS): IF TN~255 THEN 430
IF TY=1 OR TY=3 OR TY=4 OR TY=5
THEN oP=oF'+4
4 2 l21 GOT 0 2 l2! (21 \21
430 H=INTITN!256):L=(TN - 256* H) :IF TY
=2 OR TV=7 THEN OP=OF'+8:GoTO 470
440 IF TY =1 OR TY= 3 OR TY=4 OR TY=5
THEN OP=oP+12:GOTO 470
450 IF TY=6 OR TY=9 THEN 470
46121 GoTO 850
4 7 l21 GOT 0 3 ~~I ~:I (2)
39G
40 0
410
4 8 f'i
T N = \,) A L ( R $ ( 2 )
580
59~)
600
6 1 (I
6 20
63QI
6 40
AppendixC
65121
8 !Zli2!
8 1 Q!
REM *IEFO Y
T N = \l A L ( R $ ( 1 ~ L L - 1 } } : 1FT N : 2 5 5 THE
N 68i21
IF TV = 2 OR TY =5 THEN 730
IF TV=! THEN 760
GOSUB 77 0 :IF TV= l THEN OP=OP+2~:
GOTO 71.0
IF TY=5 TH E N OP=OP+28:G OTO 710
GO TO 85Q)
GOTO 3(:H~H~)
TN=VAL(RS(l , LL - 1)1:IF TN ) 255 THE
N GOSUB 770:GOTO 780
IF TY=2 THEN OP=OP+16:GOTO 760
IF TY=1 OR TV=3 OR TY=5 THEN OP=
o P + 2 QI : GOT 0 7 6 i~!
GOTO 85~~i
GOT 0 2 i2; ~~! !21
H=INT(TN/256}:L=TN-256*H:RETURN
IF TV=2 THEN OP=OP +2 4:GOTO 810
IF TY=1 OR TY=3 OR TY=5 THEN OP=
OF' +28: GO TO 8 i i~l
GOT 0 8 5 (21
GOT 0 3 i~H~H2;
8 2
T N = \) A L ( F: $ )
670
675
680
690
n~lQl
71 i2!
720
730
740
751~1
7 6
!~)
770
780
790
~!
830
GOSUB 77(,~!
GOTO 71 G
85H PRINT .. {BELL}13;~:t.J:.": GOTO 23121
1000 REM 1 BYTE INSTRUCTIONS
1010 POKE SA.OP:SA=SA+l:IF HX=l THEN
84~!
1 QI3 ~~!
HS:GOTO
23l-~1
2000
REM
2 0 QI 5
1FT N ;- 2 5 6
BYTE
INSTRUCTIONS
T HE N
'")
'J
"E I
I 0 .. - -
" :
23i~!
234
Appendix C
4020
A=DE-A*256:AH=INT(AiI6):AL=A-AH
*16:H$(LEN(H$)+1)=HE$(AH+l,AH+l
):H$(LEN(HS)+I}=HES(AL+l,AL+l):
SI=l:RETURN
5000 REM HEX TO DECIMAL (HS TO DE)
5010 D=0:Q=3:FOR M=l TO 4:W=ASC(H$(M
- 4 8 : I F W> 9 THEN W=W-7
5030 D=D*16+W:NEXT M:DE=INT(D):RETUR
N
6065
H$(LEN(H$)+l)=RS:GOSUB 5000:RS=
5TRS(DE):RETURN
235
AppendixC
6070
If
If;
If
PY4192,DEC2198~DEX0202,DEY0136
. EOR 1 (2!65
DATA INC2230,INX0232.INY0200,J
MP6076 .JSR 4 032.LDA1161,LDX5162
, LDY516 f!
20040 DATA LSR3066,NOP0234,ORA1001.P
HA0072, PHP0008,PLA0104. PLP0040
, ROL3!2!34
20050 DATA ROR3098,RTI0064.RTS0096,S
BC1225 ,SEC0056.SED024 8,SEI0120
,STAl129
20060 DATA STX2134,STY2132.TAX0170,T
AY0168,TSX0186 ,TXA013 8 . TXS0154
, TYA~~! 15 2
20030
236
Appendix D
Note: The /\ means" to the power of" as in 2 /\ 2 = 4.
Program 0-1. Disassembler (VIC, PET, Apple, 64 Version).
1 HE$="0123456789ABCDEF"
2 L$="-- - ------- -------------- ------------
"
4 J$="
--->"
13 PRINT" DISASSEMBLER
14 PRINT
16 DIMM$(15,15)
17 FORI=0T015:FORB=0T014:READM$(I,B):NEXTB:
NEXTI
25 REM START MAIN LOOP
30 PRINT"STARTING ADDRESS (DECIMAL)"; : INPUT
SA:TA=SA
31 PRINT"START ADDRESS HEX "; :DE=SA:ZX=3:G
OSUB1200: PRINTH$"
IFSA<0THENEND
35
41 I=SA
45 REM PRINT ADDRESS
46 PRINTI" ";
50 X=PEEK(I)
55 GOSUB5000
56 IFL%=150RM$(H%,L%)="0"THENPRINT" '(
X:CK=0:LN=LN+1:GOT070
58 PRINTM$(H%,L%)i
60 GOSUB6000:IFEQTHENEQ=0
70 1=1+1
72 IFLN=20THENLN=0:GOT02000
80 GOT045
600 IFCK=12THEN603
601 B=PEEK(I+1):IFB>127THENB=((NOTB)AND255)+
l:B=-B
"BAD:I=I+1:RETUR
602 BAD=I+2+B:PRINT"
II
II
603 IFH%>8THEN800
604 IFH%=2THENJ=1:GOT0850
605 IFH%=6THENPRINT:PRINTL$:EQ=1:RETURN
237
Appendix 0
606
607
608
610
611
612
615
616
630
631
632
635
636
640
641
642
645
646
660
661
662
663
664
680
690
691
720
722
7 25
726
727
728
729
730
731
740
741
742
800
801
850
860
870
880
238
IFH%=6THENRETURN
PRINT
RETURN
IFCK=12THEN615
PRINT" ("PEEK (1+1) ") I y"
I=I+1:RETURN
PRINT" ("PEEK(I+1)" ,X)"
I=I+1:RETURN
IFCK=12THEN635
PRINT" "PEEK(I+1)" ,X"
I=I+1:RETURN
PRINT"
"PEEK(I+1)
I=I+1:RETURN
IFCK=12THEN645
PRINT" "PEEK(I+1)",X"
I=I+1:RETURN
PRINT"
"PEEK(I+1)
I=I+1:RETURN
IFCK=12THEN645
IFH%=90RH%=11THENPRINT" "PEEK(I+1)", y"
IFH%=70RH%=150RH%=50RH%=3THEN640
IFH%=13THEN631
PRINT:GOT0642
PRINT: RETURN
IFCK=12THEN800
I$="Y":GOT0850
IFCK=12THEN725
I$="X":GOT0850
IFH%=6THENPRINT" (IND.
";: 1=1+1
IFH%=2THEN850
IFH%=4THENPRINTJ$;:GOT0850
IFH%=80RH%=100RH%=120RH%=14THEN850
GOT0610
IFCK=12THEN850
I$="X":GOT0850
IFCK=12THEN850
IFH%=11THENI$="Y":GOT0850
I$="X":GOT0850
PRINT"
#"PEEK(I+1)
I=I+1:RETURN
N=PEEK(I+1)+PEEK(I+2)*256
IFI$=" "THEN900
IFI$="X"THENPRINT"
"N" ,X"
IFI$="y"THENPRINT"
"N" I y"
Appendix 0
890 I$="":I=I+2:RETURN
900 PRINT"
"N: 1=1+2
906 RETURN
1000 DATABRK,ORA,0,0,0,ORA,ASL,0,PHP,ORA,ASL,
0,0,ORA,ASL,BPL,ORA,0,0,0,ORA,ASL
1010 DATA0,CLC,ORA,0,0,0,ORA,ASL,JSR,AND,0,0,
BIT, AND, ROL, 0, PLP, AND, ROL, 0, BI'1'
1020 DATAAND,ROL,BMI,AND,0,0,0,AND,ROL,0,SEC,
AND,0,0,0,AND,ROL,RTI,EOR,0,0,0
1030 DATAEOR,LSR,0,PHA,EOR,LSR,0,JMP,EOR,LSR,
BVC,EOR,0,0,0 , EOR,LSR,0,CLI,EOR,0
1040 DATA0,0,EOR,LSR,RTS,ADC,0,0,0,ADC,ROR,0,
PLA,ADC
1045 DATAROR,0,JMP,ADC,ROR,BVS,ADC,0,0,0
1050 DATAADC,ROR,0,SEI,ADC,0,0,0,ADC,ROR,0,ST
A
1055 DATA0,0,STY,STA,STX,0,DEY,0,TXA,0,STY,ST
A
1060 DATASTX,BCC,STA,0,0,STY,STA,STX,0,TYA,ST
A,TXS,0,0,STA,0,LDY,LDA,LDX,0
1070 DATALDY,LDA,LDX,0,TAY,LDA,TAX,0,LDY,LDA,
LDX,BCS,LDA,0,0,LDY,LDA,LDX,0
1080 DATACLV,LDA,TSX,0
1090 DATALDY,LDA,LDX,CPy,CMP,0,0,CPY,CMP,DEC,
0,INY,CMP,DEX,0,CPY,CMP,DEC
1095 DATABNE,CMP,0,0,0,CMP,DEC,0,CLD,CMP,0,0,
0,CMP,DEC;CPX,SBC,0,0,CPX,SBC,INC
1098 DATA0,INX,SBC,NOP,0,CPX,SBC,INC,BEQ,SBC,
0,0,0,SBC,INC,0,SED,SBC,0,0,0,SBC
1099 DATAINC
1200 REM MAKE DECIMAL INTO HEX
1201 H$= 1111: FORM=ZXT00STEP-1 : N%=DE/ (16 AM) : DE=D
A
E-N%*16 M:H$=H$+MID$(HE$,N%+1,1)
1202 NEXT:RETURN
2000 PRINT"TYPE C TO CONTINUE FROM" I
2001 GETK$:IFK$=""THEN2001
2002 IFK$="C"THENSA=I:TA=SA:GOT035
2003 INPUTSA:TA=SA:GOT035
5000 REM ANALYZE H & L OF OPCODE
5010 H%=X/16:L%=X-H%*16
5020 :RETURN
6000 REM FIND ADDRESS TYPE & GOSUB
6020 CK=H%/2:IFCK=INT(CK)THENCK=12
6025 L%=L%+l
239
Appendix 0
6030 ONL%GOSUB600,610,800,6050,640,640,660,60
50,680,690,680,6050,720,730,740
6040 CK=0
6045 LN=LN+l
6050 RETURN
: ':>
1 1 ~ 0: ':>
eli:i-til
"L 0 a din 9 op C
If
odes . . . "
110 DIM OPCODES(256*10)~LN(255)~NB(25
5) ~TS(10} ~DS(5)
120 FOR 1=0 TO 255
125 READ T$~NB
130 LN(I)=LEN(TS)
140 GPCODES(I*10+1,I*10+LN(I=TS
150 NB(I)=NB
160 NEXT I
1 70 G RAP H I C S (I: PO SIT ION 1 1 ~ (I:? "eli:"i#tI I
e~) Ija-J:'i'--s.-J 3:;1 .3
3 :."
180':> :?
190 TRAP 190:? "{UP}{DEL LINE}Star-tin
9 Addr-ess (Decimal)";:INPUT ADDR:
TRAP 40000
200 IF ADDR(O OR ADDR}65535 THEN 190
210 OP=PEEK(ADDR):NB=NB(OP}
220 TS=OPCODES(OP*I(1+1~OP*10+LN(OP)}
230 PRINT ADDR;:POKE 85,10:PRINT OP;:
POKE 85,15
240 ON NB+2 GOTO 242~244~250,260,270
242 NB=2:T=PEEK(ADDR+l}:IF T}128 THEN
T=T-256
243 PRINT T;:POKE 85~20:PRINT TS;"
;ADDR+2+T:GOTO 300
244 ? "llfifl::lj('::;::t=Uii($": NB= 1 : GOTO 300
246 PRINT TS;" ";ADDR+2+T:GOTO 300
250 POKE 85,20:PRINT TS:GOTO 300
260 PRINT PEEK(ADDR+l);:POKE 85~20:DS
=STRS(PEEK(ADDR +l)}:GOSUB 400:GOT
o 300
240
Appendix D
A~I,?~O~?~O~ORA
,3~?~0~BPL~-I,ORA
520 DATA
?~O~ORA
C,I~ORA
~3~ASL
()Y~2~?~0~?~0
X,2~ASL
X~2,?~0~CL
Y~3~?~0,?~0~?~0~ORA
~2~?~0,JSR
~?~O~?~O~BIT
~3~AND
,2,AND
~2~ROL
~2~ROL
X~3
(X)~2
~2~?,0
A~I~?~O~B
~3~?~0~BMI~-I~AN
X~2,ROL
2~?~0~SEC~I~AND
560 DATA
?~O,AND
I~I~EOR
Y~3~CLI~I~?~0
X,3~ROL
X~3~?~0~RT
(X)~2~?~0~?~0~?~0~EOR
~2
X~2~LSR
X~2~?~0~CLI~I~EOR
Y~2
590 DATA
?~O~?,O~?~O~EOR
3,?~0~RTS~ I~ADC
(X)
X~3~LSR
X~
~2~?,0~?~0
~2~?~0,PLA,
(I ~
J MP
()
108
~3,?~0~BVS~-I~ADC
~?,O~?,O,?,O~ADC
X,2~ROR
()Y~2
X,2,?~
o
241
Appendix 0
640
650
660
670
,2,STA
,2,?,0,DEY,1,?,0,TXA,1,?,0
DATA STY
,3,STA
,3,STX
,3,?,0,
BCC,-l,STA (}Y,2,?,0,?,0,STY
X,2
,STA
X,2
DATA STX
Y,2,?,0,TYA,1,STA
Y,3,
TXS,l,?,O,?,O,STA
X,3,?,0,?,0
DATA LDY # ,2,LDA (X},2,LDX # ,2,
?,O,LDY
,2,LDA
,2~LDX
,2,?,0,T
AY,l,LDA # ,2
DATA TAX,l,?,O,LDY
,3,LDA
,3,LD
X ,3,?,0,BCS,-I,LDA (}Y,2,?,0,?,
242
.L..
Appendix E
Number Tables
This lookup table s hould make it convenient when you need to
tran slate hex, binary, or decimal numbers. The first co lumn lists the
decimal numbers between 1 and 255. The second colum n is the
hexa d ecimal equivalent. The third column is the decimal equivalent
of a hex most significant byte or "MSB." The fourth column is the
binary.
If you need to find out the d ecimal equivalent of the hex number
$FDI5, look up $FD in the MSB column and you'll see that it's 64768.
Then look up the $15 in the LSB column (it's 21 decimal) and add
21+64768 to get th e answer: 64789.
Going th e other way, from decimal to hex, you could translate
64780 into hex by looki ng in the MSB column for the closest number
(it must be small er, h owever). In this case, the closest smaller number
is 64768 so jot down $FD as the h ex MSB. Then subtract 64768 from
64780 to get the LSB: 12. Look up 12 in the decimal column (it is $OC
hex) and put the $FD MSB together with the $OC LSB for your
answer: $FDOC.
With a little practice, you can use this chart for fairly quick
co nversions behveen the number systems. Most of your translations
will only involve going from h ex to decimal or vice versa with the LSB
of hex numbers, the first 255 numbers, which require no addition or
subtraction. Just look them up in the table.
Table E-!.
IDecimal I
1
2
3
4
5
6
7
8
9
10
(r;~) I
01
02
03
04
05
06
07
08
09
OA
Hex
(MSB)
256
512
768
1024
1280
1536
1792
2048
2304
2560
Binary
00000001
00000010
00000011
00000100
00000101
00000110
00000111
00001000
00001001
00001010
243
Appendix E
Binary
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
244
OB
OC
00
OE
OF
10
11
12
13
14
15
16
17
18
19
1A
1B
1C
10
1E
1F
20
21
22
23
24
25
26
27
28
29
2A
2B
2C
20
2E
2F
30
31
2816
3072
3328
3584
3840
4096
4352
4608
4864
5120
5376
5632
5888
6144
6400
6656
6912
7168
7424
7680
7936
8192
8448
8704
8960
9216
9472
9728
9984
10240
10496
10752
11008
11264
11520
11776
12032
12288
12544
00001011
00001100
00001101
00001110
00001111
00010000
00010001
00010010
000 leo 0 11
00010100
00010101
00010110
00010111
00011000
00011001
00011010
00011011
00011100
00011101
00011110
00011111
00100000
00100001
00100010
00100011
00100100
00100101
00100110
00100111
00101000
00101001
00101010
00101011
00101100
00101101
00101110
00101111
00110000
00110001
Append ix E
Binary
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
32
33
34
35
36
37
38
39
3A
3B
3C
3D
3E
3F
40
41
42
43
44
45
46
47
48
49
4A
4B
4C
40
4E
. 4F
50
51
52
53
54
55
56
57
58
12800
13056
13312
13568
13824
14080
14336
14592
1484 8
15104
15360
15616
15872
16128
16384
16640
16896
17152
17408
17664
17920
18176
18432
18688
18944
19200
19456
19712
19968
20224
20480
20736
20992
21248
21504
21760
22016
22272
22528
00110010
00110011
00110100
00110101
00110110
00110111
00111000
00111001 00111010
00111011
00111100
00111101
00111110
00111111
01000000
01000001
01000010
01000011
01000100
01000101
01000110
01000111
01001000
01001001
01001010
01001011
01001100
01001101
01001110
01001111
01010000
01010001
01010010
01010011
01010100
01010101
01010110
01010111
01011000
245
Appendix E
Binary
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
246
59
5A
5B
5C
50
5E
5F
60
61
62
63
64
65
66
67
68
69
6A
6B
6C
60
6E
6F
70
71
72
73
74
75
76
77
78
79
7A
7B
7C
70
7E
7F
22784
23040
23296
23552
23808
24064
24320
2 4576
24832
2 5088
25344
25600
25856
26112
26368
26624
26880
27136
27392
27648
27904
28160
28416
28 672
28928
29184
29440
29696
29952
30208
30464
30720
30976
31232
31488
31744
32000
32256
32512
01011001
01011010
01011011
01011100
01011101
01011110
01011111
01100000
01100001
01100010
01100011
01100100
01100101
01100110
01100111
01101000
01101001
01101010
01101011
01101100
01101101
01101110
01101111
01110000
01110001
01110010
01110011
01110100
01110101
01110110
01110111
01111000
01111001
01111010
01111011
01111100
01111101
01111110
01111111
Appendix E
Binary
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
80
81
82
83
84
85
86
87
88
89
8A
8B
8C
80
8E
8F
90
91
92
93
94
95
96
97
98
99
9A
9B
9C
90
9E
9F
AO
~
~J..
A2
A3
A4
AS
A6
32768
33024
33280
33536
33792
34048
34304
34560
34816
35072
35328
35584
35840
36096
36352
36608
36864
37120
37376
37632
37888
38144
38400
38656
38912
39168
39424
39680
39936
40192
40448
40704
40960
41216
41472
41728
41984
42240
42496
10000000
10000001
10000010
10000011
10000100
10000101
10000110
10000111
10001000
10001001
10001010
10001011
10001100
10001101
10001110
10001111
10010000
10010001
10010010
10010011
10010100
10010101
10010110
10010111
10011000
10011001
10011010
10011011
10011100
10011101
10011110
10011111
10100000
10100001
10100010
10100011
10100100
10100101
10100110
247
Appendix E
Binary
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
18.6
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
248
A7
A8
A9
AA
AB
AC
AD
AE
AF
80
Bl
B2
B3
B4
B5
B6
B7
B8
B9
BA
BB
BC
BD
BE
BF
CO
Cl
C2
C3
C4
C5
C6
C7
C8
C9
CA
CB
CC
42752
43008
43264
43520
43776
44032
44288
44544
44800
45056
45312
45568
45824
46080
46336
46592
46848
47104
47360
47616
47872
48128
48384
48640
48896
49152
49408
49664
49920
50176
50432
50688
50944
51200
51456
51712
51968
52224
10100111
10101000
10101001
10101010
10101011
10101100
10101101
10101110
10101111
10110000
10110001
10110010
10110011
10110100
10110101
10110110
10110111
10111000
10111001
10111010
10111011
10111100
10111101
10111110
10111111
11000000
11000001
11000010
11000011
11000100
11000101
11000110
11000111
11001000
11001001
11001010
11001011
11001100
Appendix E
Binary
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
CO
CE
CF
DO
01
02
03
04
05
06
07
08
09
OA
DB
DC
DO
DE
OF
EO
E1
E2
E3
E4
E5
E6
E7
E8
E9
EA
EB
EC
ED
EE
EF
FO
F1
F2
52480
11001101
52736
11001110
52992 11001111
53248
11010000
53504
11010001
53760
11010010
54016
11010011
54272 11010100
11010101
54528
54784
11010110
55040 11010111
55296 11011000
55552 11011001
55808
11011010
56064 11011011
56320 11011100
56576 11011101
56832 11011110
11011111
57088
57344 11100000
11100001
57600
57856 11100010
58112 11100011
58368 11100100
58624 11100101
58880 11100110
59136 11100111
59392 11101000
11101001
59648
59904 11101010
60160 11101011
60416 11101100
60672 11101101
60928 11101110
61184 11101111
61440 11110000
61696 11110001
61952 11110010
249
Appendix E
IDeCimal1
243
244
245
246
247
248
249
250
251
252
253
254
255
(r;~) I (~~~)
F3
F4
F5
F6
F7
F8
F9
FA
FB
FC
FD
FE
FF
62208
62464
62720
62976
63232
63488
63744
64000
64256
64512
64768
65024
65280
Binary
11110011
11110100
11110101
11110110
11110111
11111000
11111001
11111010
11111011
11111100
11111101
11111110
11111111
250
Appendix E
220 PRINT#4:NEXTX
230 END:REH TRANSFORM TO HEX
240 H$="I1:FORM=lT00STEP-l:N%=DE/(16"M):DE=DE
-N%*16"M
250 H$=H$+MID$(HE$,N%+l,l):NEXT
260 PRINT#4,H$" "i :DE=X*256
262IFDE<1000THENPRINT#4,"
"i :GOT0270
264 IFDE<10000THENPRINT#4,"
270 PRINT#4,DE" "i:RETURN
II
251
Appendix F
SUPERMON For PET
Tile' fallmpillg //I ollilor exlel lsiall s are til f il'O rk a/seve rail'rogmllllllers alld were previull siy
I'u/,lisir ed ill COMPUTE! Magazille. (See lir e cOl'yrigirl page for references.)
1. Type in the BASIC program (Program 1). It is the same for all
versions. Then save it normally by typing SAVE "CONTROL". This
program will be used later to automatically find your memory size,
transfer Superman to the top, and report to you the SYS address you
use to activate it.
2. Now the hard part: type SYS 1024 which enters you into the
machine language monitor. You will see something like the
following:
Figure I.
B*
.,
PC
IRQ
SR AC XR YR SP
0401 E455 32 04 5E 00 EE
Then type: M 0600 0648 and you will see something similar to this
(the numbers will be different, but we are going to type over them
which, after hitting RETURN on each line, will enter the new
numbers into the computer's memory):
253
Appendix F
Figure 2.
oM
o
..
o
0600 0648
0600 28 58
0608 FF FC
0610 CB 85
0618 34 85
0620 00 93
0628 06 F0
063(1 1 8 65
0638 20 43
0640 50 06
0648 1F 00
FF
00
1F
21
06
11
34
06
90
02
FF
21
A9
AS
06
85
AA
8A
DB
C6
00
06
0C
35
00
23
AS
20
60
20
08
03
85
85
16
20
23
43
EA
C6
06
AD
20
22
20
38
65
06
EA
1F
AD
A9
AS
A0
38
06
35
20
AS
B1
Appendix F
SUP E R~1 0 N4 !
DISSASSEMBLER
SINGLE STEP
BY WOZNIAK/BAUM
BY,] H'I R U S S 0
MOST OTHER STUFF ,BY BILL SEILER
TIDIED & WRAPPED BY JIM BUTTERFIELD
Appendix F
(RETURN)
(SCREEN CLEARS)
.,
2000 A9 12
LOA #$12
.,
2002 90 00 80
STA $8000,X
.,
2005 AA
TAX
.,
2006 AA
TAX
(FULL PAGE OF INSTRUCTIONS)
DISASSEMBLES 22 INSTRUCTIONS
STARTING AT 2000 HEX.
THE THREE BYTES
FOLLOWING THE ADDRESS MAY BE MODIFIED.
256
Appendix F
Appendix F
258
Appendix F
SAVE
.S "PROGRAM NAME " ,01,0800,0C8rJ
SAVE TO CASSETTE #1 MEMORY FROM
0800 HEX UP TO BUT NO T INCLUDING 0C80
HEX AND NAME IT PROGRAM NAME
S "0:PROGR AM NAME ",0 8 ,1 200 ,1F50
SAVE TO DISK DRIVE #0 MEMORY FROM
1 200 HEX UP TO BUT NOT IN CLUDING 1F50
HEX AND NAME IT PROGRAM NAME.
TRANSFER MEMORY
.T 100 0 110 0 5000
TRANSFER MEMORY IN THE RANGE 1000
HEX TO 1100 HE X AND START STORING IT AT
ADDRESS 5000 HEX.
EXIT TO BASIC
.X
RETURN TO BASIC READY MODE.
THE STACK VALUE SAVED WHEN ENTERED WILL
BE RESTORED.
CA RE SHOULD BE TAKEN THAT
THI S VALUE IS THE SAME AS WHEN THE
MONITO R WAS ENTER ED.
A CLR IN
BASIC WILL FIX ANY STACK PROBLEMS.
Program I. CONTROL.
120 PRINT"
S INGLE STEP {REV}I
{OFF} BY JIM RUSSO
130 PRINT"MOST OTHER STUFF {REV},HA
LT{OFF} BY BILL SEILER
150 PRINT"{DOWN}TIDIED & WRAPPED BY
JIM BUTTERFIELD"
259
Appendix F
170 L=PEEK(52)+PEEK(53)*256:SYS1536
:M=PEEK(33) :N=PEEK(34)
180 POKE52,M:POKE53,N:POKE48,M:POKE
49,N:N=M+N*256
210 PRINT"{02 DOWN}LINK TO MONITOR
- - SYS";N
220 PRINT:PRINT"SAVE WITH I"1LM: "
230 PRINT".S ";CHR$(34) ;"SUPERMON";
CHR$(34);" ,01"; :X=N/4096:G
OSUB250
240 X=L/4096:GOSUB250:END
250 PRINT","; :FORJ=lT04:X%=X:X=(X-X
%)*lG:IFX%>9THENX%=X%+7
260 PRINTCHR$(X%+48); :NEXTJ:RETURN
Program 2. SUPERMON 4.0
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
260
0600
0608
0610
0618
0620
0628
0630
0638
0640
0648
A9
A5
A0
38
06
35
20
A5
Bl
C6
CB
34
00
06
18
20
50
iF
iF
22
85
85
20
F0
65
43
06
D0
60
C6
iF
21
38
11
34
06
90
02
48
21
A9
A5
06
85
AA
8A
DB
C6
A5
68
0C
3S
D0
23
A5
20
60
20
21
91
85
85
16
20
23
43
EA
C6
D0
21
20
22
20
38
65
06
EA
iF
02
60
0650
0658
0660
0668
0670
0678
0680
0688
0690
0698
A9
60
AA
AA
AA
AA
AD
FF
8D
FB
80
AA
AA
AA
AA
AA
FE
00
FA
03
C5
AA
AA
AA
AA
AA
FF
85
03
00
iF
AA
AA
AA
AA
AA
00
35
AD
00
A9
AA
AA
AA
AA
AA
85
AD
FD
A2
06
AA
AA
AA
AA
AA
34
FC
FF
08
E5
AA
AA
AA
AA
AA
AD
FF
00
DD
20
AA
AA
AA
AA
AA
FF
00
8D
DE
06A0 FF 00 D0 0E 86 B4 8A 0A
Appendix F
.
.
.
.
.
.
.
.
.
.
.
..
.
.
.
.
..
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
06A8
06B0
06B8
06C0
06C8
0600
0608
06E0
06E8
AA
FF
9A
00
02
20
A9
79
07
BO
00
FA
84
E()
98
00
FA
90
E9
48
00
FB
OE
07
00
00
09
FF
60
A2
00
06
C9
80
20
60
00
CA
02
08
FC
20
00
6B
20
48
10
2C
B4
06
F0
00
07
98
BO
EA
A2
FC
FB
F9
01
20
07
E8
4C
00
00
60
60
20
57
20
06F0
06F8
0700
0708
0710
0718
0720
0728
0730
0738
54
4C
FA
60
02
00
02
FE
E5
81
07
A4
60
A2
95
F1
4C
38
FC
FA
B0
07
E6
02
FA
60
CE
E5
A8
00
OE
20
FO
B5
68
AO
FA
FB
00
20
AE
31
00
FA
90
0B
00
80
1B
44
06
05
02
48
0A
02
AS
1B
02
07
02
CA
E6
BO
02
AC
FO
02
60
20
9A
00
FE
0A
CA
0C
A4
98
20
92
0740
0748
075 0
0758
0760
0768
0770
0 77 8
0780
0788
FA
FA
07
C1
FO
00
18
FE
DE
C1
00
00
90
FA
20
EB
02
85
00
FA
20
20
15
00
A8
20
05
FE
3D
00
AF
CA
A6
90
FA
C1
FO
20
A1
B0
FA
FA
OE
60
00
FA
85
AF
FB
34
00
00
00
A1
20
00
FO
FA
81
20
20
20
65
FB
39
18
98
00
FO
65
92
44
20
81
05
AO
65
AG
20
FA
0790
0 79 8
07A0
07A8
0780
0788
07C0
07C8
0700
0708
00
00
20
98
B5
00
39
4C
44
07
20
20
92
07
A6
90
05
BA
07
20
68
31
FA
20
DE
0C
00
04
2 ~3
98
FA
FA
00
63
00
() 0
4C
20
44
90
20
81
9A
FA
1B
44
07
14
CA
FB
FA
00
00 20
FB
07
20
85
FA
20
1\5
EE
20
92
07
00
20
07
11
BS
4C
81
FA
A2
(J 0
20
44
ovJ 00 20
261
Appendix F
.
.
.
.
.
.
.
.
.
.
07E0
07E8
07F0
07F8
0800
0808
0810
0818
0820
0828
98
07
C9
F0
07
CF
07
B4
00
0C
C9
10
F0
8E
C6
C9
86
34
81
E8
27
02
22
00
90
00
E0
05
FB
E4
00
E8
E0
00
10
F0
20
A2
DO
84
14
20
20
01
02
09
00
00
10
00
20
CF
00
20
E8
20
EC
00
02
F3
98
FF
F1
GB
20
63
86
A0
00
20
0830
0838
0840
084 tl
0850
0858
0860
0868
0870
0878
17 07 20
A6 OF: D0
B0 DO 4C
00 80 00
02 A9 04
02 8E 0A
FF A9 16
00 20 64
FC C6 135
02 FF 4C
31
92
BA
02
A2
02
85
FC
00
BA
05 20
20 CA
04 20
AS FC
00 00
A9 93
B5 20
00 8S
F2 A9
04 A0
39
FA
81
80
80
20
06
FB
91
2C
05
00
FA
0E
09
02
Fe
84
20
20
0880
0888
0890
0898
08A0
08A8
08B0
08B8
08C0
08C8
79
A2
00
03
13
C9
FC
0E
00
45
05
00
48
FC
AC
E8
00
BO
BO
FO
20
00
20
00
1C
B1
88
51
S7
00
A1
BB
A2
02
FB
00
FF
FF
CA
FB
FC
06
F0
B0
F2
00
00
00
20
00
E0
0E
1C
06
20
F0
04
74
68
03
AS
20
FF
45
03
60
FC
20
00
FF
5C
90
FO
20
20
0800
0808
08E0
08E8
08F0
08F8
0900
0908
68
98
20
02
65
90
13
00
FC
20
22
38
FB
0B
29
FF
00
5C
07
A4
90
4A
07
00
AA
FC
A6
FC
01
80
09
80
E8
00
B4
AA
C8
17
80
04
00
8A
60
10
60
C9
4A
4A
01
86
AD
01
A8
22
AA
4A
C8
B4
1C
88
4A
F0
BO
4A
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
..
.
.
262
07
90
00
1C
90
FF
90
20
00
C8
17 07 20 31 05
Appendix F
0910 4A 29 0F 00 04 A0 80 A9
0918 00 00 AA 80 44 FF 00 85
.
.
.
.
.
.
.
.
.
.
.
.
0920
0928
0930
0938
0940
0948
0950
0958
0960
0968
FF
8F
08
88
81
20
90
F0
08
02
29
AA
4A
00
F8
Al
F0
60
02
A9
03
98
90
FA
20
FA
A2
A8
89
00
80
A0
08
C8
5C
00
03
89
9E
00
lC
03
4A
88
FC
CC
CC
5E
FF
A0
02 98 29
E0 8A F0
~l\ 09 20
00 F2 60
00 A2 01
lC 02 C8
09 02 90
FF 00 80
00 80 0C
05 0E 0C
0970
0978
0980
0988
0990
0998
09A0
09A8
0980
0988
02
69
4C
44
07
02
08
F8
20
04
2E
3F
31
07
A9
8E
FC
84
CA
20
08
20
05
20
04
0A
00
FC
FA
81
02
02
20
92
A2
02
20
20
00
FA
2A
FF
81
FA
00
20
64
35
80
00
88
CA
FA
00
00
34
FC
F3
E9
A9
00
00
00
20
80
05
00
F0
4C
03
F6
EA
20
44
09
20
85
05
8A
85
09C0
09C8
0900
0908
09E0
09E8
09F0
09F8
0A00
0A08
B5
F8
02
0A
A9
0A
FF
85
13
00
20
AO
85
02
03
02
00
91
E8
00
98
00
FC
F0
A2
20
85
A9
A9
80
07
02
4C
03
24
34
90
A0
2E
49
20
85
E7
20
80
05
AD
80
80
E8
08
FE
FB
02
09
78
FB
4E
48
AE
05
AD
00
FF
02
AO
FF
E8
E8
06
00
0E
60
8E
FA
00
CE
A9
02
0A10
0A18
0A 20
0A28
0A30
9A
80
80
8D
BA
4C
05
03
01
8E
55
02
02
02
06
D6
68
68
68
02
20
80
8D
80
58
C0
04
02
00
20
FC
02
02
00
34
68
68
68
02
05
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
co
263
Appendix F
.
.
.
.
.
0A38
0A40
0A48
0A50
0A58
20
20
00
F8
20
23
FE
02
20
35
0A60
OA68
0A70
0A78
0A80
0A88
0A90
0A98
0AA0
0AA8
0A80
0A88
0AC0
0AC8
0AOO
0A08
0AE0
0AE8
0AF0
0AF8
0800
0808
0810
0818
0820
0828
0830
0838
0840
0B48
.
.
.
.
.
.
..
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
264
05
04
85
17
F3
85
2 (j
FC
07
C9
85
31
AD
20
F7
A0
05
01
0E
F0
00
AD
02
FC
F9
00
00
85
00
20
35
FF
81
02
CA
3F
10
A2
lE
00
F3
F0
FA
A2
00
A0
02
00
F4
00
03
F9
05
88
132 20
C9 20
80 0F
03
4C
20
20
A2
4A
00
Cf
F0
20
4C
58
44
79
03
6E
F6
FF
F5
78
BA
FO
07
FA
68
04
00
8E
00
38
02
00
00
F7
A4
C9
84
02
8E
F0
00
00
5E
E0
03
AS
FC 85
E8 90
0B 02
04 E6
oc
uU 35
A6 FF
FF 00
FE 00
DO 1A
Ff C9
FB
10
A2
DE
AS
8E
BO
00
AC
E8
A9
02
00
F0
20
FE
FF
51
B3
FE
00
90
2F
20
E6
00
90
FF
CA
00
A4
20
AD
CA
FE:
00
08
00
00
00
AD
44
0C
FA
00
C5
8C
20
DO
A9
0B
07
02
00
DE
0C
9E
E2
lC
A9
11
CA
C9
20
07
30
E8
00
78
20
02
FF
A2
02
30
90
00
86
A2
"7
''"''
AA
00
0G
f0
B0
20
11
48
E9
6E
ED
Fe!
FE
F8
10
DB
DE
00
,. '-BC
20
E0
15
21
lI'~
DO CA 20 E8
DO E8 06
88
57
E0
FO
20
02
AC
C9
90
FF
FE
0A
OF
C5
lC
90
08
00
00
20
FE
B5
02
00
98
80
00
OF
00
00
F0
20
00
0850 05 AE 18 02 10 08 4C 9A
0858 FA 00 C8 00 FA AE 18 02
Appendix F
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
0860
0868
08 7 0
0878
0B80
0888
0890
0898
10
00
88
64
41
31
E6
86
F5
03
00
FC
20
05
FE
84
CA
89
F8
00
79
4C
00
A6
CA
FC
AS
85
05
08
00
85
8A
00
OE
F8
20
FO
11
00
AC
00
91
84
17
00
98
10
lC
91
F8
FC
07
A8
F0
02
02
F8
20
A0
20
20
0E
08
0BA0
08A8
0880
0888
08C0
08C8
0800
0808
08ECl
08E8
E8
30
40
30
40
40
00
00
44
40
86
90
02
22
02
02
00
00
9A
09
85
03
45
45
45
45
22
11
10
10
A6
C9
03
33
33
83
44
22
22
22
84
47
00
00
00
00
33
44
44
44
28
60
08
08
08
08
00
33
33
33
60
38
40
40
40
40
8C
00
00
00
C9
60
09
09
09
09
44
8C
08
08
08F0
08F8
0C00
0(:08
0C10
0C18
0C20
0C28
0C30
0C38
40
21
40
29
58
23
23
19
18
lA
09
81
91
2C
24
50
90
AE
23
58
62
82
92
23
24
88
8B
69
24
58
13
00
86
28
00
18
10
A8
53
AS
78
00
4A
24
00
Al
Al
19
19
69
A9
00
85
59
lC
9D
00
23
Al
24
00
00
90
00
8A
8A
00
24
00
24
00
59
2C
00
lC
ID
29
53
00
AE
0C40
0C48
0CS0
0CS8
0C60
0C68
0C70
0C78
0C80
0C88
AE
00
53
A0
88
94
28
A4
74
00
A8
15
84
08
54
00
GE
8A
74
00
AO
9C
13
62
44
00
74
00
72
22
29
60
34
SA
C8
B4
F4
00
44
00
00
9C
11
48
54
08
CC
AA
00
AS
AS
26
68
84
4A
A2
68 82
00 lA
7C
69
69
62
44
74
72
A2
32
lA
00
29
23
94
E8
84
F2
74
82
26
265
Appendix F
.
.
.
.
.
.
.
.
0C90
0C98
0CA0
0CA8
0CB0
0CB8
0CC0
0CC8
26
48
44
OB
013
FO
B9
33
72
44
50
FA
01
00
04
FA
72
44
2C
00
FB
04
7F
00
88
A2
41
30
00
FO
FO
AA
C8
C8
49
FB
F8
00
00
AA
C4
54
4E
00
FC
40
4A
AA
CA
46
00
5E
00
FO
FA
AA
26
48
00
FB
28
00
00
AA
.
.
.
.
.
06E0
06E8
06F0
06F8
79
E7
A7
4C
FA
90
E7
F7
00
09
B0
E7
20
60
DE
20
BE
20
AE
CD
E7
EB
06
FO
20
E7
02
CA
AA
20
9A
00
0738 81 FA 00 20 97 E7 20 92
.
.
.
0748 FA 00 20 CA FA 130 20 97
0750 E7 90 15 A6 OE 00 65 20
.
.
.
.
.
.
.
07C0
07C8
0700
0708
07E0
07E8
05
4C
97
E7
EB
E7
FO
56
E7
20
E7
90
00
FO
20
EB
C9
10
EE
20
92
E7
27
02
4C
81
FA
A2
00
E8
9A
FA
00
00
14
20
FA
00
20
00
20
CF
00
20
97
20
EB
FF
07F8
0800
0808
0810
0818
F0
E7
CF
E7
B4
lC
90
FF
90
20
8E
C6
C9
B6
00
00
90
00
E0
FO
00
10
F0
20
A2
01
02
09
00
00
20
E8
20
EC
00
BE
20
B6
86
A0
.
.
.
.
.
.
.
.
266
0600 20 EB E7 C9 20 F0 F9 60
0760 FO 20 A8 FA 00 20 05 FO
0798 00 20 81 FA 00 20 97 E7
07A0 20 92 FA 00 20 97 E7 20
07A8 EB E7 20 B6 E7 90 14 85
0830 6A E7 20 CO FO 20 05 FO
0840 B0 DO 4C 56 FO 20 81 FA
Appendix F
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
..
.
.
.
.
0878 D2 FF 4C 56 FD A0 2C 20
0880 15 FE 20 6A E7 20 CD FD
08E0 20 75 E7 A6 B4 60 AD lC
0980
0988
0990
0998
4C
97
E7
02
CD
E7
A9
8E
FO
20
04
0A
20
92
A2
02
81
FA
00
20
FA
00
00
D0
00
20
8D
FD
20
97
09
20
09A8
09B0
09B8
09C0
FB
20
FD
B5
84
CA
20
20
FC
FA
81
EB
20
00
FA
E7
01
B0
00
20
F3
E9
A9
A7
F0
4C
03
FD
05
56
85
D0
09E8 0A 02 20 D0 FD 78 AD FA
0AHl 9A 4C Fl FE 20 7B FC 68
0A30 BA 8E 06 02 58 20 D0 FD
0A38 20 BF FD 85 B5 A0 00 00
0A40 20 9A FD 20 CD FD AD 00
0A50 FB 20 SA E7 20 0E FC 00
0A58 20 01 F3 C9 F7 F0 F9 20
0A60 01 F3 D0 03 4C 56 FD C9
0A70 81 FA 00 20 97 E7 8E 11
0AA8 00 B0 0F 20 CB E7 A4 FB
0B38 90 20 97 E7 AC lC 02 F0
0B80 41 20 15 FE 20 6A E7 20
0B88 CD FD 4C 08 FD 00 A8 20
0CC0 55 FD 7F FD 00 4A FA 00
Appendix F
268
Appendix F
PET MICROMON
An Enhanced Machine
Language Monitor
Micromon is for Upgrade and 4 .0 BASICs, all memory sizes, all
keyboards and is in the public domain. If you have enough memory,
you can add the additional commands of "Micromon Plus" as well.
"Plus" is from $5BOO to $5F48 and you will want to move Micromon
from $1000 up to $6000.
There is quite a bit of typing here so there are two checksum
programs which will find and flag any errors. See the instructions for
typing in Supermon.
Micromon Instructions
SIMPLE ASSEMBLER
.A 2000 LOA #$12
.A 2002 STA $8000,X
.A 2005 OEX:GARBAGE
In the above example, the user started assembly at 2000 hex . The first
instruction was load a register with immediate 12 hex. In the second
line the user did not need to type the A and address. The simple
assembler retypes the last entered line and prompts with the next
address. To exit the assembler, type a return after the address
prompt. Syntax is the same as the Disassembler output. A colon (:)
can be used to terminate a line.
BREAK SET
.B 1000 OOFF
The example sets a break at 1000 hex on the FF hex occurrence of the
instruction at 1000. Break set is used with the QUICK TRACE
command. A BREAK SET with count blank stops at the first
occurrence of the break address.
COMPARE MEMORY
.C 1000 2000 COOO
269
Appendix F
Fills the memory from 1000 hex to 1100 hex with the byte FF hex.
GO RUN
.G
Go to the address in the PC Register display and begin run code. All
the registers will be replaced with the displayed values .
. G 1000
cooo
0000 'READ
Hunt through memory from COOO hex to 0000 hex for the ASCII
string "read" and print the address where it is found. Maximum of
32 characters may be used .
.H
cooo
0000 20 02 FF
Hunt memory from COOO hex to DOOO hex for the sequence of bytes 20
02 FF and print the address. P. iOCt,"(ir.uLlln of 32 bytes may be used .
Hunt can be stopped with the STOP key.
KILL MICROMON
.K
Restore the Break vector and IRQ that was saved before Micromon
was called and break into the TIM monitor. A return to Micromon can
be done with a Go to the value in the PC register.
LOAD
.L "RAM TEST",08
270
Appendix F
Load the program named RAM TEST from the disk. Note for cassette
users: To load or save to casse tte. Kill Micromon with th e K command
to return to the TIM monitor. Then use the TIM monitor Land S
commands to load and save to th e cassettes. This has to be done
because of the repeat keys of Micromon . BASIC 4.0 u sers then can
return to Micromon with a Go command to the PC value, but BASIC
2.0 users should return to BASIC, then SYS to Micromon because the
TIM overwrites the IRQ value for loads and saves w ith a filename.
MEMORY DISPLAY
.M 0000 0008
.: 0000 30 31 32 33 34 35 36 37 1234567
.: 0008 38 41 42 43 44 45 46 47 89ABCDE
Display m emory from 0000 h ex to 0008 in hex and ASCII . The bytes
following the address may be m odified by editing and then typing a
RETURN.
Memory displ ay can also be done w ith the cursor control keys.
NEW LOCATER
.N 1000 17FF 6000 1000 1FFF
.N lFBO 1FFF 6000 1000 1FFF W
The first line fixes all three byte instructions in th e range 1000 hex to
IFFF hex by adding 6000 hex offset to the bytes following th e
instruction. New Locater w ill not ad just any instruction outside of the
1000 hex to 1FFF h ex range. The second line adjusts Word values in
the same range as th e first line. New Locater stops and disassembles
on any bad op code.
CALCULATE BRANCH OFFSET
.0 033A 033A FE
Calculate the offset for branch instructions. The first address is the
starting address and the seco nd address is the target address. Th e
offset is then displayed.
QUICK TRACE
.Q
.Q 1000
271
Appendix F
Displays the register values saved when Micromon was entered. The
values may be changed with th e edit followed by a RETURN.
SAVE
.S "l:PROGRAM NAME",08,0800,OC80
Save to disk drive #1 memory from 0800 hex up to, but not including,
OC80 hex and nam e it PROGRAM NAME. See note in LOAD
command for cassette users.
TRANSFER MEMORY
.T 1000 1100 5000
Transfer memory in the range 1000 h ex to 1100 hex and start storing it
at address 5000 hex.
WALK CODE
.W
Single step starting at address 1000 hex. Walk will cause a single step
to execute and will disassemble the next instruction. Stop key stops
walking. The Jkey finishes a subroutine that is walking, then
continues with the walk.
EXIT TO BASIC
.X
Return to BASIC READY mode. The stack value saved when entered
will be restored. Care should be taken that this value is the same as
when the monitor was entered. A CLR in BASIC will fix any stack
problems. Do not X to BASIC then return to Micromon via a SYS to
the cold start address. Return via a SYS to BRK (SYS 1024) or SYS to
the Warm start of Micromon (Warm start = Cold start + 3). An X and
cold start will write over th e TIM break vector that was saved.
CHANGE CHARACTER SETS
.Z
A hex number is input and the decimal value, the ASCII for the two
bytes, and the binary values are returned. The ASCII control values
are returned in reverse.
Hex conversion can also be scrolled w ith th e cursor control keys.
DECIMAL CONVERSION
.#16706 4142 A B 0100 0001 0100 0010
272
Appendix F
A d ecimal number is inpu t and th e hex value, the ASCII for the two
bytes, and the binary va lu es are returned.
BINARY CONVERSIO N
.%010000010100001 0 4142 16706 A B
A bin ary num ber is inpu t and th e h ex value, the decim al number, and
th e ASCII valu es are re turn ed .
ASCII CONVERSION
." A 41 65 0100 0001
3333
The two hex numbers input are added , and the sum displayed .
SUBTRACTION
.-3333 1111 2222
The second number is s ubtracted from the first number and the
difference displaye d .
CHECKSUM
.& AOOO AFFF 67E2
C
D
E
F
G
H
K
L
M
N
Q
R
S
T
W
X
Z
$
273
Appendix F
BINARY CONVERSION
ASCII CONVERSION
ADDITION
SUBTRACTION
CHECKSUM
+
&
Old Value
New Value
X3E7
X3EC
X3F6
X427
XD18
XDA3
XCFC
XD7B
XE16
XE20
XE24
XE26
XE37
XE46
X681
08
08
08
08
08
08
28
28
83
28
CO
04
27
28
24
10 To display 16 instead
10 of 8 bytes .
10
10
10
10
50 To fix scroll.
50
87
50
80
08
4F
50
00 To print all characters
in Walk command .
PRINTING DISASSEMBLER
. (Shift) D 1000 lFFF
The same as the Disassembler but no ., printed before each line. Also
the ASCII values for the bytes are output at th e end of the line.
FORM FEED SET
.1
Sets a form feed for printout . Gives 57 printed lines per page . Works
with the Shift D and Shift M commands .
.I "Heading"
Sets form feed with a message to be printed at the top of each page .
.1
Appendix F
Kill Micromon and its additions and BRK to the TIM monitor. This is
the same as the unshifted K command except now a G command will
reinitialize Micromon and the additions .
LOAD FROM DISK
.(Shift) L "filename"
This is the same as the normal load command except that the disk
(device #8) is used as the default, not the cassette.
PRINTING MEMORY DUMP
.(Shift) M FOOO FlOO
The same as the normal Memory dump, but does not print the .: r:nd
prints out 16 hex bytes and the ASCII for them.
PRINT SWITCHER
.r
If the output is to the CRT then switch the output to the printer
(device #4). If the output is not to the CRT then clear the output
device and restore the output to the CRT.
. r06
This is for 8032 and Fat 40's to go from Text to Graphics mode or vice
versa .
275
Appendix F
DOS SUPPORT
.@or.>
This reads the directory from disk device number 8. The SPACE BAR
will hold the display, any other key will start it again, and the STOP
key will return to command mode.
CONTROL CHARACTERS
.(Up arrow)g
This command will print the con trol character of th e ASCII character
input.
Examples of controls:
g
M
n
N
q
Q
s
S
u
v
Ring bell
Tab set and clear
Insert line
Text mode
Graphics mode
Cursor down
Cursor up
Home cursor
Clear screen
Delete line
Erase end
Erase begin
PRINTING DISASSEMBLER
HEADING AND FORM FEED CONTROL
J PRINT LOAD ADDRESS
(Shift) K KILL MICROMON ADDITIONS
(Shift) L
LOAD FROM DISK
(Shift) M PRINT MEMORY DISPLAY
PRINTER SWITCHING
P
SEND TO PROM PROGRAMMER
U
SPECIFY LOAD ADDRESS
Y
(Shift) z
TEXT /GRAPHICS FLIP
> DOS SUPPORT COMMANDS
@
DOS SUPPORT COMMANDS
(Up arrow) CONTROL CHARACTERS
I
276
Appendix F
Program 2. Micromon.
1 000
1 008
1010
101 8
1 020
1028
1030
1 038
104 0
1048
1 050
1 058
10 60
4C
FF
93
F6
8E
lF
91
lF
02
90
lF
35
84
0C
4C
80
IF
E4
85
CO
F0
AD
86
E0
85
02
10
02
E5
AE
02
92
EE
10
EE
91
80
30
80
4C
FF
02
F7
AD
86
lF
80
lF
AD
B0
86
85
6F
78
8E
IF
F0
93
00
9E
AE
EC
08
31
02
10
A5
E6
80
iF
A5
05
02
EF
iF
85
A9
A9
4C
92
02
E3
AE
90
EC
8E
lF
AE
34
10
00
CF
A6
AD
02
Fl
A6
EF
9F
85
ED
86
80
80
277
Appendix F
H168 86 02 8D A2 02 58 00 38
1070 AD 7B 02 E9 01 8D 7B 02
1078 AD 7A 02 E9 00 8D 7A 02
278
1080
1088
1090
1098
10A0
10A8
10B0
10B8
10C0
10C8
10D0
10D8
10E0
10E8
10F0
10F8
20
29
20
20
8D
18
F5
8D
IF
6C
02
FB
94
00
09
A2
55
18
09
09
A2
C9
A2
87
85
FB
A2
D0
02
8D
20
02
19
A9
10
10
02
2E
ID
02
FB
00
02
09
D6
8C
52
B5
A2
52
20
A9
A2
F0
DD
8A
BD
CA
D0
B4
FC
02
19
FA
42
D0
55
00
FF
F9
92
0A
Bl
10
02
FC
D6
20
CA
48
A9
23
19
8D
9A
C9
1F
AA
IF
E5
A2
D0
FB
4F
D0
BD
2A
A9
A9
94
20
20
D0
BD
85
6C
00
03
60
12
FA
91
20
3F
2E
02
A4
F0
13
B0
FC
E3
B4
EE
A9
A2
60
02
1100
1108
1110
1118
1120
1128
1130
1138
1140
1148
1150
1158
1160
1168
1170
1178
95
Fl
4C
E5
A8
02
17
3C
03
FD
AC
0A
85
F8
B0
AC
FA
60
17
FB
0D
A9
20
18
4C
D0
94
11
FD
10
53
94
68
AD
11
8D
91
01
55
90
C5
02
02
18
98
20
20
02
9D
92
A5
91
02
8D
19
IB
11
E6
D0
AD
65
7F
Dl
D0
91
02
FD
02
60
95
20
20
20
FE
45
91
FE
11
10
ID
02
AC
A4
98
A9
02
13
0A
7F
20
F0
02
85
20
20
F0
CA
93
FE
E5
00
20
11
11
11
3B
E5
65
FE
0A
D5
EB
D0
02
38
FC
F0
E6
20
B0
E6
19
20
FD
20
11
10
A2
Appendix F
1180
1 .J.vv
100
1190
1198
llA0
llA8
llB0
1188
llC0
llC8
1100
1108
l1E0
l1E8
llF0
llF8
00
81
18
01
20
18
02
AD
00
20
18
00
E8
E0
02
02
Al
FO
20
60
0B
90
D0
89
EC
01
A2
14
20
20
20
E8
F8
C1
52
4C
18
17
12
02
4C
18
00
7.0
06
00
77
20
AC
FO
19
93
20
80
20
81
8E
20
20
A4
10
Fl
18
06
95
FO
20
10
A4
89
13
F8
10
0B
A4
18
C9
F0
90
10
02
08
AE
20
18
02
11
20
4C
18
18
90
0D
lC
CC
C9
F0 02
13
18 F0
01 18
20 6F
AE 94
90 0D
38 19
93 10
20 A4
C9 27
A3 02
F0 22
8E 97
90 A3
00 F0
1200
1 208
1210
1218
1220
1228
1 230
1238
1240
1248
1250
1 258
1260
12 68
1270
1 278
09
00
A2
02
00
AC
B0
20
E7
00
47
20
20
14
02
A1
20
EC
00
00
F2
94
DE
13
10
EE
19
0E
22
AC
C9
12
6F
8E
A0
0A
20
02
4C
11
20
20
20
lE
13
8B
E8
88
18
88
00
C8
8E
00
93
90
A8
83
13
48
A2
02
81
00
90
02
Bl
E8
11
05
10
00
12
15
18
20
06
F0
FB
Fl
BC
20
F8
EC
20
20
20
A0
20
00
20
08
E0
OF
80
E0
55
DO
88
38
13
39
2C
AE
E3
52
13
03
AD
lD
0E 96
20
19
A3
02
19
11
14
20
18
20
19
68
00
96
20
02
1280
1288
1290
1298
1 2AO
12A8
12B0
90
80
CA
E8
8A
88
12
0E
EF
00
00
8E
02
85
BO
1E
02
01
88
60
F8
E9
F0
60
C8
02
AD
84
1E
03
20
98
20
8B
FC
20
20
87
20
lA
02
60
15
15
AA
12
AE
86
A4
'){;\
<"'1.I
AD
AD
12
Al
18
20
38
279
Appendix F
280
1288
12C0
12C8
1200
1208
12E0
12E8
12F0
12F8
FC
01
80
09
04
04
lE
02
E0
AA
C8
17
80
4A
A0
80
98
8A
HJ 01 88 65 F8 90
1300
1308
1310
1318
1320
1328
1330
1338
1340
1348
1350
1358
1360
1308
1370
1378
4A
00
A2
C8
Fl
02
00
02
09
20
A0
CO
CO
AS
83
24
09
F2
01
90
60
89
A0
2A
10
01
2C
F8
F9
97
02
C9
20
60
20
F0
A8
36
05
88
CA
18
4C
IF
IF
1380
1388
1390
1398
13A0
13A8
1380
1388
13C0
13C8
1300
1308
13E0
F0
85
02
97
48
48
20
68
14
11
18
19
20
05
02
AS
A9
AD
6C
A4
49
AE
90
00
A2
52
A8
22
AA
4A
A9
02
8F
08
4A
F0
BO
4A
00
29
AA
4A
90
13
98
29
AA
03
98
90
08
29
lE
elF
80
80
A0
08
88
81
Fl
A2
89
IF
0E
00
00
A9
50
00
00
",..., 83
A9 10
FF F0
00
F8
10
03
F6
80
93
F6
EA
03
15
08
03
02
80
20
FA
20
CC
C0
lE
93
02
69
4C
20
80
80
20
F0
84
AD
C8
Al
88
03
80
02
2E
3F
52
AC
05
06
07
CE
00
9E
02
F2
9E
18
FF
94
08
EE
2E
19
02
A9
08
A8
48
80
19
AE
00
06
4A
3A
13
00
02
A9
AD
08
89
19
12
00
13
12
20
18
16
80
00
F3
48
02
00
20
20
20
20
29
A9
60
C9
4A
4A
80
96
29
F0
~u
84
11
00
85
IF
02
20
4C
02
20
4C
A9
20
4A
07
80
00
DC
88
03
4A
88
12
.02
90
92
A9
92
20
19
13
01
01
18
0A 8D
02 00
84 02
CE
85
85
IF
48
48
F8
39
13
AE
55
18
08
Appendix F
13E 8 20 03 19 A9 08 20 B9 13
13F0 A9 12 20 09 10 A0 08 A2
13F8 00 Al FB 29 7F C9 20 80
1400
1408
1410
1418
1420
1428
1430
1438
1440
1448
1450
145 8
14 60
1468
1470
1478
02
F0
20
20
4C
20
13
15
20
06
85
02
90
CA
3F
A3
A9
04
09
3B
09
AC
A9
20
06
18
FO
20
80
30
A0
02
2E
C9
10
19
10
13
3A
01
10
4C
86
A4
02
14
05
88
20
62
A9
88
20
20
80
18
C9
55
FE
18
E8
BO
4A
00
09
00
22
00
01
B3
6F
85
00
19
A2
C9
E0
80
6E
F6
10
0A
20
DB
18
15
02
FO
F0
20
00
20
03
02
A4
F0
C9
A9
09
A9
A9
20
4C
86
03
4C
8E
F0
00
38
02
E9
22
14
10
92
08
06
5C
FE
20
18
A4
F4
Fl
E9
6E
A2
1480
1488
149 0
1498
14A0
14A8
14B0
14 B8
14C0
14C8
1400
1408
14E0
14 E8
14F0
14 F8
02
C9
20
A4
90
00
94
94
8E
84
A2
02
A9
00
E9
F0
20
3A
A4
FB
A3
07
02
02
93
15
06
F0
30
Fl
1E
03
06
F0
15
84
02
8E
A2
20
02
BO
E0
0F
B0
0E
20
20
10
lE
B0
FC
E8
92
00
C3
AA
F6
03
AD
lE
96
84
84
C9
C9
01"
85
90
02
8E
12
BO
lE
00
96
20
02
15
IS
00
20
20
FB
A3
A2
89
AE
36
20
14
02
81
90
BO
CA
F0
F0
84
A9
02
00
02
96
IF
84
AC
C9
15
0E
EF
00
22
Fl
18
30
E8
8E
AD
02
20
15
8B
E8
88
BO
1E
02
15 00 F0 06 20 8 1 15 20 81 15
15 08 AD 9 2 02 CD 89 02 F0 03
281
Appendix F
282
AC
C9
0A
6A
02
02
88
A0
20
80
20
02
88
9[1
98
10
10
91
91
B3
A9
A5
80
8E
85
18
02
90
30
91
88
FB
FB
15
20
FC
72
73
9E
15
A3
02
10
60
38
A9
4 l>.
0F
68
02
80
02
AD
08
02
8E
02
F0
E8
C9
60
91
4A
4C
29
8C
7B
A9
13
68
68
88
F0
03
8E
30
CD
4C
20
32
EF
7F
02
80
E8
80
8D
02
00
4C
89
90
8C
09
32
18
80
02
68
80
10
7F
7D
AE
68
82
02
03
02
10
18
80
7C
68
69
86
03
02
02
02
02
80
07
02
2C
CD
CD
68
A5
81
18
29
86
99
98
80
90
02
AD
10
02
02
02
78
80
8A
12
Fel
50
D0
00
02
82
8E
E8
03
IF
6D
65
1510
151 8
1 520
1 528
15 30
l538
1540
15 48
155 0
l558
15 60
1 568
1570
157 8
4C
02
00
00
08
60
03
F8
8C
10
02
15
FB
74
91
F0
IF
SF
C8
:i 5
2E
20
AE
00
20
AD
13
91
65
3C
93
11
02
AE
CA
\- /""\
GA
M\-
B9
AD
6F
20
80
8E
20
~j 2
FC
94
02
A8
75
71
B8
A9
00
02
20
12
02
02
15
07
1 580
15 88
1590
15 98
15 A0
15A8
15 80
1588
15C 0
15C8
1500
1508
15E0
15E8
15F0
15F8
10
89
68
14
AE
C9
00
48
AA
70
02
18
00
02
4C
68
20
02
EE
4C
88
47
03
4A
68
02
8E
69
80
00
55
80
84
DO
94
BE
02
60
60
4A
29
08
7E
01
7A
21
13
7E
1600
1608
1610
161 8
162 0
1628
1630
1638
68
68
02
80
58
4C
AD
AD
80
80
A5
02
AD
6F
7A
78
7C
7A
91
20
7C
10
02
02
,....
.r-
D(J
00
41
E7
70
88
A5
02 80
4C 93
Appendix F
1640
1648
1650
1658
1660
1668
1670
1678
AD
D0
14
02
1F
20
20
02
9C
55
4E
9A
48
30
0B
85
02
A9
86
AD
4C
19
19
FB
D0
80
02
F5
1F
8D
AD
86
5D
8D
90
1F
17
89
7B
FC
AD
86
D2
48
20
02
02
20
9D
02
AE
AD
55
A0
AE
52
02
30
80
F4
19
00
7A
19
1680
1688
1690
1698
16A0
16A8
16B0
16B8
16C0
16C8
16D 0
16D8
16E'1
16E8
16F0
16F8
A9
20
03
A9
9D
C9
A2
12
9C
02
10
5C
06
19
A0
12
24
E4
4C
'11
02
EE
53
AD
'12
A9
C9
2'1
10
AD
8D
E8
8D
FF
93
8D
CE
F0
4C
9A
8E
8'1
'1D
6'1
C9
86
4E
AD
8C
F0
10
86
9C
'14
85
02
9D
8D
F0
18
0D
02
E8
F0
02
FB
C9
02
02
C9
10
AE
'12
86
11
20
D0
F0
CE
1F
20
C9
4A
D'1
AD
6F
A9
9B
A9
02
C9
FC
4F
22
13
AE
52
03
D0
4F
12
D0
'10
'12
40
20
20
18
20
78
E8
F1
12
D0
56
CE
E8
3E
F'1
8D
D'1
'16
D0
20
55
A9
2C
1F
17'10
1708
1710
1718
172'1
1728
1730
1738
174'1
1748
1750
175 8
1760
1768
8D
A2
AE
85
7A
7C
'12
20
02
02
9B
8D
18
5D
82 02
00 8D
80 '12
91 AD
02 48
02 48
AC 7F
4C 18
A9 '10
20 5D
02 4C
A0 02
8D 8D
18 8D
8E
48
9A
82
AD
AD
'12
8D
8D
18
93
8E
02
8F
81
E8
78
'12
7B
7D
40
98
9A
8D
1'1
A1
8E
02
02
8E
AD
85
'12
'12
4C
02
02
9A
20
02
8E
8E
A9
49
81
90
48
AE
8E
8E
8D
02
E6
20
'12
90
3B
E8
02
AD
AD
7E
10
99
9B
8E
17
5D
20
'12
283
Appendix F
177 0 20 06 1 0 C9 00 F0 0A 20
177 8 06 1 0 C9 57 00 03 EE 8C
3C
0A
11\
F6
93
33
Bl
FB
8F
Fl
A0
Al
10
FD
02
60
18
11
Bl
IE
10
F0
FB
ED
02
FB
02
02
FA
86
8E
18
AE
90
FB
00
AC
03
AA
8E
Fl
90
91
91
30
FE
93
85
94
13
20
06
8B
8C
ED
02
FB
10
FB
FB
9E
20
02
FB
02
AC
C3
20
02
8B
8D
90
C8
88
C8
20
20
50
20
86
00
8C
12
E7
C0
02
02
IE
AD
18
Bl
3B
4C
18
A4
FC
4C
03
60
48
AA
8A
18
3A
FC
F3
A4
18
18
01
97
D0 09
18
20
AS
4A
68
20
69
60
95
60
18
80
90
60
02
20
B0
50
FC
4A
29
09
F6
A2
FA
A9
C9
08
07
4C
20
A4
F6
18
20
4A
0F
10
90
02
68
00
20
20
AA
8E
A4
18
20
85
lA
4A
20
68
02
85
95
80
F0
A4
20
10
18
C9
60
FO
18
20
32
4C
69
FA
FC
97
F9
18
6F
A9
C9
20
17 80
17 88
17 90
17 98
17A 0
17A 8
17 B0
17B 8
17C0
17C8
17D0
17D 8
17E0
17E8
17F0
17F8
02
18
02
AA
10
02
88
C8
88
90
8A
FB
19
18
80
18
20
20
00
BD
4C
00
38
Bl
AD
02
60
60
88
85
92
20
180 0
1 808
1 8 10
1818
18 20
182 8
1830
183 8
1 840
184 8
1 850
1 858
1 860
186 8
1 870
1 878
60
18
86
AS
32
18
09
06
48
CA
02
20
20
18
00
20
20
B0
FE
FB
18
48
10
69
B5
00
20
84
6F
90
80
1 880 00 0F 1 8 60 20 99 1 8 0A
188 8 0A 0A 0A 80 97 02 20 A4
284
Appendix F
189 0
189 8
1 8A0
J. 8A8
1 8B0
18 B8
18C0
18C8
18013
18D8
18E0
18ES
18F0
18F 8
18
60
02
0D
C9
85
13
18
85
78
E8
SD
AD
85
20
C9
69
00
EF
9E
E8
D0
80
AD
A9
11
EE
91
99
3A
08
F8
00
28
6A
08
A9
40
7F
ES
IF
28
18
08
60
4C
07
60
90
20
00
E8
80
A9
85
613
0D
29
20
93
08
20
F7
D7
85
09
4E
3D
90
80
97
0F
06
10
20
C6
60
18
AF
113
E8
8D
AD
7B
02
28
10
AS
CC
18
20
A9
613
80
A9
13
EF
132
38
90
C9
9B
FF
AD
AE
133
138
40
3C
E8
IF
8E
19 130
1908
1910
1918
19 20
1928
19 30
1938
19413
1948
195 13
195 8
19613
1968
1970
1978
7A
213
20
613
81
10
A9
A9
FC
48
29
09
09
3B
lA
20
132
52
3B
20
FB
213
7C
05
013
213
18
10
10
213
18
52
613
19
19
6F
Cl
3B
85
60
133
55
A9
A2
E8
47
AD
19
8D
Bl
CE
18
FB
19
FB
E6
EE
19
213
00
E0
19
7B
AD
89
FB
89
90
F0
CE
A9
FB
94
68
2C
BD
lC
AD
132
81
02
20
02
0B
03
89
132
00
02
A2
A9
76
00
7A
20
132
Aa
lA
00
A2
4C
132
85
07
613
2E
IF
F5
02
lA
20
1313
18
F0
013
8E
60
FC
E6
98
213
4C
20
A0
20
18
lA
1980
19 88
1990
1998
19A0
19A8
1980
19B8
18
30
4C
18
81
20
F0
9A
AD
19
8E
20
02
A4
DB
6C
82
20
113
50
20
18
20
94
02
03
213
18
30
20
613
013
20
19
4C
80
19
19
lC
4C
lA
4C
18
82
80
19
AE
8E
18
93
20
02
89
00
813
10
20
10
FC
8E
02
F8
02
A0
aD
285
Appendix F
286
19C0
19C8
1900
1908
19E0
19E8
19F0
19F8
01
84
85
F9
DB
C9
C8
87
84
90
OA
C9
20
00
C0
02
04
A9
20
0D
06
F0
10
C9
88
02
06
F0
10
0B
F0
4C
84
85
10
lA
C9
91
C7
00
01
DB
C9
C9
22
OA
00
El
84
A9
20
22
F0
E6
EA
AD
96
A3
F0
00
36
01
AD
00
lA00
lA08
lA10
lA18
lA20
lA28
lA30
lA38
lA40
lA48
lA50
lA58
lA60
lA68
lA70
1A78
C0
4C
56
10
10
F0
C9
10
E6
2C
86
F9
C9
40
10
4C
C9
12
F3
00
C9
20
03
C9
20
00
CA
C9
53
00
C9
93
40
lA
20
El
00
6F
F0
00
F9
F4
20
00
00
06
4C
10
00
C9
BC
4C
F0
18
FA
F0
17
20
06
00
F7
20
00
20
06
4C
18
93
02
29
85
BA
20
60
10
EC
AD
A4
04
01
20
00
AS
10
C9
0F
04
C9
06
18
C9
AD
00
F6
20
18
22
AD
96
20
2C
F0
20
2C
10
85
20
87
C0
4C
E3
20
F3
20
29
06
00
C3
06
00
C9
C9
F0
02
C9
93
F6
3B
lA80
lA88
1A90
lA98
lAA0
lAA8
lAB0
lAb8
lAC0
lAC8
lAD0
lA08
lAE0
lAE8
19
52
00
08
06
8E
4C
A9
20
19
52
92
09
A6
20
19
15
C8
20
10
93
24
2F
20
19
02
10
FB
3B
20
AD
D0
lA
20
10
20
lB
CC
A2
2E
CA
80
19
13
91
0B
18
01
20
29
20
lA
04
93
00
93
20 0B 18 20
11 90 0A 98
02
AD
4C
18
55
18
E6
20
A9
02
EF
02
30
91
93
20
19
20
1A
CF
30
69
60
8E
10
02
10
C0
A2
13
20
lA
18
00
AS
92
10
10
4C
lA
2E
18
52
20
0E
20
FC
02
Appendix F
lAF0 20 52 19 A5 FC 20 FA lA
lAF8 AS FB AA 20 52 19 8A 29
IB00
IB08
IB10
IB18
IB20
IB28
IB30
IB38
IB40
IB48
IB50
IB58
IB60
IBb8
IB70
IB78
7F
20
8A
C9
10
05
52
C0
C0
8E
52
4C
FC
FB
00
20
C9
09
20
62
A9
A9
19
C0
4C
10
19
93
20
20
F7
06
20
10
09
00
22
92
A6
40
00
20
20
10
17
78
08
10
08
8A
10
0A
20
20
FB
00
03
5B
13
A2
lC
IB
20
C9
B0
18
C9
A9
09
09
A5
03
4C
IB
18
04
20
20
52
00
0A
69
22
14
10
10
FC
4C
83
B0
20
A9
83
92
19
F0
A9
40
F0
20
28
60
AC
09
CF
F8
C3
00
IB
IB
28
0F
12
AA
04
09
B0
20
00
DC
4C
20
lA
85
85
CA
60
C9
IB80
IB88
IB90
IB98
IBA0
IBA8
IBB0
1 BB8
IBC0
18C8
IBD0
IB08
IBE0
IBE8
IBF0
IBF8
20
3A
18
FB
26
65
AS
65
8D
20
52
IB
93
20
lA
85
F0
B0
60
48
FC
FC
FE
FC
93
52
19
20
10
13
4C
FB
0B
BC
85
06
68
85
65
85
02
19
68
52
20
18
93
85
C9
29
FE
FB
65
FC
FB
FC
48
68
AA
19
F4
20
10
FC
30
0F
AS
26
FB
06
85
60
48
20
A9
20
IB
2F
A2
20
90
60
FC
FC
85
FB
FB
20
20
lA
00
CC
20
IB
0F
17
C0
68
48
06
FB
26
A9
17
52
18
20
lA
52
20
A9
lC
C9
68
AS
FB
68
FC
00
lC
19
20
36
4C
19
E6
00
20
lC00 83 IB 20 11 lC 20 78 IB
1C08 20 11 lC CA 00 F7 4C 52
287
Appendix F
288
lC10
lC18
lC20
lC28
lC30
lC38
lC40
lC48
lC50
lC58
lC60
lC68
lC710
lC78
19
A4
02
93
20
85
4C
11
20
10
78
92
02
2A
4A
18
40
10
2A
FB
50
84
52
20
AO
86
85
lC
26
C9
4C
20
lC
A5
lC
FC
19
60
E5
93
90
20
FB
20
E8
0B
18
FC
20
AD
20
lC
02
AD
86
3C
26
F0
80
18
AS
65
2A
91
13
00
AE
9E
91
18
FC
F9
4C
4C
FB
FE
lC
02
18
6C
E6
02
58
20
lC80
le88
lC90
lC98
lCA0
lCA8
lCB0
lCB8
lCC0
lCC8
lC00
lC08
lCE0
lCE8
lCF0
lCF8
A0
210
00
92
02
88
AO
10
00
AO
08
FO
9C
3A
24
38
00
13
18
02
80
lC
92
AO
06
6F
C9
AS
02
F0
F0
AS
8C
11
A0
80
93
AO
02
A2
68
02
18
C5
A0
lA
12
FO
92
90
00
92
02
93
20
02
A8
C9
00
85
01
C9
CE
E9
02
10
18
02
20
02
lA
00
68
11
EO
FE
20
2C
9C
28
8C 93
94
Bl FB
98 60
3B 19
20 l A
18 4C
04 AS
AA 68
00 70
A5 C4
A9 19
8C IE
F0 1 6
02 F0
85 FO
60
93
4C
18
93
9E
40
AS
85
80
C9
C9
CA
B0
1000
1008
1010
1018
1020
1028
1030
1038
El
20
C9
08
06
lA
00
12
C6
45
3A
85
13
210
80
A9
FE
IE
00
FB
4C
0E
8C
00
00
B0
11
90
39
IE
02
85
DO
B5
18
02
10
20
A0
9E
80
AO
A5
E6
C9
AB
2C
4C
102
02
69
20
F0
A9
4F
12
60
60
E8
F6
65
85
20
85
4C
EC
02
AE
60
52
AD
87
87
FB
FC
24
12
20
4A
20
A9
4C
17
FO
FC
13
FB
93
IF
85
9F
20
19
02
02
Appendix F
1040
1048
1050
ID58
10G0
1068
1070
1078
4C
lA
AS
A5
02
F0
F0
A5
C2
4C
08
C5
A0
lA
12
FO
lC
39
00
85
01
C9
CE
69
20
10
EC
FE
20
2C
9C
28
3B
C9
A5
A9
8C
F0
02
85
19
91
C4
19
lE
16
F0
FO
20
00
85
80
C9
C9
15
90
B3
F0
FO
9C
3A
24
18
El
1080
1088
ID90
1098
IDA0
10A8
10B0
10B8
10C0
10C8
1000
1008
10E0
10E 8
10 F0
10F8
E6
45
87
F0
AS
C6
9E
15
4C
A6
80
02
FC
13
02
02
FE
lE
02
10
FB
FC
20
lE
AO
FC
9C
85
20
11
00
20
00
90
C9
00
E9
20
40
20
10
85
02
FB
0E
F0
E0
B9
00
03
3A
27
08
09
lE
05
20
FO
38
A5
lE
07
EE
13
80
4C
F0
20
85
13
4C
10
15
86
A5
FE
20
B0
8B
A2
87
C2
06
15
FB
A9
96
20
lE
FE
FO
E9
AB
F3
02
00
02
lC
C9
lE
B0
00
10
B6
A5
A9
EO
00
12
CE
AO
Al
20
AO
24
38
02
85
20
lA
FB
10
9C
85
20
9C
8B
FB
lE00
lE08
lE10
lE18
lE 20
lE28
lE30
lE38
lE40
l E48
lE50
lE 58
lE60
lE68
8E
20
Al
C8
28
Bl
C8
A9
A9
02
F0
75
80
0A
8C
52
FB
85
85
C7
C6
20
13
38
F3
lE
A2
AS
02
12
4C
FE
FO
91
FE
90
4C
60
88
85
02
A9
A9
4C
C3
A9
A0
FO
CA
00
09
20
20
FB
85
A4
2C
AD
12
00
C0
20
10
A9
85
A2
00
Fl
CA
C0
lE
lE
FC
A5
91
40
A2
83
C7
04
F8
A2
10
28
C9
AA
A9
AA
C4
19
00
85
A9
88
C6
27
FA
00
20
20
98
00
80
10
8C
75
86
A7
Cb
FF
F0
A9
289
Appendix F
lE70 00 85 AA 18 60 20 BC lE
lE78 20 99 18 0A 0A 0A 0A 80
290
lE80
lE88
lE9f2J
lE98
lEA0
lEA8
lE80
lE88
lEC0
lEC8
lED0
lE08
lEE0
lEE8
lEF0
lEF8
97
00
7F
40
30
40
40
00
11
10
10
62
00
85
59
lC
02
97
C9
02
22
02
02
22
22
22
22
13
00
90
00
23
20
02
20
45
45
45
45
44
44
44
44
78
59
2C
58
50
8C
60
80
03
33
33
83
33
33
33
33
A9
40
29
24
88
lE
81
02
00
00
00
00
00
00
00
00
00
91
2C
24
18
20
FO
09
08
08
08
08
8e
8C
08
08
2l
92
23
00
Al
99
C8
40
40
40
40
40
44
44
40
40
81
86
28
lC
90
18
29
60
09
09
09
09
00
9A
09
09
82
4A
24
8A
8A
1F00
1F08
1F10
IF18
IF20
IF28
IF30
IF38
IF40
1F48
IF50
1F58
IF60
1F68
IF70
1F78
10
19
18
58
A8
6D
34
5A
C8
08
CC
A2
82
26
26
20
23
AE
23
58
AD
ge
11
48
54
84
4A
A2
32
26
48
20
90
69
24
A5
29
A5
A5
26
68
74
72
74
82
72
44
20
88
A8
53
69
00
69
69
62
44
84
F2
74
00
72
44
50
10
19
19
24
7e
29
23
94
E8
28
.\4
74
22
88
A2
43
Al
23
A1
24
00
53
A0
88
94
6E
8A
72
00
C8
C8
20
00
24
00
AE
15
84
D8
54
00
74
00
44
lA
e4
00
20
29
53
lA
AE
9C
13
62
44
84
F4
AA
68
lA
CA
20
49
Appendix F
IF80
1 F88
IF90
IF98
IFA0
IFA8
IFB0
IFB8
IFC0
IFC8
IF00
IF08
IFE0
IFE8
IFF0
1 FF8
52
43
53
48
57
2B
40
90
BE
BF
48
4A
7B
77
EB
BC
51
20
50
4C
58
20
14
11
13
19
13
IB
lA
lC
15
18
20
58
41
40
2C
4F
38
85
55
29
23
Bo
IF
B2
B9
30
20
52
42
4E
3A
5A
17
16
17
11
14
IB
lC
19
lC
35
53
20
43
51
3B
4B
25
C8
B9
C9
93
30
59
00
C6
32
52
59
44
52
24
25
11
11
16
16
19
lC
lC
10
15
37
20
52
46
53
23
26
35
BF
5A
B5
AA
43
E2
55
8E
38
41
20
47
54
22
45
12
19
19
19
lA
lC
IB
13
10
31
10 DATA 15965,14778,13059,14282,14
416,17693,12979,12903,1767
6,21760
20 DATA 14416,17693,12979,12903
100 Q==23296
110 FOR BLOCK==IT08
120 FOR BYTE==0TOI27
130 X==PEEK(Q+BYTE) :CK==CK+X
140 NEXT BYTE
150 READ SUM
160 IF SUM <> CK THEN PRINT" ERROR IN BLOCK #"BLOCK:GOTOI70
165 PRINT"
BLOCK"
BLOCK" IS CORRECT
170 CK==0:Q==Q+128
180 NEXT BLOCK
190 PRINT"ANY REMAINING PROBLEMS AR
E EITHER WITHIN THE FINAL"
200 PRINT"SHORT BLOCK OR WITHIN OAT
A STATEMENTS IN THIS PROGR
AM. "
291
Appendix F
5800
5808
5810
5818
5820
5828
5830
5838
5B40
5848
5850
5858
5860
5B68
5870
5878
78
00
9E
AE
92
02
E3
AE
3E
08
31
02
02
00
80
5F
A5
05
02
EF
A6
AD
02
Fl
5F
85
A9
A9
80
A2
87
85
90
EC
8E
6F
93
3C
8E
6F
AE
34
10
00
E7
0C
02
F8
A6
EF
9F
85
80
5F
E4
85
3F
86
80
80
02
DO
8A
80
91
6F
02
90
E5
AE
02
92
5F
35
84
86
80
15
0A
23
CO
F0
AD
86
02
3D
AD
86
E0
85
02
02
E8
5F
AA
5F
EE
30
EE
91
8E
5F
F0
93
80
30
80
80
02
00
80
85
6F
80
6F
A5
E6
80
6F
AO
80
86
85
A2
58
13
22
FC
5880
5888
5890
5898
5BA0
58A8
5880
5888
58C0
58C8
5800
5808
58E0
58E8
58F0
58F8
6C
60
17
52
20
4C
A0
88
C9
A9
68
E3
4C
09
08
96
F8
20
20
62
93
98
00
02
03
04
29
58
93
5C
20
00
00
39
EF
20
5C
60
81
C8
00
E0
iF
4C
60
AE
8A
E2
CA
64
60
A8
20
A2
F8
90
19
00
C9
98
85
00
F0
60
10
20
8E
58
AE
lE
20
F5
20
F0
04
60
80
C0
20
E0
E5
13
8C
20
68
20
60
60
06
09
90
20
85
E0
20
4C
4C
61
02
A8
00
Fl
5C
A5
60
20
AF
CC
b4
40
Fl
00
8E
90
20
62
E4
60
CC
80
AA
6F
20
FF
20
00
A5
50
5C00 20 05 F0 20 48 F1 4C F7
5C08 58 A9 00 85 96 80 FC 03
5C10 85 00 80 E8 02 60 20 39
292
Appendix F
5C18
5C20
5C28
5C30
5C38
5C40
5C48
5C50
5C58
5C60
5C68
5C70
5C78
64
61
5C
58
68
20
A2
00
69
29
4C
F0
6C
AE
90
20
A2
A2
03
04
Al
88
7F
09
19
C9
94
08
AE
05
02
69
20
FE
00
C9
60
C9
58
02
20
68
20
20
A9
Fl
20
F5
20
20
20
F0
00
31
00
Fl
Fl
10
60
60
60
80
06
00
50
10
5C
E8
60
60
20
A0
5C
4C
02
60
03
20
20
20
4C
20
A9
89
10
20
8E
A9
C9
20
71
13
93
A8
13
10
63
A2
38
60
20
00
17
50
5C80
5C88
5C90
5C98
5CA0
5CA8
5C80
5C88
5CC0
5CC8
5C00
5C08
5CE0
5CE8
5CF0
5CF8
8E
4C
4C
02
AE
Cl
A3
02
09
39
E7
20
60
24
60
4C
E8
98
98
F0
8
5C
02
00
20
80
02
09
C9
48
20
DO
02
60
60
31
02
A2
20
F4
55
E7
80
5C
00
20
06
5B
A2
A2
20
CE
F0
14
09
A2
69
02
E8
20
FO
9E
60
20
02
04
55
E7
lA
20
60
03
CA
60
02
CC
16
50
C9
52
20
20
69
02
A2
Fl
E8
5C
5C
E7
2C
20
8D
013
A9
4C
FF
C9
68
00
69
A7
Cl
AE
00
06
60
EC
02
FA
00
98
20
24
20
00
213
A2
A9
80
60
06
F0
09
F6
C5
5000
5008
5010
5018
5020
5028
5030
5038
5040
50
20
82
20
02
06
06
00
20
20
09
50
55
84
60
60
ED
06
06
60
20
69
01
AA
A4
20
60
60
00
88
A0
A9
A4
96
36
F0
C9
F4
50
03
08
96
00
68
05
00
A2
20
00
85
00
2F
20
20
F0
00
55
02
AF
36
C6
52
09
F0
20
69
A0
20
20
01
69
60
OVl
E8
293
Appendix F
294
SD48
SDS0
SD58
5D60
5D68
5D70
5078
D0
AF
20
F7
20
6C
06
F6
20
E4
C9
55
C9
60
20
E4
FF
03
69
22
C9
55
FF
F0
D0
4C
D0
00
69
F0
F8
8A
93
78
F0
A9
C9
C9
20
60
A2
0C
00
D0
20
12
20
00
C9
85
05
F0
5E
17
20
22
5D80
5D88
5090
5098
50A0
SDA8
5D80
5088
50C0
5DC8
5DD0
SOD8
50E0
5DE8
SOF0
50F8
F0
90
DA
20
85
40
20
D0
43
D3
00
F0
58
A5
4C
60
08
EO
A9
F3
D4
00
28
36
F1
A9
C0
A5
C0
03
8E
85
90
60
02
50
85
08
F1
20
4C
08
C0
03
4C
20
60
03
A3
86
85
4C
80
20
4C
D5
F7
85
40
20
00
93
A9
AD
02
01
D8
C9
AC
8A
F7
F0
58
04
00
64
08
F1
08
00
E8
A9
20
50
00
F0
58
A9
A9
85
08
F1
20
4C
85
C0
E0
A3
CC
A9
A9
C0
6F
6F
AF
20
4C
02
F7
04
C9
40
85
FF
08
C0
6F
4C
20
85
AC
86
F7
F0
58
A9
40
5E00
5E08
5E10
5E18
5E20
SE28
5E30
5E38
5E40
5E48
5E50
SES8
5E60
5E68
00
C9
F7
C0
C9
02
F0
93
20
00
12
20
93
5F
06
4C
58
C9
4C
2C
02
60
88
20
5E
20
60
A0
20
00
A9
40
00
4C
09
20
50
06
20
29
20
08
66
E4
00
00
CC
E8
80
09
20
60
52
68
60
84
F4
20
85
03
4C
08
20
5C
06
80
69
20
6C
04
4C
AS
AF
4C
CE
A9
09
20
60
FC
A9
13
00
A0
F7
F4
AO
8F
F3
0E
60
6E
80
00
24
68
6C
4C
58
4C
00
F3
A9
28
4C
50
F8
20
A2
4C
3E
8C
Cel
Appendix F
5E80
5E88
5E90
5E98
5EA0
5EA8
5E80
SE88
5EC0
. SEC8
5E00
5E08
5EE0
5EE8
5EF0
5EF8
8E
29
20
92
AS
09
90
F8
E9
60
70
20
20
60
C9
01
60
IF
2A
02
D4
60
0F
20
A9
20
6C
6E
80
A9
40
SF
20
C9
6C
8E
20
20
AE
lA
03
CC
20
50
50
00
00
C9
A4
04
AS
93
E3
52
94
68
20
FF
09
86
20
85
06
4C
68
90
FO
02
58
69
02
20
09
20
5C
01
06
AF
20
00
20
F1
A6
20
A9
20
00
38
60
F8
20
20
60
AO
52
81
6F
85
FE
3C
02
13
0A
69
20
60
01
04
20
00
F3
20
68
04
80
68
20
61
Al
00
EF
4C
68
SF
06
C0
4C
8C
5F00
5F08
5F10
SF18
SF20
SF28
SF30
SF38
5F40
F3 4C 12 6A
40 00 03 4C
00 EA 4C 49
co 40 3E OA
55 59 8E 58
16 SC 08 SC
3A SE 62 SE
82 SE 02 5E
31 30 32 31
AD
0A
F4
4A
89
08
69
69
38
00
F4
50
C8
58
SC
SE
58
31
C0
C9
C4
CC
68
27
77
00
AA
C9
4C
49
5E
SC
SE
SE
58
AA
295
Appendix F
VIC Micromon
VIC machine language programmers: here's one of the most valuable
tools there is for working in machine language. Thirty-four
commands are at your disposal including single-step, hex conversion ,
search, EPROM routines, and a relocator. If you aren' t yet working
with machine language, the instructions for entering and using this
program are easy to follow. As presented, this program takes up 4K
of memory from $4000 (16384 decimal) to $4FFF (20479), but there are
instructions for locating it elsewhere in RAM memory . To enter
Micromon directly, see the Tiny PEEKer/POKEr program with
Supermon 64 (in this Appendix). The commands for VIC Micromon
are the same as the PET/CBM version except as noted below .
VIC Micromon Instructions
Initialize Memory And Screen Pointers
.I 1000 1EOO 1E
Search for and, if found, load into memory the data file on device #1
named TEST FILE. If the name is not specified, the first file found is
296
Appendix F
3,2,1
0
Use
Parity Options
Duplex
Unused
Handshake
Value
--0
001
011
101
111
0
1
Descrition
Parity disabled
Odd parity
Even parity
Mark transmitted
Space transmitted
Full duplex
Half duplex
0
1
3 line
x line
297
Appendix F
6,5
4
3,2,1,0
Use
Stop Bits
Word Length
Unused
Baud Rate
Value
0
1
00
01
10
11
Description
1 stop bit
2 stop bits
8 bits
7 bits
6 bits
5 bits
0000
User rate
50 Baud
75
110
134.5
150
300
600
1200
1800
2400
COOl
0010
0011
0100
0101
0110
0111
1 000
1001
1010
Save
.5 2000 3000 "TEST FILE" 01
Save memory from $2000 up to, but not including, $3000 onto device
#1, which is the VIC cassette tape. If the dev!ce number is not
specified, it defaults to device #1. Th e name TEST FILE is placed in
the file header for the file saved.
Verify
.v
Search for and verify, if found, the data file on device #1 named
"TEST FILE." If the name is not specified, the first file found is
verified. The data is verified by reading the fil e and comparing it to
the data in memory starting at location $2000. If not specified, the
device defaults to device #1. If th ere is a mismatch , th e message
ERROR is output to the screen at th e end of th e fil e verification .
Command End Tone
.(
298
Appendix F
.)
Disable the co mmand end tone.
Program EPROM
.7r
2800 2FFF 00
Program the 2716 type EPROM via the EPROM programmer on the
VIC User 1/0 port w ith data read from memory starting at location
$2800 and ending at location $2FFF . The last input parameter specifies
in hex the sta rting 256 byte page offse t on the EPROM. If the low
order byte of th e s tarting memory address is zero and the offset is
zero, the n the programming starts with the first byte of the EPROM.
For example, to program only the last byte of the 2K EPROM with a
data byte from location $2FFF in memory, the command would be:
.7r
2FFF 2FFF 07
Load m em ory starting at loca tion $2000 and ending at location $27FF
with data read from th e EPROM via th e EPROM programmer on the
VIC User 1/0 port. The las t input parameter specifies in hex the
starting 256 byte page offse t on the EPROM . If the low order byte of
the starting memory address is zero and the offset is zero, then
reading s tarts with th e first byte of the EPROM . For example, to read
only th e las t byte of the 2K EPROM and load that byte into memory at
location $10FF, the command would be:
.f 10FF 10FF 07
Appendix F
the starting 256 byte page offset on the EPROM. If the low order byte
of the starting memory address is zero and the offset is zero, then the
reading starts with the first byte of the EPROM . For example, to read
only the last byte of the 2K EPROM and compare that with the data
byte in memory at location $37FF, th e co mmand would be:
. = 37FF
37FF 07
Command
A
B
C
D
E
F
G
H
I
J
L
M
N
o
P
Q
R
S
T
V
W
X
#
$
0/0
&
(
)
Appendix F
301
Appendix F
Location
---Old Value
6018
602A
6392
6650
66E7
6897
45
43
4C
45
45
43
New Value
65
63
6C
65
65
63
302
Contents
----09
AO
C7
FE
Appendix F
1 IFPEEK(20478)=67ANDPEEK(20479)=73THENRUN10
2 PRINT"VIC20 !'1ICROMON LOAD &":PRINT"VERIFIC
ATION PROGRAM.":PRINT
303
Appendix F
Q=16384
FOR BLOCK=1T032
FOR BYTE=0T0127
X=PEEK(Q+BYTE) :CK=CK+X
NEXT BYTE
READ SUM
IF SUM <> CK THEN PRINT"ERROR IN BLOCK #"B
LOCK:ERR=1:GOT0170
PRINT"BLOCK #"BLOCK" OK"
CK=0:Q=Q+128
NEXT BLOCK
IFERR=1THENPRINT"LOAD FAILED":END
SYS16384
4000
4008
4010
4018
4020
4028
4030
4038
4040
4048
4050
304
78
CD
18
45
14
04
8E
85
9D
03
03
4C
20
E5
80
03
E0
61
B2
A2
8E
D0
15
8D
20
16
AE
43
03
A9
D6
64
03
40
FD
F9
03
15
F0
20
80
20
03
CE
41
20
FD
8E
03
09
94
8D
50
58
3C
30
52
A9
17
C9
80
48
8A
4E
00
03
C3
FD
DF
03
91
60
A9
02
8E
CE
20
C2
20
A2
AD
D0
03
75
85
48
3D
AE
Appendix F
4058
4060
4068
4070
4078
45
A9
A9
A9
4E
A2
3F
0F
2E
03
42
20
80
20
80
A9
02
0E
02
56
2A
FF
90
FF
03
4C
A9
20
A9
80
3D
00
AE
00
64
49
2C
45
80
03
4080
4088
4090
4098
40A0
40A8
40B0
40B8
40C0
40C8
4000
4008
40E0
40E8
40F0
40F8
A2
F0
DO
8A
BD
CA
00
B4
FC
03
49
FA
90
54
A5
53
7F
F9
90
0A
B6
10
02
FC
06
20
CA
48
53
03
FO
03
9A
C9
4F
AA
4F
E5
A2
00
FB
13
00
BO
03
AC
A4
98
20
20
00
BO
85
4C
00
03
60
42
FA
53
CA
55
FE
E5
8C
F0
13
B5
FC
60
B4
EE
A9
A2
60
03
00
03
38
FC
48
F5
80
4F
6C
40
FB
56
00
09
A2
95
Fl
4C
E5
A8
C9
A2
49
85
FB
A2
00
03
80
20
02
FA
60
F4
FB
00
2E
24
03
FB
00
02
09
06
4E
38
B5
68
AD
40
80
53
4100
4108
4110
4118
4120
4128
4130
4138
4140
4148
4150
4158
4160
4168
4170
4178
03 60 A9 00 F0 02 A9 01
80 57 03 20 CB 47 20 AE
45
18
41
IF
E8
65
FE
E7
B2
EB
F0
20
FF
Al
20
20
E6
49
20
FO
20
40
40
A2
02
F8
F0
49
F0
E7
FO
AC
E7
85
05
B0
AC
00
81
47
2A
F0
40
40
00
56
40
FO
40
51
56
Al
FO
20
60
IE
20
90
02
03
18
98
20
20
03
FB
Cl
38
20
AE
21
7F
E6
00
AD
65
59
AE
DVl
AC
FO
49
E6
56
48
20
FE
6E
53
FE
41
40
46
57
F0
20
47
03
90
59
20
F0
03
85
20
20
P0
03
0B
El
20
00
305
Appendix F
306
4180
4188
4190
4198
41A0
41A8
41B13
41B8
41C0
41C8
4100
4108
41E0
41E8
41F0
41F8
' ,...
54
AO
013
213
00
E8
00
5F
20
90
133
B1
E8
41
E3
48
4B
F3
74
12
213
F3
48
A4
C8
20
FB
EC
20
213
F0
80
03
4C
41
213
A4
F13
90
49
E0
AE
DO
4A
IF
2B
40
4B
81
613
213
8C
49
lA
06
F0
213
45
65
03
49
44
90
03
FB
413
8C
48
Fc)
BE
90
09
00
A2
133
17
20
20
4C
48
90
2 ,~
59
65
20
EE
00
D0
00 F2
20 7C
20 F0
60
7C
IF
68
C9
65
E13
133
133
57
8E
A0
0A
20
41
40
41
49
40
27
03
213
20
E8
48
4A
00
C8
68
B0
90
4200
4208
4210
4218
42213
4228
42313
4238
4240
4248
42513
4258
4260
4268
42713
4278
00
42
45
47
213
136
F13
FB
F1
4E
133
20
98
213
40
FC
A13
20
013
213
CF
E0
0F
B0
13E
213
213
7B
213
FF
03
60
2C
E1
8A
38
42
133
AO
10
58
99
99
42
65
47
20
38
20
FF
20
49
68
00
58
20
03
45
45
AA
42
AE
7A
A4
C4
00
20
20
20
14
03
65
913
BO
CA
E8
8A
4A
42
FC
413
EE
49
C9
E6
AC
C9
42
13E
EF
D0
D0
8E
03
85
AA
213
20
20
40
42
40
E8
88
BO
4E
D2
01
4A
60
FB
10
6F
B6
F8
48
A2
03
Bl
013
E9
F13
60
C8
133
AO
84
01
42813
4288
42913
4298
42A13
42A8
42B0
88
4A
F0
BO
4A
65
913
13
98
29
130 AA
29 03
FB
13B
29
4E
13F
BO
80
913
4A
137
813
00
OC
40
01
B0
09
134
134
4E
03
C8
17
80
4A
A0
80
98
60
C9
4A
4A
813
58
29
A8
22
AA
4A
A9
133
8F
.LI.-
'. n
':;1()
20
Appendix F
42B8
42C0
42C8
4200
4208
42E0
42E8
42F0
42F8
AA
4A
00
FB
40
03
F6
80
55
98
90
FA
20
CC
C0
4E
55
03
A0
08
C8
65
40
03
80
03
2E
03
4A
88
42
03
90
54
A9
54
E0
4A
00
A2
C8
Fl
03
00
03
8A
09
F2
01
90
60
B9
A0
2A
4300
4308
4310
4318
4320
4328
4330
4338
4340
4348
4350
4358
4360
4368
4370
4378
F6
EA
03
45
91
91
A5
11
20
20
43
Al
8D
A9
3A
80
69
4C
20
00
20
A5
FF
91
54
6E
AD
FB
19
20
43
11
3F
38
9E
00
3A
FB
A0
A0
48
41
49
80
91
2C
58
91
20
49
43
00
43
A0
14
lC
85
20
03
10
A9
10
8E
AD
02 FF CA 00
20 E6 47 A9
A0 2C 4C 3C
A9 3C 8D 13
A9 FF 80 12
18 20 34 43
80 10 91 8C
8C 11 91 60
FF 20 AE 45
7C 41 20 lC
0A 08 90 17
91 78 A9 C4
3C 8D 11- 91
91 F0 FB 20
12 91 A9 0C
10 91 28 B0
4380
4388
4390
4398
43A0
43A8
43B0
43B8
43C0
43C8
43D0
43D8
43E0
43E8
04
03
B7
48
03
00
20
20
20
20
0E
A9
AB
A9
10
20
A9
48
48
F8
2B
F0
E1
AE
48
08
43
12
02
68
4C
48
20
68
44
40
FF
45
20
20
20
20
81
41
48
6C
8C
49
AE
90
00
A2
38
EA
38
02
FB
20
A9
60
48
FF
56
08
EE
2E
49
48
49
FF
C1
IF
77
03
20
4C
03
20
4C
A9
20
A9
20
A0
F0
20
60
20
F0
A8
36
05
88
FB
49
48
8D
00
72
D0
C8
0E
3A
F8
08
38
08
0B
88
Bl
CE
A2
B9
4F
0E
00
F0
D0
08
4B
49
42
0D
43
42
20
47
20
49
A2
307
Appendix F
43F0 00 Ai FB 29 7F C9 20 B0
43F8 02 A9 2E 20 02 FF A9 00
4400
4408
4410
4418
4420
4428
4430
4438
4440
4448
4450
4458
4460
4468
4470
4478
85
EA
00
A9
20
4C
86
EB
85
03
90
CA
3F
65
02
F0
04
EA
OF
08
C8
48
FE
47
FO
20
4F
30
A0
03
20
1E
EAEA
EA EA
4C OF
20 9E
43 A9
45 20
20 A4
4C AE
86 FE
8C 48
03 E8
14 BO
05 4A
88 00
A4 49
C9 20
EA
20
4A
43
3A
E6
49
45
A2
C9
E0
4F
6E
F6
F0
F0
EA
iF
20
20
80
47
F0
4480
4488
4490
4498
44A0
44A8
44B0
44B8
44C0
44C8
4400
4408
44E0
44E8
44F0
44F8
45
84
03
8E
A2
20
03
BO
E0
0F
B0
0E
20
20
20
03
B0
FC
E8
54
00
87
AA
F6
03
AD
1E
58
70
70
60
CD
0F
85
90
03
8E
42
BO
4E
00
58
20
03
45
45
45
4B
6C
A9
03
00
03
58
4F
70
AC
C9
45
0E
EF
00
60
00
20
FB
65
A2
4B
AE
36
20
14
03
60
90
BO
CA
20
03
00
20
03
03
66
F0
22
F3
EA
49
E6
B6
77
85
03
31
8E
F0
00
38
[3
E9
C9
20
EA
88
47
45
02
FO
20
48
66
F4
F1
E9
6E
A2
3A
90
48
30
E8
8E
AD
03
20
45
40
E8
88
BO
4E
02
45
7F
A4
90
00
56
56
8E
70
A2
03
A9
00
E9
F0
P0
AD
20
FB
65
09
03
03
55
45
06
F0
30
F1
4E
03
06
54
21
20
4500 48 AC 40 03 F0 2F AD 55
4508 03 C9 90 00 20 20 F0 40
4510 90 01 88 C8 00 6F 98 2A
308
Appendix F
4518
4520
4528
4530
4538
4540
4548
4550
4558
4560
4568
4570
4578
AE
80
AC
91
91
86
A9
A5
80
8E
85
8E
03
53
03
40
F8
F8
45
20
FC
7A
78
C6
4A
F0
03
38
03
88
A0
20
80
20
02
02
4C
03
00
E0
80
00
00
41
C4
78
9F
A5
80
68
AE
68
82
60
03
F8
8C
40
02
45
F8
7C
40
48
68
A8
CA
89
AD
77
20
80
8E
20
02
20
03
EE
00
CA
FC
56
02
6F
70
79
9F
A9
70
DO
56
03
8A
00
03
20
42
02
02
45
07
45
65
03
4580
4588
4590
4598
45A0
45A8
4580
4588
45C0
45C8
4500
4508
45E0
45E8
45F0
45F8
F0
E8
C9
60
4A
68
20
4C
29
8C
3D
A9
C0
91
03
03
03
8E
30
CD
4A
29
02
02
EF
41
03
80
80
20
68
68
4C
48
90
4E
4A
0F
FF
FF
80
03
68
80
2E
94
80
80
A0
03
03
03
4A
4C
A9
80
3E
68
69
48
91
48
40
3E
44
AE
C9
00
20
17
0A
3F
03
18
00
03
A9
08
03
03
4C
4A
47
1A
17
48
2C
03
8E
69
80
00
3F
68
68
68
60
03
60
60
48
A9
A9
08
40
01
3C
26
80
80
8D
80
40
60
38
48
AA
00
91
68
03
80
03
A9
2E
41
3F
3D
4600
4608
4610
4618
4620
4628
4630
4638
4640
03
80
03
03
2C
CD
CD
D0
80
68
44
8A
29
48
58
5A
58
80
80
03
8E
10
03
03
03
AD
48
3C
AD
42
F0
50
00
00
SF
03
03
15
03
03
1F
68
63
03
30
AD
03
58
4C
AD
AD
AD
00
12
14
80
AD
4E
3C
3D
5E
53
4E
03
43
3E
40
03
03
03
A9
48
309
Appendix F
310
4648
4650
4658
4660
4668
4670
4678
03
45
20
03
03
20
20
90
48
AE
A0
AE
38
16
02
A9
45
00
3C
49
42
AE
BA
20
20
03
A9
20
42
48
14
F2
85
24
E4
03
4C
49
48
FB
80
FF
9A
06
80
AD
86
4E
F0
A9
47
4B
3D
FC
03
FB
4680
4688
4690
4698
46A0
46A8
4680
4688
46C0
46C8
4600
4608
46E0
46E8
46F0
46F8
C9
4A
00
AD
53
AD
03
A9
F0
48
4B
IF
5F
80
A2
AE
03
00
47
21
4C
5C
8E
80
0F
20
20
78
80
44
00
42
00
4E
CE
91
5B
03
5F
80
C9
E3
AE
A9
2E
03
80
03
03
A9
5F
C9
40
AE
03
48
20
48
45
A0
91
8E
28
9A
4C
01
03
FE
A9
50
A9
03
00
20
AD
80
A9
43
91
78
68
80
CE
00
00
03
40
20
56
A4
48
2E
OF
03
8E
AD
40
48
5E
3A
F0
80
00
A4
20
49
03
91
A2
A9
29
44
C9
03
03
A2
12
5E
02
49
45
00
F0
A9
45
49
91
03
4700
4708
4710
4718
4720
4728
4730
4738
4740
4748
4750
4758
4760
4768
4770
4778
AE
03
03
AC
31
A9
20
03
62
80
48
A4
57
48
40
81
43
48
48
41
48
00
42
4C
03
4F
80
49
00
AE
90
F8
03
AD
AD
03
8D
8D
48
68
8E
03
51
F0
03
56
13
20
20
3D
3F
40
5A
5C
80
40
63
8E
03
0A
EE
03
AC
87
98
03
03
4C
03
03
5C
20
03
50
8E
20
4E
00
4E
42
48
48
AE
60
8E
8D
03
CB
20
03
52
CF
03
18
03
AA
AD
AD
40
40
58
50
8E
47
42
20
03
FF
20
20
00
BD
3C
3E
03
20
03
03
50
80
48
42
20
C9
21
E7
lA
F6
Appendix F
4780
4788
4790
4798
47A0
47A8
47B0
47B8
47C0
47C8
4700
4708
47E0
47E8
47F0
47F8
4E
40
F0
FB
ED
03
FB
03
03
FA
86
8E
48
48
20
A5
00
AC
03
AA
50
Fl
90
91
91
30
FE
55
85
B0
42
FC
06
40
8C
ED
03
FB
10
FB
FB
9E
20
03
FB
F6
48
20
20
03
40
4F
90
C8
88
C8
20
20
42
20
86
20
85
FF
C4
C0
03
03
IE
AD
18
Bl
IF
31
48
8C
FC
45
FO
47
40
02
88
C8
88
52
8A
FB
49
48
80
48
60
48
86
A5
4C
00
38
Bl
AD
03
60
60
88
85
54
20
20
B0
FE
FB
68
33
Bl
FB
51
Fl
62
63
10
FO
03
45
31
03
60
48
4800
4808
4810
4818
4820
4828
4830
4838
4840
4848
4850
4858
4860
4868
4870
4878
4A
68
20
69
60
95
60
48
B0
90
60
00
20
00
0A
48
4A
29
02
F6
A2
FA
A9
C9
08
07
4C
80
00
0F
0A
213
4A
0F
FF
90
02
68
00
20
20
AA
60
59
09
18
0A
81
4A
20
68
02
B5
95
80
F0
8C
20
40
03
20
60
80
48
20
17
4C
69
FA
FC
59
F9
48
57
20
20
8C
20
59
00
17
48
02
06
48
CA
03
20
20
48
74
8C
48
81
03
59
48
48
FF
69
B5
00
20
6C
57
90
41
48
C9
48
20
03
AA
8A
18
3A
FC
F3
8C
48
48
01
A9
C9
20
0A
8C
38
4880
4888
4890
4898
48A0
48A8
48B0
60
02
FA
80
A4
FB
03
C9
69
4C
14
49
05
00
3A
08
65
03
F0
FC
9E
08
60
40
8E
37
F0
A5
29
20
A9
15
20
22
FB
0F
A4
91
03
E6
A5
80
28
49
A2
60
47
9A
93
90
00
43
20
AS
C9
02
311
Appendix F
312
48B8
48C0
48C8
48D0
48D8
48E0
48E8
48F0
48F8
A5
A8
02
02
4C
DC
03
38
IF
FC
20
20
20
68
D0
60
49
49
8D
BA
C9
C3
40
Fl
8D
81
CE
94
FF
FF
FF
A5
8D
4B
FB
4B
02
20
4C
A9
9A
3D
03
20
03
A9
C0
75
03
C9
03
A0
FF
D0
02
FF
40
85
03
8E
00
47
F0
AA
A2
A9
9A
F0
3C
20
20
60
4900
4908
4910
4918
4920
4928
4930
4938
4940
4948
4950
4958
4960
4968
4970
4978
20
FB
CE
A.9
FB
03
AE
A9
A2
E8
2D
AD
49
44
20
40
57
Cl
4B
03
D0
EE
45
20
00
E0
49
3D
AD
03
EA
20
48
FB
03
85
09
56
68
4C
BD
IC
AD
03
43
20
48
31
90
D0
60
FC
E6
03
A2
D2
76
D0
3C
20
03
FF
4C
48
08
69
A9
A9
FF
60
2E
FF
4F
F5
03
FF
20
47
68
20
A2
20
3E
05
E6
98
20
20
20
A0
20
47
FF
20
40
E3
00
IF
85
60
FC
48
0E
0E
D2
3B
FF
20
47
14
4C
48
81
49
FB
E6
D0
20
48
48
FF
20
47
38
AD
49
60
20
4980
4988
49913
4998
49A0
49A8
49B0
49B8
49C0
49C8
49D0
49D8
49E0
42
20
48
213
06
13D
A2
213
D13
E8
22
F0
51
48
14
20
CF
20
60
65
E6
08
47
D0
08
90
8D 44
49 8D
11'13 49
FF C9
F0 47
A13 01
A0 133
47 AD
213 A4
20 98
A320
91 BB
F0 B0
03
4B
DQJ
213
20
84
20
49
49
49
CF
E6
91
8E
03
F8
F0
CF
BA
BD
03
F0
F0
FF
B7
20
43
213
FQJ
1"9
FF
A9
FF
C9
AF
29
C9
C8
A4
03
8C
DB
D0
C9
00
A8
53
213
C9
22
C0
49
Appendix F
49E8 F0 0E 20 57 48 29 IF F0
49F0 85 85 BA 20 98 49 D0 D9
49F8 A9 00 85 B9 AD 49 03 C9
4A00
4A08
4A10
4A18
4A20
4A28
4A30
4A38
4A40
4A48
4A50
4A58
4A60
4A68
4A70
4A78
53
FE
4C
FC
F0
CB
A5
20
47
0A
10
03
40
7A
A2
F8
00
20
F0
20
EA
4C
40
IF
20
98
10
10
4C
4A
2E
47
0C
08
02
05
A9
60
4C
49
38
00
08
06
60
4C
A9
20
A9
FF
A9
FF
69
40
68
20
49
15
C8
20
40
68
24
EA
FB
4C
01
A5
A0
20
40
IF
20
AO
00
FF
20
40
20
4A
A6
68
A6
90
C3
E6
20
49
F0
53
0B
47
E6
20
0E
20
FO
40
FB
29
20
47
E6
20
40
03
AO
4C
47
AE
48
A0
A4
49
A4
10
IE
20
47
F0
90
30
53
68
20
45
20
4A
4A80
4A88
4A90
4A98
4AA0
4AA8
4AB0
4AB8
4AC0
4AC8
4AD0
4A08
4AE0
4AE8
4AF0
4AF8
20
4A
18
00
A5
54
B4
8A
A9
40
85
EA
92
02
FC
41
38
20
0E
20
FC
03
4A
29
12
AA
D4
EA
2C
FF
4C
20
49
38
54
02
A6
20
A5
7F
20
8A
EA
EA
A9
20
CO
38
20
49
03
FF
FB
38
FB
C9
02
20
EA
EA
14
38
00
49
86
A2
2E
CA
80
49
AA
20
FF
02
EA
28
2C
49
20
20
4A
04
55
00
55
A5
20
08
8A
FF
EA
B0
A9
A6
05
F8
20
A9
03
EF
03
FC
38
B0
18
A9
EA
C0
22
FB
4B
47
89
30
69
60
8E
20
49
0A
69
00
EA
A9
4C
A5
B0
20
4B00 70 4A 4C 68 40 A2 04 A9
4B08 00 85 FC 20 C2 4B 20 2B
313
Appendix F
314
4B10
4B18
4B20
4B28
4B30
4B38
4B40
4B48
4B50
4B58
4B60
4B68
4870
4B78
4B
4B
28
20
3A
18
FC
FC
85
FB
FB
20
20
FF
85
CA
60
F0
B0
60
48
06
FB
26
A9
C2
38
47
FB
00
20
0B
07
4C
A5
FB
68
FC
00
4B
49
20
20 22
F7 08
A4 49
C9 30
29 0F
60 40
FB 48
26 FC
65 FC
A5 FE
65 FC
80 55
20 38
38 49
4B
20
F0
90
60
85
06
68
85
65
85
03
49
68
20
38
0F
0B
68
FE
FB
65
FC
FB
FC
48
68
AA
3D
49
C9
C9
68
A5
26
FB
06
85
60
48
20
A9
4B80
4888
4B90
4B98
4BA0
4BA8
4BB0
4BB8
4BC0
4BC8
4B00
4B08
4BE0
4BE8
4BF0
4BF8
00
86
20
4A
0F
C2
20
F7
FC
F9
A6
FO
E5
F0
18
FC
20
4A
38
20
A9
4B
22
4C
60
60
FB
A4
20
47
A5
65
Fl
4C
49
A0
00
20
4B
38
20
20
A4
FE
A4
4C
FB
FE
4A
68
20
4A
85
2B
20
49
8C
54
FC
20
E3
DB
65
85
20
40
F8
4C
FB
4B
BC
4A
48
48
20
7B
4C
47
FO
FC
38
20
47
68
85
20
4B
26
C9
80
8A
FE
68
20
85
4C
49
9F
20
40
FC
BC
CA
FB
20
88
FE
20
40
E7
FB
00
20
4B
EA
A2
20
4B
00
26
F0
02
A6
18
20
4B
A5
4C
4C00
4C08
4C10
4C18
4C20
4C28
4C30
4C38
4C40
20
AD
20
2C
40
85
C9
E7
A0
E7
53
F8
A9
78
B2
E6
4B
00
4B
03
47
00
20
AE
F0
20
8C
20
85
4C
80
52
42
95
21
54
F0
FB
68
0B
FO
03
6C
48
03
40
20
40
90
58
9A
00
20
8C
84
38
A9
4C
A9
A5
C0
38
55
FC
49
F0
65
3C
73
20
49
03
Appendix F
4C48
4C50
4C58
4C60
4C68
4C70
4C78
20
D0
8D
55
AD
03
64
F0
16
54
03
55
20
03
40
18
03
20
03
FF
D0
90
Bl
98
IF
20
47
04
IB
FB
6D
49
FF
4C
A5
AC
6D
55
4C
47
68
C6
56
54
03
48
AD
40
D0
03
03
8D
4C
54
AD
03
4C80
4C88
4C90
4C98
4CA0
4CA8
4CB0
4CB8
4CC0
4CC8
4CD0
4CD8
4CE0
4CE8
4CF0
4CF8
4C
D0
A5
A9
51
F0
03
85
8D
AD
A5
E6
C9
6F
2C
4C
56
7D
Dl
17
4E
16
F0
FD
49
49
FB
FC
24
42
20
0E
FF
A5
85
8D
C9
C9
CD
80
03
03
69
20
F0
A9
13
42
AD
D6
FD
5E
3A
24
38
El
20
C9
08
C8
lA
00
42
4C
77
C9
A5
03
F0
F0
A5
C6
0A
3A
85
43
20
8D
A9
56
02
16
D2
A0
lA
12
FD
FE
4E
D0
FB
4C
C9
4E
00
FF
C9
D0
85
01
C9
CE
E9
D0
B0
11
90
F4
4D
03
85
20
11
F0
FE
20
2C
5E
16
DD
B8
18
02
4C
20
A0
C6
IF
4D00
4D08
4D10
4D18
4D20
4D28
4D30
4D38
4D40
4D48
4D50
4D58
4D60
4D68
4D70
4D78
49
91
D1
17
4E
16
F0
FD
49
56
06
D0
FB
A9
70
20
20
D0
85
8D
C9
C9
15
90
03
FF
C9
4D
B0
00
40
70
6D
F0
FD
5E
3A
24
18
E1
20
AD
24
38
02
85
20
4A
4A
A5
A5
03
F0
F0
A5
E6
0A
49
F0
A5
C6
C6
D0
4C
4C
D6
D2
A0
1A
12
FD
FE
4E
03
1D
FB
FC
20
4D
68
F4
D0
85
01
C9
CE
69
D0
90
C9
D0
E9
20
05
20
4D
4C
EC
FE
20
2C
5E
16
DD
03
3A
27
08
CB
4E
B2
20
C9
A5
A9
51
F0
03
85
8D
4C
F0
20
85
43
4C
40
D0
315
Appendix F
316
4080
4088
4090
4098
40A0
40A8
40B0
40B8
40C0
4DC8
40D0
4008
40E0
40E8
40F0
40F8
40
FE
FO
E9
6F
F3
03
00
20
40
A6
86
A9
Bl
AO
A6
A5
A9
EO
00
42
CE
AO
Al
33
A2
02
AO
2C
AC
C6
02
FB
10
5E
85
20
5E
40
FB
49
00
20
86
85
91
FE
86
A6
80
03
FC
F0
03
03
8E
20
Al
07
FE
FO
FO
CA
FE
FC
5E
85
20
40
00
20
4E
16
FB
40
A2
A0
98
10
84
85
03
FB
C9
F0
E0
AB
03
42
4C
A6
00
CE
00
Fl
FO
FO
38
A5
40
07
EE
43
A9
4C
87
F4
86
E8
F8
A9
A0
86
A5
FE
20
B0
40
A2
2C
68
42
E8
AC
88
C6
20
2B
4E00
4E08
4E10
4E18
4E2QJ
4E28
4E3QJ
4E38
4E4QJ
4E48
4E50
4E58
4E60
4E68
4E70
4E78
91
02
20
20
FB
85
A4
18
0A
51
60
B0
20
00
49
52
FO
FF
51
3A
86
CC
03
60
0A
4E
Bl
02
00
43
4F
88
C0
4E
4E
FC
A5
91
20
0A
20
FO
09
FF
00
32
40
10
16
C9
AA
A9
CF
01
51
0A
81
C8
40
E8
00
30
4F
FB
00
20
20
FF
F0
A9
4E
80
48
29
60
00
00
20
4E
A9
02
F0
3A
80
0A
QJ0
20
59
00
7F
BO
F7
00
40
20
13
38
F3
4E
64
A5
85
81
03
59
C9
98
60
00
49
56
4C
60
88
85
03
CE
CF
48
20
03
20
40
00
56
43
31
4E8r21
4E88
4E9r21
4E98
4EA0
4EA8
4EB0
2E
4C
20
40
30
40
40
32
20
4A
02
22
02
02
2121 20
5945
414E
45 03
45 33
45 33
45 B3
2121
45
20
00
00
00
00
42
2121
20
08
08
08
08
49
32
38
40
40
40
40
4C
32
33
09
09
09
09
02
Appendix F
4E88
4EC0
4EC8
4ED0
4E08
4EE0
4EE8
4EF0
4EF8
00
11
10
10
62
00
85
59
1C
22
22
22
22
13
00
90
00
23
44
44
44
44
78
59
2C
58
50
33
33
33
33
A9
40
29
24
88
00
00
00
00
00
91
2C
24
18
8C
8C
08
08
21
92
23
00
A1
44
44
40
40
81
86
28
1C
90
00
9A
09
09
82
4A
24
8A
8A
4F00
4F08
4F10
4F18
4F20
4F28
4F30
4F38
4F40
4F48
4F50
4F58
4F60
4F68
4F70
4F78
10
19
18
58
A8
60
34
5A
C8
08
CC
A2
82
26
26
20
23
AE
23
58
AD
9C
11
48
54
84
4A
A2
32
26
48
20
90
69
24
A5
29
A5
A5
26
68
74
72
74
82
72
44
20
88
A8
53
69
00
69
69
62
44
84
F2
74
00
72
44
50
10
19
19
24
7C
29
23
94
E8
28
A4
74
22
88
A2
43
A1
23
A1
24
00
53
A0
88
94
6E
8A
72
00
C8
C8
20
00
24
00
AE
15
84
08
54
00
74
00
44
1A
C4
00
20
29
53
1A
AE
9C
13
62
44
84
F4
AA
68
1A
CA
20
49
4F80
4 F88
4F90
4F98
4FA0
4FA8
4F80
4F88
4FC0
52
43
53
48
57
2B
56
48
41
51
20
50
4C
58
20
29
3D
87
20
58
41
40
2C
4F
3D
44
41
20
52
42
4E
3A
49
5C
1F
A4
53
20
43
51
3H
4A
FF
47
46
52
59
44
52
24
25
AA
02
A0
20
52
46
28
23
26
49
41
41
41
20
47
54
22
45
9F
F9
AA
317
Appendix F
4FC8
4F00
4F08
4FE0
4FE8
4FF0
4FFB
318
49
49
4C
4A
4C
48
4C
BeJ
16
eJC
F4
35
37
40
43
4C
43
4A
4A
4C
43
3C
eJ6
15
68
CA
21
40
47
41
44
48
48
4C
43
A8
88
79
ED
2C
AA
40
46
46
49
48
4A
49
43
40
2A
64
eJeJ
80
19
49
Appendix F
Supermon64
Supermon64 is your gateway to machine language programming on
the Commodore 64. Supermon, in several versions, has been popular
over the years as a major programming tool for Commodore users.
Supermon64 itself is in machine language, but you can type it in
without knowing what it means . Using the Tiny PEEKer/POKEr
(Program 1), or via the built-in monitor of a PET, type it in and SAVE
it. The fastest way to check for errors is to type in Program 3 on a
regular PET. Then load Supermon64 into the PET. It will come in
above your BASIC. Then RUN the checksum and it will report the
location of any errors. Type POKE 8192,0 and hit RETURN. Then
type POKE 44,32 followed by NEW .
Enter the following:
Program I. Tiny PEEKer/POKEr.
11010
1110
1210
1310
1410
1510
1610
1710
1810
1910
21010
2Hl
2210
2310
2410
2510
2610
2710
2810
31010
3110
3210
3310
3410
3510
3610
3710
Appendix F
380
390
400
410
420
430
440
500
510
520
550
560
600
610
620
630
640
650
660
670
680
690
7 00
710
720
730
740
750
760
770
780
790
800
V=(V-V%)*16
IF V%>9 THEN V%=V%+7
PRINT CHR$ (V %+48 );
NEXT J
NEXT I
PRINT " / ";T
GOTO 110
P=l
L=4
GO TO 600
P=J
L=2
E=0
V=0
FOR J=P TO LEN(X$)
X=ASC(MID$(X$,J))
IF X=32 THEN NEXT J
IF J>LEN(X$) GOTO 790
P=J
FOR J=P TO LEN(X$)
X=ASC(MID$(X$,J))
IF X<>32 THEN NEXT J
IF J-P<>L GOTO 7 90
FOR K=P TO J-1
X=ASC(MID$(X$,K))
IF X<58 THEN X=X-48
IF X>64 THEN X=X-55
IF X<0 OR X>15 GOTO 790
V=V*16+X
NEXT K
RETURN
E=-l
RETURN
320
Appendix F
.0 2000
(SCREEN CLEARS)
2000 A9 12
LOA #$12
321
Appendix F
2002 90 00 80
2005 AA
2006 AA
STA $8000,X
TAX
TAX
.P 2000,2040
2000 A9 12
2002 90 00 80
2005 AA
TAX
203F A2 00
LOX #$00
LOA #$12
STA $8000,X
.F 1000 1100 FF
Fills the memory from 1000 hex to 1100 hex with the byte FF hex.
Go run
.G
Go to the address in the PC register display and begin RUN
code. All the registers will be replaced with the displayed values .
. G 1000
Go to address 1000 hex and begin running code.
Hunt memory
.R C000 0000
'READ
Hunt through memory from COOO hex to DOOO hex for the ASCII
string read and print the address where it is found. A maximum of 32
characters may be used.
322
Appendix F
.H C000 D000 20 D2 FF
Hunt through memory from COOO hex to 0000 hex for the
sequence of bytes 20 02 FF and print the address. A maximum of 32
bytes may be used.
Load
.L
Load any program from cassette #1 .
. L "RAM TEST"
Load from cassette #1 the program named RAM TEST .
. L "RAM TEST",08
Load from disk (device 8) the program named RAM TEST. This
command leaves BASIC pointers unchanged.
Memory display
.M 0000 0080
.: 0000 00 01 02 03 04 05 06 07
0008 08 09 0A 08 0C 0D 0E 0F
Display memory from 0000 hex to 0080 hex. The bytes following
the.: can be altered by typing over them, then typing a return.
Register display
.R
PC IRQ SR AC XR YR SP
0000 E62E 01 02 03 04 05
Displays the register values saved when Supermon64 was
entered. The values may be changed with the edit followed by a
return.
Save
.S "PROGRAl'-1 NAME",01,0800,0C80
SAVE to cassette #1 memory from 0800 hex up to but not
including OC80 hex and name it PROGRAM NAME.
323
Appendix F
.x
Return to BASIC ready mode . The stack value SAVEd when
entered will be restored. Care should be taken that this value is the
same as when the monitor was entered. A CLR in BASIC will fix any
stack problems.
Program 2. Supermon64.
0800
0808
0810
0818
0820
0828
0830
0838
0840
0848
0850
0858
0860
0868
0870
0878
324
00
12
45
4E
11
20
00
20
55
4C
28
35
AA
AA
AA
AA
lA
10
52
00
20
20
48
2E
54
44
C2
36
31
AA
AA
AA
04
10
20
31
20
20
04
2E
54
00
28
AC
32
AA
AA
AA
64
10
36
04
20
20
78
4A
45
66
34
C2
37
AA
AA
AA
00
10
34
6E
20
20
00
49
52
04
33
28
29
AA
AA
AA
99
53
20
00
20
20
99
40
46
82
29
34
00
AA
AA
AA
22
55
40
99
20
20
22
20
49
00
AA
34
00
AA
AA
AA
93
50
4F
22
20
20
11
42
45
9E
32
29
00
AA
AA
AA
Appendix F
0880
0888
0890
0898
08A0
08A8
08B0
0888
08C0
08C8
0800
0808
08E0
08E8
08F0
08 F8
AS
AS
A0
C6
00
F0
C6
24
37
91
C6
90
85
00
00
80
20
37
00
22
02
21
23
AA
00
37
38
B6
33
4F
80
17
85
85
AS
Bl
C6
85
C6
A.5
02
8A
C6
C9
AS
4F
16
03
22
24
22
22
23
26
22
26
C6
48
37
4F
38
4F
03
A9
AS
AS
00
00
C6
AS
B1
65
38
AS
68
00
85
4F
AD
80
2E
38
02
3C
22
22
22
25
C6
37
91
ED
34
AD
E7
20
85
85
C6
AS
B1
00
18
48
37
00
37
AS
6C
E6
FF
90
23
25
23
22
22
02
65
AS
68
02
18
37
37
FF
00
FF
0900
0908
0910
0918
0920
0928
0930
0938
0940
0948
0950
0958
0960
0968
0970
0978
00
80
80
8A
00
02
2A
34
02
00
02
00
05
C9
A2
8A
00
3D
3B
E9
00
20
20
E6
E6
00
FF
A9
20
2E
0E
0A
08
02
02
02
80
57
57
Cl
26
F8
A9
2E
02
F0
DO
AA
68
68
68
80
39
FO
FA
00
60
68
00
20
FF
F9
B7
BO
80
80
AA
3A
02
00
00
06
20
68
00
57
20
C9
FF
C7
3E
3C
68
02
BA
A2
A9
E6
CF
A9
85
FA
3E
20
00
FF
02
02
A8
98
8E
42
52
C2
FF
90
26
00
F8
F0
00
00
68
68
38
E9
3F
A9
00
00
C9
20
A2
A9
00
F5
0C
48
325
Appendix F
0980
0988
0990
0998
09A0
09A8
09B0
09B8
09C0
09C8
09D0
09D8
09E0
09E8
09F0
09F8
BD
EC
3A
A9
54
00
F1
A2
03
00
A9
48
4C
FF
20
A0
C6
4C
02
08
FD
20
60
00
4C
C6
02
20
57
A2
02
3B
FF 00 48 60
ED FA 00 AS
AS C2 8D 39
85 1D AVl 00
00 B1 C1 20
33 F8 00 C6
20 88 FA 00
00 81 C1 C1
ED FA 00 20
1D 60 A9 3B
85 C2 A9 05
57 FO 00 68
FA 00 A9 90
00 00 BO EA
FF E8 E0 16
20 C2 F8 00
0A00
0A08
0A10
0A18
0A20
0A28
0A3'"
0A38
0A40
0A48
0A50
02
20
20
F8
20
20
FA
E:1
AS
90
20
F0
FA
20
FA
20
20
48
80
00
69
79
00
FF
C3
2E
41
E0
00
B7
00
3E
48
FA
F8
20
FA
FA
0P.58
0A60
0A68
0A70
0A.78
A9
F0
C5
A0
FA
4C
90
F8
90
F8
FA.
00
00
79
00
00
90
3C
C1
3A
00
ED
03
00
EB
00
00
20
F0
FA
20
90
20
A6
AS
20
20
FA
20
D0
A9
20
AD
B7
5C
00
3E
28
02
26
C4
C2
8B
00
80
07
08
A1
CA
C1
02
00
48
1D
90
C1
33
85
60
A2
20
FF
00
AO
10
8D
60
20
FA
D0
0B
F0
F8
C1
98
2E
D2
00
F5
39
3A
F8
20
90
F8
20
FF
D0
E5
F8
F8
20
F8
20
35
F8
02
00
3E
33
00
69
20
38
C2
00
00
79
00
79
1D
00
0A80 D0 F8 4C 47 F8 00 20 CF
0A88 FF C9 00 F0 0C C9 20 00
0A90 D1 20 79 FA 00 90 03 20
326
Appendix F
0A98
0AA0
0AA8
0AB0
0A88
0AC0
0AC8
0A00
0A08
0AE0
0AE8
0AF0
0AF8
80
AE
48
48
3E
AE
01
84
A9
20
22
F0
E6
F8
3F
AD
AD
02
3F
84
90
02
F0
00
10
B7
00
02
3A
3C
40
02
8A
84
85
F9
14
C9
C8
A9
9A
02
02
A9
9A
84
93
BC
C9
20
00
C0
90
78
48
AE
90
6C
89
A9
20
00
CF
F0
10
20
1'.0
AD
3D
20
02
88
40
CF
F0
FF
29
00
02
39
38
02
02
A0
84
85
FF
38
C9
91
EC
FF
02
02
AC
FF
A0
B7
B8
C9
C9
22
88
4C
0800
0808
'1810
0818
0820
0828
083'1
0838
0840
0848
0850
0858
0860
0868
0870
0878
ED
F0
FA
F0
00
20
20
f9
4C
C9
20
2C
Cl
69
00
F2
FA
16
00
E5
60
96
02
00
47
2C
69
00
85
FA
98
F9
00
C9
29
85
6C
F9
FF
A5
F8
00
FA
AD
AE
00
A9
00
20
2C
0F
8A
30
00
A9
90
00
8A
00
20
AS
20
90
4C
CF
00
F0
20
03
00
00
29
20
20
20
79
C2
CF
20
47
FF
DC
E9
CF
6C
04
00
10
96
79
CF
FA
85
FF
02
F8
C9
20
C9
FF
32
A9
20
00
F9
FA
FF
'10
AF
C9
FF
00
00
88
03
C9
03
90
EF
C4
00
00
C9
AS
20
00
20
AS
0880
0888
0B90
0898
08A0
08A8
C2
4A
AA
48
FF
06
20
4A
68
8A
09
60
48
4A
29
20
30
A2
FA
4A
0F
02
C9
02
00
20
20
FF
3A
85
AS
60
60
68
90
C0
Cl
FA
FA
4C
02
48
48
00
00
02
69
BS
327
Appendix F
328
0880
0888
08C0
08C8
0800
0808
08E0
08E8
08F0
0BF8
C2
F3
85
85
20
20
18
0A
20
C9
95
60
C2
C1
3E
3E
60
0A
AF
3A
C0
20
20
60
F8
F8
20
85
FA
90
68
88
88
A9
00
00
AF
2A
00
02
95
FA
FA
00
C9
C9
FA
20
05
69
C2
00
00
00
20
20
00
3E
2A
08
CA
90
90
85
00
00
0A
F8
38
29
00
02
02
2A
09
0E
0A
00
60
0F
0C00
0C08
0C10
0C18
0C20
0C28
0C30
0C38
0C40
0C48
0C50
0C58
0C60
0C68
0C70
0C78
60
C1
26
F8
00
FA
FA
00
3F
A9
00
60
A2
C0
A5
0E
A2
00
06
00
00
00
00
20
02
3F
20
E6
02
68
C3
88
02
08
C2
C9
80
20
90
79
9A
20
54
C3
B5
95
A4
90
2C
B4
06
20
00
8F
09
FA
A9
02
FO
00
C0
27
C4
0B
A2
C2
C1
F0
00
FA
60
00
90
FF
02
48
CA
38
A5
00
00
60
F9
01
00
20
80
20
4C
CA
E6
B5
00
E9
28
00
02
20
60
20
20
3E
DE
02
47
00
C4
27
F3
02
A4
B4
E6
3E
A9
CC
7C
F8
AE
FF
F8
FA
60
95
60
B0
29
0C80
0C88
0C90
0C98
0CA0
0CA8
0CB0
0CB8
0CC0
0CC8
0C00
0C08
0CE0
4C
38
A8
20
20
20
90
FB
20
00
1E
85
00
33
E5
05
69
tilC
2F
15
00
05
EB
65
C4
3D
FB
C1
1E
FA
FB
FB
A6
90
FB
20
C3
20
A1
00
85
60
00
00
00
26
5F
00
28
85
0C
C1
A5
1E
20
20
20
20
00
A1
20
FB
C3
FB
81
C3
98
04
E5
E5
69
64
C1
33
00
98
00
C3
A4
E5
FA
FA
FA
FA
20
81
F8
18
65
A6
20
C4
C2
00
00
00
00
28
C3
00
A5
C4
26
28
~0
Appendix F
0CE8 FB 00 B0 34 20 B8 FA 00
0CF0 20 BG FA 00 4C 70 FB 00
0CF8 20 04 FA 00 20 69 FA 00
0000
0008
0010
0018
0020
0028
0030
0038
0040
0048
0050
0058
0060
0068
0070
0078
20
20
90
20
81
4C
20
20
20
3E
3E
CF
00
20
02
09
E5
3E
14
2F
C1
ED
04
E5
3E
F8
F8
FF
Fl
8F
E8
20
FA
F8
85
FB
20
FA
FA
FA
F8
00
00
C9
F0
FA
20
88
00
00
10
00
33
00
00
00
00
C9
90
00
IC
00
CF
FA
20
20
A6
90
F8
4C
20
20
A2
27
10
F0
8E
90
FF
00
69
88
26
0C
00
47
69
69
00
00
02
22
00
C6
C9
90
FA
FA
00
A5
00
F8
FA
FA
00
14
E8
E0
00
90
00
B6
00
00
11
10
EE
00
00
00
20
20
20
20
01
10
F0
E0
0080
0088
0090
0098
00A0
00A8
00B0
00B8
00C0
00C8
0000
0008
00E0
00E8
00F0
00F8
20
02
00
02
F3
00
80
47
20
86
90
20
85
A9
00
54
00
FF
A0
00
20
20
20
F8
A5
28
20
6A
C1
91
A0
FO
EC
20
00
0C
41
33
2F
00
C2
A9
02
FC
84
20
2C
00
86
57
00
C8
FA
F8
FB
20
85
93
FF
00
C2
02
20
20
1C
FO
Bl
E8
00
00
00
04
21
20
A9
20
C6
FF
C2
41
A9
00
Cl
E4
20
A6
B0
FA
A2
02
16
CA
10
4C
F8
FA
90
A2
00
lC
54
26
00
00
00
FF
85
FC
00
47
00
00
20
00
10
00
FO
00
4C
85
00
A9
10
00
F2
F8
20
20
0E00 54 FO 00 A2 00 00 A1 C1
0E08 20 09 FC 00 48 20 1F FO
329
Appendix F
330
0E10
0E18
0E20
0E28
0E30
0E38
0E40
0E48
0ES0
0E58
0E60
0E68
0E70
0E78
00
E0
AS
20
2A
AS
03
60
01
86
60
01
A8
22
68
03
2A
C2
90
FO
20
20
C8
lC
AS
88
4A
F0
20
00
C9
FC
0E
00
AS
CD
98
20
IF
65
90
13
35
12
E8
00
BO
BO
FO
FC
20
48
38
Cl
0B
29
FO
A4
Bl
88
2A
30
00
00
C2
FA
A4
90
4A
07
00
IF
Cl
00
FF
FF
CA
AA
FC
00
C2
01
B0
09
A2
F0
B0
F2
00
00
00
E8
00
A6
AA
C8
17
80
06
0E
lC
06
20
F0
05
00
8A
lC
10
60
C9
4A
0E80
0E88
0E90
0E98
0EA0
0EA8
0EB0
0EB8
0EC0
0EC8
0E00
0E08
0EE0
0EE8
0EF0
0EF8
AA
4A
80
00
29
F0
20
60
01
90
60
B9
00
88
CA
4C
BO
4A
A9
85
8F
0B
88
Bl
20
Fl
A8
77
A0
00
00
02
09
4A
00
2A
AA
4A
00
Cl
FE
A2
B9
FF
05
F8
EC
FF
FE
29
00
29
98
90
FA
20
FA
03
37
00
06
69
A9
20
00
0F
AA
03
A0
08
C8
C2
00
C0
FF
85
29
3F
20
04
B0
00
BO
8S
03
4A
88
FC
C4
04
00
29
26
20
2C
FA
04
04
10
IF
E0
4A
00
00
IF
90
85
A9
28
02
A9
00
4A
A0
FF
98
8A
09
F2
A2
C8
F2
28
00
2A
FF
00
20
0F00
0F08
0F10
0F18
0F20
0F28
0F30
0F38
69
69
A9
00
00
F0
4C
A9
FA
FA
90
20
85
05
47
03
00
00
20
72
Cl
20
F8
8S
20
A2
02
FC
84
2F
00
10
E5
00
FF
00
C2
FB
20
20
FA
00
20
20
20
00
04
3E
00
86
57
CA
El
1::\0
FA
F8
20
28
FO
FC
FF
E9
00
00
Appendix F
0F40
0F48
0F50
0F58
0F60
0F68
0F70
0F78
20
85
FC
FF
FA
CC
03
6E
Al
Cl
00
60
00
FA
68
11
F8
AS
C5
20
8E
00
38
02
00
21
28
04
11
48
E9
6E
00
85
F0
FA
02
CA
3F
F8
C2
03
00
A2
D0
A0
Hl 02
AS
4C
20
20
03
F9
05
88
20
46
D2
69
20
A2
4A
00
0F80
0F88
0F90
0o'98
0FA0
0FA8
0FB0
0FB8
0FC0
0FC8
0F00
0F08
0FE0
0FE8
0FF0
0FF8
F6
FF
F5
9C
C1
10
00
F0
26
29
FF
A2
F0
B0
20
EB
CA
C9
20
FA
A9
02
00
75
20
AA
00
06
lS
21
C1
06
00
00
00
00
30
E8
86
A2
09
BC
20
E0
AS
20
FE
2A
ED
F0
FE
A4
90
D0
26
00
FC
37
B9
03
2A
BF
00
90
A2
1E
00
C1
10
DB
F0
00
00
FF
FE
00
C9
FE
00
0B
02
C9
B0
84
02
86
04
86
A6
00
00
19
E8
00
C7
BC
20
20
0F
C2
E8
28
E6
10
2A
BO
00
A4
A9
D0
88
30
CF
F0
20
85
90
A2
26
AS
86
77
E3
1F
30
CC
D0
FF
1000
1008
1010
1018
10 20
1028
1030
103 8
10 40
104 8
10S 0
10 S8
1060
106 8
00
00
20
FE
D0
F0
20
04
00
A4
91
C1
C2
20
BO
00
B8
00
A0
28
1C
AS
C8
iF
C1
20
A9
C2
2A
5S
FE
00
20
AS
FB
1E
00
00
88
CA
90
F8
FF
CA
00
A6
69
29
00
10
FA
03
00
FC
20
00
00
00
AS
FA
C9
90
0A
AS
B9
F8
00
02
20
20
01
AB
28
00
9D
0A
4C
1E
C2
AS
85
FF
S4
B9
F0
20
CS
A4
00
98
ED
10
00
26
C1
A0
FO
FE
0A
B8
10
1F
1A
D0
FA
0'6
00
91
84
41
00
~0
331
Appendix F
1070 20 41 FA 00 20 54 FO 00
1 078 A9 05 20 02 FF 4C B0 FO
1080
1088
109 0
1 098
10A0
10A8
10B0
1 0B8
10C0
1 0C8
1000
1008
10E0
1 0E8
1 0F0
10F 8
00
98
10
28
60
08
08
08
08
00
33
33
33
A9
00
85
A8
F0
02
60
38
40
40
40
40
8C
00
00
00
00
00
90
20
0E
08
C9
60
09
09
09
09
44
8C
08
08
00
59
2C
BF
86
E8
30
40
30
40
40
00
00
44
40
40
21
40
29
FE
1C
86
90
02
22
02
02
00
00
9A
09
09
81
91
2C
00
A6
10
03
45
45
45
45
22
11
10
10
62
82
92
23
00
10
A6
C9
03
33
33
B3
44
22
22
22
13
00
86
28
11
00
1C
47
00
00
00
00
33
44
44
44
78
00
4A
24
1100
1108
1110
1118
1120
1128
1130
1138
1140
1148
1150
1158
116 0
1168
117 0
117 8
59
lC
90
00
23
Al
24
00
AS
AS
26
68
84
4A
A2
B2
00
8A
8A
00
24
00
24
7C
69
69
62
44
74
72
A2
32
00
lC
10
29
53
00
AE
00
29
23
94
E8
B4
F2
74
B2
58
23
23
19
IB
lA
AE
00
53
A0
88
94
28
A4
74
00
24
50
90
AE
23
5B
A8
15
84
08
54
00
6E
8A
74
00
24
8B
8B
69
24
58
AO
9C
13
62
44
00
74
00
72
22
00
IB
10
A8
53
AS
29
60
34
SA
C8
B4
F4
00
44
00
00
A1
Al
19
19
69
00
9C
11
48
54
08
CC
AA
68
00
11 80 lA lA 26 26 7 2 72 88 C8
1188 C4 CA 26 48 44 44 A2 C8
332
Appendix F
3A 3B
54 46
F9 00
F7 F8
00 F4
FB / 00
38 FC
00 AC
F7 00
11D8 20 50
11E0 41 43
11E8 20 53
1190
1198
11A0
11A8
11B0
11B8
11C0
11C8
11D0
52
48
35
00
F9
92
00
FD
ED
43
20
50
4D
44
F9
56
00
FB
5B
00
F7
20
58
AA
47
50
00
F9
0C
00
FD
46
00
20
52
AA
58
2C
CC
00
FA
C0
00
F8
0D
53
20
AA
4C
41
F8
89
00
FB
8A
00
20
52
59
AA
53
42
00
F9
3E
00
FD
FF
20
20
52
AA
333
AppendixG
The Wedge
One of the best reasons to learn machine language is that it can
improve your BASIC programming significantly. There are two main
ways that machine language can assist BASIC programming: adding
commands to BASIC itself and replacing parts of a BASIC program
with a high-velocity machin e language subroutine. To add an ML
subroutine to a BASIC program, you SYS, USR, or CALL (from
Microsoft, Atari, or Appl e BASICs respectively). That's fairly
straightforward. To make changes to the BASIC language itself,
however, we n eed to wedge into BASIC somehow.
You can make BASTC a customized language with a wedge. Do
you want auto-numbering when writing a program in BASIC? Add it.
Does your BASIC lack a RENUMBER facility? You can give it one. Do
you want a\l your BASIC programs to contain a REM line with your
name in it? This could be automatically put into each of your
programs if you know machine language. Using a wedge to a
machine language program, you can communicate directly to your
machine, bypass BASIC's limitations, and do pretty much what you
want to do.
How To Wedge In
Adding commands to BASIC is a matter of interrupting a loop. This is
often referred to as adding a wedge into BASIC. Under the control of
the BASIC language, the computer is looking to see if a BASIC word
has been typed in, followed by a hit on the RETURN key. Or, during
a RUN , the computer examines the program in m emory to see what
you want accomplished .
These, then, are th e two contexts in which the computer
analyzes a BASIC word: in a program or in "direct mode." In direct
mode, you can type the word " LIST" onto the screen and hit the
RETURN key. The computer looks up the meaning of "LIST" in a
table of words which includes the addresses of the appropriate ML
subroutines . It then JSR ' s (Jumps to a SubRoutine) somewhere in the
vast ML of your computer's BASIC. This subroutine performs the
actions necessary to provide you with a listing of the program in your
computer's memory. If you could add some additional words to this
table, you could add to BASIC. You could customize it.
Here's how. When you first turn on a computer which uses
Microsoft BASIC, one of the first things that happens is that the
operating system puts some important ML instructions into a zone in
335
AppendixG
th e firs t 256 m em ory loca tion s (this area of RAM is call ed zero page).
Th ese instruction s are pu t into zero p age to h an dle th e loop - often
calle d th e CHRG ET loo p (wh ich m ean s " ch aracter ge t") - wh ere the
op era ting sys tem w ill forever after jump w hile power is o n . This
loca tion is of great importan ce to BASIC; it is th e " di d th ey typ e any
BASIC into th e co m p uter?" su brou tine . It's w h ere BASIC an alyzes
w h at it find s o n scree n or in a program, looking a t so m e thing
ch aracter by character to see w h at it ad d s u p to.
If you typ e "LI ST, " this littl e zero page ML subroutin e looks at
the "L" then the " I" an d so o n . Th e exact location of CHR GET
diffe rs on the variou s computers:
64:
Apple :
112-135
115-138
115-138
177-200
0070
0072
0074
0076
0079
007B
0070
007F
0081
0082
0084
0085
0087
E6
DO
E6
AD
C9
BO
C9
FO
38
E9
38
E9
60
INC $77
77
02
BNE $0076
INC $78
78
03 02 LOA $ 0203
3A
CMP #$3A
OA
BCS $0087
CMP #$20
20
EF
BEQ $0070
SEC
SBC #$30
30
SEC
DO
SBC #$00
RTS
This is put into your zero p age RAM withi n th e fi rst few seco nds
after y ou turn on the com puter. You ca n ch an ge it (RAM m e m ory can
be changed) to jump OMP) to your own ML progra m by replacing the
first three bytes of co d e. In o ur example above, we w ill repl ace th e
three bytes a t h exad ecim a l locatio n 0070 (th e exact address w ill vary
according to th e CHRGET loca ti o n as liste d ab ove for th e d ifferent
computers). H ere is h ow th e replacement looks in th e exampl e
CHRGET routine:
Appendix G
0074
0076
0079
007B
007D
007F
0081
0082
0084
0085
0087
E6
AD
C9
BO
C9
FO
38
E9
38
E9
60
INC
78
02 02 LDA
CMP
3A
BCS
OA
CMP
20
EF
BEQ
SEC
SBC
30
SEC
SBC
DO
RTS
$78
$0202
#$3A
$0087
#$20
$0070
#$30
#$DO
7500
7502
7504
7506
7508
750B
E6
DO
E6
A9
8D
4C
INC
77
BNE
02
INC
78
LDA
41
00 80 STA
76 00 JMP
$77
$7506
$78
#$41
$8000
$0076
Notice that we had to first perform the actions that the CHRGET
would have performed. Before we can start our LDA #$41 to put an
"A" on screen, we had to replace the early part of CHRGET that we
wrote over (see 7500 to 7505 in Example 3). And, after we're done
with our custom routine, we jump back into CHRGET at 750B.
Adding a wedge to Atari BASIC is somewhat more involved. A
clear and complete expositio n of the techniques involved appears in
an article by my colleagu e Charles Brannon, "The Atari Wedge"
(COMPUTE! Magazine, November 1982).
337
Index
A
A or AC register (see Accumulator)
Absolute addressing 25,40-42, 45,46, 48, 51, 56, 68,69, 75, 81
Abso lute, X and Absoute, Y addressing 48,51, 68, 69, 75, 81
Accu mulator 19, 26,31,33,39,56,66
Accum ul ator mod e 51
ADC 20, 56, 58, 68, 149
Ad dresses 1, 2, 19, 20, 47, 54, 77, 85, 99, 124, 127, 128, 130, 139, 140,
146
get a ch aracter add ress 1
las t key pressed 77
safe place address 1, 2
sta rt of RAM 1, 99
s tart print address 1
wh ich key is pressed? 1, 54, 127, 128
Add ressing 18, 22, 40
Address ing modes 12, 33-34, 37-51, 68, 69, 75, 81, 149-166,223, 224
Absolute 25, 40-42, 45, 46, 48, 51, 56, 68, 69, 75, 81
Absolute, X and Abso lute, Y 48, 51, 68, 69, 75, 81
Accu m ul ator mode 51
Immed ia te 25, 33, 34, 43, 51, 66, 68, 69
Im plied 43-45, 55, 81
Ind irect Indexe d 74,125, 141
Ind irect X 51, 68, 69
In direct Y 42,49, 51,57, 58,69, 70, 74, 77, 85
Relative 25,45-47, 69
Zero Page 33, 34, 42-43, 51, 55, 65 , 68, 69, 75
Zero Page, X 48, 68, 69, 75
Zero Page, Y 51
"Alph abe tic" m ode 54
AND 39,88,89,149
Arca de ga me progra m m ing in ML vi
Argum ent viii, 40, 55, 69, 70, 77, 81, 223, 224
ASCn cod e 3,9,53, 70, 78, 131, 144
ASL 51, 59, 68, 89, 149
ASM mode (A tari moni tor) 27, 28, 110
Assembl er vii, 2, 35, 45, 46, 61, 140,223
asse mbler program 18
traditional co nve n tio ns, lis t of 224
two-pass asse mblers 72, 223, 225
339
Index
B
BASIC v-vi, vii-xii, 1-4, 7, 19, et passim
advantages of xii
commands vii, 63, 121-147
ASC 144
CHR$144
CLR 121-22
CONT86, 122
DATA xii, 122-23, 140
DIM 123
END 63, 124-25
FOR-NEXT 125-26
FOR-NEXT-STEP 126-27
GET 40,93, 127-28, 131
GOSUB 81, 128-29, 141, 142
GOTO 18, 84, 85, 129-30
IF-THEN 69, 71, 131
INPUT 131-32, 133
LEFT$ 144, 145
LEN 145
LET 132-34
LIST xi, 134
LOAD 30, 92, 134-35
MID$145
NEW 121, 135-36
ON GOSUB 71, 136, 137
ON GOTO 69, 71, 74, 137
PRINT x, 40, 137-40
READ 140
REM 140
RETURN 5, 131, 141
RIGHT$145-46
RUN 141-43
SAVE 30, 110, 143
SPC 146-47
STOP 122, 124, 143
340
Index
TAB 146,147
loaders 19
Microsoft BASIC vii, 2, 4, 17, 91, 93, 105, 135, 141, 144,224,335
words xi
BCC 45, 59, 61, 69, 71, 74, 75, 131, 150
BCS 45, 59, 61, 69, 71, 74, 75, 150
BEQ 25, 45, 47, 59, 69, 71, 77, 131, 151
Binary numbers 7, 8, 9, 15, 243-50
program for printing table of 16
BIT 89, 151
Bits and bytes 8, 9, 10,12-15
BMI45, 59, 61, 68, 71, 74, 75, 151
BNE 24, 45, 59, 61, 69, 71, 72, 74, 75, 77, 131, 151
BPL 24, 45,59,61,68,71, 74,75, 152
Branch address 47
Branches:
ON-GOTO 74
forward 78
Branching instructions 25, 45, 46, 47, 59, 67, 68, 69, 71-72, 73, 88
BRANCHTARGET 72, 74
Breakpoints 86, 87, 143
BRK 29,30,34, 37, 45, 61, 67, 86-87, 90, 122, 124, 134, 143, 152
Buffer 42, 98
BUG 28,142
Bugs 31, 33-34
BVC 45, 63, 68, 71, 152
BVS 45, 68, 71, 152
c
CALL instruction viii, x, xi, 23, 65, 141
Carriage return 54, 144
Carry flag 37,39, 45, 56, 58, 68, 69
Cassette buffer 1
CHRGET loop 336
CHRGET ML program 336
Circumflex 26,223
CLC 43,56,58,68, 109, 153
CLD 43, 56, 68, 153
CLI 89,153
CLV 63,153
CMF instruction 8, 33, 34, 61, 69, 70, 71, 75, 77, 89, 127, 128, 131, 136,
145, 154
Code 53
"Cold start" address 124
341
Index
D
Data table 31, 121, 225
Debug xii
DEBUG (Atari monitor mode) 26,28,29, 142, 143
commands in 28-30
Debugger 23,36
Debugging 86
methods 87-88
DEC 75, 155
Decimal address 19
Decimal flag 56
Decimal numbers 8,9, 10, 14, 16, 243-50
Default 92
Delay loop 83-84, 125-26, 129
Delimiter 78, 138, 145, 146
DEX 45, 75, 84, 155
DEY 45, 75, 155
Dimensioned memory 123
Direct mode 4, 335
Disassembler viii, 20, 134
Disassembly viii, ix, 20, 140
Disassembly listings 25
Dollar sign ($) 10, 12, 28, 223
Do-nothing loop (see Delay loop)
342
Index
E
Echo 131
EDIT mode (Atari monitor) 27,28,30, 143
Effective address 85
END 4 (see Pseudo-ops)
Endless loop 33,54,74, 76, 124, 125, 145
EOR 39,88, 156
Equates 72
Error messages 26, 48,77
F
Fields 25,27
Filename 143
FILL instruction 67
"Fill memory" option 135
FIND command (Atari) 110-118
Flags 8, 12,31, 37, 39, 45, 56, 61, 66-67, 68, 69, 77, 131
B flag 68,86
C or Carry flag 37,39,45,56,58, 68, 69
D flag 68
I flag 68,86
interrupt flag 89
N or Negative flag 64,66,68,69,75,89
status register flags 68, 131
V or overthrow flag 45, 68,89
Z or Zero flag 39, 64, 66, 67, 68, 69, 71, 75, 77, 78, 89, 130,
131, 138, 145
Floating point accumulator 141
Floating point arithmetic 59, 142
G
GET#93
H
Hexadecimal numbers viii, 1-2, 7, 8, 9, 10, 11-12, 16-17, 45, 243-50
conventions of 12
Hex dump 19,20,24
343
Index
I
Immediate addressing 25, 33, 34, 43, 51, 66, 68, 69
Immediate mode 141
Implied addressing 43-45, 55, 81
INC 75,156
Indirect-indexed addressing 74, 125, 141
Indirect jump 85,224
Indirect X addressing 51, 68, 69
Indirect Y addressing 42, 49, 51,57, 68, 69, 70, 74, 77, 85
Initialization routine 121
"Instant action" keys 54
Instruction field (see Fields)
INT mode 25
Interactivity 34-35
Interpreter 125, 133
Interrupt request 31,86
Interrupts:
maskable 89
non-mask able 90
INX 45,55,75, 156
INY 45, 75, 157
IRQ 31, 37, 39, 86
J
]MP instruction 18, 24, 34, 81, 82, 84-85, 91, 128, 129, 130, 157
]SR24,25, 45, 67, 71, 72, 80, 81, 82, 91, 92, 124, 129, 130, 136, 141, 143,
157
K
Kernal91
Kernal jump table 91, 92, 94, 128
L
Label table 72
Languages vii, xi
FORTH 82
(see also BASIC; Machine langu age)
LDA 20,25,26,29,33,39,40,43,45,48, 55,61,63,64,66,69, 71, 158
LDX 51, 64, 66, 158
LDY 33,34,64,66, 159
Loaders ix-x
344
Index
M
Machine language (ML)
advantages of viii, xi
equivalents of BASIC commands 121-47
INPUT subroutine 131-32
instruction groups 64-90
arithmetic 39, 68-69
debuggers 86-90
decision-makers 69-75
loop 75-81
subroutine and jump 81-86
transporters 64-68
instructions vii, 121-47, 149-66
monitor 253,269-333
strings 77-80, 144-47
subroutines 31 , 91-96
Maps 42
Atari Memory Map 205
Commodore 64 Memory Map 193-204
PET /CBM 4.0 BASIC ROM Routines 175-80
PET /CBM 4.0 BASIC. Zero Page 172-75
PET Original and Upgrade BASIC 167-69
Upgrade PET/CBM 169-72
VIC Zero Page and BASIC ROMs 181-92
Masking 88-89
Mass-move 80
Memory addresses 1, 2, 20
Memory dump , 24, 28-29, 30, 275
Memory map 1 (see also Maps)
Memory mapped video 70
Memory zones 133
Message table 138
Message zone 77
Micromon 23, 31, 130, 269-333
VIC Micromon 296-318
345
Index
N
Natural numbers 7
NOP 45,86, 169
uses of 87-88
Number tables (hex, binary, decimal) 243-50
o
Object code 18, 22, 28, 47, 225, 226
Opcode 18,20, 55, 66, 223, 224
Operand 55 (see Argument)
ORA 160
OS (operating system) 42
p
Page 33
page one 42
page six 68, 110
page zero 33,42,51,56,57, 98, 139, 140, 336
Parameters 67, 83, 128, 141
PET ASCII 3
PHA 45,67,81, 82, 160
PHP 45,67, 160
PLA 3, 4,5, 45, 67, 82, 161
PLP 45, 67, 161
346
Index
R
RAM (Random Access Memory) viii, xi, 1, 2, 4, 9, 12, 19,31,33,37,
42,80,97,98, 225
Reference sources 221
Registers 26, 28, 30-31, 57, 66, 70, 82
Relative addressing 25, 45-47, 69
REM statements xii, 20
"Resolving" labels 225
347
Index
s
Safe areas 2-3,42, 68, 97-98, 99, 105
SBC 61, 68, 163
Screen address 139, 140
Screen position (see STA)
Search bloader 119-20
Search routine 88
SEC 43,58,61,68, 163
SED 43, 56, 63, 163
SEI89-90, 164
SGN command 63
Simple Assembler 1, 2, 3, 4, 5, 10, 17, 22, 25, 26, 27, 28, 35, 43, 47, 57,
73, 74, 79, 223-36
Single-stepping 87
6502 machine language (see Machine language)
Softkey 132
Source code 18, 19, 22, 28, 49, 72, 225
Source program 140,225
Spaces, important 224
STA20, 40, 49, 51, 55, 56, 57, 63, 64, 65, 67, 164
Stack 42,67-68,81-83, 141
Stack pointers 26, 28, 37, 39
Status Register 8, 26, 28, 31, 39, 56, 66, 68, 82
Ster 26, 29-30, 31, 126-27
String handling 77-80, 144-47
Structured programming 85
STX 51, 64, 67, 164
STY 64, 67, 165
Subroutines 31, 91-96
Supermon 23,31, 130,253-68
Supermon64319-333
Symbols 53
SYS instruction v, viii, x, xi, 19, 25, 30, 65, 124, 141
T
TAN command 63
Target address 130, 139, 146
TAX 64, 66, 165
348
Index
u
Unconditional branch 129, 130
Unmatched RTS 141, 143
Upward arrow 223 (see also Circumflex)
USR instruction v, viii, x, xi, 3, 4, 19, 63, 64, 67, 110, 111, 124, 141, 142
v
Variable x-xi, 132-34, 140
storing 57
Vector 86
w
"Warm start" address 124
Wedge 335-37
x
X register 46, 51, 67, 75, 125, 126
X and Y registers 26, 31, 39, 45, 48, 66, 75, 93, 94
y
Y register 26, 34, 39, 57, 70, 147
z
Zero address 47
Zero page 33, 42, 51, 55, 56, 57, 98, 139, 140, 336
349
Index
Zero page addressing 33, 34,42-43, 51, 55, 65, 68, 69, 75
Zero page locations 49, 99
Zero page snow 68
Zero page, X addressing 48,68,69,75
Zero page, Y addressing 51
Zone of variables 133, 134
350
800 .. 334-0868
In NC call 919-275-9809
COMPUTE!
P.o. Box 5406
G reensboro. NC 27403
My Computer Is:
o PET 0 Apple 0 Atori 0 VIC 0 Other - - - 0 Do n't yet have one ...
o $20.00 One Yeor US Subsc ripti o n
o $36.00 Two Yeor US Subscription
o $54.00 Three Yeor US Subsc ription
Subscription rates outside the US:
o $25.00 Canada
o $38.00 Europe, Austra li a, New Zealand/Ai r De livery
o $48.00 Middle East. No rth Afri ca, Centra l Ame rica/Air Mail
0$68.00 Elsew here/Ai r Mail
o $25.00 International Surface Mail (lengthy, unreliable delivery)
Name
Address
City
State
Zip
Country
Payment must be in US Funds drawn on a US Bank; Inte rnational Money
Order, or chorge cord.
Payment Enc losed
VISA
America n Express
MasterCord
Expires
Acc t. No.
o
o
233111
800-334-0868
In NC call 919-275-9809
COMPUTE!'s GazeHe
PO Box 5406
Greensboro. NC 27403
My computer is:
Oth e r _ _ __ _ _ __
o $25 Canada
o $45 Air Mail Delivery
o $25 Inte rnational Surface Mai l
Name
Add ress
City
State
Zip
Country
Payment must b e in US Funds d rawn o n a US Bank, Internationa l Money
Order, or charge card
o Payment Enclosed
o MasterCard
Acct. No.
233111
o VISA
o Ame rican Express
Expires
COMPUTE!
Books
PO Box 5406 Greensboro, NC 27403
Ask your retailer for these COMPUTE! Books, If he or she
has sold out, order directly from COMPUTE!
For Fastest Service
Call Our TOLL FREE US Order Line
800-334-0868
In
Quantity
Ne call 919-275-9809
Title
Price
$ 3.95**
$12.95*
$19.95*
$12.95*
$24.95***
$ 4 .95**
$12.95*
$12.95*
$12.95*
$14.95*
$14.95*
$12.95*
Total
o
o
Name
Address
City
Country
Allo w 4-5 weeks fo r delivery.
State
Zip