When you are writing a BASIC program it is often necessary to be able to switch between two screens of information. Perhaps you would like the user to be able to call a help screen, or have a player instantly “transported” to another location in an adventure game. It is simple to call the original screen drawing subroutine, but if the screen display is created by the user when the program is operating, there is no way to re-create it once it is erased or written over. This month’s column is about a program that solves that problem.
The following “Screen-Save” program is written in machine code and will allow you to instantly save and re-call two graphics screens in the memory of your computer. If you have a Spectrum ROM in your 2068 the program will also work. (The people who program on the 1000 series of Timex/Sinclair machines can find two articles on saving screens in issue #3 of T-S HORIZONS). You will have to enter and call the routine from BASIC but once it is in memory it can be saved and loaded along with the stored screens as machine code.
To enter the machine code, type in, save and run program 1. The machine code will be checked as it is being poked into memory and the program will inform you if you have made any typing errors. If you have not you can save the machine code to tape by pressing the “S” key. Press any other key and the program will stop. If you would like a demonstration of the program in operation type in program 2. It draws, saves and switches between two screens.
Using the machine code in your own programs
The first line in your basic program has to “make room” for the machine code and stored screens. Use the command ‘CLEAR 51484″. This will ensure that the BASIC program won’t write over your machine code. The code is actually comprised of four routines. Each one has a different function and is called by its own RANDOMISE USR command. The first routine saves the first screen into memory. It is called by: RANDOMISE USR 65319. The routine that re-calls the first screen using: RANDOMISE USR 65331. The routine to save screen 2 into memory is called by: RANDOMISE USR 65343. To re-call the second screen use: RANDOMISE USR 65355. To load the machine code from tape once it has been saved by program 1 use: LOAD “code”CODE . If you have saved two screens in memory and want to save them to tape use: SAVE “code”CODE 514484,14051 . This saves the program, the two screens, and any User Defined Graphics you might have created.
10 REM PROGRAM 1 *************
20 CLEAR 51495
30 LET c=0
40 FOR a=65319 TO 65366
50 READ b
60 LET c=c+a-(775*b)
70 POKE a,b
80 NEXT a
90 IF c<>6990 THEN PRINT "PLEASE CHECK FOR TYPING ERRORS!": STOP
100 PRINT "TYPING OK"
110 DATA 33,0,64,17,39,201,1,0,27,237,176,201,33,39,201,17,0,64,1,0,27,237,176,201,33,0,64,17,39,228,1,0,27,237,176,201,33,39,228,17,0,64,1,0,27,237,176,201
10 REM PROGRAM 2 *************
20 PAPER 5: CLS
30 FOR a=0 TO 77
40 PRINT "screen 1 ";
50 NEXT a
60 RANDOMIZE USR 65319
70 PAPER 6: CLS
80 FOR a=0 TO 77
90 PRINT "SCREEN 2 ";
100 NEXT a
110 RANDOMIZE USR 65343
120 FOR a=30 TO 1 STEP -1
130 RANDOMIZE USR 65331
140 PAUSE a
150 RANDOMIZE USR 65355
160 PAUSE a
170 NEXT a
180 PAPER 7: CLS
190 PRINT "DEMONSTRATION COMPLETE"
Now that you have the Screen-Save program up and running, you should be able to find some interesting uses for it. Perhaps you could even do a simple form of animation with it. Next issue I’ll be writing about the SCREEN$ function on the 2068 and 1000.
TSH
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.