Dragon 32 Programmers Reference Guide (John Vander Reyden)
Dragon 32 Programmers Reference Guide (John Vander Reyden)
programmer's
reference guide
DRA&ON32
-,,ragrammer•s
reference g11ide
All rights reserved. This book is copyright. No part of this book may be
copied or stored by any means whatsoever whether mechanical or
electronic, except for private or study use as defined in the Copyright Act.
All enquiries should be addressed to the publishers
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 1
What's included ..... ..... ................. 1
How to use this guide .......................... ... 2
Chapter 1
BASIC ...................................... ......... 3
Constants .................. ............ .3
Variables .4
Arrays ... ............. .. 4
Conversion ........... .. 5
Lines ................................. . 7
BASIC Commands ...................................... 7
BASIC Functions ....................... 28
Errors in BASIC ........................ 35
Chapter 2
GRAPHICS .. ....... .. ............. 36
Pixels and Resolution .... 37
Modes ............. 37
Video Memory ... ................ 39
Lo Resolution Graphics .............•................. 42
CLS ... .. ...... ............................ 43
SET/RESET ....... ....................... 43
Graphics using STRINGs ........................... 43
Hi Resolution Graphics ...... ...................... 46
Initialising commands .............................. 46
Producing Graphics ..... .................... 48
Assembler/Machine Code Graphics .................... 54
Graphics Modes .......•................. 55
Chapter 3
SOUND .... ............. 70
Example programs ..... ................... 72
Chapter 4
MACHINE CODE ... 81
What is Machine Code .. ...................... 81
The CPU ..................................... . 82
Registers .. 84
Addressing Modes ................... 85
Using M/C programs on the DRAGON ...... 90
Handy ROM Routines ...... ........................ 93
Handy Memory Locations .•.•...... . ... 96
Now BASIC Stores Variables ... 97
String Stack ....... 98
How Numerics are stored in the Variable Block ......... 98
How to access BASIC variables from
Machine Language programs .. .. 99
Chapter5
PERIPHERALS ...................................... 1 07
Joysticks ....... ...... .... 1 01
Printer ........................................ 1 01
Cassette ....................... ........ 1 02
Monitor/TV ...................................... 1 02
Edge Connector ................................ 1 03
Chapters
HANDY ROUTINES and TIPS .......................... 104
Speeding things up ............................... 1 04
Disable/Enable break key ......................... 1 05
Auto Key Repeat .. .. ... 106
Reading Two Keys at Once ... 107
Recovering a Program after a NEW command ... 1 07
Merge .. .... 1 08
Redefining BASIC Keywords ............... ... 109
Page Swapping ........... .. 109
Various Circles .•.............................. 1 1 0
Lines .. ................................ 1 1 2
Scrolls .......................................... 1 1 2
Appendix A
Basic Keywords .. 120
Basic Symbols .. 122
Appendix B
Error Messages .... 123
AppendixC
Memory Map .. 125
AppendixD
Colour Codes .. 126
Colour-set Table ...... 127
AppendixE
Character Codes (CHA$ & ASC) . 128
AppendixF
Print@GRID . 129
AppendixG
ASCII Codes ..... .... 130
Appendix H
Character Codes (PEEK & POKE) 132
Appendix I
Base Conversions ..... 133
AppendixJ
6809 Instruction Set .... 137
INTRODUCTION
This book has been developed as a reference source for people like you,
who want to get the most out their DRAGON. It contains the information
you need for your programs, from the simplest exercises right though to
complex business or game applications. The DRAGON
PROGRAMMERS GUIDE is designed so that everyone from the
beginning BASIC programmer to the professional experienced 6809
machine language programmer can get information to develop their own
creative programs. At the same time this book shows you just what your
DRAGON can do.
WHAT'S INCLUDED?
• Complete "BASIC dictionary" includes the DRAGON BASIC
language commands, statements and functions, a detailed description of
each word and examples on how to use it, even the average time it takes
to execute each one, useful for "time critical" game programs.
• An introduction to machine code programming and how to use
machine code programs from BASIC.
• A complete listing of the 6809 instruction set.
• The peripherals chapter (Chapter 5) shows how the DRAGON can
communicate with the outside world via its ports.
• Useful routines and memory locations you can access from both
BASIC and machine code
• BASIC and machine code routines for you to type in yourself which will
make your program even more powerful and user friendly.
HOW TO USE THIS GUIDE
Throughout this manual certain conventional notations are used to
describe the syntax (programming sentence structure) of BASIC
commands to show both the recuired and the optional parts for each
keyword. The rules to use for interpreting statments' syntax are as
follows:
• BASIC keywords are shown in capital letters. They must appear
where shown in the statement, entered and spelled exactly as shown.
• Parameter names are shown enclosed in square brackets ( [ ] ) and
these must be substituted with values. These can be either a single
constant, a single variable name or any complex expression unless
otherwise stated.
• TIME - Most commands have a time quoted for them at the end of their
description. This is the approximate average time that the command
takes to run, measured in seconds. It is included to enable comparison of
different ways of performing a certain routine when programming time
critical programs.
2
CHAPTER 1
BASIC
This chapter is a reference guide to the DRAGON 32's BASIC. If you are
new to programming then I suggest that you use a book like THE
COMPLETE DRAGON BASIC COURSE which is written for people who
don't have a lot of BASIC programming experience. If you are a
competent programmer but have not used BASIC before, this chapter is
probably sufficient to teach you the basics of the BASIC language.
CONSTANTS
DRAGON BASIC has two fundamental types of constants; string and
numeric.
b) HEXIDECIMAL
These can contain the digits O through to 9, A through to F and a sign ( +
or-), where:
A represents 1 0
B represents 11
C represents 12
3
D represents 13
E represents 14
F represents 15
"&H" is placed at the start of the number to indicate that it is in
hexadecimal format. If a sign is specified then it must come before "&H".
Example:
&H1A00, -&H1A0F
c) OCTAL
These can contain 0 through to 7 and a sign ( + or - ). "&" or "& O" is
placed at the start of the number to indicate that it is an octal number. If a
sign is specified it must be placed at the very head of the number.
Example:
&0707, -&0707, & 147
VARIABLES
Again, the DRAGON has two types of variables, string and numeric, the
only difference being that all numeric variables are floating point. A
variable. need not be declared unless it is an array with more than 10
elements.
ARRAYS
An array is a group, or table of values with the same variable name.
Individual values (called elements) are referenced by subscript(s) of
numeric expressions. Multiple dimensioned arrays are available and the
number of subscripts must agree with the number of dimensions that the
array was declared with (see the DIM statement).
4
CONVERSION
When a constant of hexadecimal or octal format is assigned to a numeric
variable, or printed, it is automatically converted to a floating point
number. String constants or variables cannot be mixed directly with
numeric variables and constants but there are functions forth is purpose.
EXPRESSIONS
The following is the formal priority or execution sequence in BASIC
numeric expressions, their symbols and function:
1. Parenthesis () Give sub-expressions higher
execution priority
2. Functions (see pages 28-35)
3. Arithmetic Exponentation e.g. 2 1 3 = 23
operators make numbers negative
Multiplication
Division
+ Addition
Subtraction
4. Relational Equivilence
operators < >,> < Not equal
< less than
> greater than
< = , = <> less than or equal to
> =, = greater than or equal to
5. Logical Operators
NOT(negation) X NOTX
true(-1) false(0)
false(0) true(-1)
OR(logical add) X Y XORY
true(-1) true(-1) true(-1)
true(-1) false(0) true(-1)
false(0) true(-1) true(-1)
false(0) false(0) false(0)
AND(logical multiply) X Y XANDY
true(-1) true(-1) true(-1)
true(-1) false(0) false(0)
false(0) true(-1) false(0)
false(0) false(0) false(0)
The relational operators return a value of -1(for true) or 0(for false).
Example:
X=3
PRINTX=3;X > 4;X > = 2-result is -1 0 -1
The logical operators use two byte 2s compliment numbers and do a full
bit by bit operation on these bytes. This means that not only can they be
5
used to connect relational operators in a condition but they can also be
used to set and reset specific bits without affecting the others.
Example:
7 AND 3 = 3 7- 00000000 00000111
AND
3 - 00000000 00000011
3 - 00000000 00000011
7OR8 = 15 7 - 00000000 00000111
OR
8 - 00000000 00001000
15 - 00000000 00001111
To reset specific bits is a bit harder. The AND operator is used with a
number which has all its bits set except for the one you wish to reset.
Probably the easiest way to produce this number to be ANDed is to use
the NOT operator which simply sets all the bits reset, and resets all the
bits set. Therefore, to reset bit 7 in Y the expression, Y = Y AND NOT
2 t 7 is used. Again as with the OR operator more than one bit may be
reset with the one AND operation.
The AND operator can also be used to check if particular bits are set, eg.
to see if bit 7 is set in Y then AND Y with2 t 7. If bit 7is set then2 1 7
will be returned otherwise 0 will be returned. As conditions are taken to
be true if the number is non-zero then this can easily be used in an IF
statement.
e.g. IF (Y AND 2 t 7) THEN PRINT" BIT7 IS S ET" ELS E PRINT" BIT
7 IS NOT S ET"
Possibly the best way to become familiar with the OR, AND and NOT
functions is to try out various examples and see what results you obtain.
6
Character strings can be linked together with the operator"+". They
can also be compared using the same comparison operators as used
in numerics.
The comparison operators work on the character ASCII codes for each
string. Strings are equal if all character codes are equal. The character
string first having an ASCII code smaller than the other is said to be less
than the other. If strings are the same except that one is longer then the
shorter one is considered to be the smaller.
Examples:
"ASM" > "ASB"
"ASMT" < "ASMTQ"
"ALL" < "ZERO"
LINES
BASIC statements can be executed directly from the keyboard or stored
in a program. If a statment is typed in preceeded by a line number
(0-63 999) then the statement is automatically put in the program, sorted
in numerical order, otherwise it is executed immediately.
More than one BASIC statement can be on the same line, both for a
program or for immediate execution by separating them with a colon ( :).
Spaces are optional in BASIC. Extra spaces between keywords, variable
names, symbols and constants are ignored and the only time a space is
required is if a BASIC keyword follows on from a variable name, these
must then have a space between them.
Example:
IF A = B THEN- correct
IFA = B THEN-correct
IFA = BTHEN - incorrect, as BTHEN would be regarded as a variable
name
BASIC COMMANDS
AUDIO
• Connect/disconnect cassette output to 1V
•AUDIO ON
AUDIO OFF
• Connecting the cassette to the 1V allows you to record sound effects
on tape then play them back under program control (see MOTOR) to add
special sound effects to programs.
• AUDIO ON .00050 sec.
AUDIO OFF .00044 sec.
7
CIRCLE
• Draw a circle on the graphics screen
• CIRCLE ( [x],[y] ), [r]
CIRCLE ( [x],[y] ), [r], [attribute list]
where the [attribute list] is made up of some or all of the following options:
[c], [hw]. [start], [end], separated by commas.
• This command will draw a circle on the current graphic page (see
PMODE, Chapter 2.)
Parameters are:
- x,y: position of the centre of the circle (x=0-255,y=0-191)
- r : radius of circle
- c : colour ( 0 - 8 ) optional, default is foreground colour
- hw: height-width ratio : (used for drawing elipses) optional. The width
of the circle is always two times the radius you specified. The height
width ratio determines how high the circle is, default is 1
- start, end: starting and ending positions of the circle ( 0 - 1), posijion 0
of the circle is 3 o'clock, .25 is 6 o'clock position, etc. Whenever the
starting position is greater than the ending position, or when either start
or end is omitted, a complete circle is drawn. When the start and end
positions are specified the hw option must also be specified.
CLEAR
• Initialize variables, reserve string space and set highest BASIC
address
• CLEAR [string space], [address]
• Sets all numeric variables to 0 and string variables to null strings. If the
[string space] is specified then that many bytes is reserved for string
storage space, default is 200. If the [address] is specified then that is the
highest address that BASIC will use, leaving a 'safe' area for machine
code routines. Note that if [address] is specified then [string space] must
also be specified
• CLEAR
CLEAR 100
CLEAR 300, 10000
8
CLOAD
• Load a BASIC program from tape
• CLOAD
CLOAD""
CLOAD "[filename]"
• Will load a program from tape in either token form or ASCII form (see
CSAVE). If [filename] is specified the program with that name will be
loaded otherwise the first program found is loaded. [filename] must be 8
characters or less.
• CLOAD
CLOAD "DRAGON 1"
"'
CLOAD '
CLOADM
• Load a machine code program from tape
• CLOADM
CLOADM""
CLOADM''[filename]"
CLOADM"", [offset]
CLOADM"[filename]", [offset]
• This loads a machine code program (or block of memory - see
CSAVEM) from tape. If [filename] is specified the file with that name will
be loaded otherwise the first file found will be loaded. If the [offset] is
specified, this is added to the value of the addresses that were saved,
otherwise the original addresses are used.
• CLOADM
CLOADM "DRAGON M"
CLOADM "DRAGON M", 1024
CLOSE
• Closes open files or devices
• CLOSE [device-number]
where [device-nu mber] is either #-1 or #-2
• When a cassette data file (#-1) is CLOSEd, if it has been used in
output mode, the data remaining in the buffer and an EOF marker is put
on the tape; if it has been used as input then the buffer is cleared; either
way the buffer is made available for another OPEN command.
There seems to be no effect when closing files for device #-2 (the
printer).
CLOSE with no parameter closes all currently open files.
(See OPEN#-1)
• 0.00280 sees.
9
CLS
• Clear the screen and set background colour
• CLS [colour]
• Clears the screen and if [colour] is specified sets the screen to that
colour otherwise green is used by default.
• CLS
CLS3
• CLS .00807 sees
CLS x . 0 0997 sees
COLOR
• Set foreground and background colours on a graphic page.
• COLOR [foreground], [background]
• Set the foreground and/or the background colours (within limits - see
Colour Sets) for a graphic page.
Defaults are : [foreground] - lowest available colour
[background] - highest available colour
• COLOR3
COLOR3 .5
• COLOR x .00225 sees
COLOR x,y .00412 sees
CONT
• Continue a program
• CONT
• After the BR EAK key is pressed or a STOP or END statement is
executed, the program can be re-started from the next statement using
the CONT command. CONT will not work if any changes have been
made to the program (by EDIT or adding lines) or if another command
was entered incorrectly and an error message given between the
BR EAK and CONT. CONT always resumes execution at the next
statement after the program was stopped.
• CONT
CSAVE
• Save BASIC programs on tape
• CSAV E
CSAV E ""
CSAVE "[filename]"
CSAV E "",A
CSAV E "[filename]", A
• Saves a BASIC program o n tape either i n token format (the internal
tokens are saved) or ASCII format (actual words saved) selected by
',A'at the end of the command. The program name can be up to 8
characters (any character except " can be used).
10
Note: If ASCII format is to be specified then the quotation ( ') marks must
"'
CSAVEM
• Save a machine language routine on tape.
• CSAVEM "",[start],[end]. [entry]
CSAVEM "[filename]", [start], [end], [entry]
• Blocks of memory are saved on tape. [filename]is the name of the file,
[start] is the first address to be saved, [end] is the last address to be
saved and [entry] is the first address to be executed when the first EXEC
command is given after the program is reloaded.
• CSAVEM "SCROLL", 10000, 1 1000, 10100
Note: The parameters may be specified in decimal, hexadecimal or octal
by following the normal rules for numeric constants.
DATA
• Stores data in your program
• DATA [value], [value]. .
• The DATA statement allows you to keep both numeric and string data
in your program. Each piece of data is separated by a comma. If you
require a comma in your string then that piece of data must be enclosed
in quotation ("") marl<s. If a piece of data starts with a quotation (") mark
then every character (including commas) up to the next quotation mark
will be put in the string-variable.
• 1 0 FOR I = 1 TO 5 : READ X$ : PRINTX$ : NEXT I
20 DATA ",.10, ",HELLO"DRAGON", 1 0,HELLO,GOODBYE"
Result:
. . 10,
HELLO"DRAGON"
10
HELLO
GOODBYE"
DEFFN
• Define numeric function
• DEF FN [name] ( [var] ) = [expression]
• This sets up a user defined function. [expression] may be any
mathematical expression and use any of the program variables. Note
that the variable defined in brackets (after the name) can only be used
inside the formula and will not affect a variable of the same name outside
the definition. The function can then be called in your program like any
11
other BASIC function. If a function is defined in two places of a program
then the last executed definition is used.
Note: DEF FN cannot be executed in immediate mode, only in a
program.
Example:
5 Y = 10
1 0 DEF FNRR(X) = X/ 2 + Y
1 5 PRINTFNRR(7)
Result - 1 3.5
DEFUSR
• Define machine language routine
• DEFUSR[n] = [address]
• Specifies the starting address of a machine language routine (0 -
65535). You can specify up to 10 user machine language routines by
specifying [n] as O - 9, default is o.
• 10 DEFUSR =11000
DEL
• Deletes program lines
• DEL [lines-desc]
• Delete lines specified in [lines-desc]. Values of [lines-desc] are:
[n] - delete line [n]
[-1 - delete entire program
[-n] - delete up to and including line [n]
[n-] - delete from line [n] including line [n]
[n1-n2] - delete from line [n1] to line [n2] inclusive
• DEL 10-50
DIM
• Define(dimension) one or more arrays
• DIM [name] ( [dim-list]), [name]( [dim-list]), ..
• Define one or more arrays with the name [name] and size [dim-list].
When a single number is used in [dim-list] that is the upper bound of the
array and subscripts are in the range O to upper bound inclusive. Multi
dimensional arrays are defined by separating each dimension upper
bound by a oomma in the [dim-list]. Both oonstants and variables may be
used in [dim-list]
• DIM A(10), 8(5,7), C(D), E$(7)
DRAW
• Draw a line on a graphic page.
• DRAW [oommand string]
• [oommand string] can be a oonstant string (enclosed in quotes) or a
string variable, or a combination ooncatenated with ·+·.
[command string] may oontain any of the following:
12
C OMMANDS:
M- move draw position. Mx, y- position on screen (x = 0 - 255, y =0
- 1 91). M + x, + y - move relativeto current position. Note that if it
is a positive offset the plus sign must be included.
U - move/draw position up. Ux go up x positions
D - move/draw position down. Dx go down x positions
L - move/draw position left. Lx go left x positions
R - move/draw position right. Rx go right x positions
E - move/draw position 45° angle x positions
F - move/draw posttion 1 35° angle x positions
G - move/draw position 225° angle x positions
H - move/draw position 315° angle x positions
X - execute a substring and return
MODES:
C - change colour to x
A - tilt every1hing at an angle. x = 0 - 3 means angle is O', 90', 180',
27()<>
S - change the scale of every1hing. x = 1 - 64 indicates the scale factor
in units o f 1 /4
Example:
x = 2 Scale factor 2/4 or 1/2
x = 8 scale factor 8/4 or 2 (double)
OPTIONS:
B- immediately before any motion command, blanks that command i.e.
move but not draw.
N - immediately before any motion command, does not update posttion
i.e. draw but return to original cursor position.
EDIT
• change program lines
• EDIT [line]
• After typing EDIT and a line number the line is displayed and the
cursor placed underneath the line : it is now ready for editing
Commands are:
nC - change n characters
nD - deletes n characters
13
I - insert new characters
H - deletes rest of lines and waits for new input
L - list current line and continue edit
nSc - searches for the nth occurence of the character 'c'
X - extend line; add new characters to the end of the line
SHIFT t - escape from sub command
n SPACE - move n spaces to the right
n ... - move n spaces to the left
K - deletes rest of line- from current position
nKc - deletes the line up to the nth occurence of the character 'c'
END
• Ends program execution
• END
• Terminates program execution. Program maybe restarted on the next
line with CONT. This is optional and, if not included, program execution
ends with the last BASIC statement.
EXEC
• Transfer control to machine language program
• EXEC [address]
• Control is passed to a machine code program starting at [address]. if
the address if not specified control passes to the address used in the last
CLOADM command. When the machine code program executes an
RTS command, control is returned to the next BASIC command (if
entered directly, to the command level)
• EXEC 10000
FOR
• Create a loop in the program
• FOR [variable] = [n1] TO [n2) ... /NEXT [variable]
FOR [variable) = [n1) TO [n2] STEP [n3] ... /NEXT [variable]
• Creates a loop which executes the commands between the FOR and
the NEXT commands. The variable specified in [variable] is initialized to
[n1 ]. Each time through the loop [n3] (default 1 ) is added to the [variable)
and the statements executed until [variable) equals or surpasses [n2].
When [variable) equals [n2] the statements are executed and control is
passed to the statement after the NEXT statements. If [variable) does not
equal [n2] (has incremented past [n2)) control is passed directly to the
statement following the NEXT statement.
Note:
The loop is always executed once.
10 FOR I = 1 TO 5 STEP 2 : X$(I) = "HELLO" + STR$(I) : NEXT I
20 FOR I = 1 TO 5
30 PRINT I, X$(I)
14
40 NEXT I
50 FOR I = 5 TO 1 STEP -3 : PRINT I, X$(I): NEXT I
Result:
1 HELLO1
2
3HELLO3
4
5HELLO5
5HELLO5
2
• FOR I = 1 TO 10 : NEXT I - 0.001868 sees per loop
GET
• Save a rectangle of graphics screen
• GET ( [x1 ],[y1] ) - ( [x2],[y2] ) , [variable]
GET ( [x1] ,[y1] ) - ( [x2],[y2] ) , [varable] , G
• Gets a rectangle of the screen specified by the diagonally opposed
corners, [x1],[y1] and (x2],[y2] and places it in the array [variable] (see
Chapter 2 for a full discussion). The syntax also allows for a 'G' to be
added at the end of the command to specify that full graphic detail is to be
saved.
• GET (10, 10) - (20,20), A
• GET (10,10) - (15,15), A - 0.01 808 secs
GET (10, 10) - (30,30), A - 0.03231 sees
GOSUB
• Perform a subroutine
• GOSUB [line-number]
• Control is passed to the BASIC line whose number is specified by
[line-number] and execution continues until a RETURN is encountered,
then control is passed to the statement following the originating GOSUB.
10 GOSUB 100
20 PRINT "HELLO";
30 END
100 PRINT "SAY "
110 RETURN
Result:
SAY HELLO
• GOSUB/RETURN - 0.00181 sees
GOTO
• Pass control of program to another line
• GOTO [line-number]
• Control is passed to the BASIC line whose line number is specified by
[line-number] and execution continues from there.
15
1 0 GOT0 40
20 PRINT "THERE"
30 END
40 PRINT "HELLO"·,
50 GOT0 20
Result:
HELLO THERE
• 0.00093 sees
IF/THEN/ELSE
• Test relationships
• IF [condition] THEN [statements or line-number]
IF [condition] GOTO [line-number]
IF [condition] THEN [statements or line-number] ELSE [statements or
line-number]
IF [condition] GOTO (line-number] ELSE [statements or line-number]
• [condition] can be any numerical or relational expression and is said to
be true if it does not equal zero. If [condition] is true then the statements
following THEN (up to ELSE or the end of the line) are executed or
control is passed to the line having (line-number] after THEN or GOTO.
If [condition] is not true (false, zero) and there is an ELSE, the statements
following it are executed or control passed to the line having [line
number] after ELSE.
If [condition] is false and there is no ELSE, control is passed to the next
BASIC line.
• A = 27 : B = 16 : X = 1 1 : A$ = "YES"
IF A = B THEN 200 ELSE300 - Next line executed is 300.
IF X GOTO 1 000 - Next line executed is 1 000.
IF A$ = "YES" THEN PRINT "OK" ELSE B$ = "NO" : GOTO 20 - OK is
printed.
iF A < B THEN A = B: B = 0: GOTO 300 - Nothing will happen; next
line executed is the next
line number.
• 0.00274 sees
INPUT
• Enter data from keyboard
• INPUT "[prompt string]" ; [var1], [var2], .
• When the INPUT command is executed the [prompt string] is
displayed (if one has been given) then a question mark and the computer
waits for the keyboard input.
The [prompt string] must be a constant in quotes. The question mark is
placed directly after the string with no blanks. Note that if [prompt string]
is used it must be followed by a semicolon (';'). If no [prompt string] is
used, the quote marks ("") are not required.
16
When multiple variables are to be entered on one line they can either be
entered one at a time with an ENTER keystroke after each one or all on
one line separated by commas.
• INPUT "TWO NUMBERS PLEASE" ; A, B
INPUT A$
INPUT "YES OR NO" ; ANS$
INPUT#-1
• Enter data from tape
• INPUT#-1 [prompt string] ; [var1], [var2], .
INPUT#-1 [var1], [var2], .
• Accepts data from tape that has been previously recorded using
PRINT#-1. Note that if the data on tape is of a different type or format
the program will halt with an FM, FD or 0 1 error.
If a prompt string is used it is ignored and has no effect. It can be used as
a comment in the program. (see OPEN#-1)
• INPUT#-1 "TAPE DAT A", AB$
INPUT#-1, A, B
LET
• Assign a variable a value.
• LET [var] = [expression]
• The LET keyword is an option when assigning variables values. It is
included because many version of BASIC require it and programs from
these machines can, at times, be used on the DRAGON without
extensive modification.
• LET A = 34 / X
• LET B$ = "DRAGON"
• LET B$ = B$ + "ISHERE"
• 0.00157 sees
LIST
• List program on the screen.
• LIST (line-desc]
• List entire program or lines specified in [line-desc] onto the screen.
Format of [line-desc] is as follows:
n - list line n
-n - list all lines up to and including n
n- - list all lines after n, including n
n1 -n2 - list all lines between n1 and n2 inclusive
If no (line-desc] is given then the complete program is listed.
• LIST
LIST -30
LIST 40 -70
17
LLIST
• List program on line printer
• LUST [line-desc]
• Same as LIST except the listing is done on the printer.
• LUST
LLIST 100-
LINE
• Draws a line
LINE ( [x1],[y1] ) - ([x2],[y2] ), [a]
LINE ( [x1],[y1] ) - ([x2],[y2] ), [a], [b]
• Draws a line from the starting point [x1],[y1]to the end point [x2], [y2]. If
the starting point is omitted the ending point of the last LINE or DRAW
command is used or, if there isn't a previous LINE or DRAW command,
the line will start at (126, 96).
[a] must be either PSET or PRESET. If PSET is used then the line is
drawn in the foreground colour. If PRESET is used the line is drawn in the
background colour, that is, the line is erased.
LINE INPUT
• Enter data from keyboard
• LINE INPUT "[prompt string]" ; [var]
LINE INPUT [var]
• The difference between INPUT and LINE INPUT is that LINE INPUT
will take the entire line including leading blanks and commas and place it
in a string variable. LINE INPUT cannot be used for numerical input and
has a maximum length of 255 characters. Only one variable may be
used. There is no question mark after the prompt string.
• LINE INPUT "HELLO LINE?" ; ANS$
18
MOTOR
• Turn the cassette motor on or off
• MOTOR ON
MOTOR OFF
• Allows the motor of the cassette to be controlled by a program for
creating special effects (see AUDIO)
• MOTOR ON 0.5272 sees
MOTOR OFF 0.0005 sees
NEW
• Clears the current BASIC program from memory. This does not
actually erase any of the memory but rather modifies the pointers to the
BASIC program so that it cannot be accessed.
ON..GOSUB
• Multibranch to subroutines
• ON [var] GOSUB [line-number1]. [line-number2], .
• This allows multiple GOSUB commands on the one line. Depending
on the value of [var] a branch to a subroutine is executed. If [var] is 1 , then
[line-number1 ] is used, if [var]is 2, then [line-number2] is used, etc. If [var]
is zero or greater than the number of line numbers specified then the
statement following the ON-GOSUB statement is executed. Negative
values of [var] will cause an error. Values of [var] that are not integers are
reduced to integers by removing the fraction.
• ON X GOSUB 100, 200, 300, 400, 500
• 0.00258 sees
ON .. GOTO
• Multi-branches
• ON [var] GOTO [line-number1], [line-number2], .
• Same as ON . GOSUB except the branches are to lines not to
subroutines.
• ON X GOTO 10, 20, 30, 40, 70
• 0.00258 sees
OPEN
• Opens a data file.
• OPEN "[a]",#-1, [filename]
• Opens a file on tape for either reading or writing. [a] determines
whether you can read or write. The legal values of [a] are 'O' and 'I' which
stand for Output and Input respectively.
19
/
from the tape and whenever all the data is INPUT# - 1 ed from the buffer
it will be filled again from the tape automatically. When a file is opened for
output and PRINT# - 1 statements are executed the data does not
immediately get put onto tape, but rather, into this buffer and when the
buffer is full or the file is closed the data is transferred onto the tape.
• OPEN "l",#-1, "ADDRESSES"
• 0.00387 sees
PAINT
• Paints a section of a graphics page.
• PAINT ( [x],[y] )
PAINT ( [x],[y] ), [colour]
PAINT ( [x],[y] ), [colour], [border]
• Paints a section of a graphics page, starting at position [x], [y], with
colour [colour]. If [colour] is not specified the current foreground colour is
used. The painting will be contained by a border of colour [border]. Note
that if there is any small gap in the border then the painting will 'escape'
outside of the border and continue until it is contained by another border
or fills the whole screen. If [border] is omitted then the entire screen will
be painted, regardless of the values of x and y.
• PAINT (10,10), 3, 1
PAINT (100, 100)
• Time is approx. 4 sees for half a screen.
PCLEAR
• Reserve memory for graphics
• PCLEAR [n]
• Reserve [n] pages for graphics memory. [n] can be in the range 1-8.
The contents of the memory reserved are not affected. This should be
done near the start of the BASIC program as there may be strange
side-effects if done in the middle.
This effects the amount of memory available for BASIC. For the
maximum memory available to BASIC use PCLEAR
• PCLEAR s PL "l..S , 6 : N ,\.., . i, " , o )
• 0.00477 sees
PCLS
• Clears graphic pages
• PCLS [n]
• Clears the current graphics page to colour [n]. If [n] is not specified the
current background colour is used.
This should be done whenever PMODE selects a new graphics
resolution.
• PCLS
PLC S 4
• 0.0274 sees
20
PCOPY
• Copy graphics pages
• PCOPY [n1] TO [n2]
• Copies the graphic page [n1] to the graphic page [n2].
• PCOPY 2 T0 4
• 0.02605 sees for PMODE 1
PLAY
• Play music
• PLAY [command string]
• Play music as specified in [command string]. Commands in the string
are:
A-G notes
1-12 tones
On Octave n (0-5) default 2
Vn Volume n (0-31) default 15
Ln Length of notes (1-255) default 1
Tn Tempo n (1-255) default 2
Pn Pause n (1-255)
Xn$ Executes string n$ and returns
# or + Sharp
flat
½ as long again
For a more detailed explanation of the PLAY command see Chapter �.
• PLAY "A ; B ; C ; D ; E #"
PMODE
• Select resolution and graphic page
• PMODE [n1], [n2]
• Selectthe resolution to be [n1] and the starting graphic page to be [n2].
Defaults are 2 for resolution and the last page is used for start page.
• PMODE, 3
PMODE 1
PMODE 1, 3
• 0.00448 sees
POKE
• Fill a memory location with a specified value.
• POKE [address], [val]
• Set the memory location specified by [address] (0 - 32538) to the value
specified by [val]. The value ' poked' is to be between O and 255 (one
byte).
• POKE 10000, 1 00
• 0.00931 sees
21
PRESET
• Set to background colour
• PRESET ( [x],[y] )
• Set a point on the graphic page to the background colour. The point is
specified by [x] (0 - 255) and [y] (0 - 191 ).
• PRESET (10,10)
• 0.00477 sees
PRINT
• Display information on the screen
• PRINT [expression] [separator] [expression] [separator] ...
• Outputs character on the TV screen. When no expression is given, a
blank line is left. The [expression] may be any numeric or string
expression, including string constants. The legal values of the
[separator] are comma ',' , semicolon ';' , or a space ' ' If a
comma is used the output will be in two columns, each 15 characters
wide. If the first expression is longer than 15 characters then the second
expression is printed on the next line down. If the second is too long it
'wraps around' onto the next line down.
With a semicolon, or a space, strings are printed next to each other and
numeric items have a space on either side of them. The semicolon holds
the cursor in its last position ready for the next PRINT statement.
Note that a question mark may be used instead of the PRINT keyword.
• PRINT "12345678910"
A$= "12345678910"
PRINT A$
? A, B;
PRINT B$A
• PRINT "1234567891O" - 0.00506 sees
PRINT A$- 0.00487 sees
PRINT USING
• Formatted output
• PRINT USING [format string] [output list]
This outputs variables in a specified format. [format string] specifies how
the data is to be printed and can be either a string constant or string
variable.
',' -indicates that there is to be a comma to the left, of every third digit to
the left of the decimal point. The comma must be specified between the
start of the field and the decimal point.
'**' - placed at the start of a field specifies that all unfilled columns to the
left be filled with asterisks.
'$' - indicates that the number is to be preceded by a dollar sign at the
start of the field definition.
'$$' - indicates the dollar sign is to be on the immediate left of the number,
i.e. it is floating.
'**$' - indicates that the unused columns to the left of the floating dollar
sign will contain asterisks.
' + ' - placed at the start or end of a field specification will be printed as "+"
for positive numbers or " -" for negative numbers in the appropriate
place(indicates sign).
' - ' - placed at the end of a field specification will be printed " - " for
negative numbers and " " for positive numbers(indicates negative sign
only).
t t t t -indicates that the number is to be printed in exponential form
('scientific notation').
! -indicates that only the first character of the string is to be printed.
%spaces%-specifies the length of the string variable to be printed. If the
length of the string to be printed is smaller than the length of the
specification it is left justified, if it is greater then only the first characters-
up to the length of the specification - will be printed.
Any other characters will be printed as they appear.
PRINT U SING "#####";66.2 66
PRINT USING "##;66.2 %66
PRINT USING "#.#";66.25 %66.3
PRINT USING "########,";1234567 1,234,567
PRINT USING ,,..####";66.2 •••• 66
PRINT USING "$####.##"; 1 8.6735 $ 18.67
PRINT USING "$$####.##";18.6735 $18.67
PRINT U SING .... $.###";8.333 •$8.333
PRINT U SING " +••###";6.217 .... + 6
PRINT USING "####.#-";-8124.420 8124.4-
PRINT USING "##.####t t t 1 ";123456 1.2346E+ 05
PRINT USING "!"·"ARITHMETIC" A
PRINT USING "�/: %";" NUMERALS" NUMERAL
PRINT U SI NG " SCORE######,";SC SCORE 1,000
PRINT U SI NG "### IS LESS THAN ###";A,B 10 IS LESS THAN 11
23
PRINT @
• Place output at a specified location
• PRINT @ [expression], [print list]
• [expression] can be any numeric expression between 0 and 51 1 and
specifies where on the screen to start the printing (see Appendix H for
locations).
[print list] is the same as for a normal PRINT statement
• PRINT @ 192, "HELLO"
• 0.00740 sees
PRINT#
• Output to other devices
• PRINT#-1, (print list]
PRINT#-2, [print list]
PRINT USING #-1, [format string] ; [print list]
PRINT USING #-2. [format string] ; [print list]
• Has the same function as other PRINT statements except output is
directed to: cassette for #-1, printer for #-2.
PSET
• Set a point on the graphic page to a specific colour.
• PSET ( [x],[y].(c] )
• Set a point on the graphic page to the colour specified by [c]. If [c] is
omitted then the colour is set to the foreground colour. The point is
specified by [x] (0 - 255) and [y] (0 - 191 ).
• PSET ( 1,1,2 )
• 0.00694 sees
PUT
• Puts the graphics stored in an array onto the graphic page.
• PUT ( [x1],[y2]- [x2],[y2] ), [a], [b]
• Puts the graphics stored in array [a] onto the graphic page at location
specified by [x1], [y1] (top left corner) and [x2], [y2] (bottom right corner)
with the action specified in [b].
Values of [b] can be:
PSET - sets all the points set in the array.
PRESET - resets all the points set in the array.
AND - sets all points that are set both in the array and on the screen,
otherwise reset the point. (Sets all points common to both.)
OR - sets all points that are set in either the array or the screen. (Sets all
points that are set).
NOT - reverses the screen in the area specified regardless of what is in
the array. That is, all points set are reset and all points reset are set.
The array must be the correct size (see Chapter 2).
• PUT (10,10) - (20,20), A, PSET
• 0.01149 sees for a 1Ox10 array
24
READ
• Gets the next item from a DATA statement.
• READ [var1], [var2], ...
• Reads the next item of data from a DATA line and places it in [var]. An
error results if there is no data to READ. A pointer is kept at the next
element to be read (see RESTORE).
• READ A
FOR X = 1 TO 10 : READ A : NEXT X
• 0.00998 sees
REM
• Remark
• REM
• Allows the use of comments in the program. Everything from the REM
to the end of the line is ignored.
• 10 'THIS IS IGNORED
20 X = 0 : REM INITIALIZE X
• empty -0.00042 sees
100 characters - 0.00485 sees
RENUM
• Renumbers the program lines
• RENUM [newline], [startline], [increment]
• Renumbers all program lines from [startline] to the end of the program.
[newline] is the value that the [startline] is renumbered to. All line
numbers after [startline] are incremented by the value of [increment]. All
line numbers embedded in the program (eg. GOTO 200) are changed
accordingly. All parameters are optional and the default value for all
parameters is 10.
• RENUM
RENUM,,5
RENUM, 100, 100
RESET
• Set a point on the text screen to the background color.
• RESET ( [x],[y] )
• Sets a point on the text screen to the background color, that is, erases
it. The point is specified by [x] (0 - 63) and [y] (0 - 31).
• RESET (0,0)
RESET (10,10)
• 0.00460 sees
25
RESTORE
• Allow rereading of data
• RESTORE
• Restores the data pointer to the start of the DATA statements allowing
them to be reread.
• RESTORE
• 0. 00039 sees
RETURN
• Return from subroutine
• RETURN
• Returns control to the main BASIC program after a subroutine has
been executed. Processing is resumed at the statement following the
last GOSUB executed. RETURN is the last statement in a subroutine.
• 10 PRINT "THIS IS A SUBROUTINE"
20 RETURN
RUN
• Start a program
• RUN [line]
• Start the BASIC program executing at [line]. If [line] is omitted then
execution starts at the lowest line number. This can also be used inside a
program.
• RUN20
RUN
SCREEN
• Set graphics or text screen and colour set.
• SCREEN [type], [colour-set]
• The [type] parameter sets the type of screen to use either text (0) or
graphics(1 ). The [colour-set] determines the colour set to be used and is
either O or 1. The colours available depend on the current PMODE
setting (tor more information see Chapter 2, page 47 and Appendix D).
The default settings tor both is 0. Note that at least one parameter must
be given.
• SCREEN 1
SCREEN, 1
SCREE N1, 0
• 0.00476 sees
SET
• Set a point on the screen.
• SET ( [x],[y],[c] )
26
• This sets a point on the text screen. The position of point set is [x] (0 -
63) and [y] (0 -31). The [c] parameter specifies the colour to use (0 - 8),
irrespective of the current colour set.
Note that the rest of the points in the character block that contains the
points that haven't been specifically SET, are reset to black.
• SET (1,1,7)
SET (61,25,1)
• 0. 00669 sees
SKIPF
• Move past a file on tape
• SKIPF
SKIPF ""
SKIPF "[filename]"
• If no name is given at the end of the command, one file is skipped, that
is, the tape runs through and stops at the end of the first file encountered.
If [filename] is specified the tape will run until the end of the file named. If
no file of the name is found the tape will run to the end.
• SKIPF
SKIPF "PROGRAM1"
SOUND
• Generate sound
• SOUND [pitch], [duration]
• [pitch] is a number between 1 and 255 with 1 being the lowest tone.
[duration] is a number between 1 and 255. A duration of 16 is
approximately 1 second. Note that while the sound is being generated no
other processing can be done and the program cannot be stopped with
the BREAK key.
• SOUND 100,100
STOP
• Terminate program execution.
• STOP
• The STOP command is the same as the END command except that a
"BREAK IN #" message is printed. The CONT command will start
execution at the next statement as for END.
• IF ANS$ = "N" THEN STOP ELSE 30
TRON/TROFF
• Turn trace mode on/off.
• TRON
TROFF
27
• Trace mode is switched on by TRON and off by TROFF. When a
BASIC program is executed in trace mode the line numbers of the
program are displayed as they are encountered. The numbers are
enclosed in square brackets ( T and ']' ).
• TRON
TROFF
• TRON-0.00033 sees
TROFF -0.00037 sees
BASIC FUNCTIONS
ABS
• Absolute value
• ABS ( [argument] )
• Returns the absolute value, ie. regardless of + or - signs.
• PRINT ABS(3 -2 • B + 7)
• 0.00230 sees
ASC
• ASCll code
• ASC ( [string] )
Returns the ASCII code of the first character in the [string] argument.
• 1 0 AS = ASC ("AND")
20 PRINT AS
• 0.00267sees
ATN
• Arctangent
• ATN ( [argument] )
• Returns the arctangent (inverse tangent) of the [argument] in radians.
• PRINT "ANGLE : " ; ATN(R3)
• 0.00622 sees for 0
0.05562 sees for 100
CHR$
• Character conversion
• CHR$ ( [argument] )
• Takes the [argument] as an ASCII code and returns the character
equivalent (see Appendix E for codes). The argument must be between O
and 255.
• A$ = CHR$( 129 )
• 0.00287 sees
28
cos
• Cosine
• COS ( [argument] )
• Returns the cosine of the [argument], which is assumed to be in
radians.
• CS = COS(X)
• 0.02856 sees
EOF
• End of file
• EOF ( [file-number] )
• Indicates whether the file specified has more data in it or not. If an
INPUT is given when there is no data in the file an error occurs.
• IF EOF(-1 ) THEN 150 ELSE INPUT#-1 ; A, B$
• 0.00292 sees
EXP
• Natural exponential
• EXP ( [argument] )
• Raise e (natural logarithm) to the power [argument]. Inverse of LOG
• A = EXP(2) + B
• 0.00547 sees for O
0.03023 sees for 100
FIX
• Truncate
• FIX ( [argument] )
• Truncates (removes all digits to the right of the decimal point).
• PRINT FIX (7.75)
• 0.00275 sees
HEX$
• Converts to hexadecimal
• HEX$ ( [argument] )
• Returns a string containing hexadecimal digits O - 9 and A- F which
is the equivalent to the decimal [argument] (0- 65535).
• PRINT HEX$(1 5), HEX$(73)
• 0.00337 sees
INKEY$
• Character input from keyboard.
• INKEY$
• This returns the last key pressed that has not been INPUT. If no key
has been pressed since the last INPUT, LINE INPUT or INKEY$ a null
string is returned (ie. the keyboard has a one character buffer).
29
• ANS$ = INKEY$
• 0.00167 sees
INSTR
• String search
• INSTR ([argument], [string1 ], [string2] )
• Searches [string1] for [string2]. The search starts at the character
number, [argument] and returns either the starting posttion of [string2] or
0 if [string2] is not found.
• IF INSTR (1, "NYny", ANS$) = 0 THEN 30
• 0.00358 sees
INT
• Convert to integer
• INT ( [argument] )
• Rounds [argument] downwards. Therefore if [argument] is positive the
function is the same as FIX.
• A = INT(B / 2.3)
• 0.00340 sees
JOYSTCK
• Find position of joystick
• JOYSTCK ( [argument] )
• Returns the current horizontal or vertical position of either the left or
the right joystick according to [argument]. Values of [argument] are:
0 - horizontal left joystick
1 - vertical left joystick
2 - horizontal right joystick
3 - vertical right joystick
• LX = JOYSTK (0)
• 0.00443 sees
LEFT$
• Left part of string
• LEFT$ ( [string],[argument] )
• Returns a string which contains the left characters of [string]. The
number of characters returned is specified by [argument].
• PRINT LEFT$ ("WILL NOT BE PRINTED", 4)
• 0.00498 sees for 5 characters
LEN
• Length of string
30
• LEN ( [string] )
• Returns the number of characters in [string] including characters that
are not displayed on the screen (ie. control characters put there either by
the system or by the CHA$ function).
• PRINT LEN ("FOUR")
• 0.00285 sees
LOG
• Natural logarithm
• LOG ( [argument] )
• Returns the natural logarithm of [argument] which must be positive.
• A = LOG (X I 2) + LOG (Y)
• 0.02651 sees
MEM
• Free memory
• MEM
• Returns the amount of memory that is not being used by the system
(ie., available for programs and data). MEM does not include the memory
needed for the screen and graphics pages etc.
• PRINT MEM
• 0.00159 sees
MID$
• Middle of string
• MID$ ( [string], [argument1], [argument2] )
• This returns a substring which is in the middle of [string]. [argument1]
specifies which character to start at and [argument2] specifies how many
characters are to be returned. If [argument2] is omitted, all the characters
from [argument1] to the end, are returned. Note that this can be used the
other way to replace characters in the middle of a string. The parameters
have the same function when it is used this way, except when
[argument2] is omitted the number of characters assigned is the length of
the string replacing the original string.
• PRINT MID$ ("THIS WILL NOT BE PRINTED!", 1, 4)
A$ = "I AM VERY HAPPY" : MID$(A$, 6, 4) = "NOT " PRINT A$
Results-THIS
I AM NOTHAPPY
• 0.00683 sees for 3 characters.
PEEK
• Returns contents stored in memory
• PEEK ( [address] )
• Returns the current value of memory location [address] (0- 65535).
• PRINT PEEK (15000)
• 0.00292 sees
31
POINT
• Check for dot on text screen.
• POINT ( [x], [y] )
• Test a position on the text screen. If the position is a text character, -1
is returned. If there is nothing there, 0 is returned, otherwise the colour (1
- 8) of the dot is returned. [x] is the horizontal position (0- 63) and [y] is
the vertical position (0 - 31).
• IF POINT (X,Y) = C THEN 200
• 0.00509 sees
POS
• Current cursor position
• POS ( [argument] )
• Returns the current horizontal position of the cursor. Values of
[argument] are O for screen cursor or -2 for printer head.
• IF POS (0) = 31 THEN PRINT ELSE PRINT "
• 0.00469 sees
PPOINT
• Check for dot on graphic screen
• PPOINT ( [x], [y] )
• Checks the position on a graphic screen as specified by [x] and [y] and
returns O if cell is off and its colour (1 - 8) if it is on.
• IF PPOINT < >- 0 THEN 20
• 0.00469 sees
RIGHT$
• Right part of string
• RIGHT$ ( [string], [argument] )
• Returns a substring which contains the right portion of [string]. The
number of characters in the returned string is specified by [argument].
• B$ = "HELLO"
PRINT RIGHT$ (B$,3)
Result - LLO
• 0.00472 sees for 2 characters
0.00751 sees for 20 characters
RND
• Random numbers
• RND ( [argument] )
• Returns a random integer between 1 and [argument]. If [argument] is 0
then a real number between O and 1 is returned.
• B = A ( RND (10) )
• 0.01149 seesfor RND(1)
32
SGN
• Sign of argument
• SGN ( argument] )
• Returns the sign of [argument]. If [argument] is negative, -1 is
returned. If [argument] is positive, 1 is returned, otherwise [argument] is
0, in which case 0 is returned.
• IF SGN (A) = -1 THEN PRINT "NEGATIVE"
• 0.00269 sees
SIN
• Sine value
• SIN ( [argument] )
• Returns the sine of [argument]. It assumes that [argument] is in
radians.
• PRINT X, "SINE = ";SIN (X)
• 0.00588 sees for 0
0.03374sees for 2000
STRING$
• String building
• STRING$ ( [argument1], [argument2] or [string] )
• Makes a string of length [argument1 ] which contains either the
character with the code [argument2] or the first character of [string].
• PRINT STRING$ (10, "AS")
Result - "AAAAAAAAAA"
PRINT STRING$(10, 45)
Result - "EEEEEEEEEE"
• 0.00423 sees for 1 character
0.00371 sees for O character
0.00847 sees for 1 00 characters
STR$
• Numeric to string conversion
• STR$ ( [argument] )
• Converts a numeric expression, [argument], to a string of digits (0 -
9). Note that the minimum length of the string returned is 2 as the first
character of the string is a blank (space).
• PRINT LEFT$ (STR$ (1 / 3), 4)
Result - 0.33
• 0.00292 sees for O
0.00904 sees for 50
SQR
• Square root.
• SQR ( [argument] )
33
• Returns the square root ( v ) of [argument]. If [argument] is negative
then the program halts with an error.
• PRINT SOR (16)
• 0.00245 sees for 0
0.06150 sees for 1,000,000
TAN
• Tangent of argument
• TAN ( [argument] )
• Returns the tangent of [argument]. It assumes that [argument] is in
radians.
• X = TAN (Y / 2)
• 0.02824 sees for 0
0.05921 sees for 10,000
TIMER
• Set or return time
• TIMER
• TIMER acts as a variable in that you can both get its value and assign it
a value but it is continuously being incremented (approximately 50 times
a second).
The maximum value of TIMER is 65535 and it is reset to O if this value is
reached.
• TIMER = 0
PRINT TIMER
• 0.00185 sees
USR
• Call user defined routine.
• USR n ( [argument] )
• Calls a machine language routine that was defined earlier in the
program using DEFUSR. For details of machine language routines and
the argument see Chapter 4.
• X = USR (Y)
VAL
• String to number conversion
• VAL ( [string] )
• Returns the numeric equivalent of the digits (0 - 9) in [string]. If
[string] contains non-digit characters then only digits to the left of the first
non-digit character are converted; if there are no digits before the non
digit character then O is returned.
Note that hexadecimal numbers can be converted also.
• B = VAL ("1 2345")
PRINT VAL ("&HFF")
34
• 0.00337 sees for 1
0.00875 sees for 120,000
VARPTR
• Address of variable
• VARPTR( [argument] )
• This gives the head address where the variable specified by
[argument] is located. To find the head address of array variables,
specific elements of the array must be passed, e.g. B =VARPTR(A(0) ).
When one address is known the others can be calculated as each
consists of 5 bytes. For details of how variables are stored see Chapter 4.
• B =VAPPTR(A)
• 0.00223 sees
ERRORS IN BASIC
We have found one problem when executing BASIC programs and this is
in floating point addition. The error is that if a number is the result of an
addition it does not always exactly equal the number displayed.
e.g. 53.74 does not equal 51 + 2.74
For example, the above program will work correctly if an extra line is
added and line 30 changed. They should read.
15 X$ = STR$ (X) : Y$ = STR$(Y)
30 IFX$ = Y$ THEN PRINT "RIGHT" ELSE PRINT "WRONG"
35
CHAPTER 2
GRAPHICS
Probably the most impressive and powerful feature of the DRAGON is
unfortunately also its most confusing; its graphics.
All these modes and commands are covered later in the chapter, but let
me give you a brief, simple (if that's possible) rundown on how the
DRAGON handles its graphics.
Basically there are two different things the screen can display; text
(normal writing etc.) and graphics (more on this later). The text screen is
the old familiar standard screen which you see when you switch most
computers on, ie. letters, numbers and the other symbols which also
appear on the keyboard. On the DRAGON this is green with a black
border and black writing.
On the other hand anything can be put on any particular graphic screen
without effecting any of the others or what is being displayed (unless that
screen is currently being displayed) at any time. This allows many things
to be done 'behind the user's back' on the graphics screen, for example,
while he is busy with the text screen, etc.
36
PIXELS AND RESOLUTION
In computer graphics (similar to photographs and printed pictures) the
different shapes are made up by many small dots. Each of these dots can
be made to be one of several colours and when seen with the other dots
around, it creates a picture. These are called picture elements or 'pixels'
for short. It is the number of these pixels which control the resolution.
Resolution is a measure of the 'quality' of the picture. The higher the
resolution (the more pixels),the better the quality of the picture (e.g.
photographs have higher resolution than newspaper print which has
higher resolution than most computers).
Obviously the higher the resolution, for a given number of colours, the
more memory needed to store the information. so there must be a
trade-off between the resolution and the amount of memory to be used or
the number of colours on the screen. There is also a trade-off between
speed and resolution as the more pixels there are, the longer it will take to
change them all.
MODES
When the BASIC interpreter was written for the DRAGON the designers
decided to implement 1 semigraphic mode and 5 high resolution modes.
What they didn't tell you is that the VDG (Video Display Generator) chip
that they used is capable of handling 14 different modes; 5
semigraphic and 8 true graphic plus the standard text mode! However,
most of these extra modes are not really useful (which is probably why
they didn't bother to implement them).
TEXT
The text mode is the old standard that you use for most of your
programming. This is the mode you use to type in, run and edit your
programs as well as INPUT, PRINT, etc. from inside your BASIC
programs. The text mode also incorporates semigraphic 4 as shown
below.
SEMIGRAPHIC
Semigrahic modes are so called as each character block is divided into a
number of elements (pixels). The number of elements per character
block is used to name the mode, i.e. Semigraphic 4 has four elements per
character block, Semigraphic 8 has eight elements per character block,
etc.
37
The other semigraphic modes use the same area of memory as the text
mode so that when using these modes the text screen is not preserved.
However information can be put onto the text screen while the graphics
screen is being displayed by using POKE. Using the POKE to put
information on the text screen is quite simple as the following program
demonstrates.
10CLS
20 A$ = " THIS IS PRINTED OUT"
30 FOR I = 1 TO LEN (A$)
40 A =ASC (MID $ (A$, l,1))
50 IF A < 33 or A > 128 THEN A = 96
60 IF A < 64 THEN A =A + 64
70 POKE 1151 + I , A
80 NEXT I
GRAPHIC
The true graphic modes are of much higher resolution and are based on
dot graphics. The graphic modes implemented by BASIC are the higher
resolution graphic modes of the VDG and have very powerful BASIC
commands such as LINE, CIRCLE, etc. as well as the low level PSET
and PRESET dot graphic commands.
A table comparing the different modes and their attributes is given below.
A more detailed description as well as how they are stored in memory
and how to set the screen to these modes is given at the end of the
chapter.
The graphic modes which are not directly implemented by BASIC are
probably not as useful or practical as those that are. These 'non-mode'
modes can be set up by a series of PEEKs and POKEs and are
cumbersome to set up and use.
38
Graphics 1 0 , 1 1 - when resolution has to be reasonable but time and the
amount of memory used is still important.
Graphics 12 ,13- probably the most useful mode as resolution is quite
good and speed and memory size is still acceptable.
Graphics 1 4 - for very high resolution graph plotting such as cos, sin
and complex 3 -D graphs; could also be used in games where speed and
memory size are not important; limited however in that only two colours
are available.
NUMBER NUMBER
MOOE RESOLUTION IMPlEMENTED OF OF
IN COLOURS BYTES
BASIC PER PER
SCREEN SCREEN
X y
1. Alphanumeric 32 16 Y ES 2 512 (0 . 5 K)
2. Semigraphic 4 64 32 Y ES 8 512 (0.5K)
3. Semigraphic 6 64 48 NO 4 512 (0.5K)
4. Semigraphic 8 64 64 NO 8 2048 (2 K)
5. Semigraphic 12 64 96 NO 8 3072 (3 K)
6. Semigraphic 2 4 64 1 92 NO 8 61 44 (6K)
7. Graphic 64 64 NO 4 1 02 4 (1 K)
8. Graphic 128 64 NO 2 1 02 4 (1 K)
9. Graphic 128 64 NO 4 2048 (2 K)
10. Graphic 128 96 Y ES 2 153 6 (1 .5K)
11. Graphic 128 96 Y ES 4 3 0 72 (3 K)
12 . Graphic 128 1 92 Y ES 2 3 0 72 (3 K)
13 . Graphic 128 1 92 YES 4 61 44 (6K)
1 4. Graphic 256 1 92 Y ES 2 61 44 (6K)
VIDEO MEMORY
Video memory is the area of RAM used for storing the information to
display on the screen.
The area is from 1 02 4 (&H400 ) upwards. The minimum size for this area
in BASIC is2048 (2 K) bytes (enough for the tex1 screen and one graphic
page) and can be expanded up to 12800 (12 .5K) bytes by using the
PCL EAR command. This area can be shrunk down to 512 (0.5K) bytes
and expanded up to the top of RAM by setting the Start of BASIC pointer
and the Start of Free Memory pointer before loading the program. These
39
pointers are located at 25 (&H19), 26 (&H1 A)and 31 (&H1F), 32 (&H20).
To reduce this area to 0.5K bytes these pointers must be set to 1536
(&H600) by the following:
POKE 25, 6
POKE 31 , 6
}-··-·
13824 3600
PMODE O S"ooo8
12288 3000 } PMODE 1 &2 Screen 4
Page 7 q
10752 2AOO
Page6
9216 2400 } PMODE , &2 &,ooo 3
Pages
]---
7680 ,eoo
Page 4
6'44 '800 }PMODE ,&2 &,0002
Page 3
4606 '200
PMODE 0 Sc,ooo 2 }
3072 ocoo PMODE 1&2 Screen 1
MODE 0 Screen 1
'536 0600
1024 0400 Standard -TeKtand
Semigraphics 4
Video Memory
The above diagram shows how the video memory is divided up into
pages and screens for the different modes.
PAGE SWAPPING
Apart from having all these different modes, the VDG also has the ability
to have the screen displaying the contents of any section of memory.
This is limited to a certain number of pages (depending on the resolution)
in BASIC but by following the instructions below (setting up addresses
&HFFC6 to &HFFD3) or the program Listing 1 the screen can display any
section of memory you want to.
Listing 2'aemonstrates this by cycling through the entire memory.
40
LISTING 1
This routine allows easy setting of the start of display area for
initialization prior to doing graphics work. Before using this program set
the variable S to the address to start, the bottom 9 bits of this address are
ignored as addresses can only be multiples of 512.
1 00 S = INT(S / 512)
110 FOR I = &HFFC6 TO &HFFD2 STEP 2
120 R = S - INT (S I 2) • 2 : S = INT (S / 2)
130 POKE I + R, 0
140 NEXT I
LISTING 2
I = O : GOSUB100
'.' GOT02
5 PRINT"F'F':ESS ANY KEY TO MOVE ONTO THE NEXT Bl.OU: "
10 FOR!=2 T0 1 28
20 GOSUBlO(•
30 A$=INKEY$: IFAl= " " THEN30
40 NEXT!
50 FORI=OT02
60 A$=INKEY$: IFA$= " " THEN6(•
70 GOSUBlOO
80 NEXTI
90 END
100 ' ** SET UF' STAfn OF SCf.:EE�
1 05 PRINT "UP TO"HEXI( I*512 l
106 A$=INKEY $ : JFM= " " THEN106
1 10 S=I/2
120 FORK=IHFFC6 TO IHFFD2 STEP:
130 P=S-INTI S/2 )12: S=!NTI S/2 )
140 Pm:E K+h l•
1 50 NEXTK
160 RETURN
There is a 7-bit register in the VDG which controls the start address of the
screen. The number in this register is multiplied by 512 to give the actual
starting address.
To set this register there are 14 different memory locations, two for each
bit.
The relationship between the locations and the register is shown below.
41
FFD3 (65491 ) SET
FFD2 (65490) RESET BIT 6
FFD1 (65489) SET
FD0 (65488) RESET BIT 5
FFCF (65487) SET
FFCE (65486) RESET BIT4
FCD
FCC � (65485)
(65484)
SET
RESET BIT 3
FFCB (65483) SET
FFCA (65482) RESET BIT2
- FFC9 (65481) SET
- FFC8 (65480) RESET BIT 1
� FFC7 (65479) SET
� FFC6 (65478) RESET SIT O
I I
6 0
512 - ADDRESS OF START
OF SCREEN
I
In BASIC this can be achieved with the PMODE command but only over
a limited range of memory. Using this feature can greatly speed up
programs which need fast, repetative movement on screen. You can set
up in advance slightly different pictures in different areas of memory and
cycle through! them rapidly to create the effect of movement.
The rest of this chapter looks at each BASIC graphic command in detail
and finishes with a summary of the modes and how to select them.
42
games graphics, a,1d even lower (32 x 1 6) if you are not using a black
background (see SET/R ES ET). Because of these limitiations it is only
suitable for work such as bar charts, crude block figures, etc. The only
real advantages of this resolution are that text can be intermingled with
the graphics and it is simple and therefore can be fast.
CLS
This command is used to set the entire screen to a particular colour. Note
that it does not make this colour the background colour but rather sets all
the colour bits to the particular colour and sets all the on/off bits on. When
text is put on screen after a CLS [n], wherever the text appears, it is the
familiar black on green.
The two exceptions to this are: a CLS without any parameter - this
reverts to the standard black on green - and a CLS O simply causes all
the on/off bits to be off (ie. 0).
SET/RESET
The S ET command sets one element to a specified colour. However,
there are some surprises. Because the semigraphic 4 mode (standard)
has each byte containing four elements, only two colours can exist in the
same block (the size of a character) and that is black (i.e. the on/off bit's
off) and the color specified in the color bits (i.e. the on/off bit's on).
Therefore, when one individual element is turned on the others are
turned off. If you are not using a black background you get a big black
block with a quarter of it the colour you specified. If any other SETs are
done in this block the old one will change to the new one's colour.
The easiest way (but not necessarily the best) to overcome this problem
is to only turn the complete block on and off but this reduces the
resolution dramatically (to 3 2x1 6).
The RESET command simply sets the on/off bits so that that particular
element is turned off.
43
D
GRAPHICS CHARACTERS FOR SEMIGRAPHICS 4
1 28 132 136 1 40
� � �
-- •
� 129
[I 133
� 137
� 1 41
� 130
� 134
I] 1 38
� 1 42
131 135 1 43
� � 139
The filled in elements represent those that have their on/off bit set to 1
{i.e. a colour); the other elements have their on/off bits set to 0 (i.e.
black).
The above codes represent the filled in elements being green. For
different colours add the numbers shown below.
+ 1 6 - yellow
+3 2 - blue
+48 - red
+ 64 - buff
+80 - cyon
+96- magenta
+ 1 1 2 - orange
Example:
CHR$ (1 3 1 ) green
CHA$ (13 1 + 8 0 ) cyan
CHA$ (142 + 3 2 ) blue
Note that when a PRINT statement is executed, no matter what mode the
screen has been set to, it will revert to the standard black on green
alpha/semigraphic 4 mode. Strings can still be used in other modes by
44
doing all the PRINTing on the standard screen before setting the screen
to a different mode.
Note also that for different modes the CHR$ function will produce
characters (see byte mapping for the various modes at the end of this
chapter).
SET /RESET VERSUS STRINGS
Here are two programs to demonstrate the speed advantage of strings,
using the old favorite, INVADERS.
Version 1
10 Al$=CHR$( 128 l+CHR$( 133 )+CHR$( 1 3 8 :• +CHRJ;( 128 •
20 B l l=CHR$1 1 28 l+CHRl( 142 µ(HR$( 1 4 1 l+CHR� 128 )
30 A$=Al $ : B$;Bl$
40 FORI=l T05
50 A$=A$+A l $ : B$=Bl+Blt
60 NEXT
70 CLSC,
80 FDRI=64T072
90 PRINT@ I , A$ 1 : PR I NT@I+32 , BS '
1 00 FDRJ= 1T060: NEXT
110 NEXT
120 FDRI=7 1T065 STEP -1
130 PRINT@ I , As ; : F� I NT@I+32 , B $ '
1 40 FORJ=1T060: NEXT
150 NEXT
1 60 Gorn Bo
Version 2
10 CLS
20 FORJ=1T01 4 : GOSUB5 0 : NEXTJ
30 FORJ=13T02STEP - 1 : GOSUB50 : NEXTJ
�O GOT020
50 FDRI = 1 T048 STEF'B
60 RESETI J+I-1 , 4 1 : RESETI J + l - 1 , 5 ) : RESET! J + l - l , 6 ) :
RESET( J + I - 1 � 1 )
70 RESETI J+l , 4 ) : RESETI J+ I , 5 ,
80 SET< J+I+l , 4 , 0 ) : SET( J+!+l , 5 , 0 ) : SET( J + l +2 � 4 � 0 ) :
S£T� J+ 1 -.· 2 � s � o )
90 SETI J+I , 6 , 0 ) : SET( J+ I , 7 , 0 ) : SETI J + l + l , 6 , 0 ) :
SEH J + l -'·2 � 6 1 0 _,
100 RESET< J+I + l , 7 ) : RESET( J+! + 2 , 7 l
1 1 0 SET( J+I+3 , 6 , 0 J : SET( J+ I +3 , 7 , 0 ,
120 RESET< J+I+3 , 4 ) : RESET( J+l + 3 , 5 ) : RESET( J+ I + 4 , 6 ) :
RESET( J+I+4 , 7 )
45
130 NEXTI
l.'tO RETURN
Note also the ease with which indivual invaders can be removed from
strings - simply use the MID$ function to change the middle of the string.
INITIALIZING COMMANDS
SCREEN
The SCREEN command sets the display to either text or the current
graphics page as well as selecting the colour set to use. The format of
SCREEN is:
SCREEN [type],[colour-set]
Where [type] is O for text and 1 for current graphics and [colour-set] is
either 1 or 0. The colours available for each colour set depends on the
current mode (see below for colours available). The SCREEN command
can be used anywhere in a BASIC program but the screen is
automatically set to text and color set O whenever BASIC has text to
display, e.g. PRINT, INPUT, errors, etc.
PCLEAR
The PCLEAR command is used to reserve up to 8 pages of graphic
memory. The memory immediately after the graphics pages reserved is
used for your BASIC program. For this reason if PCLEAR is to be used it
should be close to the beginning, otherwise there may be strange results.
There are four pages of graphics reserved when BASIC is initialized.
Each page is 1536 bytes long. PCLEAR is used to either increase the
number of graphic pages allowing more to be 'flipped through', or to
decrease the number of graphic pages leaving more RAM space for your
BASIC programs.
46
PMODE
The PMODE command is used to change the current resolution and
starting page of the display. Only modes 1O through 14, and pages 1 to 8,
can be selected by PMODE. For imformation about setting other modes
and pages see the end of the chapter. PMODE can be used at any time to
change the resolution of the screen (note that the SCREEN command
must be given to actually see the current page). Below is a table which
shows the colours that are available for the various page and colour-set
combinations.
PMODE is also used to set the starting mode of the screen display so it
can be used to 'flip through' pages of graphics giving a movement effect.
Below is a table showing how many pages are needed for each mode
and therefore how many different screens can be stored simultaneously.
47
PCOPY
The PCOPY command is used for copying one graphics page onto
another. This allows multiple pages of the same picture or multiple
pictures on the same screen by copying a page into the page above it
then a high resolution mode is used to display the page.
PCLS
The PCLS command clears the current graphic screen to the specified
colour. If the specified colour is not in the current colour set or the colour
has not been specified then the current background colour is used. Note
that the entire screen is cleared, which may contain more than one page.
COLOR
The COLOR command allows the background and foreground colours to
be set. The border (in graphics) is either green or buff and if we set the
background to this colour the border disappears. The foreground colour
is used as the default colour in other graphic commands.
PRODUCING GRAPHICS
The PSET command is useful for drawing curves such as SIN etc. as the
program below shows.
10 PMODE O, 1
20 PCLS
30 SCREEN 1, 1
40 1 = 0
50 SS = SIN (I)
60 CS = INT (SS • 80) + 96
70 PSET (I • 20 - 0, CS)
80 I = I + 0.01
90 IF I < 12. ? THEN 50
100 GOT0 100
48
Try this program changing the resolution of the graphics in line 1 0. See
how the curve stays the same but it becomes smoother as the resolution
gets higher.
PPOINT
The other low level graphic command is PPOINT which simply samples a
particular pixel and returns the colour the pixel is set to.
HIGH LEVEL
So far we have discussed dot graphics which is OK for curve plotting and
simple pictures, etc. but why spend useful time on something that is
already done for you?
The BASIC high level commands LINE, CIRCLE and DRAW produce
shapes for you without all the complex functions, loops, data, etc. (for
examples of the use of these commands see the chapter on handy
routines).
LINE
The LINE command not only draws lines, boxes and filled in boxes but
also erases lines, boxes and filled in boxes. The format of the LINE
commmand is
LINE ( [x1],[y1 ] )-( [x2 ],[y2 ] ), [fn1 ], [fn2 ]
Execution of LINE produces a line that runs from the first co-ordinates
through to the second co-ordinates. The colour of the line drawn
depends on [fn1]. This is either PSET or PRESET (sound familiar?). If
PSET is specified then the line is drawn in the the current foreground
colour (set with the COLOR command) and if PRESET is specified the
current background colour is used, effectively erasing a line.
CIRCLE
The CIRCLE command, like the LINE command, does more than draw
circles; it also draws arcs and elipses. To draw a plain circle the format is:
CIRCLE ( [x],[y] ), [r], [c]
Were [x] and [y] are the co-ordinates (same as PSET) of the centre of the
circle and [r] is the radius. The legal values of [x] are 0 -255and [y] are O
- 1 91 .
49
The radius is specified by [r], [r] can have any value. Any part of the circle
that happens to go outside the screen area is ignored. The [c] parameter
specifies the colour that the circle is drawn in. If [c] is omitted the current
foreground colour is used and if [c] is set to the background colour the
circle is effectively erased.
The next and final option availble on the CIRCLE command controls the
start and end position of the circle allowing arcs to be drawn. Both start
and end values must be between 0 and 1. The way this relates to degrees
is shown below:
12 o'clock
(JO
0.75
9 o'clock 3 o'clock
27()0 9()0
0.5 0 and 1
6 o'clock
18()0
0.25
To calculate the parameter (0- 1) using degrees divide by 360 then, if
the result is negative, add 1.
If the end point is smaller than the start point, or either start or end is
omitted then a complete circle is drawn starting from the start point and
going clockwise. So the final format of circle is:
CIRCLE ( [x],[y] ), [r], [c], [H/W], [START], [END]
When the start/end options are used the H/W option must also be
specified (use 1 for true circles).
Using the CIRCLE command with different radii, H/W ratios and start/
end option, almost any curve can be drawn. (See the program on page
1 10, Circle Example Program.)
50
DRAW
Another very powerful graphic command available from BASIC is DRAW
and it would take a chapter on its own to describe fully.
The way that the DRAW command works is by having a current starting
position that it remembers but you cannot see. Whenever any of the
motion commands are encountered in the string this starting position
moves either to an absolute position on the screen (same co-ordinates
as PSET, x = 0 - 255, y = 0 - 191 ) or relative to its current position and
as it moves, it leaves a trail behind it. Therefore a string,
"U 1 0L 10D10R10", will draw a closed in box and the start position will be
the same as when it started. Before any motion commands have been
executed the start position is in the centre of the screen (128, 96). As
always there are exceptions to this rule and they are the two options N
and B. N causes the line to be drawn as normal but the starting position
does not move so that the next command starts from the same position.
B causes the starting position to move as normal but it doesn't leave its
trail behind.
In reality the B option is not 'move but don't draw' but draw in background
color (similar to PRESET) so that if its path takes it over the top of another
line, it effectively erases it.
51
The main difficulty encountered when using the DRAW motion
commands is that the commands that move at an angle (E, F, G,H)use a
different scale than the others. These lines are approximately 1 .42 times
longer than those in the horizontal and vertical planes. Therefore, to draw
a perfect triangle you use the string "R50U50G50" and you have a
perfect triangle but the line that runs at 45° is actually 71 units long.
The scale mode (S) is not as simple as it looks. The number directly
following the S (1 - 62) indicates the scaling factor, however each unit of
scale represents 0.25 or a quarter, thus 1 = 0.25 : 1 scale, 4 = 1 : 1 scale
and 1 0 = 2.5: 1 scale, therefore S4 has no effect, S1 - S3 make things
smaller and S5 - S62 make things bigger.
52
PAINT
The PAINT command does exactly what you think it would do, that is fill in
the screen with a specific color. The format of PAINT is:
PAINT ( [x],[y] ), [c], [b]
Where [x] (0 - 255) and [y] (0 - 1 91 ) are the standard graphic co
ordinates and specify where the painting is to start from; [c] is the colour
that the area is to be set to and [b] is the colour of the border of the area to
be painted. [c] and [b], like all the other colour definitions can be any of
the 8 colours but depend on the current colour set. What happens when
the PAINT command is executed is that the screen is painted within the
confines of the boundary, the colour specified by [c]. If the boundary has
the smallest of gaps in it (ie. one element) then the entire screen will be
painted.
Where the co-ordinates [x1], [x2], [y1] and [y2] define a rectangle the
same as for LINE, [a] is the name of the array in which the data is to be
stored and 'G' is an option which specifies full graphic detail (this seems
to have no effect, except slightly less space is needed). The size of the
array to hold the data must be set by a DIM statement. The array must
have two dimensions which between them have enough bytes to contain
all the data.
The easiest way to work out the dimensions is make the first dimension
equal to [x2]-[x1 ] and the second dimension [y2]-[y1 ]. This method is
quick to calculate but wastes space. To calculate the most efficient array
storage use the one dimension O and the other calculate as below.
1 . Find the number of elements to be stored
x2 -x1 • y2 - y1
2. If using PMODE 4 or 3 divide this by 8.
If using PMODE 2 or 1 divide this by1 6.
If using PMODE O divide this by 3 2.
Round up.
3 . Divide this by 5 and round it up again.
53
The number you have now should be right but may need adjustment by 1,
either up or down. Try this number; if you get a FC error when you try the
GET command increase the number in the DIM statement by 1, and try
again.
Using this saves quite a bit of memory. For example, in PMODE 4, with
the G option, if the rectangle being 'got' from the screen was (10, 1 0) -
(30, 30), the first method requires an array DIM (20, 20) or 121 O bytes but
the second method requires an array DIM (0, 1 1) or 11 bytes, less than
10% of the first.
The PUT statement has much the same format as GET.
PUT ( [x1],[y1] ) - ( (x2],[y2] ), [a], [action]
Where [x1], [y1], [x2], [y2] and [a] all have the same meaning as for GET.
The [action] parameter can have the following values: PSET, PRESET
(our old friends), AND, OR or NOT.
With PSET the picture on screen is exactly as it was when the GET
statement was used, as would be expected. The PRESET options will
erase (PRESET) all the points that are set in the array.
The AND option performs an AND operation on the points set in the array
and the points on the screen, then any points set both in the array and on
the screen it sets on the screen and all the rest are reset. This option can
be used to mask out certain areas of graphics.
The OR option performs an OR operation on the points set on screen and
the points set in the array and will set the points that are set in either the
screen or the array, resetting all others. this can be used to make two
shapes appear on the screen at once.
With the NOT option, it doesn't matter what is in the array even though
one must be specified. When the NOT option is used all points on the
screen inside the defined rectangle are reversed, ie set points are reset
and reset points are set. This can be used to get reverse video effects,
etc.
ASSEMBLER/MACHINE CODE GRAPHICS
Using graphics from assembler or machine code is quite a deal harder
but startling results can be achieved.
The first thing that must be done is set the mode you want by setting
memory location 65472 - 65477 as described at the end of the chapter.
Once one of the 14 modes and the starting address of the screen have
been set then there are many different methods to produce graphics.
One way could be to calculate each byte value and save this as data then
all your program does is load it into the screen memory. This is a simple
program, but it is hard to create the 'picture'. Another way would be to
write your own machine code routine to fake the BASIC commands
LINE, DRAW, PAINT, etc.
54
Whichever method you choose, graphics from machine code can be
both detailed and fast, much more so than from BASIC.
The following section has details on how each graphic mode stores the
pixels and how to use these modes from both BASIC and machine
language.
GRAPHICS MODES
This next next section is a description of the 1 4 graphic modes and how
to use them. This page is an explanation of the pages describing the
modes. It has the same format and headings but instead of data under
the heading it has an explanation of the heading.
MODE number and name of this mode.
ELEMENTS how may elements this mode has. horizontal x vertical
MEMORY MAPPING Where each element is stored
e.g.
Addresses
from start +0
i.e. "the contents o f this address"
is the start +1
address + 1
BYTES The number of bytes needed to hold one screen
ADDRESS How to calculate the address for each element. START is the
address which the screen starts at, see page 41.
NOTE: With byte mapping the elements name in a bit means that if a 1 is
there the element is 'ON' and if a zero is there the element is 'OFF', an X
means that that bit is not used.
55
MODES
MODE 1
ALPHANUMERIC - NORMAL TEXT
ELEMENTS 32 x 16
Memory mapping
+O LINE 1, CHARACTER 1
+1 LINE 1, CHARACTER 2
+ 32 LINE 2, CHARACTER 1
+33 LINE 2, CHARACTER 2
BYTES = 512
ADDRESS =32 •Y + X+ START
BYTE MAPPING 7 0
I I I I I I I I I
O
�
SEE APPENDIXH
COLOURS:
BORDER =BLACK
FOREGROUND COLOUR SET =0 - GREEN
COLOUR SET =1 - ORANGE
SELECT:
This is the standard screen.
56
MOD E 2
SEMI GRAPHIC 4
ELEMENTS 64 x 32
ELEMENT FORMAT
MEMORY MAPPING
+O LINE 1 , CHARACTER 1
+1 LINE 1 , CHARACTER 2
BYTES = 512
ADDRESS = 32 • Y + X + START
BYTE MAPPING 7 0
I ! CIC I C I L,I I I Loi
1 L, L,
SELECT:
SET/RESET when in TEXT mode
Alphanumeric and this mode are together
57
MODE 3
SEMI GRAPHIC 6
ELEMEN TS 64 x 48
ELEMEN T FORMAT
L, L,
L, ½
L, '-o
. A�P�P�
MEMORY M =G������
IN
�
+0 LINE 1 , CHARACTER 1
+1 i, LINE 1 , CHARACTER 2
BYTES = 512
ADDRESS =32 • Y + X + START
SELECT:
A = P EEK(65314): POKE 65314, (A and7) + 1 6 + X
Where X = 0 for colour set 0
X = 8 for colour set 1
P OKE 65476,0: POKE 65474, 0 POKE 65472,0
58
MODE 4
SEMI GRAPHICS 8
ELEMENTS 64 x 64
ELEMENT FORMAT
A L, ¼
B L, L,
C L, L,
D L, ¼
MEMORY MAPPING
+o �R� - ,�
w- A L� �E-1�,-
IN c�H��
AR 1�
+1 ROW A, LINE 1, CHAR 1
BYTES = 2048
ADDRESS =128 • Y + 32 • ROW + X + START
BYTE MAPPING
SELECT:
A = PEEK(65314) : POKE 65314, (AAND 7)
POKE 65475, 0 : POKE 65475,1 : POKE 65472,0
59
MODE S
SEMI GRAPHIC 12
ELEMENTS 64 x 96
ELEMENT FORMAT
BYTES = 3072
ADDRESS =v · 192 + Row • 32 + X+ START
BYTE MAPPING
7 0
A 1 C C C L,, L10 X X
B 1 C C C i... i.. X X
C 1 C C C L, L. X y
D 1 C C C X X L, L,
E 1 C C C X X L,
F 1 C C C X X L, I.,,
COLOURS BORDER BLACK
cc 000 GREEN
001 YELLOW
010 BLUE
011 RED
100 BUFF
101 CYAN
110 MAGENTA
111 ORANGE
SELECT:
A = PEEK (65314) : POKE 65314, (A AND7)
POKE 65477, 1 : POKE 65474, 0 : POKE 65472, 0
60
MODE 6
SEMI G RAPHICS 24
ELEMENTS 64 x 192
ELEMENT FORMAT A L,,
B ½1 ½o
C L, • L,.
D L, , L,.
E L ,s L,.
F L, , L, ,
G L,, L ,o
H La
I L,
J L, L•
K ½
L L, ¼
MEMORY MrA�P�P�IN
�G������
+0 ROW A , LINE 1 , CHAR 1
+1 ROW A, LINE 1, CHAR 2
BYTES = 6144
ADDRESS = Y • 384 + ROW • 32 + X + STARTS
BYTE MAPPING
7 0
A 1 C C C L,, L,, X X '
F 1 C C C L, , L, , X X
G 1 C C C X X L, , L, o
L 1 C C C X X L, ¼
COLOURS BORDER BLACK
CCC 000 GREEN
001 YELLOW
010 BLUE
011 RED
100 BUFF
101 CYAN
110 MAGENTA
111 ORANGE
61
SELECT:
A = PEEK(65314) : POKE 65314, (A AND 7)
POKE 65477, 1 : POKE 65475, 1 : POKE 65472, 0
MODE?
G RAPHICS 64 x 64 FOUR COLOUR
MEMORY MrA�P�P�
IN
�G=--,,��
�- �-
+0 ROW 1, COLUMN 1-4
+1 ROW 1, COLUMN !>----8
BYTES =1024
ADDRESS = Row·15 + FIX((COLUMN-1)/4) + START
SELECT:
A = PEEK(65314) : POKE 65314, (A AND 7) + 128 + C
Where C = 0 for COLOUR SET 0
C = 8 for COLOUR SET 1
POKE 65473, 1 : POKE 65474, 0 : POKE 65476, 0
62
MODE S
G RAPHICS 128 x 64 TWO COLOU R
MEMORY MAPPING
+0 =R� O�W 1,�c=o=L�U�MN�1�-8� - �
:-;.-=c =
BYTES = 1024
ADDRESS = Row·16 + FIX((COLUMN - 1)/8) + START
BYTE MAPPING 7 0
COL N + 7
COL N + 6
'----- � ------+ COL N + 5
L____ _ _, COL N + 4
L____ _ _ � COL N + 3
L---- -
- - ------> COL N + 2
COL N + 1
L---- - - - -
- - ->
- COL N
SELECT:
A = PEEK (65314) : POKE 65314, (A AND7) + 128 + 16 + C
Where C = 0 for COLOU R SET = 0
C = 8 for COLOUR SET = 1
63
MODE 9
G RAPHICS 128 x 64 FOU R COLOUR
+ 31 ROW1, COL 61 - 64
+ 32 ROW2, COL 1-4
BYTES = 2048
ADDRESS = Row · 32 + FIX((COLUMN-1)/4)
+ START
BYTE MAPPING 7 0
COL N + 3
COL N + 2
'-- - -
- ....,, COL N + 1
'-- - - - - ----, COL 1
SELECT:
A = PEEK (65314) : POKE 65314, (A AND 7) + 128 + 32 + C
Where C = 0 for COLOUR SET =0
C = 8 for COLOUR SET =1
POKE 65472, 0 : POKE 65475, 0 : POKE 65476, 1
64
MODE 10
GRAPHICS 128 x 96 TWO COLOUR
MEMORY MAPPING
---,
+0 - O�
R� �
W �=
1. c u=
o�L� -8�-
M�N�1�
+1 ROW1, COLUMN9-16
BYTES = 1536
ADDRESS =Row · 16 + FIX((COLUMN-1)/8) + START
BYTE MAPPING 7 0
!c ! c! c ! c ! c ! c ! c ! c !
SELECT:
PMODE0
or
A = PEEK (65314) : POKE 65314, (AAND7) + 128 + 32 + 16 + C
POKE 65476, 0 : POKE 65475, 1 : POKE 65473, 1
65
MODE 11
128 x 96 FOUR COLOUR
MEMORY MAPPING
EACH BYTE HOLDS 4 COLUMNS
BYTES = 3072
ADDRESS = Row · 32 + FIX((COLUMN-1)/4) + START
BYTE MAPPING 7 0
cc I cc I cc I cc 1
SELECT:
PMODE1
or
A =PEEK (65314) : POKE 65314, (A AND7) + 128 + 64 + C
POKE 65477, 1 : POKE 65474, 0 : POKE 65472, 0
66
MODE 12
G RAPHICS 1 28 x 192 TWO COLOU R
MEMORY MAPPING
EACH BYTEHOLDS 8 COLUMNS
BYTES = 3072
ADDRESS = ROW " 16 + FIX ((COLUMN-1)/8) + START
BYTE MAPPING
COLOURS BORDER
C=0
1
0
1
:��, l
GREEN
GREEN
BLACK
BUFF
COLOUR SET = 0
COLOUR SET = 1
COLOUR SET = 0
COLOUR SET = 1
SELECT:
PMODE 2
or
A = PEEK (65314) : POKE 65314, (AAND 7) + 128 + 64 + 1 6 + C
POKE 65477, 1 : POKE 65474, 0 : POKE 65473, 1
67
MODE 13
GRAPHICS 128 x 192 FOUR COLOUR
MEMORY MAPPING
EACH BYTE HOLDS 4 COLUMNS
BYTES =6144
ADDRESS = Row · 32 + FIX((COLUMN-1)/4) + START
1 cc I cc I cc I cc 1
BYTE MAPPING 7 0
g��� }
10 BLUE
11
00
01 COLOUR SET =1
10 MAGENTA
11 ORANGE
SELECT:
PMODE 3
or
A = PEEK (65314) : POKE 65314,(A AND 7) + 128 + 64 + 32 + C
POKE 65477, 1 : POKE 65475, 1 : POKE 65472, 0
68
MODE14
GRAPHICS 256 x 192 TWO COLOUR
MEMORY MAPPING
EACH BYTE H OLDS 8 COLUMNS
BYTES 6144
ADDRESS = Row · 32 + FIX((COLUMN-1)/8) + START
7 0
lclclclclcl clclcl
BYTE MAPPING
SELECT:
PMODE 4
or
A =PEEK(65314) : POKE 65314, (AAND7) + 128 + 64 + 32 + 16 + C
POKE 65477, 1 : POKE 65475, 1 : POKE 65472, 0
69
CHAPTER 3
SOUND
There are a variety of methods to make your DRAGON roar. There are
the two BASIC commands, SOUND and PLAY as well as generating
sound using a machine code routine.
The BASIC command SOUND is useful for creating sound effects in your
programs. You may want to prompt peoplethat they are required to enter
data, maybe even different tones for different types of data and another
when a mistake is made.
Try this line for when people make mistakes:
FOR I = 150TO 10 STEP - 1 0 : SOUND I, 1 : NEXT
Sound is fine for special effects but what about some music. The PLAY
command is very powerful and designed for just that. The string of
commands needed for PLAY is very easy to produce from a sheet of
music. Notes, sharps and flats, length of notes and pauses are directly
converted, even the tempo and the volume can be changed.
3 5 6 8 10 12
Fig 4.2 Keyboard
70
Note thatC# is the same note as D-and D#the sameas E- etc., but be
warned DRAGON does not recognise C- as being B or B# as being C.
The play command has a five octave range. When notes are played they
are played from the current octave (the initial current octave is 2 ).
Octaves are changed using the O option and once the octave has been
set it remains at that until either it is reset by another O option or the
machine is switched off. The same is true for volume, length and tempo.
The P option lets you pause between notes and the number which
follows the P has the same effect as in L options, the only difference
being you can't add a dot at the end. To make a pause of half as long
again use two P's in a row. e.g. P2P4.
The T option lets you change the overall speed of music or how many
beats there are in every second. The number following T multiplied by 0.4
gives you how many beats there are per second or2 .5 times the number
of beats per second you want gives you the value to use in the T option.
The PLAY command, like DRAW, has the ability to execute substrings.
This is done with the X option followed by the name of the string to be
executed. Note that a semicolon (;) must be placed after the dollar sign in
the string name (it is optional between all other commands). After the
substring has been executed control returns to the option after the
semicolon.
71
10 '** GOD SAVE THE QUEEN U ·
20 A$="T3; L3DDEL3. rnL6DL3E"
30 B$=" F»FttGL3. F!!L6EUDEL<CiWP2"
sO C$="L3AAAL3. AL6GL3F�GGGL3 .. GL6nL:3E"
50 D$=" L3FttL6GF"EDL 3 . F»L6GL3A"
60 ES="L6BGL2F"ED"
70 PLAY Al+B$+C$+[1$+Et
The speaker is connected to the PIA and is controlled through the PIA
registers. These registers are located in memory from &HFFOO to
&HFF3 F.
For sound we are only interested in &HFF22 and &HFF23 . Bit 3 of the
&HFF23 register is the sound enable/disable register. To enable the
one-bit sound this bit must be set to 0. Bit-1 of the register &HFF22 is the
72
bit that actually controls the speaker. However, it must first be setto be an
output bit, not an input bit. The short assembly program below sets up the
PIA registers ready for production of sound.
7002 86 FF2 3 LDA $FF2 3
7005 84 F3 ANDA #$F3
7006 87 FF2 3 STA $FF2 3
700A F6 FF22 LDB $FF22
700D CA 02 ORB #$02
700 F F7 FF22 STB $FF22
7012 SA 04 ORA #$04
701 4 87 FF2 3 STA $FF2 3
After the PIA registers have been set up as above, then toggling bit 2 of
register &HFF22 turns the speaker on and off. (Be careful that no other
bits are affected by toggling as they cotrol the VDG.) The easiest way to
accomplish this is shown below.
73
the length of time between changes of the level of the cassette port, ie.
suppose the cassette port is low (0) then we start counting until it goes
high (1) at this stage we save the count in memory and reset the counter
to zero. We then start counting again until the port goes low again save
the count, reset it to zero, etc. This process is continued until the
available memory is filled up.
I - INPUT SPEECH
The speech is input from the cassette port using one of two methods
described below.
When the I key is pressed the computer will display the message
"PRESS ANY KEY TO START", at this point the cassette should be
readied to send the speech to the computer. When all is ready press any
key and the computer will start to store the speech. The computer will
display a graphic screen which will fill up with what looks like rubbish but
is actually the values that make up the input speech. When the screen is
full the computer will return you to the menu.
Actually getting the speech to the computer is very simple and can be
done in one of two ways, both using your cassette recorder.
Method 1:
Prepare a cassette with the speech you want the computer to record
using either the built in microphone or an external microphone (note the
better the sound of this recording the better the results will be when the
computer plays back the speech, so rt is usually best to use an external
microphone).
Once the cassette is ready it is simply played into the computer just like a
program cassette. Note that since the program will not start the cassette
motor you should unplug the remote jack from the cassette recorder.
Method 2:
This is similar to the above except that you don't need to record what you
want to say you just say it directly to the computer. Firstly your cassette
74
recorder must be able to send what it is recording to the external speaker
jack. If it can do this then all you need to do is put the machine into record
mode and talk into the microphone when the computer is inputting
speech.
To put the cassette recorder into record mode without a cassette in it you
must open the cassette door and look inside. You should see a small
switch at the back left hand side. If this is pressed in then with the
RECORD and PLAY buttons pressed in the cassette will be in record
mode.
0 - OUTPUT SPEECH
This will call the machine language subroutine to send the recorded
speech to the speaker in the television set. The graphic screen
containing the speech is displayed while it is talking and if you look
carefully you will see a small white line moving around the screen. This
line is tracing the speech on the screen as it is sent to the speaker.
A- ANALYSE SPEECH
Since the sound is stored as a sequence of numbers we can draw a
graph of them and see the distribution of frequencies in what was said to
the computer. The graph is drawn on the highest resolution graphics
screen with the vertical scale being the total count that each number
occurs (ie. the higher the line the more times that number occured), while
the horizontal scale is the numbers (from O to 255, see above for how
these numbers are calculated).
When this graph is finished the screen will change colour and the
computer will wait until you hit a key. You will probably notice on this
graph that the left side of the screen is full of tall lines while the right side
of the screen is fairly empty. This is because in a given time interval you
can fit more short counts (hence small numbers) than long ones. To try
and correct this problem a new graph is drawn, after you press a key, in
which the vertical scale is the total time used by each interval length.
When this graph is finished the computer will again wait for a key to be
pressed at which time it will return to the menu.
75
The computer will ask you for a name to use when it saves your speech to
cassette. After you press ENTER it will save the speech in digital form on
the cassette so make sure your recorder is ready and that the
microphone and remote plugs are back in.
TIPS
To get the best results you will need to experiment with the volume levels
on your cassette recorder. Since it may take a number of tries to find the
optimum setting we suggest that you make a recording of some speech
first and use method 1 to input the speech initially. Remember the better
the sound on the cassette the better the results will be.
RUN the above program then press BREAK when at the command
menu.
Prepare your cassette recorder for saving a program and type in:
CSAVEM "SCODE",&H7000,&H705D,&H7029
This will save the machine code to tape.
RUN the program again. Input the speech you wish to use and save it to
tape - note that you can save as many blocks as you like and include
them all in your program.
76
Now suppose you have saved the machine code and two blocks of
speech to tape, and you wish to have a program that puts these two
blocks at memory location &H4000 and &H5800 respectively then in
your program you will need the following:
10 CLEAR 200, &H4000 : 'PROTECT MEMORY
20 CLOADM "SCODE" : 'LOAD MACHINE CODE
30 CLOADM "name1 ", &H4000 -&H0600
This line loads the first block of speech (with name name1 ) at location
&H4000 onward (the normal location is &H0600 so the offset to put it at
&H4000 is &H4000-&H0 600) .
40 CLOADM "name2", &H5800-&H0 600
Similarly for the second block.
When you want to output the first block of speech you should use
POKE &H7000 ,&H40 : POKE &H7001 ,0
EXEC &H7029
To output the second block you need the lines
POKE &H7000 ,&H58 : POKE &H7001 ,0
EXEC &H7029
77
300 EXEC 15' INPUT SPEECH
310 GOTO 1 2 0
320
330 ' OUTPUT SPEECH ONCE
340 PMODE 4 1 ! : SCREEN I , I
350 AUD I O ON:EXEC 05' OUTPUT SPEECH
360 GOTO 1 2 0
370 '
380 ' OUTPUT SPEECH REPEATEDLY
390 PMODE 4 1 1 : SCREEN 1 1 1: AUD I O ON
400 EXEC 05: IF I NKEY$= " " THEN 400
410 GOTO 1 2 0
420
430 ' SAVE SPEECH TO CASSETTE
440 I NPlJT"NAME " ; Af.
450 CSAVEM A$, SS, SE, 0
460 GOTO 1 2 0
470 '
480 ' LOAD SPEECH FROM CASSETTE
490 INPlJT " NAME " ; A$
500 CLDAOM A$
510 GOTO 1 2 0
520
530 ' ANALYSE SPEECH
540 PMODE4 , 5 : PCLS: SCREEN 1 , 1
550 FOR 1=0 TO 255: A < I J =0: NEXT I
560 FOR I =SS TD SE
570 P=PEEK ( 1 )
580 I F A ( P ) < 192 THEN PSET < P , 192-A ( P ) )
590 A ( P ) =A C P J + l
600 NEXT I
610 SCREEN 1 , 0: GOSUB 730
620 FOR 1 = 1 TO 255
630 A ( I > =A ( I ) *I ' CORRECT VALUES
640 I F A ( l ) >P THEN P=A < I J
650 NEXT I
660 P = 1 9 1 /P
670 FOR I = l TO 255
680 LINE ( I , 1 9 1 ) - ( I , 1 9 1-PtA ( I ) ) , PSET
690 NEXT I
700 GOSUB 730
710 GOTO 1 2 0
720 '
730 ' SUBROUTINE TO WAIT FOR KEY PRESS
740 A$=INKEY$: I F A$= " " THEN 740
750 I F ASC (A$) =3 THEN STOP
760 RETURN
770 '
780 ' SPEECH ROUT INE OFFSETS FROM START OF CODE
790 DATA 4 , 4 1
8'!10 -· CODE START ADDRESS
810 DATA �H7'i'l00
820 ' SPEECH MEMORY START H IGH�LOW BYTES
830 DATA 6, 0
840 ' SPEECH MEMORY LENGTH H 1 GH�LOW BYTES
850 DATA 24, 0
B60 ' SPEECH SUBROUT I NES
B70 DATA 26, 8 0 , 206,255, 32, 1 7 4 , 1 40, 244 , 1 6 , 1 74 , 140, 242
78
880 DATA 95,92, 1 4 1 , 72 , l i?l0, 1 96• 37,249 , 23 1 , 1 28,95,
92, 1 4 1 , 62 , 100, 196
890 DATA 36 , 249 , 23 1 , 1 28 , 49 , 62, 38, 232,57, 26,80,
206, 255, 32, 204, 52
900 DATA 63, 1 6 7 , 93 , 76, 1 6 7 , 95 , 231 , 67 , 1 7 4 , 140, 197,
1 6 , 1 74 , 140, 195, 230
910 DATA 1 2 8 , 99, 132, 1 34 , 128, 1 6 7 , 196 , 1 4 1 , 1 9 , 90,38,
247, 99, 132, 230, 128
920 DATA 1 1 1 , 196, 1 4 1 , 8, 90, 38,249, 49, 62, 38,228, 57, 57
930 DATA - 1
.
I SPEECH JNF'UT ANO OUTF·UT ROUTINES
I SUBROUT I NE INPUT MON I TORS THE
I CASSETTE I NF'UT LI NE ANO RECORDS
t THE LENGTHS OF THE H I GHS ANO LOWS
.
t SUBROUT I NE OIJTPUT T Alo, ES THESE
t LENGTI-IS ANO OUTPUTS HIGHS AND
.
I THE SPEECH l'IEP10AY LOCAT fON AND
I S I Z E .::.RE SPEC I F I E D AT TSTART
I ANO LENGTH RESPECT IVELY
79
'!1028 7'!128 3? R,S
• OUTPUT SPEECH
ti!029 7029 OUTPUT
0i1130 7029 1A50 ORCC #$50 D I SABLE INTERRUPTS
0031 702B CEFF20 LDU #PIA POINTER TO P I A
011132 702E CC343F LDD #$343F
0033 711131 A75D STA -3 , U SELECT DAC
0034 7033 4C INCA BE I NG CAREFULL ABOUT
012135 7034 A75F STA - 1 , U MOD I F Y I NG INTERRUPTS
0036 7036 £743 5TB 3 , U SOUND ENABLE
0037 7038 AE8CC5 L D X TSTART, PCR POI NTER TO START OF MEMORY
0'1138 703B 1 0AE8CC3 LOY LENGTH, PCR MEMORY FREE FOR SPEECH
0039 703F OLOOP
• OUPUT H I GH S I GNAL
0'?!40 703F E680 LOB • X + GET T I ME COUNT
0041 7041 6384 COM , X FLASH NEXT BYTE (TO SEE I T >
111042 7043 OH
0'1143 7043 8680 LDA #$80 OUTPUT LEVEL
0044 712145 A7C4 STA , U SEND TD P I A
0045 7047 8D13 BSA DELAY DELAY
0046 7049 SA DECB DECREMENT TI ME COUNTER
011147 71!14A 26F7 BNE OH LOOP UNTIL 0
80
CHAPTER 4
All the instructions are numbers of one or two bytes long. So how does
the DRAGON understand BASIC programming language?
To answer this question, you must first see what happens inside the
DRAGON. Apart from the CPU there are also two types of memory; RAM
and ROM. RAM (Random Access Memory) is the memory where the
programs you enter are stored.RAM is volatile, which means that unless
there is a power supply to the memory it 'forgets' everything. The other
type of memory is ROM (Read Only Memory). This type of memory has
the operating system in it. The operating system is a huge machine
language program stored in ROM (so that it can't be changed and is
automatically run when the DRAGON is turned on).
All the commands that are available in BASIC are simply reorganized by
another big machine language program called the interpreter, which is
also stored in ROM.
The interpreter simply deciphers each BASIC statement one by one and
executes the appropriate machine language program, unless you do
something wrong in which case it puts an error message on the screen.
So why bother with machine language if somebody else has already
written these vast programs to make your computer 'friendly' and 'talk' a
language which is easy for you to learn?
Well, programs written in machine language are very fast, use less
memory and are usually more complex. You may have noticed with the
programs you have bought, those that were written in machine language
have more graphical detail and run so much faster than those written in
BASIC.
81
If atthis stage you are still interested in machine language programming
but don't really understand what I am talking about then probably the best
way to go about learning machine language is to read the other book in
this series DRAGON MACHINE LANGUAGE FOR THE ABSOLUTE
BEGINNER.
THE CPU
The CPU used in the DRAGON is the M6809, one of the most powerful
8-bit micros available today. The power of the M6809 over other 8-bit
CPUs is by specific improvements in architecture, software and
hardware over its predecessor, the M6800.
82
To show the relative power of the M6809 the table below shows time
comparisons for eight different software operations on the popular CPUs
used today.
,.,
RIGHT S BITS ADDS ADDS MULT (64 BYTES)
""
.
"' '"
...
68092.0MHz 28 287.5 3'.5 325 82 3'4.5
"
..,
2804.0MHz 38.3 220.5 73.3 323 3'2
" "'
99003.0 MHz 72 66' 98 22 53' 53' 53'
68002.0MHz
8080 3.0MHz
80S5 2.0MHz
24.5
52.7 506., "·'
6' 5
91.3
993.5
•098
"'
'38
,
498.5 "'9.5
1176
1 123.5
'262
79 '60
83
REGISTERS
The internal register structure of the M6809 is shown below followed by a
brief description of what each register is used for.
-
_ _
7 _ A_ _ __o 1 7_ _ _ B_ _ _ O--, 8 B� Accumulators A & B
J._ _ l r
�
15 D O 16-Bit Accumulator D
� - ---- ---- --- - -- - � .
5 X O I X index register
J1
�- ---- --- -- -- - ---�
0 Y index register
�15 - -- - ----y - - - - - - �
I
L
15
__ _ _ _
_ _ _ u__ _ ___ ___o�f U stackpointer
L
15
__ _ _
_ _ _ s_____ ____o�I S stack pointer
I
LI7
_ _ _ D P_
_ _ _ oI Direct Page Register
�
15 PC � Program Counter
__o
L
I
__ _ _ _ ____ _____ I
ACCUMULATORS
There are two 8-bit accumulators which are used to hold the current data
to work with. These two can be combined to form one 1 6-bit accumulator,
the D accumulator. Almost every instruction uses one of these registers
and most data manipulation instructior.s (ADD, SUB, etc.) work only on
the accumulators.
84
INDEX REGISTERS
These two 1 6-bit registers are used mainly to 'point' to sections of data
and can be accessed automatically during load and store instructions
(see Indexed Addressing Mode) with all sorts of fancy tricks to make
large data manipulation very fast. They can also be used to store 1 6-bit
numbers temporarily while the accumulators are manipulating other
data.
STACK POINTERS
The M6809 is one of the few8 -bit CPUs to have two stackpointers. With
most CPUs, if the user wanted to implement a stack he would have to do
some very tricky manoeuvering because the stack pointer is needed for
interrupts and other system usage. With the two stack pointers, one can
be used solely for the system leaving the other for the user's use.
PROGRAM COUNTER
The program counter controls the execution of a program and contains
the address of the next instruction to be executed. This register cannot
be accessed directly but is automatically changed during branching
operations, etc. The program counter can be used with an offset in
indexed addressing mode allowing position independent code.
ADDRESSING MODES
You are about to see what makes the M6809 such a powerfull CPU. The
addressing modes of the M6809 is one of the main factors in the M6809's
power. The M68 0 9 has 59 different instructions which utilize 10
lundamental addressing modes bringing the total number of unique
instructions to 1 464. An addressing mode describes how the data, that
the instruction is going to use, is to be found.
INH ERENT
This is sometimes called implied addressing and is the simplest mode as
the instructions which use this mode do not need any data. Instructions
such as INC, D EC and ASL work on the accumulators only and do not
need any data.
85
IMMEDIATE
Immediate addressing is where the data to be used with the instruction
immediately follows the instruction. The analogy in BASIC would be a
constant, whereas the other modes that follow are analogous to various
types of variables.
EXTENDED
This mode of address requires two bytes, following the instruction, which
contain the address of the data to be used. With extended addressing a
full 64K of memory can be accessed.
DIRECT ADDRESSING
This is a limited form of extended addressing and only requires one byte
to follow the instruction. This is sometimes called zero page addressing
as only the first 255 bytes of memory can be accessed but reduces the
time and space that a program needs to run in as only the low byte needs
to be specified. The advantage of the M6809 over most other CPUs is
that it allows this 'zero page' to be moved about in memory by setting the
Direct Page register which in effect becomes the high byte of the
address.
RELATIVE ADDRESSING
There are two main types of relative addressing: Branch Relative and
Program Counter Relative and using the two allows completely
relocatable code to be written.
BRANCH RELATIVE
There are two types of branch instructions, short and long, both of which
use a two's complement (signed) relative address offset. Upon execution
of the branch the offset is added to the program counter's contents to
form the address of the next instruction to be executed. Note that when
the instruction is executing the program counter is already pointing to the
next sequential instruction. The short branch uses one byte offset which
allows a branch length of -128 through to +127, whereas the long
branch uses a two byte offset allowing branches of -32768 through to
+32767 in length.
86
PROGRAM COUNTER RELATIVE
This is really an indexing mode but is covered briefly here as it, in
combination with branch relative addressing, is needed to write
relocatable code. Basically, what is done is to use the index addressing
mode which allows you to have a 16-bit register and an 8-or 16-bit offset
field and specify the PC as the register to use (see constant offset
indexed addressing).
INDEXE D ADDRESSING
There are four basic forms of index addressing, each of which can use
the four pointer registers (X, Y, S, U). They are: zero-offset, constant
offset (which can also use PC), accumulator offset and auto-increment/
decrement.
OP CODE 1 or 2 b es
POST BYTE
OFFSET (0. 1 or 2 bytes)
As you can see the instruction is always followed by the post byte which
specifies the form of indexing to use and register to use as the pointer
that will be used in determining the effective operand address. The post
byte may or may not be followed by an offset.
ZERO-OFFSET I NDEXING
This type of indexing uses the pointer registers as the effective operand
address, with no offset. The post byte specifies the zero-offset mode and
which register to use.
ACCUMULATOR-OFFSET INDEXING
This form of indexing is similar to the constant offset form except that the
contents of one of the accumulators (A, B, D) is added to the specified
index register(X, Y, S, U). The obvious advantage of this is that the offset
can be calculated just prior to the indexing operation.
87
AUTO-INCREMENT/DECREMENT INDEXING
This mode of indexing is a blessing as it eliminates the need to
increment/decrement the index register with a separate instruction when
stepping through memory or moving blocks of memory. When
incrementing, the register is changed after the contents have been used
to find the effective address and when decrementing,the register is
changed before the contents are used. So it is post-increment and
pre-decrement. The post byte specifies the auto-imcrementing/
decrementing, the pointer register to use and the amount to increment/
decrement by (1 for 8-bit data or 2 for 16-bit data).
rr·
1 X X 1 1 0 0 EA=PC± 7 bit offset
1 X X 1 1 0 1 EA=PC+ 1 5 bit offset
1 1 1 '1 INDIRECT EXTENDED
I _, ADDRESSING MODE
OR
•
4-BIT OFFSET
INDIRECT FIELD •
..
OR
SIGN BIT FOR 5-BIT OFFSET
REGISTER SELECT
00 = X
01 = Y
10= U
11 =S
X = NOT USED
FIVE BIT OFFSET FIELD
0 = FIVE BIT OFFSET
1 = OTHER MODE SEE
ADDRESSING MODE FIELD
88
INDIRECT ADDRESSING
With indirect addressing the operand's address (where the data is
stored) is contained at the location specified by the operation. Indirect
addressing can be used with any of the indexing modes except for
auto-increment/decrement by 1 (see table above) as well as with
extended addressing. To specify indirect addressing in the indexing
modes, set bit 4 of the post byte. To get indirect addressing using
extended mode the post byte must have:
When using indirect extended mode the opcode (for indexing mode) is
followed by the post byte (&H9F) followed by the address which contains
the address of the operand.
REGISTER ADDRESSING
The last addressing mode covered is register addressing which is used
on the EXT and TFR instructions. With these instructions the post byte
contains two fields: bits O - 3 specify the destination register and bits 4
- 7 specify the source register.
89
USING MACHINE LANGUAGE PROGRAMS ON THE
DRAGON
On the other hand if you are going to be doing a lot of machine language
programming then you need a monitor program, or better still a full
Assembler/Editor. If you look around you will find a few assembler/
editors on the market but if you want to get out of it cheaply, I have
included a simple monitor program with which you can enter, modify, and
display parts of memory as well as find a string of characters in memory,
execute a machine language program and convert numbers from
hexadecimal to decimal and vice-versa.
The commands, their format and a description of each is given below
followed by the program listing and a brief outline of how the program
works.
90
F- F[b address] [e address] [string]- Find a string in memory.
- This searches memory beginning at [b address] through to [e address]
for the character string, [string]. All the addresses which point to the start
of the string, if there are multiple strings, are displayed. If [string] is not
found, nothing is printed.
C- C D [number]
; - C H [number]
- This converts the number [number] to either hex or decimal depending
on whether H (decimal to hex) or D (hex to decimal) is specified.
E- E- Exit to BASIC.
NOTE: All addresses must be four hex digits.
Formats must be exactly as shown, ie. no spaces between the command
letter and the first address (except for C) and 1 space between all other
parameters.
LISTING
91
230 BA=BA+l : G0T/J:!.20
300 BA=VAL( " I H " + M I Dl( CLS , 2 , 4 ) ,
310 I F B < O OR B A l lHFF�• THEN 900
320 CNT=C•
325 PRINT HEX$( BA ) ;
330 FORI=O TO �. : f'Rn�T" ''HE: Xi�( f:o �Ei..-.:( E>h-t· I .i ) ; :; NE/T l �
p�:; .u..i r;
3lf(, FOf\I;:,:i) TIJ J ! f'l: UNT' 1 CHf..: $( H::E!\� I1A+ I ) ) ;: : NEXT I � f-'fiif/ l'
11
345 BA=BA+"+
350 IF CNT C 1 2 fHEN CNT=CNT+ 1 : GQTOJ25
360 PRINT: CNi =C•
370 MC$=INKEY$ : IF MC%= 1 1 1 1 T�·! EN37( 1
This is only a sample of what a machine language monitor can do. Other
functions which are very useful (but outside the scope of this book) are an
assembler, disassembler, block moves, etc.
A brief summary of what the routine does and what the entry and exit
conditions are, is also included. At the end of the section there is a list of
the variables (memory locations) that are used in the routines and a brief
word on what they do.
INIT &HBB40
Initialize hardware interfaces such as printer, cassette, video, memory,
etc.
SETUP &HBBBB
Sets U;J BASIC system variables such as keyboard debounce, cassette
leader length, printer variables, etc.
BLINK &HBBB5
Decrements location 0OBF and when this counter reaches zero the
cursor is toggled from black to green or vice-versa.
TOUCH &HBE1 2
Write the character in the accumulator A onto the cassette.
93
BYTE-IN &HBDAD
Gets 8 bits off the cassette and puts them into the A accumulator.
BIT-IN &HBDA5
Gets the next bit on tape and puts it into the carry bit.
BLKIN &HB93E
Reads a block from cassette
CONDITIONS
ENTRY - cassette must be on and in bit synchronization (see
CSRDON)
- CBUFAD(7E) contains the buffer address.
I
EXIT-BLKTYP(7C) contains the block type
- BLKLEN(7D) contains number of data blocks in the block (0-255).
-Z = 1, ACC = 0 if no errors CSRERR(81) = 0
-Z = 0, ACC = 1 if checksum error CSRERR(81) = 1
- Z = 0, ACC = 2 if memory error CSRERR(81) = 2
-Unless there was an error X points to the last byte in the buffer
-U, Y preserved, all others changed.
Interrupts are masked.
BLKOUT &HB999
Writes a block to cassette
CONDITIONS
ENTRY-Tape should be up to speed
-a leader of &H55's should have been written if this is the first block to
be written after motor on
- CBUFAD(7E)-buffer address
-BLKTYP(?C) - contains block type
-BLKLEN(?D)-contains number of bytes in block
EXIT-X points to last byte in buffer
-All registers modified
Interrupts are masked.
WRTLDR &HBE6A
Turns cassette on and writes a leader.
CONDITIONS
ENTRY-none
EXIT-U preserved, all others modified.
CSRDON &H8021
Turns cassette on and gets in bit sync.
CONDITIONS
ENTRY-none
94
EXIT-FIRQ and IRQ are masked.
- U, Y preserved, all others modified.
CHROUT &HB54A
Outputs a character
CONDITIONS
ENTRY-DEVNUM(SF) set to -2 (printer) or O (screen).
- A character to be used.
EXIT - All registers except CC preserved.
JOYIN &HBD52
Sample joystick ports
CONDITIONS
ENTRY-none
EXIT - Y preserved, all others changed.
- POTVAL (15A) through to POTVAL + 3 (15D) contain the position of
joysticks.
POLCAT &HBBE5
Polls keyboard for a character
CONDITIONS
ENTRY-none
EXIT
-Z = 1, A= 0-no key pressed.
-Z = 0, A = key code-if key seen.
-B and X preserved, all others modified.
VARIABLES FOR ABOVE ROUTINES
BLKLEN(?D) length of cassette block
BLKTYP(?C) type of cassette block
0 = File Header
1 = Data
FF = End of File
CBUFAD(?E) cassette buffer address
CSRERR(81) cassette error type
0 = no errors
1 = checksum error
2 = memory error
DEVNUM(6F) device for CHROUT
-2 = printer
0 = screen
POTVAL(15A) 4 bytes holds current joystick position
15A = left joystick up/down
15B = left joystick left/right
15C = right joystick up/down
15D= right joystick left/right
95
HANDY MEMORY LOCATIONS IN THE DRAGON
START ADDRESS DESCRIPTION END ADDRESS
DEC HEX DEC HEX
00025 0019 Address of start of BASIC program 00026 001A
00027 001B Address of Start of variable storage
also address -1 is end of Basic program 00028 001C
00029 0010 Address of start of array storage 00030 001E
00031 001F Address of start of free memory 00032 0020
00033 0021 Address of start of string stack 00034 0022
00035 0023 Address of BASIC upper limit 00036 0024
00039 0027 Highest available RAM address 00040 0028
00108 006C Current column position of cursor
00111 006F Device number DEVNUM
00113 0071 Warm start flag RSTFLAG
&HO = Condition before cartridge program
Starts created by BASIC
&H 12 = Do warm start
&H55 - If RSTVEC points to a NOP
then execute from address
RSTVEC else start BASIC
00114 0072 Warm start Vector RSTVEC 00115 0073
00116 0074 Highest physical memory address 00117 0075
00124 0076 Block type BLKTYP
0 = file header
1 -data
FF -end of file
00125 0070 Bytes in block BLKLEN
00126 007E Buffer address CBUFAD also program 00127 007F
end + 1 after CLOADM
00128 0080 Checksum
00129 0081 CSRERR
00140 008C Sound frequency
00141 0080 Sound duration 00142 OOBE
00157 0090 Transfer address after CLOADM 00158 009E
00182 OOB6 Current Pmode
00256 0100 SWl3vector 00258 0102
00259 0103 SWl2vector 00261 0105
00262 0106 SWI 1 vector 00264 0108
00265 0109 NMl vector 00267 010B
00268 010C IRQ vector 00270 010E
00271 010F FIRQvector 00273 0111
00289 0121 Pointer to BASIC command Token Table 00290 0122
00290 0123 Pointer to BASIC command Jump Table 00292 0124
00294 0126 Pointer to BASIC function Token Table 00295 0127
00296 0128 Pointer to BASIC function Jump Table 00297 0129
00337 0151 KEYBOARD Recover Table 00345 0159
96
00337 0151 Bit cleared if any bit in same column cleared
7 6 5 4 3 2 1 0
00338 0152 ENTER X p H @ 8 0
00339 0153 CLEAR Y a A 9 1
00340 0154 z R B 2
..
00341 0155 t s K C 3
00342 0156 l- T L D 4
00343 0157 u M E 5
00344 0158 V N F 6
00345 0159 spaceW 0 G 7
00346 015A Joystick 0- left x position
00347 015B Joystick 1 - left y position
00348 015C Joystick 2 - right x position
00349 015D Joystick 3 - right y position
00466 0102 CASSETTE file name 00473 0109
00474 OlDA CASSETTE buffer 00731 0208
00485 01E5 Transfer address used in CSAVEM 00486 01E6
00733 02DD Keyboard buffer 00988 03DC
01024 0400 Text screen memory 01535 05FF
01536 0600 GRAPHICS Screen memory (in 8 pages
of 1536 bytes each) 13823 35FF
03072 ocoo User RAM note can start 32767 7FFF
anywhere between 03072 (OCOO)
and 13224 (3600) depending
on graphics pages.
32816 8033 BASIC command word table 33064 8128
33108 8154 BASIC command jump table 33225 81C9
33226 81CA BASIC function word table 33359 824F
33360 8250 BASIC function jump table 33427 8293
33449 82A9 BASIC error message table 33499 82DB
33504 82EO BASIC interpretor 49151 BFFF
49152 cooo cartridge slot 65279 FEFF
65280 FFOO PIA (Parrallel 1/0 Adapter) 65521 FFF1
65522 FFF2 SWI 3vector (contains 0100) 65523 FFF3
65524 FFF4 SWI 2vector (contains 0103) 65525 FFF5
65526 FFF6 FIRQvector (contains 010F) 65527 FFF7
65528 FFF8 IRQ vector (contains 010C) 65529 FFF9
65530 FFFA SWI 1vector (contains 0106) 65531 FFFB
65532 FFFC NMIvector (contains 0109) 65533 FFFD
65534 FFFE RESETvector (contains B384) 65535 FFFF
HOW BASIC STORES VARIABLES
At the top of user RAM a space is reserved for the string stack. This
space can be increased or decreasedby the CLEAR command. Possible
reasons for changing the size of the stackare:
Increase -you have a short program which uses a lot of strings and
string manipulations.
97
Decrease -you have a large program (ie.r unn ing o ut o f memory for the
program itsel f)that does not use many str n i gs .
Immediately belo w this s pace is the variable stack.
For every ne w var iable used the variable stackgrows down wards 6bytes
and contains -for:
Strings :byte 1 -length o f string
bytes 2, 5, 6-reserved for system
bytes 3, 4-address, n i string stack, o f the first byte o f the string
Numer ics :byte 1 -ex ponent
bytes 2-5 -mantissa
byte 6 -reserved for system
STRING STACK
Whenever a str ing var iable is made, even i f it is for the same var a i ble
name, it is put on 'to p'of the stack. So when a string variable is assigned
a di fferent str ing , the ne w string is put on t' o p' of the stack and the
address in the var iable stack is u pdated. Note that the old str ing is still n
i
the str ing stack but cannot be accessed. This means that a program that
does a lot o f string mani pulations , wastes a lot of s pace on the str ing
stack.
10 A$ = "HELLO"
20 B$ = "DRAGON"
30A$ =A$+ B$
7 7 7 7 7 7 7
F F F F F F F F
F F F F F F F E
StackAdr F E D C B A 9 8 7 6 4 3 2 1 0 F E D C B A
Afterline10 H E L L 0
Atterline20 H E L L O D R A G O N
Atterline30 H E L L O D A A G O N H E L L O D A A G O N
98
and this bit is used to store the sign of the mantissa (positive = 0,
negative = 1).
After reserving space for your program it must then be put into memory.
This can be done by CLOADM, POKEs or a BASIC program.
There are two ways to start it; EXEC and USR. The main difference
between the two commands is that with USR you can pass parameters
from BASIC to machine language and have values returned from
machine language to BASIC.
99
It is possible to convert this to an integer by calling the ROM routine
INTCNV (hex BB30) which returns a 1 6-bit two's compliment integer in
the D register. If the data was a string, INTCNV causes an overflow error
and control is returned to BASIC.
For string data the X register points to the 5-byte descriptor as described
above.
The USA function always returns at least one value to BASIC. If the
machine language program does not explicitly return a value, the value is
the same one as that passed to the program. In general, the type of data
returned is the same as that passed, in the same location and in the same
format.
There are a few rules when modifying string variables and returning them
to BASIC.
The length of the string may be changed by changing the length byte in
the string's descriptor. Strings may be shortened by this but a USA
routine should never lengthen a string. To allow variable length strings to
be returned, the string should be forced to a maximum length of 255
before the USA call. For example:
A$ = USR0 (STRING$("", 255))
The starting address may be modified by changing the address in the
descriptor. However, the new address should generally be that of a
memory location contained in the original string and the length reduced
by the appropriate amount. It is possible to swap the addresses of two
strings which would be useful for a fast string sorting routine.
The GOLDEN RULE when modifying strings is to never let two strings
intercept.
Apart from using the USA call it is possible to transfer data to and from
machine language programs by POKEing data into memory locations
reserved by the CLEAR command. The address to POKE into is also
known by the machine language routine and can be used and modified in
any way and then left to be PEEKed at by the BASIC program after the
machine language routine has finished.
1 00
CHAPTERS
PERIPHERALS
JOYSTICKS
The two ports marked for joysticks are really four analogue to digital
converters. One left/right right converter, one up/down right converter,
one left/right left converter, and one up/down left converter. These ports
are accessed in BASIC by the command JOYSTK with the parameter 0
- 3 selecting which AD converter to sample. Memory location 65280
indicates if the fire buttons have been pushed. The values of the location
are: 255 means no buttons pushed, 254 means the right button, 253 the
left and 252 means both fire buttons have been pushed.
Apart from plugging joysticks into these ports, other analogue devices
may be used and the information converted to digital form.
GND
100K
FIRE
Figure 6.1
Figure 6.1 gives details for the pin connections when joysticks are used
and using this diagram and some initiative virtually any analogue device
could be connected. Useful devices to interface could be a thermister for
a digital thermometer, multi-turn potentiometers for a trackball or with
strings and pullies for a pen tracer. The possibilities are endless, the only
limitations being your imagination and initiative.
PRINTER
The parallel printer port can be used from BASIC by the LUST command
and also the PRINT#-2 command. The port can be used not only for
printer connections but also other devices that accept parallel data such
as a down loader etc. Pin connections for the printer port are shown in
Figure6.2.
101
ACK D7 D6 D5 D4 D3 D2 D1 DO S TB
19 • • 1
20 • • 2
CASSETTE
The cassette port is used from BASIC by the commands relating to
saving and loading programs and the INPUT#-1 and PRINT#-1
commands. Having the ability to switch the motor on and off could be
used with another relay to control home electrical appliances. This could
be a heater and using a thermister wired into a joystick port your
DRAGON could be used as a thermostat for energy saving. The pin
connections for the cassette ports are shown in Figure 6.3
earjack micjack
remote controljack
FIGURE6.3
MONITOR/TV
There are two ways to get video signals on a screen. There are
connections for a standard UHF TV or an RGB monitor. When an RGB
102
monitor is being used the sound can be heard from the cassette
interface, via the lead normally connected to the microphone socket. If a
TV is being used it should be tuned to approximately channel 44UHF.
EDGE CONNECTOR
The edge connector is designed for using ROMpack games, disk drives,
memory expanders, etc but could also be used for any hardware that you
can think of to interface. Building circuitry with address decoders etc.
would allow you to have memory mapped 1/0, program and use your
own EPROMs etc.
Figure 6.4
PIN
1 -12V 10-17 D0-D7
2 +12V 18 R/W
3 HALT 19-31 AO-A12
4 NMI 32 CODD- FEFF (chip select)
5 RESET 33, 34 ov
6 E(6809 CLOCK) 35 Analogue in
7 0(6809 CLOCK) 36 FF40-FF5F select
8 CB1 37-39 A13 - A15
9 +5V 40 Turn off internal ROM
103
CHAPTER S
T his s hould be ente red, saved on cassette and tested be fore t rying to
enter the 1 .8MHz mode . Even t houg h t he displa y si meaningless w hile
t he DRAGO N is in t he 1 .8MHz mode, an yt hing put on the screen can be
ve i wed once 0.9MHz mode si re t urned . The 1 .8MHz can be entered b y
PO KEing 65497 w i t hzero and ex i ted as descr b i ed above .
T he charac ter si t ics o f the t hree modes a re :
MO DE
0.9MHz 0.9/1.8MHz 1 .8MHz
S PEE D 1 .0 :::; 1 .35 2.0
displa y yes yes no •
casset t e yes no yes ••
pr ni ter yes no yes ..
so und yes yes yes
jo ys t ci ks yes yes yes
graphics yes yes no •
1 04
NO TES:
1 . When the reset butt on is p ushed while i n 1 .8MHz m ode the
c ompu t er may or may n ot ret urn t o 0.9MHz m ode even th ou gh the CPU
and VDG w li l still be out of sync .
2. S ome of the CPUs pr oduced by Mot or olla may n ot be capable of
handl i n gthe extra speed s o we d on ot rec ommend that y ou use th is as a
rule .
T o disable the B REA Kkey en ter the f oll owin g c ommands, directly f rom
the keyb oard .
PO KE 41 1, 228
PO KE 412, 203
PO KE 41 3,4
PO KE 414, 237
PO KE 41 5, 228
Then t ot urn the B REA Kkey on and off use :
PO KE 4 1 0, 236t ot urn ti off
PO KE 41 0, 57 t oturn it on
..
B REA Kkey on and off fr om y ou pr ogram. T omake thin gs easier there si
a BAS IC pr ogram t o p ut th i s r outine int o h igh mem ory, which y ou can
then save with a CSA VEM "B REA K", &H7FE 0, &H7 FF$, &H7FE 0t obe
used w ith other pr ograms .
10 CLEA R 300, &H7FE 0
20 FO R A D = &H7 FE 0 TO &H7FF4
30 REA D B$ : B = VA L ("&H " + B$)
40 PO KE A D, B
50 NEX T A D
60 PO KE &H019B, &H7F : PO KE &H01 9C, &HE 0
7 0 PRI NT "B REA K D ISA B LE D ": PO KE &H019A, &H7E
80 FO R I = 1 TO 2000 : NEXT
90 PRINT "B REA KE NA B LE D " : PO KE &H019A, &H39
1 00 FO R I = 1 TO 2000 : NEX T
1 1 0GO TO 7 0
1 20 DA TA 32,62, 1 C,AF,BD,80,06,26,07,81, 1 3,26,03
1 30 DA TA 7E,85,2B,97,87,7E,84,A 6
1 05
?FED 32 62 START LEAS 2,S
7FE2 DC AF ANDCC #$AF
7FE4 BD 8006 JSR $8006
7FE7 26 07 BNE :1
7FE9 81 13 CMPA #$13
?FEB 26 03 BNE :1
?FED 7E 852B JMP $852B
?FF0 97 87 :1 STA $87
7FF2 7E 84A6 JMP $84A6
ADDRESS
l"1 1 'L.1-1 'l..>'1 'lJ.tl
BITS
15• �D 'cS'-I
DEC HEX 7 6 5 4 3 2 0
337 0151
338 01 52 ENTER X p H @ 8 0
339 0 1 53 CLEAR Y Q I A 9 1
340 0 1 54 z R J B 2
341 0 1 55
342 0 1 56 •
t s
T
u
K
L
C
p
3
4
343 0 1 57
344 0 1 58 ... V
M
N
E
F • 5
6
""�
345 0 1 59 SPACE W 0 G 7
Ll J .'°6 c )
106
When there are no. keys pressed this table is completely filled with 1's.
Whenever a key is pressed its corresponding bit in the table is reset to 0.
e.g. when A is pressed bit 2 of memory location 339 (01 53hex) is 0.
Memory location 337 (0151hex) has the property that if any bit in the
same column in the table is O then it will be 0. This is the reason that when
a key is held down and another pressed then the first released (if both
keys are in the same column of the table) the second key does not
register as being pressed. To overcome this problem simply POKE 337
with 255 immediately before an INPUT or INKEY$ command.
To allow keys to be repeated when a key is pressed and held down, then
each time an INKEY$ call is made the key value is returned, set the entire
table to 1's before each INKEY$. For example:
10 FOR I = 337 TO 345 ; POKE I, 255 : NEXT
20 A$ = INKEY$
30 PRINT A$
40 GOTO 10
This program will continue to print the key held down. If you now change
line 1 0 to contain a REM then the program will only print the key once-
no matter how long you hold it down.
If line 30 is removed then if two keys in the same column of the rollover
table are pressed at the same time then only the first will be recorded in
the table.
107
9E 19 LOX $19
BD 83F3 · JSR #83F3
30 02 LEAX 2,X
9F 1B STX $1B
9F 1D STX $1 0
9F 1F STX $1F
37 RTS
After running this program and saving it, type NEW; then LIST, then
EXEC 32754, then LIST. If everything was correct your program should
be the same as the original program youjust entered.
If you have inadvertantly keyed in NEW and you wish to restore your
program DO NOT type in the BASIC program above as it will destroy your
original program. If you have not CSAVEMed the machine language
program then you will have to POKE each number in the DATA
statement into its right address (start at 32754 and add 1 for each number
POKEd). I recommend that you type in this program now and CSAVEM
it, then it can be ready for use whenever you need it (use CSAVEM
"UNNEW", 32753, 32767, 32753 and CLOADM whenever you need it)
or have this routine at the start of each of your programs.
MERGE
Often it is handy to merge two or more BASIC programs together. For
example, you might have a standard sorting routine or a standard menu
controller. Merging two programs can be accomplished by the following :
1. CLOAD one of the programs
2. FOR I = 25 TO 28 : PRINT I, PEEK(!)
3. POKE 25, (the number beside 27)
4. POKE 26, (the number beside 28 - 2)
5. Now write down 25 and 26 and numbers beside them
6. CLOAD the second program
7. Make sure all line numbers are greater than those in the first program
(see below)
8. POKE 25, (the number you wrote beside 25)
9. POKE 26, (the number you wrote beside 26)
108
out of order and BAS I C won 't be able to follo w t hem pro perly so strange
things may occur .
There are several ways to ensure t ha t t he line numbers are correct.
1 . Write all your standard rou tines with ve rylarge numbers (e .g. 1 0,000
on wards) or small (e .g . less than 1 00) and wr ti e your programs
inbet ween .
2. A fter loading in the second program bu t before the PO K Es in s te ps 8
and 9, R EN UMber . At th si stag e i t will only change the line numbers of
the second program.
REDEFING BASIC KEYWORDS
By shi f ting the token table and jum p tables out o f the ROMinto some hig h
RAM loca tions , resetting the poin ters n i &H1 21, 1 22 (token table),
&H 1 23, 1 24 (command jum p table)and &H1 26, 127 (function jum p table)
and substituting the addresses of your o wn command handling routines
in the a p pro pria te place of the jum p table , you can easily redefine t he
act ion to ta ke place when a BAS IC key word si executed.
By taking a careful loo ka t the s truc ture o f these tables and ex panding
t hem so t hat their layout si s t li l the same Qus tbigger)you can even define
ne w BAS I C key words and a p pro pr a i te actions to take place on their
execution.
Belo w is a small mach n
i e language rout n
i e which rede fines the SO UN D
command (this could use t he machine language program in t he sound
c ha pter (4)).
1 09
BOXES SHOWING PAGE SWAPPING
This program, although not very useful, shows just how fast pages of
screen can be swapped to make fast animation.
10 PCLEAR 8
20 FOR f"D=lT OB
30 F·MODE O , Pr•
40 PCLS
50 SCREENO, (•
60 L I NE� 1 28-l l*PD, 96- l l *PD )·-( 1 2B+ll
*PD , 96 + ! l*PD ) , PSET , B
7 0 NEXT PD
80 I = l : SP=l
90 I = l +SF·
1 00 IF ! ( = 1 OR 1 = • 8 THEN SP= -SP
110 F"MODEO , I
120 SCREEN l , O
1 30 GOTO 9(•
VARIOUS CIRCLES
This program shows the power of the CIRCLE command and produces
some quite nice pictures.
' '** MAIN F"ROGf;:AM H '
1 0 CLS
2 0 PRINHl42, "CIRCLES"
30 F'R I NT@98, " r - fiANDiJM"
40 F'RINT@ 162, f 11
F-' lLL OWN OPTI ONS"
50 F'RINT@226 l' " 9 P I E GRAPH 1 1
60 F'R I NTl!,290, "p ' F"ACMAN ' "
7 0 F'RINT@354 , " " 1, FACE"
80 PRINT@450 , "PRESS ONE OF THl M)OI.IE KEY S "
90 F'RINT@482l' "ent1:�i-- TO RETUm� TD T H E ME�.il.J " ;
1 0 0 A$=1NK[Y $ : JF A$= " " -,- flEN 1.00
1 1 0 A = ! NSTR( " Ffr"Gf·A" , A$ .•
120 IF A=O THEN 100
130 F'MODE3 , 1 : PCLS • SCREEN 1 , 0
1 40 O N A GOSUB 200, 300 , 400,500, 600
150 GOTOl O
199 ' ** RANOM CIRCLES U '
2 0 0 PCLS
210 C I RCLE( RND< 250 l , RND( i80 l l d':ND( 70 ) , O , F:NI:•( 4 )
220 FOR I= 1 T0200 : NEX T I
110
230 A$=INKEY $ : IFA$= " " THEN 200
2'10 IF ASC< A$ )=13 THEN RETURfJ EI_SE 20(•
299 ' ** OWN OPTIONS * * '
300 CLS
310 I NPUT "CO-ORDINATES( Xd i " : x , r
320 INPUT"RADIUS" ; F:
330 I NPUT " COLOR( 0-7 ) " ; C
340 INPUT "HEIGHT··WIDTH RAT IO<: 0-4 '" ; H•'
350 I NPUT 1 1 ST ART( 0-1 ) 11 ; S
360 INPUT" END( 0-1 !" ; ,:
370 PHODE 3 , l : PCLS : SCREEN1 , 0
380 C I RCLE< X , Y l , R , C , HW , S , E
390 A $=INKE'/ $ : IF A$= " " THEN 390
395 IF ASC( M '=13 THEN RE: fURN EL.SE 39(•
399 ' ** P I E GRAPH 11 '
400 C I RCLE( l l B , 1 06 1 , 60 , 0 , 1 , 0 , . 75
410 C I RCLE( 138 , 86 ) , 60 , 0 , 1 , . 7 5 , l
420 L I NE< 1 1 8 , 106 :,-( 1 1 8 , 4 6 l , PSET
430 L INE< 1 1 8 , 106 H 1 78 , 106 i , F·SET
440 LINE< 1 38 , 86 )-( 1 3B , 26 l , F'SET
450 L I NE( 138 , 86 }-( 198 � 86 ) , F'SET
460 PAINT< 1 49 , 75 1 , 0 , 0
470 A$=INKEY$: I F A$= " " THEN '170
480 IF ASC< AS l=l3 THEN RETURN ELSE 470
,,99 ' ** PACK MAN **
500 C I RCLE( 1 28 , 96 1 , B0 , 0 , 1 , . 06 , . 9 �
510 C I RCLE( 1 4 8 , 5 0 ) , 9 , 0
520 L I NE( 128 , 96 )-·( 200 , 65 : • , F'SET
530 L I NE( 128 , 96 )-( 200 d 1 9 ) , F'SET
540 PAINT( 120 , 2 0 ) , 0 , 0
550 A$=INKEY $ : I F A$='"' THEN 550
560 IF ASC( Al 1 =13 THEN RETURN ELSE 550
599 ' ** A FACE **
600 C I RCLE( 1 2 8 , 96 ) , 7 0 , 0 , 1 . 2
610 C I RCLE< S0 , 96 ) , 10 , 0 , 3
620 C I RCLE( 207 ,96 1 , 1 0 , 0 , 3
630 C IRCLE( l00,70 ) , 1 2 , 0 , . 7
640 C I RCLE< 1 56 , 70 l , 12 , 0 , . 7
650 C I RCLE( 128,96 ) , 6 , 0 , 3
660 C I RCLE( 1 2 8 , 130 ) , 45 , 0 , . 7 , 0 , . 5
670 C IRCLE( 128 , J.30 ) , 47 , 0 , . 25 , 0 , . 5
111
680 PAINT< 12E h 150 ) 1 0 , 0
690 A$=INKEY $ : I F A$= " " THEN 690
700 I F ASC( A$ )=13 THEN RETURN ELSE 69(•
LINES
This program, like the last few, is not particularly useful but demonstrates
the power of the graphics and produces some interesting effects.
lO CLS
20 PMODE4 , 1 : PCLS
30 P I =3 . 1 41592654
40 R=lBO/PI
50 SX=192/'12767
60 SY;;:;255/4276;
70 INPUT" STEF· SIZE" ; I
80 I F I =O THEN END
90 f'CLS : SCREEN! , 1
100 A 1 = 1 28 : B 1 =96
1 1 0 A2=128 : B2=96
120 FOR�=l TO 16000 STEP :;:
130 I =K/R
140 A=K*COS( I )*SY+A�
150 B=K*SIN( I )*SX+B.2
160 LIN8 A , B l-( A 1 , B l > , PSET
1 70 A l =A : Bl=B
180 NEXT�
1 90 AS=INKEYl : J FAl= " " THEN190
200 GOT070
SCROLLS
Here are some machine language programs to scroll the text screen.
1 12
7014 Cl IF C"PB 131
7016 2F EA BLE : !
701B 39 RTS
To use these routines on the graphics screens the starting and ending
addresses need to be changed as well as the 'gap' between each line.
On the text screen the 'gap' is 32, the start address &H400 and end
address &H600.
113
APPENDIXB
ERROR MESSAGES
MESSAGE EXPLANATION
10 Division by zero
AO Attempting to open a file which is already open
BS Bad Subscript. Trying to use an array subscript
outside the range it was defined as. Sometimes if
a computer cannot recognize a function this
message is given.
CN Can't Continue. When you use the CONT
command after making changes to the program
or the program is at the end.
DD Trying to dimension the same array more than
once.
DN Device number error. There are only three
device numbers. -0- standard, screen,
keyboard; -1 - tape; -2- printer.
DS Direct Statement. This occurs if a direct
statement is in a data file on tape.
FC Illegal Function Call. This occurs when a function
or statement parameter is out of range.
FD Bad File Data.This occurs when the wrong type
of data is being read from a file, that is if numeric
data is being INPUT into a string variable and
vice-versa.
FM Bad File Mode. This occurs when you try to
INPUT data from a file OPEN for OUTPUT or
vice-versa.
ID Illegal Direct Statement. For example, when an
INPUT statement is executed outside a program.
IE Input Past End of File. Use EOF to check for the
end of the file.
10 Input/Output Error. Olten caused by bad tapes,
i.e. when the DRAGON cannot understand what
is on the tape.
LS String too Long. A string can only have 255
characters in it.
NF NEXT without FOR. Occurs when a NEXT
statement is encountered without a
corresponding FOR statement.
NO File Not Open. You cannot access a data file
without first opening it.
OD Out of Data. When a READ statement is
executed and there are no elements left in any
DATA statements.
123
OM Out of Memory. All available memory has been
used or reserved.
OS Out of String Space. There is not enough space
for string operations. You may be able to CLEAR
more space.
ov Overflow. A number has been made too long for
the computer to store. The range of numbers
available is + 1. 7E +38.
RG RETURN without GOSUB. A RETURN
statement has be encountered without a
previous GOSUB statement.
SN Syntax Error. This message is given whenever
the DRAGON cannot understand the command.
May result from misspelling the word or incorrect
number of parameters, etc.
ST String formula too complex.Break up the
formula into shorter steps.
TM Type Mismatch. This occurs when numeric data
is assigned to a string variable (e.g. A$= 8) or
vice-versa.
UL Undefined Line Number. This happens when any
command references a line number which does
not exist.
124
APPENDIXC
MEMORY MAP
125
APPENDIXD
COLOUR CODES
These are codes for each of the nine colours you can create
Code Color
0 Black
1 Green
2 Yellow
3 Blue
4 Red
5 Buff
6 Cyan
7 Magenta
8 Oranae
The colour may vary in shade from these, depending on your TV. Colour
0 (Black) is actually an absence of colour.
126
COLOUR-SET TABLE
,
4 0 Black/Green -
Black/Buff -
-
,
0 -
-
3 GreenNellow/Blue/Red
- Buff/Cyan/Magenta/Orange
,
0 Black/Green
-
2
,
Black/Buff
,
0 - Green/Yellow/Blue/Red
Buff/Cyan/Magenta/Orange
,
0 0 Black/Green -
Black/Buff
127
APPENDIXE
CHARACTER CODES
For use with CHR$ function and ASC function.
HEX 20 30 40 50 60 70
OFC: '.'12 48 "4 An Q6 1 1�
0 0 0 @ p @ p
1 1 ! 1 A Q A Q
" B R
2 2 2 B R
3 3 # 3 C s C s
4 4 $ 4 D T D T
5 5 % 5 E u E u
6 6 8 6 F V F V
7 7 7 G w G w
8 8 ( 8 H X H X
9 9 ) 9 I y I y
A 10 J z J z
-
B 11 + K [ K
�
12 L L
- -
=
D
E
13
14 • M
N
I M
N
I
F 15 I ? 0 0
NOTE:
1) The last two columns are the lower case values of the previous two
columns and will be shown as inverse video on the screen.
2) Characters 0- 31 are ASCII control characters and have no effect on
screen. Two exceptions are 8 which is backspace and 13 which is
carriage return.
128
APPENDIXF
PRINT@GRID
0
•�+'---.'r' r'�· r'nr
' n
' ' r'n�'-,-'�r'-r'-,-'--r'-r'-TC..,---.'-r'-,�--.'�..C..,.'-,-',-'-,
129
APPENDIXG
-03
Kev Hex If Decimal#
Unahlfted Shifted Unshltted Shifted
-
IIBml 03 03 03
- -
m!B) oc - 12
- -
l!HIIBl 00 OD 13 13
- -
llfilEm!) 20 32 32
- -
! 21 33
- -
•s 22 34
-
23 35
- -
24 36
- -
% 25 37
- -
& - 26 38
! -
27 39
- -
( 28 40
-
29 41
- -
- 2A 42
- -
+ 2B 43
- 20 - 45
-
2E 46
-
I 2F 47
- -
0 30 - 48
- -
1 31 - 49
- -
2 32 - 50
-
3 33 51
-
4 34 52
-
5 35 53
- -
6 36 - 54
-
7 37 - 55
- -
B 38 - 56
- -
9 39 57
-
3A - 58
-
3B 59
-
.>
-
< 3C 60
-
�A
30 61
3E - 62
? 3F 63
40 13 64 19
61 41 97 65
B 62 42 98 66
C 63 43 99 67
D 64 44 100 68
E 65 45 101 69
F 66 46 102 70
G 67 47 103 71
H 68 46 104 72
I
J
K
69
6A
6B
••
49
48
105
106
107
73
74
75
L 6C 4C 108 76
M 60 40 109 n
130
Key Hex# Decimal#
Unshifted Shifted Unshlfted Shifted
N
0
p
6E
6F
70
4E
4F
50
"'
110
112
78
79
80
a 71 51 113 81
A 72 52 114 82
s 73 53 115 83
T 74 54 116 84
u 75 55 117 85
V 76 56 118 86
w n 57 119 87
�
X 78 56 120 88
�
y 79 59 121 89
z 7A SA 122 90
SE SF 94 95
OA 58 10 91
(I) 08 15 8 21
(I) 09 5D 9 93
131
APPENDIXH
CHARACTER CODES
For use with PEEKs and POKEs direct to the text screen.
HEX 0 10 20 30 40 50 60 70
DEC 0 16 32 48 64 80 96 112
0 0 @ p 0 @ p 0
1 1 A Q ! 1 A Q ! 1
" "
2 2 B R 2 B R 2
3 3 C s # 3 C s # 3
4 4 D T $ 4 D T $ 4
5 5 E u % 5 E u % 5
6 6 F V 8 6 F V 8 6
7 7 G w 7 G w 7
8 8 H X ( 8 H X ( 8
9
A
9
10
I
J
y
z
) 9 I
J
y
z ! 9
- -
B 11 K [ + K [ +
.
C 12 L L
- -
I = I =
D
E
13
14
M
N • M
N
F 15 0 I ? 0 I ?
132
APPENDIX I
BASE CONVERSIONS
The following table lists base conversions for all one-byte values.
133
DEC. BINARY HEX. OCT. DEC. BINARY I HEX. OCT.
60 00111100 3C 074 94 0Hl11\H) SE 136
61 001111')1 30 075 95 01011111 SF 137
62 00111110 3E 076 96 01100000 60 140
63 00111111 3F 077 97 01100001 61 141
64 01000000 40 100 98 01100010 62 142
65 01000001 41 101 99 01100011 63 143
66 01000010 42 102 100 011')0100 64 144
67 01000011 43 103 101 01100101 65 145
68 01000100 44 104 102 011')0110 66 146
69 01000101 45 105 103 01100111 67 147
70 01000110 46 1060 104 01101000 68 150
71 01000111 47 107 105 01101001 69 151
72 01001000 48 110 106 01101010 SA 152
73 01001001 49 111 107 01101011 68 153
74 01001010 4A 112 108 01101100 6c 154
75 01001011 48 113 109 01101101 60 1550
..
76 01001100 4C 114 110 0110111e SE 156
77
78
79
01001101
01001110
01001111
40
4E
4F
115
116
117
111
112
113
01101111
01110009
01110001
,.
SF
71
157
180
161
01010000 se 126 114 0111001e 72 162
81 01010001 51 121 115 01110011 73 163
82 01010010 52 122 118 01110100 74 164
83 01010011 53 123 117 01110101 75 165
84 01010100 54 124 118 01110110 76 168
85 01010101 55 125 119 01110111 77 167
66 01010110 56 126 120 01111')01 78 170
87 01010111 57 127 121 01111001 79 171
86 01011009 56 130 122 01111010 7A 172
89 01011001 59 131 123 01111011 78 173
90 01011010 SA 132 124 01111101 7C 174
91 01011011 58 133 125 01111101 70 175
92 01011100 5C 134 126 01111110 7E 178
93 01011101 50 135 127 01111111 7F 177
1 34
DEC. BINARY HEX. OCT. DEC. BINARY HEX. OCT.
128 10000000 80 200 162 10100010 A2 242
129 10000001 81 201 163 10100011 A3 243
130 10000010 82 202 164 10100100 A4 244
131 10000011 83 203 165 10Hl0101 AS 245
132 10000100 84 204 166 10100110 A6 246
133 10000101 85 205 167 10100111 A7 247
134 10000110 86 206 166 10101000 AB 250
135 10000111 87 207 169 10101001 A9 251
136 10001000 88 210 170 10101010 AA 252
137 10001001 89 211 171 10101011 AB 253
138 10001010 BA 212 172 10101100 AC 254
139 10001011 BB 213 173 10101101 AO 255
14B 10001100 BC 214 174 10101110 AE 256
141 10001101 80 215 175 10101111 AF 257
142 10001110 BE 216 176 10110000 B0 260
143 10001111 BF 217 177 10110001 B1 261
144 10010000 90 220 178 10110010 B2 262
145 10010001 91 221 179 10110011 B3 263
146 10010010 92 222 180 10110100 B4 264
147 10010011 93 223 181 10110101 BS 265
148 10010100 94 224 182 10110110 B6 266
149 10010101 95 255 183 10110111 B7 267
156 10010110 96 226 164 10111000 B6 270
151 10010111 97 227 185 10111001 B9 271
152 10011000 98 230 186 10111010 BA 272
153 10011001 99 231 187 10111011 BB 273
154 10011010 9A 232 188 10111100 BC 274
155 10011011 9B 233 189 10111101 BO 275
156 10011100 9C 234 190 10111110 BE 276
157 10011101 90 235 191 10111111 BF 277
156 10011110 9E 236 192 11000000 co 300
159 10011111 9F 237 193 11000001 Ct 301
160 10100000 A0 240 194 11000010 C2 302
161 10100001 At 241 195 11000011 C3 303
135
OEC. BINARY HEX. OCT. OEC. BINARY HEX. OCT.
196 11')00100 C4 304 227 11100011 E3 343
197 11000101 CS 305 228 11100100 E4 344
198 11000110 CS 306 229 11100101 ES 345
199 11000111 C7 307 230 11100110 E6 346
200 11001000 C8 310 231 11100111 E7 347
201 11001001 C9 311 232 11101000 ES 350
202 11001010 CA 312 233 11101001 E9 351
203 11001011 CB 313 234 11101010 EA 352
204 11001100 cc 314 235 11101011 EB 353
205 11001101 co 315 236 11101100 EC 354
206 11001110 CE 316 237 11101101 ED 355
207 11001111 CF 317 238 11101110 EE 356
206 11010000 DO 320 239 11101111 EF 357
209 11010001 01 321 240 11110000 F0 360
210 11010010 02 322 241 11110001 F1 361
211 11010011 D3 323 242 11110010 F2 362
212 11010100 D4 324 243 11110011 F3 363
213 11010101 OS 325 244 11110100 F4 364
214 11010110 D8 326 245 11110101 F5 365
215 11010111 07 327 24a 11110110 F6 366
216 11011000 D8 330 247 11110111 F7 387
217 11011001 09 331 24a 11111000 FS 370
218 11011010 DA 332 249 11111001 F9 371
219 11011011 DB 333 250 11111010 FA 372
220 11011108 DC 334 251 11111011 FB 373
221 11011101 DO 335 252 11111100 FC 374
222 11011110 DE 330 253 11111101 FD 375
- �·
223 11011111 OF 337 254 111111HII FE 376
224 11100001 EO 340 255 11111111 FF 3TT
225 11100001 El 341
,.
136
APPENDIX J
00
03
NEG
COM
6
'' ",,IC
2 IMMED
INHERENT 2
3 2 2E
2F
'"' '"
6 2 22 SHI INHERENT $ 2
oec
IIA 2 23 8L$ 5 '
0C INC 2 24 8HS18CC 3 2 36 PSHU
"" '
8D TST 6 2 2$ BtOIBCS
'' ,."
ee JMP
'"
8F CLR Olf1EC? 6 2 27 SEO 2 JA ABX
INHERENT 2 28 eve 38 RTI 611 5 1
2 JC CWAI
16 LBRA
11 L8SA
19 OA,A INHERENT 2 1 2C BGE
1A ORCC 3 2 20
"'
U LSRA INHERENT 2 1 SO TSTB INHERENT 2
" ,o,
46 RORA 2 CLAS INHERENT 2
-,o INDE)(EO so,
48 ASLAILSV, oec
'' ''
49 ROI..A 6 2 7C !NC
o. DECA m
•C INCA
TSTA. 66 A$L/L$l 2 7F CLR
•F CtRA 69 ROL 2 ee sue"
50 NEGB
'"
53 COMB SBCA
'
s• LSRB SUIID
..
57 A$RA INOE)(EO 6 BITA
...
5,8 ASLBILSLB
59 ROLB COM
74 LSR 7 3 89 ADCA
SC INCB INHERENT 2 76 ROA EXTENDED 7 ORA
137
"
"" ' '"
' �
IMMEO 2 2 9E
'' """
6C CMPX 4 3 9F DIRECT 5 2 81
.. '"
"
. "
97 STA BB AOOA
' '
98 EORA CMPX
9A ORA
E)(TENOEO 6
9C CMPX C,
CMPB IMMEO
"
CS 81TB
C6 LOB 2 2 DB
coo 2 EE LOU
' '
C, srn
'"
EXTENDED 5
CB ADOB FI CMPB s '
'"
3 3 Ee IN0€)(E0 F2 SBCB s '
ce
'' ""
3 3 E1 CMPB
oe SUBB 2 E2 SBCB
01 CMPB 4 2 EJ 6 2 FS
'"
02 SBCB 4 2 F6
,
2 E6 LOB
05 81TB 2 E7 $TB 2 F9 AOCB
D6 LOB INDEXED 4 ORB EXTENDED 5
'
AODB EXTENDED 5 3 1112E LBGT RELATIVE 5{6) • 10CE LOS
FC LOO 6 3 182F LBLE RELATIVE 5{6) •
6 3 IBJF SWl/2 INHERENT 20 2 10OF ST$
FE LOU IMMEO H�EE LOS
I 1&EF STS
' .
SW EXTENDED 6 1"'8C CMPY
RELATIVE 5 4 1&8E LOY !MMEO
1022 LBHI
1023 LBLS 5(6) • 3 113F SWIil INHERENT 20 2
1'!124 LBHSILBCC 5(6) , Hl9E LOY 3 1183 CMPU
1825 LBCSILBLO 5(6) •
J 1193 CMPU
5(61 ' J 11!1C CMPS
5(6) 4 1ME LOY
5(6) 4 ll)AF STY
1028 LBMI
1&2C LBGE
1820 LBLT RELATIVE
5(6) 4
5(6) 4
516) 4
H�BC CMPY
1&BE LDY
1IBF STY
I ,
EXTENOEO 7
1 38
INDEXED ADDRESSING
POST BYTE REGISTER
BIT ASSIGNMENTS
INDEXED
POST-BYTE REGISTER BIT ADDRESSING
7 6 5 , 3 2 ' 0 MODE
0 X X X X X X X EA • , A :!: 4 BlTOFFSET
1 X X O O O O 0
1 X X X O O 0 ,A+ +
1 X X O O O 1 , -R
1 X X X O 0 ,--R
1 X X X 0 1 0 EA = . A :t O OFFSET
1 X X X 0 1 1 EA • ,A :!: ACCB OFFSET
X 0 O EA • ,A :!: ACCA OFFSET
' X X ' 0 EA = , A :t 7 BIT OFFSET
1 X X X 1 0 0 1 EA ,. ,R :t 1 5 81T OFFSET
1 X X X 1 0 1 I EA • , A :!: D OFFSET)
1 X X X 1 1 O O EA = , PC :t 7 BIT OFFSET
1 X X X 1 t 0 1 EA • , PC :t 1 5 BtT OFFSET
t X X 1 1 1 1 1 EA a ,ADDAESS
PULL ORDER
1
cc 6809 VECTORS
A FFFE Restart
B FFFC NM•
DP FFFA SWI
X Hi FFF8 ,aa
X Lo FFF6 FIAO
Y Hi FFF4 SWI2
Y Lo FFF2 SWl3
TRANSFER/EXCHANGE POST BYTE U/SHi FFF0 Reserved
1 39
INDEXED ADDRESSING MODES
FORMS
CONSTANT OFFSET FROM A NO OFFSET A 1 RR00100 0 0 L Al l1RR10100 3 0
5 8 1 T 0 FFSET n, R ORRnnnnn 1 O de!aults to8-bit
8 81T OFFSET
1 6 81T OFFSET
ACCUMULATOR OFFSET FROM A A-REGISTER OFFSET A. A 1RROOt10 \ 0 IA,RI 1 RR10 1 l 0 4 0
8-REGISTER OFFSET 8, A I A R00101 \ 0 18. AJ 11AA10101 4 0
0-REGISTER OFFSET D. R 1RR01011 4 0 ID.Al 1RRl1011 7 0
UTO INCREMENT!DECREMENT A INCREMENT BY 1
INCREMENT BY 2
DECREMENT BY 1
DECREMENT BY 2
ICONSTANT OFFSET FROM PC 8 81T OFFSET n, PCR 1 )( )( 0 1 100 1 1 In, PCAI 1 x x 1 1 1 00 4 1
1
1 6 81T0FFSET n. PCA 1 x xo1 10 1 5 2 ln,PCR] 1XX11101 8 2
EXTENDED INDIRECT 16 BIT ADDRESS (nl 1 1001 1 1 1 1 5 2
R • X, Y. U . o r S
X w OONTCARE
NOTES·
1 G,ven , n me 111ble arethe base cycles and byte coun1s To determ,ne 1he tot11t cycles and byte counts add lhe values
trom1he '68091ndex,ng modes· table
2. R1 and R2may beany pair ol 8 M or any pair o 1 1 6 b1t reg,s1e1s
The 8 bot registers are A. B. CC. OP
The 1 6 b1t reg,s1e,sa,e X. Y. U. S. O. PC
J EA•s lhe eHect,veaodress
4 n,e PSH and PUL >nst,uct,ons ,equore scye1es p1us 1 cycle to, each ovte pusr.ed 01pulled
5 5(6) means 5 cydes " Dranch not taken. 6 cycles ,1 taken
6 SW1 sets l&F bots SW12andSWl300 no1auec1 1&F
7 Cond11,ons Cooes set asa dorecl result olthe ,ns11uc1,on
8 Va1ue o1 hall·cany llag,s undehned
9 Spec,a1 Case-Carry set � b7 ,s SET
LEGEND:
OP Operat,on Code (Hexadec,mal). Z Zero (byte)
Number ot MPU Cycles. Overflow. 2·s complement
N1,l<Tl0er of Program Bytes. Carryfrom t>o t 7
A1,1rime1,c Plus, Test andset ofuue. c1eared olherw,se
Antnmeuc M,nus. No1 Allected
Mulhply CC Cond,t,on Code Aeg,ster
M Complement ot M Conca1enat,on
- T•ansfer lntc, Log,ca l o r
H Halt-carry hom bitJ, Log,cal ana
N Ne9a11ve (s,9n b11) Log,cal Exclus,ve or
140
'
'
6809 ADDRESSING MODES
INHE RENT DIRECT EXTENOEI IMMEDIATI INDEXED' RELATIVE 53 2 1
..
INSTRUCTIONI
FORMS OP • OP • OP • OP . • OP # OP -• * DESCRIPTION HN
ABX JA 3 B + )(--, X
''
'' , ,.
(UNSIGNED)
ADC ADCA 99 2 B9 3 89 2 A9 4 , 2 • A • M • C-A 1 1 1 1 1
.
0, 1 1 1 1 1
,. .
ADCB 2 " 3 C9 2 E9 4• 2 • B • M · C-B
ADO AOOA 98 2 •• 3 .. 2 AB 4+ 2 + !tlli
AOOB 08 2 F8 3 4+ 2+ B + M- B 1 1 1 1 1
03 6 2 " 7
�· O+MM•l-0 ! l ! I I
.
ADDO 3 �3 3 E3 16 + 2+
ANO ANDA 2 " 3 " 2 .. 4 + 2 + A M-A • I I O •
ANOB o, 2 " 3 c, 2 " 4. 2· M-B • 1 1 0
ANDCC ,c 2 cc IMM - CC ;
"'
ASLB
ASL 0B 6 2 " 7 3 66 6 + 2 + �}��o BB lI ii il !l
., '
'
��9
ASA ASRA 2 S l l • l
,.
ASA 57 2 S I i • !
07 6 S l ! • t
,cc BCC 2 Branch C = O
LBCC 1 0 5(6) 4 Long Branch
c.,
'"' ""'
2C Zero
BGT BGT 2E 3 2 Branch > Zero
LBGT 1 0 5(6) 4 Long Branch >
2E Zero
22 3 2 Branch Higher
LBHI 1 0 5(6 4 Long Branch
22 Higher
BHS BHS 24 3 2 Branch Higher
or Same
LBHS 10 5(6) 4 Long Branch
""
24 Higher or Same
BITA 95 2 65 3 85 2 A5 4 • �' Bit Test A(M A A) • 1 1 O •
81TB 05 2 F5 3 CS 2 ES 4• 2• BitTes! B (M A B) • 1 1 0 •
BLE BLE
LBLE 1 0 5(6 4 Long Branch "'
"'°
2F Zero
8'Q 25 3 2 Branch Lower
LBLO 1 0 5(6) 4 Long 8ranch
25 Lower
"" ""
BLS BLS 23 3 2 Branch Lower
or Same
LBLS 10 5(6) 4 Long Branch
23 Lower or Same
""' ""'
20 3 2 Branch < Zero
LBLT 10 5(6) 4 Long Branch <
20 Zero
2B 3 2 Branch Minus
LBMI 1 0 5(6) 4 Long Branch
28 Minus
BNE BNE 26 3 2 Branch Z 1' o
LBNE 10 �(6) 4 Long Branch
26 Z"0
8PC BPC 2A 3 2 Branch Plus
LBPL 1 0 516) 4 Long 8ranch
2A Plus
1 41
tN::.,Hu..; Tlf.)Ni
INHfRENT DIRECT EXTEND€D �MEDIATE INDE�� REL�:1ve
_ _
7�
"
...
...
FORMS ()p - 11bP - II OP - II bP - 11 bP - II OP _ , II DESCRIPTION Hfl, z v
"
BRA BRA 20 3 2 Branch Always
LBRA 3 LongB<anchAlways • •
BAN BAN 3 2 Branch Never
LBRN ,0 5 4 LongBranchNever • •
,.,
LBSA 3 long 8ranch 10
Subrou1ine
"
8'C 8'C 2 9ranch V = O
LBVC 1 0 516) 4 Long Branch
""
2B
B'5 8'S 3 2 Branch V = 1
"
LBVS 1 0 5(6 4 Lo 9 e anch
C_ ;
.. ... ..
0-A • 0 1 olo
,.
CLR CLRA
2
' ! ��
CLRB o-B • 0 1 0 0
2 "
" B "
CLR 6 7 3 6f l6. 2· 0 -• M • 0 1 0 0
CMP CMPA 2 " 5 3 " 4• 2 + Compare M from A 8 t
11 1
CMPB o, 2 " compare M from B 8 t II I
" "
.
93 BJ AJ !rom D
CMPS 7 3 5 11 7 + 3+ Compare M : M + 1 • t 11 1
!rom S
' .
9C BC ,c AC
CMPU 7 3 5 11 7+ 3• Compare M: M + 1 • I 11 1
93 BJ A3 1rom U
CMPX 9C 6 2 BC 7 3 ,c 3 ,c 16+ 2+ Compare M: M + 1 • t II I
!rom X
CMPY ,0 7 3 ,0 ,0 5 1 0 7• 3• Compare M: M ... 1 • I I II
lrom Y
'
,c BC ,c AC
<l 2
'
COM COMA A-A • : 1 0 1
0-B • : 1 0 1
"
COMB 53 2
COM 03 6 2 73 7 3 63 6 • 2� M-M · : : 0 1
..
CWAI 3C 20 2 cc IMM -CC
Wa,1 tor lnterrupt
'
.
DAA 2 Decimal Adjust A • ! ! O I
'
: � r:
I
• I l l •
'
DEC OECA 2 A- 1-A
8- 1-B · I l l •
"
OECB SA 2
oec OA 6 2 7A 6A 6 • 2 · • I l l •
EOR EORA 98 2 B8 2 Aa 4 • 2 + A .,. M - A • 1 1 0 •
EORB o, 3 c, 2 " 4+ 2• B..- M- B
E<G
.'
A 1 . A2 7 2 A1 - R2'
INC INCA ,c 2 • l t l •
INCB SC 2 B+ 1-B • l l f •
. ,.
INC oc 6 2 7C 7 3 6C 6 + 2+ M• 1-M • I l l •
JMP OE 3 2 7E 3 6E 3 · 2 · EA' - • PC
.....
. . ,_, . "'.
JSR ,o 7 2 BO 3 AD 7 - 2• l.iumptoSubroutine
"
98
°'
I
CD LOA 2 86 5 3 " 2 A6 4 · M-A • ! 1 0 •
2 F6 3 C6 M-a • 1 1 0 •
: : :1 6 :
LOB 5 2 E6 4 ·
"
2 M M • ' -D
. .
LDD De FC 6 3 cc 3 EC 5 · · 1 1 0 •
LOS ,0 3 ,0 7 ,0 10 6 · M M ,
"
DE CE EE
LDU DE 2 " 6 3 CE 3 J EE 5 · M M
,o, 2 BE 6 3 BE 3 3 AE 5 • M M
,o, ,0 3 ,0 7 ,0 10 6 · M M • • 1 1 0 •
BE BE AE
I ·1·1· · ·'1
LEA LEAS EA" - S
LEAU 33 4 + 2 I EA' - U
LEA> 30 4+ 2 EA' - X • • I • •
EA' - Y ••I••
I LEAY I I I I I I I I I I I 3f
1 4 + '�
2 I
1 42
"
INHERENT DIRECT EXTENOEC WAEOIATI INDEXED' RELATIVE Ii J 2 I 0
NSTRlJ
." .."
f1��� p I-' -• # DESCAIFlIOf� ;. t, C.
LSL LSLA
LSLB 56 :}o...mmrn-
M C c., bo
o:i:::
LSL 6 • 1 1 I t
" '
LSA LSAA
LSAB :1o_JI[Jfill)-!
M b, bo c
:gl: l
LSA 6 2 ,. 7 3 • 0 I • t
MUL 30 A >< 8- 0
(Uns,gr.ed)
NEG NEGA 40 2 1 A, 1-A 8 1 1 1 1
NEGB 50 2 1 a+ 1-e e I 1 t1
NEG 00 6 2 70 7 3 60 6 • 2 · M, 1-M B t l l l
NOP 12 2 1 No Operahon
OA ORA 9A 4 2 BA 5 J 8A 2 2 AA 4, 2 • A v M- A • I I 0 •
ORB DA 4 2 FA 5 3 CA 2 2 EA 4 • 2 • t 1 0
�c" � �� - cc . ;
OACC 2
'
PSH PSHS 34 5 • ' 2 Push Reg,s1ers on • • • • •
S Stack
PSHU 36 S , • 2 PushRe91s1erson • • • • •
U Stack
PUL PULS 35 5· Pu11 Reg,ster5 1rom • • • • •
., ''
S S1ack
:ILO-llilIIIDJ : f l f f
PULU 37 5• 2 Pull Reg,sters trom • • • • •
U Stack
"
AOL ROLA 2
: lCO-iiliimP : : : : l
AOLB 59 2
AOL 09 6 2 79 69 6 + 2 • M c b, - bo • I I t I
""
ROA AOAA 2 '
ROAB 56 2 '
"' '
ROA 06 6 2 " 7 3 66 6 · 2 • Mr C b, - bo • ) I • l
3B II ' Retu,n From
lnlerrupt
'" '"
ATS ReturnF,om
' '
Sut>foutme
SBC SBCA 92 2 B2 3 82 2 A2 4 + 2• A - M - C-A 8 t I t I
.' ''
. ·-·--
SBCB o, 3 c, 4• 2• B - M - c- B a 1 1 1 1
s" ,o S19n Ex1end B • 1 1 0 •
on10A
" "
ST STA 97 > B7 A7 4+ 2• • 1 10 •
"
STS ,0 6 3 " 7 10 6• 3• S - M: M • 1 • I I o •
o,
STU o, EF S• 2 • U - M: M + 1 • ! ID•
sr, 2 " AF S • 2 • X - M: M • 1 • ! ID•
m 6 3 Y-M:M • 1 •11D•
AF 6 , 3 <
"
SUBD 93 6 2 83 3 83 4 3 AJ 6• 2 • 0 - M M • l -D • I I I I
SWI SWI" 3F 19 Soltwarelnterrupt l • • • • •
SWl2" 10 20 Sottwa1e lntern.,pt2 • • • • •
SWl3' 11 20 2 SottwarelnterruptJ • • • • •
3F
SYNC 13 2 1 Syncruon,zelo
lnte.,ul)I
TFR R 1 , R2 1F 7 2
TST TSTA 40 Tes1 A • 1 1 0 •
TSTB SO TestB • l l 0 •
TST OD 6 2 70 7 3 Tes1 M • 1 1 0 •
143
INDEX
A END . 14
ABS . . . . . . . 28 EOF . . . . . . . . . . . . . . .29
Addressing modes . . . . . . . . . . . .85-89 Errors in BASIC . . . . . . . . . . . . 35
AND . . . . . . .5,6 Error messages . .123
Arrays . . .4 EXEC . 14,99
ASC . 28 EXP . . . . . . 29
ASCII . . 10, 130 Exponential Format . . . . . .3
Assembler graphics . . 54, 112 Extended Addressing . . . . 86
Assemblersound . . . . . . . . . . . . . . . . . . . . .72, 114
ATN . . .. 28 F
AUDIO .7 Files . 9, 17, 19, 24,27,29
•
Autokey repeat . . . . . . . . . . . . . . . . . . . . . . 106 FIX . . .29
FOR/TO/NEXT 14
Bose Conversions . G
BASIC GET . . . . . . . . . . . . . . . . . . . . . . . . . 15, 53, 1 1 4 , 1 1 8
- address space . 8,31 GOSUB/RETURN . . . . . . . . . . . . . . . . . . 15
-commands 7-35 GOTO . . . . . . . . . . . . . . 15
-constants . . . . . . . . . . . . . . . . . .3,4,7,29 Graphics . . . . . . . .36-69
-error messagas . . . . . .. 123, 124 - Hi-res . . 36, 38, 46-54
-el(press10ns . . . . . .5 - Lo-res . .37,42-46
- keywords . 2.109. 120-121 - Modes . . . . . . . .37,39. 55-69
- lines . . . . . .7 - Using S1rings . . . . . . . . . .43-46
- symbols . . . . . . . . . . . . . . . . . . . . 122
-variables . . . . . . .4,6,7,98 H
BLINK . . 93 HEX$ 29
BLKIN . . 94 Hexadecimal . . . . . . . . . . . .3,29
BLKOUT . . . . . . . . . . . . 94 High Resolution graphics . 36,38, 46-54
Boxes . . . . 110
BYTEIN . 94 I
IF/THEN/ELSE . . . . 16
C Immediate Addressing . . .86
Cassette recorder . . . .7-11, 17, 19,24, 27,29, 102 Indexed Addressing . . . . . . . . . . . 87,88
CharacterCodes . . . . . . .44, 128, 132 Indirect Addressing . . . . . .89
Characters in hi-res . . .. 118 Inherent Addressing . . . . . .85
CHA$ . 28 INIT . . 93
CHROUT . . . . . 95 INKEY$ . . 29
CIRCLE . . . 49. 110 INPUT . . 16
CLEAR . . . . .8,90 INPUT# . . . . . . . . . . . . . 17
CLOAO . . 9 INSTA . . . . . .30
CLOADM . . .9 INT . . . 30
CLOSE . . . .9
c� . ,o.a J
COLOR . . . . . . . . .10,48 JQYIN . .95
ColourCodes . . . . . . . . . . . . . 126 JOYSTK 30
Colour Sets . . 46, 127 Joysticks . 101
Conditions . . . . . .6, 16
CONT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 K
Conversion . . .5,33,34 Keywords . . . . . . . . . . . . .2, 109, 120, 121
cos . .29
C.P.U. . .82, 104 L
CSAVE . . 10 LEFT$ . JO
CSAVEM . . . . . . . . . 1 1 , 90 LEN . . . . . . . . . .30
CSADON . . 94 LET . .17
LINE . . .18,49, 1 1 0 . 1 1 2
D LINE INPUT . . . . . . . 18
DATA . UST .17
DEFFN . 11 LUST .. 1 7
DEF USR . . 12 LOG . . . . . . . . . . . .31
DEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Low-resolutiongraphics . 37,42-46
�M . . . . A, 12
Direct Addressing . . . . .86 M
Disable/Enable BREAK key 105 M6809
DRAW . 12,51, 118 - instruction set .
E
Edge Connector . . . 103
EDIT 13
ELSE . 16
Memo� SET . . . . . • • . . . . . • . .26,43, 106
- map . . . . . . . . . 93-96, 125 SETUP .. • . . . • . . . • . . . •93
-video · · · · · · · · · · · · · · · · · · · · · · · · · . . .39,40 SGN . . .33
Merge • . . . . . . . . . . . 106 SIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33
MID$ . . . . . . . . . . . . • • . . • . . . . . . . . . . . . . . . . . . . .31 SKIPF . . . . . . . . .27
MOTOR . . . . . . . . . . . . . . 19 SOUND . . • . . . . . . • • . . . • • . . • • . . .27, 70
Moving Graphics . . . . . 11• SpeachReproduction . • • • . • • . . . . •73-80
Music . . . . . . . . . . . . . . . . . . . . . . . . . . . 21, 27.70-80 SJ:-:ling Things up . . . . . . . . . . . . . . . . . . . . . . . .104
SOR . . . . .33
Startofscreen memory . . . . . . . . . . . .40-42, 47, 1 1 0
STRING$ . . . . . . . . . . . . . . .33
STRS . ..33
String
Numeric - oonstants . . . . . . . . . . . . . . .3,7
- constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 - space/stack .• . . . .8,98
- variables . . . .4, 98 - variables . . . . . . . . . . .4, 7, 98
SubscriptS . • . •4
0 Symbols . • . . . . . . . . . . . . . . . . . . . .5
Octal . . . . . • .4 Syntax . . . . .2
ON- GOSUB . . . . . 19
ON- GOTO . . . . . . . . . . . 19 T
OPEN . . . . . . . . . . . . . . . . . .9,19 TAN . . . . . . . . . . . . . . . . . . . . . . .34
OR . . . . . . . . . . . . .5,6 Text . . . . . . . .36,37
THEN . . . . . . . 16
p TIMER . . .34
PAINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20, 53 Ti mes . . • . .2
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 TO . . . . . . . . . . . . . . . . . . . . . . . 14
PCLEAR . . . . . . . . . . . . . . . . . . • . .20, 46 TOUCH . . . . . . . . . . . . . . . .93
PCLS . . . . . . . . . . . . . . . . . . . . .20,48 TRON/TROfF . . . .27
PCOPY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21, 48
PEEK . . . . . . . . . . . . . . . .31 u
PLAY . . . . . . . . . . • . • • • . . . • . .21, 70 USA . . . .34,99
PMOOE . . . . . • • . . . . .21, 47, 110
POINT • . . . . . . . . . . . . . . . .32 V
POKE . . . . . . . . . . . . . . . . .21 VAL . . • • . . • . . . • . . .34
POLCAT . . . . . . . . . . . . . . . .95 Variable
P0S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32 - names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4,6
PPOINT . • • • • . . . . . . . . . . . . . . . . . • • . . . • . . . 32, 49 - stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .97
PRESET . . . . . . . . . . . . . . . . . . . . . • . . . . . . . . .22, 48 VARPTR . . . . . . . . . . . . . .35
PRINT . • • • . . . . . . . . . . . . . .22 V.D.G. . . . • • • . . . . • . . . .37, 40, 41
Printer . . . . . . . . . . . .9,24, 101 Video Memory . . . • • . . • . . . •39, 40
PRINT USING . . . . . . . . . . . . . . . . . . . . . . .22
PRINT@ . . . . . . . . . . . . . . . . . . . . . . . . • . . . • . . . . • 24 w
-grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 29 WRTLDR . . . . . . . . .94
PRINT# . . . . . . . . . . . . . . . . . . . .24
PSET . . . .24,48
PUT . . . . . . • • . . . . . . . . . . . . . . . . .24. 53, 114. 1 1 8
R
READ . . . . . . . . . . . . . . . . . . . . . . .25
Reading two keys at once . . . . . . . . . . . 107
Recovering from a NEW . . . . . . . . . . . . . . . . . . 107
Redefining BASIC keyworcls . . . . . . • . . . . . . . . • . 109
Register Addressing . . . . . . . . .89
Registers- C.P.U. . . . . . . . • . . . . . . . . . . . . .84, 85
Relative Addressing . . . .86
REM . • . . .25
RENUM . . • • • • . . . . . . . . . . . . . . . . . • . . . . . . . . . . .25
RESET . . . . . . . . . . . . . . . . . . . . • • • . . . . . .25, 43, 106
Resolution . . . . . . . . . • . . • • . . . . . . . . . . . . . . . .37,47
RESTORE . . . . . . . . . . . . • • • . . • • . . . •26
RETURN . . . . . . . . . . . . . . . . . . • • • . . • . . . . . . . . . .26
RIGHTS . . . . . . . . . . . . . . . . . . • • • . . . . . . . . . . . . . . .32
AND . . . . . . . . . . . . . • . . • . . . . • . . . . . . . . . . . . . . . .32
ROM Routines . . . . . . . . . . . . . . . . . .93-95
RUN . . . . .26
s
SCREEN . .26,46
Scrolling . . . . • . • . . . •1 1 2
Semigraphics . . . . . . . .37,42-46
DllAliON 32
pragrammer•s reference guide
REGISTRATION CARD
Please fill out this page and return it promptly in order that we may keep
you informed of new software and special offers that arise. Simply cut
along the dotted line and return it to the correct address selected from
those overleaf.
Please tell us what software you would like to see produced for your
DRAGON.
Name . . .
Address
. . . . Code