Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local init
- do
- local component_invoke = component.invoke
- local 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
- local function drawCenteredText(text)
- local gpu = component.list("gpu")()
- local w, h = component.invoke(gpu, "getResolution")
- local x = math.floor((w - #text) / 2)
- local y = math.floor(h / 2)
- component.invoke(gpu, "set", x, y, text)
- end
- local function setResolution(width, height)
- local gpu = component.list("gpu")()
- component.invoke(gpu, "setResolution", width, height)
- end
- local function delay(seconds)
- local deadline = computer.uptime() + seconds
- repeat until computer.uptime() >= deadline
- 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 screen = component.list("screen")()
- local gpu = component.list("gpu")()
- if gpu and screen then
- boot_invoke(gpu, "bind", screen)
- setResolution(80, 25) -- Adjust resolution for larger text
- end
- 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.maxinteger or 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 function drawBootMessage()
- local gpu = component.list("gpu")()
- local w, h = component.invoke(gpu, "getResolution")
- component.invoke(gpu, "fill", 1, 1, w, h, " ") -- Clear the screen
- component.invoke(gpu, "setBackground", 0x000000) -- Set background to black
- drawCenteredText("DOGGY CORP")
- end
- local function drawErrorMessage()
- local gpu = component.list("gpu")()
- local w, h = component.invoke(gpu, "getResolution")
- component.invoke(gpu, "fill", 1, 1, w, h, " ") -- Clear the screen
- component.invoke(gpu, "setBackground", 0x000000) -- Set background to black
- drawCenteredText("BIOS failed to locate boot drive!")
- end
- local function runWithoutHalting()
- drawErrorMessage()
- computer.beep(1500, 0.5) -- Longer beep
- delay(0.5) -- Delay after the beep
- for _ = 1, 2 do
- computer.beep(1500, 0.10) -- Beep 2 times quickly
- delay(0.2) -- Delay between beeps
- end
- while true do
- computer.pullSignal(0.5) -- Adjust the delay time as needed
- drawErrorMessage()
- end
- end
- local reason
- drawBootMessage()
- delay(2) -- Wait 2 seconds
- 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
- runWithoutHalting() -- Run the error message without halting the computer
- return
- end
- computer.beep(1000, 0.10)
- end
- return init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement