When diving into programming for the Commodore 64, one of the most crucial aspects to grasp is how memory is organized and accessed by the 6502-based CPU. Unlike modern systems with gigabytes of RAM and virtual memory management, the C64 operates within a tight 64KB address space, and every byte counts.
The 6502’s 16-bit Address Space
The 6502 microprocessor at the heart of the C64 has a 16-bit address bus, which allows it to address 2¹⁶ = 65,536 bytes (64KB) of memory. This entire memory space is shared between RAM, ROM, I/O registers, and special-purpose areas like zero page and stack.
Key Memory Regions on the C64
Here’s a breakdown of the most important memory regions:
Address Range | Size | Purpose |
---|---|---|
$0000-$00FF | 256 B | Zero Page – fast access area |
$0100-$01FF | 256 B | Stack |
$0200-$03FF | 512 B | Screen input buffer, scratch |
$0400-$07E7 | ~2 KB | Screen RAM |
$0800-$9FFF | ~37 KB | Main RAM |
$A000-$BFFF | 8 KB | BASIC ROM (can be banked out) |
$C000-$CFFF | 4 KB | More usable RAM |
$D000-$DFFF | 4 KB | I/O Area & Character ROM |
$E000-$FFFF | 8 KB | KERNAL ROM |
Bank Switching and Memory Control
The C64’s memory map is more flexible than it seems, thanks to bank switching. Certain regions (especially $A000-$BFFF
, $D000-$DFFF
, and $E000-$FFFF
) can be switched between RAM and ROM (or I/O) by writing to the processor port at address $0001
.
This allows, for example:
- Replacing BASIC ROM with RAM for custom code.
- Temporarily disabling I/O to access the underlying RAM at
$D000-$DFFF
.
Zero Page and Stack
The zero page is a special 256-byte memory region ($0000-$00FF
) with optimized access: many 6502 instructions support special addressing modes for it, resulting in faster and smaller code.
The stack is fixed at page 1 ($0100-$01FF
) and used for subroutine calls, interrupts, and manual pushing/popping of data.
I/O and Peripherals
Memory-mapped I/O registers reside at $D000-$DFFF
, controlling:
- VIC-II (graphics)
- SID (sound)
- CIA chips (timers, I/O ports)
- Color RAM (at
$D800-$DBFF
, though not part of main RAM)
Final Thoughts
Understanding the C64’s memory layout is key to effective programming. While the 64KB may seem limited, careful planning and use of bank switching, zero page, and hardware registers allows for surprising complexity and performance.
Whether you’re writing assembly, optimizing BASIC routines, or building your own emulator, mastering this map is your first step toward truly understanding the C64’s architecture.