Controladores de joystick Linux de puerto paralelo v1.2 BETA (c) 1998 Vojtech Pavlik (c) 1998 Andree Borrmann Traducción NuLies: David Marín Carreño ---------------------------------------------------------------------------- 0. Advertencia ~~~~~~~~~~~~~~ Toda la información de este fichero se proporciona tal cual, sin garantía de que sea cierta. Por lo que debe utilizarla bajo su propia responsabilidad. Los daños que pudieran ocasionarse incluyen la quemadura de su puerto paralelo y/o de sus mandos de juego o incluso más. Al igual que cuando un rayo le puede matar, ese no es nuestro problema. 1. Introducción ~~~~~~~~~~~~~~~ Los controladores de joystick para puerto paralelo se utilizan para joysticks y gamepads que no se diseñaron en un principio para PCs ni para otros sistemas en los que Linux funciona. Debido a ello, los PCs carecen de puertos adecuados en los que conectar estos dispositivos. El puerto paralelo, debido a su capacidad de cambiar bits individuales a su deseo, y gracias a proporcionar tanto bits de salida como de entrada, es el puerto más adecuado para conectar estos dispositivos a su PC. 2. Dispositivos soportados ~~~~~~~~~~~~~~~~~~~~~~~~~~ Muchos mandos y palancas de mando de consola y de computadores de 8 bits están soportados. Las siguientes subsecciones tratan del uso de cada uno de ellos. 2.1 NES y SNES ~~~~~~~~~~~~~~ Los mandos de Nintendo Entertainmente System y Super Nintendo Entertainment System están muy extendidos y son fáciles de conseguir. Además, son bastante fáciles de conectar a un PC, y no necesitan demasiada velocidad de proceso (108 us para NES y 165 us para la SNES, comparado con los casi 1000 us de los mandos para PC) para comunicarse con ellos. Todos los NES y SNES utilizan el mismo protocolo serie síncrono, regulado desde el computador (por lo que no son sensibles al tiempo). Para permitir conectarse hasta 5 mandos NES y/o SNES simultáneamente al mismo puerto paralelo, las líneas de salida del puerto paralelo se comparten, mientras que una de las cinco líneas de entrada disponibles se asigna a cada mando. Este protocolo se maneja por el controlador joy-console.c, por lo que ese es el que deberá utilizar para mandos NES y SNES. El principal problema de los puertos paralelos de PC es que no tienen una fuente de energía de +5 V en cualquiera de sus patillas. Por lo que, si desea una fuente de energía eficaz para sus mandos, utilice tanto el teclado como el puerto del joystick, y haga un cable para pasar de uno a otro. También puede sacar la energía directamente de la fuente de alimentación (el cable rojo lleva +5 V). Si sólo desea utilizar el puerto paralelo, puede tomar la energía de una patilla de datos. Para la mayoría de implementaciones sólo se necesita una patilla, y recomiendo la patilla 9 para ello, la del mayor bit de datos. Sin embargo, si no planea utilizar nada más que NES/SNES en el puerto, puede tomar cualquier patilla desde la 4 hasta la 9 (ambas inclusive). (pin 9) -----> Energía Desafortunadamente, hay mandos que necesitan mucha más energía, y los puertos paralelos no pueden proporcionar tanta corriente a través de las patillas de datos. Si este es su caso, deberá utilizar diodos (para evitar destruir su puerto paralelo), y combinar la corriente de dos o más bits de datos juntos. Diodos (pin 9) ----|>|-------+------> Energía | (pin 8) ----|>|-------+ | (pin 7) ----|>|-------+ | : | (pin 4) ----|>|-------+ Ground is quite easy. On PC's parallel port the ground is on any of the pins from pin 18 to pin 25. So use any pin of these you like for the ground. (pin 18) -----> Ground NES and SNES pads have two input bits, Clock and Latch, which drive the serial transfer. These are connected to pins 2 and 3 of the parallel port, respectively. (pin 2) -----> Clock (pin 3) -----> Latch And the last thing is the NES / SNES data wire. Only that isn't shared and each pad needs its own data pin. The parallel port pins are: (pin 10) -----> Pad 1 data (pin 11) -----> Pad 2 data (pin 12) -----> Pad 3 data (pin 13) -----> Pad 4 data (pin 15) -----> Pad 5 data Note that pin 14 is not used, since it is not an input pin on the parallel port. This is everything you need on the PC's side of the connection, now on to the gamepads side. The NES and SNES have different connectors. Also, there are quite a lot of NES clones, and because Nintendo used proprietary connectors for their machines, the cloners couldn't and used standard D-Cannon connectors. Anyway, if you've got a gamepad, and it has buttons A, B, Turbo A, Turbo B, Select and Start, and is connected through 5 wires, then it is either a NES or NES clone and will work with this connection. SNES gamepads also use 5 wires, but have more buttons. They will work as well, of course. Pinout for NES gamepads Pinout for SNES gamepads +----> Power +-----------------------\ | 7 | o o o o | x x o | 1 5 +---------+ 7 +-----------------------/ | x x o \ | | | | | | o o o o | | | | | +-> Ground 4 +------------+ 1 | | | +------------> Data | | | | | | +---------------> Latch | | | +-> Ground | +------------------> Clock | | +----> Clock +---------------------> Power | +-------> Latch +----------> Data Pinout for NES clone (db9) gamepads Pinout for NES clone (db15) gamepads +---------> Clock +-----------------> Data | +-------> Latch | +---> Ground | | +-----> Data | | | | | ___________________ _____________ 8 \ o x x x x x x o / 1 5 \ x o o o x / 1 \ o x x o x x o / \ x o x o / 15 `~~~~~~~~~~~~~' 9 9 `~~~~~~~' 6 | | | | | | | +----> Clock | +----> Power | +----------> Latch +--------> Ground +----------------> Power 2.2 Multisystem joysticks ~~~~~~~~~~~~~~~~~~~~~~~~~ In the era of 8-bit machines, there was something like de-facto standard for joystick ports. They were all digital, and all used D-Cannon 9 pin connectors (db9). Because of that, a single joystick could be used without hassle on Atari (130, 800XE, 800XL, 2600, 7200), Amiga, Commodore C64, Amstrad CPC, Sinclair ZX Spectrum and many other machines. That's why these joysticks are called "Multisystem". Now their pinout: +---------> Right | +-------> Left | | +-----> Down | | | +---> Up | | | | _____________ 5 \ x o o o o / 1 \ x o x o / 9 `~~~~~~~' 6 | | | +----> Button +--------> Ground However, as time passed, extension to this standard developed, and these were not compatible with each other: Atari 130, 800(XL/XE) MSX +-----------> Power +---------> Right | +---------> Right | +-------> Left | | +-------> Left | | +-----> Down | | | +-----> Down | | | +---> Up | | | | +---> Up | | | | | | | | | _____________ _____________ 5 \ x o o o o / 1 5 \ o o o o o / 1 \ x o o o / \ o o o o / 9 `~~~~~~~' 6 9 `~~~~~~~' 6 | | | | | | | | | +----> Button | | | +----> Button 1 | +------> Power | | +------> Button 2 +--------> Ground | +--------> Output 3 +----------> Ground Amstrad CPC Commodore C64 +-----------> Analog Y +---------> Right | +---------> Right | +-------> Left | | +-------> Left | | +-----> Down | | | +-----> Down | | | +---> Up | | | | +---> Up | | | | | | | | | _____________ _____________ 5 \ x o o o o / 1 5 \ o o o o o / 1 \ x o o o / \ o o o o / 9 `~~~~~~~' 6 9 `~~~~~~~' 6 | | | | | | | | | +----> Button 1 | | | +----> Button | +------> Button 2 | | +------> Power +--------> Ground | +--------> Ground +----------> Analog X And there were many others. 2.2.1 Multisystem joysticks using joy-db9.c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For the Multisystem joysticks, and their derivatives, the joy-db9.c driver was written. It allows only one joystick / gamepad per parallel port, but the interface is easy to build and works with almost anything. For the basic 1-button Multisystem joystick you connect its wires to the parallel port like this: (pin 1) -----> Power (pin 18) -----> Ground (pin 2) -----> Up (pin 3) -----> Down (pin 4) -----> Left (pin 5) -----> Right (pin 6) -----> Button 1 However, if the joystick is switch based (eg. clicks when you move it), you might or might not, depending on your parallel port, need 10 kOhm pullup resistors on each of the direction and button signals, like this: (pin 2) ------------+------> Up Resistor | (pin 1) --[10kOhm]--+ Try without, and if it doesn't work, add them. For TTL based joysticks / gamepads the pullups are not needed. For joysticks with two buttons you connect the second button to pin 7 on the parallel port. (pin 7) -----> Button 2 And that's it. On a side note, if you have already built a different adapter for use with the digital joystick driver 0.8.0.2, this is also supported by the joy-db9.c driver, as device type 8. (See section 3.2) 2.2.2 Multisystem joysticks using joy-console.c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For some people just one joystick per parallel port is not enough, and/or want to use them on one parallel port together with NES/SNES/PSX pads. This is possible using the joy-console.c. It supports up to 5 devices of the above types, including 1 and 2 buttons Multisystem joysticks. However, there is nothing for free. To allow more sticks to be used at once, you need the sticks to be purely switch based (that is non-TTL), and not to need power. Just a plain simple six switches inside. If your joystick can do more (eg. turbofire) you'll need to disable it totally first if you want to use joy-console.c. Also, the connection is a bit more complex. You'll need a bunch of diodes, and one pullup resistor. First, you connect the Directions and the button the same as for joy-db9, however with the diodes inbetween. Diodes (pin 2) -----|<|----> Up (pin 3) -----|<|----> Down (pin 4) -----|<|----> Left (pin 5) -----|<|----> Right (pin 6) -----|<|----> Button 1 For two button sticks you also connect the other button. (pin 7) -----|<|----> Button 2 And finally, you connect the Ground wire of the joystick, like done in this little schematic to Power and Data on the parallel port, as described for the NES / SNES pads in section 2.1 of this file - that is, one data pin for each joystick. The power source is shared. Data ------------+-----> Ground Resistor | Power --[10kOhm]--+ And that's all, here we go! 2.2.3 Multisystem joysticks using joy-turbografx.c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The TurboGraFX interface, designed by Steffen Schwenke allows up to 7 Multisystem joysticks connected to the parallel port. In Steffen's version, there is support for up to 5 buttons per joystick. However, since this doesn't work reliably on all parallel ports, the joy-turbografx.c driver supports only one button per joystick. For more information on how to build the interface, see http://www2.burg-halle.de/~schwenke/parport.html 2.3 Sony Playstation ~~~~~~~~~~~~~~~~~~~~ WARNING: PSX support is experimental, and at the moment doesn't seem to work for most people. If you like adventure, you can try yourself. The PSX controller is supported by the joy-console.c. Pinout of the PSX controller (compatible with DirectPadPro): +---------+---------+---------+ 9 | o o o | o o o | o o o | 1 parallel \________|_________|________/ port pins | | | | | | | | | | | +--------> Clock --- (4) | | | | +------------> Select --- (3) | | | +---------------> Power --- (5-9) | | +------------------> Ground --- (18-25) | +-------------------------> Command --- (2) +----------------------------> Data --- (10,11,12,13,15) one only... You may have to add pull up/down resistors. Maybe your pad also won't like the 5V (PSX uses 3.7V). Currently the driver supports only one psx pad per parallel port, and these controllers: * Standard PSX Pad * NegCon PSX Pad * Analog PSX Pad (red mode) * Analog PSX Pad (green mode) 2.4 Sega ~~~~~~~~ All the Sega controllers are more or less based on the standard 2-button Multisystem joystick. However, since they don't use switches and use TTL logic, the only driver useable with them is the joy-db9.c driver. 2.4.1 Sega Master System ~~~~~~~~~~~~~~~~~~~~~~~~ The SMS gamepads are almost exactly the same as normal 2-button Multisystem joysticks. Set the driver to Multi2 mode, use the corresponding parallel port pins, and the following schematic: +-----------> Power | +---------> Right | | +-------> Left | | | +-----> Down | | | | +---> Up | | | | | _____________ 5 \ o o o o o / 1 \ o o x o / 9 `~~~~~~~' 6 | | | | | +----> Button 1 | +--------> Ground +----------> Button 2 2.4.2 Sega Genesis aka MegaDrive ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The Sega Genesis (in Europe sold as Sega MegaDrive) pads are an extension to the Sega Master System pads. They use more buttons (3+1, 5+1, 6+1). Use the following schematic: +-----------> Power | +---------> Right | | +-------> Left | | | +-----> Down | | | | +---> Up | | | | | _____________ 5 \ o o o o o / 1 \ o o o o / 9 `~~~~~~~' 6 | | | | | | | +----> Button 1 | | +------> Select | +--------> Ground +----------> Button 2 The Select pin goes to pin 14 on the parallel port. (pin 14) -----> Select The rest is the same as for Multi2 joysticks using joy-db9.c 2.4.3 Sega Saturn ~~~~~~~~~~~~~~~~~ Sega Saturn has eight buttons, and to transfer that, without hacks like Genesis 6 pads use, it needs one more select pin. Anyway, it is still handled by the joy-db9.c driver. Its pinout is very different from anything else. Use this schematic: +-----------> Select 1 | +---------> Power | | +-------> Up | | | +-----> Down | | | | +---> Ground | | | | | _____________ 5 \ o o o o o / 1 \ o o o o / 9 `~~~~~~~' 6 | | | | | | | +----> Select 2 | | +------> Right | +--------> Left +----------> Power Select 1 is pin 14 on the parallel port, Select 2 is pin 16 on the parallel port. (pin 14) -----> Select 1 (pin 16) -----> Select 2 The other pins (Up, Down, Right, Left, Power, Ground) are the same as for Multi joysticks using joy-db9.c 3. The drivers ~~~~~~~~~~~~~~ There are three drivers for the parallel port interfaces. Each, as described above, allows to connect a different group of joysticks and pads. Here are described their command lines: 3.1 joy-console.c ~~~~~~~~~~~~~~~~~ Using joy-console.c you can connect up to five devices to one parallel port. It uses the following kernel/module command line: js_console=port,pad1,pad2,pad3,pad4,pad5 Where 'port' is either the address of the parallel port the joystick/pad is connected to (eg. 0x378), or, if you are using the parport driver of 2.1+ Linux kernels, the number of the parport interface (eg. 0 for parport0). And 'pad1' to 'pad5' are pad types connected to different data input pins (10,11,12,13,15), as described in section 2.1 of this file. The types are: Type | Joystick/Pad -------------------- 0 | None 1 | SNES pad 2 | NES pad 4 | Multisystem 1-button joystick 5 | Multisystem 2-button joystick 6 | Sony PSX controller 7 | N64 pad 8 | N64 pad with direction pad as buttons (DirectPadPro style) The exact type of the PSX controller type is autoprobed, so you must have your controller plugged in before initializing. Should you want to use more than one of parallel ports at once, you can use js_console_2 and js_console_3 as additional command line parameters for two more parallel ports. Changes: v0.1 : First version (SNES only) v0.2 : X/Y directions were exchanged... v0.3 : Adaptation for kernel 2.1 v0.4 : Adaptation for joystick-1.2.6 - added open/close callbacks v0.5 : Renamed to "joy-console" because I have added PSX controller support. v0.6 : NES support v0.7V : Added "multi system" support v0.8 : Bugfixed PSX driver... v0.9V : Changed multi system support Added Multi2 support Fixed parport handling Cleaned up v0.10 : Fixed PSX buttons 8 and 9 v0.11V: Switched to EXCL mode Removed wakeup v0.12V: Added N64 support v0.13V: Updated N64 support v0.14V: Fixed N64 axis/button counts 3.2 joy-db9.c ~~~~~~~~~~~~~ Apart from making an interface, there is nothing difficult on using the joy-db9.c driver. It uses the following kernel/module command line: js_db9=port,type Where 'port' is either the address of the parallel port the joystick/pad is connected to (eg. 0x378), or, if you are using the parport driver of 2.1+ Linux kernels, the number of the parport interface (eg. 0 for parport0). Caveat here: This driver only works on bidirectional parallel ports. If your parallel port is recent enough, you should have no trouble with this. Old parallel ports may not have this feature. 'Type' is the type of joystick or pad attached: Type | Joystick/Pad -------------------- 0 | None 1 | Multisystem 1-button joystick 2 | Multisystem 2-button joystick 3 | Genesis pad (3+1 buttons) 5 | Genesis pad (5+1 buttons) 6 | Genesis pad (6+2 buttons) 7 | Saturn pad (8 buttons) 8 | Multisystem 1-button joystick (v0.8.0.2 pin-out) 9 | Two Multiststem 1-button joysticks (v0.8.0.2 pin-out) Should you want to use more than one of these joysticks/pads at once, you can use js_db9_2 and js_db9_3 as additional command line parameters for two more joysticks/pads. Changes: v0.1 : First version v0.2 : Changed kernel parameter format v0.3V: Added Sega Saturn support Fixed parport and PS/2 mode handling Cleaned up v0.4V: Switched to EXCL mode Removed wakeup v0.5V: Added 0.8.0.2 HW compatibility for Multi sticks v0.6V: Better timing for Genesis 6 v0.7V: Added 0.8.0.2 second joystick support 3.3 joy-turbografx.c ~~~~~~~~~~~~~~~~~~~~ The joy-turbografx.c driver uses a very simple kernel/module command line: js_tg=port,js1,js2,js3,js4,js5,js6,js7 Where 'port' is either the address of the parallel port the interface is connected to (eg. 0x378), or, if you are using the parport driver of 2.1+ Linux kernels, the number of the parport interface (eg. 0 for parport0). 'jsX' is the number of buttons the Multisystem joysticks connected to the interface ports 1-7 have. For a standard multisystem joystick, this is 1. Should you want to use more than one of these interfaces at once, you can use js_tg_2 and js_tg_3 as additional command line parameters for two more interfaces. 3.4 PC parallel port pinout ~~~~~~~~~~~~~~~~~~~~~~~~~~~ .----------------------------------------. At the PC: \ 13 12 11 10 9 8 7 6 5 4 3 2 1 / \ 25 24 23 22 21 20 19 18 17 16 15 14 / ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Pin | Name | Description ~~~~~~|~~~~~~~~~|~~~~~~~~~~ 1 | /STROBE | Strobe 2-9 | D0-D7 | Data Bit 0-7 10 | /ACK | Acknowledge 11 | BUSY | Busy 12 | PE | Paper End 13 | SELIN | Select In 14 | /AUTOFD | Autofeed 15 | /ERROR | Error 16 | /INIT | Initialize 17 | /SEL | Select 18-25 | GND | Signal Ground 3.5 End ~~~~~~~ That's all, folks! Have fun!