Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component_invoke = component.invoke
- local component = component
- local computer = computer
- local unicode = unicode
- function boot_invoke(address, method, ...)
- local result = table.pack(pcall(component_invoke, address, method, ...))
- if not result[1] then
- return nil, result[2]
- else
- return table.unpack(result, 2, result.n)
- end
- end
- -- backwards compatibility, may remove later
- local eeprom = component.list("eeprom")()
- computer.getBootAddress = function()
- return boot_invoke(eeprom, "getData")
- end
- computer.setBootAddress = function(address)
- return boot_invoke(eeprom, "setData", address)
- end
- do
- local gpu = component.list("gpu", true)()
- local w, h
- if gpu and screen then
- component.invoke(gpu, "bind", screen)
- w, h = component.invoke(gpu, "getResolution")
- component.invoke(gpu, "setResolution", w, h)
- component.invoke(gpu, "setBackground", 0x000000)
- component.invoke(gpu, "setForeground", 0xCC0C0C)
- component.invoke(gpu, "fill", 1, 1, w, h, " ")
- end
- local y = 1
- local function status(msg)
- if gpu and screen then
- component.invoke(gpu, "set", 1, y, msg)
- if y == h then
- component.invoke(gpu, "copy", 1, 2, w, h - 1, 0, -1)
- component.invoke(gpu, "fill", 1, h, w, 1, " ")
- else
- y = y + 1
- end
- end
- end
- component.invoke(gpu, "set", 1, 1, "███ █ █ ███ ██ ███ ███ █ ██ ")
- component.invoke(gpu, "set", 1, 2, "██ ██ █ █ █ ██ ██ █ █ █")
- component.invoke(gpu, "set", 1, 3, "███ █ █ ███ ██ ███ █ █ █ █ █")
- computer.beep(20, 3.5)
- component.invoke(gpu, "set", 1, 5, "Booting in 3,")
- computer.beep(20, 1)
- component.invoke(gpu, "set", 1, 5, "Booting in 2,")
- computer.beep(20, 1)
- component.invoke(gpu, "set", 1, 5, "Booting in 1,")
- computer.beep(20, 1)
- component.invoke(gpu, "set", 1, 5, "Booting in 0,")
- end
- local function tryLoadFrom(address)
- local handle, reason = boot_invoke(address, "open", "/init.lua")
- if not handle then
- return nil, reason
- end
- local buffer = ""
- repeat
- local data, reason = boot_invoke(address, "read", handle, math.huge)
- if not data and reason then
- return nil, reason
- end
- buffer = buffer .. (data or "")
- until not data
- boot_invoke(address, "close", handle)
- return load(buffer, "=init")
- end
- local init, reason
- if computer.getBootAddress() then
- init, reason = tryLoadFrom(computer.getBootAddress())
- end
- if not init then
- computer.setBootAddress()
- for address in component.list("filesystem") do
- init, reason = tryLoadFrom(address)
- if init then
- computer.setBootAddress(address)
- break
- end
- end
- end
- if not init then
- error("FATAL: No bootable medium found." .. (reason and (": " .. tostring(reason)) or ""), 0)
- end
- computer.beep(1000, 0.2)
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement