|function getCompactSize(size: longword): word;|
// sizes must be multiples of 256!
Assert(size mod 256 = 0);
size := size shr 8;
i := 0;
while (size mod 2 = 0) and (size >= 32) and (i < 15) do begin
i := i + 1;
size := size shr 1;
result := ((i and $F) shl 11) or (size and $7FF);
function getFlags(sysSegSize, gpuSegSize: longword): longword;
result := (getCompactSize(sysSegSize) and $7FFF)
or (getCompactSize(gpuSegSize) and $7FFF) shl 15
or 3 shl 30;
For the more than 100 files which I tested this on, only about 60% of the calculated flags are identical (see test cases). But since they are technically correct, i.e. encode the same sizes, just with different multipliers, they might still work. REspawn tested this for radio_hud.wtd and the game didn't crash...