Scrolls

This file is part of and SINCUS Exchange Tape 102 - Utilities & Business. Download the collection to get this file.
Developer(s): Tim Hartnell
Date: 1983
Type: Program
Platform(s): TS 2068
Tags: Demo

This program demonstrates eight different software-driven text scroll routines in BASIC, sourced from the book “Mastering Your Timex” by Hartnell and Jones. The core technique stores the entire 22-row by 32-column display (704 characters) in a single string array variable, then shifts it by manipulating substrings before reprinting with PRINT AT 0,0. Vertical scrolls move the string by 32-character (one row) increments, while horizontal scrolls use a nested loop stepping through each row with STEP 32 to shift characters one position at a time. Wrap-around variants preserve the displaced characters by concatenating the “scrolled-off” portion back onto the opposite end of the string rather than replacing with spaces.


Program Analysis

Program Structure

The program is organized into a menu front-end (lines 4–21) and eight self-contained scroll subroutines located at high line numbers (9500–9850). Each routine is reached by a direct GO TO from the menu dispatcher and returns to line 1 (which falls through to the menu at line 6) via GO TO 1. The high-numbered placement of the routines is a common BASIC practice to keep them out of the way of any future expansion of the main program body.

Display Buffer Strategy

Every routine allocates a 704-character string array a$ with DIM a$(704). This exactly models the 22-row × 32-column visible text area (22 × 32 = 704). The user fills this buffer via INPUT "Enter text: ";a$, and the entire buffer is blasted to the screen each iteration with PRINT AT 0,0;a$, relying on the interpreter to wrap the long string across rows automatically.

Scroll Algorithms

The eight routines fall into two families — non-wrapping (options 1–4) and wrapping (options 5–8) — each covering all four cardinal directions.

OptionDirectionWrapKey operation
1UpNoa$=a$(33 TO )+"                                "
2DownNoa$="                                "+a$( TO 672)
3LeftNoPer-row: a$(f TO f+31)=a$(f+1 TO f+31)+" "
4RightNoPer-row: a$(f TO f+31)=" "+a$(f TO f+30)
5UpYesa$=a$(33 TO )+a$( TO 32)
6DownYesa$=a$(673 TO )+a$( TO 672)
7LeftYesPer-row: a$(f TO f+31)=a$(f+1 TO f+31)+a$(f)
8RightYesPer-row: a$(f TO f+31)=a$(f+31)+a$(f TO f+30)

Vertical scrolls operate on the whole 704-character string in a single assignment, shifting by 32 characters per step. Horizontal scrolls use a FOR f=1 TO 673 STEP 32 inner loop to process each of the 22 rows individually, shifting by one character per step within each 32-character row slice.

Notable Techniques

  • Single-string display buffer: Packing the entire screen into one string and printing it with a single PRINT AT 0,0 avoids the overhead of per-row print statements and keeps the scroll loop tight.
  • Substring slice assignment: The BASIC interpreter supports in-place slice assignment (a$(f TO f+31)=...), allowing each row to be updated without rebuilding the entire string for horizontal scrolls.
  • Wrapping via concatenation: Wrap routines reattach the displaced portion directly — for example, scroll-up-with-wrap at line 9695 appends the first row back at the tail: a$=a$(33 TO )+a$( TO 32).
  • Menu input validation: Line 13 uses a compound IF a<1 OR a>8 THEN GO TO 12 to re-prompt on out-of-range input before the chain of equality tests at lines 14–21.

Bugs and Anomalies

  • Off-by-one in horizontal scroll loop bound: The FOR f=1 TO 673 STEP 32 loop visits 22 values: 1, 33, 65, …, 673. With a 32-character slice f TO f+31, the last iteration addresses characters 673–704, which is correct. However, the loop runs FOR n=0 TO 32 (33 iterations) for left/right scrolls, one more than the 32-column width needed for a full single-pixel shift cycle — the final iteration is redundant but harmless.
  • Re-declaration of a$ each routine: Every routine starts with DIM a$(704), which resets the array to spaces before the user fills it. This is intentional for isolation between menu selections but means any previous display content is discarded.
  • GO TO 1 target: Line 1 does not exist; execution falls through to line 4 (the first REM), then continues to line 6 where BORDER, PAPER, and CLS reset the display before the menu redraws. This is an intentional fall-through, not a bug.

Content

Appears On

Library tape from the Sinclair Computer Users Society (SINCUS).

Related Products

Related Articles

Image Gallery

Scrolls

Source Code

    4 REM ++ Scrolls in basic ++++
    5 REM From Mastering Your Timex       & by Hartnell and Jones
    6 BORDER 6: PAPER 6: CLS 
    8 INK 0
   10 PRINT AT 2,6;"SCROLLS IN BASIC";TAB 6;"----------------"
   11 PRINT AT 5,6;"1. Scroll upwards";AT 7,6;"2. Scroll downwards";AT 9,6;"3. Scroll to the left";AT 11,6;"4. Scroll to the right";AT 13,6;"5. Scroll up with wrap";AT 15,6;"6. Scroll down with wrap";AT 17,6;"7. Scroll left with wrap";AT 19,6;"8. Scroll right with wrap"
   12 INPUT "Which scroll?  ";a
   13 IF a<1 OR a>8 THEN GO TO 12
   14 IF a=1 THEN GO TO 9500
   15 IF a=2 THEN GO TO 9530
   16 IF a=3 THEN GO TO 9560
   17 IF a=4 THEN GO TO 9620
   18 IF a=5 THEN GO TO 9670
   19 IF a=6 THEN GO TO 9710
   20 IF a=7 THEN GO TO 9750
   21 IF a=8 THEN GO TO 9800
 9500 REM --------scroll up
 9510 DIM a$(704)
 9511 INPUT "Enter text: ";a$
 9512 FOR n=0 TO 22
 9513 PRINT AT 0,0;a$
 9515 LET a$=a$(33 TO )+"                                "
 9520 NEXT n
 9525 GO TO 1
 9528 REM ---------scroll down
 9530 DIM a$(704)
 9535 INPUT "Enter text: ";a$
 9537 FOR n=0 TO 22
 9540 PRINT AT 0,0;a$
 9545 LET a$="                                "+a$( TO 672)
 9550 NEXT n
 9555 GO TO 1
 9560 REM -------scroll left
 9565 DIM a$(704)
 9570 INPUT "Enter text: ";a$
 9575 FOR n=0 TO 32
 9580 PRINT AT 0,0;a$
 9585 FOR f=1 TO 673 STEP 32
 9590 LET a$(f TO f+31)=a$(f+1 TO f+31)+" "
 9595 NEXT f
 9600 NEXT n
 9605 GO TO 1
 9620 REM --------scroll right
 9625 DIM a$(704)
 9630 INPUT "Enter text: ";a$
 9635 FOR n=0 TO 32
 9640 PRINT AT 0,0;a$
 9645 FOR f=1 TO 673 STEP 32
 9650 LET a$(f TO f+31)=" "+a$(f TO f+30)
 9655 NEXT f
 9660 NEXT n
 9665 GO TO 1
 9670 REM ----scroll up with wrap
 9675 DIM a$(704)
 9680 INPUT "Enter text: ";a$
 9685 FOR n=0 TO 22
 9690 PRINT AT 0,0;a$
 9695 LET a$=a$(33 TO )+a$( TO 32)
 9700 NEXT n
 9705 GO TO 1
 9710 REM ----scroll down with   wrap
 9715 DIM a$(704)
 9718 INPUT "Enter text: ";a$
 9720 FOR n=0 TO 22
 9725 PRINT AT 0,0;a$
 9730 LET a$=a$(673 TO )+a$( TO 672)
 9735 NEXT n
 9740 GO TO 1
 9750 REM --scroll left with wrap
 9755 DIM a$(704)
 9760 INPUT "Enter text: ";a$
 9765 FOR n=0 TO 32
 9770 PRINT AT 0,0;a$
 9775 FOR f=1 TO 673 STEP 32
 9780 LET a$(f TO f+31)=a$(f+1 TO f+31)+a$(f)
 9785 NEXT f
 9790 NEXT n
 9795 GO TO 1
 9800 REM -scroll right with wrap
 9805 DIM a$(704)
 9810 INPUT "Enter text: ";a$
 9815 FOR n=0 TO 32
 9820 PRINT AT 0,0;a$
 9825 FOR f=1 TO 673 STEP 32
 9830 LET a$(f TO f+31)=a$(f+31)+a$(f TO f+30)
 9835 NEXT f
 9840 NEXT n
 9850 GO TO 1
 9998 SAVE "SCROLLS" LINE 1
 9999 VERIFY ""

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

Scroll to Top