5 Out of screen
Sinclair ZX Spectrum
Severity: MinorWhat Does This Error Mean?
Error 5 on the ZX Spectrum means a PRINT AT or PLOT command tried to write outside the visible screen area. The Spectrum screen is 32 columns by 24 rows for text, or 256x176 pixels for graphics. Check your coordinates are within these limits.
Affected Models
- Sinclair ZX Spectrum 48K
- Sinclair ZX Spectrum 128K
- Spectrum+
- Spectrum +2
- Spectrum +3
- ZX Spectrum Next
- Fuse emulator
Common Causes
- PRINT AT with row above 21 or column above 31
- PLOT with X above 255 or Y above 175
- DRAW going beyond the screen edges
- Loop variable causing coordinates to exceed screen limits
- Trying to PRINT AT in the bottom two rows (reserved for input)
How to Fix It
-
Check PRINT AT coordinates: row 0-21, column 0-31.
PRINT AT 22,0 causes error 5 because rows 22 and 23 are reserved for the input area. The last usable row for PRINT AT is 21.
-
Check PLOT coordinates: X 0-255, Y 0-175.
PLOT 256, 0 causes error 5 because X must be 0-255. PLOT 0, 176 also fails because Y must be 0-175.
-
Add bounds checking before PRINT AT or PLOT.
Before PLOT X, Y add: IF X > 255 OR Y > 175 THEN GOTO (skip line) This prevents the error when coordinates are calculated dynamically.
-
For DRAW: check that the line stays within screen bounds.
DRAW draws relative to the last PLOT position. If DRAW takes the pen outside the screen, you get error 5.
Frequently Asked Questions
Why are the bottom two rows reserved?
The Spectrum reserves rows 22 and 23 for system messages and INPUT. When you type INPUT A$, the prompt appears in these bottom rows. You can print there using PRINT #0, but PRINT AT cannot access them.
Why is the Y coordinate for PLOT different from PRINT AT?
PRINT AT uses row 0 at the top and row 21 at the bottom. PLOT uses Y=0 at the bottom and Y=175 at the top — the axes are flipped. This matches mathematical convention where Y increases upward.