Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cinv = component.invoke
- function binv(address, method, ...)
- local result = table.pack(pcall(cinv, address, method, ...))
- if not result[1] then
- return nil, result[2]
- else
- return table.unpack(result, 2, result.n)
- end
- end
- local eeprom = component.list("eeprom")()
- computer.getBootAddress = function()
- return binv(eeprom, "getData")
- end
- computer.setBootAddress = function(address)
- return binv(eeprom, "setData", address)
- end
- do
- local screen = component.list("screen")()
- local gpu = component.list("gpu")()
- if gpu and screen then
- binv(gpu, "bind", screen)
- binv(gpu, "setResolution", 53, 22)
- binv(gpu, "setForeground", 0x00FF00)
- end
- end
- local function tryLoadFrom(address)
- local handle, reason = binv(address, "open", "/init.lua")
- if not handle then
- return nil, reason
- end
- local buffer = ""
- repeat
- local data, reason = binv(address, "read", handle, math.huge)
- if not data and reason then
- return nil, reason
- end
- buffer = buffer .. (data or "")
- until not data
- binv(address, "close", handle)
- return load(buffer, "=init")
- end
- function startsWith(string,start)
- return string.sub(string,1,string.len(start))==start
- end
- local init, reason
- do
- local keyboard = component.list("keyboard")()
- local screen = component.list("screen")()
- local gpu = component.list("gpu")()
- if not keyboard then
- if gpu and screen then
- computer.beep(500, 0.4)
- binv(gpu, "fill", 1, 1, 53, 22, " ")
- binv(gpu, "set", 1, 1, "NO KEYBOARD CONNECTED")
- end
- while true do
- computer.pullSignal()
- end
- else
- local userinput = true
- local keycount = 0
- local useraddr = ""
- if gpu and screen then
- binv(gpu, "fill", 1, 1, 53, 22, " ")
- binv(gpu, "set", 1, 1, "MY BOOTLOADER")
- binv(gpu, "set", 1, 2, "ENTER FS ADDRESS OR LABEL")
- while userinput do
- binv(gpu, "set", 1, 4, ">")
- local name, _, key = computer.pullSignal()
- if name == "key_up" then
- if (key >= 0x30 and key <= 0x39) or (key >= 0x61 and key <= 0x66) or (key >= 0x41 and key <= 0x46) then
- binv(gpu, "set", 3 + keycount, 4, unicode.upper(unicode.char(key)))
- useraddr = useraddr .. unicode.lower(unicode.char(key))
- keycount = keycount + 1
- end
- end
- if keycount == 3 then
- binv(gpu, "set", 1, 6, "TRYING TO BOOT FROM FS " .. unicode.upper(useraddr))
- local addr, _
- for addr, _ in component.list("filesystem") do
- if binv(addr, "getLabel") ~= nil and startsWith(unicode.lower(binv(addr, "getLabel")), useraddr) then
- init, reason = tryLoadFrom(addr)
- if init then
- break
- end
- else
- if startsWith(addr, useraddr) then
- init, reason = tryLoadFrom(addr)
- if init then
- break
- end
- end
- end
- end
- if init then
- userinput = false
- computer.setBootAddress(addr)
- binv(gpu, "set", 1, 7, "SUCCESS, STARTING INIT.LUA...")
- else
- binv(gpu, "set", 1, 7, "FAILURE, UNABLE TO BOOT")
- keycount = 0
- useraddr = ""
- local sTime = computer.uptime()
- while computer.uptime() < sTime + 3 do
- computer.pullSignal(0.5)
- end
- binv(gpu, "fill", 1, 4, 53, 4, " ")
- binv(gpu, "fill", 1, 6, 53, 6, " ")
- binv(gpu, "fill", 1, 7, 53, 7, " ")
- end
- end
- end
- end
- end
- end
- computer.beep(1000, 0.2)
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement