117 lines
4.0 KiB
Lua
117 lines
4.0 KiB
Lua
-- bitfield-check.lua -- read the M6 bitfield marker words and compare them
|
|
-- with the oracle's expected values.
|
|
--
|
|
-- BITFIELD_MARKERS is the bit address of _bitfield_markers from the linker
|
|
-- map; each marker is one 32-bit word at base + n*0x20 bits. The struct
|
|
-- case is the Task 5 oracle: a:3@0, b:5@3, c:4@8 (signed), d:20@12, e:4@32,
|
|
-- and the raw word0/byte4 markers pin the actual storage bytes, not just the
|
|
-- compiled read-back.
|
|
--
|
|
-- The marker read runs one frame before loader.lua's inspection/exit frame.
|
|
|
|
dofile(os.getenv("M2_LOADER_LUA"))
|
|
|
|
local ENDF = tonumber(os.getenv("LOADER_END") or "2900")
|
|
local BASE = tonumber(os.getenv("BITFIELD_MARKERS"), 16)
|
|
local N = 62
|
|
local frames = 0
|
|
local checked = false
|
|
|
|
local expect = {
|
|
[0] = 5, -- struct s.a (bits 0..2)
|
|
[1] = 21, -- struct s.b (bits 3..7)
|
|
[2] = 0xFFFFFFFD, -- struct s.c = -3, signed 4-bit
|
|
[3] = 0x000ABCDE, -- struct s.d (bits 12..31)
|
|
[4] = 9, -- struct s.e (bits 32..35)
|
|
[5] = 0xABCDEDAD, -- raw word0 = a|b<<3|c<<8|d<<12
|
|
[6] = 0x09, -- raw byte4 low nibble = e
|
|
[7] = 7, -- c = +7
|
|
[8] = 0xFFFFFFF8, -- c = -8 (the 4-bit minimum)
|
|
[9] = 0x000FEDCB, -- cross.x
|
|
[10] = 0x00012345, -- cross.y at bit 20, crossing bit 32
|
|
[11] = 0x345FEDCB, -- raw word0: x | (y low 12) << 20
|
|
[12] = 0x12, -- raw byte4: y high 8 bits
|
|
[13] = 3, -- zw.a
|
|
[14] = 17, -- zw.b after the ignored :0 (bit 3)
|
|
[15] = 0x8B, -- raw byte = 3 | 17 << 3
|
|
[16] = 0xFFFFFFFF, -- one.s = -1 (signed 1-bit)
|
|
[17] = 1, -- one.u
|
|
[18] = 0x03, -- raw byte: s in bit 0, u in bit 1
|
|
[19] = 0, -- one.s = 0
|
|
[20] = 1, -- one.u = 1
|
|
[21] = 0x02, -- raw byte
|
|
[22] = 0xFFFFFFFF, -- one.s = -1
|
|
[23] = 0, -- one.u = 0
|
|
[24] = 0x01, -- raw byte
|
|
[25] = 0xDEADBEEF, -- word.w (full 32-bit field)
|
|
[26] = 1, -- word.v at bit 32
|
|
[27] = 0xDEADBEEF, -- raw word0
|
|
[28] = 0x01, -- raw byte4
|
|
[29] = 0x01234567, -- edge.p (28 bits)
|
|
[30] = 0xA5, -- edge.q at bit 28, crossing bit 32
|
|
[31] = 0x0C, -- edge.r at bit 36
|
|
[32] = 0x51234567, -- raw word0: p | (q low nibble) << 28
|
|
[33] = 0xCA, -- raw byte4: q high nibble | r << 4
|
|
[34] = 0xFFFFFFFD, -- sx.a = -3 (signed 3-bit)
|
|
[35] = 2, -- sx.b
|
|
[36] = 0xFFFFFF38, -- sx.c = -200 (signed 9-bit)
|
|
[37] = 0xFFFE0000, -- sx.d = -131072 (signed 18-bit)
|
|
[38] = 0x80002715, -- raw word0 of the packed signed fields
|
|
[39] = 0xFA0A1F00, -- sy.e = -100000000 (signed 30-bit)
|
|
[40] = 0xFFFFFFEC, -- sy.f = -20 (signed 6-bit, crosses bit 32)
|
|
[41] = 0x3A0A1F00, -- raw word0
|
|
[42] = 0x0B, -- raw byte4: f high nibble
|
|
[43] = 1, -- g2.a through a pointer
|
|
[44] = 30, -- g2.b
|
|
[45] = 0xFFFFFFFE, -- g2.c = -2
|
|
[46] = 0x00054321, -- g2.d
|
|
[47] = 15, -- g2.e
|
|
[48] = 0x54321EF1, -- g2 raw word0
|
|
[49] = 0x0F, -- g2 raw byte4
|
|
[50] = 6, -- lz.a (leading :0 ignored)
|
|
[51] = 9, -- lz.b at bit 3
|
|
[52] = 0x4E, -- raw byte = 6 | 9 << 3
|
|
[53] = 0x12345678, -- l64.f = 0x12345678 (bit 33)
|
|
[54] = 0x00000000, -- l64 raw word0 (pad)
|
|
[55] = 0x2468ACF0, -- l64 raw word1 (pad[32] | f<<1)
|
|
[56] = 0x89ABCDEF, -- q64.q low word
|
|
[57] = 0x89ABCDEF, -- q64 raw word0 (LSW)
|
|
[58] = 0x01234567, -- q64 raw word1 (MSW)
|
|
[59] = 0x12345678, -- copy_l64 read-back after an aggregate copy
|
|
[60] = 0x2468ACF0, -- copied l64 raw MSW
|
|
[61] = 0x5A5A5A5A, -- marker after bitfield_run returns
|
|
}
|
|
|
|
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] then
|
|
bad = bad + 1
|
|
end
|
|
end
|
|
io.write(string.format("M6 bitfield:"))
|
|
for i = 0, N - 1 do
|
|
io.write(string.format(" %08X", got[i]))
|
|
end
|
|
io.write("\n")
|
|
if bad == 0 then
|
|
print("M6 BITFIELD MAME: PASS")
|
|
else
|
|
for i = 0, N - 1 do
|
|
if got[i] ~= expect[i] then
|
|
print(string.format(
|
|
"M6 bitfield: marker %d got %08X want %08X",
|
|
i, got[i], expect[i]))
|
|
end
|
|
end
|
|
print("M6 BITFIELD MAME: FAIL")
|
|
end
|
|
end
|
|
end, "bitfield-check")
|