I agree!XavSnap wrote:Step One ... the Basic.
Step Tow ... The ASM.
Step Tree ... Save the World !
Tricks in BASIC
Re: Tricks in BASIC
Re: Tricks in BASIC
Hi,
Ther's a mysterious ASM Code !
Basic:
ASM:
Ther's a mysterious ASM Code !
Basic:
Code: Select all
# DISPLAY EXEMPLE
# ><AVSNAP
# ®®®®®®®®®®®®®®®®®
# FOUND IN ORDI5 n2
# PAGE 29
# AUTHOR :
# ERIC WEINSTEIN.
# ®®®®®®®®®®®®®®®®®
1 REM [HEX:\
0E,21,3E,06,C6,02,47,CD,\
18,09,CD,9B,09,12,FD,34,\
3A,2A,0C,40,23,16,06,ED,\
B1,15,20,FB,54,5D,ED,B1,\
C3,5D,0A ]
7 POKE 16536,6
8 POKE 16517,6
10 LET I=1
50 DIM N$(50,16)
55 FOR A=1 TO 50
60 LET N$(A)=VAL A + "HELLO"+ VAL A
70 NEXT A
90 FOR I=1 TO 50
96 RAND USR 16514
98 PRINT N$(I);"(";I;")"
100 NEXT I
8999 STOP
9000 SAVE "AUTOSCROLL"
Code: Select all
#define ORG .org ; TASM crossassembler definitions
ORG $4082
LD C,$21
LD A,$06
ADD A,$02
LD B,A
CALL $0918 ; [LOCADDR]
CALL $099B ; [ONESPACE]
LD (DE),A
INC (IY+58)
LD HL,($400C) ; GET DFILE
INC HL
LD D,$06
Lb4099:
CPIR
DEC D
JR NZ, Lb4099 ; [$4099:16537]
LD D,H
LD E,L
CPIR
JP $0A5D ; [RECLAIM1]
.end
 Attachments

 Display.p
 ASM display codes [autoscroll] (ZX81)
 (1.31 KiB) Downloaded 190 times
Re: Tricks in BASIC
As you may have noticed, I've been messing about with Sinclair BASIC again and thanks to this thread I've found some excellent tips.
For instance, you can negate some of the problems of it not allowing multiple statements like:
by calling the routine in the BASIC, like
As luck would have it, USR 2602 (CLS) returns zero so it's valid in the FOR statement. Very handy indeed
Any more tips?
Regards,
Shaun.
For instance, you can negate some of the problems of it not allowing multiple statements like:
Code: Select all
10 CLS: FOR I=0 TO 10
...
20 NEXT I
Code: Select all
10 FOR I= USR VAL "2602" TO 10
...
20 NEXT I
Any more tips?
Regards,
Shaun.
Re: Tricks in BASIC
NOT PI =0
SGN PI =1
INT PI =3
SAVE maybe included in program, then after loading from tape it carries on, so if you'd typed LET A=0 before then it'll still =0.
SGN PI =1
INT PI =3
SAVE maybe included in program, then after loading from tape it carries on, so if you'd typed LET A=0 before then it'll still =0.
Re: Tricks in BASIC
I think NOT PI should = faster than PIPI
& maybe CODE "$" faster than VAL "35"
LET A = A + A faster than A * 2
IF NOT A THEN faster than IF A <>0 THEN
0 = NOT PI
1 = SGN PI
3 = INT PI
Text within " " may include full words, press key for THEN & then other keys & delete THEN if not needed.
& maybe CODE "$" faster than VAL "35"
LET A = A + A faster than A * 2
IF NOT A THEN faster than IF A <>0 THEN
0 = NOT PI
1 = SGN PI
3 = INT PI
Text within " " may include full words, press key for THEN & then other keys & delete THEN if not needed.
Re: Tricks in BASIC
On Spectrum I used sometimes also expressions like PI*PI, PI+PI, etc.
Considering that numbers occupy the visualization bytes plus 5 hidden bytes for the internal number encoding (mantissa etc..), it can save lots of memory, even if many of such combinations slow down the code.
Sometimes the "INT" rounding can be omitted.
One more idea:
USR VAL "3893" (pause) will act also as keyboard scanner reporting different codes depending on the 5key group being pressed.
Considering that numbers occupy the visualization bytes plus 5 hidden bytes for the internal number encoding (mantissa etc..), it can save lots of memory, even if many of such combinations slow down the code.
Sometimes the "INT" rounding can be omitted.
One more idea:
USR VAL "3893" (pause) will act also as keyboard scanner reporting different codes depending on the 5key group being pressed.
Re: Tricks in BASIC
On a ZX Spectrum you don't really need to save memory in BASIC. You have at least 16K where on a ZX81 you would have 1K.stefano wrote:On Spectrum I used sometimes also expressions like PI*PI, PI+PI, etc.
Considering that numbers occupy the visualization bytes plus 5 hidden bytes for the internal number encoding (mantissa etc..), it can save lots of memory, even if many of such combinations slow down the code.
Sometimes the "INT" rounding can be omitted.
One more idea:
USR VAL "3893" (pause) will act also as keyboard scanner reporting different codes depending on the 5key group being pressed.
Only reason on a ZX Spectrum might be to stay in BASIC under 24064 to start machinecode on a 256border.
Re: Tricks in BASIC
more interesting constants /hints:
1 = COS PI
255 = PEEK PI
36.5 = PI**PI (approx.)
1.5 = LN PI**PI (approx)., but VAL "1.5" is just 2 bytes longer
Another interesting trick could be:
10 RAND PI
20 PRINT EXP EXP RND
30 GOTO 20
..and take benefit of the fixed sequence
1 = COS PI
255 = PEEK PI
36.5 = PI**PI (approx.)
1.5 = LN PI**PI (approx)., but VAL "1.5" is just 2 bytes longer
Another interesting trick could be:
10 RAND PI
20 PRINT EXP EXP RND
30 GOTO 20
..and take benefit of the fixed sequence
Re: Tricks in BASIC
Memory on a Spectrum: yes and no.. the real memory availability on the 16K model was much lower, I'd say 7/8K. The 16K rampack on a ZX81 had a way wider space for the BASIC programs.
The Supercode II tools for the Spectrum included compression routines able to remove comments and compress number encoding.. I don't remember them all but one of them was simply zeroing all the visible part of the number, thus preserving the program speed, obfuscating the program a little and gaining few bits of pragram size.
The Supercode II tools for the Spectrum included compression routines able to remove comments and compress number encoding.. I don't remember them all but one of them was simply zeroing all the visible part of the number, thus preserving the program speed, obfuscating the program a little and gaining few bits of pragram size.
Re: Tricks in BASIC
A little more, perhaps useful in trigonometry, graphics, etc
360 (approx) = EXP EXP SQR PI
5.5 (approx) = LN PEEK PI
360 (approx) = EXP EXP SQR PI
5.5 (approx) = LN PEEK PI