Lowering RAMTOP without a reset

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Lowering RAMTOP without a reset

Post 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.
Last edited by sirmorris on Wed Jan 11, 2012 9:13 pm, edited 2 times in total.
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: Lowering RAMTOP without a reset

Post 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 ?
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: Lowering RAMTOP without a reset

Post 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
what's that Smell.... smells like fresh flux and solder fumes...
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: Lowering RAMTOP without a reset

Post 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' ?
:idea:
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: Lowering RAMTOP without a reset

Post by Andy Rea »

i think it may be assembler dependant, but tasm uses :-

ex af,af'

Andy
what's that Smell.... smells like fresh flux and solder fumes...
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: Lowering RAMTOP without a reset

Post 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 :D

C
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: Lowering RAMTOP without a reset

Post 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. :mrgreen:
MOB-i-L
Posts: 64
Joined: Mon Apr 19, 2010 12:13 am
Location: Lund, Skåne/Scania, Sweden
Contact:

Re: Lowering RAMTOP without a reset

Post 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.
User avatar
siggi
Posts: 990
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: Lowering RAMTOP without a reset

Post 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
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
MOB-i-L
Posts: 64
Joined: Mon Apr 19, 2010 12:13 am
Location: Lund, Skåne/Scania, Sweden
Contact:

Re: Lowering RAMTOP without a reset

Post by MOB-i-L »

You're right! This worked well in my case.
Post Reply