SHARE
TWEET

bios2 source

The_Puzzlemaker Jan 1st, 2020 (edited) 277 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local init
  2. do
  3.   local component_invoke = component.invoke
  4.   local list = component.list
  5.   local function boot_invoke(address, method, ...)
  6.     local result = table.pack(pcall(component_invoke, address, method, ...))
  7.     if not result[1] then
  8.       return nil, result[2]
  9.     else
  10.       return table.unpack(result, 2, result.n)
  11.     end
  12.   end
  13.   local eeprom = list("eeprom")()
  14.   computer.getBootAddress = function()
  15.     return boot_invoke(eeprom, "getData")
  16.   end
  17.   computer.setBootAddress = function(address)
  18.     return boot_invoke(eeprom, "setData", address)
  19.   end
  20.   local gba = computer.getBootAddress
  21.   local screen = list("screen")()
  22.   local gpu = list("gpu")()
  23.   if gpu and screen then
  24.     boot_invoke(gpu, "bind", screen)
  25.   else
  26.     error("GPU/Screen required")
  27.   end
  28.   local function tryLoadFrom(address)
  29.     local handle, reason = boot_invoke(address, "open", "/init.lua")
  30.     if not handle then
  31.       return nil, reason
  32.     end
  33.     local buffer = ""
  34.     repeat
  35.       local data, reason = boot_invoke(address, "read", handle, math.huge)
  36.       if not data and reason then
  37.         return nil, reason
  38.       end
  39.       buffer = buffer .. (data or "")
  40.     until not data
  41.     boot_invoke(address, "close", handle)
  42.     return load(buffer, "=init")
  43.   end
  44.   local reason
  45.   local validAddresses = {}
  46.   for address in list("filesystem") do
  47.     if boot_invoke(address, "exists", "/init.lua") then
  48.       validAddresses[#validAddresses+1] = address
  49.     end
  50.   end
  51.   if #validAddresses == 0 then
  52.     error("no valid fs found")
  53.   end
  54.   local function tryGetLabel(address)
  55.     local label = boot_invoke(address, "getLabel")
  56.     if label ~= nil and label ~= "" then
  57.       return label
  58.     else
  59.       return "NO LABEL"
  60.     end
  61.   end
  62.   local function printl(addr, pre, k)
  63.     boot_invoke(gpu, "set", 1, k, k .. ": " .. pre .. "[" .. tryGetLabel(addr) .. "] " .. addr);
  64.   end
  65.   local function printAddrs()
  66.     for k,address in ipairs(validAddresses) do
  67.       printl(address, "", k)
  68.     end
  69.   end
  70.   printAddrs()
  71.   while true do
  72.     local evt, addr, char, code, pN = computer.pullSignal()
  73.     if evt == "key_up" then
  74.       local num = tonumber(unicode.char(char))
  75.       if num ~= nil then
  76.         if num >= 1 and num <= #validAddresses then
  77.           printl(validAddresses[num], "[TRYING] ", num)
  78.           init, reason = tryLoadFrom(validAddresses[num])
  79.           if init then
  80.             printl(validAddresses[num], "[BOOTING] ", num)
  81.             computer.setBootAddress(validAddresses[num])
  82.             break
  83.           else
  84.             computer.beep(500, 0.2)
  85.             printl(validAddresses[num], "[INVALID] ", num)
  86.           end
  87.         end
  88.       end
  89.     end
  90.   end
  91.   computer.beep(1000, 0.2)
  92. end
  93. init()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top