
Dummy Screen Memory Map
One of the programs you received on the APR-82 cassette was a game called BOUNCING-BOMES. This program uses a unique routine that memory-maps the CRT screen with BASIC programming commands.
The ZX-81 does not have as part of its resident utilities programmed in ROM, a screen memory mapping utility. Characters or graphics that appear on the screen are forgotten by the computer. If you want the computer to look at a certain part of the screen and see what is there, the ZX-81 does not have this capability from what is provided in its pre-programmed memory.
This does not mean that it can not be done.
The secret lies in correlating the information that appears on the screen, as it appears on the screen, with memory locations in RAM.
Sounds confusing, doesn’t it? Think of your computer’s memory banks as being a large hotel. This building is 64 stories tall. Each floor has 1024 rooms to it.
The first 16 floors are pretty much taken up by utilities used to keep the hotel operational. These are the ROM or Read Only Memory floors. For all practical purposes, you can not put anything into the rooms on these floors. The hotel manager (Z-80 microprocessor) will allow you to use any of the above floors starting with the 17th and will also allow you any of the services provided by the lower floors.
If you have a 1K machine, this means you have rented the entire 17th floor and can put anything into any of the rooms on that floor. These floors are known as RAM or Random Access Memory.
If you have a 16K machine, you have rented the floors from 17 to 32 and a total of 16,384 rooms.
Let us look at the following program. This is not a memory mapping program but it will show you how to POKE information into those rooms and then PEEK into those rooms and recall it. To make the program a little more dramatic, the information will be recalled in the reverse order that it was entered.
10 PRINT "TYPE IN YOUR MESSAGE
AND ENTER"
20 INPUT A$
30 LET A = 17000
40 LET B = A
100 FOR N = 1 TO LEN A$
110 POKE A,CODE A$(N)
120 LET A=A+1
130 NEXT N
140 PRINT
150 PRINT A$
160 PRINT
200 FOR N = B + LEN A$ - 1
TO B STEP -1
210 PRINT CHR$ (PEEK N);
220 NEXT N
This program puts your message in an area starting in memory location 17000 and then recalls it. If you were to change the number 17000 in line 30 to a number low enough, the program would bomb, because the program itself resides in memory locations lower than 17000. The POKE routine in line 110 would actually destroy the operation of the existing program commands.
Try changing it to 16400 and see what happens (make sure you save it on cassette first).
Try changing it to 64000 and see what happens.
Why?
In the program, BOUNCING BOMBS, lines 15, 16 and 17 reset the memory locations from 30000 to 32000 to a value of 0. This is done just in case any stray numbers may have entered these locations.
The routine from lines 20 to 170 set up the screen graphics. Lines 90 to 130 build the random city and line 115 POKEs into memory the number (128) for each of the city’s building blocks starting with the possible memory location of 30000. The memory locations correspond with the screen co-ordinates of each building block.
Line 400 determines if the (Z) key was pressed at the proper time and if it was, the program proceeds to create a graphic bomb that moves from one screen location to another. The graphic bomb is PLOTted into its new screen location and its previous location is UNPLOTted.
If the graphic bomb happens to occupy the same screen location as one of the building’s blocks, the block will disappear. This is determined by the routine starting at line 2000. It PEEKs into the corresponding memory location and if it finds the number (128) residing there, it goes through a series of routines that add a point to your score and change the contents of that memory location back to (0). This way if a bomb ever enters that memory location again, it is instructed to pass right through it without adding points to your score and if no blocks were encountered during the bombs travel, another rouutine credits you with a miss.
The following is a short program that demonstrates the memory mapping of the screen without POKEing the information into memory. Consult page #89 of your ZX-81 manual for screen co-ordinate locations.
100 PRINT "ENTER YOUR NAME"
110 INPUT A$
120 LET A = LEN A$
130 DIM X(A)
140 DIM Y(A)
200 FOR N = 1 TO A
210 LET X(N) = INT (10 * RND)
220 LET Y(N) = INT (32 * RND)
230 PRINT AT X(N),Y(N);A$(N)
240 NEXT N
300 PRINT AT 10,0;"CO-ORDINATES
(X) (Y)"
310 FOR N = 1 TO A
320 PRINT A$(N);TAB 16;X(N);TAB
23;Y(N)
330 NEXT N
The routine starting at line 100 dimensionalizes all the variables. It allows the total fmount of each variable to be equal to the amount of characters in your name (11 is the limit).
The routine starting at line 200 picks random screen positions for these characters to appear on the top half of the screen.
The routine starting at line 300 cross-references these positions to the variables held in memory and prints them on the lower half of the screen.
You may notice that sometimes, letters are missing but their positions are listed. This is because the screen co-ordinates that were picked at random, were picked again for a different character. This can easily be evidenced by looking for duplicate co-ordinate positions.
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.