Skip to content

Text Utilities (BASIC)

Centre text on any row and clear rows — two tiny subroutines used in every BASIC game.

Taught in BASIC Game 1, Unit 1textcentreclearprintbasicutility

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.

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,(32-LEN t$)/2;t$
3020 RETURN
3100 REM === Clear row r (cols 2-29) ===
3110 PRINT AT r,2;"                            "
3120 RETURN

Trade-offs

Aspect Detail
Speed Two PRINT AT calls — negligible overhead
Memory 4 lines of code total
Limitation Clear row assumes cols 1-30 (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 to avoid: Never. These are always useful.

Patterns: Screen Frame, Character Printing (assembly)

Vault: ULA | ZX Spectrum