You are on page 1of 304

THE ANATOMY OF THE

COMMODORE 64

Authors:

Michael.Angerhausen
Dr. Achim Becker
Lothar Englisch
Klaus Gerits
Translated

by:

Detlev Kesten

Edited

by:
Jeff

Kirby
Arnie

Hanson

Hanson
Lee

Abacus 11 Software
P.O. BOX 7211 GRAND RAPIDS, MICH. 49510

Third English Printing,


Copyright

1983,1984

Copyright 1983,1984

June

Data

Merowingerstr. 30
4000 Dusseldorf W.
Abacus Software
P.O. Box
7211

Grand

This book

1984

Becker GmbH

is copyrighted.

Rapids,

MI

Germany

49510

No part of this publication may be

reproduced, stored in a retrieval system, or transmitted in


any
form or
by any means,
electronic,
mechanical,
photocopying, recording, or otherwise, without the prior

written permission of ABACUS


ISBN

0-916439-00-3

Software,

Inc.

PREFACE

The Commodore 64 is a super machine.


That became clear to
us after working with the machine for only a short time.
But even with the best computer you can't do much if you
don't know much about its functioning and handling.

The only area which disappointed us about the Commodore 64


was the documentation.
The user's guide was a good starting
point,
but lacked the detail which we sought.
Further
literature was not available.
Therefore we decided to write
the book ourselves.
The result is in front of you.
It does not claim to be
complete, nor to have literary qualities,
but this book
contains the results of months of long and intensive work.
We hope that it will help you to take advantage of the
superb qualities of the COMMODORE 64.

TABLE OF CONTENTS

Chapter 0 :

INTRODUCTION

Chapter 1:

MACHINE LANGUAGE PROGRAMMING ON THE


COMMODORE

1.1
1.2
1.3
1.4
1.5
1.5.1

1.5.2
1.5.3

1.5.3.1
1.5.3.2
1.5.4
1.5.5

64

Introductary Concepts
The Monitor and its uses

4
6
How to go about programming in machine language..10
Useful addresses of the Commodore 64 ROMs
14
Data Input and Output from Machine Language......17
Input and Output of Single Characters
17

Input and output using Peripheral Devices


Saving and Loading data
Saving Data on Cassette
Saving Data on Diskette
Programming the RS-232 interface

The Serial Bus

Chapter 2:
2.1
2.2
2.3
2.4

18
......21
21
23
4.27
31

THE NEXT STEP - ASSEMBLER PROGRAMMING

Why Assembly Language


Table of 6510 commands
A Typical Assembler Program
Still more programs

35
36
37
..40

Chapter 3: A CLOSE-UP LOOK AT THE COMMODORE 64

3.1
3.2

What you should know about the Commodore 64


An Overview of the Hardware

43
43

3.4
3.5
3.6

Memory Configurations
The Expansion Port
The User port..

45
48
48

3.3

Special Features' of the 6510 Processor

Chapter 4:
4.1
4.1.1
4.1.2
4.1.3
4.1.3.
4.1.3.2
4.2
4.3

THE SYNTHESIZER AND ITS PROGRAMMING

The Sound Controller 6581


50
General notes about the SID 6581
50
Explanation of the Registers
51
The Analog/Digital Converter
55
Handling the A/D Converter
55
Using the Game Paddles
55
Programming of the 6581
57
SYNTHY-64 - Full fledged Synthesizer Software....59

Chapter 5:
5.1
5.1.1
5.1.2
5.1.3
5.2

44

GRAPHICS PROGRAMMING

The Video Interface Chip 6567


Chip Description
Register Descriptions
Display Techniques
Programming color and graphics

62
.(2
63
65
73

5.3

Sprites - Graphics magic on the Commodore 64

5.3.2

Sprite Capabilities

5.3.4

Programming

s!3.1

introduction to Sprites

5.3.3

Sprite Structure

82

ro

Sprites

5.3.4.1

Sprite

5.3.4.2

The

5.3.4.3
5.3.4.4

Turning On a Sprite
Memory areas for Sprites

Sprite Positioning

**

5.3.4.6
5.3.4.7
5.3.4.8

Shifting Sprites
Sprite Colors
Enlarging Sprites

5.3.4.9

Background

5.3.4.5

Patterns

Program

5.3.4.10 Sprite-Sprite Collisions.


5.3.4.11

Sprite-Background Collisions

5.3.4.12

Multicolor

Chapter 6:

"

Sprites....

BASIC FROM A DIFFERENT VIEWPOINT

6.1

How the BASIC interpreter works

6.3.2

HARDCOPY - RENEW - PRINT USING

6.2
6.3
6.3.1
6

3.3

6*.3.4

6.3.5

6.4
6.5

**

98

Using variables in your Program


Get More Out of Your BASIC
How to Extend BASIC

.*
^
lv"

Self-developed mathematical

iu*

SQR, SUM, and PROD functions

1^

routines

Changing to Different Data Formats

iu*

Routines of the BASIC Interpreter


Low Memory Usage

Ill
LLf0

Chapter 7: VIC-20 - Commodore 64 - CBM/PET

7.1
7 2
7i,3

Comparison table of the ROM addresses


120
Changing VIC-20 programs to the Commodore 64...122
Changing CBM/PET programs to the Commodore
123
Chapter 8:

INPUT/OUTPUT CONTROL - CIA 6526

8.1

General notes about the 6526

8 .3

i/O-ports

8.2

8.4
8.5
8.6

8.7

124

Register Usage

Timer
Real-time clock
The CIAs in the Commodore 64

Using the joysticks

APPENDIX A - ROM Listing


APPENDIX B - A Short Lesson

126

'

iZl

***
^"
132

133
A-l

in Hexadecimal Arithmetic.B-l

APPENDIX. C - Summary of Capabilities

C-l

APPENDIX D'- Bibliograpy

D-l

CHAPTER 0:

INTRODUCTION

The
Commodore 64 sets a new standard in terms of price
and
performance
in pesonal computing.
At the price of a home
computer,
the
Commodore
64
is
a
professional
quality
computer.
computers

As the owner of a Commodore 64,


in one.
Let's look at these -

THE LEARNING AND INTRODUCTORY COMPUTER

At

i^s

low

introductory

price,

EKe

Commodore

level computer.

64

is

you have several

an

affordable

Add a cassette drive and the

Commodore 64 is a very capable computer system.

Yet as

the

beginner
increases his computer proficiency,
the Commodore
64 has enough capabilities so as not to limit his growth.

Since the Commodore 64 uses the familiar BASIC language, the


beginner should have
an easy time learning
to
program.
Commodore
64
BASIC
is
very
compatible
to
the
BASIC
interpreters of other Commodore computers. Adapting BASIC

programs for the Commodore 64 is straightforward.

Although The Anatomy of the Commodore 64 is not written


for
the beginner, the first chapters should provide satisfactory
reading for most of you.
For those of you who want to start
at a more advanced level, start with Chapter 4 (SYNTHESIZEP)
and
Chapter 5 (GRAPHICS).
For you VIC-20 owners converting
to the Commodore 64, Chapter 7 gives you information on this
subject.

THE BUSINESS COMPUTER

The
Commodore
64 offers such high
price-performance
that
many
businesses find it extremely attractive in the
office
or
industry
setting.
Whether it is used
for
maintaining
mailing
lists
or accounts receivable,
drawing
graphs
or
charts, performing word processing
or playing the "what-if11
games,
it
can be a very productive member of the
business
team.

Without having to spend thousand of dollars,


sample
the
automated computer world
with

a business can
an
inexpensive

computers

purposes.

Commodore

THE

64.

are

We

really

find

that

being

used

many

for

Commodore

business

64

"home"

DEVELOPMENT COMPUTER

The
advanced
programmer will appreciate the
large
memory
bank
of the Commodore 64.
With 64K RAM and 20K
ROM,
the
Commodore
64
offers sufficient memory,
even for the
most
sophisticated programs.
The memory layout of the Commodore
64 is described in chapter 3.

This
can

memory coupled with many of the advanced


capabilities
be
used
to
full
advantage
from
machine
language

programs.

In

Commodore

64's

order

to

encourage

BASIC

programmers

to

use

to

the

machine language programming,


we present an introduction to
machine
and
assembler language programming in
Chapter
1.
Machine
language
or
assembler
language
programming
can
enhance
working
in BASIC and make you more
aware
of
the
In

chapter

potential.

6 we describe how to

add new

commands

BASIC interpreter.
After experimenting,
you should be able
to
create
your own new commands,
similar to ones
in
our
example
program.
An
important
help
is
the
extensively
documented
ROM listing of Commodore BASIC and the operating
system which

is

THE

COMPUTER

GRAPHICS

in APPENDIX

A.

With many other computers you have to buy expensive hardware


additions
to create graphics.
But the Commodore 64
offers

these features as standard.

The Commodore 64 gets its

high

resolution
color
graphics capabilities from a totally
new
computer
chip whose qualities and capabilities we
describe
in

Chapter

5.

We also describe the magic-like SPRITES.


user
definable
graphics symbols enable

These super-large,
arcade
and
educa
tional animation that,
in the past, were possible only with
a great amount of sophisticated programming.

THE

SYNTHESIZER

There's

music

in

the

Commodore

641

The
Commodore
64
uses a high
quality
synthesizer
which
rivals
some
dedicated music
machines.
Here
again,
the
reason
for
these
capabilities
is
a
newly
developed
integrated
circuit whose capabilities and possibilities
we
examine

closely

for

you.

All
that's
really missing is a
piano keyboard to
make
a
home
organ
out
of the
Commodore
64.
With
appropriate
programming,
this
organ
could outperform bigger and
much
more expensive ones.
Some keyboards are beginning to appear
on

the

market

now.

Another
interesting possibility is connecting the Commodore
64 to a stereo system.
Music lovers will be delighted with
the results.
Their ears will be pleasantly surprised.

THE

CONTROL

COMPUTER

The
Commodore 64 can be used for various kinds
of
control
purposes
provided
it is
appropriately
interfaced.
The
electronic
hobbyist and the industrial user can achieve
an
unusual amount of computer performance for their money. They
will soon find a lot of areas where the Commodore 64 can
be
used.
One of the areas described in this book is the use of

the
paddle
port as an A/D converter.
Further
hints
are
given in the description of the input/output control,
found
in Chapter 8.

YOUR OWN COMPUTER

Whether
you
bought the Commodore 64 for
composing
music,
maintaining
a mailing
list or learning
how
to
program,
The Anatomy of the Commodore 64
will
help
you
as
you
encounter Commodore

You

will

find

64's

fantastic

capabilities.

a range of applications

which you never thought were possible.

for

your

computer

CHAPTER Is MACHINE LANGUAGE PROGRAMMING ON THE COMMODORE 64

1.1

Introductory Concepts

The main programming language of the Commodore 64 is BASIC.


It's a language that is "spoken" by many computers and with
which the user can solve most all of his problems. The BASIC
language was originally developed for the beginner.
In the
course of time it became more and more common, and now it is
being used on

almost all

microcomputers.

Today, most computer companies offer a version of BASIC


written by the Microsoft Corporation. Since Microsoft BASIC
is similar for most computers, it is not very difficult to
rewrite programs for the Commodore 64.

Actually, the BASIC language is not directly understood by


the computer.
Though you write programs in BASIC, the
computer must

first

interpret the BASIC language statements.

The computer creates shorthand commands from the commands


that we enter at the keyboard and converts them into machine
language that the 6510 processor of the Commodore 64
understands.

Why not
simple.

write all your programs


Programming in machine

in machine language? Quite


language is time-consuming

and error prone, especially for the beginner.


Most BASIC
statements are equivalent to dozens of machine language
instructions.

Therefore

machine

lengthy than an equivalent

language

program

programs

written

in

are

BASIC.

more

Here's

a small example:

The 6510 CPU chip in the Commodore 64 can add numbers within
the range of 0 thru 255. To add numbers outside of this
range, then you must perform multiple additions.
you might program like this:
PRINT

The

whole

6+5

operation

can

be

entered

In machine language you would do the


CLC
LDA
ADC
JSR

a single

#$05
OUTPUT

;add 5 to accumulator
?print result

A
A
A

are

line.

following:

;clear carry flag


;load accumulator with 6

PHA
LSR
LSR
LSR

as

#$06

;here

OUTPUT

In BASIC

further

commands

;save the accumulator


;shift bits 7 thru 4
;
to bits 3 thru 0
;unoccupied bits become

LSR

JSR

HEXASC

;transform numbers into characters


;get accumulator from stack

PLA

#$0F

AND

HEXASC

CLC
ADC
BCC
ADC

;mask bits 7 thru


;clear carry flag

#$F6

;add 246
;result <=255? yes-skip
;add 6 decimal
;add 58 decimal
;output character

$04
#$06
#$3A
$FFD2

ADC
JMP

So
the same process of adding to number and displaying
the
results
requires more programming when written
in
machine
language.

How does

the

computer understand

these

instructions.

You
probably know that there are two electrical
conditions
in the field of electronics: POWER ON and POWER OFF.

We
also find these conditions in computer technology.
The
smallest
information
unit in data processing is
called
a
BIT
(binary digit).
Based on this idea,
the binary number
system

was developed.

The

binary number

system

includes

only
two (binary) numbers:
the 1 and the 0 (where 1 stands
for POWER ON and 0 for POWER OFF).
By combining strings of
l's and 0's you can create larger numbers.
The
6510 processor contained in the Commodore 64 works with
groups of 8-bit at a time.
Within a byte, each bit position
has a corresponding decimal value. These values are:

bit position
corresponding

value

b7

b6

b5

b4

b3

b2

bl

bO

128

64

32

16

Each
bit
position has a fixed value.
Its
value
can
easily
calculated
by raising 2 to the power
identical
position number:
The

value

of

b7
b6
b5
b4
b3
b2
bl

bO

(2**x

=
=
=

2**7
2**6
2**5

=
=
=
=
=

2**4
2**3
2**2
2**1
2**0

is pronounced

as 2

=
=
=
=

be
is

128
64
32
16
8
4
2
1

to the

x power)

Using this scheme,


numbers up to 255 can be represented.
For
example,
the
number
14 is represented as 00001110 and
is
equivalent to 0*128 + 0*64 + 0*32 + 0*16 + 1*8 + 1*4 + 1*2 +
0*1.
The
number
117
is represented as
01110101
and
is

equivalent to 0*128 + 1*64 +1*32 + 1*16 +0*8 + 1*4 + 0*2 +


1*1.
The electronic circuitry of the 6510 processor is set to
perform certain operation such as addition, subtraction,
logical testing or branching in response to certain bit
patterns.
perform a
is these

A set of bit patterns,


carefully arranged
desired set of operations is called a program.
programs which make the computer appear

to
It
to

understand.

So binary number system is fundamental to understanding


machine language. If you are not yet acquainted with this
system,

we

would

recommend

one

of

the

books

from

our

bibliography.

After this short introduction to the binary number


we move onto actual machine language programming.

system,

Comparing BASIC and machine language, you should recognize


that using machine language requires a different approach
than regular BASIC programming. It is certainly not easy for
the beginner to understand this new kind of programming.
But if you want to master the computer you need to deal with
machine

language.

For example,

if

you

want

to write

routine, you cannot do this with BASIC.


to understand the operating system

underpinnings of BASIC,
machine

there

is

fast

sort

or

search

For those who want


or to explore the

no other choice

than

using

language.

If you find
understand,

can

come

that this chapter is too difficult for you to


don't hesitate to skip it for now.
Later you
back to these chapters to review the material.
We

have tried to design all chapters, even those that deal with

machine language and assembler language programming, in a


way so that even beginners can understand them.
Many things
will become
clearer after you read them; others may still
be confusing.
For those want who to know more things about
machine
and assembler language programming, consult the
bibliography.

1.2

The MONITOR - and

its uses

In order to program in machine language you need a MONITOR.


A monitor is a program that allows you to inspect and change
the computer's memory and registers. Additionally you can
save and load programs with the monitor. Some monitors allow
you to disassemble memory (display the machine mnemonics
from raw code)
and lets you test and correct machine
language

programs.

Here

we show you how to work with a monitor.

illustrated

The

commands

are for the SUPERMON monitor included with

the

ASSEMBLER/MONITOR package from ABACUS Software.


But most of
these
commands are identical to the commands used by
other

monitors.

After
SUPERMON
is loaded from
diskette,
you
begin
the
monitor
by
typing RUN.
The monitor identifies
itself
by
printing
C*
and the contents of the 6510 registers on
the
screen.

The
registers are special memory locations contained in the
6510
processor that allow a ; computer to perform
arithmetic
and
logical operations,
keep track of
program
locations,
etc.

The purpose of
Program

the

individual

counter:

PC - keeps

within the program that


Interrupt

registers are:

vector:

track of

the

address

is to be processed next.

IRQ

- is

the

address

of

the

routine that gains control when a program interrupt


occurs.

Status
register:
SR
- contains
indicators
conditions
that
have
occured as
the
result
arithmetic or logical processing.

of
of

Accumulator:

of

AC

- contains

arithmetic or logical operations;

data during

the

results

used to transfer

input or output operations.

The
x-register:
XR
- index
register
differing ways to access memory

used

for

The
y-register:
YR
- index
register
differing ways to access memory

used

for

The stack pointer: SP - contains


top of the stack (work memory)
After
this:

RUNning

the monitor,

the

the

pointer

screen display

to

the

looks

like

C*
PC

.;

E145

SR AC

XR YR SP

31

E6

40

00

F6

All
data
is
displayed
or entered
into
the
monitor
in
hexadecimal number format.
For those of you unfamiliar with
hexadecimal

notation,

see

APPENDIX

B.

If

to

the

contents

of

you

want

change

any of

the

registers,

position the cursor over the appropriate "old value", type


in the "new

value"

and press

the

RETURN key.

The contents of memory can also be displayed and changed. To


display the contents of a certain memory range, enter the
command:

M XXXX YYYY <RETURN>

where M stands for MEMORY, XXXX for the 4-digit starting


address

Both

and YYYY

addresses

contents

of

the 4-digit ending address.

are

the

entered

memory

as

hexadecimal

locations

XXXX

numbers.

thru

The

YYYY

are

you

can

displayed. If the given memory range doesn't fit completely


on the screen, the screen scrolls upward line by line. By
pressing the STOP key, you get back in the command line.
As

with

the

changing

of

the

register

contents,

change individual memory locations. Simply place the cursor


over the corresponding "old value", enter the desired new
value"

and press

the RETURN key.

To enter a machine language program into memory use the M

command to display the contents of a particular area


memory.

Then position the

be overlayed with the desired machine langauge


in

their

The

hexadecimal

following

.M

is

in

cursor over the area of memory to

instructions

equivalents.

a display of a particular memory range:

C000

.: C000
.s C008
.: C010

C010

<RETURN>

A9 10 8D 16 03 A9 CO 8D
17 03 A9 43 85 97 DO 16
A9 42 85 97 D8 4A 68 8D

Memory can be displayed in another way by disassembling.


Disassembling attempts to convert the hexadecimal contents

of memory into the more easily understandable machine


language instructions called mnemonics. Each 6510 machine
language
instruction
is
represented
as
a
specific
hexadecimal value. Disassembling converts these hexadecimal
values
You
by

into the corresponding mnemonics.

can

disassemble

entering

.D C000

When

the

like

this:

the

contents

of

the

above

memory

range

the command:

C019

above

area

C000:

A9

of

10

<RETURN>

memory

is

disassembled

LDA #$10

it

would

look

Using

C002:
C005:
C007:

8D 16
A9 CO
8D 17

COOA:
COOC:
COOE:
CO1O:
C012:
C014:
C015:
C016:
C017:

A9

43

85

97
16
42
97

DO
A9

85
D8
4A

03

STA

LDA

03

STA
LDA

STA
BNE
LDA

STA

CLD
LSR

68

8D

$0316
#$C0
$0317
#$43
$97
$C026
#$42
$97
A

PLA

18

03

STA

$0318

the above as an example,

the hexadecimal value A9

stands for the mnemonic instruction LoaD Accumulator and the

value

8D

stands

for

Accumulator.

the

mnemonic

instruction

STore

The next step after entering or changing a program in memory


is program testing. You test you program by given the

monitor this command:

.G XXXX <RETURN>

Here G stands for GOTO and XXXX for the 4-digit hexadecimal
starting
address of the routine to be tested.

This command causes the monitor to jump to address XXXX and


begin executing the the machine program that's written
there. XXXX is any address within the Commodore 64's memory
range.

If the machine language program contains a BRK (BREAK)


instruction (hexadecimal value 00), the monitor stops,

identifies

contents.

itself

with

B*

and

displays

the

register

Here the program counter PC contains the address after the


BRK command.
By inserting BRK instructions at various
memory location of a machine language program,
it is
possible to test this program quickly and easily. After
testing the program,
you can replace the unneeded BRK

instruction with the original instruction

memory

location.

You can also save or load


from cassette or diskette.
To save

a machine

program

contained at

th*t

machine langauge program to or

on

cassette

or diskette,

enter:

.S "NAME",XX,YYYY,ZZZZ <RETURN>

indicates SAVE.

program

device

(the

For "NAME",

quotation marks

address

you can enter any name


are a must). XX

(01-cassette,

08-diskette),

is

for the

two-digit

YYYY

is

the

starting

address

and

ZZZZ

the ending

address

of

the

program

which must be hexadecimal.


After

pressing

the

RETURN

key,

the

machine

language

starting at address YYYY and ending at address


on

the

To

selected

LOAD program

ZZZZ

progrem

is

saved

device.
from cassette
.L

"NAME'rXX

or

diskette

enter:

<RETURN>

Here L means LOAD and XX the device address discussed above.

The address of the program is not needed. The program is


loaded into the area of memory from which it was originally
saved.

When you

are

finished using

the

monitor you

can exit

to

the

BASIC interpreted by entering X.

A monitor is an
programmer. If you
machine language
should become very

1.3

invaluable aid to the machine langauge


are going to do any significant amount of
or assembler language programming, you
familiar with the monitor.

How To Go About Programming

in Machine Language

If you are familiar with the monitor to some degree, you can

now

start with the actual programming.

Programming
1.

can

Firstly

you

program

is

be

divided

must

to

into

clearly

parts:

spell

accomplish.

out exactly what

You

must

decide

on

the

an

approach to take in building that program. Unfortu


nately this step is often given too little thought.
The programmer is too anxious to get to the pro
gramming step that the program suffers. The author

hasn't clearly thought out the method. This step is


vital regardless of the programming langauge used.
It must be addressed for a program written in BASIC
or a machine language or assembly language program.
For

example,

suppose

you

decide

that

you

need

to

compute the logarithm


in base 10 of
various
numbers. You could approach this program in several
ways: a) creating a table of logarithms and looking
them up as needed; b) finding the logarithm from

scratch by using a complex series of formulas; c)


using a derivative of a builtin function. By using
one of the builtin functions of the Commodore 64,
you can create a very simple solution.
This
eliminates the need for a complex program, thereby
simplifying the overall task to be done, namely to

10

compute

2.

the

common

logarithm for a given

argument.

Secondly
you
have
to decide where in
memory
to
place
the machine language program.
Most
machine
language programs run alongside a BASIC program. So
you

must

program
BASIC

make

sure

is protected

that

the

machine

language

from accident destruction

by

The simplest way is to tell BASIC that it has


only
a
certain amount of memory at its
disposal.
Thus
BASIC
can run concurrent with the machine language
program,
but
will
langauge program.

Another possibility

into
With

not

is

overwrite

to place

the

the machine

program

memory
where it can't be reached
by
the Commodore 64 this is no problem.

BASIC.
Of the

64K
RAM that Commodore 64 has,
BASIC can
only
39K,
while machine language has 52K
disposal.

3.

machine

Thirdly

you have to write the program

address
at
its

itself.

We

recommend
using
an
assembler
Without
using
an
assembler
you
will
have
to
hand-assemble
the
assembler language
source statements.
We'll leave
it to you to find a way of generating the resulting
machine language code.
We advise you to keep
your
routines as short as possible if you must resort to
hand
assembly techniques.
Also take advantage
of
the
builtin routines that are described
elsewhere
in
this manual.
They will save you much time
and
effort.

4.

Forthly
you have to decide how you will place
the
resultant machine language program into memory. One
way
is to POKE the resultant program
into
memory
from a BASIC program.
An alternative way is to use
a machine language monitor as previously described.
An
assembler
program
lets
you
assemble
code
directly into the computers memory.

5.

Lastly
you
have to decide how you will test
your
new
program.
It isn't too often that we
write
a
program which runs correctly the first time that we
try
it.
Once again,
the machine language monitor
offers
some
help in testing
these
programs.
By
inserting the BRK instructions into the program
to
be tested, you can cause the program to temporarily
halt
execution.
At this time you may examine
the

contents

of memory and

registers

and alter

them if

you desire.
Then you can continue the execution of
the program from this breakpoint.
If you don't use
a monitor,
then you will have to test
blindly.
A
single bad instruction in the program could hang up

11

the

Commodore

back

on

to

64 forcing you

recover

from

the

to

turn

it

off

and

error.

By
following these five steps,
you are creating a
careful
plan
and not a haphazard attempt
at your problem
solving.
Use good programming sytle right from the startl
The

following

First we
of
text
text

To

up

an

example

planned

program development.

state the objective of our program:


To type a line
in at the keyboard and then redisplay all
of
the
to

the

simplify

thar

is

are

part

Next we have

<RETURN> key.

the program,
of

the

we will

Commodore

to decide where

64

use

some

builtin

routines

ROMs.

this program is

to be placed

in

memory.

One place for a machine program with a maximum length of


4K
is
a
block
of 4K RAM in the upper part of
memory
($C000
upwards).
In that location, the program can't be destroyed
by

BASIC.

Alternatively
you
locate
a machine
language
program
in
memory that BASIC can access if you first protect this area.
From BASIC

this

is

done

as

POKE

55,XXX

POKE
CLR

56,YYY

follows:

where
XXX
and YYY are decimal numbers between 0
and
255.
POKE
55,XXX sets the least significant byte and 56,YYY
the
most significant byte (b4,b5,b6,b7) of the new "memory limit",
When

the

Commodore

64

is

first

turned

on,

memory

location

55

contains
the value 0 and memory location 56 the value
160.
Memory
location
55
holds the least significant
byte
and
memory
location 56 the most significant byte of the
memory
limit
of
BASIC.
If
you
convert
these
numbers
into
hexadecimal,
you find the value $A000.
This is the
normal
ending
address of BASIC.
By poking a different value
into
these
two locations,
you can make BASIC think that it
has
less
memory to work with.
For example,
you can POKE 55,0:
POKE 56,144 to set the new memory limit to $9000. BASIC will
think that the top of its memory is $9000.
Let's
say
that
we want our program to begin
starting
at
address 49152 ($C000) in a place inaccessible to BASIC.
The
program will then look like this:

12

ADDR

0000
COOO
COOO
COOO
COOO
COOO
C003
C005
C008
C00B
C00D
COOF
C012
C014
C016
C019
C01A
C01D
C020
C022
C025

VALUE

LABEL
BASIC
CLRSCR

OPERAND

ORG

$C000
$A474
$E544
$FFE4
$AB1E

EQU
EQU

GET

20
A2

44 E5
00
8E 2F CO
20 E4 FF
C9 00
FO F9
AE 2F CO
C9 OD
FO OA
9D 30 CO
E8
8E 2F CO
4C 08 CO
A9 00
9D 30 CO
A9 30

C027 AO
C029 20
C02C
C02F

4C
00

C030

00

EQU
STROUT EQU
START
JSR
LDX
LOOP

OUT

program

CLRSCR

;CLEAR SCREEN
;ZERO LENGTH
;SAVE IT
;READ KEYBOARD

#$00

STX

SAVEX

JSR

GET

CMP

#$00

;KEY

BEQ

LOOP

;NO-BACK!

LDX

SAVEX

CMP

#$0D

;RETURN

BEQ

OUT

STA

BUFF,X

;YES OUTPUT!
;NO-SAVE CHARACTER
;LENGTH TEXT +1

PRESSED?

;YES-RESTORE
KEY?

STX

SAVEX

;SAVE

JMP

LOOP

;READ AGAIN

LENGTH

LENGTH

LDA

#$00

;PLACE

STA

BUFFrX
#<BUFF

;
;LSB

LDA

CO
IE AB
74 A4

>M
>:
>:
>:
>:
>:
.:

REMARKS

I NX

$00 AT

END

OF TEXT
OF TEXT START

LDY

#>BUFF

JSR

STROUT

;MSB OF TEXT START


;PRINT STRING

JMP

SAVEX

BYT

BASIC
0

;X-REG

BUFF

DST

80

;RESERVE

The memory excerpt with

Our

OPC

;RETURN

the monitor

C028
COOO 20 44
C008 20 E4
C010 2F CO
C018 CO E8
C020 A9 00
C028 CO 20

looks

TO

BASIC

SAVE

like

80-BYTES

this:

COOO

is

instructions of

48

the

E5
FF
C9
8E
9D
IE

bytes

A2
C9
OD
2F
30
AB

00
00
FO
CO
CO
5C

8E
FO
OA
4C
A9
74

long.

2F
F9
9D
08
30
A4

It

CO
AE
30
CO
AO
00

uses

only

total 6510 instructions available.

The program is being


SYS

started

from BASIC with

the

few

command:

49152

The
purpose
of
this
SYS command is
to
call
a
machine
language
program
that
begins
at
memory
location
49152
($C000).
If the machine language program has errors in it,
your

computer

program may

offf

and

back on

this case,

"crash11

and

become

inoperable.

In

you have no alternative but to turn the computer

then

again.

13

By
the
way,
you
can
also use the SYS
command
to
call
routines in operating system (see Chapter 1.4). By using the
builtin routines,
you can save a lot of time and effort
in
your programming.
Now experiment with your own programs.

1.4

Useful

addresses

of

the

COMMODORE

64

ROMS

If you write your own programs in machine language,


you can
save
a lot of time by taking advantage of the ROM
routines
that are built into the Commodore 64.
Especially useful are
the
routines
for accessing the peripheral devices such
as
the printer or

floppy disk.

The
most
important
routines
of
the
Commodore
64
are
summarized
in
a jump table located at the end
of
memory.
This
jump
table contains the memory locations of
commonly
used routines of the operating system and is also called the
KERNAL. Commodore has promised not to change these addresses
as new Commodore computers appear on the market.
Therefore
it should be possible to transfer program to newer Commodore

computers

as

they are

introduced

if

these

Kernal

routines

are used. The jump table of the Commodore 64 is for the most
part identical with the VIC 20, so it is easy to convert VIC
20
programs to work with the Commodore 64 with the help
of
these routines.
NOw we

take

a closer

look at

some

of

these

routines:

ADDRESS

FUNCTION

$FF90

controls the output of kernal messages


if
bit 6 is set - control messages from
kernal
are displayed.
if bit 7 is set - error messages from kernal are
displayed.

$FF93

sends
secondary
address
after LISTEN command

$FF96

sends
secondary
after TALK command

$FF99

if
carry
address to

over

flag
set - returns
X and Y registers;

if

carry

flag

is reset - sets

if

carry

flag

is

address
$FF9C

address

over

address

to

that

contained

serial

bus

the

serial

bus

the

highest

RAM

the

highest

RAM

lowest

RAM

in X and Y registers;

set - returns

to X and Y registers;

14

the

the

if
carry
address to

flag is reset - sets the


lowest
RAM
that contained in X and Y registers;

$FF9F

SCAN keyboard

$FFA2

sets the time-out flag for the serial bus

$FFA5

$FFA8

for pressed keys

transfers

data

from

the

serial

bus

to

the

transfers

data

from

the

accumulator

to

the

accumulator

serial

bus

$FFAB

sends UNTALK command

$FFAE

sends UNLISTEN command to the serial bus

$FFB1

sends LISTEN command to the serial bus

$FFB4

sends TALK command to the serial bus

$FFB7

returns

$FFBA

the I/O status word

$FFC3

to the accumulator

sets

address

parameter

length of name,
filename

$FFC0

serial bus

sets the file parameters:


accumulator = logical
number;
X-reg
= device number;,
Y-reg
=

file

secondary

$FFBD

to the

OPEN logical
CLOSE logical

for

filename,

accumulator

X-reg and Y-reg = address of

=
the

file
file,

accumulator = logical

file

number

$FFC6

CHKIN
logical

prepares a logical
file

has

$FFC9

CHKOUT
prepares
logical file has

$FFCC

CLRCH resets

to

file

first be

for

a logical file for


to first be OPENed

input/output

to

input.

The

ouput.

The

OPENed.

the default devices

(keyboard/screen)

$FFCF

BASIN transfers
the

a character

from

input device

to

accumulator,

$FFD2

BSOUT transfers a character


to the output device.

$FFD5

LOAD program

$FFD8

SAVE programs

into memory
from memory

15

from the

accumulator

$FFDB

resets
contain

$FFDE

reads

$FFE1

checks

$FFE4

GET,

$FFE7
$FFEA ~

CLALL closes all open files


updates the system clock

$FFED

returns
in

$FFF0

$FFF3

the system clock.


A,X and
the number of jiffies.

the
to

see

gets

if

number of

registers

into A,X and Y registers.

STOP key

character

the

X and

if
in

system clock

is

into

depressed

the

accumulator

columns/rows on

the

screen

Y registers

carry
Y-reg

flag is set - returns cursor


position
(# of columns) and
X-reg
(# of rows)
if carry flag is reset - sets cursor position to
row in X-reg and column in Y-reg.

returns

the

starting

address

of

the

I/O

component

There
are
other
routines available for
manipulating
screen.The more important routines are listed below:
ADDRESS

FUNCTION

$E518
$E544

completly
reset
the
CLR - clear the screen

$E566

HOME

- position

corner

$E56C

$E5A0

of

the

calculates
address at

loads

the

screen

cursor

to

and

the

keyboard

upper

left

screen

the
cursor position and
$D1-D2 (209-210 decimal).

the

the

the

video controller with

places

its

the

standard

10-byte

keyboard

values

$E5B4

gets

character

from of

the

buffer

$E5CA

waits

for keyboard

$E8EA

scrolls

$E9FF

blank one

$EA1C

sets
a
current

screen

input

up one

screen

line

line designed

by X-reg.

character
in
color on
the
screen
at
cursor
position
(screen
code
in
the

accumulator

and

color

16

in X-reg)

1.5

DATA INPUT/OUTPUT FROM MACHINE LANGUAGE PROGRAMS

There

are

two ways

to perform data

input

or

output

from

machine
language
programs on your Commodore
64.
You
can
write the routines yourself or you can use the routines that
are

part

of

the

builtin

operating

system.

This section describes how you can use the routines that are

part

of

the operating

system.

The biggest

using
these builtin ROM routines is that they
written and are proven to work correctly.

1.5.1
The

advantage

are

of

already

Input and Output of Single Characters


two basic routines

called:

BASIN which

is

for inputting or outputting data are

located at $FFCF and

inputs a character

and

BSOUT which
The

bytes

accumulator.

Example:
OUTPUT
LI

is

to be

located at $FFD2 and outputs a character


input or output

Output 12-byte
LDX
LDA
JSR

string of

BNE

#12
LI

RTS
TEXT

ASC

1 EXAMPLE

transferred

text

to

the

via

the

screen.

;zero index register


;get one character text
;and display it on screen
;point to next character
;all characters yet?
;no-keep going
;yes-we're done

#0
TEXT,X
BSOUT

INX

CPX

are

TEXT

Input is performed similarly. For instance, if text is


entered
from
the keyboard ,
the cursor flashes
and
character is accepted until the RETURN key is pressed.
INPUT

LDX

#0

;zero

LI

JSR

BASIN

STA

TEXT,X

;get a character from keyboard


;and save it
;point to next character
;RETURN key pressed?
;no, get more characters
;yes-we're done
;space for saving the text

INX
CMP
BNE

#13
LI

RTS
TEXT

When

DST

80

writing onto

the

screenf

you

17

index

to be
each

can

register

take

full

advantage

of

the
screen control characters.
For instance,
you can use
the
control character for clearing the screen
or
changing
the character colors. The appropriate control code is loaded
into the accumulator and sent to the output routine (BSOUT).
Example:

For
the
routines
for

clear
LDA

#147

;code

JSR

BSOUT

;output

clearing

A routine

the

screen

can be

clearing

the

screen

for homing

the

cursor

HOME

want

called directly -

;located

CLRSCR

JSR
you

for

screen output there are some


additional,
helpful
which can simplify your programming.
The
routine

JSR

If

screen

place

to

the

$E544

is:

;located

position:

at

cursor

at $E566
at

specific

LDX

#LINE

LDY

#COL

;line number, 0
;column number,

CURSOR

;set carry clear


;position cursor

= cursor
$FFF0

output

CLC
JSR
LDA

#'A

;character

JSR

BSOUT

;output

to

screen

to 24
0 to 39

be

The
routine called CURSOR has two functions.
When
called
with
carry
flag
clear
(as
in
the
above
example),
it
positions
the cursor at the line and the column that are in
the
X
and the Y register.
If CURSOR is called
with
the
carry
you

flag

in

Once

set,

the

again here

are

$FFCF

BASOUT
CLRSCR

$FFD2
$E544
$FFF0
$E566

HOME

For

the

BASIN

CURSOR

1.5.2

current

cursor position

is

returned

to

the X and Y registers.

Input

input

addresses

of

the

routines

used

above:

and Output Using Peripheral Devices

and

system contains

The peripheral

output
the

are

using peripheral

necessary

routines.

assigned a device

18

devices

number

the

from 0

operating

to 15.

NUMBER

DEVICE

0
1
2
3
4-15

keyboard
datasette
RS 232 interface
screen
devices of the serial

bus

In addition to this device number,


there may be a secondary
address
which further specifies information required by the
peripheral device and a file name. To establish a connection
to

the peripheral,

you must OPEN a file.

The OPEN command specifies a logical file number,


a
device
number
and the optional secondary address.
So as to
avoid
specifying
the peripheral device number each time you want
to
transfer information,
only the logical file
number
is
used
after
the OPEN is complete.
The logical file
number
then refers to the device number and secondary address
with

which

it was OPENed.

Again,
before any transfer of information can happen to or
from peripheral devices,
a file must be OPENed.
You
can
OPEN a file from BASIC or from a machine language program.
To

OPEN

file

from a machine language program

you

must

the

file

first set the file parameters.


You must place the
logical
file number in memory location $B8 (184);
the device number
in $BA (186), secondary address in $B9 (185); length of file
name
in $B7 (183) (zero if no file name is given);
and the
address of the file name in $BB/$BC (187/188).
Then the you

may call

The

the

kernal

parameters.

routine

contains

The

to OPEN a

routine

several

SETLFS

file

at $FFC0.

routines

($FFBA)

to

sets

set

the

logical

file

number,
device
number and secondary address.
The
routine
SETNAM
($FFBD)
sets the filename for OPEN,
LOAD and
SAVE
routines. The following example illustrates the use of these
routines:

LDA
LDX

#1

;logical file number in accumulator


;device number in X-register

#8

LDY

#4

JSR

SETLFS

LDA

#LNAME

LDX

#<NAME

;secondary address in Y-register


;located at $FFBA
;length of filename
;low order address of filename

LDY

#>NAME

;high

JSR

SETNAM

JSR

OPEN

;located
;located

at
at

;this
;this

the
the

NAME

ASC

FILE1

LNAME

BYT

order

is
is

19

address of

filename

$FFBD
$FFC0

filename
length of

filename

Before
writing
output to an OPEN file you must:
call
the
routine CHKOUT ($FFC9) in order to ready the output path
to
the
peripheral
associated
with the logical
file
number;
place the data to be transferred into the
accumulator;
and
call BSOUT ($FFD2)

to output

the data.

Here's a short program that does


LDX

#LF

;logical

JSR

CHKOUT

;$FFC9
;place

LDA

DATA

JSR

BSOUT

this:

file

data

number

into

;write data

accumulator

to output

file

All
output
is directed to this device
until
the
routine
CLRCH
is
called.
CLRCH reset the standard
ouput
to
the
screen,
so
that
subsequent calls to BSOUT results in
the
data

being
JSR

If

you

sent

to

the

CLRCH

screen.
;$FFCC

reset

output

want to input data from a file:

to

screen

call

the

routine

CHKIN
($FFC6)
in
order
to ready the input
path
to
the
peripheral associated with the logical file number; and call
BASIN ($FFCF) to input the data.
BASIN will return the data
in

the

accumulator.

LDX

#LF

;file number of

JSR
JSR
STA

CHKIN
BASIN
DATA

;located at $FFC6
;located at $FFCF
;save the data

the

input device

All
data is input from this device until the routine
CLRCH
is called.
CLRCH reset the standard input to the
keyboard,
so
that
subsequent
calls to BASIN results in
data
being
input

from

the

keyboard.

When
CLRCH is called,
all files
redirects
input and output to or
of the Commodore 64 (keyboard and
When
must

you
close

remain open.
CLRCH merely
from the standard
devices
screen respectively).

are finished using an input or output


each using the routine CLOSE ($FFC3).

LDX

#LF

;logical

file

JSR

CLOSE

;located

at $FFC3

The
alternative is to
routine CLALL ($FFE7).
JSR

CLALL

you

using

the

number

close

all

of

;close

all

open

20

file,

the

files

files

by

1.5.3

Saving

and Loading Data

For saving data and programs, the Commodore 64 offers you


both tape and disk for secondary storage. Since both devices
operate quite differently they are described separately.
1.5.3.1

Saving Data on Cassette

A cassette recorder allows sequential recording of data and


reading it in that same order.
You must read through all
the data on a tape until you encounter the desired data.
Likewise, you cannot change data written to a tape. You can
only read the file completely through, change it in the
computer's memory, and then rewrite the entire file onto the
tape.

Since saving or loading programs requires only sequential


writing or reading, a cassette recorder is a suitable medium
for program storage.
The major disadvantage or cassette is
the slow speed of data transfer.
For reliability, data is written to the tape redundantly.
Later, if errors are detected when reading the tape, the
redundant

Let's

take

data

can

closer

be

used

look

at

to

correct

the

the

technique

errors.

of

writing

data

to

tape.

A
file
is
written
to
tape
in
three
parts.
First
a
synchronizing sound is written to the tape. The enables the
Commodore 64 to prepare itself for subsequent data transfer.
Next a header is written to the tape. The header contains

identifying information about the file that follows. Finally


the data is written to the tape. This data is written
redundantly.

Since various forms of data can be saved to tape, there must


be a way to distinguish them from one another. This is the
purpose of the header. The header contains the following
information:
position
within header
1

Value
type

of

value:

header

meaning:

BASIC program -

it

is

loaded

at

the

starting

BASIC address
data block - bytes

machine

2-192

21

contain

the

language

data
program

loaded at absolute addr


data header-data follows

2-3
4-5
6-21

For

the

addresses of

itself

is

redundantly

block of tape

staring address (low,high)


ending address (lowrhigh)
file name

header types 1

program),

end-of-tape
denotes end

(BASIC program)

header

specifies

the program and

contained

the

or 3

(machine

the starting

program name.

in the next

block.

It

and

The

is

language

ending

program

recorded

(twice).

For
header type lf
the starting address specified
in
the
header
is ignored,
and the BASIC program contained on
the
tape
is
loaded beginning at the starting address of
BASIC

(normally
$800).
By using a secondary address of 1
during
loading,
you can override the starting address of BASIC and
force
the
program
to be loaded at
the
starting
address
indicated in the header.
This is absolutely necessary
when
loading
machine language programs,
since such programs can
only run in the memory area for which they were written.
SAVE nPRGMln,l
SAVE fIPRGK2M,l,l

SAVE BASIC PROGRAM


SAVE PROGRAM AS MACHINE

LANG.

For header type 3, a program is loaded into the Commodore 64


beginning
at the starting address specified in the
header.
For
header type 2,
data (not a program) is written to
the

cassette

tape

in blocks of 192 characters at a

time.

This

avoids
the time consuming process of starting and
stopping
the
cassette
drive
each
time
a
character
is
to
be
transferred. As each PRINT* command is performed, instead of
writing single characters to the tape, the data is collected
in
a
tape
buffer
until 192
such
characters
have
been
collected.
When
the tape buffer is full,
the data in
the
buffer
is written to the tape.
The buffer is then
emptied
and readied for the next 192 characters.
The tape buffer is
located

at

the

address

828

thru

1019

($33C -

$3FB).

When reading from a tape file using INPUT# or GET#,


instead
of reading single characters from the tape,
a data block is
read into the tape buffer.
Each character read with
INPUT#
or GET# is retrieved from the data in the tape buffer.
When
all
192
characters of the block have been
processed,
the

buffer

is

Saying
writes

a
program with a secondary address of 2 or
3
also
an end-of-tape block after the program is
recorded.

read

An

said

from the

end-of-tape

searching

recorded

for

to be empty and

tape and

beyond

into

the

the next block of

tape

block will prevent

any program on the


the end-of-tape

22

buffer.

the

Commodore

tape that may

block.

data

64

have

is

from

been

Summarizing all the relations in a table again:

LOAD

LOAD

"NAMEn,l

loads BASIC program,


at the start
of BASIC.
Type 3 header is loaded

LOAD

"NAME",

loads every program absolutely

absolutely.

SAVE

SAVE "NAME'M
SAVE "NAME",1,1
SAVE "NAME",1,2

SAVE "NAME",1,3

When

saves

saves

a machine program

BASIC

program

saves

BASIC program with

opening a tape data file for processing the

secondary

address has the following meaning:


OPEN 1,1,0
OPEN 1,1,1
OPEN 1,1,2,

an

additional EOT block


saves as machine program with an
additional EOT block

"NAME" - opens file for reading


"NAME" - opens file for writing
"NAME" - opens file for writing with an
additional EOT block

The
CLOSE command performs the necessary housekeeping
for
the file.
If the file was open for writing,
a zero byte is
written into the tape buffer and the buffer is written
onto
the tape.
Thus it is absolutely necessary
to CLOSE a tape
file. Otherwise, the final data is not written to the tape.
There
tape.

are

also restrictions concerning data transfer

Normally

data

is written onto the

tape

in

onto

ASCII

format (letters,
digits,
arid special symbols).
If data is
written with PRINT#1,
CHR$(I), not all possible symbols can
be written.
In particular, CHR$(0) is filtered out, because
it is used as an end symbol by the operation system.
1.5.3.2

Saving Data on Diskette

A diskette is divided into tracks and sectors


accessed individually. That makes it possible
access
data.

to

data without

having

to

read

thru

which can
be
to have direct
all

the

other

Programs
are saved as follows.
The address of the
program
are transferred to the program file on diskette. The address
is
sent
least significant byte first followed by the
most
significant byte. Then the program itself is transferred. On

23

disk,

there

is

when

LOADing

no difference

between

or a machine language program.

LOAD

the

a BASIC program

program.

"NAME",8

LOAD

saving

A distinction is only made

loads

"NAME",8,1

BASIC program

BASIC

address

saved

starting

loads BASIC program

at

start of

starting at

address

the

If you want to find the starting address of a program that


is contained on a diskette,

you can use this little program:

10 OPEN 1,8,1,"NAME11

:REM program file for reading

20
30
40
50

GET#1, AS,
B$
:REM get start address
IF A$ = " " THEN A$ = CHR$(0)
IF B$ = " " THEN B$ = CHR$(0)
PRINT ASC(A$)+256*ASC(B$) :REM decimal address

60

CLOSE

The

starting

address

of

the

program

is

printed

out

in

decimal. The test for a null string in lines 30 and 40 is


necessary, because the GET command does not accept a byte
with

zero

value.

If you want to write a machine language program to diskette,


you can do

it

like

this:

10 OPEN 1,8,0,"NAME,P,W"

:REM program file

30 PRINT#1, CHR$(AD/256);

:REM start address high

20 PRINT#1,

CHR$(AD-INT(AD/256)*256)?:REM address

40 FOR 1=0 TO N-l


50 PRINT#1, CHR$(PEEK(AD+D);
60 NEXTI
60 CLOSE

low

s-REM save N bytes


:REM this is your

sREM
program data
*REM close program file

The variable AD contains the starting address of the machine


language

program and the variable

the program

in

N contains

the

length of

bytes.

How do you save programs or areas of memory from within a


machine language program?

Here

again

we

have

two

operating

system

routines

can

be

used:

LOAD

$FFD5

SAVE

$FPD8

The LOAD routine is used in the following way:


The

name of the file and the appropriate device number must


be set using the kernal routines SETFLS ($FFBA) and SETNAM
($FFBD). The accumulator
is loaded with zero to indicate
that a LOAD is to be performed. If LOAD is called with 1 in

24

the accumulator,

VERIFY is performed

instead of LOAD.

The secondary address determines where in memory the loading


is to take place. If the secondary address is 1 or 2, the
program is loaded at the address from which the program was
saved.

loaded

If

the

at

(low/high).

Example:

original

the

secondary

address

Loading

of

address.
LDA

#8

LDX

#8

LDY

#1

JSR

SETFLS

LDA

#5

LDX
LDY

#<NAME
#>NAME

JSR

SETNAM

LDA

#0

JSR

LOAD

STX

ADR

STY

ADR+1

address

specified

machine

is

zero,

the

program

is

by the X and Y registers

program

from

diskette, to

the

;logical file number


;device number of the floppy
;secondary address
;located at $FFBA-set file parms.
;length of the file name
;address of the file name
;high byte of the address
;located at $FFBD-set file name

;LOAD flag
;load program
;end address low
;end address high

NAME

ASC

'FILEl'

Note that the LOAD routine returns the ending address of


loaded program in the X and Y registers.

the

In the following example, a program is loaded from the tape,


starting at address $6000.
The saved address is ignored.

LDY

#1
#1
#0

JSR

SETLFS

LDA

#5

LDX
LDY

#<NAME
#>NAME

JSR

SETNAM

LDA

LDX

LDA

#0

LDX

#$00
#$60

LDY
JSR

NAME

LOAD

STX

ADR

STY

ADR+1

ASC

IFILE2I

;logical file number


;device number cassette recorder
;secondary address
;at $FFBA-set file parameters
;length of the file name
;address of file name
;high byte of address
;at $FFBD-set parms for file name
;LOAD-flag
;load address low
;load address high
;load program
;end address low
;end address high

25

If a machine program is to be loaded with LOAD from


program, you will encounter a few difficulties.

a BASIC

You can load a program at an absolute address by using a


secondary address of 0 during OPEN, but there still is a
problem.
After every LOAD, the ending address of the load

is set equal to the ending address of the BASIC program and


program execution starts at the beginning of the program.

This makes sense

for

reloading

of

BASIC programs

(overlay),

but it creates problems when loading of machine language


programs or the contents of a range or memory.
In such a
case, you can use a small machine language program (such as
in the previous example) that you can call from the BASIC
program

by

SYS.

Saving programs and any memory ranges with the SAVE routine
happens similarly. In addition to the device number and file
name information, the SAVE routine has to know the starting

and the ending address of the program. The starting address


kept in zero page in two consecutive memory locations (low

and high byte).

The address of this zero page

location

is

transferred to the SAVE routine via the accumulator. The


ending address is in the X-register (low byte) and the Yregister

(high

byte).

Suppose we now want to save the memory range from $C000


through $CFFF on a diskette under the name "PGRMB". The
starting address of the program is in $FB/$FC.
LDA
LDX
LDY

#1
#8
#0

;logical file number


;device number of the
;secondary address

JSR
LDA
LDX

SETLFS
#5
#<NAME
#>NAME
SETNAM
#$C0

;at $FFBA-set file parameter


;length of file name
;address of file name

STA

$FC

LDA
STA
LDA
LDX
LDY

#$00
$FB
#$FB
#$00
#$D0

;address low of the start


;
of the program
;pointer on start address
;end address +1 low
;end address +1 high

JSR

SAVE

;save

ASC

'PGRMB1

LDY

JSR
LDA

NAME

;high

byte

of

floppy

address

;at $FFBD-set parms for file


;address high of the start
of

;file

the

name

program

program

name

In the above example, the ending address of the program


passed to the SAVE routine in the X and Y registers.

As

final

example,

here

is

how

26

to

save

BASIC

is

program

without a file name but with EOT symbol on tape:


LDA

#1
#1

LDX
LDY

;logical file number


;device number of the recorder
;secondary address for EOT
;at $FFBA-set file parameter
;no file names

#2

JSR

SETLFS

LDA

#0

JSR

SETNAM

LDA
LDX

;pointer to BASIC program start

LDY

#$2B
#$2D
#$2E

JSR

SAVE

;save

;at $FFBD-set parms

for

;end address low of


;end address high

the program

1.5.4 Programming the RS-232

file

names

program

Interface

The
Commodore 64 has an RS-232 interface for connection
to
any
peripheral
device that follows
the
RS-232
protocol.
There are hundreds of devices on the market that use RS-232.
These
include
printers,
modems,
plotters
and
A/D
controllers.

The
RS-232
interface transfers data
serially.
What
does
serial
transfer mean and when is it used?
The Commodore 64
stores
data
in characters consisting of
8
bits.
When
a
character
is
to be sent to or received from
a
peripheral
device
by
a
serial method,
each
of
the
8
bits
are
transferred one

bit

at

a time.

In contrast,
a character can also be sent using a
parallel
method
of transfer.
Here,
all 8 bits are sent or received
from
a
peripheral device at one
time.
The
advantage
of
parallel transfer is that it is faster than serial transfer.
But
parallel
transfer is also more expensive as
each
bit
must
have
its
own
line
over
which
to
transfer
the
information. Using serial transfer, fewer lines are required
as
each
bit
waits its turn to be sent to
the
peripheral
device.

The

kernal of

the Commodore 64 contains software

necessary

to use the RS-232 interface. You can purchase a standard RS232 connector as an add-on module, which can then be plugged

into

the

Commodore

232 device.

USER
64

is

port.

ready

to

With

this

RS-232

communicate with

connector,

any

standard

the

RS-

The RS-232 interface is assigned a device number of-2.


When
a logical file
using device number 2 is OPENed,
the kernal
sets aside two buffers of 256 characters each for use by the
RS-232 device.
One buffer is used for data that is inputted
from
the peripheral and the second buffer is used for
data
that
These

is

outputted

buffers

are

to

the

peripheral.

normally

set

27

aside

in memory

at

the

end

of

BASIC

program

RAM.

If

the RS-232

interface

is

used

from

BASIC

you should OPEN the RS-232 device before allocating

any
string variables.
If not,
when the RS-232
device
is
OPENed
and the two buffers are allocated,
then the
string
variables

Also
for

are

note
the

overwritten

and

that only one

RS-232

destroyed.

channel

can be

OPENed

at one

time

interface.

The
characteristics
of the RS-232 interface
can
adjusted
when the channel
is OPENed.
This is done by setting both a
control

register

and

command

register.

The
control
register serves to define the baud
rate,
number of data bits and the number of stop bits that are
be
transferred.
The baud rate determines the speed of

the
to
the

data
transfer in bits per second.
The number of data
bits
determines the length of each word (or character) that is to
be transferred.
The number stop bits are the number of bits
to be

sent

after each word.

In the control
rate according
BIT

register, the lower 4 bits determine


to the following table:
DECIMAL

10

0
0
0
0

0
0
0
0

0
0
1

0
1
0

0
1

3
4
5
6
7
8
9
10
11
12

BAUD

set

0
0 1
110

111
0 0 0
0 0 1
0 10
0 11
1 1 0 0
1 1 0 1
1110
1111

RATE

by

user

(not

implemented)

50
75
110
134.5
150
300

the baud

600
1200

1800
2400
3600
4800
7200
9600
19200

13
14
15

(not
(not

(not
(not
(not

implemented)
implemented)
implemented)
implemented)
implemented)

You
can
program
the RS-232 interface to
use
baud
rates
between 50 and 2400.
The number of data bits are determined
by bit 5 and 6.

BIT

DECIMAL

0
1
1

1
0
1

32
64
96

NUMBER

8
7
6
5

28

OF

DATA

bits
bits
bits
bits

BITS

The number of stop bits


BIT 7

is determined by bit 7.

DECIMAL

0
1

NUMBER OF STOP BITS

0
128

1
2

The command register determines the transfer mode,

type

parity and mode of handshake.

of

The command register is organized as follows:


BIT 0

DECIMAL

0
1

0
1

BIT

BIT

no

1 1

no parity check,
always

always

no parity check,

try an example.
with

check,

the

2 stop bits
no parity check
8th data bit always 0
full duplex
3-wire handshake

The OPEN directions would

value

8th data bit

an

RS-232

in decimal
10
0
128
0
224
0
0

then look like this:

29

8th

8th data bit

Suppose you want to OPEN

following parameters:

parameter
transfer rate 2400 baud
8 bit ASCII data

no

bit

odd parity
even parity

224

channel,

CHECK

parity

data

32
96
160

10 1

Let's

PARITY

0 0 1
Oil

handshake
handshake

TRANSFER MODE
full duplex
half duplex

DECIMAL

X X 0

3-wire
X-wire

DECIMAL
0
16

0
1

data

HANDSHAKE

OPEN 1,2,0fCHR$(10+0+128)+CHR$(0+0+224)

Input
and
output
peripheral devices.
the

are
handled
the
same
as
with
other
BASIN and BSOUT transfer data to or from

RS-232 device.

The only difference is the status register (ST).


When using
RS-232,
the
status
register
returns a different
set
of
errors than when using other input or output devices.
Reading

the

status variable

ST from BASIC clears

status variable

from a machine

the

status

each time it is read. Therefore you should always assign the


status
variable to another variable if you want to remember
its

value.

does

not

Reading

the

clear

the

language

program

status.

ST
gives you only the RS-232 status for data exchanged over
the RS-232 interface.
The meaning of the different bits
of

the
is

RS-232 status is described below.

set

(on),

then

BIT

DESCRIPTION

0
1
2

parity mistake
frame mistake
receiver buffer

unused

unused

break

If a particular bit

that particular condition has occurred.

CTS

full

(clear to send)

DSR (data

signal missing

set ready)

signal

signal missing

received

If
you using the RS-232 interface from a
machine
program, you can place the input and output buffers
transmission anywhere in memory.

language
for data

The
pointers
to
these buffers are
set
during
the
OPEN
command, but may be moved after the OPEN is complete.
These
pointers
are
located in zero page:
$F7/$F8 points to
the
input
buffer
and
$F9/$FA
points to
the
output
buffer.
Programming
the
RS-232 is similar to programming
for
any
other
input or output device except that the device
number
is 2.
Other

important
$0293
$0294
$0298
$0297

addresses

for

RS-232

input/output

control word
command word
number of data bits,
PS-232 status word

30

computed

at

are:

OPEN

1.5.5

The Serial Bus

In
order
Commodore

to
communicate
with
peripheral
devices,
64 has a serial bus to which several devices

the
can

be
connected
at
the
same
time.
From
a
programming
standpoint,
the
bus
is similar to the
IEEE-488
bus
of
earlier Commodore computers (PET, 8032, 4032, etc.). But the
data is transmitted bit by bit over the serial bus.
This is
unlike
the IEEE-488 which transmits data in
parallel.
The
transmission
speed
of
the
serial
bus
is
therefore
considerably

slower.

First we explain the concept of the serial bus.

Since several devices can be connected to the serial bus


at
the same time,
there must to be a way of distinguishing one
device
from another.
This is the purpose
of
the
device
number.
The
Commodore 64 assigns device numbers 4 thru 31
to

the

serial

bus.

When a device is addressed, the Commodore 64 (called the bus


controller) sends an attention signal (called ATN)
over the
bus.
This alerts all connected devices that they should
be
aware
that
communication is being established with one
of
them.
Next
the
Commodore 64 sends device
number
of
the
desired
device over the bus.
If the device is attached
to
the
bus,
then it responds to the ATN,
otherwise we get
a

message

Next,

DEVICE

the

NOT PRESENT.

device

is

informed

that

it

is

to either

data from or transmit data to the Commodore 64.

is

to

receive data,

then the Commodore 64 sends a

command to the device. If a device


Commodore 64
sends a TALK command

is to send data,
to the device.

sent

secondary

address

may also be

to

the

receive

If a device

LISTEN

then

the

device

to

perform
any
necessary
setup.
For
example:
OPEN
1,4,7
transmits
secondary
address
7 to the printer
(device
4)
which selects UPPER/LOWER case mode for printing.
Now
the data can be sent to the device or received
device.
In
order
for the data
transmission
to

from the
function

accurately, data is transmitted one character at a time. The


receiver
of
the data informs the sender when the data
has
been
successfully
accepted.
Only
when
the
receiver
acknowledges the receipt of the data may the sender transmit
another
character
of
data.
This
procedure
is
called
handshaking
and
insures the integrity of the
data
as
it
transmitted.
When
the
data
transmission is
complete,
the
device
is
deaddressed:
if the device was sending data,
the Commodore
64 sends it an
UNTALK command;
if the device was receiving
data,
the
Commodore 64
sends it an UNLISTEN
command.
At

31

this

point,

Now

we move on

language

the

bus

is

free

to

handle

to programming

the

the

serial

next

bus

transmission.

from a machine

program!

The kernal
necessary

of the Commodore 64 contains all of the


routines
for
communicating with devices over
the
serial

bus.

Let's
show
you
an example of the use
of
some
of
these
builtin kernal routines.
This short example reads the error
channel from the disk drive.
First we show you how to read
the error channel using a BASIC program:
10
20

REM open

OPEN 15r8f15:
INPUT#15,A$fB$,C$,D$:

REM

30

PRINT A$;nrn;B$;tl,tl;C$;1

40

CLOSE

15:

get

error
error

channel
message

r;D$:REM and output


REM close channel

You
can
do this only in program mode
(not
command
mode)
because the INPUT command is valid only in program mode.
This machine program does the same thing:

cooo
C002
C004
C007

C009
C00B
C00E

con
C014

C016
C018
C01B

A9 08
85 BA
20 B4 FF
A9 6F
85 B9
20 96 FF
20 A5 FF
20 D2 FF
C9 OD
DO F6
20 AB FF
60

ACPTR

EQU

CHROUT

EQU

$FFA5
$FFD2
$BA

FA

EQU

SA

EQU

TALK

EQU

$B9
$FFB4

TKSA

EQU

$FF96

UNTLK

EQU

$FFAB

START

LDA

#8

STA

FA

JSR

TALK

LOOP

LDA

#15+$60

STA

SA

JSR

TKSA

JSR

ACPTR

JSR

CHROUT

CMP

#13

BNE

LOOP

JSR

UNTLK

RTS

From BASIC you

can

call

this

routine

;device number of disk


;set device no.
;send talk
;sec. addr 15 + $60
;sec. addr for talk
;read byte from device
;display on screen
;is it carriage return?
;no-go back for more
;yes-send untalk
;return to caller

by

typing SYS

12*4096.

With the next machine language program,


you can display the
directory of a diskette. Using this routine, you do not have
to
LOAD"$",8
to view the directory and
consequently
lose
your

current

BASIC

program.

32

A9

C002
C004
C006
C008
COOA
COOC

85 FB
A9 FB
85 BB

CO1O
C012
C014

C016
C018
C01B
C01D
C020
C022
C025

C027
CO29
C02B
C02D

C030
C032
C034
C036
C039
C03B
C03D
C03F
C040
C042
C044
C047

C049
C04C
C04F
C051
C053
CO54
C056
C059
C05C

EQU

CHROUT
CLSFIL

EQU

FA

EQU
EQU

FNADP

EQU

FNLEN

LNPRT

EQU
EQU

SA

EQU

SENDNM

EQU

STATUS

EQU

TALK

EQU

TKSA

cooo

COOE

ACPTR

24

AA

20
4C
A9

$B7
$BDCD
$B9
$F3D5
$90
$FFB4
$FF96

#'$

LDA

$FB
#$FB

STA

FNADR

STA

A9 00
85 BC
A9 01
85 B7
A9 08
85 BA
A9 60
85 B9
20 D5 F3
A5 BA
20 B4 FF
A5 B9
20 96 FF
A9 00
85 90
AO
03
84 FB
LI
20 A5 FF
85 FC
A4 90
DO 2F
20 A5 FF
A4 90
DO 28
A4 FB
88
DO E9
A6 FC
20 CD BD
A9 20
20 D2 FF
20 A5 FF L3
A6 90
DO 12
FO

EQU

LDA

$FFA5
$FFD2
$F642
$BA
$BB

LDA

#0

STA

FNADR+1

LDA
STA

#1

L2

is

file

LDA

#8

STA

FA

;addr of

file

name

;high byte
;length of

file

;dev.addr of

LDA

#$60

STA

SA

JSR

LDA

addr

for

SENDNM
FA

;open

file

with

JSR

TALK

;send

talk

LDA

SA

JSR

TKSA

;send

sec

LDA

#0

STA

STATUS

LDY

STY

#3
$FB

JSR

ACPTR

STA

JSR

$FC
STATUS
L4
ACPTR

LDY

STATUS

;test

BNE

L4
$FB

;get

LDY

LDY

DEY
BNE

name

floppy

;sec.

BNE

name

FNLEN

LOAD

name

addr

;clear status
;skip first three
;save

as

byte from
save it
;status ok?
;no-get

;get

bytes

counter

;get
;and

floppy

out

byte

from

floppy

status
counter

and

decrement

LI

LDX

$FC

JSP

LNPRT

LDA

;output no. blks


;space between

JSR

#'

CHROUT

JSR

ACPTE

;get

LDX

STATUS

;test

BNE

L4

TAX

06
D2 FF
4C CO
OD

;$ char
;save

next

used

byte

status

;zero?

BEQ

L2

7yes-then

JSR

CHROUT

7no-output

JMP

L3

LDA

#13

?and get next character


?carriaqe return

33

end

of

line

C05E

20

D2

JSR

CHROUT

;output

C061
C063
C065

A0

02

LDY

#2

DO
20
60

C6
42

BNE

LI

JSR

CLSFIL

;2 bytes addr
;continue
;close file
;all done

C068

This

The

FF

F6

RTS

routine

directory

without

L4

losing

is again called from BASIC with SYS


of the diskette

your

BASIC

is displayed on

program.

34

the

12*4096.

screen

CHAPTER 2

: THE NEXT STEP - ASSEMBLER PROGRAMMING

2d Why Assembler Language?

What advantages does an assembler have compared to machine


language programming?
if you have
ever
used
machine
language,
you know that you must figure out
the opcode,
translate
decimal numbers into hexadecimal,
keep track
of
absolute memory addresses,
compute relative
jumps,
etc.
These

tasks are very tedious and error prone.

An
assembler
is a program that performs all of
the
these
tasks
very quickly and accurately.
An assembler allows you
to use symbols to represent memory location and data.
With
an
assembler
you
use LABELS to
represent
actual
memory
addresses.

For example:

Machine language
C000

JSR

$E544

C056

JMP

$C129

C129

JSR

$A474

"

"

Assembler
BEGIN

JSR

CLRSCR

JMP

TEST

JMP

BASIC

TEST

CLRSCP
BASIC

EQU
EQU

$E544
$A474

The
label
CLRSCR
stands
for
"clear
screen".
When
an
assembler
language
programmer want to clear the screen
he
can code JSR
CLRSCR to perform this task. This is certainly
much easier to remember than
JSR
$E544.
Yet this is
not
the only advantage of assembler language programming.
Imagine
program,

you have just written a very long machine


and

now you want

to change

some

code.

language

Consider how

bothersome this procedure is:


you must recalculate all
the
addresses
of
relative
branch instruction
that
may
have
changed; you must recalculate all absolute addresses for JSR
or
JMP
instructions
that
may
have
changed;
you
must
respecify
the addresses of any data or tables that may have
changed,

But

etc.

if you were writing

program

recalculates

in assembler language,
all

these

addresses

for

the assembler
you.

After

making
the
change to the assembler source program,
it
is
assembled again and saved onto cassette or diskette as a new
machine language program.
All this takes place quickly
and
accurately.

Just
as
language

a monitor is
programming,

a necessary
prerequisite for
machine
an assembler is necessary if you
are

35

to write

2.2

The

long

or

numerous

Table of 6510

following

machine

language

programs.

Instructions

table

lists all of

the 6510

instructions.

You should note that the binary equivalents of many of the


6510 instructions are not complete. They may contain several
small letter b's. The value of the binary equivalent of the
instruction
varies according to the addressing mode of the
instruction.

Binary

Command

Function

ADC
AND

add With carry


logical AND
shift left one bit
branch on carry clear
branch on carry set
branch on result zero

ASL
BCC

BCS

BEO
BIT
BMI
BNE

BPL

tests bit
branch on result minus
branch on result not zero
branch on result plus
software break
branch on overflow clear
branch on overflow set

OllbbbOl
OOlbbbOl
OOObbblO
10010000
10110000
11110000
OOlOblOO
00110000
11010000
00010000

DEC

clear carry flag


clear decimal flag
clear interrupt disable bit
clear overflow flag
compare memory and accumulator
compare memory and X-register
compare memory and Y-register
decrement memory

00000000
01010000
01110000
00011000
11011000
01011000
10111000
HObbbOl
HlObbOO
HOObbOO
HObbllO

BRK

BVC
BVS

CLC
CLD
CLI
CLV
CMP

CPX

CPI
DEX

decrement X-register

10101010

DEY

decrement

EOR

Mexclusive-OR"
increment memory
increment X-register
increment Y-register
jump to new location
jump to new location
load accumulator
load X-register
load Y-register

10001000
OlObbbOl
lllbbllO
11101000
11001000
OlbOllOO
00100000
lOlbbbOl
lOlbbblO
lOlbbbOO

INC
I NX
INY

JMP

JSR
LDA
LDX

LDY
LSR
NOP

ORA
PHA
PHP
PLA

Y-register

logical right
no operation
logical "OR"

in

sub program

shift

put accumulator on stock


put status register on stack
get accumulator from stack

36

OlObbblO
11101010
OOObbbOl
01001000

00001000
01101000

PLP

get

ROL

status

rotate
rotate
return

ROR
RTI

RTS
SBC

register

from stack

00101000
OOlbbblO
OllbbblO
01000000
01100000
lllbbbOl
00111000

one bit left


one bit right
from interrupt

return from subprogram


subtract with carry

SEC
SED
SEI

STA

set
set

carry flag
decimal

set

interrupt disable status

00111000
01111000
lOObbbOl
lOObbllO
lOObblOO
10101010
10101000
10111010
10001010
10011010
10011000

store accumulator
store X-register
store Y-register

STX

STY
TAX

transfer
transfer
transfer
transfer

TAY

TSX
TXA
TXS

accumulator to X-register
accumulator to Y-register
stack pointer to X-register
X-register to accumulator

transfer X-register to stack pointer


transfer Y-register to accumulator

TYA

For

a more detailed index of the commands and

2.3

A Typical Assembler Program

consult one of the books listed in Appendix D.

their usaqe,

An assembler is a program that translates a symbolic


source
program
into
its
binary
equivalent.
Each
symbolic

instruction

is

translated

into

machine

language

instruction
that
is
lf
2,
or 3
bytes
in
length.
The
resulting machine language program is called object code.

line

consists

of

of

typical

assembly

several elements:

language

source

program

the line number - comparable to BASIC line number


the
address - the memory location of this line
the code - the hexadecimal representation of the
instructions and data (object code)
the label - a symbolic name for the beginning of
this

instruction

the opcode - the symbolic name for a 6502 instruction


the operand - symbolic names for any parameters of
the

the

instructions

remark - commentary
language

to describe

the machine

code

Elements
4 thru 7 are optional.
They are not necessary
each line of the assembly language source program.

In

addition

to

the

6510

instructions,

37

most

in

assemblers

understand
some special instructions called pseudo opcodes.
For
instance
some assemblers have a pseudo
opcode
called
BYT.
This pseudo opcode allows you to insert data into
the
program.
You
can
specify
the data in decimal
format
or
hexadecimal

format.

More
sophisticated
assemblers
allow
you
to
peform
conditional assembly.
Using conditional assembly,
you
can
choose
to
translate parts of source programs
into
object
code if certain conditions are satisfied.

Here

is a typical printout of an assembler listing:

line

addr

10

0000

20

0000

30
40
50

0000
0003
0006

A9 00
8D 00
4C 23

180
190

0123
0124

38
E9

label

code

oper

BUFFER

operand

comment

EQU

$C000

;variable BUFFER

ORG
LDA
STA
JMP

$0000
#$00
BUFFER
JUMP

;start code at $0000


;zero accumulator
;store into BUFFER
;at JUMP it goes on

#$OA

;carry flag set


;subtract 10

is

TEST
CO
01

SEC

JUMP

SBC

0A

stored

at $C000

You can clearly see the difference between machine


language
programming
and assembler language programming:
you
don't
have
to
calculate addresses and memory locations
anymore.
These calulation are taken care of by the assembler.
At the
same
time the assembler can identify possible mistakes
and
notify the user.
Assembler language programming is not only
faster, but considerably more accurate than machine language
programming.

Let's now turn to another assembler language


program.
This
routine
is
much
more
accurate and faster
than
the
SQR
routine in BASIC.
The algorithm for this function is:

X (N+l) = X (N)
X = F (A)
X (N+l) = (X(N)

The

running

time

The

program

is

as

of

- F

(X(N))

+ A / X

this

/ F

(N))

function

is

(X(N))
2

only

about

14 ms.

follows:

FAST

SQR

ROUTINE,

38

ABOUT

14MS

ALGORITHM X(N+l)=X(N)-F(X(N))/F(X(N)

;X=F(A),
110: 033C
120: 033C
130: 033C
140: 033C
150: 033C
160: 033C
170: 033C
180: 033C
190: 033C
200: 033C
210: 033C
220: 033C
230: 033F
240: 0341
250: 0343
260: 0346
270: 0349
280: 034B
290: 034C
300: 034E
310: 034F
320: 0350
330: 0351
340: 0353
350: 0354
360: 0356
370:
380:
390:
400:
410:
420:
430:
440:
450:
460:
470:
480:
490:
500:

0358
035A
035C
035E
0361
0363
0365
0368
036A
036C
036F
0371
0373
0375

20
F0
10
4C
20
A5
38
E9
08

2B

BC

SIGN

EQU

ILLEGAL

EQU

EXP

EQU

ACCU3
ACCU4

EQU

JSR

B2
BB

OK

;0?

JMP

JSR

ILLEGAI
A1TOA4

;+? YES->OK
;ILL. QUAN.

LDA

EXP

;EXP.->ACCU

#$81

;NORMALIZE EXPONENT
;STAT.REG. ON STACK
;HALVE EXPONENT
;CLEAR CARRY FLAG

LSR

CLC
ADC

ERR.

;ACCU#1->ACCU#4

;ADD

;STAT.REG.FROM
;CARRY?NO->S1

STACK

BCC

SI

ADC

#$7F

;ADD

STA

EXP

LDA

#$04

;MEMORY AS EXPONENT
;FOUR ITERATIONS
;MEMORY IN VARIABLE

STA

COUNT

JSR

A1TOA3

LDA

#<ACCU4

;LOAD
;LOAD

MEMDIV

LDY
JSR

#>ACCU4

127

?ACCU#1->ACCU#3
LSB
MSB

FROM AC.4
FROM AC.4

MEMPLUS

DEC

;DIVIDE BY ACCU#1
;LOAD LSB FROM AC.3
;LOAD MSB FROM AC.3
?ADD TO ACCU#1

EXP

DEC

COUNT

;ACCU#1/2(EXP.-1)

BNE

ITER

#<ACCU3
LDY #>ACCU3
LDA

JSR

END

YES->OK

#$01

PLP

ITER

BUFFER

END

SBC

SI

IN TAPE
SIGN

OK

PHP

4A
18
69 01
28
90 02
69 7F

;PGM
;GET

BEQ

SEC

81

85 61
A9 04
85 67
20 CA BB
A9 5C
AO 00
20 OF BB
A9 57
AO 00
20 67 BB
C6 61
C6 67
DO E9
60

SIGN

BPL

03

48

$BC2B
$B248

$61
$57
EQU $5C
COUNT
EQU $67
A1TOA3
EQU $BBCA
A1TOA4
EQU $BBC7
MEMDIV
EQU $BB0F
MEMPLUS EQU $B867
ORG $33C

34

C7
61

X(N+1)=(X(N)+A/X(N)

RTS

;ONE ITERAT. LESS


;MORE ITER.? YES
?BACK TO PROGRAM

(LSB=least significant byte


MST=most

significant

byte)

You
can
enter this
program using either a monitor
or
an
assembler. To use it, you can call it from BASIC. You can do
this by using the BASIC USR command.
The USR command passes
control
to
the routine whose address is placed
in
memory
locations
$311/$312.
The parameter passed
via
the
USR
routine is automatically made available to this routine.
39

Here

is

10
20
30
40
50
60

an

example:

POKE 785,60:
POKE 786,03:

REM LSB REM MSB -

60
03

DECIMAL
DECIMAL

3C

HEX

03

HEX

A=10

B=USR(A)

PRINT "SQR OF ";A?"

IS ";B

END

RUN

SQR OF

10

If
you
are
please
read

IS

3.16227766

interested in further
mathematical
Chapter
6.3.3.
There
you
will

functions,
find
more

information.

In

Chapter

between

2.4

6.3,

BASIC

Still

you will find

and machine

More

more

language

about

communicating

programs.

Programs

Next
are
several
programming.
The

more
examples
of
assembler
language
routines
are
useful
as
well
as

illustrative.

These

programs

developing

are

programs

of

intended
your

to

serve

as

models

for

own.

First,
is
accumulator

a
routine
which
prints
the
contents
ofthe
in hexadecimal format to the currently assigned
output
device.
If the current output device is the
screen
(default),
then the contents of the accumulator are printed
onto
the
screen.
If you OPENed a printer
device (OPEN 4,4) ,
then the contents of the
sent to the printer.

as
the
output
accumulator are

This
program is placed in the Commodore 64 cassette buffer.
This location is suitable for such small routines because it
is not affected by BASIC unless input from or output to
the
cassette

drive

is

attempted.

ORG

$033C

;starting

033C

BSOUT

EQU

$FFD2

;declare

addr

o/p

033C 48
033D 4A
033E 4A
033F 4A
0340 4A
0341 20
0344 68
0345 29

START

PHA

033C

LSR

LSR

LSR
LSR

47

03

JSR

HEXASC

PLA

OF

AND

kernal

;save

#$OF

40

addr

value

of
of

pgm.
the

routine
of

accum
;shift bits 4
; thru 7 to positions
; of bits 0
; thru 3
;convert digit to ASCII
;restore accumulator
;mask out bits 4-7

0347
0348
034A
034C
034E

18
69
90
69
69

F6
02
06
3A

HEXASC

CLC
ADC
BCC
ADC
ADC

0350 4C D2 FF

JMP

;clear carry flag


;prepare for conversion
;branch is <=255
normalize for A-F
;make ASCII value

#$F6
* + 4
#$06
#$3A

BSOUT

;write result

Here's an explanation.
Suppose the accumulator contains the
value $FE (254 in decimal).
Keep in mind that the
hexadecimal number $FE is represented as a single character
(8 bits) inside the computer. To display this value however,

you must change

it two two individual ASCII characters.

To display the value, first divide the hexadecimal number


into two separate numbers.

byte
left
time
have
with
bits,

To do this, "split" the 8- bit

into two four bit nibbles. You do this by shifting the


four bits of this number to the right which at the same
fills the vacated bits with zeros.
As a result you
a one-digit number between 0 and F.
Shifting is done
the 6510 LSR instruction. Since we must shift four
we execute the LSR instruction 4 times.

Shifting causes us to lose the right four bits of the


number. This is why we saved the original number with a PHA
instruction. The accumulator is saved on the STACK.
Before outputting the each hexadecimal digits, convert them
to ASCII characters. The routine called HEXASC does exactly
this. Hexadecimal numbers have this order: 0, 1, 2, 3, 4, 5,
6, 7, 8, 9, A, B, C, D, E, F. However the ASCII equivalent
of these numbers are not in this sequence.
Adding $F6 to
the digit makes

the

next

step easier.

If the digit is between 0 and 9,


is either less than or equal to
remain clear. Therefore adding
value between $30 (ASCII 0)
and
is

ready

for display.

If

the digit

is between A and F,

greater than 255 and the

the
255
$3A
$39

result of this addition


and the carry flag will
to the digit, creates a
(ASCII 9) and the digit

the result of adding $F6

carry flag will

be

set.

The

is

BCC *+4

instruction tests this condition and the next instruction

normalizes the digit for the correct ASCII values of A-F by


adding an $06 to the digit to arrive at a value between $41
(ASCII A) and $46 (ASCII F).
After outputting the first digit (in our example F) we can
output the second digit.
For this purpose, we have to mask
out left four bits of the original number.
We can do this
by using an AND instruction using a mask of $0F. The value
$0F looks like this:
00001111

41

When ANDing two values, each bit is only set on only if both
corresponding

bits

original
mask
result

of

AND

are

set.

In

this example:

PE:
OF:

1 1 1 1 1 1 1 0
00001111

0E:

00001110

The number is now correctly formatted

to be output.

Finally, we present a program that aids you in inputting


your machine language
programs.
You can enter the
instructions

100

in

AD=828:

hexadecimal.

REM

110

READ OP$

120

GOSUB 65000

130

POKE

140
150

AD=AD+1
IF XO96

160

END

AD-> START ADDR OF

MACHINE

PGM (DECIMAL)

ADfOP

THEN GOTO

110

170
175
180
190
200

REM
REM
REM
REM
DATA

FOLLOWING DATA LINES CONTAIN THE OPCODES OF YOUR


MACHINE LANGUAGE PROGRAM. THIS EXAMPLE IS THE
ROUTINE PREVIOUSLY EXPLAINED THAT PRINTS THE
CONTENTS OF THE ACCUMULATOR IN HEX FORMAT
48f4Ar4Af4Ar4Ar20 47 03

210

DATA

220

DATA 69r06f69f3Ar4CfD2fFFf96

68,29,OF,18,69,F6,90,02

65000

REM

65010
65020
65030

OL$=LEFT$(OP$fl): OR$=RIGHT$(OP$,1)
OL=VAL(OL$): IF OL=0 AND OL$<>"0" THEN OL=ASC(OL$)-55
OR=VAL(OR$): IF OR=0 AND OR$<>"0" THEN OR=ASC(OR$)-55

THIS

ROUTINE

CONVERTS

HEX NUMBERS

INTO DECIMALS

65040

OP=OL*16+OR

65050

RETURN

Using this program you can input a machine language routine


byte by byte.
Even though this method of placing machine

language routines is convenient, it still does not match a


monitor or assembler for convenience.
We hope that this chapter better aquainted you with machine
and assembler language programming.
The best advice we can
give to the reader is to try writing his own program.
PRACTICE

MAKES

PERFECT!

After a short while, you will become more accomplished. In


any event, you will discover that programming in machine
language is just as much fun as programming in BASIC.

42

CHAPTER 3 A CLOSE-UP LOOK AT THE COMMODORE 64

3.1 What you should know about the Commodore 64

The Commodore 64 is an outstanding achievement,


its

remarkably affordable price.

considering

When working with the Commodore 64, you will soon notice
that, as far as hardware is concerned, very little is
missing, if you also own a VIC-20, you might want to take a
time to look at the insides of both devices.
You

will

notice

that

the

Commodore

64

contains

fewer

integrated circuits (ICs) than the VIC-20, even though it

contains far more power than the VIC-20. This


possible by extremely high density of the ICs.

There

are

Commodore

64.

several

newly

developed,

ICs

is

inside

made

the

The Commodore succeeded in putting the following things into


64K

*
*
*

address

space:

64K dynamic RAM


IK color RAM
4K character generator

* Color video-controller with hires graphics


* Synthesizer with three independent voices

* 8K BASIC interpreter
* 8K operating system
* 2 parallel I/O ports
* RS-232 interface

3.2 An Overview of the Hardware

The Commodore 64 contains 64K of RAM, 20K of ROM and a bank


of memory for accessing the input and output devices. Since
the 6510 processor can only address a 64K memory space, a
method is required to allow access to this larger array of
memory

The

space.

method

several

used

is

system

called multiplexing.
components

to

Multiplexing

share

the

allows

same

bus

(communication) lines by using them at different times. This


complex function is coordinated by a special IC which we
will simply call address-space manager, since we don't have
a name

for

it.

More

about

this

in

section

The character generator and I/O bank


address
range.
But this apparent

3.4.

are located in the same


conflict
presents
no

problems, since the video interface chip takes advantage of


the 6510's unused cycles when accessing
the character

43

generator.

The

of

complete

20K.

section

ROM

and parts of the RAM overlap over a range

description

of

this

overlap

is

presented

in

3.4.

Besides handling the screen display, the video interface


chip (VIC) also performs
an additional function of
refreshing the RAM. All of these procedures are taken care
of by the video controller which must also
provide generate
the text and graphics.

3.3

Special

features of

the 6510 processor

The Commodore 64 contains a 6510 CPU. It is an 8-bit


processor which is run at a frequency of about 980 Khz. The
6510
is the newest member of the 65xx family of
microprocessors.

The

most

significant

difference

from

the well-known 6502

is

that the chip has 6 I/O lines available. Compared to the


6502 which has no I/O lines available,
the 6510 can
communicate over these six I/O lines without requiring
additional ICs to perform the I/O.
These

lines

support

the

cassette

operation

and

memory

management.

Here is a list of the 6510 pinouts. These pinouts were


derived from an empirical testing approach,
lines actually
go.
Here is the result:

1
2
3

6
7-20
21
22-23
24-29
30-37

J^IN input clock cycle time; 980 KHz


RDY ready; 0 = processor stops at the next reading
cycle until RDY=1;
-IRQ interrupt request;
0=processor gets next command from vector $FFFE and
continues there.
Permitted if status register bit 2=0
-NMI non-maskable
interrupt;
0=processor gets next command from vector $FFFA and
continues there.
AEC address enable control;
0=processor brings data address and operation bus into
tri-state.
The bus can now be used by other units,
i.e. a second processor.
operating voltage +5V
AO-A13; address bus
GND

A14-A15; address
P5-P0; I/O port
D7-D0; data bus

bus

44

38

39
40

R/-W;
O=write access
l=read access

02in
RES

clock cycle

reset;

0=processor goes into non-operating state.


After
transition from 0 to 1, the processor gets vector from
$FFFC and begins execution there.
3.4

Memory Configurations

As mentioned before, the Commodore 64 has 64K of RAM, 20K of


ROM, 4K of I/O RAM and 8K character generator ROM. The 6510
processor

can

access

all

of

this

memory

IC which we call the address manager.

with

the

help

of

an

By programming memory locations 0 and 1, you can affect the


address manager to make different combinations of RAM, ROM
and I/O available to the Commodore 64.
Memory

location

is

called

the

input/output.

Memory

location 0 is the control port for the input/output port and


in part determines the memory configurations.

Three bits of the control port are of note:

Bit 0

called LORAM

0=selects RAM at $A000-$BFFF

Bit 1

called HIRAM

0=selects RAM at $E000-$FFFF

Bit 2

called CHAREN 0=selects ROM at $D000-$DFFF

l=selects

ROM at $A000-$BFFF

l=selects

ROM

l=selects

I/O at $D000-$DFFF

at $E000-$FFFF

An example shows you how you can program the control port.
Suppose you want to disable the ROMS that contain the BASIC
interpreter at $A000-$BFFF. To do this you would have to set
the bit LORAM to zero. The following statement could do this
for you:
POKE 0,PEEK(0)AND254

It is necessary to use the AND the original contents of the


control port (PEEK(O)) since the other bits control port
must not be disturbed.
There are also two lines which are connected to the address
manager. One line is called EXROM and is set when a ROM
cartridge is found is the expansion slot. The other line is
called GAME and is also set when a ROM cartridge is found
in the expansion slot.

Thus using these five variables, we can describe the eight


major memory configurations that are possible with the

45

Commodore 64. The following pages


different memory configurations.

8K

ROM

KERNAL

EOOO

4K

D000

8K

I/O
D000

4K RAM

cooo

pictorally

8K BASIC

RAM

4K

I/O

4K

RAM

16K RAM

RAM

8000

LORAM

8000

16K

RAM

16K

RAM

LORAM
HIRAM
EXROM
GAME

=
=
=
=

1
1
1
1

4000

16K

RAM

16K

RAM

GAME

THIS

CONFIGURATION GIVES

RAM,

BUT

YOU

MUST

DRIVER TO HANDLE

8K

COOO

1
0

EXROM

0000
THIS CONFIGURATION APPEARS WHEN
THE COMMODORE 64 IS TURNED ON.

D000

HIRAM =

4000

0000

EOOO

these

COOO

ROM

A000

8K

describe

KERNAL

4K

ROM

16K

YOU

60K OR

YOUR OWN

I/O TO DEVICES.

RAM

I/O

4K RAM

PROVIDE

LORAM - 0
HIRAM * 0

COOO

EXROM =
16K

16K

RAM

RAM

GAME

OR

8000

LORAM =

8000

HIRAM * 1
16K

RAM

EXROM

= X

GAME

= 1

16K

4000

RAM

LORAM = 0
HIRAM 0
EXROM 0
GAME

4000

16K

16K RAM

RAM

0000

0000
THIS CONFIGURATION GIVES

YOU

52K

RAM,

I/O AND DRIVER TO HANDLE I/O DEVICES.


USED BY CP/M CARTRIDGE.

46

THIS CONFIGURATION GIVES A FULL 64K


RAM. YOU MUST PROVIDE YOUR OWN I/O
DRIVER AND BANK THE 4K I/O BACK WHEN
ACCESSING THE I/O DEVICES.

8K

E000

KERNAL

ROM

8K

D000

D000

4K RAM

C000

KERNAL

E000

4K I/O

C000
8K

BASIC

ROM

8K

CARTRIDGE

A000

LORAM
HIRAM
EXROM
GAME

=
=

1
1
0
0

8K

4000

LORAM
HIRAM
EXROM
GAME

16K

RAM

16K

RAM

= 0
= 1
= 0
= 0

4000

16K RAM

0000

0000

THIS CONFIGURATION SHOWS A STANDARD


BASIC SYSTEM USING AN EXPANSION

CARTRIDGE.

THIS CONFIGURATION GIVES YOU 40K RAM


AND LETS YOU REPLACE THE BUILT IN
BASIC WITH AN 8K ROM CARTRIDGE.

8K ROM

8K KERNAL ROM

D000

RAM

8000

16K RAM

E000

I/O
RAM

8K CARTRIDGE

A000

8000

4K

4K

ROM

E000

4K I/O
4K

C000

C000
16K

ROM

I/O

4K

UNUSED

8K

UNUSED

A000

LORAM
HIRAM
EXROM
GAME

8000

4K

D000

RAM

=
=
=
=

1
1
0
0

8K

ROM

8000

16K

16K RAM

LORAM

HIRAM
EXROM

=
=

X
1

GAME

UNUSED

4000

4000

12K UNUSED
16K

RAM

1000

4K

0000

0000

THIS CONFIGURATION GIVES YOU 32K RAM


AND LETS YOU REPLACE THE BUILT IN
BASIC WITH A 16K CARTRIDGE.

THIS

CONFIGURATION

IMAGE

OF

WHICH

IS STILL

THE

BY COMMODORE.

47

RAM

GIVES

ULTIMAX

YET TO

YOU THE

COMPUTER

BE

RELEASED

3.5

The Expansion Port

At the back of the Commodore 64 is a 44-pin connector.


This
is called an expansion slot. This slot contains connections
for
the complete system bus and the accompanying control
channel.

Among

the

things that

are

connected at this port are BASIC

and operating system expansions and game


expansion

Since
pin

(serial

many

signals

overlay

GND

2-3

+5V

4
5
6

and

input/output

bus).

are

not

self-explanatory,

we

explain

the

here:

-IRQ; connected with the IRQ of the processor


R/-W; connected with the R/-W of the processor
DOT CLOCK;dot scanning cycle for the VIC chip,

8.18

MHz

"I/l;

8
9

-GAME; input to the address manager


-EXROM; input to the address manager

10

-I/O2?

12

BA;

13

reading data.
-DMA;
input.

II

usually =0

in the address

range $DEOO to $DEFF

usuallY =0 in tne range $DFOO to $DFFF

-ROML;

output

signal

from

AM;

from VIC,

see

ch.3.4.

which

indicates

0=reserve

bus

the

system

validity

for

of

external

access

14-21

CD7-CDO;

22

GND

GND

-ROMH;

-RESET

-NMI

09'

output

AI5-AO;

GND

The

bus

from address

manager

at

$E0OO

system cycle output

F-Y

3.6

data

address

bus

User Port

With

the user
interface.
It

controllers

port,

is

or

the Commodore 64 offers an versatile


possible to connect analog to digital

parallel

interfaces

(Centronics-type)

for

of

and

example.

Basically,
several

the

control

GND

+5V;

-RESET;

user

port

channels

connected

consists

explained

with

as

an

8-bit

the processor of

48

port

follows:

the

same

name

4
5
6
7
8
9
10
11

CNT1; connected with CNT from CIA1


SP1; connected with SP from CIA 1
CNT2; connected with CNT from CIA 2
SP2; connected with SP from CIA 2
-PC2; handshake output from CIA 2
SERIAL ATN; control channel of the
9V AC; + phase
9V AC; - phase

serial

bus

12

GND

GND

B
C-L

-FLAG2; handshake input


PB0-PB7; I/O lines from

PA2; I/O line from CIA 2; This


line
substitutes
for
the CB2 which is known from other CBMs of the VIA 6522.

GND

Some

of

the

CIAs

please

pre-assigned

lines

mentioned

functions.

refer

to

For

chapter

from CIA
CIA 2

before

more

8.

49

already

have

information

on

definitely

using

the

CHAPTER

4.1

THE

SYNTHESIZER

The Sound Controller 6581

4.1.1

The

4s

General

sound

notes

about

synthesizer

the

SID

included

in

6581

the

Commodore

64

gives

you

the opportunity to produce all kinds of sounds, ranging from


a flute to a big steam engine. Most computer synthesizers
have only one voice, the Commodore 64 offers a three-voice
synthesizer.
All

the

elements

necessary

to

produce

quality

sound

found on a single IC. This IC is called


the sound
device
(SID)
6581.
It
is a new component of
family.
It is provided with:

seperately

programmable,

independent

are

interface
the 65xx

oscillators

(voices)

*
*
*

4 mixable waveforms for every voice


3 mixable filters (high-low tape pass)
Attack/decay/sustain/release control (ADSR-control)
every

*
*
*

2 ring modulators
alternation possibility for
2
8-bit A/D transformer

Pin

layout

1-2

for

voice

of

the

CAPlAfCAPlB;

filters.

6581

external

signal

source

are:

condenser

Recommended

connector

for

capacity:

2200

the

programmable

pF.

3-4
5

CAP2ArCAP2B; as 1-2
-RES (reset); =0 brings

02(system frequency 2); all data-bus actions only take


place during 02=1*
R/W: 0=write access, l=read access
-CS (chip select);0=data valid, l=data invalid
A0-A4
(address bits 0-4);
select one of
the
29
registers of the SID.
GND(ground); The SID should have its own ground so as
to avoid interferences from other system components.

7
8
9-13
14

SID

into

basic

state

15-22 D0-D7; data lines to/from the 6510 processor


23
A2IN analog input 2
24
A1IN
analog input 1
25
VCC; supply voltage +5V
26
EXT IN (external input);
input for external

27

signals for mixing with SID.


AUDIO OUT; output for signals

that

were

audio

produced

by

SID.

28

VDD;

supply

voltage

+12V

The SID 6581 can produce three synthesized voices that can

50

be controlled independently of each other. This is an


unusually powerul
capability for a single integrated
circuit. Additionally, the voices can be used in combination
to produce some extremely complex

sounds.

Each voice consists of an oscillator, a waveform generator


capable of producing four different timbres, an envelope
generator,

and

an

amplitude

modulator.

The oscillator produces the basic frequency in the


from 0-8200 Hz with a reslolution of 16 bits.

The SID

can produce

four different waveforms:

sawtooth, pulse and white noise.


influences the sound quality.

range

triangular,

The choice of waveforms

A triangular waveform has a very soft sound, like a


recorder. The sawtooth waveform produces a full spectrum
sound. Consequently, it has a more harsh sound, like a
trumpet. The pulse waveform is missing some some harmonic
ranges.

It

sounds

little

hollow,

somewhat

like

clarinet. The white noise consists of a random sequence of


different frequencies within defined limits.
The volume of a tone is influenced by an amplitude modulator
which is controlled by the envelope generator.
When the
envelope generator is triggered, the amplitude (volume) of
the sound is controlled by the ADSR parameters that define
the

envelope.

Additionally, the outputs of each voice can be sent


adjustable filters which further define the sound.

through

The SID also lets you use voices 1 or 2 in combination with


voice 3 to produce a ring modulated sound much like a bell
sound.

The

SID

also

contains

two

8-bit

analog

converters. These A/D converters can be used


paddles, electrical controllers, etc.

to

digital

to connect game

4.1.2 Explaination of the Registers

The SID is located at address $D400 (54272). The registers


that control

the

SID are:

REG 0

oscillator

frequency

low byte

for voice 1

REG 1

oscillator frequency high byte for voice 1

REG 2
REG 3

pulse width low byte for voice 1


pulse width high byte for voice 1

Registers 2 and 3 determine the pulse width


relation of the pulse waveform output of voice 1.

Only

the

bits 0-3

are used by register 3.


51

REG 4

control register for voice 1


bit 0 GATE: gate bit for the envelope generator.
When
this
bit
is
set
to
one,
the
ATTACK/DECAY/SUSTAIN cycle begins. The volume
of voice 1 increases from zero to the maximum
according to the attack time set in REG 5 and
then decreases according to the decay time in
also set in REG 5 to the sustain level set in
REG 6.
When this

set to zero,
the RELEASE
volume decreases to zero
according to the release time set in REG 6.
1 SYNC: When set to 1, the frequency of voice
1 is synchronized with that of voice 3.
2 RING: When set to 1, the triangular waveform
output of voice 1 is replaced by a ring
modulated combination of voices
1
and 3.

Bit
Bit

Bit 3
Bit

Bit

cycle

bit is
begins. The

TEST:

When

set

to 1,

voice

is

locked until

the TEST bit is reset to 0.


TRI: When set to 1,
a triangular
selected
SAW:
When set to 1,
a sawtooth

waveform
waveform

selected

Bit

PUL:

When

set

to

set

to

1,

pulse

waveform

selected.

Bit

NSE:

When

1,

noise

generator

selected.

It is possible to select several waveforms


simultaneously. The result is a logicel
ANDing

REG 5

Bits

the

waveworms.

range is variable from 6msec to 24sec.


4-7 ATTACK: Sets the time in which the volume
increases from zero to maximum volume after
gating the voice. The range is variable from
2msec

REG 6

of

ATTACK/DECAY (see TABLES 4.1 and 4.2)


Bits 0-3 DECAY: Sets the time in which the volume
falls from maximum to the sustain level.
The

to 8

sec.

SUSTAIN/RELEASE (see TABLE 4.2)


Bits 0-3 RELEASE: Sets the time in which the volume
falls from the sustain level to zero volume
after resetting the GATE bit to zero.
The
range

Bits

is

variable

from

6msec

to

24

sec.

4-7 SUSTAIN: The proportion of the peak volume


that constitutes the sustain level. A zero
value indicates a zero volume, a value of 8
is a sustain level equal to one-half of the
peak volume and a value of 15 is a sustain
level

equal

to

the

52

peak

volume.

REG

7-

REG 13

These registers control voice 2 analogously


registers 0-6 with the following exceptions:
SYNC
RING

REG

with

the

ring-modulated

voice

combination

the voices 1 and 2.

14-

REG 20

synchronizes voice 2 with voice 1


replaces the triangular output of

of

These registers control voice 3 analogously


registers 0-6 with the following exceptions:
SYNC synchronizes voice 3 with voice 2.
RING substitutes the triangular output

voice

with

the

ring-modulated

of voice 3 and 2.

REG 21
REG 22

filter

frequency low. Only bits 0-2

filter

frequency high.

to

to
of

combination

are used.

The 11-bit number of registers 21 and 22 determine


the cutoff frequency of the filters. This frequency
is computed as follows:
F=(30+W*5.8)Hz, W is this 11-bit

REG

23

REG 24

Filter resonance and

switch.

resonance)

(maximum

Bit 0
l=output voice 1 through the filter.
Bit 1
l=output voice 2 through the filter.
Bit 2
l=output voice 3 through the filter.
Bit 3 l=input external signal source through filter
Bits 4-7
Resonance frequency of filter.
The resonance frequency is variable from zero (no
to

15

Bits 0-3:

to

overall

volume

modulate

the other voices

from

voice

POTX

27

Noise

at

reads

converter)

REG

audible

listed above.

You may

reads the position of the potentiometer

converter)

POTY:

without

3.

You may only write to the registers


only read the registers listed below:

26

which

4 : LP sets the low-pass output of the filter.


5 : BP sets the band-pass output of the filter.
6 : HP sets the high-pass ouput of the filter.
7 : 3OFF l=disconnect voice 3 output. Use this
results

REG

resonance)

emphasizes the frequencies at the cutoff frequency.


.This register has the following functions:

Bit
Bit
Bit
Bit

REG 25

number.

pin

the
at

position

pin

generator

This

24.

of

the

potentiometer

(A/D
(A/D

23.

register allows you to read the output of


53

voice 3. This allows you to modulate the other


voices to produce interesting sounds.
REG

28

Envelope

This

generator 3

registers

allows you to read

voice 3 envelope generator.

produce

harmonic

register

to

the

envelopes

filter

0
1

RATE

ms

ms

16 ms
24 ms

3
4

38

ms

56

ms
68 ms
80 ms

5
6
7
8

100
250
500
800

9
10

11
12
13
14
15

TABLE

VALUE

by

frequency.

ATTACK

VALUE

ms
ms
ms
ms

sec

sec

sec

sec

4-1

DECAY/RELEASE

6ms

24ros

2
3

48ms

114ms

168ms

204ms
240ms

8
9

300ms
750ms

72ms

10
11

1.5sec

12
13

3sec
9sec

14

15sec

15

24sec

2.4sec

TABLE

54

4-2

the output of

This allows you to

RATE

adding

this

4.1.3 The Analog/Digital Converter (Potentiometers)

The A/D converter, also called a potentiometer is a device


that changes an analog signal (i.e. voltage) into a digital
value. The critical problem with such a transformation is to
change an analog value with an infinite gradation into a
digital value with a finite gradation (fixed intervals).
Inevitably, a maximum error of +/- of the smallest digital
step

The

occurs.

SID 6581 contains

POTY.

two A/D converters named POTX and

They each use a fixed reference voltage of 5V.

produce a reading as follows:

They

a capacitor is discharged and

its is value is read into register 25 or 26. This value is

porportional to the time required


for a recharging of the
capacitor using the reference voltage.
This procedure is
repeated

cyclically.

4.1.3.1 Handling the A/D Converter

It becomes clear from the points made above that only


potentiometrical switching is possible,
if currents have to
be measured, they must to be put into a suitable form first.
This can be achieved by using a unijunction transistor.

The measuring arrangements are such that the one end of the
measuring resistance is connected to +5V (available at the
control port of the Commodore
connected to the analog input of

64)
the

and the other end


SID (also available

is
at

the control ports, marked as POTX and POTY). The value read
from registers 25 and 26 is a measurement of the resistance.

In order to take advantage of the entire 8-bit range,


resistance must operate in range from 0 to 500 megaohm.
4.1.3.2

the

Using the Game Paddles

You can connect regular game paddles to the Commodore 64.


Two sets of game paddles (four in all) may be connected at

one time. They are simply plugged into the control ports on
the right side of the device. A game paddle is nothing more
than a potentiometer (which is connected to the SID as was
explained in the preceding section), and a key which has an
effect on joystick position LEFT for the one paddle and
RIGHT

for

the

other

paddle.

The procedure of reading the game paddle values from program


presents a

little problem. The game paddles

and

the keyboard

share some of the lines of CIA 1 and CIA 2. Because two sets
of the paddles (four paddles in all) may be connected at on
time and because there are only two analog converters in the
Commodore 64, a way of sharing the converters is required.
So as to avoid inteference of the game paddles with the
keyboard, we have to write a small machine language routiie

55

to

read

the

keyboard

game

paddle

values

without

disturbing

the

functions.

The solution is the following program which allows us to


access all four paddles. The program is located in a memory
range that is not normally used by the operating system.
;prevent

CFBE

SEI

CFBF

CFCA

#$80
JSR $CFEC
STX $033C
STY $033D
LDA $DC00

CFCD

AND

CFCF

STA

CFD2

LDA

CFD4
CFD7

JSR

CFDA

STY

CFC1

CFC4
CFC7

LDA

STX

keyboard

?parameter

for

;get A/D values


;save POTX
;
and save

#$0C
$029F
#$40
$CFEC
$033E
$033F
$DC01
#$oc
$02A0
#$FF
$DC02

interruptions

paddle-set

Al

POTY

;get key A from CIA 1


;filter required bits
;and save
;parameter

for

;get

A/D values

;and

save

paddle

Bl

LDA

CFE0
CFE2
CFE5
CFE7

AND

CFEA

CLI

CFEB

RTS

CFEC

STA

$DC00

;back to basic
;select paddle

CFEF

ORA

CFF2

STA

#$co
$DC02

;on

CFF4

LDX

#$0

CFF6

DEX

;time delay to
;
stabilize input

CFF7
CFF9

BNE

LDX

CFFC

$CFF6
$D419
LDY $D41A

;A/D input
;get A/D 1
;get A/D 2

CFFF

RTS

;return

LDA

STA

-set

and

B2

?get keys B from CIA 2


;filter required bits

CFDD

STA

and A2

?and

save

;all bits output in CIA


;in order to enable
;keyboard inquiry

;and

set

program
set

appropirate

bits

output

(POTX)
(POTY)

to main

program

Here is A BASIC program which POKES the above program into


memory. Connect the paddles, load and start the program and
see

what

happens.

10
20
30
40
50
60
70
80
90

DATA 120,169,128,32,236,207,142,60,3,140,61,3,173
DATA 0,220,41,12,141,159,2,169,64,32,236,207,142
DATA 62,3,140,63,3,173,1,220,41,12,141,160,2,169
DATA 255,141,2,220,88,96,141,0,220,9,192,141,2
DATA 220,162,0,202,208,253,174,25,212,172,26,212,96
FOR M=53182 TO 53247
READ A: POKE M,A: NEXT: read in REM machine program
AX=830: REM paddle 1 at control port 1
AY=831: REM paddle 2 at control port 1

100

BA=672:

110
120
130
140
150

BX=828: REM paddle 1 at control port 2


BY=829: REM paddle 2 at control port 2
BB=830: REM keys from paddle pair B
SYS 53182: REM get all values
PRINT PEEK(AX)11 "PEEK(AY)11 "PEEK(BA)" ";

REM keys

from paddle

56

pair A

160

PRINT PEEK(BX)"

170

GOTO

4.2

Programming

"PEEK(BY)11

"PEEK(BB)"

140

the SID 6581

This section describes the programming the synthesizer.


For the simple production of a tone you should:
1) load
register 24;
2)
set the appropriate ADSR registers
(5,6,12,13,19,20);
3)
set
the
remaining
registers,
preferably in the order of their voice range with the
exception of the registers 4, 11 and 18; 4) load registers
4,11 and 18 at the end (don't forget bit 0!) and then you'll
hear

the

tone.

The following brief program will acquaint you


waveforms and the tone range of the synthesizer:
10
20
30
40
50
60
70
80
100
110
120
130
140
150
160
170

Sl=54272: REM voice 1


S2=54279: REM voice 2
S3=54286: REM voice 3
FL=54293: REM filter lo-byte
FH=54294: REM filter hi-byte
RS=54295: REM resonance+switch
PL=54296: REM pass kind+volume
POKE Sl+4,0: POKE S2+4,0: POKE S3+4,0
POKE Sl+2,0: POKE Sl+3,8
POKE Sl+5,0: POKE Sl+6,240
POKE RS,0: POKE PL,15
PRINT "TRIANGLE"
T=16: GOSUB 300
PRINT "SAWTOOTH"
T=32: GOSUB 300
PRINT "RECTANGLE"

180
190
200
210

T=64: GOSUB 300


PRINT "NOISE"
T=128: GOSUB 300

300
310
320
330

POKE Sl,0: POKE Sl+1,0


POKE S1+4,T+1: REM switch on tone
FOR 1=0 TO 255: FOR J=0 TO 255 STEP
POKE S1,J: POKE Sl+l,I

340

NEXT J,I

the

END

350

POKE

360

RETURN

Lines 10

programs.

The

with

next

S1+4,T:

REM switch off

thru 80 shuld be

generator

It makes

program

clearer.

tone

written

the program a

makes
For

the

50

before each

lot

easier

function

reasons

of

of

of your sound

to

handle.

the

simplicity,

envelope

just

copy

lines 10 to 80 from the preceding program, and add lines 100


57

through

160

as

found

100

A=9:

D=9:

120
130

POKE
POKE

RS,0: POKE PL,15


SI,37: POKE Sl+1,17

140
150
160

POKE Sl+4,33
FOR 1=0 TO H:
POKE Sl+4,32

110

S=8:

below.

R=9:

POKE Sl+5,16*A+D:

H=400

POKE Sl+6,16*S+R

NEXT

Now try changing the data in line 100 in order to get a


feeling for the parameters and what influence they have on
the tone. The values A,D,S, and R may only be in a range
from 0 to 15, otherwise you will get an ILLEGAL QUANTITY
ERROR.

As you probably
increment time

found out by now, variable A determines the


and variable D the decrement time of the

volume level; variable H determines the time to hold the


tone at the sustain level and variable R the release time to
zero volume after resetting the GATE bit.

Here is a program to play a three voice chord on the


harpsichord.
Again, keep lines 10 to 80 from the first
program!

100

A=0:

140
150
160
170
180

POKE RS,0: POKE PL,15


POKE SI,37: POKE Sl+1,17
POKE S2,154: POKE S2+l,21
POKE S3,177: POKE S3+l,25
POKE Sl+4,33: POKE S2+4,33:

190

FOR

110
120
130

200

D=l:

S=13:

R=10:

POKE S1+5,16*A+D:
POKE S2+5,16*A+D:
POKE S3+5,16*A+D:

POKE

1=0

TO

H:

Sl+4,32:

H=100

POKE Sl+6,16*S+R
POKE S2+6,16*S+R
POKE S3+6,16*S+R

NEXT

POKE

S2+4,32:

POKE

S3+4,33

POKE

S3+4,32

In the next example, the frequency of the tone


reading the envelope generator of voice 3
experimenting with the data in line 100 again.

100
110

A=9:
POKE

RS,0:

130

POKE

S3+4,33

120

D=9:

S=9: R=9: H=30


POKE PL,15

POKE S3+5,16*A+D:

140

FOR

150

POKE

160

FOR

Finally,

1=0

is changed by
(54300).
Try

TO

H:

POKE

POKE S3+6,16*S+R
S3+1,PEEK(54300):

NEXT

S3+4,32

1=0

TO

let

the

R*4:

POKE

"STARSHIP

S3+1,PEEK(54300):

ENTERPRISE"

58

pass

NEXT

by

acousticly:

100
110
120
130
140

A=15:
POKE
POKE
POKE
POKE

160

POKE Sl+4,129:

150

170
18Q

D=0:
RSf0:
Sl,0:
S2,0:
S3f0:

S=8:
POKE
POKE
POKE
POKE

R=13: H=8000
PLf15
Sl+lf30
S2+l,l
S3+l,100

POKE S1+5,16*A+D: POKE Sl+6,16*S+R


POKE S3+4f23

FOR 1=0 TO H: NEXT


POKE Sl+4,128: POKE S3+4,16

We are sure that all these examples provide you enough


incentive to try your own programs on the synthesizer. Have
fun!

4.3 SYNTHY-64 - Full-fledged Synthesizer software

When people heard about the Commodore 64 and its tremendous


capabilities in graphics and sound, they became excited.

But after reading the user's guide, some people started to


wonder whether some pages in this book were missing. Very

little was said about programming color, sound, or graphics.

You have to admit that programming color,


sound,
and
graphics is not necessarily easy. You must set every
register and memorize addresses to create the
different
sound.

For example you need three POKE commands for the note "C":
POKE 54272,37:

POKE 54273,17:

POKE 54276,65

This is, of course, not very suitable for writing long


compositions.
You have to control the production of quarter
or eighth notes, etc.
All this may dim your joy in the
Commodore 64 slightly.
Fortunately, there is software that

save you from the bothersome procedures


and machine language programming.

of

POKEs

and

PEEKs

One such software packages is SYNTHY 64.


It allows you to
take advantage of the fantastic sound capabilities of the
Commodore 64, without having to resort to machine language
programming.
Using the SYNTHY 64 as an example, we will
show you how easy and relaxing the composition of music can

be. This program allows you to play several voices, indicate


the presently played tone, save and load the different songs
and much more. SYNTHY-64 is a product of ABACUS Software.
With

SYNTHY-64,

the

composition

of

music

is

similar

to

the

process used in writing regular sheet music - and using a


structure similar to BASIC.
You put in a line number and

59

afterwards

Notes

the

commands

or

the

are entered according

entered

simply

as

to

notes.

their names:

the

note

"C"

is

C.

For the first note of each voice you may add. the following
information:

VOICE

NOTE VALUE

OCTAVE

NOTE

DURATION

Example: +G5/4.
+ stands for voice 1, "G" note is played in
the fifth octave as a quarter note. If you don't change the
voice, octave or note duration you need only
indicate the
note

value

on

subsequent

commands.

When used to write music, SYNTHY-64 gives you a BASIC shell


in the editor. If you LIST the SYNTHY-64 shell, it looks
like

this:
1

RUN"<clr>"

63000

REM

63005

rem*******

<clr>

appears

as

reversed

heart

63010 @WP @P8 @A0 @D9 @S0 @R0 @F0 RETURN PIANO
63020 @WT @A4 @D2 @S10 @R5 @F0 RETURN FLUTE
63030 @WS @A6 @D0 @S10 @R1 CB X10 Y12 @F1
RETURN

TRUMPET

63040

@WP

@P1

@A0

@D9

@S0

@R0

63050

@WS @A6

@D5

@S2

@R2

ZH X8

@F0

RETURN

Y12

@F1

BANJO

RETURN

ACCORDION

The RUN command in line 1 must be the first command in every


music program which you compose.
Lines 63010 to 63050 are
five independent routines that can be used to set up a voice
to sound like a particular instrument. You set a voice from
anywhere
within
the
program
to GOSUB
to
the proper
subroutine. In our example, we would GOSUB the subroutine in
line 63050
(accordion).
+GOSUB

63050

where

stands

The commands that you see


in
special features of SYNTHY-64.

for

voice

lines 63010
With these

proper registers in the Commodore 64 are


For

1
to 63050
commands

are
the

set by SYNTHY-64.

example:
@WP
@P8
@A0

sets
sets
sets

a voice to a pulse waveform


the pulse width to 8
the attack speed to 0

You can use SYNTHY-64 to easily control the envelope


generator, filters, ring modulator, and dozens of other
variations allowed by the SID chip.

60

Below, is an example of using SYNTHY-64 to play a familiar


piece of music - "Swing Low, Sweet Chariot".
1

RUN"<clr>"

10 +GOSUB63050

50

T130

-GOSUB63020

100 +B5/4
G4/1 +G4/2 B5/4
150 G/A
G +G G G B5 B B/4

G4/4.
G +G/8
D +D/1
200 E/8
G + D B/2 D/4 G4/4.
C/2 +G/8 E
250 G/8
G +G G G B5
D +B A/4 G4/2.
G/l
300 D G +G4/8 E G G/4 G/8 G
C/2 +G G/4
350 G/8
G/l +G G G B5 B D/4 D/2.
D +D/4
400 E/8
G + D B/4 B G4 G/8
C/2 +G G G

E/8

D/4.

G + D/4.
+B5/4
E/8
G + D/4.
E

G/2 + D/4.

450 A/8
G +G G G
999 END
63000 REM
63005 PEM*******

B5

63010
63020
63030
63040
63050

@D9 @S0 @R0 @F0 RETURN


@S10 @R5 @F0 RETURN
@S1O @R1 ZB X10 Y12 @F1 RETURN
@D9 @S0 @R0 @F0 RETURN
@S2 @R2 ZH X8 Y12 @F1 RETURN

@WP
@WT
@WS
@WP
@WS

@P8
@A4
@A6
@P1
@A6

@A0
@D2
@D0
@A0
@D5

D +B A/4 G4/1

PIANO
FLUTE

TRUMPET
BANJO

ACCORDION

You can see in lines 10 through 450 that it is much easier


to enter music using a note-oriented language as opposed to
a POKE-oriented language. After entering the above music
and listen to your song. Have fun composing!

Of course, you can use SYNTHY-64 to create your own sounds


and instruments. The Commodore 64 has a remarkable ability
to make music

and

sound

effects.

61

Chapter 5

GRAPHICS PROGRAMMING

5.1 The Video Interface Chip 6567

5.1.1

CHIP Description

The VIC chip is a very sophisticated integrated of the 65xx


family. Not only is it responsible for producing the

pictures on the screen, but it also handles refreshing of


the Commodore's 64K of dynamic memory. Here are the most
important

features:

ability

to

display

16

colors

*
*
*
*
*

produces a 40 characters X
25 lines picture
has high resolution graphics with 320 x 200 pixels
5 types of bit mapping operations
handles 8 sprites with 24x21 dots each simultaneously
independent refreshing of 64K dynamic ram

movable

character

movable

video RAM

Pin description of
1-7

D6-D0;

the VIC

processor

6567

data

follow:

bus

-IRQ;

-LP;

11
12

R/W; 0=taking over data from bus


BA; 0= data not ready at reading

13
14

VDD; +12V
COLOR; color

10

15
16
17

-CS;

generator

if a bit of the IMR and the IRR coincide

input,

light-pen strobe

processor-bus action only take place

clock

CS=0.

access

information output
SYNC; Impulses to synchronize lines and
AEC; 0=VIC uses system bus, 1= bus free
0qOUT;

if

screen

output

18

-RAS;

Dynamic ram control-signal

19

-CAS;

as

20
21

GND
0COLOR;

22
23

0IN;
All;

24-29
30-31
32-34

A0/A8-A5/A13; multiplexed (video-)


A6-A7; (video-) ram address bus
A8-A10; processor address bus

35-38
39

Dll-8; data from color ram


D7; processor data-bus

40

VCC;

above

Input color frequency


Input dot frequency
processor address-bus

+5V

62

ram

address-bus

5.1.2

Register Descriptions

The VIC has 47 registers that are explained here.


REG 0

REG 1

sprite 0 X-coordinate

This is the low-order 8 bits of the X-coordinate of


sprite 0 position. The ninth bit is found in REG 16.
sprite 0

Y-coordinate

This is the Y-coordinate of sprite 0 position.


REG 2- same as above for sprites 1

thru 7

15 The register pair 2/3 is for sprite 1,

pair 4/5 for

sprite 2 etc.

REG

16

sprite 0 X-coordinate MSB

These are the high order bits of the sprite X-registers, bit 0 for sprite 0, bit 1 for sprite 1 etc.
REG

17

Control

register 1

Bit 0-2 number of dots to smooth scroll y-direction


Bit 3
0=display 24 rows; l=display 25 rows

Bit 4
Bit 5

0=blank screen
l=standard bitmap mode

Bit 6
Bit 7

l=extended color mode


raster compare high order bit REG 18

REG 18 When read, contains current raster position (8 bits


plus bit 7,

REG 17).

When written tor contains the raster compare value.


In this case, a raster inti jrupt is triggered when
the current raster matches Uiis value

REG 19 Contains

the X-position of

the

light

pen

input

after

REG 20 Contains

the Y-position of

the

light

pen

input

after

the

light

the

REG

21

pen

is

light pen

Sprite

is

triggered.

triggered.

enable

Each spirte 0 thru 7 is enabled (turned on) when its

corresponding
REG

22

Control

bit

register

is

set

to

1.

Bit 0-2
number of dots to smooth scroll x-direction
Bit 3
0=38 column display; 1=40 column display
Bit 4
Bit 5
REG

23

l=multicolor mode
l=reset VIC chip

Sprite

Each

width
is

expand X

sprite

set

in

the

to 1.

thru

is

x-direction

63

expanded

when

its

to

twice

normal

corresponding

bit

REG 24 Base address of character generator and video ram


Bit 1-3 address bits 11-13 for the character base
Bit 4-7 address bits 10-13 for the video-ram base
REG

REG

25

26

IRR
Bit
Bit
Bit
Bit
Bit

interrupt request register


0
raster interrupt (REG 18)
1
sprite-background interupt (REG 31)
2
sprite-sprite interrupt (REG 30)
3
light pen interrupt (pin LP)
7
set if zero if of the above bits is

IMR interrupt mask register


Bit 0
raster interrupt enable
Bit 1
sprite-background interrupt enable
Bit 2
spite-sprite interrupt enable
Bit

REG 27

28

REG

29

light

pen

interrupt

Sprite-background priority

Each sprite 0 thru 7 has a priority higher than the


background
if the corresponding bit
is
zero.
Background has higher priority if corresponding bit
is

REG

set to 1

one.

Sprite multicolor mode

Each sprite 0 thru 7 is displayed


if the corresponding bit is one.
Sprite

expand

in multicolor mode

Each sprite 0 thru 7 is expanded to twice the normal


height in the Y-direction if the corresponding bit is
one.

REG

30

Sprite-sprite

collision

For each sprite 0 thru 7 that has collided (nontransparent areas, are coincident) the corresponding
bit is set to one and IRR bit 2 is also set to one.
The bits in this register remain set until the
register

is

read.

REG

31

Sprite-background collision
For each sprite 0 thru 7 that has collided (nontransparent area are coincident with non-background
color characters) the corresponding bit it set to one
and the IRR bit 1 is set to one. The bits in this
register remain set until the register is read.

REG

32

Border

color

Bits

thru

3.

REG

33

Background color
Bits 0 thru 3.

#0

REG

34

Background

#1

Bits
REG

35

color

thru 3.

Background

color

#2

64

Bits 0

thru 3.

REG 36

Background color #3
Bits 0 thru 3.

REG 37

Sprite multicolor #0
Bits 0 thru 3.

REG 38

Sprite multicolor #fl


Bits 0 thru 3.

REG

39-

Sprite

46

Color of

5.1.3

color

sprites 0

thru 7.

Display Techniques

The VIC

chip

can

produce

different

types of displays:

a) standard characters displayed by the character generator;


b) multicolor characters; c) extended color mode;
d) high
resolution bit mode; e) multicolor bit mode; f) sprite

graphics.

Each

is

described below:

a) standard character generation:


Each character on the keyboard is assigned a screen code.
The letter A is given a screen code of 1, B a screen code
of 2, etc. The list of screen codes appears in Appendix E
of

the

Commodore

64

User's

Guide.

Screen memory holds the screen codes of the characters to

be displayed. Since the Commodore 64 can display 25 lines


of 40 characters each, there are 1000
screen memory
locations. Screen memory is normally located beginning at
$400 (1024 decimal) thru $7E7 (2023 decimal) but can be
moved if desired. When a character is to be displayed,
the character's corresponding screen code is written to
the

appropriate

screen memory

location.

For each of the 1000 screen memory locations, there is a


corresponding color memory location. Color memory is
located beginning at $D800 (55296 decimal) thru $DBE7

(56295) decimal. There is a one-to-one correspondence


with screen memory. Each position in color meory contains
a value of the color of the corresponding screen memory
character to be displayed. The Commodore 64 can display
16 colors, so only
location are used.

four

bits

of

each

color

memory

The character generator contains a set of patterns that


make up the letters, numbers and graphics symbols that
are to be displayed. The character generator is located
beginning at $D000 (53248 decimal) thru $D7FF (55295
decimal). Each pattern is 8 bytes long amd corresponds to

the 8 rows of dots which make up a display character. For


65

example,
symbol

the pattern in the character generator for the

looks

<lbyte

like

this:

>
Memory

BITS

location:

Value

1
2

$D000

$1C

$D001

3
4

$D002
$D003

$22
$4A
$56

Row

5
6

$D004
$D005

$4C
$20

Row

Row

$D006
$D007

$3E
$00

76543210
**

Row

*
*

Row

Row

**

Row

**

Row

*****

The screen code for @ is 0; the screen code for A is 1;


the screen code for B is 2, etc. The patterns in the
character generator are ordered by this

Thus

the

pattern

for

the

letter

same screen code.

would

follow

the

pattern for the symbol @ and the pattern for the letter B
would

follow

pattern

for

the

letter Af

etc.

Now to display characters on the screen. As each raster


line (TV scan) is displayed, the VIC chip gets the value

of the screen code from screen memory. The screen code is


multiplied by 8 and added to the address of beginning of
the character generator ($D800). The resulting address is
the location of the pattern to be used for this
character. The corresponding color memory location is

also read to determine the color in which the character

is to be displayed. The pattern is read out bit by bit,


row by row to create the character in the correct color
on the screen. Using this method, up to
256 different
characters

Diagram 5-1

can

be

shows

depicted.

this

in pictorial

66

form.

Screen

Color

memory

normally

at

always

$400

memory

at

$D800

VIC

Character

Chip

Generator

$D000-$D7FF

Monitor

or

DIAGRAM

b)

television

screen

5-1

Multicolor character generations


Using the standard character

method

of

display,

character is displayed in a single color only. This is


because each bit from the character generator is

translated as either on or off. A bit which is on takes


on the
foreground color
(as determined by the

corresponding

color

memory

67

location),

while

bit

which

is

off

takes

on

the

background

color.

You tell the VIC chip that you want to use the multicolor
character mode by setting set 4 of REG 22. Using the
multicolor character mode, the Commodore 64 can display
characters in one of four different colors. In the multi
color character mode, VIC chip translates the color and
character generator
information
diffently
than
the
standard

character

method.

Here the color memory location for each screen code


examined. If bit 3 of a color memory location is
(making the color value 0 thru 7), then the character
displayed in the standard character mode as described
a) above. However if bit 3 of a color memory location
1 (making the color value 8 thru 15),
is displayed in the multicolor mode.

is
0
is
in
is

then the character

During multicolor display, the VIC chip interprets the


character generator differently. Instead of the bits of a
pattern being interpreted as either on or off, multicolor
character mode uses consecutive pairs of bits to
construct a display character. The pairs of bits are
interpreted

as

follows:

COLOR
BIT

COLOR

PAIR

00

Background

color

01
10
11

Background

color

Background

color

Color
of

TAKEN

DISPLAYED

from
color

0
1
2

low 3-bits

FROM

$D021
$D022
$D023

(53281)
(53282)
(53283)

color

memory

memory

This makes it possible to display a character made up of


four different color within any 8X8 cell on the screen.
Of course the character is now depicted as a 4X8 pattern,
but with pixels twice as wide as with standard character
mode.
Again,
up to 256 different characters can
be
displayed

c)

in

multicolor

character

mode.

Extended color mode:


In the extended color mode, you can control the color of
the background for each individual character. Using the
extended color mode, the VIC chip can display a character
in one color, having a second color as a background, on a
screen of a third color. Thus,
every character can be
made up of two colors, but the background color is not
necessarily the same for each character.

To get

into

the

extended

color mode,
68

you

set

bit

6 of

REG

17. In the extended color mode, color memory is used the


same way as in the standard character mode. However
screen memory is interpreted differently. The two high-

order bits (bits 7 and 6) are used to select the register


from which
to get the color value for the background.

The

following

Screen

tables describes

this:

code

value of bits
7
6

Use Background
Register #

0
0
0
1
10
11

0
1
2
3

Taken

from

$D021
$D022
$D023
$D024

(53281)
(53282)
(53283)
(53284)

Since two bits of the screen code are used to select the
background color of the character, only six bits of the
screen

code

are

left

to

select

Thus only 64 different patterns

the

character

patten .

can be displayed.

d) High resolution bit mode:

Using high resolution bit mode of display, the VIC chip


can display 320 X 200 pixels in a choice of two colors
within each 8X8 screen cell.
Thus the 64,000 (320 X
200) individual pixels require 8K of memory to represent
an image on the high resolution screen. We call this 8K,
bit-mapped memory. Each bit of the bit-mapped memory
represents

a pixel

on

the

high resolution

screen.

To enable high resolution bit mode, bit 5 of REG 17 is


set and REG 24 must be primed with the address of the

bit-mapped memory.
Color memory is ignored in the high
resolution bit mode. Instead, the normal screen memory is
utilized as a sort of color memory.
Each byte of

the normal screen memory supplies the color


information for each 8X8 cell. Here normal screen
memory is divided into two four-bit nibbles. If a bit in
the bit-mapped memory is set to 1, then the high order
nybble (bits 4-7) of normal screen memory specifies the
color of these bits within that 8X8 cell. If a bit in
the bit-mapped meory is set to 0, then
the low order
four bits (bits 0-3) specifies the color of these bits in
that

same

cell.

e) Multicolor bit mode:

The multicolor bit mode allows each 8X8 cell to display


In the multicolor bit mode
there are
160 X 200 pixels. The pixels are displayed

up to four different colors.

69

twice
the

as

high

wide

on

the

resolution

screen

bit

in multicolor

bit

mode

as

in

mode.

Multicolor bit mode is enabled by setting bit 5 or REG 17


and bit 4 of REG 22 and REG 24 must be primed with the
address

of

the

bit-mapped memory.

There is a one-to-one correspondence between the bit


mapped memory and screen display except that here the 8K
bit-mapped memory is interpreted in pairs of two bits.
The pairs of bits cause the double wide pixels to appear
in
color as follows:

Bit pair

f)

Color

from

00
01
10

background register #0
screen memory low nybble
screen memory high nybble

11

color

memory

Sprites:
Sprites are large user definable characters that can be
displayed anywhere on the screen. They can be displayed
independently of the other types of displays on the
screen. Sprites also have other properties:

1)

4)

Up to 8 sprites can be defined and maintained by the


VIC chip. The sprites are numbered 0 thru 7 and each
sprite is 24 X 21 pixels large.
Each sprite can be expanded
in the horizontal
direction and/or the vertical direction immediately.
Each
sprite
can
be
positioned
on
the
screen
independently of other sprites.
A sprite can be defined as high resolution cr

5)

multicolor.
Sprites have

2)
3)

priorities

with

respect

to

each

other.

Sprite 0 has priority over sprite 1. This means that


if sprite 0 and sprite 1 are positioned so as to
overlap, sprite 0 would appear in front of spirte 1.
6)

7)

8)

Sprites have priorities with respect to background


objects.
A backgroud object
is defined
as
any
character or graphics on the screen that has other
than the background color. Each sprite can be made to
have a higher or lower priority than a background
object.
Collisions between sprites occur when they are
positioned so as to overlap.
Sprite
to sprite
collisions can be set to notify the Commodore 64
automatically.
Collisions between sprites and the background occur
when a sprite is positioned to overlap a background
object. Sprite to background collisions can be set to
70

notify the Commodore 64 automatically.

A high resolution sprite is defined as a 24 X 21 pixel


character. This means that 504 bits or 63 bytes are

needed to define a high resolution sprite. In defining a


high resolution sprite, each bit that is set to 1 appears
in that sprites foreground color (REG 39 thru 46). Each
bit that is set to 0 is transparent and whatever color is
be.hind

it

appears.

A multicolor sprite is defined as a 12 X 21 pixel


character with the horizontal pixels being double wide.
Still 504 bits define a multicolor sprite, but the bits
are interpreted in pairs. This allows a sprite to take on
up to four colors. To set a sprite to multicolor mode,

you must set the corresponding bit (0


REG

The

28.

sprite

follows:

colors

BIT Pair

are

defined

by

Color

00
01
10
11

thru 7)

the

bit

to one

in

pairs

as

FROM

Transparent
Sprite MC REG 0
Sprite color reg
Sprite MC REG 1

Screen color
$D025 (53285)
$D027-$D02E
$D026 (53286)

The VIC chip must be told where to find the definition of


the sprites. You pass this information to the VIC chip in
the last 8 bytes of screen memory. Thus if you were using
the normal screen memory location $400-$7FF, the memory
locations $7F8 (2040) thru $7FF (2047) contain the
pointers to the sprite definitions. The pointer for
sprite 0 is found at $7F8 (2040); the pointer for sprite
1 is

found at $7f9 (2041),

etc.

This pointer is actually the number of the 64-byte chunk


of memory in which the sprite definition is found. For

example the pointer, to a sprite located at $340 (832) is


13 (832/64).
This pointer would have to be placed in the
appropriate screen memory pointer location for that
sprite. For example, if we were using sprite 0, then we
would place the value of the pointer (13) into the screen
memory location for that pointer $7F8 (2040). Sprites do
not

This

appear on

is

done

the

by

screen

until

they

REG 21 to on. To turn off that same

in REG

21 must be

A sprite
locations

have

setting the appropriate bit


turned off.

sprite,

been

enabled.

(0 thru 7)

in

the same bit

may be positioned at one of 512 horizontal


or 256 vertical locations on the screen. These
71

are more than the 320 horizontal and 200 vertical screen
locations that appear
on the screen. But since a sprite
is so large, these extra locations allow a sprite to be
moved smoothly

into

the

viewing

area

of

the

screen.

When using sprites, the viewing area can be thought of as


the 320 horizontal and 200 vertical pixels on the screen
as

depicted

below:

511,0

)rO
H

343,30

24,30

VIEWING

1200

AREA

I
i

*
i

343,250

24,250

511,255

0,255

Note that the above diagram shows this 320 X 200 pixel
viewing area. A sprite's position is figured from its
upper

left

corner.

To position a sprite, the desired X-position is placed


into the corresponding REG 0 thru 14
(even registers)
and its Y-position is placed into the corresponding REG 1
thru REG 15 (odd registers). Since the register can hold
only 256 positions, the extra bit (which makes possible
the 512 positions) is located in REG 16. REG 16 contains
the most significant bit
for the X-position of each
sprite.

Anytime the non-transparent area of one sprite overlaps


that
of
another
sprite,
the
two
are
said
to
be
coincident. When they are coincident, the sprite with the
lower sprite number will appear in front of the other.
This is called sprite-sprite priority and is strictly a
function of the sprite number.
So sprite 0 has
the
highest priority of any sprite and always appears to pass
in front of a higher numbered sprite.
72

A sprite may also be coincident with background area. The


background area is any data on the screen that has a
color different from the background color. When the
sprite and the background area are coincident, either the
sprite or the background can be made to appear in front

of the other. This is controlled by the sprite-background


priority register, REG 27. If the corresponding bit (0
thru 7) in REG 27 is set to one, then the sprite has a
lower priority than the background area and appears to
pass behind the background area. If the corresponding bit
(0 thru 7) in REG 27 is set to zero, then the sprite has
a higher priority than the background area and appears to

pass

in front of

the background area.

The Commodore 64 also has the ability to detect when two


sprites are coincident. This is called sprite-sprite
collision detection. To enable this feature, bit 2 of REG
26 must be set to one. When at least two sprites have
collided, the Commodore 64 jumps to the IRQ vector
(interrupt handling routine) and sets bit 2 of REG 25 to
indicate the sprite-sprite collision. At the same time,
the corresponding bit (0 thru 7) in REG 30 for each
sprite that is coincident

is set to one.

Similarly, the Commodore 64 has the ability to detect


when a sprite and background area are coincident. This is
called sprite-background collision detection. To enable
this feature, bit 1 of REG 26 must be set to one.
When a
sprite and a background area have collided, the Commodore
jumps to the IRQ vector (interrupt handling routine) and
sets bit 1 of REG 25 to indicate the sprite-background
collision. At the same time, the corresponding bit (0
thru 7) in REG 31 for each sprite that has collided with

a background area

is

Sprites can also be


the width or both

set

to one.

expanded. You can double the height,


to produce larger objects on the

screen.

To expand

a sprite

to one.

You can expand a

in width,

the corresponding

bit (0 thru 7) in REG 29 is set to one. To expand a


sprite in height, the corresponding bit in REG 23 is set
multicolor modes.

sprite

in either

the

hires

or

5.2 Programming color and graphics

The outstanding features of the Commodore 64 are certainly


its color and its builtin synthesizer.
But how can you
appreciate these features if you aren't told how to program
graphics and
sprites?
On the following pages we will
explain to you how to go about programming these Commodore
64

specialties.

73

The graphic

possibilities of the Commodore 64 are better


than those of many other computers in the same or higher

price

category.

The most important feature is the ability of the Commodore


64 to control up to eight user definable objects on the

screen called sprites. Each sprite can be made to appear in


any of the 16 different colors.
In addition, you can define
and display multicolor sprites which can take on up to four
different colors. A sprite is a 24 X 21 pixel character comparable to a block of 3 X
3 normal size characters.

And sprites can be made to move independently of one another


with

ease.

The Commodore 64 allows you to display in up to 16 colors.


The color of the background,

foreground and the character

can be changed. In order to change the character color from


the keyboard, you hold the CTRL key or C= key while pressing
a number key between 1 and 8. Table 5-1 lists the color that
are

possible:

COLOR

COLOR

KEY
CTRL
CTRL

CTRL

CTRL

CTRL

CTRL

CTRL
CTRL

Note

C=

is

VALUE

BLACK

WHITE

RED

4
5
6

TURQUOISE
GREEN

2
3
4
5

BLUE

YELLOW

7
8

PURPLE

ORANGE

C=

1
2
3

C=

GRAY

1
2

C=

C=

BROWN
LIGHT

RED

9
10
11
12

C=

GRAY

C=

LIGHT

GREEN

13

C=

LIGHT

BLUE

14

C=

7
8

the

GRAY

TABLE

5-1

Commodore

key

15

You can change the border and background colors by POKEing


the color values
into the corresponding registers.
The
border color is in REG 32 and the background color is in REG
33. To change the border color, POKE 53280 with the desired
color value. To change the background color, POKE 53281 with
74

the

desired

color
POKE

makes a
of just

value.

For

53280,0:

POKE 53281,0

totally black screen.


one screen character,
POKE

This POKE changes

the

instance:

In order to change
all you need is:

the

color

the

upper

55296,1

color of

the

character

in

left corner of the screen to white.


The color of
characters on the screen would remain unchanged.

any other
Location

55296 is the beginning of an area called color memory and


continues to location 56295.
Location 55296 contains the
color of the character in line 1, column 1;
location 55297
the color of the character in line 1, column 2; location

56295

the

color

of

the

character

in

line

In order to get the screen full of A's,


following brief program:

10
20
30
40
50

column

you could

40,

etc.

write

the

PRINT CHR$(147):REM CLR SCREEN


1=1024 TO 2023:REM SCREEN MEMORY
POKE I,ASC("A")
NEXT I
END
FOR

You will see how the screen


left to the lower right.
In order
following

35

25,

POKE

fills

to add color to the


line to the program:

up

with

display,

55296+1-1024,INT(RND(l)*15)sREM

A's

you

from

would

the

add

upper

the

ADD COLOR RANDOMLY

The program runs almost the same, with the difference that
after POKEing the letter "A" into screen memory,
the
corresponding color memory location was set to a random
color.

Now lets investigate high resolution graphics. One use of


high resolution color graphics is for plotting mathematical
function. The following program illustrates the calculation
of the bit mapped memory locations needed for X and Y
coordinates.
Commodore BASIC does not have builtin graphics commands. So
drawing lines or circles is not very convenient from BASIC.
But the fact that these builtin commands don't exist does
not mean that the Commodore 64 is not capable of spectacular
graphics. All that is needed are some programming tools.

Towards

the

end of

this

section,
75

we

introduce

you

to

such

tool which we call HIRES GRAPHIC AID. Using this program,


you can conveniently make draw graphics.
This program even
enables you to save complete graphics on cassette or
diskette for later loading them from there.
This program is
written
in
a way
that
should enable you
to use
it
practically and even extend it.
Now back to the sample plotting program.
The objective of
this program is to draw a sine-wave on the screen. It is a
very common example of the application of graphics.

10

20

REM

SINE - PLOT PROGRAM


V=53248: REM START ADDR OF

THE

GRAPHIC

30

AD=8192:

THE

HIRES

40

POKE

V+17,59:

REM

SET

50

POKE V+24,24:

REM

POINT

60

FOR 1=1024 TO 2023:

POKE

REM

START ADDR

OF

HIRES
TO

PROCESSOR

BIT

MAP

MODE
SCREEN

MEMORY

REM SET COLOR RAM

70

80
90

NEXT I
FOR 1=8192

Ir16

100
110
120
130
140
150
160
170
180
190
200
210
220

: POKE 1,0
NEXT I
FOR X=0 TO 319: REM DRAW THE X-AXIS
: Y=100: REM POSITION OF THE X-AXIS
: GOSUB 1000: REM CALL DRAWING ROUTINE
NEXT X
FOR Y=0 TO 199: REM DRAWING OF THE Y-AXIS
: X=160: REM POSITION OF THE Y-AXIS
: GOSUB 1000: REM CALL DRAWING ROUTINE
NEXT Y
X=0
FOR I=-3.14159265 TO 3.14159265 STEP 0.0196349541
: REM INTERVAL LIMITS

TO

16383:

230

Y=100+99*SIN(I):

240

GOSUB

250

260

: X=X+1
NEXT I

270

GOTO

1000
1010

REM

CLEAR

SCREEN

MEMORY

FUNCTION

1000

270

OY=320*INT(Y/8) + (Y
OX=8*INT(X/8)

1020 MA=2A((7-X) AND 7)


1030 AV=AD+OY+OX
1040 POKE AV,PEEK(AV) OR
1050

REM

AND

MA:

7):

REM

REM

CALCULATE DOT POSITION

PLOT

DOT

RETURN

The SINE PLOT PROGRAM assumes that the hires screen is


arranged such that the origin (0,0) is located in the upper
left corner.
The subroutine beginning at line 1000,

calculates
and

then

the

position

proceeds

to

of

plot

the

that

76

individual

dot.

dot

to

be

plotted

What all happens now in our plot-program?


First, the two
starting addresses of the VIC chip registers and hires
screen memory are defined in lines 20 and 30. The next two

POKE commands:

POKE V+17,27+32 and POKE V+24,16+8

switch to graphics mode by changing the VIC chip registers.

POKE V+17,27+32

changes

the

Commodore

64

from

the

standard

character display (text mode) to the graphics mode of


display. POKE V+24,16 + 8 point sets the VIC chip to use the
bit map screen memory starting at 8192.

If you want to switch back to the text page later on, you
have to save their old values old values before changing the
addresses in the VIC chip. You should save the values in two
variables, since you will need these values later on.
This
could

look

like

this:

A1=PEEK(V+17)

and

A2=PEEK(V+24)

To get back into text mode later, after having worked with
graphics, you can just restore the VIC registers with these
saved

values:

POKE V+17,A1

Then you are

back

normally.

and POKE V+24rA2

into the

text

page

and

can

proceed

In lines 60 thru 80, you have to change the color of the


graphics display. You do this by changing each byte of color
memory. Lines 90 thru 110 clear the bit-mapped area to off
so that nothing

is

displayed

on

the

screen.

Each bit in the bit-mapped screen area represents one screen


pixel. Each bit has a value of either 0 or 1 and if the bit
is set to one, then the pixel is to be displayed; if the bit
is set to zero, then the pixel is not to be displayed. Eight
bits constitute a byte. One line of is represented as 8
bits/byte X 40 bytes/line = 320 bits / line. One column is
represented

bits/column.

mapped memory.

Let's

as

continue

composed

of 8

bits/byte

25

bytes/column

200

Altogether there are 64,000 bits in hires bit

by

looking

8 dots

at

giving

a character.
us

64

dots

Each of these dots can be set


or cleared
the others.
A character arranged as such:

77

A character

in

is

character.

independently of

64

dots

To enable each of the 64,000 bits to be displayed in 16 (24)

colors, we would need 4 X 64,000 bits or color memory. This


is not practical since 16K of memory would be required just
for this. So the 64 dots within this this 8X8 matrix must
have the same color.
This is not too serious a problen ,
since most
television sets do not permit much higher
resolution without the colors bleeding into each other.
By using the bit mapped technique to draw graphics, we seem
to lose the capability to write text to the graphics screen.
But by duplicating the pixels that form a text character on
the graphics screen, you can add text to graphics.
On the following pages you will find the program
GRAPHIC AID that will simplify graphics programming.

HIRES

If you are interested in programming graphics without the


hassle of POKES and PEEKS,
then we recommend either SCREEN
GRAPHICS 64 or ULTRABASIC 64 from ABACUS Software.
Each
provide graphics extensions to BASIC which make graphics
programming a cinch. Contact your dealer or ABACUS Software
for details.

The

assembler

listing

for HIRES

180:
190:
200:

HIRES

GRAPHIC AID
GRAPHIC

ORG

$C000

cooo

CR

EQU

cooo

XCOORD

EQU

FLAG

EQU

LF

EQU

SA

EQU

COOO

FA

EQU

COOO

TMP

EQU

13
$14
$97
$B8
$B9
$BA
$FD

ADR

EQU

TMP

AV

EQU

TMP

COLLOW

EQU

COLHI

EQU

GRALOW

EQU

330:
340:

COOO
cooo
cooo
cooo
cooo
cooo

GRAHI

EQU

cooo

GETCOR

EQU

350:
360:

cooo
cooo

CHKCOM
GETBYT

EQU

$400
$80
$2000
$4000
$B7EB
$AEFD
$B79E

210:
240:
250:
260:

COOO
COOO
COOO

270:
280:
290:
300:
310:
320:

EQU

78

follows:

AID

;LOGICAL

FILENUMBE1

;SECONDARY ADDRESS
;DEVICE NUMBER

; START

HIRES

COLOR

END HIRES COLOR


; START HIRES BIT

RAM

RAM
MAP

; END
; GETS X-AND Y COORD.
; CHECKS ON COMMA
? GETS BYTE VALUE

370:
380:
390:
400:
410:
420:
430:
440:

COOO
COOO
COOO
COOO
COOO
COOO
COOO
COOO

480:
490:
500:
510:
520:
530:
540:
550:
560:
570:
580:
590:
600:
610:
620:

EQU

GETPAR

EQU

CLSCRN
CHKOUT

EQU

PRINT

EQU

CLRCH
LOAD

EQU

SAVE

450:

460:
470:

VIDEO

EQU

$D000
$E1D4
$E544
$FFC9
$FFD2
$FFCC
$FFD5
$FFD8

EQU

EQU
JUMP

COOO
C003
C006
C009

COOC
COOF

C012
C015
C018
C01B
C01E
C021
C024
C027
CO 2 A
C02C
C02F
C031
C034
C037
C039
CO3C
C03D
C03F

4C
4C
4C
4C
4C
4C

CONTROLLER

;GET FILE- AND DEVICE


;CLEAR SCREEN
;SET OUTPUT DEVICE
;OUTPUT

ROUTINE

;OUTPUT

ON

ROUTINE

;SAVE

ROUTINE

FOR

FUNCTIONS

IE
3D
54
71

CO
CO

JMP

INIT

JMP

CLEAR

CO
CO

JMP

COLOR

;SWITCH ON GR.
;CLEAR GRAPHIC
;SET COLOR

JMP

8B

REVERS

CO

7 INVERT

JMP

SET

8E

;SET

CO

JMP

RESET

;RESET

Cl

JMP

GLOAD

3A
18
62

Cl

;LOAD

JMP

GSAVE

;SAVE

JMP

SELF

;NOT

JMP

AD

11

GOFF
;SWITCH
VIDEO+17
STORE1

CO

Cl
DO
Cl
DO

SELF

INIT

LDA

8D

72

AD

18

8D

Cl

STA

VIDEO+24
STORE2

A9

73
3B

8D
A9

11
18

DO

LDA
STA

#27+32
;SET
VIDEO+17

LDA

#16 + 8

8D
20

18

DO

STA

3D CO
10
5A CO

JSR

VIDEO+24
CLEAR

LDX

#16

JSR

COL

C043

720:
730:
740:

C045
C046
C048

750:
760:
770:
780:
790:
800:
810:
820:
830:

C049 DO
C04B E6
C04D A5
C04F C9
C051 DO
C053 60
C054 20
C057 20
C05A AO

840:
850:
860:
870:
880:
890:
900:
910:

C05C
C05E
C060
C062
C063
C065
C066
CO68

STA

LDA

GRAPHIC
POINT

GRAPHICS
GRAPHICS
USED

OFF

GR.

GR.

MODE

MODE

RTS

AO

00

A9
84

20
FD

STY

TMP

85
98
91
C8

FE

STA

TMP+1

A9
84

MODE

POINT

52

A2
20
60

DEFAULT

;LOAD

4C
4C
4C
4C

630:
640:
650:
660:
670:
680:
690:
700:
710:

C041

TABLE

;VIDEO

CLEAR

CLR1
CLR2

FD

LDY

#0

LDA

#>GRALOW

;CLEAR

GR.

MEMORY

TYA
STA

(TMP),Y

INY
FB

BNE

FE

INC

TMP+1

FE

LDA

TMP+1

40
F2

CMP
BNE

#>GRAHI
CLR1

CLR2

RTS

FD

AE

9E
00
04

B7

COLOR
COL

FD

JSR

CHKCOM

;SET

COLOR

JSR

GETBYT

;GET

COLOR

LDY

#0

LDA

#>COLLOW

STY

TMP

STA

TMP+1

85
8A
91
C8

FE

DO

FB

BNE

E6

FE

INC

FD

COL1

TXA

COL2

STA

;COLOR

(TMP),Y

INY

79

COL2
TMP+1

CODE

CODE

IN

ACC.

920:

C06A

A5

FE

LDA

TMP+1

930:
940:
950:

C06C
C06E

C9
DO

08
F2

CMP

#>COLHI
C0L1

C070

60

960:

C071

AO

00

LDY

#0

970:
980:
990:
1000:

C073
C075

A9
84
C077 85
CO79 Bl
C07B 49
C07D 91

20

LDA

#>GRALOW

FD

STY

TMP

FE

STA

TMP+1

1010:
1020:

BNE

RTS
REVERS

LDA

(TMP)fY

FF

EOR

#%11111111

FD

STA

(TMP)fY

REV1

FD

C07F C8
C080 DO F7
1050: C082 E6 FE
1060: C084 A5 FE
1070: C086 C9 40
1080: C088 DO EF
1090: CO8A 60I
1100: C08B A9 00
1110:
C08D 2C
1120: C08E A9 80
1130: C090 85 97

1030:
1040:

1140:

C092

1150:

1190:
1200:

CO95 20
C098 EO
C09A BO
C09C A5
C09E C9
C0A0 90

1210:
1220:

C082
C0A4

1160:
1170:
1180:

20

DO

;INVERT

FD
EB

INC
LDA
CMP
BNE

ILL

RTS

SET

LDA

RESET

LDA

.BYT

AE

B7

;RETURN

#0

$2C
#$80

STA

FLAG

JSR

CHKCOM

JSR

GETCOR

CPX

EE

BCS

15

LDA

01
08

CMP

#200
ILL
;Y
XCOORD+1
#>320

BCC

OK

ILL

1260:
1260:

C9 40
BO EO
COAA 8A
COAB 4A
COAC 4A
COAD 4A

1270:

COAE

A8

1290:
1300:
1310:

COAF

E9
8D
B9

1320:
1330:
1340:
1350:
1360:
1370:

C0B8
COBB
COBC
COBE
COBF

C0A6

CMP

#<320

1240:

C0A8

BCS

ILL

21
75
08

8D 76
8A
29 07
18
6D 75
8D 75

OK

TXA

1440:
1450:

C0C5
C0C7
C0C9

COORD.

POINT

TO

XCOOR,Y

TO

X-REG

COORDINATE

>

199

;X

COORDINATE

>

319

;Y

COORDINATE

TO

ACC.

LSR
LSR

;DIVIDED

LSR

BY

TAY

;OFFY=320*INT(Y/8)+(YAND7)

Cl
Cl

LDA

MULTLO,Y

STA

OFFY

Cl
Cl

LDA

MULTHI,Y

STA

OFFY+1

AND

Cl

ADC
STA

320

COORDINATE

#%111
;PLUS

CLC

Cl

;TIMES
?Y

TXA

;0FFX=8
1390:
1400:
1410:
1420:
1430:

;X

C8

1230:

INVALID

;SKIP INSTRUCTION
;RESET POINT

XCOORD

C0C2

IF

;SET

LDA

C0B2
C0B5

BITS

REV1
TMP+1
TMP+1
#>GRAHI
REV1

BNE

1250:
1260:

;INVERT

INY
BNE

E6
14

A5

GRAPHICS

AND

OFFY
OFFY

INT(X/8)

A5

14

LDA

29

F8

AND

#%11111000

8D
18

74

Cl

STA

OFFX

COCC
COCD A9 00
COCF 6D 75 Cl
C0D2 85 FD

CLC

;AV=GRALOW+OFFY+OFFX
#<GRALOW

LDA

XCOORD

ADC

OFFY

STA

AV

80

1460:

C0D4

A9

20

1470:

C0D6

6D

76

1480:
1490:

C0D9
CODB

85
18

FE

1500:
1510:
1520:

CO DC

A5

FD

CODE

6D
85

74

A5

AV

FD
FE

LDA

AV+1

15

ADC
STA

XCOORD+1
AV+1
;MA =

LDA
AND

XCOORD
#7

EOR

#7

1570:
1580:

COE9 A5
COEB 29

14
07

1590:
1600:

COED
COEF
COFO
C0F2
C0F3
C0F5
C0F6

07

1620:
1630:
1640:
1650:

Cl

AA

01

LDA

SET4

BMI

;MA
7

SET3

BNE

SET4

;SHIFT BIT LEFT


?ABSOLUTE JUMP

;ACC,.

ASL
FA

1660:

C0F8

AO

00

LDY

#0

1670:

CO FA
COFC
COFE

24

97

BIT

FLAG

10
49

05

BPL

SET5

FF

EOR

#$FF

31
2C

FD

1710:

C100
C102

AND
.BYT

1720:
1730:
1740:
1750:

C103
C105
C107
C108

11

FD

91
60

FD

(AV)fY
$2C
(AV)fY
(AV),Y

1680:
1690:

1700:

1760:

C108

00

C110
C118

08
12

C120
C121

ID

SET3

SET5

ORA

STA
END

00
OA
14

2*((7-X)AND 7)

#1

DEX

03

OA
DO

AV

TAX

CA

30

AV+1

OFFX

FE

A9

STA

LDA

65
85

1610:

#>GRALOW
OFFY+1

ADC
STA

1540:
1550:

49

LDA
ADC

CLC

COE1
C0E3
C0E5
C0E7

1530:

Cl

CONTAINS

;CLEAR
;SET

MASK

BIT

BIT

RTS

MULTHI

EQU

;TABLE

HIBYTES

END+1

N*320

01

02

03

05

06

07

OB
15

OC
16

OD
17

OF
19

10
IB

11
1C

MULTLO

EQU

;TABLE

LOBYTES

C121

00

40

80

CO

00

C129

C131
C139

00
00
00

40
40

80
80

CO
CO

00
00

1870:

C13A

20

FD

AE

1880:

C13D

20

D4

El

1890:

C140

A2

1900:
1910:

C142
C144

AO
A9

1920:
1930:

C146
C148

85
A9

1940:

C14A

1950:
1960:
1970:

1980:
1990:

GSAVE

40
40
40

80
80
80

MULTHI+25

N*320
CO
CO
CO

JSR

CHKCOM

;SAVE

JSR

GETPAR

;GET FILENAME
& DEVICE ADDR

00

LDX

#<GRAHI

40

LDY

00

LDA

#>GRAHI
#<GRALOW

FD

STA

TMP

20

LDA

#>GRALOW

85

FE

STA

TMP+1

C14C

A9

FD

LDA

#TMP

C14E
C151

20
60

D8

JSR

SAVE

C152
C155

20

FD

AE

20

D4

El

FF

GRAPHIC

RTS

GLOAD

JSR
JSR

81

CHKCOM
GETPAR

;LOAD
:GET

GRAPHIC

FILENAME

2000:

C158

A9

61

LDA

#$61

2010:

C15A

85

STA

SA

2020:

C15C

A9

B9
00

2030:
2040:

C15E

D5

FF

C161

20
60

2050:
2060:

C162
C165

AD

72

Cl
DO

11
C168 AD 73
C16B 8D 18
C16E 20 44

2070:

2080:
2090:
2100:

C171

GOFF

2120:
2130:
2140:

use

5.3

#0
LOAD

LDA

STORE1
VIDEO+17

Cl

LDA

DO

STA

STORE2
VIDEO+24

E5

JSR

CLSCRN

ADDR
FLAG

:CLEAR

SCP

RTS

60

this

following

;LOAD

LDA

JSR
RTS
STA

C173
C174
C175
C177

2110:

To

8D

;SEC

STORE1
STORE2

BYT

OFFX

BYT

OFFY

BYT

machine

calls

language

from

*+l
*+l
*+l
*+2

BYT

routine,

you

can

use

the

BASIC:

SYS49152

INIT

turn

SYS49555

CLEAR

clear

graphics mode

SYS49158,c

COLOR

SYS49161
SYS49164,x,y

REVERSE

SYS49167rxfy

RESET

SYS49570,"f",d

GLOAD

SYS49573,"f,d

GSAVE

SYS49579

GOFF

the

on

screen

set plotting
reverse each

color
point

to
on

c
screen

set point at coord, xry


reset point at coord. x,y

SET

load graphics
name "f"
save graphics
name "f"
turn

picture with
from device d
picture with
to device d

graphics mode

off

SPRITES - Some graphics magic on the Commodore 64

5.3.1

Introduction to Sprites

Aside from its superb sound synthesis capabilities, the


ability to create and manipulate sprites is certainly the
outstanding feature of the Commodore 64.
Sprites are large
graphics designs that can be controlled independently of the
other

5.3.2

For

graphics

or

text

on

the

screen.

Sprite Capabilities

a moment,

let's

imagine

that

there

are

no such

thing

as

sprites. You are creating an arcade game and want to draw a


finely detailed character (we'll call it a blob) on the
screen and and animate it. The fine detail requires that you
use the high resolution screen. As previously discussed, you
have to draw the blob on the screen by using bit mapped
82

techniques to place the character at the desired position on


the screen. This involves setting each pixel that comprises

the blob to on. If a blob is made up of 60 pixels, then all


60 pixels must be turned on. Additionally, you have to
coordinate the color of the pixels, by manipulating the
screen memory
colors).

In

order

to

(which

move

the

control

blob,

the

you

bit

have

mapped

to

graphics

calculate

new

position for each pixel that makes up the blob. But befoie
you redraw the blob at its new position, you must first make
the earlier blob disappear from its old position. You do

this

you

by

can

resetting
proceed

(turning off)

to

redraw

each pixel

the

blob

at

that

its

was on.

new

Then

position.

Repeating this technique, you can make the blob move across
the bit mapped graphics screen.
Now let's say that there are some other stationary objects
on the screen, maybe a house. In order to make it appear
that the blob is entering the house, we must make the blob
gradually disappear as its pixels meet the pixels that make
up the house. To do this, you must know the position of the
house's pixels on the screen.
As
the blob's new pixel
positions are calculated, they are compared to the pixel
positions of the stationary house. If these pixel position
coincide, then the blob's new pixel at that position is not
set

on.

Instead,

that

position

is

left

If you continue along these same


blob disappear into the house.

to

lines,

display

you

can

the

house.

make

the

In a like manner, you can make the blob pass in front of the
stationary house. When the blob's new pixel position
coincides with the pixel position of the house, the blob's
pixel is displayed instead of the house's pixel. The same
technique is applicable to collisions that might occur with
other

blobs.

You can see that all of these calculations and logic to


determine which pixels need to be turned on or off is not
only complicated, but very time consuming. If done from a
BASIC program, the blob might be able to move about as fast
as molases. If done from a machine language program, the
blob can be made to move fast, but only at the expense of a
lot of program coding and testing.
The idea behind sprites is that most of the tedious and
time-consuming calculations to determine the blob's new
position are handled by the VIC chip. A sprite,
once
defined,
can be moved and manipulated very easily from
within a program.
After

you define a sprite, you do not have to turn on or off


individual pixels when drawing the sprite. When you move the
sprite from one position on the screen to another, you do
not have to erase the previous positon of the sprite. You
can make a sprite pass in front of or behind stationary

83

objects automatically. In fact, you can make one sprite pass


in front of or behind another sprite. Or make it disappear
altogether. Eight such sprites can be handled by the
Commodore 64

at one

time.

If you want, you can have the Commodore 64 notify you when a
sprite and a stationary object or two different sprites
have collided. And changing the color of the sprite is also
very simple. These sprite capabilties makes the Commodore 64
a

very

5.3.3

powerful

computer.

Sprite Structure

When using
sprites, it is good idea to be familiar with
binary arithmetic. Sections 1.1 and 5.1 will acquaint you
with the registers of the VIC chip.
When using sprites,
the majority of the work involves
setting up the registers of the VIC chip that control
movement, color, and the other features of the sprites.

Each register consists of 8 bits which the user can set or


reset according to the desired effect.

When using sprites, we refer to the numbers which define hew


the sprite looks as the sprite pattern. An important point
in using sprites is the location in memory of the sprite
pattern.
As you know, one sprite consists of 24x21 points
(pixels).
Horizontally a sprite has
24 pixels and
vertically

it

has

21

pixels.

84

SPRITE

ROW

ROW

LAYOUT

ROW 3
ROW 4
ROW 5
ROW 6
ROW 7
ROW 8

ROW 9
ROW 10
ROW 11

ROW 12
ROW 13
ROW

14

ROW 15
ROW 16
ROW 17
ROW

18

ROW 19

ROW 20
ROW 21

Each "row" consists of 3-bytes each with 8 pixels or bits


each.
The color of a sprite can be specified in either of
two ways:

1.

HIRES

SPRITE

When

using

hires

sprites,

one

bit

in

the

sprite

pattern

produces one point on the screen. This point

thru 46)

if the bit

has either the background color if the bit is zero, or


the color specified by its corresponding register (REG 39

2.

is one.

MULTICOLOR SPRITE

When

using multicolor

sprites,

two bits

in the

sprite

pattern produces one point on the screen. The point is


actually two pixels wide on the screen. The point

is
either: the color of the background if the bits are 00;
the color specified by REG 37 if the bits are 01; the
color specified by its corresponding register (REG 39
thru 46) if the bits are 10; or the color specified by
REG 38 if the bits are 11.

In the following section,

these

sprites.

we deal with the programming of

85

5.3.4

5.3.4.1

Programming sprites

Sprite Patterns

When programming sprites,


you must first
pattern which is to represent the sprite.

set

up

the

sprite

In order to help you in developing sprites. Diagram 5-1 is a


a design sheet. You may either copy this design sheet or use
it as a sample for your own design sheet.
First draw a rough sketch of the sprite on a separate piece
of paper. Decide whether the sprite is to be one color or
multicolor. Next transfer this rough sketch to the sprite
design sheet.

If using one color sprites, fill in each box on the sprite


design sheet that corresponds to the rough sketch. Treat ore
box on the sheet as one pixel on the screen. If you fill the
squares that make the pattern completely and then stand back
from the sprite design sheet, it is quite easy to recognize
the pattern and determine if any changes are required to
give the sprite the final touches.
If using multicolor sprites,
fill in each box with the
desired color (color pencils work nicely) that corresponds
to the rough sketch. Keep in mind that two horizontally
adjacent boxes on the sprite design sheet correspond to one
pixel (each pixel is twice as wide) on the screen.
Only
four different colors may be used. One color is common and
is the background color;
one color is unique
for each
sprite; and two colors are common to all sprites that are
used. The background color is always given a value of 00, so
the values for the two horizontally adjacent boxes is also
00. The unique color is always given a value of 10, so the
values for the two horizontally adjacent boxes is also 10.
The color specified by multicolor register 0 is given a
value of 01,
while
the
color specified
by multicolor

register 1 is given a value of 11 and these are the values


for the two horizontally adjacent boxes if these colors are
chosen on the sprite design sheet.
With either one color or multicolor sprites, the next step
is to determine the numeric values that make up the sprite
as drawn on the sprite design sheet. To do this, you treat
each group of eight horizontal boxes as a unit. Add the
number that corresponds to that column for all boxes. Keep
in mind that the multicolor sprites may have a value or 00,
01, 10, or 11 according to the color that is represented by
the pair of horizontally adjacent boxes.

86

5-2

SPRITE DESIGN SHEET

87

For each unit of eight boxes, the sum of these eight values
are used in subsequent POKE commands. The most convenient
way to define the points of a spirte pattern is by entering
them into BASIC DATA statements.
Then you can READ them
from within a FOR-NEXT loop and POKE them into a memory area
that you've set aside for the pattern. The sprite is now in
memory and ready for use. In order to get the programming a
little more

statements

This

organized,

to

structure

you may want

look

like

this:

1000

DATA

000,000,000

1010

DATA

1020
1030
1040
1050
1060
1070
1080
1090
1100
1110
1120
1130
1140
1150
1160
1170
1180
1190
1200

DATA
DATA
DATA
DATA
DATA
DATA
DATA
DATA
DATA
DATA
DATA
DATA
DATA
DATA
DATA
DATA
DATA
DATA
DATA

000,000,000
000,000,000
000,000,000
000,000,000
000,000,000
000,000,000
003,255,255
000,002,000
192,170,128
194,150,080
234,150,080
194,170,168
192,170,168
000,032,128
000,170,160
000,000,000
000,000,000
000,000,000
000,000,000
000,000,000

represents

the

bytes

to

arrange your

(24 bits)

DATA

X 21 bit of

a sprite.
Each number between 0 and 255 represents the
pixel pattern that makes up the sprite.
Thus it is possible
to program any figure - from a single point to a full 24 X
21 block or any other combination in between.

5.3.4.2

The

Program

Now let's move on to programming the sprites. Back to our


example. What do these DATA statement represent? For this we
have to present the decimal numbers in binary again:

88

SPRITE

LINE
LINE
LINE
LINE
LINE
LINE
LINE
LINE
LINE
LINE
LINE
LINE
LINE
LINE
LINE
LINE
LINE
LINE
LINE
LINE
LINE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000011
00000000
11000000
11000010
11101010
11000010
11000000
00000000
00000000
00000000
0000000 0
00000000
00000000
00000000

Here we have a
recognize it on

PATTERN

00000000
00000000
00000000
00000000
00000000
00000000
00000000
11111111
00000000
10101010
10010110
10010110
10101010
10101010
00100000
10101010
00000000
00000 0 00
00000000
00000000
0000 0000

00000000
0 0000000
00000000
00000000
00000000
00000000
00000000
11111111
00000000
100 0 0000
01010000
01010000
10101000
10101000
10000000
10100000
00000000
00000000
00000000
00000000
00000000

pattern of a helicopter.
If you don't
paper, you will when it appears on the

screen.

5.3.4.3

Turning the Sprite On

After having defined the sprite pattern, you have to turn it


on. The sprite number determines how to turn that sprite on.
The corresponding bit (bit 0 thru 7) in REG 21 is set to one
for the sprite number that is to be displayed.

Sprite:
Bit
:
Value

POKE V+21rl

76543210
b7
b6
b5
b4
b3
b2
bl
bO
128

64

makes

32

sprite

16

visible;

POKE

21,3

(values

of

2) makes sprites 0 and 1 visible; and POKE V+21r255 (values


of 1 + 2 + 4 + 8 "+ 16 + 32 + 64 + 128) makes spirtes 0 thru
7 visible.

89

5.3.4.4

Memory Areas

for

Sprites

Next the addresses of the sprite patterns must be specified.


The addresses of the sprite patterns are placed in the last
eight locations of screen memory and are called pointers. If
screen memory in its default location ($400), then these
pointers are located at 2040 thru 2047. Each sprite pattern
is 63 bytes in length (24 bits X
21 rows) = 63 bytes. An
extra byte is added to the sprite pattern as a separator and
is set to zero. Thus we should speak of each sprite pattern
as being 64 bytes in length.

Within a 16K memory bank, there are 256 64-byte blocks. The
value in a sprite pointer is actually the number of the
block within that 16K block where the sprite's pattern is
located.

For example,
if a sprite is defined beginning at memory
location 832, then the pointer for that sprite is 13 (832 /
64 =13). If this pattern is to be used for sprite 0, then we
would POKE 2040,13
to set
the
correct
sprite pointer.
Location 2040 is the pointer for sprite 0. The value of 13
is the 13th 64-byte block in the 16K memory bank that the
VIC chip can address.
From the above, it is clear that a sprite pattern must start
on a 64-byte boundary. When screen memory is at its default
location ($400 = 2048 decimal),
the following addresses and
pointer values may be used for sprite definitions:

Pointer

Address

10
11

640
704
768
832
896
960
1024
1088
1152
1216
1280

The

12

13
14
15
16
17
18
19
20

following table gives you the pointer location of each

sprite

for

POINTER
Sprite

the

default

screen

memory:

: 2040 2041 2042 2043 2044 2045 2046 2047


:01234567

If you place the value 13 in memory 2040 it means that the


sprite pattern begins at memory location 832.
You can also

90

write 13 in memory location 2041. This means that sprite 1


is has the same pattern as sprite 0.
In this case, all of
the other information, such as color, position, expansion

etc., may be different


shapes are identical.

This

feature

of

for

these

sprites

two

can

sprites,

but

potentially

the

basic

reduce

the

programming effort tremendously. In games, for example, you


may have several alien creatures that are clones of each
other, except for position. One sprite pattern can serve as
the model for all of these aliens.
By setting the
appropriate sprite pointer to refer to the same pattern, you
can clone seven more of these creatures while the
computer
takes care of the display. Each of the creatures can have

its own color. Furthermore, each creatures can be positioned

independently of each

other.

By using a FOR-NEXT loop from BASIC,

pattern
832.

may

be

FOR 1=0
READ X

transferred

TO

62:
:

POKE 832+1,X

NEXT

5.3.4.5

REM
REM

to

the

the values of sprite

memory

area,

at

63 BYTES OF A SPRITE
READING OF THE BYTE

: REM WRITING OF THE BYTE


:

starting

REM

END OF

LOOP

INTO THE BLOCK

Sprite Positioning

Next we want to specify the position of the


screen.
A sprites's position is set by

sprite on the
priming two

registers: one that specifies the sprite's X-position and

one

that

specifies

the

sprites's

Y-position.

From now on we'll use variable V in or examples to stand for

the beginning address of the video controller registers.

We

set V = 53248, the address is the start address of the video


controller.
So one of the first line number of every
program that uses graphic or sprites should read like this:
10 V=53248:

To

position

REM START OF VIDEO CONTROLLER

sprite

on

the

screen

you

need

two

POKE

commands:

POKE V+0,COLUMN: REM


POKE V+1,LXNE
: REM

SPRITE 0 - X position
SPRITE 0 - Y position

So if you want to position the helicopter near the middle of


the screen, all you need is
POKE

V+0r184

POKE

V+lf125

91

5.3.4.6

Shifting Sprites

We can also move the sprites quite easily. In order to


achieve smooth movement, we should change the location of
the sprite by one screen point at a time. We can do this by
using

FOR-NEXT

loop:

100

FOR 1=159 TO 100

110

120

NEXT

STEP -1

POKE V+0,1
I

The above routine moves the helicopter to the left, yet it


remains in the same vertical position.
If you want to watch
the movement more slowly, you have to insert another loop

before

the

NEXT

I:

115

FOR 11=1

TO

100:

NEXT

Now the sprite moves much slower and you can watch it.
You

might

have

recognized

horizontal positions.

one

the X-register can only be 255.


to the

right

side of

problem:

there

are

But the highest value of a POKE

the

320

into

How can you move the sprite

screen?

For this, there is another register.


Register 16 holds one
high order bit for each sprite.
If the X-coordinate of a
sprite is higher than 255,
then the bit for the
corresponding sprite is set to one. For sprite 1, we would
do the

following

for an X-coordinate greater than 255:

POKE V+16,1

After this POKE, 255 is added to our addressing.


Now POKE
V+0,1 would mean a positioning on dot 256.
In order to get

to dots smaller than 256,

this bit has to be set back again:

POKE V+16,0

5.3.4.7

Sprite Color

We can also change


sprite has its own
located

at V+39

the color of a one color sprite. Each


color register.
These registers are

to V+46:

Register: 39
40
41
42
43
44
45
46
Sprite
:01234567

92

Below

colors:

is

the

numbers

which

correspond

to

the

specific

COLOR
0

BLACK

WHITE

RED

TURQUOISE

4
5

PURPLE

BLUE

7
8

ORANGE

BROWN

10
11
12

13
14
15

GREEN
YELLOW

LIGHT

RED

GRAY

GRAY

LIGHT

GREEN

LIGHT

BLUE

GRAY

For example, by using POKE V+39,14


blue in color.

5.3.4.8

sprite

becomes

light

Enlarging Sprites

You can magnify or enlarge a sprite in the horizontal and/or


a
vertical
direction.
Two
registers
perform
this
enlargement.
One register is
for enlargement in the X
direction, and the other for enlargement in the Y direction.
Thus every sprite control-register is constructed as
follows:

Bit
Sprite

:76543210
:7
65
4
3
2
1
0

Value

:128

64

32

16

If sprite 0 is to be enlarged in X as well as


direction, the following POKE commands are necessary:
POKE V+23,1:
POKE V+29,1:

REM ENLARGES
REM ENLARGES

SPRITE
SPRITE

In order to enlarge sprites 0 and


V+23,3 (value of 1 + 2) will handle

0
0

in

IN Y-DIRECTION
IN X-DIRECTION

1 in Y direction,
the job.

POKE

Every sprite can be doubled in the X and Y directions. This


means that one character can be enlarged to 4 times its
original size.

93

5.3.4.9

Background

The next example shows another feature of the Commodore 64.


You can choose whether the sprite is placed in front of or
behind the background.
Some nice effects result.
When you
have the helicopter on the screen,
type:
POKE V+27,1

With

this

poke,

you can direct

the

sprite

to appear

in

front

of or behind the background.


In order to see the effect,
bring the cursor to the same line as the sprite.
Then you
simply enter a few characters, just enough to cover the

sprite with the letters.

The letters are considered to be

background. Try different colors to see the best contrast to


the sprite.
You'll see that the writing appears in front of
the sprite.
Actually you moved the sprite into another
"level" - namely under the background.
Now go to another
line

and

type:
POKE V+27,0

The sprite will move in front of the text again.


register for the background-sprite priority then looks
this:
Bit

SpritePriority

:76543210

b7

b6

b5

b4

b3

b2

bl

The
like

bO

With this register you can change the priority of every


sprite at will.
If the bit is set to 0, it means that the
sprite appears is in front of the background; set to 1, the

sprite appears behind the background.


By setting and
clearing of the bits there is the possibility of setting
several sprites on top of each other and still be able to

differentiate between foreground and background. As


mentioned,
this enables the Commodore 64 to create
dimensional pictures.

5.3.4.10

already
three-

Sprite-sprite Collisions

There is more to say about the overlapping of sprites. There


is a register in which a collision of different sprites is
recorded.
The contents of this register remains set to
zero until two or more sprites collide, or until you reset
this register.
Once the sprites have overlapped (collided),

94

have

collided.

The value of this register tells us what sprites have


collided. For example, if we have the following statement:
CO=PEEK

(V+30)

and the value of CO = 3, then we know that sprites 1 and 2


have collided.
The bit structure of the register is the
same

as

the

other

After this PEEK,

registers.

the register has

to be

reset by:

POKE V+30,0

If you did not clear REG 30, then the registers would stay

set even

5.3.4.11

if a collision

was not taking place.

Sprite-background Collisions

A collision between a sprite and the background can be


recorded too. Register 31 serves this purpose.
This

register is treated similar to register 30.


The only
difference is the result of the PEEK.
The value informs us
which sprite(s) has collided with a character.
It does not

tell us which background character it was not its location.


In order to get this information you have to determine that
yourself from the other registers and memory locations.
CO=PEEK (V+31)

This

register has

5.3.4.12

to be cleared after a collision,

too.

Multicolor Sprites

Multicolor sprites add much flavor to the Commodore


graphics capabilities.
A multicolor sprite can be made

64
up
of three colors. The expense for the extra two colors less
resolution since two bits of the sprite pattern appear as
one double-wide pixel on the screen.
Therefore we have a 4
x 8 matrix instead of an 8 x 8 one.
These two bits contain
the information about the color.
We already know that we can transfer 4 pieces of
with 2 bits: 00, 01, 10, and 11.
When using
these 2 bits have the following effects:
00

information
multicolor

- The dot has the background color


(you don't see a dot)
01 - The color displayed is in register 37
10 - The color displayed is in corresponding
register 38-46
11 - The color displayed is in register 38

95

This means that a sprite can have its own color and
colors that are common to all sprites.

two

Maybe you asked yourself why our helicopter looks a little


strange.
We can answer this question now: it was designed
as a multicolor sprite.
Since a multicolor sprite consists
of fewer dots, you can't get a decent picture in the normal
sprite mode.
To finish this chapter, we want to show you

the complete program with the multicolor helicopter.


It is
advisable to experiment with the programming of sprites,

using this program as


readily acquainted with

an example.
That way you
the programming technique.

become

REM

10

REM

15
20

REM
V=53248:

SPRITE

DEMONSTRATION

HELICOPTER

30

REM START VIDEO CONTROLLER


POKE V+32,15: POKE V+33,14: REM BACKGROUND

40
50

PRINT "<CTRL>-711: REM PRINTING CONTROL AND 7


POKE V+21,3: REM TURN ON SPRITE 1 AND 2

COLORS

60 POKE V+28,3: REM SPRITE 1 AND 2 ARE MULTICOLOR


70 POKE V+39,6: REM COLOR OF SPRITE 1 - BLUE
80 POKE V+40,2: REM COLOR OF SPRITE 2 - RED
90 POKE V+37,14:REM MULTICOLOR COLOR 1 - LIGHT BLUE
100 POKE V+38,0: REM MULTICOLOR COLOR 2 - BLACK

110 POKE 2040,13:


120 POKE 2041,13:

REM SPRITE 1 FROM MEMORY RANGE 832-895


REM SPRITE 2 FROM MEMORY RANGE 832-895

125
130
140
150

REM THAT MEANS SPRITE 1 AND 2 HAVE THE SAME FORM


FOR 1=0 TO 62: REM LOOP TO READ IN THE DATA
: READ X: REM READING OF THE DOT COMBINATION
: POKE 832+1,X: REM SAVING OF THE DOT COMBINATION

160

NEXT

170
180

POKE V+0,24:
POKE V+2,60:

190

END

997
998

REM
REM

999

REM

1000
1010
1020
1030
1040
1050

I:

DATA
DATA
DATA
DATA
DATA
DATA

REM

SPRITE

END OF

LOOP

POKE V+1,50:
POKE V+3,50:

PATTERN

REM POSITION OF
REM POSITION OF

FOLLOWS

000,000,000
000,000,000
000,000,000
000,000,000
000,000,000
000,000,000

1060

DATA 000,000,000

1070

DATA

003,255,255

1080

DATA

000,002,000

1090

DATA

192,170,128

1100
1110
1120
1130
1140

DATA
DATA
DATA
DATA
DATA

194,150,080
234,150,080
194,170,168

192,170,168
000,032,128

96

SPRITE
SPRITE

1
2

1150
1160
1170
1180
1190
1200

DATA
DATA
DATA
DATA
DATA
DATA

00.0,170,160
000,000,000
000,000,000
000,000,000
000,000,000
000,000,000

We hope that you use this program as a guide to writing your

own

sprite programs.

97

CHAPTER 6

6.1

Basic From a Different Viewpoint

How the BASIC Interpreter Works

Let's see how the BASIC interpreter works. As you enter text
into the Commodore 64, the interpreter first checks to see

if there is a number at the beginning of the text. When it


sees a number there, it assumes that the text is a program
line. The interpreter uses this number as a line number and
assumes that the text following are part of the program
statements. If the line number does not already exist, then
the program line is new and is placed into memory in program
line sequence. If the line number already exists, then this
program line replaces the previously entered program line. A
program line number without any text following it merely
deletes any previously entered program line.
As the program lines are entered, the interpreter also
searches for any keywords that are imbedded
within the
text. Keywords are the special reserved words such as: IF,
GOTO, OPEN, REM, SIN, etc. When it recognized a keyword, the
interpreter replaces the keyword with a one-byte token. The
value of the token is a hexadecimal number between $80 and
$FE. Therefore any character with its high bit set (bit 7)
is

token

for a

BASIC

keyword.

As a BASIC program is executed, the interpreter can easily


find tokens within the text since their high bit is set.
Using the token, it finds the appropriate BASIC routines in
ROM which handle the particular function or action.
addresses of the routines are found in Chapter 6.4;
routines themselves are described in Appendix A.

The
the

In order to take the most advantage of the built in ROM


routines, you should understand something about the number
representation of the interpreter.
BASIC differentiates
between three data types: real numbers, integer numbers, and
strings. Real numbers are in a range from +/- 1E-39 to +/1E38. Integer numbers can
only
take
whole-number values
from -32768 to 32767. Strings are character strings with a
length

from

to

255

characters.

Variables are used to store values. Each variable occupies


seven bytes of memory. Here we discuss only simple variables
(non-array

variables).

The first two bytes of each variable contain the variable


name. The next five bytes contain the value of the variable.
If the variable represents a floating point number,
the
first byte is the exponent and the next 4 bytes represent
the mantissa. If the variable represents an integer number,
only two bytes are used - the high and the low byte of a 16-

bit binary number. If the variable represents a string,


first byte contains the length of the string (0 to 255),

98

the
and

the

next

two bytes

contain

the

address

of

the

strings.

The BASIC interpreter differentiates the the different


variable types by encoding the variable name, or floating

point

variables,

the

variable

name

is

the

first

two

characters of the name. For integer variables, the high


order bit (bit 7) of both the first and second characters of
the name are set. For string variables, the high order bit
of the second character is set.
For

example:

Variable name
:
Stored as (hex):

41

AB
42

Cl

AB%
C2

41

AB$
C2

The variable table is the place in memory where all simple


variables are stored. The variable table starts immediately
following the BASIC program.
A pointer located at S2D/2E
(45/46 in decimal) indicates the start of the variable
table.

For example, if you make the following


variable table looks like this:
A

10.3

B%

-23

C$

"Commodore

With

the

002D
0803
080A

03
41
C2

08
00
80

0810

43

80

24
E9
F4

CC CC
00 00
9F 00

6.2 Using Variables

the

64"

monitor you can now look at

84
FF
0C

assignments,

the memory content:

variable table starts at $0803


CD var. A, floating point value 10.3
00 var. B%,integer value -23
00 var. C$,length 12, address $9FF4

in your Program

How can the variables or terms be passed from BASIC to a


machine language program? There is a convenient routine in
the BASIC interpreter that lets you do this. It evaluates
any term in a BASIC expression.
The
routine
called
FRMEVL (formula evaluation)
and
is
located at $AD9E. Routine FRMEVL evaluates numeric as well
as string parameters.
When FRMEVL is called, it sets the type flag
(located at
$0E,
decimal
14).
If
the type
flag
is
$00
then
the
expression that was evaluated was numeric. If the type flag
is $FF, then the expression that was evaluated was a string.

If the expression is numeric,


then the result of the
evalution is stored in the floating point accumulator 1
(FAC).
The
FAC
is
located at memory location
$61-$65

99

(decimal 97-101).
There is also a second floating point
accumulator called ARG, that is used for for arithmetic
operations such as additions.
ARG is located in memory at
$69-$6D (decimal 105-109).
The result after calling
routines such as addition is always found in FAC.
Also when
calling functions, the argument is transferred to FAC and
the

result placed

there.

If the expression is a string, then a pointer at $64-$65


(decimal 100-101) to a string descriptor is set. The string
descriptor contains the length and the address of the
evaluated string.
By calling the routine at $B475 you can
transfer the string length into the accumulator and the
address into the X-(low byte) and into the Y-(high byte)
register.

You

might

place

want

using

to keep

floating

in mind

point

that all

numbers.

If

arithmetic
any

takes

operands

are

integer numbers,
these are first changed into the floating
point format, the operations are carried out in floating
point format, and finally the results are converted back to
integer

format.

Now let's look at some useful routines


interpreter that execute arithmetic tasks.
ADDRESS

FUNCTION

$B853
$B86A

minus
plus

FAC = ARG - FAC


FAC = ARG + FAC

SBA28
$BB12

multiplication
division

FAC = ARG * FAC


FAC = ARG / FAC

$BF7B

exponentiation

FAC =

ARG to

the

of

the

power

of

BASIC

FAC

The addresses of further routines as well as the memory map


of zero-page and the operating system are found at the end
of

6.3

this

chapter.

GET more

6.3.1

out

of

How to Extend

your BASIC

BASIC?

Let's say that you want to tie a machine language routine


into BASIC. First find the part of the interpreter that
examines a
BASIC statement and then executes it.
Here is
that excerpt from the POM listing:

A7E1 6C 08 03
A7E4 20 73 00
A7E7 20 A7 ED
A7EA 4C AE A7

JMP ($0308)
JSR $0073
JSR $A7ED
JMP $A7AE

;
;
;
;

normally points on $A7E4


get next char, from BASIC-text
executes statement
back to interpreter loop

100

We can easily insert our own routine by changing the vector


that normally resides at $308/$309. This vector normally

points to $A7E4,

machine
One

language

common

way

but we can chnage

it to point to our own

routine.
of

extending

BASIC

is

to

prefix

the

new

commands with a special character, such as an exclamation


mark.
So we can extend BASIC with our own version of a
PRINT command
100

like

this:

iPRINT

Our routine first checks for an exclaimation point.


If
found, you can branch to your own routine to handle a new
PRINT command;
otherwise the normal PRINT command is
performed.
A program excerpt could look like this:

DECODE

JSR

$0073

CHRGET,

is

FOUND

yes-we

JMP

$A7E7

JSR

COMMAND

;
;

no-BASIC handles it
execute our own command

JMP

$A7AE

back

CMP

BEQ
FOUND

next

character

it our special
handle

to

character?

it

interpreter

loop

The pointer in $0308/$0309 has to be set to point to the


address of DECODE in the above example when the initializing
the BASIC extensions.
If you want to implement several

commands, you can build in a routine to differentiate the


command words that select the various new commands. In the

following sections, you will find some


implementation of your own routines.

suggestions

for

the

6.3.2 HARDCOPY - RENEW - PRINT USING


Example 1 -

Hardcopy Function to 1515 or 1525E printer

This hardcopy command copies


the BASIC text screen content
to a printer (device number 4) and can be called directly
with SYS 9*4096.

9000
9002
9004
9006
9008
900A
900C
900E
9010
9012

A9

04

LDA

85

BA

STA

FA

A9
85
A9
A0

7E

LDA

#126

B8

STA

LF

00

LDA

85
84
85
85

HARDCOPY

FUNCTION

device

;
;
;
;

logical
address
address
remeber

;
;

no file name
secondary address

#4

04

LDY

#0
#4

71

STA

TEMP

72
B7

STY

TEMP+1

STA

FNLEN

B9

STA

SA

101

number

of

printer

file number
low of screen
high of screen
as pointer

zero

20

CO

9017
9019

A6
20

B8

901C
901E
9020
9023
9026
9028
902A
902C

A2 19
A9 OD
20 D2
20 El
F0 2E
AO 00
Bl 71
85 67
29 3F
06 67
24 67
10 02
09 80
70 02
09 40

9014

902E
9030
9032
9034
9036
9038
903A
903C
903F

C9

JSR

OPEN

LDX

LF

FF

JSR

CKOUT

LOOP

LDX #25
LDA #13

FF

JSR

BSOUT

JSR

STOP

BEQ

EXIT

FF

FF

LOOP

E6

904E

CA

904F
9051
9053
9056

;
;
;
;

new line
to printer
ask stop key
pressed, the

LDY #0
LDA (TEMP), Y;get
STA

STORE

AND

#$3F

ASL

STORE

BIT

STORE

end

character

from

code

screen

screen

and

line

;
;

yes, set pointer


on next line

all

lines put out yet?

new

line

output

close

BPL *+4

change

to ASCII

code

ORA #$80

BVS *+4
ORA #$40
JSR

20 D2 FF
C8
9040 CO 28
9042 DO E6
9044 98
9045 18
9046 65 71
9048 85 71
904A 90 02
904C

; open printer file


; logical file number of printer
; printer as output device
; number of screen lines

BSOUT

INY

CPY
BNE

#40
LOOP

CLC

TEMP

STA

TEMP

BCC *+4
INC TEMP+1

72

DEX

BNE

CD

finished?

LOOP

DO
A9 OD
20 D2
20 CC

FF
FF

JSR
EXIT JSR

BSOUT
CLRCH

9059 A2
905B 4C

7E
C3

FF

LDX
JMP

#126
CLOSE

Example

LDA #13

to printer

TYA

ADC

send

back

on

screen

print-data

and

done

RE-NEW

The following program can be very useful if you accidentally


typed NEW.
The program finds the end of the program ard
sets the BASIC-pointers back on the previous value. It will
work only if no new program lines have been entered and if
nor new variables have been used. The start address here is
12*4096+15*256.

CFOO
CF02
CF04
CF06

A5
A4
85
84

2B
2C
22
23

RE-NEW

FUNCTION

; GETS BACK
LDA PRGSTRT

CLEARED PROGRAM
; BASIC program-start

LDY PRGSTRT +1
STA TEMP
;
STY TEMP +1

102

save

as

pointer

CF08 AO
CFOA C8

03

LDY
ZERO

#3

INY

CFOB

Bl

22

LDA

(TEMP),Y

CFOD

DO

FB

BNE

ZERO

CFOF
CF1O
CF11
CF12
CF14
CF16
CF18
CF1A
CF1C
CF1D
CF1F

C8
98
18
65
AO
91
A5
69
C8
91
88

CF20
CF22

A2
E6

03
22

CF24
CF26

DO
E6

BNE *+4

CF28

Bl

02
23
22

CF2A

DO

F4

BNE

CF2C CA
CF2D DO
CF2F A5
CF31 69
CF33 85
CF35 A5
CF37
CF39
CF3B

69
85
4C

;
;

Looks
(zero

for end
byte)

of

first

line

INY
TYA

CLC

22

TEMP
; add offset
LDY #0
STA (PRGSTRT), Y; save as pointer

ADC

00
2B
23

LDA TEMP+1

00

ADC

#0

on

next

line

now

;
;

program end equal


look for three zero-bytes

set

CLR and

INY

STA

2B

(PRGSTRT), Y

DEY

AGAIN
TDREIO

LDX

#3

INC

TEMP

INC TEMP+1
LDA (TEMP),Y

contains

zero

AGAIN

DEX

F3

BNE

TDREIO

22

LDA

TEMP

02

ADC

#2

2D
23

STA

PRGEND

00
2E

ADC #0
STA PRGEND+1

63

Example 3 -

LDA TEMP+1

A6

JMP

CLR

pointer

on program-end

ready.

PRINT USING

A very useful routine is the formatted output of numbers,


often called PRINT USING.
This routine works as follows:
(see address $C900-$C90C): first a numeric term is placed
into the floating point accumulator; then it is changed into
its ASCII string representation; next the formatting is
carried out using the ASCII string;
and finally the
formatted string is output.
To use

SYS

the

routine,

you

use

the

following

call:

(AD),X

Here AD is the start address of the print using routine and


X the variable or numeric term to be printed. The parameters
for the term are set with POKEs:
POKE 51612,
POKE 51613,
POKE 51614,
POKE 51615,

X
0 = whole number, 1 = number with decimal-point
L
0-10, complete length - 1
N
number of digits after the decimal point
ASC(" ") fill-character before the number

103

POKE 51549,

ASC("

")

leading

character before

the

number

The default values are: decimal number, length 10 (9+1), 2


decimal digits, blank character as leading character and
filler.

SYS(51456)r100

leads

to

the

following

printout:

100.00

With

POKE

51613,3

the output of

POKE

the example

51615,ASC("*")
above

POKE

looks

like

PRINT

USING

51549ASC("$")

this:

**$100.000

C900

20

8A AD

JSR

FRMNUM

C903

20

BB

BD

JSR

ASCII

C905

20

OD

C9

JSR

USING

C909

20

IE

AB

JSR

OUT

C90C

60

C90D A9
C90F 20

RTS

45
8E

USING

JSR

CHECK

C912 BO 59
C914 AD 9C C9

BCS

SETPTR

C917
C919

AD

59
02

C91C
C91E

DO
AC

OB
9D

C921

A9

30

C9 23 99
C9 26 88
C9 27 DO
C929 A9
C92B 20
C92E A8
C92F 90
C931 AO
C933 A9
C935 20
C9 38 98
C939 9D
C9 3C A9
C93E 20
C941 AC
C944 E8
C945 88
C946 DO
C948 EC
C94B BO
C94D AC
C950 A9
C952 99

02

LDA DECINT

01

C9

numeric
to

term

change

ASCII

i
;
;
;

beginning at $100
out new routine
string output
return to caller

checks

LDA #fE

C9

FO

get
;

BEQ

INTEGER

LDA

$102

BNE

LI

LDY

LENGTH

#'0
STA $102,Y

flag

on

exp.format

for dec/integer

complete

length -

LDA

01

L2

fill

buffer w/

decimal

zeros

DEY
BNE

FA

LI

2E

8E

C9

L2

LDA

JSR

CHECK

TAY

02

BCC

30

LDY

#'0

00
8E

LDA

C9

#0
CHECK

00

01

JSR
TYA

2E

8E
9E

STA

$100,X

LDA

#'.

C9

JSR

CHECK

C9

LDY

DECLEN

L3

INX
DEY

FC

9D C9
20

9D

C9

00
01

01

L8

BNE

L3

CPX

LENGTH

BCS

SETPTR

LDY

LENGTH

LDA

#0
$101,Y

STA

104

of

digits

C955
C958

BD

C9

00
20

C95A DO
C95C A9
C95E 99
C961 CA

02
20

C962
C964

06
9F

10
AD

C967
C968

88
10
C96A 88
C96B 10
C96D A9
C96F AO
C971 60
C972 A9
C974 20
C977 90
C979 8A
C97A A8
C97B AD

00

01

01

L6

L5

C9

EO
DO
18
60
01
09

C99E
C99F

02
20

C9A0

6.3.3

DD

FO
E8

#'

BNE

L5

LDA

#'
$100,Y

STA

leading

set

char,

blank

BPL

L4

LDA

FILLER

DEY

F4

BPL

L4
E8
00
01

SETPTR

00

INTEGER

L5

DEY

LDA

L6
#0

LDY

#1

BPL

pointer

on

buffer

RTS

8E

C9

F4

02
09
2E

LDA #0
JSR

CHECK

BCC
TXA

SETPTR

TAY

01

LDA

C9

$102

BEQ

L7

LDA

#'.

JSR

CHECK
L7

BCC
TXA
TAY

L7

C98A AA
C98B CA

10
A2

$100fX

DEX

C97E FO
C980 A9
C982 20 8E
C985 90 02
C987 8A
C988 A8
C989 98

C98C
C98E
C990
C993
C995
C996
C998
C99A
C99B
C99C
C99D

LDA
CMP

TYA

TAX
DEX
BA

00
00
06

BPL

01

CHECK
L9

L8

LDX

#0

CMP

$100,X

BEQ

L10

I NX

OC

CPX

F6

BNE

#12
L9

CLC

L10

RTS

DECINT
LENGTH

BYT

1
9

BYT

;decimal
;length 9

DECLEN

BYT

FILLER

BYT

LEADING

EQU

L5-1

;# of decimal digits
; fill character
;leading character

Self-developed mathematical routines

If we have the need for mathematical routines,

ones

that the

interpreter doesn't offer, quite often it is worthwhile to


write a subprogram in machine language yourself.
For
functions with one argument, the USR function would be best.

105

How does the USR function work?

The USR function,

just

like

all other function-calls of the interpreter, can serve like


the SIN function in terms for the calculation of variables
or it can be in a PRINT statement. When calling the USR
function, you must place the starting address of the routine
in memory locations $311-$312 (decimal 785-786). You can
POKE these locations with the address of your routine.
When calling the USR function, the value of the argument (it

can be any complicated term) is passed


in floating point
accumulator 1.
Now the function can be calculated in your
machine language routine.
You place the result of the
function back into the FAC issue an RTS instruction to
transfer

Now

control

let's

look

and

at

the

some

value

back

examples

of

to

BASIC.

how

to write your own

functions.

6.3.4

SQR,

SUM,

and PROD Functions

First is a routine for calculating a square root.


Though
the BASIC interpreter already provides such a routine, this
one is faster and more precise. As a starting point, we take
the
argument
and
halve
the
exponent
which
already
constitutes a good estimation of the square root value.
The
algorithm is
x(n+l) = (x(n)+a/x(n)) / 2, with 'a1 being the
argument and 'x(n)'
and x(n+l)'
being the old and
new
estimate-value.
Through experimenting it becomes clear that
after

iterations

the

SIGN

;check

BEQ

END

20

2B

C803

F0

34

C805
C807

10
4C

48

B2

C80A

20

C7

BB

C80D
C80F

A5
38

61

C810

E9

81

C812

08

PHP

C813
C814

CLC

C915

4A
18
69

C817

28

03
OK

OK
ILL

JSR

FACA4

;transfer

LDA

EXP

FAC

to

SBC

#$81

LSR A

01

ADC

;normalize
;halve

exponent

exponent

#1

PLP

BCC
ADC

SI
#$7F

C81C

STA

EXP

C81E

A9

04

LDA

#4

C820
C8 22
C825

85
20

67
CA

STA

COUNT

A9

5C
00

61

A9

OF
57

A0

00

SI

BB

BB

ITER JSR

FACA3

LDA

#$5C

;restore

;4

to

LDY

#$00

;pointer

JSR

DIV

;divide

LDA

#$57
#$00

;pointer

LDY

106

exponent

iterations

;FAC

accu#3
on accu#4
by FAC

on

quantity'

accu#4

SEC

02

A0
20

signs

BPL

7F

C8 27

anymore.

JMP

90

C829
C82C
C82E

change

;value=0, ready
?positive, then ok
;negative, 'illegal

69
85

C818
C81A

doesn't

JSR

C800

BC

result

accu#3

C830 20 67 B8

C833 C6 61
C835 C6 67
C837 DO E9
C839

60

Before

END

calling

JSR PLUS

;add to FAC

RTS

;ready

DEC EXP
;FAC/2(exponent - 1)
DEC COUNT ;lower counter
BNE ITER
;another iteration

this

USR

function

we

have

to

tell

the

interpreter first where our USR function starts.


For thisf
the low-byte of the address is poked to $311 (decimal 785)
and the high-byte is poked to $312 (786).
For our function
this

would

look

POKE

785,0

like this:

POKE

786,

12*16+8

Now to call the routine you can use a statement such as:
PRINT USR(A). if you compare the execution time this routine
with built in the SQR routine of the interpreter, it takes

just 12 milliseconds which is about 4 times as fast as SQR

which take about 52 milliseconds.

Now let's look at a little more complicated example. Often


you're confronted with the task of adding up arrays of
numbers, for example if you have to determine the mean or
any statistical calculations.
Let's assume that the data is

available
10

in an array (dimensioned

variable).

DIM A(100)

100 S = 0:REM CALCULATION OR READ IN OF DATA


110 FOR I = 0 TO 1000 : S = S + A(I) : NEXT
120

PRINT

If we substitute a USR function for BASIC lines 100 and 110.

we get
100

Here

the

S =

statement:

USR(A)

parameter A stands

later

on,

the

for

product

of

the array name.

the

array

calculated by changing two machine commands.

033C 20 8D AD

;ptr to array-list.

STA TEMP+1

;running pointer

CPX ARREND

;end of array listing?

86

5F

0347 C5
0349 DO

32
04

CMP ARREND+1
BNE SI

034B E4

31

034D F0 ID
034F A0 00
0351 Bl 5F
0353

C8

0354 C5
0356 DO

45
06

LDX ARRTAB

SI

be

LDA ARRTAB+1

0343

0345 85 60

see

;variable numeric?

2F

S3

can

JSR NUMTEST

033F A6

0341 A5 30

As we will

elements

STX TEMP

BEQ NOTFOUND
LDY #0
LDA (TEMP),Y
INY

CMP VARNAM
BNE S2

107

;first

letter of name

;comp. w/searched name


;no, check next array

035C

A5
Dl
F0

035E
035F

C8
Bl

0361
0362
0364

18

0358
035A

65

46

LDA VARNAM+1

5F

CMP

(TEMP),Y

;compare

BEQ

FOUND

?found

17
S2

(TEMP)fY

60
D7

ADC

TEMP+1

BCC

S3

LDX
STX

#<TAB
$22

LDA

#>TAB

JMP

ERROUT

A9

03
45

0375

C8
Bl
18
65
85
C8
Bl
65
85
C8
Bl
20
85
84
24
30
20

037D

037E
0380

0382
0384
0385
0387
038A
038C
038E
0390
0392
0395 18
0396 90
0398 20
039B 18
039C A5
039E 69
03A0 85
03A2 90
03A4 E6
03A6 A4
0 3A8 C5
03AE 90
03B0 60
03B1 20
03B4 20
03B7 18
03B8 A5
03BA 69
03BC 85
03BE 90
03C0 E6
03C2 C5

offset

of

next

array

INY
LDA

E2
22

0378
0379
037B

;+

5F

A2
86

4C

TEMP

TAX

036C
036E
0370
0372
0376

ADC

AA

0365 C8
0366 Bl
0368 65
036A 90

(TEMP),Y

CLC
5F

letter

INY
LDA

5F

;second

NOTFOUND

A4
FOUND

to

;;output

error

of

message

error message

INY
LDA

5F

j;ptr.

(TEMP),Y

CLC
5F

ADC

TEMP

24

PTA

STORE

INY

5F

LDA

(TEMP)fY

60

ADC

TEMP+1

25

STA

STORE+1

INY

5F
96

Bl

LDA

(TEMP),Y

JSR

SETARR

;number of elements
;ptr. 1st array elem.

5F

STA

TEMP

60

STY

TEMP+1

;pointer

OE
IF

BIT

INTFLG

?check

BMI

INTEGER

JSR

MEMAC1

;element

BCC

LOOP

JSR

MEMPLUS

;jump in loop
;variable plus

A2

BB

to

temp

integer

in

flag

FAC

CLC

04
67

B8

S5

FAC

CLC
5F

LDA

TEMP

05

ADC

#5

5F

STA

TEMP

02

BCC

60

INC

S4
TEMP+1

LOOP

60

S4

24
E8
D5

OC

03
BC

LDY

TEMP+1

CMP

STORE

BCC

S5

;ptr

to

next

element

;end

of

array?

READY

RTS

INTEGER
S6

JSR

INTAKK

;yesf

ready
;integer variable

JSR

A1TOA2

;FAC

to

to ARG

CLC
5F
02

ADC

#2

5F

STA

TEMP

02
60

BCC

S7

INC

TEMP+1

CMP

STORE

24

LDA

S7

TEMP

108

;ptr

to

;end

next

of

array

array

elem.

range?

F/

03C4
0 3C6

90
A5

06
60

BCC
LDA

03C8
03CA
03CC

C5
BO
20

25
E4
D5 03
6F B8
B4 03
00
5F

CMP
BCS
JSR

03CF

20

03D2 4C
03D5 A0
03D7 Bl
03D9 AA
03DA

C8

03DB
03DD
03DE
03DF
0 3E2
03E5
03F0

Bl
A8
8A
4C
41
41
C4

The

STORE+1
READY
INTAKK
;integer var
JSR ACPLUS
;FAC +ARG
JMP S6
LDY #0
LDA (TEMP)rY
TAX

S8

INTAKK

to

FAC

INY

5F

91
52
59

B3
52
20

program

TAB
4F

can

integer arrays.

ARRAY NOT

Since

S8
TEMP+1

the

FOUND

logic

54

20

LDA (TEMP),Y
TAY
TXA
JMP INTFLOAT
;to floating
ASC fARRAY NOT FOUN1
46 50 55 4F
PYT fD'+$80

process

arrays

with

real

If an array can't be

is

numbers

found,

comma

as

well

output.

for calculating

the array elements

is the

same, you can obtain a product function by substituting


calls for addition with the multiplication routine.

this at $0398
2B

BA.

In

order

this

time,

to

we

substitute 20

use

our

have

as

the message

28

BA and

routine,

which

to poke

POKE 785,3*16+12

the

start

at $03CF

is

in

address

the

the
For

substitute 20

tape

again:

buffer

POKE 786,3

For a comparison, calculate


and then with our routine -

the sum with the BASIC


the time difference is

loop once
immense!

6.3.5 Changing to Different Data Formats


If more than one parameter is to be transferred, the USR
function is not suitable anymore.
Here an extended variant
of the SYS command is most suitable.
Normally the SYS
command only carries out the machine program starting from
this address and transfers no further parameters.
The above
routine FRMEVL evaluates the parameter following the SYSxxx
and transfers the value to the floating point accumulator.
If separated by a comma or parenthesis,
any number of
parameters can be transferred.
For the formula evaluation
routine there are several more routine addresses and sub
routines available which check, for instance, for a comma or
evaluate parameters in parenthesis.
The type of variable

or

numeric

string

can

be

checked,

109

too.

For

numeric

variables, there is an additional range-check possible.


The
most important routines are summarized below.
For further
details, please check chapter 6.4 for the ROM listings.

ADDRESS

DESCRIPTION

AD8A

evaluate argument and check on numeric

AD8D
AD8F
AD9E

check on numeric
check on string
argument evaluation,

AEFA

checks

on parenthesis

B79E

checks

on

AEF1
AEF7

any

term

evaluate argument in parenthesis


checks on parenthesis closed

0073

gets

In using

these

next

comma

character

routines,

open

from BASIC

if a

value

text

is out of

range

an error

message ILLEGAL QUANTITY is issued. If a variable type does


not coincide with the intended type an error message TYPE
MISMATCH

You

is

issued.

can convert

to different

formats using the following

routines:
ADDRESS

DESCRIPTION

B1BF

changes

BCF3
BDDD

changes digit string to floating-comma


changes FAC in digit-string

B395
B3A2
BC9B

FAC

to

integer

changes 16-bit integer-number in A/X to running-comma


changes byte in Y to floating comma
changes FAC to 16-bit number

Now let's look at an example of a SYS routine with parameter

passing. Say you want to output from BASIC to a certain


position on the screen. Here's an easier way of doing this
with

The

a short

call

SYS

has

PR,

machine

the

language

following

column,line,

routine.

syntax:

printlist

Here PR is the starting address of the routine, line and


column are the cursor positions at which the variables or
terms

of

the

printlist

are

to

cooo

20

FD

AE

JSR

CKCOM

C003

20
8A
48

9E

B7

JSR

GETBYT

C006

C007

be

output.

;
;

checks comma
gets column value

remember

to X

TXA
PHA

110

column-number

C008

20

FD AE

JSR

CKCOM

checks

C00B
COOE
COOF

20
68
A8

9E

JSR

GETBYT

gets

column

C010

18

C011
CO 14

20
20

FO FF
FD AE

JSR

CURSOR

sets

JSR

CKCOM

checks

C017

4C

A4

JMP

PRINT

B7

on

comma

line

value

PLA
TAY

value

to

CLC

AA

cursor

on comma
continue with PRINT

command

If you assign start address $C000 of the routine to the


variable PR at the beginning of the program, you can output
the text "example" with the following command, starting with
the 24th column in line 20:

10

PR =

100

SYS

12*4096
PRf24,20f"EXAMPLE"

6.4 Routines Of The BASIC Interpreter


The BASIC interpreter of the Commodore 64 is almost
identical to VIC-20 interpreter.
The major difference is in
their positions in memory. The conversion of an address for
the Commodore 64 into the
20 happens as follows:

At

addresses

from

$A000

corresponding

address

to $BFFF you simply add

for

the VIC-

$2000,

$A860

becomes the address $C860 in the VIC-20.


At addresses from
$E000 to $E73A,
3 is subtracted from the Commodore 64
address.
$E30E becomes address $E30B at the VIC-20.
Appendix A
Commodore

ADDRESS

A000
A002
A004
A00C
A052
A080
A09E

contains

64

BASIC

the

and

full

kernal

disassembled

listing

of

the

routines.

DESCRIPTION

start vector
NMI vector
'cbmbasic1
addresses of the BASIC commands minus 1
addresses of the BASIC functions
hierarchy-codes and addresses of the BASIC
list of BASIC command words

A19E

BASIC

A364
A38A
A3B8
A3FB
A408
A435

messages of the BASIC interpreter


stack search-routine for FOR-NEXT and GOSUB
block-shifting routine
checks on space in stack
makes space in memory
output of 'out of memory1

error-messages

A437

output

A469

break

of error message
vector

111

operators

A474

ready

A480

input waiting-loop

vector

A49C

clear and

A533
A560
A571
A579

tie BASIC program-lines anew


gets a line into input-buffer
output of 'string too long1
change of a line into interpreter-code

A642
A6 5E
A68E

BASIC-command NEW
BASIC-command CLR
set program-pointer

A69C

A717

BASIC-command

change

LIST

A742

BASIC-command

FOP

A81D

BASIC-command

RESTORE

A82F
A831
A857
A871
A883
A8A0
A8F8
A8F8
A906

BASIC-command STOP
BASIC-command END
BASIC-comraand CONTINUED
BASIC-command RUN
BASIC-command GOSUB
BASIC-command GOTO
BASIC-command RETURN
BASIC-command DATA
looks for next statement

A613

A7AE
A7ED
A8 2C

inserting program lines

look for start address of a BASIC line

to

BASIC

interpreter-code

to

interpreter loop, carries


carries out BASIC-command
interrupts program

next

command

word

out BASIC commands

at pressed

stop-key

A909

looks

A928
A93B
A94B

BASIC-command IF
BASIC-command REM
BASIC-command ON

A9A5

BASIC-command

AA80
AA86

BASIC-command PRINT#
BASIC-command CMD

AAAO

BASIC-command

ABIE
AB3E
AB4D

output string
output empty-character( or
error handling for INPUT

AB7B
ABA5
ABBF
AC06

BASIC-command

GET

BASIC-command
BASIC-command
BASIC-command

INPUT#
INPUT

ACFC

'?extra

AD1D

BASIC-command

AD8A
AD8D
AD8F
AD99

FRMNUM gets term and checks


checks on numeric
checks on string
output of 'type mismatch'

AD9E
AE83
AEA8
AED4

FRMEVL gets and evaluates any term


get arithmetic term
floating-point constant for pi
BASIC-command NOT

AEF1
AEF7

gets term
checks on

A96B

for

start

line

looks for address of a BASIC

line

LET

PRINT

cursor

right)

READ

ignored1

and

f?redo

from

start1

NEXT

on

in parenthesis
'parenthesis closed1

112

numeric

AEFA
AEFD
AEFF
AF08
AF28

checks on 'parenthesis open1


checks on 'comma1
checks on characters in accumulator
output of 'syntax error1
gets variable

AFE6

BASIC-command

AFE9
BO 16
B081

BASIC-command AND
comparison-operations
BASIC-command DIM

B113
B194
B1A5
B1AA
B245
B248
B34C
B37D
B39E
B3A6
B3AB
B3AE

checks for letter


calculates pointer to first array-element
floating-point constant -32768
change FAC to integer
output of 'bad subscript'
output of 'illegal quantity'
calculates array-size
BASIC-function FPE
BASIC-function POS
check on direct-mode
output of 'illegal direct'
output of 'undef'd function'

B3B3
B3E1
B3F4

BASIC-command DEF
check FN-syntax

B465
B475
B487
B526
B63D
B6A3
B6EC
B700
B72C
B737
B77C
B782
B78B
B79B
B7AD
B7EB
B7F7
B80D
B824
B82D

OR

BASIC-function FN
BASIC-function STR$
string administration,
establish string

garbage collection, remove unused


string connection '+'
string administration FRESTR
BASIC-function CHR$
BASIC-function LEFT$

pointer

on

string

strings

BASIC-function RIGHTS
BASIC-function MID$
BASIC-function LEN
get string parameter

BASIC-function ASC
gets byte-term (0 to 255)
BASIC-function VAL
gets address (0 to 65535) and byte-value (0 to 255)
change FAC to address-format (range 0 to 65535)
BASIC-function PEEK
BASIC-command POKE
BASIC-command WAIT

B849

FAC

B850
B853
B867

minus
minus
plus

B86A
B97E
B9BC
B9EA

plus
FAC = ARG + FAC
output 'overflow'
floating point constant
BASIC-function LOG

BA28
BA2B
BA8C

calculate

FAC +0.5

FAC = constant (A/Y)


FAC = ARG - FAC
FAC = constant (A/Y)

multiplication
multiplication
ARG = constant

for

- FAC

- FAC

LOG

FAC = constant (A/Y)


FAC = ARG * FAC
(A/Y)

113

FAC

BAE2

FAC = FAC *

BBOF

FAC = constant

BAF9
BAFE

10

floating-point constant 10
FAC = FAC/10

(A/Y)

/ FAC

BB12
BB8A
BBA2

FAC = ARG/FAC
output of 'division by
FAC = constant (A/Y)

BBC4
BBCA
BBDO

accu#4 =
accu#3 =
variable

BBFC
BCOC
BC1B

FAC = ARG
ARG = FAC
round FAC

BC2B
BC39
BC58

get signs of FAC


BASIC-function SGN
BASIC-function ABS

BCCC

BASIC-function

BDC2

output

BDDD
BF11
BF16
BF71

change FAC to ASCII-format


floating-point constant 0.5
binary numbers for change of
BASIC-function SQR

BFBF
BFED

floating point constant


BASIC-function EXP

E097
E107

BASIC-function RND
output of 'break1

E10C
E112

BSOUT output of
BASIN receive a

E124
E156
E165
El68
E1BE
E1C7

GETIN get a character


BASIC-comand SYS
BASIC-coromand SAVE
BASIC-command VERIFY
BASIC-command LOAD
BASIC-command OPEN
BASIC-command CLOSE

E1D4

get parameters

E219
E264

get parameter for OPEN


BASIC-function COS

E26B
E2B4

BASIC-function SIN
BASIC-function TAN

E30E
E33E

BASIC-function ATN
floating-point constants

BC5B
BC9B
BCF3
BDB3

BDCD

BF78
BF7B

E043
E059
E08D

E118
E11E
E12A

E2E0

zero1

FAC
FAC
= FAC

compare constant (A/Y) with


change from FAC to integer

FAC

INT

change ASCII to floating-point


floating-point constants for floating-point
of

line-number

output of positive

at

error

message

integer-number
FAC

(0 to 65535)

to ASCII

FAC = constant (A/Y) to the power of


FAC = ARG to the power of FAC
for

FAC

EXP

series 1 polynomial calculation


series 2 polynomial calculation
floating point constant for RND

a character
character

CKOUT establish output-device


CHKIN establish input-device

floating-point

for LOAD and

constants

114

SAVE

for SIN and COS


for

ATN

to ASC:

E37B
E394
E3A2
E3BA
E3BF

BASIC

NMI jump-in
BASIC cold-start
copy of the CHRGET-routine
start-value for the RND-function
initialize RAM for BASIC

E447

table

E453 .

load

of

BASIC-vectors

BASIC-vectors

115

6.5

Low

Memory Usage

Hex-address

Decimal

00
01

Description
data-direction register for processor
processor register
unused
vector floating point to fixed
vector fixed to floating point
search character

08

0
1
2
3-4
5-6
7
8

09

memory

0A

10

load=0, verify=lf interpreter-flag


pointer input-buffer, # of dimensions

02
03
05
07

04
06

OB

11

OC
0D

12
13
14
15
16

0E
OF
10
11

12
13

14-15
16
17-18
19-21
22-25
26-2A
2B-2C
2D-2E

2F-30
31-32

33-34
35-36
37-38

command

DIM

type-flag $00=numeric, $FF = string


flag for integer=$80, floating = $00
high-comma flag at LIST
INPUT $00,

flag

for

TAN

19

active I/O-device
integer-address, i.e. line number
pointer to string stack
pointer to string used last
string stack
pointer for various uses
register for func eval. and arith.
pointer BASIC program-start
pointer to start of the variables
pointer to start of the arrays
pointer to end of the arrays
pointer to begin of the strings
aid-pointer for strings
pointer to BASIC-RAM end
present BASIC-linenumber
previous BASIC-linenumber
pointer to next BASIC stmt for CONT
present linenumber for DATA
pointer to next DATA-element
pointer to origin of input
variable name
variable address
variable-pointer for FOR/NEXT
intermediate memory for program ptr
mask for comparison operations
pointer for FN
string descriptor
constant $4C
JMP for functions
jump vector for functions
register for arithmetic, accum#3
register for arithmetic, accum#4
floating-point accum#l, FAC
sign of FAC
counter for polynomial evaluation
round-off byte for FAC

20-21
22
23-24
25-33
34-37
38-42
43-44
45-46
47-48
49-50
51-52
53-54
55-56

61-62

3F-40

63-64
65-66
67-68
69-70
71-72

49-4A
4B-4C

73-74

4D
4E-4F

77

5C-60

TAB

for

3D-3E

61-65
66
67
68

at

for

57-58

57-5B

for

column

flag

59-60

55-56

for

flag

3B-3C

50-53
54

flag

flag

17
18

39-3A

41-42
43-44
45-46
47-48

quote

75-76

78-79
80-83
84
85-86
87-91
92-96
97-101
102
103
104

116

FN

GET $40,

READ $98

port

Hexaddresis

Decimal

69-6D

Description

105-109
110
111
112
113-114

floating-point accum#2,ARG
sign of ARG
comparison of signs of FAC and ARG

6E

6F
70
71-72
73-8A
7A-7B
8B-8F
90

115-138
122-123
139-143

flag

146

time-constant

95

149

96
97
98

150
151
152

99
9A

153
154

9B

155

9C

156

9D

157
158

9F

A6

159
160-162
163
164
165
166

A7-AB

167-171

AC-AD

B2-B3

172-173
174-175
176-177
178-179

A5

AE-AF

B0-B1
B4

180

B5
B6

181

B7
B8

183
184

B9

185
186

BA

BB-BC
BD
BE
BF

CO

C1-C2
C3-C4
C5
C6
C7

182

187-188
189
190
191
192
193-194
195-196
197
198

FAC

word

for

ST

stop-key

for tape

flag for LOAD $00 or VERIFY $01


flag at IEC-output
output-buffer for IEC-bus
receive flag for EOT from tape

intermediate-memory

for register

number of open files


active input-device
active output-device
parity for tape
receive flag for byte
flag direct-mode $80, program
tape-pass 1 check-sum
tape-pass 2 error-correction
time
bit-counter for serial output
counter

for

$00

tape

write counter for tape


pointer in tape buffer
work-memory for tape in-/output
ptr for tape-buffer and scrolling
ptr on program end at LOAD/SAVE

time-constants

for tape-timing

pointer on tape-buffer
bit-counter for tape
next bit for RS
buffer for byte
length

of

logical

file

file

secondary

232
to be

output

name

number

address

device number
pointer to file name
work-memory serial I/O
pass

counter

for

tape

buffer for serial output


flag for tape-drive
start address for I/O
end address for I/O
key pressed last
number of pressed keys
flag for RVS-mode

C9

199
200
201

line end for input


cursor line for input

CA

202

cursor

C8

text

program pointer
last RND-value
status

147
148

for

cassette buffer
char, from BASIC

145

93
94

A0-A2
A3
A4

byte

144

91
92

9E

round-off

pointer for
CHRGET gets

column

117

for

input

Hexaddress

Decimal

Description

CB

203
204
205
206

pressed key, no key = 64


flag for blinking cursor
counter for cursor-blinking

CC
CD
CE

DO
D1-D2

207
208
209-210

D3
D4

211
212

D5
D6

213
214
215

CF

D7

F3-F4

216
217-242
243-244

F5-F6
F7-F8

247-248

F9-FA

249-250

D8
D9-F2

245-246

character

flag
flag

ptr

under

the

to start of

cursor
flag

actual

for

length

screen

MSB of

screen-line

pointer

to

pointer to keyboard decoding table


pointer to RS-232 input buffer
pointer to RS-232 output buffer

buffer

floating

point

memory

0100-01FF

0200-0258

256-511
512-600

processor stack
BASIC input-buffer

0259-0262

601-610

0263-026C

611-620
621-630

table
table
table

of
of
of

641-642

key-board buffer
start of BASIC-RAM

0283-0284

643-644

end

0285

645
646

649
650

028B

028E
028F-0290

651
652
653
654
655-656

0291

657

0292
0293

658

028C
028D

0294

0295-0296
0297

0298
0299-029A

of

high-byte
length of

flag

for

shift

029D

669

video-RAM
key-board

'repeat

flag

pointer

buffer
function1

for

key-board

for

all

keys

decoding

flag

for

shift/Commodore

flag

for

scrolling

RS-232

668

for serial IEC-bus

counter for repeat-speed


counter for repeat-delay
flag for shift and CTRL

665-666

667

flag

present color
color under cursor

RS-232
RS-232

029C

BASIC-RAM

time-out

659
660
661-662
663
664

029B

tape-input

logical file-numbers
device-numbers
secondary address

631-640

0289
028A

to ASCII

for correction at

0277-0280
0281-0282

647

beginnings

color-RAM

256-318

648

line

line

cursor line
various purposes
number of inserts

255-266

0288

screen

cursor

of

00FF-010A

0286
0287

or

screen

column

0100-013E

026D-0276

cursor

for cursor-blinking
for input of keyboard

blocked

control-word
command-word

bit-timing
RS-232

status

number of

data

bits

for RS-232

baud-rate

pointer to
pointer to
pointer to
118

received byte RS-232


input of RS-232
byte RS-232 to be transferred

Hexaddress

Decimal

Description

029E
029F-02A0
0 2A1
02A2
0 2A3
02A4
02A5
02C0-02FE
0300-0301
0302-0303
0304-0305
0306-0307
0308-0309
030A-030B
030C
030D
030E
0310
0311-0312
0314-0315
0316-0317
0318-0319
031A-031B
031C-031D
031E-031F
0320-0321

670

pointer to output on RS-232


memory for IPQ during tape-operation

0322-0323
0324-0325
0326-0327
0328-0329
032A-032B
032C-032D
032E-032F
0330-0331

0332-0333
033C-03FB
0340-037E
0380-03BE
03C0-03FE

671-672
673
674
675

676
677
704-766
768-769
770-771

772-773
774-775
776-777
778-779
780
781
782
784
785-786
788-789
790-791
792-793
794-795
796-797

798-799
800-801
802-803
804-805
806-807
808-809
810-811
812-813
814-815
816-817
818-819
828-1019
832-894

896-958
960-1022

CIA

NMI

flag

CIA 1 timer A
CIA 1 interrupt flag
CIA 1 flag for timer A
screen line
sprite 11
vector for error message
vector for BASIC warm-start
vector for change to interpreter-code
vector for change to clear text (LIST)
get vector for BASIC-command address
evaluate vector for term
accu for SYS-command
X-reg

for
for

Y-reg

SYS-command
SYS-command

$4C JMP-command for USR-function


$B248 USP-vector
$EA31 IRQ-vector
$FE66 BRK-vector
$FE47 NMI-vector
$F34A OPEN-vector
$F291 CLOSE-vector
$F20E CHKIN-vector
$F250 CKOUT-vector
$F333 CLRCH-vector
$F157 INPUT-vector
$F1CA OUTPUT-vector
$F6ED STOP-vector
$F13E GET-vector
$F32F CLALL-vector
$FE66 warm-start vector
$F4A5 LOAD-vector
$F5ED SAVE-vector
tape

buffer

sprite
sprite
sprite

13
14
15

119

CHAPTER 7:

COMMODORE 64 - VIC 20

7.1 Comparison table of the ROM addresses


C64

VIC

Description

E45F

E429

messages of the operating


waits for Commodore key

E4E0

system

E500

E500

E505

E505

constants for RS-232 timing


gets BASIC-address of the CIA or
gets screen format line/column

E50A
E518
E544

E50A
E518

set cursor or get cursor position


screen

E55F

clear

E566

E581

E5A0
E5B4

E5BB

cursor home
initialize video-controller

E5CA

E5E5
E64F

E4EC

E632

E5CF

E684
E6B6

E6B8

E8DA
E8EA

E921
E975

E9C8

EA56

E9FF

EA8D

EA1C
EA24

EAA1
EAB2

E6EA

reset
screen

get character from keyboard buffer


waiting-loop for keyboard input
get

character

checks

for

from

calculate MSB for line


table of color-codes
scroll

EA31

EABF

EB1E

keyboard

EB48

EBDC

EB79

EC46

color

on

on

screen

color-RAM

prompt

key

decoding-tables
checking on control-character

EB81

EC5E

ED21

EC78
ECB9

EDE4

ECE7

EDF3

ECFO

EDFE

LSB-tables

ED09

EE14

send

TALK

EDOC

EE17

send

LISTEN

ED40

EEE4

EDB9

EECO

send
send

UNLISTEN

decoding-tables

constants

load

for video-controller

(cr)

run
of

(cr)'
screen

starts

output of byte on IEC-bus


send secondary address for LISTEN
send secondary address for TALK

EDC7

EECE

EDEF

EEF6

EDFE

EF04

EE13

EF19
EF96

get

a byte

one

millisecond

output

F014

EFA3
F027
FOED

output

in

F086

F14F

GET

of

RS-232

F0A4

F160

FOBD

F174

set timer for IEC


error messages of

F12B

F1E0

put

out

EF4A

starts

checking on shift, CTRL and Commodore


pointer on keyboard decoding tables

EC44

EEBB

screen

screen

EA87

EEB3

the

quote

shift line up
clear screen-line
set character and
calculate pointer
interrupt routine

ED69

the VIA

UNTALK

from the

IEC-bus

delay

RS-232

calculate number of RS-232 data-bits


RS-232

buffer

time-out
the operating

messages

120

system

C64

VIC

Description

F157

F20E

BASIN

get

F1CA

F27A

BSOUT

putout

character

F20E
F250

F2C7
F309

CHKIN
CKOUT

fixing of
fixing of

character

the
the

input-device
output-device

F291

F34A

CLOSE

F30F
F31F
F32F

F3CF
F3DF
F3EF

F34A

F40A

F49E
F5AF

F542
F647

look for logical file number


set file parameter
CLALL closes all I/O-channels
OPEN
LOAD
output 'searching for file name1
output 'loading/verifying1

F5D2

F66A

F5DD

F675

F68F
F69B
F6DD
F6E4

F728
F734
F760
F767

SAVE
output 'saving
UDTIM increase
get time
set time

file name'
running time

F6ED

F770

ask

F6FB
F72C
F76A
F7D0
F7D7
F7EA
F80D
F817

F77E
F7AF
F7E7
F84D
F854
F867
F88A
F894

put out error messages of the operating system


read program header of tape
write header on tape
get start address of the tape buffer
set start and end address of the tape buffer
tape-header look for name
increase tape-buffer pointer
waits for tape-key for reading

F82E
F838

F8AB
F8B7

asks tape-key
waits for tape-key

F841
F84A
F864
F86B
F8BE
F8E1
F92C
FB97
FBA6
FBCD
FCB8
FCCA

F8C0
F8C9
F8EA
F8EA
F92F
F94B
F98E
F8DB
FBEA
FCOB
FCF6
FD08

read block of tape


load program of tape
write tape buffer on tape
write block or program on tape
wait for I/O-end
checks on stop key
read interrupt routine for tape
set bit-counter for serial output
write one bit on tape
write interrupt routine for tape
set IRQ-vector
switch off tape drive

FCD1
FCDB
FCE2
FD02
FD10
FD15
FD30
FD50
FD9B
FDF9
FE00
FE07
FE18

FD11
FDlB
FD22
FD3F
FD4D
FD52
FD6D
FD8D
FD6D
FE49
FE50
FE57
FE66

checks on reaching of end address


increase address pointer
RESET
checks on ROM in $8000 or $A000
ROM-module identification
set or get hardware and I/O-vectors
table of hardware and I/O-vectors
initialize work-memory
table of IRQ-vectors
set parameter for file names
set parameter for active file
get status

set

stop -key

flag

for writing

for messages

121

of

the

operating

system

Description

C64

VIC

FE1C

FE6A

set

FE21

FEF6

FE25

FE73
FE82

set timeout-flag for IEC-bus


set or get RAM-upper limit
set or get RAM-lower limit
NMI-routine
constants for RS 23 2 baud rate
interrupt handler
jump table of the operating-system

FE34

FE43
FEC2
FF48
FF81

FEA9
FF5C
FF72
FF8A

7.2.

status

Changing VIC-20 programs

routines

to the Commodore 64

Although outwardly, the Commodore 64 looks similar to the


VIC-20, the '64 contains much more than its smaller brother.
The
with
high-resolution
color
graphics,
sprites
and
fabulous sound synthesizer - all this makes the Commodore 64
different from the VIC-20.
Nevertheless, we don't want to
do
without VIC-20's
software.
Unfortunately
it
is
net
possible to interchange the plug in cartridges. But there
are enough program listings for you to transfer onto the
Commodore 64.
One
1.

has

to

differentiate

The machine

language

between

two

kinds

of

programs:

programs

With this program the adaption is not really difficult but


yet more complicated than with BASIC programs.
In order to
be able to adapt these programs, you have to refer to the
comparison table in chapter 7.1.
For example, if you come
to a jump-address that points to an address in ROM, you have
to find to find this address in the comparison table of the
Commodore 64 and change it with the address of the VIC-20 in
the program.
Generally it can be said that you can
calculate
the difference
between
the
single
addresses
yourself. For instance, the start-address of the BASIC-GET
routine at the VIC-20 is $CB7B.
At the Commodore 64 it is
exactly $2000 lower - $AB7B.
Starting at $E000, the value 3

has

to

be

subtracted

to

get

the

VIC-20

2.

The

BASIC

from

the

Commodore 64

address

in

order

address.

programs

With
the
BASIC
complicated.
The

programs,
first thing

the
adaption
is
not
that
to mention, of course, is the

different screen format.


Here you have to observe that you
either have to rewrite the screen-format of the VIC-20
program completely or use a return after 22 characters so

that

the

The only
commands.
kinds:

other

characters

don't

slip

into

the

same

line.

things that constitute a problem are the POKE


Here, too, you have to differentiate between two

122

1. POKE-commands into the screen memory


Here you have to change all the addresses.
compare the tables of the character-generator

Please
and the

screen-page.

2.

POKE-commands
machine

7.3
Many

into the operating system

The same procedure that applies


programs

is

used.

to the changing of

the

Changing CBM/PET programs to the Commodore 64


people

haven't

even

noticed

yet

that

there

is

much

similarity between the Commodore 64 and its big


"colleagues".
It is entirely possible to make use of

programs of the legendary PET.

same -

25

lines

of

The screen formats are

40 characters

each.

the

All Commodores of

this category (BASIC 2 and BASIC 3) have one advantage:


their built in BASIC interpreter is fully compatible.
That

means

that you don't have

programs,

unless

they

are

to make

any

changes

POKE commands.

in

the

BASIC-

For POKEs you have to know the corresponding addresses of


PET memory are different from the ones of the Commodore 64.

There is a great amount of literature available for the


PET/CBM devices.
You will find the appropiate books in our
bibliography.

In general one can say:

BASIC and machine language are not

different for these two devices.


The 6510 is fully
compatible with the 6502.
Thus the only changes refer to
the vector addresses to the different routines in the
operating system or the different addresses of the screen
memory

and

the

vectors

of

If you observe

all

this,

these programs

you

can

the

zero-page.

you can use all

the programs of

the

PET/ CBM or VIC-20 devices on your Commodore 64.


All it
takes is a little practice.
And remember: by extending
even

take

advantage

of

the

graphics,

tone, and color of the Commodore 64.


Which PET can offer
you that?
Besides, you have a 64K work-memory available en
the Commodore 64 - enough to make the changed programs even
better!

Have

fun

with

adapting

your

software!

123

CHAPTER 8s

8.1

INPUT-/OUTPUT CONTROL - CIA 6526

General notes

about

the 6526

The complex interface adapter (CIA) 6526 is a new


element of the 65xx family.
It is equipped with:

16 separately programmable

in-output

peripheral

lines

* 8 or 16-bit handshake at input as well as output

* 2 independent, cascadeable 16-bit interval-timer


* 24-hour clock (am/pm) with programmable alarm
* 8-bit shift-register for the serial in-output
You'll

find

the

block-schematic

of

the

CIA

6526

in

Diagram

8-1.

Pin-overlay of

the 40-pin housing:

mass

2-9
10-17

I/O-port A;
I/O-port B;

18
19
20
21

8-bit bidirectional
8-bit bidirectional.
Bits 6 and
programmed to indicate
the
lower course

can

of

be

both

timers.
-PC
(port
control);
exit only;
signals
the
availability of data at port B or at both ports.
TOD (time of day); only 50/60 Hz entrance; triggers
the real-time clock.
+5V; operating voltage
-IRQ (interrupt request); exit only; becomes 0 at the
concurrence of a set bit in ICR with the happening of

24
25

the appropiate event.


P/W (read/write); entrance only; 0= taking over of
data bus, l=output to data bus.
-CS (chip select); entrance only; 0=data bus valid,
l=data bus tri-state (high-ohm).
-FLAG; entrance only; meaning like -PC.
02 (system frequency 2); entrance only; all data-bus

26-33

actions only take place at 02=1.


DB7-DB0(data bus); bi-directional;

22
23

interface

for

the

processor.

34
35-38

-RES(reset); entrance only; 0=setting back the CIA to


original state.
RS3-RS0(register select); entrance only; serves for

39

selecting one of the 16 registers of the CIA; only


valid with -CS=0.
SP(serial
port);
bi-directional;
serves
as

42

entrance/exit of the shift register.


CNT(count);
bi-directional;
entrance/exit of
shift-register frequency or trigger-entrance for
interval-timer.

124

the
the

SP

Pflflr?

DIAGRAM 8-1

125

The

CIA

8.2

Register Usage

REG

REG

PRA (port register A)


access; READ/WRITE
bit 0-7 This register
pins PAO-7
PRB

(port

register

to

the

state

of

corresponds

to

the

state

of

B)

access: READ/WRITE
bit 0-7 This register
pins PBO-7
REG

corresponds

DDRA (data direction register A)


access: READ/WRITE
bit 0-7 These bits determine the data-direction of
the corresponding data-bits of port A. 0=entrance,
l=exit.

REG

DDRB (data direction register B)


access: READ/WRITE
bit 0-7 These bits determine the data-direction of
the corresponding data-bits of port B. 0=entrance,
l=exi'; ,
i

REG

TA

LO

(timer A LO-byte)

access:

READ

bit

This

0-7

the

register

low-byte

access:

of

represents

the

present

state

of

timer A,

WRITE

bit 0-7 Into this register we load the low-byte of


the value from which the timer shall count on zero.
REG

TA

HI

(timer

access:

bit 0-7
of

the

access:

Hi-byte)

READ

This register represents the present state


hi-byte

of

timer

A.

WRITE

bit 0-7
Into this register we load the hi-byte of
the value from which the timer shall count on zero.
REG

REG

REG

TB LO (timer B LO-byte)
access and overlay is the

same

as

in

REG

4.

TB HI (timer B Hi-byte)
access and overlay is the

same

as

in

REG

5.

TOD

10THS

access:

(clock

1/10

sec)

READ

bit 0-3 tenth

seconds of

the

real-time clock

format

bit

4-7

access:

always
WRITE

0
and

CRB

bit

bit 0-3 tenth seconds


bit 4-7 must be 0

in

access:

bit

WRITE

and

CRB

126

7=0

BCD
7=1

format

in BCD

bit 0-3 preselection of


alarm-time in BCD format
bit 4-7 must be 0
REG

TOD

SEC

access:

(clock

the

tenth

seconds

of

the

sec)

READ

bit 0-3 single-seconds of the clock in BCD format


bit 4-6 decimal-seconds of the clock in BCD format
bit 7
always 0
Further

REG

10

types

of

access

TOD MIN

(clock min)

access:

READ

are

analogous

to

REG

8,

bit 0-3 single-minutes of the clock in BCD format


bit 4-6 decimal-minutes of the clock in BCD format
bit 7
always 0
Further
REG

11

TOD

HR

access:

types
(clock

of

access

are

analogous

to

REG

8,

hour)

READ

bit 0-3 single-hours of the clock in BCD format


bit 4
decimal-hours of the clock
bit 5-6 always 0
bit 7
0= am, 1= pm
Further types of access

are

analogous

to REG

8.

REG

12

SDR (serial data register)


access: READ/WRITE
bit 0-7 From this register, the data is pushed out
bit by bit to pin SP or pushed into this register by
pin SP respectively.

REG

13

ICR (interrupt control register)


access: READ (INT DATA)
bit 0
l=lower course timer A
bit 1
l=lower course timer B
bit 2
l=parity of time and chosen alarm-time
bit 3 1=SDR
full/empty, depending
on the
operation

way

of

bit 4
l=signal occured at pin FLAG
bit 5-6 always 0
bit 7
correspondence of at least one bit of INT MASK
and INT DATA occured
ATTENTION: When reading this register, all bits are
cleared!

access:WRITE (INT MASK)


Meaning of the bits as above,

bit

l=every 1-bit

The

others remain untouched.


0=every 1-bit clears

bit.
The others

remain

sets

the

untouched.

127

except bit 7:
corresponding

the

mask-bit.

corresponding

mask-

REG

14

CRA (control register A)


access: READ/WRITE
bit 0
l=timer A start, 0=stop
bit 1
l=lower course of timer A

is

signaled

to pin

PB6.

bit 2
l=each lower course of timer A tilts PB6 into
the respective position,0=each lower course of timer
A creates a Hi-pulse at the PB6 with the length of
one
bit

system-frequency.
3
l=timer A only

value to zero and


counts

from

the

stops

counts

then,

start-value

once

from

the

start-

0=timer A continuosly

to

zero.

bit 4
l = absolute loading of a new start-value into
timer A. This bit functions as strobe. It has to be
set anew at every absolute loading.
bit
5
This
bit
determines
the
source
of
the

time_trigger. l=timer counts increasing CNT-flanks,


0=timer counts system-frequency pulses,
bit 6
1=SP is entrance, 0=SP is exit
bit 7
l=realtime-clock trigger is 50Hz, 0=trigger is
60Hz

REG

15

CRB (control register B)


access: READ/WRITE
bit 0-4
These bits have the same meaning as in REG
14, but related to timer B and pin PB7 bit 5-6
These
bits determine the source of the trigger for timer B.
00=timer counts system-frequencies,
10=timer counts
increasing
CNT-flanks,
01=timer
B
counts
lower
courses of timer A, ll=timer B counts lower courses
of timer A if CNT=1
bit 7
l=set alarm,

8.3

0=set

time.

I/O Ports

Ports A and B each consist of an 8-bit data register (PR)


and an 8-bit data-direction register (DDR).
If a bit is set
in DDR, the corresponding bit in PR functions as an output.
If a bit in DDR =0, the corresponding bit in PR is defined
as
input.
During a READ-access,
the PR represents
the
present state of the corresponding pin (PAO-7,PBO-7), for
the entrance as well as for the exit bits.
Beyond this, PB6
and PB7 can take over exit functions for both timers.

The data-transfer between the CIA and


connected to PA/PB can be achieved by a

the "outside world"


discharge-operation.

For this serve PC and FLAG. PC becomes 0 for the duration of


a frequency if it was preceded by a READ or WRITE access to
PRB.
Thus the signal can indicate the availability of data
to PB or the acceptance of data by PB. FLAG is a negatively
edge-triggered input that could be connected to a PC of
another CIA.
A falling-edge at FLAG also sets the FLAG
interrupt-bit.

128

The serial data port SDR is a synchronous 8-bit shiftregister.


CRA bit6 determines input or output mode. In the
input mode, the data to SP with the increasing flank of a
signal at CNT are transferred into a shift-register.
After
8 CNT-pulses,
the content of the shift-register is
transferred

In

to SDR and

the SP-bit

is

set

in ICR.

the

output mode, timer A functions as a baud-rate


The data from SDR is pushed out to SP with half
the lower-course frequency of timer A.
The theoretically
highest baud-rate is thus 1/4 of the system frequency.
generator.

The transfer starts after the data has been written into
SDR, provided that timer A is running and in continuous mode
(CRA bit 0=1 and bit 3=0).

The cycle derived from timer A appears at CNT.


The data
from SDR are loaded into the shift-register and then pushed
out

of

SP with every falling

flank

at CNT.

After 8 CNT-pulses the SP-interrupt is created.


But if SDR
is loaded with new data before this event, these are loaded
automatically into the shift-register and pushed out.
In
this case no interrupt appears. The data from SDR are pushed
out with the Hi-byte first.
Incoming data should have the
same

format.

8.4

The Timer

Each of the two interval-timers consists of a 16-bit counter


(read only) and a 16-bit intermediate memory (write only).
Data that is written into the timer ends out in the

intermediate

present

state

memory
of

the

while

the

reading-data

counter.

represents

the

Both timers can be used independently as well as together.


The different ways of operation allow the creation of long
time delays, variable pulse-lengths, and impulse-strings.
When using th CNT-entrance, the timers can count external
impulses

Every

allows

or measure

timer
it

the

START/STOP

This

bit

control-register

following

functions:

(bit 0)

can start or stop

PB ON/OFF

Here,

has

frequencies.

the

1)
lower course of

the

timer at

the

timer

the

to

it

which

any time.

(bit

for timer A, PB7 for timer B).

before

assigned

data-direction determined

129

is directed

to PB (PB6

This function has priority


in DDRB.

TOGGLE/PULSE

This bit determines the kind of lower-course pulse that


appears at PB.
Either PB is tilted to the respective other
position, or a positive pulse with the duration of one cycle
is

created.

ONE-SHOT/CONTINUOUS (bit 3)
In the one-shot operation

intermediate

memory

value

to

the timer counts from the


zero, sets the IRC-bit, loads

the counter again with intermediate-memory value and stops


then.
In the continuous-mode the event described above
happens

cyclic.

FORCE LOAD (bit 4)


This bit allows the
whether

it

is

timer

presently

to

load

running

or

any

time,

no

matter

not.

INPUT MODE (bit 5 CRA, bit 5-6 CRB)


These allow a choice of the cycle with which the

timer

is

counted down.
Timer A can be supplied by either the systemcycle or with a cycle that was given to CNT.
In addition to
that, timer B can be fed with the lower-course pulses of
timer A, either absolute or independent of CNT=1.

8.5

The

Real-Time Clock

real-time

resolution

of

clock

(TOD)

is

24-hour

clock

(am/pm)

with

l/10sec.

It consists of four registers: l/10sec, sec, min, hr.


The
am/pm-bit is the one with the highest value of the hour
register. Every register is organized in the BCD-format so
that the read values can be used without big calculation
operations.
A cycle

serves a 50/60Hz-signal (programmable, CRA-bit 7) at


pin TOD. Furthermore, there is an alarm-register with which
one can create an interrupt at any time.
The alarm-register
overlays the same address as the TOD-register.
That is why
the access is controlled with bit 7.
The alarm-register is
write only.

Every read-access represents

TOD-register,
In
has

order
to be

to

independent

set

and

read

of
the

CRB
time

bit

the state

of

the

7.

correctly,

certain

order

kept:

If the hour-register is being written on, the clock stops


automatically.
It is not until a write-access to the 1/10
sec-register took place that the clock will continue to run.

By this the clock starts indeed at the right time. Since a


transfer into an already read register can occur during the
reading of the complete time, the complete time will be
buffered into an intermediate-memory at the reading of the

130

hour-register.
until

the

1/10

The

has

intermediate-memory

been read.

is

not

set

free

If only one register shall be read, this can happen easily


of course; but if this register is the hour-register, the
l/10sec-register has to be read afterwards in order to set
the intermediate-memory free again.

8.5.1

With a small trick,

the right time

The long-time accuracy of the clock TI$f supplied by the


operating system, leaves something to be desired as far as
the system is concerned.
You have to count on a maximum

deviation of 1/2 hr. per day.

For those who insist on the correct time, the real-time


clock in the CIAs offer a solution.
It gets its cycle from
the main frequency which shows an amazing long-time
constancy.

In order to simplify the handling of the real-time clock for


you, we worked out two small basic-programs.
One serves for

setting

the

clock,

program for setting


on

here.

the

it.

other

for

The value

reading

10
20
30
35
40
50
60
70
80

C=56328: REM basis address of the clock


REM C=56584 for the clock in CIA 2
POKE C+7,PEEK(C+7)AND127
POKE C+6,PEEK(C+6)OR128
INPUT"PUT IN TIME IN FORMAT HHMMSS";A$
IF LEN(A$)<>6 THEN 40
H=VAL(LEFT$(A$,2))
M=VAL(MID$(A$,3,2))
S=VAL(RIGHT$(A$,2))

110

POKE C+3,16*INT(H/10)+H-INT(H/10)*10

130

POKE C+2,16*INT(M/10)+M-INT(M/10)*10

90
100
120

IF H>23
IF H>11
IF

M>59

THEN

IF

POKE C+l,16*INT(S/10)+S-INT(S/10)*10

10
20
30

40

in CIA 1

40

150

The

THEN

40

POKE C,0

following program

enables you to read the time:

C=56328: REM basis address of the clock in CIA 1


PRINT "(shft/clr)":REM C=56584 for clock in CIA 2
H=PEEK(C+3):M=PEEK(C+2):S=PEEK(C+1):T=PEEK(C)
FL=1

50

IF

60

H=INT(H/16)*10+H-INT(H/16)*16:ON FL GOTO 80

65

First

is always

40
H=H+68

140
160

S>59

THEN
THEN

it.

for l/10sec

IF

H>32
H=12

THEN
THEN

H=H-128:FL=0
85

131

the
set

70

H=H+12

80
85
90

IF H=12 THEN H=0


M=INT(M/16)*10+M-INT(M/16)*16
S=INT(S/16)*10+S-INT(S/16)*16

100

T$=STR$(T)

140
150

PRINT "(home)";
PRINT "RIGHT$(H$,2)":IIRIGHT$(M$,2)":"RIGHT$(S$,2)":0";

160

PRINT RIGHT$(T$,1)

170

GOTO

110
120
130

H$=STR$(H):IF LEN(H$)=2 THEN H$ = " 0"+RIGHT$(H$,1)


M$=STR$(M):IF LEN(M$)=2 THEN M$=" 0"+RIGHT$(M$,1)
S$=STR4(S):IF LEN(S$)=2 THEN S$ = " 0H+RIGHT$(S$,1)

30

After pressing STOP/RESTORE,

you have to set the time again

since the operating system sets all registers back to the


start-value.
Unfortunately, the bit for the 50/60HZ
selection is affected by this as well. Your clock would be
far

behind.

8.6

If

The CIAs in the Commodore 64

you

want

to

use

the

CIAs

in

the

CBM64

for

your

own

purposes, please note that they were assigned special tasks


in the computer.
This applies especially for the usage of
interrupts because they cause

through certain routines.


in

the operating-system

to run

So please avoid changing the mask

ICR.

The

assignments

CIA 1
REG

Base

for the CIAs from within CBM64 are:

address

(PRA)
Bit 0-7

$DC00(56320)

During

normal

operation

the

sequence-

selection of the keyboard-matrix is determined here.


Yet some bits are connected with control-port 1
outside the computer. It serves for connecting joy
sticks

or

paddles:

Bit 0-4 Joy-stick 0, order:


key

Bit 6-7
two

REG

pressed.

REG

13

may

be

(PRB)
Bit 0-7 During
back-report of

port 2

down,

Selection paddle-set A/B.

bits

Bit 0-4

up,

The

left,

Only one of

the

0.

normal operation occurs a columnthe keyboard-matrix if a key was

same

function

as

REG 0,

but

(joy-stick 1).

(ICR)
Bit

right,

Input-data

from

the

132

cassette-port

for control-

CIA

PEG

Basis-address $DDOO(56576)
(PRA)

Bit 0-1

of

the

Bit 2

VA 14-15

video-ram).

REG

the highest value

TXD (only in connection with

cartridge,

Bit
Bit
Bit
Bit
Bit

(address bits of

3
4
5
6
7

otherwise

ATN
CLOCK
DATA
CLOCK
DATA

free).

with an RS 232

(exit serial bus)


(exit serial bus)
(exit serial bus)
(entrance serial bus)
(entrance serial bus)

(PRB)

Bit 0-7 Usually free.


When putting on
cartridge they get the following meaning:

Bit
Bit
Bit
Bit
Bit
Bit
Bit
REG

13

0
1
2
3
4
6
7

(receive data)
(request to send)
(data terminal ready)
(ring indicator)
(data carrier detect)
(clear to send)
(data set ready)

RXD

(only

RS

232

(ICR)

Bit

free).

8.7

RXD
RTS
DTR
RI
DCD
CTS
DSR

an

at

RS

232

operation,

otherwise

Using the Joysticks

When using the joysticks you ought to know that they overlay
the same CIA-bits that are used for asking the keyboard at
normal

In

operation.

order

to work

with

the

joysticks

anyway,

the

keyboard-

input has to be eliminated for that particular time.

can

only

keyboard

happen

and

thus

within

does

The following program


reliable manner:

not

program

contain

shows

the

an

POKE56322,224
J=PEEK(56320)
IF(JANDl)=0 THEN

40
50
60
70

IF(JAND2)=0 THEN PRINT "DOWN"


IF(JAND4)=0 THEN PRINT "LEFT"
IF((JAND8=0 THEN PRINT "RIGHT"
IF(JAND16)=O THEN PRINT "BUTTON"

80

GOTO20

This program expects


joystick is operated

does

INPUT

joystick

10
20
30

PRINT

that

or

not

the

This

use

the

like.

functions

in

"UP"

the joystick at control port 2.


at control port 1,
the address
133

If the
in line

20

has

to

be

changed

to 56321.

The only thing that'll


get you out of the above program is
STOP/RESTORE.
The last line in a "serious" program should
be:

100

POKE

56322,255

With this you unlock the keyboard again.


Of course you can
put this line before any keyboard action if your program
needs the keyboard and the joy-sticks.
But then a command

like the one in line 10 has to come before every reading of


the

joystick.

134

APPENDIX A
Commodore 64 Rom Listings

Basic

Interpreter

AOOO

94

E3

A002

7B

E3

AOO4

43

42

*E394
*E37b

cbmbasic

*********************#*******

AOOC

30

A8

41

A7

ID

AD

F7

A8

A014

A4

AB

BE

AB

80

BO

O5

AC

A01C

A4

A9

9F

A8

70

A8

27

A9

A024

1C

A8

82

AS

Dl

A8

3A

A9

A02C

2E

A8

4A

A9

2C

B8

67

El

A034

55

El

64

El

B2

B3

23

B8

A03C

7F

AA

9F

AA

56

AB

9B A6

A044

5D

A6

B5

AA

29

El

BD

A04C

C6

El

7A

AB

41

A6

39

BC

CC

A05A

7D

B3

A062

EA

B9

Addresses

of

commands

BASIC

(minus

1)

El

***************#****#********

A052

Start-Vector
NMI-Vector

BC

58

BC

10

9E

B3

71

BF

97

EO

ED

BF

64

E2

6B

E2

Addresses

of

BASIC

functions

O3

A06A

B4

E2

OE

E3

OD

B8

7C

B7

A072

65

B4

AD

B7

8B

B7

EC

B6

A07A

00

B7

2C

B7

37

B7

79

69

A080

79

69

B8

79

52

B8

7B

2A

addresses

A088

BA

7B

11

BB

7F

7A

BF

50

opperators

A090

E8

AF

46

E5

AF

7D

B3

BF

A098

5A

D3

AE

64

15

BO

A09E

45

4E

C4

46

4F

D2

4E

45

end

for

A0A6

58

D4

44

41

54

Cl

49

4E

next

data

AOAE

50

55

54

A3

49

4E

50

55

input#

input

A0B6

D4

44

49

CD

52

45

41

C4

dim

read

AOBE

4C

45

D4

47

4F

54

CF

52

let

goto

A0C6

55

CE

49

C6

52

45

53

54

run

if

AOCE

4F

52

C5

47

4F

53

55

C2

restore

gosub

Priority

BASIC

codes
for

command

A0D6

52

45

54

55

52

CE

52

45

return

rem

AODE

CD

53

54

4F

DO

4F

CE

57

stop

on

A0E6

41

49

D4

4C

4F

41

C4

53

wait

load

AOEE
A0F6

41
D9

56
44

C5
45

56
C6

45
50

52
4F

49
4B

46
C5

save

verify

def

poke

AOFE

50

52

49

4E

54

A3

50

52

print#

print

A106

49

4E

D4

43

4F

4E

D4

4C

A10E

49

53

D4

43

4C

D2

43

4D

cont

list

A116

C4

53

59

D3

4F

50

45

CE

clr

cmd

A11E

43

4C

4F

53

C5

47

45

D4

open

close

get

new

tab(

to

spc (

then

not

stop

A126

4E

45

D7

54

41

42

A8

54

A12E

CF

46

CE

53

50

43

A8

54

A136 48 45 CE 4E 4F D4 53 54
A13E

45

DO

AB

AD

AA

AF

DE

41

A146

4E

C4

4F

D2

BE

BD

BC

53

-*/

A-l

and
BASIC

words

sys

and

or

sgn

A14E

47

CE

49

4E

D4

41

42

D3

A156

55

53

D2

46

52

C5

50

4F

int

abs

usr

A15E

D3

53

51

D2

52

4E

C4

4C

fre

pos

sqr

A166

4F

C7

45

58

DO

43

4F

D3

rnd

log

A16E

53

49

CE

54

41

CE

41

54

exp

cos

sin

45

CB

4C

45

CE

tan

atn

peek

A4

56

41

CC

41

len

str*

val

asc

A176

CE

50

45

A17E

53

54

52

A186

53

C3

43

48

52

A4

4C

45

A18E

46

54

A4

52

49

47

48

54

A196

A4

4D

49

44

A4

47

CF

00

chr*

left*

right*

mid*

*****************************

BASIC

A19E 54 4F 4F 20 4D 41 4E 59
A1A6 20 46 49 4C 45 D3 46 49

1-

too

A1AE

4C 45 20 4F 50 45 CE

2-

file

open

A1B6
A1BE

49 4C 45 20 4E 4F 54 20
4F 50 45 CE 46 49 4C 45

3-

file

not

46

A1C6 20 4E 4F 54 20 46 4F 55
A1CE 4E C4 44 45 56 49 43 45
A1D6 20 4E 4F 54 20 50 52 45
AIDE

53

45

4E

A1E6

49

4E

50 55 54

D4

4E

4F 54 20

20 46 49
A1EE 4C C5 4E 4F 54 20 4F 55
A1F6 54 50 55 54 20 46 49 4C

error

go

messages

many

files

open

4-

file not

5-

device

found

6-

not

input
output

not

present

file

7.

not

A1FE C5 4D 49 53 53
A206 20 46 49 4C 45
A20E 4D C5 49 4C 4C

49 4E 47
20 4E 41
45 47 41

8.

missing

filename

9.

illegal

device

A216

4C 20

A21E

20

44

45 56

49

43

45

4E 55

4D 42

45 D2

4E

20

49

file

A226

45 58

48

10-

next

A22E
A236

4F 55 54 20 46
59 4E 54 41 P8

4F D2 53
52 45 54

11-

syntax

A23E

55

52

57

49

54

48

12.

return

without

A246

4F

55 54

20 47

4F

53

55

A24E

C2

4F

55

54

20

4F

46

20

13-

out

data

A256

44

41

54

Cl

49

4C

4C

45

14-

illegal
overflow

54

4E

2O

57

54

without

of

47

41

4C

20

51

55

41

4E

A266

54

49

54

D9

4F

56

45

52

A26E

46

4C

4F

D7

4F

55

54

20

15-

A276

4F

46

20

4D

45

4D

4F

52

16-

out

A27E

D9

55

4E

44

45

46

27

44

17-

undef'd

A286

20

53

54

41

54

45

4D

45

A28E

4E

D4

42

41

44

20

53

55

A296

42

53

43

52

49

50

D4

52

18-

bad

A29E

45

44

49

4D

27

44

20

41

19-

redim'd

A2A6

52

52

41

D9

44

49

56

49

A2AE

53

49

4F

4E

20

42

59

20

20.

division

A2B6

5A

45

52

CF

49

4C

4C

45
21-

illegal

A2BE

47

41

4C

20

44

49

52

45

A2C6

43

D4

54

59

50

45

2O

4D

A2CE

49

53

4D

41

54

43

C8

53

22-

type

54

52

49

4E

47

2O

54

4F

23-

string

A2DE

4F

20

4C

4F

4E

C7

46

49

24.

file

A2E6

4C

45

20

44

41

54

Cl

46

4F

52

4D

55

41

20

54

gosub

memory
statement

subscript

A2D6

A2EE

for

quantity

A25E

of

number

array

by

zero

direct

mismatch
too

data

long

Aq

A-Joujaui

aajj-

uo

autq.noj

if n

n tr it a n ?ir rr 'it iir it

siy
^xau

>| 33143

d8W$

3Na

2T*#

oaw

tr it

it

it

it irir

saw

oa

tr3W

ww
ST

it

z.aw

09
8a

xw

81

jaq-utod

X
X

saW

69

T3W
3WW

Od

oaw

WB

tfXJL

8T

313
LO

dW3

*0T0#

Z.0

3NQ

03W$

6tr

yan

6fr$

dW3

*20T0*

038

Z3W*

ys

wtr$

yis

6tr*

yai

*0T0$

TO

TO

zo

W17
TO

0
6i7

aww

aa

6WW

sw

Z.WW

oa

frWW

aa

2WW

d6W

aa

06W

S8

wai

4TOIO$

dN3

T8$#

TS

3N8

Z3W$

96W

sw

W17

wan

wt$

86W

oa

WO

3Na

irWW$

SO

*20T0* wan

apoD

,.X3N-U0d,

,.anS09.,

TO

T8
TO

TO

W6W

aa

fr6W

oa
63

Z6W

d8W

aa

wa

XSJ.

88W

83

XNI

38W

83

XNI

08W

83

XNI

38W

83

XNI

W8W

*****************************

sir wo
frfr Tfr

sa6essaui

00
3S

ao
Sfr

00 3fr

OW

00

si7 os 02

00

3fr

6I7 02

Ttr Sir

SS

wo ao sz 6s
WO ao 00 02
SS

dfr

SS

ao at

25

&

39W

ao 1^9W

*****************************

W 8 W fr2 09W
W 30 W 00 2W 03 8SW

W 3T

2W *3 2W SO 2W 83 2W W3 OSW
2W WW 2W 06 2W 06 2W
2W ZL 2W W9 2W WS 2W

8frW

2W S 2W S 2W S2 2W OT 8W
TW dd TW Od TW 23 TW 00 0W
TW 23 TW S3 TW 3W TW 36 82W
sa6essaui

j-o

*****************************

\/3

"62

p.j-apun

-^.2
-93

ooq.

-93

dtr

OS a*

3i7

3t^

frS

02

frtr
SS

02
S3

dtr

33

3\r

dfr

60

6fr
LZ
3tr

9fr

6*

trS tr
9tr
6*

LZ

Sir
trS
T17

fr

2S

Ttr

Sir

3fr

92W

9S

3TW

SS 9fr

frfr
3fr

3*
dir

tr

9TW

SS
fr

80

02

30W
90W

Sir

d*

3d2W

dtr

9d2W

A3BB
A3BD

85 31
84 32

STA $31
STY $32

A3C0

A5 5A

LDA $5A

A3BF

A3C2
A3C4
A3C6
A3C7
A3C9

A3CB
A3CC
A3CD
A3CE
A3D0

A3D2
A3D3
A3D5
A3D7
A3D9
A3DB
A3DC
A3DE
A3E0
A3E2
A3E4
A3E6
A3EB
A3EA
A3EC
A3ED
A3EF
A3F1
A3F3
A3F5
A3F7
A3F8
A3FA

38

E5 5F
85 22

SEC

SEt Carry

SBC $5F
STA $22

$5A/$5B
$58/$59

A8
A5 5B
E5 60
AA
E8

TAY
LDA $5B
SBC $60
TAX
INX

98
F0
A5
38
E5
85
BO
C6
38
A5
E5
85
BO
C6
90
Bl
91
88
DO
Bl
91
C6
C6
CA
DO
60

TYA
BEQ
LDA
SEC
SBC
STA
BCS
DEC
SEC
LDA
SBC
STA
BCS
DEC
BCC
LDA
STA
DEY
BNE
LDA
STA
DEC
DEC
DEX
BNE
RTS

23
5A
22
5A
03
5B
58
22
58
08
59
04
5A
58
F9
5A
58

5B
59
F2

$5F/$60

85

A402
A403

BA
E4 22

TSX
CPX

A407

60

RTS

A405

22

90 2E

$22
$5A
$A3DC
$5B
$58
$22
$58
$A3EC
$59
$A3EC
($5A),Y
($58),Y
$A3E8
($5A),Y
($58),Y

$5B
$59
$A3EC

C5 33

Check on stack-space
accumulator must get hal-f
the amount of needed space
display "out of memory

STA $22

$22

BCC $A435

display "out of memory

*****************************
A408 C4 34
CPY $34
A40A 90 28
BCC $A434
A40C
DO 04
BNE $A412
A40E

old block-start+l
new block-end

$A3F3
$5A

*****************************
A3FB
OA
ASL
A3FC
69 3E
ADC #$3E
A3FE
BO 35
BCS $A435
A400

old =|<-**r*

CMP $33

Creats space in memory for


inserted lines and
variables
sets A & Y to location in
memory.

A-4

A410

90

A412

48

A413

A2

A415

98

A416

48

A417

B5

A419

CA

22

BCC

$A434

PHA
09

LDX

#$09

TYA

PHA
57

LDA

$57, X

A41A

10

FA

A41C

20

26

A41F

A2

BPL

$A416

$B526

F7

LDX

#$F7

61

STA

A421

68

95

A424

E8

A425

30

A427

68

A428

A8

TAY

A429

68

PLA

$61, X

FA

collection

get

back

register

BMI

$A421

PLA

C4

34

CPY

$34

90

06

BCC

$A434

A42E

DO

05

BNE

$A435

A430

C5

33

CMP

$33

A432

BO

01

BCS

$A435

10

LDX

60

garbage

INX

A42C

A2

for

PLA

A42A

A435

registers

arithmetic

JSR

B5

A422

A434

save

DEX

O.K.
no

ready

space,

"out

of

memory"

RTS
#$1O

error

****** ************** *********

A437

6C

00

03

A43A

8A

TXA

A43B

OA

ASL

A43C

AA

A43D

BD

26

A440

85

22

A442

BD

27

A445

85

23

A447

20

CC

A44A

A9

00

A44C

85

13

A44E

20

D7

AA

A451

20

45

AB

A454

AO

A456

Bl

A458

48

A459

29

7F

A45B

20

47

A45E

C8

A45F

68

A460

10

F4

A462

2O

7A

A465

A9

69

A467

AO

A3

A469

20

IE

A46C

A4

3A

A46E

CB

JMP

Output
JMP

($0300)

-for

"out

error

of

memory"

messages

$A43A

error

in

x-register;

30

TAX

A3

LDA

$A326,X

STA

$22

LDA

$A327,X

STA

$23

JSR

$FFCC

LDA

#$00

STA

$13

set

JSR

$AAD7

out-put

(CR)

JSR

$AB45

out-put

"?"

00

LDY

#$00

22

LDA

text

of

error

message

out-put

error

message

A3
FF

get

address

of

message

set back active


channels

($22),Y

back

I/O

I/O

flag
&

(LF)

PHA

AB

AND

#$7F

JSR

$AB47

INY
PLA
BPL
A6

AB

$A456

initialize

BASIC-pointers,

JSR

$A67A

LDA

#$69

block

LDY

#$A3

JSR

$AB1E

pointer
out-put

A/Y to
string

LDY

$3A

program

mode?

CONT

error

INY

A46F

FO

03

A471

20

C2

BEQ

$A474

JSR

$BDC2

A474

A9

76

LDA

#$76

A476

AO

A3

LDY

#$A3

BD

no

output
set

A-5

"in

pointer

(line

number)"

"READY."

A478

2O

A47B

A9 80

IE AB

LDA #$80

JSR $AB1E

A47D

20 90 FF

JSR $FF90

A480

6C

output
set

direct-mode

INPUT
02

03
A5

A483

2O

60

A486

86

7A

A488

84 7B

A48A

20

73

00

JMP

($0302)

JSR

$A56O

STX

$7A

string

waiting

JMP

$A483

get

BASIC

flag

loop

line

into

STY

$7B

CHRGET

pointer

JSR

$0073

CHRGET

get

bu-f-fer

empty,

to

next

bu-f-fer

character

TAX

A48D

AA

A48E

F0

FO

BEQ $A480

A490

A2

FF

LDX

#$FF

A492

86

3A

STX

$3A

sign

A494

90 06

BCC

$A49C

digit,

then

insert

A496

20

79

A5

JSR

$A579

change

line

to

A499

4C

El

A7

JMP

$A7E1

execute

********************************

A49C

20

6B

A9

A49F

20

79

A5

A4A2

84

OB

A4A4

20

13

A4A7

90

44

AO

A6

01

mode

as

command

insrt

of

program

lines

to

form

JSR

$A579
SOB

change line to intrpr code


pointer to input buffer

JSR

$A613
$A4ED

calculate

LDY

Erase
#$01

Bl

5F

LDA

85

23

STA $23

<$5F>,Y

A4AF

A5

2D

LDA

$2D

A4B1

85

22

STA

$22

A4B3

A5

60

LDA

$60

A4B5

85

25

STA

$25

A4B7
A4B9

A5
88

5F

LDA
DEY

$5F

A4BA

Fl

5F

A4BC

18

SBC

($5F),Y

CLC

A4BD

65

2D

ADC

$2D

A4BF

85

2D

STA

$2D

A4C1

85

24

STA

$24

A4C3

A5

2E

LDA

$2E

A4C5

69

FF

ADC

#$FF

A4C7

85

2E

STA

$2E

A4C9

E5

60

SBC

$60

A4CB

AA

A4CC

38

A4CD

A5

5F

LDA

$5F

A4CF

E5

2D

SBC

$2D

A4D1

A8

A4D2

BO

A4D4

E8

A4D5

C6

A4D7

18

TAX
SEC

TAY
BCS

$A4D7

INX

DEC

$25

CLC

A4D8

65

22

ADC

$22

A4DA

90

03

BCC

$A4DF

A-6

code

STY
BCC

line

line

interpreter

change

A4AD

25

&

direct

waiting

$A96B

A4AB

03

Clr

-for

keep

JSR

X"X"**-K

#**"*

A4A9

input

bu-f-Fer

address

program

line

addr

of

line

A4DC

C6

A4DE

IS

DEC

23

$23

CLC

A4DF

Bl

22

LDA

($22),Y

A4E1

91

24

STA

($24),Y

shiftloop

I NY

A4E3

C8

A4E4

DO

F9

BNE

$A4DF

A4E6

E6

23

INC

$23

A4E8

E6

25

INC

$25

A4EA

CA

A4EB

DO

DEX
BNE

F2

$A4DF

*****************************

Insert program
CLR command

A4ED
A4F0

20 59
20 33

A6
A5

JSR
JSR

$A659
$A533

A4F3

AD

00

02

LDA

$0200

characters

A4F6

FO

88

BEQ

$A480

no,

A4F8

18

A4F9

A5

2D

LDA

$2D

A4FB

85

5A

STA

$5A

65

OB

ADC

$0B

A4FF

85

58

STA

$58

A501

A4

2E

LDY

$2E

A503

84

5B

STY

$5B

Ol

BCC

$A50B

A505

9O

C8

new

program

then

go

A508

84

59

20

B8

A50D

A5

14

A3

STY

$59

JSR

$A3B8

LDA

$14

A50F

A4

15

LDY

$15

A511

8D

FE

01

STA

$01 FE

A514

BC

FF

01

STY

$01FF

A517

A5

31

LDA

$31
$32

A519

A4

32

LDY

A51B

85

2D

STA

$2D

A51D

84

2E

STY

$2E

A51F

A4

OB

LDY

SOB

A521

88

A522

B9

FC

A525

91

5F

A527

88

shift

BASIC

to

waitingloop

lines

DEY

01

LDA

$01FC,Y

STA

($5F),Y

DEY

A528

10

F8

BPL

$A522

A52A

20

59

A6

JSR

$A659

CLR

command

A52D

20

33

A5

JSR

$A533

tie

new

A530

4C

80

A4

JMP

$A480

jump

***** ***E-***r**-3*****[*******

A5

line

buffer?

I NY

A50A

A533

in

CLC

A4FD

A507

tie

line

2B

LDA

Tie

$2B

A535

A4

2C

LDY

$2C

A537

85

22

STA

$22

A539

84

23

STY

$23

A53B

18

CLC

A53C

AO

01

LDY

A53E

Bl

22

LDA

A540

FO

ID

BEQ

#$01

($22),Y
$A55F

A-7

to

new

program

line

waiting-loop
BASIC

programline

LDY

04

#$04

A542

AO

A544

C8

A545

Bi

22

LDA

A547

DO

FB

BNE $A544

A549

C8

I NY

A54A

98

TYA

A54B

65

A54D

AA

A54E

AO 00

LDY #$00

A55O

91

22

STA

A552

A5

23

LDA

$23

A554

69

OO

ADC

#$00

A556

C8

A557

91

22

STA

($22),Y

A559

86

22

STX

$22

A55B

85

23

STA $23

A55D

90

DD

BCC $A53C

A55F

60

I NY

ADC

22

($22),Y

$22

TAX

($22),Y

I NY

RTS

**********************************

Input

new

A560

A2 00

A562

20

12

A565

C9

OD

A567

FO

OD

A569

9D

00

A56C

E8

A56D

EO

59

CPX

#$59

no,

A56F

90

Fl

BCC

$A562

A571

A2

17

LDX

#$17

output

A573

4C

37

A4

JMP

$A437

finish

A576

4C

CA

AA

JMP

$AACA

El

02

#$00

JSR

$E112

get

CMP

#$OD

RETURN

BEQ

$A576

yes,

STA

$0200,X

store

character

89'th

character?

INX

JMP

key?

end

get

for

($0304)

Change

A579

6C

04

A57C

A6

7A

LDX

$7A

A57E

AO

04

LDY

#$04

A580

84

OF

STY

$0F

flag

A582

BD

00

LDA

$0200,X

get

02

character

input

next

JMP

in

bu-f-fer

character

"string

too

error

long"

message

buffer

output

*******************************

03

line

LDX

with

$00,

carriage

line

to

return

interpreter

$A57C

for

code

interpreted

character

from

A585

10

07

BPL

$A58E

no

A587

C9

FF

CMP

#$FF

check

for

A589

FO

3E

BEQ

$A5C9

A58B

E8

A58C

DO

F4

BNE

$A582

A58E

C9

20

CMP

#$20

empty

character

A590

FO

37

BEQ

$A5C9

A592

85

08

STA

$08

A594

C9

22

CMP

#$22

A596

FO

56

BEQ

$A5EE

A598

24

OF

BIT

$0F

A59A

70

2D

BVS

$A5C9

A59C

C9

3F

CMP

#$3F

A59E

DO

04

BNE

$A5A4

basic

comma

buffer

code?
Pi

code

INX

interpreted

question

A5AO

A9

99

LDA

#$99

A5A2

DO

25

BNE

$A5C9

A5A4

C9

30

CMP

#$30

check

A5A6

90

04

BCC

$A5AC

smaller?

comma

mark

substitute

with

",'

"?"

code

for

PRINT

A-8

for

zero

"0"

A5A8

C9

3C

CMP

#$3C

A5AA

90

ID

BCC

$A5C9

A5AC

84

71

STY

$71

A5AE

AO

00

LDY

#*00

A5B0

84

OB

STY

*0B

A5B2

88

A5B3

86

A5B5

CA

DEY
7A

STX

A5B6

C8

I NY

A5B7

E8

INX

A5B8

BD

A5BB

38

$7A

DEX

OO

O2

LDA

*O2OO,X

character

compare

SEC

A5BC

F9

9E

SBC

*A09E,Y

A5BF

FO

F5

BEG

$A5B6

A5C1

C9

80

CMP

#*80

AO

A5C3

DO

30

BNE

*A5F5

A5C5

O5

OB

ORA

*0B

A5C7

A4

71

LDY

*71

INX
I NY
STA

$01FB,Y

LDA
BEQ

$01FB,Y
*A6O9

A5C9

E8

A5CA

C8

A5CB

99

FB

Ol

A5CE

B9

01

A5D1

FO

FB
36

A5D3

38

A5D4

E9

3A

SBC

#*3A

A5D6

FO

04

BEQ

*A5DC

A5D8

C9

49

CMP

#*49

DO

02

BNE

*A5DE

A5DC

85

OF

STA

*0F

A5DE

38

A5DF

E9

55

SBC

#*55

A5E1

DO

9F

BNE

$A582

A5E3

85

08

A5E5

BD

00

STA
LDA

$08
*O2OO,X

A5E8

FO

DF

BEQ

*A5C9

A5EA

C5

08

CMP

$08

A5EC

FO

DB

BEG

*A5C9

A5EE

ce

A5EF

99

A5F2

E8

buffer

with

BASIC-word
list

found,

code

counter

save
and

check

status
then

for

division
DATA

is

even

+*80

BASIC-code
get

finish,

SEC

A5DA

in

register

done

color

":"

marks?

code?

SEC

02

REM

code?

I NY
FB

01

STA

*01FB,Y

INX

A5F3

DO

FO

BNE

*A5E5

A5F5

A6

7A

LDX

*7A

A5F7

E6

OB

INC

*0B

A5F9

C8

A5FA

B9

9D

A5FD

10

FA

A5FF

B9

9E

A602

DO

B4

A604

BD

00

A607

10

BE

A609

99

FD

STA

*01FD,Y

A60C

C6

7B

DEC

*7B

I NY

AO

AO
02

01

LDA

$A09D,Y

BPL

*A5F9

LDA

*A09E,Y

BNE

*A5B8

LDA

$0200,X

BPL

*A5C7

A60E

A9

FF

LDA

#*FF

A610

85

7A

STA

*7A

A612

60

compare

set

RTS

A-9

with

buffer

listing

pointer

to

mox

o/i

ii*

ssox3

OT-V

Tiyi3

dsr

3dd*

yiS

-b

A1S

a89y*

dd

3Na

178

i?y

as

699y

98

os

1.3

oa

099y
399y

*****************************

oo

oq.

.jaq.u tod l33dH3

389y*

as*

a*(as*)
00*

M3N-3ISy3

dSF 9y

6y

38 OS

9y

3S

69

00

98

3S

as

ys

yai

so

69

3ay

as

yai

oo*#

99y

T6
83

ys

3Na

Tfr9y*

999y

98
8T

313

yis
ANI

a'(as*)

upujuiod

as
oo

ad

16
6y

oa

*****************************

09
313

daa:>i

iT9y*

a'<d9*)
auxx

^xau

j-o ssajppe

81

S33

LQ.

yai
A3a

d9

uaAa

jo

Tfr9y*
Tfr9y*

A* (d9*)

uaqq.

uau.}

q.jeq.s

ubas

3N3

9y*

yai

fri*

3S9y*

janeuis

T1z9y*

AA(d9*)

pa>iaas

a^ex"=xe3

9T*

01?9y*

ia
yy

yai

d9

T3

89y

88

033

yO

333

30

dW3

Od
06

d9 TO

A30

axq^^TASUT

>iD3L|D
;qu

jaquinu-auxx

:*ou
uaAa

O9*

as*

ssajppe

03

8B

xy

A*(d9*)

A30

X=3

janpujs

Jaqujnuauxx aj^duiou

duinr

88

i7i

60

A30
jaquinu
punoj.

auo ^uasajd M^TM ajedmoD

punoj.

'0

a*(d9*)

auxx
j-o

9y

00
88

033

333

8T

dW3

d9

yai

9T

Od
06

TO
83

AN I

dT

d9

X1S

09

3S

xai

to

Aai

d9

yis

9y

T9y
09y

3S9y

3S9y
3S9y
6S9y
Z.S9V

9S9y

9y

B3

AN I
033

yai

as

yai

TS9y

Od

T3
98
98
oy

9y

9y

*****************************

A66B

A5

2D

LDA

$2D

A66D

A4

2E

LDY

$2E

A66F

85

2F

STA

$2F

A671

84

30

STY

$30

A673

85

31

STA

$31

STY

$32

JSR

$A81D

19

LDX

#$19

16

STX

$16

A675

84

32

A677

20

ID

A67A

A2

A67C

86

A67E

68

PLA

A67F

A8

TAY

A8

variable

finish

variable
start

RESTORE
set

command

back

string

descriptor
indexes

A680

68

A681

A2

A683

9A

TXS

A684

48

PHA

A685

98

TYA

A686

48

A687

A9

00

LDA

#$00

A689

85

3E

STA

$3E

A68B

85

10

STA

$10

A68D

60

PLA

FA

LDX

#$FA

initialize

stack

pointer

PHA

block

CONT

RTS

*****************************
A68E

18

A68F

A5

2B

A691

69

A693

85

Program pointer

CLC

to BASICstart

LDA

$2B

FF

ADC

#$FF

7A

STA

$7A

BASIC-start

A695

A5

2C

LDA

$2C

A697

69

FF

ADC

#$FF

A699

85

7B

A69B

STA

60

$7B

A69C

90

06

BCC

$A6A4

A69E

sign?

FO

04

BEG

$A6A4

only

list?

for

minus

RTS

**#*}

BASIC-LIST

command

(line

number)

A6A0

C9

AB

CMP

#$AB

A6A2

DO

E9

BNE

code

$A68D

A6A4

20

diff.

6B

A9

JSR

$A96B

A6A7

get

20

13

A6

JSR

$A613

A6AA

20

79

00

JSR

$0079

calculate start
get last symbol

"-"
(through)
code, SYNTAX ERROR

line

number

address of
line

A6AD

FO

OC

BEQ

$A6BB

A6AF

C9

AB

no

CMP

#$AB

A6Bi

DO

8E

BNE

$A641

A6B3

20

73

00

JSR

code for "-"


(through)
no, SYNTAX ERROR

$0073

A6B6

20

get

next

symbol

6B

A9

JSR

$A96B

A6B9

DO

86

get

line

number

BNE

$A641

A6BB

68

line

number?

PLA

A6BC

68

A6BD

A5

14

LDA

$14

A6BF

05

15

ORA

$15

A6C1

DO

06

BNE

$A6C9

PLA

A6C3

A9

FF

LDA

#$FF

A6C5

85

14

STA

$14

A6C7

85

15

STA

$15

A6C9

AO

01

LDY

#$01

A6CB

84

OF

STY

$0F

is

second

line-number

no

list

A-11

to

the

end

0?

A6CD

Bl

5F

LDA

link

address

A6CF

FO

43

BEQ

$A714

yes,

ready

A6D1

20

2C

A8

JSR

$A82C

A6D4

20

D7

AA

JSR

$AAD7

check on stop
out-put <CR),

A6D7

CB

A6D8

Bl

A6DA

AA

A6DB

C8

A6DC

Bl

A6DE
A6E0

A6E2

($5F),Y

key
new

line

I NY
5F

LDA

($5F),Y

TAX
get

I NY

line-number

($5F),Y

5F

LDA

C5

15

CMP

$15

DO

04

BNE

$A6E6

E4

14

CPX

$14

compare with

end

bigger,

then

-finish

A6E4

FO

O2

BEQ

$A6E8

A6E6

BO

2C

BCS

$A714

A6E8

84

49

STY

$49

A6EA

20

CD

JSR

$BDCD

output

line

A6ED

A9

20

LDA

#$20

out-put

"

A6EF

A4

49

LDY

$49

A6F1

29

7F

AND

#$7F

A6F3

20

47

JSR

$AB47

A6F6

C9

22

CMP

#$22

A6F8

DO

06

BNE

$A7OO

BD

AB

A6FA

A5

OF

LDA

$0F

A6FC

49

FF

EOR

#$FF

A6FE

85

OF

STA

$0F

A700

C8

A701

FO

11

BEQ

A703

Bl

5F

LDA

A705

DO

10

BNE

A707

A8

output
..(!)

turn

no

I NY

get

($5F),Y

no

$A717

number

number

"

(space)

character
inverted

quote?

inverted-comma

line-end

symbols,

$A714

after

then

flag

255

stop

character
line-end, then

list

TAY
LDA

5F

($5F),Y

A708

Bl

A70A

AA

A70B

C8

A70C

Bl

5F

LDA

($5F),Y

A70E

86

5F

STX

$5F

A710

85

60

STA

$60

A712

DO

B5

BNE

$A6C9

A714

4C

86

JMP

$E386

start

TAX
I NY

E3

save

address

as

Change
BPL

$A6F3

C9

FF

CMP

#$FF

FO

D3

BEQ

$A6F3

just

A720

24

OF

BIT

$0F

inverted

A722

30

CF

BMI

$A6F3

then

just

A724

38

A725

E9

#$7F

null

off

A727

AA

A728

84

49

STY

$49

renumber

A72A

AO

FF

LDY

#$FF

A72C

CA

A72D

FO

08

BEQ

A72F

C8

A730

B9

A71A

10

A71C
A71E

03

SBC
TAX

first

DEX

AC

LDA

clear

code, just
out-put

out-put

comma

mode?
out-put symbol

o-f-f-set

code to X

character

command

pointer

word?

$A737

I NY

9E

into

BASIC

no interpreter
code -for Pi

SEC

7F

line

text

D7

06

to

BASIC-CODE

($0306)

6C

next

WARM-START

JMP

A717

o-f

pointer

continue

<-**-]***

****

high

find

$A09E,Y

A-12

of-f-set

for

command

A733

1O

FA

BPL

$A72F

A735

30

F5

BMI

$A72C

bit/set,

LDA

$A09E,Y

get

BMI

$A6EF

last

out-put
out-put

A737

C8

A738

B9

9E

A73B

30

B2
47

word

next

word

I NY

A0

A73D

20

JSR

$AB47

A740

DO F5

BNE

$A737

A742

A9

LDA

#$80

AB

80

command

word

letter,

-from

then

list

finished

character
next letter

BASIC-FOR command
block integer

A744

85

10

STA

$10

A746

20

A5

A9

JSR

$A9A5

LET

A749

20

8A

A3

JSR

$A38A

A74C

searches

DO

05

BNE

$A753

A74E

8A

not

A74F

69

J*$OF

A751

AA

TAX

increase stack-pointer

A752

9A

TXS

A753

68

PLA

A754

63

PLA

A 755

A9

09

A757

20

FB

A3

JSR

$A3FB

A75A

20

06

A9

JSR

$A906

TXA
OF

ADC

LDA

18
98

A75F

65

A761

48

A762

A5

7B

I DA

$7B

A764

69

00

ADC

#$00

A766

48

A76"'

A5

A769

48

A76A

A5

variable
loop

name

the

same name

return

address from
stack

#$O9

A75E

checks on
searches

CLC
TYA

ADC

for

-Found

get

A75D

7A

sets FOR

program

space in stack
next BASIC-

for

pointer

$7A

statement
to next
command

PHA

and

save on

stack

PHA
LDA

3A

$3 A

PHA
LDA

39

running

line

number

$39

on

stack

A76C

48

A76D

A9

A4

PHA
LDA

#$A4

"TO"

A76F

20

FF

AE

JSR

$AEFF

checks

A772

20

8D

AD

JSR

$ADBD

numeric

A775

20

8A

AD

JSR

$ADBA

gets

number

from

A778

A5

66

LDA

#66

A77A

09

7F

ORA

#$7F

A77C

25

62

AND

$62

A77E

85

62

STA

$62

A780

A9

8B

LDA

#$8B

A782

AO

A7

LDY

#$A7

save

return

address

A784

85

22

STA

$22

A786

84

23

STY

$23

A788

4C

43

JMP

$AE43

A78B

A9

BC

LDA

#$BC

A7BD

AO

B9

LDY

#*B9

points

A7BF

20

A2

BB

JSR

$BBA2

default-STEP

A792

20

79

OO

JSR

$0079

get

A795

C9

A9

CMP

#$A9

"STEP"

A797

DO

06

BNE

$A79F

no

A799

20

73

00

JSR

$0073

get

A79C

20

8A

AD

JSR

$AD8A

gets

AE

put

code

on

code

variable?

loopend

FAC

variable

on

stack

A-13

to

last

constant

value

as

in

character

code

step

next

value

character

number

from

FAC

FAC

A79F

20

2B

BC

JSR

$BC2B

get

signs

A7A2

20

38

AE

JSR

$AE38

put

signs

A7A5

A5

4A

LDA

$4A

A7A7

48

A7A8

A5

A7AA

48

A7AB

A9

A7AD

48

LDA

STEP
on

value
stack

variable-name

PHA
49

and

$49

PHA
LDA

81

and

#$81

FOR

code

on

stack

PHA

*****************************

Intpreter

checks

$A82C

7A

LDA

$7A

A4

7B

LDY

$7B

program

CO

02

CPY

#$O2

direct

BEQ

$A7BE

yes

$3D

save

3E

STA
STY

20

2C

A7B1

A5

A7B3

A7B5

A7B7

EA

A7B8

FO

04

A7BA
A7BC

85
84

3D

#$00

loop

on

JSR

A8

A7AE

stop

key

pointer

mode?

NOP

A7BE

AO

00

LDY

A7C0

Bl

7A

LDA

A7C2

DO

43

BNE

$A807

A7C4

AO

02

LDY

#$02

A7C6

Bl

7A

LDA

A7C8

18

A7C9

DO

03

A7CB

4C

4B

A7CE

C8

running

($7A),Y

($7A),Y

CLC
A8

pointer

-for

CONT

$3E

BNE

$A7CE

JMP

$A84B

not

character

end

end

o-f

set

flag

of

line?

program

-for

yes,

then

save

running

END

execute

END

I NY

A7CF

Bl

7A

LDA

A7D1

85

39

STA

A7D3

C8

A7D4

Bl

7A

LDA

A7D6

85

3A

STA

A7D8

98

($7A),Y
$39

I NY

line

($7A),Y
$3A

TYA
set

program

pointer

A7D9

65

7A

ADC

$7A

A7DB

85

7A

STA

$7A

A7DD

90

02

BCC

$A7E1

A7DF

E6

7B

INC

$7B

A7E1

6C

08

03

JMP

A7E4

20

73

00

JSR

$0073

get

A7E7

20

ED

A7

JSR

$A7ED

execute

statement

A7FA

4C

AE

A7

JMP

$A7AE

back

interpreter

execute

($0308)

It***:***********

*****-***!*-*-*-

to

Execute

A7ED

FO

3C

BEQ

$A82B

end

A7EF

E9

80

SBC

#$80

token?

A7F1

90

11

BCC

$A804

no,

A7F3

C9

23

CMP

#$23

A7F5

BO

17

BCS

$ABOE

A7F7

OA

ASL

A7F8

A8

TAY

A7F9

B9

A7FC

48

A7FD

B9

A800

48

OD

AO

LDA

AO

LDA

o-f

line

statement

character
loop

BASIC

statement

line,

then

goto

function

LET

end

command

token

BASIC-command

or

GOTO

code

times

$AOOD,Y
get

PHA
OC

BASIC

next

to

command

address

-from

1isting

$AOOC,Y

PHA

as

A-14

return

address

on

stack

A801

4C

73

00

JMP

$0073

next

A804

4C

A5

A9

JMP

$A9A5

to

A807

C9

A8O9
A80B

3A
CMP #$3A
F0 D6
BEQ $A7E1
4C 08 AF JMP $AF08

II.

character

LET

C9

4B

A810

DO

F9

A812

20

73

"syntax

A815

A9

A4

A817

20

FF

A81A

4C

AO

"GO"

BNE

$ABOB

JSR

$0073

gets

LDA

#$A4

"TO"

AE

JSR

$AEFF

checks

A8

JMP

$A8A0

to

38

next

code

character

on

GOTO

"TO"
$80)

code

command

BASIC-RESTORE

<-***-}(*****

A81D

"GO"

(nimus

#$4B

******

command

error"

on

CMP
00

execute

II

Checks
A8OE

and

command

command

SEC

A81E

A5

2B

LDA

$2B

A820

E9

01

SBC

#*01

A822

A4

2C

LDY

$2C

A824

BO

01

BCS

$A827

A826

88

program

start

current

DATA

-1

DEY

A827

85

41

STA

$41

AB29

84

42

STY

$42

AB2B

60

A82C

20

El

A82F

BO

01

A831

18

A832

DO

3C

BNE

$A870
$7A

address

RTS

Checks
FF

JSR

SFFE1

BCS

*A832

on

checks

stopkey

stop-key

BASIC-STOP

set

STOP

BASIC-END
CLC

set

END

A834

A5

7A

LDA

A836

A4

7B

LDY

$7B

program

A838

A6

3A

LDX

$3A

direct
yes

A83A

E8

A83B

FO

OC

BEQ

*AB49

A83D

85

3D

STA

*3D

command

-flag

to

(C=l)

command

-Flag

to

(C=0)

pointer
mode?

INX

A83F

84

3E

STY

$3E

A841

A5

39

LDA

$39

A843

A4

3A

LDY

$3A

A845

85

3B

STA

S3B

A847

84

3C

STY

*3C

AS49

68

set

pointer

curent

store

line

-for

-for

CONT

number

CONT

PLA

A84A

68

A84B

A9

81

LDA

#$81

get

PLA

return

address

from
stack

A84D

AO

A3

LDY

#$A3

set

A84F

90

03

BCC

$A854

"END"

A851

4C

69

A4

JMP

$A469

no,

A854

4C

86

E3

JMP

*E386

to

A-15

pointer

to

"BREAK"

-flag?

out-put
BASIC

"BREAK

warm-start

IN

XXX1

apoui

doox

joj.

9T-V

3z.$

si*

>joax

606y*

jaqiunu aun 3S&


0109-3isys

Ja^ajdjs^ui

xa~i

3Z.

pue

33S

S9

3ay

yz.

30

S33

z:68y*

0109

6S9y*
0Z.8y$

sy
OO

60

oy
6Z.

as
6

sy

sssy

asy
S38y
Tasy
dVBy
aysy

aysy

S3

os

Oyay

os
OS

6y
sy
8fr

sy

yai

sy

yai

^l

yan

3Z.
3d

asr

dwr

asr
dWC

sy

9y
9y

3N3

z:6

^as

06dd*

dSF

sy
os
6y

3fr

968y

fr68y
68y

T68y
068y

38sy
assy

sssy
yBsy

sssy
sssy
ssy

os
6S 3fr
00

83

dd

ossy

09

did

03

frT

33S

yai

use
HSr

8fr

yai

Bfr

ya~i
yHd

8fr

yHd

Bfr

yHd

yai

*****************************

099y$

no
ujejBojd
PUTJ-

&XJ-

aun

jo^.

S3

sy

6
6y

3yz.y$ dWT Z.y 3y 3fr


oysy*
6Z.00*

aun

ja^uiod

aun

joj-

yai

06
oo

dHd

i,Ny3..

9y

86

yAi
st

33s

33S

yai
ysr

396y* dSP 6y 39 OS

*****************************

o}

0109

yHd

as$#

yHd

6*
jaqujnu

sz.*

3nso9-3isys

oq.

jaqtunu

uiewi&ojd

oo$#
Nna-3isya

jaqumu

Z.Z8y

OS
6y
80

*****************************

;S5

&$

yj^g

A1S

yai

3/1
\>l

yis

yai

Aai
A1S

,,"iN03

WI$#

jojj3

3*

1N03

S98y*

ou

ozsy*
!N03-3ISy3

3N3

z.

dur

fry

A01

xai

yx

3N3

z.T

398y

fr8

0Z.8y

09
gg

fry
sy
fr8
S8

898y
998y

sy

ofr
00

fry
sy

oa

dssy
0S8y

3S8y
6ssy

z.s8y

*****************************

ABB7

90

A8B9

E8

A8BA

BO

04

BCS

A8BC

A5

2B

LDA

$2B

A8BE

A6

2C

LDX

$2C

A8C0

20

17

JSR

A8C3

90

IE

BCC

A8C5

A5

5F

LDA

$5F

A8C7

E9

01

SBC

#$01

A8C9

85

7A

STA

$7A

A8CB

A5

6O

LDA

$6O

A8CD

E9

00

SBC

#$00

A8CF

85

7B

STA

$7B

A8D1

60

ABD2

DO

FD

A8D4

A9

A8D6

85

A8D8

20

8A

A8DB

9A

A8DC

C9

8D

CMP

#$BD

GOSUB

A8DE

FO

OB

BEQ

$A8EB

found?

A8E0

A2

OC

#for

A8E2

2C

A2

07

BCC

current

$ABCO

line

INX

A6

$A8C0
searches

-from

program

SA617

searches

program

$A8E3

not

start

-Found,

then

line

"UNDEF'D"
statement

set

program

pointer

to

new

line

RTS

BASIC-RETURN

BNE

$A8D1

FF

LDA

#$FF

4A

STA

$4A

JSR

$A3BA

A3

find

next

command

GOSUB

TXS

LDX

#$0C

11

BIT

$11A2

"RETURN

WITHOUT

A8E5

4C

37

A4

JMP

$A437

4C

08

AF

JMP

$AFOB

out-put

error

A8EB

68

PLA

out-put

"SYNTAX

A8EC

68

PLA

A8ED

85

A8EF

68

A8F0

85

A8F2

68

A8F3

85

A8F5

68

A8F6

85

STA

set

stack

code

ABEB

39

data
in

for

"UNDEF'D

GOSUB11

STATEMENT"
message
ERROR"

$39

PLA
3A

STA

$3A

get

line

number

get

program

from

stack

PLA
7A

STA

$7A

PLA
7B

STA

$7B

pointer

from
stack

BASIC-DATA

A8F8

20

06

A9

JSR

A8FB

98

TYA

A8FC

18

CLC

search

$A906

and

for

REM

next

commands

statement

offset

A8FD

65

7A

ADC

$7A

A8FF

85

7A

STA

$7A

A901

90

02

BCC

$A905

A903

E6

7B

INC

$7B

A905

60

A906

A2

3A

A908

2C

A2

A90B

86

07

A90D

A0

A90F

84

add

to

program

pointer

RTS
Find
LDX

#$3A

BIT

$00A2

STX

$07

00

LDY

#$00

08

STY

$08

00

color

end

of

A-17

offset

11: "

of

next

line

contains

offset

"="

A911

A5

08

LDA

$O8

A913

A6

07

LDX

$07

A915

85

07

STA

$07

A917

86

08

STX

$08

A919

Bl

7A

LDA

A91B

FO

E8

BEG

$A905

A91D

C5

08

CMP

$08

A91F

FO

E4

BEG

$A905

A921

C8

A922

C9

22

CMP

#$22

A924

DO

F3

BNE

$A919

A926

FO

E9

BEG

$A911

desired

<$7A),Y

I NY

*****************************

A928
A92B

20 9E AD JSR $AD9E
20 79 00 JSR $0079

A92E

C9

B9

CMP

A93O

FO

05

BEQ

$A937

A932

A9

A7

LDA

#$A7

A934

20 FF

A937
A939

A5 61
DO 05

A93B

20 09

A93E

FO BB

A940

20

A943

BO 03

A945

4C

AO

A948

4C

ED

79

AE

A9
00

get

character

end

o-f

line,

pointer

inverted

comma

BASIC-IF
last

expression

character

"GOTO"

code

yes

"THEN"

code

JSR $AEFF

result

of

LDA $61
BNE $A940

expression

JSR

program

no,

$A909

BEQ $A8FB

get

JSR

pointer

last

new

to

line

next

character

no

digit?

to

GOTO

A8

JMP

decode

A7

JMP $A7ED

$A8A0

IF-term

true?
for next

look

$0079

JSR

done

command

BCS $A948

B7

then

increase

calculate

new
line

command

next

command

and

execute

a.***.**.***********************

9E

character

BASICON

get

$B79E

command

byte

values

(0-255)

A94B

20

A94E

48

A94F

C9

8D

CMP

#$8D

"GOSUB"

A951

FO

04

BEQ

$A957

yes

A953

C9

89

CMP

#$89

"GOTO"

A955

DO

91

BNE

$A8E8

no

A957

C6

65

DEC

$65

decrease

pointer

A959

DO

04

BNE

$A95F

not

yet?

A95B

68

A95C

4C

EF

A7

JMP

$A7EF

execute

A95F

20

73

00

JSR

$0073

get

next

character

A962

20

6B

A9

JSR

$A96B

get

line

number

A965

C9

2C

CMP

#$2C

","

comma?

A967

FO

EE

BEG

$A957

A969

68

PLA

A96A

60

RTS

save

PHA

yes,

no,

A-18

code

code

then

yes,

PLA

code

"SYNTAX

zero

get

back

code

and

command

then

get

ERROR"

continue

return

code,

done

*****************************

A96B

A2

00

LDX

#$00

A96D

86

14

STX

$14

Gets

line

it

to

and

A96F

86

15

STX

$15

pre-filling

A971

BO

F7

BCS

$A96A

resulting
line

A973

E9

2F

SBC

#$2F

A975

85

07

STA

$07

A977

A5

15

LDA

$15

A979

85

22

STA

$22

A97B

C9

19

CMP

#$19

A97D

BO

D4

BCS

$A953

A97F

A5

14

LDA

$14

A981

OA

A982

26

A984

OA

is

22

ROL

22

ROL

$22

65

14

ADC

$14

A989

85

14

STA

$14

A98B

A5

22

LDA

$22

A98D

65

15

ADC

$15

A98F

85

15

STA

$15

A991

06

14

ASL

$14

A993

26

15

ROL

$15

A995

A5

14

LDA

$14

A997

65

07

ADC

$07

A999

85

14

STA

$14

A99B

90

02

BCC

$A99F

A99D

E6

15

INC

$15

A99F

20

73

00

JSR

$0073

A9A2

4C

71

A9

JMP

$A971

CHRGET

get

BASIC-LET

JSR

$B08B

49

STA

$49

84

4A

STY

$4A

save

A9

B2

LDA

#$B2

" = '

A9AE

20

FF

JSR

$AEFF

checks

A9B1
A9B3

A5
48

OE

LDA
PHA

$0E

save

A9B4

A5

OD

LDA

$0D

and

type

A9B6

48

$AD9E

get

term

20

8B

A9A8

85

A9AA
A9AC

9E

BO

AE

next

looks

character

evaluation

statement

-for

variable

variable

address

code
on

code

integer

-flag

flag

<l=string)

AD

JSR

PLA
ROL

A9BB

2A
20

90

A9BF

DO

18

A9C1

68

A9C2

10

AD

JSR

$AD90

BNE

$A9D9

get

back

and

check

type
on

-flag
correct

type

PLA
BPL

12

$A9D6

read?

*****************************

20

PHA

A9BC

A9C4

=
the

$16/$15

for

***** ****(***t-**-)t***4(*****

A9A5

20

in

o-f

$22

26

68

line

address

ASL

A985

A9BA

o-f

-Format

ASL

A987

A9B7

converts

address

IB

BC
Bl

Value

assignment

JSR

$BC1B

round
and

A9C7

20

BF

JSR

*B1BF

A9CA

AO

00

LDY

#$00

A9CC

A5

64

LDA

$64

A9CE

91

49

STA

change

bring

($49),Y

A-19

INTEGER

FAC

value

to

integer

into

variable

A9D0

C8

INY

A9D1

A5 65

LDA

A9D3

91

STA

A9D5

60

49

$65
($49),Y

RTS

*****************************

AQnA

AC.

no

RR

.IMP

*****************************

A9D9
A9DA
A9DC
A9DE

A9E0
A9E3
A9E5
A9E7

A9E9

68
A4
CO
DO
20
C9
DO
AO
84

PLA
4A
LDY
BF
CPY
4C
BNE
A6 B6 JSR
06
CMP
3D
BNE
00
LDY
61
STY

VAlue

assignment

bring

*RRnO

Value

FAC

#$BF

is

$AA2C
$B6A6

no

high

TI$?

FRESTR

string length = 6
no, "illegal quality"

#$06
$AA24
#$00
$61

A9EF

checks

A9F2

20 E2 BA

JSR

FAC

A9F5

E6 71

INC $71

A9F7

A4 71

LDY

A9F9
A9FC

20 ID AA JSR $AA1D
20 OC BC JSR $BCOC

A9FF

AA

AAOO

FO

AA02

E8

INX

AA03

8A

TXA

AA04

A9ED

string

address

variable

84 66
STY $66
84 71
STY $71
20 ID AA JSR $AA1D

A9EB

REAL

variable

assignment

variable

$4A

to

$BAE2

next

FAC

increase

$71

checks

copy

10

digit

next

FAC

number

to

counter

number

ARG

TAX
0?

$AA07

FAC

20 ED BA JSR

$BAED

FAC

AA07

A4 71

LDY

$71

increase

digit

AA09

C8

INY

AAOA

CO 06
DO DF

CPY
BNE

#$06
$A9ED

yet?

AAOC
AAOE

20

E2

BA

JSR

$BAE2

AA11

BC

JSR $BC9B
LDX $64

FAC = FAC * 10
make FAC right-binding

AA14

20 9B
A6 64

AA16

A4

63

LDY

AA18

A5

65

LDA $65

AA1A

4C

DB

05

BEQ

FF

JMP

LDA

digits

time

$63

set

$FFDB

*****************************

22

= FAC

that

ARG

was

counter

put

Check

number
number

AA1D

Bl

AA1F
AA22
AA24

20 80 00 JSR $0080
90 03
BCC $AA27
4C 48 B2 JMP $B248

"ILLEGAL

AA27
AA29

E9 2F
SBC
4C 7E BD JMP

change -from ASCII


transfer into FAC

#$2F
$BD7E

*****************************

AA2C

AO

02

LDY

AA2E

Bl

64

LDA

AA30

C5

34

CMP

$34

AA32

90

17

BCC

$AA4B

AA34

DO

07

BNE

$AA3D

AA36

88

AA37

Bl

64

LDA

($64),Y

AA39

C5

33

CMP

33

Value

in

t i me

check

($22),Y

QUANTITY"

assignment

to hex
and ARG

to

normal
string

#$02

string

($64),Y

address

compare

with

smaller,
within

DEY

string
compare

A-20

string

string
the

high

is

program

address

low

start

stored
space

string
AA3B

90

0E

BCC

$AA4B

AA3D

A4

65

LDY

$65

AA3F

C4 2E

CPY

$2E

AA41

90

08

BCC

$AA4B

AA43

DO

OD

BNE

$AA52

AA45

A5

64

LDA

$64

AA47

C5

2D

CMP

$2D

AA49
AA4B

BO
A5

07
64

BCS
LDA

$AA52
$64

AA4D

A4

65

LDY

$65

AA4F

4C 68 AA

JMP

$AA68
#$00

AA52

AO

00

LDY

AA54

Bl

64

LDA

AA56

20

75

AA59

A5

5O

B4

$B475

LDA

$50

AA5B

A4

51

LDY

$51

AA5D

85

6F

STA

$6F

AA5F

84

70

AA61

20

7A

AA64

A9 61

AA66

AO

AA68

85

AA6A

84

51

AA6C

20

DB

AA6F

AO

00

AA71

Bl

50

LDA

($50),Y

AA73

91

49

STA

($49),Y

STY

$70

JSR

$B67A

LDA

#$61

00

LDY

#$00

50

STA

$50

STY

$51

JSR

$B6DB

LDY

#$00

B6

B6

AA75

CB

AA76

Bl

50

LDA

($50),Y

AA78

91

49

STA

($49),Y

in

length

of

checks

memory

transfer

string
space,

string
string

clear

sets

pointer

into
range

descriptor
string

from
stack

length

I NY
address

AA7A

C8
Bl

50

LDA

($50),Y

and

AA7D

91

49

STA

($49),Y

bring

AA7F

60

AA80
AA83

20 86 AA JSR
4C B5 AB JMP

AA86
AA89

20
FO

9E
05

AA8B

A9

2C

AA8D
AA90

20
08

FF

low

I NY
address
into

high
variable

RTS
BASIC-PRINT#

B7

$AA86
$ABB5

CMD
to

PRINT

command

BASIC-CMD

command

gets

JSR $B79E
BEQ $AA90

command

command

byte

expression

LDA #$2C
AE

checks

JSR $AEFF

on

comma

PHP

AA91

86

13

STX

$13

save

AA93
AA96

20
28

18 El

JSR
PLP

$E118

set

out-put
output

AA97

4C AO

AA

AA9A

20

21

AB

JSR

$AB21

print

AA9D

20

79

00

JSR

$0079

last

35

devices
device

JMP $AAAO

******************#**********

FO

program

string

AA7B

AAAO

the

space

($64),Y

JSR

is

BEQ

$AAD7

A-21

string
character

BASIC-PRINT

command

AAA2

FO

43

BEQ

$AAE7

AAA4

C9

A3

CMP

#$A3

AAA6

FO

50

BEQ

$AAF8

AAA8

C9

A6

CMP

#$A6

AAAA

18

AAAB

FO

4B

BEQ

$AAF8

AAAD

C9

2C

CMP

#$2C

AAAF

FO 37

BEQ

$AAE8

AAB1

C9

CMP

#$3B

AAB3

FO

AAB5

20 9E

AAB8
AABA
AABC
AABF

3B

$AB13
AD JSR $AD9E
BIT $0D
24 OD
BMI $AA9A
30 DE
20 DD BD JSR $BDDD
20 87 B4 JSR $B487

BEQ

5E

AAC8
AACA

A9

00

AACC

9D

00

AACF

AAC5

code

"SPC<"

code

CLC

20 21 AB JSR $AB21
20 3B AB JSR $AB3B
BNE $AA9D
DO D3

AAC2

"TAB("

LDA

#$00

STA

$O2OO,X

A2 FF

LDX

#$FF

AADI

AO 01

LDY

#$01

AAD3

A5

13

LDA

$13

AAD5

DO

10

BNE

$AAE7

AAD7

A9

OD

LDA

#$0D

AAD9

20

02

get

term

type

-flag

string?

change FAC to ASCII


get

string

point

string

out-put

space

continue

input

bu-f-fer

finish

with

$0

set pointer

to

number o-f
<CR)

AAE2

20

JSR

$AB47

AAE5

49 FF

EOR

#$FF

AAE7

60

RTS

AAE8

38

AAE9

20

AAEC

98

AAED

38

AAEE

E9

OA

SBC

#$0A

AAFO

BO

FC

BCS

$AAEE

subtract

AAF2

49

FF

EOR

#$FF

not

AAF4

69 01
DO 16

ADC

#$01
$ABOE

add

AAF6

47

47

AB

logical
smaller
(LF)

FF

JSR

AAFA

128?

feed

get

tabulator

cursor

w/comma

position

SEC

BNE

AAFF
AB02

C9 29

CMP

AB04

DO 59

BNE $AB5F

AB06

28

PLP

AB07

90 06

BCC $ABOF

ABO9

8A

TXA

ABO A

E5

ABOC

90 05

BCC $AB13

ABOE

AA

TAX

09

SBC

10

negative

invert

08
PHP
38
SEC
20 FO FF JSR $FFFO
84 09
STY $09
20 9B B7 JSR $B79B

AAFD

than

line

decimal

$FFFO

TYA

*****************************

AAF8
AAF9

-File-number

output

SEC

FO

buffer

devices

carriage return

AAEO

AADE

input

out-put

output

AB JSR $AB47
BIT $13
24 13
BPL $AAE5
10 05
LDA #$0A
A9 OA

AADC

string

parameters

#$29

one

TAB(

<C=1)

save

and

get

cursor

and

save

it

get

byte

value

11)"
no,

closing
"SYNTAX

to

TAB

SPC(

(C=0)

flag

position

?
ERROR"

SPCC

value

in

ASCII

compare w/ cursor position


value less than position,

$09

then

A-22

ready

ABOF

E8

INX

AB1O

CA

DEX

ABU

AB13

DO
20

06
73

00

JSR

SAB 19
$0073

BNE

AB16

4C

A2

AA

JMP

$AAA2

AB19

20

3B

AB

JSR

$AB3B

AB1C

DO

F2

BNE

SAB 10

CHRGET get next character


and

*****************************

ABIE
AB21

20 87 B4 JSR $B487
2O A6 B6 JSR $B6A6

AB24

AA

TAX

AB25

AO 00

LDY

AB27

E8

INX

space

to

start

loop

Out-put

#$00

AB28

CA

DEX

FO BC

BEQ $AAE7

AB2B
AB2D

Bl 22
LDA ($22),Y
20 47 AB JSR $AB47

AB30

C8

AB31
AB33
AB35

C9 OD
CMP #$0D
DO F3
BNE $AB28
20 E5 AA JSR $AAE5

no,

AB38

4C 28 AB JMP $AB28

and

string

end?

string

character

output

INY

11CR"

A5

13
03

AB3D

FO

A9 20
2C

LDA #$20
-BYTE $2C

AB48
AB4A

A9
2C

ID

LDA #$1D
-BYTE $2C

AB4B

A9

3F

AB47

20

OC

AB4A

29

FF

AB4C

60

Out-put

El

LDA

#$3F

JSR

$E10C

AND

#$FF

11

"?"
set

Error

LDA $11
BEQ $AB62

flag

AB51

30

04

BMI

READ

AO

FF

LDY

#$FF

DO

04

BNE

$AB5B

LDA $3F
LDY $40

84

3A

4C

08

AF

Error
data

*****************************

STA

for

at

input

INPUT/GET/READ

GET

*****************************

A5 3F
A4 40

treatment

INPUT

$AB57

AB53

mark

flags

11
11

AB55

right

question

A5
FO

AB5D

character

out-put

AB4D
AB4F

AB5F

empty

sqace

cursor

*****************************

39

an

BEQ $AB42

RTS

85

code

continue

LDA $13

AB3F
AB47

AB5B

carriage return
continue

invert

*****************************

AB57
AB59

string

get string paremeter


FRESTR
string length

AB29

AB3B

continue

out-put

Error

at

READ

line-number

at

GET

$39

STY

$3A

is

line

number

JMP

$AF08

"SYNTAX

ERROR"

*****************************

Error

at

mistake

INPUT

AB62

A5

13

LDA

$13

number

AB64

FO

05

BEQ

$AB6B

keyboard?

AB66

A2

18

LDX

#$18

number

A-23

of

of

for

input

device

"FILE DATA"

A4

JMP

$A437

LDA

#$0C

LDY

#$AD

JSR

$AB1E

AB6B

4C

37

AB6B

A9

OC

AB6D

AO

AD

AB6F

20

IE

AB72

A5

3D

LDA

$3D

AB74

A4

3E

LDY

$3E

AB76

85

7A

STA

$7A

AB78

84

7B

STY

$7B

AB7A

60

AB

out-put

error

message

pointer to "?REDO FROM


out-put string
START
program pointer
to

INPUT

command

BASIC-BET

command

back

RTS

*****************************

AB7B

20 A6 B3 JSR $B3A6

AB7E

C9

23

CMP

#$23

AB80

DO

10

BNE

$AB92

AB82

20

73

OO

JSR

$0073

9E

B7

JSR

$B79E

LDA

#$2C

JSR

$AEFF

STX

$13

JSR

$E11E
#$01

AB85

20

AB88

A9

2C

AB8A

20

FF

AB8D

86

13

AB8F

20

IE

AE

El

AB92

A2

01

LDX

AB94

AO

02

LDY

#$02

AB96

A9

00

LDA

#$00

AB98

8D

01

AB9B

A9

40

AB9D

20

OF

ABAO

A6

ABA2

DO

ABA4

60

02

"#"

#$40

JSR

$ACOF

13

LDX

$13

13

BNE

$ABB7

no?
get

next

character

get

byte

value

","

comma

checks on
GET

gets

code
a a character

pointer to buffer end= $201


buffer ends with $201 and$0

STA $0201
LDA

AC

checks on direct mode

GET

flag

value asignment
input

not

to variable

device

keyboard,

then

CLRCH

RTS

*****************************

ABAS
ABA8
ABAA
ABAD
ABAF
ABB2

20
A9
20
86
20
20

9E
2C
FF
13
IE
CE

B7 JSR
LDA
AE JSR
STX
El JSR
AB JSR

ABBS

AS

13

ABB7
ABBA

20 CC FF JSR $FFCC
A2 00
LDX #$00

ABBC

86

ABBE

60

ii

STX

bute
on

comma

input

device

get

character

INPUT
sets

w/o

dialog

back

input

$13

command

va:ie

ii

checks

LDA $13

13

BASIC-INPUT*
gets

$B79E
#$2C
$AEFF
$13
$E11E
$ABCE

input

device

is

string
device
keyboard

RTS

*****************************

ABBF
ABC1

C9 22
DO OB

CMP #$22
BNE $ABCE

ABC3

20 BD

AE JSR $AEBD

ABC6

A9

3B

ABC8

20

FF

AE

ABCB

20

21

AB JSR

ABCE

20

A6

B3

ABD1

A9

2C

ABD3
ABD6

8D
20

FF
F9

ABD9

AS

13

LDA

BASIC-INPUT
H

(H)

command

inverted

comma

no

get

dialog

string

semicolon

#$3B

checks

JSR $AEFF

out-put

$AB21

JSR $B3A6

checks

LDA #$2C

11,"

01 STA $0IFF
AB JSR $ABF9
LDA

to

on

buffer

number

A-24

code

string
direct

mode

comma

out-put

$13

on

start

question
of

input

mark
device

ABDB
ABDD
ABEO

ABE2
ABE4

ABE7
ABEA

ABED
ABEF
ABF1
ABF3

ABF6
ABF9

ABFB
ABFD

FO OD
BEQ $ABEA
20 B7 FF JSR $FFB7
29 02
AND #$02
FO 06
BEQ $ABEA

get

Time-out?

yes, CLRCH, reset keyboard


execute next statement

20

06 A9 JSR $A906
4C FB A8 JMP $ABFB
A5 13
LDA
DO 06
BNE $AC03

AC03

20 45 AB JSR $AB45
AB JSR $AB3B
4C 60 A5 JMP $A560

AC06

A6

41

AC08

A4

ACOA

ACOO

keyboard?
status

20 B5 AB JSR $ABB5
4C F8 A8 JMP $ABF8
AD OO O2 LDA $0200
DO IE
BNE $ACOD
A5 13
LDA
DO E3
BNE $ABD6

get
yes,

not

20 3B

LDX

$41

42

LDY

$42

A9 98

LDA

#$98

ACOC

2C

A9

ACOF

85

11

STA

$11

AC11

86 43

STX

$43

AC13

84

44

STY

$44

AC15

20

8B

AC18

85

49

AC1A

84

4A

STY

$4A

AC1C

A5 7A

LDA

$7A

AC1E

A4

7B

LDY

$7B

AC20

85

4B

STA

$4B

AC22

84

4C

STY

$4C

AC24

A6

43

LDX

$43

AC26

A4

44

LDY

$44

input

device

out-put

"?"

output

space

input

line

BASIC-READ command
get DATA pointer
READ flag

set

JSR $B08B
STA

character

keyboard?

get

00 BIT $00A9

BO

-first

end?

INPUT pointer to input


looks for variable

$49

save

variable

address

undersave program pointer


in

$4b/$4c

AC28

86

7A

STX

$7A

INPUT pointer

AC2A

84

7B

STY

$7B

equals program pointer

AC2C

2O

79

JSR

$0079

AC2F

DO

20

BNE

$AC51

AC31

24

11

BIT

$11

AC33

50

OC

BVC

$AC41

AC35

20

24

El

JSR

$E124

AC38

8D

OO

02

STA

$0200

AC3B

A2 FF

LDX

#$FF

AC3D

AO

LDY

#$O1

AC3F

DO

OC

BNE $AC4D

AC41

30

75

BMI

$ACB8

AC43

A5

13

LDA

$13

AC45

DO

03

AC47

20

45

AC4A

20

F9

AC4D

86

7A

AC4F

84

7B

AC51

20 73

AC54

24

OD

AC56

10

AC58

24

00

CHRGOT gets

last

input

flag

write

character

BNE $AC4A

input

device

AB

JSR $AB45

not

AB

JSR $ABF9

out-put

"?"

STX

$7A

out-put

second

STY

$7B

set

program

JSR $0073
BIT $OD

get

next

31

BPL

$AC89

type

11

BIT

$11

01

00

A-25

character

into

keyboard?

flag

"?"

pointer

character

buffer

BVC

$AC65

AC5A

50

AC5C

E8

AC5D

86

7A

STX

$7A

AC5F

A9

00

LDA

#$00

AC61

85

07

STA

$07

AC63

FO

OC

BEQ

$AC71

AC65

85

07

STA

$07

AC67

C9

22

CMP

#$22

AC69

FO

07

BEQ

$AC72

AC6B

A9

3A

LDA

#$3A

AC6D

85

07

STA

$07

AC6F

A9

2C

LDA

#$2C

AC71

18

AC72

85

08

STA

AC74

A5

7A

LDA $7A

AC76

A4

7B

LDY

$7B

AC78

69

00

ADC

#$00

AC7A

90

01

BCC

$AC7D

AC7C

C8

AC7D

20

8D

B4

JSR

$B48D

AC80

20

E2

B7

JSR

$B7E2

AC83

20

DA

A9

JSR

$A9DA

AC86

4C

91

AC

JMP

$AC91

continue

AC89

2O

F3

BC

JSR

$BCF3

get

AC8C

A5

OE

LDA

$0E

INTEGER/REAL

AC8E

20

C2

A9

JSR

$A9C2

assign

AC91

2O

79

00

JSR

$0079

get

AC94

FO

07

BEQ

$AC9D

end?

AC96

C9

2C

CMP

#$2C

AC98

FO

03

BEQ

$AC9D

AC9A

4C

4D

JMP

$AB4D

AC9D

A5

7A

LDA

$7A

AC9F

A4

7B

LDY

$7B

ACA1

85

43

STA

$43

ACA3

84

44

STY

$44

ACA5

A5

4B

LDA

$4B

ACA7

A4

4C

LDY

$4C

ACA9

85

7A

STA

$7A

ACAB

84

7B

STY

$7B

ACAD

20

79

JSR

$0079

ACBO

FO

2D

BEQ

$ACDF

ACB2

20

FD

AE

JSR

$AEFD

checks

ACB5

4C

15

AC

JMP

$AC15

continue

ACB8

2O

06

A9

JSR

$A9O6

look

-for

ACBB

C8

ACBC

AA

line

end?

ACBD

DO

12

BNE

$ACD1

no

ACBF

A2

OD

LDX

#$OD

ACC1

C8

ACC2

Bl

7A

LDA

ACC4

FO

6C

BEQ

ACC6

C8

ACC7

Bl

7A

LDA

ACC9

85i

3F

STA

ACCB

C8

O9

I NX

>

inverted

comma

CLC
$08

I NY

AB

00

take over

string

program pointer
assign

to

string

digit

behnd

to

string

in

FAC to #

variable

character

error

treatnebt

equals

pointer

DATA

pointer

get

back

program

get

last

character

on

pointer

comma

next

statement

I NY

TAX

I NY
($7A),Y

$AD32

end

I NY

o-f

"OUT
($7A),Y
$3F

I NY

A-26

FAC

flag

last

program

strng

variable

program?

OF

DATA"

X=0

ACCC

Bl

ACCE

C8

7A

LDA

<$7A),Y

INY

ACCF

85

40

STA

$40

ACD1

20

FB

A8

JSR

$A8FB

ACD4

20

79

OO

JSR

$0079

ACD7

AA

ACD8

EO

83

CPX

#$83

ACDA

DO

DC

BNE

$ACB8

ACDC

4C

51

JMP

$AC51

ACDF

A5

43

LDA

$43

ACE1

A4

44

LDY

$44

ACE3

A6

11

LDX

$11

program

get

TAX

AC

pointer

last

keep

read
input

pointer

-flag

$ACEA

no

DATA?

at

DATA

OO

LDY

#$00

Bl

43

LDA

FO

OB

BEQ

$ACFB
$13

ACEA

AO

ACEC
ACEE

A8

looking

input

$A827

03

27

pointer

($43),Y

ACFO

A5

13

LDA

ACF2

DO

07

ACF4

A9

FC

ACF6

AO

AC

BNE $ACFB
LDA #$FC
LDY #$AC

pointer

to

ACF8

4C

IE

JMP

out-put

stri ng

ACFB

60

"7EXTRA

IGNORED"

AB

SAB IE

"EXTRA

IGNORED"

RTS

ACFC

3F

45

58

54 52

41

20

49

AD04

47

4E

4F

52

45

44 OD

00

ADOC 3F

52

45

44

4F

20

AD14 4F

4D

20 53 54 41

AD1C

st

atement

data

JMP

10
4C

next

"DATA"
no,

BPL

ACES
ACE7

to

character

46 52
52

"?REDO

FROM

START"

54

OD

******** * ****** ** **** ****** **

AD1E

DO

04

BNE

$AD24

AD20

AO

00

LDY

#$00

BEQ

$AD27

JSR

$BOBB

BASIC-NEXT

does

AD22

FO

O3

AD24

20

8B

AD27

85

49

STA

$49

AD29

84

4A

STY

$4A

variable

AD2B

20

8A A3

JSR

$A38A

looks

-for

AD2E

FO

05

BEQ

$AD35

found

it

AD30

A2

OA

LDX

#$0A

number

AD32

4C

37

JMP

$A437

out-put

AD35

9A

TXS

AD36

8A

TXA

AD37

18

AD38

69

AD3A

48

AD3B

69

06

ADC

#$06

AD3D

85

24

STA

$24

AD3F

68

AD40

AO

01

AD42

2O

A2

AD45

BA

AD46

BD

09

AD49

85

AD4B

A5

BO

A4

command

variable

looks

-for

name follow?

variable
address

FOR-NEXT

in

for

loop
stack

"NEXT W/0

error

FOR"

message

CLC

04

ADC

#$04

PHA

PLA

BB

LDY

#$01

JSR

$BBA2

get

variable

01

from
put

TSX

LDA

$0109,X

66

STA

$66

49

LDA

$49

variable

A-27

address

stack,
in

FAC

AD4D

A4

4A

LDY

$4A

AD4F

20

67

B8

JSR

$B867

AD52

20

DO

BB

JSR

$BBDO

AD55

AO

01

AD57

20 5D

AD5A

BA

TSX

AD5B

38

SEC

AD5C

FD 09

AD5F

FO

AD61

BD OF

AD64

85

39

AD66

BD

10

AD69

85

3A

AD6B

BD

12

AD6E

85 7A

AD70

BD

11

AD73

85

7B

AD75

4C

AE

AD78

8A

AD79

69

AD7B

AA

AD7C

9A

AD7D

20

79

AD80

C9

2C

adds STEP value to FAC


bring FAC to variable

LDY

BC

01

17
01

01
01

01

A7

JSR

compare FAC with

$BC5D

SBC

$0109,X

BEQ

$AD78

LDA

$010F,X

STA

$39

LDA

$0110,X

STA

$3A

LDA

$0112,X

STA

$7A

LDA

$0111,X

STA

$7B

ADC

11

line

get

program pointer

to

number

interpreter

loop

#$11

TAX
TXS
00

JSR

$0079

CMP

#$2C

DO Fl

BNE

$AD75

AD84

73

00

JSR

$0073

AD87

20

24

AD

JSR

$AD24

CHRGOT

9E

AD

JSR

*****************************

18

last

character

comma

no,

then

done

get

next

character

Get

NEXT-variable

term and

get

$AD9E

get

11,"

next

*****************************

AD8D

get

1 oop

TXA

20

20

value

o-f

JMP $A7AE

AD82

AD8A

end

check

numberic

term

Checks

on

numeric

Checks

on

string

CLC

AD8E 24
*****************************

AD8F

38

SEC

AD90

24

OD

BIT

$0D

AD92

30

03

BMI

$AD97

03

BCS

$AD99

AD94

BO

AD96

60

AD97

AD99

BO
A2

FD
16

AD9B

4C

37

A4

$AD96
#$16

JMP

$A437

output

LDX

$7A

DO

02

BNE

$ADA4

C6

7B

DEC

$7B

ADAO
ADA2

"TYPE

BCS
LDX

7A

A6

type

-flag

RTS

ADA4

C6

7A

DEC

$7A

ADA6

A2

00

LDX

#$00

ADA8

24

.BYTE

ADA9

48

PHA

ADAA

8A

TXA

ADAB

48

PHA

for

FRMEVL

***** ***]********-***)******

AD9E

check

A-28

message

evaluation

decrease

$24

MISMATCH"

error

program

o-f

term

pointer

ADAC

A9

01

LDA

#$01

ADAE

20

FB

A3

JSR

$A3FB

checks

ADB1

20

83

AE

JSR

$AEB3

get

ADB4

A9

00

LDA

#$00

ADB6

85

4D

STA

$4D

ADB8

20

79

JSR

$0079

ADBB

38

ADBC

E9

Bl

SBC

#$B1

ADBE

90

17

BCC

$ADD7

ADCO

C9

O3

CMP

#$03

ADC2

BO

13

BCS

$ADD7

ADC4

C9

Ol

CMP

#$01

ADC6

2A

ADC7

49

01

EOR

#$01

ADC9

45

4D

EOR

$4D

ADCB

C5

4D

CMP

$4D

ADCD

90

61

BCC

ADCF

85

4D

STA

$AE30
$4D

ADD1
ADD4

20
4C

73
BB

JSR
JMP

$0073
$ADBB

ADD7

A6

4D

LDX

$4D

ADD9

DO

2C

BNE

$AEO7

ADDB

BO

7B

BCS

$AE58

ADDD

69

07

ADC

#$07

ADDF

90

77

BCC

$AE58

ADE1

65

OD

ADC

$0D

ADE3

DO

03

BNE

$ADE8

ADE5

4C

3D

JMP

$B63D

ADE8

69

FF

ADC

#$FF

ADEA

85

22

STA

$22

ADEC

OA

ADED

65

ADEF

A8

00

bytes
on

next

mask
get

-for
last

fre

stack

space

character

compare

operator

character

SEC

mask

ROL

00

AD

B6

-for

CHRGET

<,

get

=,

or

next

>

characte

back

string
code

linkage

$AA

ASL
ADC

22

$22

times

CMP

$A0BO,Y

BCS

$AE5D

compare with

JSR

$ADBD

checks

$AE2O

operator

TAY

ADFO

68

ADF1

D9

80

ADF4

BO

67

ADF6

20

8D

ADF9

48

ADFA

20

ADFD

68

ADFE

A4

4B

LDY

$4B

AEOO

10

17

BPL

$AE19

AE02

AA

three

PLA
AO

AD

on

order

flag

numeric

PHA
2O

AE

JSR
PLA

address

operands

on

and

stack

TAX

AE03

FO

56

BEQ

$AE5B

AE05

DO

5F

BNE

$AE66

AE07

46

OD

LSR

$0D

AE09

8A

AEOA

2A

AEOB

A6

7A

LDX

$7A

AEOD

DO

02

BNE

$AE11

AEOF

C6

7B

DEC

$7B

AE11

C6

7A

DEC

$7A

AE13

AO

IB

LDY

#*1B

o-f-fset

AE15

85

4D

STA

$4D

set

clear

string

-flag

TXA
ROL

decrease

A-29

o-F

flag

program

order

pointer

flag

BNE

$ADFO

CMP

$AO8O,Y

BCS

$AE66

AE17

DO D7

AE19

D9

80

AE1C

BO

48

AE1E

90

D9

AE20

B9

82

AO

81

AO

AE

JSR $AE33

operands

on

stack

to

of

loop

AE23

48

AE24

B9

AO

BCC

$ADF9

LDA

$A082,Y

compare

operation

PHA

20

33

AE2B

A5

4D

AE2D

4C

A9

AD

LDA $4D
JMP $ADA9

AE3O

4C

08

AF

JMP

$AF08

g i ves

AE33

A5

66

LDA

$66

signs

AE35

BE

80

LDX

$AO8O,Y

order

AE38

A8

AO

68

PLA

AE3A

85 22

STA

$22

AE3C

E6

22

INC

$22

AE3E

68

AE3F

85

AE41

98

TYA

AE42

48

PHA

AE43

20

IB

AE46

A5

65

AE48

48

AE49

A5

AE4B

48

AE4C

A5

AE4E

48

AE4F

A5

AE51

48

AE52
AE54

A5
48

61

AE55

6C

22

AE58

AO

FF

STA

23

BC

LDA
LDA

63

LDA

62

FAC

LDA

$61

PHA
OO

JMP
LDY

($0022)

BEQ $AE64

AE61

20

8D

AE64

84

4B

AE71

85

AE73

68

AE74

85

AE76

AE77

68
85

AE79

68

to

operation

PLA
CMP

68

jump

#$FF

03

85

stack

PHA

FO

AE70

on

$62

AE5F

AE6E

FAC

$63

PHA

BEQ $AE80

68

round

$64

64

85

address

PHA

C9

AE6D

return

PHA
64

AE5D

AE6B

flag

LDA $65

23

68

save

JSR SBC IB

68

AE6A

ERROR"

sign

FO

85

"SYNTAX

$23

AE5B

AE68

start

PLA

AE5A

68

on

TAY

AE39

4A

address

-flag

PHA

48

AE28

AE66

order

LDA $A081,Y

AE27

AE67

with

AD

#$64

JSR $AD8D
STY

checks

on

numeric

$4B

PLA
LSR
12

STA

$12

PLA
69

STA

$69

PLA

6A

STA

$6A

PLA
6B

STA

get
$6B

PLA
6C

STA

$6C

PLA
6D

STA

$6D

PLA

A-30

ARG

from

stack

stack

AE7A
AE7C

85 6E
45 66

STA $6E
EOR $66

AE7E

85 6F

STA

AE80
AE82

A5 61
60

LDA

$6F

RTS

*****************************

AE83

6C OA 03 JMP

<$030A>

Get ari thmeti c


JMP $AE86

AE86

A9

AE88

85 OD

AE8A

20 73 OO JSR

AE8D

BO

AE8F

4C

AE92
AE97

20 13 Bl JSR $B113
90 03
BCC $AE9A
4C 28 AF JMP $AF28

no

AE9A

C9

FF

CMP

AE9C

DO

OF

BASIC

BNE $AEAD

AE95

00

LDA

#$00

STA $0D

get

03

BCS $AE92
F3 BC JMP $BCF3

AE9E

A9

A8

LDA

#$A8

AO

AE

LDY

#$AE

AEA2

20 A2 BB JSR

next

on

numeric

character

digit?
get variable to FAC
letter?
get

#$FF

AEAO

AEA5

type flag

$0073

term

variable

code

pointer

$BBA2
4C 73 00 JMP $0073

get

for

to Pi

cpmstamt

Pi?
constant

tp

FAC

*****************************

AEA8
AEAD

82
C9

49 OF
2E

DA

A1

Constant

CMP

#$2E

$AE8F

AEAF

FO

DE

BEG

AEB1

C9

AB

CMP

#$AB

AEB3

FO

58

BEQ

$AFOD
#$AA

AEB5

C9

AA

CMP

AEB7

FO

Dl

BEQ

$AE8A

AEB9

C9

22

CMP

#$22

AEBB

DO

OF

BNE

$AECC

AEBD

A5

7A

LDA

$7A

AEBF

A4

7B

LDY

$7B

AEC1

69

00

ADC

#$00

01

BCC

$AEC6

AEC3

90

AEC5

C8

get

Pi

3.14159265

program

pointer

I NY

AEC6

20

87

B4

JSR

$B487

transfer

AEC9

4C

E2

B7

JMP

$B7E2

program

AECC

C9

A8

CMP

#$AS

AECE

DO

13

BNE

$AEE3

AEDO

AO

18

LDY

#$18

AED2

DO

3B

BNE

$AFOF

"NOT"

string
pointer

to

string
end + 1

code

offset

of

order

f1ag

in

list

XXXIE'**iM[ X1 X )(' 'M1 X X M

AED4

20

BF

JSR

$B1BF

AED7

A5

65

LDA

$65

AED9

49

FF

EOR

#$FF

AEDB

A8

AEDC

A5

64

LDA

$64

AEDE

49

FF

EOR

#$FF

AEEO

4C

91

JMP

$B391

Bl

change

turn

FAC

around

C9

integer

all

bits

TAY

B3

return

to

*****************************

AEE3

to

A5

CMP

#$A5

11FN"

A-31

code

running

comma

AEE5

DO

AEE7

4C F4

O3

B3

BNE

$AEEA

JMP

$B3F4

execute

IN

*****************************

AEEA

C9 B4

AEEC
AEEE

90 03
BCC $AEF1
4C A7 AF JMP $AFA7

"SGN

CMP #$B4

for

*****************************

AEF1

20 FA AE JSR $AEFA

AEF4

2O 9E AD

JSR $AD9E

*****************************

29

LDA

28

LDA #$28

A9

2C

.BYTE $2C
LDA #$2C

AO

00

LDY

AF01

Dl

7A

CMP

AF03

DO 03

AF05

4C

73

AF08

A2

OB

AFOA

4C 37

AFOD

AO

AFOF

68

AF10

68

AF11

4C FA

AF14

38

AF15

A5

64

LDA

$64

AF17

E9

00

SBC

#$OO

AF19

A5

65

LDA

$65

AF1B

E9

AO

SBC #$A0

AF1D

90 08

BCC

$AF27

AF1F

A9

A2

LDA

#$A2

AF21

E5

64

SBC

$64

AF23

A9

E3

LDA

#$E3

AF25

E5

65

SBC

$65

AF27

60

AEF7

A9

AEF9

2C

AEFA

A9

AEFC
AEFD

2C

AEFF

#$29

.BYTE

00
A4

15

code

smaller

Gets

(no

-function)?

calculation
term

in

checks

on

FRMEVL

gets

Checks on

of

-function

parenthesis

parenthesis

character

")"

closeing

11 ("

opening

in

parenthesis

#$00

compare

<$7A> *

BNE $AF08

no

JMP

$0073

get

LDX

#$0B

next

for

curent

number

character

"SYNTAX

JMP $A437

out-put

LDY

offset

#$15

with

concurrence?

ERROR"

error

order

message

code

change

of

for
sign

PLA
for

JMP $ADFA

evaluation

SEC

RTS
****************

********

AF28

20

8B

AF2B

85

BO

JSR

$B08B

64

STA

$64

Get

variable

look

for

points

84

65

STY

$65

A6

45

LDX

$45

AF31

A4

46

LDY

$46

variable

AF33

A5

OD

LDA

$OD

type

AF35

FO

26

BEQ

$AF5D

numeric?

AF37

A9

00

LDA

#$00

AF39

85

70

AF3B

2O

14

JSR

$AF14

AF3E

90

1C

BCC

$AF5C

AF4O

EO

54

CPX

#$54

DO

18

BNE

$AF5C

AF44

CO

C9

CPY

#$C9

variable

string

STA $70

AF42

variable

to

AF2D
AF2F

AF

text

parenthesis

$2C

PLA

AD

open

term

ii-rii

11 I$"

A-32

flag

or

descriptor

name

AF46

DO

14

AF48

20

84

AF4B

84

BNE

$AF5C

JSR

$AF84

5E

STY

$5E

AF

AF4D

88

AF4E

84

71

STY

AF50

AO

06

LDY

#$06

AF52

84

5D

STY

$5D

get

time

DEY

$71

AF54

AO

24

LDY

#$24

AF56

20

68

BE

JSR

$BE68

AF59

4C

6F

B4

JMP

$B46F

AF5C

60

AF5D

24

OE

BIT

$OE

AF5F

10

OD

BPL

$AF6E

AF61

AO

00

LDY

#$00

AF63

Bl

64

LDA

AF65

AA

AF66

C8

AF67

Bl

AF69

A8

produces

string

RTS

INTEBER/REAL

-flag

REAL?

($64),Y

TAX

get

i nteger

and

change

number

I NY
64

LDA

($64),Y

TAY

AF6A

8A

AF6B

4C

91

B3

JMP

$B391

AF6E

20

14

AF

JSR

$AF14

AF71

90

2D

BCC

$AFAO

AF73

EO

54

CPX

#$54

AF75

DO

IB

BNE

$AF92

AF77

CO

49

CPY

#$49

AF79

DO

25

BNE

$AFAO

AF7B

20

84

JSR

$AF84

AF7E

98

AF7F

A2

AO

AF81

4C

4F

TXA

AF

to

running

po

11T"

"I"

get

TIME

to

FAC

TYA
BC

LDX

#$A0

JMP

$BC4F

*****************************

AF84

20

DE

AF87

86

AF89
AFBB

AF8D

FF

Get

time

get

TIME

and

into

JSR

$FFDE

64

STX

$64

84

63

STY

$63

85

65

STA

$65

AO

00

LDY

#$00

AF8F

84

62

STY

$62

AF91

6O

AF92

EO

53

CPX

#$53

AF94

DO

OA

BNE

$AFAO

AF96

CO

54

CPY

#$54

AF98

DO

06

BNE

$AFAO

AF9A

20

B7

FF

JSR

$FFB7

get

AF9D

4C

3C

BC

JMP

$BC3C

change byte

AFAO

A5

64

LDA

$64

AFA2

A4

65

LDY

$65

variable

AFA4

4C

A2

JMP

$BBA2

get

AFA7

OA

-floating

point

accumulator

RTS

BB

S"
"T"

48

PHA

AFA9

AA

TAX

AFAA

20

73

AFAD

EO

8F

AFAF

90

20

AFB1

20

FA

OO

AE

character

BCC

$AFD1

function

JSR

$AEFA

checks on

A-33

in

times

next

to

-format

address

code

$0073
#$8F

accum.

point

variable

CPX

JSR

in

floating

ASL

AFA8

status

FAC

code?
parentheses

op

q.uxod Bui^eoxj- oq. aBueq=>

*****************************

I68$ dWP 8
ao*

9UW

U03

BciJ-

16 3fr

108
noa

st

ao

S3 d008

LO

80

H03

da

S17

S3

S"b
03

aooa
aooa

W008
8008

9008

"bOOa
300a
dddw

la

80 S8
80

dO3

Str

S8

WddW
8ddW

9ddw
trddW

3ddW
oddw

30 \rB

oo ow

33

dwr

aw

08

3"b
03

83dW
93dW

L.dW
03dW

3adW

sadw

8W

AWl

9adw

A*W3d6$ wan d6 W3 63

dsr

Td3W$

d8aw$

uo

sq.a6

sw

3ddW

88 3d 03

tflS

S9 sw

wan

80 1?
t>9 sw

d8T8$ WSr T3 d3 03
9O$ A1S

oo$# Aan

*****************************

dd OW

dd$# Aan

33$ 3XA8"

*****************************
a8aw$

frS

9S 58

WJ.S

sadw

W1S

89

wnd
dwr

ad3W$

uo

Aue

s*

sw

^9

wan

80

aNW

S9

wan

3d33$ dSP
80$

^as

aNW-3ISW3

joj.

uo

9S$

3ISW9

ux

ao

8W

AWl

30

30$ dO3

80$

S9$

3Wd

LO

W1S

80$ U03
1^9$ wan

o^ 3Wd aBueup
Bt?i

aNy -joj* ^ei^

pueuiuioD

yO

pueuiuiOD ao-3ISW8
Dxjauinu

00

"bSOO$

6adW

SS S8

A*33d6$ wan d6 83 68
ss$

jo^dba

apoD

sasaqq.uaJBd

9adW$

3W
dW

Td
9a

36aw$

03
317

8W

AWl

W8

wxx

8ir

WHd

89

wnd

36218$

a^Aq

1^9$

36 03

t-adw

xadw

33dW

a3dw
33dW

83dW
W3dW
Z3dW
93dW
1r3dW

8tr

WHd

S3dW

W8

WXl

3ir

WHd

tr9

wan

SW
81r

WHd

S9$

sasaq^ua-ied

S9

wan

SW
89

wnd

WW

XWl
aw

3W
USD

aw

d8
ad
36

03
03
03

33dW
I3dW

d8dW

38dW
a8dW
W8dW
8dW
ir3dW

BO 16

20

9O

B019

BO

13

AD

JSR

$AD90

check

BCS

$B02E

strint?

$6E

BO1B

A5

6E

LDA

BO1D

09

7F

BO1F

25

6A

ORA #$7F
AND $6A

B021

85

6A

STA

$6A

B023

A9

69

LDA

#$69

B025

AO

00

LDY

#$00

5B

JSR

B027

20

BO2A

AA

BO2B

4C

BC

ARG

A9

in

same

variable

then

continue

memory

-Format

address

of

$BC5B

compare

ARG

$B061

get

type

ARG

with

FAC

TAX
61

BO

JMP

***** ***AL**41**4I****t-****JL

B02E

on

00

LDA

#$00

B030

85

OD

STA

$OD

B032

C6

4D

DEC

$4D

result

String
clear

to

comparison
string

-Flag

B034

20

A6

JSR

$B6A6

FRESTR

B037

85

61

STA

$61

string

length

B039

86

62

STX

$62

B03B

84

63

STY

$63

string

address

B03D

A5

6C

LDA

$6C

LDY

$6D

pointer

JSR

$B6AA

FRESTR

B03F

A4

6D

B041

20

AA

B6

B6

FAC

to

second

string

second

string

B044

86

6C

STX

$6C

B046

84

6D

STY

$6D

address

o-F

B048

AA

lengths

TAX

B049

38

B04A

E5

61

SBC

$61

compare

B04C

FO

08

BEQ

$B056

equal?

#$01

SEC

B04E

A9

01

LDA

B050

90

04

BCC

$B056

B052

A6

61

LDX

$61

B054

A9

FF

LDA

#$FF

B056

85

66

STA

$66

B058

AO

FF

LDY

#$FF

B05A

E8

B05B

C8

I NY

B05C

CA

DEX

B05D

DO

07

BNE

$B066

B05F

A6

66

LDX

$66

B061

30

OF

BMI

$B072

B063

18

B064

90

OC

BCC

B066

Bl

6C

LDA

B068

Dl

62

CMP

B06A

FO

EF

BEQ

$B05B

B06C

A2

FF

LDX

#$FF

B06E

BO

O2

BCS

$B072

B070

A2

01

LDX

#$01

B072

E8

second

string

shorter

INX

CLC

$B072

comparison

($6C),Y

o-F

strings

characterwise

($62),Y

INX

B073

8A

TXA

B074

2A

ROL

B075

25

12

AND

$12

B077

FO

02

BEQ

$B07B

B079

A9

FF

LDA

#$FF

get

A-35

result

to

FAC

B07B

4C

3C

BC

JMP

$BC3C

B07E

20

FD

AE

JSR

$AEFD

checks

*****************************

B081

AA

on

BASIC-DIM

comma

command

TAX

dimension

variable

B082

20

90

BO

JSR

$B090

B085

2O

79

OO

JSR

$0079

get

last

character

B088

DO

F4

BNE

$B07E

not

end,

next

B08A

6O

LDX
JSR

#$00

flag

$0079

get

last

STX
STA

$0C

set

DIM-flag

RTS

-for

non-dimensioning

B08B

A2

00

B08D

20

79

B090

86

OC

B092
B094

B5

45
79

$45

variable

20

00

JSR

$0079

CHRGOT

get

B097

2O

13

Bl

JSR

$B113

checks

on

B09A

BO

03

BCS

$B09F

yes

B09C

4C

08

JMP

$AF08

"SYNTAX

B09F

A2

00

LDX

#$00

B0A1

86

OD

STX

SOD

clear

string

B0A3

86

OE

STX

$0E

clear

integer

BOAS

20

73

JSR

$0073

get

B0A8

90

05

BCC

$BOAF

digit?

BOAA

20

13

JSR

$B113

chhecks

BOAD

90

OB

BCC

$BOBA

no

BOAF

AA

BOBO

20

73

B0B3

90

FB

B0B5

20

13

B0B8

BO

BOBA

00

AF

00

Bl

character
name

last

ERROR"

next

flag
-flag

character

on

letter

second

letter

$0073

CHRGET

get

BCC

$BOBO

digit?

JSR

$B113

checks

F6

BCS

$BOBO

yes,

C9

24

CMP

#$24

BOBC

DO

06

BNE

$B0C4

BOBE

A9

FF

LDA

#$FF

BOCO

85

OD

STA

$0D

set

B0C2

DO

10

BNE

$BOD4

jump

B0C4

C9

25

CMP

#$25

"7."

B0C6

DO

13

BNE

$BODB

no

B0C8

A5

10

LDA

$10

integer

BOCA

DO

DO

BNE

$BO9C

no,

BOCC

A9

80

LDA

#$80

BOCE

85

OE

STA

$0E

BODO

05

45

ORA

$45

B0D2

85

45

STA

$45

B0D4

8A

B0D5

09

B0D7

AA

Bl

character

letter

JSR

TAX
00

variable

on

read

of

next

name
character

letter
more

characters

no

string

flag

permitted?

"SYNTAX

ERROR"

set

integer

flag

set

bit

in

name

TXA

#$80

second

leter

JSR

$0073

CHRGET

get

STX

$46

save

ORA

80

of

name

TAX
OO

B0D8

2O

73

BODB

86

46

BODD

38

BODE

05

10

ORA

$10

BOEO

E9

28

SBC

#$28

ii

B0E2

DO

03

BNE

$B0E7

not

B0E4

4C

Dl

JMP

$B1D1

process

second

next

character

letter

SEC

Bl

B0E7

AO

00

LDY

#$00

B0E9

84

10

STY

$10

BOEB

A5

2D

LDA

$2D

/ ii

parentheses

open?

dimensioned
variable

pointer

A-36

to

variable

start

BOED

A6

2E

LDX

$2E

BOEF

86

60

STX

$60

BOF1

85

5F

STA

$5F

B0F3

E4

30

CPX

$30

save

-for

BOF5

DO

04

BNE

$BOFB

B0F7

C5

2F

CMP

$2F

end

B0F9

FO

22

BEQ

$B11D

yes,

$45

first

of

BOFB

A5

45

LDA

Dl

5F

CMP

BOFF

DO

08

BNE

$B109

no,

B1O1

A5

46

LDA

$46

second

B103

C8

Dl

5F

CMP

B106

FO

7D

BEQ

B108
B109

88

DEY

18

CLC

<$5F),Y

B1OA

A5

5F

69

07

LDA
ADC

$5F
#$07

B1OE

90

El

BCC

$BOF1

B11O

E8

Bill

DO

BNE

DC

41

CMP

90

05

BCC

$B11C

5B

SBC

#$5B

A5

SBC

38

B11C

60

list

looking

letter

increase pointer
byte

keep

REAL

by

(2+5

variable)

looking

Checks

on

letter

yes,

then

#$41

E9

E9

name

variable

compare

$BOEF

B115
B119

keep

I NX

B117
B11A

of

with

SB 185

B1OC

C9

letter

compare

already?

-found

I NY

B104

B113

variables

not

BOFD

<$5F>,Y

searching

SEC

no,

#$A5

then

C=l
C=0

RTS

ft*** ******f-**** *******h

PLA

BUD

68

B11E

48

B11F

C9

2A

B121

DO

B123

A9

B125

AO

PHA

check

calling

CMP

#$2A

calling

05

BNE

$B128

no

13

LDA

#$13

pointer

BF

LDY

#$BF

from
on

address

FREMEVL?

constant

RTS

B127

60

B128

A5

45

LDA

$45

B12A

A4

46

LDY

$46

variable

B12C

C9

54

CMP

#$54

11T"

B12E

DO

OB

BNE

$B13B

B130

CO

C9

CPY

#$C9

B132

FO

EF

BEQ

$B123

yes,

B134

CO

49

CPY

#$49

"I"

B136

DO

03

BNE

$B13B

no

B138

4C

08

JMP

$AF08

"SYNTAX

B13B

C9

53

CMP

#$53

B13D

DO

04

BNE

$B143

B13F

CO

54

CPY

#$54

B141

FO

F5

BEQ

$B138

B143

A5

2F

LDA

$2F

B145

A4

30

LDY

$30

B147

85

5F

STA

$5F

B149

84

60

STY

$60

B14B

A5

31

LDA

$31

B14D

A4

32

LDY

$32

AF

ST,

TI$

then

pointer

A-37

name

ERROR"

"SYNTAX

to

array

ERROR

listing

B14F

85

5A

STA

$5A

B151

84

5B

STY

$5B

B153
B154

18

CLC

69

07

ADC

#$07

B156

9O

01

BCC

$B159

B158

C8

B159

85

58

STA

$58

B15B

84

59

STY

$59

shi-ft

by

-find

in

new

block

end

B15D

20

B8

JSR

$A3B8

A5

58

LDA

$58

B162

A4

59

LDY

$59

B164

C8

B165

85

A3

new

shi-ft

I NY
2F

STA

$2F
$30

#$00
$45

B167

84

30

STY

B169

AO

B16B
B16D

A5

00
45

LDY
LDA

91

5F

STA

set

C8

A5

46

LDA

B172

91

5F

STA

B174
B176

A9 00
C8

LDA
XNY

B177

91

5F

STA

B179

C8

B17A

91

B17C

C8

B17D

91

B17F

CB

B180

91

B182

C8

B183

91

5F

STA

B185

A5

5F

LDA

block

pointer

new

array

first

letter

o-f

name

($5F), Y

second

$46

letter

o-f

name

<$5F), Y

#$00

($5F),,Y

I NY
STA

5F

($5F),,Y

five

I NY
5F

STA

5F

STA

times

zero

-for

value

<$5F),,Y

I NY
($5F).,Y

I NY
($5F).,Y
$5F

CLC

B187

18

B188

69

02

ADC

#$02

B18A

A4

60

LDY

$60

B18C

90

01

BCC

$B18F

B18E

C8

B18F

85

47

STA

$47

B191

84

48

STY

$48

B193

60

B194

A5

B196

OA

B197

69

I NY

RTS

Calculates
OB

LDA

number

$0B

times

ASL
05

ADC

plus

#$05

B199

65

5F

ADC

$5F

B19B

A4

60

LDY

$60

B19D

90

01

BCC

$B1AO

B19F

CB

B1A0

85

58

STA

$58

B1A2

84

59

STY

$59

B1A4

60

B1AA
B1AD

to

listing

I NY

B16F
B170

90

to

variable

I NY

B160

B1A5

order

add

o-f

painter
DIM'S

to

2
5

to

$5F/$60

I NY

result-poi nter

RTS
80

00

20 BF Bl
A5 64

00

00

constant-32768

change

JSR $B1BF
LDA $64

A-38

FAC

to

-first

element

integer

B1AF

A4

B1B1

60

65

LDY

$65

RTS

*****************************

B1B2

20

73

00

JSR $0073

B1B5

20

9E

AD

JSR

$AD9E

B1B8

20

8D

AD

JSR

$AD8D

BIBB

A5

66

LDA

$66

Change
get

-floating

next

evaluate

checks

numeric

sign

B1BD

30

OD

BMI

$B1CC

A5

61

LDA

negative,

$61

B1C1

C9

90

CMP

exponent

#$90

B1C3

9O

09

sign

BCC

$B1CE

no

#$A5

then

bigger

B1C5

A9

A5

LDA

AO

Bl

LDY

#$B1

B1C9

20

5B

pointer

to

JSR

$BC5B

B1CC

DO

7A

BNE

FAC

BICE

4C

9B

$B248
$BC9B

compare

JMP

uneven

"ILLEGAL
QUANTITY"

B1C7

BC

integer

term

on

B1BF

BC

to

character

than

32768?

constant
with

"ILLEGAL

constant
QUANTITY"

changes -Floating

point

to

integer
***** ****

***4*****t******

B1D1

A5

OC

LDA

$0C

OE

Dimension
DIM-flag

ORA

$0E

integer

$0D

string

flag

$46

second

letter

$45

first

$B1B2

get

index

get

back

get

flags

B1D3

05

B1D5

48

B1D6

A5

B1D8

48

B1D9

AO

B1DB

98

B1DC

48

B1DD

A5

B1DF

48

B1E0

A5

B1E2

48

B1E3

20

B1E6

68

B1E7

85

B1E9

68

B1EA

85

PHA
OD

LDA
PHA

00

LDY

variable
-flag

#$00

TYA
PHA
46

LDA
PHA

45

LDA
PHA

B2

Bl

JSR
PLA

45

STA
STA

B1EC

68

PLA

B1ED

A8

TAY

B1EE

BA

B1EF

BD

B1F2

48

B1F3

BD

of

and

the

the

goto

name

name
integer

$45

PLA

46

letter

of

$46

variable name

TSX
02

01

LDA

$0102, X

PHA

01

01

LDA

$0101, X

B1F6

48

B1F7

A5

64

B1F9

9D

02

B1FC

A5

65

B1FE

9D

01

B201

C8

B202

20

79

JSR

$0079

B205

C9

2C

CMP

#$2C

B207

FO

D2

BEQ

$B1DB

B209

84

OB

STY

$0B

B20B

20

F7

JSR

$AEF7

B20E

68

B20F

85

from

stack

PHA

01
01

LDA

$64

STA

$0102, X

LDA

$65

STA

$0101, X

index

low

and

high

on

stack

I NY
00

AE

STA

last

","

comma?

yes,

then

number

check

PLA
OD

get

$0D

A-39

of

on

character
next

index

indications

parenthesis

close

get

PLA

B211

68

B212

85

OE

STA

$0E

B214

29

7F

AND

#$7F

B216

85

OC

STA

$OC

B218

A6

2F

LDX

$2F

B21A

A5

30

LDA

$30

B21C

86

5F

STX

$5F

back

-Flags

pointer
save

to

array

pointer

B21E

B5

60

STA

$60

B220

C5

32

CMP

$32

B222

DO

04

BNE

$B228

B224

E4

31

CPX

$31

compare with

B226

FO

39

BEQ

$B261

yes,

B228

AO

00

LDY

#$00

B22A

Bl

5F

LDA

B22C

C8

not

names

($5F),Y

INY

listing

-from

compare

end

o-f

listing

-found
listing

with

hunted

name

B22D

C5

45

CMP

$45

B22F

DO

06

BNE

$B237

B231
B233
B235

A5 46
Dl 5F
FO 16

LDA
CMP
BEQ

$46
($5F),Y
$B24D

B237

CB

B238

Bl

B23A

18

B23B

65

B23D

AA

B23E

CB

B23F

Bl

5F

LDA

<$5F),Y

B241

65

60

ADC

$60

B243

90

D7

BCC

$B21C

B245
B247

A2

12

LDX

#$12

B248

A2

OE

LDX

#$0E

B24A

4C

37

JMP

$A437

out-put

B24D

A2

13

LDX

#$13

B24F

A5

OC

LDA

$0C

DIM

flag

B251

DO

F7

BNE

$B24A

no,

then

B253

20

94

JSR

$B194

B256

A5

OB

LDA

$0B

B25B

AO

04

LDY

#$O4

B25A

Dl

5F

CMP

($5F),Y

B25C

DO

E7

BNE

$B245

B25E

4C

EA

B2

JMP

$B2EA

B261

20

94

Bl

JSR

$B194

length

of

array head

B264

20

08

A4

JSR

$A408

checks

on

free

B267

AO

OO

LDY

#$00

B269

84

72

STY

$72

B26B

A2

05

LDX

#$05

default

B26D

A5

45

LDA

$45

first

B26F

91

5F

STA

B271

10

01

BPL

B273

CA

B274

C8

B275

A5

second

letter

found

INY
LDA

5F

($5F),Y

CLC
ADC

5F

add

-Field

length

and

continue

$5F

TAX
INY

-BYTE

2C
A4

Bl

number

$2C

for

error

number

ARRAY"

zero?
error

to
of

message

first
found

element
dimensions

compare

with DIM
uneven,then "BAD

searches
Apply

($5F),Y

for

array

value

letter

in

array

$B274

no

integer?

$46

second

A-40

number

SUBSCRIPT"

wanted

element

variable
memory

for
of

listing

INY
LDA

message

"REDIM'D

DEX
46

searching

"BAD SUBSCRIPT"

"ILLEGAL QUANTITY"

pointer

*******

*"**-)

-for

-for

leter

length

the

name

B277

91

5F

B279

10

02

B27B

CA

DEX

B27C

CA

DEX

STA ($5F) ,Y
BPL $B27D

B27D

86

71

STX

$71

B27F

A5

OB

LDA

$0B

B281

C8

B282

C8

I NY

B283

C8

I NY

B284

91

5F

STA

A2

OB

LDX

($5F) ,Y

B288

A9

00

LDA

#$00

24

OC

BIT

$0C

50

08

BVC

$B296

B28E

68
18

B290

69

ADC

AA

TAX

B293

68

PLA

B294

69

C8

B297

91

B299

C8

00

ADC

STA

#$01

($5F),rY

8A

91

5F

B29D
B2A0
B2A2

20

4C

86

71

85

72

STX
STA

$72

B2A4

A4

22

LDY

$22

B2A6
B2A8

C6
DO

OB
DC

DEC
BNE

$0B
$B286

B3

JSR

($5F),,Y

65

59

ADC

$59

BO

5D

BCS

$B30B

B2AE

85

59

STA

$59

B2B0

A8
8A

B2B2

65

58

ADC

$58

B2B4

90

03

BCC

$B2B9

B2B6

C8

B2B7

FO

52

B2B9

20

08

and

save

save

variable-end

further

pointer

dimensions?

yes

field

length

plus startaddress

B2BC

85

B2BE
B2C0

TXA

I NY
BEQ

$B30B

JSR

$A408

31

STA

$31

84

32

STY

$32

A9

00

LDA

#$OO

B2C2

E6

72

INC

$72

B2C4

A4

71

LDY

$71

B2C6

FO

05

BEQ

$B2CD

A4

checks
pointer
fill

DEY

B2C8

88

B2C9

91

58

STA

($58), Y

B2CB

DO

FB

BNE

$B2C8
$59

B2CD

C6

59

DEC

B2CF

C6

72

DEC

$72

B2D1

DO

F5

BNE

$B2C8

59

INC

$59

A5

TAY

B2B1

B2D6

add

from stack

calculate free memory

$B34C
$71

B2AC

38

dimension

TXA
STA

B2AA

E6

get

I NY

B29A

B2D3

DIM's

#$00

B29B

B2D5

variable length 2,3,5


o-f dimensions

no

I NY
5F

integer?

11, de-fault value -for


call by DIM command?

CLC
01

listing
of

save

PLA

B292

B296

final

#$0B

B28A
B28C

into

number

I NY

B286

B28F

write

no string

SEC

31

LDA

$31

A-41

on
to

array

free
end
with

memory
of

listing

O's

B2D8

E5 5F

SBC

$5F

B2DA

AO

02

LDY

#$02

B2DC

91

5F

STA

<$5F),Y

B2DE

A5

32

LDA

$32

B2E0

C8

B2E1

E5

60

SBC $6O

B2E3

91

5F

STA

<$5F>,Y

B2E5

A5

OC

LDA

$0C

B2E7

DO 62

array

length

low

length

high

I NY

array

BNE $B34B

*****************************
B2E9
B2EA
B2EC

C8
Bl 5F
85 OB

INY
LDA <$5F>,Y
STA $0B

B2EE

A9

LDA #$OO

B2F0
B2F2

85 71
85 72

00

call

-from

yes,

RTS

DIM-command?

Search -For element


number

o-f

dimensions

save

STA $71
STA $72

B2F4

C8

INY

B2F5
B2F6
B2F7

68
AA
85 64

PLA
TAX
STA $64

B2F9

68

PLA

B2FA

85

65

STA $65

B2FC

Dl

5F

CMP

B2FE

9O OE

BCC $B30E

smaller?

B300

DO 06

BNE $B308

bigger,then

B302

C8

INY

B303

8A

TXA

B304
B306
B308
B30B

Dl 5F
90 07
4C 45
4C 35

get

index

compare

<$5F>,Y

when

CMP <$5F),Y
BCC $B30F
B2 JMP $B245
A4 JMP $A435

with

even,

smaller,

*****************************

-From

stack

value

"BAD

array

SUBSCRIPT"

compare

then

in

low

byte

continue

"BAD

SUBSCRIPT"

"OUT

OF

MEMORY"

Calculates

address

of

element

INY

B30E

CB

B30F

A5

72

LDA

$72

B311

05

71

ORA

$71

B313

18

CLC

B314

FO

OA

B316

20

4C

B319

8A

B31A

65

B31C

AA

B3

BEQ

$B320

JSR

$B34C

multiplication

TXA

64

ADC

$64

TAX

B31D

98

B31E

A4

22

LDY

B320

65

65

ADC

$65

B322

86

71

STX

$71

TYA

$22

B324

C6

OB

DEC

$0B

number

B326

DO

CA

BNE

$B2F2

continue

B328

85

72

STA

$72

B32A

A2

05

LDX

#$05

de-Fault

B32C

A5

45

LDA

$45

first

B32E

10

01

BPL

$B331

B330

CA

B331

A5

o-f

dimensions
with

-for

next

index

variable

letter

o-f

name

DEX

46

LDA

$46

second

A-42

letter

o-f

name

length

B333

10

B335

CA

BPL $B337

02

DEX

B336

CA

B337

86

28

STX

$28

B339

A9

00

LDA

#$OO

55

JSR

$B355

B33B

20

B33E

8A

DEX

B3

B33F

65

58

ADC

$58

85

47

STA

$47

B343

98
65

59

ADC

$59

B346

85

48

STA

$48

47

LDA

A8
A5

B34B

60

22

B34E

Bl

5F

LDA

B350

85

28

STA

B352

88

B353

Bl

5F

LDA

B355

85

29

STA

$29

#$10

STY

($5F),Y

10

LDA

5D

STA

$5D

B35B

A2

00

LDX

#$00

B35D

A0

00

LDY

#$00

B35F

8A

TXA

B360

OA

ASL

B361

AA

TAX

B362

98

TYA

B363

2A

ROL

B364

A8

B365

BO

A4

BCS

$B30B

B367

06

71

ASL

$71

B369

26

72

ROL

$72

B36B

90

OB

BCC

$B378

B36D

18

B36E

8A

B36F

65

B371

AA

TAY

CLC
TXA

28

ADC

$28

TAX
TYA
29

ADC

$29

TAY

B376

BO

93

BCS

$B30B

B378

C6

5D

DEC

$5D

B37A

DO

E3

BNE

$B35F

B37C

60

RTS

a.*****.****.*******************

A5

B37F

B381
B384
B387

38

calculation

DEY

85

B37D

array

($5F),Y

A9

A8

for

$28

B357

B375

Helper

$22

B359

65

array

in

$47

84

98

offset

RTS

***** *******E-******4********

B372

2,3,5

TAY

B34C

B373

calculate

variables

TYA

B344

B349

of

TXA

B341

B348

length

BASIC-FRE

OD

LDA

$0D

type

FO

03

BEQ

$B384

no

20
20

A6 B6
26 B5

JSR $B6A6
JSR $B526

string

FRESTR
garbage

SEC

A-43

function

flag

collection

B388

A5

33

LDA

$33

B38A

E5

31

SBC

$31

B38C

A8

B38D

A5 34

LDA

$34

B38F

E5

32

SBC

$32

B391

A2

00

LDX

#$OO

B393

86

0D

STX

$OD

B395

85

62

STA

$62

B397

84

63

STY

$63

B399

A2 90

LDX

#$90

B39B

4C

JMP

$BC44

string

44

BC

minus
set

and

A6 3A

B3A8

E8

B3A9

DO

AO

BNE

$B34B

B3AB

A2

15

LDX

#$15

B3AD

2C

B3AE

A2

IB

LDX

B3B9

to

-floating

BASIC-POS

-Function

C=l

get

get

cursor

cursor

Test

on

position

position

as

above

direct

mode

.BYTE

no, then RTS


# for "ILLEGAL QUANTIY"

$2C

# -for

#$1B

El

"UNDEF'D FUNCTION"

output

*****************************

B3B6

change

INX

4C 37 A4 JMP $A437

20

result

$3A

B3A6

B3B3

to numeric

continue

*****************************

B3B0

end

point

38
SEC
20 FO FF JSR $FFFO
A9 00
LDA #$00
FO EB
BEQ $B391

LDX

variable

-flag

save

*****************************

B39E
B39F
B3A2
B3A4

start

TAY

error

BASIC-DEF

message

FN

command

checks

FN

syntax

checks
checks

on
on

direct mode
parenthesis

B3

JSR

$B3E1

20

A6 B3

JSR

$B3A6

20

FA

JSR

$AEFA

B3BC

A9

80

LDA

#$80

B3BE

85

10

STA

$10

B3C0

20

8B

BO

JSR $B08B

B3C3

20

8D

AD

JSR

$AD8D

checks

on

numeric

B3C6

20

F7

AE

JSR

$AEF7

checks

on

parenthesis

B3C9

A9

B2

LDA

#$B2

"="

B3CB

20

FF

JSR

$AEFF

checks

B3CE

48

B3CF

A5

B3D1

48

B3D2

A5

B3D4

48

B3D5

A5

B3D7

48

B3D8

A5

AE

AE

blocks
looks

integer
-for

open

variable

variable

BASIC

close

code

on

"="

PHA

LDA

48

$48

FN

PHA

LDA

47

variables

on

stack

$47

PHA
LDA

7B

$7B
program

PHA

7A

LDA

pointer

on

stack

$7A

B3DA

48

B3DB

20

F8

A8

JSR

$A8F8

pointer

B3DE

4C

4F

B4

JMP

$B44F

get

PHA

*****************************

B3E1

A9

A5

B3E3

20

FF

B3E6

09

80

B3E8

85

10

STA

$10

AE

FN

Checks

on

next

variable
on

FN

stack

syntax

LDA #$A5

FN

JSR

$AEFF

checks

on

ORA

#$80
blocks

integer

A-44

statement
-from

code

FN

code
variables

B3EA
B3ED
B3EF
B3F1

20
85
84
4C

92 BO JSR $B092
4E
STA $4E
4F
STY $4F
8D AD JMP $AD8D

B3F4

20

El

JSR

$B3E1

B3F7

A5

4F

LDA

$4F

4E

LDA

B3F9

48

B3FA

A5

B3

48

20

Fl

AE

JSR

$AEF1

B400

20

8D

AD

JSR

$AD8D

B403

68

B404

85

B406

68

B407

85

4E

STA

$4E

STA

$4F

#$02

A0

02

LDY

Bl

4E

LDA

B40D

85

47

STA

B40F

AA

B410

C8

B411

Bl

4E

LDA

B413

FO

99

BEQ

$B3AE

B415

85

48

STA

$48

B417

C8

B418

Bl

B41A

48

B41B

88

B41C

10

FA

BPL

$B418

B41E

A4

48

LDY

$48

B420

20

D4

JSR

$BBD4

B423

A5

7B

LDA

$7B

7A

LDA

47

LDA

($4E),,Y
$47

($4E),,Y

BB

48

B429

Bl

4E

LDA

B42B

85

7A

STA

B42D

CB

($47),,Y

$7A

($4E),,Y
$7A

Bl

4E

LDA

7B

STA

$7B

B432

A5

48

LDA

$48

B434

48

B435

A5

B437

48

47

8A

LDA

AD

FN

term

$47

JSR

FRMNUM

$AD8A

get

numeric

PLA
4E

STA

$4E

PLA

85

4F

20

79

B444

FO

03

B446

4C

08

68

on

($4E),,Y

PHA

B441

B44C

pointer

PHA

B43F

68

program

I NY

85

85

FAC to FN variable

PHA

B430

B44A

transfer

PHA

B42E

B449

"UNDEF'D FUNCTION"

DEY

B428

68

gives

PHA

48

B43E

FNvariable pointer

I NY

A5

85

back

I NY

B425

B43C

get

TAX

B426

B43B

gets term in parenthesis


checks on numeric

PLA
4F

on

stack

PLA

B409

20

FN variable pointer

PHA

B40B

68

BASIC-FN function
checks FN syntax

$4E

B3FC

variable

set FN-variable pointer


checks on numeric

PHA

B3FD

B438

looks -for

00

AF

STA

$4F

JSR

$0079

BEQ

$B449

JMP

$AF08

get

no

last

more

give

character

characters?

"SYNTAX

ERROR"

PLA

7A

STA

$7A

program

PLA

A-45

pointer

term

B44D

85 7B

STA

$7B

B44F

AO 00

LDY

#$00

B451

68

PLA

B452

91

B454
B455

68
C8

B456

91

B458
B459

68

B45A

91

STA

4E

I NY
STA

4E

B45C

68
C8

B45E

91

B460

68

B461

C8

B462

91

B464

60

<$4E>,Y

PLA

I NY
STA

C8

B45D

<$4E),Y

PLA

4E

and

get

FN

variable

PLA
I NY
STA

4E

<$4E),Y

PLA

I NY
STA

4E

<$4E),Y

RTS

*****************************

BASIC-STR$

20 8D AD JSR $AD8D
AO 00
LDY #$00

checks

change FAC to ASCII

B46A

20

B46D

68

DF BD

JSR

$BDDF

B46E

68

B46F

A9

FF

LDA

#$FF

B471

AO

00

LDY

#$00

B473

FO

12

BEQ

$B487

PLA

64

LDX

$64

A4

65

LDY

$65

86

50

STX

$50

B47B

84

51

STY

$51

B47D

20

F4

JSR

$B4F4

B48O

86

62

STX

$62

B482

84

63

STY

$63

B484

85

61

STA

$61

B486

60

B487

A2

22

LDX

#$22

B489

86

07

STX

$O7

B48B

86

08

STX

$08

B48D

85 6F

STA

$6F

B48F

84

70

STY

$70

B491

85

62

STA

$62

B493

84

63

STY

$63

B495

AO

FF

LDY

#$FF

B497

C8

B498

Bl

6F

LDA

B49A

FO

OC

BEQ

$B4A8

B477

B479

numeric

PLA

start

B4

address

of

string

$FF

*****************************
A6

on

function

B465
B468

B475

from
stack

<$4E),Y

String

administration

pointer
checks

to

string

free

descriptor

memory,
string

sets

pointer

RTS

start

I NY

address

increase
($6F>,Y

B49C

C5

07

CMP

$07

B49E

FO

04

BEQ

$B4A4

B4A0

C5

08

CMP

$08

B4A2

DO

F3

BNE

$B497

B4A4

C9

22

CMP

#$22

B4A6

FO

01

BEQ

$B4A9

B4A8

18

newt
end

CLC

A-46

of

string

pointer

character
symbol?

of

string

B4A9

84

B4AB

98

61

STY

$61

B4AC

65

6F

ADC

B4AE

85

71

STA

$71

B4B0

A6

7O

LDX

$70

Ol

BCC

$B4B5

B4B2

90
E8

B4B5

86
A5

72

B4B7

STX

$72

70

LDA

$70

B4B9

F0

O4

B4BB

C9

02

BEQ $B4BF
CMP #$02

B4BD

DO

OB

BNE

B4BF

98

B4C0

20

75

B4C3

A6

B4C5

address

low

end

address

high

B4

$B475
$6F

A4

70

LDY

$70

B4C7

20

88

JSR

$B688

B4CA

A6

16

LDX

$16

B6

B4CC

EO

22

CPX

#$22

B4CE

DO

05

BNE

$B4D5

LDX

#$19

JMP

$A437

B4D0

A2

19

B4D2

4C

37

A4

B4D5

A5

61

LDA

$61

B4D7

95

00

STA

$00, X

B4D9

A5

62

LDA

$62

B4DB

95

01

STA

$01, X

B4DD

A5

63

LDA

$63

B4DF

95

O2

STA

$02, X

B4E1

AO

00

LDY

#$00
$64

B4E3

86

64

STX

B4E5

84

65

STY

$65

B4E7
B4E9

84

70

STY

$70

B4EA

84

OD

STY

$0D

B4EC

86

17

STX

$17

B4EE

E8

B4EF

E8

INX

B4F0

E8

INX

B4F1

86

B4F3

60

B4F4

46

B4F6

48

88

address

+1

high

zero?
two?
no

TYA

LDX

49

end

start

$B4CA

6F

38

string

INX

JSR

B4F9

of

$6F

B4B4

B4F7

length

TYA

string

descriptor

length

in

gets

start

copy

string

string
string

gets

A,address

X/Y

address
into $

range

descriptor pointer
stack full?

no

# for "FORMULA TO COMPLEX"


out-put error messages
bring
and

string

length

address

into

string

pointer

stack

now on

descriptor

DEY

set

16

STX
LSR

$16

save

$0F

set

PHA
FF

EOR

o-f

increase

RTS
OF

string

index

INX

#$FF

B4FA

65

33

ADC

$33

A4

34

LDY

$34

B4FE

BO

01

BCS

$B501

B500

88

DEY

B501

C4

32

CPY

$32

B503

90

11

BCC

$B516

B505

DO

04

BNE

$B50B

B507

C5

31

CMP

$31

B509

90

OB

BCC

$B516

B50B

85

33

STA

$33

A-47

by
new

back

string

SEC

B4FC

as

-flag

last

$FF

string

descr.

3
index

flag

length

for

garbage-

collection

B50D

84

34

STY

$34

B50F

85 35

STA

$35

B511

84

STY

$36

B513

AA

TAX

B514

68

PLA

B515

60

RTS

36

get

B516

A2

10

LDX

#$10

B518

A5

OF

LDA

$0F

-Flag

B51A

30
20
A9
85

BMI $B4D2
B6
26 B5 JSR $B526
80
LDA #$80
OF
STA $0F

68
DO

DO

B51C

B51F

B521
B523
B524

PLA
BNE

LDX

B528
B52A

A5 38
86 33

LDA $38
STX $33

B52C

85

STA $34

B52E
B530

AO 00
84 4F

LDY #$00
STY $4F

B532

84

STY

B536

4E
A5 31
A6 32

B538

85

5F

STA $5F

B53A

86

6O

STX

$60

B53C

A9

19

LDA

#$19

B53E

A2 00
85 22
86 23

LDX #$00
STA $22
STX $23

B544

C5

16

CMP

$16

B546

FO

05

BEQ

$B54D

B548

20

C7

B54B

FO

F7

BEQ

$B544

B54D

A9

07

LDA

#$07

B54F

85

53

STA

$53

B551

A5

2D

LDA

$2D

B553

A6

2E

LDX

$2E

B555

85

22

STA

$22

B557

86

23

STX

$23

B559

E4

30

CPX

$30

B55B

DO

04

BNE

$B561

B55D

C5

2F

CMP

$2F

B55F

FO

05

BEQ

$B566

B561

20

BD

B564

FO

B566
B568

B542

$37

B5

MEMORY"

"OUT

collection

OF

MEMORY"

collection

-f 1 ag

JSR $B5C7

JSR

$B5BD

F3

BEQ

$B559

85

58

STA

$58

86

59

STX

$59

B56A

A9

03

LDA

#$03

B56C

85

53

STA

$53

B56E

A5

58

LDA

$58

B570

A6

59

LDX

$59

B572

E4

32

CPX

$32

B574

DO

07

BNE

$B57D

Garbage

get

$4E
LDA $31
LDX $32

B5

OF

length

garbage

then

string

A6 37

B540

"OUT

-for

garbage

set

string

length

$B4F6

B526

B534

for

done,

*****************************

34

back

A-48

rid

collection

o-f

invalid

strings

B576

C5

31

CMP

$31

B578

DO

03

BNE

$B57D

B57A

4C

06

B57D

85

22

B6

JMP

$B606

STA

$22

B57F

86

23

STX

$23

B581

AO

OO

LDY

#$00

B583

Bl

22

LDA

B585

AA

B586

CB

B587

Bl

B589

08

($22),,Y

TAX
I NY
22

LDA

($22),,Y

PHP

B58A

C8

B58B

Bl

22

LDA

B58D

65

58

ADC

$58

B58F

85

58

STA

B591

$58

C8

I NY
($22),,Y

I NY

B592

Bl

22

B594

LDA

65

59

ADC

$59

B596

85

59

STA

$59

B598

28

B599

10

B59B

8A

B59C

30

B59E

C8

($22), Y

PLP
D3

BPL

$B56E

TXA
DO

BMI

$B56E

I NY

B59F

Bl

22

LDA

B5A1

AO

00

LDY

($22),,Y
#$00

B5A3

OA

B5A4

69

05

ADC

#$05

B5A6

65

22

ADC

$22

B5A8

85

22

STA

$22

B5AA

90

02

BCC

$B5AE

B5AC

E6

23

INC

$23

B5AE

A6

23

LDX

$23

B5B0

E4

59

CPX

$59

B5B2

DO

04

BNE

$B5B8
$58

ASL

B5B4

C5

58

CMP

B5B6

FO

BA

BEQ

$B572

B5B8

20

C7

JSR

$B5C7

B5BB

FO

F3

BEG

$B5B0

B5BD

Bl

22

LDA

B5BF

30

35

BMI

B5

($22), Y
$B5F6

B5C1

C8

B5C2

Bl

22

LDA

B5C4

10

30

BPL

B5C6

C8

B5C7

Bl

22

LDA

B5C9

FO

2B

BEQ

B5CB

C8

B5CC

Bl

22

LDA

B5CE

AA

B5CF

CB

B5D0

Bl

22

LDA

B5D2

C5

34

CMP

B5D4

90

06

BCC

$B5DC

B5D6

DO

IE

BNE

$B5F6

B5D8

E4

33

CPX

$33

I NY

<$22), Y
$B5F6

I NY

($22), Y
$B5F6

I NY

($22), Y

TAX
I NY

($22), Y
$34

A-49

B5DA

BO

1A

BCS

$B5F6

B5DC

C5

60

CMP

$60

B5DE

90

16

BCC

$B5F6

B5E0

DO

04

BNE

$B5E6

B5E2

E4

5F

CPX

$5F

B5E4

90

10

BCC

$B5F6

B5E6

86

5F

STX

$5F

B5E8

85

60

STA

$60

B5EA

A5

22

LDA

$22

B5EC

A6

23

LDX

$23

B5EE

85

4E

STA

$4E

B5F0

86

4F

STX

$4F

B5F2

A5

53

LDA

$53

B5F4

85

55

STA

$55

B5F6

A5

53

LDA

$53

B5F8

18

B5F9

65

22

ADC

$22

B5FB

85

22

STA

$22

B5FD

90

02

BCC

$B601

B5FF

E6

23

INC

$23

B601

A6

23

LDX

$23

B603

AO

00

LDY

#$00

B6O5

60

B606

A5

4F

LDA

B6O8

05

4E

ORA

$4E

B60A

FO

F5

BEG

$B601

B60C

A5

55

LDA

$55

B60E

29

04

AND

#$04

B610

4A

B611

A8

B612

85

55

STA

B614

Bl

4E

LDA

B616

65

5F

ADC

$5F

B618

85

5A

STA

$5A

B61A

A5

60

LDA

$60

B61C

69

00

ADC

#$00

B61E

85

5B

STA

$5B

B620

A5

33

LDA

$33

CLC

RTS

$4F

LSR
TAY
$55

($4E),Y

B622

A6

34

LDX

$34

B624

85

58

STA

$58

B626

86

59

B628

20

BF

B62B

A4

55

B62D

C8

A3

STX

$59

JSR

$A3BF

LDY

$55

I NY

B62E

A5

58

LDA

B630

91

4E

STA

B632

AA

$58
($4E),Y

TAX

B633

E6

59

INC

$59

B635

A5

59

LDA

$59

B637

CB

B638

91

4E

B63A

4C

2A

B63D

A5 65

I NY

STA
B5

JMP

($4E),Y

$B52A
String

LDA $65
A-50

connection

"+"

B63F

48

B640

A5

PHA
64

LDA

save

descriptor

B642

48

B643

20

83

AE

JSR

$AE83

B646

20

8F

AD

JSR

$AD8F

B649

68

B64A

85

B64C

68

B64D

85

B64F
B651
B653

18

get

STA

address

checks

PLA
6F

on

get
$7O

AO

00

LDY

#$OO

Bl

6F

LDA

back

($6F),,Y

length

($64),,Y

plus

71

64

ADC

90

05

BCC

$B65D

B658

A2

17

smaller

LDX

#$17

B65A

4C

37

JMP

$A437

B65D

20

75

B4

JSR

$B475

out-put

B660

20

7A

B6

JSR

$B67A

B663

A5

50

LDA

$50

B665

A4

51

LDY

$51

B667

20

AA

B6

JSR

$B6AA

B6

JSR

$B68C

LDA

$6F

LDY

$70

B66A

20

8C

B66D

A5

6F

A4

B66F

A4

70

B671

20

AA

B6

JSR

$B6AA

B674

20

CA

B4

JSR

$B4CA

B677

4C

B8

AD

JMP

$ADB8
#$00

B67A

AO

00

LDY

B67C

Bl

6F

LDA

B67E

48

B682

AA

B683

C8

B684

Bl

B686

A8

B68A

84

23

B68C

A8

B68D

FO

B68F

48

"STRING TOO
error

place

transfer
pointer

LONG"

messages

for

new

first
to

string

second

FRESTR

string

string

there

string

descriptor

connect

second
the

string
first

with

string

FRESTR

descriptor

in string stack
formula evaluation

back

to

($6F),,Y

save

string

LDA

($6F), Y

string

address

low

LDA

($6F), Y

string

address

high

string

length

PLA
STX

$22

length

STY

$23

pointer

$B699

length

to

string

TAY
OA

BEQ

zero,

then

ready

PHA

B690

88

B691

Bl

22

LDA

($22), Y

B693

91

35

STA

($35), Y

68

save

2nd

256

TAY
22

B698

for

of

than

I NY
6F

68

98

length

TAX

86

DO

string

I NY
6F

B687

B696

first

PHA

B688

B695

strings

variable

descriptor

o-f

B654

C8

2nd

CLC

B656

Bl

of

string

$6F

PLA
STA

B680

-first

string

PHA

70

B67F

o-f

$64

DEY
transfer

string

TYA
F8

BNE

$B690

PLA

B699

18

B69A

65

35

CLC
ADC

$35

B69C

85

35

STA

$35

B69E

90

02

BCC

$B6A2

B6A0

E6

36

INC

$36

B6A2

60

pointer

RTS

A-51

plus

string

length

*****************************
B6A3
20 BF AD JBR $AD8F
B6A6

A5 64

LDA $64

B6A8

B6AE

A4
85
84
20

LDY
STA
STY
JSR

B6B1

08

B6AA
B6AC

65
22
23
DB B6

String administration FRESTR


checks on string variable
pointr to string descriptor

$65
$22
$23
$B6DB

eliminate

descriptor
string

PHP

B6B2

A0

00

LDY

B6B4

Bl

22

LDA

B6B6

48

B6B7

C8

B6B8

Bl

B6BA

AA

B6BB

C8

B6BC

Bl

B6BE

A8

TAY

B6BF

68

PLA

B6C0

28

B6C1

DO

13

BNE

$B6D6

B6C3

C4 34

CPY

$34

B6C5

DO OF

BNE

$B6D6

B6C7

E4

33

CPX

$33

B6C9

DO OB

BNE

$B6D6

B6CB

48

PHA

from
stack

#$00
($22),Y

PHA
I NY

LDA

22

($22),Y

TAX
INY

LDA

22

($22),Y

PLP

string

wasn't

in string
stack

CLC

B6CC

18

B6CD

65

33

ADC

$33

B6CF

85

33

STA

$33

B6D1

90

02

BCC

$B6D5

B6D3

E6

34

INC

$34

B6D5
B6D6

68
86

22

PLA
STX

$22

B6D8

84

23

STY $23

B6DA

60

B6DB

C4

18

CPY

$18

B6DD

DO

OC

BNE

$B6EB

B6DF

C5

17

CMP

$17

B6E1

DO

08

BNE

$B6EB

B6E3

85

16

STA

$16

B6E5

E9

03

SBC

#$03

B6E7

85

17

STA

$17

B6E9

AO

00

LDY

#$00

B6EB

60

$33/$34 now point

to string
stack

RTS

is

string

descriptor
string

yes,

eliminate

in

stack

input

RTS

*****************************

Al

B7

JSR

B6EC

20

B6EF

8A

B6F0

48

B6F1

A9

B6F3

20 7D

B6F6

68

B6F7

AO

00

LDY

B6F9

91

62

STA

BASIC-CHR$

-function

gets byte value

$B7A1

code

TXA

in

(0

to 255)

accumulator

PHA

01
B4

LDA

#$01

length

JSR

$B47D

reserve
get

PLA

of

back

string

place

for

ASCII

1
string

code

#$00
($62),Y

save

A-52

all

string

characters

B6FB

68

B6FC

68

B6FD

4C

PLA

PLA
CA

B4

JMP

*B4CA

bring

descriptor

to string
stack

BASIC-LEFT* -function
B700

20

61

B7O3

Dl

50

B705

98

B706

90

04

BCC

*B70C

is

B708

Bl

50

LDA

(*50),Y

B70A

AA

TAX

string

B7

JSR
CMP

*B761

string

(*50),Y

parameter

compare

length

TYA

B70B

98

TYA

B70C

48

PHA

B70D

8A

TXA

B70E

48

PHA

B70F

2O

7D

B712

A5

50

B714

A4

51

B716

20

AA

B4

B6

*B47D
*50

LDY

*51

pointer

JSR

*B6AA

FRESTR

68
A8

TAY

B71B

68

PLA

B71C

18

CLC

less than

length/string

LDA

B719

stack

LEFT*

parameter

LEFT value

JSR

B71A

-from

with

save place -for

new

length

string

to descriptor

PLA

length

B71D

65

22

ADC

B71F

85

22

STA *22

*22

B721

90

02

BCC

*B725

B723

E6

23

INC

*23

B725

98

of

new

plus address

string
of

old

string

TYA

B726

20

BC

B6

JSR

*B68C

transfer

B729

4C

CA

B4

JMP

*B4CA

bring

newstring

descriptor

to range

to

string
stack

B72C

20

B72F

18

61

B730

Fl

B732

49

FF

B734

4C

06

B7

*B761

get

CLC
SBC

50

B7

***** ***4(***

B737

JSR

BASIC-RIGHT*
string

function
parameter

EOR

#*FF

JMP

*B706

first

element's

continue

as

BASIC-MID*

fr***4t*******

in

FF

B739

85

65

B73B

20

79

B73E

C9

29

B740

F0

06

B742

20

FD

AE

B745

20

9E

B748

20

61

B74B

FO

4B

B74D

CA

DEX

B74E

8A

TXA

B74F

48

PHA

B750

18

CLC

B751

A2

00

LDX

B753

Fl

50

SBC

length

of

B755

BO

B6

BCS

*B70D

small,

first

B757

49

FF

EOR

#$FF

new

LDA

#*FF

STA

*65

JSR

*0079

CHRGOT

CMP

#*29

11)"

BEQ

*B748

JSR

*AEFD

checks

B7

JSR

*B79E

gets

B7

JSR

*B761

get

BEQ

*B798

first

in

get

closed
on

last

character

parenthesis
comma

byte

#,

string

2nd

parameter

address,

parameter

of

first

1st

"

zero,

"ILLEGAL

old

LEFT*/string

function

A9

00

from
stack

(*50),Y

element

QUANTITY"

in

old

string
#*00
(*50),Y

A-53

string

old

string

MID parameter

length

B759

C5

65

CMP

$65

B75B

90

Bl

BCC

$B70E

B75D

A5

65

LDA

$65

B75F

BO

AD

BCS

$B70E

B761

20

F7

B764

68

PLA

B765

A8

TAY

B766

68

PLA

B767

85 55

STA

B769

68

PLA

B76A

68

PLA

B76B

68

PLA

B76C

AA

TAX

AE

absolute

get

call

close parethesis
address

$55

first

B76D

68

PLA

B76E

85 50

STA

B770

68

PLA

B771

85

51

STA

$51

B773

A5 55

LDA

$55

B775

48

PHA

B776

98

TYA

B777

48

PHA

B778

AO OO

LDY

B77A

8A

TXA

B77B

60

RTS

parameter

$50

address

low/high

last

address back

BASIC-LEN

string

change byte

*****************************

Get

string

get

string

B787

86

set

type

B789

A8

TAY

B78A

60

RTS

$OD

length

*****************************

BASIC-ASC

JSR

$B782

get

08

BEQ

$B798

length

AO

00

LDY

#$00

Bl

22

LDA

82

B78E

FO

B790
B792
B794

A8

B795

4C

A2

B3

JMP

$B3A2

change

B798

4C

48

B2

JMP

S8248

"ILLEGAL

= 0,

-first

ASCII

TAY

Gets

byt

to

-floating

value

get

20

8A

AD

JSR

$AD8A

FRMNUM

get

20

B8

Bl

JSR

$B1B8

checks

on

B7A4

A6

64

LDX

$64

high

B7A6

DO

FO

BNE

$B798

not

B7A8

A6

65

B7AA

4C

79

$65
$0079

CHRGOT

A-54

to

next
#

character

value

range

byte
0,

point

QUANTITY"

CHRGET

JMP

$22/$23

code

$0073

LDX

in

"ILLEGAL

character

JSR

00

numeric

-function

00

B7A1

73

B79E

on

in

QUANTITY"
get

($22),Y

************(**!***************

20

length

pointer

20

length

to -floating
point -format

-flag

in

B78B

B79B

stack

parameter

20 A3 B6 JSR $B6A3
A2 00
LDX #$00

B7

on

-function

FRESTR get

B782
B785

STX

string

#$00

20 82 B7 JSR $B782
4C A2 B3 JMP $B3A2

OD

of

descriptor

*****************************

B77C
B77F

jump

checks on

JSR $AEF7

to

FAC

and

changes

to

integer

"ILLEGAL

QUANTITY"

get

character

last

BASIC-VAL
B7AD

20

82

B7B0

DO

03

B7B2

4C

F7

B7B5

A6

7A

B7B7

A4

B7B9

86

B7BB
B7BD

B7

B8

function

JSR

$B782

get

BNE

$B7B5

length
zero

in

save

program

JMP

$B8F7

LDX

$7A

7B

LDY

$7B

71

STX

$71

84

72

STY

$72

A6

22

LDX

$22

B7BF

86

7A

STX

$7A

B7C1

18

string

bring

address

not

O?

FAC

into

B7C2

65

22

ADC

B7C4

85

24

STA

$24

B7C6

A6

23

LDX

$23

B7C8

86

7B

STX

$7B

B7CA

90

01

BCC

$B7CD

B7CC

E8

pointer

string

CLC

start-address
stringpointer

$22

string

end+1

INX

B7CD

86

25

STX

$25

B7CF

AO

00

LDY

#$00

B7D1

Bl

24

LDA

($24),Y

B7D3

48

B7D4

98

B7D5

91

24

B7D7

20

79

00

JSR

$0079

CHRGOT

get

B7DA

20

F3

BC

JSR

$BCF3

change

string

B7DD

68

B7DE

AO

00

LDY

B7E0

91

24

STA

($24),Y

B7E2

A6

71

LDX

$71

B7E4

A4

72

LDY

$72

B7E6

86

7A

STX

$7A

B7E8

84

7B

STY

$7B

B7EA

60

B7EB

20

8A

AD

JSR

$AD8A

FRMNUM

gets

B7EE

20

F7

B7

JSR

$B7F7

change

FAC

B7F1

20

FD

AE

JSR

$AEFD

CHKCOM

checks

B7F4

4C

9E

B7

JMP

$B79E

gets

B7F7

A5

66

LDA

$66

sign

B7F9

30

9D

BMI

$B798

B7FB

A5

61

LDA

$61

exponent

first

PHA

byte

to

string

save

TYA

STA

($24),Y

and

PLA

substitute

character

with

last
to

to

back

again

get

back

program

and

byte

GETBYT
to

on

value

change

FAC

"ILLEGAL

C9

91

CMP

#$91

compare

97

BCS

$B798

bigger,"ILLEGAL

B801

20

9B

JSR

$BC9B

change

B804

A5

64

LDA

$64

B806

A4

65

LDY

$65

get

value

B808

84

14

STY

$14

and

to

B80A

85

15

STA

$15

B80C

6O

B80D

A5

FAC

to

to

to

14

LDA

save
$14

to

A-55

16

QUANTITY"

address

function

address

65536

$15

PHA

number

QUANTITY"

$14/$15

BASIC-PEEK

LDA

frmat

RTS

15

bit

camma

bit

then

value

address

BO

BC

16

numeric

B7FF

48

pointer

RTS

B7FD

A5

floating

string/point

set

GETADR

B810

zero

character

#$0Q

GETADR

B80F

and

length

$14/$15

frmat

PHA

B812

48

B813

20

F7

JSR

$B7F7

B816

A0

00

LDY

#$00

B818

Bl

14

LDA

B81A

A8

B81B

68

B81C

85

B81E

68

B81F

85

15

B821

4C

A2

B7

change

get

($14),Y

to

TAY

FAC

PEEK

value

back

address

STA

$14
get

PLA

B3

STA

$15

JMP

$B3A2

to

floating

BASIC-POKE

20 EB B7

JSR $B7EB

get

B827

8A

TXA

write

B828

AO 00

LDY

#$00

B82A

91

STA

($14),Y

B82C

60

14

POKE

and

point

-format

command

address

POKE

and

value

value

into

accu

memory

RTS

*****************************

B82D

20

EB

B830

86

49

B832

A2

00

B834

20

79

B7

00

JSR

$B7EB

STX

$49

LDX

#$00

BASIC-WAIT

get

de-fault

JSR $0079

CHRGOT

BEQ

$B83C

no

JSR

$B7F1

checks

FO

03

20

Fl

B83C

86

4A

STX

$4A

B83E

AO

00

LDY

#$00

B840

Bl

14

LDA

($14),Y

B842

45

4A

EQR

$4A

B844

25

49

AND

$49

connect

B846

FO

F8

BEQ

$B840

keep

B848

60

and

-for
get

B839

B7

command

address

B837

third

value

third
last

parameter

character

parameter?

on

comma

and

gets

parameter
wait

address
logically

waiting

RTS

*****************************

Arithmetic

*****************************

FAC

B849

A9

11

B84B

AO

BF

B84D

4C

67

B8

8C

BA

FAC

#$11

LDY

#$BF

pointer

JMP

$B867

FAC

JSR

$BA8C

A5

66

LDA

$66

B855

49

FF

EOR

#$FF

B857

85

66

STA

$66

B859

45

6E

EOR

$6E

B85B

85

6F

STA

$6F

B85D

A5

61

LDA

$61

B85F

4C

6A

JMP

$B86A

Minus

on

FAC

constant

FAC

change

o-f

FAC

(A/Y)
=

0-5

constant

FAC=constant

Minus

FAC

routines

+0-5

constant

*****************************

B8

LDA

*****************************

B853

-frmat

B824

20

address

PLA
14

*****************************

B850

to

to

(A/Y)

(A/Y)-FAC
ARG

ARG-FAC
sign

ARG

*****************************

B862

20

99

B865

90

3C

B9

JSR

$B999

BCC

$B8A3

adjust

A-56

exponent

o-f

FAC

ARG

*****************************

B867

20 8C BA JSR $BA8C

DO 03
4C FC

BNE $B86F
BB JMP $BBFC

B86F

A6

70

LDX

$70

B871

86

56

STX

$56

B873

A2

69

LDX

#$69

B875

A5

69

LDA

$69

B877

A8

BEQ

CE

$B848

FO

B87A

38

B87B

E5

61

SBC

$61

B87D

FO

24

BEQ

$B8A3

B87F

90

12

BCC

$B893

B881

84

61

STY

$61

B883

A4

6E

LDY

$6E

B885

84

66

STY

$66

B887

49

FF

EOR

#$FF

B889

69

OO

ADC

#$00

B88B

AO

00

LDY

#$00

B88D

84

56

STY

$56

B88F

A2

61

LDX

#$61

B891

DO

04

BNE

$B897

B893

AO

00

LDY

#$00

B895

84

70

STY

$70

B897

C9

F9

CMP

#$F9

B899

30

C7

BMI

$B862

B89B

A8

B89C

A5

70

LDA

$70

B89E

56

01

LSR

$01, X

B8A0

20

BO

JSR

$B9B0

B8A3

24

6F

BIT

$6F

B8A5

10

57

BPL

$B8FE

B8A7

AO

61

LDY

#$61

B8A9

EO

69

CPX

#$69

B8AB

FO

02

BEQ

$B8AF

B8AD

AO

69

LDY

#$69

B8AF

38

B8B0

49

FF

EOR

#$FF

B8B2

65

56

ADC

$56

B8B4

85

70

STA

$70

B8B6

B9

04

LDA

$0004,Y

B8B9

F5

04

SBC

$04, X

B8BB

85

65

STA

$65

B8BD

B9

03

LDA

$0003,Y

B8C0

F5

03

SBC

$03, X

B8C2

85

64

STA

$64

B8C4

B9

02

LDA

$0002,Y

B8C7

F5

02

SBC

$02, X

B8C9

85

63

STA

$63

B8CB

B9

01

BSCE

F5

01

SEC

TAY

B9

SEC

00

00

00

00

LDA

$0001,Y

SBC

$01, X

Plus

FAC
no,

TAY

B878

FAC

constant

*****************************

B86A
B86C

Plus

A-57

FAC

constant(A/Y)+FAC

(A/Y)
=

FAC

to ARG
+

ARG

inverse zero?
the FAC = ARG

B8D0

85

62

STA

B8D2

BO

03

BCS

$B8D7

B8D4

20

47

JSR

$B947

B8D7

AO

OO

LDY

#$00

B9

$62

B8D9

98

B8DA

18

B8DB

A6

62

LDX

$62

B8DD

DO

4A

BNE

$B929

B8DF

A6

63

LDX

$63

B8E1

86

62

STX

$62

B8E3

A6

64

LDX

$64

B8E5

86

63

STX

$63

B8E7

A6

65

LDX

$65

B8E9

86

64

STX

$64

B8EB

A6

70

LDX

$70

B8ED

86

65

STX

$65

BBEF

84

70

STY

$70

B8F1

69

08

ADC

#$08

B8F3

C9

20

CMP

#$20

B8F5

DO

E4

BNE

$B8DB

B8F7

A9

00

LDA

#$00

B8F9

85

61

STA

$61

BSFB

85

66

STA

$66

B8FD

60

B8FE

65

56

ADC

$56

B900

85

70

STA

$70

B902

A5

65

LDA

$65

B904

65

6D

ADC

$6D

B906

B5

65

STA

$65

B908

A5

64

LDA

$64

B90A

65

6C

ADC

$6C

B90C

85

64

STA

$64

B90E

A5

63

LDA

$63

B910

65

6B

ADC

$6B

B912

85

63

STA

$63

B914

A5

62

LDA

$62

B916

65

6A

ADC

$6A

B918

85

62

STA

$62

B91A

4C

36

JMP

$B936

B91D

69

01

ADC

#$01

B91F

06

70

ASL

$70

B921

26

65

ROL

$65

B923

26

64

ROL

$64

B925

26

63

ROL

$63

B927

26

62

ROL

$62

B929

10

F2

BPL

$B91D

B92B

38

B92C

E5

61

SBC

$61

B92E

BO

C7

BCS

$B8F7

B930

49

FF

EOR

#$FF

B932

69

01

ADC

#$01

B934

85

61

STA

$61

B936

90

OE

BCC

$B946

B938

E6

61

INC

$61

B93A

FO

42

BEG

$B97E

invert

TYA

CLC

RTS

B9

SEC

A-58

mantisse

from

FAC

B93C

66

62

ROR

$62

B93E

66

63

ROR

$63

B940

66

64

ROR

$64

B942

66

65

ROR

$65

B944

66

70

ROR

$70

B946

6O

RTS

Invert

***** a-*-*-)****t******4******

B947

A5

66

LDA

B949

49

FF

EOR

#$FF

B94B

85

66

STA

$66

B94D

A5

62

LDA

$62

B94F

49

FF

EOR

#$FF

B951

85

62

STA

$62

B953

A5

63

LDA

$63

B955

49

FF

EOR

#$FF

B957

85

63

STA

$63

B959

A5

64

LDA

$64

B95B

49

FF

EOR

#$FF

B95D

85

64

STA

$64

B95F

A5

65

LDA

$65

B961

49

FF

EOR

#$FF

B963

85

65

STA

$65

B965

A5

70

LDA

$70

B967

49

FF

EOR

#$FF

B969

85

70

STA

$70

B96B

E6

70

INC

$70

B96D

DO

OE

BNE

$B97D

B96F

E6

65

INC

$65

B971

DO

OA

BNE

$B97D

B973

E6

64

INC

$64

B975

DO

06

BNE

$B97D

B977

E6

63

INC

$63

B979

DO

02

BNE

$B97D

B97B

E6

62

INC

$62

B97D

60

B97E

A2

OF

B980

4C

37

mantisse

from

FAC

$66

RTS
A4

LDX

#$0F

JMP

$A437

output

***** ***-5****t******4******

B9B3

A2

25

LDX

B985

B4

O4

LDY

$04, X

B987

84

70

STY

$70

B989

B4

03

LDY

$03, X

94

04

STY

$04, X

B98D

B4

02

LDY

$02, X

B98F

94

03

STY

$03, X

B991

B4

01

LDY

$01, X

B993

94

02

STY

$02, X

B995

A4

68

LDY

$68

B997

94

01

STY

$01, X

B999

69

08

ADC

#$08

B99B

30

E8

BMI

$B985

B99D

FO

E6

BEQ

$B985

B99F

E9

08

SBC

#$08

"OVERFLOW"
error

Rightshifting

#$25

B98B

for

offset

A-59

pointer

message

of
on

register
register

TAY

B9A1

A8

B9A2

A5

7O

LDA

$70

B9A4

BO

14

BCS

$B9BA

B9A6

16

01

ASL

$01, X

B9A8

90

02

BCC

$B9AC

B9AA

F6

01

INC

$01, X

B9AC

76

01

ROR

$O1,X

B9AE

76

01

ROR

$01, X

B9B0

76

02

ROR

$02, X

B9B2

76

03

ROR

$03, X

B9B4

76

04

ROR

$04, X

B9B6

6A

B9B7

C8

B9B8

DO

B9BA

18

CLC

B9BB

60

RTS

ROR
I NY
BNE

EC

$B9A6

*****-**************:**********

B9BC

81

B9C1

03

B9C2

Constants

-for

LOG

00

00

00

OC

3=polynomial

degree

7F

5E

56

CB

7*3

. 434255942

/coe-F-f i ci ents

B9C7
B9CC

80
80

13
76

9B
38

OB
93

64
16

.576584541

B9D1

82

38

AA

3B

2C>

2.88539007

B9D5

20

80

35

04

F3

.707106781

1/SQR(2)

B9DB

81

35

04

F3

34

1.41421356

SQR(2)

B9E0

80

80

00

00

00

-.5

B9E5

80

31

72

17

F8f

.693147181

LOB(2)

BASIC-LOG
get

JSR $BC2B

function

signs

B9EA

20

2B

B9ED

FO

02

BEQ

$B9F1

zero,

B9EF

10

03

BPL

$B9F4

positive,

B9F1

4C

48

JMP

$B248

"ILLEGAL

B9F4

A5

61

LDA

$61

exponent

B9F6

E9

7F

SBC

#$7F

normalize

B9F8

48

B9F9

A9

80

LDA

#$80

bring

B9FB

85

61

STA

$61

-From

B9FD

A9

D6

LDA

#$D6

B9FF

AO

B9

LDY

BA01

20

67

JSR

#$B9
$B867

BA04

A9

DB

LDA

#$DB

BA06

AO

B9

LDY

#$B9

BA08

20

OF

BAOB

A9

BC

LDA

#$BC

BAOD

AO

B9

LDY

#$B9

BAOF

20

5O

BA12

A9

Cl

BA14

AO

B9

BA16

20

43

BA19

A9

BA1B

AO

BA1D

20

67

B2

and

PHA

B8

BB

B8

then

to

divide

JSR $B850
LDA #$C1

to

to

pointer

to

FAC

minus

#$B9
$E043

EO

LDA

#$E0

B9

LDY

#$B9

pointer

JSR

$B867

add

pntr

A-60

range

constant1/SQR(2)

constant
by

SQR(2)

FAC

constant

polynome

polynome

to

in

SQR(2)

JSR

B8

to

FAC

pointer

JSR $BBOF

ok

QUANTITY"

number

0.5

pointer
add

ready
then

save

LDY

EO

.961800759

*****************************

BC

then

coe-f-ficients

calculations

to
FAC

constant

0.5

BA20

68

BA21

2O

7E

PLA

BA24

A9

BA26

AO

BA28

20

8C

BD

get

JSR

$BD7E

E5

LDA

#$E5

B9

LDY

#$B9

back

exponent

FAC=FAC+FAC
pointer
*

BA JSR $BABC

FAC

to

FAC

to
ARG

BNE

$BA3O

not

BA

JMP

$BA8B

RTS

BA

JSR

$BAB7

calculate

00

LDA

#$00

85

26

STA

$26

85

27

STA

$27

BA39

85

28

STA

$28

BA3B

85

29

STA

$29

BA3D

A5

70

BA3F

20

59

BA42

AS

65

BA2B

DO

O3

BA2D

4C

8B

BA30

20

B7

BA33

A9

BA35
BA37

BA

LDA

$70

JSR

$BA59

LDA

$65

JSR

$BA59

LDA

$64

clear

multiplication

bitwise

multiplication

bitwise

multiplication
multiplication

BA49

20

59

BA4C

A5

63

BA4E

20

59

BA51

A5

62

BA53

20

5E

BA

JSR

$BA5E

bitwise

BA56

4C

8F

BB

JMP

$BB8F

register

BA

$BA59

JSR

$BA59

LDA

$62

register

bitwise

59
64

$63

exponent

multiplication

20

JSR

FAC

FAC

bitwise

A5

LDA

-function

BA44

BA

ARG

zero?

BA47

BA

LOG(2)

constant(A/Y)

constant

*****************************

constant

to

FAC,

make

left-

binding
*****************************

BNE

$BA5E

JMP

$B983

BA59

DO

03

BA5B

4C

83

BASE

4A

BASF

09

BA61

A8

BA62

90

BA64

18

BA65

A5

29

LDA

$29

BA67

65

6D

ADC

$6D

BA69

85

29

STA

$29

BA6B

A5

28

LDA

$28

BA6D

65

6C

ADC

$6C

BA6F

85

28

STA

$2B

BA71

A5

27

LDA

$27

BA73

65

6B

ADC

$6B

BA75

85

27

STA

$27

BA77

A5

26

LDA

$26

BA79

65

6A

ADC

$6A

BA7B

85

26

STA

$26

BA7D

66

26

ROR

$26

BA7F

66

27

ROR

$27

BA81

66

28

ROR

$28

BA83

66

29

ROR

$29

BA85

66

70

ROR

$70

BA87

98

B9

Bitwise

right-shifts

LSR
SO

ORA

#$80

TAY

19

BCC

multiplication

$BA7D

CLC

TYA

A-61

the

register

BA88

4A

BA89

DO

BA8B

60

LSR
BNE

D6

$BA61

RTS

*****************************

85

22

STA

BA8E

84

23

STY

$23

BA90

AO

04

LDY

#$04

BA92

Bl

22

LDA

BA94

85

6D

STA

BA96

88

BA97

Bl

22

LDA

BA99

85

6C

STA

constant

(A

pointer

($22),Y

$6D
($22),Y
$6C

constant

DEY

BA9B

88
Bl

22

LDA

BA9E

85

6B

STA

BAAO

88

to

ARG

($22),Y
$6B

DEY

BAA1

Bl

22

LDA

($22),Y

BAA3

85

6E

STA

$6E

BAA5

45

66

EOR

$66

BAA7

85

6F

STA

$6F

BAA9

A5

6E

LDA

$6E

BAAB

09

80

ORA

#$80

BAAD

85

6A

STA

$6A

sign

DEY

BAAF

88

BABO

Bl

22

LDA

($22),Y

BAB2

85

69

STA

$69

BAB4

A5

61

LDA

$61

BAB6

60

BAB7

A5

69

LDA

$69

BAB9

FO

IF

BEQ

$BADA

BABB

18

exponent

RTS

CLC

BABC

65

61

ADC

$61

BABE

90

04

BCC

$BAC4

BACO

30

ID

BMI

$BADF

BAC2

18

BAC3

2C

BAC4
BAC6

10

14

BPL

$BADA

69

80

ADC

#$80

BAC8

85

61

STA

$61

BACA

DO

<^5

BNE

$BACF

BACC

4C

FB

BACF

A5

6F

BAD1

85

66

BAD3

60

BAD4

A5

66

LDA

$66

BAD6
BAD8

49

FF

30

05

EOR
BMI

#$FF
$BADF

CLC

.BYTE

B8

$2C

JMP

$B8FB

LDA

$6F

STA

$66

FAC=O

RTS

PLA

BADA

68

BADB

68

BADC

4C

F7

B8

JMP

$B8F7

BADF

4C

7E

B9

JMP

$B97E

PLA
FAC=O

"OVERFLOW

*****************************

20

DEY

BA9C

BAE2

ARG

$22

BA8C

OC

BC

JSR

FAC

round

$BCOC

A-62

FAC

FAC

ERROR"
*

10

and

put

in

ARG

BAE5

AA

BAE6

FO

BAE8

18

TAX
10

BEQ

i-f

$BAF8

FAC=O,then

ready

CLC

BAE9

69

02

ADC

#$02

exponent

BAEB

BO

F2

PCS

$BADF

balance?

BAED

A2

00

LDX

#$00

BAEF

86

6F

STX

$6F

BAF1

20

77

JSR

$B877

FAC=FAC+ARG,

BAF4

E6

61

INC

$61

increase

exponent,

BAF6

FO

E7

BEQ

$BADF

balance,

then

BAF8

60

-floating

point

BAF9

84

B8

+2

exponent

*4

*5

*2

"OVERFLOW"

RTS

20

00

00

00

FAC
BAFE

20

OC

BB01

A9

BC

JSR

$BCOC

F9

LDA

#$F9

FAC

round

BB03

AO

BA

LDY

#$BA

BB05

A2

00

LDX

#$00

BB07

86

6F

STX

$6F

BB09

20

A2

BB

JSR

$BBA2

constant

BBOC

4C

12

BB

JMP

$BB12

FAC

BBOF

20

8C

BA

JSR

$BA8C

BB12

FO

76

BEQ

$BB8A

FAC=O,

BB14

20

IB

JSR

$BC1B

round

BB17

A9

00

LDA

#$00

BB19

38

BB1A

E5

61

SBC

$61

BB1C

85

61

STA

$61

BB1E

20

B7

JSR

$BAB7

BB21

E6

61

INC

$61

BB23

FO

BA

BEQ

$BADF

BB25

A2

FC

LDX

#$FC

BB27

A9

01

LDA

#$01

BB29

A4

6A

LDY

$6A

BB2B

C4

62

CPY

$62

BB2D

DO

10

BNE

$BB3F

BB2F

A4

6B

LDY

$6B

BB31

C4

63

CPY

$63

BB33

DO

OA

BNE

$BB3F

pointer

FAC

in

(A/Y)

ARG

in

ARG
10

FAC

FAC

constant

put

constant

10

ARG

10

10
and

to

constant
FAC

BC

FAC

constant

(A/Y)
to

FAC

ARG

FAC

"DIVISION BY

ZERO"

FAC

SEC

BA

BB35

A4

6C

LDY

$6C

BB37

C4

64

CPY

$64

BB39

DO

04

BNE

$BB3F

BB3B

A4

6D

LDY

$6D

BB3D

C4

65

CPY

$65

BB3F

08

PHP

BB40

2A

ROL

BB41

90

BB43

E8

BB44

95

29

STA

$29, X

BB46

FO

32

BEQ

$BB7A

09

BCC

determine exponent
exponent

pointer

compare

save
$BB4C

INX

A-63

of

result

overflow

to

function

ARG

status

to

FAC

register

bitwise

BB48

10

34

BPL

$BB7E

BB4A

A9

Ol

LDA

#$01

BB4C

28

BB4D

BO

OE

BCS

$BB5D

BB4F

06

6D

ASL

$6D

BB51

26

6C

ROL

$6C

BB53

26

6B

ROL

$6B

BB55

26

6A

ROL

$6A

BB57

BO

E6

BCS

$BB3F

BB59

3O

CE

BMI

$BB29

BB5B

10

E2

BPL

$BB3F

BB5D

A8

BB5E

A5

6D

LDA

BB60

E5

65

SBC

$65

BB62

85

6D

STA

$6D

BB64

A5

6C

LDA

$6C

BB66

E5

64

SBC

$64

BB68

85

6C

STA

$6C

BB6A

A5

6B

LDA

$6B

BB6C

E5

63

SBC

$63

BB6E

85

6B

STA

$6B

BB70

A5

6A

LDA

$6A

BB72

E5

62

SBC

$62

BB74

85

6A

STA

$6A

BB76

98

BB77

4C

4F

JMP

$BB4F

BB7A

A9

40

LDA

#$40

BB7C

DO

CE

BNE

$BB4C

BB7E

OA

BB7F

OA

ASL

BB80

OA

ASL

BB81

OA

ASL
ASL

BB82

OA

BB83

OA

BB84

85

BB86

28

BB87

4C

PLP

TAY

$6D

TYA
BB

ASL

accumulator

64

register

to

ASL

STA

70

$70

PLP
8F

BB

JMP

$BB8F

help

FAC

*****************************

BB8A
BB8C

A2 14
LDX #$14
4C 37 A4 JMP $A437

##***************************

BB8F

A5

26

LDA

$26

BB91

85

62

STA

$62

BB93

A5

27

LDA

$27

BB95

85

63

STA

$63

BB97

A5

28

LDA

$28

BB99

85

64

STA

$64

BB9B

A5

29

LDA

$29

BB9D

85

65

STA

$65

BB9F

4C

D7

JMP

$B8D7

B8

85

22

STA

"DIVISION

$22

A-64

error

Transfer

make

*****************************

BBA2

for

output

help

FAC

Transfer

BY

ZERO"

message

register

($26-

$29)

FAC

to

left-binding

constant<A/Y)

to

FAC

uo

su6ts

OZ*

*(22*)
T9*

Sid

T6

22

yis

6d38

178

oz.

A1S

8d88

09

I7d88

88

A30

Sd88

sy

yon

T9

60

dZ

yao

dZ*#

0d88

52

29

QNy

29*

22

yis

4(22*)
9*

4(22*)

*(22*)

yis
yai

22

A30
yis
yai

22
179

A30
yis

22

sy

ssajppe

lj&tlj

3388
3383
6333

16

3333

88

9338

88

Z383

sy
16

17338

dO88

T6

1388

88

2383

sy

O2

8T

usv

ai3a*

98

22

X1S

22*

3033
6038

fr8

A1S

2*

oy

tfO

AO1

17O*#

0038

sy

59

yai

59*

3a

6tr

trO

ZS

xai

zs*#

00

aqi

oo*#

038

fraaa*

zaaa
17088

2038
0088
*****

***********************-

ssa_jppe

mo 1

Zd88

2d88

T6

99

yai

99*

A30
A

179*

punoj
ssajppe

fry

yi7

AO1

yi7*

xai
0}

duinr
j-o

oq.

Od
oy

2y

3388
3383
y388

*****************************

32*#

31A8"

3S*#
oq.

32

XO~1

35 2y

6383

Z.388

*****************************

09

yan

A4(22*)

T9

yis

T9*

OL

A1S
^uauodxa

22

uBis

08

08*#

29

29*

yis

yis

99*

yis

9*

yis

179*

2*

99
22
9

22
179

22
59

yis

22

yai

A1S

9388

178

58
ia
88

A30
joj.

yai

A4(22*)

58

60
58
13
88

A3O

yai

A4(22*)

2388
0383
d333
0888

asaa
6aaa
zaaa
9838

58

T3
88

A30

yai

A4(22*)

58

18
88

A3a

59*

A4(22*)

170

frO*#

58
13
oy

2883
1888

dy83
ayas
3yaa

yyaa
syaa
9yaa

178

auo

dZ.*

uoiq.Dunj.

u&ts

99-V

}a6

N9S-3ISV8

van

00*#

vs

59*

VIS

179*

X1S

19*

19
tr9

59

&

u&ts

S^qBtJ

}ag

MOU

aseajDui

fiuipunoj

aueid

<->aqq.

ApEBJ

lojaz

'ou

^uauodxa
3Vd

punoy

3Vd

dd

dO3

dd*#

00

van

00*#

VIS

9*

S38

833*

van

I0*#

038

van

99*

38

82

TO
20
dd

99
60
T9

63

T9

van

19*

3d

033

WT33*

nsv

OZ*

338

VT38*

ysr

d968*

3N3

VT38*

dwr

868*

2d
68

d9

LA

QL

58

617

SV
2V
58

dtr38

01733

air38
61738
81733

9tr38

171738
2tr38
01733

338

58

338

6V
02

6V

08
6V
SV
Od
SV

317

oa
02
06
90
Od

SV

638

838

933

fr38
238
I 33
d238
0238
8238

8238
9238
238
T2J8

dT38

0138
8T38

*****************************

punoj

-lai-sueji

8138

98

OL

xs

OZ*

VT38

09

9133

use

3138*

90

xan

90*#

S3

09

T38

56

89

X'89* vxs
X'O9* van

5T33

V3

38

8T

1133
3038

02

dO38

2V

*****************************

Jaj-sueji

98

6V

00

29

van

29*

29

vxs

29*

van

dd*#

van

19*

838*

*****************************

^iqs

d,QJ3Z

assi^ueuj

uaq^.

Sid

9UV

09

SH
3N8

2038*

X1S

OZ*

OL
6d

98
oa

8033
6038
Z.038

van

39*

vis

99*

5O

xan

50*#

S3

89

frO33

56

09

9033

V3

X*09* vis
X*89* van

X3a

sa^Aq

9yv

58
V2

~10U

88

xai

88*#

asr

8233*

*****************************

09

sia
^aAT^isod
^aAiq.e6au

V2

now

^OJSZ

3Vd
aseajDut

Aq

-JaB6tq

Appaj

oa

6d

3N3

TT33*

X3a

3Vd

^-

3Wd

99

39

2033

3d83

58

0038

2V
5V

3d38

*****************************

BC51

85

70

STA

$70

BC53

85

66

STA

$66

BC55

4C

D2

JMP

$B8D2

B8

*****************************

BC58

46

66

LSR

$66

BC5A

60

BC5B

85

24

STA

$24

BC5D

84

25

STY

$25

BC5F

AO

OO

LDY

#$OO

BC61

Bl

24

LDA

BC63

C8

BASIC-ABS
clear

function

sign

bit

RTS
Til ARlrnxiijiiiiiiiJiiiH

Compare

constant(A/Y)

with

FAC
pointer

to

constant

exponent

($24),Y

I NY

BC64

AA

BC65

FO

C4

BEQ

BC67

Bl

24

LDA

TAX

zero,

$BC2B

then

get

sign

o-f

FAC

($24),Y

BC69

45

66

EOR

$66

BC6B

30

C2

BMI

$BC2F

BC6D

E4

61

CPX

$61

BC6F

DO

21

BNE

$BC92

BC71

Bl

24

LDA

BC73

09

80

ORA

#$80

dif-feren

($24),Y

BC75

C5

62

CMP

$62

BC77

DO

19

BNE

$BC92

BC79

C8

signs

compare

1.

byte

compare

2-

byte

compare

3.

byte

compare

4-

byte

I NY

BC7A

Bl

24

LDA

BC7C

C5

63

CMP

$63

12

BNE

$BC92

($24),Y

BC7E

DO

BC80

C8

BC81

Bl

24

LDA

BC83

C5

64

CMP

$64

BC85

DO

OB

BNE

$BC92

BC87

C8

BC88

A9

7F

LDA

#$7F

BC8A

C5

70

CMP

$70

I NY
($24),Y

I NY

BC8C

Bl

24

LDA

BC8E

E5

65

SBC

$65

BC90

FO

28

BEQ

$BCBA

BC92

A5

66

LDA

$66

BC94

90

02

BCC

$BC98

BC96

49

FF

EOR

#$FF

result

BC98

4C

31

JMP

$BC31

set

BC

($24),Y

*****************************

smaller,

-flag

Change

-for

then

-floating-point

BC9B

A5

61

LDA

$61

exponent

BC9D

FO

4A

BEQ

$BCE9

zero?

BC9F

38

BCAO

E9

AO

SBC

#$A0

BCA2

24

66

BIT

$66

BCA4

10

09

BPL

$BCAF

BCA6

AA

invert

result
to

integer

SEC

TAX

BCA7

A9

FF

LDA

#$FF

BCA9

85

68

STA

$68

BCAB

20

4D

JSR

$B94D

BCAE

8A

B9

invert

TXA

A-67

mantisse

o-f

FAC

BCAF

A2

BCB1
BCB3
BCB5
BCB8

C9 F9
CMP
10 06
BPL
20 99 B9 JSR
84 68
STY

61

LDX

#$61

BCBA
BCBB

60
A8

BCBC

A5

66

LDA $66

BCBE

29

80

AND

#$80

BCCO

46 62

LSR

$62

BCC2

05

ORA $62

BCC4
BCC6

85 62
20 BO

BCC9

84

BCCB

60

#$F9
$BCBB
$B999
$68

shift

FAC

right

shift

FAC

right

RTS
TAY

62
B9

68

STA
JSR

$62
$B9B0

STY

$68

RTS

*****************************

BASIC-INT

LDA

$61

exponent

AO

CMP

#$A0

whole

20

BCS

$BCF2

yes,

JSR

$BC9B

change

70

STY

$70

A5

66

LDA

$66

84

66

STY

$66

BCDB

49

80

EOR

#$80

BCDD

2A

BCDE

A9

AO

LDA

#$A0

BCEO

85

61

STA

$61

BCE2

A5

65

LDA

$65

BCE4

85

07

STA

$07

BCE6

4C

D2

JMP

$B8D2

BCE9

85

62

STA

$62

BCEB

85

63

STA

$63

BCED

85

64

STA

$64

BCEF

85

65

STA

$65

BCF1

A8

TAY

BCF2

60

RTS

BCCC

A5

BCCE

C9

BCDO

BO

BCD2

20

9B

BCD5

84

BCD7
BCD9

61

BC

AO

function

number?
then

ready

FAC

to

integer

ROL

B8

*****************************

BCF3

bitwise

make

FAC

fill

mantise

left-binding

Change

ASCII

to

00

LDY

#$00

point

format

clear

range

BCF5

A2

OA

LDX

#$0A

BCF7

94

5D

STY

$5D,X

BCF9

CA

BCFA

10

FB

BPL

$BCF7

BCFC

90

OF

BCC

$BDOD

BCFE

C9

2D

CMP

#$2D

BDOO

DO

04

BNE

$BDO6

BD02

86

67

STX

$67

BD04

FO

04

BEQ

$BDOA

BD06

C9

2B

CMP

#$2B

BD08

DO

O5

BNE

$BDOF

BDOA

20

73

JSR

$0073

BDOD

9O

5B

BCC

$BD6A

BDOF

C9

2E

CMP

#$2E

BD11

FO

2E

BEQ

$BD41

with

$5D

zeros

Floating
to

$66

DEX

00

flag

for

CHRGET

A-68

negative

get

next

character

BD13

C9

45

CMP

BD15

DO

30

BNE

$BD47

BD17

20

73

JSR

$0073

BD1A

90

17

BCC

$BD33

OO

#$45

BD1C

C9

AB

CMP

#$AB

BD1E

FO

OE

BEQ

$BD2E

BD20

C9

2D

CMP

#$2D

BD22

FO

OA

BEQ

$BD2E

BD24

C9

AA

CMP

#$AA

BD26

FO

08

BEQ

$BD30

BD28

C9

2B

CMP

#$2B

BD2A

FO

O4

BEQ

$BD30

BD2C

DO

07

BNE

$BD35

BD2E

66

60

ROR

$60

BD30

20

73

JSR

$0073

BD33

9O

5C

BCC

$BD91

OO

BD35

24

60

BIT

$60

BD37

10

OE

BPL

$BD47

BD39

A9

00

LDA

#$00

SBC

BD3B

38

BD3C

E5

5E

BD3E

4C

49

BD41

66

BD43

CHRGET
"-"

BD

BASIC

code

11+ "

BASIC

code

set

bit

ii

$BD49

ROR

$5F

24

5F

BIT

$5F

BD45

50

C3

BVC

$BDOA

BD47

A5

5E

LDA

$5E

BD49

38

BD4A

E5

5D

SBC

$5D

BD4C

85

5E

STA

$5E

BD4E

FO

12

BEQ

$BD62

BD50

10

09

BPL

$BD5B

BD52

20

FE

ii

CHRGET
bit

BD55

E6

BD57
BD59
BD5B

BA

$BAFE

5E

INC

$5E

DO

F9

BNE

*BD52

FO

07

BEQ

$BD62

20

E2

JSR

$BAE2

BD5E

C6

5E

DEC

*5E

BD60

DO

F9

BNE

$BD5B

BA

BD62

A5

67

LDA

$67

BD64

30

01

BMI

*BD67

BD66

60

call

decimal

FAC

FAC

1O

FAC

FAC

10

point

RTS

4C
48

BD6B

24

5F

BIT

$5F

BD6D

10

02

BPL

$BD71

BD6F

E6

5D

INC

$5D

BD71

20

E2

JSR

*BAE2

FAC

BD74

68

BD75

38

BD76

E9

30

SBC

#$30

ASCII

BD78

20

7E

BD

JSR

$BD7E

BD7B

4C

OA

BD

JMP

$BDOA

add
next

OC

BC

$BCOC

FAC

68

character

set?

by

BD67

BD82

next

no

BD6A

48

get

SEC

JSR

20

character

$5E

5F

BD7F

next

SEC

JMP

BD7E

get

B4

BF

JMP

*BFB4

change

o-f

sign

FAC

PHA

BA

FAC

10

PLA
SEC

PHA
JSR
PLA

A-69

$30

next

Hex

digit

character

to

ARG

to

FAC

-FAC

BD83

20

3C

JSR

$BC3C

BD86

A5

6E

LDA

$6E

BD88

45

66

EOR

$66

BD8A

85

6F

STA

$6F

BD8C

A6

61

LDX

$61

BD8E

4C

6A

JMP

$BB6A

FAC

BD91

A5

5E

LDA

$5E

call

BD93

C9

OA

CMP

#$0A

BD95

90

09

BCC

$BDAO

BD97

A9

64

LDA

#$64

BD99

24

60

BIT

$60

BD9B

3O

11

BMI

$BDAE

BD9D

4C

7E

JMP

$B97E

BDAO

OA

ASL

BDA1

OA

ASL

BDA2

18

BDA3

65

BDA5

OA

BC

B8

B9

FAC
by

"OVERFLOW

ERROR"

CLC
$5E

ADC

5E

ASL
CLC

BDA6

18

BDA7

AO

00

LDY

BDA9

71

7A

ADC

BDAB

38

BDAC

E9

30

SBC

#$30

BDAE

85 5E

STA

$5E

BDBO

4C

JMP

$BD30

#$00

($7A),Y

SEC

30

BD

get

next

character

Constants

for

BDB3
BDB8

9B 3E BC
9E 6E 6B

IF FD
27 FD

99999999.9

BDBD

9E

28

1E9

6E

6B

BDC2
BDC4

A9 71
AO A3

BDC6

20

DA

BDC9

A5

BDCB

Out-put

line

LDA #$71
LDY #$A3

pointer

JSR

$BDUR

output

3A

LDA

$3A

A6 39

LDX

$39

BD

r***r**4-***>^*******-

BDCD

85

62

STA

$62

BDCF

86

63

STX

$63

BDD1

A2

90

LDX

#$90

BDD3

38

BDD4

20

49

BC

JSR

$BC49

BDD7

20

DF

BD

JSR

$BDDF

BDDA

4C

IE

AB

JMP

$AB1E

get

to

write

-for

integer

out-put

FAC

11

$66

sign

02

BPL

$BDE7

positive?

2D

LDA

#$2D

11-"

STA

$OOFF,Y

write

66

STA

$66

71

STY

$71

10

A9

BDE7

99

FF

BDEA

85

BDEC

84

00

FAC

to -floating
ASCII

point

to

ASCII

and
in

#$20

BDE5

to

in

A-70

"

space

minus
in

A/X

string

LDA

BDE3

number

integer

change

FAC

BIT

24

line

change

Change

rnesg

"IN"

change

20

A9

BDE1

error

in

66

BDDF

at

positive

#$01

AO

current

LDY

01

BDDD

point

string

Out-put

SEC

***** ***)<-**)***<***)********

-floating

999999999

00

******************************

*****

ARG

"E"

put
$100

for

positive

-for

negative

bu-f-fer

range

BDEE

CB

BDEF

A9

30

LDA

#$30

BDF1

A6

61

LDX

$61

BDF3

DO

03

BNE

$BDFB

BDF5

4C

04

JMP

$BF04

I NY

BF

BDF8

A9

00

LDA

#$00

BDFA

EO

80

CPX

#$80

BDFC

FO

02

BEQ

$BEOO

BDFE

BO

09

BCS

$BE09

BEOO

A9

BD

LDA #$BD

BE02

AO

BD

BEO4

2O

28

BE07

A9

BE09

LDY
BA

$BA28

F7

LDA

#$F7

85

5D

STA $5D

BEOB

A9

B8

LDA

#$BB

BEOD

AO

BD

LDY

#$BD

BEOF

20

5B

JSR

$BC5B

BE12

FO

IE

BEQ

$BE32

BE14

10

12

BPL

$BE28

BE16

A9

B3

LDA

#$B3

BE18

AO

BD

LDY

#$BD

BE1A

20

5B

JSR

$BC5B

BE1D

FO

02

BEQ

$BE21

BE1F

10

OE

BPL

$BE2F

BE21

20

E2

BE24

C6

5D

BC

BA

JSR

$BAE2

DEC

$5D

BE26

DO

EE

BE28

2O

FE

BE2B

E6

BE2D

DO

BE2F

2O

49

BE32

20

9B

BE35

A2

BE37

A5

BE39

BE3A

18
69

OA

ADC

#$0A

BE3C

30

09

BMI

$BE47

BE3E

C9

OB

CMP

#$0B

BE40

BO

06

BCS

$BE48

BE42

69

FF

ADC

#$FF

BE44

AA

BE45

A9

BE47

38

BE48

E9

02

SBC

#$02

BE4A

85

5E

STA

$5E

BE4C

86

5D

STX

$5D

BE4E

8A

BE4F

FO

02

BEQ

$BE53

BE51

10

13

BPL

$BE66

BE53

A4

71

LDY

$71

BE55

A9

2E

LDA

#$2E

BE57

C8

BE58

99

BE5B

8A

BNE

$BE16

JSR

$BAFE

5D

INC

$5D

DC

BNE

$BEOB

B8

JSR

$B849

BC

JSR

$BC9B

01

LDX

#$01

5D

LDA

$5D

BA

yes,

not

zero?

ready

compare

#$BD

JSR

BC

exponent

number

FAC

with

FAC bigger

than

pointer

constant

to

constant

pntr

(pointer

to constant

compare

999999999

constant

99999999.9
(pointer

A/Y with

FAC = FAC

FAC

FAC

10

10

FAC = FAC + .5,


FAC to integer

round

CLC

TAX
LDA

02

#$02

SEC

TXA

I NY
FF

00

STA

$OOFF,Y

TXA

A-71

*FAC

(pointer
A/Y with FAC

to constant

compare

1E9

A/Y)

constant

equal

pntr

amount

smaller

0.1?

amount

greater

1E9?

FAC

BE5C

FO

06

BEQ

$BE64

BE5E

A9

30

LDA

#$30

BE60

C8

"0"

I NY

BE61

99

FF

STA

$OOFF,Y

BE64

84

71

STY

$71

BE66

AO

00

LDY

#$00

BE68

A2

80

LDX

#$B0

BE6A

A5

65

LDA

$65

00

BE6C

18

CLC

BE6D

79

19 BF ADC

$BF19,Y

BE70

85

65

STA

$65

BE72

A5

64

LDA

BE74

79

18 BF ADC

of

the

seperate
digits

$64

$BF18,Y

BE77

85

64

STA

$64

BE79

A5

63

LDA

$63

BE7B

79

17 BF

ADC

$BF17fY

BE7E

85

63

STA

$63

BE80

A5

62

BE82

79

16

BF

calculation

LDA

$62

ADC

$BF16,Y

$62

BE85

85 62

STA

BE87

E8

I NX

BE88

BO

04

BCS $BE8E

BE8A
BE8C

10

DE

BPL

30

02

BMI

$BE6A
$BE90

BE8E

30

DA

BMI

$BE6A

BE90

8A

TXA

BE91

90

04

BCC

$BE97

BE93

49

FF

EOR

#$FF

BE95

69

OA

ADC

#$0A

BE97

69

2F

ADC

#$2F

BE99

C8

I NY

BE9A

C8

I NY

BE9B

C8

I NY

BE9C

C8

BE9D

84

47

STY

$47

BE9F

A4 71

LDY

$71

BEA1

C8

I NY

I NY

BEA2

AA

BEA3

29

7F

AND #$7F

BEA5

99

FF 00

STA

$OOFF,Y

BEA8
BEAA

C6 5D
DO 06

DEC
BNE

$5D

BEAC
BEAE

A9

LDA
I NY

#$2E

BEAF

99

FF

STA

$OOFF,Y

BEB2

84

71

STY

$71

BEB4

A4

47

LDY

$47

BEB6

8A

BEB7

49

FF

EOR

#$FF

BEB9

29

80

AND

#$80

BEBB

AA

BEBC

CO 24

CPY

#$24

BEBE

FO

04

BEQ

$BEC4

BECO

CO

3C

CPY

#$3C

BEC2

DO

A6

BNE

$BE6A

TAX

2E

C8

00

$BEB2

TXA

TAX

table-end

table-end

A-72

at FAC-change

at TI$ calculation

BEC4

A4 71

BEC6

B9

BEC9

88

BECA

C9

30

CMP

#$30

BECC

FO

F8

BEQ

$BEC6

BECE

C9

2E

CMP

#$2E

BEDO

FO

01

BEQ

$BED3

BED2

C8

BED3

A9

2B

LDA

#$2B

BED5

A6

5E

LDX

$5E

BED7

FO

2E

BEQ

$BF07

BED9

10

08

BPL

$BEE3

BEDB

A9

00

LDA

#$00

BEDD

38

BEDE

E5

BEEO

AA

BEE1

A9

2D

BEE3

99

01

FF

SEC
5E

45

99

00

BEEB

8A
A2

SBC

$5E

TAX

A9

38

$71

$OOFF,Y

I NY

BEE6

BEEE

LDY
LDA
DEY

BEEB
BEEC

00

LDA
01

01

#$2D

STA $0101,Y
LDA

#$45

STA

$0100,Y

TXA
2F

LDX

#$2F

SEC
INX

BEEF

E8

BEFO

E9

OA

SBC

#$OA

BEF2

BO

FB

BCS

$BEEF

BEF4

69

3A

ADC

#$3A

BEF6

99

03

STA

$0103,Y

BEF9

8A

01

TXA
STA

$0102,Y

LDA

#$00

STA

$0104,Y

BEQ

$BFOC

STA

$OOFF,Y

LDA

#$00

STA

$0100,Y

00

LDA

#$00

01

LDY

#$O1

BEFA

99

02

BEFD

A9

00

BEFF

99

04

BF02

FO

08

BF04

99

FF

BF07

A9

00

BF09

99

00

BFOC

A9

BFOE

AO

BF1O

60

01
01
00
01

end

buffer

with

$00

end

buffer

with

$00

pointer

to buffer

$100

RTS

*****************************

BF11

80

00

00

00 00

constant

*****************************

0.5

Constants for

for

Floating-point

32 bit #s with
100 OOO 000

BF16

FA

OA

IF

OO

BF1A

00

98

96

80

10

BF1E

FF

FO

BD

CO

BF22

OO

01

86

AO

BF26

FF

FF

D8

FO

000 000
000

000

100

000

10 000

BF2A

00

00

03

E8

BF2E

FF

FF

FF

9C

100

BF32

00

00

00

OA

10

BF36

FF

FF

FF

FF

A-73

000

SQR

signs

Constants -for
2

FF

DF

OA

8O

BF3E

00

O3

4B

CO

216

BF42

FF

FF

73

60

36

000

BF46

OO

00

OE

10

600

BF4A

FF

FF

FD

A8

600

BF4E

00

00

00

3C

6O

BF52

EC

Br53

nn

BF70

...

to TI$

000

AA

*****************************

BF71

20

OC

BF74

A9

11

LDA #$11

BF76

AO BF

LDY #$BF

BC

BB

BASIC-SQR

round

JSR $BCOC

rRRRIr'n n r ni

itfriririr

JSR

BF78

20

A2

BF7B

FO

70

BEQ

-function
FAC and put

pointer

FAC=ARG -*

FAC=ARG

A5

69

LDA

$69

exponent

BF7F

DO

03

BNE

$BF84

not

BF81

4C

F9

JMP

$B8F9

ready

BF84

A2

4E

LDX

#$4E

constant

constant

(A/Y)

FAC

ARG

to

exponent

FAC=

BF8D

10

OF

BPL $BF9E

smaller

one?

BF8F

20

CC

A9

4E

JSR $BCCC
LDA #$4E

INT

BF92
BF94

AO

00

BF96

20

5B

BF99

DO

03

BF9B

98

FAC

basis?

helping

BF8B

BC

0-5

zero?

pointer

20

BC

ARG

to FAC

LDY #$00
AO 00
D4 BB JSR $BBD4
LDA $6E
A5 6E

BF88

in

$BFED

BF7D

B8

to

constant

$BBA2
E-4Hf-iHHH

BF86

change -from TI

16O 000

BF3A

to helping

accum.

accumulator

power

exponent

function

LDY

#$OO

pointer

to

JSR

$BC5B

compare

with

helping

BNE

$BF9E

accum.

FAC

TYA

BF9C

A4

07

LDY

$07

BF9E

20

FE BB

JSR

$BBFE

ARG

to FAC

BFA1

98

BFA2

48

BFA3

20

EA

JSR $B9EA

LOG

function

BFA6

A9

4E

LDA

#$4E

BFA8

AO

00

LDY

#$00

pointer

BFAA

20

28 BA

JSR

$BA28

multiply

BFAD

20

ED

BFBO

68

TYA
PHA
B9

BF

EXP

JSR $BFED

LSR

4A

BFB2

90

OA

BCC

$BFBE

BFB4

A5

61

LDA

$61

BFB6

FO

06

BEQ

$BFBE

BFB8

A5

66

LDA

$66

BFBA

49

FF

EOR

#$FF

BFBC

85

66

STA

$66

BFBE

60

exponent

invert

RTS

A-74

helping

with

function

PLA

BFB1

to

FAC

accum.

Constants
38 AA 3B

29

-for

EXP

BFBF

81

BFC4

O7

BFC5

71

34

58

3E

56

BFCA

74

16

7E

B3

IB

1-4352314E-4

BFCF

77

2F

EE

E3

85

1-34226348E-3

1-44269504 =

l/L0G(2)

degree

polynome

2.14987637E-5

BFD4

7A

ID 84

1C

2A

9.614011701E-3

BFD9

7C

63

59

58

9A

-055051269

BFDE

7E 75

FD

E7

C6

-24O226385

BFE3

80

31

72

18

10

-693147186

BFE8

81

00

OO

OO

OO

BFED

A9

BF

BFEF

AO

BF

BFF1

20

28

BFF4

A5

BFF6

69

BFF8

BASIC-EXP
LDA

#$BF

LDY

#$BF

JSR

$BA28

70

LDA

$70

50

ADC

#$50

90

03

BCC

$BFFD

BFFA

2O

23

BC

JSR

$BC23

BFFD
EOOO

4C
85

OO

EO

56

JMP
BTA

$E000
$56

E002

20

OF

E005

A5

61

E007

C9

E009

90

BA

BC

get

$61

exponent

88

CMP

#$88

number

03

BCC

$EOOE

D4

BA

JSR

$BAD4

20

CC

BC

JSR

$BCCC

07

LDA

$07

EO11

A5

E013

18

E014

69

81

ADC

#$81

E016

FO

F3

BEQ

$EOOB

E018

38

E019

E9

EO1B

48

EO1C

A2

05

LDX

#$05

EO1E

B5

69

LDA

$69, X

E020

B4

61

LDY

$61, X

E022

95

61

STA

$61, X

E024

94

69

STY

$69, X

E026

CA

FAC

by

in

FAC

to

ARG

larger

positive,

INT

than

128?

"OVERFLOW"

function

eaual

to

127?

SEC
01

SBC

#$01

PHA

switch

FAC

and

ARG

DEX

E027

10

F5

BPL

$EO1E

A5

56

LDA

$56

E02B

85

70

STA

$70

E02D

20

53

B8

JSR

$B853

BF

E030

20

B4

E033

A9

C4

E035

AO

BF

E037

20

59

EO

JSR

$BFB4

LDA

#$C4

LDY

#$BF

JSR

$E059

E03A

A9

OO

LDA

#$00

E03C

85

6F

STA

$6F

E03E

68
20

of

CLC

E029

60

l/L0S(2)

FAC

one

$BCOF

20

constant
with

increase mantissa

JSR

EOOB

E03F

to

multiply

LDA

EOOE

E042

pointer

function

ARG-FAC

change of

sign

pointer to polynome coef.


calculate polynome

PLA
B9

BA

JSR

$BAB9

RTS

A-75

exponents

of

FAC

and

ARG

HflK

UK

r a

A HIririn

E043

85 71

E045

84 72

E047

20 CA

EO4A

A9

57

E04C

2O

28

BA
EO

E04F

2O

5D

E052

A9

57

E054

A0

OO

E056

4C 28

BB

wv ji trjijvviHfifiJiftJiit

STA

$71

STY

$72

pointer

bring

#$57

FAC

85 71

E05B

84 72

E05D

2O

C7

EO6O

Bl

$EO5D

to

polynome

LDY

BA

#$OO

pointer

JMP $BA28

degree

accum.

accum.
#3

#3

#3

(square)

calculation
to

FAC = FAC
Polynome

accum.

accum.

calc.

#3

#3

y=aO+al*x+a2*

STA $71

pointer

JSR $BBC7

bring

71

LDA

polynome

E062

85 67

STA

$67

E064

A4 71

LDY

$71

EO66

C8

I NY

E067

98

TYA

E068

DO O2

BNE

$E06C

E06A

E6

72

INC

$72

E06C

85 71

STA

$71

E06E

A4 72

LDY

$72

E070

20

28

E073

A5

E075

A4

EO77

18

E078

69

05

ADC

#$05

E07A

90

01

BCC

$EO7D

E07C

C8

E07D

85

71

STA

$71

E07F

84

72

STY

$72

E081

20

67

E084

A9

5C

LDA

#$5C

E086

A0

00

LDY

#$00

E088

C6

67

DEC

$67

E08A

DO

E4

BNE

$E070

E08C

60

BB

($71),Y

to polynome degree

FAC to

$BA28

71

LDA

$71

72

LDY

$72

accum

#4

degree

counter

increase

JSR

BA

as

then

pointer,

on

-first

shows

coefficient

FAC

= FAC * constant

add

(A/Y)

CLC

to

pointer,

next

I NY

B8

FAC = FAC +

JSR $B867

constant

pointer to accum.
decrease counter

#4

RTS

*****************************

E09C

20 2B BC JSR $BC2B
30 37
BMI $E0D3
DO 20
BNE $EOBE

E09E

20 F3 FF JSR $FFF3

E0A1

86

22

STX

$22

E0A3

84

23

STY

$23

E0A5

AO

04

LDY

#$04

E0A7

Bl

22

LDA

($22),Y

E0A9

85

62

STA

$62

Constant

for

RND

11879546

98 35 44 7A 00
68 28 Bl 46 00

3.92767774E-4

*****************************

E097
E09A

polynome

accum.

STY $72

E08D
E092

y=al*x

LDA #$57

*****************************

E059

to

FAC ot

pointer

JSR $BA28
JSR

calculations

+a1*x A3+a3*x A5

JSR $BBCA
LDA

Polynome

BASIC-RND
get

function

sign

negative?

get

basic

save

timer

A-76

as

address CIA

pointer

low

(A/Y)

EOAB

C8

EOAC

Bl

22

LDA

EOAE

85

64

STA

$64

EOBO

AO

08

LDY

#$08

E0B2

Bl

22

LDA

E0B4

85

63

STA

INY

E0B6

CB

E0B7

Bl

22

LDA

E0B9

85

65

STA

($22),Y

($22),Y

timer

high

timer

low

timer

2 high

$63

INY
($22),Y

$65

EOBB

4C

E3

JMP

$E0E3

EOBE

A9

8B

LDA

#$8B

EOCO

AO

00

LDY

#$OO

pointer

E0C2

20

A2 BB

JSR

$BBA2

put

#$8D

EO

in

to

last

RND value

FAC

E0C5

A9

8D

LDA

E0C7

AO

EO

LDY

#$E0

E0C9

20

28 BA

JSR

pointer to constant

$BA28

#$92

FAC = FAC * constant

EOCC

A9

92

LDA

EOCE

AO

EO

LDY

#$E0

EODO

20

67

JSR

$B867

B8

E0D3

A6

65

LDX

$65

E0D5

A5

62

LDA

$62

E0D7

85

65

STA

$65

E0D9

86

62

STX

$62

EODB

A6

63

LDX

$63
$64

EODD

A5

64

LDA

EODF

85 63

STA

$63

EOE1

86

64

STX

$64

E0E3

A9

00

LDA

#$00

E0E5

85

66

STA

$66

E0E7

A5

61

LDA

$61

E0E9

85

70

STA

$70

EOEB

A9

80

LDA #$80

EOED

85

61

STA

$61

EOEF

20

D7 B8

JSR

$B8D7

E0F2

A2

8B

LDX

#$8B

LDY

#$00

JMP

$BBD4

pointer

switch digits

in FAC

exponent

make FAC

E0F4

AO

00

E0F6

4C

D4

E0F9

C9

FO

CMP

#$F0

EOFB

DO

O7

BNE

$E104

EOFD

84

38

STY

$38

EOFF

86

37

STX

$37

E1O1

4C

63 A6

JMP

$A663

E104

AA

E105

DO

02

BNE

$E109

E107

A2

IE

LDX

#$1E

E109

number

4C

37

JMP

$A437

output

E10C
ElOF

20 D2 FF JSR $FFD2
BO E8
BCS $E0F9

El11

60

El12
El15
El 17

20 CF FF JSR $FFCF
BO E2
BCS $E0F9
60
RTS

BB

to constant

FAC = FAC + constant

round

set

left

FAC and

binding

save

BASIC-RAM end

to CLR command

TAX

A4

BASIC

for

"BREAK"

error

message

BSOUT

out-put

a character

RTS

BASIC BASIN
get

A-77

character

******************************

El18
ElIB

20 AD E4
BO DC

JSR SE4AD
BCS $EOF9

El ID

60

RTS

set

*****************************

ElIE
E121

2O C6 FF JSR $FFC6
BO D6
BCS SE0F9

El 23

60

BASIC CKOUT
output

BAISC
set

CHKIN
input

*****************************

20 E4 FF JSR

El27

BO DO

BCS *EOF9

El 29

60

RTS

$FFE4

BASIC

get

*****************************

GETIN

character

command

SYS

E12A

20

8A

AD

JSR

$AD8A

FRMNVM,

E12D

20

F7

B7

JSR

*B7F7

change to

El

LDA

#*E1

E130

A9
48

E133

A9

device

RTS

El24

E132

device

PHA

LDA

46

return

get

numeric

address

address

term

format

on

stack

#$46

PHA

E135

48

E136

AD

E139

48

E13A

AD

OC

03

E13D

AE

OD

03

E140

AC

OE

03

E143

28

E144

6C

14

00

E147

08

E148

8D

OC

03

OF

03

$030F

status

LDA

$O3OC

ac c umu1ator

LDX

*030D

switch

LDY

$030E

LDA
PHA

and

PLP
JMP

set
(*0014)

status

call

routine

PHP

save

status

STA *030C

accumulator

E14B

8E OD 03 STX

*030D

E14E

8C

STY

$030E

E151

68

E152

8D

$030F

status

OE

03

register

Y register

save

register,

register,

and

PLA

OF

03

STA

again

E155
*****************************

E156

20

D4

E159

A6

E15B
E15D

El

SAVE

command

JSR

$E1D4

parameter

2D

LDX

$2D

end

A4

2E

LDY

$2E

A9

2B

LDA

#$2B

start

E15F

20

D8

JSR

*FFD8

save

El62

BO

95

BCS

$E0F9

E164

60

FF

A9

El67

2C

01

LDA

#$0i

address
routine

VERIFY

command

verify -Flag

.BYTE $2C

*****************************

LOAD

El68

A9 00

LDA

#*00

1 oad

E16A

85 OA

STA

$0A

save

E16C

20 D4

El

JSR $E1D4

get

A-78

prim,

BASIC

RTS

*****************************

E165

(name,

address=

command
-f 1 ag

parameters

sec)

prgm end

pointer
BASIC

to

start

E16F

A5

OA

LDA

$0A

flag

E171

A6

2B

LDX

$2B

start

E173

A4

2C

LDY

*2C

E175

20

D5

JSR

*FFD5

E178

BO

57

BCS

*E1D1

E17A

A5

OA

LDA

*OA

E17C

FO

17

BEQ

*E195

E17E

A2

1C

LDX

#*1C

o-f-fset

E180

20

B7

JSR

*FFB7

get

FF

FF

load

address

BASIC-start

routine

load/verify

-fo

-flag

veri-fy

error

status

E183

29

1O

AND

#$1O

isolate

E185

DO

17

BNE

$E19E

status-bit

E187

A5

7A

LDA

$7A

E189

C9

02

CMP

#*02

check

E18B

FO

07

BEQ

*E194

yes,

E18D

A9

64

LDA

#*64

pointer

E18F

AO

A3

LDY

#$A3

E191

4C

IE

JMP

SAB IE

E194

60

AB

errorbit

on
the

set,

then

direct

mode

error

ready
to

"OK"

out-put

RTS

E195

20

B7

JSR

$FFB7

get

E198

29

BF

AND

#$BF

clear

E19A

FO

05

BEQ

*E1A1

no

LDX

#$1D

offset

JMP

$A437

out-put

$7B

E19C

A2

ID

E19E

4C

37

FF

A4

status
EOF-bit

error

for

"LOAD

error

E1A1

A5

7B

LDA

E1A3

C9

02

CMP

#*02

check

E1A5

DO

OE

BNE

*E1B5

no,

then

end

address

E1A7

86

2D

STX

$2D

E1A9

84

2E

STY

*2E

E1AB

A9

76

LDA

#*76

E1AD

AO

A3

LDY

#*A3

direct
=

program-end

on

out-put

string

E1AF

20

IE

AB

JSR

*AB1E

4C

2A

A5

JMP

*A52A

E1B5

20

8E

A6

JSR

*A68E

CHRGET

find

"READY."

programs

lines

pointer

E1B8

20

33

A5

JSR

*A533

fin

E1BB

4C

77

A6

JMP

$A677

initialize

ElBE

20

19

E2

JSR

$E219

get

E1C1

20

CO

FF

JSR

*FFCO

E1C4

BO

OB

OPEN

E1C6

60

E1C7

20

E1CA

A5

49

E1CC

20

C3

E1CF

90

C3

E1D1

4C

F9

E1D4

A9

00

E1D6

20

BD

E1D9

A2

E1DB

AO

E1DD

20

BA

program

BASIC-OPEN

BCS *E1D1

mode

continue

pointer

E1B2

ERROR"

message

over,CLR

to start

lines

again

ROSTORE,

BASIC

command

parameter
routine

RTS
BASIC-CLOSE

19

E2

JSR

$E219

get

LDA

$49

file

JSR

*FFC3

CLOSE

BCC

$E194

JMP

$E0F9

LDA

#*00

JSR

$FFBD

01

LDX

#*01

00

LDY

#*00

JSR

$FFBA

FF

EO

FF

FF

Get

number

routine

parameter

default

set

command

parameter

for

for

LOAD/SAVE

length

default

for

name

device number

default for second,


set file parameter

A-79

of

filename parameter
address

E1EO

20 06 E2 JSR $E2O6

further

E1E3
E1E6
E1E9

2O 57 E2 JSR $E257
20 06 E2 JSR $E206
20 00 E2 JSR $E200

get

El EC
E1EE
E1F0
E1F3
E1F6

AO
86
20
20
20
8A
A8
A6
4C

E1F9
E1FA
E1FB
E1FD

characters?

-filename

further

OO
LDY #$OO
49
STX $49
BA FF JSR $FFBA
06 E2 JSR $E206
00 E2 JSR $E2OO

parameter

set

-file

more

TXA
TAY
49
LDX $49
BA FF JMP $FFBA

characters?

get

parameter

characters?

get

parameter

set

-file

parameter

*****************************

E200
E203

2O OE E2 JSR $E20E
4C 9E B7 JMP $B79E

checks

get

*****************************

E2O6
E209
E2OB
E20C
E20D

20 79 00 JSR $0079
DO 02
BNE $E2OD
68
PLA
68
PLA
60
RTS

Checks

value

on

CHRGOT
more

and

on

byte

-further

get

more

let-

ters

to

last

characters
character

characters,then

otherwise

return

to

return

higher
routine

*****************************

E20E
E211
E214
E216

20
20
DO
4C

FD AE JSR $AEFD
79 OO JSR $0079
F7
BNE $E20D
08 AF JMP $AF08

on

CHRGOT

get

more

Get

last

character

parameter
-for

-for

A9

E21B

20 BD FF JSR $FFBD

set

E21E
E221

20 11 E2 JSR $E211
20 9E B7 JSR $B79E

more

characters?

gets

logical

E224
E226
E227

86 49
8A
A2 01

de-fault

device

E229
E22B
E22E

AO 00
LDY #$00
20 BA FF JSR $FFBA
20 06 E2 JSR $E206

de-fault

-for

more

characters?

E231
E234
E236

20 00 E2 JSR $E200
86 4A
STX $4A
AO OO
LDY #$00

gets

device

E238
E23A
E23C

A5 49
EO 03
90 01

E23E
E23F
E242

88
DEY
2O BA FF JSR $FFBA
20 06 E2 JSR $E206

more

characters?

E245

20

gets

secondary

E248
E249

8A
A8

E24A

A6

00

set

-file

o-f

name

parameter

-file

to

E2

JSR

set

$E200

LDX

$4A

A- 80

-file

address

secondary

parameter
address

LDA $49
CPX #$03
BCC $E23F

TXA
TAY
4A

-filename

OPEN

length

E219

STX $49
TXA
LDX #$01

return

ERROR"

de-fault

LDA #$00

comma

characters,then

"SYNTAX

*****************************

00

checks

parameter
address

addrs

E24C

A5

49

LDA

$49

E24E

20

BA

FF

JSR

$FFBA

set

E251

20

06

E2

JSR

$E206

more

E254

20

OE

E2

JSR

$E20E

E257

20

9E

AD

JSR

$AD9E

FRMEVL

get

E25A

20

A3

B6

JSR

$B6A3

checks

on

E25D

A6

22

LDX

$22

E25F

A4

23

LDY

$23

E261

4C

BD

JMP

$FFBD

FF

A9

EO

E266

AO

E2

E268

20

67

B8

***** ***)fr-JHH

LDA

#$E0

LDY

#$E2

pointer

JSR

$B867

add

to

to

round

constant

and

LDA

#$E5

AO

E2

LDY

#$E2

A6

6E

LDX

$6E

E274

20

07

BB

JSR

$BB07

divide

E277

20

OC

BC

JSR

$BCOC

round

E27A

20

CC

BC

JSR

$BCCC

INT

-Function

ARG

minus

E26E

A9

E270
E272

pointer

A9

00

LDA

#$00

85

6F

STA

$6F

E281

20

53

JSR

$B853

E284

A9

EA

LDA

#$EA

E286

AO

E2

LDY

#$E2

painter

E288

20

50

JSR

$B850

0-25

E28B

A5

66

LDA

$66

E28D

48

sign

on

E28E

10

PHA

BPL

OD

positive?

20

49

JSR

$B849

FAC

66

LDA

$66

sign

E295

30

09

BMI

$E2A0

negative?

E297

A5

12

LDA

$12

E299

49

FF

EOR

#$FF

E29B

85

12

STA

$12

E29D

20

B4

JSR

$BFB4

E2A0

A9

EA

LDA

#$EA

E2A2

AO

E2

20

67

E2A7

68

E2A8

10

03

E2AA

20

B4

E2AD

A9

EF

E2AF
E2B1

AO

E2

4C

43

*****

B8

BF

EO

change

20

CA

E2B7

A9

OO

E2B9

85

12

E2BB

20

6B

E2BE

A2

4E

BB

#$E2

pointer

$B867

FAA

get

sign

$E2AD

positive?

change

$BFB4

#$EF

LDY

#$E2

pointer

JMP

$E043

calculate

E2

LDA

#$00

o-f

FAC

to

constant

-Flag

polynome

polynomial

-Function

accum.

STA

$12

JSR

set

$E26B

calculate

A-81

constant

0.25

O.25

sign

to

BASIC-TAN

LHY

ARG

signs

to

JSR

$BBCA

in

0.25

LDA

JSR

Pi

around

o-f

JSR

(**-(***(***(*****

E2B4

Pi

FAC

-flag

LDY

BPL

put

ARG

+0.5

turn

PLA

in

stack

$E29D

A5

E2A4

by

and

to

E293

BF

FAC

E290

B8

put

constant

FAC

E27D

B8

to

FAC

E27F

B8

-Function

FAC

E5

OC

Pi

FAC

$BCOC

20

term

-function

BASIC-SIN

{***

term

string

JSR

E26B

BC

parameter

characters?

BASIC-COS

***** ***-){-*t-**-*(****f-*****

E264

-File

SIN

#3

coe-F-F.

E2C0

AO

00

E2C2

20

F6

E2C5

A9

57

LDA

#$57

E2C7

AO

00

LDY

#$00

E2C9

20

A2

JSR

$BBA2

EO

BB

LDY

#$00

JSR

$E0F6

pointer

FAC

to

to

pointer
accum.

helping

helping

to
#3

aceurn.

E2CC

A9

00

LDA

#$00

85

66

STA

$66

E2D0

A5

12

LDA

$12

E2D2

20

DC

JSR

$E2DC

E2D5

A9

4E

LDA

#$4E

E2D7

AO

00

LDY

#$00

E2D9

4C

OF

JMP

$BBOF

divide by

FAC

E2DC

48

E2DD

4C

9D

E2

JMP

$E29D

calculate

COS

81

49

OF

DA

E2E5

83 49

OF

DA A2

E2EA

7F 00 00 00 00

BB

sign

flag

COS

calculate
pointer

PHA

to

helping

A2

6.28318531
5

polynomial

05

84 E6

1A 2D

E2F5

86 28

07 FB F8

E2FA

87 99

68 89

E2FF

87 23 35

DF El

81.6O52237

E3O4

86

A5 5D

E7

-41.3147O21

E309

83

49

42.0077971
-76.7041703

01
28

6.28318531

OF DA A2

*****************************

E31O

48

PHA

E311

10 03

BPL $E316

E313

20 B4 BF JSR $BFB4

E316

A5

61

LDA
CMP

E31B

90

07

BCC $E324

E31D

A9

BC

LDA

#$BC

E31F

AO

B9

LDY

#$B9

E321

20 OF BB JSR $BBOF

E324

A9

E326

E328

AO E3
LDY #$E3
20 43 EO JSR $EO43

E32B

68

68
PLA
10 03
BPL $E33D
4C B4 BF JMP $BFB4

E33D

60

number

pointer

divide

to

pointer

with

constant

by FAC(reciprical)
to polynome

calculate

get

PLA

E337
E338
E33A

exponent
number smaller

pointer
Pi/2
get

coe-f-f-

polynome

back

was

#$81
$E337
#$E0
#$E2
$B850

to constant

than

1?

Pi/2

minus FAC
sign

positive?

change

o-f

signs

RTS

*****************************

E33E

signs

smaller?

LDA #$3E

E334

E332

o-f

compare

#$81

C9
90
A9
AO
20

E330

change

exponent
save

81

E32E

positive?

PHA

48

CMP
BCC
LDA
LDY
JSR

-function

sign

$61

C9

81
07
EO
E2
50 B8

2*Pi

save

E319

E32C

BASIC-ATN

$66

E318

3E

degree

-14.3813907

IB

LDA

COS

2*Pi

E2F0

A5 66

(SIN)

0.25

E2EF

E30E

accum.

Constants -for SIN and


1.57O79633
Pi/2

**********

E2E0

#3

to FAC

E2CE

E2

aceurn.

accumulator

OB

A-82

Floatingpoint

constants

ll=polynome degree

-for

ATN

E33F

76

B3

83

BD

D3

E344

79

IE

F4

A6

F5

4.B5094216E-03

E349

7B

83

FC

BO

10

E34E

7C

OC

IF

67

CA

.034209638

E353

7C

DE

53

CB

Cl

E358

7D

14

64

7O

4C

-0724571965

E35D

7D

B7

EA

51

7A

E362

7D

63

30

88

7E

-11O932413

E367

7E

92

44

99

3A

E36C

7E

4C

CC

91

C7

.19999912

E371

7F

AA

AA

AA

13

-.333333316

E376

81

OO

00

00

00

-6.84793912E-O4

2O

CC

E37E

A9

E380

85

E382

20

7A

E385

58

E386

A2

80

E3B8

6C

00

E38B

8A

E3BC

30

03

E38E

4C

3A

E391

4C

74

FF

-054279133

-0898019185
.142839808

1
BASIC

***** ***(***(**->{-*** ********

E37B

.0161117015

NMI

re-enterance

JSR

$FFCC

00

LDA

#$00

13

STA

*13

input

JSR

SA67A

initialize

A6

CLRCH
device

keyboard

BASIC

CLI

LDX
03

JMP

#$80
($0300)

BASIC

warm-start

TXA

vector

<JMP

BMI

$E391

A4

JMP

$A43A

output

A4

JMP

*A474

ready

*****************************

BASIC

error

*E38B>

message

mode
cold-start

E394
E397
E39A

20 53 E4 JSR $E453
2O BF E3 JSR *E3BF
20 22 E4 JSR *E422

set BASIC vectors


initialize RAM
out-put power-on message

E39D

A2 FB

LDX

set

E39F

9A

TXS

E3A0

DO E4

BNE $E3B6

#*FB

to warm-start

*****************************

E3A2

E6

7A

INC

*7A

E3A4

DO

02

BNE

*E3A8

E3A6

E6

7B

INC

*7B

E3A8

AD

60

LDA

$EA60

E3AB

C9

3A

CMP

#*3A

E3AD

BO

OA

BCS

*E3B9

E3AF

C9

20

CMP

#*20

E3B1

FO

EF

BEQ

*E3A2

E3B3

38

E3B4

E9

E3B6

38

E3B7

E9

E3B9

60

EA

Copy

o-f

CHRGET-routine

SEC
30

SBC

#$30

SEC
DO

SBC

#*DO

RTS

*****************************

E3BA

stack-pointer

80 4F C7 52 58

Start

value

-for

RND

-function

.811635157

*****************************

Initialize

RAM

E3BF

A9 4C

LDA #$4C

JMP

E3C1

85 54

STA $54

for -functions

A-83

-for

BASIC

E3C3

BD

10

STA

$0310

E3C6

A9

48

LDA

#$48

E3C8

AO

B2

LDY

#$B2

E3CA

8D

11

O3

STA

$0311

E3CD

8C

12

O3

STY

$0312

E3D0

A9

91

LDA

#$91

E3D2

AO

B3

LDY

#$B3

E3D4

85

05

STA

$05

E3D6

84

06

STY

$06

E3D8

A9

AA

LDA

#$AA

E3DA

AO

Bl

LDY

#$B1

E3DC

85

03

STA

$03

E3DE

84

04

STY

$04

E3E0

A2

1C

LDX

#$1C

E3E2

BD

A2

LDA

$E3A2,X

CHRGET-routine

E3E5

95

73

STA

$73, X

copy

E3E7

CA

O3

E3

-for

USRfunctions

points
save

to
as

"ILLEGAL

QUANTITY"

USR-vector

$B391

vector

for

-fixed

~~

to

point

-floating

conversion

$B3AA

vector

-for

-floating
point

into

to

-fixed

conversion

RAM

DEX
$E3E2

E3E8

10

F8

BPL

E3EA

A9

03

LDA

#$03

E3EC

85

53

STA

$53

E3EE

A9

00

LDA

#$00

E3F0

85

68

STA

$68

E3F2

85

13

STA

$13

E3F4

85

18

STA

$18

E3F6

A2

01

LDX

#$01

E3F8

8E

FD

01

STX

$01FD

E3FB

8E

FC

Ol

STX

$01 FC

E3FE

A2

19

LDX

#$19

E400

86

16

STX

$16

pointer

-for

E402

38

E403
E406

20

9C
2B

get

RAM

start

86

E408

84

2C

as

BASIC

E40A

38

E40B

20

99

E40E

86

37

E410

84

38

STY

$38

E412

86

33

STX

$33

E414

B4

34

STY

$34

E416

AO

00

LDY

#$00

E418

98

E419

91

2B

STA

E41B

E6

2B

INC

$2B

E41D

DO

02

BNE

$E421

E41F

E6

2C

INC

$2C

E421

60

step-width

-for

garbagecollection

input-device

keyboard

string

stack

SEC
FF

JSR

$FF9C

STX

$2B

STY

$2C

save

JSR

$FF99

get

STX

$37

start

SEC

FF

RAM

save

as

end

BASIC

end

TYA

$00

($2B),Y

to

BASIC

BASIC
start

start
+

RTS

*****************************

E422
E424

A5 2B
A4 2C

E426

20

08

E429

A9

E42B

LDA
LDY

$2B
$2C

pointer

JSR $A40B

checks

73

LDA

#$73

pointer

AO E4

LDY

#$E4

A4

A--84

to
on
to

BASIC-RAM
-free

start

memory

poweron

message

AB

E42D

20

IE

E430

A5

37

E432

38

E433

E5

E435

AA

E436

A5

38

E438

E5

2C

E43A

20

CD

E43D

A9

E43F

A0

E441

20

IE

E444

4C

44

JSR

$AB1E

LDA

$37

out-put

SEC
TAX

*2C

equals

$BDCD

output

quantity

60

LDA

#$60

pointer

to

E4

LDY

#*E4

AB

JSR

*AB1E

out-put

string

A6

JMP

*A644

to

83

A4

E44F

E4

A7

86

AE

7C

A5

E453

A2

1A

E455

BD

47

E458

9D

00

E45B

CA

NEW

Table

of

BASIC

#$0B

E4

LDA

$E447, X

03

STA

*0300, X

Load

BASIC

System

00

20

42

41

53

49

43

20

E467

42

59

54

45

53

20

46

52

20

20 2A

2A

E46F

45

45

OD

00

E473

93

OD 20

20

E47B

2A 2A 20

43 4F

4D 4D 4F

E483

44

4F

52

45

2O

36

34

20

E48B

42

41

53

49

43

2O 56

32

E493 20
E49B 36

2A 2A

2A

2A OD OD

20

34

4B

20

52

41

4D

20

E4A3 53 59 53

54

45

4D

20

20

*****************************

48

E4AE

20

E4B1

AA

BASIC
(CLR)
BASIC
(CR)

system

messages
BYTES
****
V2

FREE
COMMODORE

64

****

(CR)

BASIC-CKOUT

64K

RAM

SYSTEM

routine

PHA

C9

FF

JSR

*FFC9

CKOUT

TAX

E4B2

68

E4B3

90

E4B5

8A

TXA

E4B6

60

RTS

E4B7

AA

E4D9

vectors

RTS

*****************************

E4AD

vectors

*E455

BPL

F7

E45F

5C

BYTES

DEX

Opperating

E4AC

"BASIC

command

*****************************

00

-free

A7

LDX

OB

bytes

FREE"

*****************************

E4AB

start

JSR

E3

10

BASIC

SBC
BD

8B

60

ninus

*38

E447

E45E

end

LDA

*****************************

E45C

BASIC
*2B

SBC

2B

string

PLA
01

BCC

*E4B6

AA

**********************#*****

A-85

set

out-put

device

E4DA

AD

21

E4DD

91

F3

E4DF

60

RJHRX

DO

LDA

STA

back-ground

$DO21

RTS

HUNTrun h H K

Waits

H?

-for

E4E0

69

02

ADC

#$02

2*256/60

E4E2

A4

91

LDY

$91

check

E4E4

C8

E4E5

DO

04

BNE

$E4EB

key

E4E7

C5

Al

CMP

$A1

is

E4E9

DO

F7

BNE

$E4E2

E4EB

60

19

Commodore-key
=

wait

8-5

seconds

-Flag

I NY
pressed?
time

over?

RTS

*****************************

E4EC

color

($F3>,Y

Timer

constants

26

$2619=9753

-for

RS-232

SObaud/Baud-Rate

E4EE

44

19

$1944

6468

75

baud

E4F0

1A

11

$111A

4378

110

baud

E4F2

E8

OD

$ODE8

3560

134.5

E4F4

70

OC

$0C70

=3184

150

baud

baud

E4F6

06

06

$0606

1542

300

baud

E4F8

Dl

02

$O2D1

736

600

baud

E4FA

37

01

$0137

=311

1200

baud

E4FC

AE

00

$OOAE

=174

1800

baud

E4FE

69

00

$0069

=105

2400

baud

JCU.JLJC.Jt JC.JC.JLJ<JC.JC.JC.Jt JC.JCJCJt.4t.Jit.4C,JC.J|.JC.4(>4C.4C.JC.4C.4Ci

E500

A2

00

LDX

#$00

E502

AO

DC

LDY

#$DC

E504

60

Get

basic

address

Gets

of

lines

A2 28

LDX

#$28

4O

columns

E507

AO

LDY

#$19

25

lines

E509

60

19

E50E

and

columns

RTS

***** ***t****TT1r

E50C

CIA

$DC00

****.*************************

BO

the

RTS

E505

E50A

of

Set

w ->rHHftHdnn

cursor

07

BCS

$E513

86

D6

STX

$D6

1 ine

84

D3

STY

$D3

column

E510

20

6C

JSR

$E56C

set

E513

A6

D6

LDX

$D6

E515

A4 D3

LDY

$D3

E517

60

RTS

E5

*****************************

E518

20 AO

E51B

A9

E51D

BD 91

E52O

85

CF

E522

A9

48

E524

8D

8F

E527

A9

EB

E529

8D

90

E52C

A9

OA

E52E

8D

89

E5

00
02

02
02

02

Reset

(C=0)

/get

(C=l)

cursor

screen

initialize

video-controller

JSR

$E5A0

LDA

#$OO

STA

$0291

enable

shift-Commodore

STA

$CF

cursor

not

LDA

#$48

STA

$028F

LDA

#$EB

STA

$0290

LDA

#$0A

blink-phase

$EB4B

($028F)

pointer

in

to

addressis

key-board

counter

STA $0289

A-86

for

for

decoding

repeat-speed

E531

8D

8C

E534

A9

OE

E536

8D

86

E539

A9

04

E53B

8D

BB

E53E

A9

OC

E540

85

E542

85

02
02

02

STA

$O28C

LDA

#$OE

light-blue

STA

$0286

present

LDA

#$04

STA

$028B

LDA

#$0C

CD

STA

$CD

cursor

blink-time

CC

STA

$CC

cursor

blinkflag

repeat-speed

****************************.

E544

AD

88

E547

O9

80

E549

A8

E54A

A9

E54C

AA

02

LDA

$0288

QRA

#$80

Clear

screen

memory-page

94

18

E550

69

28

LDA

#$00

01

D9

$D9,X

addresses

ADC

#$28

add

40

BCC

$E555

26,

all

STY

9O
C8

E555

E8

E556

EO

1A

CPX

#$1A

E558

DO

F3

BNE

$E54D

E55A

A9

FF

LDA

#$FF

E55C

95

D9

STA

$D9,X

E55E

A2

18

LDX

#$18

24

E560

20

FF

JSR

$E9FF

clear

E563

CA

E564

10

line)

INX

E9

lines?

number

of

lines

minus

screenline

DEX
FA

BPL

$E56O

00

LDY

#$00

84

D3

STY

$D3

84

D6

STY

$D6

******************************

A6

(one

I NY

********************************

E56C

the screenline

E552

E56A

of

CLC

E554

E568

screenR

TAX

E54D

AO

for

TAY
00

E54F

E566

color

D6

LDX

$D6

E56E

A5

D3

LDA

$D3

E570

B4

D9

LDY

$D9,X

E572

30

08

BMI

$E57C

E574

18

CLC

E575

69

28

ADC

#$28

E577

B5

D3

STA

$D3

E579

CA

DEX

E57A

10

F4

BPL

$E570

E57C

B5

D9

LDA

$D9,X

E57E

29

03

AND

#$03

E580

OD

88

ORA

$0288

E5B3

85

D2

E585

BD

FO

02
EC

STA

$D2

LDA

$ECFO

E588

85

Dl

STA

$D1

E58A

A9

27

LDA

#$27

E58C

E8

E58D

B4

D9

LDY

$D9,X

E58F

30

06

BMI

$E597

INX

A-87

Cursor

home

cursor

column

cursor

line

Calc.

cursor

position,

cursor

line

cursor

column

set

screenpointer

E591

18

E592

69

E594

E8

CLC
ADC

28

#$28

INX

E595

10

F6

BPL

$E58D

E597

85

D5

STA

$D5

E599

60

RTS

*****************************

E59A

20

A0

E5

JSR

$E5A0

initialize

E59D

4C

66

E5

JMP

$E566

cursor

t-********************

*****

E5A0

A9

03

LDA

#$03

E5A2

85

9A

STA

$9A

E5A4

A9

00

LDA

#$00

E5A6

85

99

STA

$99

E5A8

A2

2F

LDX

#$2F

E5AA

BD

B8

EC

LDA

E5AD

9D

FF

CF

STA

E5B0

CA

E5B1

DO

E5B3

60

videocontroller

home

Initialize
out-put

video-controler

on

screen

input

-from

keyboard

$ECB8,X

write

constants

$CFFF,X

vi deo-control1er

into

DEX
BNE

F7

$E5AA

RTS

*****************************

E5B4

AC 77 02 LDY

$0277

E5B7

A2 00

LDX

#$OO

E5B9

BD

78

02

LDA

$0278,X

E5BC

9D

77

02 STA

$0277,X

E5BF

E8

E5C0

E4

C6

CPX

$C6

E5C2

DO

F5

BNE

$E5B9

E5C4

C6

C6

DEC

$C6

E5C6

98

TYA

E5C7

58

CLI

E5C8

18

CLC

E5C9

60

RTS

Get

character

get

-first

move

-from

keyboard-

character

bu-f-fer

up

-front

INX

compare
decrease
get

o-f

character

character

Waiting-loop

in

-for

number

accumulator

key-board

JSR

$E716

output

LDA

$C6

number

o-f

pressed

STA

$CC

STA

$0292

BEQ

$E5CD
cursor

in

blink-phase?

E5CA

20

16

E5CD

A5

C6

E5CF

85

CC

E5D1

8D

92

E5D4

FO

F7

E5D6

78

E5D7

A5

CF

LDA

$CF

E5D9

FO

OC

BEQ

$E5E7

E5DB

A5

CE

LDA

$CE

E5DD

AE

87

LDX

$0287

E5E0

AO

00

LDY

#$00

E5E2

84

CF

STY

$CF

E5E4

20

13

EA

JSR

$EA13

E5E7

20

B4

E5

JSR

$E5B4

E5EA

C9

83

CMP

#$83

E5EC

DO

10

BNE

$E5FE

E5EE

A2

09

LDX

#$09

E5F0

78

02

number

characters

*****************************

E7

with

character

input
keys

SEI

02

code
9

SEI

A-88

-for

shift-run"?

characters

E5F1

86

C6

STX

$C6

save

E5F3

BD

E6

EC

LDA

*ECE6,X

"load

E5F6

9D

76

02

STA

$0276,X

get

in

then

E5F9

CA

E5FA

DO

F7

BNE

$E5F3

E5FC

FO

CF

BEQ

*E5CD

number

icrX

o-f

C9

OD

CMP

#*OD

DO

C8

BNE

*E5CA

no,

E602

A4

D5

LDY

*D5

length

E604

84

DO

STY

$D0

set

crflag

get

character

E606

Bl

Dl

LDA

E608

C9

20

CMP

#*20

E60A

DO

03

BNE

*E60F

88

DO

E60F

CB

(*D1),Y

back

o-f

to

waiting-

screenline/
-from

eliminate sqace

at

loop

screen

lineend

DEY
F7

BNE

SE606

I NY

E610

84

C8

STY

$C8

E612

AO

OO

LDY

#$00

E614

8C

92

E617

84

D3

02

STY

$0292

STY

*D3

E619

84

D4

STY

$D4

E61B

A5

C9

LDA

*C9

E61D

3O

IB

BMI

$E63A

E61F

A6

D6

LDX

$D6

E621

2O

ED

JSR

*E6ED

E624

E4

C9

CPX

*C9
$E63A

E6

save

position

E626

DO

12

BNE

A5

CA

LDA

*CA

last

E62A

85

D3

STA

*D3

bring

E62C

C5

C8

CMP

*C8

compare

E62E

90

OA

BCC

*E63A

E630

BO

2B

BCS

*E65D

Get

***** ****f-**4&-***E-***-*t*******

into

column-pointer

with

indes

character

TYA

E633

48

PHA

E634

8A

TXA

E635

48

PHA

E636

A5

DO

LDA

$D0

CRflag

E638

FO

93

BEQ

*E5CD

no,

E63A

A4

D3

LDY

$D3

column

E63C

Bl

Dl

LDA

E63E

85

D7

STA

E640

29

3F

AND

#*3F

E642

06

D7

ASL

$D7

E644

24

D7

BIT

*D7

($D1),Y

index

column

98

then

to

-from

screen

waitingloop

get

character

-from

and

change

ASCII

screen

*D7

E646

1O

02

BPL

$E64A

E648

09

80

ORA

#*80

E64A

90

04

BCC

$E650

E64C

A6

D4

LDX

*D4

E64E

DO

04

BNE

$E654

E650

70

02

BVS

*E654

E652

09

40

ORA

#*40

E654

E6

D3

INC

$D3

move

E656

20

84

JSR

*E684

check

E6

as

cursorcolumn

E628

E632

"

bu-ffer

DEX

E5FE

E60C

<cr>

keyboard

E600

E60D

characters

run

A-89

cursor

on

to

one

forward

highcomma

cursor

in

last

E659

C4

C8

CPY

$C8

E65B

DO

17

BNE

$E674

E65D

A9

00

LDA

#*00

E65F

85

DO

BTA

$D0

E661

A9

OD

LDA

#*0D

E663

A6

99

LDX

$99

E665

EO

O3

CPX

#*03

input

E667

FO

06

BEQ

*E66F

yes

E669

A6

9A

LDX

$9A

out-put

E66B

EO

03

CPX

#$03

yes

E66D

FO

O3

BEQ

$E672

E66F

20

16

JSR

$E716

E672

A9

OD

LDA

#*0D

E674

85

D7

STA

*D7

E676

68

PLA

E677

AA

TAX

E678

68

PLA

E679

A8

E67A

A5

D7

LDA

$D7

screencode

E67C

C9

DE

CMP

#*DE

compare

E67E

DO

02

BNE

$E682

E680

A9

FF

LDA

#*FF

E682

18

CLC

E683

60

RTS

E7

column?

11 CR"~flag

write

-from

on

screen?

screen?

character

on

screen

TAY

yes,

with

code -for

substitute

by

BASIC-

code

**************){***)******

E684

C9

22

CMP

#*22

E686

DO

08

BNE

*E690

E68B

A5

D4

LDA

$D4

E68A

49

Ol

EOR

#$01

E68C

85

D4

STA

$D4

E68E

A9

22

LDA

#$22

E690

6O

Check

on

no,

then

turn

high

-for

Pi

comma

ready

around

restore

Pi

highcomma

highcomma

-flag

code

RTS

***** ***)******]***]******

E691

09

40

ORA

#$40

E693

A6

C7

LDX

$C7

E695

FO

02

BEQ

$E699

E697

09

80

ORA

#$80

E699

A6

D8

LDX

$D8

E69B

FO

02

BEQ

$E69F

E69D

C6

D8

DEC

$D8

E69F

AE

86 O2

LDX

$0286

E6A2

20

13

EA

JSR

$EA13

E6A5

2O

B6

E6

JSR

$E6B6

E6A8

68

E6A9

A8

E6AA

A5

D8

LDA

$D8

E6AC

FO

O2

BEQ

$E6BO

E6AE

46

D4

LSR

$D4

E6B0

68

E6B1

AA

TAX

E6B2

68

PLA

E6B3

18

CLC

E6B4

58

CLI

color

write

code

character

update

PLA
TAY

PLA

A-90

into

line-start

screen-

table/

E6B5

60

RTS

*******"* *** *** **********

E6B6

2O

E6B9

E6

E6BB

A5

E6BD

C5

D3

B3

E8

JSR

$E8B3

D3

INC

$D3

D5

LDA

*D5

CMP

*D3

$E700

E6BF

BO

3F

BCS

E6C1

C9

4F

CMP

#$4F

E6C3

FO

32

BEQ

*E6F7

LDA

$0292

E6C5

AD

92

E6CB

FO

O3

E6CA

4C

67

02
E9

BEQ

*E6CD

JMP

$E967

E6CD

A6

D6

LDX

$D6

E6CF

EO

19

CPX

#$19

E6D1

90

07

BCC E6DA

E6D3

20

EA

JSR

$E8EA

E6D6

C6

D6

DEC

*D6

E6DB

A6

D6

LDX

$D6

E6DA

16

D9

ASL

*D9,X

E6DC

56

D9

LSR

*D9,X

E8

E6DE

E8

E6DF

B5

D9

LDA

$D9,X

E6E1

09

80

ORA

#$80

D9

STA

$D9,X

E6E3

95

E6E5

CA

E6E6

A5

E6EB

18

Calculate

79

DEX

LDA

$D5

CLC

E6E9

69

28

ADC

E6EB

85

D5

STA

$D5

E6ED

B5

D9

LDA

$D9,X

E6EF

30

03

BMI

$E6F4

E6F1

CA

E6F2

DO

F9

E6F4

4C

FO

#$28

DEX
E9

BNE

$E6ED

JMP

$E9F0

DEC

$D6

JSR

$E87C

E6F7

C6

D6

E6F9

20

7C

E6FC

A9

00

LDA

#$00

E6FE

85

D3

STA

$D3

E700

60

E701

A6

D6

LDX

$D6

E703

DO

O6

BNE

$E70B

E705

86

D3

STX

$D3

E707

68

E8

RTS

PLA

E708

68

E709

DO

E70B

CA

E70C

86

D6

E70E

20

6C

E711

A4

D5

E713

84

D3

E715

60

PLA

9D

BNE

$E6A8

DEX

STX
E5

$D6

JSR

$E56C

LDY

$D5

STY

$D3

RTS

E716

48

E717

85

E719

8A

TXA

E71A

48

PHA

PHA

D7

STA

-for

new

1 i re
starts

INX

D5

MSB

$D7

A-91

chacacters

lines)?

TYA

E71B

98

E71C

48

E71D

A9

00

LDA

#*OO

E71F

85

DO

STA

$D0

E721

A4

D3

LDY

*D3

E723

A5

D7

LDA

$D7

E725

1O

03

BPL

*E72A

E727

4C

D4

JMP

SE7D4

E72A

C9

OD

CMP

#*0D

E72C

DO

03

BNE

*E731

E72E

4C

91

JMP

SE891

E731

C9

20

CMP

#*20

E733

90

10

BCC

*E745

E735

C9

60

CMP

#$60

E737

9O

04

BCC

*E73D

E739

29

DF

AND

#*DF

E73B

DO

02

BNE

*E73F

E73D

29

3F

AND

#*3F

E73F

20

84

E6

JSR

*E684

E742

4C

93

E6

JMP

SE693

E745

A6

D8

LDX

*D8

E747

FO

03

BEQ

SE74C

E749

4C

97

JMP

*E697

E74C

C9

14

CMP

#$14

E74E

DO

2E

BNE

*E77E

E750

98

E751

DO

06

BNE

*E759

E753

20

01

E7

JSR

*E7O1

E756

4C

73

E7

JMP

*E773

E759

20

Al

E8

JSR

$E8A1

E75C

88

E75D

84

D3

E75F

20

24

E762

CB

E763

Bl

E765

88

E766

91

E768

C8

E769

Bl

E76B

88

E76C
E76E

91
C8

F3

STA
I NY

E76F

C4

D5

CPY

*D5

E771

DO

EF

BNE

*E762

E773

A9

20

LDA

#*20

E775

91

Dl

STA

(*D1)

E777

AD

86

LDA

*0286

E77A

91

F3

STA

(*F3)

E77C

10

4D

BPL

*E7CB

E77E

A6

D4

LDX

*D4

E780

FO

03

BEQ

*E785

E782

4C

97

JMP

*E697

E785

C9

12

CMP

#*12

E787

DO

02

BNE

*E78B

E789

85

C7

STA

*C7

E78B

C9

13

CMP

#*13

PHA

E7

E8

E6

TYA

DEY
EA

STY

*D3

JSR

*EA24

I NY
LDA

Dl

(*D1)

DEY
STA

Dl

(*D1)

I NY

LDA

F3

(*F3)

DEY

02

E6

(*F3)

A-92

E7BD
E78F

DO
20

03
66 E5

BNE $E792
JSR $E566

E792
E794
E796

C9
DO
C8

ID
17

CMP #$1D
BNE $E7AD
INY

E797
E79A
E79C

20 B3 E8 JSR $EBB3
84 D3
STY $D3
88
DEY

E79D
E79F
E7A1

C4 D5
90 O9
C6 D6

E7A3
E7A6
E7A8

20 7C E8 JSR $EB7C
AO 00
LDY #$00
84 D3
STY $D3

CPY $D5
BCC $E7AA
DEC $D6

E7AA

4C A8 E6 JMP $E6A8

E7AD

C9

11

CMP

E7AF

DO

ID

BNE $E7CE

E7B1
E7B2

18
98

#$11

CLC
TYA

E7B3

69

E7B5

A8

28

ADC #$28
TAY

E7B6
E7B8

E6 D6
C5 D5

CMP $D5

E7BA
E7BC
E7BE

90 EC
FO EA
C6 D6

E7C0
E7C2
E7C4

E9 28
9O O4
85 D3

E7C6
E7C8

DO F8
20 7C E8

INC $D6

E7CB

4C A8 E6

E7CE

2O CB E8

E7D1
E7D4

4C 44 EC
29 7F

BCC
BEQ
DEC
SBC
BCC
STA
BNE
JSR
JMP
JSR
JMP
AND

$E7A8
$E7A8
$D6
#$28
$E7C8
$D3
$E7C0
$EB7C
$E6A8
$E8CB
$EC44

E7D6

C9

7F

CMP

E7D8

DO

02

BNE

$E7DC

E7DA

A9

5E

LDA

#$5E

E7DC

C9

20

CMP

E7DE
E7E0

90
4C

03
BCC
91 E6 JMP

#$20
$E7E3
$E691

E7E3
E7E5

C9
DO

E7E7

OD
CMP #$0D
03
BNE $E7EA
4C 91 E8 JMP

E7EA
E7EC

A6
DO

D4
3F

LDX
BNE

E7EE

C9

14

CMP

#$14

E7F0
E7F2

DO 37
A4 D5

BNE
LDY

$E829
$D5

$EB2D

E7F4

Bl

Dl

LDA

($D1),Y

E7F6

C9

20

CMP

#$20

E7FB

DO

04

BNE

$E7FE

E7FA

C4

D3

CPY

$D3

E7FC

DO

07

BNE

$EB05

E7FE

CO

4F

CPY

#$4F

E800

FO

24

BEQ

$EB26

A-93

E9

JSR

$E965

LDY

$D5

JSR

$EA24

E802

20

65

E805

A4

D5

E807

20

24

E80A

88

E8OB

Bl

E80D

C8

E8OE

91

E810

88

E811

Bl

E813

C8

E814

91

E816

88

E817

C4

D3

CPY

$D3

E819

DO

EF

BNE

$E80A

E81B

A9

20

LDA

#$20

E81D

91

Dl

STA

E81F

AD

86

E822

91

F3

STA

($F3),,Y

E824

E6

D8

INC

$D8

E826

4C

A8

JMP

$E6A8

E829

A6

D8

LDX

$D8

E82B

FO

05

BEQ

$E832

E82D

09

40

ORA

#$40

EB2F

4C

97

JMP

$E697

EA

DEY
LDA

Dl

($D1), Y

I NY

STA

Dl

($D1), Y

DEY

LDA

F3

($F3), Y

I NY
STA

F3

($F3),,Y

DEY

O2

E6

E6

LDA

space

<$D1),,Y

write

$0286

to

set
color

<"***-<-****"*-)

***

E832

C9

11

CMP

#$11

E834

DO

16

BNE

$E84C

E836

A6

D6

LDX

$D6

E838

FO

37

BEQ

$E871

E83A

C6

D6

DEC

$D6

E83C

A5

D3

LDA

$D3

E83E

3B

E83F

E9

28

SBC

#$28

E841

90

04

BCC

$E847

E843

85

D3

STA

$D3

E845

10

2A

BPL

$E871

E847

20

6C

JSR

$E56C

E84A

DO

25

BNE

$E871

E84C

C9

12

CMP

#$12

E84E

DO

04

BNE

$E854

E85O

A9

00

LDA

#$00

E852

85

C7

STA

$C7

E854

C9

ID

CMP

#$1D

E856

DO

12

BNE

$E86A

E858

98

E859

FO

09

E85B

20

Al

E85E

88

E85F

84

D3

STY

$D3

E861

4C

A8

E6

JMP

$E6A8

E864

20

01

E7

JSR

$E7O1

cursor

SEC

E5

TYA
E8

BEQ

$EB64

JSR

$E8A1

DEY

A-94

up

present

position

E867

4C

A8

E86A

C9

13

CMP

#*13

E86C

DO

06

BNE

*E874

E86E

20

44

E5

JSR

E871

*E544

4C

A8

E6

JMP

*E6A8

ORA

#*80

JSR

*E8CB

JMP

*EC4F

E6

EB74

09

80

E876

2O

CB

E8
EC

JMP

*E6A8

E879

4C

4F

E87C

46

C9

LSR

*C9

E87E

A6

D6

LDX

*D6

E880

E8

E881

EO

19

CPX

#*19

E883

DO

03

BNE

*E888

JSR

*E8EA

INX

E885

20

EA

E888

B5

D9

LDA

*D9,X

E88A

10

F4

BPL

*E880

E8

E88C

86

D6

E88E

4C

6C

E891

A2

OO

LDX

E893

#*00

86

D8

STX

*D8

E5

STX

*D6

JMP

*E56C

E895

86

C7

STX

*C7

E897

86

D4

STX

*D4

E899

86

D3

STX

*D3

E89B

20

7C

E8

JSR

*E87C

E89E

4C

A8

E6

JMP

*E6A8

E8A1

A2

02

LDX

#*02

E8A3

A9

00

LDA

#*00

E8A5

C5

D3

CMP

*D3

E8A7

FO

07

BEQ

*E8B0

E8A9

18

E8AA

69

E8AC

CA

E8AD

DO

E8AF

60

E8B0

C6

E8B2

60

CLC
28

ADC

#*28

DEX

F6

BNE

*E8A5

RTS

D6

DEC

*D6

RTS

E8B3

A2

02

LDX

#*02

E8B5

A9

27

LDA

#*27

E8B7

C5

D3

CMP

*D3

E8B9

FO

07

BEQ

*E8C2

EBBB

IS

E8BC

69

E8BE

CA

E8BF

DO

EBCi

60

CLC

28

ADC

#*28

DEX
F6

BNE

*E8B7

RTS

E8C2

A6

D6

LDX

E8C4

EO

19

CPX

#*19

E8C6

FO

02

BEQ

*E8CA

E8C8

E6

D6

INC

*D6

E8CA

60

E8CB

A2

OF

E8CD

DD

DA

E8D0

FO

E8D2

CA

E8D3

1O

*D6

RTS
LDX

#*0F

CMP

*E8DA,X

check

04

BEQ

*E8D6

found

FQ

BPL

E8

DEX
*EBCD

A-95

on

color-codes

E8D5
E8D6

60
RTS
8E 86 O2 BTX

E8D9

60

$0286

*****************************

E8DA 90 05
E8E2 81

set

colorcode

RTS

1C 9F 9C

IE

Table

of

color-codes

IF 9E

95 96 97 98 99 9A 9B

*****************************
LDA

A5

E8EC

48

E8ED

A5

E8EF

48

E8F0

A5

E8F2

48

E8F3

A5

E8F5

48

E8F6

A2

FF

LDX

#$FF

E8F8

C6

D6

DEC

$D6

E8FA

C6

C9

DEC

$C9

E8FC

CE

A5

DEC

$02A5

E8FF

E8

AC

Scroll

screen

$AC

E8EA

PHA

LDA

AD

$AD

PHA
LDA

AE

$AE

PHA

LDA

AF

$AF

PHA

02

INX

E900

20

FO

JSR

$E9F0

E9O3

E0

18

CPX

#$18

E905

B0

OC

BCS

$E913

E9O7

BD

Fl

LDA

$ECF1,X

E90A

85

AC

STA

$AC

E90C

B5

DA

LDA

$DA,X

E9OE

20

C8

JSR

$E9C8

E911

30

EC

BMI

$E8FF

E913

20

FF

JSR

$E9FF

E916

A2

00

LDX

#$00

E918

B5

D9

LDA

$D9,X

E91A

29

7F

AND

#$7F

E91C

B4

DA

LDY

$DA,X

E91E

10

O2

BPL

$E922

E920

09

80

ORA

#$80

E922

95

D9

STA

$D9,X

E924

E8

E9

EC

E9

E9

shi-ft

screen-line

clear

screen-line

INX

E925

EO

18

CPX

#$18

E927

DO

EF

BNE

$E918

E929

A5

Fl

LDA

$F1

E92B

09

80

ORA

#$80

E92D

85

Fl

STA

$F1

E92F

A5

D9

LDA

$D9

E931

10

C3

BPL

$E8F6

INC

$D6

INC

$02A5

LDA

#$7F

$DCOO

E933

E6

D6

E935

EE

A5

E938

A9

7F

E93A

8D

00

DC

STA

E93D

AD

01

DC

LDA

$DCO1

E940

C9

FB

CMP

#$FB

E942

08

E943

A9

7F

E945

8D

00

02

CTRL-key

PHP

DC

LDA

#$7F

STA

$DCOO

A-96

pressed?

up

E948

28

E949

DO

OB

BNE

*E956

E94B

00

LDY

tt*OO

E94D

AO
EA

PLP

NOP

E94E

CA

E94F

DO

E951

88

E952

DO

F9

BNE

*E94D

E954

84

C6

STY

$C6

E956

A6

D6

LDX

$D6

AF

STA

E958

68

E959

85

E95B

68

E95C

85

E95E

68

E95F

85

E961

68

E962

85

E964

60

DEX
FC

BNE

$E94D

delayloop

DEY

number

$AF

AE

STA

$AE

PLA
AD

STA

$AD

PLA
AC

STA

$AC

RTS

E967

E8

INX

B5 D9

LDA *D9,X

E96A

10

FB

E96C

8E

A5

EO

18

STX
CPX

$02A5

E96F
E971

FO OE

BEQ

*E981

E973

90

BCC $E981

E975

20

EA

JSR

$EBEA

E978

AE

A5 02 LDX

*02A5

E97B

CA

DEX

E97C

C6

D6

E97E

4C

DA

BPL $E967
02

OC
EB

E6

#*18

DEC

$D6

JMP

*E6DA

*****************************

E981
E983
E984
E986
E987
E989

A5 AC
48
A5 AD
48
A5 AE
48

LDA $AC
PHA
LDA $AD
PHA
LDA *AE
PHA

E98A
E98C

A5
48
A2
CA
20
EC
90
FO
BD
85
B5
20
30

LDA
PHA

*AF

LDX

#*19

E990
E993
E996
E998
E99A
E99D
E99F
E9A1
E9A4

keys

PLA

E968

E98D

pressed

PLA

*****************************
E965
A6 D6
LDX *D6

E98F

o-f

AF

19

DEX

FO
A5
OE
OC
EF
AC
D8
C8
E9

E9 JSR *E9F0
02 CPX $02A5
BCC *E9A6
BEQ *E9A6
EC LDA $ECEF,X
STA *AC
LDA SD8,X
E9 JSR *E9C8
BMI *E98F

A-97

inserting

second-line

JSR

$E9FF

LDX

#$17

CPX

$O2A5

OF

BCC

$E9BF

B5

DA

LDA

$DA,X

29
B4

7F
D9

AND
LDY

#$7F
$D9,X

E9A6

20

FF

E9A9

A2

17

E9AB

EC

A5

E9AE

90

E9B0

E9B2
E9B4

E9

O2

E9B6

10

O2

BPL

$E9BA

E9B8

09

80

ORA

#$80

E9BA

95

DA

STA

$DA,X

E9BC

CA

E9BD

DO

EC

E9BF

AE

A5

02

LDX

$02A5

E9C2

20

DA

E6

JSR

$E6DA

E9C5

4C

58

E9

JMP

$E958

DEX
BNE

$E9AB

*****************************

E9CB

29

03

AND

#$03

E9CA

OD

88

E9CD

85

AD

ORA

$0288

STA

E9CF

20

EO

$AD

JSR

E9D2

AO

$E9E0

27

LDY

E9D4

#$27

Bl

AC

LDA

E9D6

($AC),,Y

91

Dl

STA

($D1),,Y

02
E9

E9D8

Bl

AE

LDA

($AE).,Y

E9DA

91

F3

STA

($F3),,Y

E9Ii2

88

E9DD

10

E9DF

60

Shi-ft

line

up

DEY
BPL

F5

$E9D4

RTS
K-******^It 'Jr 'If' TTifrTtH-*

*****

E9E0

2O

24

JSR

$EA24

E9E3

A5

AC

EA

LDA

$AC

E9E5

85 AE

STA

$AE

E9E7

A5

AD

LDA

$AD

E9E9

29

03

AND

#$03

E9EB

09

D8

ORA

#$D8

E9ED

85

AF

STA

$AF

E9EF

60

RTS

*****************************

E9F0

BD

FO

E9F3

85

Dl

EC

LDA

STA $D1

E9F5

B5

D9

LDA $D9,X

E9F7

29

03

E9F9

OD 88

E9FC

85

E9FE

60

AND

02

D2

$ECFO,X

#$03

ORA $0288
STA $D2
RTS

*****************************

E9FF
EA01

AO 27
LDY #$27
20 FO E9 JSR $E9F0

EA04

20 24

EA07

A9

20

EA

JSR

$EA24

LDA #$20

A-98

Clear

screen-line

EA09

91

Dl

EAOB

2O

DA

EAOE

EA

EAOF

88

EA1O
EA12

10
60

STA
E4

JSR

<*D1),Y
SE4DA

NOP

DEY

F5

BPL

$EA07

RTS

EA13

A8

EA14

A9

O2

LDA

#$02

EA16

85

CD

STA

$CD

EA18

2O

24

JSR

$EA24

EA1B

98

TAY

EA

set

blink-counter

at

repeat

function

TYA

***** ***]-**]**!****4***********

EA1C

A4

D3

LDY

EA1E

91

Dl

STA

EA20

8A

EA21

91

EA23

6O

F3

Get

$D3

<$D1>,Y
<$F3),Y

and

color

position

character

TXA
STA

character

column

to

accumulator

colorcode

to

write

color-RAM

into

RTS

*****************************

Calc.

pointer

to

color-RAM

EA24

A5

Dl

LDA

$D1

EA26

85

F3

STA

$F3

EA28

A5

D2

LDA

$D2

EA2A

29

03

AND

#$03

EA2C

09

D8

ORA

#$D8

high-byte

EA2E

85

F4

STA

$F4

$F3/$F4

pointer

EA30

6O

$D1/$D2

pointer

Interupt

$FFEA

stop-key,

CC

LDA

$CC

blinkflag

DO

29

BNE

$EA61

not

C6

CD

DEC

$CD

lower

EA34

A5

EA36
EA38

FF

increase
-for

blinking,

then

DO

25

BNE

$EA61

not

zero,

then

A9

14

LDA

#$14

set

blink

counter

EA3E

85

CD

STA

$CD

EA40

A4

D3

LDY

$D3

cursor

EA42

46

CF

LSR

$CF

blink-switch

EA44

AE

87

LDX

$0287

color

under

zero

Dl

LDA

BO

11

BCS

$EA5C

blink-switch

was

EA4B

E6

CF

INC

$CF

blink-switch

on

EA4D

85

CE

STA

$CE

save

EA4F

20

24

JSR

$EA24

calculate

EA52

Bl

F3

EA54

8D

87

02

EA57

AE

86

02

EA5A

A5

CE

EA5C

49

8O

EASE

2O

1C

EA61

A5

STA

($F3),Y

character

color-code

$0287

and

save

LDX

$0286

color-code

$CE

character

EOR

#$80

flip

JSR

$EA1C

set

01

LDA

$01

on,

C=l

then

continue
under

pointer

get

to

cursor

colorRAM

under

under

cursor

cursor

RVS-bit
character

EA63

29

10

AND

#$10

checks

EA65

FO

OA

BEG

$EA71

pressed?

A-99

the

charactercode

LDA
EA

20

cursor

Bl

LDA

to

column

EA47

EA

continue

continue

EA49

set

time

blink-count

EA3A

($D1),Y

color-

position

cursor

EA3C

02

to

routine

JSR

EA

screen

position

*D8
RAM

*****************************

20

to

RAM

RTS

EA31

on

screen

and

tapekey

color

EA67

AO

OO

LDY

#$00

EA69

84

CO

STY

$C0

EA6B

A5

01

LDA

$01

EA6D

09

20

ORA

#$20

EA6F

DO

08

BNE

$EA79

EA71

A5

CO

LDA

$C0

EA73

DO

O6

BNE

$EA7B

EA75

A5

01

LDA

$01

EA77

29

IF

AND

#$1F

EA79

85

01

STA

$01

EA7B

20

87

EA

JSR

$EA87

EA7E

AD

OD

DC

LDA

$DCOD

EA81

68

PLA

EA82

A8

TAY

EA83

68

PLA

EA84

AA

TAX

EA85

68

PLA

EA86

40

RTI

set

tapeflag

tape-drive

o-f-f

tape

on

drive

keyboard-checking

restore

and

register

return

-from

interrupt

Keyboardchecking

***** ****-***E-**4[****

#$00

EA87

A9

00

LDA

EA89

8D 8D

02 STA

$028D

set

back

EA8C

AO

40

LDY

#$40

$40

EA8E

84

CB

STY

$CB

code

EA90

8D

00

DC

STA

$DCOO

EA93

AE

01

DC

LDX

$DC01

EA96

EO

FF

CPX

#$FF

no

EA98

FO

61

BEQ

$EAFB

then

EA9A

A8

EA9B

A9

81

LDA

#$81

EA9D

85

F5

STA

$F5

EA9F

A9

EB

LDA

#$EB

EAA1

85

F6

STA

$F6

EAA3

A9

FE

LDA

#$FE

EAA5

8D

00

STA

$DCOO

EAA8

A2

08

LDX

#$08

EAAA

48

EAAB

AD

Ol

DC

LDA

$DC01

EAAE

CD

01

DC

CMP

$DC01

EAB1

DO

FB

BNE

$EAAB

EAB3

4A

EAB4

BO

EAB6

48

EAB7

Bl

F5

LDA

EAB9

C9

05

CMP

#$05

EABB

BO

OC

BCS

$EAC9

EABD

C9

O3

CMP

#$03

EABF

FO

08

BEQ

$EAC9

EAC1

OD

8D

02

ORA

$028D

EAC4

8D

8D

02

STA

$028D

EAC7

10

02

BPL

$EACB

EAC9

84

CB

STY

$CB

EACB

68

EACC

CB

EACD

CO

shift/CTRLflag

no

key

for

key

pressed

pressed

key

pressed?

end

TAY

DC

pointer

to

table

$EB81

matrix-lines

PHA

keyboard,

(data

LSR

BCS

16

joystick,

$EACC

put

bits,

in

111"

pressed

get

ASCII-code

not

order,

paddles
port

B)

into

PHA
($F5),Y

"STOP'"

code?

save

I NY

CPY

or

set

PLA

41

bigger

#$41

A-100

equal

from

to

flag

number

of

key

table

5?

EACF

BO

EADi

CA

EAD2

DO

EAD4

38

SEC

PLA

OB

BCS

3EADC

bigger

than

$40?

$EAB3

next

matrix-column

next

matrix-line

DEX
DF

EAD5

68

EAD6

2A

EAD7

8D

00

EADA

DO

CC

EADC

68

BNE

ROL
DC

STA

*DCOO

BNE

$EAA8

PLA

EADD

6C

8F

EAEO

A4

CB

LDY

EAE2

Bl

F5

LDA

EAE4

AA

EAE5

C4

C5

CPY

*C5

EAE7

FO

07

BEQ

*EAFO

EAE9

AO

10

EAEB

8C

8C

EAEE

DO

36

02

JMP

JMP $EB48 sets pointer to


number of key
table

(*02BF>
*CB

get

(#F5),Y

ASCII-value from table

TAX

02

LDY

#*1O

STY

*028C

BNE

*EB26

EAFO

29

7F

EAF2

2C

8A

EAF5

30

16

EAF7

70

49

BVS

*EB42

EAF9

C9

7F

CMP

#*7F

02

AND

#*7F

BIT

$028A

BMI

*EBOD

EAFB

FO

29

BEQ

*EB26

EAFD

C9

14

CMP

#$14

EAFF

FO

OC

BEQ

*EBOD

EBO1

C9

20

CMP

#*20

EB03

FO

08

BEG

*EBOD

EB05

C9

ID

CMP

#*1D

EB07

FO

04

BEQ

$EBOD

EB09

C9

11

CMP

#$11

EBOB

DO

35

BNE

*EB42

EBOD

AC

BC

EB1O

FO

05

EB12

CE

BC

EB15

DO

2B

EB17

CE

8B

EB1A

DO

26

EB1C

AO

04

EBiE

8C

SB

EB21

A4

C6

EB23

88

02
O2
02

02

LDY

*02BC

BEQ

*EB17

DEC

*O28C

BNE

$EB42

DEC

*02BB

BNE

$EB42

LDY

#*04

STY

*02BB

LDY

*C6

compare

with

repeat-delay
clear

bit

repeat

EB24

1O

1C

BPL

$EB42

A4

CB

LDY

*CB

EB28

84

C5

STY

$C5

EB2A

AC

8D

02

LDY

*02BD

EB2D

8C

8E

02

STY

*02BE

EB30

EO

FF

CPX

#*FF

EB32

FO

OE

BEQ

*EB42

EB34

8A

EB35

A6

C6

EB37

EC

89

EB3A

BO

06

EB3C

9D

77

EB3F

E8

02

LDX

*C6

CPX

*O289

BCS

*EB42

STA

*0277,X

counter

all

keys?

bit 7 set, repeat all keys


bit 6 set, then ingnore
repeat only following keys
"DEL","INST"-code
space

cursor

right,

cursor

up,

count

counter
of

than

counter

again

characters

keyboard-code

of

then

buffer

write

INX

A-101

then

ignore

invalid?

ignore

characters

compare

in

keyboard-buffer
one character in

buffer,

yes,

down

down

number
more

left

counter

repeat-speed

set

cursor

cursor

repeat-delay

TXA
O2

key

for

DEY

EB26

last

with

full,

in

max.

ignore

characters

keybuffer
number

charcter

into

buffer

.-3.

ZOT-V

38

T6

ia

to

3y
WB

ay
68

z.6 os 2a 96
G8

06

08 fr6

ao33
003

*****************************

88

T6

WO

S3 0

TO

frO

80

33

SO 83

9a

03

d3

33

ys as

30

TO

20

OS
33

93
V8

Oy

TO
3

68

33

6
aa
O

83
93
tr3
38

i?O

OS
33
W3

L3
iz3
T3
06

dS

03
oa
63

60
30
0
08

yd33

IS

2033

dd

6tf
aa
63

3dS3
y3S3
3383

LZ. 0033
S3
3
tr6

3033
V333
3383

*****************************

d*

3i7

0*

33

3S

d3

TS

30

03
TO

33
0*

S8

98

LB

TT

ys

S*

TO

9*

*S

8S

8tr

SS

9S

8*

3i7

trO

3
03
0
8
9

*
88

3*
y*

/.*

-fr-fr

T*
01

dS
ys

OS
6*

TS33

3S

6333

T333

dd

33
6
S

3S

Z.

6S
Z.S

ao

t-T

oq.

33

33

83

33

S3

>)DPq

T8

6y33

TV33
6633
T6S3

T833

6Z33

*****************************

aq.

ja^uxod

oq.

6833
JLJLJLJLJL

**]****t**4***)(**)(**)

6uipo=>ap
6uxpoDap

oq.

9d

ys

'ou

a_4opoujufOD ^j-Tqs

03 317

dWP

y3

yz

yan

S3

33

6L
90

yai

bt

oa

33

9Z33$

yan

30$#

9ZS3

TZS3

as

as

yan

30 06

333

dMP

d933
39S3
3933
69S3

6y

Z.933
S9S3

63

i79S3

yo

30

UG3

8Toa$ ys

IMS

9Z33$

8Toa$

oa

bt
ai

so

T9S3

3*

3S83

as

3SS3

617

6SS3

ay

Z.S33

02

33 Od

3*33$ 033

t6

yan

T6so$

3830$ dN3

jaquiod

sb

sd ss

yis

yy

xyi

BO

dU3

80$#

8933$

nsy

6uxpoDap
d

apoDap

ay

dW3

SO 38 03
st oa

3N3

SSS3

a*33

63

3*33

0830$ yan so ob ay

*ldIHS

8*33

*****************************

SU

09

0030$ VIS 30 00 08
j-o

93$

XS

93

98

EC13

98 B2 AC

99

EC1B

9A

B7

A5

9B BF

BC BB
B4

A3 BD
B8

BE

EC23

29

A2

B5

30

A7

Al

B9

AA

EC2B

A6

AF

B6

DC

3E

5B A4

3C

EC33

A8

DF

5D

93

01

3D

DE

3F

EC3B

81

5F 04

95

A0 02

AB

83

EC43

FF

*****************************

EC44

C9

OE

CMP

EC46

DO

O7

EC48

AD

18

EC4B

09

EC4D
EC4F
EC51

##0E

control-character

*EC4F

LDA

*D018

character

02

ORA

#*02

DO

09

BNE

to capital-letter

*EC58

C9

8E

CMP

#$8E

DO

OB

BNE

*EC5E

AD

18

EC56

29

FD

EC58

DC>

DO>

LDA

*DO18

AND

#*FD

small-letter

STA

*D018

set

8D

18

DO

4C

A8

E6

JMP

$E6A8

EC5E

C9

O8

CMP

#*08

EC60

DO

07

BNE

*EC69

LDA

#$80

QRA

*0291

BMI

$EC72

EC62

A9

80

EC64

OD

91

EC67

30

09

02

EC69

C9

09

CMP

#*09

DO

EE

BNE

*EC5B

EC6D

A9

7F

LDA

#*7F

2D

91

02

AND

$0291

EC72

8D

91

02

STA

*0291

EC75

4C

A8

E6

JMP

*E6A8

block

FF

FF

FF

FF

FF

EC80

1C

17

01

9F

1A

13

05

FF

EC88

9C

12

04

IE

03

06

14

18

EC90

IF

19

07

9E

02

08

15

16

EC98

12

i09

OA

92

OD

OB

OF

OE

ECAO

FF

10

OC

FF

FF

IB

OO

FF

ECA8

1C

1FF

ID

FF

FF

IF

IE

FF

ECBO

90

<06

FF

05

FF

FF

11

FF

ECB8

FF

*****************************

ECB9

00

00

00

00

00

ECC1

00

ECC9

00

00

00

00

9B

37

00

ECD1

14

OF

00

ECD9

OE

O6

ECE1

02

O3

00

00

00

00

00

00

00

OO

00

08

00

00

00

00

OO

00

01

02

03

04

00

01

04

05

06

07

Keyboard-decoding

Video-controller

Text

ECE7

"LOAD

4F

41

44

OD

52 55

4E

OD

A-103

table

with

*******************************

4C

shi-Ft/Commodore

re-enable shi-ft/Commod ore

*************** ************t-**

FF

mode

chr$<9>

EC6F

IFF

mode

chr*<8>

EC6B

FF

generator

chr$<142>

EC5B

EDEA

on

chr*(14)

BNE

EC53

EC78

Checks

a-fter

(CR)

SHIFT/

RUN

4,

CTRL-key

constants

RUN

(CR)"

STOP

snq-331

o^.

a^-Aq

q.nd-q.no

170T-V

338

ysa3*

usr

3833*

yan

80*#

S38

SS03*

hsp

6y33*

338

0S03*

ysr

6y33*

"Ida

ysa3*

asr

6V33*

S3a

aya3*

dsr

S833*

18

y*

asr

Z.633*

asr

6y33*

33

80

38
3d

33

6y
3d

33

6y
3d

33

6y

yo

y
33

58
tr9

33

33

6y
Z.6

6y

02
06
02
08
02
06
O2
OT

172
02
oa

02

2903

dSO3

0S03

yso3
8S03
SS03

S03
OSO3

317O3
31703

6t/03
Z.1703

171703
T1703

903

&L

^03
03

Z.633* dSr 33 Z6 02
3833* dSC 33 38 02

0203

833* USD

33

ooaa* yis aa
80*# yya

}as

aq oq. a^Xq

joj. jaujx^ ^as


puas

N3SI"1

02

0f03
8Z
I3S
*****************************

a3
T03

oo as
80 60

I3S

Niy

uaAiB

02

i7203
203
T2O3

Z633* dSr 33 Lb 02
I3S
8Z.
S6* yiS
S6 S8

8203
6203
Z.203

S833* dSr 33 S8 02
3203* 3NS
0 00
d*# dW3
d 63

3203

ooaa* yan aa oo ay

817

yHd

trT03
2T03

yo OT
176 172

0203* "Id8
176* 18

103
9103

3T03
3TO3
6T03

yS"l
y 917
aSH
tr6 9tr
USE 03 017 02
aoa
y 99
33S
8

O2O3

yid

y*
176*
01703*
y*

331

pyas

>i~iy

89

trVOd* MSC Od fry 02


02*# yyO
02 60

TTO3

3OO3
3003

*****************************

32*

3A8

32

oi7*# yao

snq331

017 60

8003
6003

*****************************
*****************************

Od 83 OV

8T

8S

OL

86

817 02
80 03

8d
88
BL

00

8y

06 89
OS 82

0003

08

8003

03

017
00

8d33
0d33

*****************************

ED64

85 A5

ED69

CD

00

ED6C

DO

F8

ED6E

OA

ED66

STA $A5

out-out

DD CMP $DD00
BNE

$ED66

ASL

ED6F

90 3F

BCC

$EDB0

ED71

66

ROR

$95

ED73

BO 05

ED75

20

AO

ED78

DO

O3

BNE

$ED7D

ED7A

2O

97

EE JSR

$EE97

ED7D
ED80

20 85 EE JSR $EE85
EA
NOP

95

BCS $ED7A
EE JSR $EEAO

ED81

EA

NOP

ED82

EA

NOP

ED83

EA

ED84

AD

00

ED87

29

DF

ED89

09

10

ED8B

8D 00

NOP

ED8E

C6

ED90
ED92

DO D4
A9 04

DD

LDA

$DDOO

AND #$DF
ORA

#$10

DD STA $DDOO

A5

DEC

$A5

BNE $ED66
LDA #$04

ED94

BD

07

ED97
ED99

A9
8D

19
LDA #$19
OF DC STA $DCOF

ED9C

AD

OD

ED9F
EDA2
EDA4
EDA6
EDA9

set bit-counter for serial

AD 00 DD LDA $DD00

DC

DC

STA $DC07

LDA $DCOD

AD
29
DO
20
BO

OD DC LDA $DCOD
02
AND #$O2
OA
BNE $EDBO
A9 EE JSR $EEA9
F4
BCS $ED9F

EDAB

58

CLI

EDAC

60

RTS

*****************************

EDAD

A9

EDAF

2C

EDBO
EDB2

A9
20
58

EDB5
EDB6

18

EDB7

90

80

LDA

#$80

.BYTE

"DEVICE

NOT

PRESENT"

$2C

03
1C FE

LDA
JSR
CLI

#$03
$FE1C

4A

BCC $EE03

"TIME OUT"
set status

CLC

*****************************

EDB9

85

95

EDBB

20

36

EDBE

AD

00

EDC1

29

F7

EDC3

BD

00

EDC6

60

EDC7

85

95

EDC9

20

36

Send

secondary

STA

$95

save

ED

JSR

$ED36

out-put

DD

LDA

$DDOO

AND

#$F7

STA

$DDOO

DD

address

secndary
with

adrs

to

/LISTEN

ATN

set

back

ATN

Send

TALK

secondary

RTS

ED

STA

$95

save

JSR

$ED36

out-put

A-105

secondary
with

address

address

ATN

EDCC

78

EDCD

20

SEI

EDDO

2O BE ED JSR $EDBE

EDD3

20

85

EE

EDD6

20

A9

EE

EDD9

30

FB

EDDB

58

CLI

EDDC

60

RTS

A0

EE

JSR
JSR

$EEAO

set

back

ATN

$EE85

JSR $EEA9
BMI

$EDD6

*****************************

EDDD

24 94

BIT

$94

EDDF

30 05

BMI

$EDE6

EDE1
EDE2
EDE4
EDE6
EDE7

38
66 94
DO 05
48
20 40 ED

SEC
ROR $94
BNE $EDEB
PHA
JSR $ED40

EDEA
EDEB

68
85 95

PLA
STA $95

EDED

18

CLC

EDEE

60

RTS

78

EDFO

20

8E

EE

JSR

$EE8E

EDF3

AD

00

DD

LDA

$DDOO

EDF6

09

08

EDF8

8D

00

EDFB

A9

5F

EDFD

2C

out-put

byte

one

IEC-

bus

send

*****************************

EDEF

IECOUT

Send

byte

to bus

UNTALK

SEI

DD

ORA

#$08

STA

$DDOO

LDA

#$5F

-BYTE

set

$2C

*****************************

A9

ATN

EDFD

2C

3F

BIT

$3FA9

EEOO

20

EE03

20

11

ED

JSR

$ED11

BE

ED

JSR

EE06

8A

$EDBE

EE07

A2

EE09

CA

EEOA

DO

EEOC

AA

EEOD

20

85

EE

JSR $EEB5

EE10

4C

97

EE

JMP

Send

UNLISTEN

TXA

OA

LDX

#$0A

DEX

FD

BNE

wait

-for

40

micro-seconds

$EE09

TAX

frequency

on

$EE97

*****************************

EE13

78

SEI

EE14

A9

00

LDA

EE16

85

A5

STA

$A5

EE18

20

85

EE

JSR

$EE85

EE1B

20

A9

EE

JSR

$EEA9

EE1E

10

FB

BPL

$EE1B

EE20

A9

01

LDA

#$01

EE22

8D

07

DC STA

EE25

A9

19

LDA

IECIN

get

character

-from

IEC

-bus
#$00

$DC07
#$19

EE27

8D

OF

DC

STA

$DCOF

EE2A

20

97

EE

JSR

$EE97

EE2D

AD

OD

DC LDA

$DCOD

A-106

EE30

AD

OD

EE33

29

02

EE35

DO

07

EE37

20

A9

DC

LDA

*DCOD

check

EE

BNE

*EE3E

JSR

*EEA9

EE3A

30

F4

BMI

*EE3O

EE3C

1O

18

BPL

$EE56
*A5

EE3E

A5

A5

LDA

EE40

FO

05

BEQ

*EE47

EE42

A9

02

LDA

#*02

EE44

4C

B2

ED

JMP

*EDB2

EE47

20

AO

EE

JSR

*EEAO

EE4A

20

85

EE

EE4D

A9

40

EE4F

20

1C

EE52

E6

A5

EE54

DO

CA

BNE

*EE20

EE56

A9

08

LDA

#*08

FE

JSR

*EE85

LDA

#*40

"EOF"

JSR

$FE1C

set

status

set

bit-counter

INC

EE58

85

A5

EE5A

AD

00

DD

LDA

EE5D

CD

00

DD

CMP

EE60

*DDOO

DO

F8

BNE

*EE5A

STA

EE62

OA

EE63

10

F5

EE65

BPL

66

A4

ROR

$DDOO

ASL
*EE5A

EE67

AD

00

DD

LDA

EE6A

*DDOO

CD

OO

DD

CMP

EE6D

DO

F8

*DDOO

EE6F

BNE

OA

*EE67

ASL

EE70

30

F5

BMI

EE72

C6

A5

DEC

EE74

DO

E4

EE76

20

AO

EE79

24

EE7B
EE7D

BNE

EE

*EE5A

JSR

*EEAO

90

BIT

$90

50

03

status

BVC

*EE80

2O

06

no

JSR

EE80

A5

A4

*EE06

EE82

58

EE

LDA

EE83

18

CLC

6O

RTS

*****************************

EE85
EE88
EE8A

AD 00 DD LDA *DDOO
29 EF
AND #*EF
8D 00 DD STA $DDOO

EEBD

60

Serial

-frequency

on

Serial

-frequency

off

RTS

*****************************

EE8E

AD

EE91

O9

10

EE93

8D

00

EE96

60

OO

DD
DD

LDA

*DDOO

ORA

#$10

STA

*DDOO

RTS

*****************************

AD

EOF?

CLI

EE84

EE97

timer

AND

00

DD

LDA

$DDOO

A-107

Out-put

bit

"1"

EE9A

29

DF

EE9C

8D

OO

EE9F

6O

DD

AND

#*DF

STA

*DDOO

RTS

*****************************
EEAO

AD OO

EEA3

09

EEA5

8D 00

EEA8

6O

DD

20

LDA

Out-put

bit

"O"

$DDOO

ORA #*20

DD

STA $DDOO
RTS

*****************************

EEA9
EEAC
EEAF

AD 00 DD LDA $DDOO
CD 00 DD CMP *DDOO
DO F8
BNE SEEA9

EEB1

OA

ASL

EEB2

60

RTS

*****************************

EEB3

8A

TXA

EEB4

A2 B8

LDX

EEB6
EEB7

CA
DO FD

DEX
BNE $EEB6

EEB9

AA

TAX

EEBA

60

RTS

*****************************

A5 B4

LDA *B4

EEBD

FO 47

BEQ *EFO6

EEBF

30 3F

BMI*EFOO

EEC1

46 B6

LSR $B6

EEC3
EEC5

A2 OO
90 01

LDX #$00
BCC $EEC8

EEC7

CA

DEX

EEC8

8A

TXA

EEC9

45 BD

EOR *BD

EECB

85

BD

STA

EECD

C6

B4

DEC $B4

EECF

FO 06

BEQ $EED7

EED1
EED2

8A
29 O4

TXA
AND #*04

EED4

85 B5

STA *B5

EED6

60

RTS

EED7

A9 20

EED9

2C

94

BIT

$0294

EEDC

FO

14

BEQ

*EEF2

EEDE

30

1C

BMI

*EEFC

EEE2

A5 BD

LDA *BD

EEE4

DO 01

BNE

*EEE7

EEE6
EEE7

CA
C6 B4

DEX
DEC

*B4

EEE9

AD

LDA

*O293

EEEC

1O E3

BPL

*EED1

EEEE

C6

DEC

*B4

7b 14

93
B4

RS-232

$BD

LDA #*20
02

BVS $EEF6

02

milli-second

#$B8

EEBB

EEEO

One

A-108

out-put

delay

EEFO

DO

DF

EEF2

E6

BNE

B4

*EED1

INC

*B4

EEF4

DO

FO

EEF6

BNE

A5

BD

*EEE6

LDA

*BD

EEF8

FO

ED

EEFA

BEQ

DO

EA

*EEE7

EEFC
EEFE
EFOO

BNE

70

*EEE6

E9

BVS

50

E6

BVC

E6

B4

*EEE7
*EEE6

EF02

INC

*B4

A2

FF

LDX

#*FF

EF04

DO

CB

EF06

AD

94

EF09

4A

EFOA

9O

07

EFOC

2C

01

02

BNE

*EED1

LDA

*0294

LSR
DD

BCC

*EF13

BIT

*DDO1

EFOF

10

ID

EF11

BPL

50

IE

*EF2E

EF13

BVC

A9

00

EF15

LDA

85

*EF31
#*00

BD

EF17

85

B5

STA
STA

*BD
*B5

EF19

AE

98

EF1C

86

B4

02

LDX

*0298

STX

*B4

*029D

EF1E

AC

9D

02

LDY

EF21

CC

9E

02

CPY

*029E

EF24

FO

13

BEQ

*EF39

EF26

Bl

F9

LDA

EF28

85

B6

STA

*B6

EF2A

EE

9D

INC

*029D

EF2D

60

02

(*F9),Y

RTS

EF2E

A9

EF30

2C

EF31

EF33

A9
OD

97

02

ORA

#*10
*0297

EF36

8D

97

02

STA

*0297

EF39

A9

01

EF3B

8D

OD

EF3E

4D

Al

EF41

09

80

EF43

8D

Al

EF46

8D

OD

EF49

60

EF4A

A2

09

EF4C

A9

20

EF4E

2C

93

EF51

FO

01

EF53

CA

EF54

50

EF56

CA

DEX

EF57

CA

DEX

EF58

60

RTS

EF59

A6

A9

LDX

*A9

EF5B

DO

33

BNE

*EF90

EF5D

C6

A8

DEC

*AB

EF5F

FO

36

BEQ

*EF97

40

LDA

#*40

-BYTE
10

LDA

DSR

(data

set

ready)missing

*2C

LDA

#*01

DD

STA

*DDOD

02

EOR

*O2A1

ORA

#*80

02

STA

*O2A1

DD

STA

*DDOD

CTS

(clear

set

status

to

send)

missing

RTS

02

LDX

#*09

LDA

#*2O

BIT

$0293

BEQ

*EF54

Find

o-f

control

RS-232

data-bits

word

DEX

02

BVC

*EF58
X=number

A-109

o-f

databits

EF61

30

OD

BMI

$EF7O

EF63

A5

A7

LDA

$A7

EF65

45

AB

EOR

$AB

EF67

85

AB

STA

SAB

EF69

46

A7

LSR

$A7

EF6B

66

AA

ROR

$AA

EF6D

60

EF6E

C6

A8

DEC

$A8

EF70

A5

A7

LDA

$A7

EF72

FO

67

BEQ

$EFDB

EF74

AD

93

LDA

$0293

EF77

OA

EF78

A9

01

LDA

#$01

EF7A

65

A8

ADC

$A8

EF7C

DO

EF

BNE

$EF6D

EF7E

A9

90

LDA

#$90

EF80

8D

OD

STA

$DDOD

EF83
EF86

OD Al
8D Al

EF89

85

A9

STA

$A9

EF8B

A9

02

LDA

#$02

EF8D

4C

3B

JMP

$EF3B

EF90

A5

A7

LDA

$A7

EF92

DO

EA

BNE

$EF7E

EF94

85

A9

STA

$A9

EF96

60

EF97

AC

EF9A

C8

EF9B

CC

9C

EF9E

FO

2A

EFAO

8C

9B

EFA3

88

EFA4

A5

AA

EFA6

AE

98

EFA9

EO

09

CPX

#$09

EFAB

FO

04

BEQ

$EFB1

RTB

O2

ASL

DD

02 ORA $02A1
O2 STA $02A1

EF

RTS
9B

02

LDY

$029B

I NY

02
02

CPY

$029C

BEQ

$EFCA

STY

$029B

DEY
02

LDA

$AA

LDX

$0298

EFAD

4A

EFAE

E8

EFAF

DO

F8

BNE

EFB1

91

F7

STA

EFB3

A9

20

LDA

#$20

BIT

$0294

LSR
INX

$EFA9
($F7),Y

EFB5

2C

94

EFB8

FO

B4

BEQ $EF6E

02

EFBA

30

Bl

BMI

$EF6D

EFBC

A5

A7

LDA

$A7

EFBE

45

AB

EOR

$AB

EFCO

FO

03

BEQ

$EFC5

EFC2

70

A9

BVS

$EF6D

EFC4

2C

EFC5

50

A6

BVC

$EF6D

EFC7

A9

01

LDA

#$01

EFC9

2C

EFCA

A9

EFCC

2C

.BYTE

-BYTE
04

LDA

$2C
parityerror

$2C
receiver-bu-ffer

#$04

-BYTE

$2C

A-110

-full

EFCD
EFCF

A9

EFDO

80

LDA

#$80
.BYTE $2C

receiver

A9

02

LDA

#$02

97

ORA

$0297

frame-error

2C

EFD2

OD

EFD5

8D

97

02

STA

EFD8

$0297

4C

7E

EF

JMP

$EF7E

02

EFDB

A5

AA

LDA

$AA

EFDD

DO

Fl

BNE

EFDF

$EFDO

FO

EC

BEQ

$EFCD

EFE1

85

9A

STA

EFE3

AD

$9A

94

LDA

EFE6

$0294

4A

02

set

breakcommand

status

LSR

EFE7

90

29

EFE9

BCC

A9

$F012

02

LDA

EFEB

#$02

2C

01

BIT

EFEE

$DD01

10

ID

EFFO

DO

2O

EFF2

AD

Al

EFF5

29

02

EFF7

DO

F9

EFF9

2C

Ol

EFFC

70

FB

EFFE

AD

01

DD

BPL $FOOD
BNE $F012
02

LDA

$O2A1

AND
BNE

#$02

DD

BIT

$DD01

BVS

$EFF9

DD

LDA

$DD01

ORA

#$02

$EFF2

FOO1

09

02

F003

8D

01

DD

STA

F006

$DD01

2C

01

DD

BIT

$DD01

F009

70

07

BVS

FOOB

$F012

30

F9

BMI

FOOD

A9

$F006

40

FOOF

8D

97

O2

LDA

#$40

STA

$0297

F012

18

CLC

F013

60

RTS

F014

20

28

FO

JSR

$F028

F017

AC

9E

02

LDY

$029E

FO1A

C8

DSRsignal

Out-put to RS-232 bu-f-fer

I NY

FO1B

CC

9D

FO1E

FO

F4

F020

8C

9E

F023

88

F024

A5

9E

LDA

F026

91

F9

STA

F028

AD

Al

02

O2

CPY

$029D

BEQ

$F014

STY

$029E

DEY

02

LDA

$9E
<$F9),Y

$02 A1

F02B

4A

F02C

BO

IE

BCS

$F04C

F02E

A9

10

LDA

#$10

LSR

F030

8D

OE

DD

STA

$DDOE

F033

AD

99

02

LDA

$0299

F036

8D

04

DD

STA

$DD04

F039

AD

9A

02

LDA

$029A

F03C

8D

05

DD

STA

$DD05

F03F

A9

81

LDA

#$81

F041

20

3B

EF

JSR

$EF3B

F044

20

06

EF

JSR

$EF06

is missing

A-lll

LDA

#$11

STA

$DDOE

F047

A9

11

F049

8D

OE

F04C

60

F04D

85

99

F04F

AD

94

F052

4A

FO53

90

28

BCC

$FO7D

F055

29

08

AND

#$08

F057

F0

24

BEQ

$F07D

F059

A9

02

LDA

#$02

F05B

2C

01

BIT

$DD01

F05E

10

AD

BPL

$FOOD

F060

FO

22

BEQ $F084

F062

AD

Al

F065

4A

FO66

BO

FA

F06S

AD

Ol

FO6B

29

FD

F06D

8D

01

F070

AD

Ol

F073

29

04

F075

FO

F077

A9

F079

18

F07A

4C

3B

EF

JMP

$EF3B

F07D

AD

Al

02

LDA

$02A1

FO8O

29

12

AND

#$12

F082

FO

F3

BEQ

$F077

F084

18

CLC

F085

60

RTS

DD

RTS

O2

STA

$99

LDA

$0294

LSR

DD

O2

LDA

$O2A1

LSR
DD

BCS

$F062

LDA

$DD01

AND

#$FD

DD

STA

$DD01

DD

LDA

$DD01

AND

#$04

F9

BEQ

$F070

90

LDA

#$90

CLC

*****************************

GET from RS-232

FO86

AD

97

02

LDA

$0297

status

FO89

AC

9C

02

LDY

$029C

buffer

pointer

F08C

CC 9B

02

CPY $029B

F08F
F091

FO OB
29 F7

BEQ $F09C
AND #$F7

buffer

empty?

STA

clear

F093

8D

97

F096

Bl

F7

FO98

EE

9C

F09B

60

F09C

09

08

F09E

8D

97
00

O2

LDA

02

INC

$0297
<$F7),Y

get

in

byte

$029C

increment

ORA

#$08

buffer

STA

$0297

set

LDA

#$00

transfer

status
from

buffer

buffer-pointer

RTS
O2

FOA1

A9

F0A3

60

RTS

F0A4

48

PHA

Set

LDA

$O2A1

BEQ

$FOBB

LDA

$02A1

AND

#$03

F9

BNE

$FOAA

A9

10

LDA

#$10

8D

OD DD

STA

$DDOD

F0A5

AD

Al

F0A8

FO

11

FOAA

AD

Al

FOAD

29

O3

FOAF

DO

F0B1
F0B3

02
02

timer

flag

set

empty

status

set?

timer

zero

for

IEC

time-out

F0B6

A9

F0B8

8D Al

OO

LDA

FOBB

68

PLA

FOBC

60

RTS

02

#$OO

STA $O2A1

FOBD OD 49 2F 4F 20
F0C5 4F 52 20 A3
F0C9 OD 53 45
F0D1

4E

47

AO

F0D4

46

4F

52

F0D8

OD

5O 52

FOEO 4C 41
F0E8

41

41

45 52 52

52 43

48 49

searching

press

play

press

record

on

tape

50 C5

C5

4C

4F

41

44

49

4E

C7

F10E

OD

53 41

56

49

4E 47

AO

F116

OD

56

45

52

49

46

49

F11E

4E

C7

46 4F

55

4E

44 AO

F120 OD

59

F12F

BIT $9D
BPL $F13C
LDA $FOBD,Y

F132

08

PHP

F133

29
20

verifying

Output

operators error

directmode
program,

o-f-fset

o-f

AND #$7F

clear

JSR $FFD2

out-put

C8

I NY
PLP

F13A

10

F13C

18

CLC

F13D

6O

RTS

F3

BPL

more

$F12F

******#****#**************##*

lines

-flag

then

skip

err or-messages

bit

inY

letters?

GETIN

F13E

A5

99

LDA

$99

F140

DO

08

BNE

$F14A

F142

A5

C6

LDA

$C6

F144

FO

OF

BEQ

$F155

no

F146

78

F147

4C

B4

JMP

$E5B4

get

character

F14A

C9

02

CMP

#$02

F14C

DO

18

BNE

$F166

not

RS-232,

F14E

84

97

STY

$97

F150

20

86

JSR

$F086

GET

from

F153

A4

97

LDY

$97

F155

18

CLC

F156

60

RTS

input-device

o-f

char-

in

keyboard

buf.

characters?

SEI

E5

FO

99

LDA

-From

then

buffer

BASIN

routine

*****************************

A5

tape

loading

D2 FF

28

on

saving

7F

F138

play

ok

24 9D
10 OD
B9 BD FO

F139

&

found

OD 4F 4B 8D

*****************************

F157

lines

59 20 4F 4E 2O 54

50

F135

error

number

-For

41
OD

F12B
F12D

system

error

45 53 53 2O 5O

F106

F127

I/O

AO

FOEB 50 52 45 53 53 20 52 45
F0F3 43 4F 52 44 20 26 20 50
FOFB 4C 41 59 20 4F 4E 20 54
F103

Operating

BASIM-input
device

$99

A-113

RS-232

of

number

character

F159

DO

OB

BNE

$F166

F15B

A5

D3

LDA

$D3

F15D

85

CA

STA

$CA

F15F

A5

D6

LDA

$D6

F161

85

C9

STA

$C9

F163

4C

32

JMP

$E632

F166

C9

O3

CMP

#$O3

F168

DO

09

BNE

$F173

E6

not

set

85

DO

STA

$D0

F16C
F16E

A5
85

D5

LDA

$D5

C8

STA

$C8

F170

4C

32

JMP

$E632

F173

BO

38

BCS

$F1AD

F175

C9

02

CMP

#$02

F177

FO

3F

BEQ

$F1B8

E6

F179

86

97

F17B

20

99

F17E

BO

16

Fl

Input

keyboard

-From

-from

from

*****************************

position

-for

input

*****************************

F16A

keyboard

cursor

input

screen

screen

I EC-bus

Input

-from

tape

STX

$97

save

X-register

JSR

$F199

get

character

-from

tape

BCS

$F196
get

character

-from

tape

PHA

F18O

48

F181

20

99

JSR

$F199

F184

BO

OD

BCS

$F193

F186

DO

05

BNE

$F18D

last

F188

A9

40

LDA

#$40

EOF

F18A

20

1C

JSR

$FE1C

set

F18D

C6

A6

DEC

A6

decrement

F18F

A6

97

LDX

$97

get

Fl

FE

F191

68

PLA

F192

60

RTS

F193

AA

TAX

F194

68

PLA

F195

8A

F196

A6

F198

6O

character?
status
back

tape-buf-Fer

pntr-

X-register

TXA
LDX

97

$97

RTS

*****************************

F199

20

OD

F19C

DO

F19E
F1A1

F8

Get

character

increment

JSR

$F80D

OB

BNE

*F1A9

still

20

41

JSR

$F841

no,get

BO

11

BCS

*F1B4

F1A3

A9

00

LDA

#$00

F1A5

85

A6

STA

$A6

F1A7

FO

FO

BEQ

*F199

F1A9

Bl

B2

LDA

<*B2>,Y

read

F1AB

18

F1AC

60

F1AD

A5

90

LDA

$9O

check

F1AF

FO

04

BEQ

*F1B5

ok

F1B1

A9

OD

LDA

#*0D

out-put

F1B3

18

CLC

F1B4

60

RTS

zero

-from

tape

tape-bu-f-fer

characters
next

block

in

pntr.

bu-f-Fer?

from

bu-F-Ferpointer,

tape

get

character

character

-From

CLC
RTS

A-114

status
"CR"-code

bu-F-fer

*****************************

F1B5

4C

13 EE JMP $EE13

get

*****************************

F1B8

IEC-input

byte -from

RS-232

input

20 4E Fl
BO F7

JSR $F14E
BCS $F1B4

F1BD

C9

CMP

F1BF

DO F2
BNE $F1B3
AD 97 02 LDA $0297
29 6O
AND #$60

status

F1C6

DO

E9

BNE

$F1B1

F1C8

FO

EE

BEQ

$F1B8

return

F1BB

F1C1
F1C4

00

get

48

byte

-from RS-232

"CR"

BSOUT-output

of

character

for

output

PHA

F1CB

A5 9A

LDA

$9 A

F1CD

C9

03

CMP

#$03

F1CF

DO

04

BNE

$F1D5

F1D1

68

device number
screen?

PLA

F1D2

4C

16

F1D5

90

04

F1D7

68

F1D8

4C

F1DB

4A

F1DC

68

F1DD
F1DF

85
8A

E7

JMP $E716

output

BCC $F1DB

character on

screen

PLA
DD

ED

JMP

$EDDD

out-put

LSR

byte

on

IECbus

PLA
9E

STA $9E

save

TXA

F1E0

48

F1E1

98

TYA

F1E2

48

PHA

character

to be

output

PHA

F1E3

90

BCC

$F208

F1E5
F1E8

20 OD F8 JSR
DO OE
BNE

$F80D
$F1FB

23

F1EA

20

JSR

$F864

F1ED
FIEF

BO OE
A9 02

BCS
LDA

$F1FD
#$02

F1F1

AO

00

LDY

#$00

F1F3

91

B2

STA

F1F5

C8

64

F8

RS-232 output

increment
buffer

write

<$B2>,Y

F1F6

84

A6

STY

$A6

A5 9E
91 B2

LDA
STA

$9E
($B2),Y

F1FC

18

CLC
PLA

F1FD

68

FIFE

A8

TAY

F1FF

68

PLA

F200

AA

F201

A5

9E

LDA

$9E

F203

90

02

BCC

$F207

F205
F207

A9
60

00

LDA
RTS

#$00

tape-buffer

write

buffer

in

increment
write

pntr-

full?

on

control-byte

INY

F1F8
F1FA

for

tape

data-block

buffer

buffer-pointer

character

in

buffer

TAX

*****************************

F208
F20B

#$00

*****************************

F1CA

I EC-bus

20 17 FO JSR $F017
4C FC Fl JMP $F1FC

RS-232
write

A-115

out-put
char,

in

RS232

buffer

********* ********************

CHRIN-set

input

JSR

$F30F

looks

BEQ

$F216

found?

F7

JMP

$F701

"FILE

F3

JSR

$F31F

sets

BA

LDA

$BA

device

O,

keyboard
screen

F2OE

20

OF

F211

F0

03

F213

4C

01

F216

20

IF

F219

A5

F3

logical

NOT

OPEN"

file

F21B

FO

16

BEQ

$F233

C9

03

CMP

#$03

F21F

FO

12

BEQ

$F233

3,

F221

BO

14

BCS

$F237

IEC-bus

F223

C9

02

CMP

#$02

RS-232

F225

DO

03

BNE

$F22A

no,

F227

4C

4D

JMP

$F04D

yes

*****************************

F22A

A6 B9

LDX

F22C
F22E

EO 60
FO 03

CPX #$60
BEQ $F233

F23O

4C

OA

F233

85

99

F235

18

CLC

F236

60

RTS

F237

AA

F238

20

09

F23B

A5

B9

F23D

10

06

BPL $F245

F23F
F242

F7

Set

parameter

then

tape

tape

as

secondary

$B9

-file*

number

F21D

FO

device

-for

input

device

address

zero?

"NOT

INPUT

FILE"

JMP

$F7OA

STA

$99

device number

JSR

$ED09

send

LDA

$B9

secondary

address

20 CC ED JSR $EDCC
4C 48 F2 JMP $F248

waits

cycle-signal

F245

2O

send

F248

8A

F249

24 90

BIT $90

status

F24B

10

BPL $F233

ok?

F24D

4C 07

-For

output

TAX

C7

ED

ED

JSR

$EDC7

TALK

-for

secondary

address

E6
F7

JMP

"DEVICE

$F707

*****************************

F250

20

OF

F253

FO

03

F255

4C

01

F258

20

IF

F25B

A5

BA

F25D

DO

03

F25F

4C

OD

F262

C9

F264
F266

F3

JSR $F30F

CKOUT

NOT

set

PRESENT"

output

looks for

file

found?

$F258

F7

JMP

$F701

"FILE

F3

JSR

$F31F

sets

LDA

$BA

device

BNE

$F262

JMP

$F70D

not zero?
"ILLEGAL DEVICE

03

CMP

#*O3

screen?

FO

OF

BEQ

*F275

yes

BO

11

BCS

*F279

IEC-bus

F268

C9

02

CMP

#$02

RS-232

F26A

DO

03

BNE

$F26F

F26C

4C

El

JMP

$EFE1

EF

device

logical

BEQ

F7

-for

TALK

TXA

*****************************

Set

NOT

FOUND"

file

parameters

number

tape

as

F26F
F271
F273

A6 B9
EO 60
FO EA

LDX $B9
CPX #$60
BEQ $F25F

secondary

F275

85 9A

STA $9A

set

NUMBER"

out-put

device

address

zero?
tape

A-116

file

number

for

of

readi ng , error-

output

device

F277

18

CLC

F278

60

RTS

***** ***-)(-**)***}-***>(-*********

F279

AA

Lay

out-put

on

IEC-bus

TAX

F27A

20

oc

JSR

*EDOC

F27D

send

A5

B9

LDA

*B9

F27F

secondary

10

05

BPL

*F286

F281

20

BE

F284

DO

03

F286

20

B9

F289

8A

F28A

24

90

BIT

$90

F28C

status

10

E7

BPL

*F275

ok?

F28E

4C

07

JMP

$F707

"DEVICE

ED

ED
ED

JSR

*EDBE

BNE

*F2B9

JSR

*EDB9

set

LISTEN

back

send

address

ATN

secondary

address

TXA

F7

NOT

PRESENT"

*****************************

CLOSE

logical

F291

20

14 F3

JSR $F314

looks

-for

logical

F294

FO

02

BEQ *F298
fole

not

present,then

F296

18

CLC

F297

60

RTS

F298

20

F29B

8A

IF

F3

JSR

SF31F

set

-file

-File #

48

PHA

A5 BA

LDA *BA

device address

F29F

BEQ *F2F1
CMP #$03

keyboard?

F2A1

FO 50
C9 03

screen?

F2A3

FO 4C

BEQ *F2F1

F2A5

BO

47

BCS *F2EE

IEC-bus?

F2A7

C9

02

CMP #*02

RS--232?

F2A9

DO

ID

BNE $F2C8

tape

*****************************

68

in

ready

Close

RS-232

-file

PLA

F2AC

20 F2 F2 JSR *F2F2

clear

F2AF

20

83

F4

JSR *F4B3

set

back

CIAs

F2B2

FE

free

RS-232

F2B7

20 27
A5 F8
FO 01

F2B9

CB

F2BA

A5

FA

LDA

*FA

F2BC

FO

01

BEQ

*F2BF

JSR *FE27

set

LDA

*F8

input

BEQ

SF2BA

-file-entery
-for

in

table

I/O

I/O

buffer

buffer

I NY

F2BE

C8

F2BF

A9

00

LDA

#*00

F2C1

85

F8

STA

*FB

F2C3

85

FA

STA

*FA

F2C5

4C

7D F4

JMP $F47D

output

buffer

I NY

*****************************

F2C8

parameter

F29C

F2B5

in

file#

TXA

F29D

F2AB

for

LISTEN

A5

B9

LDA

*B9
#*0F

set

buffer

CLOSE

tape

secondary

F2CA

29

OF

AND

F2CC

FO

23

BEQ $F2F1

file

F2CE

20 DO F7

JSR

*F7D0

get

F2D1

A9

LDA

#$00

F2D3

38

00

SEC

A-117

for

free

file
address

reading?

tape-buffer

start

adrs.

F2D4

20

DD

Fl

JSR

$F1DD

F2D7

20

64 F8

JSR

$F864

F2DA

90

04

BCC

$F2E0

write

buffer

tape

PLA

F2DC

68

F2DD

A9

F2DF

60

F2E0

A5

B9

LDA

$B9

secondary

F2E2

C9

62

CMP

#$62

equal

LDA

00

#$00

RTS
address

F2E4

DO

OB

BNE

$F2F1

F2E6

A9

05

LDA

#$O5

control-byte

F2E8

20

6A

F7

JSR

$F76A

write

block

F2EB

4C

Fl

F2

JMP

$F2F1

F2EE

20

42

F6

JSR

$F642

close

IEC

F2F1

68

F2F2

AA

F2F3

C6

98

DEC

$98

decrement

F2F5

E4

98

CPX

$98

F2F7

FO

14

BEQ

$F30D

F2F9

A4

98

LDY

$98

F2FB

B9

59

02

LDA

$0259, Y

F2FE

9D

59

02

STA

$0259, X

F301

B9

63

02

LDA

$0263, Y

F304

9D

63

02

STA

$0263, X

F307

B9

6D

O2

LDA

$026D, Y

F3OA

9D

6D

02

STA

$026D, X

F30D

18

CLC

F30E

60

RTS

for
on

EDT-header

tape

file

PLA
TAX

equal

open

*****************************

A9

00

F311

85

90

F313

8A

F314

A6

F316

CA

F317

30

15

F319

DD

59

F31C

DO

F8

F31E

60

F30F

on

Looks

zero,

file

for

LDA

#$OO

STA

$90

clear

$98

number

of

open

then

files

ready

parametertable

logical

file#

in

status

TXA
LDX

98

of

open

files

DEX

02

BMI

$F32E

CMP

$0259,x

BNE

$F316

looks

for

entry

in

table

RTS

*****************************

F31F

BD 59 02

LDA

$0259,X

F322

85

B8

STA

$B8

F324

BD

63

LDA

$0263, X

F327

85

BA

STA

$BA

F329

BD

6D

LDA

$026D,,x

F32C

85

B9

STA

$B9

F32E

60

02

02

Set

file

logical
device

parameter
file

number

address

secondary

address

RTS

it..*.***************************
F32F

A9

00

LDA

#$00

F331

85

98

STA

$98

F333

A2

03

LDX

#$03

F335

E4

9A

CPX

F337

BO

03

BCS

F339

20 FE ED

CLALL-closes

I/O

channels

number

of

open

$9A

number

of

out-put

$F33C

smal1er
send

JSR $EDFE

A-118

than

IEC,

files

UNLISTEN

device

F33C
F33E

E4 99
BO 03

F340
F343
F345

20 EF ED JSR
86 9A
STX
A9 00
LDA
85 99
STA
60
RTS

F347
F349

CPX

$99

number of input
smaller than 3

BCS $F343
$EDEF
$9A

send

reset

IEC,

UNTALK
out-put to screen

reset

input

#$00
$99

*****************************

F34A

A6 B8

LDX

F34C

DO 03

BNE $F351

$BB

-File
not

number

4C

OA

F7

JMP

$F70A

20

OF

F3

JSR

"NOT

$F30F

F354

DO

looks -For

03

BNE

$F359

F356

4C

FE

not

JMP

$F6FE

F359

A6

98

"FILE

LDX

$98

CPX

number

#$0A

compare

F35B

EO

OA

9O

03

F35F

4C

FB

F362

E6

98

F364

A5

B8

F366

9D

59

F6

02

"TOO

$9B

increase

LDA

$B8

STA

logical

$0259,X

B9

LDA

$B9

ORA

#$60

STA

$B9

85

B9

9D

6D

F372

A5

BA

F374

9D

63

F377

FO

F379

F37B
F37D

secondary

$026D,X

STA

device

$0263,X

5A

write

BEQ

$F3D3

keyboard?

C9

03

CMP

#$03

FO

56

BEQ

$F3D3

90

05

BCC

$F384

F37F

20

D5

JSR

$F3D5

F382

90

4F

BCC

$F3D3

open

file

C9

02

CMP

#$02

tape?

03

BNE

$F38B

no

F388

4C

09

F4

JMP

$F409

RS-232

F38B

20

DO

F7

JSR

$F7D0

F38E

get

BO

03

BCS

$F393

JMP

$F713

"ILLEGAL

LDA

$B9

secondary

4C

13

B9

F395
F397

29

OF

AND

#$0F

DO

IF

BNE

$F3B8

F399

20

17

JSR

$F817

F39C

BO

36

BCS

$F3D4

F39E

20

AF

F3A1

A5

B7

F3A3

FO

OA

F3A5

20

EA

F3A8

90

F3AA

F7

F8

F5

not

on

table

IEC-bus

open

tapebuffer

DEVICE

startadrs.

NUMBER"

address

zero?

waits

for

JSR

$F5AF

LDA

$B7

BEQ

$F3AF

JSR

$F7EA

18

BCC

$F3C2

FO

28

BEQ

$F3D4

F3AC

4C

04

F7

JMP

$F704

out-put

F3Af

20

2C

F7

JSR

$F72C

search

F3B2

FO

20

BEQ

$F3D4

F3B4

90

OC

BCC

$F3C2

F7

right

screen

DO

A5

number

address

the

F384

F390

files

10

number

in

F386

F393

opened

FILES"

file

$BA

F3

-File
be

number

LDA
02

can

open

MANY

STA

02

it

with

INC

60

F36D

of

$F362

A5

(??)

OPEN"

$F6FB

09

FILE"
logical

found,

BCC

F36B
F36F

INPUT

JMP

F369

keyboard

zero

F351

F35D

to

OPEN

F34E

F6

device

PLAY

key

out-put"SEARCHING

length
no

of

file

file

name,

searches

for

FOR

name"

name
then

continue

desired

tapeheader

A-119

"FILE
for

NOT

next

FOUND"

tape-header

BCS

$F3AC

JSR

$F838

BCS

$F3D4

LDA

#$04

control-byte

for

JSR

$F76A

write

on

BF

LDA

#$BF

pointer

B9

LDY

$B9

secondary

CO

60

CPY

#$60

FO

07

BEQ

$F3D1

F3CA

AO

00

LDY

#$00

F3CC

A9

02

LDA

#$02

F3CE

91

B2

STA

F3D0

98

F3D1

85

A6

STA

F3D3

18

CLC

F3D4

60

RTS

F3B6

BO

F4

F3B8

20

38

F3BB

BO

17

F3BD

A9

04

F3BF

20

6A

F3C2

A9

F3C4

A4

F3C6
F3C8

F8

F7

waits

for

RECORD

header
to

write

TYA

in

pointer

$A6

*****************************

OPEN

in

files

B9

LDA

$B9

F3D7

30

FA

BMI

$F3D3

F3D9

A4

B7

LDY

$B7

length

F3DB

FO

F6

BEQ

$F3D3

=0,

F3DD

A9

00

LDA

#$00

F3DF

85

90

STA

$90

clear

F3E1

A5

BA

LDA

$BA

device

F3E3

20

OC

JSR

$EDOC

LISTEN

end

secondary

datablock-

buffer

tape-buffer

IEC-bus

address

of

then

file

name

error

status
address

F3E6

A5

B9

LDA

$B9

F3E8

09

FO

ORA

#$FO

F3EA

20

B9

JSR

$EDB9

send

F3ED

A5

90

LDA

$90

check

F3EF

10

05

BPL

$F3F6

ok

F3F1

68

F3F2

68

F3F3

4C

O7

JMP

$F707

11DEVICE

F3F6

A5

B7

LDA

$B7

length

F3F8

FO

OC

BEQ

$F4O6

F3FA

AO

00

LDY

#$00

F3FC

Bl

BB

LDA

F3FE

20

DD

F401

C8

F402

C4

B7

CPY

F404

DO

F6

BNE

$F3FC

F406

4C

54

JMP

$F654

address

status

PLA
PLA

F7

ED

JSR

NOT
of

PRESENT "

file-name

filename

($BB>,Y

out-put

$EDDD

on

IEC-bus

I NY

F6

$B7

UNLISTEN,

******************

********-

RS-232

20

83

F4

JSR

$F483

set

F40C

BC

97

02

STY

$0297

clear

F40F

C4

B7

CPY

$B7

length

$F41D

F409

dataheader

for

on

secondary

A5

ED

key

tape

tapebuffers

tape

F3D5

ED

PLAY

address

control-byte

($B2),Y

&

F411

FO

OA

BEQ

F413

Bl

BB

LDA

($BB),Y

F415

99

93

STA

$0293,Y

F418

C8

F419

CO

04

CPY

#$04

F41B

DO

F2

BNE

$F40F

F41D

20

4A

JSR

$EF4A

02

save

return

OPEN

CIAs
RS-232

the

of

status

filename

first

by

characters

I NY

EF

calculate

A-120

of

databits

F420

8E

98

02

STX

$0298

F423

AD

93

and

02

LDA

$0293

F426

29

OF

control

1C

AND

F428

FO

F42A

OA

ASL

F42B

AA

TAX

F42C

AD

A6

F42F

DO

09

F431

BC

Cl

FE

LDY

F434

BD

CO

FE

LDA $FECO,X

BEQ

O2

LDA

for

table

*02A6

BNE *F43A

*FEC1,X

4C

40

F4

JMP

*F44O

F43A

BC

EB

E4

LDY

*E4EB,X

F43D

BD

EA

E4

LDA

$E4EA,X

F440

8C

96

02

STY

$0296

F443

8D

95

02

STA

$0295

F446

AD

95

02

LDA

$0295

F449

OA

baud-rate,
baud-rate,

High
Low

baud-rate,
baudrate,

High
Low

ASL

F44A

20

2E

FF

JSR

*FF2E

F44D

AD

94

02

LDA

$0294

F450

4A

F451

90

09

F453

AD

01

F456

OA

determine baud-rate code

LSR
DD

BCC

$F45C

LDA

$DD01

ASL

F457

BO

03

BCS

$F45C

F459

20

OD

FO

JSR

*FOOD

F45C

AD

9B

02

LDA

*029B

F45F

8D

9C

02

STA

*029C

F462

AD

9E

02

LDA

*O29E

F465

8D

9D

02

STA

*029D

FE

F468

20

27

F46B

A5

F8

F46D

DO

05

F46F

88

JSR

$FE27

LDA

$F8

BNE

*F474

84

F8

STY

F472

86

F7

STX

A5

FA

LDA

*FA

F476

DO

05

BNE

*F47D

F478

88

84

FA

STY

F47B

86

F9

STX

F47D

38

F47E

A9

FO

F480

4C

2D

-for

set

bu-F-ferpointer

top

of

pointer

for

RS-232

output buffer
pointer

DD

input

for

used

already?

RS-232 output
buffer

LDA

#*F0

JMP

*FE2D

LDA

I/O

buffer

set

*****************************

7F

for

used already?

SEC
FE

DSR

memory

input buffer

DEY

F479

status

get

*F7

F474

set

RS-232

DEY

F470

A9

register

isolate bits -for baud-rate

*F446

F437

F483

save

#$7F

F485

8D

OD

STA

$DDOD

F48S

A9

06

LDA

#*06

F48A

8D

03

DD STA

F48D
F490

8D
A9

01
04

DD

STA $DD01
LDA #$04

*DD03

F492

OD

00

DD

ORA

$DDOO

F495

SD

00

DD

STA

$DDOO

F498

AO

00

LDY

#*00

A-121

Set

new
CIAs

top
back

of
to

memory
RS-232

F49A

8C

F49D

60

Al

02

STY

$O2A1

RTS

*****************************

LOAD

routine

save

start

address

F49E

86

C3

STX

$C3

F4A0

84

C4

STY

$C4

F4A2

6C

30

F4A5

85

93

STA

$93

F4A7

A9

00

LDA

#$00

F4A9

85

90

STA

$90

F4AB

A5

BA

LDA

$BA

F4AD

DO

03

BNE

$F4B2

F4AF

4C

13

JMP

$F713

then continue
"ILLEGAL DEVICE NUMBER"

F4B2

C9

O3

CMP

#$03

screen?

F4B4

FO

F9

BEQ

$F4AF

yes,

F4B6

90

7B

BCC

$F533

F4B8
F4BA

A4 B7
DO 03

LDY $B7
BNE $F4BF

F4BC

4C

10 F7

JMP

F4BF

A6

B9

LDX

F4C1

20 AF F5 JSR

03

F7

60

JMP

($0330)

MMP $F4A5

clear

not

address

zero,

error

smaller

3,

IEC LOAD
length o-f

not

then

from tape

-file-name

then ok
"MISSING FILE NAME"

$F71O

zero,

secondary

$B9

address

"SEARCHING FOR -filename"

$F5AF

secondary

A9

F4C6
F4C8

85 B9
STA $B9
20 D5 F3 JSR $F3D5

LDA #$60

open

F4CB

A5

device

F4CD

20 09 ED JSR $ED09

F4D0
F4D2

A5 B9
LDA $B9
20 C7 ED JSR $EDC7

F4D5

20

F4D8
F4DA

85 AE
A5 90

STA $AE
LDA $90

F4DC

4A

LSR

F4DD

4A

F4DE

BO

50

BCS

$F530

F4E0

2O

13 EE

JSR

$EE13

F4E3

85 AF

STA $AF

F4E5

8A

TXA

F4E6

DO

08

BNE

$F4F0

F4E8

A5

C3

LDA

$C3

F4EA

85

AE

STA

$AE

no,

F4EC

A5

C4

LDA

$C4

address

F4EE

85

AF

STA

$AF

F4F0

20

D2 F5 JSR

$F5D2

F4F3

A9

FD

LDA

#$FD

F4F5

25

9O

AND

$90

F4F7

85

90

STA

$9O

F4F9

20

El

JSR

*FFE1

scan

F4FC

DO

03

BNE

$F501

not

F4FE

4C

33 F6

JMP

$F633

close

F501

20

13

JSR

$EE13

get

F504

AA

F505

A5

$90

check

F507

4A

LDA

-flag

status

device

F4C4

BA

LOAD vector

load/verify

$BA

-file on

send

zero

IEC^bus

number

TALK

send

get

13 EE JSR $EE13

address

secondary

byte

save

address

from

IEC-bus

as start

address

low

status

LSR

FF

EE

time

get

out,

then

secondary
then

out-put
clear

address not
LOAD

LDA
LSR

A-122

from

zero?

given

"LOADING/VERIFYING11

timeout
STOP

bit

key

pressed,

then

continue

file

programbyte

TAX

90

error

start-address high

status

from

bus

F508

4A

F5O9

BO

F5OB

8A

F50C

A4

93

F50E

FO

OC

F510

AO

00

LDY

F512

#$00

Dl

AE

CMP

F514

FO

08

BEQ

$F51E

LDA

#$10

LSR
E8

BCS

$F4F3

error,

LDY

$93

BEQ

check

$F51C

=0,

then

interrupt

TXA

F516

A9

10

F518

20

1C

F51B

2C

FE

($AE),Y

set
save

91

AE

STA

E6

AE

INC

F520

DO

02

BNE

$F524

F522

E6

AF

INC

$AF

($AE),Y

24

9O

BIT

$90

F526

50

CB

BVC

$F4F3

F528

20

EF

ED

JSR

$EDEF

F6

20

42

90

79

F530

4C

04

F533

4A

F534

BO

O3

F536

4C

13

F7

comparison
then

set

status

status
byte

$AE

F524

F52B

flag

LOAD

unequal,

$FE1C
-BYTE $2C

F51C

F52E

veri-fy,

JSR

F51E

LOAD/VERIFY

then

JSR

$F642

BCC

$F5A9

JMP

$F704

increment

address

status
no

EOF

send
close
no

yet?

UNTALK
file

error?

"FILE

NOT

FOUND"

a-****-*****

LSR
F7

BCS

$F539

JMP

$F713

F539

20

DO F7

JSR

$F7D0

F53C

BO

03

BCS

$F541

F53E

4C

13

F7

JMP

$F713

F541

20

17

F8

JSR

$F817

F544

BO

68

BCS

$F5AE

F546

20

AF F5

JSR

$F5AF

F549

A5

B7

LDA

F54B

FO

09

BED

$F556

F54D

20

EA F7

JSR

*F7EA

F550

90

OB

BCC

*F55D

F552

FO

5A

BEQ

*F5AE

BCS

*F530

JSR

*F72C

BEQ

*F5AE

F554

BO

DA

F556

2O

2C

F559

FO

53

F7

F55B

BO

D3

BCS

*F530

F55D

A5

90

LDA

$90

F55F

29

10

AND

#$10

F561

38

F562

DO

4A

BNE

$F5AE

F564

EO

01

CPX

#$01

F566

FO

11

BEQ

$F579

F56B

EO

03

CPX

#$03

F56A

DO

DD

BNE

$F549

F56C

AO

01

LDY

#$01

device
one

number

(tape),

RS-232,
get

tape-buffer

waits

output
length
=O,

then

continue

"ILLEGAL

for

PLAY

DEVICE #"
start-

key

"SEARCHING FOR name"


of file name

then

searches

continue
for

desired

tapeheader

search

get

for

next

tape-header

status

SEC

F56E

Bl

B2

LDA

F57O

85

C3

STA

F572

C8

F573

Bl

B2

LDA

F575

85

C4

STA

$C4

F577

BO

04

BCS

$F57D

headertype

1=BASIC

program

(shiftable)

3=

machineprogram
(non-shiftable)

($B2),Y

startaddress

low

startaddress

high

$C3

I NY
($B2),Y

A-123

secondary

F579

A5

B9

LDA

F57B

DO EF

BNE

F57D

AO 03

LDY #$03

F57F
F581
F583

Bl B2
AO 01
Fl B2

LDA <$B2),Y
LDY #*O1
SBC <$B2>,Y

F585
F586

AA
AO

F588

Bl

04
B2

TAX
LDY #$O4
LDA <$B2>,Y

F58A
F58C

AO 02
Fl B2

LDY #*02
SBC <*B2),Y

F58E

A8

TAY

F58F

18

CLC

F59O
F591

8A
65 C3

TXA
ADC *C3

F593

85 AE

STA *AE

F595
F596

98
65 C4

TYA
ADC

F598
F59A
F59C

85 AF
A5 C3
85 Cl

STA $AF
LDA $C3
STA *C1

F59E
F5A0
F5A2
F5A5

A5
85
20
20

F5A8

24

C4
LDA
C2
STA
D2 F5 JSR
4A F8 JSR

not

SF56C

end-address

start

address

length

program

length

18

A6

F5AC

A4 AF

LDY $AF

F5AE

60

RTS

F5AF

A5

load

end

$AE

address

check

F5B1

10

IE

BPL

$F5D1

no,

F5B3

AO

OC

LDY

#$0C

offset

F5B5

20

2F

F5B8

A5

B7

LDA

length

F5BA

FO

15

BEQ

=0,

F5BC

AO

17

F5BE

2O

2F

F5C1

A4

F5C3

FO

F5C5

F5C7

Fl

JSR $F12F

$Ci/*C2

from

to

X/Y

"SEARCHING"

then

of

then

offset

"SEARCHING"
file

name

ready

for

"FOR"

B7

LDY

*B7

OC

BEQ

AO

00

LDY

Bl

BB

F5C9

20

D2

F5CC

CB

F5CD

C4

B7

CPY

F5CF

DO

F6

BNE

F5D1

60

F5D2

AO

49

LDY

#$49

offset

F5D4

A5

93

LDA

*93

check

load/verify

F5D6

FO

02

BEQ

*F5DA

load,

then

F5D8

AO

59

LDY

#$59

offset

LDA

out-put
length

($BB),Y

JSR

name

message

$F12F

=0,

for

skip

for

JSR

FF

tape

direct-mode

output

LDY

Fl

to

"LOADING/VERIFYING"

program

Out-put
LDA

adrs

address

output

CLC

9D

+ start

$24

F5AA

LDX

load

minus

start-address

*C4
$C2
$F5D2
*F84A

F5A9

AE

absolute

program

end

*C4

.BYTE

address

zero,then

message
of

file

then

ready

get

file

name

and

output

name

it

I NY
*F5C7

RTS
out-put

A-124

"LOADING/VERIFYING"
for

for

"LOADING"
flag

output

"VERIFYING"

F5DA

4C 2B Fl

JMP $F12B

out-put

message

F5DD

86

AE

SAVE

routine

BTX

$AE

F5DF

84

AF

end

address

low

STY

$AF

F5E1

AA

end

address

high

F5E2

B5

00

LDA

$OO,X

F5E4

85

Cl

STA

*C1

F5E6

B5

01

LDA

$01, X

STA

$C2

TAX

F5E8

85

C2

F5EA

6C

32

F5ED

A5

BA

F5EF

DO

03

F5F1

4C

13

F5F4

C9

F5F6
F5F8

O3

JMP
LDA

<$O332>

start

address

start

address high

SAVE-vector,

$BA

device

BNE

$F5F4
$F713

03

CMP

#$03

FO

F9

BED

$F5F1

screen,

90

5F

BCC

$F659

tape

"ILLEGAL

******************************

SAVE

on

IEC-bus

61

LDA

#$61

secondary

F5FC

85

B9

STA

$B9

set

F5FE

A4

B7

LDY

$B7

F600

DO

03

BNE

$F605

F602

4C

10

JMP

$F710

F605

20 D5 F3

JSR $F3D5

F608

20

8F F6

JSR $F68F

BA

LDA

length

A5

20 OC ED
A5 B9

$BA

F612
F615
F617
F61A
F61C
F61F

20
AO
20
A5
20
A5

F621
F624

20 DD ED
20 Dl FC

JSR $EDDD
JSR $FCD1

high

F627

BO

BCS *F63F

F629
F62B
F62E

Bl AC
LDA <*AC),Y
20 DD ED JSR *EDDD
20 El FF JSR *FFE1

yes,

F631
F633

DO 07
2O 42 F6

BNE $F63A
JSR $F642

F636

A9

LDA #$00

F638

38

SEC

F639

60

RTS

send

00

F63A

20 DB FC

JSR $FCDB

DO E5

BNE

$F624

JSR

$EDFE

BIT

$B9

address

secondary

address

LISTEN

address

to

start

address

low

$AC/$AD

send

and

send

end-address
then

bytes

out-put

to

scan

not

STOP

increment

20

FE

F642

24

B9

F644

30

11

BMI

*F657

F646

A5

BA

LDA

$BA

device

F648

20

OC

JSR

$EDOC

send

F64B

A5

B9

LDA

$B9

secondary

send

IEC-bus
then

IEC-bus

flag

yet?

key

pressed,

close

A-125

reached

ready

program

F63F

ED

IEC-bus

"SAVING"

start

set

F63D

ED

for

on

ok

name

LISTEN

send

B9 ED JSR $EDB9
00
LDY #$00
8E FB JSR $FBBE
AC
LDA $AC
DD ED JSR $EDDD
AD
LDA $Att

then

name

device

JSR $EDOC
LDA $B9

-file name

-file

out-put

F60B

16

o-f

missing

F6OD
F610

address

zero,

file

"

error

A9

F7

$E5ED

DEVICE NUMBER"

F5FA

not

JMP

address

JMP

F7

low

for

continue

channel
"BREAK"

current

UNLISTEN

address

LISTEN
address

output

address

F64D

29

EF

AND

#$EF

F64F

09

E0

ORA

#$E0

F651

20

B9

ED

JSR

$EDB9

F654

20 FE

ED

JSR $EDFE

output

send

F657

18

CLC

F658

6O

RTS

F659

4A

F65A

BO

03

F65C

4C

13

F65F

20 DO

F662

90 8D

F664

20

38

F667

BO

25

F669

20

8F

F66C

A2 03

LDX

#$O3

F66E

A5

B9

LDA

$B9

F670

29

01

AND

#$O1

F672

DO

02

BNE

$F676

F674

A2

01

LDX

#$01

header

F676

8A

F677

20

6A

JSR

$F76A

write

F67A

BO

12

BCS

$F6BE

F67C

20

67

JSR

$F867

F67F

BO OD

BCS

$F68E

F681

A5

B9

LDA

*B9

F683

29

02

AND

#$02

F685

FO

06

BEQ

F687
F689

A9 05
20 6A

LDA
JSR

E68C

24

.BYTE

$F65F

F7

JMP

$F713

F7

JSR $F7D0
BCC

F6

F8

F7

$F5F1

waits

$F68E

F6BD

18

CLC

60

RTS

F68F

A5

for

out-put

JSR $F68F

F68E

LDA

RECORD &

"SAVING

header-tyep
secondary

bit

yes,

is

$F6BD

no,

then

#*05
*F76A

write

EOT,

is

or

on

program

tape

stop-key

at

on

tape

stop-key

address

set

(2 or

3)

ready

control
block

byte
on

tape

*24

direct

*9D

"SAVING"
mode?

F691

10 FB

BPL *F68E

no,

F693
F695

AO 51
20 2F

offset

Fl

LDY #$51
JSR *F12F

output

message

F698

4C Cl

F5

JMP *F5C1

out-put

file

F69B

A2

VDTIM
00

3)
program

1=BASIC

at

secondary

name"

(1

program

bit

key

machine-prgm-

machine

header

jump-out

PLAY

address

type

jump-out

write

set

then

Out-put

9D

RS-232, "ILLEGAL DEVICE #"


get tape buffer start-adrs-

TXA
F7

address

tape

JSR $F838
BCS

secondary

device number

LSR
BCS

F8

of

UNLISTEN

LDX

#$00

F69D

E6

A2

INC

$A2

F69F

DO

06

BNE

$F6A7

F6A1

E6

Al

INC

$A1

F6A3

DO

02

BNE

$F6A7

F6A5

E6

AO

INC

$A0

F6A7

38

then

ready

for

"SAVING"

increase

increase

name

time

time

SEC

F6AB

A5

A2

LDA

$A2

F6AA

E9

01

SBC

#$01

F6AC

A5

Al

LDA

$A1

F6AE

E9

1A

SBC

#$1A

F6B0

A5

AO

LDA

$A0

F6B2

E9

4F

SBC

#$4F

F6B4

90

06

BCC

$F6BC

compare

smaller,

A-126

with

then

value

ok

for24

Hr

F6B6

86

F6B8

86 Ai

AO

F6BA

86 A2

F6BC
F6BF
F6C2
F6C4
F6C5
F6C7
F6C9
F6CC
F6CF
F6D2
F6D4

AD
CD
DO
AA
30
A2
8E
AE
EC
DO
8D

STX

STX $A1
STX

set time on zero

$A2

01 DC LDA $DC01
01 DC CMP $DC01
F8
BNE $F6BC
TAX
13
BMI $F6DA
BD
LDX #$BD
00 DC STX $DCOO
01 DC LDX $DC01
01 DC CPX $DCO1
F8
BNE $F6CC
OO DC STA $DCOO

F6D7

E8

INX

F6D8

DO 02

BNE $F6DC

F6DA

85 91

STA $91

F6DC

60

RTS

check stop-key

-flag for

*****************************

F6DE
F6E0
F6E2

A5 A2
A6 Al
A4 AO

F6E4
F6E5

78
85 A2

SEI
STA $A2

F6E7
F6E9
F6EB

86 A1
84 AO
58
60

STX $A1
STY $A0
CLI
RTS

*****************************

F6ED

F6EF

F6F1

A5 91

C9 7F

PHP

08

20 CC FF JSR *FFCC

F6F7
F6F9

85 C6
28

STA *C6
PLP

F6FA

60

RTS

F6FB

A9 01

LDA #*01

F6FD
F&FE

2C
A9 02

.BYTE *2C
LDA #*02

5703
F704

A9

5706

2C

5707

A9

5709

2C

570A

A9

F70C

2C

CLRCH

Out-put

-BYTE *2C
03

LDA #$03

04

LDA

05

LDA

06

LDA

2C

STOP-key

check on code for stop

F6F3

2C

Scan

CMP #*7F

F6F4

A9

time

-flag

BNE SF6FA

F701

Set

LDA $91

DO 07

F700

time

LDA $A2
LDX $A1
LDY $A0

*****************************

F6EC

Get

stop-key

-BYTE *2C
#$04
.BYTE

$2C

#$05

.BYTE

$2C

#$06

.BYTE

$2C

A-127

operating

systems

messages

F70D

A9

F7OF

2C

F710

A9

LDA

O7

#*O7

.BYTE
08

LDA

09

LDA

.BYTE

5712

2C

5713

A9

F715

48

F716

2O

CC

F719

A0

F71B

24

F71D

5O

OA

F71F

2O

2F

F722

68

F723

48

F724

09

30

F726

20

D2

F729

68

PLA

F72A

38

SEC

F72B

60

RTS

*2C

#*O8
$2C

#$09

save

PHA

FF

JSR

*FFCC

OO

LDY

#*00

9D

BIT $9D
BVC *F729
Fl

JSR

check

get

PHA

FF

to

#*30

LDA

program header

o-f-f

save

load/verify flag

read

block

A5

F72E
F72F

48
2O 41

F732

68

F733

85

93

STA

*93

get

F735

BO

32

BCS

*F769

error,

F737

AO

00

LDY

#*00

PHA
JSR $F841

number

out-put

F72C

F8

"I/O ERROR #"

error

Read

*93

-Flag

ASCII

and

JSR *FFD2

*****************************

93

direct-mode

out-put

*F12F

PLA

ORA

errornumber

CLRCH

o-f-f

tape

tape

PLA

F739

Bl

B2

LDA

F73B

C9

05

CMP

#$O5

<$B2>,Y

F73D

FO

2A

BEQ

*F769

F73F

C9

01

CMP

#*01

F741

FO

08

BEQ

*F74B

back

check

load/verify flag

then

end

header

type

EOT?

BASIC-program?

machine

F743

C9

03

CMP

#*03

F745

FO

04

BEQ

*F74B

F747

C9

04

CMP

#*04

data

F749

DO

El

BNE

*F72C

no

program?

header?

F74B

AA

F74C

24

9D

BIT

TAX

$9D

direct-mode?

F74E

10

17

BPL

$F767

no,

F750

AO

63

LDY

#*63

F752

20

2F

JSR

$F12F

out-put

F755

AO

05

LDY

#*05

offset

F757

Bl

B2

LDA

F759

20

D2

F75C

C8

F75D

CO

15

CPY

#$15

F75F

DO

F6

BNE

*F757

F761

A5

Al

LDA

*A1

F763

20

EO

JSR

$E4E0

F766

EA

NOP

F767

18

CLC

F768

88

DEY

F769

60

RTS

Fl

FF

JSR

then

continue
"FOUND"

of

file

name

<*B2>,Y

$FFD2

out-put

file

name

I NY

E4

middle
waits

time
for

byte

to

accum.

Commodore-key

or

time-loop

at

*****************************

A-128

error,

Generate

C=l

header

and

write

to

F76A

85

9E

F76C

20

DO

F76F

90

5E

F771

AS

C2

F773

48

F774

A5

F776

48

F777

A5

F779

48

F77A

A5

F7

STA

$9E

JSR

$F7D0

BCC

$F7CF

LDA

$C2

headertype
tape-bu-f-fer

get

PHA
Cl

LDA

save

LDA

AE

LDA

startaddress

$C1

PHA
AF

and
$AF

PHA

endaddress
$AE

F77C

48

F77D

A0

BF

LDY

#$BF

F77F

A9

20

LDA

#$2O

F781

91

B2

F783

88

PHA

STA

buffer-length

($B2).,Y

clear

F784

DO

FB

BNE

$F781

A5

9E

LDA

$9E

F788

91

B2

STA

F78A

C8

F78B

A5

Cl

LDA

91

B2

STA

F78F

CB

tape-buffer

<$B2),,Y

header-type

$C1

<$B2>,,Y

start-address

I NY

F790

A5

C2

LDA

F792

91

B2

STA

F794

CB

$C2

<$B2),,Y

I NY

F795

A5

AE

LDA

F797

91

B2

STA

F799

CB

$AE

<$B2),(Y

end-address

I NY

F79A

A5

AF

LDA

F79C

91

B2

STA

F79E

CB

$AF

<$B2),,Y

I NY

F79F

84

9F

STY

F7A1

AO

00

LDY

#$00

F7A3

84

9E

STY

$9E

F7A5

A4

9E

LDY

$9E

$9F

counter

for
with

F7A7

C4

B7

CPY

$B7

compare

F7A9

FO

OC

BEQ

$F7B7

F7AB

Bl

BB

LDA

all
get

F7AD

A4

9F

LDY

F7AF

91

B2

STA

F7B1

E6

9E

INC

$9E

<$BB), Y

($B2), Y

E6

9F

INC

$9F

F7B5

DO

EE

BNE

$F7A5

F7B7

20

D7

F7BA

A9

69

F7BC

85

AB

F7BE

20

6B

F7C1

A8

F7C2

68

F7C3

85

F7C5

68

F7C6

85

68

F7

F8

filename-length
length

letters, then
filename

continue

$9F

F7B3

85
68

I NY

F78D

F7C8

DEY

F786

F7C9
F7CB

address

write

in

start

and

JSR

$F7D7

LDA

#$69

STA

$AB

header

JSR

$F86B

write

header

end-address
tape

checksum block
on tape

block

TAY

PLA
AE

STA

$AE

PLA
AF

STA

Cl

STA
PLA

get

back

end-address

$AF

PLA

and

$C1

start-address

A-129

on
buffer

= $69

F7CC

85

F7CE

98

C2

STA
TYA

F7CF

60

RTS

*C2

*****************************

F7DO
F7D2
F7D4
F7D6

A6 B2
A4 B3
CO 02
60

Get

LDX *B2
LDY *B3
CPY #*02
RTS

tape-buffer

address

start-addr-

smaller

*2OO?

*****************************

F7D7

20 DO F7 JSR $F7D0

F7DA

8A

F7DB

85

F7DD

18

F7DE

69

CO

ADC

#*C0

F7E0

85

AE

STA

*AE

F7E2

98

F7E3

85

C2

STA

*C2

F7E5

69

00

ADC

#*00

F7E7

85

AF

STA

$AF

F7E9

60

get

TXA
STA

Cl

tape-buffer

start-address

$C1

tape

header

search

ID

BCS

$F80C

EOT,

05

LDY

#*05

filename

9F

STY

$9F

AO

00

LDY

#*00

84

9E

STY

$9E

counter

for

F7F7

C4

B7

CPY

*B7

compare

to

F7F9

FO

10

BEQ

*F80B

F7FB

Bl

BB

LDA

F7FD

A4

9F

LDY

F7FF

Dl

B2

CMP

F801

DO

E7

BNE

$F7EA

F803

E6

9E

INC

$9E

F805

E6

9F

INC

*9F

FB07

A4

9E

LDY

*9E

EC

BNE

*F7F7

BO
AO

F7F1

84

F7F3

F7F5

2C

F7

F809

DO

F80B

18

CLC

F80C

60

RTS

JLJLJI.M1JL

length(192)

RTS

search

F7EF

tape-

start-address

endaddress

TYA

*F72C

F7ED

start

buffer

JSR

20

CLC

*****************************

F7EA

address

next

then

then

letter

of

($B2),Y

compare

Increase

INC

$A6

increment

A6

LDY

$A6

CO

CPY

#*C0

E6

F812

A4

F814

CO

F816

60

next

tape-buffer

compare

header

counter

letters

tape-buffer

A6

F810

name

name

filename

further

get

F7

of

found

header

*F7D0

DO

header

length

equal,check

JSR

20

name

filename

increment

***?***h******H

F80D

in

searched

equal,

compare

for

header

ready

offset

($BB),Y

not

tape

pointer

address

pointer

to

max.

value

(192)

RTS
Waits

***** ******4********

for

JSR

$FB2E

scans

1A

BEQ

*F836

pressed,

IB

LDY

#$1B

offset

JSR

*F12F

output

F817

20

2E

F81A

FO

F81C

AO

F81E

20

2F

F8

Fl

A-I30

Tapekey

tape-keys
then

for

ready

"PRESS

PLAY

ON

TAPE"

F821

20

DO

F8

JSR

F824

20

2E

F8

JSR

$F82E

F827

DO

F8

BNE

$F821

F829

AO

6A

F82B

4C

2F

Fl

$FBDO
scans

LDY

#$6A

offset

JMP

$F12F

out-put

*******************#*###**#.**

F82E

A9

F830

24

01

BIT

$01

F832

DO

02

BNE

$FB36

01

BIT

$01

10

LDA

F834

24

F836

18

CLC

F837

6O

RTS

Check

#$10

20

2E

F8

JSR

yes,

FB3B

FO F9

BEQ $F836

AO

2E

LDY #$2E

F83F

DO

DD

BNE $FB1E

A9 00

LDA

#$00

F843

85 90

STA

$9O

F845

85 93

STA $93

F847

20 D7 F7 JSR $F7D7

Read

20

17 F8 JSR $F817

F84D

BO

IF

F84F

BCS $F86E

78

F850

A9

00

LDA #$00

F852

85 AA

STA

85

B4

STA

$B4

F856

85

BO

STA

$B0

F85B

85

9E

STA $9E

tape-key -for writin


then

block

clear

ready

"PRESS PLAY &


/RECORD ON TAPE"
off

tape

status

and

verify-flag

get

tape-buffer

LOAD program
waits for

address

from tape

PLAY-key

$AA

clear

work-memory for

FB5A

85

9F

STA

85

9C

STA

$9C

F85E

A9

90

LDA

#$90

F860

A2

OE

constant

LDX

#$0E

F862

DO

11

BNE

$F875

number

$9F

*****************************

20 D7 F7 JSR $F7D7
A9 14
LDA #$14
85 AB
STA $AB

38

F86E

BO

6C

F870

78

F871

A9

82

LDA

#$82

F873

A2

08

LDX

#$08

F875

AO

7F

LDY

#$7F

F877

BC

OD

DC

STY

$DCOD

F87A

8D

OD

DC

STA

$DCOD

F8

JSR

$F838

BCS

$F8DC

Write
get

for

of

timer

IRQ

high

vector,

tape buffer
tape-buffer

on

$F92C

tape

address

check-sum

for

*****************************

2O

IRQ-

routine

F85C

F86B

Z=0

SEI

F854

F864
F867
F869

otherwis

tape-key

of-fset for
re-check

*****************************

F84A

Z =1,

pressed,

*****************************

F841

ta

the

scan

"OK"

bit

Waits -for

$F82E

F83D

for

if

check

*****************************

FB38

Tape

data

Write

block

of

block

or

for

REC-

waits

header

prgm.

&

on

$14
tape

PLAY

SEI

constant
number

A-131

of

for

timer

high

IRQ-vector

$FC6A

0/1

adeq.

jo4-

joj.

* ou

yo

isy

yo

isy

xxs

la*

yai

oa*

03
T3

sy
98

Z.38d
93Bd

i73Bd
S38d

*****************************

yai

oo*#

sxa
yxs

oyso*

ssajppe

uaqq.

so

09

oy

00

08

6y

33S

89

yid

89

yid

3N3

T38d*

dsr

63d*

3d

6
3O

asr

OS
oa

8T

313

T3dd*

dd

T3

OS

T38d
30Bd
308d
308d
ya8d
608d

908d
frO8d

08d

oaad

*****************************

pua

o/I

ST

3a8d* 033

oa

USD

008d*

use

339d*

dWF

33Bd*

8d
9d
8d

33
33

3fr
OS

Od

dW3

SO

ST

03

a38d
y38d
i!3Bd
S38d

fr38d
T38d

338d

oy

8S

113

S38d*
adeq.

Z38d*

ade^

03
8T

313

yai

oyso*

STO*

*****************************

-JO*

adeq.

8d

3N3

uo

Jaquinu

joj-

ad

3N3

aNy

dT*#

yxs

TO*

yxs

03*

xai

dd*#

Aai

dd*#

yxs

33*

usr

63d*

yai

TO*

yxs

oyso*

dsr

a33d*

yai

30*#

yai

yxs

d6S0*

yai

STO*

asr

yai

TTOa*

aNy

T6*#

yuo

6T*#

oa
y3

X3a

unj

-146 tq

oa
88

A30

ade}
joj.

s>j3oxq

0/1

yxs

TTOa*

frTO*

dd
dd
03
TO
dT

TO
3d

Lh
38
SO

3d
30

0
SO
O

oa

aa

oy
ST
d6

frT
TT

d3

d3*# aNy

yxs

syso*

tryod*

yxs

dO3a*

yai

3O3O*

oa

Od
so

TT

oy

sy
S8
S8
63

sy
OS
S8
6y
OS
08

ay
08

ay
08

63
ay

03
sy 08

-fry

T6
3a

dO
6T

3a

30

63
08

6O

ay

a38d

338d
y38d
838d

Z.S8d
S38d
38d

T88d
dysd
ayBd

sy8d
8y8d
9y8d
frysd
TyBd

368d
368d
868d
S68d

S68d
068d
088d

y88d
Z.88d

S88d
388d
O88d
az.8d

F8E8

18

F8E9

65

F8EB

18

CLC
BO

ADC

$B0

CLC

F8EC

65

Bl

ADC

$B1

F8EE

85

Bl

STA

$B1

F8F0

A9

00

LDA

#$00

F8F2

24

BO

BIT

$B0

F8F4

30

01

BMI

$F8F7

F8F6

2A

F8F7

06

F8F9

2A

F8FA

06

F8FC

2A

ROL
Bl

ASL

$B1

ROL

Bl

ASL

$B1

ROL

F8FD

AA

F8FE

AD

06

F901

C9

16

CMP

#$16

F903

9O

F9

BCC

$F8FE

ADC

$B1

TAX
DC

LDA

$DC06

F905

65

Bl

F907

8D

04

DC

STA $DC04

07

DC

ADC $DC07

F90A

8A

F90B

6D

TXA

F90E

8D

05

DC

STA

$DC05

F911

AD

A2

O2

LDA

$02A2

F914

8D

OE

DC

STA

$DCOE

F917

8D A4 02

STA

$02A4

F91A

AD

OD DC

LDA

$DCOD

F91D

29

10

AND

#$10

F91F

F0

09

BEQ

$F92A

F921

A9

F9

LDA

#$F9

2A

LDA

F923

48

F924

A9

PHA

F926

48

F927

4C

F92A

58

CLI

F92B

60

RTS

#$2A

FF

JMP

<*#* ***

AE

07

F92F

AO

FF

$FF43

******

DC

LDX

$DC07

LDY

#$FF

F931

98

F932

ED

06

DC

SBC

F935

EC

07

DC

CPX

$DC07

F938

DO

F2

BNE

$F92C

Bl

STX

$B1

F93A

86
AA

input from tape


isolate bit

return

address on stack

PHA
43

F92C

F93C

read

to

interrupt

Tape read

interrupt-routine

timer

high

input

-from

TYA

$DC06

TAX

F93D

8C

06

DC

STY

$DC06

F940

8C

07

DC

STY

$DC07

F943

A9

19

F945

8D

OF

DC

F948

AD

OD

DC

LDA

$DCOD

F94B

8D

A3

02

$02A3

F94E

98

STA
TYA

F94F

E5 Bl

SBC

$B1

F951

86

Bl

STX

$B1

F953

4A

LDA

#$19

STA

$DCOF

LSR

A-133

tape

$B1

F954

66 Bl

ROR

F956

4A

LSR

F957

66 Bl

ROR

F959

A5 BO

LDA $B0

F95B

18

CLC

F95C

69

3C

ADC

#$3C

F95E

C5 Bl

CMP

$B1

F960

BO 4A

BCS $F9AC

F962

A6 9C

LDX

$9C

F964

FO O3

BEQ

$F969

F966

4C

F969

A6 A3

JMP $FA60
LDX $A3

F96B

30

IB

BMI

$F988

F96D

A2 00

LDX

#$00

F96F

69 30

ADC

#$30

F971

65 BO

ADC

$B0

F973

C5

Bl

CMP

F975

BO

1C

$Bi
BCS $F993

F977

E8

F978

69

26

ADC

#$26

F97A

65 BO

ADC

$B0

F97C

C5 Bl

CMP

$B1

F97E

BO

17

F98O

69

2C

BCS $F997
ADC #$2C

F982

65 BO

ADC

$B0

F984

C5 Bl

CMP

$B1

F986

90

03

BCC

$F98B

F988

4C

10

JMP

*FA10

F98B

A5

B4

LDA

$B4

F98D

FO

ID

BEQ

*F9AC

F98F

85 A8

STA

$A8

F991

DO

19

BNE

*F9AC

F993

E6 A9

INC

F995

BO

O2

BCS

F997

C6

A9

DEC

F999

38

F99A

E9

13

SBC

F99C

E5

Bl

SBC

F99E

65

92

ADC

F9A0

85

92

STA

F9A2

A5

A4

LDA

F9A4

49

01

EOR

#$01

F9A6

85

A4

STA

$A4

F9A8

FO

2B

BEQ

$F9D5

F9AA

86

D7

STX

$D7

F9AC

A5

B4

LDA

$B4

F9AE

FO

22

BEQ

$F9D2

F9B0

AD

A3

LDA

$02A3

F9B3

29

01

AND

#$01

F9B5

DO

05

BNE

$F9BC

F9B7

AD

A4 02

LDA

$02A4

F9BA

DO

16

BNE

$F9D2

F9BC

A9

00

LDA

#$00

F9BE

85

A4

STA

$A4

F9C0

8D

A4

STA

$02A4

F9C3

A5

A3

LDA

$A3

60

FA

$B1

I NX

FA

*F999

SEC

02

02

$92

A-134

F9C5

10

30

F9C7

BPL

3O

*F9F7

BF

BMI

F9C9

*F988

A2

A6

F9CB

LDX

20

#*A6

E2

F9CE

JSR

A5

*F8E2

9B

LDA

F9D0

*9B

DO

B9

F9D2

BNE

4C

*F98B

BC

F9D5

JMP

A5

92

*FEBC
*92

F8

FE

LDA

F9D7

FO

07

BEQ

F9D9

30

03

F9DB
F9DD

BMI

C6

BO

DEC

F9DE
F9E0

E6
A9

BO
00

INC
LDA

*F9E0
*F9DE

*BO
-BYTE *2C

2C

*B0
#*00

F9E2

85

92

STA

*92

F9E4

E4

D7

CPX

*D7

F9E6

DO

OF

BNE

*F9F7

F9E8

8A

TXA

F9E9

DO

AO

BNE

$F98B

F9EB

A5

A9

LDA

*A9

F9ED

30

BD

BMI

*F9AC

F9EF

C9

10

CMP

#*10

F9F1

90

B9

BCC

*F9AC

F9F3

85

96

STA

$96

F9F5

BO

B5

BCS

$F9AC

F9F7

8A

TXA

F9F8

45

9B

EOR

*9B

F9FA

85

9B

STA

*9B

F9FC

A5

B4

LDA

*B4

F9FE

FO

D2

BEQ

*F9D2

FAOO

C6

A3

DEC

*A3

FA02

30

C5

BMI

$F9C9

FA04

46

D7

LSR

*D7

FA06

66

BF

ROR

$BF

FA08

A2

DA

LDX

#$DA

FAOA

20

E2

F8

JSR

$F8E2

FAOD

4C

BC

FE

JMP

*FEBC

FA1O

A5

96

LDA

$96

FA12

FO

04

BEQ

*FA18

FA14

A5

B4

LDA

*B4

FA16

FO

07

BEQ

*FA1F

FA18

A5

A3

LDA

*A3

BMI

*FA1F

JMP

*F997

FA1A

30

03

FA1C

4C

97

FA1F

46

Bl

LSR

*B1

FA21

A9

93

LDA

#*93

F9

FA23

38

FA24

E5

Bl

SBC

*B1

FA26

65

BO

ADC

*B0

FA28

OA

SEC

ASL

FA29

AA

FA2A

20

E2

JSR

*F8E2

FA2D

E6

9C

INC

*9C

FA2F

A5

B4

LDA

*B4

TAX
F8

A-135

FA31

DO

11

BNE

$FA44

FA33

A5

96

LDA

$96

FA35

FO

26

BEQ $FA5D

FA37

85

A8

STA

SAB

FA39

A9

OO

LDA

#$OO

FA3B

85

96

STA

$96

FA3D
FA3F

A9
8D

81
OD

LDA

FA42

85 B4

STA $DCOD
STA $B4

FA44

A5 96

LDA

$96

FA46

85 B5

STA

$B5

FA48

FO 09

BEQ

$FA53

FA4A

A9

OO

LDA

#$OO

FA4C

85 B4

STA

$B4

FA4E

A9

LDA

#$01

FA50

8D OD

STA

$DC0D

FA53

A5

BF

LDA

$BF

FA55

85

BD

STA

$BD

FA57

A5

A8

LDA

$A8

FA59

05

A9

ORA

$A9

FA5B

85 B6

STA

$B6

FA5D

4C

BC

FE

JMP

$FEBC

FA60

20

97

FB

JSR

$FB97

FA63

85 9C

STA

$9C

FA65

A2

DA

LDX

#$DA

FA67

20

E2

JSR

$F8E2

FA6A

A5

BE

LDA

$BE

FA6C

FO

02

BEQ

$FA70

FA6E

85

A7

STA

$A7

FA70

A9

OF

LDA

#$0F

FA72

24

AA

BIT

$AA

FA74

10

17

BPL

$FA8D

FA76

A5

B5

LDA

FA78

DO

OC

BNE

$FA86

FA7A

A6

BE

LDX

$BE

FA7C

CA

FA7D

DO

OB

BNE

$FA8A

FA7F

A9

08

LDA

#$08

JSR

$FE1C

DC

01
DC

F8

return

-from

interrupt

DEX

FE

FA81

20

1C

FAB4

DO

04

BNE

$FA8A

FA86

A9

00

LDA

#$00

FA88

85

AA

STA

$AA

FA8A

4C

BC

JMP

$FEBC
$FAC0

FE

FA8D

70

31

BVS

FA8F

DO

18

BNE

$FAA9

FA91

A5

B5

LDA

$B5

FA93

DO

F5

BNE

$FA8A

FA95

A5

B6

LDA

$B6

FA97

DO

Fl

BNE

$FA8A

FA99

A5

A7

LDA

$A7

"LONG
set

return

LSR

FA9B

4A

FA9C

A5

BD

LDA

$BD

FA9E

3O

03

BMI

$FAA3

FAAO

90

18

BCC

$FABA

FAA2

18

CLC

A-136

BLOCK"

error

status

-from

interrupt

FAA3

BO

15

BCS

FAA5

29

OF

AND #$0F

$FABA

FAA7

85

AA

STA

FAA9

C6

AA

DEC

$AA

FAAB

DO

DD

BNE

$FA8A

$AA

FAAD

A9

40

LDA

#$40

FAAF
FAB1

85
2O

AA
8E

STA

JSR

$AA
$FB8E

FAB4

A9

00

LDA

#$00

FAB6

85

AB

STA

SAB

FAB8

FO

DO

BEQ

$FA8A

FABA
FABC

A9 80
85 AA

LDA
STA

#$80
$AA

FB

FABE

DO

CA

BNE

$FA8A

FACO

A5

B5

LDA

$B5

FAC2

FO

OA

BEQ

$FACE

FAC4

A9

04

LDA

#$O4

FAC6

2O

1C

JSR

FAC9

$FE1C

A9

00

LDA

#$00

FACB

4C

4A

FB

JMP

$FB4A

FC

JSR

$FCD1

FACE

20

Dl

FAD1

90

03

FAD3

4C

48

FAD6

A6

A7

FAD8

CA

FE

FB

BCC

$FAD6

JMP

$FB48

LDX

$A7

FAD9

FO

2D

BEQ

$FB08

A5

93

LDA

$93

FADD

FO

OC

BEQ

$FAEB

FADF

AO

00

LDY

#$00
$BD

FAE1

A5

BD

LDA

FAE3

Dl

AC

CMP

FAE5

FO

04

BEQ

$FAEB
#$01

($AC),Y

FAE7

A9

01

LDA

FAE9

85

B6

STA

$B6

FAEB

A5 B6

LDA

$B6

FAED

FO

4B

BEQ

$FB3A

FAEF

A2

3D

LDX

#$3D

FAF1

E4

9E

CPX

$9E

FAF3

90

3E

BCC

$FB33

FAF5

A6

9E

LDX

$9E

FAF7

A5

AD

LDA

$AD

FAF9

9D

01

FAFC

A5

AC
00

FAFE

9D
E8

error

DEX

FADB

FBO1

"SHORT BLOCK"
status

set

01
01

STA

$0101,X

LDA

$AC

STA

$O1OO,X

INX\

FB02

E8

FB03

86

9E

FB05

4C

3A

FB08

A6

FBOA

INX

STX

$9E

JMP

$FB3A

9F

LDX

$9F

E4

9E

CPX

$9E

FBOC

FO

35

BEQ

$FB43

FBOE

A5

AC

LDA

$AC

FB1O

DD

00

CMP

$0100,X

FB13

DO

2E

BNE

$FB43

FB15

A5

AD

LDA

$AD

FB

Ol

error-correction

A-137

at

FB17

DD

Ol

CMP

$O1O1,X

FB1A

DO

27

BNE

$FB43

FB1C

E6

9F

INC

$9F

FB1E

E6

9F

INC

$9F

FB20

A5

93

LDA

$93

FB22

FO

OB

BEQ

$FB2F

FB24

A5

BD

LDA

$BD

FB26

AO

00

LDY

#$00

FB28

Dl

AC

CMP

<$AC),Y

FB2A

FO

17

BEQ

$FB43

FB2C

C8

FB2D

84

B6

STY

$B6

FB2F

A5

B6

LDA

$B6

FB31

FO

O7

BEQ

$FB3A

FB33

A9

10

LDA

#$10

"SECOND

FB35

2O

1C

JSR

$FE1C

set

FB38
FB3A

DO

09

BNE

$FB43

A5

93

LDA

$93

veri-fy?

FB3C

DO

05

BNE

$FB43

yes

FB3E

A8

FB3F

A5

BD

LDA

$BD

read

FB41

91

AC

STA

FB43

20

DB

FB46

DO

43

FB4B

A9 BO

FB4A

85

FB4C

78

FB4D

A2

01

LDX

#$01

FB4F

8E

OD

DC

STX

$DCOD

FB52

AE

OD

DC

LDX

$DCOD

FB55

A6

BE

LDX

$BE

FB57

CA

FB58

30

02

BMI

$FB5C

FB5A

86

BE

STX

$BE

FB5C

C6

A7

DEC

$A7

FB5E

FO

08

BEQ

$FB68

FB6O

A5

9E

LDA

$9E

FB62

DO

27

BNE

$FB8B

FB64

85

BE

STA

$BE

FB66

FO

23

BEQ

$FB8B

FB68

20

93

JSR

$FC93

FB6B

2O

8E rs

JSR $FBBE

FB6E

AO

OO

LDY

#$00

FB70

84

AB

STY

$AB

FB72

Bl

AC

LDA

FB74

45

AB

EDR

$AB

01

read

byte

compare with

memory

content

I NY

FE

PASS"

error

status

TAY

FC

<$AC),Y

JSR

$FCDB

BNE

$FB8B

byte

save

increment

address-pointer

LDA ftfBO
STA

AA

$AA

SEI

FC

decrement

pass-counter

DEX

($AC),\

one

pass

address

ended
back

program
start

calculate

program

addresspointer

FB76

85

AB

STA

$AB

FB78

20

DB

FC

JSR

$FCDB

increment

FB7B

20

Dl

FC

JSR

$FCD1

end-address

FB7E

90

F2

BCC

$FB72

no,

FB80

A5

AB

LDA

$AB

calculated

FB82

45

BD

EOR

$BD

compare

FB84

FO

05

BEQ

$FB8B

checksum

FB86

A9

20

LDA

#$20

"CHECK

FB88

20

1C

JSR

$FE1C

set

FE

to

A-138

reached

continue

yet?

comparison

checksum

with

tapes

ok?

SUM"

status

checksum

error

checksum

FB8B

4C BC FE JMP $FEBC

FB8E

A5 C2

LDA

FB90
FB92
FB94

85 AD

A5 Cl
85 AC

STA $AD
LDA $C1
STA $AC

FB96

6O

RTS

resum -From interrupt

$C2

*****************************

FB97

FB99

FB9B
FB9D
FB9F
FBA1
FBA3
FBA5

A9 08

85 A3

A9
85
85
85
85
60

00
A4
A8
9B
A9

Set

LDA #$08

STA $A3

LDA
STA
STA
STA
STA
RTS

bit-counter

-for

serial

out-put

8 bits

#$00
$A4
$A8
$9B
$A9

*****************************

Write

one

bit

on

tape

FBA6
FBA8
FBA9

A5 BD
4A
A9 60

LDA $BD
LSR
LDA #$60

bit in $BD
bit 0 in carry
time for "1" bit

FBAD

A9 BO

LDA #$B0

time for

FBB1
FBB4

8D 06 DC STA $DC06
8E 07 DC STX $DC07

FBBA

A9 19

AD OD DC LDA $DCOD

clear interrupt-flag

FBBC

8D OF DC STA $DCOF
A5 01

LDA $01

start timer

FBC1

49 08
85

01

EOR #$08
STA

$01

invert output bit for tape

FBC5
FBC7

29
60

08

AND
RTS

#$08

FBCB

38

FBC9

66

B6

ROR

$B6

FBCB

30 3G

BMI

$FC09

FBAB
FBAF

FBB7
FBBF
FBC3

90

A2

02

00

BCC
LDX

$FBAF

#$OO

timer B low
timer B high

LDA #$19

SEC

*****************************

FBCD

A5

FBCF
FBD1

DO

12

A9

10

A8

01

LDA

Write

interrupt

routine

$A8

BNE $FBE3
#$10

LDA

FBD3

A2

FBD5

20 Bl
DO

2F

FBDA

E6

A8

INC

$A8

FBDC

A5

B6

LDA

$B6

FBDE

10

29

BPL

$FC09

FBEO

4C 57 FC JMP $FC57

FBE3

A5

A9

LDA

$A9

FBE5

DO

09

BNE

$FBFO

FBE7

20 AD FB JSR $FBAD

FBEA

DO

ID

FBEC

E6

FBEE

DO

FBD8

"O"bit

LDX

#$01

FB JSR $FBB1
BNE

write cycle on tape

$FC09

BNE

$FC09

A9

INC

$A9

19

BNE

$FC09

write second block

write

A-139

"O"-bit

for

FBFO

2O

A6

JSR

$FBA6

FBF3

DO

14

BNE

$FC09

FBF5

A5 A4

LDA

$A4

FBF7

49

01

EOR

#$01

FBF9

85

A4

STA

$A4

FBFB

FO OF

BEQ

$FCOC

FBFD

A5

BD

LDA

$BD

FBFF

49

01

EOR

#$O1

FCO1

85 BD

STA

$BD

FC03

29

01

AND

#$01

FC05

45

9B

EOR

$9B

FC07

85

9B

STA

$9B

FC09

4C

BC

JMP

FCOC

46 BD

LSR

FCOE

C6 A3

DEC

FB

FE

$FEBC

return

-from

$BD

next

$A3

decrement

A5

A3

LDA

$A3

FO

3A

BEQ

$FC4E

10 F3
2O

FC19

58

97

FB

on

bit

FC1O
FC14

bit

invert

FC12
FC16

write

BPL

$FCO9

JSR

$FB97

bit

output

set

tape

for

output

interrupt

in

position

bit-counter

next

bit

bit-counter

back

to

CLI
LDA

$A5

FC1A

A5 A5

FC1C

FO

FC1E

A2

00

LDX

#$00

FC20

86

D7

STX

$D7

FC22

C6

A5

DEC

$A5

FC24

A6

BE

LDX

$BE

FC26

EO

02

CPX

#$O2

FC28

DO

02

BNE

$FC2C

FC2A

09

80

ORA

#$80

FC2C

85

BD

STA

$BD

FC2E

DO

D9

BNE

$FC09

FC30

20

Dl

JSR

$FCD1

FC33

90

OA

BCC

$FC3F

FC35

DO

91

BNE

$FBC8

FC37

E6

AD

INC

$AD

FC39

A5

D7

LDA

$D7

FC3B

85

BD

STA $BD

BEQ $FC30

12

FC

FC3D

BO

CA

BCS

$FC09

FC3F

AO

00

LDY

#$00

FC41

Bl

AC

LDA

FC43

85

BD

STA

$BD

FC45

45

D7

EOR

$D7

FC47

85

D7

STA

$D7

FC49

20

DB

JSR

$FCDB

FC4C

DO

BB

BNE

$FC09

FC4E

A5

9B

LDA

$9B

FC50

49

Ol

EOR

#$01

FC52

85

BD

FC54

4C

BC

FC57

C6

FC59

DO

FC

($AC),Y

endaddress

byte

to

increment

STA

$BD

JMP

$FEBC

BE

DEC

$BE

03

BNE

$FC5E

another

JSR

$FCCA

no,

LDA

#$50

FC5B

20

CA

FC5E

A9

50

FE

FC

be

return

A-140

yet?

written

address

-from

decrement

reached

pointer

interrupt

counter

-for

block?

tapedrive

off

blocks

FC60

85

A7

STA

*A7

FC62
FC64

A2 O8
78

LDX
SEI

#*08

FC65

20 BD

JSR

*FCBD

IRQ

FC68

DO

EA

FC

BNE

*FC54

return

FC6A

A9

78

LDA

#*78

on

$FC6A

-from

Write tape

FC6C

20

AF

FC6F

DO

E3

FB

JSR

*FBAF

BNE

$FC54

write

FC71

C6

A7

DEC

$A7

FC73

DO

DF

BNE

$FC54

return

FC75 .

20

97

JSR

*FB97

set

FC7B

C6

AB

DEC

SAB

FC7A

10

D8

BPL

$FC54

FC7C

A2

OA

LDX

#*0A

FC7E

20

BD

JSR

*FCBD

FC81

58

FC82
FC84

E6

AB

INC

$AB

A5

BE

LDA

*BE

FB

FC

bit

interrupt

interrupt
on

-from

routine

tape

interrupt

bit-counter

-For- serial
output

IRQ

on

*FBCD

set

address back

CLI

FC86

FO

30

FC88

20

8E

FC8B

A2

09

FB

BEQ

*FCB8

JSR

*FB8E

LDX

#*09

FC8D

86

A5

STX

*A5

FC8F

86

B6

STX

$B6

FC91

DO

83

BNE

*FC16

FC93

08

to

start

PHP

FC94

78

FC95

AD

11

FC9B

09

10

FC9A

8D

11

SEI
DO

LDA

*DOli

ORA

#*10

DO

STA

*D011

FC

JSR

*FCCA

LDA

#*7F

FC9D

20

CA

FCAO

A9

7F

FCA2

BD

OD

DC

STA

*DCOD

FCA5

20

DD

FD

JSR

*FDDD

FCA8

AD

AO

02

LDA

$02A0

FCAB

FO

09

BEQ

*FCB6

FCAD

8D

15

03

STA

$0315

FCBO

AD

9F

02

LDA

*029F

FCB3

8D

14

03

STA

*0314

FCB6

28

PLP

FCB7

60

RTS

FCB8

20

turn

screen

turn

o-f-f

CIA

back

IRQ

on

Set

93 FC

JSR

*FC93

FCBB

FO

97

BEQ

FCBD

BD

93

FD LDA

*FD93,X

FCCO

8D

14

03

STA

*0314

FCC3

BD

94

FD

LDA

$FD94,X

FCC6

8D

15 O3

STA

$0315

FCC9

60

FCCA

A5

01

LDA

$01

FCCC

09

20

ORA

#*20

FCCE

85

01

STA

*01

IRQ

IRQ

on

set

IRQ

back

tape

to

on

drive

standard

values

standard

vector

standard

*FC54
vector

-from

table

RTS

switch

A-141

off

tape

drive

FCDO

60

RTS

*****************************

Checks on reaching the end-

address

SEC

FCD1

38

FCD2

A5

AC

LDA $AC

FCD4

E5

AE

SBC

$AE

FCD6

A5

AD

LDA

$AD

FCD8

E5

AF

SBC

*AF

FCDA

60

current
end

E6 AC
DO O2
E6 AD
60

FCE2

A2 FF

LDX

FCE4

78

SEI

FCE5

9A

TXS

FCE7

20 02 FD JSR *FD02

FCEA

DO 03

6C 00 80 JMP

($8000)

FCEF

8E

*D016

FCF2
FCF5

20 A3 FD JSR *FDA3
20 50 FD JSR $FD50

FCF8

20

15 FD

FCFB

20

5B FF

FCFE

58

FCFF

checks on ROM in *8000

BNE *FCEF

16 DO STX

jump to module start

JSR $FD15
JSR
CLI

6C 00 AO JMP

$FF5B

<*A000>

FD02
FD04

A2 O5
LDX #*05
BD OF FD LDA $FDOF,X

FDOA

DO 03

BNE *FDOF

FDOC
FDOD

CA
DO F5

DEX
BNE $FDO4

FDOF

60

RTS

to BASIC cold-start
Checks on ROM in $8000

DD 03 80 CMP $8003, X

compares to

*****************************

FD10

RESET

#*FF

*****************************

FD07

Increment address pointer

INC *AC
BNE $FCE1
INC *AD
RTS

*****************************

FCEC

address *AE/*AF

RTS

*****************************
FCDB
FCDD
FCDF
FCE1

address *AC/*AD

ROM

C3 C2 CD 38 30

A2 3O

LDX #$30

FD17

AO FD

LDY

FD19

18

CLC

FD1A

86

C3

STX

*C3

FD1C

84

C4

STY

$C4

FD1E
FD20

AO
B9

IF
LDY #*1F
14 03 LDA $0314,Y

FD23

BO O2

BCS *FD27

FD25
FD27

Bl
91

LDA
STA

C3
C3

identivication

"CBM8O"

*****************************

FD15

module

"CBM8011

Set/get

hardware

and

I/O

vectors

#$FD

pointer

c=l

(*C3),Y
<*C3>,Y

A-142

to table $FD30

then get vectors,

C=I

FD29

99

FD2C

88

FD2D

10

FD2F

60

FD30
FD38
FD4O
FD48

31
91
57
2F

14

03

STA

$O314,Y

DEY
Fl

BPL

$FD2O

RTS

EA
F2
Fl
F3

66
OE
CA
66

FE
F2
Fl
FE

47
50
ED
A5

FE
F2
F6
F4

4A
33
3E
ED

Table hardware &

F3
F3
Fl
F5

*****************************
FD50

A9

00

LDA

Initialize work

FD52

A8
99

02

00

STA

$0002 ,Y

FD56

zero

99

00

02

STA

$0200 ,Y

FD59

clear

99

00

03

STA

$0300 ,Y

and

TAY

FD5C

C8

FD5D

DO

F4

BNE

FD5F

A2

3C

LDX

#$3C

FD61

AO

03

LDY

#$03

FD63

86

B2

STX

$B2

FD65

B4

B3

STY

$B3

03

LDA J*$03

FD67

A8
A9

memory

#$00

FD53

FD6B

I/O vectors

page

page

page

3.

I NY
$FD53

tape-buffer pointer

on$033C

TAY

FD6A

85

C2

STA

$C2

FD6C

E6

C2

INC

$C2

Cl

LDA

FD6E

Bl

FD70

AA

FD71

A9

55

LDA

FD73

91

Cl

STA

check

RAM from $400

<$C1> ,Y

TAX

FD75

Dl

Cl

CMP

FD77

DO

OF

BNE

FD79

2A

FD7A

91

Gl

STA

FD7C

Dl

Cl

CMP

FD7E

DO

08

BNE

FD8O

8A

FD81

91

Cl

STA

FD83

C8

#$55

7.01010101

<$C1> ,Y
<$C1) ,Y
$FDB8

ROL

7.10101010
<$C1) ,Y

<$C1) ,Y
$FD88

TXA
($Ci> ,Y

I NY

FD84

DO

E8

BNE

$FD6E

FD86

FO

E4

BEQ

$FD6C

FD88

98

TYA

FD89

AA

FD8A

A4

FD8C

13

FD8D

20

2D

FD90

A9

08

FD92

8D

82

FD95

A9

04

FD97

8D

88

FD9A

60

FD9B

6A

TAX
C2

LDY

$C2

CLC
FE

02
02

JSR

$FE2D

LDA

#$O8

STA

$0282

LDA

#$04

STA

$0288

set

memory

BASIC

(RAM)

start

Video-RAM

on

on

top

$800

$400

RTS

IRQ

FC

CD

FB

31

EA

2C

F9

A-143

vectors

$FC6A,

$FBCD,

$EA31,

$F92C

(CIA1)

FDA3

A9

7F

LDA

#$7F

FDA5

8D

OD

DC

STA

$DCOD

FDA8

8D

OD

DD

STA

$DDOD

FDAB

8D

OO

DC

STA

$DCOO

FDAE

A9

O8

LDA

#$08

FDBO

8D

OE

DC

STA

$DCOE

FDB3

8D

OE

DD

STA

$DDOE

FDB6

8D

OF

DC

STA

$DCOF

FDB9

8D

OF

DD

STA

$DDOF

control
control
control
control

FDBC

A2

OO

LDX

#$00

entrance mode

FDBE

8E

03

DC

STX

$DC03

FDC1

8E

03

DD

STX

$DD03

data direction register B 1


data direction register B 2

FDC4

8E

18

D4

STX

$D41B

volume

FDC7

GA

FDCB

8E

O2

FDCB

A9

07

FDCD

8D

00

FDDO

A9

3F

FDD2

8D

02

FDD5

A9

E7

FDD7

85

Ol

STA $01

FDD9

A9

2F

LDA

#$2F

FDDB

85

00

STA

$00

FDDD

AD

A6

LDA

$02A6

FDEO

FO

OA

BEQ

$FDEC

FDE2

A9

25

LDA

#$25

FDE4

8D

04

STA

$DC04

FDE7

A9

4O

LDA

#$40

FDE9

4C

F3

JMP

$FDF3

FDEC

A9

95

LDA

#$95

FDEE

8D

O4

STA

$DC04

FDF1

A9

42

LDA

#$42

FDF3

8D

O5

DC

STA

$DC05

FDF6

4C

6E

FF

JMP

$FF6E

interrupt

DD
DD

02

DC

FD
DC

$DC02

LDA

#$07

85

register
register
register
register

-for

STA

$DDOO

LDA

#$3F

STA

$DD02

LDA

#$E7

CIA2

SID

A
A
B
B

on

CIA 1
CIA 2
CIA 1
CIA 2

zero

mode

data direction register


port

A CIA

Set

parameter

B7

STA

$B7

length

FDFB

86

BB

STX

$BB

address

low

FDFD

84

BC

STY

$BC

address

high

FDFF

60

-For

A 2

-filename

RTS

*****************************

Set

active

FEOO

85 B8

STA

$B8

logical

FE02

86

BA

STX

$BA

device

FE04

84

B9

STY

$B9

secondary

FE06

60

files

-file

parameter

number

address

address

RTS

*****************************

FE07
FE09
FEOB

A5 BA
C9 02
DO OD

LDA $BA
CMP #$02
BNE $FE1A

FEOD
FE10

AD 97
48

O2 LDA $0297
PHA

FE11
FE13

A9 OO
LDA #$OO
BD 97 02 STA $0297

FE16

68

Get

status

device
equal

number
??

no

get

RS-232

clear

PLA

A-144

data direction register

*****************************

FDF9

A CIA

out-put

STX

register
11

port

DEX

DC

control

status

status

FE17

60

RTS

*****************************

FEiS

85 9D

STA $9D

*****************************

FEiA

A5 90

LDA $90

*****************************

FE1C

05 90

ORA $90

FE1E
FE20

85
60

STA $90
RTS

90

*****************************

FE21

FE24

8D 85 02 STA $0285

60

FE25

90

FE27
FE2A

AE 83 02 LDX $0283
AC 84 02 LDY $0284

FE2D

8E

83

02 STX

$0283

FE30

BC
60

84

02

$0284

06

BCC

STY

$FE2D

90

06

BCC

$FE3C

FE36

AE

81

02

LDX

$0281

FE39

AC

82

02

LDY

$0282

FE3C

8E

81

O2

STX

$0281

FE3F

8C

82

02

STY

$0282

FE42

60

6C

Set

time-out -flag for

MEMTOP get/set

get

end o-f

is

I EC

BASIC-

set

address to

carry

set

X/Y

clear

X/Y to address

MEMBOT get/set

bottom of
BASIC-RAM

s.a.

t**-i************#

78

48

status

RTS

***** ***4

FE44

Set

RAM

RTS

FE34

FE47

status

carry

*****************************

FE43

Get

RTS

*****************************

FE33

Set operatingsystem messages

NMI-interrupt

SEI

18

03

JMP

($0318)

JMP

$FE47

PHA

FE48

8A

TXA

FE49

48

PHA

FE4A

98

TYA

save

register

FE4B

48

FE4C

A9

7F

FE4E

8D

OD

FE51

AC

OD

FE54

30

1C

FE56

20

02

FE59

DO

03

FE5B

6C

02

80

JMP

FE5E

20

BC

F6

JSR

FF

JSR

$FFE1

scan

$FE72
$FD15

not

pressed

set

standard

PHA
LDA

#$7F

DD

STA

$DDOD

DD

LDY

$DDOD

BMI

$FE72

RS-232

active

JSR

$FD02

checks

on

BNE

$FE5E

no,

FD

($8002)

yes,

$F6BC

FE61

20

El

FE64

DO

OC

FE6&

20

15

FD

BNE
JSR

FE69

20

A3

FD

JSR

$FDA3

FE6C

20

18

E5

JSR

$E518

then

set

jump

-flag

in

$8000

to

for

stop

module-NMI

STOP-key

key

I/O

vectors

initialize

I/O

initialize

I/O&clear

to

A-145

ROM

continue

BASIC

warm-start

screen

i02

AO

<$AOO2>

JMP

FE6F

6C

FE72

98

FE73

2D

FE76

AA

FE77

29

01

AND

#$01

FE79

FO

28

BEQ

$FEA3

FE7B

AD

OO

LDA

$DDOO

FE7E

29

FB

FE80
FE82

05 B5
8D 00

DD

STA

$DDOO

FE85

AD

Al

02

LDA

$02A1

FE88

8D

OD

DD

STA

$DDOD

FE8B

8A

FE8C

29

12

AND

#$12

FE8E

FO OD

BEQ

$FE9D

FE90

29

O2

AND

#$02

FE92

FO 06

BEQ

$FE9A

FE94

20 D6

FE

JSR $FED6

FE97

4C

9D

FE

JMP

$FE9D

FE9A

2O

O7

FF

JSR

FE9D

20

BB

EE

JSR

FEAO

4C

B6

FE

JMP

FEA3

8A

FEA4

29

02

AND

FEA6

FO

06

BEQ $FEAE

TYA

Al

O2

AND

$O2A1

TAX

DD

AND #$FB
ORA $B5

TXA

RS-232

in

$FF07

RS-232

out

$EEBB

RS-232

output

$FEB6

return

from

interrupt

RS-232
return

in
-From

interrupt

RS-232

out

TXA
#$O2

FEAB

20 D6 FE JSR $FED6
4C B6 FE JMP $FEB6

FEAE

8A

FEAF

29

10

AND

#$1O

FEB1

FO

03

BEQ

$FEB6

FEB3

20

07

FF

JSR

$FF07

FEB6

AD Al

02

LDA

$O2A1

FEB9

8D OD DD STA $DDOD

FEA8

TXA

FEBC

68

PLA

FEBD

A8

TAY

FEBE

68

PLA

FEBF

AA

TAX

FECO

68

PLA

FEC1

40

RTI

get

*********************************

back

Baud-rate

register

timer

iconstants
50 baud

27

$27C1

29377

3A

1A

$1A3A

6718

75

baud

C5

11

$11C5

4549

110

baud

FEC8

74

OE

$OE74

3700

134.5

baud

FECA

ED

OC

$OCED

3309

150

baud

FECC

45

O6

$0645

1605

300

baud

FECE

FO

02

$O2FO

752

600

baud

FEDO

46

01

$0146

326

1200

b aud

FED2

B8

OO

$00B8

184

1800

baud

FED4

71

00

$0071

113

2400

baud

FED6

AD

01

FED9

29

01

AND

#$01

FEDB

85

A7

STA

$A7

FEC2

Cl

FEC4

FEC6

NMI-routine

DD

LDA $DD01

A-146

tor

RS-232

input

FEDD

AD

06

FEEO

E9

1C

DD

LDA

$DD06

SBC

#$1C

FEE2

6D

99

O2

ADC

$0299

FEES

8D

06

DD

STA

3DDO6

FEE8

AD

07

DD

LDA

$DDO7

FEES

6D

9A

O2

ADC

$029A

FEEE

8D

07

DD

STA

$DD07

FEF1

A9

11

FEF3

8D

OF

LDA

#$11

DD

STA

$DDOF

FEF6

AD

Al

02

LDA

$O2A1

FEF9

8D

OD

DD

STA

$DDOD

FEFC
FEFE

A9
8D

FF
06

DD

LDA
STA

#$FF
$DDO6

FFO1

8D

07

DD

STA

$DD07

FF04

4C

59

EF

JMP

$EF59

RS-232 timer baud constants

*****************************

FF07

AD

95

FFOA

02

8D

06

DD

FFOD

AD

96

02

FF1O

8D

07

DD

FF13

A9

11

FF15

8D

OF

FF1S

A9

12

FFiA

4D

Al

FF1D

8D

Al

DD

LDA

$0295
STA $DD06
LDA $0296
STA $DD07
LDA #$11
STA

$DDOF

LDA

#$12

02

EOR

$02 A1

02

STA $O2A1

FF20

A9

FF

FF22

8D

06

DD

FF25

STA

8D

$DD06

07

DD

STA

*DD07

02

LDA

RS-232 timer baud constants

#$FF

FF28

AE

98

FF2B

86

A8

FF2D

60

FF2E

FF2F
FF32
FF33

AA
TAX
AD 96 02 LDA $0296
2A
ROL
A8
TAY

FF34

8A

FF35

69

C8

FF37

8D

99

LDX

*0298

STX

$A3

number

o-f

bits to be sent

RS-232

timing

RTS

TXA

FF3A

98

FF3B

69

00

FF3D

8D
60

9A

FF40

NMI-routine -For RS232 output

ADC #*C8
02

STA $0299
TYA

ADC #$00

02 STA $029A
RTS

FF41

EA

NOP

FF42

EA

NOP

*********************
08
PHP

Interrupt -from tape-routine

FF43

FF44

68

FF45

29 EF

FF47

48

PLA

AND #$EF

clear break-flag

PHA

*****************************

A-147

IRQ-interrupt

FF48

48

PHA

FF49

8A

TXA

FF4A

48

PHA

FF4B

98

TYA

FF4C

48

PHA

FF4D

BA

FF4E

BD

O4

FF51

29

1O

FF53

FO

O3

FF55

6C

16

03

JMP

($0316)

FF58

6C

14

O3

JMP

($0314)

save

TSX

Ol

LDA

$O1O4,X

AND

#$10

BEQ

$FF5B

***************<***************

FF5B

20

18

E5

JSR

$E518

FF5E

AD

12

DO

LDA

$D012

FF61

DO

FB

BNE

$FF5E

FF63

AD

19

LDA

$D019

FF66

29

01

AND

#$01

FF68

8D

A6

02

STA

$02A6

FF6B

4C

DD

FD

JMP

$FDDD

DO

register

get

breakflag

anc

check

not

set

-from

stack

BREAK-routine

interrupt-routine

initialize

video-controller

*****************************

FF6E

A9

FF70

8D OD DC STA $DCOD

81

LDA

#$81

FF73

AD

OE DC LDA

$DCOE

FF76

29

80

AND

#$80

FF78

09

11

ORA

#$11

FF7A

8D

OE

DC

STA

$DCOE

FF7D

4C

8E

EE

JMP

$EE8E

FF80

OO

BRK

*****************************

5B

FF

Jump-table

-for

operating-

system

FF81

4C

JMP

$FF5B

FF84

4C A3 FD JMP

$FDA3

FF87
FF8A

4C 50 FD JMP $FD50
4C 15 FD JMP $FD15

FF8D

4C

1A FD JMP

$FD1A

FF9O

4C

18 FE

JMP

$FE18

FF93

4C B9 ED JMP

$EDB9

FF96

4C C7 ED

JMP $EDC7

FF99

4C

25 FE

JMP

$FE25

FF9C

4C

34 FE

JMP

$FE34

FF9F
FFA2
FFA5

4C 87 EA JMP $EA87
4C 21 FE JMP $FE21
4C 13 EE JMP $EE13

scan

FFA8

4C

DD ED

JMP

$EDDD

output

FFAB

4C

EF

ED

JMP

$EDEF

send

UNTALK

FFAE

4C

FE

ED

JMP

$EDFE

send

UNLISTEN

FFB1

4C

OC

ED

JMP

$EDOC

send

LISTEN

FFB4

4C

09

ED

JMP

$ED09

send

FFB7

4C

07

FE

JMP

$FE07

get.

FFBA
FFBD

4C
4C

00
F9

FE
FD

JMP
JMP

$FEOO
$FDF9

set

-file

set

filename

FFCO

6C

1A

03

JMP

($031A)

$F34A

OPEN

FFC3

6C

iC

O3

JMP

($0310

$F291

CLOSE

initialize

clear

or

check

initialize

I/O

initialize

I/O

set

RAM
vectors

status

send

LISTEN

send

TALK

secondary

secondary

set/get

RAM-end

set/get

RAM-start

set

adrs.

address

keyboard

I EC-bus

input

A-148

routines

CIAs

-from
to

time-out

-flag

I EC-bus,
IEC-bus

TALK
status

parameterparameter

FFC6

6C

IE

O3

JMP

<*O31E)

*F20E

CHKIN

set

input

FFC9

6C

20

03

JMP

<*O32O>

*F250

CKOUT

set

output

FFCC

6C

22

O3

JMP

($0322)

*F333

CLRCH

FFCF

6C

24

03

JMP

($0324)

$F157

BASIN

FFD2

6C

26

0.3 JMP

<*0326>

$F1CA BSOUT

FFD5

4C

9E

F4

JMP

FFD8

4C

DD

F5

FFDB

4C

E4

F6

FFDE

4C

DD

FFE1

6C

FFE4

*F49E

LOAD

JMP

$F5DD

SAVE

JMP

$F6E4

set

time

F6

JMP

*F6DD

get

time

28

03

JMP

($0328)

$F6ED

scan

6C

2A

O3

JMP

<*032A>

*F13E

GET

FFE7

6C

2C

O3

JMP

<*O32C>

$F32F

CLALL

FFEA

4C

9B F6

JMP

*F69B

increase

FFED

4C

05

E5

JMP

SE505

SCREEN

FFFO

4C

OA

E5

JMP

*E50A

set/get

FFF3

4C

OO

E5

JMP

*E500

get

FFF6

52

52

42

59

*****************************

character

output

character

STOP-key

lines

cursor
of

43

FE

*FE43

NMIvector

FFFC

E2

FC

*FCE2

RESET-vector

FFFE

48

FF

$FF48

IRQ-vector

&

columns

position

I/O

vectors

FFFA

A-149

device

time

get

start

Hardware

input

device

element

APPENDIX

A Short Introduction to Hexadecimal Arithmetic

Computers represent data in binary format. In the


number system, a digit may take on a value of either
Each digit position in the binary number system has
that is a power of 2, just as each digit position
decimal number system has a value that is a power of
BINARY

NUMBER

Power of
Value

SYSTEM

7
128

DECIMAL NUMBER
Power

of

binary
0 or 1.
a value
in the
10.

10

5
32

4
16

SYSTEM
5
100000

Value

6
64

4
10000

3
1000

100

10

If you want to represent the decimal number 17 in the binary


number system, you would use the string of binary diqits
10001 which

stands

for:

1 X 24 + 0 X 23
16

0 X

0 X 21 + 1X2

2"

17

Representing

called

numbers

"bits")

Decimal

would

as a string of binary digits

look as

shown:

Binary

(commonly

Decimal

Binary

13

1101

10

14
15
16

1110
1111

11

4
5

8
9

100
101
110
111
1000
1001

10

1010

11

1011
1100

12

Eight bits

(remember -

17

18
19
20
21
22

23
24
25

binary digits)

10111

11000
11001

is called a byte.

byte is the smallest accessible unit of data


Commodore 64. Eight bits is capable of representing
equivalent to decimal 255.

B-l

10000
10001
10010
10011
10100
10101
10110

in the
a value

A string of eight bits however, is not very easy to read or


write. Because they are awkward to interpret, bits are often
represented in the hexadecimal numbering system (base 16).
Each hexadecimal digits stands for four bits.
Hexadecimal notation uses 16 symbols to represent the 16
different values. These symbols are the numerals 0 thru 9
and the letter A thru F.

Below is an equivalency chart:


HEXADECIMAL

BINARY

:imal

1
10

1
2

2
3
4

11
100

5
6
7
8

101
110
111
1000

5
6
7
8

1001
1010

9
A

1011
1100
1101
1110

1111

10
11
12

13
14
15

3
4

C
D
E

To convert binary numbers to hexadecimal notation, divide


the binary number into groups of four bits, starting at the
right hand side. Replace each group of four bits by the
corresponding hexadecimal symbol. If the left most group of
bits is not a full four bits, then fill in with zeros. The
example below illustrates

this:

101001101011010110
0010/1001/1010/1101/0110
2

B-2

=
=

(binary number)
(4-bit groups)
(hexadecimal

number)

APPENDIX C

Summary of

What

are

the

computers

features

don't

the

of

offer?

Commodore

the

What

64

Commodore

makes

its

64

that

other

capabilities

so

different from the others? .We'll attempt to summarize at


this

time.

The Commodore 64 is far from being a game only machine.


It
has ambitions that are far beyond those computers that offer
colorf graphics, and sound.
It can be a computer for
commercial use as well.
With its graphics capabilities, you
can get results that were formerly available only on much

larger and more expensive computers. Yet even the micros of


today will have a hard time competing against the Commodore.
Through the use of BASIC 2, it is suitable for most
applications.
The beginner will be able to use it just as
well as the experienced programmer.
Since it can be
programmed in assembler, there are excellent possibilities
for expansion with the several assemblers already on the

market.

Besides BASIC and assembler,

there are other languages such

as PILOT, PASCAL, LOGO, and FORTH currently available.

In

addition, a Z-80 card is available that makes it possible to

use the CP/M operating system.


CP/M is the world's most
popular an operating system and opens a new level of
programming and software applications to the Commodore 64
user..
This Z^80 card, for which the Commodore 64 already
has a built-in slot, contains, as its name already implies,
a Z-80 processor.
It was to complement this processor that
the 6510

was developed.

In addition to this card, there are 80-column cards which


enable the Commodore 64 to display 80 character lines.
This
card

is

very useful

Obviously you

for word processing.

won't

be

left

without

support

for

your

Commodore 64.
Every day there are new developments.
Others
receently announced include graphics tablets, sketch pads
such as the KOALA Pad, and voice synthesizers.
Software
support is also rapidly expanding to fill the void felt

earlier.

Since

the

Commodore

64

has

the

ability

to

use

other

Commodore machine's software, you have a wide variety of


software available.
Considering its capabilities,
the
Commodore 64 is superior to other CBM/PET computers and the
VIC-20 while being one of the least expensive on the market.
BASIC

for

the

Commodore

64

is,

C-l

as

mentioned

before,

BASIC

2.

This
BASIC
is
a version developed by Microsoft for
Commodore.
It is not only very capable, but also very easy

to learn.

The professional will like the first point? the

beginner will

appreciate

the

second.

There are some advantages to Commodore BASIC compared to


other versions.
For one thing, editing programs is very
fast and efficient.
In order to change a line, you simply
move

the

cursor

to

the

proper

line,

clear

characters

or

whole words, insert new text if needed, and move to the next
line by pressing RETURN.
On pressing RETURN, the Commodore

64 determines if there is a program-line in the next line.


If there is, BASIC automatically places the cursor at the
beginning of the line.
In a like manner you may go through
your entire program making necessary changes.
When editing
is completed, press the CLR key clearing the screen and
returning

the cursor to

HOME position.

This screen-oriented editor offers yet another advantage.


After an error in direct mode input which is refused by a
SYNTAX ERROR message, it is possible to bring the cursor
back to this line, correct it, and then RETURN.
This saves
a

considerable

amount

of

retyping.

The third time the editor is useful is

in loading programs

from diskette.
You move the cursor to the line containing
the chosen program title (you must have called the index

previously, of course, using LOAD"$",8), type LOAD over the


number indicating blocks used, cursor to the end of the
title and type ',8:'. On RETURN,
the program is loaded.
This

procedure

eliminates

the

possibility

errors common with mistyped titles,


excessive

of

FILE

NOT

FOUND

and again you are spared

typing.

Another advantage of
the
64 is the option of using
abbreviations for commands and statements.
On the 64, a
command may normally be given by typing the first letter of
the word followed by a shifted second letter and pressing
RETURN.
For example, ILI followed by SHIFT'I' is the
replacement

for

LIST.

There are,
of course,
differences between the various
versions of BASIC.
In order to use programs that run on
other computers, you must know these differences.
One of
the first is in clearing the screen.
In every system, this
command is different.
In some it's called HOME, in others
it's CLS, and some use CHR$.
The 64 has two options.
The first is the input of a control character, CHR$(147).
This control character issues the command to clear the
screen.
The other possibility is to insert a CLR command

within a print instruction.


On the screen you will see an
inverse heart.
This command has the same effect as the
CHR$(147).
It is used more often in Commodore listings.

C-2

Another difference is in the output of inverse text.


There
are systems that use an INVERSE/NORMAL command routine.
Again,
the 64 has two options.
The first is to use
CHR$(18);
the second is to place RVS-ON in a print
statement.

CHR$(146)

or

To

return

including

other machines,

to

normal,

RVS-OFF

in

the

command

print

is

either

statement.

On

it may be the use of the command NORMAL.

Naturally other systems have an extended BASIC as well.


There are, for instance, commands for a formatted number
output (PRINT USING) or automatic error branching (ON ERROR
or GOSUB).
As you have found out while reading this book,

it

is not difficult

Following

is

to develop

these

routines

yourself.

a list of commands used by the Commodore 64:


CONT

RUN

LIST

SAVE

LOAD

VERIFY

NEW

and

4- o
statements:
ts:

CLOSE

GOSUB

CLR

GOTO

CMD

IF..THEN

READ

DATA

INPUT

REM

DEF

FN

DIM

PRINT

or GO

TO

PRINT*

INPUT#

RESTORE

LET

RETURN

END

NEXT

STOP

FOR..TO. .STEP

ON

SYS

GET

OPEN

WAIT

GET#

POKE

Besides these, BASIC offers a great number of efficient


mathematical functions,
and it also contains string
functions that allow convenient working with text.

C-3

APPENDIX D -

Fisher,
BUS.

E.

Berkeley,

and
CA:

Jensen,

Bibliography

CW.

PET

Osborne/McGraw-Hill,

Leventhal, Lance and


SUBROUTINES. Berkeley,

AND

THE

IEEE

488

1980.

Saville, W. 6502 ASSEMBLY LANGUAGE


CA: Osborne/McGraw-Hill, 1982.

Leventhal,
Lance.
6502
ASSEMBLY
LANGUAGE
Berkeley, CA: Osborne/McGraw-Hill, 1979.

PROGRAMMING.

Osborne, A.;
Strasma,
J.;
and Strasma,
E. PET
COMPUTER GUIDE. Berkeley, CA: Osborne/McGraw-Hill,
West,
Level

Raeto Collin. PROGRAMMING


Limited, 1982.

Zaks,
1979.

Rodney.

THE

6502 APPLICATIONS

D-l

PET/CBM.

PERSONAL
1982.

Greensboro,

BOOK. Berkeley,

CA:

NC:

Sybex,

OTHER

BOOKS

AVAILABLE:

The Anatomy of the Commodore 64 - is our insider's guide to


your favorite computer. This book is a must for those of you
who want to delve deep into your micro. This 300+ page book
is full of information covering all aspects of the '64.
Includes

fully

commented

listing

of

the

ROMs

so

you

can

investigate the mysteries of the BASIC interpreter,


kernal and operating system. It offers numerous examples of
machine language programming and several samples that make
your programming sessions more enjoyable and useful.

ISBN# 0-916439-00-3

Available now:

$19.95

The Anatomy of the 1541 Disk Drive - unravels

the

mysteries

of working the the Commodore 1541 disk drive. This 320+ page
book starts by explaining program, sequential and relative
files.
It covers the direct access commands,
diskette
structure, DOS operation and utilties. The fully commented
ROM listings are presented for the real "hackers". Includes
listings for several useful utilities including BACKUP,
COPY, FILE PROTECTOR, DIRECTORY. This is the authoritive
source

ISBN#

for

1541 disk drive

0-916439-01-1

information.

Available

now:

$19.95

The Machine Language Book of the Commodore 64 - is

aimed

at

the Commodore 64 owner who wants to progress beyond BASIC.


If you want to write programs that run faster, use less
memory or perform functions not available in BASIC, then
this book will help you learn machine language. Included are
listings for three full length programs:
a working
assembler so you can create your own machine language
program; a disassembler so you can inspect other machine
language programs; and a 6510 simulator so that you can
"see"

the

operation

of

the

processor.

ISBN# 0-916439-02-X
Available
Optional program diskette:

Tricks & Tips

now:

$14.95
$14.95

for the Commodore 64 - presents

collection

of easy-to-use programming techniques and hints. Chapters


cover advanced graphics, easy data entry, enhancements for
advanced BASIC, CP/M, connecting to the outside world and
more. Other tips include sorting, variable dumps, and POKEs
that do tricks. All-in-all a solid set of useful features.
ISBN#

0-916439-03-8

OTHER TITLES

COMING

Available June

SOON!!!

29th

$19.95