|
|
> > > > Since JOYSTICK_DOWN is in IN1, separate from the other three in IN2, I can't fully > > > > animate the upright 8-way stick? (Though I could still do the cocktail > version?). > > > > > > It can be done with Lua script, but not without. Remind me to show you how to do this > > > one after MAME 0.227 is released (layout scripting is going to change substantially > > > for MAME 0.227). > > > > I got all of my files updated with working ball joysticks, but a few still don't > > fully work because of this. Just a prayer for the MAME gods to save us again. > > This should be in 0.227. Vas posted documentation here: > > https://docs.mamedev.org/techspecs/layout_script.html > > The only "extra" on here, is that you can't simply run a game with default > settings... you need to run it with the extra parameters to get the animation. If I'm > reading everything right, you can still run the game with regular artwork, but you > will get a warning that if the view you choose requires the plugin, and it is not > used, then that view will not work?
Yeah, the layout plugin has to be enabled for scripts in layouts to work. The view will still work without the layout plugin, but the joystick won’t visibly move on the screen.
I put the warning message in so the user will know they’re missing something if the plugin isn’t enabled. The cheat, autofire and data plugins are pretty popular, so people should know how to enable plugins in mame.ini by now.
> He uses Espial as an example on that page, so you should be able to copy/paste that > to see it working (I haven't had time to play with it yet).
Complete scripted Espial artwork zip attached here, including the SVG graphics for the joysticks.
Let’s look at the bit manipulation code in a bit more detail. Here are the input ports for reference:
Code:
PORT_START("IN1") PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_START1 ) PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_START2 ) PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_COCKTAIL PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_COCKTAIL PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_8WAY PORT_COCKTAIL PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_COCKTAIL PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_COCKTAIL
PORT_START("IN2") PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNKNOWN ) PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNKNOWN ) PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_8WAY PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_COCKTAIL PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_8WAY
But for simplicity, we want to rearrange the bits for both joysticks so they effectively look like this for each of the joysticks:
Code:
PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_8WAY PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_8WAY
We want the bits to be organised like this, from most significant to least significant (“.” represents an unused bit):
Code:
....RLDU
Let’s look at where the bits are for the first joystick (“.” represents a bit that isn’t used for this joystick):
Code:
IN1: ..D..... IN2: L..UR...
- Up is in IN2, and it’s four positions to the left of were we want it. We’ll need to shift it to the right by four positions.
- Down is in IN2 and it’s also four positions to the left of where we want it, so we’ll need to shift it to the right by four positions as well.
- Left is in IN2 and needs to be shifted to the right by five positions to get it to the correct place.
- Right is in IN2, and already in the position we want, so it won’t need to be shifted.
Here’s the code that shuffles the bits for the first joystick:
Code:
p1_stick:set_state( ((in2_val & 0x10) >> 4) | -- shift up from IN2 bit 4 to bit 0 ((in1_val & 0x20) >> 4) | -- shift down from IN1 bit 5 to bit 1 ((in2_val & 0x80) >> 5) | -- shift left from IN2 bit 7 to bit 2 (in2_val & 0x08)) -- right is in IN2 bit 3
We isolate the bit for each direction using “&”, which is the bitwise and operator, and shift them as necessary with “>>”, the right shift operator (if we needed to shift to the left, we’d use “<<”, the left shift operator). We combine the bits with “|”, the bitwise or operator.
Now we’ll look at where the bits are for the second joystick:
Code:
IN1: .D.URL..
- Up is in IN1, and it’s four positions to the left of were we want it. We’ll need to shift it to the right by four positions.
- Down is in IN1 and it’s five positions to the left of where we want it, so we’ll need to shift it to the right by five positions.
- Left is in IN1 and is is already in the position we want.
- Right is in IN1, and also in the desired position.
The code to shuffle the bits here should be easy enough to understand now:
Code:
p2_stick:set_state( ((in1_val & 0x10) >> 4) | -- shift up from IN1 bit 4 to bit 0 ((in1_val & 0x40) >> 5) | -- shift down from IN1 bit 6 to bit 1 (in1_val & 0x04) | -- left is in IN1 bit 2 (in1_val & 0x08)) -- right is in IN1 bit 3
|
|