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
Lightguns Arcade1Up Try the site in https mode Site News

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

  

Author Topic: MAME LUA - Defender 8-way control Plugin  (Read 3090 times)

0 Members and 1 Guest are viewing this topic.

oomek

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 268
  • Last login:December 08, 2023, 02:31:38 pm
  • Mame forever.
    • https://github.com/oomek
MAME LUA - Defender 8-way control Plugin
« on: September 05, 2020, 06:56:23 am »
Hi, I've always wanted to write a plugin that would allow 8-way control in defender. I know there are modified versions of mame floating around, but I needed something universal. Here is the script I wrote. It works, but only with a keyboard. I'm struggling with finding a way of fetching default "P1 Left" and "P1 Right" mapped controls when the game does not have it in fields. In defender only "P1 Up" and "P1 Down" are available. Any ideas how to make it work with the bindings set by the user in Input(general) ?

plugin.json
Code: [Select]
{
  "plugin": {
"name": "defender",
"description": "Defender 8-way Control",
"version": "0.0.1",
"author": "Radek Dutkiewicz",
"type": "plugin",
"start": "false"
  }
}

init.lua
Code: [Select]
-- license:BSD-3-Clause
-- copyright-holders:Radek Dutkiewicz
local exports = {}
exports.name = 'defender'
exports.version = '0.0.1'
exports.description = 'Defender 8-way Control'
exports.license = 'The BSD 3-Clause License'
exports.author = { name = 'Radek Dutkiewicz' }

local defender = exports

function defender.startplugin()

local inp = {}
local ui = {}
local registered = false
local btn_thrust

local function process_frame()
if inp:code_pressed(inp:code_from_token("KEYCODE_LEFT")) then
manager:machine().devices[":maincpu"].spaces["program"]:write_direct_u8(0xA0BB, 0xFD)
btn_thrust.field:set_value(1)
elseif inp:code_pressed(inp:code_from_token("KEYCODE_RIGHT")) then
manager:machine().devices[":maincpu"].spaces["program"]:write_direct_u8(0xA0BB, 0x03)
btn_thrust.field:set_value(1)
else
btn_thrust.field:set_value(0)
end
end

local function load_settings()
if not registered then
if emu.romname() == "defender" then
inp = manager:machine():input()
ui = manager:machine():uiinput()
print("defender")
for tag, port in pairs(manager:machine():ioport().ports) do
if port.fields["Thrust"] then
print("btn_thrust")
btn_thrust = {port = port, field = port.fields["Thrust"]}
end
end
emu.register_frame_done(process_frame)
registered = true
end
end
end

emu.register_start(load_settings)
end

return exports

« Last Edit: September 15, 2020, 08:31:02 pm by oomek »

oomek

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 268
  • Last login:December 08, 2023, 02:31:38 pm
  • Mame forever.
    • https://github.com/oomek
Re: MAME LUA - Defender 8-way control Plugin
« Reply #1 on: September 15, 2020, 08:22:09 pm »
After posting a question on mamedev on GitHub it turned out an unuversal, not hardcoded control was not possible, but a kind dev added it, so it will hopefuly be implemented in the next mame release. I'm gonna update the plugin once it's done, so there will be possibility to use keyboard, joystick, or whatever was mapped to P1 Left/Right in Input(General) in mame settings.