thecodingidiot.com

c03-the-reader

The Reader

The Question File

Jeopardy![1] is a quiz show created by Merv Griffin in 1964. The format is inverted: the answer is given first, and contestants respond in the form of a question. A clue reads "The capital of France" — the winning response is "What is Paris?" It became one of the most recognised game show formats in television history.

By 1988, Griffin had sold his production company, Merv Griffin Enterprises, to Coca-Cola, and then to Columbia Pictures Entertainment. That corporate handover left a strange trace in the NES ROM: a small Coca-Cola logo sits at offset F08B, never displayed, never used. Coca-Cola had wanted to advertise its ownership before the game shipped; the sale to Columbia happened first.[2]

Coca-Cola logo found in the Jeopardy! (NES) ROM

The NES cartridge (1988) shipped with roughly 50 questions baked into ROM — no more, no less. The Amiga version (1989) loaded questions from floppy disk one at a time as the player progressed. The cartridge could not grow without a new cartridge. The disk could — but only if the program could read a file one line at a time without pulling everything into RAM at once.

Jeopardy! NES — splash screen (PRG0 revision)
Jeopardy! NES — title screen (PRG0 revision)

The NES version knew how many questions it had before the program ran. The Amiga version did not — the question file could be as long as the disk allowed. tci_getline is what makes that possible.

The last chapter was about output — writing formatted text to a file descriptor. This one is the input side of the same pair.

The implementation pages build tci_getline from the ground up — the read() syscall first, then the static buffer that persists across calls, then the line extractor. tciu_split follows: once you can read a line from a file, you need to parse it into fields. This chapter also introduces libtciutil, the second library. Start at Setup.

Implementation

Setup

Begin Implementation
  1. 0Setup
  2. 1The read() Syscall
  3. 2Persistent State
  4. 3The Line Loop
  5. 4Edge Cases
  6. 5Multiple File Descriptors
  7. 6Splitting Lines

Footnotes

  1. Jeopardy! - Wikipedia

  2. Jeopardy! (NES) - The Cutting Room Floor