wrote a more flexible terminal creation system

This commit is contained in:
Izaya 2019-07-28 19:09:12 +10:00
parent 12df3de7df
commit 6c45180119
2 changed files with 53 additions and 1 deletions

View File

@ -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/*

52
module/dispmanager.lua Normal file
View File

@ -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