-
Notifications
You must be signed in to change notification settings - Fork 0
/
eeprom.lua
94 lines (84 loc) · 2.55 KB
/
eeprom.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
local invoke = component.invoke
function boot_invoke(addr, method, ...)
local result = table.pack(pcall(invoke, addr, method, ...))
if not result[1] then
return nil, result[2]
else
return table.unpack(result, 2, result.n)
end
end
-- backwards compability, may remove later
local eeprom = component.list("eeprom")()
computer.getBootAddress = function()
return boot_invoke(eeprom, "getData")
end
computer.setBootAddress = function(addr)
return boot_invoke(eeprom, "setData", addr)
end
do
local screen = component.list("screen")()
local gpu = component.list("gpu")()
local w, h
if gpu and screen then
boot_invoke(gpu, "bind", screen)
component.invoke(gpu, "bind", screen)
w, h = component.invoke(gpu, "maxResolution")
component.invoke(gpu, "setResolution", w, h)
component.invoke(gpu, "setBackground", 0x000000)
component.invoke(gpu, "setForeground", 0xFFFFFF)
component.invoke(gpu, "fill", 1, 1, w, h, " ")
end
end
local y = 1
local function writeln( txt )
if gpu and screen then
component.invoke(gpu, "set", 1, y, txt)
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
local function loadaddr(addr)
local handle, reason = boot_invoke(addr, "open", "/init.lua")
if not handle then
return nil, reason
end
local buffer = ""
repeat
local data, reason = boot_invoke(addr, "read", handle, math.huge)
if not data and reason then
return nil, reason
end
buffer = buffer .. (data or "")
until not data
boot_invoke(addr, "close", handle)
return load(buffer, "=init")
end
writeln("Trying to find boot devices...")
local init, reason
if computer.getBootAddress() then
writeln("Trying '" .. computer.getBootAddress() .. "'")
init, reason = loadaddr(computer.getBootAddress())
end
if not init then
computer.setBootAddress()
for addr in component.list("filesystem") do
writeln("Trying '" .. addr .. "'")
init, reason = loadaddr(addr)
if init then
computer.setBootAddress(addr)
break
end
end
end
if not init then
error("no bootable medium found!")
end
computer.beep(1000,0.2)
writeln("not calling /init.lua ...")
--init()
writeln("quitting...")
error("nobody is perfect.")