add basic kernel
This commit is contained in:
parent
e089223284
commit
041a6d0ded
1 changed files with 115 additions and 0 deletions
115
raven.lua
Normal file
115
raven.lua
Normal file
|
@ -0,0 +1,115 @@
|
|||
_G._KERNEL_VERSION = "0.1.0"
|
||||
_G._KERNEL_NAME = "Raven"
|
||||
_G.raven = {}
|
||||
_G._OS_INFO = "Raven kernel operating system"
|
||||
_G._OS_VERSION = 0
|
||||
|
||||
colors = {}
|
||||
colors.white = 1
|
||||
colors.orange = 2
|
||||
colors.magenta = 4
|
||||
colors.lightBlue = 8
|
||||
colors.yellow = 16
|
||||
colors.lime = 32
|
||||
colors.pink = 64
|
||||
colors.gray = 128
|
||||
colors.lightGray = 256
|
||||
colors.cyan = 512
|
||||
colors.purple = 1024
|
||||
colors.blue = 2048
|
||||
colors.brown = 4096
|
||||
colors.green = 8192
|
||||
colors.red = 16384
|
||||
colors.black = 32768
|
||||
|
||||
colours = {}
|
||||
setmetatable(colours, {__index = colors})
|
||||
colours.grey = colors.gray
|
||||
colours.lightGrey = colors.lightGray
|
||||
|
||||
term.clear()
|
||||
term.setCursorPos(1, 1)
|
||||
print("Raven kernel " .. _G._KERNEL_VERSION .. " booting.")
|
||||
|
||||
if _G._FEATHER_VERSION or _G._PELICAN_VERSION then
|
||||
print("Removing S1 and S2 version numbers from the env.")
|
||||
_G._FEATHER_VERSION = nil
|
||||
_G._PELICAN_VERSION = nil
|
||||
end
|
||||
|
||||
print("Initalising error handler.")
|
||||
function raven.writeColour(colour, text)
|
||||
local precolour = term.getTextColour()
|
||||
term.setTextColour(colour)
|
||||
write(text)
|
||||
term.setTextColour(precolour)
|
||||
return
|
||||
end
|
||||
|
||||
function raven.writeColor(color, text)
|
||||
raven.writeColour(color, text)
|
||||
return
|
||||
end
|
||||
|
||||
function error(e)
|
||||
raven.writeColour(0x4000, "An error has occured: ")
|
||||
term.setTextColour(0x1)
|
||||
if e then
|
||||
write(e .. "\n")
|
||||
else
|
||||
write("Undefined error." .. "\n")
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
print("Initialising benign API functions.")
|
||||
function raven.fullTermClear()
|
||||
term.clear()
|
||||
term.setCursorPos(1, 1)
|
||||
end
|
||||
|
||||
print("Initialising execution functions.")
|
||||
function raven.run(path, env, ...)
|
||||
local _ARGS = {...}
|
||||
env._ARGS = _ARGS
|
||||
local file, e = loadfile(path, env)
|
||||
if file then
|
||||
file()
|
||||
return true
|
||||
else
|
||||
error(e)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function raven.exec(path, ...)
|
||||
local sandbox = {}
|
||||
setmetatable(sandbox, {__index = _G})
|
||||
if raven.run(path, sandbox, ...) then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
print("Loading kernel configuration.")
|
||||
dofile(fs.combine(_G._KERNEL_ROOT, "/boot/raven.conf.lua"))
|
||||
|
||||
if _G._SHELL then
|
||||
print("Executing shell.")
|
||||
dofile(fs.combine(_G._KERNEL_ROOT, _G._SHELL))
|
||||
else
|
||||
print("Shell not defined in configuration file.")
|
||||
print("Entering basic kernel-level shell.")
|
||||
print("Programs can be executed with the direct path.")
|
||||
print("Programs will most likely exist within /bin/.")
|
||||
while true do
|
||||
write("> ")
|
||||
local exec = read()
|
||||
if fs.exists(fs.combine(_G._KERNEL_ROOT, exec)) and not fs.isDir(fs.combine(_G._KERNEL_ROOT, exec)) then
|
||||
raven.exec(fs.combine(_G._KERNEL_ROOT, exec))
|
||||
else
|
||||
error("Program not found.")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue