Introduction to the Spectrum’s Memory Map
The ZX Spectrum is a 48KB machine with a simple, fixed memory map. Understanding this map is crucial because the Z80 must interact with the screen and system variables at hardcoded addresses.
The 64KB address space is divided into four main 16KB blocks:
Address Range | Size (KB) | Content | Usage |
---|---|---|---|
0000H - 3FFFH |
16 KB | System ROM | Holds the BASIC interpreter and operating system kernel. |
4000H - 7FFFH |
16 KB | Low RAM | Holds the Display File (Screen + Attributes) and user data. |
8000H - BFFFH |
16 KB | High RAM 1 | General purpose user program space. |
C000H - FFFFH |
16 KB | High RAM 2 | Used for user programs and the CPU Stack (grows downwards). |
The Display File (Screen Memory)
The most important fixed addresses are those related to the screen, which resides in the low RAM area.
Address | Size (Bytes) | Content |
---|---|---|
4000H |
6144 B | Pixel Data: The actual dots on the screen (Part 23). |
5800H |
768 B | Attribute Data: Color, bright, and flash data (Part 24). |
Key Code: To plot to the top-left corner, you must start writing at address 4000H
.
The Program Entry Point (ORG)
In most cases, Z80 assembly programs for the 48K Spectrum are loaded and run immediately after the system has finished booting.
Standard Start Address: Programs typically begin at address `8000H′ because the RAM below is used by BASIC and system files.
ORG 8000H ; Standard start address for user code
START:
LD SP, FFFFH ; Initialize Stack Pointer to the top of RAM (FFFH)
CALL MAIN_ROUTINE ; Begin program execution
; The code ends by returning to BASIC via a system call or RST
RST 08H ; Common BASIC routine call (implementation specific)
Key System Variables
The Spectrum’s operating system stores crucial running information in fixed RAM addresses.
Address | Content | Purpose |
---|---|---|
5C3B |
2 B | CH_ADD (Channel Address) |
5C6A |
2 B | FRAMES |
Usage: The FRAMES variable is often read to provide basic timing or simple random seed generation (Part 29).