The Dragon King
Mame Hooker: Creating a User-Navigable Display Card System 
About Mame Hooker Overview:

In our last tutorial, I showed you how to automatically display a marquee for each game on your secondary monitor. This looks nice, but isn't particularly useful. Wouldn't it be nice if we could display a menu with game info that the user could navigate through while playing? While it takes a bit of effort, this is possible using the current system.

For our example we are going to add a "cards" sytem that allows you to cycle through a collection of images for each game. I've included some card packs for Mortal Kombat II and UMK3 here. DO NOT install it yet... let's explain how it works first.

First off let's look at the display file included in the displays/cards folder:

[Layout]
NumberofImages=4

[Image1]
x=0
y=0
height=1
width=1
length=25
image=%mamepath%cards\%rpd%\card#.jpg
keepaspect=1

[Image2]
x=0
y=0
height=1
width=0.5
length=25
image=%mamepath%cards\%rpd%\card#.jpg
keepaspect=1

[Image3]
x=.5001
y=0
height=1
width=0.5
length=25
image=%mamepath%cards\%rpd%\card#.jpg
keepaspect=1

[Image4]
x=0
y=0
height=1
width=1
length=1
image=%mamepath%marquees\%rpd%.png
keepaspect=1

It isn't nearly as complex as it appears. You've got 4 images. The last image, on the bottom, displays a marquee from the game. In addition you've got two small images, each taking half of the screen and one large image that takes up the whole screen, all three displaying the card packs. Why three identical images? Because we want to make something fancy. When only one player is navigating the cards the cards will take up the whole screen, but if a second player looks through the cards, each player gets to see their own card selection, which takes up half the screen.

So no cards look like this:

P1 Navigating looks like this:

And Both Players Navigating Looks like this:

Now that we've gone over the layout, we need to actually control the thing. In the included package, in the ini folder, load up the default.ini in notepad so we can go over it.

[General]
MameStart=lds cards,sbf 1 1

[KeyStates]
RefreshTime=66
PAGE UP=nll y|sds 1 -%b1%,sds 2 -1
PAGE DOWN=nll y|sds 1 +%b1%,sds 2 +1
SUBTRACT=nll y|sds 3 -1,sbf 1 0, sds 1 0
ADD=nll y|sds 3 +1,sbf 1 0, sds 1 0

There are a lot of new concepts here, so we'll go over them one at a time. First off, sbf is the "set buffer" function. Mamehooker has 10 variables or "buffers" available to the user that can store any numeric or text data you choose. In this case we are mainly using buffer 1 to keep track of if the display file is in 2 player mode or not. Also notice we are using the keystates section instead of the output section. Mamehooker can track the state of keystates if you so choose and treat them as outputs. Finally the "nll" command does nothing... it's just a placeholder. Since we don't want to do anything when the key is released, we use a nll command to make a dummy function.

Ok first off remember what our Display file is like. We've got 4 images, the marquee on the bottom (image 4), two small player 1 and player 2 cards (images 2 and 3) and a larger player 1 card that covers it all.(image 1) Player 1's navigation is controlled via the page keys, player 2's navigation is controlled via the add and subtract keys. When only player one keys are used, they control the large player 1 card that covers everything, but if the player 2 keys are pressed, with reverts to the two smaller cards, one for each player. If no cards are found, the marquee is displayed.

Now it's just a matter of explaining what all this code does. Yes congratulations, this sort of scripting is less like binding functions and more like code. How does this work? Well, when Mame starts we set buffer 1 to 1. Why? Well notice the manipulation of the two player 1 images. The large, 1 player only image doesn't plus or minus the image position by 1, but rather by the value of buffer 1. If buffer 1 is set to 0 (which it IS when player two controls are used) then that image doesn't get changed. Also note that any time player two navigation keys are used, it also sets image 1's navigation position to 0, so it makes it invisible, and un-navigable. Now when player 1 isn't the only one moving through the cards, his smaller card image is also being maniplulated. We could script to change this, but the larger image is in the foreground, so you can't see it anyway. Other than that, the code is pretty straight forward. The keys simply change the display number to move through the cards.

You should have a general understanding of how to do this sort of advanced scripting by now. To install you want to put the various files and folder where instructed. Have fun making card packs!