There are a number of possible places to store machine code:
(1) Above RAMTOP. This is a good safe place not bothered by NEW, but you can’t SAVE it.
(2) In a REM statement at the beginning of the program area. You write
1 REM 12345.......n (where n=number of bytes
you wish to reserve)
(NOTE – starting address for your machine code is always 16514, or 4082h
(3) In a REM statement at the end of the program area.
(4) In the variables area. (Don’t use RUN or CLEAR!)
I am prepared to ignore these last two places.
Included in this discussion are techniques for writing, listing, inserting, deleting, and easily transferring machine code back and forth between a REM statement and above RAMTOP by means of HEXLD4 programs.
HEXLD, HEXLD2 and HEXLD3 can be found in “Mastering Machine Code on Your ZX-81”, by Toni Baker.
HEXLD stores your machine code at 30000. (you have to set RAMTOP at 30000 before you RUN it.) (Ed. note – in the TIMEX/Sinclair User’s Manual see page 124 for how to change RAMTOP).
HEXLD2 asks for an address, in hexadecimal, so you have a choice. Also, you can use character codes instead of hex code if you want to. If you store your code in a REM statement,(using 4082h as the starting address), the procedure is to delete the HEXLD2 program line by line, leaving only line 1 – the REM statement – and then to type in the basic lines of your program.
HEXLD3 works as follows:
RUN To list stored machine code RUN 100 To write new machine code RUN 200 To insert new machine code RUN 300 To delete previous machine code RUN 400 To SAVE machine code
The machine code for HEXLD3 is stored in a REM statement at the beginning of the program in 246 bytes. The “subject program” therefore has to go above RAMTOP.
A good thing to have handy is a method for converting back and forth between decimal and hex. Mine is a program, “Hex”, run on a Texas Instruments TI 58C calculator.
User-defined Key Operation
A d to h
B h to d
C decimal address, 2 bytes
An example of this last operation is that when you want to change RAMTOP, you enter 30000, and you get 48 and 117.
(AT THIS POINT THE AUTHOR PROVIDES THE COMPLETE LISTING FOR HEXLD4 IN HEX. – in the interest of space and accuracy we do not list the program at this time. You may obtain a photo copy of the program by writing SINCUS or contacting the Editor at a monthly meeting)
The BASIC for HEXLD4 is as follows:
1 REM (246 bytes)
10 LET L=16514
20 FOR X=31750 TO 31995
30 POKE X, PEEK L
40 LET L=L+1
50 NEXT X
60 POKE 16388, 48
70 POKE 16389, 117
80 PRINT AT 8,12;"HEXLD4"
90 PAUSE 300
100NEW
When HEXLD4 is RUN the machine code is stored above RAMTOP in 246 bytes; from 31750 to 31995, or 7C06 to 7CFB in hex. RAMTOP is set at 30000. After identifying itself, the BASIC is then wiped out by a new statement.
HEXLD4 BASIC, the next program on the tape, and necessary for the operation of HEXLD4, can be loaded or wiped out with the command NEW at any time. Self-loading machine code programs such as this one can be loaded into adjacent locations above RAMTOP. You RUN is exactly as you do HEXLD3: from the beginning, lines 100, 200, 300, or 400 to list, write, insert, delete, or SAVE, respectfully.
(AT THIS POINT THE AUTHOR LISTS THE BASIC FOR HEXLD4 – again you may obtain this by contacting the Editor at a monthly meeting or writing to SINCUS Editor)
The next program on the tape is “DownLoad” (the listing is again available for you). This program works the other way around from these self-loading programs, that, when run, transfer from a REM statement to above RAMTOP, then wipe out the BASIC. It asks for the location of the machine code, and the number of bytes, then stores it in a REM statement in which 255 bytes (or whatever you needed) had been reserved. You then edit and delete the unused part of the REM statement, erase lines 10 through 100, add appropriate lines of BASIC, then name and SAVE it.
The thing to do now might be to establish a machine code convention whereby really useful machine code routines could be written at addresses set aside by common agreement. A bar graph could be drawn, say, from 30000 to 32767 at increments of 25 bytes per line. Programs could be listed with their instructions:
NAME: INSTRUCTIONS: HEXLD4 LOAD and RUN HEXLD4 BASIC RENUMBER RAND USR 32000
They should all set RAMTOP to the same place to avoid confusion and concern over order of loading.
Scott Eddy
SINCUS
June 1983
(AGAIN TO OBTAIN THE FULL LISTINGS OF THE PROGRAMS IN SCOTT’S ARTICLE _ write to Editor, SINCUS or see me at the monthly meeting)
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.