P

ADVANCED AHK AND JOHNNY5 CONCEPTS

INTRODUCTION

This page will look at some options with the AutoHotKey Script and Johnny5 that are not required for MAME™ usage and are too detailed to explain in the main pages of this site.  It is assumed that you will have a good familiarity with the standard useage of Johnny5 and AHK so the explanations here will be less detailed than the main page sections.

Most of the credit for these workarounds goes to papaschtroumpf (mainly) and popcorrin from BYOAC.  I haven't done a lot with this, but I have verified the basic functionality.

The concepts can work fairly well with either PC games or other emulators, either arcade or console.  Generally speaking, the steps to be undertaken are as follows:

BASIC CONCEPTS

This page basically divides into three sections:

AHK SCRIPT CONCEPTS

A detailed description of all the ways to utilize the AHK Script and possible modifications to it is far beyond the scope of this page.  I will provide some ideas, and unfortunately, either you will likely be able to expand these concepts to make the script do what you want, or you won't. . .  There are basically three ways of modifiying the AHK Script (aside from completely different AHK Scripts for new functions):

The results you could achieve with modifications to the AHK script are pretty impressive.  I have not tried it out and don't have room to post it in detail, but you can read about it here (local edited mirror here).

JOHNNY5 THEORY AND LIMITATIONS

Papaschtroumpf actually has more experience with using Johnny5 with PC games and I will rely highly on his descriptions for the instructional part of the text, but for now I will try to explain, for those who want to know, as best I can why we are able to use Johnny5 with non-MAME games.  This is a simplified example, and may not be 100% accurate, but should give you an idea of how this is accomplished.  First, this is how Johnny5 normally works when we pass it a romname:

With this info we can deduce the following conclusions:

JOHNNY5 SETUP OVERVIEW

If you don't care about the theory and just want to get on with it, the steps to modify Johnny5 are basically as follows:

JOHNNY5 SETUP

The first optional, but recommended, step to this procedure is to copy the entire c:\johnny folder and subfolders to a new directory, for example, c:\johnnypc.

Most of the concepts for this page came for this BYOAC thread (local mirror from 13 Oct 05).  I ended up quoting most of the thread, but have also expanded on it and also sorted the data into the appropriate sections.  

The first thing I did was test Popcorrin's idea of creating a dummy entry in the controls.ini file.  I modified c:\johnnypc\data files\controls.ini and added the following between two of the existing games:

Then I ran "Johnny5 testgame" and it displayed fine, as below (click twice to enlarge):

testgame

NOTE:  The information below in yellow was provided by papaschtroumpf, my comments are in white.

I do have additional information, and I think I'm 95% of the way where I want to be:

It seems the easiest way to do this is to add your PC games at the end of the real controls.ini. I think I'll keep a PCcontrols.ini file that I can append at the end of the official controls.ini whenever I download a new version. Just like you did, I kept all the fields that appear in a regular mame entry, maybe it's not necessary but it won't hurt. You can even set the alternating and numplayers fields to describe the game if you want to.

EDIT:  I recommend creating a new controls.ini in the c:\johnnypc\data files\ folder rather than c:\johnny\data files\.

You then just set P1NumButtons and enter the proper P1_BUTTON? labels, just like in your example.  Make sure that P1NumButtons is set to the correct value, or Johnny5 will ignore "extra" button labels.

I had another problem to solve:  In my PC games, I use additional buttons that are either not used in MAME or are considered "admin" buttons by Johnny5 and therefore ignored by its parsing.

For example I may have mapped a PC game control to the "1" key, which is the Player 1 Start key for MAME, labelled "START1" in the CTRLR files.(Default CTRLR file is C:\MAME\CFG\default.cfg). I tried adding "START1=test" to the entry in controls.ini, but johnny5 ignores it, even if I create a label for "KEYCODE_1" in the layout designer.  Johnny5 seems to only match KEYCODE_? labels in the layout file to P1_BUTTON? entries in the control.ini.

EDIT:  Johnny5 also ignores Player2_ButtonX= entries in the controls.ini file, using the P1_ButtonX entry instead.

I managed to solve the problem with the following "hack":

I defined my additional buttons as P1_BUTTON10 through P1_BUTTON14 in my CTRLR file. I don't have Internet access at home right now (typing this from work) so I can't cut and paste what it looks like, but just look at the definition of "P1_BUTTON1" and cut and paste it and modify the button name to P1_BUTTON10 and change the keycode to the correct value.

Note that's it's OK to have multiple definitions for a single keystroke. For example mame's START1 is mapped to the "1" key, but you can also map "P1_BUTTON10" to the same "1" key.

EDIT:  I personally would start with P1_BUTTON11 through P1_BUTTONXX since MAME already has a default P1_Button10 assignment (although the only game I know that approaches that many buttons would be the Whack-A-Mole type games and they only use nine.)  To avoid confusion, I am using P1_BUTTON10 and up in the examples.

Here is what the added code in the c:\mame\cfg\default.cfg file should look like (although leaving the defaults for P1_BUTTON10 is optional and I am guessing what papaschtroumpf used for buttons 11, 12, and 13):

I highly recommend manually making a chart of button assignment to panel button and saving it for future reference, something like:
P1_BUTTON10 = Start 1
P1_BUTTON11 = Coin 1
P1_BUTTON12 = Start 2
P1_BUTTON13 = Orange button on front of control panel
etc.

You will also want to assign buttons for Joystick 2 and the Player 2 buttons, say P1_BUTTON15 through P1_BUTTON26.  This should cause no problems for MAME, as 2-Player games will not use more than 15 Player 1 butttons, and PC games won't typically have any Player 2 buttons.

You might end up with a lot of defined fake Player 1 buttons, up to the limit of your encoder.  You might even include shifted inputs, which I think you could display in a different color than primary ones by customizing your Johnny5 layout (.lof) file.  One thing to consider is screen real estate for the PC games.  The image below (click to enlarge) was something I worked up in Microsoft Word for Microsoft Train Simulator.  Red entries are shifted entries.  This would be difficult to fit on a Johnny5 layout and impossible to view on an arcade monitor.  (And I left out some less often used controls):

msts

I then added the corresponding keycode labels in my Johnny5 layout file (c:\johnnypc\layouts\*.lof file, using the layout editor function of Johnny5), for example I added a label for KEYCODE_1 under the picture of the Player 1 Start button (which is now also defined as P1_BUTTON10).

NOTE:  You might want to make other customizations to your .lof file at this time.  For example, the "2-Player Simultaneous/2-Player Alternating" field doesn't make sense for a lot of non-MAME games, so you might want to remove it, etc.

A (controls.ini) entry for a game would then look something like this:

The entries in blue show the "regular" mame buttons and the entries in red show the "additional" buttons that are either unused or admin buttons in mame. For example P1_BUTTON10 is tied to key "1" as explained above and P1_BUTTON14 is tied to "P" on my cab.

After initially reading this, I asked papaschtroumpf for clarification on the following:
Okay, so I can have a P1_BUTTON14 and Johnny is happy with it even though MAME doesn't define this?
Okay, I re-read your example and that seems to be what you are saying. . .

He replied with the yellow text below:

Yes it is.

As far as MAME is concerned, the 1 key is mapped to the START1 "event", it will ignore the fact that 1 is also mapped to "P1_BUTTON10"
As far as Johnny5 is concerned, it will see that P1_BUTTON10 is mapped to the 1 key and that it has a label for KEYCODE_1 so it will display the P1_BUTTON10 entry in the KEYCODE_1 label.

Finally Howard Casto (aqua text) and papaschtroumpf (yellow text) had the following discussion.  I don't completely follow it, but you can make Johnny5 work with the infomation provided so far, but I thought it might be helpful:

I just want to clarify some things:

I made Johnny5 as generic as possible because I had always planned on expanding it for other uses.  Johnny5 is a data translator, with a very few exceptions, there are no constants in Johnny5 that prevent you from "making" other physical inputs.  The list of possible inputs are stored and read from a simple text file and it looks for those inputs in the ini cfg/etc files.  It doesn't look to see if they are valid, nor does it care.  A search string is a search string.

I did this because MAME also supports "non-MAME" inputs.  MAME outputs these extra controls on a joystick/keyboard as whatever the Windows driver labels them.  Since I have no way of knowing every possible input every odd-ball joystick puts out, this had to be done.

To officially add these labels to the layout viewer simply open up the "keycode constants.txt" in the data files folder and add them at the bottom. (I would suggest adding a nice header like "PC Inputs Only:")  This is also how you add static labels btw, just remember to put a "*" first in the case of static labels.

I tried to add "START1=test" in controls.ini since START1 is one of the official MAME controls defined in my CTRLR file for MAME.  More exactly, it is defined as KEYCODE_1 or KEYCODE_ENTER.  I think the default for MAME is just KEYCODE_1 but I have it set up as ENTER in my keyboard encoder, because ENTER is commonly needed in PC Games, especially for menu selections, which makes it fitting to be mapped to START1.

I added a KEYCODE_ENTER label in my layout, expecting it to show up in the generated picture but it didn't work.
I tried to run Johnny5 with the -debug option and saw nothing in the debug window that referenced looking for START1.

What am I missing?

It's quite simple really.....  Do you have START defined as Enter anywhere in MAME?  I talked about adding more physical inputs, not virtual ones.  Since none of your MAME mappings have Start1 mapped to Enter, it has no way of knowing that you use Start1 as Enter.  And of course, Start1 has to be somewhere in the p1controltype string setup properly in the format.  Viewers know which labels to read from an entry by the controltype entry at the beginning.

I don't understand what this means, so maybe it's the problem, but I can't fix it until I know what you mean.  Where is the "p1controltype" string?

In the controls.ini of course.....  (P1Controls= )

This entry is always read first and tells the viewer how many and what kinds of virtual inputs this game uses.  If the MAME constant of a label description isn't included, it never gets read.

To add a "virtual" control you have to have three things:

A label description in the controls.ini (P1Start=Start)

A Virtual/Physical link tacked onto the control type string (|Player 1 Start+P1Start)

A cfg/ctrlr/Std.ini entry that defines said virtual keys MAME constant to a physical keyboard key (P1Start=KEYCODE_ENTER)

Please note that I have no clue if P1Start is a real constant, I'm just using it as an example.

Also note that it doesn't have to be a real MAME constant, it just has to be in the same name in the cfgs  and both places in the controls.ini.  And of course it has to have a real key assigned to it in said MAME cfgs.

The easiest way to add "fake" virtual inputs is to define a bunch in your std.ini which may or may not be in your current MAME build, but will be read by the viewer if you include one.

Cool, thanks the the explanation.  I may handle it that way since it seems cleaner that my "P1_BUTTON10..." hack.

Heh, I think you are confused......

Buttons are a special case.

Since adding 1-button1..etc to the p1controls string would be excessively long, those are assumed.  (Unless the game only uses buttons, but that's another story)

In each entry there is a "NumberofButtons" entry.  The viewer just reads how many buttons are counted and automatically knows the keys to search for (P#Button#=)

Now again, some physical key has to be defined to that virtual key somewhere in your MAME cfgs, but you never have to worry about it being added somewhere, just make sure your NumberofButtons Entry matches. 

Yes, I actually figured out how that part worked (thanks to the -debug option), which is why I was able to add extra buttons that are defined in the MAME CTRLR file but not really used for MAME (I don't play any 10 button games.)

At this point, Johnny5 should be working well.

CPVIEWER/CPVW CONCEPTS

NOTE:  The information below in yellow was provided by papaschtroumpf:

The same basic idea works with CPViewer: either add entries at the end of controls.ini or create a new directory with a PCgames specific controls.ini and fill in game entries as with Johnny5. Note however that the P1NumButtons is not really used in CPViewer.

Again, the entries in blue show the "regular" mame buttons.

Things are handled differently in CPViewer/CPVW: the program doesn't try to be so intelligent of mapping entries in your CTRLR file to your layout file the way Johnny5 does.  Instead it directly matches entry names in controls.ini to a label name in your layout.  Basically if you have a label for "P1_BUTTON1", it looks for a corresponding "P1_BUTTON1" label in controls.ini.  By default, it will also attach the same value to the "P2_BUTTON1" in your layout if you have added that label.

The "trick" to use here is that you can override P2_BUTTON? entries so that they don't match the corresponding P1_BUTTON entries.

For example, if you mapped additional PC game controls to your P2 entries (I'm assuming the PC game is single player in this example), then you can just add them in by specifying their P2_BUTTON? equivalent:

P2_BUTTON1=Cockpit Cam
P2_BUTTON2=Tail Cam
P2_BUTTON3=Wing Cam
P2_BUTTON4=Wide view
P2_BUTTON5=Zoom in
P2_BUTTON6=Zoom out

Now you may have mapped some controls to "admin" buttons on your control panel. For example, let's say that in addition to your 2 buttons per players, you also have a player 1 start (mapped to "1"), player 2 start (mapped to "2"), pause (mapped to "P"), mame menu (mapped to TAB).
Your PC game may have something mapped to the 1, 2, and TAB key, so you want to label them in CPViewer.

If you have set up your CP for MAME, then you have told CPViewer to create labels for P1_BUTTON1..P1_BUTTON6 and P2_BUTTON1..P2_BUTTON6. Since CPViewer lets you define up to 8 buttons per player, you have 4 spares (2 on player 1 and 2 on player 2)

Since CPViewer doesn't really care what your buttons are, you can put a P1_BUTTON7 label under your player start1, a P1_BUTTON8 under your player 2 start, P2_BUTTON7 under the MAME menu/tab button, etc...

Assuming that key "1" and "2" in your PC game are mapped to "easy" and "difficult" and TAB is used for "quicksave", you can add the following to the game's entry in controls.ini:

P1_BUTTON7=Easy
P1_BUTTON8=Difficult
P2_BUTTON7=QuickSave

Your final controls.ini then looks like this:

Again, the entries in blue show the "regular" mame buttons, the entries in  yellow show the modified Player 2 Button entries, and the entries in  red show the "spare" buttons.

You are limited to a total of 16 mappable buttons; however, which may or may not be a limiting factor depending on how complex your control panel is.  In my case, I have a single player cabinet with P1_Buttons only, so I have 10 spares that I can use.

The other thing to be aware of is that if you use that same layout for MAME, you may have buttons mislabelled, for example the P1_BUTTON7 text would show under your player 1 start with the example above, even though pressing that button would not act as the player's 7th button.  This can be solved by using a different layout for MAME and PC Games.  Maybe future versions of CPViewer coud add "custom" buttons to the list in addition to the 1-8 P1 and P2 buttons.

JCrouse from BYOAC posted the green text below and  papaschtroumpf replied with the yellow text:

I have made contact with the CPVW author and we are planning on some changes.  For starters, adding P3 and P4 buttons.  We will also probably make about 12 labels per user AND a generic set of labels, probably eight or ten, that you can use as you want.  I will make a special layout designer specifically for the application to rid out the massive overhead of CPViewer.  The designer will still require the .NET framework.  However, you could create the layout by hand.  I did that over the weekend.

Also, for some reason CPVW, as it is now, needs the alternating field and it must be set to either one or two.  I'm not sure why but that seems to be the way it is.

I'll post more news as it materializes.

I'm not at home right now so I can't check, but I don't think it had anything special to do with the "alternating=" line, even though I saw your comment in your e-mail. My cab is an upright, is yours a cocktail?  Could that be why alternating seems to matter for you but not me?  I'm not quite sure what the viewer setup wizard does under the hood, but cabinet style and orientation does seem to matter a lot.

Edit: the additional buttons sound great!

EMULOADER INTEGRATION

EmuLoader supports batch files directly starting with version 4.7 or above.  The text below is written for EmuLoader 4.7.4 (16Oct05).  I will cover Z26, MESS (for the Atari 2600, and ZSNES examples, because these are what I have used before, and I won't cover launching AHK with them, but if you follow these examples and the previous pages, setup should be fairly straight-forward.

EmuLoader officially supports five emulators:  MAME, Zinc, Daphne, AgeMAME, and PinMAME (not Visual Pinball).  Usage with other programs is not supported and frankly, Ciro (the EmuLoader author) highly discourages it and will not offer support for it.  Ciro has graciously given me permission to document the available methods here, but I must request that you honor his wishes and not submit E-mails to him or post questions regarding this on the EmuLoader forum.  If you run into a particularly difficult problem, contact me and I will do my best to sort it out.

Having said that, EmuLoader is a very robust program and can handle most of the challenges required, although the implementation (manually adding games) may be cumbersome.

NOTE:  It is probably possible to get Visual Pinball working in EmuLoader using the methods below, the information on this page, and possibly Howard Casto's wrappers.

The text below is arranged to give you a view of the processes involved before you start making changes and then have to re-do your work.  I highly recommend reading this entire section before attempting anything!

Also, if you are just wanting this method for console emulation, Ciro has another frontend, Emucon Playground, which has many of the features on EmuLoader as well as auto-generation of game lists, although I don't know if it is up to calling batch files instead of the direct emulator, etc.  The program is currently being re-written, but should be back on a subpage of EmuLoader's Homepage.

MAMEWAH INTEGRATION

Unfortunately, I am not very familiar with MAMEwah.  I have set it up and used it previously, but it is not my frontend of choice (no offense to it or MinWah), so I am not very familiar with it.  The information in yellow below was provided by papaschtroumpf from BYOAC and my reply is in white:  

There is one issue that I haven't solved yet, and that's why I don't consider this a full solution yet: the game "rom" name should not contain any spaces:

I use MAMEwah and have it setup to show the link name in the rom list, so I have a game called "Tower of the Ancients.lnk" so MAMEwah passes "Tower of the Ancients" to Johnny5 as the ROM name, but then Johnny5 only looks for a ROM named "tower".

One way to deal with it is to make an entry in the controls.ini with a rom name of [tower] and a game name of "Tower of the Ancients". This will work as long as you don't have another game that also starts with the name tower.  If you have both "Tower of the Ancients" and "Tower of Doom" then this trick won't work.

Another way to deal with it would be to replace the spaces in the name with underlines.  This would however cause mamewah to show the game in the game list as "Tower_of_the_Ancients" which is not too bad but not really what we want.

I know mamewah has a {8.3} tag for the command line, but I haven't explored what it does.  If it takes a full name and turns it into a unique 8.3 name, we might be able to use that.

You could also do:
Tower of the ancients.lnk
Tower1 of Doom.lnk
Tower2 of Power.lnk
Tower3 Trouble.lnk

but that's not perfect either. . .

OTHER FRONTENDS

Unfortunately, I don't have much info on setup with other frontends.

CONCLUSION

Well, that's about all I have to say.  Hopefully this page was helpful for you.  If you see anything major that I got wrong, know of a better way to do this, or if you just can't get it to work, shoot me an E-mail and I will either fix the page or try to help you out.

Document made with Nvu