NC firmware update (thanks spsf). opencomputers now uses mutiple gpus to speed up rendering and now has net drivers. currently working on kernel memory protections to prevent malicious kernel drivers. spm does not work on opencomputers, this is a known issue i am working on fixing it :D sorry for the slow development.

This commit is contained in:
Astronand committed 2026-11-04 14:19:15 -05:00
1 parent fbaafc7cff
commit ef4b856ee6
89 files changed
+3955 -563

No files matched your search

@@ -1,4 +1,3 @@
-- OpenComputers TTY driver
local kernel = ...
local component = kernel.oc.component
@@ -26,7 +25,6 @@ local plt = {
0x660000, 0x660040, 0x660080, 0x6600C0, 0x6600FF,
0x662400, 0x662440, 0x662480, 0x6624C0, 0x6624FF,
0x664900, 0x664940, 0x664980, 0x6649C0, 0x6649FF,
0x666D00, 0x666D40, 0x666D80, 0x666DC0, 0x666DFF,
0x669200, 0x669240, 0x669280, 0x6692C0, 0x6692FF,
0x66B600, 0x66B640, 0x66B680, 0x66B6C0, 0x66B6FF,
0x66DB00, 0x66DB40, 0x66DB80, 0x66DBC0, 0x66DBFF,
@@ -65,116 +63,328 @@ local plt = {
0xB4B4B4, 0xC3C3C3, 0xD2D2D2, 0xE1E1E1
}
local gpus,screens = {},{}
local gpus = {}
local screens = {}
-- Collect GPUs.
for addr, typ in component.list("gpu") do
if typ == "gpu" then
gpus[#gpus+1]=component.proxy(addr)
local gpu = component.proxy(addr)
gpus[#gpus + 1] = {
addr = addr,
gpu = gpu,
screen = nil,
fg = nil,
bg = nil
}
end
end
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}
-- Collect screens.
for addr, typ in component.list("screen") do
if typ == "screen" then
screens[addr] = {
cx = 1,
cy = 1,
w = 0,
h = 0,
addr = addr,
fg = 0xFFFFFF,
bg = 0x000000,
gpu = nil
}
end
end
-- Count screens.
local scrnum = 0
for _ in pairs(screens) do
scrnum = scrnum + 1
end
-- Find a GPU that can bind to a screen.
local function bindGPU(scr)
if scr.gpu then
local state = scr.gpu
if state.screen == scr.addr then
return state
end
end
for i = 1, #gpus do
local state = gpus[i]
-- Avoid unnecessary rebinding.
if state.screen == scr.addr then
scr.gpu = state
return state
end
-- Try binding this GPU.
local ok, result = pcall(state.gpu.bind, scr.addr)
if ok and result ~= false then
state.screen = scr.addr
state.fg = nil
state.bg = nil
scr.gpu = state
local w, h = state.gpu.maxResolution()
scr.w = w
scr.h = h
pcall(state.gpu.setResolution, w, h)
return state
end
end
error("No GPU available for screen " .. tostring(scr.addr))
end
-- Initialize screens.
for addr, scr in pairs(screens) do
local ok, result = pcall(bindGPU, scr)
if not ok then
kernel.log(
"Failed to initialize screen " ..
tostring(addr) .. ": " .. tostring(result)
)
end
end
kernel.log(
"initialized " ..
tostring(#gpus) ..
" gpus and " ..
tostring(scrnum) ..
" screens"
)
local newid = 0
-- Get the GPU currently assigned to a screen.
local function getGPU(scr)
local state = scr.gpu
if not state then
state = bindGPU(scr)
end
if state.screen ~= scr.addr then
local ok, result = pcall(state.gpu.bind, scr.addr)
if not ok or result == false then
state.screen = nil
state.fg = nil
state.bg = nil
scr.gpu = nil
state = bindGPU(scr)
else
state.screen = scr.addr
state.fg = nil
state.bg = nil
end
end
return state
end
-- Set colors only when they actually change.
local function setColors(state, scr)
local gpu = state.gpu
if state.fg ~= scr.fg then
gpu.setForeground(scr.fg)
state.fg = scr.fg
end
if state.bg ~= scr.bg then
gpu.setBackground(scr.bg)
state.bg = scr.bg
end
end
-- Scroll terminal.
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
-- Write terminal output.
local function write(text, addr)
local scr = screens[addr]
if not scr then
error("NODEV")
end
local state = getGPU(scr)
local gpu = state.gpu
setColors(state, scr)
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
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
scroll(scr, gpu)
scr.cy = scr.cy - 1
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
-- Create TTY.
local function newtty(addr)
newid=newid+1
kernel.devfs.data["tty"][tostring(newid)]=function(op, mode)
if op=="type" then
newid = newid + 1
kernel.devfs.data["tty"][tostring(newid)] = function(op, mode)
if op == "type" then
return "Terminal"
elseif op=="open" then
elseif op == "open" then
local h = {
read=function(amount) end,
write=function(content)
read = function(amount)
end,
write = function(content)
write(content, addr)
end,
size=function()
return screens[addr].w, screens[addr].h
size = function()
local scr = screens[addr]
return scr.w, scr.h
end,
clear=function()
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
clear = function()
local scr = screens[addr]
local state = getGPU(scr)
local gpu = state.gpu
setColors(state, scr)
gpu.fill(
1, 1,
scr.w, scr.h,
" "
)
scr.cx = 1
scr.cy = 1
end,
gpos=function()
return screens[addr].cx, screens[addr].cy
gpos = function()
local scr = screens[addr]
return scr.cx, scr.cy
end,
spos=function(x,y)
if not tonumber(x) or not tonumber(y) then error("Invailid arg") end
screens[addr].cx, screens[addr].cy = x,y
spos = function(x, y)
if not tonumber(x) or not tonumber(y) then
error("Invalid arg")
end
local scr = screens[addr]
scr.cx = x
scr.cy = y
end,
sfgc=function(c)
screens[addr].fg=c
sfgc = function(c)
local scr = screens[addr]
if scr.fg ~= c then
scr.fg = c
end
end,
sbgc=function(c)
screens[addr].bg=c
sbgc = function(c)
local scr = screens[addr]
if scr.bg ~= c then
scr.bg = c
end
end,
gfgc=function()
gfgc = function()
return screens[addr].fg
end,
gbgc=function()
gbgc = function()
return screens[addr].bg
end,
isvirt=function()
isvirt = function()
return false
end,
gplt=function()
gplt = function()
return plt
end,
gfx=function()
gfx = function()
return false
end
}
if mode=="rw" then
if mode == "rw" then
return h
elseif mode=="r" then
h["write"]=nil
elseif mode == "r" then
h.write = nil
return h
elseif mode=="w" then
h["read"]=nil
elseif mode == "w" then
h.read = nil
return h
end
end
end
end
if #gpus>=1 and scrnum>=1 then
for addr,obj in pairs(screens) do
newtty(addr)
if #gpus >= 1 and scrnum >= 1 then
for addr, scr in pairs(screens) do
if scr.gpu then
newtty(addr)
end
end
end
end