-
Notifications
You must be signed in to change notification settings - Fork 8
/
dualboot_init.lua
68 lines (62 loc) · 2.08 KB
/
dualboot_init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
local cp = component or package.loaded.component
local pc = computer or package.loaded.computer
pc.supportsOEFI = function()
return false
end
local loadfile = load([[return function(file)
local pc,cp = computer or package.loaded.computer, component or package.loaded.component
local addr, invoke = pc.getBootAddress(), cp.invoke
local handle, reason = invoke(addr, "open", file)
assert(handle, reason)
local buffer = ""
repeat
local data, reason = invoke(addr, "read", handle, math.huge)
assert(data or not reason, reason)
buffer = buffer .. (data or "")
until not data
invoke(addr, "close", handle)
return load(buffer, "=" .. file, "bt", _G)
end]], "=loadfile", "bt", _G)()
if component.list("gpu")() == nil or component.list("screen")() == nil then
error("gpu and screen required")
end
if not cp.invoke(computer.getBootAddress(), "exists", "/lib/core/boot.lua") then -- OpenOS doesn't exists, so always boot Fuchas
_G.loadfile = loadfile
loadfile("Fuchas/Kernel/boot.lua")()
return
elseif not cp.invoke(computer.getBootAddress(), "exists", "/Fuchas/Kernel/boot.lua") then -- Fuchas doesn't exists, so always boot OpenOS
loadfile("/lib/core/boot.lua")(loadfile)
return
end
local gpua = cp.list("gpu")()
local screena = cp.list("screen")()
local gpu = cp.proxy(gpua)
gpu.bind(screena)
gpu.setResolution(22, 2)
gpu.setBackground(0x000000)
gpu.fill(1, 1, 22, 2, ' ')
gpu.set(1, 1, "Press ENTER for Fuchas")
gpu.set(1, 2, "Press O for OpenOS")
while true do
local id, _, _, ch = computer.pullSignal()
if id == "key_down" then
if ch == 28 then
_G.loadfile = loadfile
loadfile("Fuchas/Kernel/boot.lua")()
break
elseif ch == 24 then
loadfile("/lib/core/boot.lua")(loadfile)
-- OpenOS's shell behavior
while true do
local result, reason = xpcall(require("shell").getShell(), function(msg)
return tostring(msg).."\n"..debug.traceback()
end)
if not result then
io.stderr:write((reason ~= nil and tostring(reason) or "unknown error") .. "\n")
io.write("Press any key to continue.\n")
require("event").pull("key_down")
end
end
end
end
end