Tricks in BASIC

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
archmageirvine
Posts: 1
Joined: Sat Jul 01, 2017 1:52 am

Re: Tricks in BASIC

Post by archmageirvine »

I have an article describing a lot of these memory saving techniques and their history.

See: https://mega.nz/#!ioVzgDLa!Vmb4uS9c4Ivz ... wETip0tSp8

RWAP
Posts: 1330
Joined: Thu May 08, 2008 8:42 am
Location: Stoke-on-Trent, UK
Contact:

Re: Tricks in BASIC

Post by RWAP »

archmageirvine wrote:
Sat Jul 01, 2017 1:55 am
I have an article describing a lot of these memory saving techniques and their history.

See: https://mega.nz/#!ioVzgDLa!Vmb4uS9c4Ivz ... wETip0tSp8
Welcome to the forums - that is quite an interesting short article - I have uploaded it here to make it easier to accesss
Attachments
zx81-memory.pdf
(104.14 KiB) Downloaded 235 times

Shaun_B
Posts: 471
Joined: Wed Apr 22, 2009 10:22 am

Re: Tricks in BASIC

Post by Shaun_B »

Type this:

Code: Select all

LET A$="DONKEYSOFT"
in direct mode, and then:

Code: Select all

10 PRINT A$;" ";
20 GOTO 10
9998 SAVE "D"
9999 GOTO 10
Do not try RUNning the listing, instead type:

Code: Select all

GOTO 9998
As you will see, the file will save everything including the variable stack. So that means - if you are careful - you may type in your variables in direct mode and use them in your program. It also means that if someone breaks your program to hack it, and types RUN, the var stack will be wiped.

Regards,

Shaun

Shaun_B
Posts: 471
Joined: Wed Apr 22, 2009 10:22 am

Re: Tricks in BASIC

Post by Shaun_B »

I haven't thought of a practical use for it yet, but this is possible:

Code: Select all

  10 LET I=CODE "4"
  20 FOR I=I/I TO I
  30 PRINT I,;
  40 NEXT I
So you're re-using I in place of the start and end of the loop counter, and declaring I as the scalar value for the FOR/NEXT loop.

Regards,

Shaun.

JJH
Posts: 6
Joined: Sun Jan 28, 2018 4:15 pm

Re: Tricks in BASIC

Post by JJH »

Hi

I've not programmed anything in 30 years and am really struggling with many things.
This caught my eye while I was reading a few threads earlier this evening and I wonder if anyone could post an explanation of line 20.
The rest is simple enough to follow and I think I kind of somewhat get it, but not totally, so please assume I know nothing.

10 LET A$=" HELLO USER. THIS IS THE BEST COMPUTER IN THE WORLD. THE SINCLAIR ZX81 "
20 LET A$=A$(2 TO )+A$(1)
30 PRINT AT 10,1;A$(1 TO 30)
40 GOTO 20

Also, if this is covered in the SINCLAIR BASIC manual and anyone knows what page it's on, please let me know that too.

Thanks in advance to anyone that might respond.

JJH
Posts: 6
Joined: Sun Jan 28, 2018 4:15 pm

Re: Tricks in BASIC

Post by JJH »

Must have been extra dozey earlier. I get it now.
@The little basic program is a nice way to achieve a simple text crawl:)

User avatar
Paul
Posts: 1087
Joined: Thu May 27, 2010 8:15 am
Location: Germanys west end

Re: Tricks in BASIC

Post by Paul »

Hi jjh
Well you did not give us much time to respond. ;)
Glad you sorted it out.
Sinclair Basic is a little different to others because of the usage of the keyword TO and the omitted parameters.
Kind regards Paul
In theory, there is no difference between theory and practice. But, in practice, there is.

JJH
Posts: 6
Joined: Sun Jan 28, 2018 4:15 pm

Re: Tricks in BASIC

Post by JJH »

Hi Paul
Thanks for checking it out.
Think I was just super tired last night after work.
It's a great forum/resource going on here that I only stumbled upon just over a week ago.
Lot's of really friendly, passionate it seems like and quick too offer help too.
Cheers!

Shaun_B
Posts: 471
Joined: Wed Apr 22, 2009 10:22 am

Re: Tricks in BASIC

Post by Shaun_B »

Here's a scrolly text in a GOTO-less state:

Code: Select all

    1 LET X=SGN PI
    2 LET Y=INT (PI*10)
    3 FOR I=. TO SGN PI STEP .
    4 PRINT AT .,.;"                                ... SCROLLY DEMO BY DONKEYSOFT MMXX ... HELLO TO ALL ZX-FANZ OUT THERE ...                                "(X TO X+Y)
    5 LET X=X+SGN PI
    6 IF X>VAL "106" THEN LET X=SGN PI
    7 LET I=I+LEN INKEY$
    8 NEXT I
It looks like the lack of a ZX-Next arriving has meant that I'm going to be making more ZX81 warez, so apologies in advance for more of my basic carp.

And Happy New Year guys!

Regards,

Shaun.

User avatar
XavSnap
Posts: 893
Joined: Sat May 10, 2008 4:23 pm

Re: Tricks in BASIC

Post by XavSnap »

Hi,
The dot character equal a "0" integer and don't save memory. (8 bytes)
Anyway, it a good code!
8-)
Xavier

Post Reply