Home     Contact     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS     Terms of services     Privacy policy  
 Home      Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science   

27 May 2009
Author: Giorgos Lazaridis
MAME Arcade-style console circuit

The Problem...

A poor (but enough for demonstration reasons) arcade console with 2 joysticks, 4 buttons for each player, 2 start buttons and one coin button

The PCB with all parts soldered, ready for action

I am sure that every one knows the MAME machine, the ROM arcade emulator. There are thousands of people that spend their time with the "oldies but goldies" arcade coin-up games. The problem when playing MAME is than when you play games such as street fighter or samurai shodown, games that require multiple keyboard keys to be pressed simultaneously in order a special move to be achieved, the keyboard cannot handle it. The key matrix of the keyboard can allow no more than 5-6 keys, in special cases, to be pressed simultaneously. The problem is harder when there are two players playing together. The annoying distinctive "BEEP" will be heard when one makes low defense and the other attacks from above...

Particularly this problem, sent me directly to the lab, under the bright cool light, in order to design something that would allow enough keys for both players to be pressed simultaneously without any problem. The first idea was to have more than one USB keyboard and use some of the keys from each keyboard, but this idea was pretty lame. Other ideas like using keys from the keyboard matrix that do not really interact to each other came up to be easy but not-enough, as those keys are way too few. After hours of concentration and rejections, i discovered finally that what i really need is a keyboard replacement...

A custom keyboard replacement

The scenario was to copy the keyboard protocol and put it in a PIC. The inputs of the PIC would be also the inputs of the buttons. I found the keyboard protocol to be easy to re-create. I wrote a tutorial myself for PS2 keyboard protocol theory for those that would like to know how the keyboard talks with he computer.

To make the keyboard replacement much more expandable, i decided not to use a big PIC with many inputs for the keys. Instead, i would use a 16F88 and from 3 I/O ports i would cascade 74166 TTL's to perform a PISO (Parallel In Serial Out) circuit that could be easily expanded with as many inputs as i wanted. The following circuit has up to 24 inputs. 4+4 inputs for the two joysticks, 12 buttons (6 for each player), 2 start buttons, 1 coin button and one pause button. That would be the original layout, but can be changed in terms of button count and functionality.

To test this circuit, we run some extreme tests. No matter how many buttons where pressed simultaneously, the circuit responded fast and accurate to the PC. A big relief :D

In action!!!

I really like to see first a circuit in action and then the circuit itself, when i visit other site with electronic projects. This helps me understand through the action if it really worths to see the circuit itself :). Therefore, in every project that will follow, i will first demonstrate the construction working and then the how-to.

The following video demonstrates the circuit capabilities. 11 keys (contacts) will be pressed simultaneously (as possible as that can be) to see how the computer will response to this flood. You will also see that using a conventional keyboard this is by far not possible to be done.

The electronic circuit

Following may you find the schematic circuit of the construction.

IMPORTANT!!! The schematic is rather new, drawn during May 2009. The project was first created during October 2005. The original schematic circuit is lost, therefore i had to draw a new schematic. The new schematic is NOT 100% compatible with the PCB that will follow. That's why you will have to decide which one to follow if you wish to make the project yourself. The PIC program on the other hand will work for both the PCB and the schematic.

The PIC is the heart of the circuit. The oscillation frequency (XTAL) is 4MHz. When no input from the 74166 is taken low (no button is pressed), the PIC will give always control to the external keyboard attached. Thus, the user will be able to use the keyboard normally.

All the time, the PIC runs a loop internally to acquire the 24 inputs from the three TTL. If an input changes state, from HIGH to LOW or vice versa, it will cut-off the external keyboard and will give control to the PIC itself, by changing the bidirectional switches of the 4066. Then, it will send the appropriate data to the PC, according to the PS2 protocol. The circuit is clocked at 24KHz, a perfect tune for the PS2 (20-30KHz range). Right after, it shall give control back to the external keyboard.

The loop shall run again after a short period of time, to avoid flooding the PC buffer due to switch bounces.

You should NOT forget to connect an external PS2 keyboard to the "Keyboard" pads. This keyboard will handle all the communication needed to be done between this and the computer during the startup time, so that the PS2 will operate normally. And also, this keyboard will later operate as a normal keyboard attached to the PS2.

The 5 Volts power supply is better to be taken from another source. I have tested myself this circuit with power supply taken directly from the PS2 port with no problem at all. This is not suggested though, as the PS2 can supply up to 100mA normally. Enough for one keyboard but not for a keyboard and PCB with 5 chips.

My suggestion is to hack your old PS2 cheap keyboard, remove the useful wire with the PS2 connector on the edge, and solder another 4-core wire in it's place. This wire will be connected to your PCB ("Keyboard" pads). The wire that was taken from the keyboard, the one with the PS2 connector on one end, shall be used to connect your PCB with the computer ("PC" pads). Then, you will have a parallel male PCB mounted right angle connector mounted on the PCB. Hack you old parallel printer connection cable then. Remove completely the male connector and trash it. There will be 25 wires inside the cable. 24 for the keys and one with the LOW signal to actuate them. If you use a standard parallel printer cable, this wire should be the White-Blue wire.

Your construction should be ready to work! Do not forget to connect the pull-up resistors otherwise funny things may happen. You could alter the PCB a little bit but i wanted to use resistor nets and that was very difficult for a small on-layer PCB. So i have not include them on the PCB. See bellow how i have connect them. I did some surgery-work on the bottom side (copper) of the PCB and soldered two resistor-nets of 9 and 6 more 1/4 Watt resistors, all 10K rated, directly to the pads of he 25-pin plug. You could do the same to save significant space on the PCB.

Programming the keys

There are 24 available inputs from the three 74166 TTL inputs. Those inputs correspond to 24 places of the EEPROM memory within the PIC controller. The key to be sent upon an input actuation (a LOW transition of the input) is defined within these 24 spaces of the EEPROM. So, you should program your EEPROM of the PIC accordingly. Those 24 places are located from 0x00 to 0x17, and could have a single byte number, Each number corresponds to a key that shall be sent. The following table show those number and key definitions:

Number KEY
0x00 0
0x01 1
0x02 2
0x03 3
0x04 4
0x05 5
0x06 6
0x07 7
0x08 8
0x09 9
0x14 a
0x15 b
0x16 c
0x17 d
0x18 e
0x19 f
0x1A g
0x1B h
0x1C i
0x1D j
0x1E k
00x1F l
0x20 m
0x21 n
0x22 o
0x23 p
0x24 q
0x25 r
0x26 s
0x27 t
0x28 u
Number KEY
0x29 v
0x2A w
0x2B x
0x2C y
0x2D z
0x2E Left Shift
00x2F Right Shift
0x30 Ctrl
0x31 Left Alt
0x32 Backspace
0x33 <
0x34 >
0x35 /
0x36 :
0x38 [
0x39 ]
0x3A -
0x3B =
0x3C Enter
0x3D *
0x3E -
00x3F +
0x40 ~
0x41 Space
0x43 Right Alt
0x44 Left Arrow
0x45 Right Arrow
0x46 Up Arrow
0x47 Down Arrow
0x48 Ins
0x49 Del
0x4A Home
0x4B End
0x4C Page Up
0x4D Page Down

For example, if you would like to send key "LEFT ARROW" when the first input is actuated, you should put the number 0x44 to the position 0x00 of the EEPROM and so on.

Each time that the PIC requests to read the inputs, they are shifted in series. The first bit corresponds to EEPROM position 0x00, the seccond to 0x01 and so on. The very first bit comes from the IC1-A, the second from IC1-B and so on until the 8th bit. Then, the 9th bit comes from the IC2-A, the 10th from the IC2-B and so on until the 16th bit. The last 8 bits (17-24) comes from the IC3 inputs A to H.

You should now be able to program the corresponding keys for your layout yourself. In any case, you can find flowing an attached file that has pre-programmed the inputs the way that i have the keys programmed. It's a good start if you really want to avoid this step. Just download the file data to the PIC EEPROM and that's all.

 EEPROM - My key definitions

Just for the records, i use the key 5 for the coins, 1 and 2 for player 1 and 2 to start, arrow keys for the player 1 moves, DGRF for the player 2 moves, L Ctrl, L Alt, L Shift and Space for the player 1 keys (1-4) and QWAS for the player 2 keys. Almost the same as the MAME original setup that i have.

For the one that wants to go deeper in programming the keys, i have also include a pdf to download and see all the scan codes for all the keys, even for the modern keyboards with multimedia and ACPI support.

 Keyboard Scan Codes

The Printed Circuit Board

Please read the note from the "electronic circuit" above before you start etching!!!

The PCB from the copper side

The PCB from the components' side

As you may notice, there are no pull-up resistors (R1,R2 and R3) included in the above PCB. That is one of the differences that the actual schematic and this PCB have. The original design had the resistors soldered on each button. You may use the same PCB, but remember to add those resistors yourself. You could also make another small PCB that would be plugged between the 25pin input of the circuit and the 25pin cable of the buttons. Or any other way. Use your imagination.

The PIC code

Following you may find the complete PIC code for this project. The code is fully tested ONLY on a PIC 16F88 chip. You may need to alter it if you want to program another PIC. The Code.zip is the actual code files, and the HEX.zip is the same code assembled into hex-code so that you can easily program a chip. Please note that I use MPLAB and therefore, there could be problems reading the assembly code from another GUI.

 Code.zip - The assembly code listing

 HEX.zip - The code assembled into hex-code ready to be programmed


It's not over yet. As you may have already notice, there are 5 I/O ports of the PIC that are not used, however they are wired to pads. Those pads are actually unused... Yet, there are some ideas for them. The upgrade of this circuit is an LCD monitor for the user to be able to program the EEPROM keys directly, without the need of re-programming the chip. Or it could work in a way that the external keyboard will be used to program the keys. Or maybe both! In any case, stay tuned!

Also, the communication with the PC is still NOT bidirectional. It has been left from the test-runs like this. Until now, we had no problem with this. That's why i have not proceed with the other half of the protocol implementation. For educational reasons i may enrich it with 'ears' in later days. But i have to note here that during the PC startup, it requests an answer to some commands from the keyboard in order to consider it present. If no answer, the PS2 will not operate at all. Therefore, the external keyboard is very important to be connected to the appropriate inputs of the PCB. During startup, it will answer to all the questions of the PC and the PS2 will operate normally. That's the trick!

Relative pages
  • Learn how to interface ICs
  • Learn how the PS2 keyboard protocol works
  • 4000 series IC pinouts
  • 74 Series IC Pinouts
  • Learning PICs @ PCB Heaven On-Line Book

  • Comments


      Email (shall not be published)


    Notify me of new posts via email

    Write your comments below:
    BEFORE you post a comment:You are welcome to comment for corrections and suggestions on this page. But if you have questions please use the forum instead to post it. Thank you.


  • At 27 May 2012, 12:10:37 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]
    • @Stoqn Nikolov C1=0.1uF, C2=C3=18nF

  • At 27 May 2012, 12:03:29 user Stoqn Nikolov wrote:   [reply @ Stoqn Nikolov]
    • how can I find what are the C1 C2 C3 ? I want to try it...

  • At 15 August 2009, 16:46:41 user Kammenos wrote:   [reply @ Kammenos]
    • Yes Anonymous, i can send to USA. The shipping costs is 3 to 5 euro. I have to ask first. You can donate me the money. That's how it worked with another guy from Germany.
      We are working on this project with the rest of the PCB Heaven staff to see how we can really make it work.

  • At 12 August 2009, 19:52:37 user Anonymous wrote:   [reply @ Anonymous]
    • Can you send to USA?

  • At 10 June 2009, 10:54:31 user Kammenos wrote:   [reply @ Kammenos]
    • I've checked the shipping costs with normal mail. Depending on the country/region, it should be about 3 to 5 euros. For more info please email me (webmaster@pcbheaven.com)

  • At 10 June 2009, 5:42:38 user ditter wrote:   [reply @ ditter]
    • How much is the shipping costs to Germany?

  • At 3 June 2009, 21:12:12 user Kammenos wrote:   [reply @ Kammenos]
    • How would it be if i do the programming for you people? You may send me the PICs. You will only pay the transportation from and to Greece (where i live)...

  • At 3 June 2009, 18:16:25 user guest1 wrote:   [reply @ guest1]
    • Just amazing… great job!!! Sadly not all of us have a pic programmer…

  • At 31 May 2009, 8:39:19 user Tivo wrote:   [reply @ Tivo]
    • geil!

    reddit this Reddit this

     HOT in heaven!

    NEW in heaven!

    New Theory: AC electric motor working principle

     Contact     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS   

    Site design: Giorgos Lazaridis
    © Copyright 2008
    Please read the Terms of services and the Privacy policy