154 lines
6.4 KiB
Lua
154 lines
6.4 KiB
Lua
-- xshow-check.lua -- load the M4 image/event COFF with dwt/loader/loader.lua,
|
|
-- inject a real LK401 `Q` key, and prove the mapped 1-bit XImage in VRAM.
|
|
--
|
|
-- M4_LOADER_LUA path to vendor/vt1200/dwt/loader/loader.lua
|
|
-- LOADER_AT injection frame (default 2500)
|
|
-- LOADER_END loader inspection/exit frame (default 3400)
|
|
--
|
|
-- Markers (0x20 bits apart):
|
|
-- 018A8000 display nonzero
|
|
-- 018A8020 window nonzero
|
|
-- 018A8040 image nonzero
|
|
-- 018A8060 quit 1 after the `q` KeyPress
|
|
-- 018A8080 events count of XNextEvent calls (> 0)
|
|
-- 018A80A0 keycode ev.xkey.keycode (193 for the LK401 Q)
|
|
-- 018A80C0 keysym XLookupString keysym (XK_q = 0x71)
|
|
-- 018A80E0 xerrors 0
|
|
-- 018A8100 focus XGetInputFocus after XSetInputFocus
|
|
-- 018A8120 last last X event type (2 = KeyPress)
|
|
--
|
|
-- The client window is XCreateSimpleWindow(..., 20, 20, 640, 480, ...) with
|
|
-- no border. The VT1200 server copies a 1-bit bitmap correctly only when the
|
|
-- destination x is 32-bit aligned, so the client draws the aligned pixmap at
|
|
-- window x = 12 (screen x = 32) and fills the 12-pixel prefix with the
|
|
-- preceding cell's colour. The checker cells are 32 pixels wide with a
|
|
-- 12-pixel phase: image data x = sx - 20 - 12. The window-relative points
|
|
-- (30,30) and (50,30) are adjacent cells (0,0) and (1,0), as are (30,62) and
|
|
-- (50,62). The samples at data (368,280), (468,380) and (568,430) prove the
|
|
-- banded PutImage assembled the whole 640x480 image, not just its first band.
|
|
-- The prefix samples at screen (25,30)/(25,62) prove the preceding-cell fill.
|
|
-- The pixel is read from the exact VRAM bit address (VR319: 2048-bit rows,
|
|
-- LSB-first), not from a whole unaligned word that would cross a cell.
|
|
--
|
|
-- The focus path is the tablet click: XSetInputFocus alone leaves the DWT WM
|
|
-- at PointerRoot (verified: focus=0x1 and no key), so the gate moves the
|
|
-- absolute tablet (0..2199) to (700,500), the termtris-proven in-window point,
|
|
-- and clicks. That point maps inside termtris' (80..560,80..392) rectangle,
|
|
-- which is contained in this client's (20..660,20..500) window. The focus
|
|
-- marker must become the client's own window; the ButtonRelease handler
|
|
-- samples it after the click.
|
|
|
|
dofile(os.getenv("M4_LOADER_LUA"))
|
|
|
|
local ENDF = tonumber(os.getenv("LOADER_END") or "3400")
|
|
local ports = manager.machine.ioport.ports
|
|
local key_q = ports[":lk401:K13"].fields["Q"]
|
|
local tabx = ports[":tablet:TABLET_X"].fields["Tablet X"]
|
|
local taby = ports[":tablet:TABLET_Y"].fields["Tablet Y"]
|
|
local tabb = ports[":tablet:TABLET_BTN"].fields["P1 Button 1"]
|
|
|
|
local MOVE_AT = 2900
|
|
local CLICK_DOWN = 2920
|
|
local CLICK_UP = 2930
|
|
local Q_DOWN = 3000
|
|
local Q_UP = 3010
|
|
|
|
local VRAM_BASE = 0x04000000
|
|
local VRAM_PITCH = 2048 -- VR319: 2048 bits per row
|
|
local WIN_X, WIN_Y = 20, 20
|
|
local IMG_PHASE = 12 -- pixmap is copied to window x=12 (screen x=32)
|
|
|
|
local frames = 0
|
|
local checked = false
|
|
|
|
local function read_bit(prog, sx, sy)
|
|
local bit = VRAM_BASE + sy * VRAM_PITCH + sx
|
|
return prog:read_u16(bit) % 2, bit
|
|
end
|
|
|
|
emu.register_frame_done(function()
|
|
frames = frames + 1
|
|
|
|
if frames == MOVE_AT then
|
|
tabx:set_value(700)
|
|
taby:set_value(500)
|
|
print(string.format("M4: inject frame %d tablet (700,500)", frames))
|
|
elseif frames == CLICK_DOWN then
|
|
tabb:set_value(1)
|
|
print(string.format("M4: inject frame %d button down", frames))
|
|
elseif frames == CLICK_UP then
|
|
tabb:set_value(0)
|
|
print(string.format("M4: inject frame %d button up", frames))
|
|
elseif frames == Q_DOWN then
|
|
key_q:set_value(1)
|
|
print(string.format("M4: inject frame %d Q down", frames))
|
|
elseif frames == Q_UP then
|
|
key_q:set_value(0)
|
|
print(string.format("M4: inject frame %d Q up", frames))
|
|
end
|
|
|
|
if frames == ENDF - 1 and not checked then
|
|
checked = true
|
|
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
|
local m = {}
|
|
for i = 0, 9 do
|
|
m[i] = prog:read_u32(0x018A8000 + i * 0x20)
|
|
end
|
|
|
|
print(string.format(
|
|
"M4: display=%u window=%u image=%u quit=%d events=%d keycode=%d keysym=0x%X xerrors=%d focus=0x%X last=%d",
|
|
m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9]))
|
|
|
|
-- screen -> image (window-relative) -> 32-pixel cell
|
|
local function sample(sx, sy)
|
|
local b, bit = read_bit(prog, sx, sy)
|
|
local rx, ry = sx - WIN_X - IMG_PHASE, sy - WIN_Y
|
|
local cx, cy = math.floor(rx / 32), math.floor(ry / 32)
|
|
print(string.format(
|
|
"M4: pixel screen(%d,%d) image(%d,%d) cell(%d,%d) bit=0x%08X value=%d %s",
|
|
sx, sy, rx, ry, cx, cy, bit, b,
|
|
b == 1 and "white" or "black"))
|
|
return b
|
|
end
|
|
|
|
-- The task's exact pair plus the orthogonal pair, at cell centres and
|
|
-- at points well inside the cells (away from a 32-pixel boundary).
|
|
local b00 = sample(50, 50) -- data (18,30) cell (0,0) -> black
|
|
local b10 = sample(70, 50) -- data (38,30) cell (1,0) -> white
|
|
local b01 = sample(50, 82) -- data (18,62) cell (0,1) -> white
|
|
local b11 = sample(70, 82) -- data (38,62) cell (1,1) -> black
|
|
local c00 = sample(36, 36) -- data (4,16) cell (0,0) -> black
|
|
local c10 = sample(68, 36) -- data (36,16) cell (1,0) -> white
|
|
local c01 = sample(36, 68) -- data (4,48) cell (0,1) -> white
|
|
local c11 = sample(68, 68) -- data (36,48) cell (1,1) -> black
|
|
-- later bands, so a repeated first-band bug cannot pass
|
|
local d1 = sample(400, 300) -- data (368,280) cell (11,8) -> white
|
|
local d2 = sample(500, 400) -- data (468,380) cell (14,11) -> white
|
|
local d3 = sample(600, 450) -- data (568,430) cell (17,13) -> black
|
|
-- the 12-pixel prefix is the preceding cell: white in band 0, black
|
|
-- in band 1, so it cannot be a constant left stripe.
|
|
local p0 = sample(25, 30) -- data (-7,10) cell (-1,0) -> white
|
|
local p1 = sample(25, 62) -- data (-7,42) cell (-1,1) -> black
|
|
|
|
local keysym_ok = (m[6] == 0x71)
|
|
local image_ok = b00 == 0 and b10 == 1 and b01 == 1 and b11 == 0
|
|
and c00 == 0 and c10 == 1 and c01 == 1 and c11 == 0
|
|
and d1 == 1 and d2 == 1 and d3 == 0
|
|
and p0 == 1 and p1 == 0
|
|
local ok = m[0] ~= 0 and m[1] ~= 0 and m[2] ~= 0
|
|
and m[3] == 1 and m[4] > 0 and m[7] == 0
|
|
and m[5] == 193 and keysym_ok
|
|
and m[8] == m[1] and m[8] ~= 0 and m[9] == 2
|
|
and image_ok
|
|
|
|
if ok then
|
|
print("M4 MAME: PASS")
|
|
else
|
|
print(string.format(
|
|
"M4 MAME: FAIL (markers display/window/image=%u/%u/%u quit=%d events=%d keycode=%d keysym=0x%X xerrors=%d focus=0x%X last=%d; image %s)",
|
|
m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9],
|
|
image_ok and "checker-ok" or "checker-mismatch"))
|
|
end
|
|
end
|
|
end, "xshow-check")
|