1

I just bought an old 2-axis 6-button gamepad on eBay which I plan to add support for in a game i'm writing for MS-DOS in 8086 assembly.

While I wait for it to be delivered i've been looking into low level programming of joysticks and game port based controllers. I can't find any documentation pertaining specifically to programming gamepads, only joysticks. I'm assuming they're treated the same as joysticks at the hardware level anyway, but I may be wrong.

Here's a link to an image of the gamepad just to show that it's nothing like a joystick.
https://i.ebayimg.com/images/g/9xsAAOSwBjdaOHFo/s-l1600.jpg

From what I can find, you access the game port via hardware port 201h, but I can't understand what the documentation is getting at as far as what the input bits actually represent.

This link describes the bits: http://docs.huihoo.com/help-pc/hw-game_port.html

First of all it only mentions 2 buttons. What if the controller has 6 buttons? Also, "joystick a, x coord (0 = timing active)" is the description of bit 0. Okay, but where do you actually collect the X coord? That just seems to tell you if timing is active, or inactive. Is it the length of time of the pulse that determines the X coord?

This link mentions that int 15h function 84 provides a somewhat easier method of accessing joysticks, but it only returns 4 button inputs, 2 per joystick, I think.

http://www.fysnet.net/joystick.htm

I would rather collect input directly from port 201h rather than use the BIOS service. Just to understand how it works.

bad
  • 939
  • 6
  • 18
  • 1
    Paddles worked like joysticks. You charge the capacitors with a write to port 201h and see how long each of the axises bits remain high (i.e. zero) you can then compute the position (i.e. the resistance value) using the usual exponential formula for a capacitor discharge or with a linear approx. See [here](http://pinouts.ru/Inputs/GameportPC_pinout.shtml). – Margaret Bloom Dec 24 '17 at 09:43
  • IDK how the extrabuttons are handled, maybe by using the joystick B bits? – Margaret Bloom Dec 24 '17 at 09:44
  • Out of curiosity, how are you connecting a gameport device to a modern computer? Do expansion cards exist for PCI.e? – Margaret Bloom Dec 24 '17 at 09:52
  • I'm using an old laptop. They can also be emulated by DOSBox. – bad Dec 24 '17 at 11:02
  • Now that I look more closely at the game pad, I realize it has 4 buttons and 2 trigger buttons. My guess is that the 4 buttons map to the 2 sets of 2 buttons per joystick. So really I think it just behaves like 2 joysticks installed at the same time. Maybe the 2 trigger buttons map to the second joystick's X/Y coordinate input bits somehow? – bad Dec 24 '17 at 11:37
  • @Proughgrammor That's probably the case, especially if the trigger buttons are analog. – fuz Dec 24 '17 at 12:20
  • @MargaretBloom Yes, they do. – fuz Dec 24 '17 at 12:20

1 Answers1

3

From what I can find, you access the game port via hardware port 201h, but I can't understand what the documentation is getting at as far as what the input bits actually represent.

I'd assume that the joystick uses an RC ("resistor/capacitor") circuit, where the position of the joystick's X or Y control effects the resistance, which effects the time it takes for the capacitor to charge up. When the capacitor's charge reaches a certain level it'd set the "timing active" bit, and when the capacitor is fully charged it'd be drained/discharged for the next time. The end result is that by repeatedly reading from (e.g.) "joystick a, x coord" at regular intervals and measuring the time between "bit first became set" to "bit became unset again" it'd tell you which position the joystick's (variable) resistor was in.

Don't forget that these things were notoriously inaccurate. You'd have to calibrate the joystick before use (using a sequence that typically involved measuring "dead center" X and Y values, then measuring "top right" X and Y values and "bottom left" X and Y values, then defining some kind of dead-zone near the middle; and after doing this painful calibration procedure you'd play a game for 15 minutes causing the variable resistors to heat up a little and throw the calibration out; and usually (due to dust/wear on a carbon track within the typically cheap/low quality variable resistor) the joystick would become erratic after a few days of use. Of course this all assumes that the variable resistors are actually compatible with the PC joystick port (e.g. same range of resistances with the same curve), and there's no reason to assume that the variable resistors in a gamepad would be compatible at all.

Also note that (back then) most people didn't use the joystick port (and just used a mouse that didn't have the accuracy or reliability problems), and the few manufacturers that originally provided a joystick port stopped bothering decades ago (everyone switched to USB instead), so it'd be extremely difficult to find any hardware that actually has a working joystick port now. I'd assume the same would have happened for "BIOS int 15h function 84" (that BIOS manufacturers haven't bothered to implement it for three decades and the function just returns "carry flag set" or "everything always zeros").

First of all it only mentions 2 buttons. What if the controller has 6 buttons?

It was only intended to support 2 buttons per joystick; but was also intended to support 2 joysticks. This means that you should be able to connect 4 buttons (2 buttons as "joystick a buttons" and the 2 extra buttons as a "joystick b buttons"); as long as you're writing the software yourself and don't expect any existing old game to support it. For more than 4 buttons the joystick port won't work, but maybe you could connect the buttons to something else instead (e.g. with suitable buffering logic and pull-up resistors; connect them to control lines in a parallel port or serial port).

Brendan
  • 35,656
  • 2
  • 39
  • 66
  • You really have to calibrate them each and every time? The controller I bought just has a 4 direction d-pad (I think it still works like a joystick, though). The only thing I would need to know is if the user is holding up, left, right, or down on the d-pad. I wouldn't be able to tell that without calibration? – bad Dec 24 '17 at 11:13
  • @Proughgrammor: Back then, the OS (MS-DOS) didn't do anything (e.g. track joystick settings) and each game needed to have its own calibration (and the joysticks really were quite bad). If the gamepad you've bought has 4 direction switches (and doesn't have "2-axis variable resistors" for direction) then it won't need calibration but also won't work for the old PC joystick controller (because the joystick would essentially be "0-axis, 12 buttons"). – Brendan Dec 24 '17 at 17:59