ZX81 basic: running the program without clearing variables

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
hjalfi
Berk
Posts: 26
Joined: Wed Jul 18, 2018 10:58 am

ZX81 basic: running the program without clearing variables

Post by hjalfi » Fri Aug 03, 2018 7:18 pm

So ZX81 Basic, unusually, allows modification of the program without clearing all the variables; and SAVE and LOAD will save them and reload them.

Except, RUN implicitly does a CLEAR, wiping them before the program runs.

Given that the ZX81 does (AFAIK) allow autorunning of programs, how does this make loading variables off tape useful? Where there any titles where the instructions to start the program told you to do GOTO 0 instead of RUN?

(Why, yes, I am desperately trying to save space in a program; why do you ask?)
0 x

User avatar
PROSM
Berk
Posts: 44
Joined: Fri Nov 17, 2017 7:18 pm
Location: Sunderland, England
Contact:

Re: ZX81 basic: running the program without clearing variables

Post by PROSM » Fri Aug 03, 2018 10:03 pm

Well, you would have to write something like this for an auto-running program that did not clear the variables:

Code: Select all

10 SAVE "PROGRAM"
20 ... (rest of the program here)
To save the program, you type GOTO 10 (so as not to clear the variables) and the SAVE command will be executed. Due to the way ZX81 Basic works, the current state of the BASIC program will be saved, thus when this example is loaded back in, it will automatically start at line 20, believing that it has just finished the SAVE command from line 10.
0 x
All software to-date

Current Projects:
Currently working on ZX Adventure Designer, which lets one create point-and-click graphic adventures for a 48K Spectrum.

User avatar
djnzx48
Microbot
Posts: 176
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: ZX81 basic: running the program without clearing variables

Post by djnzx48 » Sat Aug 04, 2018 3:53 am

Is that why so many ZX81 listings from magazines have something like

9996 STOP
9997 CLEAR
9998 SAVE "THING"
9999 GO TO 1

at the end of them? For example this one.

Some listings even made you type in the LET statements yourself before using GO TO to start the program.
0 x

User avatar
1024MAK
Microbot
Posts: 188
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: ZX81 basic: running the program without clearing variables

Post by 1024MAK » Sat Aug 04, 2018 1:30 pm

Yes :D

Part of the system variable area gets saved, and that includes the state of the execution of the BASIC program.

Mark
0 x

hjalfi
Berk
Posts: 26
Joined: Wed Jul 18, 2018 10:58 am

Re: ZX81 basic: running the program without clearing variables

Post by hjalfi » Sat Aug 04, 2018 3:04 pm

Oh, yeah, I completely forgot you could do that! Except it didn't save the GOSUB stack along with the program state, hence the warning in the manual...

Gosh, I'd forgotten how... opinionated... ZX81 Basic is. Also slow.

Incidentally, several of the programs in that issue of _Sinclair Programs_ are incorrectly labelled as for the ZX81 when they clearly only run on the Spectrum. I'm appalled at the lack of professionalism. Should I write in and complain?
0 x

User avatar
1024MAK
Microbot
Posts: 188
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: ZX81 basic: running the program without clearing variables

Post by 1024MAK » Sat Aug 04, 2018 8:08 pm

One thing to keep in mind with the ZX81, is that in SLOW mode, the CPU is spending a lot of it's time sending screen data to the TV. It runs a bit faster in FAST mode (but without a screen display). But even then, the BASIC is pedestrian. The code in the ROM was written to be compact rather than fast, the idea being to squeeze in as much functionality as possible.

Mark
0 x

hjalfi
Berk
Posts: 26
Joined: Wed Jul 18, 2018 10:58 am

Re: ZX81 basic: running the program without clearing variables

Post by hjalfi » Sat Aug 04, 2018 10:23 pm

I don't think 'pedestrian' is the right word --- that implies it's somehow ordinary, which ZX81 Basic is anything but.

I think my favourite combination of features are the absence of multiple statements per line and the missing ELSE clause in if statements: these synergise beautifully for maximum inconvenience... I used to think Commodore Basic was tough to work in! Actually writing a useful program on an unexpanded ZX81 is an interesting challenge (I must try it on some of my cow orkers).

I know there's a cottage industry of alternative ROMs for the Spectrum; did anyone ever do any for the ZX81? Not counting the Jupiter Ace, of course.
0 x

User avatar
1024MAK
Microbot
Posts: 188
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: ZX81 basic: running the program without clearing variables

Post by 1024MAK » Thu Aug 09, 2018 9:34 am

Browse Sinclair ZX World forums, as that is where Zeddy folk hang out :mrgreen:

There have and still are people who have/are improving the BASIC for the ZX81. I can't remember if there is a whole alternative BASIC though.

There is however a ZX Spectrum "emulator" that runs on a ZX81!

Mark
0 x

Post Reply