Page 1 of 1
Passing values between programs
Posted: Thu Apr 24, 2025 1:06 am
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?
Re: Passing values between programs
Posted: Thu Apr 24, 2025 1:19 am
by stroebeljc
Look up RAMTOP.
Re: Passing values between programs
Posted: Thu Apr 24, 2025 11:53 am
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.
Re: Passing values between programs
Posted: Thu Apr 24, 2025 12:20 pm
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
Re: Passing values between programs
Posted: Thu Apr 24, 2025 1:00 pm
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.
Re: Passing values between programs
Posted: Thu Apr 24, 2025 8:23 pm
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