Speeding up programs by hacking the SysVars

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Speeding up programs by hacking the SysVars

Post by Moggy »

I stumbled across this thread by Robsoft, on the WOS forum and wondered is such trickery possible with our humble little door wedge?

http://www.worldofspectrum.org/forums/d ... he-sysvars
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Speeding up programs by hacking the SysVars

Post by dr beep »

It is a trick that can be used in BASIC.

I suggest the step to MC for better use of speed.
User avatar
siggi
Posts: 988
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: Speeding up programs by hacking the SysVars

Post by siggi »

The Zeddy does not have a system variable holding the beginning of the program (like the speccy's PROG). The BASIC program of a Zeddy begins always at 16509, thus no system variable is necessary to store that constant value and the BASIC interpreter always starts there to find a line.

But a similar hack could be done by patching the length of the first line (at 16511/16512): if it set to a value, that covers the first line and all following lines, which should be skipped be the BASIC interpreter (NEXTLINE - 16509 or somethig like that ;) ) , then the BASIC interpreter will (when searching for a line) start at 16509 and will add the (patched) length of the first line to find the second line. Thus all "hidden" lines (covered by the hacked length of the first line) will be skipped at once.

But caution: if you forget to "unhack" the length of the first line, all "hidden" lines will also be deleted/edited, if you delete/edit the first line!

Siggi
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Speeding up programs by hacking the SysVars

Post by dr beep »

siggi wrote:The Zeddy does not have a system variable holding the beginning of the program (like the speccy's PROG). The BASIC program of a Zeddy begins always at 16509, thus no system variable is necessary to store that constant value and the BASIC interpreter always starts there to find a line.

But a similar hack could be done by patching the length of the first line (at 16511/16512): if it set to a value, that covers the first line and all following lines, which should be skipped be the BASIC interpreter (NEXTLINE - 16509 or somethig like that ;) ) , then the BASIC interpreter will (when searching for a line) start at 16509 and will add the (patched) length of the first line to find the second line. Thus all "hidden" lines (covered by the hacked length of the first line) will be skipped at once.

But caution: if you forget to "unhack" the length of the first line, all "hidden" lines will also be deleted/edited, if you delete/edit the first line!

Siggi
Not true,

My BASIC is stored where it uses less memory. This can be anywhere.
User avatar
siggi
Posts: 988
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: Speeding up programs by hacking the SysVars

Post by siggi »

If you write your own BASIC interpreter, "your" Basic can be stored everywhere ;-)

But the ZX81-Sinclair BASIC interpreter expects the BASIC program to be stored beginning at 16509: see Chapter 27 - Organization of memory:

http://www.worldofspectrum.org/ZX81BasicProgramming/

Image

Regards
Siggi
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Speeding up programs by hacking the SysVars

Post by dr beep »

No, you show default setting of the BASIC.

All these blocks are set by sysvars and I switch the order on many 1K hires games.
I must say that my code only uses a small BASIC-routine to start MC. No VARS or so to save memory.
However i proove that BASIC-code can be relocated in a different order
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: Speeding up programs by hacking the SysVars

Post by PokeMon »

dr beep wrote: However i proove that BASIC-code can be relocated in a different order
This is maybe true but doesn't make really sense when programming in machine code. When you try to get into BASIC from your 1k programs which is maybe quite hard :mrgreen: your application may crash at least when entering a new program line or deleting one. I even wouldn't say that you use BASIC in this context at all but more several rom routines which expect BASIC typical structures when called depending on the function used.
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Speeding up programs by hacking the SysVars

Post by dr beep »

PokeMon wrote:
dr beep wrote: However i proove that BASIC-code can be relocated in a different order
This is maybe true but doesn't make really sense when programming in machine code. When you try to get into BASIC from your 1k programs which is maybe quite hard :mrgreen: your application may crash at least when entering a new program line or deleting one. I even wouldn't say that you use BASIC in this context at all but more several rom routines which expect BASIC typical structures when called depending on the function used.
So back to the original question. You could probably alter the start of the BASIC and skip searching for previous lines.
However when stopping the program you must reset it to see the original start.

Better methods to speed up BASIC is, as done often, to save the program at the end of BASIC and do initialisation after that. When reloading those lines are only executed once and a jump to lowest linnumbers is done.
The interpreter now has to serach through less lines to do code.
Post Reply