News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

Some BASIC Questions

Started by DistantStar001, 03:06, 07 March 25

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DistantStar001

Hi all, 

So there's this little BASIC program for the Commodore 128 I got off of one of the 8-Bit Guy's videos that does this dancing line "kaleidoscope" thing on the screen, and for fun, I've been trying to translate it for other machines. So far I've managed to get it for the Apple II, VIC-20, and with a little [to a lot] of help, the BBC, ZX Spectrum, C64, IBM PC, CoCo, and Atari 8-BITs. Generally, it's just fun to have running in the background of Zoom meetings. Especially on an old CRT!

Now I'm working on my Amstrad CPC 464. Unfortunately, this is looking to be one I will need a little [and hopefully not a lot of] help with.

The original Commodore 128 program is listed below [minus the REM statement]:

20 dim b1(50) : dim b2(50)
30 dim b3(50) : dim b4(50)
50 print "line spacing"; : input s
60 print "tail length"; : input l
80 d1=0 : d2=1 : d3=0 : d4=1
90 a1=0 : a2=0
100 a3=50 : a4=100
110 c=1
120 cc=0
130 p=0
140 e=1
150 graphic 3,1
151 color 0,1 : color 1,15 : color 2,8 : color 3,9
170 gosub 260
180 draw c,a1,a2 to a3,a4
190 b1(p)=a1 : b2(p)=a2 : b3(p)=a3 : b4(p)=a4
200 p=p+1 : if p=l then p=0
210 draw 0,b1(e),b2(e) to b3(e),b4(e)
220 e=e+1 : if e=l then e=0
230 cc=cc+1 : if cc<>5 then goto 170
240 cc=0 : c=c+1 : if c=4 then c=1
250 goto 170
260 if d1=0 then if a1<=s then d1=1 : a1=1 : goto 300
270 if d1=0 then a1=a1-s : goto 300
280 if a1+s>=159 then d1=0 : a1=158 : goto 300
290 a1=a1+s
300 if d2=0 then if a2<=s then d2=1 : a2=1 : goto 340
310 if d2=0 then a2=a2-s : goto 340
320 if a2+s>=199 then d2=0 : a2=198 : goto 340
330 a2=a2+s
340 if d3=0 then if a3<=s then d3=1 : a3=1 : goto 380
350 if d3=0 then a3=a3-s : goto 380
360 if a3+s>=159 then d3=0 : a3=158 : goto 380
370 a3=a3+s
380 if d4=0 then if a4<=s then d4=1 : a4=1 : return
390 if d4=0 then a4=a4-s : return
400 if a4+s>=199 then d4=0 : a4=198 : return
410 a4=a4+s
420 return

And here's what I have worked out so far for the Amstrad: 

20 DIM B1(50) : DIM B2(50)

30 DIM B3(50) : DIM B4(50)
50 PRINT "LINE SPACING"; : INPUT S
60 PRINT "TAIL LENGTH"; : INPUT L
80 D1=0 : D2=1 : D3=0 : D4=1
90 A1=0 : A2=0
100 A3=200 : A4=400
110 C=1
120 CC=0
130 P=0
140 E=1
150 MODE 1
170 GOSUB 260
180 DRAW A1,A2,C: MOVE A3,A4
190 B1(P)=A1 : B2(P)=A2 : B3(P)=A3 : B4(P)=A4
200 P=P+1 : IF P=L THEN P=0
210 DRAW B1(E),B2(E),0 : MOVE B3(E),B4(E)
220 E=E+1 : IF E=L THEN E=0
230 CC=CC+1 : IF CC<>5 THEN GOTO 170
240 CC=0 : C=C+1 : IF C=8 THEN C=1
250 GOTO 170
260 IF D1=0 THEN IF A1<=S THEN D1=1 : A1=1 : GOTO 300
270 IF D1=0 THEN A1=A1-S : GOTO 300
280 IF A1+S>=659 THEN D1=0 : A1=658 : GOTO 300
290 A1=A1+S
300 IF D2=0 THEN IF A2<=S THEN D2=1 : A2=1 : GOTO 340
310 IF D2=0 THEN A2=A2-S : GOTO 340
320 IF A2+S>=399 THEN D2=0 : A2=398 : GOTO 340
330 A2=A2+S
340 IF D3=0 THEN IF A3<=S THEN D3=1 : A3=1 : GOTO 380
350 IF D3=0 THEN A3=A3-S : GOTO 380
360 IF A3+S>=659 THEN D3=0 : A3=658 : GOTO 380
370 A3=A3+S
380 IF D4=0 THEN IF A4<=S THEN D4=1 : A4=1 : RETURN
390 IF D4=0 THEN A4=A4-S : RETURN
400 IF A4+S>=399 THEN D4=0 : A4=398 : RETURN
410 A4=A4+S
420 RETURN

The CPC version is doing something, but obviously not what it's supposed to if you compare it to the C128. For starters, it's not erasing the lines after the designated tail length. Also, the lines aren't maintaining a consistent length or angle. And lastly, I can't seem to make the background black in modes 1 or 2. I can in mode 0, but the lines are too chunky to see. Any suggestions?

lightforce6128

#1
First suspicious thing: DRAW ... MOVE in this order looks strange. In almost all cases it should be MOVE ... DRAW. Just swap this in lines 180 and 210 and erasing will work.

BORDER 0 will make the border black. INK 0,0 will make the background black.

Another thing about colors, called "pen" in BASIC filled with "ink": In line 240 the color cycles from 1 to 7. But on CPC the pen number is limited to 0-1 for mode 2, to 0-3 for mode 1, and to 0-15 for mode 0. So if mode 1 is used, the check in line 240 should be for 4, not for 8. But it seems that BASIC solves this without an error message and with simply ignoring higher bits. So e.g. pen 5 in mode 1 is the same as pen 1.

I could not check the length/angle thing, because I could only check the CPC version. This shows something similar to the old default Windows screen saver. Although there are easily available online emulators for C128 on the web, I did not find a possibility to copy/paste the above source code into the emulator.

DistantStar001

#2
Thanks!

This worked perfectly, although I did have to correct a few of my typos and correct the math a bit. But it works now :D.

in any case, if anyone's curious, here's the corrected program [hopefully typo-free]:


10 MODE 1
20 DIM B1(50) : DIM B2(50)
30 DIM B3(50) : DIM B4(50)
50 PRINT "LINE SPACING"; : INPUT Z
55 LET S=Z*1.5
60 PRINT "TAIL LENGTH"; : INPUT L
80 D1=0 : D2=1 : D3=0 : D4=1
90 A1=0 : A2=0
100 A3=75 : A4=125
110 C=1
120 CC=0
130 P=0
140 E=2
150 MODE 1: BORDER 0: INK 0,0
170 GOSUB 260
180 MOVE A1,A2: DRAW A3,A4,C
190 B1(P)=A1 : B2(P)=A2 : B3(P)=A3 : B4(P)=A4
200 P=P+1 : IF P=L THEN P=0
210 DRAW B1(E),B2(E) : MOVE B3(E),B4(E),0
220 E=E+1 : IF E=L THEN E=0
230 CC=CC+1 : IF CC<>5 THEN GOTO 170
240 CC=0 : C=C+1 : IF C=4 THEN C=1
250 GOTO 170
260 IF D1=0 THEN IF A1<=S THEN D1=1 : A1=1 : GOTO 300
270 IF D1=0 THEN A1=A1-S : GOTO 300
280 IF A1+S>=639 THEN D1=0 : A1=638 : GOTO 300
290 A1=A1+S
300 IF D2=0 THEN IF A2<=S THEN D2=1 : A2=1 : GOTO 340
310 IF D2=0 THEN A2=A2-S : GOTO 340
320 IF A2+S>=399 THEN D2=0 : A2=398 : GOTO 340
330 A2=A2+S
340 IF D3=0 THEN IF A3<=S THEN D3=1 : A3=1 : GOTO 380
350 IF D3=0 THEN A3=A3-S : GOTO 380
360 IF A3+S>=639 THEN D3=0 : A3=638 : GOTO 380
370 A3=A3+S
380 IF D4=0 THEN IF A4<=S THEN D4=1 : A4=1 : RETURN
390 IF D4=0 THEN A4=A4-S : RETURN
400 IF A4+S>=399 THEN D4=0 : A4=398 : RETURN
410 A4=A4+S
420 RETURN

On a side note, is there a Mac-compatible CPC emulator that I can copy and paste text into?

genesis8

#3
Simpler than a MacOS emulator :

CPCBasicTS on Github

Run your basic code directly on the web

I tried 1 - 10, 1 - 5 without problems, 1 - 2 got a basic error of type mismatch
____________
Amstrad news site at Genesis8 Amstrad Page

ZorrO

Do you have link for this  8-Bit Guy's video?
CPC+PSX 4ever

DistantStar001

Quote from: ZorrO on 20:33, 07 March 25Do you have link for this  8-Bit Guy's video?

It's in the sale announcement for the Commander X-16, "My Dream Computer is Finally on Sale!," about 11 minutes and 50 seconds in:


McArti0

#6
C128
Quote from: DistantStar001 on 03:06, 07 March 25210 draw 0,b1(e),b2(e) to b3(e),b4(e)


CPC
Quote from: DistantStar001 on 07:03, 07 March 25210 DRAW B1(E),B2(E) : MOVE B3(E),B4(E),0
210 MOVE B1(E),B2(E) : DRAW B3(E),B4(E),0
CPC 6128, Whole 6128 and Only 6128, with .....
NewPAL v3 for use all 128kB RAM by CRTC as VRAM
One chip driver for 512kB(to640) extRAM 6128
TYPICAL :) TV Funai 22FL532/10 with VGA-RGB-in.

ZorrO

#7
I think we can write a better screensaver ourselves. Here is my first version, for now quite slow and without changing colors yet. DSK for the lazy. This version looks good in emulator at 800% speed. Improved will come soon. :)

10 BORDER 0:INK 0,0:INK 1,20:MODE 1:DEFINT a-z:FOR a=1 TO 3:a(a)=RND*10+5:b(a)=RND*10+5:a(a+3)=a(a):b(a+3)=b(a):NEXT:FOR a=1 TO 3:x(a)=RND*390:y(a)=RND*150:x(a+3)=x(a)+15*a(a):y(a+3)=y(a)+15*b(a):NEXT
20 WHILE INKEY$="":MOVE x(1),y(1),0:DRAW x(2),y(2):DRAW x(3),y(3):MOVE x(4),y(4),1:DRAW x(5),y(5):DRAW x(6),y(6)
30 FOR a=1TO 6:x(a)=x(a)+a(a):IF x(a)>630OR x(a)<10THEN a(a)=-a(a)
40 NEXT:FOR a=1TO 6:y(a)=y(a)+b(a):IF y(a)>390OR y(a)<10THEN b(a)=-b(a)
50 NEXT:WEND:RUN

Any key at any time randomizes new lines.
CPC+PSX 4ever

DistantStar001

Quote from: ZorrO on 02:12, 08 March 25I think we can write a better screensaver ourselves. Here is my first version, for now quite slow and without changing colors yet. DSK for the lazy. This version looks good in emulator at 800% speed. Improved will come soon. :)

10 BORDER 0:INK 0,0:INK 1,20:MODE 1:DEFINT a-z:FOR a=1 TO 3:a(a)=RND*10+5:b(a)=RND*10+5:a(a+3)=a(a):b(a+3)=b(a):NEXT:FOR a=1 TO 3:x(a)=RND*390:y(a)=RND*150:x(a+3)=x(a)+15*a(a):y(a+3)=y(a)+15*b(a):NEXT
20 WHILE INKEY$="":MOVE x(1),y(1),0:DRAW x(2),y(2):DRAW x(3),y(3):MOVE x(4),y(4),1:DRAW x(5),y(5):DRAW x(6),y(6)
30 FOR a=1TO 6:x(a)=x(a)+a(a):IF x(a)>630OR x(a)<10THEN a(a)=-a(a)
40 NEXT:FOR a=1TO 6:y(a)=y(a)+b(a):IF y(a)>390OR y(a)<10THEN b(a)=-b(a)
50 NEXT:WEND:RUN

Any key at any time randomizes new lines.

Okay... So the program I posted still had some typos in it. BUT,I gotta say, I LOVE what you did with it! I'm definately adding this to my Zoom background displays. I'm also going to try to figure out how to translate this to my other machines as well. Monochrome's fine by the way, as the Apple II always looked best in green phosphor anyways.

As for what I posted: The program's supposed to have straight lines (as seen in the above posted video), not a v shape. Also, it's not erasing after the tail. I guess this is what happens when you save in a word processor and test on real hardware. Fortunately, I've found an a Mac compatible emulator that can copy/paste text (CPCemu) which is how I discovered my (assumably) many "mistakes."

This should be the [REALLY, FULLY TESTED, and TRUELY] typo-free version:

10 MODE 1
20 DIM B1(50):DIM B2(50)
30 DIM B3(50):DIM B4(50)
50 PRINT "Line Spacing";:INPUT Z
55 LET S=Z*1.5
60 PRINT "Tail Length";:INPUT L
80 D1=0:D2=1:D3=0:D4=1
90 A1=0:A2=0
100 A3=75:A4=125
110 C=1
120 CC=0
130 P=0
140 E=2
150 MODE 1:BORDER 0:INK 0,0
170 GOSUB 260
180 MOVE A1,A2: DRAW A3,A4,C
190 P=P+1:IF P=L THEN P=0
200 B1(P)=A1:B2(P)=A2:B3(P)=A3:B4(P)=A4
210 MOVE B1(E),B2(E):DRAW B3(E),B4(E),0
220 E=E+1:IF E=L THEN E=0
230 CC=CC+1:IF CC<>5 THEN GOTO 170
240 CC=0:C=C+1:IF C=4 THEN C=1
250 GOTO 170
260 IF D1=0 THEN IF A1<=S THEN D1=1:A1=1:GOTO 300
270 IF D1=0 THEN A1=A1-S:GOTO 300
280 IF A1+S>=639 THEN D1=0:A1=638:GOTO 300
290 A1=A1+S
300 IF D2=0 THEN IF A2<=S THEN D2=1:A2=1:GOTO 340
310 IF D2=0 THEN A2=A2-S:GOTO 340
320 IF A2+S>=399 THEN D2=0:A2=398:GOTO 340
330 A2=A2+S
340 IF D3=0 THEN IF A3<=S THEN D3=1:A3=1:GOTO 380
350 IF D3=0 THEN A3=A3-S:GOTO 380
360 IF A3+S>=639 THEN D3=0:A3=638:GOTO 380
370 A3=A3+S
380 IF D4=0 THEN IF A4<=S THEN D4=1 : A4=1 : RETURN
390 IF D4=0 THEN A4=A4-S : RETURN
400 IF A4+S>=399 THEN D4=0 : A4=398 : RETURN
410 A4=A4+S
420 RETURN

ZorrO

I just think that two lines create more interesting patterns on screen than one line. :)
CPC+PSX 4ever

Powered by SMFPacks Menu Editor Mod