summaryrefslogtreecommitdiffstatshomepage
path: root/plugins/cheat
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2020-12-27 01:32:37 +1100
committer Vas Crabb <vas@vastheman.com>2020-12-27 01:32:37 +1100
commit9e36b6a6d951ea6f2d72cab874c3c8e72d001001 (patch)
treec41bfd0c1b499d790c4091eb266caf6955219fc1 /plugins/cheat
parent509c946736b5f02cac84d19f2cde4e966d637a2c (diff)
More Lua interface cleanup - it's simpler with cleaner underlyng APIs.
Made the sound manager mute controls readable, and got rid of system enable since it just controls system mute anyway. This was causing confusion: phantom2 was trying to use both independentlyt casuing the mute bit to be ignored. THe Lua interface changes are mostly changing methods to properties, some renames to make things clearer, and some additional properties for better control over snapshots.
Diffstat (limited to 'plugins/cheat')
-rw-r--r--plugins/cheat/cheat_simple.lua8
-rw-r--r--plugins/cheat/cheat_xml.lua2
-rw-r--r--plugins/cheat/init.lua88
3 files changed, 49 insertions, 49 deletions
diff --git a/plugins/cheat/cheat_simple.lua b/plugins/cheat/cheat_simple.lua
index 9640cf22bc6..f65cc9e46b7 100644
--- a/plugins/cheat/cheat_simple.lua
+++ b/plugins/cheat/cheat_simple.lua
@@ -48,7 +48,7 @@ local function prepare_rom_cheat(desc, region, addr, val, size, banksize, comp)
end
if banksize and comp then
- local rom = manager:machine():memory().regions[region]
+ local rom = manager.machine.memory.regions[region]
local bankaddr = addr & (banksize - 1)
addr = nil
if not rom then
@@ -92,7 +92,7 @@ function codefuncs.nes_gg(desc, code)
if #code == 6 then
addr = ((value >> 4) & 7) | ((value >> 8) & 0x78) | ((value >> 12) & 0x80) | ((value << 8) & 0x700) | ((value << 4) & 0x7800)
newval = ((value >> 20) & 7) | (value & 8) | ((value >> 12) & 0x70) | ((value >> 16) & 0x80)
- if manager:machine():memory().regions[":nes_slot:cart:prg_rom"].size > 32768 then
+ if manager.machine.memory.regions[":nes_slot:cart:prg_rom"].size > 32768 then
emu.print_verbose("warning: gamegenie 6 char code with banked rom " .. desc)
end
return prepare_rom_cheat(desc, ":nes_slot:cart:prg_rom", addr, newval, 8)
@@ -130,7 +130,7 @@ local function snes_prepare_cheat(desc, addr, val)
if ((bank <= 0x3f) and (offset < 0x2000)) or ((bank & 0xfe) == 0x7e) then
return prepare_ram_cheat(desc, ":maincpu", addr, val, 8)
end
- if (manager:machine().devices[":maincpu"].spaces["program"]:read_u8(0xffd5) & 1) == 1 then --hirom
+ if (manager.machine.devices[":maincpu"].spaces["program"]:read_u8(0xffd5) & 1) == 1 then --hirom
if (bank & 0x7f) <= 0x3f and offset >= 0x8000 then
-- direct map
elseif (bank & 0x7f) >= 0x40 and (bank & 0x7f) <= 0x7d then
@@ -309,7 +309,7 @@ function simple.conv_cheat(data)
end
offset = tonumber(offset, 16)
val = tonumber(val, 16)
- if manager:machine().devices[cputag] then
+ if manager.machine.devices[cputag] then
cheat = prepare_ram_cheat(desc, cputag, offset, val, size)
else
cheat = prepare_rom_cheat(desc, cputag, offset, val, size)
diff --git a/plugins/cheat/cheat_xml.lua b/plugins/cheat/cheat_xml.lua
index d5cee8ac2a2..d9032814f30 100644
--- a/plugins/cheat/cheat_xml.lua
+++ b/plugins/cheat/cheat_xml.lua
@@ -59,7 +59,7 @@ function xml.conv_cheat(data)
data = xml_parse(data)
local cpu_spaces = {}
- for tag, device in pairs(manager:machine().devices) do
+ for tag, device in pairs(manager.machine.devices) do
local sp
for name, space in pairs(device.spaces) do
if not sp then
diff --git a/plugins/cheat/init.lua b/plugins/cheat/init.lua
index 83dbdc7bfb1..46a086f8ac2 100644
--- a/plugins/cheat/init.lua
+++ b/plugins/cheat/init.lua
@@ -94,12 +94,12 @@ function cheat.startplugin()
local function load_cheats()
local filename = emu.romname()
local newcheats = {}
- local file = emu.file(manager:machine():options().entries.cheatpath:value():gsub("([^;]+)", "%1;%1/cheat") , 1)
+ local file = emu.file(manager.machine.options.entries.cheatpath:value():gsub("([^;]+)", "%1;%1/cheat") , 1)
if emu.softname() ~= "" then
if emu.softname():find(":") then
filename = emu.softname():gsub(":", "/")
else
- for name, image in pairs(manager:machine().images) do
+ for name, image in pairs(manager.machine.images) do
if image:exists() and image:software_list_name() ~= "" then
filename = image:software_list_name() .. "/" .. emu.softname()
end
@@ -134,7 +134,7 @@ function cheat.startplugin()
local function load_hotkeys()
local json = require("json")
- local file = io.open(emu.subst_env(manager:machine():options().entries.cheatpath:value():match("([^;]+)")) .. "/" .. cheatname .. "_hotkeys.json", "r")
+ local file = io.open(emu.subst_env(manager.machine.options.entries.cheatpath:value():match("([^;]+)")) .. "/" .. cheatname .. "_hotkeys.json", "r")
if not file then
return
end
@@ -142,7 +142,7 @@ function cheat.startplugin()
for num, val in ipairs(hotkeys) do
for num, cheat in pairs(cheats) do
if val.desc == cheat.desc then
- cheat.hotkeys = {pressed = false, keys = manager:machine():input():seq_from_tokens(val.keys)}
+ cheat.hotkeys = {pressed = false, keys = manager.machine.input:seq_from_tokens(val.keys)}
end
end
end
@@ -152,7 +152,7 @@ function cheat.startplugin()
local hotkeys = {}
for num, cheat in ipairs(cheats) do
if cheat.hotkeys then
- local hotkey = {desc = cheat.desc, keys = manager:machine():input():seq_to_tokens(cheat.hotkeys.keys)}
+ local hotkey = {desc = cheat.desc, keys = manager.machine.input:seq_to_tokens(cheat.hotkeys.keys)}
if hotkey.keys ~= "" then
hotkeys[#hotkeys + 1] = hotkey
end
@@ -160,7 +160,7 @@ function cheat.startplugin()
end
if #hotkeys > 0 then
local json = require("json")
- local path = emu.subst_env(manager:machine():options().entries.cheatpath:value():match("([^;]+)"))
+ local path = emu.subst_env(manager.machine.options.entries.cheatpath:value():match("([^;]+)"))
local attr = lfs.attributes(path)
if not attr then
lfs.mkdir(path)
@@ -215,7 +215,7 @@ function cheat.startplugin()
return
end
if type(x) == "string" then
- y = y * mame_manager:ui():get_line_height()
+ y = y * mame_manager.ui.line_height
end
output[#output + 1] = { type = "text", scr = screen, x = x, y = y, str = str, color = color }
end
@@ -278,13 +278,13 @@ function cheat.startplugin()
run_if(wp.cheat, wp.func)
-- go in case a debugger other than "none" is enabled
-- don't use an b/wpset action because that will supress the b/wp index
- manager:machine():debugger().execution_state = "run"
+ manager.machine.debugger.execution_state = "run"
end
else
local bp = breaks[point]
if bp then
run_if(bp.cheat, bp.func)
- manager:machine():debugger().execution_state = "run"
+ manager.machine.debugger.execution_state = "run"
end
end
end
@@ -313,7 +313,7 @@ function cheat.startplugin()
end
local function bwpclr(cheat)
- if not manager:machine():debugger() then
+ if not manager.machine.debugger then
return
end
for num, bp in pairs(breaks) do
@@ -340,7 +340,7 @@ function cheat.startplugin()
if entry.port:sub(1, 1) ~= ":" then
entry.port = ":" .. entry.port
end
- local port = manager:machine():ioport().ports[entry.port]
+ local port = manager.machine.ioport.ports[entry.port]
if not port then
errout(entry.port, entry.field)
end
@@ -372,7 +372,7 @@ function cheat.startplugin()
error("input_run only allowed in one shot cheats")
return
end
- local _, screen = next(manager:machine().screens)
+ local _, screen = next(manager.machine.screens)
list.begin = screen:frame_number()
inputs[#inputs + 1] = list
end
@@ -451,7 +451,7 @@ function cheat.startplugin()
frombcd = frombcd,
pairs = pairs,
ipairs = ipairs,
- outputs = manager:machine():outputs(),
+ outputs = manager.machine.output,
time = time,
input_trans = input_trans,
input_run = function(list) input_run(cheat, list) end,
@@ -483,8 +483,8 @@ function cheat.startplugin()
if cheat.cpu then
cheat.cpudev = {}
for name, tag in pairs(cheat.cpu) do
- if manager:machine():debugger() then
- local dev = manager:machine().devices[tag]
+ if manager.machine.debugger then
+ local dev = manager.machine.devices[tag]
if not dev or not dev.debug then
cheat_error(cheat, "missing or invalid device " .. tag)
return
@@ -505,7 +505,7 @@ function cheat.startplugin()
if cheat.space then
for name, space in pairs(cheat.space) do
local cpu, mem
- cpu = manager:machine().devices[space.tag]
+ cpu = manager.machine.devices[space.tag]
if not cpu then
cheat_error(cheat, "missing device " .. space.tag)
return
@@ -525,17 +525,17 @@ function cheat.startplugin()
end
if cheat.screen then
for name, screen in pairs(cheat.screen) do
- local scr = manager:machine().screens[screen]
+ local scr = manager.machine.screens[screen]
if not scr then
local tag
- tag, scr = next(manager:machine().screens) -- get any screen
+ tag, scr = next(manager.machine.screens) -- get any screen
end
cheat.cheat_env[name] = scr
end
end
if cheat.region then
for name, region in pairs(cheat.region) do
- local mem = manager:machine():memory().regions[region]
+ local mem = manager.machine.memory.regions[region]
if not mem then
cheat_error(cheat, "missing region " .. region)
return
@@ -545,7 +545,7 @@ function cheat.startplugin()
end
if cheat.ram then
for name, tag in pairs(cheat.ram) do
- local ram = manager:machine().devices[tag]
+ local ram = manager.machine.devices[tag]
if not ram then
cheat_error(cheat, "missing ram device " .. tag)
return
@@ -555,7 +555,7 @@ function cheat.startplugin()
end
if cheat.share then
for name, tag in pairs(cheat.share) do
- local share = manager:machine():memory().shares[tag]
+ local share = manager.machine.memory.shares[tag]
if not share then
cheat_error(cheat, "missing share " .. share)
return
@@ -615,36 +615,36 @@ function cheat.startplugin()
return
end
- local input = manager:machine():input()
+ local input = manager.machine.input
local poller = input:switch_sequence_poller()
- manager:machine():popmessage(_("Press button for hotkey or wait to leave unchanged"))
- manager:machine():video():frame_update(true)
+ manager.machine:popmessage(_("Press button for hotkey or wait to leave unchanged"))
+ manager.machine.video:frame_update()
poller:start()
local time = os.clock()
local clearmsg = true
while (not poller:poll()) and (poller.modified or (os.clock() < time + 1)) do
if poller.modified then
if not poller.valid then
- manager:machine():popmessage(_("Invalid sequence entered"))
+ manager.machine:popmessage(_("Invalid sequence entered"))
clearmsg = false
break
end
- manager:machine():popmessage(input:seq_name(poller.sequence))
- manager:machine():video():frame_update(true)
+ manager.machine:popmessage(input:seq_name(poller.sequence))
+ manager.machine.video:frame_update()
end
end
if poller.modified and poller.valid then
cheat.hotkeys = { pressed = false, keys = poller.sequence }
end
if clearmsg then
- manager:machine():popmessage()
+ manager.machine:popmessage()
end
- manager:machine():video():frame_update(true)
+ manager.machine.video:frame_update()
end
for num, cheat in ipairs(cheats) do
if cheat.script then
- menu[#menu + 1] = {cheat.desc, cheat.hotkeys and manager:machine():input():seq_name(cheat.hotkeys.keys) or _("None"), ""}
+ menu[#menu + 1] = {cheat.desc, cheat.hotkeys and manager.machine.input:seq_name(cheat.hotkeys.keys) or _("None"), ""}
hotkeylist[#hotkeylist + 1] = function(event) return hkcbfunc(cheat, event) end
end
end
@@ -703,7 +703,7 @@ function cheat.startplugin()
end
local function menu_callback(index, event)
- manager:machine():popmessage()
+ manager.machine:popmessage()
if hotkeymenu then
if event == "select" or event == "clear" then
index = index - 3
@@ -745,7 +745,7 @@ function cheat.startplugin()
end
if event == "up" or event == "down" or event == "comment" then
if cheat.comment then
- manager:machine():popmessage(string.format(_("Cheat Comment:\n%s"), cheat.comment))
+ manager.machine:popmessage(string.format(_("Cheat Comment:\n%s"), cheat.comment))
end
elseif event == "left" then
if cheat.parameter then
@@ -779,9 +779,9 @@ function cheat.startplugin()
else
itemtext = cheat.parameter.value
end
- manager:machine():popmessage(string.format(_("Activated: %s = %s"), cheat.desc, itemtext))
+ manager.machine:popmessage(string.format(_("Activated: %s = %s"), cheat.desc, itemtext))
elseif not cheat.parameter and cheat.script.on then
- manager:machine():popmessage(string.format(_("Activated: %s"), cheat.desc))
+ manager.machine:popmessage(string.format(_("Activated: %s"), cheat.desc))
end
end
end
@@ -803,7 +803,7 @@ function cheat.startplugin()
start_time = emu.time()
cheats = load_cheats()
local json = require("json")
- local file = io.open(manager:machine():options().entries.cheatpath:value():match("([^;]+)") .. "/output.json", "w")
+ local file = io.open(manager.machine.options.entries.cheatpath:value():match("([^;]+)") .. "/output.json", "w")
if file then
file:write(json.stringify(cheats, {indent = true}))
file:close()
@@ -812,8 +812,8 @@ function cheat.startplugin()
parse_cheat(cheat)
end
load_hotkeys()
- if manager:machine():debugger() then
- consolelog = manager:machine():debugger().consolelog
+ if manager.machine.debugger then
+ consolelog = manager.machine.debugger.consolelog
consolelast = 0
end
end)
@@ -833,22 +833,22 @@ function cheat.startplugin()
run_if(cheat, cheat.script.run)
end
if cheat.hotkeys and cheat.hotkeys.keys then
- if manager:machine():input():seq_pressed(cheat.hotkeys.keys) then
+ if manager.machine.input:seq_pressed(cheat.hotkeys.keys) then
if not cheat.hotkeys.pressed then
if cheat.is_oneshot then
if not run_if(cheat, cheat.script.change) then
run_if(cheat, cheat.script.on)
end
- manager:machine():popmessage(string.format(_("Activated: %s"), cheat.desc))
+ manager.machine:popmessage(string.format(_("Activated: %s"), cheat.desc))
elseif not cheat.enabled then
cheat.enabled = true
run_if(cheat, cheat.script.on)
- manager:machine():popmessage(string.format(_("Enabled: %s"), cheat.desc))
+ manager.machine:popmessage(string.format(_("Enabled: %s"), cheat.desc))
else
cheat.enabled = false
run_if(cheat, cheat.script.off)
bwpclr(cheat)
- manager:machine():popmessage(string.format(_("Disabled: %s"), cheat.desc))
+ manager.machine:popmessage(string.format(_("Disabled: %s"), cheat.desc))
end
end
cheat.hotkeys.pressed = true
@@ -858,7 +858,7 @@ function cheat.startplugin()
end
end
for num, input in pairs(inputs) do
- local _, screen = next(manager:machine().screens)
+ local _, screen = next(manager.machine.screens)
local framenum = screen:frame_number() - input.begin
local enttab = input.start[framenum]
if enttab then
@@ -907,7 +907,7 @@ function cheat.startplugin()
function ce.inject(newcheat)
cheats[#cheats + 1] = newcheat
parse_cheat(newcheat)
- manager:machine():popmessage(string.format(_("%s added"), newcheat.desc))
+ manager.machine:popmessage(string.format(_("%s added"), newcheat.desc))
end
function ce.get(index)
@@ -922,7 +922,7 @@ function cheat.startplugin()
is_oneshot = cheat.is_oneshot,
comment = cheat.comment,
get_hotkeys = function() if cheat.hotkeys then return cheat.hotkeys.keys end return nil end,
- set_hotkeys = function(seq) cheat.hotkeys = { pressed = false, keys = manager:machine():input():seq_clean(seq) } end
+ set_hotkeys = function(seq) cheat.hotkeys = { pressed = false, keys = manager.machine.input:seq_clean(seq) } end
}
if cheat.script then
intf.script = {}