ZX81 Resources: A 0 REM Generator

See all articles from Sinc-Link v10 n3
Author(s): Rene Bruneau
Publication: Sinc-Link
Pub Details: Sinc-Link v10 n3 (Volume 10, Issue 3)
Date: May/June 1992
Pages: 25

Rene Bruneau 6 March 1992

Reading through some old issues of Your Computer, I found this small machine code utility for creating REM statements of any length. The original listing used Basic to poke the number of bytes required into memory after which the routine was invoked by a RAND USR (address). Because the code was relocatable, I wondered if there was an easier way to pass information regarding the length to the machine code without resorting to Basic input. A long time ago, when we were still meeting up at the North York Library, Peter McMullin had noted that the RAND function conveniently divided a number into Lo and Hi bytes by the computer and stored in SEED (memory locations 16434 and 16435). This is how we can pass information to a machine code program directly from the keyboard without running a basic program. The original listing was modified and an instalation program added to tranfer the code to any location in memory.

Enter Listing 1, RUN 100 to input the mc data in Listing 2. On completion, enter S, and confirm that the checksum is 5307. You may now delete line 100 to the program end. Save the program several times. On running, the program asks you for the address where the code will be located. Entering a number will relocate the mc. Note that if you intend to locate the code above RAMTOP on a standard machine, you must lower RAMTOP before you load the program into memory. To generate your REM statement, make sure that there is at least 1 basic line in memory, 10 REM, for example, key in

       RAND (rem size), ENTER
where 'rem size' is the number of bytes required,
LET L=USR (mc location), ENTER

When you LIST, there is your REM statement on line 0.

LISTING 1

1 REM ---54 SPACES----
10 PRINT "ROUTINE ADDRESS"
20 INPUT ADD
30 FAST
40 FOR X=0 TO 53
50 POKE ADD+X, PEEK (16514+X)
60 NEXT X
70 SLOW
80 STOP
100 LET X=16514
110 LET T=0
120 LET A$=""
130 IF A$="" THEN INPUT A$
140 IF A$="S" THEN PRINT "CHECK SUM = ";T,P
150 POKE X,16*CODE A$+CODE A$(2)-476
160 LET T=T+ PEEK X
170 IF PEEK 16442<=2 THEN SCROLL
180 PRINT X;" ";A$(1 TO 2)
190 LET X=X+1
200 LET A$=A$(3 TO)
210 GOTO 130

LISTING 2

16514   ED 4B 32 40 C5 21 06 00
16522 09 E5 C1 21 7D 40 CD 9E
16530 09 3E 76 EB 77 3E 17 C1
16538 C5 04 2B 77 0D 20 FB 05
16546 20 F8 2B 3E EA 77 D1 13
16554 13 7A 2B 77 7B 2B 77 3E
16562 00 2B 77 2B 77 C9

HEX LOADER FOR THE ZX81

This hex loader is pretty standard. It allows you to enter as many hex numbers at one input as you wish. When you have finished entering all the code (in hex), press the “S” key to stop.

 1 REM (FILL THIS LINE WITH ENOUGH
CHARACTERS TO HOLD THE MACHINE CODE
10 LET X=16514
20 LET A$=""
30 IF A$="" THEN INPUT A$
40 IF A$="S" THEN STOP
50 POKE X,16*CODE A$(1)+CODE
A$(2)-476
60 PRINT AT 11,7;X;" ",A$(1 TO 2)
70 LET X=X+1
80 LET A$=A$(3 TO)
90 GOTO 30

From Your Computer magazine May ’83 p67

GFC