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
Regions worth memorizing
| Range | Name | Why you care |
|---|---|---|
$0000–$00FF | Zero page | Instructions addressing it are shorter and faster. BASIC and DOS claim most of it; a few locations are free for your programs. |
$0100–$01FF | Stack | Fixed home of the 6502 stack. Don't put data here. |
$0300–$03CF | Free page 3 | Traditional scratch area for small machine-language routines — nothing in the system uses it. Your first assembly program goes here. |
$0400–$07FF | Text page 1 | The visible 40×24 text screen. POKE here and characters appear. |
$0801… | BASIC program | Where Applesoft stores your program text, growing upward; variables above that. |
$2000–$3FFF | Hi-res page 1 | The 280×192 graphics screen — 8K of pixels. |
$C000–$C0FF | Soft switches | The hardware control panel. This lecture's main event. |
$D000–$FFFF | ROM | Applesoft 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:
- Read
$C000→ you get the last key pressed (plus a "new key" flag in bit 7). - Touch
$C010→ clears that flag so you can detect the next key. - Touch
$C030→ the speaker cone pops in or out. Toggle it fast enough and you get a tone. - Touch
$C050/$C051→ the display switches to graphics / back to text.
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.
3. The soft-switch cheat sheet
| Address | PEEK/POKE from BASIC | Effect |
|---|---|---|
$C000 | PEEK(-16384) | Read keyboard: value ≥ 128 means a new key is waiting (subtract 128 for the ASCII code) |
$C010 | POKE -16368,0 | Clear the keyboard strobe (acknowledge the key) |
$C030 | X = PEEK(-16336) | Toggle the speaker once (a click) |
$C050 | POKE -16304,0 | Display graphics instead of text |
$C051 | POKE -16303,0 | Display text |
$C052 | POKE -16302,0 | Full-screen graphics (no text window) |
$C053 | POKE -16301,0 | Mixed: graphics with 4 text lines at the bottom |
$C054 | POKE -16300,0 | Show page 1 |
$C055 | POKE -16299,0 | Show page 2 (the key to flicker-free animation) |
$C056 | POKE -16298,0 | Lo-res graphics mode |
$C057 | POKE -16297,0 | Hi-res graphics mode |
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,0PEEK(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?