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
Drutt
Posts: 28
Joined: Wed Jul 18, 2018 11:58 am

ZX81 basic: running the program without clearing variables

Post by hjalfi »

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?)
User avatar
PROSM
Manic Miner
Posts: 472
Joined: Fri Nov 17, 2017 7:18 pm
Location: Sunderland, England
Contact:

Re: ZX81 basic: running the program without clearing variables

Post by PROSM »

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.
All software to-date
Working on something, as always.
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: ZX81 basic: running the program without clearing variables

Post by djnzx48 »

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.
User avatar
1024MAK
Bugaboo
Posts: 3104
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 »

Yes :D

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

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
hjalfi
Drutt
Posts: 28
Joined: Wed Jul 18, 2018 11:58 am

Re: ZX81 basic: running the program without clearing variables

Post by hjalfi »

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?
User avatar
1024MAK
Bugaboo
Posts: 3104
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 »

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
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
hjalfi
Drutt
Posts: 28
Joined: Wed Jul 18, 2018 11:58 am

Re: ZX81 basic: running the program without clearing variables

Post by hjalfi »

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.
User avatar
1024MAK
Bugaboo
Posts: 3104
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 »

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
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
Post Reply