thecodingidiot.com

f04-writing-c

Writing C

The Threshold

The Atari 2600 has 128 bytes of RAM. That number is not a development philosophy — it is a physical constraint. A C program needs a stack for function calls, space for local variables, a mechanism for returning from functions. There is no room.

The 2600 ran assembly because nothing else fit. The NES had 2 kilobytes. The SNES had 128 kilobytes. Better each time, but still machines where a C compiler's overhead was visible — where the code it generated was measurably slower and larger than what a skilled programmer could write by hand. The developers who made those games wrote assembly because the hardware demanded it.

The PlayStation[1][2] ran a MIPS R3000A[3] — a 32-bit RISC processor built with compilers in mind.

Sony PlayStation logo
Sony CXD8606BQ — the MIPS R3000A-based CPU inside the PlayStation

A clean register file, no legacy quirks, predictable pipeline behaviour. It had 2 megabytes of RAM. Its software came on CD-ROM rather than cartridge, removing the code-size constraint entirely. For the first time, a mass-market console had hardware that a C compiler could target efficiently. Sony recognised this; SN Systems[4] built the Psy-Q SDK that most PlayStation studios used.

The N64 and Game Boy Advance followed with C-based SDKs. C became the language consoles ran on — not by choice over assembly, but because the hardware had finally caught up.

This is where it starts. The language is C. The first program is twenty lines.

The implementation pages build up from the compilation pipeline to a working guessing game, one concept at a time: types and values, control flow, functions, the standard library. The final page brings everything together and points you at the Doom source code — the same C you just learned to write, at a different scale. Start at Setup.

Implementation

Setup

Begin Implementation
  1. 0Setup
  2. 1Your First Program
  3. 2Variables and Types
  4. 3Control Flow
  5. 4Functions
  6. 5The Standard Library
  7. 6The Guessing Game

Footnotes

  1. PlayStation (console) - Wikipedia

  2. PlayStation® Official Site: Consoles, Games, Accessories & More

  3. R3000 - Wikipedia

  4. SN Systems - Wikipedia