Authors
Publication
Pub Details
Date
Pages
I wrote this program one day while trying to figure out how to read the TS 1000 display file.
The point of this program is to figure out what is 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 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 T/S 1000‘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/2k 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 : CHRS(PEEK D_FILE + 33 x 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.