From d85e9b96b288a0a0656f87950f9399ea83ebd360 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Mon, 15 Jan 2018 20:38:30 -0500 Subject: [PATCH] transition to kernel --- sys/boot/opus.boot | 71 +----------------------------------- sys/extensions/0.splash.lua | 44 ++++++++++++++++++++++ sys/extensions/1.device.lua | 2 +- sys/extensions/3.network.lua | 2 + sys/kernel.lua | 46 +++++++++++++++++++---- sys/services/log.lua | 6 +-- 6 files changed, 89 insertions(+), 82 deletions(-) create mode 100644 sys/extensions/0.splash.lua diff --git a/sys/boot/opus.boot b/sys/boot/opus.boot index 1adee42..0df7dc5 100644 --- a/sys/boot/opus.boot +++ b/sys/boot/opus.boot @@ -1,9 +1,6 @@ -- Loads the Opus environment regardless if the file system is local or not -local colors = _G.colors local fs = _G.fs local http = _G.http -local term = _G.term -local window = _G.window local BRANCH = 'develop-1.8' local GIT_REPO = 'kepler155c/opus/' .. BRANCH @@ -17,46 +14,6 @@ sandboxEnv.BRANCH = BRANCH _G.debug = function() end -local terminal = term.current() -local w, h = term.getSize() -local kernelWindow = window.create(terminal, 1, 1, w, h, false) -term.redirect(kernelWindow) -kernelWindow.parent = terminal -local splashWindow - -local function splash() - splashWindow = window.create(terminal, 1, 1, w, h, false) - splashWindow.setTextColor(colors.white) - if splashWindow.isColor() then - splashWindow.setBackgroundColor(colors.black) - splashWindow.clear() - local opus = { - 'fffff00', - 'ffff07000', - 'ff00770b00 4444', - 'ff077777444444444', - 'f07777744444444444', - 'f0000777444444444', - '070000111744444', - '777770000', - '7777000000', - '70700000000', - '077000000000', - } - for k,line in ipairs(opus) do - splashWindow.setCursorPos((w - 18) / 2, k + (h - #opus) / 2) - splashWindow.blit(string.rep(' ', #line), string.rep('a', #line), line) - end - end - - local str = 'Loading Opus OS...' - print(str) - splashWindow.setCursorPos((w - #str) / 2, h) - splashWindow.write(str) - splashWindow.setVisible(true) - return splashWindow -end - local function makeEnv() local env = setmetatable({ }, { __index = _G }) for k,v in pairs(sandboxEnv) do @@ -92,7 +49,6 @@ end local args = { ... } -splash() local s, m = pcall(function() -- Install require shim if fs.exists('sys/apis/injector.lua') then @@ -106,37 +62,12 @@ local s, m = pcall(function() fs.mount('', 'gitfs', GIT_REPO) end - -- runLevel 6 if passed a program to run - -- otherwise, runLevel 7 (multishell) - run('sys/apps/shell', 'sys/kernel.lua', args[1] and 6 or 7) - - kernel.hook('kernel_ready', function() - splashWindow.setVisible(false) - kernelWindow.setVisible(true) - if args[1] then - local s, m = _G.kernel.run({ - title = 'startup', - path = 'sys/apps/shell', - args = args, - haltOnExit = true, - }) - if s then - _G.kernel.raise(s.uid) - else - error(m) - end - end - - end) - _G.kernel.start() + run('sys/apps/shell', 'sys/kernel.lua', table.unpack(args)) end) if not s then - splashWindow.setVisible(false) - kernelWindow.setVisible(true) print('\nError loading Opus OS\n') _G.printError(m .. '\n') - term.redirect(terminal) end if fs.restore then diff --git a/sys/extensions/0.splash.lua b/sys/extensions/0.splash.lua new file mode 100644 index 0000000..2c19af0 --- /dev/null +++ b/sys/extensions/0.splash.lua @@ -0,0 +1,44 @@ +if false then + local colors = _G.colors + local term = _G.term + local window = _G.window + + local terminal = term.current() + local w, h = term.getSize() + + local splashWindow = window.create(terminal.parent, 1, 1, w, h, false) + splashWindow.setTextColor(colors.white) + if splashWindow.isColor() then + splashWindow.setBackgroundColor(colors.black) + splashWindow.clear() + local opus = { + 'fffff00', + 'ffff07000', + 'ff00770b00 4444', + 'ff077777444444444', + 'f07777744444444444', + 'f0000777444444444', + '070000111744444', + '777770000', + '7777000000', + '70700000000', + '077000000000', + } + for k,line in ipairs(opus) do + splashWindow.setCursorPos((w - 18) / 2, k + (h - #opus) / 2) + splashWindow.blit(string.rep(' ', #line), string.rep('a', #line), line) + end + end + + local str = 'Loading Opus OS...' + print(str) + splashWindow.setCursorPos((w - #str) / 2, h) + splashWindow.write(str) + + terminal.setVisible(false) + splashWindow.setVisible(true) + + kernel.hook('kernel_ready', function() + kernel.window.setVisible(true) + end) +end diff --git a/sys/extensions/1.device.lua b/sys/extensions/1.device.lua index a5d5b73..e082b65 100644 --- a/sys/extensions/1.device.lua +++ b/sys/extensions/1.device.lua @@ -4,7 +4,7 @@ local Peripheral = require('peripheral') _G.device = Peripheral.getList() -_G.device.terminal = _G.kernel.terminal.parent +_G.device.terminal = _G.kernel.terminal _G.device.terminal.side = 'terminal' _G.device.terminal.type = 'terminal' _G.device.terminal.name = 'terminal' diff --git a/sys/extensions/3.network.lua b/sys/extensions/3.network.lua index 6451bf2..f045293 100644 --- a/sys/extensions/3.network.lua +++ b/sys/extensions/3.network.lua @@ -1,4 +1,5 @@ local kernel = _G.kernel +local os = _G.os _G.network = { } @@ -18,4 +19,5 @@ end) if _G.device.wireless_modem then startNetwork() + os.sleep(0) -- give the network a cycle to start end diff --git a/sys/kernel.lua b/sys/kernel.lua index d53a8c7..9fcb6a4 100644 --- a/sys/kernel.lua +++ b/sys/kernel.lua @@ -6,8 +6,6 @@ _G.kernel = { UID = 0, hooks = { }, routines = { }, - terminal = _G.term.current(), - window = _G.term.current(), } local fs = _G.fs @@ -15,6 +13,11 @@ local kernel = _G.kernel local os = _G.os local shell = _ENV.shell local term = _G.term +local window = _G.window + +local w, h = term.getSize() +kernel.terminal = term.current() +kernel.window = window.create(kernel.terminal, 1, 1, w, h, false) local focusedRoutineEvents = Util.transpose { 'char', 'key', 'key_up', @@ -77,6 +80,9 @@ function Routine:resume(event, ...) self.filter = result else _G.printError(result) + if self.haltOnError then + error(result) + end end if coroutine.status(self.co) == 'dead' then Util.removeByValue(kernel.routines, self) @@ -108,7 +114,7 @@ function kernel.newRoutine(args) routine.uid = kernel.UID routine.timestamp = os.clock() routine.env = args.env or Util.shallowCopy(shell.getEnv()) - routine.terminal = args.terminal or kernel.terminal + routine.terminal = args.terminal or kernel.window routine.window = args.window or kernel.window return routine @@ -127,7 +133,7 @@ function kernel.launch(routine) end if not result and err and err ~= 'Terminated' then - _G.printError(tostring(err)) + error(err, 2) end end) @@ -219,19 +225,22 @@ function kernel.start() local eventData = { os.pullEventRaw() } local event = table.remove(eventData, 1) kernel.event(event, eventData) - until event == 'kernel_halt' or not kernel.routines[1] + until event == 'kernel_halt' end) - kernel.window.setVisible(true) if not s then + kernel.window.setVisible(true) + term.redirect(kernel.window) print('\nCrash detected\n') _G.printError(m) end term.redirect(kernel.terminal) end -local function init(runLevel) - runLevel = tonumber(runLevel) or error('Invalid run level') +local function init(...) + local args = { ... } + + local runLevel = #args > 0 and 6 or 7 local dir = 'sys/extensions' local files = fs.list(dir) @@ -245,11 +254,32 @@ local function init(runLevel) end end end + os.queueEvent('kernel_ready') + + if args[1] then + kernel.hook('kernel_ready', function() + local s, m = kernel.run({ + title = args[1], + path = 'sys/apps/shell', + args = args, + haltOnExit = true, + terminal = kernel.terminal, + }) + if s then + kernel.raise(s.uid) + else + error(m) + end + end) + end end kernel.run({ fn = init, title = 'init', + haltOnError = true, args = { ... }, }) + +kernel.start() diff --git a/sys/services/log.lua b/sys/services/log.lua index 399690d..35dad8a 100644 --- a/sys/services/log.lua +++ b/sys/services/log.lua @@ -22,7 +22,7 @@ end -- need: window.getParent() -- window.copy(target) -local terminal = _G.kernel.terminal.parent +local terminal = _G.kernel.terminal local w, h = kernel.window.getSize() local win = window.create(kernel.window, 1, 1, w, h + 50, false) @@ -52,12 +52,12 @@ Terminal.scrollable(win, kernel.window) -- update kernel with new window, set this tab with the new kernal window local routine = kernel.getCurrent() for _,r in pairs(kernel.routines) do - if r.terminal == kernel.terminal then + if r.terminal == kernel.window then r.terminal = win r.window = win end end -kernel.terminal = win +--kernel.terminal = win kernel.window = win routine.terminal = win routine.window = win