1
1
mirror of https://git.shadowkat.net/izaya/OC-PsychOS2.git synced 2024-11-25 12:42:10 -05:00

fuck this shit

This commit is contained in:
XeonSquared 2019-10-27 02:40:25 +11:00
parent 2e3907abd3
commit 824c443629
8 changed files with 5 additions and 261 deletions

View File

@ -1,19 +0,0 @@
local ts = {}
for a,_ in component.list("screen") do
ts[#ts+1] = a
end
local ttyn = 0
for a,_ in component.list("gpu") do
local r,w = vtemu(a,table.remove(ts,1))
-- fd[#fd+1] = {["read"]=r,["write"]=w,["close"]=function() w("\27[2J\27[H") end,["t"]="t"}
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

View File

@ -1,51 +0,0 @@
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/") or {}) 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
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

View File

@ -1,3 +1,7 @@
--#include "module/sched.lua"
--#include "module/buffer.lua"
--#include "module/fs.lua"
--#include "module/loadfile.lua"
os.spawn(function() print(pcall(function()
print(_OSVERSION,tostring(math.floor(computer.totalMemory()/1024)).."K memory")
os.setenv("PWD","/boot")

View File

@ -1,65 +0,0 @@
do
_G.fd,_G.io = {},{}
function io.write(d) -- writes *d* to stdout
fd[os.getenv("t") or 1].write(d)
end
function io.read(d,b) -- reads *d* from stdin, until something is returned, or b is true
local r = ""
repeat
r=fd[os.getenv("t") or 1].read(d)
coroutine.yield()
until r or b
return r
end
function print(...) -- outputs its arguments to stdout, separated by newlines
for k,v in pairs({...}) do
io.write(tostring(v).."\n")
end
end
local function fdw(f,d)
fd[f.fd].write(d)
end
local function fdr(f,d)
return fd[f.fd].read(d)
end
local function fdc(f)
fd[f.fd].close()
fd[f.fd] = nil
end
function io.newfd() -- creates a new file descriptor and returns it plus its ID
local nfd=#fd+1
fd[nfd] = {}
return nfd,fd[nfd]
end
local function fdfile(f,m) -- create a fd from a file
local e,fobj = pcall(fs.open,f,m)
if e and fobj then
local fdi, fdo =io.newfd()
if fobj.read then
function fdo.read(d)
return fobj:read(d)
end
end
if fobj.write then
function fdo.write(d)
return fobj:write(d)
end
end
function fdo.close()
fobj:close()
end
return fdi
end
return false
end
function io.open(f,m) -- opens file or file descriptor *f* with mode *m*
if type(f) == "string" then
f = fdfile(f,m)
end
if fd[f] then
local t = {["close"]=fdc,["read"]=fdr,["write"]=fdw,["fd"]=f,["mode"]=m}
return t
end
return false
end
end

View File

@ -1,64 +0,0 @@
iofs = {}
iofs.files = {}
iofs.fds = {}
iofs.nextfd = 0
iofs.component = {}
local function rfalse()
return false
end
function iofs.component.getLabel()
return "iofs"
end
iofs.component.spaceUsed, iofs.component.spaceTotal, iofs.component.isReadOnly, iofs.component.isDirectory,iofs.component.size, iofs.component.setLabel = function() return computer.totalMemory()-computer.freeMemory() end, computer.totalMemory, rfalse, rfalse, rfalse, rfalse
function iofs.component.exists(fname)
return iofs.files[fname] ~= nil
end
function iofs.component.list()
local t = {}
for k,v in pairs(iofs.files) do
t[#t+1] = k
end
return t
end
function iofs.component.open(fname, mode)
fname=fname:gsub("/","")
if iofs.files[fname] then
local r,w,c,s = iofs.files[fname](mode)
iofs.fds[iofs.nextfd] = {["read"]=r or rfalse,["write"]=w or rfalse,["seek"]=s or rfalse,["close"]=c or rfalse}
iofs.nextfd = iofs.nextfd + 1
return iofs.nextfd - 1
end
return false
end
function iofs.component.read(fd,count)
if iofs.fds[fd] then
return iofs.fds[fd].read(count)
end
end
function iofs.component.write(fd,data)
if iofs.fds[fd] then
return iofs.fds[fd].write(data)
end
end
function iofs.component.close(fd)
if iofs.fds[fd] then
iofs.fds[fd].close()
end
iofs.fds[fd] = nil
end
function iofs.component.seek(fd,...)
if iofs.fds[fd] then
return iofs.fds[fd].seek(...)
end
end
function iofs.register(fname,fopen) -- Register a new iofs node with the name *fname* that will run the function *fopen* when opened. This function should return a function for read, a function for write, function for close, and optionally, a function for seek, in that order.
iofs.files[fname] = fopen
end
fs.mounts.iofs = iofs.component

View File

@ -7,7 +7,7 @@ end
function runfile(p,...) -- runs file *p* with arbitrary arguments in the current thread
return loadfile(p)(...)
end
function spawnfile(p,n) -- spawns a new process from file *p* with name *n*
function os.spawnfile(p,n) -- spawns a new process from file *p* with name *n*
return os.spawn(function() print(pcall(loadfile(p))) end,n)
end
function require(f) -- searches for a library with name *f* and returns what the library returns, if possible

View File

@ -1,16 +0,0 @@
os.spawn(function()
print(_OSVERSION,tostring(computer.totalMemory()/1024).."K memory")
for k,v in pairs(fd) do
if v.t == "t" then
os.setenv("t") = k
print("Spawning Lua prompt for "..tostring(k))
os.setenv("PWD","/boot")
os.spawn(function() print(pcall(function() while true do
io.write(_VERSION.."> ")
tResult = {pcall(load(io.read()))}
for k,v in pairs(tResult) do
print(v)
end
end end)) end,"lua prompt")
end
end end,"init")

View File

@ -1,45 +0,0 @@
function vtemu(gpua,scra)
local gpu,scr = component.proxy(gpua),component.proxy(scra)
gpu.bind(scra)
local write = vt100emu(gpu)
local kba = {}
for k,v in ipairs(scr.getKeyboards()) do
kba[v]=true
end
local buf = ""
os.spawn(function()
while true do
local ty,ka,ch = coroutine.yield()
if ty == "key_down" and kba[ka] then
if ch == 13 then ch = 10 end
if ch == 8 then
if buf:len() > 0 then
write("\8 \8")
buf = buf:sub(1,-2)
end
elseif ch > 0 then
write(string.char(ch))
buf = buf .. string.char(ch)
end
end
end
end,"keyboard daemon for "..gpua:sub(1,8)..":"..scra:sub(1,8))
local function read(n)
n = n or "\n"
local rdata = ""
if type(n) == "number" then
rdata = buf:sub(1,n)
return rdata
else
if n == "*a" then
rdata = buf
buf = ""
return rdata
end
local pr,po = buf:match("(.-)"..n.."(.*)")
buf = po or buf
return pr
end
end
return read,write
end