Build Your Own Arcade Controls Forum
Main => Software Forum => Topic started by: oomek 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
{
"plugin": {
"name": "defender",
"description": "Defender 8-way Control",
"version": "0.0.1",
"author": "Radek Dutkiewicz",
"type": "plugin",
"start": "false"
}
}
init.lua
-- 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
-
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.