ZX Ideas
Loading the Screen Character by Character on the ZX Spectrum Using BASIC
In many games (e.g. MIKIE, BATMAN, ALIEN HIGHWAY) we can see this effective way of loading the SCREEN. This routine is only 178 bytes long, and anyone can incorporate it into their program.
However, the problem is not writing a program to load it; the bigger problem is converting the screen contents into a format that the loader can use.
First, we need to write a program to save the screen contents. For simplicity, this program is written in BASIC:
10 LET A=50000
20 FOR I=40000 TO 40255
30 GO SUB 100
32 POKE A+10,PEEK (I+6144)
35 LET A=A+11
40 NEXT I
50 FOR I=42048 TO 42303
60 GO SUB 100
62 POKE A+10,PEEK (I+4352)
65 LET A=A+11
70 NEXT I
80 FOR I=44096 TO 44351
90 GO SUB 100
92 POKE A-10,PEEK (I+2560)
95 LET A=A+11
96 NEXT I
98 STOP
100 RANDOMIZE I-23616
110 POKE A,PEEK 23670: POKE A+1,PEEK 23671
120 POKE A+2,PEEK I:POKE A+3,PEEK (I+256)
130 POKE A+4,PEEK (I+512):POKE A+5,PEEK (I+768)
140 POKE A+6,PEEK (I+1024):POKE A+7,PEEK (I+1280)
150 POKE A+8,PEEK (I-1536):POKE A+9,PEEK (I+1792)
160 RETURN
To use the program above, load your SCREEN at address 40000. First, lower RAMTOP to 39999.
Load (type in) the BASIC program above and run it. It will generate a new SCREEN format starting at address 50000. Its length will increase from 6912 bytes to 8448 bytes. Save this code to tape with:
SAVE NOVISCRE CODE 50000
We won’t need the header, so don’t save it. Those who have been reading carefully so far are surely wondering how our routine will know how much to load. The CARRY FLAG takes care of that.
Throughout the loading process its value is 1; at the end of loading, it becomes 0. The RET NC instruction (return if there is no carry) then exits the routine.
When you have finished saving the SCREEN, load the machine-code routine at address 40000. Start loading the SCREEN character by character with RANDOMIZE USR 40000, and play the tape with the saved SCREEN (without the header). And there you are—the result of your work is right before your eyes! Here is the machine-code section in DATA form:
10 DATA 243,205,70,156,
20 DATA 62,198,184,48,224
30 DATA 205,207,156,208,
Save this machine code with:
SAVE SCREEN CODE B.J.
Share your thoughts about the article