Advertisement
Akuukis

Testing

May 12th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.67 KB | None | 0 0
  1. _G._OSVERSION = "OpenLoader 0.1"
  2. local component = component or require('component')
  3. local computer = computer or require('computer')
  4. local unicode = unicode or require('unicode')
  5.  
  6.  
  7. local gpu = component.list("gpu")()
  8. local w, h
  9.  
  10. local screen = component.list('screen')()
  11. for address in component.list('screen') do
  12.     if #component.invoke(address, 'getKeyboards') > 0 then
  13.         screen = address
  14.     end
  15. end
  16.  
  17. local cls = function()end
  18. if gpu and screen then
  19.     component.invoke(gpu, "bind", screen)
  20.     w, h = component.invoke(gpu, "getResolution")
  21.     component.invoke(gpu, "setResolution", w, h)
  22.     component.invoke(gpu, "setBackground", 0x000000)
  23.     component.invoke(gpu, "setForeground", 0xFFFFFF)
  24.     component.invoke(gpu, "fill", 1, 1, w, h, " ")
  25.     cls = function()component.invoke(gpu,"fill", 1, 1, w, h, " ")end
  26. end
  27. local y = 1
  28. local function status(msg)
  29.     if gpu and screen then
  30.         component.invoke(gpu, "set", 1, y, msg)
  31.         if y == h then
  32.             component.invoke(gpu, "copy", 1, 2, w, h - 1, 0, -1)
  33.             component.invoke(gpu, "fill", 1, h, w, 1, " ")
  34.         else
  35.             y = y + 1
  36.         end
  37.     end
  38. end
  39.  
  40. local function loadfile(fs, file)
  41.     --status("> " .. file)
  42.     local handle, reason = component.invoke(fs,"open",file)
  43.     if not handle then
  44.         error(reason)
  45.     end
  46.     local buffer = ""
  47.     repeat
  48.         local data, reason = component.invoke(fs,"read",handle,math.huge)
  49.         if not data and reason then
  50.             error(reason)
  51.         end
  52.         buffer = buffer .. (data or "")
  53.     until not data
  54.     component.invoke(fs,"close",handle)
  55.     return load(buffer, "=" .. file)
  56. end
  57.  
  58. local function dofile(fs, file)
  59.     local program, reason = loadfile(fs, file)
  60.     if program then
  61.         local result = table.pack(pcall(program))
  62.         if result[1] then
  63.             return table.unpack(result, 2, result.n)
  64.         else
  65.             error(result[2])
  66.         end
  67.     else
  68.         error(reason)
  69.     end
  70. end
  71.  
  72. local function boot(kernel)
  73.     status("BOOTING")
  74.     _G.computer.getBootAddress = function()return kernel.address end
  75.     cls()
  76.     dofile(kernel.address, kernel.fpx .. kernel.file)
  77. end
  78.  
  79. status("OpenLoader")
  80. status("Select what to boot:")
  81.  
  82. local osList = {}
  83.  
  84. for fs in component.list("filesystem") do
  85.     if component.invoke(fs, "isDirectory", "boot/kernel/")then
  86.         for _,file in ipairs(component.invoke(fs, "list", "boot/kernel/")) do
  87.             osList[#osList+1] = {fpx = "boot/kernel/", file = file, address = fs}
  88.             status(tostring(#osList).."."..file.." from "..(fs:sub(1,3)))
  89.         end
  90.     end
  91.     if fs ~= computer.getBootAddress() and component.invoke(fs, "exists", "init.lua") then
  92.         local osName = "init.lua"
  93.         if component.invoke(fs, "exists", ".osprop") then
  94.             pcall(function()
  95.                 local prop = dofile(fs, ".osprop")
  96.                 osName = (prop and prop.name) or "init.lua"
  97.             end)
  98.         end
  99.         osList[#osList+1] = {fpx = "", file = "init.lua", address = fs}
  100.         status(tostring(#osList).."."..osName.." from "..(fs:sub(1,3)))
  101.     end
  102. end
  103. status("Select os: ")
  104. if #osList == 1 then
  105.     boot(osList[1])
  106. end
  107. if #osList == 0 then
  108.     error("No OS found")
  109.     while true do computer.pullSignal() end
  110. end
  111. while true do
  112.     local sig = {computer.pullSignal()}
  113.     if sig[1] == "key_down" then
  114.         if sig[4] >= 2 and sig[4] <= 11 then
  115.             if osList[sig[4]-1] then
  116.                 boot(osList[sig[4]-1])
  117.             else
  118.                 status("Not found!")
  119.             end
  120.         end
  121.     end
  122. end
  123. error("System crashed")
  124. while true do computer.pullSignal() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement