The Full Screen Data Load
To display a custom image on the Spectrum (e.g., a title screen or game level background), you must copy two large blocks of data from your program’s memory into the Spectrum’s Display File RAM.
The Two Blocks:
- Pixel Data: 6144 bytes of raw $256 \times 192$ pixel information (starts at `4000H′).
- Attribute Data: 768 bytes of color and flash information (starts at `5800H′).
Routine 1: Loading the Pixel Data
The Pixel Data is 6144 bytes long. Since the data layout is non-linear (Part 73), you generally copy the data block-by-block. However, if your source data is already arranged in the Spectrum’s non-linear format, you can use the fastest method: `LDIR′.
The LDIR Copy (Pixel Data):
PIXEL_RAM_START EQU 4000H
PIXEL_SIZE EQU 6144
LOAD_PIXELS:
LD HL, PIXEL_DATA_SOURCE ; HL ← Start address of the image data in your program's RAM/ROM
LD DE, PIXEL_RAM_START ; DE ← Destination screen memory (4000H)
LD BC, PIXEL_SIZE ; BC ← 6144 bytes to copy
LDIR ; High-speed block copy (Part 7)
RET
Routine 2: Loading the Attribute Data
The Attribute Data is 768 bytes long and is copied separately because it starts at a different address (`5800H′) and follows a linear layout (one byte for every $8\times 8$ character cell).
The LDIR Copy (Attribute Data):
ATTR_RAM_START EQU 5800H
ATTR_SIZE EQU 768
LOAD_ATTRIBUTES:
LD HL, ATTRIBUTE_DATA_SRC ; HL ← Start address of the attribute data
LD DE, ATTR_RAM_START ; DE ← Destination attribute memory (5800H)
LD BC, ATTR_SIZE ; BC ← 768 bytes to copy
LDIR ; High-speed block copy
RET
Storing the Raw Data
For the routines above to work, your program must contain the raw image data, defined using the `DB′ (Define Byte) directive (Part 14) somewhere in your assembly source code.
Data Definition Example:
ORG 9000H ; Image data placed after the main code
PIXEL_DATA_SOURCE:
DB 0AAH, 55H, 0F0H, 00H, ... ; First few bytes of your 6144 bytes of pixel data
ATTRIBUTE_DATA_SRC:
DB 3FH, 3FH, 3FH, 3FH, ... ; First few bytes of your 768 bytes of color data