Editor’s note: Although this pearl of programming poetry is not a direct Pro/File enhancement, it is never the less, a utility with many useful applications for people who like to cut and hack into Pro/File or any other program. Now for Richard’s wisdom:
Those of us who use 64K RAM on our ZX81/TS1000 must poke RAMTOP and execute NEW before loading large programs. This can also be done by a short machine code routine added to the high-speed loader programs like ZXLR-8 described in previous UPDATES.
This routine can be placed in a 35 character REMarks statement following any existing REMs in the loader (e.g. 2 REM for Z-XLR&8). The following list is poked into the 35 locations beginning with the first REMark character–for ZXLR-8 that is location 18833.
18833 42
18834 4
18835 64
18836 167
18837 237
18838 114
18839 229
18840 193
18841 237
18842 91
18843 4
18844 64
18845 42
18846 50
18847 64
18848 34
18849 4
18850 64
18851 237
18852 66
18853 249
18854 235
18855 237
18856 66
18857 237
18858 176
18859 27
18860 27
18861 27
18862 27
18863 237
18864 83
18865 2
18866 64
18867 201
The following BASIC routine can be used to POKE the REM:
7000 FOR I=0 T 34
7010 INPUT J
7020 POKE (18833+I),J
7030 NEXT I
7040 STOP
The routine reads the new RAMTOP value from the random number seed, which must be preset using RAND 65535. It computes the current length of the machine stack, copies the stack to the new end of memory, sets the new value into RAMTOP, sets ERR_SP, and points the stack pointer (SP register) to the new stack.
The Z80 instructions are:
; MOVE MACHINE STACK
; NEW RAMTOP IN RND SEED
; COPY STACK TO NEW TOP
; SET STACK POINTER TO
; NEW STACK
; SET ERR-SP TO NEW END
; OF STACK
2A0440 LD HL,(4004) ;OLD RAMTOP
A7 AND A ;CLEAR CARRY
ED72 SBC HL,SP ;STACK SIZE
E5 PUSH HL ;MOVE TO COUNTR
C1 POP BC
ED5B0440 LD DE,(4004) ;OLD RAMTOP
2A3240 LD HL,(4032) ;NEW RAMTOP
220440 LD (4004),HL ;SET RAMTOP
ED42 SBC HL,BC ;NEW SP
F9 LD SP,HL ;SET NEW SP
EB EX DE,HL ;SWAP PTRS
ED42 SBC HL,BC ;OLD SP
EDB0 LDIR ;COPY BOTTOM-UP
1B DEC DE ;NEW RAMTOP-1
1B DEC DE ;ADJUST TO ERRSP
1B DEC DE
18 DEC DE
ED530240 LD (4002),DE ;SET ERRSP
C9 RET
To include this stack mover in ZXLR-8, delete statements 9080 and 9082, and add the following to both expand the usable memory and automatically start the loader:
9100 REM MOVE MACHINE STACK 64K
9110 RAND 65535
9120 RAND USR 18833
9200 REM MOVE Z-XLR8
9210 RAND USR 18141
9220 REM EXECULTE ZXLR8
9230 RAND USR L
This routine can also be used (alone or with a loader) where the BASIC memory must be reduced to protect an area at the top of a 16K RAM. Just precede the RAND USR statement by RAND and the new RAMTOP value you want to have.