From 6c4518011906b8b2025de0dbc6b592915ee4f8db Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Sun, 28 Jul 2019 19:09:12 +1000 Subject: [PATCH] wrote a more flexible terminal creation system --- build.sh | 2 +- module/dispmanager.lua | 52 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 module/dispmanager.lua diff --git a/build.sh b/build.sh index 752efce..c9ef01b 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash mkdir build cd module -cat sched.lua syslog.lua vt100.lua fs.lua iofs.lua loadfile.lua vt-task.lua io.lua createterms.lua init.lua > ../build/psychos.lua +cat sched.lua syslog.lua vt100.lua fs.lua iofs.lua loadfile.lua vt-task.lua io.lua dispmanager.lua init.lua > ../build/psychos.lua cd .. echo '_OSVERSION="PsychOS 2.0a0"' >> build/* echo sched\(\) >> build/* diff --git a/module/dispmanager.lua b/module/dispmanager.lua new file mode 100644 index 0000000..3ef5f05 --- /dev/null +++ b/module/dispmanager.lua @@ -0,0 +1,52 @@ +do +local tG,ttyn = {}, 0 + +local function checkUnused(addr) -- returns false if a screen *addr* is already allocated to a GPU + for k,v in pairs(tG) do + if v == addr then + return false + end + end + return true +end +local function findNextDisplay() -- finds the next available screen, or nil if there are no available screens + for a,_ in component.list("screen") do + if checkUnused(a) then + return a + end + end + return nil +end + +for file in ipairs(fs.list("/boot/cfg/disp/")) do -- allows files in /boot/cfg/disp with filenames as GPU addresses to bind to specific screens + if component.proxy(file) then + local f = io.open("/boot/cfg/disp/"..file) + if f then + local sA = file:read() + if checkUnused(sA) then + tG[file] = sA + end + f:close() + end + end +end + +for a,_ in component.list("gpu") do -- allocate a screen to every unused GPU + tG[a] = findNextDisplay() +end + +for gpu,screen in pairs(tG) do + dprint(gpu,screen) + local r,w = vtemu(gpu,screen) + iofs.register("tty"..tostring(ttyn),function() return r,w,function() w("\27[2J\27[H") end end) + local f = io.open("/iofs/tty"..tostring(ttyn),"rw") + fd[f.fd].t = "t" + ttyn = ttyn + 1 +end +do + iofs.register("syslog",function() return function() return "" end, function(msg) syslog(msg,nil,tTasks[cPid].n) end, function() return true end end) +end +if #fd < 1 then + io.open("/iofs/syslog","rw") +end +end