mirror of
https://github.com/20kdc/OC-KittenOS.git
synced 2024-11-23 10:58:06 +11:00
Improve the compression, and get rid of imitclaw (will be outdated)
This commit is contained in:
parent
9254745a33
commit
8ab47c96b3
1
.gitignore
vendored
1
.gitignore
vendored
@ -20,6 +20,7 @@ repobuild/*/*
|
||||
repobuild/*/*/
|
||||
repobuild/*/*/*
|
||||
|
||||
laboratory/ocemu.cfg
|
||||
laboratory/*/
|
||||
laboratory/*/*
|
||||
laboratory/*/*/
|
||||
|
@ -1,61 +1,45 @@
|
||||
-- This is released into the public domain.
|
||||
-- No warranty is provided, implied or otherwise.
|
||||
|
||||
-- BDIVIDE
|
||||
-- BDIVIDE r5 edition
|
||||
-- Algorithm simplified for smaller implementation and potentially better compression
|
||||
-- format:
|
||||
-- 0-127 for constants
|
||||
-- <block + 128>, <(len - 3) * 2, + lowest bit is upper bit of position>, <position - 1>
|
||||
-- <128 + (length - 4)>, <position high>, <position low>
|
||||
-- Position is where in the window it was found, minus 1.
|
||||
-- windowSize must be the same between the encoder and decoder,
|
||||
-- and is the amount of data preserved after cropping.
|
||||
|
||||
io.write("\x00") -- initiation character
|
||||
|
||||
local blockCache = {}
|
||||
local window = 0
|
||||
local blockUse = 128
|
||||
for i = 128, 128 + blockUse - 1 do
|
||||
blockCache[i] = ("\x00"):rep(512)
|
||||
local blk = io.read("*a")
|
||||
local windowSize = 0x10000
|
||||
local windowData = ("\x00"):rep(windowSize)
|
||||
|
||||
local function crop(data)
|
||||
windowData = (windowData .. data):sub(-windowSize)
|
||||
end
|
||||
|
||||
local function runBlock(blk)
|
||||
-- firstly, get current block index
|
||||
local blockIndex = window + 128
|
||||
window = (window + 1) % blockUse
|
||||
blockCache[blockIndex] = ""
|
||||
-- ok, now work on the problem
|
||||
local i = 1
|
||||
while i <= #blk do
|
||||
local bestData = blk:sub(i, i)
|
||||
local bestRes = bestData
|
||||
local bestScore = 1
|
||||
for bid = 128, 128 + blockUse - 1 do
|
||||
for lm = 0, 127 do
|
||||
local al = lm + 3
|
||||
local pfx = blk:sub(i, i + al - 1)
|
||||
if #pfx ~= al then
|
||||
break
|
||||
end
|
||||
local p = blockCache[bid]:find(pfx, 1, true)
|
||||
if not p then
|
||||
break
|
||||
end
|
||||
local score = al / 3
|
||||
if score > bestScore then
|
||||
bestData = string.char(bid) .. string.char((lm * 2) + math.floor((p - 1) / 256)) .. string.char((p - 1) % 256)
|
||||
bestRes = pfx
|
||||
bestScore = score
|
||||
end
|
||||
end
|
||||
while blk ~= "" do
|
||||
local bestData = blk:sub(1, 1)
|
||||
local bestRes = bestData
|
||||
for lm = 0, 127 do
|
||||
local al = lm + 4
|
||||
local pfx = blk:sub(1, al)
|
||||
if #pfx ~= al then
|
||||
break
|
||||
end
|
||||
-- ok, encode!
|
||||
io.write(bestData)
|
||||
blockCache[blockIndex] = blockCache[blockIndex] .. bestRes
|
||||
i = i + #bestRes
|
||||
local p = windowData:find(pfx, 1, true)
|
||||
if not p then
|
||||
break
|
||||
end
|
||||
local pm = p - 1
|
||||
bestData = string.char(128 + lm, math.floor(pm / 256), pm % 256)
|
||||
bestRes = pfx
|
||||
end
|
||||
-- ok, encode!
|
||||
io.write(bestData)
|
||||
crop(bestRes)
|
||||
blk = blk:sub(#bestRes + 1)
|
||||
end
|
||||
|
||||
while 1 do
|
||||
local blkd = io.read(512)
|
||||
runBlock(blkd)
|
||||
if #blkd < 512 then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
@ -46,6 +46,7 @@ local sequences = {
|
||||
{"=1 w", "=1w"},
|
||||
{"=380 l", "=380l"},
|
||||
{"=127 t", "=127t"},
|
||||
{"<128 t", "<128t"},
|
||||
{"=128 t", "=128t"},
|
||||
{">255 t", ">255t"},
|
||||
{"=512 t", "=512t"}
|
@ -1,19 +1,35 @@
|
||||
-- This is released into the public domain. XX
|
||||
-- No warranty is provided, implied or otherwise. XX
|
||||
local sector = io.write -- XX
|
||||
-- BUNDIVIDE reference implementation for integration XX
|
||||
local Cs,Cbu,Cb,Cw,Cp,Ct,Ci,CP,CB,CD={},128,"",128,"",""
|
||||
CP = function(d,b)
|
||||
-- XX
|
||||
-- BUNDIVIDE (r5 edition) reference implementation for integration XX
|
||||
-- Lines ending with XX are not included in the output. XX
|
||||
-- Lines that both start and end with -- are only for use in the output, XX
|
||||
-- and are thus not executed during any sanity-check procedure. XX
|
||||
-- XX
|
||||
Cp,Ct,Cc,Cw="","","",("\x00"):rep(65536)
|
||||
-- High-level breakdown: XX
|
||||
-- CP is unescaper & TAR-sector-breakup. XX
|
||||
-- It'll only begin to input if at least 3 bytes are available, XX
|
||||
-- so you'll want to throw in 2 extra zeroes at the end of stream as done here. XX
|
||||
-- It uses Ct (input buffer) and Cp (output buffer). XX
|
||||
-- Ignore its second argument, as that's a lie, it's just there for a local. XX
|
||||
-- CD is the actual decompressor. It has the same quirk as CP, wanting two more bytes. XX
|
||||
-- It stores to Cc (compressed), and Cw (window). XX
|
||||
-- It uses Ca as the "first null" activation flag. XX
|
||||
-- It outputs that which goes to the window to CP also. XX
|
||||
-- And it also uses a fake local. XX
|
||||
CP = function (d, b)
|
||||
Ct = Ct .. d
|
||||
while#Ct>2 do
|
||||
while #Ct > 2 do
|
||||
b = Ct:byte()
|
||||
Ct = Ct:sub(2)
|
||||
if b == 127 then
|
||||
b = Ct:byte()
|
||||
Ct = Ct:sub(2)
|
||||
if b == 127 then
|
||||
b = Ct:byte()+254
|
||||
if b > 255then
|
||||
b = Ct:byte() + 254
|
||||
if b > 255 then
|
||||
b = b - 256
|
||||
end
|
||||
Ct = Ct:sub(2)
|
||||
@ -21,53 +37,36 @@ CP = function(d,b)
|
||||
b = b + 127
|
||||
end
|
||||
end
|
||||
Cp = Cp..string.char(b)
|
||||
Cp = Cp .. string.char(b)
|
||||
if #Cp == 512 then
|
||||
sector(Cp)
|
||||
Cp = ""
|
||||
end
|
||||
end
|
||||
end
|
||||
for i = 128, 127 + Cbu do
|
||||
Cs[i] = ("\x00"):rep(512)
|
||||
end
|
||||
Cs[Cw] = ""
|
||||
CB = function (d, i, d2, x, y)
|
||||
i=1
|
||||
while i <= #d - 2 do
|
||||
b=d:byte(i)
|
||||
d2=d:sub(i,i)
|
||||
i=i+1
|
||||
if not Ci then
|
||||
if b==0then
|
||||
Ci=1
|
||||
end
|
||||
-- XX
|
||||
CD = function (d, b, p)
|
||||
Cc = Cc .. d
|
||||
while #Cc > 2 do
|
||||
b = Cc:byte()
|
||||
if not Ca then
|
||||
Ca, b, Cc = b < 1, "", Cc:sub(2)
|
||||
elseif b < 128 then
|
||||
b, Cc = Cc:sub(1, 1), Cc:sub(2)
|
||||
else
|
||||
if b >= 128 then
|
||||
x = d:byte(i)
|
||||
i = i + 1
|
||||
y=d:byte(i) + ((x % 2) * 256)
|
||||
i = i + 1
|
||||
d2=Cs[b]:sub(y + 1,y + 3 + math.floor(x / 2))
|
||||
end
|
||||
Cs[Cw]=Cs[Cw]..d2
|
||||
if #Cs[Cw]>=512 then
|
||||
CP(Cs[Cw])
|
||||
Cw=((Cw-127)%Cbu)+128
|
||||
Cs[Cw]=""
|
||||
end
|
||||
p = Cc:byte(2) * 256 + Cc:byte(3) + 1
|
||||
b, Cc = Cw:sub(p, p + b - 125), Cc:sub(4)
|
||||
end
|
||||
CP(b)
|
||||
Cw = (Cw .. b):sub(-65536)
|
||||
end
|
||||
return i
|
||||
end
|
||||
CD = function(d)
|
||||
Cb = Cb .. d
|
||||
Cb = Cb:sub(CB(Cb))
|
||||
end
|
||||
-- XX
|
||||
CD(io.read("*a")) -- XX
|
||||
--D.remove("init-bdivide.lua")--
|
||||
--D.rename("init.lua","init-bdivide.lua")--
|
||||
--local Ch=D.open("init-bdivide.lua","rb")--
|
||||
--dieCB=function()D.close(Ch)D.remove("init-bdivide.lua")end--
|
||||
--while true do local t=D.read(Ch, 64)if not t then break end CD(t)end--
|
||||
CD("\x00\x00")CP(Cs[Cw] .. "\x00\x00")
|
||||
-- XX
|
||||
CD("\x00\x00")CP("\x00\x00")
|
||||
|
34
imitclaw.lua
34
imitclaw.lua
@ -1,34 +0,0 @@
|
||||
-- This is released into the public domain.
|
||||
-- No warranty is provided, implied or otherwise.
|
||||
|
||||
-- Imitation CLAW
|
||||
local done = {}
|
||||
|
||||
local f, e = loadfile("code/data/app-claw/local.lua")
|
||||
if not f then error(e) end
|
||||
f = f()
|
||||
if not os.execute("mkdir work") then
|
||||
error("Delete 'work'")
|
||||
end
|
||||
for k, v in pairs(f) do
|
||||
for _, vd in ipairs(v.dirs) do
|
||||
os.execute("mkdir work/" .. vd .. " 2> /dev/null")
|
||||
end
|
||||
for _, vf in ipairs(v.files) do
|
||||
-- not totally proofed but will do
|
||||
if not os.execute("cp code/" .. vf .. " work/" .. vf) then
|
||||
error("Could not copy " .. vf .. " in " .. k)
|
||||
end
|
||||
if done[vf] then
|
||||
error("duplicate " .. vf .. " in " .. k)
|
||||
end
|
||||
print(vf .. "\t\t" .. k)
|
||||
done[vf] = true
|
||||
end
|
||||
end
|
||||
os.execute("mkdir -p work/data/app-claw")
|
||||
os.execute("cp code/data/app-claw/local.lua work/data/app-claw/local.lua")
|
||||
os.execute("cd code ; find . > ../imitclaw.treecode")
|
||||
os.execute("cd work ; find . > ../imitclaw.treework")
|
||||
os.execute("diff -u imitclaw.treecode imitclaw.treework")
|
||||
os.execute("rm imitclaw.treecode imitclaw.treework")
|
@ -1,140 +0,0 @@
|
||||
--OCEmu configuration. Designed to mimic HOCON syntax, but is not exactly HOCON
|
||||
--syntax.
|
||||
ocemu {
|
||||
|
||||
--Client side settings, presentation and performance related stuff.
|
||||
client {
|
||||
|
||||
--The sample rate used for generating beeps of computers' internal speakers.
|
||||
--Use custom values at your own responsibility here; if it breaks OC you'll
|
||||
--get no support. Some potentially reasonable lower values are 16000 or even
|
||||
--8000 (which was the old default, but leads to artifacting on certain
|
||||
--frequencies).
|
||||
beepSampleRate=44100
|
||||
|
||||
--The base volume of beeps generated by computers. This may be in a range of
|
||||
--[0, 127], where 0 means mute (the sound will not even be generated), and
|
||||
--127 means maximum amplitude / volume.
|
||||
beepVolume=32
|
||||
|
||||
--The color of monochrome text (i.e. displayed when in 1-bit color depth,
|
||||
--e.g. tier one screens / GPUs, or higher tier set to 1-bit color depth).
|
||||
--Defaults to white, feel free to make it some other color, tho!
|
||||
monochromeColor="0xFFFFFF"
|
||||
}
|
||||
|
||||
--Computer related settings, concerns server performance and security.
|
||||
computer {
|
||||
|
||||
--The maximum size of the byte array that can be stored on EEPROMs as
|
||||
--configuration data.
|
||||
eepromDataSize=256
|
||||
|
||||
--The maximum size of the byte array that can be stored on EEPROMs as
|
||||
--executable data..
|
||||
eepromSize=4096
|
||||
|
||||
--Settings specific to the Lua architecture.
|
||||
lua {
|
||||
|
||||
--Whether to allow loading precompiled bytecode via Lua's `load` function,
|
||||
--or related functions (`loadfile`, `dofile`). Enable this only if you
|
||||
--absolutely trust all users on your server and all Lua code you run. This
|
||||
--can be a MASSIVE SECURITY RISK, since precompiled code can easily be
|
||||
--used for exploits, running arbitrary code on the real server! I cannot
|
||||
--stress this enough: only enable this is you know what you're doing.
|
||||
allowBytecode=false
|
||||
|
||||
--Whether to allow user defined __gc callbacks, i.e. __gc callbacks
|
||||
--defined *inside* the sandbox. Since garbage collection callbacks are not
|
||||
--sandboxed (hooks are disabled while they run), this is not recommended.
|
||||
allowGC=false
|
||||
}
|
||||
|
||||
--The time in seconds a program may run without yielding before it is
|
||||
--forcibly aborted. This is used to avoid stupidly written or malicious
|
||||
--programs blocking other computers by locking down the executor threads.
|
||||
--Note that changing this won't have any effect on computers that are
|
||||
--already running - they'll have to be rebooted for this to take effect.
|
||||
timeout=5
|
||||
}
|
||||
|
||||
--Emulator related settings. Components, accuracy, and debugging.
|
||||
emulator {
|
||||
|
||||
--Default components available to the computer.
|
||||
components {
|
||||
|
||||
{"gpu", "c1-gpu-tier3", 0, 160, 50, 3},
|
||||
{"gpu", "c1-gpu-tier1", 0, 50, 16, 1},
|
||||
{"screen_sdl2", "c1-screen-tier3", -1, 160, 50, 3},
|
||||
{"screen_sdl2", "c1-screen-tier1", -1, 50, 16, 1},
|
||||
{"modem", "c1-modem", 1, false},
|
||||
{"eeprom", "c1-eeprom", 9, "lua/bios.lua"},
|
||||
{"filesystem", "c1-tmpfs", -1, "tmpfs", "tmpfs", false, 5},
|
||||
{"filesystem", "c1-sda", 5, nil, "Workbench", false, 4},
|
||||
{"filesystem", "c1-sdb", 5, nil, "Repository", false, 4},
|
||||
{"filesystem", "openos", 0, "loot/openos", "openos", true, 1},
|
||||
{"internet", "c1-internet", 2},
|
||||
{"computer", "c1-computer", -1},
|
||||
{"ocemu", "c1-ocemu", -1},
|
||||
{"keyboard_sdl2", "c1-keyboard", -1}
|
||||
}
|
||||
|
||||
--Whether to enable the emulator's extremely verbose logging.
|
||||
debug=false
|
||||
|
||||
--Whether to choose performance over timing-accuracy.
|
||||
fast=false
|
||||
|
||||
--Whether to return vague error messages like OpenComputers.
|
||||
vague=false
|
||||
}
|
||||
|
||||
filesystem {
|
||||
|
||||
--The maximum block size that can be read in one 'read' call on a file
|
||||
--system. This is used to limit the amount of memory a call from a user
|
||||
--program can cause to be allocated on the host side: when 'read' is, called
|
||||
--a byte array with the specified size has to be allocated. So if this
|
||||
--weren't limited, a Lua program could trigger massive memory allocations
|
||||
--regardless of the amount of RAM installed in the computer it runs on. As a
|
||||
--side effect this pretty much determines the read performance of file
|
||||
--systems.
|
||||
maxReadBuffer=2048
|
||||
}
|
||||
|
||||
internet {
|
||||
|
||||
--Whether to allow HTTP requests via internet cards. When enabled, the
|
||||
--`request` method on internet card components becomes available.
|
||||
enableHttp=true
|
||||
|
||||
--Whether to allow TCP connections via internet cards. When enabled, the
|
||||
--`connect` method on internet card components becomes available.
|
||||
enableTcp=true
|
||||
}
|
||||
|
||||
--Other settings that you might find useful to tweak.
|
||||
misc {
|
||||
|
||||
--The maximum size of network packets to allow sending via network cards.
|
||||
--This has *nothing to do* with real network traffic, it's just a limit for
|
||||
--the network cards, mostly to reduce the chance of computer with a lot of
|
||||
--RAM killing those with less by sending huge packets. This does not apply
|
||||
--to HTTP traffic.
|
||||
maxNetworkPacketSize=8192
|
||||
|
||||
--The maximum distance a wireless message can be sent. In other words, this
|
||||
--is the maximum signal strength a wireless network card supports. This is
|
||||
--used to limit the search range in which to check for modems, which may or
|
||||
--may not lead to performance issues for ridiculous ranges - like, you know,
|
||||
--more than the loaded area. See also: `wirelessCostPerRange`.
|
||||
maxWirelessRange=400
|
||||
}
|
||||
|
||||
--The configuration version this config was generated at. This is used to
|
||||
--allow the emulator to reset/migrate parts of the config when their meaning
|
||||
--has changed across versions.
|
||||
version=3
|
||||
}
|
11
laboratory/reset-i.sh
Executable file
11
laboratory/reset-i.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This is released into the public domain.
|
||||
# No warranty is provided, implied or otherwise.
|
||||
|
||||
cp ocemu.cfg.default ocemu.cfg && rm -rf c1-sda c1-sdb tmpfs
|
||||
mkdir c1-sda c1-sdb
|
||||
echo -n c1-sda > c1-eeprom/data.bin
|
||||
cd ..
|
||||
./package.sh
|
||||
cp inst.lua laboratory/c1-sda/init.lua
|
@ -7,7 +7,7 @@ rm code.tar
|
||||
# Hey, look behind you, there's nothing to see here.
|
||||
# ... ok, are they seriously all named "Mann"?
|
||||
tar --owner=gray:0 --group=mann:0 -cf code.tar code
|
||||
lua heroes.lua `wc -c code.tar` | lua bonecrunch.lua > inst.lua
|
||||
lua heroes.lua `wc -c code.tar` | lua com2/bonecrunch.lua > inst.lua
|
||||
echo -n "--[[" >> inst.lua
|
||||
cat com2/code.tar.bd >> inst.lua
|
||||
echo -n "]]" >> inst.lua
|
||||
|
Loading…
Reference in New Issue
Block a user