Memotech Memopak 64

Publication: ZXir QLive Alive!
Pub Details: ZXir QLive Alive! v3 n4 (Volume 3, Issue 4)
Date: Winter 1993
Pages: 6-7

A few of our readers requested this information.

There are two memory locations which you change in order to tell the computer the upper limit of your memory (or RAMTOP). These are 16389 and 16388.

To set top of RAM at 64K, type the following:

POKE 16388,255 (this is not usually needed)
POKE 16389,255 (this is usually set at 128 for a 32K limit)
NEW (the memory is now cleared to start afresh; and will now be organized to the new limit).

To check the current top of RAM, type PRINT PEEK 16389 and the value 255 should appear in the top left-hand corner of the screen. For a quick check that the memory is now at your finger-tips you can now try the following little programs:

10 DIM A$(90,500)
or
10 DIM A(9000)
or
10 POKE 65000,128
20 PRINT PEEK 65000

These programs reach the top end of memory Remember numeric fields take up five bytes. (Tip_if you want to store more numbers and they are integers which don’t exceed 255, then why not use the CODE and CHR$ functions to store values as single byte characters?).

How can I test that all my variable locations are good?

First, set the top of RAM back to 32K (either POKE 16389, 128 or just power up again).

Type in this program which will test every bit in the 32-64K area, in FAST mode.

 10 FAST
20 FOR I = 32768 TO 65535
30 POKE 1,255
40 LET A = PEEK I
50 POKE 1,0
60 LET B = PEEK I
70 IF A<>255 0R B<>O THEN
GOSUB 130
100 NEXT I
110 PRINT "END OF RAM TEST"
120 STOP
130 SLOW
140 PRINT "ERROR AT:";I
150 STOP
160 FAST
170 RETURN

You can find how far your program has got by doing a BREAK. Resume by using CONT. The program will print an error message if a bad location is found, and halt. By keying CONT, the program will continue its testing.

If it reaches “END OF RAM TEST” without having shown an error, you’re now ready to start that BIG program.

What is where?

First of all, our pack does contain a full 64K RAM (and this can be used by other Z80 processors, in principle). But the ZX81 can only address 64K locations altogether, and the first 8K are obviously dedicated to its own ROM. So although we’ve got 64K RAM, and the ZX81 can address 64K locations, this MEMOPAK cannot add on more than 56K to the ZX81 ROM. This brings the ZX81 – MEMO-PAK configuration to 64K total. The original 1 K of RAM of the ZX81 (located at 16K + ) is disabled and its functions will take place in the MEMOPAK 64K RAM. Confused? There is a diagram on the inside cover to sort it out. The main thing to remember is that the top 48K is automatically used by the ZX81 BASIC.

As programs are entered into the system the elements are sifted into the instruction file and the array file. The instruction file, the display file (holding screen data) and the array file lie next to each other in that order at the bottom end of memory. Gradually, as the instruction file increases, the other files are pushed up through memory.

Remember, the original 1 K of RAM in the ZX81 (located at 16K+) has been disabled and all its functions take place in the MEMOPAK.

This pushing goes on until either the array file reaches the top of the memory or until the display file begins to straddle the 32K mark (by going above 32767).

Does this mean if I’ve got 32K or more of RAM, I still can’t have more than 15K or so of instructions?

No. Many people think you are restricted but there is a neat trick where you can force your display file to leap the 32K mark in one bound by putting in a large, dummy instruction. The important thing is to make sure that the display file never straddles the 32K mark. Here is how:

a) On input, check from time to time the value in the VARS system variable, as this lies just above the end of the display file:

PRINT PEEK 16401 * 256 + PEEK 16400

b) When the values of VARS approaches 32767, enter a huge line into the program, like: LET ZERO = O + O + O + O etc. with about 100 repetitions of [+0]. This will push the display file entirely above 32768.

c) Check the system variable D-FILE to make sure the display file now begins above 32768:

PRINT PEEK 16397 * 256 + PEEK16396

If it is, then you can carry on programming.

What about the mysterious 8-16K area?

On the ZX81 this area does not exist. We have supplied it, and you can now reach it directly in your BASIC program, using PEEK and POKE, or with machine code. The sort of thing you can use it for will depend on how expert you are, but we can suggest:

a) Storing data and machine code sub-routines
b) Passing them from one program to another
c) Memory-mapping buffer areas for add-ons.

For Sinclair ZX80/81 users, the simplest thing is to set switches 2 and 3 ON and 1 and 4 OFF (MODE E). This gives the biggest possible area. This is how the pack leaves us, and normally there will be no need to change the settings. The other settings are intended to accommodate the needs of special add-ons being developed.

MODE        SWITCH
--------------------------------------
-     1      2      3      4
--------------------------------------
A     ON     OFF    OFF    OFF
This mode is not compatible with the ZX80/81 but offers a
full 64K RAM to a Z80 that is designed to address it.
--------------------------------------
B*    OFF    ON     OFF    OFF
Memory is available in the 12-16K area.
--------------------------------------
C*    OFF    OFF    ON     OFF
Memory is available in the 8-12K area.
--------------------------------------
D*    OFF    OFF    OFF    ON
No memory is available in the 8-16K area.
--------------------------------------
E*    OFF    ON     ON     OFF
Memory is available in the 8-16K area.

\* In these cases, 48K for normal BASIC work is still available. Memory made available in the 8-16K area can be used with PEEK and POKE, or for machine code. For ZX81 users, switching between modes B, C, D and E is possible, as long as at least one and no more than two switches are ON at the same time. Never have more than two switches ON at a time, as this can lead to overloading. Remember ON is UP!

Have you any tips for running a ful ZX81 system?

Yes. These may or may not help in your situation. When connected to MEMOPAK 64K and printer, make sure that LOADing takes place with cassette recorder volume set at maximum. If possible, make sure that your cassette recorder and ZX81 are plugged into different main sockets. With some cassette recorders, you shouldn’t have the LOAD (EAR) and SAVE (MIKE) connectors plugged in at the same time. LOADing is more likely to be successful If you quote the file name, rather than null (” “). Clean your connectors regularly. Don’t use the first twenty seconds of a cassette tape, as that is where a lot of LOAD bugs live.

Can I run programs written for a 16K pack on the Memopak 64K?

Yes, they should run straight away, but things are a little tricky if you want to en-large your arrays to use the larger memory and you have been SAVEing your data. Basically, you have to re-enter all data after you have re-dimensioned, to be sure that the right data is going to be accessed. What we suggest is:

a) LOAD the original program.
b) Edit in a special routine which will list and label the contents of all variables on the printer.
c) Run this routine. You now have a hard copy of your data.
d) Re-set your dimensions. Also enter a routine to allow you to re-input all your old values plus any new ones.
e) Run your program and enter the values.

One more thing, to use the memory fully it is much better to use a multi-dimensional string array rather than a simple string, since the ZX81 limits single string sizes to a maximum length of 16K, and also duplicates it unnecessarily.

A couple of program examples

BASIC strings are stored in the instruction area of RAM (16-32K). This means that when you set a literal, say, LET A$ = “CAT” the word CAT is actually duplicated, once as a literal as part of the instruction, and once in the variable area A$. It would be more economical if we could set up an initialization routine which would store all literals once only in the variables area. This simple loop would let you input up to 10 strings of 20 characters each:

 10 DIM A$(10,20)
20 INPUT I
30 IF I = O THEN GOT0 70
40 INPUT B$
50 LET A$(1) = B$
60 GO TO 20
70 INPUT I
80 IF I = O THEN GOTO 110
90 PRINT A$(1)
100 GOTO 70
110 REM AUTOMATIC SELF SAVE
120 SAVE "SELF"
130 GOTO 20
140 STOP

Breakdown:
Lines 20-60 Store strings
Lines 70-100 Display strings
Lines 110-140 Save program with string arrays

Now look carefully at the instructions from line 110. With increased array capacity in the memory you will probably want to store your data more permanently. The ZX81 system does not (at least as yet) support free-standing files but it is possible to save your arrays (and their contents) along with your program. However, it is important that when you next load the program, it does not carry out a RUN but a GOTO instead; otherwise RUN will automatically clear the arrays. This program will SAVE itself automatically (line 120). When you next LOAD it will pick up straight away at line 130 the line after the SAVE_and branch back to the line quoted there (in this case 20). In this way, the RUN instruction is avoided and the variables are not cleared. But make sure you don’t branch back to a point where you re-dimension the array you’re trying to save !

Good luck from all at MEMOTECH!