thecodingidiot.com

c02-the-voice

The Voice

High Score

Pac-Man[1] (1980) ran on a Z80A at 3.072 MHz — no printf, no standard library. The score display was rendered by writing digit characters into video memory at fixed addresses; the hardware scanned those addresses and drew what it found.

To update the score, the code computed the last digit with % 10, removed it with / 10, and repeated until nothing remained. It wrote each character code to the correct address.

Pac-Man arcade screenshot — HIGH SCORE display at the top of the screen

When Namco licensed Pac-Man to Nintendo for the Famicom in 1984, the problem changed shape. The NES PPU renders by reading a name table — a 32×30 grid of tile indices. A score of 12400 meant computing the digits and writing the tile indices into the name table. Different chip, different addresses, same algorithm — and no printf.

Neither did the Atari 2600, the ColecoVision, the MSX, nor the early arcade boards. These machines ran assembly language on CPUs with no C runtime and no standard library. Every score counter on every platform through the early 1980s was a printf written by hand, per project.

We are going to write ours for the same reason we wrote libtci: to understand what it does before we use it.

The implementation pages build tci_printf from the ground up — variadic argument mechanics first, then the output primitive, then the format string parser, then one specifier group at a time. The flags page extends it with the full flag, width, and precision system. Start at Setup.

Implementation

Setup

Begin Implementation
  1. 0Setup
  2. 1Variadic Arguments
  3. 2The Output Primitive
  4. 3The Format Loop
  5. 4Characters and Strings
  6. 5Integers
  7. 6Hex and Pointers
  8. 7Complete tci_printf
  9. 8Flags, Width, and Precision

Footnotes

  1. Pac-Man - Wikipedia