Lowering RAMTOP without a reset

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: Lowering RAMTOP without a reset

Post by PokeMon »

Ähmm can I use this trick vice versa to let big programs run on my 1k Zeddy at home ?
Set RAMTOP up and type CLEAR ? :shock: :mrgreen:
MOB-i-L
Posts: 63
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 »

I made a program for ZX81 with 16K RAM (or higher) that makes RAMTOP as large as possible but still with small D_FILE (i.e. 3.25K). I load this before I enter a program. This makes it faster to enter programs and makes the filesize smaller and more probable to load on a 1K ZX81.

Code: Select all

    2 SAVE "SMALLDFILE"
    3 LET D=16389
    5 GOSUB 1000
   10 POKE D,76
   15 POKE D-1,255
   20 GOSUB 1000
   30 PRINT "PRESS: A(=NEW) AND NEWLINE"
  999 STOP 
 1000 PRINT PEEK D*256+PEEK (D-1)-16384
 1010 RETURN 
User avatar
1024MAK
Posts: 5118
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Lowering RAMTOP without a reset

Post by 1024MAK »

PokeMon wrote:Ähmm can I use this trick vice versa to let big programs run on my 1k Zeddy at home ?
Set RAMTOP up and type CLEAR ? :shock: :mrgreen:
Yes, as long as you use M!cro$oft's virtual memory system for your ZX81. Guaranteed to make it run faster*. Don't forget to set up your page file.
* when the video picture is recorded and played back at x1000 speed. :lol: :lol: :lol:
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
User avatar
mrtinb
Posts: 1910
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Lowering RAMTOP without a reset

Post by mrtinb »

Andy Rea wrote: Wed Jan 11, 2012 6:16 pm 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
Great routine.

This lowers the RAMTOP. If I want to raise the RAMTOP again, could I just replace LDDR with LDIR?
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: Lowering RAMTOP without a reset

Post by PokeMon »

mrtinb wrote: Wed Mar 08, 2017 1:45 pm
Andy Rea wrote: Wed Jan 11, 2012 6:16 pm 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
Great routine.

This lowers the RAMTOP. If I want to raise the RAMTOP again, could I just replace LDDR with LDIR?
Well - this routine is not to recommend as it works only if there is no overlap between source and target buffer. To move a memory block from higher to lower address you should use LDIR instead of LDDR as LDDR may overwrite some copied data if both buffers overlap. For moving a memory block up, LDDR is typically used. Both methods are robust against possible buffer overlap. Of course, the pointers DE and HL have to be adjusted properly.

Best code would be (for a buffer without adjusting stack pointer):
; moving down
LD DE,end_buffernew
LD HL,end_bufferold
LD BC,buffersize
LDDR

;moving up
LD DE,start_buffernew
LD HL,start_bufferold
LD BC,buffersize
LDIR
You can read something more detailed here
http://sgate.emt.bme.hu/patai/publicati ... part3.html
(moving data blocks)
Post Reply