Page 1 of 6

Tricks in BASIC

Posted: Sat Jun 28, 2008 10:47 pm
by zx81jens
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

Re: Tricks in BASIC

Posted: Sun Jun 29, 2008 3:35 pm
by Andre
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

Re: Tricks in BASIC

Posted: Sat Oct 18, 2008 9:02 pm
by ken_uk
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.

Re: Tricks in BASIC

Posted: Tue Apr 28, 2009 7:11 pm
by Shaun_B
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.

Re: Tricks in BASIC

Posted: Thu Apr 30, 2009 3:42 pm
by sirmorris
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!

Re: Tricks in BASIC

Posted: Sat May 02, 2009 11:37 pm
by Moggy
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

Re: Tricks in BASIC

Posted: Wed Jul 14, 2010 11:16 pm
by Shaun_B
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.

Re: Tricks in BASIC

Posted: Sat Jul 17, 2010 6:22 pm
by XavSnap
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" (4bytes!) [PI-PI = 3bytes]
It's used to preserve memory (in case of 1Kb).

You can use the "optimisation" option in the XuR basic window to retrieve 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 function can be located 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) , Reset the variable if N=10... X=0, however X=X

Re: Tricks in BASIC

Posted: Sun Jul 18, 2010 4:25 pm
by Shaun_B
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.

Re: Tricks in BASIC

Posted: Tue Jul 20, 2010 12:38 am
by XavSnap
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.