Tricks in BASIC

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Tricks in BASIC

Post by dr beep »

JJH wrote: Wed Feb 07, 2018 12:00 am 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.
Line 20 takes position 2 to the end of the text and adds position 1 at the back.
The next time it does the same, but then position 1 is taken by original position 2.
In this way the text moves to right and is added at the back.
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

Re: Tricks in BASIC

Post by Shaun_B »

XavSnap wrote: Tue Jan 07, 2020 6:58 pm Hi,
The dot character equal a "0" integer and don't save memory. (8 bytes)
Anyway, it a good code!
8-)
I think it is faster then NOT PI and 0, or am I incorrect on that?

Also, this line:

Code: Select all

    7 LET I=I+LEN INKEY$
Any reason why LET I=LEN INKEY$ wouldn't work instead? (i.e., why I had to increment the I counter in the FOR/NEXT loop to exit the loop)

Thanks,

Shaun
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Tricks in BASIC

Post by XavSnap »

1 LET X=SGN PI
2 LET Y=VAL"31"
3 FOR I=NOT PI TO SGN PI STEP NOT PI
4 PRINT AT 0,0;" ... SCROLLY DEMO BY DONKEYSOFT MMXX ... HELLO TO ALL ZX-FANZ OUT THERE ... "(X TO X+Y)
5 LET X=X+1
6 IF X=106 THEN LET X=SGN PI
7 IF NOT NOT INKEY$ THEN LET I=I+SGN PI
8 NEXT I
To speed up the code, you had to use FP values in the loop.
The FOR line is read one time, but all lines incude in the FOR/next had to be changed.
We can't save memory in the room…
7 IF NOT NOT INKEY$ THEN LET I=I+SGN PI
Or 7 IF NOT INKEY$ THEN NEXT I
8 line deleted.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

Re: Tricks in BASIC

Post by Shaun_B »

Thanks for the tips XavSnap!

Here is a maze generator simulator to try:
InfiMaze.png
InfiMaze.png (2.51 KiB) Viewed 17402 times
I've added additional white spaces for some more readability. Remove them to save bytes.

Regards,

Shaun
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Tricks in BASIC

Post by XavSnap »

Code: Select all

1 LET B$="3086"
2 LET A=USR VAL B$
3 PRINT "@80@00@01@02@87@04@05@83@03@85@81@82@07@84@06@86"(RND*15+1);
4 LET A=A+1
5 IF A=32 THEN GOTO PI-PI/PI
6 GOTO PI
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

Re: Tricks in BASIC

Post by Shaun_B »

Here's a new version of the maze generator simulator in 5 BASIC lines :-)
InfiMaze2.png
InfiMaze2.png (2.21 KiB) Viewed 17398 times
Enjoy!

Regards,

Shaun.
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Tricks in BASIC

Post by XavSnap »

Code: Select all

2 LET A=USR VAL "3086"
3 PRINT "@80@00@01@02@87@04@05@83@03@85@81@82@07@84@06@86"(RND*15+1);
4 LET A=A+1
5 IF A=32 THEN RUN
6 GOTO PI
:lol:
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

Re: Tricks in BASIC

Post by Shaun_B »

XavSnap wrote: Tue Jan 07, 2020 10:29 pm

Code: Select all

2 LET A=USR VAL "3086"
3 PRINT "@80@00@01@02@87@04@05@83@03@85@81@82@07@84@06@86"(RND*15+1);
4 LET A=A+1
5 IF A=32 THEN RUN
6 GOTO PI
:lol:
Excellent work, as always!

One day the apprentice will become a master.

Regards,

Shaun.
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Tricks in BASIC

Post by XavSnap »

Just faster in 16k !
Greet Master…
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

Re: Tricks in BASIC

Post by Shaun_B »

XavSnap wrote: Wed Jan 08, 2020 1:44 am Just faster in 16k !
Greet Master…
16K of RAM ought to be enough for anyone, right?

Regards,

Shaun.
Post Reply