This program implements a scrolling text-ticker display using a string buffer. The variable B$ accumulates characters and is printed at screen position AT 0,0, with a cursor marker (▖ followed by a space) appended to show the current insertion point. Four control keys—coded 112, 113, 114, and 115—provide editing functions: character deletion (backspace), forward scroll by one line (32 spaces), space insertion, and cursor movement. The string B$ is constrained to a maximum length of roughly 672 characters (21 screen lines × 32 columns), enforcing a soft upper bound on the text buffer. The program relies on raw INKEY$ polling in a tight loop (lines 100–120) rather than INPUT, giving it immediate single-keypress response.
Program Analysis
Program Structure
The program is divided into three functional regions:
- Initialisation (lines 10–20): Clears the buffer
B$and prints the initial cursor graphic. - Input loop (lines 100–120): Polls
INKEY$continuously until a key is pressed, then dispatches to the command handler. - Command handler (lines 1000–1530): A chain of
IFtests onCODE A$routes execution to one of four editing sub-routines, followed by a display refresh and a return to the input loop.
Key Codes and Their Actions
| Code | Key | Action | Handler |
|---|---|---|---|
| 114 | r | Backspace / delete last character | 1200 |
| 115 | s | Insert a single space | 1300 |
| 113 | q | Scroll forward one line (append 32 spaces) | 1400 |
| 112 | p | Scroll back one line (trim 33 chars from end) | 1500 |
Buffer Management
All text is held in the string B$. Normal printable characters are appended at line 1100 after the dispatch chain finds no matching control code. The buffer’s effective maximum length is enforced by the guard at line 1030: if LEN B$>672 when the scroll-forward key (q) is pressed, the operation is silently skipped by jumping directly to the display refresh at 1110. Similarly, line 1050 prevents the scroll-back operation when LEN B$<32, avoiding an attempt to slice a string shorter than 33 characters.
Cursor Display
The cursor is represented by the block graphic ▖ (ZX Spectrum char 130, zmakebas escape \. ) followed by a space. It is appended to B$ at print time (line 1110: PRINT AT 0,0;B$;"▖ ") but never stored in B$ itself, so the buffer always contains only the actual content.
Backspace Routine (lines 1200–1230)
The delete handler at line 1200 replaces the last character of B$ with a space (B$( TO LEN B$-1)+" "), prints this padded version to erase the on-screen character, then removes the trailing space before falling through to the normal display refresh. This two-step approach avoids leaving a ghost character on screen when the cursor graphic shifts left.
A guard at line 1000 prevents deletion when LEN B$=0, jumping straight to the refresh instead.
Scroll-Back Routine (lines 1500–1530)
The scroll-back (p) handler appends a space, prints the buffer with an extra trailing space to clear any residual cursor graphic, then trims 33 characters from the end with B$( TO LEN B$-33). The asymmetry with scroll-forward (which appends 32 spaces) is intentional: the extra character accounts for the temporary space appended at line 1500 before slicing.
Notable Techniques and Idioms
- Tight
INKEY$polling (lines 100–110) rather thanINPUTgives immediate single-keystroke response with no Enter key required. - The dispatch chain at lines 1000–1060 uses paired guards (check boundary, then check key code) so boundary violations fall through to the no-op path at 1110 without needing explicit
ELSEbranches. PRINT AT 0,0;redraws from the top-left on every keypress, effectively using the screen as a 32-column-wide viewport into the string buffer.- The cursor graphic is appended purely at print time, keeping
B$clean and simplifying all length arithmetic.
Content
Source Code
10 LET B$=""
20 PRINT AT 0,0;" ."
100 LET A$=INKEY$
110 IF A$="" THEN GOTO 100
120 GOTO 1000
1000 IF CODE A$=114 AND LEN B$=0 THEN GOTO 1110
1010 IF CODE A$=114 THEN GOTO 1200
1020 IF CODE A$=115 THEN GOTO 1300
1030 IF CODE A$=113 AND LEN B$>672 THEN GOTO 1110
1040 IF CODE A$=113 THEN GOTO 1400
1050 IF CODE A$=112 AND LEN B$<32 THEN GOTO 1110
1060 IF CODE A$=112 THEN GOTO 1500
1100 LET B$=B$+A$
1110 PRINT AT 0,0;B$;" . "
1120 GOTO 100
1200 LET B$=B$( TO LEN B$-1)+" "
1210 PRINT AT 0,0;B$
1220 LET B$=B$( TO LEN B$-1)
1230 GOTO 1110
1300 LET B$=B$+" "
1310 GOTO 1110
1400 LET B$=B$+" "
1410 GOTO 1110
1500 LET B$=B$+" "
1510 PRINT AT 0,0;B$+" "
1520 LET B$=B$( TO LEN B$-33)
1530 GOTO 1110
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
