My First C64/X16 Programs!
My First C64/X16 Programs!
Just fooling around with C64 BASIC and the new X16 BASIC commands! Code is too simple to share compared to some other games and demos you guys made!
It's been a while trying to use variable names with only 2 unique characters!
"PALETTE.BAS"
"MANDELBROT.BAS" - Took forever to generate this 150px by 150px by 16 greyscale. 6502/200MHz please!
My First C64/X16 Programs!
Look at the demo directories there are some Mandelbrot already. Two 320x240@256 versions ... it is running some 20-30 minutes for a full run.
-
- Posts: 511
- Joined: Sat Apr 25, 2020 4:53 pm
My First C64/X16 Programs!
5 minutes ago, SerErris said:
Look at the demo directories there are some Mandelbrot already. Two 320x240@256 versions ... it is running some 20-30 minutes for a full run.
You used pure C64 BASIC right with all those POKE's ? I used the new X16 BASIC commands and is somewhat smaller:
20 SCREEN 128
30 MAXDWELL = 150
40 COLRS = 16
50 NROW = 150
60 NCOL = 150
70 YOFFSET = 1
80 XOFFSET = 1
90 INPUT "LOWER LEFTHAND CORNER, REAL PART"; AA
100 INPUT "LOWER LEFTHAND CORNER, IMAG. PART"; BB
110 INPUT "LENGTH OF SIDE"; SIDE
120 CLS
140 LINE 0, 0, NCOL + XOFFSET, 0, 16
150 LINE NCOL + XOFFSET, 0, NCOL + XOFFSET, NROW + YOFFSET, 16
160 LINE NCOL + XOFFSET, NROW + YOFFSET, 0, NROW + YOFFSET, 16
170 LINE 0, NROW + YOFFSET, 0, 0, 16
250 HIGHDWELL = 0
260 GAP = SIDE / NROW
270 AC = AA
280 FOR X = XOFFSET TO NROW - 1 + XOFFSET
290 AC = AC + GAP
300 BC = BB
310 FOR Y = YOFFSET TO NCOL - 1 + XOFFSET
320 BC = BC + GAP
330 AZ = 0
340 BZ = 0
350 CNT = 0
360 SZE = 0
370 IF (SZE < 4) AND (CNT < MAXDWELL) GOTO 380
375 GOTO 470
380 TEMP = AZ * AZ - BZ * BZ + AC
390 BZ = 2 * AZ * BZ + BC
400 AZ = TEMP
410 SZE = AZ * AZ + BZ * BZ
420 CNT = CNT + 1
425 GOTO 370
470 IF (CNT < MAXDWELL) AND (CNT > HIGHDWELL) THEN HIGHDWELL = CNT
480 IF CNT = MAXDWELL THEN PSET X, NROW - Y + 1, 16: GOTO 490
483 RE = CNT-INT(CNT/(COLRS-1))*(COLRS-1)
485 PSET X, NROW - Y + 1, RE + 1 + 16
490 NEXT Y
520 NEXT X
530 GET A$ : IF A$="" THEN GOTO 530
Your full screen Mandelbrot ran for 20-30 minutes running in BASIC? I was impatient and let it run overnight so I don't know how fast my code was even if a smaller 150x150.
I will try cc65 and see much faster it becomes... unless you already did that ?
My First C64/X16 Programs!
And much slower . I write the color directly to VRam using the autoincrememt feature of Vera. But this is also a very good example more BASIC stile and good to understand. The issue with C64 Basic and also this version is that good to read is heavily inefficient (read slow).
and to speed up on the initial diagram you should reduce maxdwell to 30. You will not be able to see any difference in that resolution ...
I am not sure if anyone have done a c implementation. I next aim for a assembler version. The required math make my head spin already. We need long int mul/div ... phew
- desertfish
- Posts: 1094
- Joined: Tue Aug 25, 2020 8:27 pm
- Location: Netherlands
My First C64/X16 Programs!
I am working on a version in Prog8 that uses floating point via the kernel routines (so in the end it may not be that much faster than a basic variant, but we'll see once it is finished)
My First C64/X16 Programs!
I believe that you save the parsing and some other stuff. So maybe it is faster.
- desertfish
- Posts: 1094
- Joined: Tue Aug 25, 2020 8:27 pm
- Location: Netherlands
My First C64/X16 Programs!
Btw: I can't get the fractal256.bas to work (garbled screen) and fastfract256 doesn't work either (seems to be missing part of the code at the end). I'm looking in the x16-demo git repository. So I used part of their source to create my own basic version of the mandelbrot program.
Turns out the prog8 compiled one is significantly faster (4x) even though it is using the same ROM routines as Basic does for the actual floating point calculations. It took slightly more than 11 minutes to finish the task (256 * 200 * 16 image) whereas the basic one took 45 minutes for the identical picture.
My First C64/X16 Programs!
Hi fractal256.bas works. Tried it from the repository. It looks like a garbled screen, that is even getting more garbled .. however after 10 seconds or so you seen in the first line some ping/violett movement ... that is the fractal creeping over the screen - not not fast :-).
fastfractal256.bas was unfortunately an upload missing a lot of thing, not sure how that happened. I attached the correct version here ... Hope that helps in the meantime.
Ah and of cause - these files need to get copy and past into the emulator. They are not BAS files in the meaning of a X16 save command (not coded, but pure text).
BTW: The garbled screen exists because both programmers (fract256 and me) were to lazy to wipe the screen before activating it. The wipe process is pretty slow.
Also in the two programs, you see different VRAM layouts. fract256 starts at $0000 with the bitmap and therefore overwriting the CHARRAM of Layer0. Also the CHARROM is kopied to $0F800 and is sitting in the middle of the screen, where you can see it. That is overwritten by fract256 as well. After the program finishes, you need to reset the C64 cause you cannot read anything anymore.
My approach is preserving the CHARRAM of Layer0 by starting at $4000 and copying the CHARROM to $1F000 and changing the Tilebase to preserve it. Works great.
I also believe that the CHARROM should be copied by default to $1F000 to keep it out of the way. It sits really in a spot were it hurts for 320x240 modes.
fastfract256.bas
My First C64/X16 Programs!
8 hours ago, desertfish said:
Turns out the prog8 compiled one is significantly faster (4x) even though it is using the same ROM routines as Basic does for the actual floating point calculations.
Prog8 - that's a very interesting language you developed. What's the history of the language?
I can't see how one can make it faster other than perhaps write a fixed point scaled-integer math library (faster but less precision) OR ask for some sort of coprocessor chip (maybe inside VERA itself?) with various mathematical functions including vector math to allow for some cool 3D games! Actually I saw someone create a 16-bit LOOKUP table for the fixed point scaled-integer math for various math funtions and burned into 1Mx8 EPROM pairs. How cool would it be to have INSTANT math calculations on a "simple" 8-bit machine? Many geek points there...
It's been a while and I didn't have time to do some manual readings BUT how many bits wide are C64/X16's math functions? I have been in 32-bit/64-bit land far too long...