-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcode.lua
113 lines (108 loc) · 2.92 KB
/
code.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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
-- 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)
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.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 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("no bootable medium found Insert Boot Media Or select Correct Boot Device" .. (reason and (": " .. tostring(reason)) or ""), 0)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
computer.beep(1000, 0.2)
local computer = require("computer")
local tty = require("tty")
tty.clear()
computer.shutdown()
end
computer.beep(1000, 0.2)
end
init()