Free RAM on 1k ZX81

Discussions about Sinclair ZX80 and ZX81 Hardware
Lardo Boffin
Posts: 2173
Joined: Sat Nov 26, 2016 2:42 am

Free RAM on 1k ZX81

Post by Lardo Boffin »

This may be a daft question but ignoring the screen how much free RAM is left on a 1k machine after system variables (125 bytes I think) and the stack etc. I can calculate screen usage but couldn't find anything about the stack.

Thanks!
ZX80
ZX81 iss 1 (bugged ROM, kludge fix, normal, rebuilt)
TS 1000 iss 3, ZXPand AY and +, ZX8-CCB, ZX-KDLX & ChromaSCART
Tatung 81 + Wespi
TS 1500 & 2000
Spectrum 16k (iss 1 s/n 862)
Spectrum 48ks plus a DIVMMC future and SPECTRA
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: Free RAM on 1k ZX81

Post by PokeMon »

Lardo Boffin wrote:This may be a daft question but ignoring the screen how much free RAM is left on a 1k machine after system variables (125 bytes I think) and the stack etc. I can calculate screen usage but couldn't find anything about the stack.

Thanks!
An empty ZX81 starts with available program/data RAM at 16509 while 1k ends at 17408.
Empty screen has 26 bytes and stack would be about 20 bytes normally, depending on functions used.
The calculator stack could take more additional space.
So around 850 bytes you would have left for use.

There are system variables that can be used as well, at least the printer buffer with 33 bytes.
Lardo Boffin
Posts: 2173
Joined: Sat Nov 26, 2016 2:42 am

Re: Free RAM on 1k ZX81

Post by Lardo Boffin »

PokeMon wrote:
An empty ZX81 starts with available program/data RAM at 16509 while 1k ends at 17408.
Empty screen has 26 bytes and stack would be about 20 bytes normally, depending on functions used.
The calculator stack could take more additional space.
So around 850 bytes you would have left for use.

There are system variables that can be used as well, at least the printer buffer with 33 bytes.
Thanks Pokemon. When I got a zeddy again one of the things on my to do list was to write a game in 1k. Needless to say it will all be in machine code (which I am now learning - it's a lot different to the 6502 I am used to) so I assume I won't need the calculator stack.

I didn't know I could reclaim the printer buffer - 33 bytes is a lot to waste on one of these!

Is this in a fixed place regardless of the amount of memory or would it crash a 16k (or 32 etc.) zeddy if I placed all my game variable here? 33 bytes should be plenty for that.

Thanks

Lardo
ZX80
ZX81 iss 1 (bugged ROM, kludge fix, normal, rebuilt)
TS 1000 iss 3, ZXPand AY and +, ZX8-CCB, ZX-KDLX & ChromaSCART
Tatung 81 + Wespi
TS 1500 & 2000
Spectrum 16k (iss 1 s/n 862)
Spectrum 48ks plus a DIVMMC future and SPECTRA
User avatar
mrtinb
Posts: 1911
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Free RAM on 1k ZX81

Post by mrtinb »

Lardo Boffin wrote:
PokeMon wrote:I didn't know I could reclaim the printer buffer - 33 bytes is a lot to waste on one of these!

Is this in a fixed place regardless of the amount of memory or would it crash a 16k (or 32 etc.) zeddy if I placed all my game variable here? 33 bytes should be plenty for that.
Looking in ZX81 BASIC Programming chapter 28 describes the systemvariables including PRBUFF.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
Lardo Boffin
Posts: 2173
Joined: Sat Nov 26, 2016 2:42 am

Re: Free RAM on 1k ZX81

Post by Lardo Boffin »

mrtinb wrote:
Lardo Boffin wrote:
PokeMon wrote:I didn't know I could reclaim the printer buffer - 33 bytes is a lot to waste on one of these!

Is this in a fixed place regardless of the amount of memory or would it crash a 16k (or 32 etc.) zeddy if I placed all my game variable here? 33 bytes should be plenty for that.
Looking in ZX81 BASIC Programming chapter 28 describes the systemvariables including PRBUFF.
Thanks. That's where I got the idea to use the second byte of FRAMES as a seed for my random number generator.

Are the system variables always at the same location regardless of the amount of memory present?
ZX80
ZX81 iss 1 (bugged ROM, kludge fix, normal, rebuilt)
TS 1000 iss 3, ZXPand AY and +, ZX8-CCB, ZX-KDLX & ChromaSCART
Tatung 81 + Wespi
TS 1500 & 2000
Spectrum 16k (iss 1 s/n 862)
Spectrum 48ks plus a DIVMMC future and SPECTRA
User avatar
mrtinb
Posts: 1911
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Free RAM on 1k ZX81

Post by mrtinb »

Lardo Boffin wrote:Are the system variables always at the same location regardless of the amount of memory present?
According to Documentation for NO$ZX Emulator, memory always starts at $4000/16384. And memory starts with system variables.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
Lardo Boffin
Posts: 2173
Joined: Sat Nov 26, 2016 2:42 am

Re: Free RAM on 1k ZX81

Post by Lardo Boffin »

Excellent. I am using EightyOne for testing so will shift the variables to the printer buffer and then change the memory to check it is ok.
ZX80
ZX81 iss 1 (bugged ROM, kludge fix, normal, rebuilt)
TS 1000 iss 3, ZXPand AY and +, ZX8-CCB, ZX-KDLX & ChromaSCART
Tatung 81 + Wespi
TS 1500 & 2000
Spectrum 16k (iss 1 s/n 862)
Spectrum 48ks plus a DIVMMC future and SPECTRA
User avatar
1024MAK
Posts: 5118
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Free RAM on 1k ZX81

Post by 1024MAK »

If you go to the previous chapter (27) of the ZX81 manual (the link posted earlier, go to the bottom of the page) or via this direct link, there is a nice diagram showing the memory map of the BASIC system. Where address numbers are listed, these boundaries/areas do not move. Where names are listed, these are pointed to via the same named pointers in the system variables area ;)

Of course, once a machine language program is given control, if a return to BASIC will never be needed, a lot of the system variables can be written over. How many depends on if your code will require to use any of the ROM routines.

Mark
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.
Lardo Boffin
Posts: 2173
Joined: Sat Nov 26, 2016 2:42 am

Re: Free RAM on 1k ZX81

Post by Lardo Boffin »

Thanks all.

I have put my variables in the printer buffer and it all seems to work fine regardless of RAM pack in EightyOne.

Lardo
ZX80
ZX81 iss 1 (bugged ROM, kludge fix, normal, rebuilt)
TS 1000 iss 3, ZXPand AY and +, ZX8-CCB, ZX-KDLX & ChromaSCART
Tatung 81 + Wespi
TS 1500 & 2000
Spectrum 16k (iss 1 s/n 862)
Spectrum 48ks plus a DIVMMC future and SPECTRA
dr beep
Posts: 2079
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Free RAM on 1k ZX81

Post by dr beep »

My experience is that a stack of 32 bytes is minimum.
When you start machinecode and don't go back to BASIC you can use the bytes from #4000 to DFILE without problem for variables. Other sysvar can be used too, but not all (FRAMES, LASTK, CDFLAG).

When you write your own displayroutine by setting IX you can even use up to FRAMES.

Largest code I could load in 1K was 952 bytes.
This used after loading all adresses but 64 bytes.
Screensize differs from 90 bytes to 320 bytes.
Post Reply