178 lines
5.3 KiB
Lua
178 lines
5.3 KiB
Lua
-- data-check.lua -- read the M7.1 `.data` initializer gate markers and the raw
|
|
-- object bytes, and compare them with the exact expected values.
|
|
--
|
|
-- M4_LOADER_LUA is the dwt loader script. Marker n is at 018A8000 + n*0x20
|
|
-- bits; marker 60 is the post-return sentinel. The raw image is at
|
|
-- 018A9000: x@0, s@8, p@13, arr@26, u@44, pt@64, y@80 (the pt pointer bytes
|
|
-- are compared with the linked address of x from marker 25). In the native
|
|
-- run only, markers 26..29 and the 5-byte packed odd-offset pointer record at
|
|
-- byte 96 are checked too; the raw GSPA path rejects that shape.
|
|
--
|
|
-- The marker read runs one frame before loader.lua's inspection/exit frame.
|
|
|
|
dofile(os.getenv("M4_LOADER_LUA"))
|
|
|
|
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
|
|
local BASE = 0x018A8000
|
|
local OUT = 0x018A9000
|
|
local N = 34
|
|
local SENT_IDX = 60
|
|
local SENT = 0x5A5A5A5A
|
|
local NATIVE = os.getenv("M7_DATA_NATIVE") == "1"
|
|
local frames = 0
|
|
local checked = false
|
|
|
|
local expect = {
|
|
0x55667788, -- 0: low word of x
|
|
0x11223344, -- 1: high word of x
|
|
5, -- 2: s.a
|
|
17, -- 3: s.b
|
|
0xFFFFFFFD, -- 4: s.c (signed -3)
|
|
0x000ABCDE, -- 5: s.d
|
|
9, -- 6: s.e
|
|
0x11, -- 7: p.a
|
|
0x22334455, -- 8: p.b
|
|
0xAABBCCDD, -- 9: low word of p.c
|
|
0x66778899, -- 10: high word of p.c
|
|
0x11223344, -- 11: arr[0].a
|
|
0x778899AA, -- 12: arr[1].a
|
|
0xDDEEFF00, -- 13: arr[2].a
|
|
0x5566, -- 14: arr[0].b
|
|
0x12345678, -- 15: union active struct i
|
|
0x9ABC, -- 16: union active struct h
|
|
1, -- 17: pp == &x and *pp == x
|
|
3, -- 18: cp - &x in bytes
|
|
0x1234, -- 19: pt.tag
|
|
1, -- 20: pt.p == &x and pt.c == 0x5A
|
|
0x12345678, -- 21: union low word
|
|
0x00009ABC, -- 22: union high word
|
|
0x1122, -- 23: arr[2].b
|
|
0xBBCC, -- 24: arr[1].b
|
|
nil, -- 25: linked address of x (runtime)
|
|
nil, -- 26: odd.c (native only)
|
|
nil, -- 27: odd.p == &x (native only)
|
|
nil, -- 28: low word of *odd.p (native only)
|
|
nil, -- 29: high word of *odd.p (native only)
|
|
0x55667788, -- 30: low word of y[0]
|
|
0x11223344, -- 31: high word of y[0]
|
|
0xDDEEFF00, -- 32: low word of y[1]
|
|
0x99AABBCC, -- 33: high word of y[1]
|
|
}
|
|
local raw = {
|
|
{ 0, "8877665544332211", "x" },
|
|
{ 8, "8DEDCDAB09", "s" },
|
|
{ 13, "1155443322DDCCBBAA99887766", "p" },
|
|
{ 26, "443322116655AA998877CCBB00FFEEDD2211", "arr" },
|
|
{ 44, "78563412BC9A0000", "u" },
|
|
{ 80, "887766554433221100FFEEDDCCBBAA99", "y" },
|
|
}
|
|
|
|
local function read_bytes(prog, off, len)
|
|
local out = {}
|
|
for i = 0, len - 1 do
|
|
out[#out + 1] = string.char(prog:read_u8(OUT + (off + i) * 8))
|
|
end
|
|
return table.concat(out)
|
|
end
|
|
|
|
local function hex(s)
|
|
return (s:gsub(".", function(c) return string.format("%02X", string.byte(c)) end))
|
|
end
|
|
|
|
emu.register_frame_done(function()
|
|
frames = frames + 1
|
|
if frames == ENDF - 1 and not checked then
|
|
checked = true
|
|
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
|
local got = {}
|
|
local bad = 0
|
|
|
|
for i = 0, N - 1 do
|
|
got[i] = prog:read_u32(BASE + i * 0x20)
|
|
if expect[i + 1] ~= nil and got[i] ~= expect[i + 1] then
|
|
bad = bad + 1
|
|
end
|
|
end
|
|
local sent = prog:read_u32(BASE + SENT_IDX * 0x20)
|
|
if sent ~= SENT then
|
|
bad = bad + 1
|
|
end
|
|
|
|
for _, r in ipairs(raw) do
|
|
local got_bytes = read_bytes(prog, r[1], #r[2] / 2)
|
|
if hex(got_bytes) ~= r[2] then
|
|
bad = bad + 1
|
|
print(string.format(
|
|
"M7 data: %s bytes got %s want %s",
|
|
r[3], hex(got_bytes), r[2]))
|
|
end
|
|
end
|
|
|
|
-- pt: tag, linked pointer, char. The pointer bytes are the
|
|
-- little-endian linked address of x from marker 25.
|
|
local pt = read_bytes(prog, 64, 9)
|
|
local pt_tag = string.unpack("<I4", pt, 1)
|
|
local pt_ptr = string.unpack("<I4", pt, 5)
|
|
local pt_c = string.byte(pt, 9)
|
|
if pt_tag ~= 0x1234 or pt_c ~= 0x5A or pt_ptr ~= got[25] then
|
|
bad = bad + 1
|
|
print(string.format(
|
|
"M7 data: pt bytes got %s (ptr %08X want %08X)",
|
|
hex(pt), pt_ptr, got[25]))
|
|
end
|
|
if hex(read_bytes(prog, 64, 4)) ~= "34120000" then
|
|
bad = bad + 1
|
|
print("M7 data: pt.tag bytes do not match the field read")
|
|
end
|
|
|
|
-- Native-only packed { char, long long * }: the pointer field is
|
|
-- at byte offset 1. Marker 25 is the linked address of x.
|
|
if NATIVE then
|
|
local odd = read_bytes(prog, 96, 5)
|
|
local odd_c = string.byte(odd, 1)
|
|
local odd_ptr = string.unpack("<I4", odd, 2)
|
|
if got[26] ~= 0x5A or got[27] ~= 1 or
|
|
got[28] ~= 0x55667788 or got[29] ~= 0x11223344 then
|
|
bad = bad + 1
|
|
print(string.format(
|
|
"M7 data: odd markers %08X %08X %08X %08X",
|
|
got[26], got[27], got[28], got[29]))
|
|
end
|
|
if odd_c ~= 0x5A or odd_ptr ~= got[25] then
|
|
bad = bad + 1
|
|
print(string.format(
|
|
"M7 data: odd bytes %s (ptr %08X want %08X)",
|
|
hex(odd), odd_ptr, got[25]))
|
|
end
|
|
end
|
|
|
|
io.write("M7 data:")
|
|
for i = 0, N - 1 do
|
|
io.write(string.format(" %08X", got[i]))
|
|
end
|
|
io.write(string.format(" %08X\n", sent))
|
|
|
|
if bad == 0 then
|
|
print("M4: data gate markers and raw bytes match")
|
|
print("M4 MAME: PASS")
|
|
print("M7 DATA MAME: PASS")
|
|
else
|
|
for i = 0, N - 1 do
|
|
if expect[i + 1] ~= nil and got[i] ~= expect[i + 1] then
|
|
print(string.format(
|
|
"M7 data: marker %d got %08X want %08X",
|
|
i, got[i], expect[i + 1]))
|
|
end
|
|
end
|
|
if sent ~= SENT then
|
|
print(string.format(
|
|
"M7 data: sentinel got %08X want %08X",
|
|
sent, SENT))
|
|
end
|
|
print("M4: data gate marker/byte mismatch")
|
|
print("M4 MAME: FAIL")
|
|
print("M7 DATA MAME: FAIL")
|
|
end
|
|
end
|
|
end, "m7-data-check")
|