1
0
mirror of https://github.com/XeonSquared/OC-Copper.git synced 2024-11-23 09:58:06 +11:00

Make the network stack slightly smaller and add a generated "just the network stack" output file.

This commit is contained in:
20kdc 2017-04-04 17:41:52 +01:00
parent f6387530a4
commit effb6459a5
4 changed files with 88 additions and 41 deletions

View File

@ -1,7 +1,10 @@
all: uc-rsctl.lua all: uc-rsctl.lua basestack.lua
uc-rsctl.lua: postprocess.lua ecomponents/base ecomponents/relib ecomponents/app-rsctrl uc-rsctl.lua: postprocess.lua ecomponents/base ecomponents/relib ecomponents/app-rsctrl
cat ecomponents/base ecomponents/relib ecomponents/app-rsctrl | lua postprocess.lua > uc-rsctl.lua cat ecomponents/base ecomponents/relib ecomponents/app-rsctrl | lua postprocess.lua > uc-rsctl.lua
basestack.lua: postprocess.lua ecomponents/base ecomponents/relib
cat ecomponents/base ecomponents/relib | lua postprocess.lua > basestack.lua
clean: .PHONY clean: .PHONY
rm -f uc-rsctl.lua rm -f uc-rsctl.lua basestack.lua

51
oc/basestack.lua Normal file
View File

@ -0,0 +1,51 @@
S,C,TC=string,component,"copper"
function CG(n)return C.proxy(C.list(n)())end
TH,TX=CG("eeprom").getLabel(),CG("modem")TX.open(4957)TB=TX.broadcast
function TN(m)if#m<2then return end
local n,t=m:byte(1)+2t=m:sub(n+1)if#t>=n then return m:sub(2,n),m:sub(n+1)end
end
function TR(m)local h,s,m,d=m:byte(),TN(m:sub(2))if s then
d,m=TN(m)if d then
return s,d,m
end
end
end
function TS(d,m)TB(4957,TC,S.char(0,#TH-1)..TH..S.char(#d-1)..d..m)end
R1,R2,R3,R4=0x40,60,12,2.5
RT,RA,RN,RU,R,X={},{},{},computer.uptime,math.random,255
RP,RK,RF=function(f,x)if#RT<R1 then
local t={f,RU()+x}table.insert(RT,t)return t
end
end,function(t)for i=1,#RT do
if t==RT[i]then
table.remove(RT,i)end
end
end,function()local i,t=1,RU()while#RT>i do
if t>RT[i][2]then
table.remove(RT,i)[1]()else
i=i+1
end
end
end
function RC(r,f,t,d)if d and#d>=7then
local p,b,g,k=d:byte(2)+(d:byte(1)*X),d:byte(7),d:sub(1,5)if b==0x01or b==0x00then
k=t..g
if not RA[k] then
r(f,t,p,d:sub(8))else
RK(RA[k])end
RA[k]=RP(function()RA[k]=nil end,R2)if not(b~=0x01or t~=TH)then
TS(f,d:sub(1,6).."\x02")end
end
k=f..g
if b==0x02 and RN[k]then
RK(RN[k])RN[k]=nil
end
end
end
function RS(t,p,d)local g,a,j,x=S.char(p>>8,p%X,R(X)-1,R(X)-1,R(X)-1),-1
j=function()a=a+1
x=nil
if a~=R3 then
TS(t,g..S.char(a,1)..d)x=RP(j,R4)end
RN[t..g]=x
end j()end

View File

@ -18,31 +18,45 @@
-- RK: Kill timer. -- RK: Kill timer.
-- RC: Message receive raw. -- RC: Message receive raw.
-- RF: Refresh system. -- RF: Refresh system.
-- RG: Generate 1 random char (as a number) -- R: math.random
-- RS: Send message. -- RS: Send message.
R1,R2,R3,R4=0x40,60,12,2.5 R1,R2,R3,R4=0x40,60,12,2.5
RT,RA,RN,RU={},{},{},computer.uptime
function RP(f,x) -- It is shorter to have this (R) than not have it or localize it. *sigh*
RT,RA,RN,RU,R,X={},{},{},computer.uptime,math.random,255
-- Add timer. Kill timer.
-- Refresh function to clean up & execute timers.
RP,RK,RF=function(f,x)
if#RT<R1 then if#RT<R1 then
local t={f,RU()+x} local t={f,RU()+x}
table.insert(RT,t) table.insert(RT,t)
return t return t
end end
end end,function(t)
function RK(t)
for i=1,#RT do for i=1,#RT do
if t==RT[i]then if t==RT[i]then
table.remove(RT,i) table.remove(RT,i)
end end
end end
end,function()
local i,t=1,RU()
while#RT>i do
if t>RT[i][2]then
table.remove(RT,i)[1]()
else
i=i+1
end
end
end end
function RC(r,f,t,d) function RC(r,f,t,d)
if d and#d>=7then if d and#d>=7then
-- Keep in mind the ID used by tables is (originalPacketToName..GID) -- Keep in mind the ID used by tables is (originalPacketToName..GID)
-- ',k' unspecified value "trick" -- ',k' unspecified value "trick"
local p,b,g,k=d:byte(2)+(d:byte(1)*256),d:byte(7),d:sub(1,5) local p,b,g,k=d:byte(2)+(d:byte(1)*X),d:byte(7),d:sub(1,5)
if b==0x01or b==0x00then if b==0x01or b==0x00then
k=t..g k=t..g
@ -67,26 +81,9 @@ function RC(r,f,t,d)
end end
end end
-- Refresh function to clean up & execute timers.
function RF()
local i,t=1,RU()
while#RT>i do
if t>RT[i][2]then
table.remove(RT,i)[1]()
else
i=i+1
end
end
end
-- It is shorter to have this than not have it or localize it. *sigh*
function RG()
return math.random(256)-1
end
function RS(t,p,d) function RS(t,p,d)
-- j,x unspecified. x is used in j. -- j,x unspecified. x is used in j.
local g,a,j,x=S.char(math.floor(p/256),p%256,RG(),RG(),RG()),-1 local g,a,j,x=S.char(p>>8,p%X,R(X)-1,R(X)-1,R(X)-1),-1
j=function() j=function()
a=a+1 a=a+1
x=nil x=nil

View File

@ -12,18 +12,23 @@ end
end end
function TS(d,m)TB(4957,TC,S.char(0,#TH-1)..TH..S.char(#d-1)..d..m)end function TS(d,m)TB(4957,TC,S.char(0,#TH-1)..TH..S.char(#d-1)..d..m)end
R1,R2,R3,R4=0x40,60,12,2.5 R1,R2,R3,R4=0x40,60,12,2.5
RT,RA,RN,RU={},{},{},computer.uptime RT,RA,RN,RU,R,X={},{},{},computer.uptime,math.random,255
function RP(f,x)if#RT<R1 then RP,RK,RF=function(f,x)if#RT<R1 then
local t={f,RU()+x}table.insert(RT,t)return t local t={f,RU()+x}table.insert(RT,t)return t
end end
end end,function(t)for i=1,#RT do
function RK(t)for i=1,#RT do
if t==RT[i]then if t==RT[i]then
table.remove(RT,i)end table.remove(RT,i)end
end end
end,function()local i,t=1,RU()while#RT>i do
if t>RT[i][2]then
table.remove(RT,i)[1]()else
i=i+1
end
end
end end
function RC(r,f,t,d)if d and#d>=7then function RC(r,f,t,d)if d and#d>=7then
local p,b,g,k=d:byte(2)+(d:byte(1)*256),d:byte(7),d:sub(1,5)if b==0x01or b==0x00then local p,b,g,k=d:byte(2)+(d:byte(1)*X),d:byte(7),d:sub(1,5)if b==0x01or b==0x00then
k=t..g k=t..g
if not RA[k] then if not RA[k] then
r(f,t,p,d:sub(8))else r(f,t,p,d:sub(8))else
@ -37,16 +42,7 @@ RK(RN[k])RN[k]=nil
end end
end end
end end
function RF()local i,t=1,RU()while#RT>i do function RS(t,p,d)local g,a,j,x=S.char(p>>8,p%X,R(X)-1,R(X)-1,R(X)-1),-1
if t>RT[i][2]then
table.remove(RT,i)[1]()else
i=i+1
end
end
end
function RG()return math.random(256)-1
end
function RS(t,p,d)local g,a,j,x=S.char(math.floor(p/256),p%256,RG(),RG(),RG()),-1
j=function()a=a+1 j=function()a=a+1
x=nil x=nil
if a~=R3 then if a~=R3 then