forked from izaya/LuPPC
Implement eeprom component
This commit is contained in:
parent
e6f07e6cb6
commit
7d5a223f85
@ -3,6 +3,8 @@
|
||||
extern char lua_boot[];
|
||||
extern char lua_component[];
|
||||
extern char lua_computer[];
|
||||
extern char lua_eepromDefault[];
|
||||
extern char lua_eeprom[];
|
||||
extern char lua_init[];
|
||||
extern char lua_sandbox[];
|
||||
extern char lua_textgpu[];
|
||||
|
@ -11,6 +11,8 @@ void setup_modules(lua_State *L) {
|
||||
pushstuple(L, "boot", lua_boot);
|
||||
pushstuple(L, "component", lua_component);
|
||||
pushstuple(L, "computer", lua_computer);
|
||||
pushstuple(L, "eeprom", lua_eeprom);
|
||||
pushstuple(L, "eepromDefault", lua_eepromDefault);
|
||||
pushstuple(L, "sandbox", lua_sandbox);
|
||||
pushstuple(L, "textgpu", lua_textgpu);
|
||||
pushstuple(L, "color", lua_util_color);
|
||||
|
@ -6,10 +6,24 @@ function boot.boot()
|
||||
print("r= " .. tostring(w) .. " " .. tostring(h))
|
||||
gpu.fill(0, 0, w, h, " ")
|
||||
gpu.set(10, 5, "HHHHHHHHHHHHH")
|
||||
gpu.set(11, 11, "VVVVVVVVVVVVVVVVV", true)
|
||||
print("LuPI L2 INIT")
|
||||
print("FIXME: boot stub")
|
||||
native.sleep(1000000)
|
||||
error("Unable to boot")
|
||||
|
||||
local code = modules.component.api.invoke(modules.component.api.list("eeprom", true)(), "get")
|
||||
if not code then
|
||||
print("No bootcode")
|
||||
error("No bootcode")
|
||||
end
|
||||
---PASS SANDBOX!!!!!!
|
||||
local f, reason = load(code, "=BIOS")
|
||||
if not f then
|
||||
print(reason)
|
||||
else
|
||||
f()
|
||||
print("System quit, Panic")
|
||||
end
|
||||
end
|
||||
|
||||
return boot
|
||||
|
68
src/lua/core/eeprom.lua
Normal file
68
src/lua/core/eeprom.lua
Normal file
@ -0,0 +1,68 @@
|
||||
local eeprom = {}
|
||||
local default = moduleCode["eepromDefault"]
|
||||
local size = 4092
|
||||
local dataSize = 256
|
||||
|
||||
function eeprom.register()
|
||||
local component = {}
|
||||
function component.get()
|
||||
local h = io.open("usereeprom.lua", "r")
|
||||
if h then
|
||||
local data = h:read("*a")
|
||||
h:close()
|
||||
return data
|
||||
else
|
||||
return default
|
||||
end
|
||||
end
|
||||
function component.set(data)
|
||||
checkArg(1, data, "string")
|
||||
data = data:sub(1, size)
|
||||
local h = io.open("usereeprom.lua", "w")
|
||||
if not h then
|
||||
error("Critical: Cannot open EERPOM file")
|
||||
end
|
||||
h:write(data)
|
||||
h:close()
|
||||
end
|
||||
function component.getLabel()
|
||||
return "LUA BIOS"
|
||||
end
|
||||
function component.setLabel()
|
||||
return nil, "Cannot set label"
|
||||
end
|
||||
function component.getSize()
|
||||
return size
|
||||
end
|
||||
function component.getData()
|
||||
local h = io.open("usereepromdata.lua", "r")
|
||||
if h then
|
||||
local data = h:read("*a")
|
||||
h:close()
|
||||
return data
|
||||
else
|
||||
return default
|
||||
end
|
||||
end
|
||||
function component.setData(data)
|
||||
checkArg(1, data, "string")
|
||||
data = data:sub(1, dataSize)
|
||||
local h = io.open("usereepromdata.lua", "w")
|
||||
if not h then
|
||||
error("Critical: Cannot open EERPOM file")
|
||||
end
|
||||
h:write(data)
|
||||
h:close()
|
||||
end
|
||||
|
||||
--FIXME: Implement
|
||||
function component.getChecksum()
|
||||
error("Method stub")
|
||||
end
|
||||
function component.makeReadonly()
|
||||
return false, "Method stub"
|
||||
end
|
||||
modules.component.api.register(nil, "eeprom", component)
|
||||
end
|
||||
|
||||
return eeprom
|
61
src/lua/core/eepromDefault.lua
Normal file
61
src/lua/core/eepromDefault.lua
Normal file
@ -0,0 +1,61 @@
|
||||
local component_invoke = component.invoke
|
||||
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 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("no bootable medium found" .. (reason and (": " .. tostring(reason)) or ""), 0)
|
||||
end
|
||||
computer.beep(1000, 0.2)
|
||||
init()
|
@ -41,6 +41,7 @@ loadModule("color")
|
||||
loadModule("component")
|
||||
loadModule("computer")
|
||||
|
||||
loadModule("eeprom")
|
||||
loadModule("textgpu")
|
||||
|
||||
loadModule("sandbox")
|
||||
@ -50,5 +51,7 @@ loadModule("boot")
|
||||
modules.component.prepare()
|
||||
modules.computer.prepare()
|
||||
|
||||
modules.eeprom.register()
|
||||
modules.textgpu.start()
|
||||
|
||||
modules.boot.boot()
|
||||
|
Loading…
Reference in New Issue
Block a user