oc firmware 1.0
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user