oc firmware 1.0
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
Hyperion
|
||||
Astronand
|
||||
Xtimhedae
|
||||
@@ -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
|
||||
|
||||
@@ -27,7 +27,7 @@ do
|
||||
end
|
||||
end
|
||||
local function tryLoadFrom(address)
|
||||
local handle, reason = boot_invoke(address, "open", "/boot/oc/boot.lua")
|
||||
local handle, reason = boot_invoke(address, "open", "/oc/boot.lua")
|
||||
if not handle then
|
||||
return nil, reason
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ local internal = {}
|
||||
|
||||
local function createDisk(id, hw)
|
||||
local disk = {
|
||||
address = id,
|
||||
address = id,
|
||||
isReadOnly = function() return hw.isReadOnly() end
|
||||
}
|
||||
|
||||
|
||||
@@ -67,23 +67,52 @@ local plt = {
|
||||
|
||||
local gpus,screens = {},{}
|
||||
|
||||
for addr, typ in component.list() do
|
||||
for addr, typ in component.list("gpu") do
|
||||
if typ == "gpu" then
|
||||
gpus[#gpus]=component.proxy(addr)
|
||||
elseif typ == "screen" then
|
||||
screens[addr]={cx=1,cy=1,w=w,h=h}
|
||||
gpus[#gpus+1]=component.proxy(addr)
|
||||
end
|
||||
end
|
||||
|
||||
local binds,newid={},0
|
||||
if #gpus>0 then
|
||||
for addr, typ in component.list("screen") do
|
||||
if typ == "screen" then
|
||||
gpus[1].bind(addr)
|
||||
local w,h = gpus[1].maxResolution()
|
||||
gpus[1].setResolution(w,h)
|
||||
screens[addr]={cx=1,cy=1,w=w,h=h,addr=addr,fg=0,bg=0,gpu=nil}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local scrnum = 0
|
||||
for i,v in pairs(screens) do
|
||||
scrnum=scrnum+1
|
||||
end
|
||||
|
||||
kernel.log("initialized "..tostring(#gpus).." gpus and "..tostring(scrnum).." screens")
|
||||
|
||||
local binds,newid={},0
|
||||
local curaddr=""
|
||||
local function scroll(scr, gpu) gpu.copy(1,2,scr.w,scr.h-1,0,-1);gpu.fill(1,scr.h,scr.w,1," ") end
|
||||
local function write(text, addr)
|
||||
local g=gpus[1]
|
||||
local scr=screens[addr]
|
||||
if not scr then error("NODEV") end
|
||||
if curaddr~=addr then g.bind(addr); g.setForeground(scr.fg); g.setBackground(scr.bg) end
|
||||
for i=1,#text do
|
||||
local char=text:sub(i,i)
|
||||
if char=="\n" then scr.cx=1;scr.cy=scr.cy+1
|
||||
elseif char=="\t" then scr.cx=scr.cx+(4-((scr.cx-1)%4))
|
||||
elseif char=="\b" then if scr.cx>1 then scr.cx=scr.cx-1;g.set(scr.cx,scr.cy," ") end
|
||||
else g.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 scroll(scr, g);scr.cy=scr.cy-1 end
|
||||
end
|
||||
end
|
||||
|
||||
local function newtty(addr)
|
||||
newid=newid+1
|
||||
kernel.devfs.data["tty"][newid]=function(op, mode)
|
||||
kernel.devfs.data["tty"][tostring(newid)]=function(op, mode)
|
||||
if op=="type" then
|
||||
return "Terminal"
|
||||
elseif op=="open" then
|
||||
@@ -93,33 +122,33 @@ local function newtty(addr)
|
||||
write(content, addr)
|
||||
end,
|
||||
size=function()
|
||||
local s={obj.getSize()}
|
||||
return tostring(screens[addr].w)..":"
|
||||
return screens[addr].w, screens[addr].h
|
||||
end,
|
||||
clear=function()
|
||||
obj.clear()
|
||||
obj.setCursorPos(1,1)
|
||||
local g=gpus[1]
|
||||
local scr=screens[addr]
|
||||
if addr~=curaddr then g.bind(addr) end
|
||||
g.fill(1,1,scr.w,scr.h," ");
|
||||
scr.cx,scr.cy=1,1
|
||||
end,
|
||||
gpos=function()
|
||||
local s={obj.getCursorPos()}
|
||||
return table.concat(s,";")
|
||||
return screens[addr].cx, screens[addr].cy
|
||||
end,
|
||||
spos=function(x,y)
|
||||
return obj.setCursorPos(x,y)
|
||||
if not tonumber(x) or not tonumber(y) then error("Invailid arg") end
|
||||
screens[addr].cx, screens[addr].cy = x,y
|
||||
end,
|
||||
sfgc=function(c)
|
||||
fg=c
|
||||
return obj.setTextColor(aprox(c))
|
||||
screens[addr].fg=c
|
||||
end,
|
||||
sbgc=function(c)
|
||||
bg=c
|
||||
return obj.setBackgroundColor(aprox(c))
|
||||
screens[addr].bg=c
|
||||
end,
|
||||
gfgc=function()
|
||||
return fg
|
||||
return screens[addr].fg
|
||||
end,
|
||||
gbgc=function()
|
||||
return bg
|
||||
return screens[addr].bg
|
||||
end,
|
||||
isvirt=function()
|
||||
return false
|
||||
@@ -141,6 +170,8 @@ local function newtty(addr)
|
||||
end
|
||||
end
|
||||
|
||||
if #gpus>=1 and #screens>=1 then
|
||||
|
||||
if #gpus>=1 and scrnum>=1 then
|
||||
for addr,obj in pairs(screens) do
|
||||
newtty(addr)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,113 @@
|
||||
--:Minify:--
|
||||
local kernel=...
|
||||
kernel.oc.keyboards={}
|
||||
local kbs=kernel.oc.keyboards
|
||||
|
||||
local kbidx=0
|
||||
local keyboard = {}
|
||||
|
||||
keyboard.keys = {
|
||||
back = 0x0E, -- backspace
|
||||
delete = 0xD3,
|
||||
down = 0xD0,
|
||||
enter = 0x1C,
|
||||
home = 0xC7,
|
||||
lcontrol = 0x1D,
|
||||
left = 0xCB,
|
||||
lmenu = 0x38, -- left Alt
|
||||
lshift = 0x2A,
|
||||
pageDown = 0xD1,
|
||||
rcontrol = 0x9D,
|
||||
right = 0xCD,
|
||||
rmenu = 0xB8, -- right Alt
|
||||
rshift = 0x36,
|
||||
space = 0x39,
|
||||
tab = 0x0F,
|
||||
up = 0xC8,
|
||||
["end"] = 0xCF,
|
||||
numpadenter = 0x9C,
|
||||
}
|
||||
kernel.oc.keys=keyboard.keys
|
||||
|
||||
for i=0, 255 do
|
||||
kernel.oc.keys[string.char(i)]=i
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
function keyboard.isAltDown(addr)
|
||||
return kbs[addr].pressedCodes[keyboard.keys.lmenu] or kbs[addr].pressedCodes[keyboard.keys.rmenu]
|
||||
end
|
||||
|
||||
function keyboard.isControl(char)
|
||||
return type(char) == "number" and (char < 0x20 or (char >= 0x7F and char <= 0x9F))
|
||||
end
|
||||
|
||||
function keyboard.isControlDown(addr)
|
||||
return kbs[addr].pressedCodes[keyboard.keys.lcontrol] or kbs[addr].pressedCodes[keyboard.keys.rcontrol]
|
||||
end
|
||||
|
||||
function keyboard.isKeyDown(addr,charOrCode)
|
||||
if type(charOrCode) == "string" then
|
||||
return kbs[addr].pressedChars[utf8 and utf8.codepoint(charOrCode) or charOrCode:byte()]
|
||||
elseif type(charOrCode) == "number" then
|
||||
return kbs[addr].pressedCodes[charOrCode]
|
||||
end
|
||||
end
|
||||
|
||||
function keyboard.isShiftDown(addr)
|
||||
return kbs[addr].pressedCodes[keyboard.keys.lshift] or kbs[addr].pressedCodes[keyboard.keys.rshift]
|
||||
end
|
||||
kernel.oc.keyboard=keyboard
|
||||
|
||||
local function serializeBool(bool)
|
||||
if bool then
|
||||
return "T"
|
||||
else
|
||||
return "F"
|
||||
end
|
||||
end
|
||||
|
||||
for addr, typ in kernel.oc.component.list("keyboard") do
|
||||
if typ=="keyboard" then
|
||||
kbidx=kbidx+1
|
||||
kbs[addr]={pressedChars = {}, pressedCodes = {}, events=kernel.newFifo()}
|
||||
kernel.devfs.data["input"]["keyboard"..tostring(kbidx)]=function(op,mode)
|
||||
if op=="type" then
|
||||
return "Keyboard"
|
||||
elseif op=="open" then
|
||||
local h = {
|
||||
read=function(amount)
|
||||
local rv=""
|
||||
for i=1, amount or 1 do
|
||||
local event = {kernel.oc.keyboards[addr].events.pop()}
|
||||
if event[1] then
|
||||
rv=rv..event[1]
|
||||
end
|
||||
end
|
||||
if rv=="" then rv=nil end
|
||||
return rv
|
||||
end,
|
||||
write=function(content)
|
||||
end,
|
||||
gctrl=function()
|
||||
return serializeBool(keyboard.isControlDown(addr))..";"..serializeBool(keyboard.isAltDown(addr))
|
||||
end,
|
||||
isKeyDown=function(char)
|
||||
return keyboard.isKeyDown(addr,char)
|
||||
end
|
||||
}
|
||||
if mode=="rw" then
|
||||
return h
|
||||
elseif mode=="r" then
|
||||
h["write"]=nil
|
||||
return h
|
||||
elseif mode=="w" then
|
||||
h["read"]=nil
|
||||
return h
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
--:Minify:--
|
||||
local kernel=...
|
||||
local keys=kernel.oc.keys
|
||||
|
||||
kernel.processes.ocdaemon = function()
|
||||
|
||||
local timeout = false
|
||||
|
||||
kernel.log("OC daemon started")
|
||||
|
||||
local ctrlKeyMap = {
|
||||
[keys.a]=1, [keys.b]=2, [keys.c]=3,
|
||||
[keys.d]=4, [keys.e]=5, [keys.f]=6,
|
||||
[keys.g]=7, [keys.h]=8, [keys.i]=9,
|
||||
[keys.j]=10, [keys.k]=11, [keys.l]=12,
|
||||
[keys.m]=13, [keys.n]=14, [keys.o]=15,
|
||||
[keys.p]=16, [keys.q]=17, [keys.r]=18,
|
||||
[keys.s]=19, [keys.t]=20, [keys.u]=21,
|
||||
[keys.v]=22, [keys.w]=23, [keys.x]=24,
|
||||
[keys.y]=25, [keys.z]=26,
|
||||
}
|
||||
|
||||
local specialKeyMap = {
|
||||
[keys.up] = "\27[A",
|
||||
[keys.down] = "\27[B",
|
||||
[keys.right] = "\27[C",
|
||||
[keys.left] = "\27[D",
|
||||
[keys.home] = "\27[H",
|
||||
[keys["end"]] = "\27[F",
|
||||
--[keys.pageUp] = "\27[5~",
|
||||
--[keys.pageDown] = "\27[6~",
|
||||
[keys.delete] = "\27[3~",
|
||||
[keys.enter] = "\n",
|
||||
[keys.back] = "\b",
|
||||
[keys.tab] = "\t",
|
||||
}
|
||||
|
||||
while true do
|
||||
|
||||
local event = {kernel.EFI.getMachineEvent()}
|
||||
|
||||
if event[1] then
|
||||
|
||||
local eventType = event[1]
|
||||
local addr = event[2]
|
||||
local char = event[3]
|
||||
local keyCode = event[4]
|
||||
|
||||
if eventType == "key_down" then
|
||||
|
||||
local keyboard = kernel.oc.keyboards[addr]
|
||||
|
||||
if keyboard.ctrl then
|
||||
|
||||
local ctrlByte = ctrlKeyMap[keyCode]
|
||||
|
||||
if ctrlByte then
|
||||
if ctrlByte == 3 then
|
||||
|
||||
for _, task in ipairs(syscall.getTasks()) do
|
||||
syscall.sigsend(task, 1)
|
||||
end
|
||||
|
||||
else
|
||||
keyboard.events.push(string.char(ctrlByte))
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
local special = specialKeyMap[keyCode]
|
||||
|
||||
if special then
|
||||
keyboard.events.push(special)
|
||||
|
||||
elseif char and char > 0 then
|
||||
keyboard.events.push(kernel.apis.unicode.char(char))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
elseif eventType == "key_up" then
|
||||
|
||||
end
|
||||
|
||||
timeout = false
|
||||
|
||||
else
|
||||
timeout = true
|
||||
end
|
||||
|
||||
if timeout then
|
||||
sleep(0.05)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
kernel.log("OC daemon queued for execution")
|
||||
@@ -120,7 +120,10 @@ function kernel.main()
|
||||
end
|
||||
end
|
||||
end
|
||||
kernel.EFI:yield()
|
||||
if kernel.EFI:getEpochMs()>=nextyield then
|
||||
kernel.EFI:yield()
|
||||
nextyield=kernel.EFI:getEpochMs()+5000
|
||||
end
|
||||
end
|
||||
|
||||
local T_prev_avg = (N > 0) and (totalTaskTime / N) or 0
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
firmware for Opencomputers mod
|
||||
@@ -0,0 +1 @@
|
||||
1.0.0
|
||||
Reference in New Issue
Block a user