Lecture 03

Memory Map & Soft Switches

The 6502's sixteen address lines give it 65,536 addresses — the famous 64K. The genius of the Apple II is how that space is carved up: RAM, screen, I/O hardware, and ROM all live at fixed, documented addresses. Learn this map and you can make the machine do anything from one line of BASIC.

1. The map

$FFFF ROM — 12K Applesoft BASIC + Monitor Permanent. The reset vector at $FFFC points into the Monitor. $CFFF $C800 expansion ROM (shared) $C7FF slot ROMs (slot n at $Cn00) $C0FF $C000 I/O — SOFT SWITCHES Keyboard, speaker, graphics modes, paddles. Not memory! $BFFF Free RAM (top used by DOS if booted from disk) $5FFF HI-RES PAGE 2 (8K) $3FFF $2000 HI-RES PAGE 1 (8K) Free RAM — BASIC loads at $0801 $0BFF TEXT/LO-RES PAGE 2 ($0800–$0BFF) $07FF TEXT/LO-RES PAGE 1 ($0400–$07FF) ← what you see on screen $03FF $0200 buffer · FREE AT $0300–$03CF $01FF STACK ($0100–$01FF) $00FF $0000 ZERO PAGE ($0000–$00FF) JSR/RTS return addresses Fast 1-byte addressing; heavily used by BASIC/DOS Not to scale — small but important regions are enlarged. Green = RAM, blue = I/O, orange/purple = ROM.
The Apple II address space, $0000 (bottom) to $FFFF (top). A 48K machine has RAM from $0000 to $BFFF; the last 16K is I/O space and ROM. The bright green regions are RAM that the video hardware also reads — write there and you're drawing on the screen.

Regions worth memorizing

RangeNameWhy you care
$0000–$00FFZero pageInstructions addressing it are shorter and faster. BASIC and DOS claim most of it; a few locations are free for your programs.
$0100–$01FFStackFixed home of the 6502 stack. Don't put data here.
$0300–$03CFFree page 3Traditional scratch area for small machine-language routines — nothing in the system uses it. Your first assembly program goes here.
$0400–$07FFText page 1The visible 40×24 text screen. POKE here and characters appear.
$0801…BASIC programWhere Applesoft stores your program text, growing upward; variables above that.
$2000–$3FFFHi-res page 1The 280×192 graphics screen — 8K of pixels.
$C000–$C0FFSoft switchesThe hardware control panel. This lecture's main event.
$D000–$FFFFROMApplesoft BASIC and the Monitor. Full of useful routines you can call (Lecture 06).

2. Memory-mapped I/O: the big idea

The 6502 has no special "input/output" instructions. Instead, the Apple II's address-decoding logic routes certain addresses to hardware rather than to memory chips. Reading or writing those addresses does things:

These are called soft switches: switches you flip with software. For most of them the value you write is irrelevant — the mere act of accessing the address flips the switch.

6502 CPU A = $00 Address decoder $0000–$BFFF → RAM $C000–$C0FF → hardware $D000–$FFFF → ROM $C000 Keyboard latch: $C1 ('A') Speaker $C1 Two bus transactions: read the keyboard at $C000, then click the speaker at $C030. BASIC equivalent: K = PEEK (-16384) : POKE -16336,0 (negative numbers are how Applesoft writes addresses ≥ $8000: -16384 = $C000, -16336 = $C030)

Animated: memory-mapped I/O. The CPU issues ordinary memory reads; the address decoder notices the address is in $C0xx and routes it to hardware instead of RAM. The keyboard answers with a byte; the speaker just moves.

3. The soft-switch cheat sheet

AddressPEEK/POKE from BASICEffect
$C000PEEK(-16384)Read keyboard: value ≥ 128 means a new key is waiting (subtract 128 for the ASCII code)
$C010POKE -16368,0Clear the keyboard strobe (acknowledge the key)
$C030X = PEEK(-16336)Toggle the speaker once (a click)
$C050POKE -16304,0Display graphics instead of text
$C051POKE -16303,0Display text
$C052POKE -16302,0Full-screen graphics (no text window)
$C053POKE -16301,0Mixed: graphics with 4 text lines at the bottom
$C054POKE -16300,0Show page 1
$C055POKE -16299,0Show page 2 (the key to flicker-free animation)
$C056POKE -16298,0Lo-res graphics mode
$C057POKE -16297,0Hi-res graphics mode
TRY IT: In your emulator, type this one-liner and press Return — you'll hear a buzz built from 200 individual speaker clicks:
FOR I = 1 TO 200 : X = PEEK (-16336) : NEXT
Then flip the display to graphics and back without drawing anything:
POKE -16304,0 : FOR I = 1 TO 1000 : NEXT : POKE -16303,0
CAREFUL: PEEK and POKE take decimal addresses, and Applesoft treats addresses above 32767 as negative numbers (address − 65536). That's why $C030 = 49200 appears as −16336. Both forms work: PEEK(49200) and PEEK(-16336) touch the same switch.

4. Pages: why the screen has two of everything

Notice the map has two text pages and two hi-res pages. The soft switches at $C054/$C055 select which one the video hardware displays. This enables double buffering, the same technique every modern game engine uses: draw the next frame on the hidden page, then flip the switch. The eye never sees a half-drawn frame. You'll use this in the graphics exercises.

Check your understanding

Q1. What happens when the CPU reads address $C030?

Q2. Where would you POKE a byte to make a character appear on screen?

Q3. Why is $0300 the traditional home for a beginner's machine-language routine?

← Lecture 02: The 6502 CPU Lecture 04: Graphics & Sound →