Passing values between programs

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
Post Reply
AndiD
Posts: 6
Joined: Thu Apr 17, 2025 5:54 am

Passing values between programs

Post by AndiD »

Maybe a bit of an odd question, but I am looking for ways to pass a few bytes between 'chained' programs in Basic on a ZX81 (i.e., when program A load/runs program B from tape). Variables get reset when LOADing, apparently.

Are there memory areas that are safe to POKE stuff into in program A and that survive LOADing a new program from tape, so that I can grab the values from those memory areas in program B?
stroebeljc
Posts: 114
Joined: Thu Apr 23, 2020 6:02 am
Location: Minneapolis, MN

Re: Passing values between programs

Post by stroebeljc »

Look up RAMTOP.
John
User avatar
XavSnap
Posts: 2193
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.
Contact:

Re: Passing values between programs

Post by XavSnap »

Hi AndiD,

"few bytes"... skills, score...

On a SPECTRUM game, i had to send this info to a second program.

I give an ASCII password (10 chars) to setup the next program.

If the password was a fake, the second program was unable to launch.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
1024MAK
Posts: 5526
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: Passing values between programs

Post by 1024MAK »

On a ZX81, either lower the value of the RAMTOP system variable (unless your system has more than 16K bytes of RAM) then store your data above this point or if your system has RAM in the 0x2000-3FFF area, use this.
Everything from 0x4009 through to the address stored in RAMTOP will or may be replaced by a new program that is loaded in.

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Amp

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

Re: Passing values between programs

Post by mrtinb »

If you know your own programs that you want to chain between, you could just POKE to address 30000, which will likely be in the empty space below the stack, and above the variables and calc-stack. This is the space your stack grows down towards from top of memory, and most likely is above your variables and calc-stack.

To be safe, you can PEEK the STKEND and maybe check the stack pointer if you code in ML, before POKEing. If you find that the space is already occupied you can give an error message.

The same checks can be done after the new program is loaded to make sure the address contains valid data and has not been overwritten.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
David G
Posts: 632
Joined: Thu Jul 17, 2014 7:58 am
Location: 48 North

Re: Passing values between programs

Post by David G »

You can put a lot of data in the SPARE region. With a 16K RAM pack, i have put 1K of data there reliably. It all depends on how big the two programs are. But for temporary use you can determine this once
mrtinb wrote: Thu Apr 24, 2025 1:00 pmyou can PEEK the STKEND and maybe check the stack pointer if you code in ML
I use "guard bytes" before and after the data, some fixed 2-byte value. Works whether your data is two bytes or 1000 bytes. Without using Machine Language, you can PEEK after loading the 2nd program. If the guard bytes are unchanged, the data is good

See Chapter 27 Organisation of Memory
Post Reply