diff options
Diffstat (limited to 'plugins/cheat/cheat_simple.lua')
-rw-r--r-- | plugins/cheat/cheat_simple.lua | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/plugins/cheat/cheat_simple.lua b/plugins/cheat/cheat_simple.lua index 11c63e6e642..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,13 +92,20 @@ 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 + 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) elseif #code == 8 then addr = ((value >> 12) & 7) | ((value >> 16) & 0x78) | ((value >> 20) & 0x80) | (value & 0x700) | ((value >> 4) & 0x7800) newval = ((value >> 28) & 7) | (value & 8) | ((value >> 20) & 0x70) | ((value >> 24) & 0x80) comp = ((value >> 4) & 7) | ((value >> 8) & 8) | ((value << 4) & 0x70) | (value & 0x80) - -- assume 8K banks, 32K also common but is an easy multiple of 8K - return prepare_rom_cheat(desc, ":nes_slot:cart:prg_rom", addr, newval, 8, 8192, comp) + -- try 32K banks then 8K + local status, cheat = pcall(prepare_rom_cheat, desc, ":nes_slot:cart:prg_rom", addr, newval, 8, 32768, comp) + if not status then + cheat = prepare_rom_cheat(desc, ":nes_slot:cart:prg_rom", addr, newval, 8, 8192, comp) + end + return cheat else error("error game genie cheat incorrect length " .. desc) end @@ -123,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 @@ -302,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) |