joystick port interface projects

25
Joystick port interface projects Written by Tomi Engdahl with Shih Tzus Check new revised version at http://www.hut.fi/Misc/Electronics/docs/joystick/ * Digital Joysticks * Paddle controllers * Analogue Joysticks * Comparision of analogue and digital joysticks features * How PC joystick port hardware works * PC analogue joystick interface * Typical controller connectors used in home computers * Typical "Atari style" joystick circuit diagram * Light gun connections * PC Analogue Joystick to Amiga * Adding four joystick to Commodore Amiga * Special PC joystick circuits * PC special joysticks * Electronics projects for joystick port * Programing support of PC analogue joystick port * Useful tool programs * Information sources Introduction to computer game controlling devices There have been many different types of game controllers used in the history of computer games. The most popular controller hase been joystick, which is simple a box with button and stick to control the motion in the game. But there have been many types of joysticks and I try to clear out some facts in this introduction part. Digital Joysticks The most common joystick type in home computers have been Atari-style digital joysticks. Those joysticks are calle after Atari, because this joystick type was first introduced in Atari 2600 videogame and then adopted to the home computers introduced on ever since (VIC 20, Commodore 64, Amiga, MSX-computers and even Sinclair Spectrum joystick adapters used this joystick type). The joystick itself consisted of five whiched which are arranged to that four of them told about the joystick direction (UP, DOWN, LEFT, RIGHT) and one was for fire button. The joystick connector was 9 pin D-shell connector. Normally all of those whiches are open, but when joystick is turned from the center position, one or two position whiched are closed (according to what direction the stick is turned). The fire button worked so that it closes when button is pressed. All of the swiches are connected between ground and corresponding signal pin of the joystick connector. The nicest thing is that those joysticks were standard and there were joysticks available from many manufactureers. Unfortunatelu most of those

Upload: andreisc

Post on 20-Apr-2015

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Joystick Port Interface Projects

Joystick port interface projects Written by Tomi Engdahl with Shih Tzus

Check new revised version at http://www.hut.fi/Misc/Electronics/docs/joystick/ * Digital Joysticks * Paddle controllers * Analogue Joysticks * Comparision of analogue and digital joysticks features * How PC joystick port hardware works * PC analogue joystick interface * Typical controller connectors used in home computers * Typical "Atari style" joystick circuit diagram * Light gun connections * PC Analogue Joystick to Amiga * Adding four joystick to Commodore Amiga * Special PC joystick circuits * PC special joysticks * Electronics projects for joystick port * Programing support of PC analogue joystick port * Useful tool programs * Information sources Introduction to computer game controlling devices There have been many different types of game controllers used in the history of computer games. The most popular controller hase been joystick, which is simple a box with button and stick to control the motion in the game. But there have been many types of joysticks and I try to clear out some facts in this introduction part. Digital Joysticks The most common joystick type in home computers have been Atari-style digital joysticks. Those joysticks are calle after Atari, because this joystick type was first introduced in Atari 2600 videogame and then adopted to the home computers introduced on ever since (VIC 20, Commodore 64, Amiga, MSX-computers and even Sinclair Spectrum joystick adapters used this joystick type). The joystick itself consisted of five whiched which are arranged to that four of them told about the joystick direction (UP, DOWN, LEFT, RIGHT) and one was for fire button. The joystick connector was 9 pin D-shell connector. Normally all of those whiches are open, but when joystick is turned from the center position, one or two position whiched are closed (according to what direction the stick is turned). The fire button worked so that it closes when button is pressed. All of the swiches are connected between ground and corresponding signal pin of the joystick connector. The nicest thing is that those joysticks were standard and there were joysticks available from many manufactureers. Unfortunatelu most of those

Page 2: Joystick Port Interface Projects

joysticks broke down quite fast (especially very popula types manufactured by Quickshot) because switches and mechanics were made cheaply. Paddle controllers Paddle controller is a simple controller which consists of one knob which is used to control the game. Paddle controllers were used in videogames since the first TV-games to control the racket on the screen. Paddle controllers use analogue principle for control, and they simply consist of one potentiometer and button in one controller. The analogue information from potentiometer has to be converted to digital for in order the computer to use that information. Nowadays it would be done with Analogue to Digital converters, but ten to fifteen years ago those things were hard to get, hard to use and expensive. So home computer manufacturers needed a simpler and less expensive alternative. The answer was to convert the potentiometer position to pulse width information which can be easily conveted to numbers using counter chip or simple software loop. This was cheap, but not very accurate method, especially when software loop was used for measurement. Analogue Joysticks Analogue joysticks were like a combination of ideas of both joystick and paddle. The idea was that potentiometers were used to measure the movement of tick (instead of swiches like in digital joystick). Digital joystick made is possible to have more accurate control, which was needed in flight simulator programs. Analogue joysticks have been used in Apple, Amiga and IBM PC, which only had analogue joystick inputs. Analogue joysticks are not so standardized as digital ones. Each manufacurer had it's own specifications of the stick and their own connector model. PC analogue joystick interface Nowadays the most common analogue joystick type is PC analogue joystick. This joystick model was presented by IBM together with their first IBM PC computer. The joystick is just a basic analogue joystick with two buttons. The original joystick interface had circuit for connecting two joysticks, but had only one joystick connector. A special Y-cable was needed if there was need for two joysticks at the same time. Later time some manufacturers put two connectors to their interface card and some card manufacturers implemented only one joystick input. Fortunately most of the card nowadays have option for two joysticks like the original IBM joystick card. The joystick interface card was designed to be as simple and cheap as possible. The card consisted only of bus interface electronics and four monostable multivibrators (all in on 558 chip). Those monostable multivibrators were simple timer circuits which put out a pulse with width directly proportional to the joystick resistance value. The pulse width was then measured using software loop. This has caused anormous amounts of

Page 3: Joystick Port Interface Projects

problems to game programmers when computers have become faster and faster all the time. On faster machines, the joystick routine in the software does not read the joystick signal properly resulting in a timing problems. Some dedicated joystick cards are designed to vary the joystick signal so the software can properly detect the joystick and process the data. The joystick consists of two potentiometers with variable resistance value between 0 Ohm and 100 kohm (in some joysticks up to 150 kohm). The potentiometer resistances have the minimum values when the joystick is at the top left position. One end of the potentiometer is connected to +5V pin and the center pin is connected top the analogue input of the joystick. The other end of the potentiometer is left not connected to anywhere. There are two commonly used ways how PC analogue joystick stick mechanism is constructed. Some joystick convert the stick position to linear motion, whcih then changes the position of the slider in about 100 kohm linear potentiometer. More popular construction is to use normal axial potentiometers and the joystick movement directly turns those potentiometers. Some joystick used special 100 kohm potentiometer which can only turn that 60..90 degrees which joytick can turn. The more common construction is to use the standard 470 kohm (lin) 270 degree potentiomer and use about one fourth of the scale from the beginning (in this way getting 0..120 kohm value range). Usually those potentiometers are normal carbon slider potentimeters which do not last long in intense gaming. Comparision of analogue and digital joysticks features Atari digital stick PC analogue stick Technology 5 switches 2 potentiometers and 2 switches Connector in stick 9 pin D female 15 pin D male power feed to stick optional +5V +5V needed for for autofire operation Stick directions 8 unlimited Auto centering Yes Yes or No (usually adjustable) Buttons 1 (optionally 2 2 or 3) Sticks per connector 1 1 or 2 (need Y-cable) Connectors typically 2 1 Calibration needed No Yes Stick durability Bad to good Bad to average Limitations only 8 directions No stick moved/centered on/off control feeling/feedback to user Other uses for port Mouse,paddle, Steering wheel, lightpen Flightstic with pedals Programming issues Position reding method One I/O command Special reading routine Position reading time < 1 us 1..2 ms Button reading methid One I/O command One I/O command

Page 4: Joystick Port Interface Projects

Button reading time < 1 us < 1 us Suitability for games Flight simulators Bad Very good Car simulators Average Good Pick and jump Good Average Shoot then up Good Good to bad depens on game Nowadays there are so called PC digital joysticks. Those sticks have implemented some other way thatn through PC joystick card interface to avoid some of the common PC joystick problems and providing faster access for joystick for game programs. The way how those digital PC joysticks communicate with PC is not standardized and possible methods are keyboard connector, serial port or proprietary serial protocol through old joystick interface. Joystick connector pinouts PC joystick interface (analog) .-----------------------. \ 8 7 6 5 4 3 2 1 / \ 9 10 11 12 13 14 15 / ~~~~~~~~~~~~~~~~~~~ 1 XY1 (+5v) 2 Switch 1 3 X1 4 Ground (for switch 1) 5 Ground (for switch 2) 6 Y1 7 Switch 2 8 N.C. 9 XY2 (+5v) 10 Switch 3 11 X2 12 Ground (for switch 3&4) 13 Y2 14 Switch 4 15 N.C. Some I/O cards have implemented only the first joystick functions: X1, Y1, Switch 1 and Switch 2. Some joystick adapter have +5V output also in pin 8. Many soundcards have joytick interfaces with midi port function enbedded to the same connector. Those midi port impelemtations use pins 12 (midi data output from computer) and 15 (midi data input to computer). The midi cable includes the necessary electronics for signal conversion and isolation. That's a nonstandard way of using the pin and it may cause problems in some cases (some functions of the joyticks are not working or sound card does not even work correctly when certain joyticks are used !). Here is the

Page 5: Joystick Port Interface Projects

joystick port pinout used in PC soundcards (Soundblaster, Gravis Ultrasound and many other): pin purpose 1 potentiometer common (Joy A) 2 button 1 (Joy A) 3 X coordinate potentiometer (Joy A) 4 button common (Joy A) 5 button common (Joy B) 6 Y coordinate potentiometer (Joy A) 7 button 2 (Joy A) 8 unused 9 potentiometer common (Joy B) 10 button 1 (Joy B) 11 X coordinate potentiometer (Joy B) 12 MIDI TXD (transmit) (computer -> midi) 13 Y coordinate potentiometer (Joy B) 14 button 2 (Joy B) 15 MIDI RXD (midi -> computer) Typical PC joytick circuit diagram and inside picture [PC joystick schematic] [Picture of pc joystick electronics] Typical controller connectors used in home computers Pin Joystick Analog joystick Paddle 1 Forward Button 3* - 2 Back - - 3 Left Button 1 Left Button 4 Right Button 2 Right Buttom 5 - Pot X Right POT 6 Button 1 - - 7 +5V* +5V +5V 8 GND GND GND 9 Button 2* Pot Y Left POT * those pins are optional Potentiometers used in paddles are usually few hundred kilo-ohm linear potentiometers (max. 470 kOhm). Potentiometers are connected between +5V and input pin. Typical "Atari style" joystick circuit diagram [Image] The joystick industry had de-facto wiring for wires used in joystick cables. Here is the de-facto wiring used in Commodore 64 (many other

Page 6: Joystick Port Interface Projects

manufacturers used same coloring): Pin Color Function 1 White Up 2 Blue Down 3 Green Left 4 Brown Right 5 no contact 6 Orange Fire button 7 Red +5V, max. 50 mA 8 Black Ground 9 no contact There are many ways to contruct a digital joystick. Some of the cheapest joystick just have mechanics of cheap buttons, where the better ones usually utilize microswitches. On the picture below you can see WICO Boss joystick construction. It uses five switches which are built from two springs which touch each other when stick is moved or button is pressed. [Picture of WICO joystick electronics] Special 2 button Atari 7800 sticks The original ATARI 2660 video game set some kind of se-facto standard for 9 pin digital joystick connector. Theat system supported onlu one buttons and lately different manufacturers added more buttons using different methods. Also Atari made some changes to orignal design in it's 7800 video game. From: galt%[email protected] (Greg Alt) _________________ \ o5 o4 o3 o2 o1/ \ o9 o8 o7 o6 / \___________/ pin # 2600 control 7800 control 1 WHT- Up WHT- Up 2 BLU- Down BLU- Down 3 GRN- Left GRN- Left 4 BRN- Right BRN- Right 5 unused RED- Button (R)ight (-) 6 ORG- Button ORG- Both buttons (+) 7 unused unused 8 BLK- Ground(-) BLK- Ground(-) 9 unused YLW- Button (L)eft (-) 2600 control (button) pin 6 ORG(+) --------------()------------BLK(-) pin 8 Button

Page 7: Joystick Port Interface Projects

7800 control (buttons) /----------YLW(-) pin 9 Button L / /---------()---| YLW splits / \----/\/\/-----\ pin 6 ORG(+) -------| ORG splits 520 ohm |---BLK(-) pin 8 \ /----/\/\/-----/ \---------()---| 520 ohm Button R \ RED splits \----------RED(-) pin 5 Sega genesis joysticks Sega genesist used a little but different approach in joystick connection than Atari. Because it seem that there are lots of Sega joysticks also loating around and people want to convert them to other videogames or computer, I include here one schemtic whichj should help to figure out how the conversion can be done. The Sega joytick pinout seems to be the "standard" 2 button joystick configuration where pins 6 and 9 are used for buttons which ground the pin when pressed. The only strange thing is that the joystick seems to want +5V also at pin 5. Pin Joystick 1 Forward 2 Back 3 Left 4 Right 5 +5V 6 Button 1 7 +5V 8 GND 9 Button 2 Sega hasadded more buttons to it's newer joystick models (there are 3 and 6 bitton models). Those joysticks use basically the same interface, but more buttons are added by extra electronics which multiplexes the new button signals with the existing joystick signals using control bit in connector pin 7. For more information on this, check an article written by Charles Rosenberg at http://www.isr.com/~chuck/segasix.txt. Super Nintendo Entertainment System Joystiks Super Nintendo Entertainment System (SNES) joysticks work differnetly compared to other joystics. SNES does not use separate pins for every joytick function but uses special serial protocol between the joystick and the game system. There is a description of the protocol available at http://www.paranoia.com/~filipg/HTML/LINK/F_SNES.html". Here is the pinout information taken from that document (notice that the pin numbering might not be according the Nintendo official numbering scheme):

Page 8: Joystick Port Interface Projects

----------------------------- --------------------- | | \ | (1) (2) (3) (4) | (5) (6) (7) | | | / ----------------------------- --------------------- Pin Description Color of wire in cable === =========== ====================== 1 +5v White 2 Data clock Yellow 3 Data latch Orange 4 Serial data Red 5 ? no wire 6 ? no wire 7 Ground Brown Light gun connections Light guns are floating around from old video games. The best know light gun might be the Sega light gun. The light gun has a special connector, which is not suitable for any other than Sega game systems. Fortunately the electronics in the light guns are quite generic, so conversion is usually possible just by changing the connector. One method for converting Sega light gun connectors was presented in article "First look: Inside the XE Game System: Hardware surprises revealed!" in Antic Magazine, August 1988, Vol. 7, num. 4. Using the same ideas and correct pinout configuration it is possible to convert Sega light gun to Commodore Amiga computer. To modify the Sega gun for the Atari, you'll have to cut off the incompatible connector. The wires must be stripped back and soldered into an Atari joystick connector as follows: SEGA GUN ATARI JOYSTICK PORT Blue wire Pin 1 stick FWD Gray wire Pin 6 trigger Green wire Pin 7 +5 volts Black wire Pin 8 Ground Once it's all hooked up, you'll notice that gun fires when you release the trigger, which is annoying. The Sega trigger wiring is the opposite of what the Atari light gun uses. To rewire the trigger switch, remove the five screws (one is under the Sega logo on the side). Find the trigger micro-switch with three connections. Wire to the normally closed contacts instead of normally open. --------------------------------------------------------------------------- Joytick circuits PC Analogue Joystick to Amiga The PC Joystick has a 15 pin normal-density male D-type connector which

Page 9: Joystick Port Interface Projects

will be wired to female 9-pin D-type connector, which will go into the Amiga port. To make this conversion work the software has to support analogue joystick, examples of games that do (and to good effect) are Formula 1 Grand Prix and Gunship 2000 (Microprose). 9-pin Male 15-pin female 3 2 4 7 5 6 7 1 8 4 9 3 Adding four joystick to Commodore Amiga Normally Commodore Amiga provides interface for two joysticks, but for some multi-user games more joystick are needed. For this purpose, it has been designed a multi-joystick extender circuit, which have bocome kind of de-facto standard for adding more joysticks to Amiga computers. The circuit is very simple adapter which is connected to the parallel printer port of Commodore Amiga. The circuit consists only of three connectors (on BD25 male and two BD9 male) and some wiring. That's why it is very easy to build. Multi-joystick extender circuit wiring Port JOY3 JOY4 ---------------------------------- 2 1 UP 3 2 DOWN 4 3 LEFT 5 4 RIGHT 6 1 UP 7 2 DOWN 8 3 LEFT 9 4 RIGHT 11 6 FIRE 13 6 FIRE 18 8 GROUND 19 8 GROUND Circuit Diagram Note: none of the wires join when crossing each other. They all ~~~~~ go from one pin straight to another pin. JOY3 6 1o------ o5 9 JOY4 --------o ! o ! o-----!-- ------------o ! o ! ! ! o--------

Page 10: Joystick Port Interface Projects

! o-----!-!-- --!-----------o ! ! -----o ! ! ! ! ! o ! ! ! o-----!-!-!-- --!-!-----------o ! ! ! o ! ! ! ! ! ! ! o---- ! ! ! 9 o ! ! ! ! --!-!-!-----------o 6 ! ! ! ! 5 ! ! ! ! ! ! ! ! 1 ! ! ! ! ! ! ! ! ! ! ! ! ----------------! ! ! ! ! ! ! ! ! ! ! ! ! -------- ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! o o o o o o o o o o o o o ! ! ! ! 1 DB-25 (Parallel) 13 ! ! ! ! o o o o o o o o o o o o ! ! ! ! 14 ! ! 25 ! ! ! !---------------------!-! ! ! !------------------------!---------------------! ! !------------------------------! Software Support The following games support this multi-joystick extender circuit: * Kick Off II (Anco) * Gauntlet II (US Gold) * Leatherneck (Microdeal) * International Soccer (Microdeal) * Projectyle (Electronic Arts) * TV Sports Basketball (Cinemaware) * Dynablaster Special PC joystick circuits Adding second joystick to PC joystick interface PC joystick interface was designed to support two joysticks, but unfortunately it has only one connector. The second joystick can be added when you get a special Y-cable, which has connectors for two joysticks. Those cables can be bought ready-made from nearly any good computer store, but can be easily made if you already have the parts. If you decide to build Y-cable yourself, make it well and avoid possible short circuits (+5V line can give quite remarkable amount of current in short circuit and burn your wiring). Some other manufacturers have made joystick interfaces which have two connectors. Some manufacturers have saved few cents in their multi-io cards and impelemented only the electronics of the joystick one. Y-cable |----------15-pin female f1 ------------------ | | 15-pin male m1 |-----------| ------------------ |----------15-pin female f2

Page 11: Joystick Port Interface Projects

m1 f1 f2 ----------------------------------------------------------- 1 : +5vDC 1 2 : Stick 1 button 1 2 3 : Stick 1 X-position 3 4 : Gnd 4 5 : Gnd 5 6 : Stick 1 Y-position 6 7 : Stick 1 button 2 7 8 : +5vDC 8 9 : +5vDC 9 1 10 : Stick 2 button 1 10 2 11 : Stick 2 X-position 11 3 12 : Gnd 12 4 and 5 13 : Stick 2 Y-position 13 6 14 : Stick 2 button 2 14 7 15 : +5vDC 15 9 If you are interrested what the complete wiring of two joystick connected to one joystick port looks like, check the joystick wiring diagram from CrystaLake Multimedia web pages. Y-cable problems with soundcards Jystick connector typical PC sound card is not fully compatible with the original PC joystick interface, because soundcard manufacturers have replaced pins 12 and 15 with the MIDI interface pins. If the joystick or joystick adpater you connect to soundcard useds those pins, then it will not work properly with soundcard joystick interface. I think that it was quite stupid choice form Creative Labs to put the MIDI signals to the Soundblaster's joytick interface, and then all other manufacturers have copied this stupid idea. It seems that the manufacturer's customer support is typically unaware of this incompatibility and great deal of problems this causes to many users. Typical problem are that some joysticks doe not work properly and even in worst case the soundcard doughterboard stops to work when some otherwise well working joystick is connected to the joystick port. It is possible to build an adapter wich enable using two joysticks or joystick with pedals on soundcard interface. D15S (male)----------D15S(female) to soundcard---------to joystick 1------------------------1 2------------------------2 3------------------------3 4------------------------4 5--------------------+---5 6--------------------|---6 7--------------------|---7 8--------------------|---8

Page 12: Joystick Port Interface Projects

9 ----+--------------|---9 10----|--------------|--10 11----|--------------|--11 12 | +--12 13----|-----------------13 14----|-----------------14 15 +-----------------15 When you have built this interface, you can then use any standard joystick or joystick Y-cable with it. If you heap up your soldering iron to make your own adapter, then why not make a complete workign joystick Y-cable using the following modified wiring scheme which works with the soundcards also. Soundcard stick1 stick2 ----------------------------------------------------------- 1 : +5vDC 1 1 2 : Stick 1 button 1 2 3 : Stick 1 X-position 3 4 : Gnd 4 5 5 : Gnd 5 5 6 : Stick 1 Y-position 6 7 : Stick 1 button 2 7 8 : +5vDC 8 9 : +5vDC 9 9 10 : Stick 2 button 1 10 2 11 : Stick 2 X-position 11 3 12 : MIDI 13 : Stick 2 Y-position 13 5 14 : Stick 2 button 2 14 6 15 : MIDI For those who are looking for ready-made cable, go to your computer store and ask for "Joystick Y cable". Many manufacturers make this type of cable, the best known cable might be Gravis "Y" Cable. Soundcard joystick port problem solver Typical PC soundcards (for exampel Sound Blaster family) has added MIDI interface to the joystick connector by using pin 12 for MIDI output and pin 15 for MIDI input. This causes sometimes problems with some joysticks and adapters which work pefectly on standard joystick port. The following conversion circuit enables standard joystick Y-cables to be used with soundcards without problems. This circuit provides GND to pin 12 and +5V to pin 15 as in original PC joystick interface. This enables using standard Y cables and joyticks with extra functions (like pedals) to be used with soundcards without problems like some of the joystick functions not working properly or the MIDI doughterboard does not work when joystick is installed. D15S (male)----------D15S(female) to PAS-----------------to joystick

Page 13: Joystick Port Interface Projects

1------------------------1 2------------------------2 3------------------------3 4------------------------4 5--------------------+---5 6--------------------|---6 7--------------------|---7 8--------------------|---8 9 ----+--------------|---9 10----|--------------|--10 11----|--------------|--11 12 | +--12 13----|-----------------13 14----|-----------------14 15 +-----------------15 NOTE: Do not try to connect your soundcard MIDI adapter after this circuit ! Connecting MIDI adapter to this circuit can damage it. Parallel Gameport Adapter Genovation designed a PC joystick interface module which can be plugged to PC parallel port. The near-total lack of drivers made it virtually useless. I have no more information about that product. A Digital JoyStick for the IBM-PC Parallel Printer Port Ian Harries has designed a small circuit which can be used for connecting normal "atari style" digital joystick to PC parallel port. The joystick position can be read easily from your own software (there is pascal source code in the project page) but this kind of joystick interface does not have any support in commercial programs. The whole project information is available at http://www.doc.ic.ac.uk/~ih/doc/joystick/. PC special joysticks Gravis Gamepad for PC Gravis PC keypad is a simple game controller desgined for replacing PC analogue joystick in some games. Gamepad has better "touch" in some games and sometimes there is need for more than two buttons. _____ || | \____||________ | __ GRAVIS \ | / \ GamePad B | | \__/ A C| |______________ D | \_____| Resistance values for different gamepad positions:

Page 14: Joystick Port Interface Projects

+----------------------------------------------+ ¦ x = 0 kohm ¦ x = 50 kohm ¦ x = 100 kohm ¦ ¦ y = 0 kohm ¦ y = 0 kohm ¦ y = 0 kohm ¦ +--------------+---------------+---------------¦ ¦ x = 0 kohm ¦ x = 50 kohm ¦ x = 100 ohm ¦ ¦ y = 50 kohm ¦ y = 50 kohm ¦ y = 50 ohm ¦ +--------------+---------------+---------------¦ ¦ x = 0 kohm ¦ x = 50 kohm ¦ x = 100 kohm ¦ ¦ y = 100 kohm ¦ y = 100 kohm ¦ y = 100 kohm ¦ +----------------------------------------------+ The GamePad buttons are accessed the same way that the normal joystick buttons are accessed: +--------------------------------------------------------+ ¦ GamePad Button A = Joystick A, Button 1 ¦ ¦ GamePad Button B = Joystick A, Button 2 ¦ ¦ GamePad Button C (autofire A) = Joystick B, Button 2 ¦ ¦ GamePad Button D (autofire B) = Joystick B, Button 1 ¦ +--------------------------------------------------------+ Gravis Analog Pro Gravis Analog Pro is a PC analogue joystick designed specially for flight simulators and sgn games. The joystick has four buttons and throttle control. The Analog Pro joystick position is read the same as the regular Joystick A. The throttle value is read the same as for the regular Joystick B X-axis value. +---------------------------------------------+ ¦ Analog Pro Button A = Joystick A, Button 1 ¦ ¦ Analog Pro Button B = Joystick A, Button 2 ¦ ¦ Analog Pro Button C = Joystick B, Button 1 ¦ ¦ Analog Pro Button D = Joystick B, Button 2 ¦ +---------------------------------------------+ Radio Shack Deluxe Joystick (260-0384) In Radio Shack Deluxe Joystick the control stick controls the X-Axis (Up/Down) and Y-Axis (Left/Right) of "Joystick 1". Deluxe Joystick's on-board throttle and rudder controls control the X- and Y-Axes of "Joystick 2". Some software lets you use a second joystick to control your speed. The Deluxe Joystick throttle control works as a second joystick, if needed. The rudder control performs the function of a second joystick's Y-axis. Some tips in using: Before using your software, slide both throttle controls to the minimum position (closest to you) and make sure the rudder control is in the center position.

Page 15: Joystick Port Interface Projects

Virtualpilot Pro and F-16 comp.stick. Information to this chapter is from article posted to sfnet.harrastus.elektroniikka newsgroup by Vesa Saastamoinen ([email protected]). Normal joystick movement is same as in normal joystick. Throttle is joystick 2 Y-direction. Pedals are connected in series and each is 0..50 kohm potentiometer circuit. Right pedal up is 0 kohm and down is 50 kohm. Left pedal up is 50 kohm and down is 0 kohm. 50 kohm 50 kohm INPUT o------|\/\/\/\|---+---|\/\/\/\|------o +5 V /_______|_______/ | Right up equals 50 kohm, Right down equals 0 kohm, Left up equals 50 kohm, Left down equals 0 kohm, Buttons A B C D Function X Button 1 X Button 2 X Button 3 X Button 4 X X Button 5 X X Button 6 X X X X Hat 1 up x x x Hat 1 down X X X Hat 1 right X X Hat 1 left X X X Hat 2 up X X Hat 2 down X X Hat 2 right X X Hat 2 left What those markings mean: A = connected from ground switch in series with diode to pin 2 B = same as above, but to pin 7 C = same as above, but to pin 10 D = same as above, but to pin 14 Example: A+B ___

Page 16: Joystick Port Interface Projects

GND-----. .----|<|---pin 2 | --|<|---pin 7 Microsoft sidewider 3D pro Microsoft sidewider 3D pro works in two modes: analog and digital interface. In analog emulation it emulates the two resistors in a standard joystick. The other mode is all digital where it sends a serial data stream on one of the joystick button inputs, It feeds a clock on another of the button inputs. It senses the 555 timer discharge pulses to trigger a response, then clocks and sends a fixed length serial packet (64 bits I think). All timing is done by the Sidewinder and appears not to be adjustable. The drivers sit in a tight loop reading in the packet. The clock rate is something like 500kHz. Interrupts are disabled while it reads in the packet but DMA isn't and if your system has some extra overhead doing ISA DMA across the ISA/PCI bridge then it will miss bits from the stream and will not ever get a valid packet. Basically a crap interface design. One solution is changing the crystal for the uP inside the sidewinder to slow it down enough to work on some systems. (something like 30% slower didn't seem to affect the rest of it's operation too much). The position sensors in the Sidewinder are impressively simple, some sort of split photodiode (or maybe it is some sort of photo array) and 3 LEDs to sense 4 axies (sp?) - neat. Microsoft sidewinder 3D pro description is based on article posted to sci.electronics.design newsgroup by Terry Harris ([email protected]). Stering wheels and pedals Some PC car games have started to support steering wheels and pedals. The steering wheels is simply a steering wheel connected to potentiometer which is wired to joystick 1 X-axis (between pins 1 and 3). The shift buttons are standard PC joystick 1 buttons. Gas and break pedals are both connected to PC joytick 1 Y-axis (between pins 6 and 8). The pedals are connected in series just like in flight simulator pedals. 50 kohm 50 kohm INPUT o------|\/\/\/\|---+---|\/\/\/\|------o +5 V /_______|_______/ | The connection is made so that when both pedals are released, the joystick interface sees about 50 kohm resistance. When gas is pressed (and break is kept up) the resistance increases and gets maximum resitance when gas pedal

Page 17: Joystick Port Interface Projects

is fully pressed down. When the break pedals is fully pressed and gas pedal is released, the pedals system gets the minimun resistance. There is nice picture of wheel and pedal wirings at http://www.monmouth.com/~lw4750/electric.htm. For more detailed wiring diagram of steering wheels and pedals, check Build your own wheel & pedals article from Wally's World, How to build rudder pedals (for little money)? article from http://meritbbs.unimaas.nl/Fun/pedals/pedals.htm and Lew's Wheels page. Additional features in some PC joystics Some PC joystick have also some other extra features. The hat-switch is implemented by using joystick B Y-axis for those buttons. The Y-axis is (usually) divided to four parts to implement the functions needed. Gravis has come up with their own special GrIP technology for multi-player gaming and adding extrafunctions to game controllers. The system consist of one GrIP hub which communicates digitally though standard PC joystick port (using proprietary protocol) and a driver program for Windows 95. How PC joystick port hardware works The joystick port is a very simple 8 bit I/0 card which resides in ISA bus I/O address 201h. The CPU can read and write to the joystick port I/O address 201h. Writing to that address starts joystick postition measurement. Joystick interface only uses the signal that somebody is writing to the I/O address to reset the multivibrators in the card. The data value is not stored anywhere, so it is really same what value is written to this address. When you read one byte from I/O addess 201h, you get the status information of the joystick interface. The following table will show how the bits are mapped in the value you get. Game port 201h byte: _______________________________________________________ | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | | but4 | but3 | but2 | but1 | stk4 | stk3 | stk2 | stk1 | |______|______|______|______|______|______|______|______| The four most significant bits tell you the state of the joystick buttons. Four least significant bits tell the state of the multivibrators which are used for measuring the resistance value of the joytick position potentiometers. Resistive analogue inputs (joystick position) Joystick position inputs are simply inputs where a variable 0-100 kohm joystick potentiometer is connected to. The potentiometers are wired between the +5V power pin and one potentiometer input pin. The following picture tries show how the wiring is done:

Page 18: Joystick Port Interface Projects

+5 ________________ | stick1 ________ | | 100K | _/\/\/\_____| stick2 ________ | | 100K | _/\/\/\_____| stick3 ________ | | 100K | _/\/\/\_____| stick4 ________ | | 100K | _/\/\/\_____| The resistance value of the joystick potentiometers are measured using very simple monostable multivibrator circuit, where a small capacitor is loaded through the joystick potentiometer to a certain voltage level. The joystick interface has four this type of monostable multivibrators. Typically joystick interface multivibrators are all in one 558 IC (that IC is like four simplified 555 type timers in one IC). Joystick Pot in >---+ (stick n) | \ R1 / ____________ 2.2K \ | | / | |>----------> data bit to ISA bus | | Monostable |out +-------| Multi- | | | vibrator | C1 --- | |<----------< write to I/O port strobe 22 nF --- |____________|trigger | | --- The multivibrator work on the following way: * 1. Normally on idle state the capacitor C1 is fully charged (5V) and multivibator output gives out logic 1. * 2. Computer writes to I/O address 201h to reset the multivibrators. The multivibrator get a triggger pulse from I/O write signal and it discharged capacitor C1. The multivibrator output goes to logic 0 because the capacitor is discharged (0V). * 2. The capacitor starts to charge form the current which goes through R1 and the joystick potentiometer. * 3. When the capacitor voltage reaches certain oltage threshold level, the multivibrator output goes back to logic 1.

Page 19: Joystick Port Interface Projects

The bigger the potentiometer resistance value is, the loger it takes from the capacitor to reach the threshold voltage. The time how long it take for each multivibator to reach the logic 1 after the triggering is measued using software and that value tells the resistance of the potentiometer (and the stick position as well because the potentiometer is connected to the stick). This simple method for measuring the resistance value is quite cheap, but not very accurate. This simple joystick port hardware implementation (originally designed for 4.7 MHz IBM PC) causes many headaches to game programmers (problems of different computer speeds, joycitck port differences, problems in multitasking operating systems etc.). Big tolerances in joysticks and joystick ports mean that the every game must have an option to cablibrate the joystick (which actually means that the program adapts to accept the values in th range which the joystick reading routine does and then converts the values to it's internal format using the values measured in joystick calibration process). Switch inputs (joytick buttons) The joystick buttons are simple on/off inputs. Joystick button either leaves the pin floating or connect it to the ground. ___ button1 ______o o_______ ___ | button2 ______o o_______| ___ | button3 ______o o_______| ___ | button4 ______o o_______| | GND ________________| The state of the buttons is directly fed to the joystick interface and through it to ISA bus data lines when somebody reads the joystick interface I/O address. The buttons are very easily wired. Every input has 1 kohm pull-up resistor R1 which ensires that the joystick button pins stay in +5V potential (logic 1) when no button is pressed down. +5V | \ / R1 \ 1K / Joystick | button in >--------+-------------------------> data bit to ISA bus (button n) When one button is pressed down, that input is grounded which caused the voltage on that pin goes to 0V which means that the joystick interface then

Page 20: Joystick Port Interface Projects

gets logic 0 form that input. If you just keep reading the joystick port I/O address contantly, you will get a real-time sate of the button pins. Electronics projects for joystick port Build your own joysticks and controllers Building your own normal PC joystick is not economically wise, but if you can't find a joystick you would like to have, then you have te consider doing it yourself. The connections inside PC joystick are quite simple to do, the harder part is the mechanics. Buttons are quite easy to mout to the case you use when you select suitable buttons, but the problematic part is geeting the stick movement to move the slider in the potentimeter. Commercial sticks use different mechanical constructions for getting the stick movement to rotating or linear motion. If you manage to get the stick movement to rotation which you can connect to normal potentiometer, then the problem is tha normal potentiometer have rotation of about 270 degrees and the sticks moves normally much less than 90 degrees. So you will not be able to use the whole scale of the potentimeter. You can solve this problem by using 470 kohm linear potentiometer instead on 150 kohm potentiometer. In this way you get nice 0-100 kohm value range when you use only first 60 degrees of potentiometer. Some commercial stick use this method. If you are more interrested in building wheels and pedals for playing car games, you should checck Wally's World website pages Build your own wheel & pedals. They give you very detailed information how to do the project. Convert Atari-style joystick to PC joystick port Some games are easier to play with digital joystick instead of analogue type. Unfortunately PC has only analogue joystick connector, which makes it impossible to connect normal digital joystick to it. But with a little adapter circuit, it is possible to use Atari style digital joystick with IBM PC joystick interface. The circuit adapts the joystick connectors and converts digital joystick movement signals to analogue signals. The circuit can be used with any PC game to replace the original analogue joystick. The circuit also simulates also Gravis Gamepad operations except the extra buttons. [Image] The joystick adapter can be quite easily built to a small plastic box which can be easily fitted between the PC joystick adapter and the joystick you wish to use. On the picture below you can see my protoype. [Image] I built my prototype to a small piece of veroboard. Take a look at the inside of my prototype to get ideas how to lay out the components in your circuit. On the left side you see the 15 pin male connector and on the

Page 21: Joystick Port Interface Projects

right there is 9 pin male connector. Both connectors are glued to the case using hot glue. [Image] When you have built the interface, you have to set the trimmers to correct positions.The potentiometers must be set so that the circuit shows 50 kohm to joystick interface when the joystick is in the center position. So first align the potentiometers just to the center position. If you want to more accurate alignment, use a simple test program to align those more accurately. The aligning procedure is very simple: just urn tje joystick to left and right positions and calculate the average of those values the test program shows. The align the potentiometer so that the circuit gives the calculated value when joystick is in the center position. Do the same to the forward/back direction. A quite similar building project for digital joystick to PC adapter can be foind from http://proffa.cc.tut.fi/~k150585/projektit.html. That designs ases a slightly different circuit and also includes the picture of the PCB for two digital joysticks. Note that the description text pf this circuit is written in Finnish. Use game console joysticks with PC Console Cable makes special wires and software drivers for connecting different joysticks to PC parallel port. The software driver makes the game console joystick to emulate PC keyboard functions. Use PC joystick port to measure temperature and light levels Pc joystick port can be used very easily for simple measurement of light and temperature values. All you need for light measurements is to connect a LDR resistor between +5V and potentiometer input. For temperature measurements substitute the LDR with suitable NTC-resistor. If you use only one input, put a 0..100 kOhm resistor to other input so that the computer don't think that there is no joystick available (this is for those that use BIOS routines or some other ready-made library). Here is thje pin 1 +5 ________________ | NTC or LDR | pin 3 stick 1x ____/\/\/\_____| | 100 k | pin 6 stick 1y ____/\/\/\_____| Select the variable resistor (NTC or LDR) type so that is will give resistor values are in 0..100 kOhm area in your measurement situations. The larger difference between smallest and largest resistor value, more accurate the system will be. The problem is that the system will never be very accurate, because the joystick interface is not degigned to be very accurate instrument. The value given you get can vary from component

Page 22: Joystick Port Interface Projects

temperature drift, large differences between diffrenet joystick interface cards, computer clock speed differences and some other things. I have tested the system with some LDR resistors and one NTC resisotr taken from a small electronic thermometer. You can't make very fast measurements with this method (limited by joystick port technology), because each measurement takes normally arount 1 to 2 milliseconds. You can test your own circuits using my joystick test program. You can see how X position value of the joystick 1 will change according the value you measure. Remeber that the value changes are not typically lienarly related to the temperature or the light intensity. The rensponse of LDR and NTC resistors is typically some exponential response (you can try to match an exponetial curve to some measured values you get). Connect other circuits to PC joystick port PC joystick connector provides easily usable four TTL level inputs (with pull-up resistors) and four resistive inputs. Using those inputs is very simple as you can see from the joystick circuit or the circuit diagram below: pin 1 +5 ________________ | pin 3 stick1x ________ | | 100K | _/\/\/\_____| pin 6 stick1y ________ | | 100K | _/\/\/\_____| pin 11 stick2x ________ | | 100K | _/\/\/\_____| pin 13 stick2y ________ | | 100K | _/\/\/\_____| ___ pin 2 button1 ______o o_______ ___ | pin 7 button2 ______o o_______| ___ | pin 10 button3 ______o o_______| ___ | pin 14 button4 ______o o_______| | pin 4 GND ________________| PC joystick port can be a very useful interface for simple digital input circuits, because joystick connector has +5V power output, which other standard PC interface connectors don't have. You need to be a little bit careful with this power output, because it can give quite much current in short circuit situation (up to 20A in some cases). This current is enough for burning small wires in your circuit or inside your PC (I have burned

Page 23: Joystick Port Interface Projects

one flatcable coming form multi-IO card to joytick connector !). I have connected succesfully a light sensor, magnetic card reader, bar code reader and infra-red remote control receiver to PC joystick port. Joystick port has been also an useful power source for some other projects connected to other ports. If you have problems in accessing you own circuits connected to joystick port using some ready made joystick routines (for example BIOS routines or routines in operating system), check that your circuit looks like the real joystick in all aspects. If the analogue inputs (or even one of them) in the joystick port are left not connected anywhere, the joytick routine might think that there is no joystick attaced. So be sure that there is always resistance of 0..100 kohm between all analogue inputs of the joytick used and +5V power connector (for more details, check the joytick schematic). Programing support of PC analogue joystick port I the beginning there was not ready made BIOS routines for reading joystick in IBM PC. That's why every programmer had to do their own routines. Since IBM AT, joystick routines have been a standard part of BIOS routines. But long time game manufacturers had to use their own routines, because they couldn't rely that the computer had BIOS support for joystick. Bios functions INT 15 - BIOS - JOYSTICK SUPPORT (XT after 11/8/82,AT,XT286,PS) AH = 84h DX = subfunction 0000h read joystick switches Return: AL bits 7-4 = switch settings 0001h read positions of joysticks Return: AX = X position of joystick A BX = Y position of joystick A CX = X position of joystick B DX = Y position of joystick B Return: CF set on error AH = status 80h invalid command (PC,PCjr) 86h function not supported (other) CF clear if successful Notes: if no game port is installed, subfunction 0000h returns AL=00h (all switches open) and subfunction 0001h returns AX=BX=CX=DX=0000h a 250kOhm joystick typically returns 0000h-01A0h Your own routines To read the joysticks (or your slide pot positions), you must first write a byte to port 201h. It doesn't matter what value you send, as long as you perform an I/O write. This triggers the 558 timer on the game adapter.

Page 24: Joystick Port Interface Projects

Game port 201h byte: _______________________________________________________ | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | | but4 | but3 | but2 | but1 | stk4 | stk3 | stk2 | stk1 | |______|______|______|______|______|______|______|______| The most machine-independent way to sample the game port is to use a timer. Note the time (e.g., read the countdown register in Timer 0, you need pretty fine resolution and this timer performs 65535 counts every 55 ms) just before you trigger the 558. After triggering, sit in a loop reading port 201h and examining bits 0-3. For those bits that have a joystick pot attached, you'll see them sit for a while at 0, then become 1. As each bit flips back to 1, note the time again. When all bit 0-3 have flipped back to 1, you're almost done. Compute elapsed time for each bit, and you end up with a value that is proportional to pot position. Pots are normally 0-150k variable resistors (0-100k sometimes), and according to the IBM techref, the time is given by Time = 24.2e-6s + 0.011e-6s * R/Ohms. This equation does not accurately represent the real situation, where theare are differences in absolute components values. In reality you have to calibrate the joystick for the application you use. Thse most straighforward way to calibrate the stick for the program isto record the values the joystick gives in extreme positions and in the center position. Buttons can be read at any time just by reading port 201h and looking at bits 4-7. No triggering is required. Button bits are normally 1; while a button is depressed, its bit will flip to 0. Useful tool programs I have written an simple joystick tester program which I have found to be useful in many simple electronics tests. The program is a simple DOS test program which shows the information of both joystics easily readable on the screen. The program is useful in testing joysticks and your own project. The program is easy to use. Just download this program and run this under DOS. The program used BIOS routines to read the joystick, so the computer must be at least AT class (286 processor) to be able to run this program. The sourcecode is also freely available for those who are interrested in how to read joytick using Turbo Pascal. You need binary.tpu to compile the program so take also the binary tpu source code. For those who prefer C can check the joystick test progam written in C by Jack Morrison. CH Producs has a free JCENTER.EXE joystick testing and centering program in their Tech Support Web page Information sources

Page 25: Joystick Port Interface Projects

* Amiga Hardware Reference, Commodore-Amiga Incomporated * A Digital JoyStick for the IBM-PC Parallel Printer Port by Ian Harries * Build your own wheel & pedals web pages by Walt Ottenad * PC Games Programming Encyclopedia * Ray Duncan, IBM ROM BIOS * Radio Shack Product Support Faxback Doc. # 14976 * Various Usenet news articles from sci.electronics.* and sfnet.harastus.elektroniikka newsgroups * How to read game port by Bill Frolik * CH Virtualpilot pro and F-16 comp.stick buttons connections by Vesa Saastamoinen * Classic Atari Game Systems FAQ * The 15 Worst Peripherals from Computer Gaming World magazine * Logitech Customer Support Documents * Analogue Joystick to Amiga from Tom-D-Tek's AMIGA Hack Page * Super Nintendo Entertainment System pinouts by Jim Christy --------------------------------------------------------------------------- Tomi Engdahl <[email protected]>