You may have wanted to change RAMTOP without wiping out what you have in memory. It is not enough to simply POKE 16388 and 16389 with the desired RAMTOP, since the machine-code stack stays in the same place until you relocate them using NEW. Several “fixes” have been reported, including one using a ROM call in SWN 1:3; an observant reader pointed out that it simply didn’t work. Since then, I’ve been looking into how the various programs that accomplish this go about it, and found there are several different approaches. My favorite is used in the initialization routine for G. Russell’s “HRP” program. In its simplest form, the routine goes like this:
215B40 LD HL,TADD
F9 LD SP,HL
21nnnn LD HL,desired RAMTOP
220440 LD (RMTP),HL
2B DEC HL
F9 LD SP,HL
2B DEC HL
2B DEC HL
220240 LD (ERSP),HL
C37506 JP 0675
Notice how the routine uses system variable TADDR, which the manual claims is “very unlikely to be useful.” (Heh, heh…) Also note the lack of a RET at the end; instead it jumps into the ROM (at an “uncharted” entry point, no less) from whence the ROM returns you to BASIC, The charm of this one is that you can use it within a program and keep right on running on return. Don’t call it from within a GOSUB or m/c CALL, and don’t PUSH anything you want to keep, as the stack is reset to “empty.