Atari 800 Robotics
Collage of Robots

What an Atari 800 Can Do
Obtaining and Operating an Atari 800
Programming the Atari 800
Programming the Atari 800 to Control External Devices
Programming the Atari 800 to Acquire Data
Building the Control Circuit

What an Atari 800 can do

In its four joystick ports, an Atari 800 has a total of 16 pins which can be used for input or output, and 4 input-only pins. If you connect wires to the console buttons you can get 3 more bits of input. It also has eight analog-to-digital converters (paddle readers) which read values from 0 to 228. This is a great deal more "pin-level" IO capacity than a PC parallel port.

Obtaining and Operating an Atari 800

The Atari 800 is an ancient personal computer (from the early eighties). It has a 1.77 MHz, 8-bit CPU and 48k of memory. They can be bought today at thrift stores and garage sales. Before buying one, ask all your friends if they have one. Chances are, somebody you know has one in a closet somewhere. Be sure to open up the top cover and check for the necessary cartridges. There are four memory slots behind two smaller program cartridge slots. You'll need a BASIC cartridge in the front, left slot, a 10k ROM cartridge in the front memory slot, and at least one RAM cartridge behind that. The maximum memory is 48k using three 16k cartridges. The memory will limit the size of your control program. You'll also need the external power supply. The Atari produces an RF video signal on channel 3 or 4 and connects to a regular TV like a video game machine.

If you plan to write a complex control program, you'll want a 5.25" Atari disk drive. They're harder to find than the computers. Otherwise you'll have to type in the program each time you turn on the computer. A very simple program, like one to randomly flash a strobe light, could be typed in in less than a minute, but the Atari 800 is capable of much more. To use the disk drive, you'll also need a DOS boot disk, another power supply, and the data cable.

If you have a floppy drive and you can find the BASIC editor/interpreter executable file, you can load BASIC from your floppy. You won't need a BASIC cartridge.

An additional advantage of a floppy drive is the ability to automatically recover from a power failure. If you have the file called AUTORUN.SYS and a BASIC program named HELLO on a bootable floppy, and you have a BASIC cartridge in the computer, when the Atari 800 and the floppy drive are powered on simultaneously, the disk will boot and HELLO will be run. The BASIC program must be saved, not listed (see below). If you set the ports to output before the floppy stops spinning, it will keep spinning. Just include a delay at the start of the program to prevent this.

There's a program called "My Utility" written by Mark K. Vallevand which allows single-sided "double density" (180k) Atari floppies to be read and written in a 5 1/4" PC floppy drive. The Atari 810 floppy disk drive is "single density" and won't work with "My Utility".

It's possible to load programs into the Atari 800 from a cassette tape, but I don't have any details.

Sometimes the keys on old Atari 800 keyboards stop working reliably. If the keys don't get better after some use, then the only way to fix it is to disassemble the computer and fix the connections between the two plastic layers of the keyboard. There is a row of connections along on edge of the keyboard which are simply pressed together to make continuous electrical contact. They can be fixed by coating them with conductive grease, gluing them together with conductive glue, or by increasing the pressure on the connections by inserting a spacer. When you unscrew the bottom of the keyboard and peel apart the layers, it's fairly obvious what contacts I mean. Pressing really hard on a key can make it work because the pressure bends and distorts the keyboard making the continuous connections between the layers work momentarily. Pounding on the keys or pressing harder can't affect the membrane switches under the keys because the keys have a spring-loaded mechanism which applies the same pressure to the switch no matter how hard the key is pressed.

The Atari 400 is basically the same as the 800, but with only one cartridge slot and a membrane keyboard. It also usually has less memory. They originally came with 8k or 16k, but they could be expanded to 48k. To find out how much memory a particular Atari 400 has, put in the BASIC cartridge, leave the floppy drive off, turn it on, and type:


and hit [RETURN]. (That's a zero, not the letter "O".) If it says 37902, it has 48k.

The Atari 800XL isn't nearly as useful for robotics as the 800 because it only has one pair of joystick ports. It does, however, have built-in BASIC, no cartridge needed. (It does have some type of parallel port in the back, but I don't have any information on programming it.)

The Atari 8-bit FAQ from the comp.sys.atari.8bit newsgroup has a great deal of general information including the types of floppy drives.

Peter Nyman's Atari 8-bit Page has lots of links to Atari 8-bit utilities including versions of Atari DOS and Atari-to-PC transfer programs. It also has links to programming references.

The Atari Peripheral Emulator (APE) is a program which allows an IBM PC to simulate the presence of multiple Atari hard drives and floppy drives for an Atari computer using a special cable which connects between the Atari serial port and the PC serial port. It also allows programs running on the Atari to use a printer connected to the PC and to access individual files on the PC hard drive. The registered version of APE is $40. A shareware version with nags and limitations is available. The cable can be purchased for $60 or you can build it yourself using the free instructions on the site. The cable uses a 1489 IC chip and a diode. Shipping is $5 unless you are buying the cable too.

Programming the Atari 800

When you turn the computer on with a BASIC cartridge inserted, you'll get a READY prompt. Now you can start typing in program lines and commands. Atari BASIC is fairly simple. Type this, pressing [RETURN] at the end of each line:

10 FOR A=0 TO 10

Now type: RUN[RETURN]

You'll see the numbers from 0 to 10. Now, modify the program by re-typing line 20:

20 PRINT A;",";

This will add a comma after the number, and the semicolon at the end will make the next thing printed appear on the same line rather than the next line.

Run the program again to see: 0,1,2,3,4,5,6,7,8,9,10,

You can use [CTRL] plus the arrow keys to move up to a listed line and edit it. You can insert and delete in the line with [CTRL]+Delete and [CTRL]+Insert. Just be sure to press [RETURN] when you're done or your changes won't be entered.

Use the STEP command to make a loop count backwards or count by any number.

1030 FOR A=10 TO 0 STEP -1
1040 FOR T=0 TO 100 STEP 10

The Break or System Reset keys can be used to stop a running BASIC program. System Reset does NOT erase the current program. The NEW command erases the current program.

New lines can be inserted by choosing an appropriate line number.

Type LIST (or L.) to see your program. With programs larger than one screen, you can pause the display by pressing [CTRL] and the numeral one. You can also list a range of line numbers:

L. 20,50

This command clears the screen: GRAPHICS 0

You can print anywhere on the screen by positioning the cursor:

10 POSITION 11,11

Comments are done like this, but keep them short since your memory is limited:


Mathematical operators look like this:

120 A=(100-B)*(C+(22/D))

To raise 2 to the 5th power use:

50 ANSWER=2^5

However, the power function doesn't work perfectly. According to Atari BASIC, 2^5 is 31.99993444. You can correct the value if you know it's an integer by using INT((2^5)+0.1). This will return 32.

Variables can be whole words, but must start with a letter:


The IF/THEN command is essential. All the commands separated by colons after the THEN will be executed if the condition is true. Notice that the equals sign means two different things depending on where it is used.

5010 IF A>20 THEN A=0
5040 IF (A=12 AND B=13) OR (A=14 AND B=15) THEN TIMER=60

The INPUT command allows a program to ask you to enter a value into a variable.


PEEK and POKE allow you to read and write numbers (0 to 255) directly from and to memory locations.

100 VALUE=PEEK(54016)
110 POKE 710,VALUE*10

The Atari 800 has a built-in clock. It's simply 3 memory locations which count in 60ths of seconds. This program will reset the clock to zero and then continuously print the clock value.

10 POKE 18,0
20 POKE 19,0
30 POKE 20,0
50 PRINT PEEK(18)*65536+PEEK(19)*256+PEEK(20)
60 GOTO 40

To get whole seconds change line 50 to:

50 PRINT INT((PEEK(18)*65536+PEEK(19)*256+PEEK(20))/60)

To use this to time an event, you'd simply add a value to the current clock value and store it in a goal variable. Then periodically check to see if the current clock value is greater than the goal.

Useful Atari 800 memory locations:
709 -- Color of the text.
710 -- Background color of the text screen.
755 -- POKE 755,0 to make the cursor invisible. (It looks nicer when you're printing stuff repeatedly to the screen.) POKE 755,2 to make it visible again.
764 -- The key currently being pressed on the keyboard. You'll have to determine what numbers correspond to what keys by experimenting.
32789 -- PEEKing here will tell you the status of the console keys: Option, Select, and Start. See below for details. POKE 32789,0 makes the built-in speaker click. Put it in a short loop to make a buzz. In BASIC you can only make clicks and buzzes, but it does allow the computer to get your attention without having to leave a TV on all the time.

For a complete list of what the memory locations do, I recommend "Mapping the Atari" by Ian Chadwick (Compute! Publications, 1983). Good luck finding it though.

To save and load BASIC programs to and from the disk drive use either SAVE/LOAD or LIST/ENTER. The filenames have up to 8 letters, then a period, then up to three letters. Just enter these commands at the READY prompt:



SAVE and LOAD are faster and take less disk space, but there's a bug in the Atari BASIC editor which can corrupt your programs after multiple cycles of running and editing. LISTing the program to disk, turning the computer off and on, and then ENTERing the program from the disk, resets the "countdown to corruption", so to speak.

I recommend using SAVE to frequently save your work as you program, but when you're done working for the day, LIST the program to disk. After stopping a running program, typing CLR[RETURN] and then END[RETURN] before editing the program might prevent the problem.

These are just the essentials of Atari programming. The Atari 800 also has a four-channel tone generator. It has multiple text and graphics modes which can be mixed together on the screen. And it has "player/missile" graphics (sprites). Atari BASIC can handle text strings and arrays, it can store data in and retrieve data from files on a floppy, it has several mathematical functions, and it can execute machine language subroutines for greater speed.

Programming the Atari 800 to Control External Devices

There are 4 pins in each of the four joystick ports along the front of the computer which can be turned on and off to run transistor-controlled relays. The ports are grouped into two pairs. The left two ports are controlled by one set of memory locations, and the right two by another set. You can set one pair of ports to output and the other pair to input.

This set of POKEs sets the two left ports to output:

POKE 54018,48
POKE 54016,255
POKE 54018,52

And these set the two right ports to output:

POKE 54019,48
POKE 54017,255
POKE 54019,52

(From now on I'm going to refer to only 54016 and the left-hand pair of ports since both pairs of ports work the same way. Substitute 54017 for 54016 to control the right pair of ports.)

After setting the pair of ports to output, the number you POKE into 54016 will be displayed in binary by the pins of the two ports. The ports have 5 pins across the top, and 4 across the bottom (standard RS232). As you look at the computer, pins 1 through 5 run across the top from left to right, and pins 6 through 9 run across the bottom from left to right.

Pin 8 of each port is ground (negative). When a pin is off, it has about 35 millivolts relative to the ground pin. When it's on, it's about 5 volts.

Pin 1 of the left port corresponds to the binary digit valued at 1
Pin 2 of the left port corresponds to the binary digit valued at 2
Pin 3 of the left port corresponds to the binary digit valued at 4
Pin 4 of the left port corresponds to the binary digit valued at 8
Pin 1 of the right port corresponds to the binary digit valued at 16
Pin 2 of the right port corresponds to the binary digit valued at 32
Pin 3 of the right port corresponds to the binary digit valued at 64
Pin 4 of the right port corresponds to the binary digit valued at 128

Add together the binary digit values of the pins you want to turn on, and POKE that value into 54016.

For example, if you want pins 2 and 4 of the left port, and pin 3 of the right port to have power, you add up their values (2+8+64) and POKE the total, 74, into 54016.

Here's a little program which makes the 8 pins chase. You can hook LEDs directly to the pins for testing. Hook the negative lead of the LED to pin 8 (ground) and the positive lead to one of the output pins.

30 POKE 54018,48
40 POKE 54016,255
50 POKE 54018,52
60 FOR B=0 TO 7
70 POKE 54016,INT((2^B)+0.1)
90 GOTO 60

The power function is so slow that no time delay is needed in this program.

Line 70 needs some explanation. The power function of Atari BASIC doesn't work properly. 2^2 returns 3.99999996. Also, the INT (integer) function doesn't round to the nearest integer, it just drops everything after the decimal point. So what I've done here is to increase the number so it's just over the correct value, and then use INT to chop off everything after the decimal point to get the correct integer value. Hey, it works.

Programming the Atari 800 to Acquire Data

Each of the four joystick ports has a joystick button, STRIG(0) through STRIG(3), and two paddle buttons, PTRIG(0) through PTRIG(7). When a pair of ports is set to output, the joystick buttons still work, but the paddle buttons don't because they use pins 3 and 4. The joystick trigger is pin 6. Connect pin 6 to pin 8 (ground) on the leftmost of the four joystick ports to make STRIG(0) return zero.

10 IF STRIG(0)=0 THEN POKE 53279,0

Paddle Circuit Each of the four ports has two paddle readers. The paddles are numbered 0 through 7. Pin 7 is paddle ground. On the leftmost of the four ports, pin 9 is PADDLE(0) and pin 5 is PADDLE(1). Connect your variable resistor across pin 7 and pin 9 for PADDLE(0).

The paddle pins read resistances from about 10 ohms to about 570,000 ohms. PADDLE(0) through PADDLE(7) return vales from 0 to 228 inclusive. The paddles always work, even when the ports are set to output. Here's a programming example:

10 IF PADDLE(6)>200 THEN POKE 53279,0

If you don't set a pair of ports to output, you can read from them. PEEK(54016) equals the total of all the binary digit values (see above) of pins NOT connected to ground. This program will set the variables P1 through P8 to 1 if the corresponding pin is connected to the ground pin (pin 8), or 0 if it isn't.

10 P1=1
20 P2=1
30 P3=1
40 P4=1
50 P5=1
60 P6=1
70 P7=1
80 P8=1
90 A=PEEK(54016)
100 IF A>127 THEN P8=0:A=A-128
110 IF A>63 THEN P7=0:A=A-64
120 IF A>31 THEN P6=0:A=A-32
130 IF A>15 THEN P5=0:A=A-16
140 IF A>7 THEN P4=0:A=A-8
150 IF A>3 THEN P3=0:A=A-4
160 IF A>1 THEN P2=0:A=A-2
170 IF A>0 THEN P1=0

This program can be entered much faster by using the arrow keys. Type in line 10, press [RETURN] and then use the arrow keys to move up to the line number and change it to 20. Then press [RETURN] and repeat the process up to line 80. Then LIST the program and change the variable names to P2, P3, etc.... Then move back to the top and press [RETURN] for each line. Use a similar procedure to enter lines 100 through 170.

Add these lines to make it continuously display the pins:

180 POSITION 2,0
190 PRINT P1;P2;P3;P4;P5;P6;P7;P8
200 GOTO 10

After setting the pair of ports to output, you can set them back to input with:

10 POKE 54018,48
20 POKE 54016,0
30 POKE 54018,52

In fact, you can set each pin to either input or output individually. Add up the binary digit values (see above) of each pin you want to set to output, and POKE that value into 54016 on line 20 above. This is especially useful with Atari 800XLs since they have only one pair of ports.

If you're handy with a soldering iron, you can wire up the three orange console buttons for an additional 3 independent inputs. Just take the bottom off the computer. It's easy to find the points to solder to. The buttons' bit values are added to PEEK(53279) if the buttons are NOT pressed.

Option is bit value 4
Select is bit value 2
Start is bit value 1

This routine will assign a 1 to the variables OPTION, SELECT, and START if the corresponding button is pressed.

30 START=1
40 A=PEEK(53279)

The keyboard connects to the computer internally through a ribbon cable and plug. This could be tapped into for several more bits of input, but I don't have details.

The System Reset key actually calls a particular interrupt. It could be reprogrammed to provide another bit of input. However, this would require machine language programming.

Building the Control Circuit

Output Circuit The +V and -V are the input voltage which should match the voltage of the relay. The diode between the emitter and pin 8 is a safety precaution which prevents power from flowing backwards into the computer. The diode connected across the relay coil absorbs the voltage spike generated when the relay switches off. Reproduce this circuit for each pin (1 through 4) you wish to use for output.

If you buy the NPN transistors at Radio Shack, the package will show which leads are emitter, base, and collector. The stripe on a diode is nearest the negative lead. The negative lead connects to pin 8 in the diagram.

Most transistors will handle enough power for most relays. A common 5x5x4 millimeter transistor will power relays up to an inch or two in size. For example, the 2N2222 transistor can handle 800 mA, while an inch-and-a-half-tall relay (Radio Shack part number: 275-218C) only draws 75 mA. On the transistor package the maximum current may be called any of these:

CE current (or amperage)
Collector current (or amperage)
Collector/emitter current (or amperage)

It will be given in milliamps (mA).

Make sure the relay's current ("nominal current" or "coil current" on the package) isn't greater than the transistor's maximum current. If the relay pulls more current than the transistor can handle, the transistor will overheat and burn out. I don't think it would hurt the computer with my circuit, but I can't guarantee that.

Be sure the relay is rated to handle the amount of power you intend it to switch. The package should say something like, "Contact rating: 1.7 amps @ 125VAC". This means 212.5 watts of house outlet power. (Volts times amps equal watts.) Such a relay would handle at least 1.7 amps at a lower voltage, but not necessarily 212.5 watts.

Feel free to E-mail me with questions. They'll help me improve this page. However, please don't ask questions about graphics programming on the Atari 800. It can get very complicated. And don't ask questions which you could figure out for yourself by doing a simple experiment!
Text and circuit diagrams copyright 2010 R. Allen Gilliam. All rights reserved.
I am serious about this copyright. I will sue you if you republish this page.
The BASIC program code may be used, but not republished.

[ Main Halloween page ]