1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2024-06-25 19:47:12 -07:00

add ad-hoc address translation to rom patcher

This commit is contained in:
Connor Olding 2016-04-09 04:18:00 -07:00
parent 335fe5ca9d
commit 9ef811be23

View File

@ -2,15 +2,20 @@ package.path = package.path..";./?/init.lua"
local assemble = require "lips" local assemble = require "lips"
local function inject(patch, target, offset) local function inject(patch, target, offset, erom, eram)
offset = offset or 0 offset = offset or 0
local f = io.open(target, 'r+b') local f = io.open(target, 'r+b')
if not f then
print("file not found:", target)
return
end
local function write(pos, line) local function write(pos, line)
assert(#line == 2, "that ain't const") assert(#line == 2, "that ain't const")
-- TODO: write hex dump format of written bytes if erom and eram and pos >= eram then
if pos >= offset then pos = pos - eram + erom
elseif pos >= offset then
pos = pos - offset pos = pos - offset
end end
if pos >= 1024*1024*1024 then if pos >= 1024*1024*1024 then
@ -19,6 +24,10 @@ local function inject(patch, target, offset)
return return
end end
f:seek('set', pos) f:seek('set', pos)
-- TODO: write hex dump format of written bytes
print(("%08X %s"):format(pos, line))
f:write(string.char(tonumber(line, 16))) f:write(string.char(tonumber(line, 16)))
end end
@ -28,12 +37,19 @@ local function inject(patch, target, offset)
f:close() f:close()
end end
local offset = arg[3] local function parsenum(s)
if offset then if s:sub(2) == '0x' then
if offset:sub(2) == '0x' then s = tonumber(s, 16)
offset = tonumber(offset, 16)
else else
offset = tonumber(offset) s = tonumber(s)
end end
return s
end end
inject(arg[1], arg[2], offset)
local offset = arg[3]
local extra_rom = arg[4]
local extra_ram = arg[5]
if offset then offset = parsenum(offset) end
if extra_rom then extra_rom = parsenum(extra_rom) end
if extra_ram then extra_ram = parsenum(extra_ram) end
inject(arg[1], arg[2], offset, extra_rom, extra_ram)