-- 0.2/P6: четыре сортировки, reverse, независимость панелей и refresh. 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 = { c={"P1.4",0x08}, d={"P1.4",0x04}, e={"P1.4",0x20}, m={"P2.0",0x10}, o={"P2.2",0x02}, p={"P2.3",0x20}, r={"P1.5",0x01}, s={"P1.2",0x08}, t={"P1.5",0x20}, x={"P1.2",0x10}, [" "]={"P2.4",0x80}, ["."]={"P2.2",0x10}, ["\n"]={"P2.1",0x10}, [":"]={"P2.3",0x02,true} } local function type_text(t, value) for i = 1, #value do local ch = value:sub(i, i) local def = chars[ch] or chars[ch:lower()] local shifted = def[3] or ch ~= ch:lower() 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 local function ctrl_f(t, tag, mask) chord(t, "P1.1", 0x02, tag, mask) end type_text(8.0, "d:\n") type_text(9.0, "SORTRT.EXE\n") type_text(12.0, "SPRCMD.EXE\n") key(18.0, "P2.1", 0x10) -- left -> SORTL. key(20.0, "P1.6", 0x20) -- Tab -> right. key(21.0, "P2.3", 0x10) -- Down -> SORTR. key(22.0, "P2.1", 0x10) -- right -> SORTR. key(24.0, "P1.6", 0x20) -- left active again. ctrl_f(27.0, "P2.6", 0x80) -- Ctrl+F4: extension ascending. ctrl_f(31.0, "P2.6", 0x80) -- extension descending. ctrl_f(35.0, "P2.1", 0x80) -- Ctrl+F6: size ascending. ctrl_f(39.0, "P2.1", 0x80) -- size descending. ctrl_f(43.0, "P2.1", 0x40) -- Ctrl+F5: date ascending. ctrl_f(47.0, "P2.1", 0x40) -- date descending. ctrl_f(51.0, "P2.6", 0x40) -- Ctrl+F3: name ascending. ctrl_f(55.0, "P2.6", 0x40) -- name descending. ctrl_f(59.0, "P2.1", 0x80) -- left size ascending. ctrl_f(61.0, "P2.1", 0x80) -- left size descending. key(63.0, "P1.6", 0x20) -- right active, still N+. ctrl_f(65.0, "P2.6", 0x80) -- right extension ascending. chord(68.0, "P1.1", 0x02, "P1.5", 0x01) -- refresh keeps E+. key(72.0, "P2.3", 0x80) -- F10. key(74.0, "P2.1", 0x10) -- Enter: cleanup. table.sort(events, function(a, b) return a[1] < b[1] end) local snap_times = { 25.5, -- обе панели N+; 29.0, -- left E+; 33.0, -- left E-; 37.0, -- left S+; 41.0, -- left S-; 45.0, -- left D+; 49.0, -- left D-; 53.0, -- left N+; 57.0, -- left N-; 66.5, -- left S-, right E+; 70.0, -- refresh сохранил right E+; 76.0 -- чистый DSS prompt. } 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("[p6-sort] snapshot t=" .. elapsed) end end if elapsed >= 78.0 then print("[p6-sort] exit t=" .. elapsed) manager.machine:exit() end end)