Some of you may remember the Nintendo entertainement system, at least the controller pads. The main NES unit itself got some major flaws (search "NES blinking led" on Google and you'll see), but the controllers are extremely reliable and flexible.

:::Warning, technical stuff ahead.

The reason is because they're as simple as it can get. Instead of using a higly advanced programable microcontroller, the only chip inside is a CMOS 4021B Shift Register. It's capable of interfering with anything from 3v to 30v, and it's therefore TTL compatible at 5V.

In the controller, the buttons are connected to each their Parallel Data input of the shift register (8 in total). If a button is not pressed, a pull-up resistor forces the input high, but if the button are pressed, that input line goes low. Three of the controll lines (Latch input, Clock input and Serial Data output) goes to the connector, and the remaining line (Serial Data input) is grounded. VCC and GND also goes to the connector.

The transfer protocoll used by the controller is quite simple. In order to read the combination of pressed keys, the user have to pull "Latch" high for at least 50nS, then pull it low again. Then the clock line must be toggeled to poll in the bits on the Data line. In other words, It's plain old Monodirectional Synchronous Serial Data Transmittion of 8-bits with no start bits, no stop bits and no pairity bits.

:::End of technical stuff

Because of this, it's easy to make it speak to an USB port. The only thing you need is a small microcontroller that handles the USB handshaking stuff. It's even easier to just connect it to the Parallel port since all you need then are some wires and a driver.

All of the above has already been done. That's why I don't plan to try to re-design any of them. However, I got some old XT's (an early version of the PC) with a keyboard layout not really designed for gamers, and I got some NES controller pads.

The XT's keyboard totally lacks the handy arrow keys of the more recent computers. To play games, you have to use the arrows on the numberic-keypad, and it's wery easy to hit num5 instead of "down-arow" as I'm used to the more recent keyboard layout. In addition, the keyboard is quite noisy, and makes a loud "click" sound each time a key is pressed. As you understand, therse computers wasn't designed for gaming.

Because of this, I want to make an adapter I can use to connect the NES controller to the XT, and a piece of software to take over certain interrupt vectors so I can use it with many games. I know both my XT's got parallel port expansion cards, but I don't care. I want to transmitt the data through the keyboard-input!

The reason wht I choosed the keyboard port was simple. Unlike all modern computers, the keyboard interface in the XT doesn't use a microcontroller. Just like the NES controll-pad, it uses a shift register with some extra logic to tie it to IRQ1. Because of this, it need no handshaking and timing, all it needs is a program knowing what's going on, almost at least.

After some resourcing, I figured the keyboard transfer bytes to the XT in 8-bit packets. The signal format is just as with the NES controller, with the only difference that the keyboard input requires one positive start-bit. Another fact is that the keyboard port only got one Input line and one bidirectional line (can be controlled by both software and the connected device). The bidirectional line is controlling the clock input of the shift register.

By the keyboard, the Input line is used to transfer serial data. This data is syncronized with pulses (sendt from the keyboard) on the bidirectional line. It's basically the same transfer method as the NES uses with the exeption that the keyboard doesn't got a latch input and that it generates the clock itself.

Now to the problems. The clock is no problem since the line is software controllable. However, the lack of a "latch" output and the requirement of a start bit was a real problem. I started to think about it and I came up with that I had to make some logic that took care of both the start-bit and the latch signal with the clock as the only input.

The ressult was kind of clever. I took 4 D-type flip-flops (74LS74) and made a divide-by-16 frequency-divider. I connected the output from this divider to another D-type flip-flop, and made the original clock reset this flip-flop on each negative pulse. The output from this was a 1-clock pulse every 16 clock cycle, and voila, I got my "Latch" signal.

for the stop-bit, I took a last D-type flip-flop and used it as a one-bit shift register. The data from the controller is clocked through this register, and therefore delayed one clock cycle. The register is also set with an inverted "latch" signal, and there I got my start-bit.

Finally, the data is just pushed through a 74LS07 buffer so that it's compatible with the open-collector signal of the data-line.

The last thing I had to do was to write a program. Currently, all this program does is to print the input from the controller to the screen, but I'll expand it in the future.

If anybody is interested in Gerber files or schematics, feel free to make a reply. I gladly accept comments.
Somebody was bored Razz

BTW wrong subforum; this should be under hardware.
Looks interesting, but sadly, tl;dr.
foamy3 wrote:
but sadly, tl;dr.

Ok. here is a short sumary of the article:

I just want to make a small adapter to connect the nes controll pad to the keyboard port of the PC/XT. The post explains why I'm doing it, what problems I had doing it, and how I'm able to overcome the the problems.

I got schematics and PCB layout ready, but I lacks the parts I need to make it so I can't confirm if it'll work.
Very neat, good use of digital logic. Personally, I felt that the technical warning around that one paragraph was wholly unnecessary; you definitely didn't delve into anything too esoteric. Smile
olav_nordmann wrote:
The reason is because they're as simple as it can get. Instead of using a higly advanced programable microcontroller, the only chip inside is a CMOS 4021B Shift Register. It's capable of interfering with anything from 3v to 30v, and it's therefore TTL compatible at 5V.
Quite the opposite - the NES controllers are needlessly overengineered. Most other consoles were using the standard DE-9 connector based on the Atari 2600 design, with one pin for common/ground and the other pins being connected to switches inside the controller. All you need to connect them to your PC's parallel port is a straight-through adapter from a DE-9 to DB-25. You can then simply read all eight input bits straight from the parallel port.

Interesting project, otherwise. Smile
Is there a particular reason that they went for the serial design instead of the much simpler parallel implementation you detailed above, benryves? Perhaps they couldn't spare the eight CPU I/O pins?
KermMartian wrote:
Is there a particular reason that they went for the serial design instead of the much simpler parallel implementation you detailed above, benryves? Perhaps they couldn't spare the eight CPU I/O pins?

I think it is because the CPU then has the ability to register all different key-combinations. If that should be possible through a parallel interface, it would have used 8 pins for data, and maybe one for triggering a read. Then the two extra pins used by the zapper also need to be added, and VCC/GND needs to be there too.

A connector with 7 pins is just cheaper and more reliable than one with >12 pins.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement