testing version of LuaBIOS and OpenOS

people were having issues getting them to work so now we promote consistency
This commit is contained in:
2025-06-28 20:41:49 +02:00
parent 8210e20939
commit 687cfebd00
182 changed files with 14016 additions and 1 deletions

View File

@@ -0,0 +1,131 @@
local comp = require("component")
local text = require("text")
local dcache = {}
local pcache = {}
local adapter_pwd = "/lib/core/devfs/adapters/"
local adapter_api = {}
function adapter_api.toArgsPack(input, pack)
local split = text.split(input, {"%s"}, true)
local req = pack[1]
local num = #split
if num < req then return nil, "insufficient args" end
local result = {n=num}
for index=1,num do
local typename = pack[index+1]
local token = split[index]
if typename == "boolean" then
if token ~= "true" and token ~= "false" then return nil, "bad boolean value" end
token = token == "true"
elseif typename == "number" then
token = tonumber(token)
if not token then return nil, "bad number value" end
end
result[index] = token
end
return result
end
function adapter_api.createWriter(callback, ...)
local types = table.pack(...)
return function(input)
local args, why = adapter_api.toArgsPack(input, types)
if not args then return why end
return callback(table.unpack(args, 1, args.n))
end
end
function adapter_api.create_toggle(read, write, switch)
return
{
read = read and function() return tostring(read()) end,
write = write and function(value)
value = text.trim(tostring(value))
local on = value == "1" or value == "true"
local off = value == "0" or value == "false"
if not on and not off then
return nil, "bad value"
end
if switch then
(off and switch or write)()
else
write(on)
end
end
}
end
function adapter_api.make_link(list, addr, prefix, bOmitZero)
prefix = prefix or ""
local zero = bOmitZero and "" or "0"
local id = 0
local name
repeat
name = string.format("%s%s", prefix, id == 0 and zero or tostring(id))
id = id + 1
until not list[name]
list[name] = {link=addr}
end
return
{
components =
{
list = function()
local dirs = {}
local types = {}
local labels = {}
local ads = {}
dirs["by-type"] = {list=function()return types end}
dirs["by-label"] = {list=function()return labels end}
dirs["by-address"] = {list=function()return ads end}
-- first sort the addr, primaries first, then sorted by address lexigraphically
local hw_addresses = {}
for addr,type in comp.list() do
local isPrim = comp.isPrimary(addr)
table.insert(hw_addresses, select(isPrim and 1 or 2, 1, {type,addr}))
end
for _,pair in ipairs(hw_addresses) do
local type, addr = table.unpack(pair)
if not dcache[type] then
local adapter_file = adapter_pwd .. type .. ".lua"
local loader = loadfile(adapter_file, "bt", _G)
dcache[type] = loader and loader(adapter_api)
end
local adapter = dcache[type]
if adapter then
local proxy = pcache[addr] or comp.proxy(addr)
pcache[addr] = proxy
ads[addr] =
{
list = function()
local devfs_proxy = adapter(proxy)
devfs_proxy.address = {proxy.address}
devfs_proxy.slot = {proxy.slot}
devfs_proxy.type = {proxy.type}
devfs_proxy.device = {device=proxy}
return devfs_proxy
end
}
-- by type building
local type_dir = types[type] or {list={}}
adapter_api.make_link(type_dir.list, "../../by-address/"..addr)
types[type] = type_dir
-- by label building (labels are only supported in filesystems
local label = require("devfs").getDeviceLabel(proxy)
if label then
adapter_api.make_link(labels, "../by-address/"..addr, label, true)
end
end
end
return dirs
end
},
}

View File

@@ -0,0 +1,57 @@
return
{
eeprom =
{
link = "components/by-type/eeprom/0/contents",
isAvailable = function()
local comp = require("component")
return comp.list("eeprom")()
end
},
["eeprom-data"] =
{
link = "components/by-type/eeprom/0/data",
isAvailable = function()
local comp = require("component")
return comp.list("eeprom")()
end
},
null =
{
open = function()
return
{
read = function() end,
write = function() end
}
end
},
random =
{
open = function(mode)
if mode and not mode:match("r") then
return nil, "read only"
end
return
{
read = function(_, n)
local chars = {}
for _=1,n do
table.insert(chars,string.char(math.random(0,255)))
end
return table.concat(chars)
end
}
end
},
zero =
{
open = function()
return
{
read = function(_, n) return ("\0"):rep(n) end,
write = function() end
}
end
},
}

View File

@@ -0,0 +1,9 @@
local adapter_api = ...
return function(proxy)
return
{
beep = {write=adapter_api.createWriter(proxy.beep, 0, "number", "number")},
running = adapter_api.create_toggle(proxy.isRunning, proxy.start, proxy.stop),
}
end

View File

@@ -0,0 +1,22 @@
local cache = {}
local function cload(callback)
local c = cache[callback]
if not c then
c = callback()
cache[callback] = c
end
return c
end
return function(proxy)
return
{
contents = {read=proxy.get, write=proxy.set},
data = {read=proxy.getData, write=proxy.setData},
checksum = {read=proxy.getChecksum,size=function() return 8 end},
size = {cload(proxy.getSize)},
dataSize = {cload(proxy.getDataSize)},
label = {write=proxy.setLabel,proxy.getLabel()},
makeReadonly = {write=proxy.makeReadonly}
}
end

View File

@@ -0,0 +1,25 @@
local fs = require("filesystem")
local text = require("text")
return function(proxy)
return
{
["label"] =
{
read = function() return proxy.getLabel() or "" end,
write= function(v) proxy.setLabel(text.trim(v)) end
},
["isReadOnly"] = {proxy.isReadOnly()},
["spaceUsed"] = {proxy.spaceUsed()},
["spaceTotal"] = {proxy.spaceTotal()},
["mounts"] = {read = function()
local mounts = {}
for mproxy,mpath in fs.mounts() do
if mproxy.address == proxy.address then
table.insert(mounts, mpath)
end
end
return table.concat(mounts, "\n")
end}
}
end

View File

@@ -0,0 +1,17 @@
local adapter_api = ...
return function(proxy)
local screen = proxy.getScreen()
screen = screen and ("../" .. screen)
return
{
viewport = {write = adapter_api.createWriter(proxy.setViewport, 2, "number", "number"), proxy.getViewport()},
resolution = {write = adapter_api.createWriter(proxy.setResolution, 2, "number", "number"), proxy.getResolution()},
maxResolution = {proxy.maxResolution()},
screen = {link=screen,isAvailable=proxy.getScreen},
depth = {write = adapter_api.createWriter(proxy.setDepth, 1, "number"), proxy.getDepth()},
maxDepth = {proxy.maxDepth()},
background = {write = adapter_api.createWriter(proxy.setBackground, 1, "number", "boolean"), proxy.getBackground()},
foreground = {write = adapter_api.createWriter(proxy.setForeground, 1, "number", "boolean"), proxy.getForeground()},
}
end

View File

@@ -0,0 +1,7 @@
return function(proxy)
return
{
httpEnabled = {proxy.isHttpEnabled()},
tcpEnabled = {proxy.isTcpEnabled()},
}
end

View File

@@ -0,0 +1,11 @@
return function(proxy)
return
{
wakeMessage =
{
read = function() return proxy.getWakeMessage() or "" end,
write= function(msg) return proxy.setWakeMessage(msg) end,
},
wireless = {proxy.isWireless()},
}
end

View File

@@ -0,0 +1,18 @@
local adapter_api = ...
return function(proxy)
return
{
["aspectRatio"] = {proxy.getAspectRatio()},
["keyboards"] = {read=function()
local ks = {}
for _,ka in ipairs(proxy.getKeyboards()) do
table.insert(ks, ka)
end
return table.concat(ks, "\n")
end},
["on"] = adapter_api.create_toggle(proxy.isOn, proxy.turnOn, proxy.turnOff), -- turnOn and turnOff
["precise"] = adapter_api.create_toggle(proxy.isPrecise, proxy.setPrecise),
["touchModeInverted"] = adapter_api.create_toggle(proxy.isTouchModeInverted, proxy.setTouchModeInverted),
}
end