Jump to content

Hacking a mag swipe reader onto a mame arcade system...


CYAPPS
 Share

Recommended Posts

Ok, here's my issue, I am building my own arcade system from an old cabinet, pc (running windows xp and mame) and controls that I purchased online. I have my coin doors setup to credit the game when a coin is inserted but I was wanting to do something a little different. The way that the emulator (mame) receives a credit is by receiving the "5" key.

I wanted to have a mag swipe card reader on the machine (like some of the newer arcade style places) that would allow someone to swipe a card and have the emulator (mame) receive the "5" as a key press. I found some usb swipe card readers on feebay for a good price and they work perfectly as they where made, however the issue is they act as a human interface device and send the information that is on the magnetic strip to the computer as a unique string of text, so the emulator just freaks out thinking a bunch of different keys where pressed.

I either need a hardware device that can capture the data that the reader sends out as key presses and parse that data then determine if it is on a previously entered list of cards and then pass the "5" key on to the system to credit the game otherwise just halt.

Or something on the software level that will capture the data before it reaches the emulator and parse it, etc. then act accordingly.

Is there a way to force a human interface device to use a custom driver that would allow me to capture what was entered by just that device? I would prefer not to capture all keys that are pressed and just focus on ones from that exact device, that way I can avoid any slow down in game play.

I hope this makes sense (a little tired) and hope someone can point me in the right direction.

Thanks

Link to comment
Share on other sites

Run a script in front of the game, blocking all input, then kill it(or put it to sleep) after it has received the keys needed... think of GINA in windows. The problem with that is that when the person dies or time runs out how is the script going to restart its self? Best bet may be to redefine what keys the emulater uses, or block the input devices(there are settings somewhere, just dont feel like digging them up).

Link to comment
Share on other sites

this project sounds really fun,

So do you have a "pay station" where you can pay cash to put money into this card, then when you swipe the card, it takes money off of it?

If only I had the money and the use for this...

Link to comment
Share on other sites

this project sounds really fun,

So do you have a "pay station" where you can pay cash to put money into this card, then when you swipe the card, it takes money off of it?

If only I had the money and the use for this...

It is not about making money I just want to give someone a card and add it to the accepted list so they can play without having to insert a token into the coin slot. And maybe add in the option to log when a player swipes the card to play to keep track of how much they have played. It is more about getting the experience of doing it than a real need.

I understand how arcade machines work. I already have the machine setup and working, I just wanted to add the swipe card reader to the system. I haven't came across information of anyone else doing this other than at some entertainment places (Dave & Busters, etc.). They purchase there solutions pre-made from a third party and I just want to hack something together.

The hardest part is grabbing the key presses before the emulator sees them and then passing the appropriate key press through. I was thinking about using some type of hardware solution like the arduino and have the swipe reader send the text to that for processing, but I am not sure of its limits.

Link to comment
Share on other sites

I was thinking about using some type of hardware solution like the arduino and have the swipe reader send the text to that for processing, but I am not sure of its limits.

A card reader with serial output would be easy to interface with an Arduino. I don't know if there is a standard serial output (TTL or RS232) on the reader you have or if it is just USB.

Interfacing a USB magstripe reader with an Arduino would be difficult, as you would need a USB host controller to handle the USB magstripe reader device.

If you want help interfacing the magstripe reader with an Arduino (or the $20 Teensy USB dev board that Darren showed on episode 5x03) and PC, I'm interested in the project.

I don't know if there is a way to intercept the keypress data from your USB magstripe reader in software. Maybe there is a way to grab the specific device, but I don't know.

Link to comment
Share on other sites

I see two possible ways of doing this without requiring some sort of circuit/micro-controller or advanced key hook teqnikes to catch key presses.

First way is get a card writer and program the card contain the string "5 5 5 5 5 5 5 5 5 5" So they get 10 credits every time the card is swiped.

The only other way I can think of is add another button called labeled "free play" When pressed it would run a program that would pop up over mame. The box would prompt the user to swipe the card, in the popup have an invisible text box that was set to the default cursor location, So when the card it swiped the text box gets the Card information and most readers send an enter key press an the end (would press the OK button on the window). If the card info is the same as the one stored it would "press" the button 5 a few times.

Link to comment
Share on other sites

Using Raw Input from C# to handle multiple keyboards looks like it might be a good start to a software solution. A program running in the background capturing the input from the second keyboard (USB magstripe reader) could push a '5' into the keypress buffer when a valid card is swiped.

I don't have a USB magstripe reader that acts as a keyboard, nor have I tried the code at the above link (I just found it and haven't read through it all yet), nor have I used MAME, so I'm not certain how well it all fits together, but I think it could work.

Link to comment
Share on other sites

Thanks so much everyone for the input you have found me a lot of great leads to follow up on!

As for the reader I have, it is a SEMTEK 9172 and the spec file is at http://www.semtek.com/products/mini_swipe.pdf according to what I read the reader can output usb and rs232 so I believe the arduino would work nicely as I also want to hack around with it as well.

From what I have heard from the arcade community at http://forum.arcadecontrols.com mame is a little difficult to work with on the software side so my best and "easiest" solution might be hardware anyways.

Otherwise I may be able to implement a unlocking mechanism in the frontend loader via a plugin before mame starts that would unlock a free credit button located on the control panel that I could light up and activate when a valid card is swiped. I would just add an additional key value to the key map that way the coin mechs will work off of the original 5 key no matter what.

I will most likely go a head and purchase a arduino and maybe the teensy as I want to have them around anyways.

Link to comment
Share on other sites

heres a link to a magstripe -> arduino setup: http://www.instructables.com/id/Arduino-ma...stripe-decoder/

and im pretty sure you can get a serial version of the arduino here: http://www.nkcelectronics.com/freeduino-se...compatib20.html

I am thinking about getting the Arduino Duemilanove (or compatible) and maybe an arduino compatible LCD module to show the user if there card was accepted, etc. I will handle the processing and card data parsing on the mame system so I was thinking on getting the Arduino Ethernet Shield as well to allow me to "simply" take the data that was swiped and pass it to a local webserver running php then I will use php to decode and process everything then pass a simple accept or not accept string back to arduino over the ethernet shield which will display the results on the lcd and pass on the appropriate key press back to windows.

Is there an easy way to make a program for windows xp that can communicate back and forth with the arduino over the usb/serial without needing to use the ethernet shield because as of now the whole setup will be in one area and ethernet seems like overkill. Could the arduino send data directly to a program on the computer running in the background and also send key presses as a emulated keyboard?

Also if I get the freeduino kit you linked to, will all the arduino shields work with it? Is the serial version of the freeduino you linked to the same as the Arduino Duemilanove but with serial instead of usb?

Does anyone know of another arduino compatible ethernet shield that will be a little cheaper but close to the same quality?

Thanks

Link to comment
Share on other sites

This all just seems like way to much work/money for something like this. What is your exact setup, program wise, atm?

I am running windows xp pro with mame running on top of that. From what I hear mame is running at a low level so it is difficult to interface with on the software side, but as I am not a programmer I am not real sure. The money amount isn't really that bad, what I listed would be under $100 and if I can bypass the ethernet module then that would subtract $40. I will most likely be buying a arduino anyways as I want to have it to "play" with. But if I can I wouldn't mind doing this entirely with software.

Link to comment
Share on other sites

I do not have a magstrip reader but i will play with mame and see what i can come up with.

That would be great, thanks. The magswipe is just acting as a keyboard hid I believe. So being able to grab input from a unique hid device would be the same idea. Don't most hids use unique identifiers?

Link to comment
Share on other sites

The magswipe is just acting as a keyboard hid I believe. So being able to grab input from a unique hid device would be the same idea. Don't most hids use unique identifiers?

Did you take a look at the 'HID macros' program linked to from post 9 of this thread? If I understand the linked page correctly, I think it should do exactly what you want.

Link to comment
Share on other sites

Did you take a look at the 'HID macros' program linked to from post 9 of this thread? If I understand the linked page correctly, I think it should do exactly what you want.

Sorry, for some reason I bookmarked the page and downloaded the program but never looked at it... It should work for the more simple approach of catching a string that is entered by the reader and sending a keystroke back but I was also looking to use some sort of a database of card numbers and then I will be able to process and log all the swipes and stuff. But I guess I could call a bat file from this program but how would I get a key press back to the program? I am looking at it now to go more in depth. But windows key hooks looks to be what I would need to learn on the programming side.

Thanks

EDIT: I just tried it with mame so when I press 5 it would output 5555 and it didn't even see it so it may not work.

Link to comment
Share on other sites

but I was also looking to use some sort of a database of card numbers and then I will be able to process and log all the swipes and stuff.

Oh yes, I forgot about that. The solution is always simple when you ignore part of the problem. ;)

But I guess I could call a bat file from this program but how would I get a key press back to the program? I am looking at it now to go more in depth. But windows key hooks looks to be what I would need to learn on the programming side.

I'm not sure if the HID macros program can do what you want, I didn't look at it with the card database idea in mind.

It should be possible to write software that will hook the USB magstripe reader you have, and then to deal with the data however you want (checking against a db, recordkeeping, etc), and then put the '5' keypress in the keyboard input buffer (to trigger MAME).

I don't know how hard it is to put keypresses into the keyboard buffer in a way that MAME will accept them, if it hooks into the keyboard at a lower level then that may be difficult (but I would try it out anyway). I'm also not sure how hard it is to hook into the USB magstripe reader and have no other software see the input - I played around a little bit and I was able to capture keyboard input but I wasn't able to stop that input from also going to any other program that had focus. (it should be possible though - that's what the HID macros program is doing, if I understand it correctly)

I don't know if you have the option to switch to a different magstripe reader, but if you use one with a serial interface then that would solve any keyboard conflict issue. (also it would be easier to work with a serial interface if you decide to build a hardware-based solution)

I have been playing around with the Teensy development board (Darren did a segment on it a couple weeks ago), I am very impressed with it. It's low-cost and very small, and there are some nice sample programs in the 'code library' area on the PJRC website. One of the sample programs shows how to interface the Teensy board to the PC as a keyboard - it's very simple to modify the program to send whatever keypress you want. It could make a nice hardware solution if you choose to take that route.

Link to comment
Share on other sites

It should be possible to write software that will hook the USB magstripe reader you have, and then to deal with the data however you want (checking against a db, recordkeeping, etc), and then put the '5' keypress in the keyboard input buffer (to trigger MAME).

I don't know how hard it is to put keypresses into the keyboard buffer in a way that MAME will accept them, if it hooks into the keyboard at a lower level then that may be difficult (but I would try it out anyway). I'm also not sure how hard it is to hook into the USB magstripe reader and have no other software see the input - I played around a little bit and I was able to capture keyboard input but I wasn't able to stop that input from also going to any other program that had focus. (it should be possible though - that's what the HID macros program is doing, if I understand it correctly)

Yes, if I knew anything about programming I may have an easier time of things. But I only have very little experience with php. According to everything I have read mame grabs the keyboard input at a low level I believe it uses DirectInput. I have read some people talking in 2006 about editing the source of mame but that seems like it would be much.

I don't know if you have the option to switch to a different magstripe reader, but if you use one with a serial interface then that would solve any keyboard conflict issue. (also it would be easier to work with a serial interface if you decide to build a hardware-based solution)

According to the specs of this reader it is usb and serial. Maybe it sends serial data to a converter on the device that converts it to usb. If so I could bypass the usb conversion.

I have been playing around with the Teensy development board (Darren did a segment on it a couple weeks ago), I am very impressed with it. It's low-cost and very small, and there are some nice sample programs in the 'code library' area on the PJRC website. One of the sample programs shows how to interface the Teensy board to the PC as a keyboard - it's very simple to modify the program to send whatever keypress you want. It could make a nice hardware solution if you choose to take that route.

That is exactly what got me interested in the hardware solution but of course I wanted to go even further and thought about the arduino. But as I said either way I am going to most likely get a arduino and teensy to play with anyways.

Link to comment
Share on other sites

What is the exact version of mame that you are using? Is it 130 or a previous version with a frontend? Im downloading the newest source atm but it would help if i can mirror your setup as close as possible.

EDIT

src\emu\input.c

/* token strings for device classes */
static const code_string_table devclass_token_table[] =
{
    { DEVICE_CLASS_KEYBOARD, "KEYCODE" },
    { DEVICE_CLASS_MOUSE,    "MOUSECODE" },
    { DEVICE_CLASS_LIGHTGUN, "GUNCODE" },
    { DEVICE_CLASS_JOYSTICK, "JOYCODE" },
    { ~0,                    "UNKCODE" }
};

So a quick look over it I would add a new device class.

 { DEVICE_CLASS_MAGCARD, "CARDCODE" },

Then below that in the next class

 { DEVICE_CLASS_MAGCARD, "Card" },

Long code is long so i just pastebined it. Here you can hack it a bit and just remove unused keyboard keys and give them to the mag card. http://pastebin.com/f3a7c0ca6

But looking over this it hooks in way to many places, you would have to edit almost all of that and then a bunch of headers, not to mention game drivers. So yeah i dont think source editing is feasible... But ive only have 5mins to look over it.

How is mame reading your card exactly? Can you run a keylogger, getasci, and see exactly what is going on? I havent use mag cards so im just guessing here.

Link to comment
Share on other sites

What is the exact version of mame that you are using? Is it 130 or a previous version with a frontend? Im downloading the newest source atm but it would help if i can mirror your setup as close as possible.

I was running an older version of mame I believe 1.23 but I updated to 1.30. And my frontend is MaLa 1.05.

But looking over this it hooks in way to many places, you would have to edit almost all of that and then a bunch of headers, not to mention game drivers. So yeah i dont think source editing is feasible... But ive only have 5mins to look over it.

That is what I was figuring...

How is mame reading your card exactly? Can you run a keylogger, getasci, and see exactly what is going on? I havent use mag cards so im just guessing here.

When I open notepad and swipe a card I get %S3UNIQUE ALPHA NUMERIC CODE?;ID NUMBER OF CARD?;E? for a valid swipe and ;E?;E? for a bad swipe.

From what I see the string will always start with a ; or % no matter what card is swiped and the ; is used to separate the tracks on the strip (I am using a 2 track reader).

As I said I may just figure out how to make a plugin for MaLa that will capture a key swipe while in the frontend then process the data and if it is an accepted "good" swipe then it can load a keymap that will have another key mapped to the credit key and on my control panel I would just have a free play button that will be activated and lit. Just another option :).

Thanks

Link to comment
Share on other sites

Making a plugin for the frontend to MAME is going to be the best option, it should get the keys and send them to terminal.

Take a look at AutoIt, I think i remember someone making a code that would catch keys before they were entered into a text area and convert them to something elese, i.e 1234 would equal abcd, so you could convert ; or % to null and the rest to 5's. I have another project I am working on atm but when i get a chance ill see what I can do. Might want to ask in the programing section if anyone knows of a way to catch keys.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...