Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news


  

Author Topic: MAME Lua Autofire Plugin  (Read 540 times)

0 Members and 1 Guest are viewing this topic.

tj0390

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 4
  • I want to build my own arcade controls!
MAME Lua Autofire Plugin
« on: August 20, 2017, 03:59:32 pm »
I got tired of having to turn on autofire for my 3 year old every time so I decided to try to make a plugin. I am a DBA by trade so my coding is fairly weak. Below is my script. It seems close but does not work. I can actually get it to autofire without holding the button but not while holding it. I did not see anywhere in the API to set the autofire setting in MAME. If I missed this option I wasted some time. Any help is greatly appreciated. One additional question I tried the following, key = manager:machine():input():code_from_token("KEYCODE_LCONTROL"), but it returns nil. It looks correct to me though.

local button
local counter
local state

counter = 1

for tag, port in pairs(manager:machine():ioport().ports) do
   if port.fields["P1 Button 1"] then
      button = {port = port, field = port.fields["P1 Button 1"]} --TODO move this to config file
   end
end

local function press()
   button.field:set_value(1)
end

local function unpress()
   button.field:set_value(0)
end

local function check()
   state = ((button.port:read() & button.field.mask) ~ button.field.defvalue) --Gets current state of button pressed or released

   if state == 1 and counter % 3 == 0 then
      unpress() --if the button is pressed and it is every third frame release button
   else
      counter = counter + 1
      return
   end

end


emu.register_frame(check)

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 6433
  • 2013 UCA Awardee
Re: MAME Lua Autofire Plugin
« Reply #1 on: August 20, 2017, 04:21:41 pm »
I got tired of having to turn on autofire for my 3 year old every time so I decided to try to make a plugin. I am a DBA by trade so my coding is fairly weak. Below is my script. It seems close but does not work. I can actually get it to autofire without holding the button but not while holding it. I did not see anywhere in the API to set the autofire setting in MAME. If I missed this option I wasted some time. Any help is greatly appreciated. One additional question I tried the following, key = manager:machine():input():code_from_token("KEYCODE_LCONTROL"), but it returns nil. It looks correct to me though.
Code: [Select]
local button
local counter
local state

counter = 1

for tag, port in pairs(manager:machine():ioport().ports) do
if port.fields["P1 Button 1"] then
button = {port = port, field = port.fields["P1 Button 1"]} --TODO move this to config file
end
end

local function press()
button.field:set_value(1)
end

local function unpress()
button.field:set_value(0)
end

local function check()
state = ((button.port:read() & button.field.mask) ~ button.field.defvalue) --Gets current state of button pressed or released

if state == 1 and counter % 3 == 0 then
unpress() --if the button is pressed and it is every third frame release button
else
counter = counter + 1
return
end

end


emu.register_frame(check)
For future reference, you may want to use the icon to insert code tags since some font colors like beige are hard to read in some themes or on odd-numbered replies like this one.   :cheers:


Scott
« Last Edit: August 20, 2017, 04:26:30 pm by PL1 »

tj0390

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 4
  • I want to build my own arcade controls!
Re: MAME Lua Autofire Plugin
« Reply #2 on: August 21, 2017, 04:40:17 pm »
Thanks for the tip. I have lurked on here but never posted before.

crazyc

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 10
  • I want to build my own arcade controls!
Re: MAME Lua Autofire Plugin
« Reply #3 on: August 23, 2017, 05:22:46 pm »
There isn't any way to enable the builtin autofire from lua but your code is as you guessed is close to a native lua implementation.  The problem is that pressing the button overrides any set_value from lua.  Making a key for autofire is the way to get around it and what you have "key = manager:machine():input():code_from_token("KEYCODE_LCONTROL")" is correct and works for me.  I'd guess that you aren't using 0.188 which is the first version with that API.

tj0390

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 4
  • I want to build my own arcade controls!
Re: MAME Lua Autofire Plugin
« Reply #4 on: August 24, 2017, 09:47:18 am »
There isn't any way to enable the builtin autofire from lua but your code is as you guessed is close to a native lua implementation.  The problem is that pressing the button overrides any set_value from lua.  Making a key for autofire is the way to get around it and what you have "key = manager:machine():input():code_from_token("KEYCODE_LCONTROL")" is correct and works for me.  I'd guess that you aren't using 0.188 which is the first version with that API.

Thanks Crazy. That was exactly it, I was using .183. I think this will get me there. If I get the plugin working and polished I will post it here. Thanks again for the help I feel dumb now, I had been wracking my brain on that one.

tj0390

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 4
  • I want to build my own arcade controls!
Re: MAME Lua Autofire Plugin
« Reply #5 on: September 06, 2017, 12:59:23 am »
I got my plugin working. I attached the files if anyone wants to look or use it. The code is probably a little janky and could use some polish. I am pretty close to having Joy and button sequences working as well, so I can throw a SHORYUKEN with a single button push. If I get motivated and anyone is interested I will post it. Thanks again Crazy for the help.

  
 

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31