Make your own free website on Tripod.com
APPLE II INTERFACING: HOW TO CONTROL REAL-WORLD DEVICES VIA THE GAME PORT 
A Summary of the 1994 ICONference Session by Erick Wagner 

------------ 
About Myself 
------------ 
 
My name is Erick Wagner.  I'm an Apple II enthusiast and an 
electronics hobbyist.  I began using Apple 
II computers, specifically the II+, during the Summer of 1982 while 
attending Texas A&M University.  I  purchased my own computer, an Apple 
IIe, towards the end of 1984 and, as a challenge, attempted to  interface 
my Epson APL printer card with a variety of external devices (LEDs, 
electronic drum, etc.).  I briefly experimented with an I/O peripheral 
card featuring the Motorola 6821 Peripheral Interface Adapter (PIA) chip 
and then became distracted with other interests.  I did not get back into 
computer interfacing until the Spring of 1994, when I enrolled in a 
Digital Control Applications course at my local community college.  A 
6502-based microcomputer trainer was used, the EMMA II from L.J. 
Electronics, along with a 6522 Versatile Interface Adapter (VIA) chip to 
program its built-in I/O ports and internal timers.  This motivated me to 
try some new things on the Apple II, including interfacing via the 
built-in game ports. 
 
-----------
Why Bother? 
-----------
 
Question: Why would someone want to interface a computer with a 
real-world device? 
 
Perhaps it is the challenge; "because it is there" -- man (sorry ladies, 
not trying to be disrespectful) is a curious creature and seeks to 
understand and master his environment.  Or perhaps there is a real 
problem or need that needs to be solved or satisfied. 
 
In case you are having difficulties in thinking of a reason, consider the 
following: 
 
o Monitor the pH level in a swimming pool 
o Build a home control system 
o Build a home security system 
o Construct an automated weather station to measure the temperature,
  wind speed, and barometric pressure 
o Learn the fundamentals of personal robotics (controlling stepper
  motors and sensors) 
 
-------------------
Types of Interfaces 
-------------------
 
PARALLEL - the simultaneous transmission of information over more than 
one wire; usually in multiples of 4 or 8.  Most modern computers provide 
at least an 8-bit data bus but some offer a 16-bit or 32-bit bus.  
The most common parallel interfaces are typically used for disk drives or 
printers.  Some well-known examples include SCSI and the Centronics 
interface. 
 
SERIAL - the time-sequential transmission of information over a single 
wire.  The most common serial interfaces are typically used for 
keyboards, mice, printers, and modems.  Some well-known examples are 
the Apple Desktop Bus (ADB) and RS-232. 
 
DIGITAL - A signal consisting of a group of pulses that are either on or 
off; discrete values ("1" and "0") are used. 
 
ANALOG - Circuitry that varies certain properties of electricity (such as 
voltage, current amplitude of waves or pulses, or frequencies of waves or 
pulses) continuously and smoothly over a certain range, rather than 
switching suddenly between certain levels.  Signals that do not have 
discrete values, but are continuously variable. 
 
GAME PORT - Provides a combination of digital inputs (push button lines 
PB0 through PB2 -- or PB3 if you have a IIgs), digital outputs 
(annunciator lines AN0 through AN3) and analog inputs (GC0 through 
GC3) as well as a strobe output (only for II,II+,IIe). 
 
-------------------
Choice of Computers
------------------- 
 
The Apple II series is an ideal platform for learning about computer 
interfacing, although other computers are also well-suited for this 
task.  The reasons in favor of the Apple II include but are not limited 
to: 
 
The Apple II series has provided a wide-range of interfaces (slots [II,  
II+, IIe, IIgs], cassette in/out [II, II+, IIe], 16-pin game port [II, 
II+, IIe, IIgs], 9-pin game port [IIe, IIc, IIc+, IIgs], and serial ports 
[IIc, IIc+, IIgs]).  Notice that a general-purpose parallel interface is 
conspicuously missing. 
 
Today, Apple IIs are relatively inexpensive and readily available.  You 
can find them at swap meets, consignment stores, garage sales, auctions, 
and listed in classified ads. 
 
-----------------
Items to Consider 
-----------------
 
In my opinion, the best Apple IIs to use for interfacing would be the 
Apple IIe or the IIgs, although a II+ will work just fine.  The newer 
machines are better equipped to run the latest system software, such as 
ProDOS 8, and are more likely to be compatible with today's software. 
 
The closed-architecture machines (IIc, IIc+, Laser 128) provide access to 
fewer game port signals and the built-in serial ports are more difficult 
and expensive to interface with. 
 
-----------------------------
Explanation of Demonstrations 
-----------------------------
 
Use of Annunciator Outputs with a Game Port Breakout Box 
 
A custom ProDOS 8 system program and a homemade game port breakout box 
were used to "exercise" the annunciator lines of the 16-pin game port.  
The system program counted from 0 to 15 and sent the count value to the 
appropriate annunciator lines (AN3 AN2 AN1 AN0) so the value could be 
"seen" as a 4-bit value.  The program used the arrow keys to increase or 
decrease the time delay value between each count.  A logic probe was used 
to sample each of the annunciator output lines and proved that the 
computer was in fact doing something. 
 
A-to-D 
 
An inexpensive 10-bit Analog-to-Digital converter (Vernier kit #CAD-16 -- 
approximately $32) was used to monitor voltage inputs with a program that 
simulated a storage oscilloscope.  The voltage input sources included a 
AA battery (1.5 VDC) and an electric motor which was manually manipulated 
to operate as a crude generator.  A-to-D (also known as ADC or A/D) 
devices measure analog voltages (continuously variable values) and 
convert the voltage readings into digital numbers the computer can 
understand and work with.  The 10-bit digital numbers were sent to the 
Apple II in serial format (one bit at a time) by pulsing or not pulsing 
the PB2 push button input.  The particular integrated circuit (chip) used 
for this project was the Linear Technology LTC1092 which outputs it 
result in a serial format, rather than the more common parallel output.  
This project utilized the 16-pin game port because a couple of the 
annunciator output lines were used to control the LTC1092 chip. 
 
Stepper Motor 
 
A Unipolar Stepper Motor was interfaced to the 16-pin game port using the 
Allegro Microsystems (formerly Sprague) UCN-5804B integrated circuit 
(Vernier kit #CSU-16 -- approximately $16).  With this chip, only two 
digital output lines (AN0 and AN1) are needed to control a stepper motor; 
additional lines could be used to provide even greater flexibility.  One 
line was used to indicate the direction to turn (clockwise if HIGH or 
counter-clockwise if LOW) and the other line wass used to pulse the chip 
each time a step is desired.  In case you didn't know, stepper motors are 
very precise motors which advance one increment each time the electrical 
signals to their lead wires are changed. Everyday uses include printers 
where they move the print head and rotate the platen and disk drives 
where they position the read/write head over the appropriate track.  A 
program, called MOTOR.TEST, which accompanied the "Chaos in the 
Laboratory" book from Vernier Software provides the ability to rotate the 
motor in both directions and in three different speeds for the exact 
number of steps you specify. 
 
Ultrasonic Range Finder 
 
A Texas Instruments SN28827 module and a Polaroid ultrasonic transducer 
were interfaced to the 16-pin game port and used as a range finder 
capable of measuring distances ranging from 0.4 meters to 10.7 meters 
(1.33 feet to 35 feet).  A carefully written (time dependent) program was 
used to send out pulses of ultrasonic sound and time how long it took for 
the echo to return. Computations based on the speed of sound were then 
used to calculate actual distance. 
 
----------
References 
----------
 
Apple II Technical Notes - these can be downloaded from most online 
services but a complete set can be purchased from the ByteWorks 
(previously, these were available from APDA and Resource Central) 
 
Books - hardware reference section/manual for your computer.  Also see 
the list at the end of this article 
 
Internet Newsgroups (Usenet) - check out the computer, electronics, and 
robotics forums 
 
Online services (e.g., GEnie, CompuServe, America Online) 
 
Magazines - see the list at the end of this article 
 
User groups (e.g., computer, robotics) - visit or join your local 
computer and robotics user groups.  You will definitely learn something 
new, make some new friends, and locate your local experts. 
 
-------------------
Equipment and Tools 
-------------------
 
Computer - this one's kind of obvious isn't it! 
 
Game Port Extender - a special extension cable which plugs into the 
16-pin game port connector (II,II+,IIe,IIgs) on the motherboard and makes 
available a zero insertion force (ZIF) socket which is mounted outside of 
the computer.  This makes the task of plugging and unplugging devices 
much less frustrating! Otherwise you have to: (1) "pop the lid" of your 
machine, (2) use a chip puller to remove the existing device from the 
16-pin game port connector, (3) feed the plug of the new device through 
one of the holes on the back of the computer, (4) insert the new device 
into the socket with the correct orientation and without bending or 
breaking any pins, (5) replace the cover.  With the ZIF, you simply: (1) 
move the lever in one direction to release the grip and easily lift out 
the current device's plug, (2) insert the plug of the new device, (3) 
move the lever back to lock it into place.  Approximate cost is $16. 
 
Power Supply - If the devices you plan on hooking up to your computer 
require a significant amount of current (100 mA or more) or require 
voltages which are not available (anything but +5 V), you will need 
to purchase an external power supply.  Be sure to get one that can supply 
more current than you will need; an ampere rating of 2 or 3 Amps should 
be plenty unless your equipment is power hungry.  Be aware that when more 
than one power source is used (+5 V from the game port counts as a power 
source) and when one or more peripheral circuits are used together with 
the computer, you must USUALLY have the ground connections (Gnd) all tied 
together.  Also, if you are using a high-efficiency switching power 
supply to power your external circuits, be aware that the supply might 
require a MINIMUM current draw to prevent damage to the power supply.  
For example, I have a Happ Controls, Inc. 80-0016-00 12 Amp Switching 
Power Supply and it has a warning label which reads "Supply outputs must 
be connected before applying line voltage.  Failure to do so may result 
in damage to internal components and will void warranty."  If it is a 
multi-voltage supply, then each output (+5 V, -5 V, +12 V) must have some 
type of load circuit attached before applying power. 
 
Logic Probe - an optional but handy device that can be used to "look" 
into a digital circuit and determine if a signal is either high ("1") or 
low ("0"). Most models provide multicolor LEDs and a tone generator to 
provide visual and auditory feedback.  Approximate cost is within $20. 
 
Digital Multimeter - this is probably one of the most important pieces of 
test equipment you can own.  You only need the basic functions: DC 
voltage and resistance.  The resistance mode is useful for testing 
continuity (determining whether a connection is broken); a resistance of 
zero indicates a good connection, an infinite reading indicates an open 
in the circuit.  Approximate cost is within $30. 
 
Hand Tools - electronics work is done with relatively small components, 
therefore use the correct size tools.  Please don't use the same tools 
you use to work on the car or the kitchen sink; they're too big and 
probably not very clean.  Your tools should include: a pair of needlenose 
pliers, wire snips, screw drivers (both kinds), and a chip puller. 
 
Soldering Iron - use a low-wattage (between 15 to 40 watts) soldering 
iron, pencil, or station.  DO NOT use a soldering gun; these weapons are 
dangerous to semiconductor devices in terms of heat and the electricity 
flowing through the tip.  Be sure to keep a damp sponge nearby to 
periodically wipe off the tip of your iron. 
 
Wire Wrap Tool - wire wrap is an alternative to soldering and provides 
good solid connections superior to those of a solder joint.  Wire wrap 
connections can also be removed very easily (by unwrapping the 
connection).  In fact, a lot of electronic circuitry is prototyped using 
wire wrap because of the ease of revision.  Wire wrap requires use of a 
special wrapping tool, a supply of 30-gauge wire, and IC sockets or 
mounting posts which are specifically designed for wire wrap. 
 
------------------
How To Get Started 
------------------
 
Learn about the internals of your machine.  Get familiar with the memory 
map of the Apple II.  The $C0 page ($C000 through $CFFF) is reserved for 
memory mapped I/O and softswitches. 
 
Learn about and understand the binary, decimal, hexadecimal numbering 
systems. 
 
If you are a complete novice, you might begin by purchasing a low-cost 
kit or attempting a very simple project.  The kits from Vernier Software 
are ideal but feel free to use any similar materials.  Depending on 
your construction skills (e.g., soldering, wire wrap) you may need to 
learn or practice until you feel comfortable.  By all means, take your 
time.  You're supposed to have fun! 
 
You might also want to build a game port breakout box.  This is a very 
useful, low-tech device which permits easy access to each signal 
available on the 9-pin and 16-pin game port connectors.  Typically, the 
lid of a plastic box is replaced with a piece of perfboard that has been 
cut to match.  Two of each type game port connector (DB-9 female and 
16-pin DIP) and a connector (I used "RCA" phono jacks) for each 
game port signal is mounted on the perfboard.  A faceplate can be 
utilized to help label each of the game port signal connectors. 
 
-------
Pinouts 
-------
 
16-pin Dual Inline Package (DIP) socket for II+, IIe 
          +-v------+ 
+5 V      | 1   16 |     Not used 
PB0       | 2   15 |     AN0 
PB1       | 3   14 |     AN1 
PB2       | 4   13 |     AN2 
Strobe    | 5   12 |     AN3 
GC0       | 6   11 |     GC3 
GC2       | 7   10 |     GC1 
Gnd       | 8    9 |     Not used 
          +--------+ 
 
16-pin Dual Inline Package (DIP) socket for IIgs 
            +-v------+ 
+5 V        | 1   16 |     Not used 
PB0         | 2   15 |     AN0 
PB1         | 3   14 |     AN1 
PB2         | 4   13 |     AN2 
+5 V pullup | 5   12 |     AN3 
GC0         | 6   11 |     GC3 
GC2         | 7   10 |     GC1 
Gnd         | 8    9 |     PB3 
            +--------+ 
 
DB-9 Connector 
+---------------------+ 
 \ 5   4   3   2   1 / 
  \  9   8   7   6  / 
   +---------------+ 
 
(View: Looking at female connector on the back of the Apple 
IIc,IIc+,IIe,IIgs) 
 
1=PB1          2=+5 V         3=Gnd 
4=GC2          5=GC0          6=PB2 
7=PB0          8=GC1          9=GC3 
 
+5 V	- Total current drain on this pin must be less than 100 mA 
AN0	- Annunciator 0 output.  The output is capable of sourcing 0.4 mA 
at 5 V in its logic 1 state, or it can sink 8 mA in its logic 0 state. 
AN1	- Annunciator 1 output. 
AN2	- Annunciator 2 output. 
AN3	- Annunciator 3 output. 
GC0	- Game Controller 0 input.  An analog input designed to accept a 
variable resistance in the range of 0 to 150 K (ohms).  Each GC input is 
part of an analog-to-digital (A-to-D or A/D) conversion circuit 
that allows an analog resistance value to be converted into a digital 
quantity.  The resistance forms part of a simple "RC" 
(resistor-capacitor) timing circuit that sets the time constant for the 
558 integrated circuit (a quad version of the 555 Timer). 
GC1	- Game Controller 1 input.  Same as GC0. 
GC2	- Game Controller 2 input.  Same as GC0. 
GC3	- Game Controller 3 input.  Same as GC0. 
PB0	- Push Button 0 input. 
PB1	- Push Button 1 input. 
PB2	- Push Button 2 input. 
Strobe	- Normally kept at a high logic level (+5 V), this signal goes 
low (near 0 V) for half of a clock cycle any time an address in the range 
$C040 through $C04F is accessed.  Can be used to send a momentary pulse 
(a "strobe") to an external circuit.  Such a pulse may be required to 
change the state of an on/off device or to latch data into the circuit so 
that it will not change until after it has been read or sent. 
 
----------------
Apple Tech Notes 
----------------
 
Apple IIe Tech Note #6: The Apple II Paddle Circuits 
Apple IIe Tech Note #9: Switch Input Changes 
 
-----
Books 
-----
 
"Apple Connection, The", James W. Coffron, Sybex, ISBN: 0-89588-085-7 
"Apple House, The", John Blankenship, Prentice-Hall, Inc., ISBN: 
0-13-038711-8 
"Apple II Assembly Language", Marvin L. De Jong, Howard W. Sams & Co., 
ISBN: 0-672-21894-1 
"Apple II Applications", Marvin L. De Jong, Howard W. Sams & Co., ISBN: 
0-672-22035-0 
"Apple II - 6502", Richard Haskell, Prentice-Hall, Inc., ISBN: 
0-13-039230-8 
"Apple Interfacing", Jonathan A. Titus, David G. Larsen, Christopher A. 
Titus, Howard W. Sams & Co., ISBN: 0-672-21862-3 
"Apple Programmer's Handbook", (Chapter 8), Paul Irwin, Howard W. Sams & 
Co., ISBN: 0-672-22175-6 
"Build Your Own Universal Computer Interface", Bruce Chubb, TAB  Books, 
ISBN: 0-8306-3122-4 
"Chaos in the Laboratory", David L. Vernier, etal, Vernier Software, 
ISBN: 0-918731-46-1 
The "Ciarcia's Circuit Cellar" series, Steve Ciarcia, Byte 
Books/McGraw-Hill, these are reprints from his Byte Magazine column 
"Custom Apple & Other Mysteries, The", IJG, Inc., Winfried Hofacker, 
Ekkehard Floegel 
"Hardware Interfacing with the Apple II Plus", John E. Uffenbeck, 
Prentice-Hall, Inc., ISBN: 0-13-383844-7 
"How to Build a Better Mousetrap and 13 Other Science Projects Using the 
Apple II", David L. Vernier, 
Vernier Software, ISBN: 0-918731-16-X 
"Interface Projects for the Apple II", Richard C. Hallgren, 
Prentice-Hall, Inc., ISBN: 0-13-469387-6 
"Interfacing & Digital Experiments with your Apple", Charles J. 
Engelsher, Tab Books, Inc., ISBN: 0-8306-1717-5 
"Programming & Interfacing the 6502, With Experiments", Marvin L. De 
Jong, Howard W. Sams & Co., ISBN: 0-672-21651-5 
 
---------
Magazines 
---------
 
Byte (look for the Circuit Cellar column by Steve Ciarcia) 
Computer Applications Journal, The (Circuit Cellar Ink -- Steve Ciarcia) 
ComputerCraft (became MicroComputer Journal with Jan/Feb 1994 issue) 
Electronics Now 
InCider (look for the early issues before the merger with A+) 
MicroComputer Journal (formerly ComputerCraft) 
Modern Electronics 
Popular Electronics 
Radio Electronics 
Science Probe (look for the Computer Scientist column) 
 
---------
Resources 
---------
 
Byte Works 
8000 Wagon Mound Drive N.W. 
Albuquerque, NM 87120 
(505) 898-8183 
America Online: MikeW50@aol.com 
GEnie: ByteWorks@genie.com 
GEnie: Category 45 of the A2 (m645) Bulletin Board and Category 36 of 
A2Pro (m530) Bulletin Board 
 
Vernier Software 
8565 S.W. Beaverton-Hillsdale Hwy. 
Portland, OR 97225-2429 USA 
(503) 297-5317 
Internet Mail: dvernier@vernier.com 
They sell books, hardware, software, and cables for the Apple II, Mac, 
and PC 
 
[Vernier Software has been producing laboratory interfacing software 
since 1982. They specialize in assisting schools teach scientific 
principles by using personal computer technology.  So, if you are 
affiliated with a school or just an interested hobbyist, they certainly 
offer some interesting products (books, kits, sensors, probes, 
interfaces, cables, software).  They currently support the following 
platforms: Apple II (game port, peripheral slot card), IBM PC (game port, 
peripheral slot card, serial interface), and Macintosh (serial 
interface).  Call, write, or email for a current catalog.] 
 
Erick Wagner 
wagnere@netcom.com 
e.wagner10@genie.geis.com (GEnie) 
wagnere@aol.com (America Online)
[end of document]