newbie questions

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
utz
Posts: 27
Joined: Fri Jul 15, 2011 11:06 pm

newbie questions

Post by utz »

hi everybody! this is my first post here so allow me to quickly introduce myself. i'm a so-called chiptune musician with special interest in the most minimalistic sound devices. i know very little about zx81 or programming in general, but i'm trying to expand my knowledge ;)

anyway here's what i want to do. i want to create a little music demo for zx81 which uses the zx81mi music routine (and possibly others as well).

i've already written a little procedural landscape generator that i've attached below.

so here are my questions:

1) how can i speed up/optimize the code?

2) how can i inject the code from zx81mi into my program? i've tried to copy+paste it in zxtoken but that deletes the subsequent BASIC code. (btw i'm on xp pro so i can only use zxtoken, not zxbasic.)
Attachments
utzta817_ZxBasic.TXT
(1.71 KiB) Downloaded 222 times
utzta818.P
(2.67 KiB) Downloaded 234 times
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: newbie questions

Post by XavSnap »

Hi,
(btw i'm on xp pro so i can only use zxtoken, not zxbasic.)
Or... Vb81 XuR (it work too in TXT mode.)
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Re: newbie questions

Post by bobs »

utz wrote:1) how can i speed up/optimize the code?
Hello, and welcome to the forum.

To get the most speed out of your program you'd need to write it in machine code. But that's a very big step to make from BASIC. You can make some changes to make your BASIC program faster though - try the following:

As loops take time to processes you could combine your loops at lines 110-140, 160-180 & 190-210 into a single loop - and save time by not overwriting the display (i.e. put chr$ 3 and then overwrite with chr$ 137). Or instead don't do 110-140 in a loop - just replace with a 31 character string of chr$ 3s & chr$ 131s and just combine 160-180 & 190-210.
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: newbie questions

Post by XavSnap »

Hi,

I will try to code a scrolling code in Asm.
;-)

Regards the splash screen, you can capture the D_File screen in a single PRINT command...
This feature will be present in the next XuR realease.
Xav.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
utz
Posts: 27
Joined: Fri Jul 15, 2011 11:06 pm

Re: newbie questions

Post by utz »

thanks. i've implemented the suggested changes. left in the overwriting of display - the chr$ 137s depend on the randomly generated landscape so i'd have to introduce another if-clause. now i'm thinking i should combine the ifs in line 170/200 into a single line but i'm not quite sure how to make use of AND. maybe someone could give an example?

also another question, is it faster to use chr$ codes or the actual graphic symbols?

and... i still need to get the code from zx81mi into the program!!!

Code: Select all

    1 FAST 

    2 LET A=16

    3 DIM S(66)

    4 CLS 

    5 PRINT AT 4,0;"ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³³ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ                                ¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ                                ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ"

   10 FOR N=0 TO 63

   20 LET B=INT (10*RND)-4

   30 IF A+B>0 THEN LET A=A+B

   40 IF A>20 THEN LET A=A-10

   70 FOR C=8 TO A

   80 PLOT N,C

   90 NEXT C

  100 LET S(N+1)=A

  110 NEXT N

  120 LET S(66)=S(64)

  130 PRINT AT 18,0;"žžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžžž®®®®®®®®®®®®®®®®®®®®®®®®®®®®®®®®"

  160 FOR I=1 TO 32

  170 IF S(I*2)>7 THEN PRINT AT 18,I-1;CHR$ 137

  200 IF S((I*2)+2)>12 THEN PRINT AT 19,I-1;CHR$ 137

  210 NEXT I

  220 PRINT AT 0,0;CHR$ 5+CHR$ 5+CHR$ 132+CHR$ 1+CHR$ 3+CHR$ 5+CHR$ 132+CHR$ 1+CHR$ 6+CHR$ 4+CHR$ 7+CHR$ 4+CHR$ 7+CHR$ 1+CHR$ 7+CHR$ 5+CHR$ 132+CHR$ 0+CHR$ 0

  230 PRINT CHR$ 5+CHR$ 5+CHR$ 133+CHR$ 0+CHR$ 6+CHR$ 0+CHR$ 133+CHR$ 0+CHR$ 7+CHR$ 5+CHR$ 7+CHR$ 0+CHR$ 7+CHR$ 0+CHR$ 6+CHR$ 4+CHR$ 133+CHR$ 0+CHR$ 0

  240 PRINT CHR$ 3+CHR$ 1+CHR$ 2+CHR$ 0+CHR$ 3+CHR$ 1+CHR$ 2+CHR$ 0+CHR$ 1+CHR$ 1+CHR$ 1+CHR$ 0+CHR$ 3+CHR$ 1+CHR$ 3+CHR$ 1+CHR$ 2+CHR$ 0+CHR$ 0

  250 PRINT "BY IRRLICHT PROJECT"

  255 PRINT AT 21,0;"««««««««««««««««««««««««««««««««"

  260 SLOW 

  270 PAUSE 20

  280 LET A$="«««««««««««««««««««««««««««««««lets«see«if«this«routine«can«be«used«as«a«scroll«effect"

  290 LET A$=A$(2 TO )+A$(1)

  300 PRINT AT 21,1;A$(1 TO 30)

  310 GOTO 290
@XavSnap asm scolling would be nice of course! on the other hand zx81jens' routine (280-310) seems to do the job, as long as the string doesn't get too long - but that can be probably solved by splitting it up in parts.
Attachments
utzta81a.P
(2.66 KiB) Downloaded 213 times
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: newbie questions

Post by XavSnap »

Hi,
The Plot function in ASM is too slow...
In your case, you had to keep le Basic routine.

But, i have code the scrolling routine in ASM.

Have Fun.
Attachments
Line_Scroll.zip
ASM SCROLLED LINE ON ZX81
(7.83 KiB) Downloaded 208 times
LINE_SCROLL.P
(2.03 KiB) Downloaded 213 times
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: newbie questions

Post by XavSnap »


160 FOR I=1 TO 32

170 IF S(I*2)>7 THEN PRINT AT 18,I-1;CHR$ 137

200 IF S((I*2)+2)>12 THEN PRINT AT 19,I-1;CHR$ 137

210 NEXT I


OR

160 FOR I=1 TO 32
170 PRINT AT 18,I-1;CHR$ 137 AND S(I*2)>7;AT 19,I-1;CHR$ 137 AND S((I*2)+2)>12
210 NEXT I
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
RWAP
Posts: 1348
Joined: Thu May 08, 2008 8:42 am
Location: Stoke-on-Trent, UK
Contact:

Re: newbie questions

Post by RWAP »

Code: Select all

160 FOR I=1 TO 32
170 IF S(I*2)>7 THEN PRINT AT 18,I-1;CHR$ 137
200 IF S((I*2)+2)>12 THEN PRINT AT 19,I-1;CHR$ 137
210 NEXT I
I was going to suggest:

Code: Select all

160 FOR I=1 TO 32 STEP 2
170 PRINT AT 18,I-1;CHR$ 137 AND S(I)>7;AT 19,I-1;CHR$ 137 AND S(I+2)>12
210 NEXT I
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: newbie questions

Post by sirmorris »

I'd suggest removing those multiplys and constant subtractions from within your loop.

Code: Select all

159 LET Q=2
160 FOR I=0 TO 31
170 IF S(Q)>7 THEN PRINT AT 18,I;CHR$ 137
200 IF S(Q+2)>12 THEN PRINT AT 19,I;CHR$ 137
205 LET Q=Q+2
210 NEXT I
utz
Posts: 27
Joined: Fri Jul 15, 2011 11:06 pm

Re: newbie questions

Post by utz »

thanks everybody for the support!

@RWAP now that looks elegant! i totally forgot about STEP command. will use this.

@XavSnap merci beaucoup! i tried your XuR kit but i still don't know how to insert the code from zx81 Music Interpreter :(
Post Reply