a day ago
- The article explores the hidden machine code embedded in a REM statement of the 1980s BASIC game 'The Wizard's Castle' for the Exidy Sorcerer, which was used to seed the pseudo-random number generator (PRNG).
- The REM statement's ASCII text actually encodes Z80 machine code when tokenized, with specific byte values like 0xED, 0x5F, 0x28, etc., forming a routine that reads the CPU's R register and stores it to a screen address for seeding.
- The code uses the R register (incremented frequently) to generate a random seed, retrying if zero, and stores it at screen address 0xF7FF, which is then PEEK'd by BASIC to seed the PRNG, limiting dungeons to 127 variations.
- Typing the code from the magazine listing likely failed due to non-ASCII glyphs; the author likely POKEd the machine code directly, using tokenized BASIC keywords that appear as odd characters when listed.
- The investigation involved disassembly, emulator testing (MAME, Java), and a tape image that confirmed the machine code, revealing how Sorcerer BASIC could execute hidden code in REM statements.
- The article provides a bonus token decoding table for bytes 128-255, showing how characters like 'F4' (0xC9) and 'S' (0xFF) map to BASIC tokens and non-ASCII glyphs.