oc firmware 1.0
This commit is contained in:
@@ -3,11 +3,14 @@ local gpu=cp.list("gpu")() and cp.proxy(cp.list("gpu")())
|
||||
local e_rom=cp.list("eeprom")() and cp.proxy(cp.list("eeprom")())
|
||||
local screens={}
|
||||
for addr in cp.list("screen") do
|
||||
local w,h=gpu and gpu.maxResolution() or 20,10
|
||||
gpu.setResolution(w,h)
|
||||
gpu.fill(1,1,w,h," ")
|
||||
cp.proxy(addr).turnOn()
|
||||
screens[#screens+1] = {cx=1,cy=1,w=w,h=h,addr=addr}
|
||||
if gpu then
|
||||
gpu.bind(addr)
|
||||
local w,h=gpu.maxResolution()
|
||||
gpu.setResolution(w,h)
|
||||
gpu.fill(1,1,w,h," ")
|
||||
cp.proxy(addr).turnOn()
|
||||
screens[#screens+1] = {cx=1,cy=1,w=w,h=h,addr=addr}
|
||||
end
|
||||
end
|
||||
local function scroll(scr) gpu.copy(1,2,scr.w,scr.h-1,0,-1);gpu.fill(1,scr.h,scr.w,1," ") end
|
||||
local function write(t)
|
||||
@@ -22,7 +25,7 @@ local function write(t)
|
||||
elseif char=="\b" then if scr.cx>1 then scr.cx=scr.cx-1;gpu.set(scr.cx,scr.cy," ") end
|
||||
else gpu.set(scr.cx,scr.cy,char);scr.cx=scr.cx+1 end
|
||||
if scr.cx>scr.w then scr.cx=1;scr.cy=scr.cy+1 end
|
||||
if scr.cy>scr.h then error("executed")scroll(scr);scr.cy=scr.cy-1 end
|
||||
if scr.cy>scr.h then scroll(scr);scr.cy=scr.cy-1 end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -39,11 +42,9 @@ local function throw(err)
|
||||
while true do c.pullSignal() end
|
||||
end
|
||||
local ok,err=xpcall(function()
|
||||
local apis={os={},fs={},peripheral={},term={}}
|
||||
local apis={}
|
||||
local _l={coroutine=1,debug=1,_VERSION=1,assert=1,collectgarbage=1,error=1,getmetatable=1,ipairs=1,load=1,math=1,next=1,pairs=1,pcall=1,rawequal=1,rawget=1,rawlen=1,rawset=1,select=1,setmetatable=1,string=1,table=1,tonumber=1,tostring=1,type=1,xpcall=1,_G=1}
|
||||
for k,v in pairs(_G) do if not _l[k] then apis[k]=v;_G[k]=nil end end
|
||||
apis.os.clock=c.uptime;apis.os.epoch=function()return math.floor(c.uptime()*1000) end
|
||||
apis.os.queueEvent=c.pushSignal
|
||||
function sleep(t) local s=c.uptime()+t;while c.uptime()<s do c.pullSignal(s-c.uptime()) end end
|
||||
local function getFile(path)
|
||||
local h,err=b_fs.open(path,"r")
|
||||
@@ -53,25 +54,25 @@ local ok,err=xpcall(function()
|
||||
b_fs.close(h)
|
||||
return buf
|
||||
end
|
||||
local Kernel=load(getFile("/boot/kernel.lua"),"@Kernel")
|
||||
local initFs=load(getFile("/boot/oc/initdisks"),"@Init_disks")
|
||||
local fs=load(getFile("/boot/initfs"),"@InitFs")
|
||||
local Kernel=load(getFile("/kernel.lua"),"@Kernel")
|
||||
local initFs=load(getFile("/oc/initdisks"),"@Init_disks")
|
||||
local fs=load(getFile("/initfs"),"@InitFs")
|
||||
if not Kernel then throw("Kernel load failed.") end
|
||||
if initFs then initFs=initFs(apis, b_fs, b_addr) end
|
||||
if fs then fs=fs() end
|
||||
local n_addr=cp.list("filesystem")()
|
||||
local eQ={}
|
||||
local function qEv(e,...) table.insert(eQ,{e,...}) end
|
||||
apis.peripheral.getNames=function() local res={};for k in cp.list() do table.insert(res,k) end return res end
|
||||
apis.peripheral.isPresent=function(a) return cp.type(a)~=nil end
|
||||
apis.peripheral.getType=cp.type
|
||||
apis.peripheral.getMethods=cp.methods
|
||||
apis.peripheral.call=cp.invoke
|
||||
local efi={
|
||||
getEpochMs=function() return math.floor(c.uptime()*1000) end,
|
||||
getUptime=function() return c.uptime()*1000 end,
|
||||
date=function() return tostring(apis.os.date()) end,
|
||||
getMachineEvent=function() return #eQ>0 and table.unpack(table.remove(eQ,1)) or nil end,
|
||||
getMachineEvent=function()
|
||||
if #eQ > 0 then
|
||||
return table.unpack(table.remove(eQ, 1))
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end,
|
||||
getEEPROM=function() return e_rom and e_rom.get() or "" end,
|
||||
setEEPROM=function(_,t) if e_rom then e_rom.set(t) end end,
|
||||
getNvram=function() return e_rom and e_rom.getData() or "" end,
|
||||
@@ -86,8 +87,8 @@ local ok,err=xpcall(function()
|
||||
screenCtl={
|
||||
print=function(_,t) write(tostring(t).."\n") end,
|
||||
printInline=function(_,t) write(tostring(t)) end,
|
||||
clear=function() if gpu then gpu.fill(1,1,w,h," ");cx,cy=1,1 end end,
|
||||
resetCursor=function() cx,cy=1,1 end,
|
||||
clear=function() if gpu then for i=1, #screens do local scr=screens[i];gpu.bind(scr.addr);gpu.fill(1,1,scr.w,scr.h," ");scr.cx,scr.cy=1,1 end end end,
|
||||
resetCursor=function() for i=1, #screens do local scr=screens[i];scr.cx,scr.cy=1,1 end end,
|
||||
setBackgroundColor=function(_,cl) if gpu then gpu.setBackground(cl) end end,
|
||||
setTextColor=function(_,cl) if gpu then gpu.setForeground(cl) end end,
|
||||
enable=function() end,
|
||||
@@ -108,10 +109,8 @@ local ok,err=xpcall(function()
|
||||
local ev={c.pullSignal(0)}
|
||||
if ev[1]=="key_down" then qEv("keyPressed",1,ev[3]);qEv("keyTyped",1,string.char(ev[3]))
|
||||
elseif ev[1]=="key_up" then qEv("keyReleased",1,ev[3])
|
||||
elseif ev[1]=="component_added" then qEv("componentAdded",ev[3])
|
||||
elseif ev[1]=="component_removed" then qEv("componentRemoved",ev[3])
|
||||
elseif ev[1]=="modem_message" then qEv("modem_message",table.unpack(ev,2))
|
||||
elseif ev[1]=="NoSleep" then ex=true end
|
||||
end
|
||||
if ev[1]=="NoSleep" then ex=true else qEv(table.unpack(ev)) end
|
||||
end
|
||||
if st=="error" or coroutine.status(kCo)=="dead" then
|
||||
if efi.reboot then c.shutdown(true) end
|
||||
|
||||
Reference in New Issue
Block a user