HN
Today

10 REM"_(C2SLFF4

A meticulous forensic deep dive unravels the decades-old mystery of a seemingly nonsensical REM statement in the 1980s BASIC game "The Wizard's Castle." This vintage computing detective story reveals how programmers cunningly embedded Z80 machine code within a comment to seed the game's random number generator. It's a perfect blend of technical archaeology and clever problem-solving that resonates deeply with HN's fascination for obscure programming tricks and historical hardware.

10
Score
1
Comments
#3
Highest Rank
8h
on Front Page
First Seen
Jul 22, 1:00 PM
Last Seen
Jul 22, 8:00 PM
Rank Over Time
144379141616

The Lowdown

The article embarks on an engaging journey to decrypt a cryptic REM (remark) statement found as the very first line of the 1980s BASIC game, The Wizard's Castle. What initially appears to be a garbled typo, 10 REM"_(C2SLFF4, turns out to be a cleverly concealed piece of Z80 machine code, integral to the game's functionality. This detailed investigation blends historical context, technical deduction, and a dash of retro-computing detective work.

  • The mystery begins with line 10 REM"_(C2SLFF4 in the Exidy Sorcerer version of The Wizard's Castle, a comment that defies easy explanation.
  • Further lines of code, specifically POKEs to addresses 260/261 and a call to USR(0), suggest that user-defined machine code is being executed, with the REM line's starting memory address (474) coinciding with the USR call target.
  • Initial attempts to disassemble the ASCII representation of the REM text yield nonsensical Z80 instructions, leading to a temporary dead end and speculation about printing errors.
  • A crucial clue from a magazine annotation, stating the REM contains "a machine language routine to simulate the RANDOM function," confirms the machine code hypothesis.
  • The breakthrough comes from analyzing a tape image of the game, which includes a comment (line 15) explicitly listing the hex values (ED 5F 28 FC 32 FF F7 C9) of the hidden machine code.
  • A direct memory dump reveals that the actual bytes stored for the REM statement match the annotated hex, not the ASCII glyphs visible in the listing; for example, 0xED (237) is displayed as " in the BASIC listing.
  • The correctly disassembled Z80 code (LD A,R; JR Z,-4; LD (F7FF),A; RET) copies the Z80's R register (which contains a frequently changing value) to accumulator A, handles potential zero values, stores A at memory address 0xF7FF (the lower-right screen character), and returns.
  • This stored value is then immediately PEEKed by BASIC and used to seed the pseudo-random number generator, providing a random-like seed without user input.
  • The article highlights the difficulty of typing such code from the magazine, as the printed characters ("_(C2SLFF4) would not produce the correct machine code bytes. The original author likely POKEd the bytes directly.
  • The investigation also uncovers unique display quirks of Sorcerer BASIC, where certain byte values (like 247 for "LF" and 201 for "F4") are interpreted and printed as multi-character keywords, explaining discrepancies in the REM's visual representation.

Ultimately, the seemingly benign REM statement is revealed as a clever, albeit obscure, method of embedding machine code directly into a BASIC program to provide a system-derived seed for the game's random number generator. This piece of reverse engineering not only solves a long-standing retro-computing puzzle but also offers a fascinating glimpse into the ingenious techniques employed by programmers in the resource-constrained era of 8-bit microcomputers.