Code status: maintained BASIC subroutine. The source listing is included below. Supply the caller and inputs described here before using it. ROM-loaded standalone checks now cover floor centring, empty/full-width text and the clear-row footprint.
Audit execution record · Scope and remaining checks
Overview
Two subroutines that appear in every Spectrum BASIC game. Centre text calculates the column from the string length and prints at the midpoint. Clear row overwrites a row with spaces. Together they handle all status messages, titles, and feedback text without manual column counting.
Calling the routines
For GO SUB 3000, supply integer row r in 0–21 and a printable string t$ of length 0–32. Integer division leaves an odd spare column on the right. The routine does not clear an earlier, longer message: clear the owned area before replacing it.
For GO SUB 3100, supply r in 0–21. It clears exactly columns 2–29, leaving the surrounding columns alone. It inherits INK, PAPER, BRIGHT and FLASH; choose them before calling. Neither routine reserves a temporary variable, but both change the print cursor and display.
Code
10 REM Text utilities
20 REM Pattern: reusable across games
30 REM
40 REM Centre text:
50 REM LET r=10: LET t$="Hello": GO SUB 3000
60 REM Set INK, BRIGHT, FLASH etc before calling
70 REM
80 REM Clear row (cols 2-29, inside a frame):
90 REM LET r=10: GO SUB 3100
100 REM
3000 REM === Centre text t$ on row r ===
3010 PRINT AT r,INT ((32-LEN t$)/2);t$
3020 RETURN
3100 REM === Clear row r (cols 2-29) ===
3110 PRINT AT r,2;" "
3120 RETURNTrade-offs
| Aspect | Detail |
|---|---|
| Speed | Two PRINT AT calls — negligible overhead |
| Memory | 4 lines of code total |
| Limitation | Clear row writes cols 2–29 (inside a frame). Adjust for full-width |
| Flexibility | Set INK, BRIGHT, FLASH before calling — the subroutine inherits them |
When to use: Every game. Title screens, feedback messages, score displays, prompts.
When another approach helps: Dense HUD values often need stable left or right edges rather than centring. Clear only the area owned by that message.
Related
Patterns: Screen Frame, Character Printing (assembly)
Vault: ULA | ZX Spectrum