Imported stuff.
This commit is contained in:
commit
0e269aa894
128
build.lua
Normal file
128
build.lua
Normal file
@ -0,0 +1,128 @@
|
||||
-- Initialization
|
||||
log = ""
|
||||
oldprint=print
|
||||
function print(...)
|
||||
oldprint(...)
|
||||
logline = ""
|
||||
if #{...} > 0 then
|
||||
if #{...} > 1 then
|
||||
for k,v in ipairs({...}) do
|
||||
logline = logline .. "\t" .. tostring(v)
|
||||
end
|
||||
else
|
||||
tA = {...}
|
||||
logline = tostring(tA[1])
|
||||
end
|
||||
end
|
||||
log = (log .. logline .. "\n"):sub(1,-1)
|
||||
end
|
||||
print("Initializing and reading configuration")
|
||||
ts={}
|
||||
tA = {...}
|
||||
ss=""
|
||||
cfg={}
|
||||
f=io.open("build.cfg","rb")
|
||||
repeat
|
||||
line = f:read("*l")
|
||||
if line ~= nil then
|
||||
w={}
|
||||
for wo in line:gmatch("%S+") do table.insert(w, wo) end
|
||||
cfg[w[1]] = w[2]
|
||||
end
|
||||
until line == nil or line == ""
|
||||
if cfg.opath == nil then cfg.opath = "kernel.lua" end
|
||||
print()
|
||||
-- Module list
|
||||
print("Reading modules to load")
|
||||
tm={}
|
||||
f=io.open("modules.cfg","rb")
|
||||
function nl()
|
||||
return f:read("*l")
|
||||
end
|
||||
for line in nl do
|
||||
print(" - "..line)
|
||||
table.insert(tm,line)
|
||||
end
|
||||
f:close()
|
||||
print(tostring(#tm).." modules to load.\n")
|
||||
|
||||
-- Loading modules
|
||||
print("Loading modules")
|
||||
for k,v in ipairs(tm) do
|
||||
print(" - "..v.." - modules/"..v)
|
||||
f=io.open("modules/"..v,"rb")
|
||||
if cfg.optomise == "yes" then
|
||||
data = f:read("*a")
|
||||
else
|
||||
data = "--"..v.."\n"..f:read("*a")
|
||||
end
|
||||
table.insert(ts,data)
|
||||
f:close()
|
||||
end
|
||||
print(tostring(#tm).." modules loaded.\n")
|
||||
|
||||
-- Generate source
|
||||
print("Generating source")
|
||||
for k,v in pairs(ts) do
|
||||
ss=ss..v
|
||||
io.write(".")
|
||||
end
|
||||
print()
|
||||
|
||||
-- Optomise for space
|
||||
if cfg.optomise == "yes" then
|
||||
print("Optomising source")
|
||||
sl=tostring(ss:len())
|
||||
no=0
|
||||
replacements={
|
||||
{" "," "},
|
||||
{"\n ","\n"},
|
||||
{"\n\n","\n"},
|
||||
{" == ","=="},
|
||||
{" ~= ","~="},
|
||||
{" >= ",">="},
|
||||
{" <= ","<="},
|
||||
{" > ",">"},
|
||||
{" < ","<"},
|
||||
{" = ","="},
|
||||
{", ",","},
|
||||
{" %+ ","+"},
|
||||
{" %- ","-"},
|
||||
{" %/ ","/"},
|
||||
{" %* ","*"},
|
||||
{" \n","\n"},
|
||||
}
|
||||
for k,v in ipairs(replacements) do
|
||||
while ss:find(v[1]) ~= nil do
|
||||
ss=ss:gsub(v[1],v[2])
|
||||
io.write(".")
|
||||
no=no+1
|
||||
end
|
||||
end
|
||||
print("\nBefore: "..sl.."\nAfter: "..tostring(ss:len()).."\n"..tostring(no).." optomisations made.\n")
|
||||
end
|
||||
|
||||
-- Output
|
||||
print("Outputting to "..cfg.opath)
|
||||
f=io.open(cfg.opath,"wb")
|
||||
f:write(ss)
|
||||
f:close()
|
||||
print("Total size: "..tostring(ss:len()).."\n")
|
||||
|
||||
-- Check syntax
|
||||
if cfg.test == "yes" then
|
||||
print("Checking for errors...")
|
||||
err={pcall(load,ss)}
|
||||
if err[1] ~= true then
|
||||
print(table.unpack(err))
|
||||
else
|
||||
print("No errors detected by load()")
|
||||
end
|
||||
end
|
||||
|
||||
-- Write log
|
||||
if cfg.log == "yes" then
|
||||
f=io.open("build.log","wb")
|
||||
f:write(log)
|
||||
f:close()
|
||||
end
|
7
modules.cfg
Normal file
7
modules.cfg
Normal file
@ -0,0 +1,7 @@
|
||||
base/header.lua
|
||||
drivers/dterm.lua
|
||||
library/print.lua
|
||||
drivers/keyboard.lua
|
||||
library/net.lua
|
||||
applications/luash.lua
|
||||
base/footer.lua
|
7
modules/applications/luash.lua
Normal file
7
modules/applications/luash.lua
Normal file
@ -0,0 +1,7 @@
|
||||
s("lua shell",function()
|
||||
print(_VERSION)
|
||||
while true do
|
||||
h("display","> ")
|
||||
print(pcall(load(readln())))
|
||||
end
|
||||
end)
|
14
modules/base/footer.lua
Normal file
14
modules/base/footer.lua
Normal file
@ -0,0 +1,14 @@
|
||||
while #tT > 0 do
|
||||
ev={computer.pullSignal(p)}
|
||||
for k,v in ipairs(ev) do
|
||||
-- wl(tostring(v))
|
||||
end
|
||||
for k,v in ipairs(tT) do
|
||||
_G.cT=k
|
||||
if C.status(v[2])~="dead" then
|
||||
C.resume(v[2],table.unpack(ev))
|
||||
else
|
||||
T.remove(tT,k)
|
||||
end
|
||||
end
|
||||
end
|
11
modules/base/header.lua
Normal file
11
modules/base/header.lua
Normal file
@ -0,0 +1,11 @@
|
||||
tT,p,C,T={},1,coroutine,table
|
||||
function s(n,f,e)
|
||||
T.insert(tT,{n,C.create(f),(e or {})})
|
||||
end
|
||||
function l()
|
||||
-- return T.remove(tT[cT][3],1)
|
||||
end
|
||||
function h(...)
|
||||
computer.pushSignal(...)
|
||||
coroutine.yield()
|
||||
end
|
1
modules/bcstart.lua
Normal file
1
modules/bcstart.lua
Normal file
@ -0,0 +1 @@
|
||||
ns(01,computer.address())
|
4
modules/counter.lua
Normal file
4
modules/counter.lua
Normal file
@ -0,0 +1,4 @@
|
||||
function count()
|
||||
for i = 1, 10 do print(i) C.yield() end
|
||||
end
|
||||
s("counter",count)
|
10
modules/debug/debug.lua
Normal file
10
modules/debug/debug.lua
Normal file
@ -0,0 +1,10 @@
|
||||
s("debug thread",function()
|
||||
print(string.format("%." .. 2 .. "f", (computer.totalMemory()/1024)) .. "k memory total")
|
||||
while true do
|
||||
print(string.format("%." .. 2 .. "f", (computer.totalMemory()-computer.freeMemory())/1024).."k memory used; "..tostring(#tT).." running processes; "..tostring(p).." polling delay")
|
||||
for k,v in pairs(tT) do
|
||||
print(tostring(k).." - "..tostring(v[1]))
|
||||
end
|
||||
coroutine.yield()
|
||||
end
|
||||
end)
|
6
modules/debug/heartbeat.lua
Normal file
6
modules/debug/heartbeat.lua
Normal file
@ -0,0 +1,6 @@
|
||||
s("hearbeat",function()
|
||||
while true do
|
||||
computer.beep()
|
||||
C.yield()
|
||||
end
|
||||
end)
|
43
modules/drivers/dterm.lua
Normal file
43
modules/drivers/dterm.lua
Normal file
@ -0,0 +1,43 @@
|
||||
do
|
||||
local gpu, screen = component.list("gpu")(), component.list("screen")()
|
||||
local sw, sh
|
||||
local cx, cy = 1, 1
|
||||
if gpu and screen then
|
||||
gp = component.proxy(gpu)
|
||||
gp.bind(screen)
|
||||
sw, sh = gp.getResolution()
|
||||
gp.setResolution(sw, sh)
|
||||
gp.setBackground(0x000000)
|
||||
gp.setForeground(0xFFFFFF)
|
||||
gp.fill(1, 1, sw, sh, " ")
|
||||
end
|
||||
|
||||
local function cv()
|
||||
if cx > sw then cx,cy=1,cy+1 end
|
||||
if cx < 1 then cx,cy=1,cy-1 end
|
||||
if cy > sh then gp.copy(1,2,sw,sh-1,0,-1) gp.fill(1,sh,sw,1," ") cx,cy=1,sh end
|
||||
end
|
||||
|
||||
function wl(str)
|
||||
if gpu and screen then
|
||||
for c in str:gmatch(".") do
|
||||
if c == "\n" then cy=cy+1 cx=1
|
||||
elseif c == "\f" then cx=1 cy=1 gp.fill(1, 1, sw, sh, " ")
|
||||
elseif c == "\127" then cx=cx-1 gp.set(cx,cy," ")
|
||||
else gp.set(cx,cy,c) cx=cx+1
|
||||
end cv()
|
||||
end
|
||||
end
|
||||
end
|
||||
wl("GPU initialized\n")
|
||||
|
||||
s("display",function()
|
||||
while true do
|
||||
eT = ev
|
||||
if eT[1] == "display" then
|
||||
wl(tostring(eT[2]))
|
||||
end
|
||||
C.yield()
|
||||
end
|
||||
end)
|
||||
end
|
43
modules/drivers/gpu.lua
Normal file
43
modules/drivers/gpu.lua
Normal file
@ -0,0 +1,43 @@
|
||||
do
|
||||
push = h
|
||||
local gpu, screen = component.list("gpu")(), component.list("screen")()
|
||||
local w, h
|
||||
if gpu and screen then
|
||||
gp = component.proxy(gpu)
|
||||
component.invoke(gpu, "bind", screen)
|
||||
w, h = component.invoke(gpu, "getResolution")
|
||||
gp.setResolution(w, h)
|
||||
gp.setBackground(0x000000)
|
||||
gp.setForeground(0xFFFFFF)
|
||||
gp.fill(1, 1, w, h, " ")
|
||||
end
|
||||
local y = 1
|
||||
function wl(msg)
|
||||
if gpu and screen and gp then
|
||||
gp.set(1, y, msg)
|
||||
if y == h then
|
||||
gp.copy(1, 2, w, h - 1, 0, -1)
|
||||
gp.fill(1, h, w, 1, " ")
|
||||
else
|
||||
y = y + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
wl("GPU initialized.")
|
||||
s("display",function(...)
|
||||
while true do
|
||||
eT = ev
|
||||
if table.remove(eT,1) == "display" then
|
||||
for k,v in ipairs(eT) do
|
||||
wl(v)
|
||||
end
|
||||
end
|
||||
coroutine.yield()
|
||||
end
|
||||
end)
|
||||
function sbt(line)
|
||||
gp.set(1,h,tostring(line))
|
||||
end
|
||||
push("display","test")
|
||||
sbt("Test.")
|
||||
end
|
17
modules/drivers/keyboard.lua
Normal file
17
modules/drivers/keyboard.lua
Normal file
@ -0,0 +1,17 @@
|
||||
function readln()
|
||||
local s=""
|
||||
h("display","|")
|
||||
while true do
|
||||
if ev[1] == "key_down" then
|
||||
if ev[3] == 13 then
|
||||
h("display","\127\n") return s
|
||||
elseif ev[3] == 8 then
|
||||
if s:len()>0 then s=s:sub(1,-2) h("display","\127\127|") end
|
||||
elseif ev[3] > 31 and ev[3] < 127 then
|
||||
s=s..string.char(ev[3]) h("display","\127"..string.char(ev[3]).."|")
|
||||
end
|
||||
end
|
||||
C.yield()
|
||||
end
|
||||
end
|
||||
|
7
modules/evout.lua
Normal file
7
modules/evout.lua
Normal file
@ -0,0 +1,7 @@
|
||||
s("evp",function()
|
||||
local evs={l()}
|
||||
if evs ~= nil then
|
||||
ns(T.unpack(evs))
|
||||
end
|
||||
C.yield()
|
||||
end)
|
24
modules/library/net.lua
Normal file
24
modules/library/net.lua
Normal file
@ -0,0 +1,24 @@
|
||||
tM,nP,nID = {}, 4096, 1
|
||||
for a,t in component.list("modem") do
|
||||
table.insert(tM,component.proxy(a))
|
||||
component.proxy(a).open(nP)
|
||||
end
|
||||
function ns(id,po,msg)
|
||||
h("sendmsg",id,po,msg)
|
||||
end
|
||||
s("network daemon",function ()
|
||||
print("Network daemon starting.\nNetwork ID: "..tostring(nID))
|
||||
while true do
|
||||
if ev[1] == "sendmsg" then
|
||||
local eT = ev
|
||||
for k,v in ipairs(tM) do
|
||||
v.broadcast(nP,eT[2],nID,eT[3],eT[4])
|
||||
end
|
||||
elseif ev[1] == "modem_message" then
|
||||
if ev[6] == nID then
|
||||
h("net_msg",ev[7],ev[8],ev[9])
|
||||
end
|
||||
end
|
||||
C.yield()
|
||||
end
|
||||
end)
|
10
modules/library/print.lua
Normal file
10
modules/library/print.lua
Normal file
@ -0,0 +1,10 @@
|
||||
function print(...)
|
||||
for k,v in pairs({...}) do
|
||||
h("display",tostring(v).."\n")
|
||||
end
|
||||
end
|
||||
function write(...)
|
||||
for k,v in pairs({...}) do
|
||||
h("display",tostring(v))
|
||||
end
|
||||
end
|
56
modules/net.lua
Normal file
56
modules/net.lua
Normal file
@ -0,0 +1,56 @@
|
||||
tMn, tMs, tTs, CT, CO = {},{},{},component,computer
|
||||
for m in CT.list("modem") do
|
||||
T.insert(tMs,CT.proxy(m))
|
||||
tMs[#tMs].open(4096)
|
||||
end
|
||||
for m in CT.list("tunnel") do
|
||||
T.insert(tTs,CT.proxy(m))
|
||||
tTs[#tTs].open(4096)
|
||||
end
|
||||
|
||||
function ncs(n)
|
||||
for k,v in ipairs(tMn) do
|
||||
if v == n then return true end
|
||||
end
|
||||
end
|
||||
function grn()
|
||||
repeat
|
||||
mn=math.random(-65536,65535)
|
||||
until not ncs(mn)
|
||||
return mn
|
||||
end
|
||||
function rns(...)
|
||||
for k,m in ipairs(tMs) do
|
||||
m.broadcast(4096,...)
|
||||
end
|
||||
for m in ipairs(tTs) do
|
||||
m.send(4096,...)
|
||||
end
|
||||
end
|
||||
function ns(to,msg)
|
||||
if msg:len() > 4096 then
|
||||
msg=msg:sub(1,4096)
|
||||
end
|
||||
rns(grn(),to,CO.address(),msg)
|
||||
end
|
||||
function netrecv()
|
||||
CO.beep()
|
||||
while true do
|
||||
evtype,_,_,_,_,mn,to,from,msg=l()
|
||||
if evtype == "modem_message" then
|
||||
ns("Debug 1",mn,to,from,msg)
|
||||
if not ncs(mn) then
|
||||
if to == CO.address() then
|
||||
h("net_msg",from,msg)
|
||||
CO.beep()
|
||||
else
|
||||
rns(mn,to,from,msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
C.yield()
|
||||
end
|
||||
end
|
||||
s("netrecv",function()
|
||||
while true do ns(pcall(netrecv)) end
|
||||
end)
|
8
modules/pev.lua
Normal file
8
modules/pev.lua
Normal file
@ -0,0 +1,8 @@
|
||||
function pev()
|
||||
for i = 1, 10 do
|
||||
te=l()
|
||||
print(T.unpack(te))
|
||||
C.yield()
|
||||
end
|
||||
end
|
||||
s("evprint",pev)
|
8
modules/ping.lua
Normal file
8
modules/ping.lua
Normal file
@ -0,0 +1,8 @@
|
||||
s("pingd",function()
|
||||
while true do
|
||||
local evt={l()}
|
||||
if evt[1] == "net_msg" then
|
||||
ns(evt[2],CO.address,"Ping!")
|
||||
end
|
||||
end
|
||||
end)
|
3
modules/reptest.lua
Normal file
3
modules/reptest.lua
Normal file
@ -0,0 +1,3 @@
|
||||
--[[this is test 1]]
|
||||
--[[this is test 2]]
|
||||
this is not test 3 --[[this is test 3]] this is also not test 3
|
1
modules/simplefs.lua
Normal file
1
modules/simplefs.lua
Normal file
@ -0,0 +1 @@
|
||||
fs=component.proxy(computer.tmpAddress())
|
5
testboot.lua
Normal file
5
testboot.lua
Normal file
@ -0,0 +1,5 @@
|
||||
local os = require "os"
|
||||
local computer = require "computer"
|
||||
os.execute("cp /home/kbuild/kernel.lua /tmp/init.lua")
|
||||
computer.setBootAddress(computer.tmpAddress())
|
||||
computer.shutdown(true)
|
Loading…
Reference in New Issue
Block a user