mirror of
https://github.com/notwa/mm
synced 2025-02-05 13:23:23 -08:00
update build scripts
This commit is contained in:
parent
8f4c4a41b9
commit
aabb1499a6
2 changed files with 63 additions and 28 deletions
10
patch/mm-bq
10
patch/mm-bq
|
@ -2,8 +2,10 @@
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
fast=0
|
fast=0
|
||||||
[[ "$1" == "fast" ]] && fast=1
|
[[ "$1" == "fast" ]] && fast=1 && shift
|
||||||
[[ "$1" == "test" ]] && fast=2
|
[[ "$1" == "test" ]] && fast=2 && shift
|
||||||
|
|
||||||
|
args="$@"
|
||||||
|
|
||||||
inject=../Lua/inject
|
inject=../Lua/inject
|
||||||
sha1=d6133ace5afaa0882cf214cf88daba39e266c078
|
sha1=d6133ace5afaa0882cf214cf88daba39e266c078
|
||||||
|
@ -61,8 +63,8 @@ cp ../*.asm .
|
||||||
|
|
||||||
dd if=/dev/zero of=extra bs=370688 count=1 2>/dev/null
|
dd if=/dev/zero of=extra bs=370688 count=1 2>/dev/null
|
||||||
|
|
||||||
luajit patch.lua -e labels.lua -o 0x80780000 extra.asm extra
|
luajit patch.lua -e labels.lua -o 0x80780000 "$@" extra.asm extra
|
||||||
luajit patch.lua -i labels.lua code.asm patchme/"$code"
|
luajit patch.lua -i labels.lua "$@" code.asm patchme/"$code"
|
||||||
|
|
||||||
# ensure the file is the proper size (Lua seems to expand it?)
|
# ensure the file is the proper size (Lua seems to expand it?)
|
||||||
dd if=extra of=patchme/"$extra" bs=370688 count=1 2>/dev/null
|
dd if=extra of=patchme/"$extra" bs=370688 count=1 2>/dev/null
|
||||||
|
|
|
@ -4,12 +4,29 @@ local assemble = require "lips"
|
||||||
local cereal = require "serialize"
|
local cereal = require "serialize"
|
||||||
local argparse = require "argparse"
|
local argparse = require "argparse"
|
||||||
|
|
||||||
|
local function lament(...)
|
||||||
|
io.stdout:write(...)
|
||||||
|
io.stdout:write('\n')
|
||||||
|
end
|
||||||
|
|
||||||
|
local function parsenum(s)
|
||||||
|
if s:sub(1, 2) == '0x' then
|
||||||
|
return tonumber(s, 16)
|
||||||
|
elseif s:sub(1, 1) == '0' then
|
||||||
|
return tonumber(s, 8)
|
||||||
|
else
|
||||||
|
return tonumber(s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function inject(args)
|
local function inject(args)
|
||||||
args.offset = args.offset or 0
|
local offset = args.offset and parsenum(args.offset) or 0
|
||||||
|
local origin = args.origin and parsenum(args.origin) or 0
|
||||||
|
local base = args.base and parsenum(args.base) or 0x80000000
|
||||||
|
|
||||||
local f = io.open(args.output, 'r+b')
|
local f = io.open(args.output, 'r+b')
|
||||||
if not f then
|
if not f then
|
||||||
print("file not found:", args.output)
|
lament("file not found:", args.output)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,12 +41,12 @@ local function inject(args)
|
||||||
local function write(pos, b)
|
local function write(pos, b)
|
||||||
if args.extra_rom and args.extra_ram and pos >= args.extra_ram then
|
if args.extra_rom and args.extra_ram and pos >= args.extra_ram then
|
||||||
pos = pos - args.extra_ram + args.extra_rom
|
pos = pos - args.extra_ram + args.extra_rom
|
||||||
elseif pos >= args.offset then
|
elseif pos >= offset then
|
||||||
pos = pos - args.offset
|
pos = pos - offset
|
||||||
end
|
end
|
||||||
if pos >= 1024*1024*1024 then
|
if pos >= 1024*1024*1024 then
|
||||||
print("you probably don't want to do this:")
|
lament("you probably don't want to do this:")
|
||||||
print(("%08X %02X"):format(pos, b))
|
lament(("%08X %02X"):format(pos, b))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
f:seek('set', pos)
|
f:seek('set', pos)
|
||||||
|
@ -37,7 +54,28 @@ local function inject(args)
|
||||||
f:write(string.char(b))
|
f:write(string.char(b))
|
||||||
end
|
end
|
||||||
|
|
||||||
assemble(args.input, write, {unsafe=true, offset=args.offset, labels=state})
|
local options = {
|
||||||
|
unsafe = true,
|
||||||
|
labels = state,
|
||||||
|
debug_token = args.dump_token,
|
||||||
|
debug_pre = args.dump_pre,
|
||||||
|
debug_dump = args.dump_asm,
|
||||||
|
}
|
||||||
|
if args.offset then
|
||||||
|
if args.origin or args.base then
|
||||||
|
error('--offset is mutually exclusive from --origin, --base')
|
||||||
|
end
|
||||||
|
options.offset = offset
|
||||||
|
else
|
||||||
|
options.origin = origin
|
||||||
|
if args.origin or args.base then
|
||||||
|
options.base = base
|
||||||
|
else
|
||||||
|
options.base = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assemble(args.input, write, options)
|
||||||
|
|
||||||
if args.export then
|
if args.export then
|
||||||
cereal.serialize(args.export, state)
|
cereal.serialize(args.export, state)
|
||||||
|
@ -46,24 +84,19 @@ local function inject(args)
|
||||||
f:close()
|
f:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function parsenum(s)
|
|
||||||
if s:sub(1, 2) == '0x' then
|
|
||||||
return tonumber(s, 16)
|
|
||||||
elseif s:sub(1, 1) == '0' then
|
|
||||||
return tonumber(s, 8)
|
|
||||||
else
|
|
||||||
return tonumber(s)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local ap = argparse("patch", "patch a binary file with assembly")
|
local ap = argparse("patch", "patch a binary file with assembly")
|
||||||
|
|
||||||
-- TODO: option to dump hex or gs codes when no output is given
|
-- TODO: option to dump hex or gs codes when no output is given
|
||||||
ap:argument("input", "input assembly file")
|
ap:argument("input", "input assembly file")
|
||||||
ap:argument("output", "output binary file")
|
ap:argument("output", "output binary file")
|
||||||
ap:option("-o --offset", "offset to pass to lips", "0"):convert(parsenum)
|
ap:option("-o --offset", "(deprecated) offset to pass to lips", nil)
|
||||||
|
ap:option("-O --origin", "origin to pass to lips", nil):convert(parsenum)
|
||||||
|
ap:option("-b --base", "base to pass to lips", nil):convert(parsenum)
|
||||||
ap:option("-i --import", "import state file(s) containing labels"):count("*")
|
ap:option("-i --import", "import state file(s) containing labels"):count("*")
|
||||||
ap:option("-e --export", "export state file containing labels")
|
ap:option("-e --export", "export state file containing labels")
|
||||||
|
ap:flag("--dump-token", "(debug) dump statements to stdout after lexing")
|
||||||
|
ap:flag("--dump-pre", "(debug) dump statements to stdout after preprocessing")
|
||||||
|
ap:flag("--dump-asm", "(debug) dump statements to stdout after assembling")
|
||||||
--ap:option("-s --state", "--import and --export to this file")
|
--ap:option("-s --state", "--import and --export to this file")
|
||||||
-- TODO: replace this with a lua table import of associated addresses
|
-- TODO: replace this with a lua table import of associated addresses
|
||||||
ap:option("--extra-rom", "dumb stuff"):convert(parsenum)
|
ap:option("--extra-rom", "dumb stuff"):convert(parsenum)
|
||||||
|
|
Loading…
Add table
Reference in a new issue