ZX81 - save without tape plus memory check

Discussions about Sinclair ZX80 and ZX81 Hardware
jarweb
Posts: 19
Joined: Sun Oct 24, 2021 11:19 am

ZX81 - save without tape plus memory check

Post by jarweb »

Hi
I've recently got hold of a ZX81 to play with as this was my first home computer.
I've done a composite mod and also added a memory upgrade internally to give 16MB without a Ram pack.

Couple of things.

Can anyone suggest a way to save programs without tape as I no longer have a tape recorder and would prefer not to have to buy one. I can see that the output from the ZX81 is way too low for a computer to pick up using audio software in Windows so wondering what others do. If I really must buy a tape recorder then are there any suggestions as to what make/model would work ?

Also I found reference to a program that should output the amount of memory in the machine but when I run it seems to reset the computer.

This is the program

10 FOR N=16640 TO 65536 STEP 256
20 POKE N,0
30 IF PEEK N<>0 THEN GOTO 50
40 NEXT N
50 PRINT "MEMORY SIZE ";(N/1024)-16;"K"

I was initially getting a return code 1/20 previously but now it seems to just reset and I lose the program.

Thanks for any advice
User avatar
1024MAK
Posts: 5101
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: ZX81 - save without tape plus memory check

Post by 1024MAK »

That program will cause a crash as it writes over part of the system area.

The RAM between 16384 upwards contains the system variables, followed by the program, the display file, the variables, some system work space, and the internal calculator stack.

The system variable “STKEND” gives the current limit of this area. To read this use PRINT PEEK 16412+256*PEEK 16413. When I do this after entering, but not running the program you listed, I get 17477.

Then you have some free RAM.

Further on, there is the Z80 machine stack, the GOSUB stack and then any USR routines.

Only the Z80 knows where the Z80 machine stack starts, so machine code is needed to get this value. But 32752 is a typical value with it sitting at the K prompt.

As the program alters RAM from 16640 to 65536 in 256 byte steps, it only takes one POKE (write to memory) to over write another critical value and then the machine will become confused, often resulting in either a crash, with either a hang, a NEW or a reset.

To ensure the Z80 machine stack and the GOSUB stack are protected, the machine needs to be told to move them. This has to be done before entering the program.
Use:
POKE 16388,0
then
POKE 16389,69
then
NEW

Now enter the program, but change the first line to:
10 FOR N=17664 TO 65536 STEP 256

Changing the starting address to a higher value accounts for the display file being full size due to there being more than 3k bytes of RAM. The higher starting address (17664) should be clear of all the critical areas.

In terms of using a PC or other modern audio device to record the sound (tape recording) from the ZX81, you either need a suitable audio amplifier, or to modify the output attenuator circuitry in the ZX81.

To load, you will almost certainly need an suitable audio amplifier, as modern audio equipment does not produce a loud enough signal for a ZX81.

There are other methods, but the availability varies depending on if the hardware maker is manufacturing them.

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.
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: ZX81 - save without tape plus memory check

Post by XavSnap »

:shock:

... And you can't get the memory without the RAM_Top value (16k=$7FFF+1).
...And if you reset the Basic (CPU stack) stats accumulator at the end of memory, below $7FFF, the Basic or ASM code will crash.
Last edited by XavSnap on Mon Oct 25, 2021 7:17 pm, edited 2 times in total.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
1024MAK
Posts: 5101
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: ZX81 - save without tape plus memory check

Post by 1024MAK »

I should also add, that I only tested the amended program on a 16k byte system. It may not work on systems with a different amount of RAM.

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.
jarweb
Posts: 19
Joined: Sun Oct 24, 2021 11:19 am

Re: ZX81 - save without tape plus memory check

Post by jarweb »

Hi
Thanks for the replies

Mark - if I change line 10 to what you suggest it looks like I still get a reset.

So I tried a different value:
FOR N=17700 TO 65536 STEP 256

This gives me a value back of - 13.535K

Not sure what value I'd be expecting back ? It's obviously not 1K but don't know if there's just no way to show it's definitely 16K available ?

XavSnap - sorry, I don't follow your reply ?

Thanks
User avatar
mrtinb
Posts: 1906
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: ZX81 - save without tape plus memory check

Post by mrtinb »

To load and save programs on a ZX81, a cheap and great solution is buying a ESP32 microcontroller, and connect it to the ZX81. You upload the ZX-Wespi firmware to the microcontroller. ZX-Wespi detects when you try to load or save, and then is load or save from ESP32 flash memory. Files can me moved the the ESP32 "disk" over Wifi.

viewtopic.php?f=7&t=4155
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
User avatar
1024MAK
Posts: 5101
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: ZX81 - save without tape plus memory check

Post by 1024MAK »

Strange.

But do keep in mind that the starting number has to divide into 256. So 17700 is no good. The next highest suitable number is 17920.

Here’s my results using an emulator:
Listing:
POKE test listing
POKE test listing
Output:
POKE test output
POKE test output
If you run it again, what does it produce if you type:

Code: Select all

PRINT N
?

Maybe you should try this program. Listing:
RAMTOP listing
RAMTOP listing
Results from an emulated 16k ZX81:
RAMTOP output
RAMTOP output
FF252678-52F9-4FA0-A17C-6BB22E89BAAB.jpeg (16.38 KiB) Viewed 1814 times
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.
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: ZX81 - save without tape plus memory check

Post by XavSnap »

Hi,

Mark have ever pointed this problem using the SAVE"xx" command in a GOSUB jump.

try this program:

Code: Select all

1 GOSUB 10
2 STOP
10 FOR N=16640 TO 65536 STEP 256
20 POKE N,0
30 IF PEEK N<>0 THEN GOTO 50
40 NEXT N
50 PRINT "MEMORY SIZE ";(N/1024)-16;"K"
60 RETURN
The Basic editor use the SP (Stack pointer) register to store floating-point values, program's jump and CALL asm mnemonic.
In case of auto-LOAD command, the Stack is empty, and the Basic editor will crash.

POKing "0" in this segment will reset the stack memory room, and the monitor will display an error.

... Same problem to move the Ram_top. You had to reset the SP register by typing a "NEW" command... or copy le SP values.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
jarweb
Posts: 19
Joined: Sun Oct 24, 2021 11:19 am

Re: ZX81 - save without tape plus memory check

Post by jarweb »

Hi
Running the program from XavSnap I go back to the return code 1/20 I thought I was getting previously, before the resets started. Don't know if this means an error on line 20 ?

If I do a PRINT N after running the program I get a value of 17408

If I run the original program with a starting value of 17920 I get 13.75K and PRINT N gives 30464

Putting the starting value of 17664 back in looks like it goes back to hanging as I just get a white screen and the cursor never comes back.

Trying the newer program from Mark gives:

0 68
17408
1024

Not sure where this leaves me. Does it mean I have slightly more than 16K ? I followed the instructions available from a few places online to replace the 1K onboard with a 32K but only expected to get 16K. The chip I bought was:

Cypress CY62256NLL-70PXC CMOS SRAM 32k x 8 DIP Package

Thanks
User avatar
1024MAK
Posts: 5101
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: ZX81 - save without tape plus memory check

Post by 1024MAK »

Did you power off the machine after running the first program and then try the second program. Or did you just use NEW before trying the second program. I ask, because the second program is affected by the system settings. It needs to be run only after the machine has been powered on.

Which position is LK1 / LK2 in?

Can you post a link to the instructions you followed for your upgrade. Some photos of your ZX81 PCB showing the RAM chip and the wiring would help as well.

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.
Post Reply