Easier Loading for MC Utilities

Author(s): D. A. Kerr
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v4 n4 (Volume 4, Issue 4)
Date: April 1983
Pages: 10

Many machine code utility programs reside in high memory above RAMTOP. Usually, utilities are saved on cassette as a BASIC source program and the MC is stored either in a numeric array, string variable, or REM statement.

Yet, using MC utilities can be a chore. The usual procedure is:

  • POKE 16388 and 16389 to establish the new RAMTOP.
  • Execute NEW to reinitialize the stacks under the new RAMTOP.
  • Load the utility source program.
  • Run the utility source to move the MC above the new RAMTOP.
  • Execute NEW to dismiss the utility source program.

Now, you load or enter the program your MC program will work on.

You can arrange the utility source program to do all these steps automatically. First, you transfer the MC from its original location (a REM statement, for example) to a location below the present RAMTOP but above the future one. Next, the source program POKEs 16388 and 16389 to set the new RAMTOP. It then executes NEW, wiping itself out and reinitializing the stacks.

During the MC transfer the machine stack is still active. Consequently, the machine code’s final location can’t extend too high into memory. Assuming your POKE operation (used by the source to transfer the MC) just adds or subtracts (for example, adding a starting address to a byte index counter), only 44 bytes must be avoided below the initial RAMTOP.

If you have 16K, you can relocate the MC to addresses as high as 32723. If you have the available memory, you can start the MC at location 32000, and allow up to 724 machine code bytes.

To add an auto function to your source program, add a short routine (I usually start at line 9000) consisting of the SAVE “(label)” instruction followed by GOTO 0. To save your source program, hit GOTO 9000. When you load your program it automatically resumes with the GOTO 0 line. (I use GOTO 0 rather than RUN in case the MC is stored in a numeric array or string variable–RUN would wipe it out.)

Following is an illustrative source program that assumes a 20-byte MC program and a tape save name “PGM”.

   1 REM (20 BYTES OF MC)
10 FAST
20 LET A=32000
30 FOR I=16514 TO 16533
40 POKE A,PEEK I
50 LET A=A+1
60 NEXT I
70 POKE 16388,0
80 POKE 16389,125
90 NEW
9000 SAVE "PGM"
9010 GOTO 0
SYNTACTIC SUM: 10019, 8K ROM

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