Page 1 of 2
Lowering RAMTOP without a reset
Posted: Wed Jan 11, 2012 5:48 pm
by sirmorris
I've used this code any number of times in order to have a program control the value of RAMTOP.
Code: Select all
ERR_SP .equ $4002
RAMTOP .equ $4004
NEXTLINE .equ $0676
out ($fd),a ; turn off the nmi generator during stack move
ld hl,REQUIRED_RAMTOP_VALUE ** EDIT - to avoid confusion over use of square brackets **
ld (RAMTOP),hl ; save ramtop value in the sytem variable
dec hl ; point to the first byte below ramtop
ld (hl),$3e ; and mark it with 3e
dec hl
ld sp,hl ; load the stack pointer
dec hl
dec hl
ld (ERR_SP),hl ; load the error stack pointer
out ($fe),a ; turn on the nmi generator
jp NEXTLINE ; return to BASIC - we can't RET as there's no return address.
Re: Lowering RAMTOP without a reset
Posted: Wed Jan 11, 2012 5:58 pm
by PokeMon
Just saw your code and have one question because I am working on a Z80 cross assembler (nearly finished).
Why do you use square brackets in the following line and what's it about ?
ld hl,[RAMTOP VALUE]
Is this an immediate value for HL or a memory adressing like
ld (RAMTOP),hl
?
Because for immediates you don''t need / use brackets. This is quite new for me.
And where did you define RAMTOP VALUE ?
Re: Lowering RAMTOP without a reset
Posted: Wed Jan 11, 2012 6:16 pm
by Andy Rea
i just wrote a routine that copies the entire current stack to the new stack location, it is safe to call it from basic using a RAND USR xxx and as long as your new stack location is above STKEND (the calculator stack) it should work just fine.
Code: Select all
STACK_MOVE:
OUT ($FD),A ;TURN OFF NMI'D
;INTS SHOULD ALREADY BE DISABLED
LD HL,-4
ADD HL,SP ;GET THE SP
LD D,H
LD E,L ;PUT IN DE
LD HL,($4002) ;GET err-sp
OR A ;CLEAR CARRY FLAG
SBC HL,DE ;SHOULD HAVE NUMBER OF BYTES IN CURRENT STACK
LD B,H
LD C,L ;INTO BC
LD DE,28282
LD (16388),DE ;NEW RAMTOP
DEC DE ;DE PTR READY TO RECIEVE COPY OF STACK
LD HL,$7FFF
LDDR ;COPY STACK TO NEW LOCATION
LD HL,28278
LD ($4002),HL ;NEW err_sp
LD H,D
LD L,E
INC HL
LD SP,HL
OUT ($FE),A
might not be the quickest, but since as my program needs to return to basic along with the value in BC i needed to ensure that the other items on the stack got executed too.
Andy
Re: Lowering RAMTOP without a reset
Posted: Wed Jan 11, 2012 7:23 pm
by PokeMon
One more question, how do you use or code the EX AF,AF' instruction ?
Just as EX AF,AF
or really as EX AF,AF' ?

Re: Lowering RAMTOP without a reset
Posted: Wed Jan 11, 2012 8:16 pm
by Andy Rea
i think it may be assembler dependant, but tasm uses :-
ex af,af'
Andy
Re: Lowering RAMTOP without a reset
Posted: Wed Jan 11, 2012 9:08 pm
by sirmorris
And to answer your 1st question - the square brackets in the code above are simply my way of telling you to 'insert your required value here'
I've updated the code to avoid further confusion
C
Re: Lowering RAMTOP without a reset
Posted: Fri Jan 13, 2012 12:13 pm
by PokeMon
Thanks.
Maybe could be written as ex af,af' or ex af,af`.
I think I will simply ignore the ' or ` when parsing the line - so could be written same as ex af,af - without breaking fingers.

Re: Lowering RAMTOP without a reset
Posted: Fri Mar 09, 2012 7:42 pm
by MOB-i-L
Can I use this routine to lower RAM from 16K to 1K without crashing? I've typed in some 1K programs in ZX81 BASIC using 16KB RAM but I can't load them using 1KB since the DFILE is expanded. I would like to solve this problem because one can have more users of the program if it can be loaded on a 1K ZX81. It is common to use more memory when you develop and then try to fit the program into a machine with less RAM.
It would be great if you could attach a p-file with the program since that would save me the time and trouble to assemble it by hand. If you do, please also tell the adress one should poke the new RAMTOP to.
Re: Lowering RAMTOP without a reset
Posted: Fri Mar 09, 2012 8:04 pm
by siggi
IMHO it will be sufficent to set the system variable RAMTOP to a small value (e. g. POKE 16389, 68). No NEW is necessary, but the CLS-routine will "think" that you have not much ram and will make a collapsed D-FILE.
HTH Siggi
Re: Lowering RAMTOP without a reset
Posted: Fri Mar 09, 2012 10:58 pm
by MOB-i-L
You're right! This worked well in my case.