diff --git a/halyde/config/startupapps.txt b/halyde/config/startupapps.txt index 4a86914..248e747 100644 --- a/halyde/config/startupapps.txt +++ b/halyde/config/startupapps.txt @@ -1,2 +1,3 @@ -/halyde/core/shell.lua -/halyde/core/evmgr.lua \ No newline at end of file +/halyde/core/datatools.lua +/halyde/core/evmgr.lua +/halyde/core/shell.lua \ No newline at end of file diff --git a/halyde/core/cormgr.lua b/halyde/core/cormgr.lua index 8249f54..219e678 100644 --- a/halyde/core/cormgr.lua +++ b/halyde/core/cormgr.lua @@ -17,6 +17,21 @@ function handleError(errormsg) assert(false, errormsg) end +local function runCoroutines() + for i = 1, #_G.cormgr.corList do + local result, errorMessage = coroutine.resume(_G.cormgr.corList[i]) + if not result then + handleError(errorMessage) + end + if coroutine.status(_G.cormgr.corList[i]) == "dead" then + table.remove(_G.cormgr.corList, i) + break + end + --computer.pullSignal(0) + --coroutine.yield() + end +end + local handle = filesystem.open("/halyde/config/startupapps.txt", "r") local data = "" local tmpdata @@ -27,21 +42,13 @@ until not tmpdata for line in data:gmatch("([^\n]*)\n?") do if line ~= "" then _G.cormgr.loadCoroutine(line) + runCoroutines() end end _G.cormgr.loadCoroutine("/halyde/core/shell.lua") while true do - for i = 1, #_G.cormgr.corList do - local result, errormsg = coroutine.resume(_G.cormgr.corList[i]) - if coroutine.status(_G.cormgr.corList[i]) == "dead" then - table.remove(_G.cormgr.corList, i) - if not result then - handleError(errormsg) - end - end - computer.pullSignal(0) - end + runCoroutines() if #_G.cormgr.corList == 0 then computer.shutdown() end diff --git a/halyde/core/datatools.lua b/halyde/core/datatools.lua new file mode 100644 index 0000000..836e464 --- /dev/null +++ b/halyde/core/datatools.lua @@ -0,0 +1,7 @@ +function table.find(table, item) + for k, v in pairs(table) do + if v == item then + return(v) + end + end +end \ No newline at end of file diff --git a/halyde/core/evmgr.lua b/halyde/core/evmgr.lua index a0933fc..32394ce 100644 --- a/halyde/core/evmgr.lua +++ b/halyde/core/evmgr.lua @@ -2,6 +2,8 @@ _G.evmgr = {} _G.evmgr.eventQueue = {} local maxEventQueueLength = 10 -- increase if events start getting dropped +--local ocelot = component.proxy(component.list("ocelot")()) + while true do local args repeat @@ -11,6 +13,12 @@ while true do while #evmgr.eventQueue > maxEventQueueLength do table.remove(evmgr.eventQueue, 1) end + --ocelot.log("Event queue:") + for i = 1, #evmgr.eventQueue do + --ocelot.log("Args 1 and 2:") + --ocelot.log(tostring(evmgr.eventQueue[i][1])) + --ocelot.log(tostring(evmgr.eventQueue[i][2])) + end end until not args coroutine.yield() diff --git a/halyde/core/fullkb.lua b/halyde/core/fullkb.lua new file mode 100644 index 0000000..bb1e14a --- /dev/null +++ b/halyde/core/fullkb.lua @@ -0,0 +1,144 @@ +_G.keyboard = {pressedChars = {}, pressedCodes = {}} +_G.keyboard.keys = {} + +keyboard.keys["1"] = 0x02 +keyboard.keys["2"] = 0x03 +keyboard.keys["3"] = 0x04 +keyboard.keys["4"] = 0x05 +keyboard.keys["5"] = 0x06 +keyboard.keys["6"] = 0x07 +keyboard.keys["7"] = 0x08 +keyboard.keys["8"] = 0x09 +keyboard.keys["9"] = 0x0A +keyboard.keys["0"] = 0x0B +keyboard.keys.a = 0x1E +keyboard.keys.b = 0x30 +keyboard.keys.c = 0x2E +keyboard.keys.d = 0x20 +keyboard.keys.e = 0x12 +keyboard.keys.f = 0x21 +keyboard.keys.g = 0x22 +keyboard.keys.h = 0x23 +keyboard.keys.i = 0x17 +keyboard.keys.j = 0x24 +keyboard.keys.k = 0x25 +keyboard.keys.l = 0x26 +keyboard.keys.m = 0x32 +keyboard.keys.n = 0x31 +keyboard.keys.o = 0x18 +keyboard.keys.p = 0x19 +keyboard.keys.q = 0x10 +keyboard.keys.r = 0x13 +keyboard.keys.s = 0x1F +keyboard.keys.t = 0x14 +keyboard.keys.u = 0x16 +keyboard.keys.v = 0x2F +keyboard.keys.w = 0x11 +keyboard.keys.x = 0x2D +keyboard.keys.y = 0x15 +keyboard.keys.z = 0x2C + +keyboard.keys.apostrophe = 0x28 +keyboard.keys.at = 0x91 +keyboard.keys.back = 0x0E -- backspace +keyboard.keys.backslash = 0x2B +keyboard.keys.capital = 0x3A -- capslock +keyboard.keys.colon = 0x92 +keyboard.keys.comma = 0x33 +keyboard.keys.enter = 0x1C +keyboard.keys.equals = 0x0D +keyboard.keys.grave = 0x29 -- accent grave +keyboard.keys.lbracket = 0x1A +keyboard.keys.lcontrol = 0x1D +keyboard.keys.lmenu = 0x38 -- left Alt +keyboard.keys.lshift = 0x2A +keyboard.keys.minus = 0x0C +keyboard.keys.numlock = 0x45 +keyboard.keys.pause = 0xC5 +keyboard.keys.period = 0x34 +keyboard.keys.rbracket = 0x1B +keyboard.keys.rcontrol = 0x9D +keyboard.keys.rmenu = 0xB8 -- right Alt +keyboard.keys.rshift = 0x36 +keyboard.keys.scroll = 0x46 -- Scroll Lock +keyboard.keys.semicolon = 0x27 +keyboard.keys.slash = 0x35 -- / on main keyboard +keyboard.keys.space = 0x39 +keyboard.keys.stop = 0x95 +keyboard.keys.tab = 0x0F +keyboard.keys.underline = 0x93 + +-- Keypad (and numpad with numlock off) +keyboard.keys.up = 0xC8 +keyboard.keys.down = 0xD0 +keyboard.keys.left = 0xCB +keyboard.keys.right = 0xCD +keyboard.keys.home = 0xC7 +keyboard.keys["end"] = 0xCF +keyboard.keys.pageUp = 0xC9 +keyboard.keys.pageDown = 0xD1 +keyboard.keys.insert = 0xD2 +keyboard.keys.delete = 0xD3 + +-- Function keys +keyboard.keys.f1 = 0x3B +keyboard.keys.f2 = 0x3C +keyboard.keys.f3 = 0x3D +keyboard.keys.f4 = 0x3E +keyboard.keys.f5 = 0x3F +keyboard.keys.f6 = 0x40 +keyboard.keys.f7 = 0x41 +keyboard.keys.f8 = 0x42 +keyboard.keys.f9 = 0x43 +keyboard.keys.f10 = 0x44 +keyboard.keys.f11 = 0x57 +keyboard.keys.f12 = 0x58 +keyboard.keys.f13 = 0x64 +keyboard.keys.f14 = 0x65 +keyboard.keys.f15 = 0x66 +keyboard.keys.f16 = 0x67 +keyboard.keys.f17 = 0x68 +keyboard.keys.f18 = 0x69 +keyboard.keys.f19 = 0x71 + +-- Japanese keyboards +keyboard.keys.kana = 0x70 +keyboard.keys.kanji = 0x94 +keyboard.keys.convert = 0x79 +keyboard.keys.noconvert = 0x7B +keyboard.keys.yen = 0x7D +keyboard.keys.circumflex = 0x90 +keyboard.keys.ax = 0x96 + +-- Numpad +keyboard.keys.numpad0 = 0x52 +keyboard.keys.numpad1 = 0x4F +keyboard.keys.numpad2 = 0x50 +keyboard.keys.numpad3 = 0x51 +keyboard.keys.numpad4 = 0x4B +keyboard.keys.numpad5 = 0x4C +keyboard.keys.numpad6 = 0x4D +keyboard.keys.numpad7 = 0x47 +keyboard.keys.numpad8 = 0x48 +keyboard.keys.numpad9 = 0x49 +keyboard.keys.numpadmul = 0x37 +keyboard.keys.numpaddiv = 0xB5 +keyboard.keys.numpadsub = 0x4A +keyboard.keys.numpadadd = 0x4E +keyboard.keys.numpaddecimal = 0x53 +keyboard.keys.numpadcomma = 0xB3 +keyboard.keys.numpadenter = 0x9C +keyboard.keys.numpadequals = 0x8D + +-- Create inverse mapping for name lookup. +setmetatable(keyboard.keys, +{ + __index = function(tbl, k) + if type(k) ~= "number" then return end + for name,value in pairs(tbl) do + if value == k then + return name + end + end + end +}) \ No newline at end of file diff --git a/halyde/core/shell.lua b/halyde/core/shell.lua index a07b2fd..22acc45 100644 --- a/halyde/core/shell.lua +++ b/halyde/core/shell.lua @@ -1,6 +1,11 @@ import("termlib") +local event = import("event") + +--local ocelot = component.proxy(component.list("ocelot")()) print("\n │\n │ ".._OSVERSION..'\n │ Welcome! Type "help" to get started.\n │') while true do - coroutine.yield() + --coroutine.yield() + local args = table.pack(event.pull("key_down")) + --ocelot.log(tostring(args[1])) end \ No newline at end of file diff --git a/halyde/lib/event.lua b/halyde/lib/event.lua index ccf4e80..befa124 100644 --- a/halyde/lib/event.lua +++ b/halyde/lib/event.lua @@ -1,17 +1,32 @@ local event = {} -function event.pull(timeout, type) +local ocelot = component.proxy(component.list("ocelot")()) + +function event.pull(type, timeout) + checkArg(1, type, "string", "nil") + checkArg(2, timeout, "number", "nil") local startTime = computer.uptime() local args repeat - for _, eventArgs in ipairs(_G.evmgr.eventQueue) do - if eventArgs[1] >= startTime and (eventArgs[2] == type or not type) then - args = eventArgs + for i = 1, #evmgr.eventQueue do + ocelot.log("Args 1 and 2:") + ocelot.log(tostring(evmgr.eventQueue[i][1])) + ocelot.log(tostring(evmgr.eventQueue[i][2])) + ocelot.log(tostring(evmgr.eventQueue[i][3])) + ocelot.log(tostring(evmgr.eventQueue[i][4])) + if evmgr.eventQueue[i][1] >= startTime and (evmgr.eventQueue[i][2] == type or not type) then + args = evmgr.eventQueue[i] + break end end - coroutine.yield() - until args - table.remove(args, 1) - return args + if not args then + coroutine.yield() + end + until args and not timeout or args and timeout and (args or computer.uptime() >= startTime + timeout) + if args then + table.remove(args, 1) + return table.unpack(args) + end end + return event \ No newline at end of file diff --git a/halyde/lib/keyboard.lua b/halyde/lib/keyboard.lua new file mode 100644 index 0000000..e69de29