Hampsons Plane

This file is part of Timex Sinclair Public Domain Library Tape 1003 . Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 1000
Tags: Game

Hampson’s Plane is a two-player or puzzle-style board game displayed on a 26×20 grid of plus signs, with columns labelled A–Z and rows 1–20. The player enters moves as a letter-number pair (e.g. A1) via INPUT into a three-character string, and the program decodes the column using CODE() minus 35 and the row using VAL on the substring. The core mechanic is a 3×3 neighbourhood toggle: for each move, the program reads the display file address from system variables at 16396–16397 and uses PEEK/POKE to flip cells between two character codes (21 and 149, which correspond to the ‘+’ character and its inverse). A random scramble of five moves is applied at startup to set an initial board state, and a skill level is accepted but appears to have no further effect in this listing.


Program Analysis

Program Structure

The program is organised into four logical phases, each roughly separated by REM statements carrying inverse-video labels:

  1. Setup & display (lines 10–101): Print the title, instructions, skill-level prompt, and draw the 26×20 grid of + characters with letter column headers and numeric row labels.
  2. Initialisation (lines 103–265): Declare variables, build the 3×3 neighbour offset array A(), and record the display-file base address.
  3. Scramble (lines 270–310): Apply five random moves to set an initial board state.
  4. Game loop (lines 320–440): Accept a coordinate string, validate it, and call the toggle subroutine at line 400.

Grid Layout

The grid is printed as 20 rows, each containing 26 + characters. The display is 32 characters wide on the ZX81, so each row occupies 33 bytes in the display file (32 chars + 1 NEWLINE token). Row labels are printed before and after each line of plusses, and column headers A–Z appear above and below.

Display-File Direct Access

Lines 260–425 implement the core mechanic using direct memory manipulation:

  • D = PEEK 16396 + 256 * PEEK 16397 reads the system variable D_FILE to find the base address of the display file.
  • Each cell address is computed as P = D + Y*33 + X + A(Z), where 33 is the row stride (32 chars + newline), Y is the row, X is the column offset from the start of the data area, and A(Z) is the neighbour delta from the prebuilt offset table.
  • The toggle logic at line 420 is: V = V - 128*(V=149) + 128*(V=21). Character code 21 is the normal + and 149 is its inverse; the expression subtracts 128 if the cell is already inverse (turning it normal) or adds 128 if it is normal (turning it inverse). This is a compact Boolean-arithmetic toggle idiom common in ZX81 BASIC.

Neighbour Offset Table

Array A(9) stores the byte offsets for all 8 neighbours plus the cell itself, forming a 3×3 kernel centred on the target cell. With a row stride of 33:

IndexValueRelative position
1−34row−1, col−1
2−33row−1, col
3−32row−1, col+1
4−1same row, col−1
50same cell
61same row, col+1
732row+1, col−1
833row+1, col
934row+1, col+1

This is the same neighbourhood mechanic as the Lights Out puzzle genre.

Move Input and Decoding

K$ is a 3-character DIM string. The player types a letter, a one- or two-digit row number, and presses ENTER. Column X is decoded with CODE(K$) - 35: the ZX81 character code for ‘A’ is 38, so subtracting 35 gives column offset 3 for ‘A’, matching the grid’s left margin. Row Y is read with VAL K$(2 TO ), which parses the numeric substring starting at position 2. Bounds checking at line 350 restricts valid input to columns 4–27 (B–Z approximately) and rows 2–19, keeping moves away from the header rows and border columns.

Skill Level

The skill level is accepted into variable S at line 40, but S is never referenced again in the listing. This is either an unimplemented feature or a remnant of a more elaborate version where difficulty may have controlled the number of scramble moves or validated move count.

Dummy Loop and RAND

Lines 103–106 implement a FOR W=1 TO 1 … NEXT W loop that executes exactly once and has no effect. This is likely a code stub. RAND at line 265 (without an argument) seeds the random number generator from the ZX81’s frame counter, ensuring a different scramble each game.

Notable Anomalies

  • The REM at line 39 contains inverse-video text reading APPL MOVE, and line 259 reads DISPLAY FILE, line 269 SCRAMBLE BOARD, line 319 GET MOVE, line 349 CHECK MOVE — these serve as section labels encoded in inverse video within REM statements.
  • The DIM K$(3) at line 150 reserves only 3 characters. Entering a two-digit row (e.g. “A10”) fills all three characters correctly, but a single-digit row such as “A5” would store “A5 ” with a trailing space; VAL "5 " returns 5 correctly on the ZX81, so this works in practice.
  • Line 600 RUN is never reached from within the main loop (which loops via GOTO 320), so it functions only as a manual restart point.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10122 – 10175.

Related Products

Related Articles

Related Content

Image Gallery

Hampsons Plane

Source Code

   1 REM HAMPSONS PLANE
  10 PRINT TAB 7;"HAMPSONS PLANE"
  20 PRINT 
  21 PRINT "MOVES SHOULD BE ENTERED AS      LETTER,NUMBER,ENTER"
  23 PRINT 
  30 PRINT "ENTER SKILL LEVEL"
  39 REM %A%P%P%L% %M%O%V%E
  40 INPUT S
  50 CLS 
  60 PRINT "  ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  70 FOR Z=1 TO 20
  80 IF Z<10 THEN PRINT " ";
  90 PRINT Z;"++++++++++++++++++++++++++";Z
 100 NEXT Z
 101 PRINT "  ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 103 FOR W=1 TO 1
 106 NEXT W
 110 LET D=0
 120 LET P=0
 125 LET V=0
 130 LET X=0
 140 LET Y=0
 150 DIM K$(3)
 160 DIM A(9)
 170 LET A(1)=-34
 180 LET A(2)=-33
 190 LET A(3)=-32
 200 LET A(4)=-1
 210 LET A(5)=0
 220 LET A(6)=1
 230 LET A(7)=32
 240 LET A(8)=33
 250 LET A(9)=34
 259 REM %D%I%S%P%L%A%Y% %F%I%L%E
 260 LET D=PEEK 16396+256*PEEK 16397
 265 RAND 
 269 REM %S%C%R%A%M%B%L%E% %B%O%A%R%D
 270 FOR W=1 TO 5
 280 LET X=INT (RND*24)+4
 290 LET Y=INT (RND*18)+2
 300 GOSUB 400
 310 NEXT W
 319 REM %G%E%T% %M%O%V%E
 320 INPUT K$
 330 LET X=CODE (K$)-35
 340 LET Y=VAL K$(2 TO )
 349 REM %C%H%E%C%K% %M%O%V%E
 350 IF X<4 OR X>27 OR Y<2 OR Y>19 THEN GOTO 320
 360 GOSUB 400
 370 GOTO 320
 400 FOR Z=1 TO 9
 410 LET P=D+Y*33+X+A(Z)
 415 LET V=PEEK (P)
 420 LET V=V-128*(V=149)+128*(V=21)
 425 POKE P,V
 430 NEXT Z
 440 RETURN 
 500 SAVE "1013%8"
 600 RUN 

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

People

No people associated with this content.

Scroll to Top