-- pointer-check.lua -- read the M7.1 `-O2` pointer gate markers and the exact -- copy bytes, and compare them with the expected values. -- -- M4_LOADER_LUA is the dwt loader script. Marker n is at 018A8000 + n*0x20 -- bits (0..12 from the driver, 13 the post-return sentinel); the copy bytes -- are at 018A9000 + n*8 bits. -- -- 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 = 13 local SENT = 0x5A5A5A5A local frames = 0 local checked = false local expect = { 1, -- a[0..7] == "aabcdefg" after the overlapping backward copy 1, -- a[8] == 'h', a[9] and a[65] untouched 81, -- b[3] == 'Q' after `p += 3; *p = 'Q'` 0, -- b[0] untouched 0, -- b[24] untouched (the old double-scaled byte) 0, -- b[127] untouched 5, -- (q - b) in bytes 40, -- (u32)q - (u32)b in bits 1, -- the forward byte checks 1, -- late64: c + 24 bits == c + 3 bytes (not 192 bits) 1, -- narrow16 keeps (p & 0xffff) + 24 1, -- narrow8 keeps (p & 0xff) + 24 1, -- late64s: the signed i64 form also stays 24 bits } local want_bytes = "aabcdefgh" local function escape(s) return (s:gsub("\n", "\\n")) 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 got[i] ~= expect[i + 1] then bad = bad + 1 end end local sent = prog:read_u32(BASE + 13 * 0x20) if sent ~= SENT then bad = bad + 1 end local bytes = {} for i = 0, #want_bytes - 1 do bytes[#bytes + 1] = string.char(prog:read_u8(OUT + i * 8)) end local got_bytes = table.concat(bytes) io.write("M7 pointer:") for i = 0, N - 1 do io.write(string.format(" %08X", got[i])) end io.write(string.format(" %08X\n", sent)) print(string.format("M7 pointer bytes(%d): '%s' want '%s'", #got_bytes, escape(got_bytes), escape(want_bytes))) if got_bytes ~= want_bytes then bad = bad + 1 end if bad == 0 then print("M4: pointer gate markers and bytes match") print("M4 MAME: PASS") print("M7 POINTER MAME: PASS") else for i = 0, N - 1 do if got[i] ~= expect[i + 1] then print(string.format( "M7 pointer: marker %d got %08X want %08X", i, got[i], expect[i + 1])) end end if sent ~= SENT then print(string.format( "M7 pointer: sentinel got %08X want %08X", sent, SENT)) end print("M4: pointer gate marker/byte mismatch") print("M4 MAME: FAIL") print("M7 POINTER MAME: FAIL") end end end, "m7-pointer-check")