Professional Documents
Culture Documents
Stefan Dittrich
**********
Abacus HBffiffl
First Edition, October 1986
Printed in U.S.A.
Copyright © 1985 Data Becker GmbH
Merowingerstr.30
4000 Dusseldorf, West Germany
Copyright © 1986 Abacus Software, Inc.
P.O. Box 7219
Grand Rapids, MI 49510
ATARI, 520ST, 1040 ST, ST, TOS, ST BASIC and ST LOGO are
trademarks or registered trademarks of Atari Corp.
GEM, GEM Draw and GEM Write are trademarks or registered trademarks
of Digital Research Inc.
ISBN 0-916439-56-9
Preface
The Atari ST offers new dimensions for the personal computer owner. It
has great flexibility and ease of use at a very attractive price. Thanks to
the user-friendly GEM operating system and mouse, the ST can be easily
learned and used by the novice.
The purpose of this book is to give the ST user a closer look at many of
the functions of his computer. We'd like to think of this as a "travel
guide" through the fascinating world of the ST. On this trip you'll see
some remarkable sights and many helpful signposts to help you find the
right direction. The program examples will reveal many of the
capabilities of the computer. And you'll be able to implement your own
applications.
As you may gather from the title, we'll use the BASIC commands PEEK
and POKE to investigate and influence the operation of the ST. Using
these two commands and our knowledge of several internal tables
containing important system parameters, we'll be able to manipulate the
ST's operating system.
Stefan Dittrich
n
CONTENTS
Preface
2 Memory Structures 23
2.1 Internal Memory 25
2.1.1 Address Assignment of the ST 26
2.1.2 The Addresses of the I/O Chips 27
2.1.3 Error Vectors 28
2.1.4 Pointers 29
2.1.5 Stacks 32
2.2 Disk storage 34
2.2.1 Program Files 35
2.2.2 Data Files 36
2.2.3 Graphic Data Files 37
3 Computer Mathematics 39
3.1 Number System Conversion 44
3.2 Bit Evaluation 45
3.3 Logical Operators 46
m
4 The Operating System 49
4.1 The Tramiel Operating System 52
4.1.1 The BIOS 52
4.1.2 System Variables 53
4.1.3 Talking to the TOS 56
4.2 GEM 59
4.2.1 GEM Programming from BASIC 59
4.2.2 Getting Input from the Mouse 61
4.2.3 Changing the Mouse Form 62
4.2.4 Changing the Font 66
4.2.5 Graphic Text 67
5 The Desktop 71
5.1 Customizing the Desktop 73
5.2 Setting the RS-232 Interface 76
6 Programming Languages 79
6.1 DRLOGO 82
6.2 ST BASIC 84
6.3 The C Language 85
6.4 68000 Machine Language 88
6.4.1 Combining Machine Language and BASIC 98
7 BASIC Programming 103
7.1 Graphics 107
7.1.1 Circles, Ellipses and Squares 107
7.1.2 Text on the graphics screen 111
7.1.4 Shading surfaces 116
7.1.5 Creating your own shading patterns 117
7.1.6 Setting markers in the display 119
7.1.7 Testing points on the screen 121
7.1.8 Mixing colors 121
7.2 Music and sound 123
7.3 Window and Menu programming 130
7.4 Text processing 137
7.4.1 Templates 138
7.5 Mouse/Joystick Control 140
7.6 Input/Output 142
7.6.1 Printer Control 142
7.6.2 Using Disks 144
7.6.3 Telecommunication 148
7.7 Character Editors 151
IV
7.8 The Keyboard Buffer 158
Index 171
Chapter 1
Treating the ST like any other computer would be a big mistake. Few
other personal computers offer so many special features that will help
even experienced programmers. This is not because of the powerful GEM
user interface, which makes the ST user-friendly and easy to operate. It's
also because the ST's hardware is so advanced that it can be used for
nearly every personal programming application. For an overview, we
have to look under the cover of the ST to view its individual components.
Let's take a glimpse at the internal operations of this remarkable
computer.
The outside of the ST doesn't indicate what is hidden inside. You might
think, "That's really a nice-looking computer, but a little computer like
that can't do much!"
The small housing of the ST (compared, for example, with the IBM
PC®) hides an incredible amount of the latest technology. This
technology gives the ST many new capabilities. Let's take a look at some
of these new capabilities.
First there is the central processing unit, or CPU, which is the "brain" of
the computer. This processor is the MC 68000 from Motorola. It is the
largest component on the main circuit board. This processor has
incredible specifications:
The computer works internally with 32-bit words—in other words, with
values up to 2 32 - 4,294,967,296. It has 16 data lines (this is the reason
it's described as a 16 bit processor). These large numbers mean the
computer can process a lot of data in a short time. This processor operates
at 8 megahertz. This means it can execute up to eight million instructions
per second. However, this is a theoretical value, since many instructions
require several cycles. Nevertheless, the ST's speed is tremendous, as you
can see during graphic presentations on the ST .
The "workers" in the ST are the additional chips that support the
processor. There is an additional intelligent chip in the ST keyboard. It is
called the HD 6301VI and has an important job: it monitors all keyboard,
mouse and joystick functions. Furthermore, this contains a clock which
counts in seconds. For more information on the 6301 and the keyboard
see Section 1.3, "The Intelligent Keyboard."
There are a few more special chips which make the ST the remarkable
computer it is. The integrated circuits used were developed specifically
for the Atari 520ST. The GLUE coordinates all the interactions of these
ICs. Another chip is the MMU, or Memory Management Unit. This unit
administers the working storage of 512K. The MMU is capable of
handling up to 4 megabytes. The newest version of the ST, the 1040 ST,
has 1 megabyte of working memory.
Next is the shifter chip. It controls the picture on the monitor. It also
interprets the video memory in both monochrome and color modes, and
sends the corresponding video signal to the monitor. The monitor
connection of the Atari is located on the shifter. Video signals are
available at the monochrome port, or RGB-signals at the red, green and
blue ports. Information on the type of monitor attached is sent to the
computer through the monochrome-detect port, which is set at either +5
volts for monochrome or 0 volts for RGB.
Another important chip is the DMA controller (DMA stands for Direct
Memory Access). It accesses the ST's working memory directly and is
used to transfer data to and from the disk drives or hard disk. The high
speed of these data transmissions would overwhelm the CPU, so the
DMA controller performs data transfer instead.
All of these chips are programmable by the user. You can program the
sound chip with the BASIC commands SOUND and WAVE. Each IC has
an area of memory reserved for its exclusive use in which it stores its
variables and parameters. Information exchange takes place in this
reserved memory. We'll go into more detail on this later in Section 2.1.
Atari ST Peeks and Pokes A Look Inside The ST
1.2 Interfaces
• Parallel
or
• Serial
Parallel data transfer means that the entire byte is sent to the receiver at
once. The advantage of this method is the high speed of transmission. The
disadvantage is that it requires eight "wires", one for each data bit.
A typical example of a parallel interface is the Centronics port. Usually it
is used to connect to a printer, since it can only transmit data in one
direction, i.e. from the computer to the printer. The Centronics port is
located on the back of the ST and is labeled by a printer pictogram.
The physical connection between this plug and the printer (Epson, for
example) is through a cable with at least 11 wires, as follows:
Computer Pin Wire Printer Pin
1 Strobe > 1
2 Data 0 > 2
3 Data 1 > 3
4-9 Data 2-7 > 4-9
11 Busy < 11
18 Ground 19
Abacus Software Atari ST Peeks and Pokes
As you can see, the busy signal line is connected to the computer. This
return line is called the handshake line and is required to ensure the
reliability of the data transmission.
All printer output from the other computer will now be output to the
output window of the ST. We can transfer data between computers
without RS-232 ports using this method.
Atari ST Peeks and Pokes A Look Inside The ST
The serial interface transfers data, bit by bit. Therefore only one line is
required—but, ironically, serial data transmission is more complicated
than parallel transmission.
2 TD
Transmit data
3 RD
Receive data
4 RTS
Ready to send comes from I/O port A bit 3 of the sound chip and
is always high when the computer is ready to receive a byte. On
the Atari, this signal is first placed low after receiving a byte and
is kept low until the byte has been processed.
Abacus Software Atari ST Peeks and Pokes
CTS
Clear to send of a connected device is read at interrupt input 12 of
the MFP. At the present time this signal is handled improperly by
the operating system. Therefore it is possible to connect only
devices which "rattle" the line after every received byte (like the
520ST with RTS). The signal goes to input 12 of the MFP, but
unfortunately is tested only for the signal edge. You will not have
any luck connecting a printer because they usually hold the CTS
signal high as long as the buffer is not full. There is no signal high
as long as the buffer is not full. There is no signal edge after each
byte, which means that only the first byte of a text is transmitted,
and then nothing.
GND
Signal ground.
DCD
Carrier signal detected. This line, which goes to interrupt input II
of the MFP, is normally serviced by a modem, which tells the
computer that connection has been made with the other party.
20 DTR
Device ready. This line signals to a device that the computer is
turned on and the interface will be serviced as required. It comes
from I/O port A bit 4 of the sound chip.
22 RI
Ring indicator is a rather important interrupt on 16 of the MFP and
is used by a modem to tell the computer that another party wishes
connection, that is, someone called.
the data is transmitted is called baud rate. This number (for acoustic
modems 300) indicates the number of data bits transmittedper second.
If you don't know anyone who owns a modem, you can contact a bulletin
board service (BBS). These online information exchanges are offered by
many private and public agencies, and even individuals. The phone
numbers are available in trade papers, magazines, and by word-of-mouth.
The large round port on the back of the ST identified by a floppy disk
drive picture represents the connection for one or two disk drives. It is
controlled by the WD 1770 disk controller, which converts the operating
system commands into electronic signals that the disk drive can respond
to. If, for example, you want to see the directory of a diskette, GEMDOS
asks the controller to provide the data from the corresponding sector of
the selected diskette. The controller has to perform these steps :
For double-sided drives it must also specify which side of the disk to
store the data on. This signal comes from the sound chip(!). The standard
floppy unit, SF 354 drive, which writes 500K in unformatted condition,
10
Abacus Software Atari ST Peeks and Pokes
writes only on one side. Double-sided units are fully supported and can
be connected directly, however. The pin assignment is as follows:
21 R Nam? Significance
1(30) Read Data Carries the signal from the read/write head
2(32) Side 0 Select Selects which side of diskette to use
3(3) GND Ground (0V)
4(8) Index Pulse One signal per revolution
5(10) Drive 0 Select Selects drive 0
6(12) Drive 1 Select Selects drive 1
7(33) GND Ground
8(16) Motor on Turns motor on
9(18) Direction In Determines direction of read/write head
10 (20) Step Moves one step in or out
11 (22) Write Data During write data signals from the
computer
12 (24) Write Gate Signal permits writing data
13 (26) Track 0 Announces that outermost track has been
reached
h 1(28) Write Protect Signals that the diskette is write protected
The signals are standardized and correspond to the bits of the Shugart
connections. It is therefore easy to connect other disk drives.
Before a diskette is used for the first time it must be formatted. Choosing
the desktop menu 'Format' and the prompt OK will give you a choice of
formatting your disk as either single- or double-sided. With a single-side
unit you should never select 'Double-Sided', but you can format both
single- and double-sided disks with a double-sided disk drive. During
formatting, the tracks on the diskette are erased and individual sectors are
determined. Be careful: all data which had been on the diskette is erased!
11
Atari ST Peeks and Pokes A Look Inside The ST
On the back of the ST are two 5 pin DIN (Deutsch Industry Norm) ports.
They are identified as MIDI-In and MTDI-Out and support electronic
musical instruments such as synthesizers.
MIDI stands for Musical Instrument Digital Interface and this interface
has been built into many music synthesizers. If the ST is connected with
one or more synthesizers (up to 16), the ST becomes a musician that is
capable of recording melodies being played or controlling the
instruments. The information exchange is serial, following the same
principle as the modem port, but the transmission speed is a rapid 31,250
bits per second.
On the left side of the computer is another less obvious connector port. It
carries no designation, but accommodates a 40 pin cartridge. Such a
cartridge can be equipped with ROM memory up to a maximum of 128K.
Possible applications are enhancing the operating system, utility
12
Abacus Software Atari ST Peeks and Pokes
The two plugs on the right side of the ST are for joysticks. Plug 0 can
also be connected to the mouse. The main difference between joystick
and mouse lies in the joystick having a signal pin for every one of the
four directions on which it can place a LO signal (0V). The mouse, on the
other hand, provides further direction impulses to the system, since it can
be moved at various speeds.
13
Atari ST Peeks and Pokes A Look Inside The ST
The mouse/joystick plugs are only for input. The keyboard processor
does not have a command to change the direction of data transfer. It is
possible but impractical, to replace the processor with a unit whose
operating system would recognize additional commands. Output signals
are easily routed through the parallel port (printer), while this plug is also
well suited for input signals. Digital technology often uses the signal
voltages OV (LO) and +5V (HI); these correspond to the TTL level (TTL
= Transistor-Transistor-Logic). To read a key from the computer, it only
has to be connected to ground (Pin 8) and one of the pins 1-4.
A monitor lets you see what the computer is doing. The Atari ST provides
a connector for a monitor. The ST has a connector for using either the
SMI24 monochrome monitor or the SCI224 color monitor.
The newer 520 ST also has a connector for attaching a television set.
Below is the pin layout of the monitor connector:
14
Abacus Software Atari ST Peeks and Pokes
The micro-processor built into the keyboard has many tasks to perform. It
takes a load off the main 68000 processor by a constant surveillance of
the mouse and keyboard. With its own memory, the keyboard processor
is capable of monitoring the status of the mouse, keyboard and joystick
and making this information available to the 68000 at any time on
demand. The main processor does this by sending a serial command and
parameters to the keyboard processor, which returns the desired
information. This happens at a speed of 7,812.5 bits per second. The
keyboard processor is programmed so that it can perform the commands
following:
Command Reaction
15
Atari ST Peeks and Pokes A Look Inside The ST
Using the BASIC command OUT 4, n the keyboard senses the condition
of joystick 1 and reports it to the central processor. The operating system
stores this information in location 3592, where it can be read with the
PEEK (35 92) function. This value represents the joystick position in
binary. Bits 0 and 1 indicate the vertical motion of the joystick. Bit 2 and
3 are for the horizontal direction. As you can see, the function does not
require a parameter. This is illustrated with the next sample program.
16
Abacus Software Atari ST Peeks and Pokes
To see the results of this program: Enter this program, run it and then
enter the Editor and move the mouse.
Here we're telling the keyboard to output the movement of the mouse as
if the cursor keys were being used. This is useful in BASIC program
editing, since this program allows you to rapidly move the cursor across
the screen. The delay values in lines 30 and 40 signify the horizontal or
vertical movement of the mouse for each cursor step. You should not use
large values if you have only a moderately large desk. To see the mouse
again as a pointer, enter the command OUT 4,8. As illustrated, the
values given are entered as OUT commands. You must be very careful to
maintain the correct parameter number, because an incorrect parameter
can stop the data transmission between keyboard and the computer.
17
Atari ST Peeks and Pokes A Look Inside The ST
110 end
130 rem *** Set Time/Date ***
140 out 4,27 rem Set Time command
150 print "Please input Date/Time
(YYMMDDHHMMSS)"
160 input a$ : rem Input
170 for i - 1 to 6 : rem BCD Calculation
180 d =0
190 d =d + asc(mid$(a$,i*2,l) ) -48
200 d =d + (asc(mid$(a$/i*2-l,l))-48)*16
210 out 4,d : rem Set Parameter
220 next i
230 a$="" :goto 10 :rem Output new Time
Actually these are two separate programs. Program 1 displays the actual
date and time. The format is year, month, day, hour, minute, second. The
use of the format in the text variable a$ is completely up to you.
Furthermore, the function can be made into a subroutine by changing the
END statement in line 110 to RETURN. The most complicated part of the
program is the change of the BCD form (Binary Coded Decimal) into
individual numbers. In this coding method, each date number only uses 4
bits of a data byte. For example, the value of the BCD number 31 is $31,
which corresponds to a decimal 49 (See also chapter 2.1).
The same number occurs in the conversion of single numbers. In Line
130 the routine begins to set the date. After calling the 'Set Time'
command (function 27), the time is entered. For example, 053010192015
stands for the date October 30,1985 at 19:20 and 15 seconds. The 8 is
automatically added for the year. This value is automatically converted to
BCD numbers and passed to the keyboard. The statement goto 10 in
line 230 serves to determine if the function was correctly executed, and
can be omitted.
18
Abacus Software Atari ST Peeks and Pokes
If you remove the REM from line 140, this program will branch to the
selected program section after you press a function key. You can give
these sections almost any name you want instead of Fl - FlO. This type
of programming is used for menu control.
19
Atari ST Peeks and Pokes A Look Inside The ST
The mouse with its two buttons is a fast and convenient input device.
Every movement of the mouse is registered onscreen in X and Y steps
with a resolution of four steps per millimeter. How does this work?
A look into the inner housing of the mouse gives some answers. If you
remove the ball by sliding the cover away on the bottom of the mouse,
you see three small metal rollers. The large roller serves to stabilize the
ball. The others transmit the corresponding rolling motions through a
perforated disk which has two light sensors.
The processor chip in the keyboard, the HDV 6301 VI, evaluates the four
impulse sequences. Assuming you move the mouse forward in the Y
direction, the processor obtains two opposing impulse sequences at the Y
input. At first, the processor waits for both direction signals to be set HI,
and recognizes the direction the mouse has been moved by the drop of the
first of the two signals to LO level. The same procedure is applied to to
movement in the X direction, so that the actual direction of the mouse
movement can be recognized.
20
Abacus Software Atari ST Peeks and Pokes
This program is entered with the LOGO editor and called later in the
command level with DRAW.
This is a recursive program—-that is, the program can call itself. This is
accomplished by the command DRAW at the end of the procedure. The
second line shows the syntax required for the LOGO command MOUSE.
This can be regarded simply as a variable with values listed one behind
the other. The sequence of the individual entries in this list is [x y Bl
B2 B3 ], where x and y are the current coordinates of the mouse pointer.
Bl and B2 signify the status of the two keys on the mouse-Bl for left
and B2 for right. They are TRUE when the corresponding key is pressed.
B3 indicates if the mouse indicator is located in the graphic window of
LOGO (TRUE when yes). In the above sample program the fourth entry
(ITEM 4 MOUSE) shows the use of the right cursor key. With this
instruction a line is drawn to the mouse indicator when the right mouse
key is pressed.
When you run the program, you will find that nothing happens if you
move the mouse while pressing a key. This also occurs in BASIC
programs. The reason for this is that GEM must draw the mouse pointer
continuously while the mouse is moving. This keeps the computer from
doing anything else. This side effect can be useful if you want to stop a
program temporarily, and roll the mouse around while you read the
output values.
One tip for owners of an older model Atari or a similar home computer:
the plug on the mouse can be inserted into any joystick port. Through a
very fast machine language program, the mouse can be connected to your
old machine and used for input. The reading of the mouse inputs must
occur about 1,000 times per second, since the conditions change with a
movement of 1/4 millimeter!
21
Chapter 2
Abacus Software Atari ST Peeks and Pokes
Memory Structures
25
Atari ST Peeks and Pokes Memory Structures
From the variable memory locations, we now come to the fixed memory
locations—the ROM (Read Only Memory). These are permanently
programmed ROM chips whose contents remains intact, even without
power. In the new version of the ST, the operating system TOS is
installed in ROM so that it is available immediately after power-on. In the
earlier computers of the first series, the ROM contained only a program
which loaded TOS from the disk. The only advantage of the disk based
TOS is the capability of altering the operating system.
Let's examine the entire memory area of the ST. Since the computer has
an address bus of 24 bits, it can directly address 224 or 16 megabytes. This
enormous addressable area is not completely occupied with memory
chips. The following table shows the memory assignment of the
computer.
26
Abacus Software Atari ST Peeks and Pokes
Ac urn, />o«
27
Atari ST Peeks and Pokes Memory Structures
(or you see cherry bombs!). These parameters are called vectors, i.e., in
these memory locations are the jump addresses the computer branches to
when program interruptions occur. These interruptions are called
exceptions and are caused for various reasons. For example, the computer
gains access to protected areas of memory (I/O or also other
vector/tables) by using these exception vectors. The table is organized as
follows.
28
Abacus Software Atari ST Peeks and Pokes
$11C Unused
$120 HSync
$124 RS-232 transmission error
$128 RS-232 transmit buffer empty
$12C RS-232 receive-error
$ 130 RS-232 receive buffer full
Not every vector is used, but many are used quite often. The number of
the vector corresponds to the number of cherry bombs that are displayed.
After a system crash, you can guess the cause simply by counting them.
When such a crash occurs, the operating system tries to recover as best as
possible. Often it does not succeed, and you must push the reset button.
To resume operations, the computer requires the information about the
conditions before the crash. This information was saved by the operating
system in the following locations:
2.1.4 Pointers
29
Atari ST Peeks and Pokes Memory Structures
this pointer, the BIOS and the GEM can determine the location of video
RAM. Thus a program can address, through a pointer, the memory areas
whose location may differ for various models of the ST.
Here's another example. To access the video RAM, we need only read
the value of this pointer and use it as an address.
10 rem *Set display point with POKE 2.1.4*
20 defdbl a: p=1102: rem 1102 = $44E
25 a=peek(p)
30 z =20 : rem Display line
40 s =5 : rem Display column
50 bz =peek(10556) : rem Byte per line
60 for i = 0 to 10 :rem Start of loop
Lines 20 and 25 show one of the "tricks" in using pointers from BASIC.
You may recall that an integer variable normally yields 16 bits of
precision. Since the memory addressing range of the ST far exceeds the
64K of a 16-bit value, we must use a 32-bit integer.
The operating system does not have to go through this process, since the
processor can work directly with long words. The composition of the
desired display address takes place in lines 50 and 60. A character is
really a matrix consisting of 16 x 8 points. You can write a character on
the screen as follows, but let us first change the above program slightly:
70 read x$ : rem Read sample line
80 x=0 : for j = 1 to 10: rem Evaluation
90 x= x-(mid$ (x$,j,l)="*") * 2M10-J)
100 next j
110 poke a + s + (z+i)*bz,x: rem Read line
115 print x
120 next i
130 end
135 rem Sample Data
149 data "
150 data " **
160 data " ****
170 data " ****** '
180 data " ** ** ** '
190 data »**********'
200 data "** **** **'
30
Abacus Software Atari ST Peeks and Pokes
Now we have bypassed the operating system and drawn a smile on the
screen. But what happens if the value of the vector is changed? Let us try
to 'bend' the pointer a little by inputting the following:
poke 1104,peek(1104)+1600 <Return>
The display jumps down and can be checked using any window. The
operating system is misled by the false pointer address and assumes the
wrong memory area for the video display! Let's put everything back to
avoid other unpleasant effects.
This statement line restores the screen to its original state. However, there
are many pointers that cannot be 'bent' as easily as the video display
pointer. These vectors represent jump addresses (pointing to machine
language routines) to which the system will branch. An important use of
these jump addresses are the interrupt vectors. Interrupts are program
interruptions that occur in order to allow the processor to perform needed
internal tasks.
31
Atari ST Peeks and Pokes Memory Structures
This program should be saved to disk, since you'll probably use it often
to POKE around.
2.1.5 Stacks
32
Abacus Software Atari ST Peeks and Pokes
The stack works on a LEFO basis. This acronym stands for last-in-first-
out. The last plate stored is the first plate retrieved. In the ST, the last data
stored on the stack is the first data retrieved from it.
33
Atari ST Peeks and Pokes Memory Structures
Floppy disk storage is the most common method of storing large amounts
of data. The ST uses a 3.5 inch diskette. These are more expensive than
the more common 5.25 inch diskettes, but are more durable and easier to
handle. With either size, the storage technology is basically the same.
If you slide the metal safety cover on the 3.5 inch diskette, you'll see a
dark brown 3.5 inch diameter "disc." It has a magnetic coating similar to
that on audio cassettes. This "disc" turns inside the housing at a constant
speed, where the disk drive's read/write head can transfer electrical
impulses.
The SF354 is a single-sided drive with one read/write head that reads and
records data on the bottom side of the diskette.
The SF314 is a double-sided drive with two read/write heads that read
and record data on both the top and bottom sides of the diskette.
34
Abacus Software Atari ST Peeks and Pokes
A SF314 double sided disk drive has 160 tracks. Tracks 1 to 80 are on the
bottom side of the diskette while tracks 81 to 160 are on the top side of
the diskette. Again, each track is made up of 9 sectors and each sector
stores 512 bytes. This makes the storage capacity 160*9*512 = 737,280
bytes.
In general, there are three major types of files: program files, data files
and picture files.
From the last section we know that a diskette is organized in tracks and
sectors. Finding a place to store programs or data on the diskette is not so
easy. This is one of the functions of the operating system.
The operating system has built in functions for managing space on the
diskette. When you load a program, the operating system uses these disk
management routines to locate and activate the program from diskette.
35
Atari ST Peeks and Pokes Memory Structures
When you save a program, these routines find space to transfer the
program from the computer's memory to the diskette.
You can store relatively large amounts of data on a diskette. This data is
then easily exchanged by physically using the diskette on other ST
computers.
36
Abacus Software Atari ST Peeks and Pokes
By using the BLOAD and BSAVE commands, you can load and save
ranges of the ST's memory directly from/to the diskette.
For example, you can save the contents of video memory to a diskette,
thereby saving it as a "snapshot."
10 gosub 100
15 fullw 2: clearw 2
20 gosub 200
30 end
100 rem *** Display.BAS 2.2.2***
110 defdbl a : a=1102
120 b=peek(a)
130 bsave "picture.dat", b, 32000
140 return
200 rem *** Load Picture ***
210 defdbl a : a=1102
220 b=peek(a)
230 bload "picture.dat" ,b
240 return
The two parts of the program are called as subroutines with GOSUB 10 0
or 200. The selected file name "PICTURE.DAT" can be changed.
However, the file name can be at most 8 characters long and contain a
three position extension (here . DAT) where the period does not count.
Characters beyond this are ignored. Furthermore, you must be sure that
the first character in the name is alphabetic (A - Z).
37
Chapter 3
Abacus Software Atari ST Peeks and Pokes
Computer Mathematics
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F mi
41
Atari ST Peeks and Pokes Computer Mathematics
To more clearly see the "bit configuration" of the byte, we often divide
the hexadecimal number into two nibbles. Thus the first hexadecimal
digit is the first nibble and the second hexadecimal digit is the second
nibble, as below:
hexadecimal hvfp
number ujic
2 C 0010 1100
As you might guess, the nibble is actually a half-byte whose binary value
is equivalent to the hexadecimal digit. For some purposes, it is easier to
visualize the value of a byte as two nibbles.
The 68000 processor uses neither the decimal nor the hexadecimal
number systems. Since it is an electronic device it distinguishes between
two different conditions or states, for example 0 volts or +5 volts.
42
Abacus Software Atari ST Peeks and Pokes
bit position 7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
power of 2 2 2 2 2 2 2 2 2
The binary value 01100100 thus corresponds to the decimal value 100 as
follows:
Representing numbers in the binary system takes time and a lot of writing
space.
43
Atari ST Peeks and Pokes Computer Mathematics
44
Abacus Software Atari ST Peeks and Pokes
This program reads the joystick and changes the position given by X and
Y in relation to its position. The corresponding bits are tested with the
AND command. These AND relations are closely related to the BASIC
function OR, NOT and XOR. The comparisons are made in binary by
comparing the two values bit for bit. The results of the logical
comparisons are discussed in the next section.
Joystick Switches
45
Atari ST Peeks and Pokes Computer Mathematics
There are four main logical operators: AND, OR, XOR, and NOT. These
logical operators serve to manipulate and test bit combinations.
AND
0 AND 0=0
0 AND 1=0
1 and 0 = 0 The bit in the result is set only when
l and 1 = 1 both bits tested are 1.
OR
0 OR 0 = 0
0 or l = l The bit in the result is set always when
1 or 0 = l one of the tested bits is 1.
l OR l = l
XOR
o XOR 0=0
0 xor 1 = 1 The bit in the result is always a 1 when
1 xor 0 = 1 when the tested bits are different.
1 XOR 1 = 0
NOT
NOT 0=1
NOT 1=0
The result never equals 0 when the tested bit is a 1. Using this method we
can test the joystick with four such comparisons.
46
Abacus Software Atari ST Peeks and Pokes
Example:
This process is called masking. The 11101111 word represents the mask.
A similar method is used to set a bit to 1. The OR instruction is used here:
Example:
Example:
The NOT operation is similar to the XOR command. NOT inverts all bits in
a data byte. This produces a value that corresponds to the decimal 255
minus the original byte.
47
Atari ST Peeks and Pokes Computer Mathematics
Example:
The shifted bit position is filled with zeros after the operation. In short
this means that n shifts to the left correspond to a multiplication of 2n and
n shifts to the right means a division by 2n.
48
Chapter 4
r \
Operating Systems
v )
Abacus Software Atari ST Peeks and Pokes
The ST, on the other hand, has a different type of operating system. It is
icon oriented—you point the mouse at a pictorial representation and the
computer responds.
The ST's operating system is made up of several parts. We'll talk about
them now.
•3? -:.:.:.:..
imiMMHUf m
•tamai ussssam caoSasa tz&xsn
51
Atari ST Peeks and Pokes The Operating System
The ST's operating system was named after the "Father" of this
remarkable computer—Jack Tramiel. TOS maintains the diskette and
peripheral controls established with its predecessor operating system
CP/M, but TOS can do considerably more and at a faster speed. TOS has
borrowed some functions and behavior from CP/M, but additional
capabilities have been built in as well. For example, the ST has a
hierarchical directory structure which is not found in the earlier CP/M.
This makes it possible for an ST user to build subdirectories (folders).
In the newest STs, the TOS is built into the ROMs on the motherboard
and is activated automatically when the computer is turned on.
Earlier versions loaded TOS from disk into the memory area beginning at
$500 up through $32000. In addition, TOS contains GEM, the graphics
user interface (Graphics Environment Manager) and the resource
parameters to create the menu and alarm windows.
When TOS is activated, the BIOS starts into action and places the ST into
a startup condition. It searches the diskette for programs with the . ACC
suffix designators. If any are found, these accessories are loaded into
memory and are then available for use when accessed form the DESK
menu.
One important part of the TOS is its Basic Input/Output System (BIOS).
The BIOS is the interface between the physical hardware and the
software. It performs rudimentary and frequently used operations using
the input and output devices. A programmer does not have to concern
himself with the details of accessing a peripheral. Instead he requests the
services of the BIOS.
52
Abacus Software Atari ST Peeks and Pokes
53
Atari ST Peeks and Pokes The Operating System
54
Abacus Software Atari ST Peeks and Pokes
55
Atari ST Peeks and Pokes The Operating System
Most of us are familiar with only the GEM desktop. Its characteristics are
its familiar icon-oriented screen and drop-down menus.
In addition, you can talk directly to TOS. Programs that bypass GEM and
talk directly to TOS have the extension .TOS.
One way to talk to TOS without writing a program is to use the VT52
emulator found in the DESK submenu. Here the keys have a different
"meaning." A cursor key function is a sequence of key presses—the first
being the <ESC> key:
<Esc> A Cursor up
56
Abacus Software Atari ST Peeks and Pokes
<Esc> v Wraparound on
<Esc> w Wraparound off (cursor stops at right margin)
These key sequences can also be used from a BASIC program. It is
possible to erase the output window border and use the entire screen for
the program. But be careful! An erased menu line remains erased even
though it may still function. Therefore you have to redraw it after
returning to the BASIC level.
57
Atari ST Peeks and Pokes The Operating System
The use of the AUS$ variables can also be done differently. The output
loop passes the entire text, including the control character, to TOS. All
control characters shown above may be used.
58
Abacus Software Atari ST Peeks and Pokes
4.2 GEM
GEM actually consists of two parts: the VDI (Virtual Device Interface)
and the AES (Application Environment System). Although they have
different tasks, their services are accessed similarly.
The VDI is responsible for drawing graphics. It is made of the GDOS
which performs device independent graphic functions, and the GIOS
which performs the device specific graphic functions. By implementing
the GEM in this way, it's possible to quickly add a special "driver" to the
GIOS for a new graphic peripheral.
The AES manages the user interface. It is responsible for handling drop
down menus, icons, windows, etc. The AES frequently call upon the VDI
to draw its graphic displays.
Both the VDI and AES were designed for easy use from the C language
and machine language. The VDI and AES routines are contained in a
library. To use the routines, you mustpass parameters to them.
The C and machine language programmer can easily access the routines.
But the BASIC programmer has a little more work to do to use the
features of GEM. Luckily ST BASIC has two built-in commands to
59
Atari ST Peeks and Pokes The Operating System
access the VDI and AES. These commands are GEMSYS and VDI SYS.
The GEMSYS command talks only to the AES, while the VDI SYS
command accesses the VDI.
For passing parameters to or from the VDI and AES, ST BASIC reserves
several variables: INTIN, INTOUT, PTSIN, PTSOUT and CONTRL.
Each array element is 16 bits (or 2-bytes) wide. You can display the
contents of the third element of the INTIN array with the following:
PRINT PEEK(INTIN + 6)
first element
INTIN•
+2
second element
+6 third element
i
+2*n nth element
The array named INTIN is for passing input parameters to GEM. The
output parameters from GEM to the program are passed in the array
named INTOUT. The arrays PTSIN and PTSOUT are used to pass
coordinates for graphic functions. And the CONTRL array is used to
specify the desired function.
Here's a breakdown of the CONTRL array:
60
Abacus Software Atari ST Peeks and Pokes
The second, fourth, and sixth to the nth elements are the output
parameters which are returned by the routine. The others must be
specified for every function call. The entry for CONTRL (6) is a number
which GEM requires for the device identifier or unit to be accessed. Since
the screen is active and represents the actual unit, this ED is not
transmitted. All functions are performed on the screen.
Let's break away from concepts and get down to practice. This short
program determines the mouse's screen position and the state of its
button. The VDI has a function exactly for this purpose:
10 rem *** Get Mouse Position 4.2.2***
20 poke contrl,124 : rem Function Code
30 poke contrl,+2,0 : rem Number of Parameters
70 vdisys 0 : rem and Execution
80 x = peek(ptsout) : rem X Position
90 y = peek(ptsout+2): rem Y Position
100 key = peek(intout): rem Key activated
110 print x,y,key
120 goto 20
61
Atari ST Peeks and Pokes The Operating System
For all calls to the GEM, you must specify a function code in element
CONTRL (0). The number of parameters passed is specified in
CONTRL (1). In this example there are no parameters so we POKE a
value of zero. Next the call to VDI is performed. The value following
VDI SYS is a dummy argument.
62
Abacus Software Atari ST Peeks and Pokes
120 end
130 rem +++ Masks and cursor data +++
140 data "
150 data " .. .***.
160 data ".**..*****.
170 data ".**..****.
180 data " **_**_
This program probably needs some explanation. In line 20, the function
code is specified as before. Next the number of parameters are specified.
This function, whose name is vsc_read, reads 37 words from the
INTIN array. INTIN (0) and INTIN (1) contain the X and Y
coordinates of the action points of the mouse pointer. This point, for
example, activates the drop-down menus. The action point in the above
example was set at coordinates 0,3 in other words the right hand. The
following two values in INTIN (3) andINTlN(4) contain the the
color values of the cursor. You might wonder why two values are needed
for this. The reason is simple. Assume the cursor is black and is dragged
onto a black surface. It becomes invisible and therefore useless for exact
positioning. Now the mask makes its appearance. This mask lies almost
below the cursor and is slightly larger than the cursor. Its color value in
the above example in normal desktop operation is 0, which means it
appears white. The effect is that on a black surface you cannot see the
entire cursor, only its outline. This outline is the white mask.
Starting in line 80, the program passes the data for the cursor and mouse
form. Here again the binary-decimal conversion is used which was
presented in section 2.1. For this application, the conversion routine was
changed. For the computation of cursor data, which provides the binary
pattern, the * is recognized as 1. The mask on the other hand is
represented by periods since it is larger than the cursor itself. Here a
63
Atari ST Peeks and Pokes The Operating System
This example draws a vertical arrow instead of the little man from the
previous program. The action point is now located at coordinates 8,0. If
you prefer the little man form better, you can determine the values for the
DATA statements from Section 2.1 by using the binary-decimal
conversion program.
A final note about the sample program. There are practically no limits to
the cursor form. Be careful to stay within the 16 x 16 pixel format or you
may end up creating an unmanageable form.
There is also another way to change the mouse form. There are 8 pre
defined mouse forms built into GEM. For example, the "busy bee" is one
of these. You can select this or one of the other seven with a call to the
64
Abacus Software Atari ST Peeks and Pokes
AES as in the next program. We'll talk more about this shortly when we
describe menu and window programming.
The value set in line 100 represents the form. You can use any of these in
place of the 4:
0 Arrow
1 Cursor
2 Bee
3 Hand with Index Finger
4 Flat Hand
5 Thin crosshair
6 Thick crosshair
7 Crosshair as frame
When you select a FILE function, the arrow form or busy bee form is
reselected.
65
Atari ST Peeks and Pokes The Operating System
In this program the font is changed to bold and shaded style. After
displaying a sample line, it reverts to the normal font to avoid potential
problems with subsequent BASIC commands. Lines 10 to 40 are similar
to the previous example. The difference lies in line 50 where the desired
font is specified. This method makes font selection easy. The text modes
can be selected by combining the bits which represent the desired graphic
characteristics. These are represented as follows:
0 1 Fat
1 2 Shaded
2 4 Italics
3 8 Underlined
4 16 Outlined
To use a shaded, italics font with underlining, then line 50 should have
the value 2 + 4 + 8, or 14. Up to 32 styles can be selected by using
66
Abacus Software Atari ST Peeks and Pokes
This program displays the text from the variable TEXT$ on the screen at
coordinates 50,50 and stretches the text to the point where it reaches the
width of 40 characters. The 3 which is passed to the control array in line
30, gives the number of parameters to be passed in PTSIN. The first two
are the coordinates of the first character of text, where 0,0 indicates left
on top. The X-Text length is the total width which the text shall occupy.
The text is stretched by adding space between the characters. To write the
text unexpanded to the location X, the expansion mode can be switched
off by POKEing a value of zero in line 40.
The program also performs some text processing. The VDI must know
how many characters to display. This number comes from line 32 through
the parameter which it should read from the INTIN array. The function
LEN(TEXT$) outputs the length of the text in this variable. The +2
67
Atari ST Peeks and Pokes The Operating System
stands for INTIN (0) and INTIN (1). The text is written character by
character into the INTIN field.
To store a character in memory, you must write its ASCII value. ASCII
stands for "American Standard Code for Information Interchange" and is
a standard code used in most computers and printers. The function
ASC ("A") provides in a BASIC program the ASCII value of A, which
is 65. Every character has its own value, so that in our example any
desired text can be set into the variable TEXT$. The character to be
converted is selected from the string using the MID$ function.
68
Abacus Software Atari ST Peeks and Pokes
The editor action and font specify the way the currently edited line is
displayed. Normally, it is displayed in a lightly shaded font style. With
POKE SYS TAB+2,14 you can change this to a Roman font.
And now to the GEM flag. If you set it to 1 with POKE SYSTAB+2 4,1,
GEM is turned off. You won't notice anything immediately, but changes
are no longer possible. No input is accepted from the keyboard either.
The GEM flag can only be used within a program, but it must be reset to
zero at the end of the program. The advantage of setting the flag in the
first place lies in the time which GEM normally requires to perform
windowing and to manage menus. These activities are suspended when
GEM is turned off and the computer can devote more time to the
processing of BASIC programs. The program runs faster, which during
long computations can be advantageous. Disk access is permitted since it
is handled by BIOS. Don't forget to turn GEM on again!
69
Chapter 5
The Desktop
Abacus Software Atari ST Peeks and Pokes
The Desktop
Many users want to customize their ST's to satisfy their own preferences
and work habits. Let's see how you can customize the ST for yourself.
Most of the icons that appear on the desktop are difficult to change using
the accessories. For example, the disk drive icons can only contain capital
letters if you try to name them with the Install Disk Drive
option from the Options menu.
#a000000
tbOOHOO
#c7770 0070 00700 070 05520 050555222077055707505770550 411230 6
#d
#E 9B 03
#W 00 00 0C 01 ID 16 08 A:\*.*@
#W 00 00 28 01 IF 17 00 @
#W 00 00 0E 09 2A 0B 00 @
#W 00 00 OF 0A 2A 0B 00 @
#M 00 02 00 FF A FLOPPY DISK0 @
#M 00 03 00 FF B FLOPPY DISKS @
#T 00 07 02 FF TRASH CAN@ @
#F FF 04 @ *.*@
#D FF 01 @ *.*@
#G 03 FF *.PRG@ @
#F 03 04 *.TOS@ @
#P 03 04 *.TTP@ @
73
Atari ST Peeks and Pokes Customizing the Desktop
Line #a is for the RS232 configuration. The digits in this number are
related to the settings of the RS232 configuration menu. The first digit is
DUPLEX. It can be set to 0 for Full or 1 for Half duplex. The second
digit is for the baud rate. It can be set to 0 for 9600 baud, 1 for 4800, 2 for
1200 or 3 for 300 baud. Digit number 3 is for the Parity. Set it to 0 for
None, 1 for odd or 2 for Even parity. The fourth digit is for Bits/char
where a 0 represents 8 bits/char, 1 is for 7, and so on down to 5
bits/character. Digit 5 is for the XON/XOFF and RTS/CTS settings see
the diagram below. Digit 6 is for the Strip bit, set it to 0 to turn the strip
bit on or set it to 1 to turn it off.
0
* 1
* 2
* * 3
Line #c contains the color palette values. These can also be set with the
control panel. Each color is set by a group of 3 digits that correspond to
the Red, Green and Blue values.
Line #E is concerned with how folders are viewed, i.e. as text or icons
and how the files are sorted. This is easier to change with the VIEW
menu. If you do wish to set these using the DESKTOP . INF file here is a
table with all the settings:
74
Abacus Software Atari ST Peeks and Pokes
Icons Name IB
Icons Date 3B
Icons Size 5B
Icons Type 7B
Text Name 9B
Text Date BB
Text Size DB
Text Type FB
The #W lines control the windows. The first two values (in this case 00
00) are for the horizontal and vertical sliders. The zeros mean they are
inactive. The next two values (0C 01) indicate the X and Y values of the
window in units of characters. The two values following that (ID 16)
contain the width and height of the window in character units. The
information following this concerns the path for the disk directory. It's
not wise to change this path information.
The #M lines control the disk icons. The first two values (00 02) are the
position at which the icon will appear. The next value determines the
shape of the icon.
00 file drawer
01 document
02 trash can
03 program
04 folder
The FF value doesn't seem to do anything. The floppy disk labels that
follow can be changed using both upper- and lowercase letters.
The #T line is for the trash can. Its parameters are the same as those for
the disk icons.
75
Atari ST Peeks and Pokes Customizing the Desktop
After you make your changes save the file under the name
DESKTOP . INF in ASCII format.
To use your customized desktop: first shut off your ST, put the disk
containing the new DESKTOP. INF file in drive A and switch the
computer on. Your new desktop will appear on the screen.
You can only have 6 accessories on the desktop at a time. You may want
to remove some of the accessories to make room for others or just to free
up some memory. To remove an accessory, rename it with the extension
.AC1. To re-install it as an accessory, rename it with the extension
.ACC. When you reboot the system the computer will load all the files
with the .ACC extension. Remember that you are only allowed 6
accessories at time.
If you remove the SET RS232 CONFIG. accessory though, you won't
be able to set the transmission rate anymore. Fortunately there is a way to
get around this inconvenience.
This rate can be set to operate at speeds from 50 to 19,200 baud. One way
to set the transmission rate of this port is by writing a short machine
language program.
76
Abacus Software Atari ST Peeks and Pokes
70 end
80 rem - — Program Data
100 data 24602,0,44,0,0,0,0,0,0,0,0,0,0,0
110 data 16188,-1,16188,-1,16188,-1
120 data 16188,-1,16188,-1,16188,15
130 data 16188,15,20046,-8196,0,14
140 data 16999,16188,76,20033
0 19,200
1 9,600
2 4,800
3 3,600
4 2,400
5 2,000
6 1,800
7 1,200
8 600
9 300
10 200
11 150
12 134
13 110
14 75
15 50
All other settings of the interface, such as the transmission protocol or the
parity, remain in the condition set.
77
Chapter 6
t >
Programming Languages
Abacus Software Atari ST Peeks and Pokes
Programming Languages
D • • • • • •
MODULfl_2.DIR PnSCAL.DIR
81
Atari ST Peeks and Pokes Programming Languages
6.1 DRXOGO
However, its not easy to output data from a LOGO program to a printer.
LOGO only has the commands COPYON, or COPYOFF, which control all
the output to the printer. If you want to have the command LPRINT,
which works like the one in BASIC, you can define it as follows:
TO LPRINT :LINE
COPYON PR :LINE COPYOFF
END
82
Abacus Software Atari ST Peeks and Pokes
TO BROOCH
FD 100 RT 111 FD 40
TURN
BROOCH
END
TO TURN
FD 66 RT 66 FD 66
END
This example will paint a brooch on the display with the command
BROOCH. Since the procedure BROOCH will call itself constantly, it will
run until stopped, or until the power is turned off.
.DEPOSIT 12 62 starts the printout of the display. You can use this
command just as you would the POKE command in BASIC.
83
Atari ST Peeks and Pokes Programming Languages
6.2 ST BASIC
The ST BASIC interpreter stores the program lines as text. These text
lines are interpreted line by tine. Other BASIC interpreters work
somewhat differently. With them a BASIC command is stored as an
encoded number, called a token. This method simplifies the command
interpretation and improves the speed of the program. But ST BASIC is
relatively fast even without the preliminary translation to tokens.
A BASIC program can be loaded directly from diskette by a text editor
and changed. Since a BASIC program is stored as text, it can be loaded
and edited with most word processors. But since ST BASIC has a built in
editor, using a word processor is usually unnecessary. The BASIC editor
also performs a syntax check of each program line as it is entered.
BASIC is not a problem oriented language. While COBOL is designed
for business and FORTRAN for scientific problems, BASIC is general
and can be used for all applications. It does not offer special commands
such as sorting or indexing, but can perform these functions with
subroutines. Therefore, almost every problem can be solved with a
BASIC program. A problem which is very difficult to do in BASIC is the
handling of real time processes. For time critical assignments, machine
language is much better suited. You can, however, combine these two
languages, which we'll look at Section 6.4.1.
This book is also written for the BASIC programmer who wants to fully
experiment with the fabulous possibilities of the ST. BASIC commands
such as PEEK, POKE or CALL permit accessing of the operating
system facilities. For this reason the book was not called "EXAMINES
and DEPOSITS" as PEEK and POKE are called in LOGO, since only
BASIC permits almost complete access to the ST.
84
Abacus Software Atari ST Peeks and Pokes
Although it's considered a high level language, there are some elements
of the language which make it very close to machine language. This is
especially apparent since input and output functions are not part of the
standard language definition. This is because these functions are very
system specific, i.e. dependent upon the computer being used. To perform
input and output, each C compiler contains a library of input and output
functions which are then linked to the user's program.
One advantage of the C language is that it is a transportable language. C
programs written for one computer are often easily adapted for use on a
different computer.
C is derived from the family of the ALGOL language. From this language
family both FORTRAN and PASCAL originated. These languages are
characterized by their high popularity and structured approach to
programming. You can define procedures whose use is similar to a new
command. The procedure PRINTF is one of these. It belongs to the
standard input/output routines which are made available by the above
mentioned library. This procedure outputs, similar to the PRINT
command in BASIC, a text or numeric value. The text or values to be
output are passed to the function with formatting directions for the output.
Here's a sample call to this function:
PRINTF("5.2f %6.1f\n",A,B)
85
Atari ST Peeks and Pokes Programming Languages
First the program variables are defined. Then individual functions are
written. To follow the execution of a C program, first find the routine
with the name main (). This is the real program which contains a series
of function calls. Since the names of the functions usually indicate their
purpose, the general structure of the program can beeasily determined.
Small programs often consist only of the main routine. Let's look at a
small C program.
86
Abacus Software Atari ST Peeksand Pokes
program starts with the MAIN() routine. The empty parentheses indicate
that this function does notrequire a parameter.
Next follow the definitions of the variables. The following data types are
permissible:
int Integers
float Floatingpoint
char A single character
short A small, whole number value
long A large, whole number value
double A floating point value with double precision
The program assigns initial values to the variables. After that we start the
loop to calculate the 10 circumference values. This loop is defined by
WHILE (condition) and continues as long as the condition is met. A
WEND, as required in BASIC for the completion of a WHILE loop, does
not exist in C. The program portion which is enclosed by the braces
following the statement is repeated by this command.
The program portion calculates the circumference of a circle from the
radius and outputs both values in formatted form. Then the radius is
increased by one and the loop repeated if it has not exceeded the end
value of 10. If the radius is larger than 10 the program is terminated.
As you can see, a C program is not very hard to follow if you have
already learned another structured programming language. In C, all
statements are terminated with a semicolon, as in PASCAL. The
keywords IF, ELSE, WHILE, or FOR are all familiar. The
somewhat cumbersome programming becomes fairly readable through
structuring and the amount of work required is rewarded with the high
computation speed of the completed program.
For the ST there is a another reason to use C. Accessing GEM is made
easier since the parameters are well defined for the C programmer. The
ST development package from Atari contains a giant library of GEM
functions and systems parameters which make all of GEMDOS
accessible to the C programmer.
87
Atari ST Peeks and Pokes Programming Languages
Those who can estimate the speed of a BASIC program can see
immediately that even a fast BASIC, such as the ST's, can take a few
seconds to run this program. You can watch as the display is erased line
by line. Erasing the screen with a machine language routine on the other
hand, will proceed faster than you can watch.
You would think that the operating system would support such
procedures to relieve you of such time problems. But what about
88
Abacus Software Atari ST Peeks and Pokes
You will find that you cannot ignore machine language if you want to
make fullest use the system. Especially since the 68000 processor used in
the ST also offers a powerful operating system such as GEMDOS.
Let's first examine the processor and its language. There are no variables
or such easy commands as PRINT 16A3. The programmer has a few
instructions at his disposal, but they concern themselves only with bits,
bytes, words, long words and registers. If you want to store a value, it has
to be stored in the working storage location and you have to remember
the exact location.
That's it! The MOVE instruction moves data in the computer. The
extension .W indicates that it concerns a word, that is 16 bits. This could
have been . B for a byte or . L for a longword. The first instruction of our
program takes the word from storage location $1000 and puts it into DO.
This DO is a data register, a 32 bit storage location in the computer. The
68000 has 8ofthese registers, designated DO to D7. Data which are being
worked on can be stored in these registers. Registers have additional
advantages in comparison with working storage, which won't discuss at
this time.
The data register DO now contains the value of the storage location
$1000. This value is added to the content of $1002 with the ADD.W
instruction. Here too we append . Wfor the actual data length, a word.
The result of the addition is now in DO, from where it will have to be
transferred to the desired storage location. For this we'll again use the
MOVE . Winstruction. The MOVE instruction always transfers the value of
the first referenced storage location (orregister) to the second. A common
method of writing this is as follows:
89
Atari ST Peeks and Pokes Programming Languages
MOVE.datatype from, to
Datatype means the letters .B, .W, or .L. From and to indicate
from where and to where the data are to be transferred. For this type of
addressing, the 68000 offers a large selection. The following table
contains the addressing modes:
Register direct:
- Data register direct CLR DO
- Address register direct MOVEA A1,A6
- Status register direct MOVE D0,SR
- Program counter direct MOVE DO, CCR
Data immediate:
- immediate long MOVE#$20000, DO
Absolute:
- absolute short NOT $2000
- absolute long NOT $18000
As you can see from the table, addressing modes can be differentiated in
5 categories. The first three are easy tounderstand:
90
Abacus Software Atari ST Peeks and Pokes
Data immediate: the data is part of the instruction. This addressing mode
is only suitable for a data source. This addressing mode is similar to the
POKE command, since MOVE #10,10 00 is just like POKE 1000,10.
It writes a fixed value (10) into a memory location.
Absolute: the directly provided address is addressed and its content used.
With PEEK and POKE only absolute addresses can be addressed. There
are other methods of selecting a certain memory location. These
addressing methods are sometimes rather complex, but very effective.
Now let us consider two other methods of addressing.
Indirect Addressing: Here the register used is not addressed directly, but
its content is interpreted as an address. With this method simple pointers
can be processed by loading the value of the pointer into a register and
addressing indirectly. An example:
91
Atari ST Peeks and Pokes Programming Languages
In the statement:
Since the address of the start of the video display memory is already
contained in address register AO, we can display a point on the second
line using an offset of 80 as follows:
MOVE.W #1, 80(AO)
MOVE.W #0000,-(SP)
The stack pointer is decremented by two after the value OOOOH is pushed
onto the stack. Similarly you can retrieve the word form the stack with
this instruction:
MOVE.W (SP)+,D0
The data is moved from the top of the stack into data register DO and the
stack pointer is incremented by two. The stack is now ready to accept
more data.
92
Abacus Software Atari ST Peeks and Pokes
BLT SMALLER
The + sign indicates logical OR, &stands for logical AND (See section 3).
The characters in the right column ofthe table indicate the flag bits ofthe
condition code register (CCR) that may be set by each operation. Each of
these bits has its own significance and is influenced by the different
instructions.
Some of these instructions alter the flow execution within the program.
The JSR instruction (Jump to SubRoutine) is similar to the BASIC
GOSUB command. When a JSR instruction is performed the path of
execution is temporarily altered until an RTS instruction (ReTurn from
93
Atari ST Peeks and Pokes Programming Languages
94
Abacus Software Atari ST Peeks and Pokes
Mnemonic Significance
In addition, the 68000 can also process BCD numbers. For this it has the
following instructions:
Mnemonic Significance
Next the logical operations which we're familiar with from BASIC:
95
Atari ST Peeks and Pokes Programming Languages
Mnemonic Significance
The processor can also shift and rotate the bits in an operand.
Mnemonic Significance
And now we come to the instructions which move data in the computer:
96
Abacus Software Atari ST Peeks and Poke
Mnemonic Significance
These then, are the instructions of the 68000. In combination with the
various addressing modes, these instructions can be used to make
programs as efficient as possible.
Now we want to examine the program that we used to convert the display
scan rate form 60 Hertz to 50 Hertz. The machine code version of the
program is as follows:
CLR.L -(SP)
MOVE.W #$20,- (SP)
TRAP #1 * Set Supervisor State
ADDQ.L #6,A7 * Adjust Stack
MOVE.B #2,$FF82 0A * Set PAL Frequency
MOVE.L DO,-(A7) * alter SSP
MOVE.W #$20,- (SP)
TRAP #1 * Set User-State
ADDQ.L #6,SP * Adjust Stack
CLR.W -(SP)
TRAP #1 * Back to Desktop
The first TRAP changes the system to the supervisor state. We need to do
this since access to the I/O area is privileged and would generate a bus-
error in the user mode (and two cherry bombs...). After adjusting the
stack pointer, we can change to the 50 Hertz frequency. TRAP #1 calls
97
Atari ST Peeks and Pokes Programming Languages
GEMDOS again and passes the original value of the supervisor stack
pointer which puts the computer system back into user state. The state is
adjusted again and control is returned to the desktop.
The BASIC equivalent of the machine language programs which follow
contains some additional values which precede the application program.
These values are not part of the program, but are required by GEMDOS
to recognize the length and kind of program. If we call a machine
language program from BASIC with CALL, these values are not required.
Using TRAP #1 with the function number 0 is sloppy programming,
since GEMDOS does not return to the BASIC program, but to the
desktop. Such a program is generally ended with the RTS instruction,
which returns control to BASIC.
98
Abacus Software Atari ST Peeks and Pokes
The machine language program is POKEd into the area reserved for the
variable A$ after the FOR-NEXT loop. Next the computer asks you to
enter a code for the baud rate. Any code may be entered, but the 16
possible baud rates are normally sufficient to cover all needs for speed in
data transmission. You simply enter the code number for the desired baud
rate, ranging from 0 (19,200 baud) to 15 (50 baud). The table is found in
section 5.1 of this book.
99
Atari ST Peeks and Pokes Programming Languages
The 15 in line 6 which determines the baud rate, is the number which is
changed with the POKE command. By adding another POKE command to
the BASIC program you can change the transmission protocol
(XON/XOFF and RTS/CTS). Do this with POKE B+l 8, n to set a new
protocol. The -1 parameter means that the original setting is to be
retained.
100
Abacus Software Atari ST Peeks and Pokes
BASIC portion:
10 1 * -k Vc
rem *** Calltest 6.4
20 a$=space$(100) rem Make space
30 a=varptr(a$) : rem Determine address
40 bload "calltest.prg", a:rem load program
90 rem End of first part
100 call a (1,2,3) : rem test call
130 n=peek(8192) : rem Determine number
(2000 hex)
140 print n;"Arguments :"
150 defdbl j : rem Set Longword
155 d=l : rem Initiate counter
160 for j=8208 to 8204+n* 4 step 4
170 print d;": ";peek(j) : rem Output
Parameter
180 d=d+l : rem Increment Counter
190 next j : rem continue
calltest.prg 6.4.1
MOVE W 4(A7),$2000 *
*
Save # of param.
MOVE ,L 14(A7),$2010 *
First Parameter
MOVE .L 18(A7),$2014 *
Second Parameter
MOVE .L 22(A7),$2018 V;
Third Parameter
MOVE ,L 26(A7),$201C *
Fourth Parameter
MOVE .L 30(A7),$2020 *
Fifth Parameter
RTS
The BASIC portion first BLOADs the machine language portion and then
immediately CALLs it and passes three parameters. To verify that the
machine language program works correctly, lines 130-190 PEEK the area
of memory to which the parameters were moved.
101
Atari ST Peeks and Pokes Programming Languages
1000 open"R",1,"calltest.prg",16
1010 field#l,16 as bin$
1020 a$=""; for i = 1 to 16:read d$: if d$="*" then 1050
1030 a = val("&H"+d$): s=s+a:a$=a$+chr$(a):next
1040 lset bin$=a$:rec=rec+l:put l,rec:goto 1020
1050 data 60,1A, 00, 00,00,60,00,00,00,00,00,00,00,04,00,00
1060 data 00,00,00,00,00,00,00,00,00,00,00,00,33,CO,00,00
1070 data 20,00,23,EF,00,0E,00,00,20,10,23,EF,00,12,00,00
1080 data 20,14,23,EF,00,16,00,00,20,18,23,EF,00,1A,00,00
1090 data 20,1C,23,EF,00,IE,00,00,20,20,4E,75,23,DF,00,00
1100 data 00,60,4E,4E,2F,39,00,00,00,60,4E,75,23,DF,00,00
1110 data 00,60,4E,4D,2F,39,00,00,00,60,4E,75,23,DF,00,00
1120 data 00, 60, 4E,41,2F,39,00,00,00,60,4E,75,00,00,00,32
1130 data 08,08,08,08,08,00,00,00,00,00,00,00,00,00,00,00
1140 data *
1150 close 1: if s <> 52 43 then print "ERROR IN DATA!":end
1160 prinf'OK"
102
Chapter 7
BASIC Programming
Abacus Software Atari ST Peeks and Pokes
BASIC Programming
But when it comes to the PEEK and POKE commands, you may not be as
secure. These commands involve access to memory at the machine
language level. An erroneous POKE may crash the computer. Before
experimenting with PEEK and POKE make sure that you have SAVEd any
programs in memory in case the program crashes.
The programs presented here contain many PEEK and POKE commands,
just as you might suspect from this book's title. If you've worked with
BASIC before, you'll have no trouble using these two commands. PEEK
examines a memory location and POKE modifies a memory location.
There is one point that you should be aware of when using ST BASIC.
The 68000 processor in the ST is capable of accessing memory in
increments of bytes, words or longwords. The PEEK and POKE
commands of ST BASIC are also capable of accessing bytes, words or
longwords at a time. Therefore you must specify the size increment to be
used with PEEK or POKE.
Let's assume that you want to set the byte at memory location 8000 to
zero. By default, ST BASIC is set to access a word (two bytes) of
memory at a time. If we POKE 8 0 0 0, 0 not only is the memory at 8000
set to zero, but also the memory at 8001.
DEF SEG = 1
X = PEEK(A)
The DEF SEG statement tells BASIC that the offset for any access to
memory is one byte. An offset is equivalent to adding 1 to any address.
Therefore this sequence of commands DEF SEG = n: PEEK (A) reads
the address A+n. Also, all accesses to the address A are in byte
105
Atari ST Peeks and Pokes BASIC Programming
increments. Keep in mind that all subsequent accesses to memory use the
offset n, therefore you must reset the offset to zero when you're finished
by using DEF SEG = 0.
To overcome this problem you can use the DEFDBL statement. For
example, the pair of statements DEFDBL A: POKE A, X tells BASIC to
access the memory specified by variable A as a longword, or 4-bytes.
106
Abacus Software Atari ST Peeks and Pokes
7.1 Graphics
The ST is well equipped for graphic processing with its high resolution
display and the GEM operating system. GEM supports nearly everything
a programmer may want to use for graphics. You can draw lines, paint
circles and ellipses, squares with square or round corners, and fill in
various forms with shading using simple procedures. Let's start now by
drawing a shaded circle.
Perhaps you have drawn circles on other computers using the sine and
cosine functions. With ST BASIC we don't have to do this. The
command PCIRCLE X,Y,R does this quickly. The command has a
limitation. It can only draw a circle in the OUTPUT window of the BASIC
display.
If we use GEM for the graphics functions, we don't run up against this
limitation. With GEM we can draw anything anywhere on the screen. We
also have additional capabilities beyond BASIC.
107
Atari ST Peeks and Pokes BASIC Programming
The function 11 which is passed in line 30 to the CONTRL (0) field can
do more than just draw a circle. With this one function 10 different
graphics can be drawn. The information concerning what pictures are to
be drawn, is contained in the function ID which is passed in
CONTRL (5) . The assignment of ID numbers to the drawings is as
follows:
ID Drawing
1 Shaded Rectangle
2 Section of Circle
3 Shaded Circle Section
4 Shaded Circle
5 Ellipse
6 Section of Ellipse
7 Shaded Section of Ellipse
8 Square with rounded corners
9 Shaded Square with rounded corners
10 Justified text
The first of these functions, the shaded rectangle, is suitable for the
creating bar graphs. Bars of any width and shading can be drawn. Such a
rectangle can be created with the following program:
The first coordinates are the upper left corner of the square and the
second is the lower right corner. The significance of the shading attributes
are explained later.
108
Abacus Software Atari ST Peeks and Pokes
circle on the display. To do this the beginning and ending angle of the
circle are specified. These angles are given in 1/10 degrees where the
zero degrees lies to the right of the midpoint. A quarter circle in the first
quadrant, right of the midpoint, lies therefore between 0 and 900 (90
degrees). The same is true of the CIRCLE command. An example:
The same program can also draw a shaded circle section. To do this you
must insert function ID 3 and the desired shading attributes in line 20. To
draw a complete circle don't use 0 to 360 degrees with function 3, just
use function 4. It has already been presented in our first example.
Now to the ellipses. For this, functions 5,6 and 7 may be used. Let's take
function 6 as an example. This draws an ellipse section whose ends are
connected with the midpoint.
109
Atari ST Peeks and Pokes BASIC Programming
For function 7 only the function ID and shading attributes change. These
can be set with the COLOR command. Function 5 on the other hand
requires no starting or ending angle since it draws a complete ellipse.
Lines 110 and 120 are scratched and not replaced. In Line 50 a 0 is
inserted and the function ID is replaced with the 5.
We have only looked at the only the basic graphic functions which GEM
easily accomplishes. But good control of graphics also includes text. The
VDI is well suited for this since it controls text formatting. This is our
next topic.
110
Abacus Software Atari ST Peeks and Pokes
The last of the 10 calls of the VDI lets you put text formatted in many
ways on the screen—at any location. This function takes several
parameters. For one, there is the display position at which the text begins.
These coordinates point to the upper left hand corner of the first character
in the text. Furthermore, the desired total length of the text must be
specified. If this is longer than the text, it will be adjusted by adding
spaces.
Finally, the text itself is passed. It must be passed one character at a time
to the INTIN array which makes the technique a little more difficult than
the graphics programs above. Here is a sample:
111
Atari ST Peeks and Pokes BASIC Programming
Here are two new VDI commands, 8 and 12. VDI command 12 sets the
height of the characters. This height is specified in PTSIN (1) and is the
only parameter of the function. The 0 in the PTSIN (0) is not used but
we set it for safety's sake.
The next section calls function 8 which writes text at the specified X/Y
coordinates on the screen. Here a simple PRINT command is possible
which writes only to the BASIC output window.
Finally, the standard size is restored. This must be done since the display
editor does not know what to do with the enormous amount of text so that
subsequent data to the OUTPUT window would otherwise produce only
garbage.
Some interesting effects can be produced using this function. But what
can we do if we need to label a vertical line? The VDI can also help do
this. With function 13, the base line on which the text is written can be
rotated in 90 degree steps. Zero (0) is the default setting. The angle is
specified in l/10th of a degree units. An angle of 900 permits rotating the
text vertically to the left. 1800 turns it upside down and 2700 prints it
vertically to the right. Unfortunately the monitor of the ST does not
support any angle in between. These are reserved for other devices such
as a plotter.
112
Abacus Software Atari ST Peeks and Pokes
Here the text output function 8 was used. The normal PRINT command
is not sufficient. It overwrites the rotated characters which is not really
useful. As in the previous example, the standard defaults are reset before
we end the program.
So much for text output. Circles and text do not constitute graphics. Lines
must also be drawn, preferably in various thicknesses. You may also need
to draw pointers and arrows in technical drawings. But they're no
problem for the VDI.
113
Atari ST Peeks and Pokes BASIC Programming
Drawing a line in the output window can be done using the LINEF
command, where the starting and ending coordinates of the line are
specified. The corresponding VDI function is number 6, named Polyline.
Polyline is the name for several connected lines. Several coordinate
points can be passed to the function. It simply connects them with lines.
Simple drawings such as frames can be drawn with one call. Here is a
sample program:
20 clearw 2:fullw 2
30 poke contrl,6 rem Polyline Code
40 poke contrl+2,4 rem Number of Points
50 poke contrl+6,0
60 poke ptsin,50 : rem X 1
70 poke ptsin+2,50 : rem Y 1
80 poke ptsin+4,150 : rem X 2
90 poke ptsin+6,100 : rem Y 2
100 poke ptsin+8,160 : rem X 3
110 poke ptsin+10,180 : rem Y 3
120 poke ptsin+12,50 : rem X 4
This program draws a triangle on the screen. It was necessary to give the
starting and ending point twice. The number ofthe coordinates are passed
in CONTRL (1). There is a closely related function which not only draws
a polygon, but also shades it. You can use it by first using a COLOR
command to determine the shading attributes and using command code 9
instead of 6.
114
Abacus Software Atari ST Peeks and Pokes
Style Line
solid
interrupted
dashed
line point
long dashed
line point point
self defined
Style 7 can be user defined. The definition consists of a 16 bit word and
its bit pattern determines the line. The solid line is defined as
1111111111111111 = $FFFF = 65535. This number is passed to function
13 and determines the form of every line which is designated afterwards
with style 7. Here is a program which defines the two lines and draws
them:
The lines can also be drawn in variable thicknesses. Note that thicker
lines can only be represented in style 1. If another style is selected, it is
ignored. The thickness of the line can be set between 1 and 15 by calling
function 16. An example:
115
Atari ST Peeks and Pokes BASIC Programming
The shape of the line endings of these lines can also be defined. There are
three selections possible:
0 normal angle
1 arrow
2 rounded
They are set with function 108, separately for the beginning and ending
of the line. To draw an arrow from the position Xl/Yl to position X2/Y2
and to round off its beginning, our program wouldlook like this:
10 rem *** Draw Arrow 7.1.3***
20 poke contrl,108 : rem Define end
30 poke contrl+2,0
40 poke contrl+6,2
50 poke intin,2 : rem Beginning rounded
60 poke intin+2,1 : rem End arrow shaped
70 vdisys 0 : rem and normalize execution
Then we draw the line as in the previous example. The rounding off of
the line end is only noticeable with thick lines. Arrows can be drawn with
any line width.
If you draw a form you might want to shade it. In BASIC the command
for this would be FILL X, Y. The shading begins at the position given,
and shades everything within an uninterrupted outline. The
116
Abacus Software Atari ST Peeks and Pokes
shading and the color is set initially with the COLOR command. This
command expects 5 parameters. The following table explains the
parameters:
A Color of text
B Background color of FILL command
C Line color of drawings
D Pattern index
E Shading style
Pattern index and shading style specify the appearance of the shading.
The shading style is the method in which the shading is performed:
Style Shading
Shading style 4 is very interesting. This allows you to define your own
shading pattern. You can define a logo or a special character for a pattern.
Any pattern which can be designed within a 16x16 pixel area may be
defined. The program is written so that you can insert your own pattern.
Let's design a pattern based on the little man from an earlier example.
117
Atari ST Peeks and Pokes BASIC Programming
To draw this or any other user-defined pattern on the screen, call the VDI
using function 103. This is the same function that is used by the FILL
command of BASIC. The method is the same as in FILL concerning the
attribute setting and the method of shading procedure. A VDI call for
shading looks like this:
118
Abacus Software Atari ST Peeks and Pokes
Incidentally, you can add dots or lines to the menu bar of GEM if you
wish.
Type Form
1 Period
2 Plus sign
3 Asterisk
4 Square
5 Cross
6 Diamond
Any other value will produce an asterisk. Except for the period, the
symbols can be enlarged—to provide any size you desire. For example,
you can frame a character within a square.
The selection of type, size, shading color, and symbol are done
individually. This makes for more work, but their flexibility makes it
worth the effort. Many programs use these markers to indicate menu
choices in dialog boxes.
119
Atari ST Peeks and Pokes BASIC Programming
Let's examine a program where all the selections are made and several
markers are set:
120
Abacus Software Atari ST Peeks and Pokes
VDI function 105 can determine the color of a point on the screen. If the
color is the same as the color of the background, this condition is
reported. This information is passed back in array elements
INTOUT (0) and INTOUT (1). With this information you can determine
if an object collided with another in a game, for example. You could also
use this information to copy a portion of a picture. A program for
examining a point on the screen is as follows:
You can set 16 different colors with the control panel, which can be
displayed simultaneously on the color monitor. These colors are later
specified by selecting a number from 0 to 15 with the COLOR command.
Sometimes you may want to change the color in a program being
executed. This can't be done by selecting colors on the control panel.
BASIC doesn't have the capability to manipulate the individual color
registers, so this must be done through the VDI.
121
Atari ST Peeks and Pokes BASIC Programming
Here is a sample program to set the color number 2 to a brown tone. This
program only works on a color monitor:
10 rem *** Set Color 7.1.8 ***
20 poke contrl,14 : rem Function Number
30 poke contrl+2,0
40 poke contrl+6,4
50 poke intin,2 : rem Color Number
60 poke intin+2,600 : rem Red portion
70 poke intin+4,400 : rem Green portion
80 poke intin+6,200 : rem Blue Portion
90 vdisys 0 : rem and normalize execution
To set the exact color you want with these red, green and blue portions,
you have to experiment. This can be fun since you can discover the great
color capabilities of the ST.
122
Abacus Software Atari ST Peeks and Pokes
The ST has three built-in tone generators whose sounds can be mixed. In
addition, every tone channel can be used as noise generator. It also has a
sine wave generator, which lets you create some very interesting sound
effects.
You can set tone variations with a combination of SOUND and WAVE
commands. These commands offer a wide range of possibilities for
representing realistic sounds.
The simplest way to create a tone is to push a key. The click generated by
this is a tone generated by the sound chip. This explains why you can
interrupt a tone by pushing a key. The operating system contains routines
to create the clicking sound. Because of this some of the tone variations
are reserved for the operating system.
The keyboard click and the bell which sounds during certain error
messages are generated by an interrupt routine. Each l/60th of a second
(l/50th on PAL systems), the interrupt routine is called to determine the
value of a two-byte pointer into a special table. If the value of the first
byte of the pointer is zero, the data contained in this table is used to
program the sound chip. If the value of the first byte of that pointer is
$FF, normal processing takes place.
To use one of the preset tones from the operating system we set the
pointer located at $E44 to the location of the sound data for the click:
10 dedfdbl a
20 a - 3652
30 poke a,36612
To produce a bell tone, we set the pointer to a different set of sound data:
30 poke a, 36642
We can also produce a sound of our own by pointing to our own sound
data. Before doing this, let's look at the sound chip a little closer.
The values from the sound data table are passed to the sound chip
registers in the I/O area of memory.
123
Atari ST Peeks and Pokes BASIC Programming
In early versions of GEM, this I/O area was protected, so that only
privileged programs were allowed to access these ranges. To "bypass"
the protection we can write the following machine language routine
which temporarily puts the user's program into supervisor mode:
Source File: BYPASS . S
5
6 000006 42A7 CLR.L -(SP)
7 000008 3F3C0020 MOVE.W #$2 0,-(SP)
8 oooooc 4E41 TRAP #1 * Supervisor 1
9 00000E 5C8F ADD.L #6,SP *
Stack rep.
10
11 000010 226F000E MOVE.L 14(SP),Al * Get address
*
12 000014 32AF0012 MOVE.W 2 0 (SP), (Al) and s e t
13
14 000018 2F00 MOVE.L D0,-(SP)
15 00001A 3F3C0020 MOVE.W #$2 0,-(SP)
* User State
16 00001E 4E41 TRAP #1
17 000020 5C8F ADD.L #6,SP * Stack rep.
18
19 000022 4E75 EXIT: RTS * and back !
To use this routine from BASIC, we write a simple loader which puts the
machine code into the memory reserved for a BASIC variable called A$.
10 rem *** Privi! eged Access 6.4.1***
20 a$=space$(36) : rem reserve space
30 b=varptr(a$) : rem determine address
35 b=b+(b mod 2) : rem set even address
40 for i=0 to 34 step 2
50 read a : rem read . d a t a
60 poke b+i,a : rem and write
80 next i
124
Abacus Software Atari ST Peeks and Pokes
The FOR/NEXT loop in Unes 40-80 POKE the machine code into variable
A$. Then the CALL statement in line 200 performs the equivalent of a
POKE but bypasses the protection normally afforded the I/O register
memory area.
The routine first checks to make sure that two parameters are being
passed from BASIC. If not, control is returned back to BASIC.
If two parameters are passed from BASIC, the TRAP instruction sets the
program to supervisory mode and the two arguments may be used as
privileged POKE equivalents. Finally a second TRAP instruction resets
the mode back to unprivileged access.
125
Atari ST Peeks and Pokes BASIC Programming
This program creates a tone from two frequencies where one is varied
through a sine wave. The data pair starting in line 250 is a register
number of the sound chip and the value which is to be written to this
register. We can now vary the register values to hear the effect of
different combinations. The register and the corresponding content have
different uses which we'll look at now.
126
Abacus Software Atari ST Peeks and Pokes
The two ports, A and B are programmable data registers which also have
some assignments that are really are not related to tone generation. Port B
is directly connected to and controls the parallel port of the printer, while
port A controls the selection of the disk drive, the data request of the
serial interface and the GPO (General Purpose Output) connection of the
monitor connector. Changing the contents of these registers is therefore
not recommended. Let's stick with the tone generation.
127
Atari ST Peeks and Pokes BASIC Programming
The first block of data in lines 160 to 190 creates a tone whose volume is
modulated with a triangular curve. This is accomplished by setting the
volume on channel A in register 8 to 16, which creates the dependence on
the sine wave. The sine wave itself is set in registers 11,12, and 13 which
can be seen in the table of the sound register chip.
Now to lines 195 and 200. Here two special commands are issued for the
sound interrupt. These special commands are used instead of registers and
are always set larger than 127. The special command 12 8 causes the
following value to be stored (nothing else). The 12 9 starts the following
sequence:
128
Abacus Software Atari ST Peeks and Pokes
With this trick of tone generation through interrupt routines you can
create quite a few noises to use in a game. However, you should be aware
that pressing a key will alter the pointer again and turn off the tone. This
is also true of noises which were set with SOUND and WAVE. These two
commands will be examined next.
The frequency setting is also divided into octaves and notes which makes
the translation of a musical piece to BASIC, according to notes, very
easy.
With these BASIC commands you can try to create the same falling noise
in the above program. It is amazing how many different noises can be
coaxed from the ST!
129
Atari ST Peeks and Pokes BASIC Programming
You can eliminate the need to press the <Return> key by adding:
50 w=inp(2)-186
Since the Fl key produces a value of 187, we can sit variable wto 1 by
subtracting 186. We then use this value with the ON. . .GOTO command
to branch to the right section. This is the first step in simplifying the
menu. This technique is also used in many programs.
130
Abacus Software Atari ST Peeks and Pokes
But let's go to the next step towards a better menu. GEM offers several
features for easy menu operation. We have already used the VDISYS
command for programming with GEM. The VDI helps us very little here,
since it is only responsible for graphics. We shall now examine the
mysterious GEMSYS command.
GEMSYS activates GEM in the ST, just like VDISYS. The difference lies
in the fact that VDISYS only calls VDI, while GEMSYS is responsible for
the AES. The AES is responsible for the windows and menu processing
in the ST. It permits the user input with the mouse, for example.
PEEK(GB) CONTRL
PEEK(GB+4) GLOBAL
PEEK(GB+8) INTIN
PEEK(GB+12) INTOUT
PEEK(GB+16) ADDRIN
PEEK(GB+2 0) ADDROUT
These pointers are used for parameter passing to AES, i.e. the GEMSYS
command. The GLOBAL array plays a subordinate role. It contains
information on the status of the GEM-AES commands currently in
execution. Here are the meanings of the entries in the GLOBAL field:
131
Atari ST Peeks and Pokes BASIC Programming
We can usually ignore this field. The other arrays are more important.
The CONTRL field has the same partitioning as the VDI. CONTRL (0)
contains the function number, CONTRL (1) and CONTRL (2) the
number of INTIN and INTOUT entries and CONTRL (3) and
CONTRL (4) the number of entries in ADDRIN and ADDROUT fields in
long words.
Let's begin using the GEMSYS commands with a simple call. The
following example is the function FORM_ERROR which displays a TOS
error message in a small window in the middle of the display. The error
number is passed through INTIN (0) .
Let's look at this example more closely. First of all, you will note that we
don't work directly with GB, instead we access it through variable B. The
reason for this is that the pointers CN and 11 are longwords (4 bytes
long). A PEEK (GB) only produces the HI word of the pointer CONTRL
which is useless. Since the variable B is defined as double precision, the
PEEK (B) results in a long word.
Next you might ask why CONTRL and INTIN were not used as variable
names which would make the program easier to read. Unfortunately,
these two names are reserved for the system variables so they may not be
used for other variables.
132
Abacus Software Atari ST Peeks and Pokes
The text can simply be stored in a text variable and the we can pass the
address of the variable to the AES. Furthermore, another parameter is
passed which determines which of the selection choices can be selected
with the <Return> key. It will be darkly framed similar to the OK choice
in many dialog boxes.
In the early versions of BASIC there is another problem. The value of the
selection is returned in INTOUT (0). Before the value can be read with
PEEK (10) it is changed again by another call from BASIC. Up to now
we have not been successful in obtaining the correct value. The only
solution is to pass a 0 in INTIN (0). By doing this no selection can be
chosen with the <Return> key. The selection can be made only with the
mouse;its position can be determined after the return from AES. The Y
coordinate of the mouse pointer can be ignored since the selection points
are usually adjacent to one another.
The function call with the text necessary is shown in the following
program:
133
Atari ST Peeks and Pokes BASIC Programming
60 poke cn+2,1
70 poke cn+4,1
80 poke cn+6,1
90 poke cn+8,0
100 poke ii,0 : rem No 'Return' selection
110 poke d,a : rem Text address
120 gemsys 52 : rem Execution
125 t=peek(io) : rem Actual key number
The [1] stands for the symbol which appear near the text of the
message. You have a choice between a STOP sign, a question mark, or an
exclamation point. The second bracket contains the text of the message.
Line feeds are made with the vertical line. The length of the text should
be selected in such a manner that the window with the selection choices is
proportioned properly. These choices are defined in the contents of the
third bracket in the text. You can have a maximum of 3 choices with a
maximum of 20 characters in length. The separation of the individual
entries is again marked by the vertical line.
This function returns more than the position of the mouse pointer. You
also obtain the condition of the two mouse buttons and the <Shift>,
<Control> and <Alternate> keys. The call requires no parameters.
134
Abacus Software Atari ST Peeks and Pokes
The AES functions presented above used the output window on the
screen. In addition, BASIC offers four windows whose position and size
may be changed using the mouse pointer. To change one of these
windows from inside a program, another AES call is required. It concerns
the function 105 which has the name WIND^SET. With this function you
can move the window and change the outside edge of the window. For
example, it can prevent that window from being closed with the mouse.
Here a sample program to set the position and size of a LIST window.
By inserting another number in line 40, one of the other windows can be
changed.
The coordinates give the position of the upper left corner of the window.
The mode 5 is passed in line 60 sets the function to be executed by AES.
The following modes are permitted:
135
Atari ST Peeks and Pokes BASIC Programming
With these functions any window adjusted. BASIC program are made
more flexible this way.
136
Abacus Software Atari ST Peeks and Pokes
To store a text variable in a storage area, you can work with the variable
pointer VARPTR () and POKE. VARPTR (A$) points to a table in which
some information about the variable A$ is stored. The third and fourth
bytes are the storage address of the variable itself. It can be found with
the command A=VARPTR (A$). To load a file from diskette into the
string variable, which is also called a string, you can use the following
program:
With this program small files on disk (less than 200 bytes) can be read
into A$. Lines 40 to 80 are not required, but they are meaningful in
connection with an applications program (* .PRG). If one is loaded, the
beginning and the end of the actual program are calculated, and the
values output as decimal words. You can use this program to convert the
small machine language programs created with the assembler into DATA
lines. To do this you only need to type in the value output in DATA lines,
and to read it with the READ-POKE loop into the string again.
You can use this technique to store a larger text field to a diskette. It can
also be done with OPEN and PRINT#, but that takes considerably longer
than BLOAD or BSAVE.
137
Atari ST Peeks and Pokes BASIC Programming
Now we don't want to forget the real reason for text variables and their
usage. One of them is to store inputs, and if necessary to sort them. A sort
program of this type is very simple with the ST BASIC since it has a
SWAP command. Here is an example using the bubble sort algorithm:
First, you are asked to enter ten words. These are stored in the text field
W$ (). Next, they are sorted by comparing the words during a loop and if
necessary, their order is exchanged with the SWAP command.
7.4.1 Templates
138
Abacus Software Atari ST Peeks and Pokes
Line 15 checks the screen resolution, which is used in lines 180 and 60 so
the program will run on either a mono or color system.
Now the sort routine can be employed. If you want to sort the phone
numbers, only T$ (n, 5) must be sorted.
139
Atari ST Peeks and Pokes BASIC Programming
140
Abacus Software Atari ST Peeks and Pokes
This program calculates the selected position for the arrow from the
vertical position of the mouse pointer which is acknowledged with one of
the two mouse buttons.
A selection arrow does not need to be shown since the mouse pointer is
sufficient. The mouse pointer is more secure since small inconsistencies
could produce false results.
141
Atari ST Peeks and Pokes BASIC Programming
7.6 Input/Output
The normal input and output to these devices has already been discussed,
although the complete capabilities of the peripherals have not been
exhausted. Disks are divided into sectors and access to individual sectors
is not possible. The printer also has functions which we want to master.
Finally, we want to discuss the operation and programming of a modem.
The LPRINT or LLIST commands can be used to print out data and
programs. In addition to these we have the capability to output with the
OUT 0, x command with which any character can be output. This is not
limited to the output of visible characters, but control characters can also
be sent to the printer. The command OUT 0, x really corresponds to the
command LPRINT CHR$ (x) but is simpler to write and is faster.
Problems arise when different printers are connected to the ST. There is
no printer standard concerning the control codes that enable a printer to
print text and graphics. If you press the <Alternate>/<Help> keys the
computer will send some control characters to the printer that disable the
line feeds and set it into graphic mode. The problem which can occur is
the incompatibility of some printers. This means that some printers have
other control characters for various functions. The printer set-up which
was prepared by the desktop is no help here. The operating system loaded
from the disk, takes the required printer control characters from a table
which is located in memory at $16D5E. This table can be manipulated to
permit use of another printer with the ST. The sequence of the entries in
the table are as follows:
142
Abacus Software Atari ST Peeks and Pokes
Printing out the screen can start either with a combined keypress, or with
the selection of a menu choice Print Screen or with the command
POKE 1262,0.
To program the printer to print special symbols you have to send the
proper command sequences to the printer. You have the additional choice
of the resolution in which the printer should operate. <Esc> L sets this to
double density which is necessary for printing a high resolution screen.
You can select the normal resolution with an Epson black and white
printer with <Esc> K. A small sample program for the output of special
characters:
143
Atari ST Peeks and Pokes BASIC Programming
This example outputs a small UFO on the printer. The 27 is the code for
"Esc", the 75 is for "K". The 12 is the number of picture data items. With
a number larger than 255, the high byte of the number must be added to
the 128. After that, follow the data whose lowest bit is printed below. See
your printer manual for more information on programming your printer.
To use the disk drive for storing our program data, we can use the LOAD
and SAVE commands, or the BLOAD and BSAVE commands which have
already been described in section 2.2. The total control of disk access is
under BASIC or GEMDOS. However, it is also possible to take control
and to bypass the operating system. For this we need a machine language
program that can be stored in string variables.
In this section we want to examine a program that can do more. The first
part of the program reads the machine language program from DATA
lines into the text variable. This technique has been used before so that no
further explanation should be required. The second part of the program
determines which sector of the disk to read. The value input is introduced
into a machine language program to prepare it for this one sector. The
string variables D$ (0) and D$ (1) are then prepared to recieve the data
from the sector. Here two variables are needed which are located next to
each other, since a string can only be a maximum of 255 bytes long. The
variable D is then loaded with the beginning of the buffer.
Now follows the call of the machine language program which obtains the
buffer address as a parameter. The disk drive starts and the contents of the
selected sector are loaded into the buffer. Since each sector always
contains 512 bytes, D$ (0) andD$(l) are partially overwritten. Other
data buffers can also be used, but you have to be sure the memory region
is not used by some other program.
If the sector has been loaded into memory, its contents are displayed in
hexadecimal and as ASCII characters. This is helpful if you want to
investigate the directory of the disk. This table of contents starts in the
Atari ST disk format on side 0 in track 1, sector 1.
144
Abacus Software Atari ST Peeks and Pokes
145
Atari ST Peeks and Pokes BASIC Programming
Not only can the sector number be set, but also the unit number, the
number of sectors to be loaded, and the direction of the data. It is possible
to write from the buffer to the disk sector by changing the 0 to a 1 for the
data direction. Caution: attempts to write to a wrong sector can
completely destroy the disk. For example if you were to write over the
diskette's table of contents. We recommend that you work with a diskette
that does not contain important material.
This is a way to make a direct access to the diskette. The normal way is to
choose a name under which the data is stored on the disk. You issue a
LOAD"path:name. type" command and the program is loaded. The
path indicates the drive to be used, and/or the designation of the
subdirectories, and the category in which the file is located. The name is
the description of the file itself and can be a maximum of 8 characters.
The type (or extension) which appears at the end of the designation,
consists of three characters and is an abbreviation of the file usage. This
extension is arbitrary, but some of the type designations are reserved.
PRG means that it is an executable machine language program, BAS is
used for BASIC programs, etc.
146
Abacus Software Atari ST Peeks and Pokes
all programs with the extension . BAS are shown. The asterisk character
is a wildcard that represents all characters that could appear. You can
only change the selection line and perhaps show the programs from
another disk drive.
First of all we need two buffers for this. In the first the selection criterion
which we discussed before is stored. The other contains a file name. It is
not required, but the selection of OK or Discontinue will store the
name of the selected file in the buffer. Along with the path definition of
the other buffer, we now have the exact definition of the file available
which we can now use for storing or loading our data. Here is a program
that calls this function:
147
Atari ST Peeks and Pokes BASIC Programming
The beginning of this program consists of a VDI call. This function turns
on the mouse pointer, which disappears when a key is pressed. If you
omit the VDI function, and start the program without moving the mouse,
the cursor remains invisible during the entire execution of the function.
That is somewhat of a handicap for program selection.
Along with this the pointers for the AES parameters are defined. The
explanation of this process is in the chapter on menu and window
programming. The two buffers for the file definition are also prepared.
The two loops load these buffers with the value 0. This is necessary for
the proper operation of the AES routine.
Next, the parameters are transferred into the AES parameter tables.
ADDRIN (D) receives the two addresses of the buffers as longwords.
Finally we call the AES. After clicking one ofthe two choices ora double
clickon a file name, the selection window is erased and control is passed
to the BASIC program which issued the call. The two text variables now
contain the path, or name of the selected file.
In addition, the function transfers which way (OK or Cancel) the
termination of the function was achieved. The information is contained in
INTOUT (1). Unfortunately BASIC destroys this information before it
can be read, so we must evaluate the position of the mouse.
7.6.3 Telecommunication
148
Abacus Software Atari ST Peeks and Pokes
First we set the serial interface to 300 baud. Since most bulletin boards
send back every character received (a way to insure error-free
transmission), which is called echoing, we select as the operating method
Full-Duplex.
Now we connect the modem to the serial connector on the ST. To start
with telecommunications, we must run a suitable program which handles
the transmission. The simplest method is to call the VT-52 terminal
emulator of the ST. Every character typed in is automatically output on
the serial interface and all received characters are displayed on the
monitor. We can now call a bulletin board, and through the keyboard and
screen communicate with the other party.
149
Atari ST Peeks and Pokes BASIC Programming
In lines 10 to 40 some preparations are made. Lines 100-170 are the main
loop. Lines 180-300 print out the recieved data. Lines 1000-1550 are the
loader for the machine language. Lines 2000-4020 reads and displays
data from the keyboard or RS-232 port using the machine language
routine.
If only an asterisk (*) is input, the program is terminated and the text is
redisplayed. At this point a PRINT or an LPRINT can be used to send
the output to the printer and produce hardcopy of the session.
150
Abacus Software Atari ST Peeks and Pokes
A Font is the common term for the character set. The font set of the ST
contains an enormous variety of characters and symbols. The Greek
letters are available, which is helpful for physicists. Also mathematical
symbols such as V, J, or also <-> are available. You can provide scientific
text on the screen with the exact formulas.
For some applications you can define your own symbols. By doing this,
you can program games for example, by using a sequence of PRINT
CHR$ () statements which increases the speed of the graphics display
and at the same time simplifies the programming.
BASIC does not offer any way to define your own symbols. Instead you
have to use PEEK and POKE to change the font.
The operating system has 3 built in fonts. They are identical in design,
but differ in resolution. For the display on the monochrome monitor there
is a 8*16 character set, i.e. every character is 8 dots wide and 16 dots
high. For the color monitor it is only 8*8 since the vertical resolution is
only half as great. And finally there is the 6*6 font for identifying icons
or the files in the table of contents.
To change one of these fonts, you must know where they are stored.
In the version of the operating system that is loaded from diskette, the
8*16 font is located at 101474. In the version ofthe operating system that
is stored in ROM, the 8*16 font is located at 1659294.
The fonts are arranged in memory in rows. The first row of each of the
256 characters is stored in the first 256 bytes offont memory. The second
row of each of the characters is stored in the next 256 bytes of font
memory.
151
Atari ST Peeks and Pokes BASIC Programming
row 1 . . .
row 2 ...
row 3 . . .
•
• •
•
row 16 . . .
The most significant bit of the character determines the left upper point of
the character. In the standard character set, the topmost row is always
zero, i.e. white. This prevents two characters from overlapping.
Now to a program which changes the character output by PRINT
CHR$ (1). This character is the up-arrow character. The symbol can also
be obtained by typing <Control> A.
The program again uses the binary decimal conversion which we already
used. We'll once again use the image of a little man. Of course you can
change this character as you like.
Important: This program only works when TOS is loaded into RAM
from disk, it will not work with TOS in ROM! The programs in this
section only work on the monochrome monitor.
10 rem *** Change Font Character 7.7 ***
20 def seg=l : rem Set Byte brightness
80 for i=0 to 12 : read x$: rem Fill Shading
82 x=0 : for j=l to 8 : rem Change
84 x= x-(mid$(x$, j,l)<»* 2A(8-j)
86 next j
90 poke 105436+i*256,x:rem TOS on disk
100 next i
110 print chr$(l) : rem test output
152
Abacus Software Atari ST Peeks and Pokes
Ata
120 end
130 rem +++ Test Data +++
M
150 data *** »
"** * 1
180 data
II -
190 data kkkkkkk i
II
200 data kkkk k t
It
210 data kkkk k r
II kkkk f
220 data
II
230 data k k i
II k k
240 data i
II
250 data k k T
II
260 data k k f
II
270 data kk kk 1
If you want to change other characters, you only have to change the value
101474 in line 90. To create a new A, i.e. CHR$ (65) just add a 64 to
address 101474. You can create your own character set which you can
then store with BSAVE "MYFONT .FNT", 104536, 40 96 on the disk
and load later with BLOAD "MYFONT. FNT",104536.
This filename is not mandatory. You can store many fonts with files
saved in this manner and so prepare fonts for every application. Games
can be written or text prepared in the Cyrillic alphabet. The applications
of these fonts have no limit.
Some advice before you create your own characters, first store the
original font. If you do not need your characters any more, you can load
the the original font so that you can read the disk directory and the menu
choices.
153
Atari ST Peeks and Pokes BASIC Programming
Thus, you can have two different character sets, say one for PRINT and
one for OUT 2, x. Both fonts can also be combined. The program below
will work with TOS in ROM or RAM, simply change line 20. Here is an
application for the above mentioned method:
1 rem monochrome monitor only
5 rem *** Character Editor 7.7.A ***
10 defdbl a,b,c : rem pointer preparation
20 a=16595294: rem address of the original
font/TOS in ROM change to a=104536 for
TOS on disk
30 c=10532 : rem address of the pointer
40 x=a : rem copy font-pointer
50 dim a%(2050) : rem reserve position
60 for i=0 to 2050
70 a%(i)=peek(x+i*2) : rem copy font data
80 next i
100 c$="A" : rem to another screen
110 n=&H66 : rem bits of the top line
120 b=varptr(a%(0)): rem address of the new
font
130 poke c,b : rem change pointer
140 m=&HFF : rem screen preparation
150 o=asc(c$)
160 if (o mod 2)=1 then m=m*256 else
n=n*256
170 a%(o/2)=a%(o/2) and m or n
180 gosub 300 : rem modify test text
190 poke c,a : rem original font placement
200 gosub 300 : rem original test text
210 end
300 restore
310 for i=l to 9:rem output test text 'ABC
320 read x
330 out 2,x : next i
335 for i - 1 to 1000: next
340 return
350 data 27,72,27,66,27,66,65,66,67
154
Abacus Software Atari ST Peeks and Pokes
The first section of this program prepares the necessary pointers, then
copies the original font into the integer array a%. Note that every entry of
the character set requires two bytes in this array. For this reason, a mask
must be created when accessing a character; this mask will hide the extra
byte so that the byte you want changed will not be influenced. This mask
is set up in the second program section. This mask sets apart the second
byte, and overwrites it with the value n. For example, if the value $66 is
used, the A is altered.
The third part of this example displays ABC as the altered text. After
using the new font, the sample text will be output again, and will appear
as normal. This example shows just how easy it is to create a new
character set. Installing the new font data for applications is somewhat
more difficult. There is help, though. The program below is a simple
character editor which, although slow (in BASIC), will allow you to edit
fonts using the mouse.
The original character can be displayed within this pattern, although they
will appear unaltered with any PRINT statement. You will see "<" and
">" symbols beneath the original character. Click this symbol to display
the previous or next character.
155
Atari ST Peeks and Pokes BASIC Programming
position
320 if (peek (3581) and 1)=1 then 420
rem right button
330 if (peek(3581) and 2)=0 then 290
rem left button
340 if my =3 and mx = 24 then ch : ch - 1
goto 130
350 if my = 3 and mx = 27 then ch = ch + 1
: goto 130
355 if my < 0 then 300
356 if my >15 then 300
360 if mx>8 then 300
370 x = a%(ch/2+128*my)
380 m =2 A (7-mx+o) 'selected bit
390 if (x and m)=0 then x = x or m else
x=x and (m xor &HFFFF)
400 a%(ch/2+128*my)=x : ' renew
156
Abacus Software Atari ST Peeks and Pokes
Lines 420-440 save the new character set to disk. You click the right
mouse button to save the character set. You can re-load this character set
and re-activate it using the pointer at 10532. Now nothing stands in your
way to keep you from creating exotic fonts and character sets for your
programs!
157
Atari ST Peeks and Pokes BASIC Programming
The keyboard buffer in the Atari St can be accessed with the PEEK
function. The keyboard buffer does not return an ASCII value, but instead
it returns a scan code.The following program outputs the scan code
158
Abacus Software Atari ST Peeks and Pokes
Appendix A
Glossary
Addresses
Application
Assembler
Baud
Computers are equipped internally to work only with binary numbers, i.e.
numbers composed of 0 and 1. Binary digits (bits) are the smallest
information units in computer technology.
161
Atari ST Peeks and Pokes Glossary
Buffer Storage
Bus
Byte
162
Abacus Software Atari ST Peeks and Pokes
Centronics Interface
Clicking
Control Character
Control Panel
Cursor
Debugger
163
Atari ST Peeks and Pokes Glossary
Desktop
The main display level under GEM which contains menu lists, disk icons
and the waste basket.
Dialog box
An interactive window that provides information to the user and waits for
a response.
Disassembler
DMA
Duplex
Emulation
File
164
Abacus Software Atari ST Peeks and Pokes
Folder
Formatting
Before data can be written on a new disk, it must be formatted, i.e. tracks
and sectors must be set up.
Hardcopy
Hard Disk
Hexadecimal
165
Atari ST Peeks and Pokes Glossary
I/O (Input/Output)
These concepts describe the data read from peripherals (mass storage,
keyboard, mouse, etc.) into the computer or are sent from the computer to
the peripherals (display, printer, plotter, etc.)
Interface
Interrupt
K (Kilobyte)
Kilobyte really means 1,000 bytes, but in the computer field we calculate
in binary powers; a Kilobyte is therefore 2i° = 1,024 bytes.
Library
Linker
Menu
166
Abacus Software Atari ST Peeks and Pokes
MIDI Interface
Mnemonic Code
The actual machine code consists exclusively of ones and zeros. Since
commands consisting of only O's and l's would be difficult to read, easily
remembered alphabetic combinations were introduced. For example, the
sequence of ones and zeros which adds two numbers was changed to the
mnemonic code ADD. Programs written in mnemonic code have to be
translated by assemblers in order to create executable programs.
Object code
Output
Parallel Interface
Parameter
167
Atari ST Peeks and Pokes Glossary
PEEK
Peripheral
Pixel
POKE
Register
A video signal in which the three color signals are sent individually to the
television or monitor where they are additively mixed. The Atari ST can
represent each of these basic colors in 8 intensity steps to produce 8*8*8
= 512 color mixtures.
168
Abacus Software Atari ST Peeks and Pokes
RS232
Scrolling
VT52 Terminal
This choice of the desk menu causes the ST to emulate a VT52 terminal,
which can be directly connected through a serial interface to a modem or
to another computer.
Word
169
Atari ST Peeks and Pokes Important PEEKS and POKES
Appendix B
Important peeks and pokes for Disk and ROM versions of TOS
The first column is for the 197K operating system with the date
November 1985, the most common version loaded from disk.
The third column is to be used if the TOS is built into the computer. This
applies to the April 1986 version. These values are used in this book.
Address Function
170
Abacus Software Atari ST Peeks and Pokes
Index
171
Atari ST Peeks and Pokes Index
Desktop customizing 73
DESKTOP. INF 73,74,76 GB 131, 132
Dialog boxes 119, 133 GDOS 59
Digital Research 59, 82 GEM 3, 30, 56, 59, 60, 61, 64,
Disk access 144 66,69,85,99, 107,110, 111
Disk buffer 55 GEM desktop 27,56
Disk controller 10 GEM files 75
Disk drive 142 GEM flag 69
Disk icons 75 GEMDOS 10,87,89,94,98,
Disk directory 144 99, 144
DMA(Direct Memory Access) GEMSYS 60, 131, 132, 133, 134,
controller 4 135
Documents 75 GIOS 59
Double 87 GLOBAL 131
Double precision 132 GLUE 4
DRLOGO 83 GPO (General Purpose Output)
Drop-down menus 63 127
Graphic images 37
Ellipse 109, 110 Graphic buffer 69
ELSE 87 Graphic processing 107
Epson black/white printer 143 Graphics Environment Manager
Error messages 133 59
Error Vectors 28
Exception 28 Handshake line 7
Expansion plug 13 HD6301V1 4,20
Extended BIOS 100 HEX$ 44
Extension 37 Hexadecimal 41, 48, 144
Hexadecimal number system 42
FILL 116, 118 Horizontal sliders 75
Fixed memory locations 26
Float 87 I/O (Input/Output) chips 27
Floating point number 86 I/O registers 125
Floppy disks 25, 33, 34 IBM PC 3,85
Floppy-disk controller 4 Icon oriented 51
Folders 75 Icon oriented screen 56
Font 66, 69 IF 87
FOR 87 II 132
FOR-NEXT loop 99 Indirect Addressing 91, 92
FORM ALERT 133 INPUT# 36
FORTH 82 Int 87
FORTRAN 84,85 Integer variables 30
FORWARD 83 Interfaces 6
172
Abacus Software Atari ST Peeks and Pokes
173
Atari ST Peeks and Pokes Index
POKE 53, 60, 62, 67, 68, 69, 83, Shaded characters 66
88,91,98-100,105, 106,141, Shaded circle 109
143 Shaded rectangle 108
Polyline 114 Shading 116
Port A 127 Shading pattern 117
PortB 127 Shading style 117
Post incrementing 92 Shifter chip 4
Predecrementing 92 Short 87
PRINT 85,89, 113, 135 Shugart connections 11
PRINT* 36, 137 Sine 107
Printer 142 Sine wave 128, 129
PRFNTF 85 Sine wave generator 123
Procedures 82 Siren sound 127
Processor 3 Sort routine 138, 139
Programs 35 SOUND 123, 129
PTSIN 60,67 Sound chip 5
PTSOUT 60 Sound register 128
ST LOGO 82
RAM 25,53 Stack 32, 33
RAM/ROM 25 Stack Pointer 91
Recursive program 21 Startbit 9
Register direct 91 States 42
Register memory 55 Status Register 91
Registers 89 Stopbit 9
Relative addressing 92 Storage devices 25
RETURN 99 String variables 137, 144
RGB 4 Strobe 7
RIGHT 83 SWAP 138
ROM 12, 13, 25, 26 SYSTAB 68,69
Roman font 69 System variables 132
RS-232 8 System variables 53
RTS 93,98,99 System-Timer 54
RTS/CTS 100
TD 8
SAVE 144 Template 138
Screen mask 138 Text editor 84
Screen memory 25, 54 Text formatting 110
Sector 34, 35, 142, 144 Text variable 144
Select line, 12 Token 84
Serial interface 8, 88, 99, 127 Tone 123
SF314 disk drive 34 Tone generation 127
SF354 disk drive 34 Tone generators 123
174
Abacus Software Atari ST Peeks and Pokes
Underlined characters 66
UNIX 85
User-defined pattern 118
XBIOS 52,94
XON/XOFF 100
XOR 45, 46, 47
175
Optional Diskette
Tfrrrrrrrrrrfrrrrrrrrrr^^
ATARI ST
w
Peeks
and Pokes
Optional Diskette
For your convenience, the program listings contained in this book are
available on an SF354 formatted floppy disk. You should order the diskette
if you want to use the programs, but don't want to type them in from the
listings in the book.
All programs on the diskette have been fully tested. You can change the
programs for your particular needs. The diskette is available for $14.95 plus
$2.00 ($5.00 foreign) for postage and handling.
When ordering, please give your name and shipping address. Enclose a
check, money order or credit card information. Mail your order to:
Abacus Software
P.O. Box 7219
Grand Rapids, MI 49510
PRESENTING THE ST ST Beginner"* Quid* ST INTERNALS OEM Programmer'• Ref. MACHINE LANGUAGE ST TRICKS A TIPS
Essential guide to tha inside For serious programmers Program In tha fastest lang Fantastic collection of pro
Give* you an in-depth look at Written for the firsthand ST grams and info for the ST.
this sensational new user. Get a basic understand information of the ST. needing detailed information uage for your ATARI ST.
Detailed description* of on GEM. Presented In an Learn 69000 assembly lang Complete programs Include:
computer. Discusses the ing of your ST. Explora super-fast RAM disk: time-
architecture of tha ST, work LOGO and BASIC from tha sound and graphics chips, *asy-to-und«rstand format. uage. Its numbering system.
Intarnal hardware. I/O ports. AD examples ar* in C and use of registers, structure & saving printer spooler; color
ing with GEM, Km mousa, ground up. Simple explan
using GEM. Commented assembly language. Covers Important details of instruc print hardcopy; plotter output
operating system, all the ations of the hardware and
BIOS listing. An indlspen- VDI and AES functions. No tion set, and us* of Internal hardcopy, creating access
various interfaces, the 66000 Internal workings of tha ST. ories. Money saving tricks
chip and its Instructions, Illustrations, diagram*. Gloss sibie reference tar your ST sarioun programer should be system routines. Geared for
library. 4S0pp $18.95 without 410pp $1805 the ST. 260pp $18.85 and tips. 260pp $18.85
LOGO. 200pp $16.85 ary. Index. 200pp $14.95
and sound on tha ST. 2D A learning ST LOGO—the easy the examples found within ST BASIC programming. you're already a BASIC and shade 3D objects. All
this book. Explores using Detailed programming funda programmer, you can learnC programswritten In machine
3D function plotters. Mo|r* to use, powerful language. mentals, commands descrip all that much faster. Parallel language for high speed.
patterns, graphic memory Topics Include: file handling, different languages BASIC,
C, LOGO and machine tions, ST graphics & sound, examples demostrate the Learn the mathematics
and various resolutions, recursion-HI Ibart & Sierpinakl using GEM In BASIC, file programming techniques and behind 3D graphics. Hidden
fractals, recursion, waveform curve*, 2b and 3D function language, using various
Interfaces, memory usage,
management, disk operation. constructs In both languages. line removal, shading. With
generation. Example* written plots, data structure, error Tutorial problems give hands Variable*, pointers, arrays, 3D pattern maker and
In C. LOGO, BASIC and handling. Helpful guide for reading and saving from and
to disk, more. 260pp $16.95 on experience. 300pp $16.95 data structure. 250pp $19.95 animator. $24.95
Modiia2. 250pp $1985 ST LOGO users. $18.95
The ATARIlogoand ATARIST aretedemarks of Atari Corp.
Abacusl^fflSoftware
P.O. Box 7219 Dept. A9 Grand Rapids, Ml 49510 •Telex 709-101 •Phone (616) 241-5510
Optional diskettes are availablefor all book titles at $14.95
Call now for the name of your nearest dealer. Or order directly from ABACUS with your MasterCard, VISA, or Amex card. Add
$4.00 per order for postage and handling. Foreign add $10.00 per book. Other software and books coming soon. Call or
write for your free catalog. Dealer inquiries welcome-over 1400 dealers nationwide.
AA Rated Software
Atari and Abacus
DataTrieve PaintPro
_/lV
The electronic Create double-
filing system sized pictures
for the ST For erg—~p*~-
PaintPro
Multiple
windows
AssemPro PCBoard
The complete 68000
assembler development
Designer
Create printed circuit board layouts
package for the ST
ABACUS SOFTWARE
Suggested Retail Price: wmtm P. O. Box 7219
Grand Rapids, Ml 49510
$49.95 HUH! Phone:(616)241-5510
ST TextPro
for the Atari ST
ABACUS SOFTWARE
Suggested Retail Price: P. O. Box 7219
Grand Rapids, Ml 49510
$49.95 Phone:(616)241-5510
Multi-Tasking
Full-Featured
ABACUS SOFTWARE
HHHUB P. O. Box 7219