Advertisement
trapcodien

oc_openloader_bios

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