sdk-core
v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Toggle main menu visibility
Loading...
Searching...
No Matches
gen_inflate_data.py
1
#!/usr/bin/env python3
2
"""Writes src/inflate_data.h: a raw deflate stream of 64 KiB of generated text and tables, for the inflate kernel."""
3
4
import
os
5
import
random
6
import
zlib
7
8
SIZE = 65536
9
10
words = (
"player enemy level score texture vertex sound music frame buffer sprite camera light shadow model "
11
"packet render update input pad memory card save load stage world boss item weapon health magic"
).split()
12
13
rng = random.Random(12345)
14
out = bytearray()
15
while
len(out) < SIZE:
16
if
rng.random() < 0.8:
17
line =
" "
.join(rng.choice(words)
for
_
in
range(rng.randint(3, 12)))
18
out += (line.capitalize() +
".\n"
).encode()
19
else
:
20
out += bytes(rng.randrange(256)
for
_
in
range(rng.randint(8, 64)))
21
data = bytes(out[:SIZE])
22
23
comp = zlib.compressobj(9, zlib.DEFLATED, -15)
24
stream = comp.compress(data) + comp.flush()
25
26
h = 2166136261
27
for
b
in
data:
28
h = ((h ^ b) * 16777619) & 0xffffffff
29
30
path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"src"
,
"inflate_data.h"
)
31
with
open(path,
"w"
, newline=
"\n"
)
as
f:
32
f.write(
"/* Generated by gen_inflate_data.py: raw deflate (zlib level 9) of %d bytes, FNV-1a %08x. */\n"
33
% (SIZE, h))
34
f.write(
"#define INFLATE_OUT_BYTES %d\n"
% SIZE)
35
f.write(
"static const unsigned char inflate_in[%d] __attribute__((aligned(64))) = {\n"
% len(stream))
36
for
i
in
range(0, len(stream), 16):
37
f.write(
" "
+
", "
.join(
"0x%02x"
% b
for
b
in
stream[i:i + 16]) +
",\n"
)
38
f.write(
"};\n"
)
39
print(
"%d -> %d bytes, FNV-1a %08x"
% (SIZE, len(stream), h))
tests
bench
gen_inflate_data.py
Generated by
1.18.0