T/S 1000 Corner

Author(s): Jim Rodlin
Pub Details: Sinclair Timex User Group Newsletter v7 n1 (Volume 7, Issue 1)
Date: January 1988
Pages: 2

I wrote this program one day while trying to figure out how to read the TS1000 display file.

10 REM MINES by Jim Rodlin
20 LET x=15
30 LET y=10
40 LET sc=PEEK 16396 + 256*
PEEK 16397
50 PRINT AT 21,RND*31;CHR$ 4; AT
21,RND*31;CHR$ 4; AT 21,31;" "
60 LET y=y+(1 AND INKEY$ = "6")
+ (-1 AND INKEY$ = "7")
70 LET x=x+(1 AND INKEY$ = "5")
+ (-1 AND INKEY$ = "8")
80 IF PEEK (SC+33*(y)+x+1) = 4
THEN GOTO 120
90 PRINT AT y,x;"+"
100 SCROLL
110 GOTO 50
120 FOR Z = 1 TO 5
130 PRINT AT y,x;"*"; AT y,x;
"[INVERSE ASTERISK]"
140 NEXT z
150 PRINT AT y,x;CHR$ 8

Notes: Line 130: Use SHIFT-9 “*” SHIFT-9 for inverse asterisk.

The point of this program is to figure out what’s on the screen at a particular print position. It’s a game of driving a jeep through a minefield. Use arrow keys to avoid the mines. If you hit a mine, the jeep blows up and the game stops.

Most computers (including the 2068) store display files as 24 rows each with an even number of characters. It is more complicated [Simpler? Ed.] in the T/S 1000 and ZX-81. To conserve memory, the engineers at Sinclair Research developed an ingenious method of storing the display file: a blank screen consists of 25 ENTERS. What a T/S 2068 takes over 6 kilobytes to do is done on a T/S 1000 with only 25 bytes! The first byte in the display file is an ENTER and each row of the TS1000’s display consists of the characters in that row, plus ENTER.

(This data storage method is only used when there is less than about 3 1/4 K of free RAM. With expanded memory, the screen is stored conventionally, with 32 bytes + ENTER for each line.)

However, this creates a nightmare for the programmer who wants to read the display but does not know what is on the screen! Since the contents of the computer’s memory are constantly changing, the display file moves around a lot. This is because the display file is stored above a stored program in memory. When program lines are added or deleted, the display file is shifted up or down in RAM to fill in the gaps. (This is why the screen clears each time you enter a command).

A system variable called “D_FILE” keeps track of the display file’s location. The formula PEEK 16396 + 256* PEEK 16397 returns the start of the display file. In line 40, “SC” holds this value.

Line 50 prints a space at the right edge of the screen every time. In an unexpanded machine this is needed to ensure that each line has 32 characters.

Line 40 finds the beginning of D_FILE. Each line has 32 bytes plus ENTER, so for each row down the screen add 33. To look at the Nth column of that row, look forward N bytes plus one (the first byte of D_FILE is always ENTER). PEEK that location to get the character code for the character PRINTed there. The character at 12,14 will be: CHR$(PEEK D_FILE+33*12+14+1)

The magic formula is in line 80 of the program. When it finds a mine printed in this location, it means you’ve run over it and the game ends. Have fun!

  • Jim Rodlin

Transcription note: the magazine printed two lines numbered 140; typed in order, the second would replace 140 NEXT z and the explosion would flash only once, so it is renumbered 150 here.

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