Tricks in BASIC

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
User avatar
stefano
Posts: 494
Joined: Tue Dec 11, 2012 9:24 am
Contact:

Re: Tricks in BASIC

Post by stefano »

Ahh.. PI and "NOT PI".. that's the way to optimize!
The Spectrum has also "BIN" meaning zero as well, but it adds the whole mantissa, thus it is equivalent to '0'. Yet NOT PI is the only choice
AyreGuitar
Posts: 3
Joined: Sun Aug 18, 2019 4:34 pm

Re: Tricks in BASIC

Post by AyreGuitar »

Shaun_B wrote: Tue Jan 07, 2020 10:21 pm Here's a new version of the maze generator simulator in 5 BASIC lines :-)
InfiMaze2.png
Enjoy!

Regards,

Shaun.
It's possible to squeeze the maze generator into just one line using some USR calls in a PRINT statement like this:

Code: Select all

10 PRINT "@80@00@01@02@87@04@05@83@03@85@81@82@07@84@06@86"(RND*15+NOT PEEK USR (3085+(ABS(PEEK 16441-17)=16))*USR 3663)
USR 3085 does nothing, just returns, but...
USR 3086 does SCROLL, which is triggered when 16441 (S_POSN_X) = 33 (at start of program) or 1 (when about to run out of screen space)
USR 3663 is used to GOTO 0

Enjoy!
User avatar
BarryN
Posts: 151
Joined: Thu Nov 09, 2017 11:34 pm

Re: Tricks in BASIC

Post by BarryN »

AyreGuitar wrote: Wed Sep 22, 2021 8:06 pm
Shaun_B wrote: Tue Jan 07, 2020 10:21 pm Here's a new version of the maze generator simulator in 5 BASIC lines :-)

InfiMaze2.png

Enjoy!

Regards,

Shaun.
It's possible to squeeze the maze generator into just one line using some USR calls in a PRINT statement like this:

Code: Select all

10 PRINT "@80@00@01@02@87@04@05@83@03@85@81@82@07@84@06@86"(RND*15+NOT PEEK USR (3085+(ABS(PEEK 16441-17)=16))*USR 3663)
USR 3085 does nothing, just returns, but...
USR 3086 does SCROLL, which is triggered when 16441 (S_POSN_X) = 33 (at start of program) or 1 (when about to run out of screen space)
USR 3663 is used to GOTO 0

Enjoy!
How the %$^%#%$@^%#$@ do you type that in? How do you type an @?
AyreGuitar
Posts: 3
Joined: Sun Aug 18, 2019 4:34 pm

Re: Tricks in BASIC

Post by AyreGuitar »

Sorry, I was using the same convention I'd seen on this thread for using hexadecimal numbers for graphics characters, so "@80" is CHR$(128)
Here's a screenshot running on JSZeddy emulator for the actual listing:
MazeOneliner.png
The graphics string is the same as the original multi line version earlier in this thread.
dr beep
Posts: 1638
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Tricks in BASIC

Post by dr beep »

Code: Select all

10 GOTO 10-8*(INKEY$="N")
Saves a line, this code does the same as

Code: Select all

10 IF INKEY$<>"N" THEN GOTO 10
11 GOTO 2
User avatar
XavSnap
Posts: 1705
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Tricks in BASIC

Post by XavSnap »

Send datas from Basic to an ASM routine: (from Greg's AY sound driver)
Sound Cmd.jpg
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1705
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Tricks in BASIC

Post by XavSnap »

Retrieve the "BC", "B" and "C" value in BASIC from an USR function:

Code: Select all

1 REM [ASM= \
ORG 16514|\
LD BC,$0100|\
INC BC|\
INC BC|\
RET|\
]
10 PRINT AT 1,1;"BC= ";USR 16514
15 REM COMPUTE THE VALUE
20 LET R=USR 16514
30 LET B= INT (R/256)
40 LET C= R-(B*256)
50 PRINT AT 3,1;"B= ";B,"C= ";C
55 REM OR...
60 RAND USR 16514
70 PRINT AT 5,1;"BC= ";PEEK 16435*256+PEEK 16434
80 PRINT AT 7,1;"B= ";PEEK 16435,"C= ";PEEK 16434
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply