112 lines
3.5 KiB
Lua
112 lines
3.5 KiB
Lua
-- hw-check.lua -- M7.3 real-hardware marker gate, MAME-equivalent acceptance.
|
|
--
|
|
-- Loads the same COFF that hostload.py sends to the real unit
|
|
-- (scripts/m7/hwmark.c, linked at .text 018C0000 / .data 018D0000 /
|
|
-- .bss 018D8000) through vendor/vt1200/dwt/loader/loader.lua, then requires
|
|
-- exactly what hostload.py's verify_markers() requires:
|
|
--
|
|
-- 018E0000 start == the loader result block's entry (018C0000)
|
|
-- 018E0020 data == 0xDEADBEEF (copied .data)
|
|
-- 018E0040 data2 == 0x12345678 (copied .data)
|
|
-- 018E0060 bss == 0 (zeroed .bss; loader pre-fills A5A5)
|
|
-- 018E0080 count advances (the child is scheduled, not jumped)
|
|
--
|
|
-- and that the loader result status is 0. LOADER_AT/LOADER_END come from the
|
|
-- M4-style environment; the counter is sampled after the child has run, then
|
|
-- again one frame before the loader exits.
|
|
|
|
dofile(os.getenv("M4_LOADER_LUA"))
|
|
|
|
local AT = tonumber(os.getenv("LOADER_AT") or "2500")
|
|
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
|
|
local RESULT = 0x01882D00
|
|
|
|
local CELLS = {
|
|
{ 0x018E0000, "start" },
|
|
{ 0x018E0020, "data" },
|
|
{ 0x018E0040, "data2" },
|
|
{ 0x018E0060, "bss" },
|
|
{ 0x018E0080, "count" },
|
|
}
|
|
|
|
-- First sample: a few frames after injection, so the child has started.
|
|
-- Second sample: the last frame before loader.lua inspects and exits.
|
|
local SAMPLE0 = math.max(AT + 5, ENDF - 11)
|
|
local SAMPLE1 = ENDF - 1
|
|
|
|
local frames = 0
|
|
local first_count = nil
|
|
local checked = false
|
|
|
|
local function r32(prog, addr)
|
|
local ok, v = pcall(function() return prog:read_u32(addr) end)
|
|
if ok then return v end
|
|
return nil
|
|
end
|
|
|
|
emu.register_frame_done(function()
|
|
frames = frames + 1
|
|
|
|
if frames == SAMPLE0 and first_count == nil then
|
|
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
|
first_count = r32(prog, 0x018E0080)
|
|
end
|
|
|
|
if frames == SAMPLE1 and not checked then
|
|
checked = true
|
|
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
|
local v = {}
|
|
for _, cell in ipairs(CELLS) do
|
|
v[cell[2]] = r32(prog, cell[1])
|
|
end
|
|
local status = r32(prog, RESULT + 0x000)
|
|
local entry = r32(prog, RESULT + 0x020)
|
|
local count0 = first_count or 0
|
|
local count1 = v.count or 0
|
|
|
|
print(string.format(
|
|
"M7 HW: start=0x%08X data=0x%08X data2=0x%08X bss=0x%08X count=%d->%d status=%d entry=0x%08X",
|
|
v.start or 0, v.data or 0, v.data2 or 0, v.bss or 0,
|
|
count0, count1, status or -1, entry or 0))
|
|
|
|
local problems = {}
|
|
if status ~= 0 then
|
|
problems[#problems + 1] = string.format("loader status=%s, want 0",
|
|
tostring(status))
|
|
end
|
|
if entry ~= 0x018C0000 then
|
|
problems[#problems + 1] = string.format(
|
|
"loader entry=0x%08X, want 0x018C0000", entry or 0)
|
|
end
|
|
if v.start ~= entry then
|
|
problems[#problems + 1] = string.format(
|
|
"start=0x%08X, want the entry 0x%08X", v.start or 0, entry or 0)
|
|
end
|
|
if v.data ~= 0xDEADBEEF then
|
|
problems[#problems + 1] = string.format("data=0x%08X, want 0xDEADBEEF",
|
|
v.data or 0)
|
|
end
|
|
if v.data2 ~= 0x12345678 then
|
|
problems[#problems + 1] = string.format(
|
|
"data2=0x%08X, want 0x12345678", v.data2 or 0)
|
|
end
|
|
if v.bss ~= 0 then
|
|
problems[#problems + 1] = string.format("bss=0x%08X, want 0",
|
|
v.bss or 0)
|
|
end
|
|
if count0 <= 0 or count1 <= count0 then
|
|
problems[#problems + 1] = string.format(
|
|
"count did not advance (%d -> %d)", count0, count1)
|
|
end
|
|
|
|
if #problems == 0 then
|
|
print("M7 HW MAME: PASS")
|
|
else
|
|
for _, p in ipairs(problems) do
|
|
print("M7 HW: FAIL: " .. p)
|
|
end
|
|
print("M7 HW MAME: FAIL")
|
|
end
|
|
end
|
|
end, "m7-hw-check")
|