A working 8-bit Nintendo controller out of nothing? No problem! Get some speaker wire, a network cable, some floor protection pads, an empty plastic can, a 4.5 volt battery, lots of duct tape and a small cardboard box: a little something for a rainy day indeed!
Think of a standard PC parallel port once used for connecting printers: it has 8 data pins. Combine it with a cat5 network cable, which is actually 8 cables twisted together. How would you connect a gamepad, which has 8 buttons? Oh yeah.
First off, cut 8 bow-shaped, about 3 cm long pieces off the empty plastic can: these would be the button springs. For each spring, cut a lenght of about 8 cm of speaker wire, strip some isolation and put the stripped end run along the bottom side of the spring, fixing the wire into place with duct tape. On top of the spring, attach a piece of self-adhesive floor protecting material commonly used under furniture: this would make the spring look and feel more like a button. See the pics to get the idea!
Next, attach those newborn buttons on top of the little cardboard box, just like the buttons in a NES pad, and connect the loose wire ends to the positive terminal of the battery. The negative half of the circuit is to be taped on the surface of the box: for each button, put another piece of stripped speaker wire so that it runs under the button spring in a 90 degree angle. These crossing wires would then be connected to the 8 wires in a cat5 cable, which would in turn go into the 8 data pins of a PC parallel port. Last off, one of the parallel port’s ground pins should be connected to the negative terminal of the battery. The function is simple: when a button is pressed, the two crossing wires take contact, completing the electric circuit from the battery into the corresponding data pin of the parallel port. How cool is that?
Interfacing the controller with the PC is as simple. Firstly, the parallel port has to be set up being bi-directional (via BIOS setup, though it’s not possible with all systems). From here on, it’s all programming excercise!
The PC to use should be an old desktop running Linux, packed with a text editor (jed), a NES emulator (fceux), a C compiler (gcc) and a little utility for keyboard manipulation (xdotool). The gamepad buttons should be connected to the parallel port pins as follows:
Using a text editor, write a C-program which essentially does the following:
1. include sys/io.h library for port functions
2. call ioperm(0x378, 1, 1), to get access to first byte (the data bits) of the parallel port at address 0x378
3. call ioperm(0x380, 1, 1) to get access to the control register of the parallel port
4. set bit 5 of the control register to 1 (mode bit, 1=input, 0=output)
5. start an infinite loop, in which:
6. call val = inb(0x378), to read the data byte into val
7. check the bits stored in val and set appropriate flags, for example, if bit 0 is set, assign up_pressed=1
8. at the end of the loop, check the flags: if set, call system(“xdotool key X”) to simulate a keypress on the keyboard. It really makes no difference which key is simulated, but each button should obviously map into a different key
9. jump to 6.
After compiling and testing the program, it’s time to configure the NES emulator gamepad settings. As the C-program is running in the background, the set-up is all about just pressing the right buttons on the gamepad when prompted.
And the last step? Fire up the emulator with your favorite Nintendo classic and enjoy some retrospectacular Castlevania gameplay just like in the 90’s!