sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
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
4import os
5import random
6import zlib
7
8SIZE = 65536
9
10words = ("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
13rng = random.Random(12345)
14out = bytearray()
15while 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)))
21data = bytes(out[:SIZE])
22
23comp = zlib.compressobj(9, zlib.DEFLATED, -15)
24stream = comp.compress(data) + comp.flush()
25
26h = 2166136261
27for b in data:
28 h = ((h ^ b) * 16777619) & 0xffffffff
29
30path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "src", "inflate_data.h")
31with 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")
39print("%d -> %d bytes, FNV-1a %08x" % (SIZE, len(stream), h))