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