Quake9500 tools - the game's build, and PC-side checks (Git Bash, Python 3)

Since 1.1 the game's C is built here, on the PC, by GCC 14 (the SDK only builds the C++
side, quake9500.exe). The phone build of that side still takes a trip to the VM.

build_blob.sh  Builds the game: ..\blob\quake9500.rbl, objects and blob0.dis (the
            disassembly, for crash logs) in obj\quake9500. Needs the Arm GNU Toolchain
            14.2.Rel1; ARMGCC= its folder (default ..\..\RE9500\tools\dl\arm-gcc). The
            flags this old code needs are explained in the script. It checks the
            relocations (mkblob.py) and that there's no ARMv5 or Thumb code.
                sh build_blob.sh
                OPT=-O3 NAME=o3 sh build_blob.sh    ..\blob\o3.rbl, for -blob o3
mkblob.py   ELF to .rbl: the image, then the addresses the stub fixes up. --verify links
            at 0 and at 1 MB must turn into each other through that list.
armsim.c    An ARMv4 interpreter (60 million instructions a second) that runs a .rbl with
            a stand-in for the stub, and stops on an unaligned access (exception 11 on the
            9500), an undefined instruction or a jump out. Its clock is a rough cache model,
            good for comparing builds, not for the phone's fps. Build:
                ..\..\GBA9500\tools\dl\mingw64\bin\gcc -O2 -o bin\armsim.exe armsim.c
simrun.sh   One timedemo in armsim, in a folder of its own:
                sh simrun.sh quake9500 SOMEFOLDER    (report in SOMEFOLDER\quake9500\...)
comparelogs.py  Timedemo reports side by side, part by part; the first is the base:
                python comparelogs.py quakelog.txt test.txt

check.sh    Syntax check of every C file with a modern GCC in GNU89 mode (the WinLibs GCC
            in ..\..\GBA9500\tools\dl\mingw64), plus c89check.py. Quick, and it catches
            implicit declarations:
                sh check.sh                 all files ("check: OK" at the end)
                sh check.sh r_main host     only these
            The C++ files (epocsys.cpp, epocaudio.cpp, stub.cpp) need the SDK and are not
            checked.

sftest.py and armtest.py (in ..\gcc29 since 1.1, with softfloat.c, which 1.1 doesn't use):

sftest.py   Fuzz test for ..\Quake9500\softfloat.c
            A line-by-line Python mirror of every helper in softfloat.c (__addsf3,
            __muldf3, __fixsfsi, the comparisons, ...), run against exact arithmetic
            (fractions) with round-to-nearest-even and denormals flushed to zero.
            IMPORTANT: it tests the mirror, not the C file. After changing softfloat.c,
            make the same change in the mirror first, then run:
                python sftest.py                 (200000 rounds, seed 1: a few minutes)
                python sftest.py 50000 7         (rounds, seed)
            Expect "failures: 0". Signed zeros are not compared (the reference has
            only one zero). The phone-side check is SoftFloatSelfTest() in softfloat.c:
            its results are the "softfloat ..." lines at the top of quakelog.txt.
            Known facts it encodes: doubles are FPA order (high word first), and
            float->int saturates (0x7fffffff / 0x80000000, NaN -> 0) as libgcc does;
            Pocket Quake's fixed-point code depends on that saturation.

armtest.py  Tests the ARM assembly in softfloat.c (MULSF_ASM, ADDSF_ASM, UDIV_ASM) in a
            small ARMv4 interpreter, against sftest.py's mirror. The assembly text is
            read straight out of softfloat.c, so what is tested is what is built. It also
            checks that each immediate is encodable and umull's register rules.
                python armtest.py               (200000 cases per routine, ~2 min)
                python armtest.py 50000 7       (cases, seed)
            Expect "failures: 0". If you change the assembly, run this first.

c89check.py Finds C99 code that the SDK's GCC 2.9 rejects: declarations after
            statements in a block, and "for (int i ...". Heuristic: it evaluates the
            #if branches this build uses (the names are listed in the script) and can
            still report a false positive now and then.
                python c89check.py ..\Quake9500 r_main.c d_scan.c
            or, for every file:
                python c89check.py ..\Quake9500 (list the .c files)

wsedit.py   Helper for scripted edits: replaces text whatever its tabs and spaces.
            Used from Python:  from wsedit import ed;  ed('file.c', [(old, new)])
            Each old text must match exactly once, or nothing is written.

polytest\   Draws a view model with the game's own d_polyse.c on the PC and compares it
            with id's float gradient code (built from the same file). gunverts.py makes
            the screen vertices the way the engine does (r_lowres 1, the r_gunscale
            projection, z clipped at 5, the gun's lighting); harness.c runs
            D_DrawNonSubdiv on them with 32-bit wrapping arithmetic. Found the depth
            gradient overflow behind the dark patches on the double-barrelled shotgun.
                sh polytest/polytest.sh                        v_shot2 at r_gunscale 1.4
                sh polytest/polytest.sh progs/v_nail.mdl 3
                OLD=some_old_d_polyse.c sh polytest/polytest.sh   also counts an older file
            Prints how many pixels differ from the float version and writes
            polytest\out\<model>\zoom.png. A few pixels is rounding; hundreds is a bug.

hostshot\   The real engine on the PC, for screenshots: all the game's C files, with
            hoststub.c in place of epocsys.cpp and epocaudio.cpp (no window, a virtual
            clock, a script of what happens at which frame). Quake casts pointers to int
            and long, so the exe is linked to stay below 2 GB (clearlaa.py clears the
            large-address-aware bit, which this ld has no option for). Its timedemo gives
            the same "Alias models per frame" line as the phone. Timings mean nothing.
                sh hostshot/build.sh
                python hostshot/takeshots.py          the pictures in ..\blog
                python hostshot/takeshots.py gun lead only these
                python hostshot/chart.py              ..\blog\speed.png, from the phone's logs
            It needs out\base\id1\pak0.pak. takeshots' "barrels" also needs
            out\hostquake_old.exe, the same build linked with a d_polyse.c from before
            the depth gradient fix.
