Working with the ZX81/TS1000 Display File

Author(s): Ken Abramson
Publication: ZX-Appeal
Date: July/August 1986
Pages: 19-21

The April, 86 Newsletter (Page 4) gave a neat little drawing program called, “PAINT.” Here is the original listing:

  10 REM PAINT
11 REM PHIL DOUGHTY
VIDIOM
P.O. BOX 3118
PROVIDENCE, RI 02906
15 LET Z=0
20 LET X=5
30 LET Y=5
35 INPUT S$
40 PRINT AT Y,X;S$;
50 IF Z THEN PRINT AT Y,X;" ";
60 IF INKEY$="5" AND X>0 THEN LET X=X-1
70 IF INKEY$="8" AND X<31 THEN LET X=X+1
80 IF INKEY$="6" AND Y<21 THEN LET Y=Y+1
90 IF INKEY$="7" AND Y>0 THEN LET Y=Y-1
100 IF INKEY$="0" THEN LET Z=NOT Z
115 IF INKEY$="C" THEN GOTO 35
120 GOTO 40
9998 SAVE "PAINT"
9999 RUN

PROBLEM:

When the drawing is finished, you must BREAK the program in order to COPY the screen to the printer. Once your beautiful drawing has been printed, it will disappear when you try to restart the program.

Many people do not realize that the Display File (screen memory) can easily be saved by saving while the program is running and the drawing is still on the screen. Add the following line to the above program:

117 IF INKEY$="S" THEN SAVE "PAINT"

Just press “S” while the finished drawing is still on the screen and your drawing will be saved.(By the way, delete the last two program lines; lines 9998 and 9999 are no longer needed.) The drawing should come back on the screen after being saved, and you can continue working on it.

The trouble remains, however, that once you BREAK the program to COPY to the printer, you cannot restart the program without losing your original screen. What to do? Simply insert your COPY command into the program as another program line:

118 IF INKEY$="Z" THEN COPY

You can now retain the screen after COPYing, save your screen on tape at any stage and resume working on it at any stage.

Bingo! we now have a practical drawing program. Now add a little instruction menu for user friendliness and there you have it… a powerful little drawing program in less than 1k!:

  10 REM **ZXDRAW**
BY KEN ABRAMSON
20 REM BASED ON THE PROGRAM
"PAINT" BY PHIL DOUGHTY
30 REM THIS PROGRAM TAKES
PHILS PROGRAM SEVERAL STEPS
FURTHER BY ALLOWING YOU TO SAVE
A SCREEN DRAWING, HARDCOPY IT,
AND CONTINUE WORKING ON IT.
40 CLS
50 PRINT TAB 7;"ZXDRAW CONTROL KEYS",TAB 7;"▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒","5 -MOVES CURSOR LEFT",,,"6 -MOVES CURSOR DOWN",,,"7 -MOVES CURSOR UP",,,"8 -MOVES CURSOR RIGHT",,,"0 -DRAW (CURSOR NOT FLASHING)"," -ERASE (CURSOR FLASHING)",,,"C -CHANGE DRAWING CHARACTER",,,"M -INSTRUCTION MENU",,,"S -SAVE SCREEN DIRECTLY TO TAPE",,,"Z -COPY TO PRINTER"
60 PRINT AT 21,0;"PRESS ENTER TO BEGIN DRAWING"
70 INPUT P$
80 SLOW
90 CLS
100 LET S$="*"
110 LET Z=0
120 LET X=15
130 LET Y=10
140 GOTO 160
150 INPUT S$
160 PRINT AT Y,X;S$;
170 IF Z THEN PRINT AT Y,X;" ";
180 IF INKEY$="5" AND X>0 THEN LET X=X-1
190 IF INKEY$="8" AND X<31 THEN LET X=X+1
200 IF INKEY$="6" AND Y<21 THEN LET Y=Y+1
210 IF INKEY$="7" AND Y>0 THEN LET Y=Y-1
220 IF INKEY$="0" THEN LET Z=NOT Z
230 IF INKEY$="C" THEN GOTO 150
240 IF INKEY$="S" THEN SAVE "ZXDRAW"
250 IF INKEY$="Z" THEN COPY
260 IF INKEY$="M" THEN GOTO 40
270 GOTO 160

PROBLEM:

Can more than one screen be drawn, stored, and saved using a single program?

So far, our drawing program is capable of saving the Display File directly from RAM. But the program can only save one screenful in total, whether the computer is using 2K or 16K of RAM.

Using 16K of RAM should permit the storage of several screens if the contents of the Display File are dumped into a different string variable array each time a screen is finished. This process has a major disadvantage, since the poor old T/S1000 takes a long time (about 15 seconds even in FAST MODE) to dump the 726 byte Display File into a string array, and just as long a time to POKE the stored string characters back into the Display File in order to show a screen.

The following program illustrates the use of a string array for storing a screen and regenerating the screen from storage:

  10 REM **ZXDRAW** (T/S1000)
BY KEN ABRAMSON
20 REM THIS PROGRAM SHOWS HOW
TO SAVE THE DISPLAY FILE IN A
STRING ARRAY (LINES 400 TO 450)
AND HOW TO POKE THE STRING
CHARACTERS BACK INTO THE
DISPLAY FILE OR SCREEN MEMORY
(LINES 540 TO 590).
30 LET D$=""
40 LET S$="*"
50 SLOW
60 CLS
70 PRINT ,,,,TAB 10;"ZXDRAW MENU",TAB 10;"▒▒▒▒▒▒▒▒▒▒▒",,,TAB 2;"1. NEW DRAWING",,TAB 2;"2. CONTINUE DRAWING",,,TAB 2;"3. COPY DRAWING ONTO SCREEN",,,TAB 2;"4. COPY DRAWING TO PRINTER",,,TAB 2;"5. SAVE SCREEN TO TAPE"
80 IF INKEY$="1" THEN GOTO 170
90 LET C$=INKEY$
100 IF INKEY$="2" THEN GOTO 530
110 LET C$=INKEY$
120 IF INKEY$="3" THEN GOTO 530
130 LET C$=INKEY$
140 IF INKEY$="4" THEN GOTO 530
150 IF INKEY$="5" THEN GOTO 480
160 GOTO 80
170 CLS
180 PRINT TAB 10;"CONTROL KEYS",TAB 10;"▒▒▒▒▒▒▒▒▒▒▒▒","5 -MOVES CURSOR LEFT",,,"6 -MOVES CURSOR DOWN",,,"7 -MOVES CURSOR UP",,,"8 -MOVES CURSOR RIGHT",,,"0 -DRAW (CURSOR NOT FLASHING)"," -ERASE (CURSOR FLASHING)",,,"C -CHANGE DRAWING CHARACTER",,,"M -MAIN MENU",,"(SAVES SCREEN TO RAM FIRST)",,,"S -SAVE SCREEN DIRECTLY TO TAPE"
190 PRINT AT 21,0;"PRESS ENTER TO BEGIN DRAWING"
200 INPUT P$
210 SLOW
220 CLS
230 LET Z=0
240 LET X=15
250 LET Y=10
260 GOTO 280
270 INPUT S$
280 PRINT AT Y,X;S$;
290 IF Z THEN PRINT AT Y,X;" ";
300 IF INKEY$="5" AND X>0 THEN LET X=X-1
310 IF INKEY$="8" AND X<31 THEN LET X=X+1
320 IF INKEY$="6" AND Y<21 THEN LET Y=Y+1
330 IF INKEY$="7" AND Y>0 THEN LET Y=Y-1
340 IF INKEY$="0" THEN LET Z=NOT Z
350 IF INKEY$="C" THEN GOTO 270
360 LET L$=INKEY$
370 IF INKEY$="S" THEN GOTO 400
380 IF INKEY$="M" THEN GOTO 400
390 GOTO 280
400 FAST
410 DIM D$(726)
420 LET D=PEEK 16396+256*PEEK 16397
430 FOR F=1 TO 726
440 LET D$(F)=CHR$ PEEK (D+F)
450 NEXT F
460 IF L$="S" THEN GOTO 500
470 GOTO 50
480 IF D$="" THEN GOTO 670
490 CLS
500 PRINT AT 21,0;"WHEN TAPE IS READY, PRESS ENTER"
510 INPUT P$
520 SAVE "ZXDRAW"
530 IF D$="" THEN GOTO 670
540 FAST
550 CLS
560 LET D=PEEK 16396+256*PEEK 16397
570 FOR F=1 TO 726
580 POKE D+F,CODE D$(F)
590 NEXT F
600 SLOW
610 IF C$="3" THEN GOTO 720
620 IF C$="4" THEN COPY
630 IF C$="2" THEN GOTO 280
640 FOR P=1 TO 150
650 NEXT P
660 GOTO 50
670 CLS
680 PRINT AT 10,7;"USE MENU CHOICE 1."
690 FOR P=1 TO 30
700 NEXT P
710 GOTO 50
720 PRINT AT 21,0;"PRESS ENTER FOR MENU"
730 INPUT P$
740 GOTO 50

Line 410 sets aside 726 bytes in which to store the contents of the Display File (22 lines * 32 columns + 22 slots for ENTER characters needed at the end of each line).

Line 420 calculates the address of the beginning of the Display File.

Lines 430 to 450 store each byte of the Display File in correct order in the string array D$. Other drawings could be stored in other string arrays, e.g. A$, B$, C$, etc.

To get the drawing from the string array back to the screen, each byte must be POKED back into the Display File.

Line 560 again locates the address of the beginning of the Display File (which moves around).

Lines 570 to 590 POKE each byte from the string array, D$, into each successive address in the Display File. Again, by accessing stored information from other string arrays, other screens may be generated.

The above program may be expanded to store at least ten screens. You may like to try your hand at this yourself, or a ten screen version will soon be found in our software library for circulation. If you DO create some interesting graphics, please send them to the Newsletter. HAPPY DRAWING!!!

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