-- Автоматический MAME-сценарий для P1-пробы клавиатуры. -- Ввод идёт прямо в поля AT-клавиатуры Sprinter, как в -- toolchain/mame_interactive.py, но дополнен именованными клавишами. local KB = ":kbd:ms_naturl:" local HOLD = 0.06 local events = {} local function add(t, tag, mask, value) events[#events + 1] = {t, KB .. tag, mask, value} end local function key(t, tag, mask) add(t, tag, mask, 1) add(t + HOLD, tag, mask, 0) end local function chord(t, mod_tag, mod_mask, key_tag, key_mask) add(t, mod_tag, mod_mask, 1) add(t + 0.02, key_tag, key_mask, 1) add(t + 0.08, key_tag, key_mask, 0) add(t + 0.10, mod_tag, mod_mask, 0) end local chars = { a={"P1.6",0x04}, b={"P1.5",0x10}, e={"P1.4",0x20}, o={"P2.2",0x02}, p={"P2.3",0x20}, r={"P1.5",0x01}, x={"P1.2",0x10}, ["1"]={"P1.6",0x01}, [" "]={"P2.4",0x80}, ["."]={"P2.2",0x10}, ["\\"]={"P2.1",0x04}, ["\n"]={"P2.1",0x10}, [":"]={"P2.3",0x02,true} } local function type_text(t, text) for i = 1, #text do local ch = text:sub(i, i) local def = chars[ch] local shifted = false if not def then local lower = ch:lower() def = chars[lower] shifted = ch ~= lower else shifted = def[3] or false end if shifted then chord(t, "P1.7", 0x02, def[1], def[2]) else key(t, def[1], def[2]) end t = t + 0.14 end end -- Запуск P1PROBE.EXE из приглашения DSS и выбор клавиатурной пробы. type_text(8.0, "a:\\P1PROBE .EXE\n") key(14.0, "P1.5", 0x40) -- 4 -- 24 события: навигация, F1..F10, комбинации Commander и завершающий Esc. local sequence = { {"P2.4",0x01}, -- Up {"P2.3",0x10}, -- Down {"P2.1",0x08}, -- Left {"P2.4",0x40}, -- Right {"P2.5",0x01}, -- Home {"P2.5",0x20}, -- End {"P1.2",0x01}, -- Page Up {"P1.2",0x20}, -- Page Down {"P2.6",0x01}, -- Insert {"P2.6",0x02}, -- Delete {"P1.2",0x40}, -- F1 {"P1.2",0x80}, -- F2 {"P2.6",0x40}, -- F3 {"P2.6",0x80}, -- F4 {"P2.1",0x40}, -- F5 {"P2.1",0x80}, -- F6 {"P2.2",0x40}, -- F7 {"P2.2",0x80}, -- F8 {"P2.3",0x40}, -- F9 {"P2.3",0x80} -- F10 } for i, def in ipairs(sequence) do key(16.0 + (i - 1) * 0.35, def[1], def[2]) end chord(23.00, "P1.1", 0x02, "P1.5", 0x01) -- Ctrl+R chord(23.35, "P1.1", 0x02, "P1.2", 0x01) -- Ctrl+PgUp chord(23.70, "P1.3", 0x04, "P1.2", 0x40) -- Alt+F1 key(24.05, "P1.6", 0x40) -- Esc -- Закрыть итоговый экран и подтвердить возврат к главному меню. key(27.5, "P2.1", 0x10) table.sort(events, function(a, b) return a[1] < b[1] end) local snap_times = {17.8, 20.6, 23.4, 25.2, 29.0} local snaps_done = {} local start_time = nil local ports = nil local index = 1 local field_cache = {} local function now() local t = manager.machine.time return t.seconds + t.attoseconds / 1e18 end local function field(tag, mask) local cache_key = tag .. "/" .. mask if field_cache[cache_key] then return field_cache[cache_key] end for _, candidate in pairs(ports[tag].fields) do if candidate.mask == mask then field_cache[cache_key] = candidate return candidate end end error("Не найдено поле " .. cache_key) end emu.add_machine_reset_notifier(function() start_time = now() end) emu.register_periodic(function() if not start_time then return end if not ports then ports = manager.machine.ioport.ports end local elapsed = now() - start_time while index <= #events and elapsed >= events[index][1] do local event = events[index] field(event[2], event[3]):set_value(event[4]) index = index + 1 end for _, snap_time in ipairs(snap_times) do if not snaps_done[snap_time] and elapsed >= snap_time then snaps_done[snap_time] = true manager.machine.video:snapshot() print("[p1-kbd] snapshot t=" .. elapsed) end end if elapsed >= 31.0 then print("[p1-kbd] exit t=" .. elapsed) manager.machine:exit() end end)