Tricks in BASIC

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
User avatar
zx81jens
Posts: 174
Joined: Sat May 10, 2008 7:26 am
Location: a Basement in Nienburg / Germany

Tricks in BASIC

Post by zx81jens » Sat Jun 28, 2008 9:47 pm

hi!

try this:

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

greetings
jens
eyerything will be okay in the end.
if it´s not okay, it´s not the end.

and: uıɐbɐ ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ɹǝʌǝ ɹǝʌǝu ןןıʍ ı

Andre
Posts: 23
Joined: Sat Jun 21, 2008 6:28 pm
Location: Chateauguay-Quebec-Canada
Contact:

Re: Tricks in BASIC

Post by Andre » Sun Jun 29, 2008 2:35 pm

Bonjour Jens,

Yes, I tried this. Amazing what we can do with the variables' slicers in the Sinclair ZX81 basic.

Goodby(t)e, ANDRE***
http://www.zx-team.de/andre
http://zx81.ordi5.free.fr/andre

ken_uk
Posts: 4
Joined: Sat Oct 18, 2008 6:21 pm

Re: Tricks in BASIC

Post by ken_uk » Sat Oct 18, 2008 8:02 pm

Try shift V and B together instead of break. It works (so do other key combos, got that published in a mag in the 80's but didnt find out till years later, thought it never got published so never wrote any more letters at the time.GRRRRR

Another interesting trick, you will have to look it up yourself as my 81 manual is in the loft somewhere, and its about a quarter of a century since I last used a 81 is to use the codes to good effect. I think it worked on a 81, certainly worked on a spectrum, but my memory of those days is a bit faded now.

Basically look up the codes for cursor up/down/left/right etc, inverse etc (even more on the speccy) and put those in the name of the prog you are saving.

So instead of loading JETPAC or whatever it could say

Loading K
E
N

ie - you could have the text going down, or inverse etc. Never saw that done commercially, but it worked at home ;)

Also, another trick is getting sound on the 81, various different bits of code, and fast/slow mode use could get different tones if you turned up the volume on the tv. Some people even managed to get basic tunes made doing this.

Will post more if I remember them, I remember quite a lot, but the details are hazy, they sometimes do become clear though when my memory is having a good day.

Shaun_B
Posts: 329
Joined: Wed Apr 22, 2009 9:22 am

Re: Tricks in BASIC

Post by Shaun_B » Tue Apr 28, 2009 6:11 pm

Any tips on speeding up BASIC without using FAST?

For instance, it is quicker to LET X=0 or LET X=VAL "0" or LET X=PI-PI? Or is there no difference?

Can you also directly POKE chars to the screen? If you wanted to move around a single CHAR, is it quicker to POKE it directly to the location on the screen, or use the PRINT AT?

How about CLS? Is there another clever way to do this?

So many questions, so little time! My ZX81 is upstairs plugged through an old BW TV.

Regards,

Shaun.

User avatar
sirmorris
Posts: 2696
Joined: Thu May 08, 2008 4:45 pm
Location: oxon, uk

Re: Tricks in BASIC

Post by sirmorris » Thu Apr 30, 2009 2:42 pm

Hi Shaun, Ken.

The works of Andre*** are probably the gold-standard as far as making BASIC perform tricks. Check out his works - http://www.zx-team.de/andre/

Xav has also been known to make string slicing screen effects that amaze ... viewtopic.php?f=5&t=91&p=782#p782

Have fun experimenting!
--=== ZXpand+ ... A more moderner all-in-one upgrade solution for ZX81 ===--
* SD/MMC storage * 32K Hires-capable RAM * AY sound chip * Joystick port * Serial *
* BASIC enhancements - plug & play * Reset button * Auto-boot facility *

Moggy
Posts: 1513
Joined: Wed Jun 18, 2008 1:00 pm

Re: Tricks in BASIC

Post by Moggy » Sat May 02, 2009 10:37 pm

Hi all
I agree with Sir Morris, Andre has the most unique take on what makes a good ( and addictive ) game I have ever come across. Even His rem statements have great graphics!! Good gameplay and all in Basic!!

Regards Moggy

Shaun_B
Posts: 329
Joined: Wed Apr 22, 2009 9:22 am

Re: Tricks in BASIC

Post by Shaun_B » Wed Jul 14, 2010 10:16 pm

I've been messing around with the powerful ZX BASIC on the '81 and came up with this little routine:

Code: Select all

 1 REM TELETYPE ROUTINE BY SHAUN BEBBINGTON IN 2010. THIS IS FREEWARE SO USE IT AND IMPROVE IT ;-)**
 2 FAST
 3 LET A=16514
 4 LET X=PI-PI
 5 LET Y=X
 6 LET N=X
 7 SLOW
 8 IF PEEK A=VAL "216" THEN GOTO VAL "17"
 9 PRINT AT X,Y;CHR$ PEEK A;CHR$ 177
10 IF Y<=VAL "31" THEN LET Y=Y+(PI/PI)
11 IF Y=VAL "32" THEN LET N=PI/PI
12 IF N=VAL "1" THEN LET X=X+(PI/PI)
13 IF N=VAL "1" THEN LEY Y=PI-PI
14 LET N=PI-PI
15 LET A=A+(PI/PI)
16 GOTO VAL "8"
17 STOP
18 REM PUT THE REST OF YOUR CODE HERE IF YOU LIKE :-)
Okay, here is what it does. Firstly, there is no DATA statement, so what we're doing is storing what we want to write to the screen in a REM statement. This is basically where each character is, so what we need to do is read each character and then write it to the screen.

So, line 2 goes into FAST mode - you don't need to do this, it's just something I do when declaring variables and so on before I do anything more like write to the screen or such like. Line 3 sets up an integer called A and this is the location in memory where the start of the text is directly after the REM statement in line 1.

Line 4, 5 and 6 sets up the integers that we're going to use later on. PI-PI will always be zero, so it just makes X, Y and N equal to this.

Line 7 goes back to slow mode so that we'll see what's happening inside the TV screen (or virtual tele).

Line 8 checks wether or not we've reached the end of the text held in the REM statement in line 1. If so, it jumps to line 17 (end of program).

Line 9 PRINTs the byte held in the pointer in the A variable, followed by a familiar character (you'll see the relevance) and AT the location X (row) and Y (column).

Lin 10 checks if Y is smaller to or equal to 31, if so, it increases this variable by one as PI/PI is equal to 1. Then line 11 will check if Y has reached the end of the row and sets up a condition in N to tell the program to increment X by one and put Y back to zero (first column).

As we've already tested the condition N, we can return this to zero and also increase A by one. This then loops back around until the end of the text is reached by SHIFT and H (**).

From line 17, you can do what you like.

Have a play with it and see what you can make it do. For instance, you could add a condition in which the text is not output to the screen unless a key is being pressed, or something else.

Edit: Oops! Spotted a bug which was *ahem* deliberate, so I've fixed it ;-)

Regards,

Shaun.

User avatar
XavSnap
Posts: 462
Joined: Sat May 10, 2008 3:23 pm

Re: Tricks in BASIC

Post by XavSnap » Sat Jul 17, 2010 5:22 pm

Hi Shaun,
Any tips on speeding up BASIC without using FAST?

For instance, it is quicker to LET X=0 or LET X=VAL "0" or LET X=PI-PI? Or is there no difference?
NO! This tips isn't faster than LET X=0.
In basic, You had to reduce all commands!
All new lines and RAND USR in basic code, make times.
A Cls had to rebuild the D_file and the vars!
Try :

Code: Select all

10 for a=1 to 20
20 SCROLL
30 next a
40 CLS
-> it take many seconds.

LET X=VAL "0" is slower than LET X=0 !
But, LET X=0 take more rooms in memory than LET X=VAL"0" (3bytes!)
It's used to preserve memory (in case of 1Kb).

You can use the "optimisation" option in the XuR basic window to retrive some memory.
Can you also directly POKE chars to the screen? If you wanted to move around a single CHAR, is it quicker to POKE it directly to the location on the screen, or use the PRINT AT?
Yes, have a look to :
http://zx81.ordi5.free.fr/programmes/minos.zip
How about CLS? Is there another clever way to do this?
Yes...
Print USR 2602;"OK"
But, print a value... (the BC register!)

( Note : Print USR 3086;"Hello";USR 3086;"World" is a fast scroll !)

But, the CLS function don't only clear the screen...
It expend the d_file and move the VARS values too.
10 IF Y<=VAL "31" THEN LET Y=Y+(PI/PI)
11 IF Y=VAL "32" THEN LET N=(PI/PI)
12 IF N=VAL "1" THEN LET X=X+(PI/PI)
13 IF N=VAL "1" THEN LEY Y=PI-PI
To make Faster you code, Just use the AND function !

Code: Select all

10 LET N= N - (N + (PI/PI)) AND (Y=VAL "32")
11 LET Y=(Y AND N=VAL "1") + ((PI/PI) AND (y<=VAL"31"))
12 LET X=X+((PI/PI) AND N=VAL "1")
Note: the AND fuction can be lococated in the PRINT line, But, in this case, the X and the Y values are changed. X=X+ or Y=Y+ something.

Let X=X * (0 and N=10) , Restet the variable if N=10... X=0, however X=X

Shaun_B
Posts: 329
Joined: Wed Apr 22, 2009 9:22 am

Re: Tricks in BASIC

Post by Shaun_B » Sun Jul 18, 2010 3:25 pm

That's really great - thanks for the tips. I'm on a journey to learn more about the Z80, so I know what the BC register is now ;-)

Regards,

Shaun.

User avatar
XavSnap
Posts: 462
Joined: Sat May 10, 2008 3:23 pm

Re: Tricks in BASIC

Post by XavSnap » Mon Jul 19, 2010 11:38 pm

Hi,

The BC register ...
http://zx81.vb81.free.fr/ASM2.html

1 REM LD BC,$0023 + RET
2 Print USR 16514

B=$00
C=$23
The Print display the BC value ...
"35"
:D

Step One ... the Basic.
Step Tow ... The ASM.
Step Tree ... Save the World !

Have Fun.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests