From 364ef3e55c61607591c665fe77e42ca5a926e2a0 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 30 Aug 2020 23:50:31 +0200 Subject: [PATCH] tweak cx16 mandelbrots --- compiler/res/prog8lib/cx16textio.p8 | 7 +++---- examples/cx16/mandelbrot-gfx.bas | 31 +++++++++++++++++++++++++++++ examples/cx16/mandelbrot-gfx.p8 | 15 ++++++++++---- 3 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 examples/cx16/mandelbrot-gfx.bas diff --git a/compiler/res/prog8lib/cx16textio.p8 b/compiler/res/prog8lib/cx16textio.p8 index e20813128..1279658c8 100644 --- a/compiler/res/prog8lib/cx16textio.p8 +++ b/compiler/res/prog8lib/cx16textio.p8 @@ -30,7 +30,8 @@ asmsub fill_screen (ubyte char @ A, ubyte txtcolor @ Y) clobbers(A) { bne + lda #147 ; clear screen jmp c64.CHROUT -+ brk ; TODO fill screen with another character than space.... ++ ; TODO fill the screen with a different fillchar (not space) - not yet supported + rts }} } @@ -118,9 +119,7 @@ asmsub print_b (byte value @ A) clobbers(A,Y) { jsr c64.CHROUT + pla jsr conv.byte2decimal - jsr print_ub._print_byte_digits - plx - rts + jmp print_ub._print_byte_digits }} } diff --git a/examples/cx16/mandelbrot-gfx.bas b/examples/cx16/mandelbrot-gfx.bas new file mode 100644 index 000000000..d896e6970 --- /dev/null +++ b/examples/cx16/mandelbrot-gfx.bas @@ -0,0 +1,31 @@ +100 REM MANDELBROT GFX - BASIC VERSION FOR COMMANDERX16 +110 REM MANDELBROT COORDINATES +120 XL=-2.000:XU=0.500 +130 YL=-1.100:YU=1.100 +140 MI%=16 :REM MAXIMUM ITERATIONS +150 WI%=256:HI%=200 :REM SCREEN DIMENSIONS +160 DX=(XU-XL)/WI% +170 DY=(YU-YL)/HI% +200 SCREEN $80:TI$="000000" +500 REM MAIN LOOP +520 X0=0:Y0=0:GOSUB2000 +530 FOR YY=0 TO HI%-1 +540 Y0=YL+DY*YY +610 FOR XX=0 TO WI%-1 +620 X0=XL+DX*XX +700 REM CALCULATE MANDELBROT +710 X=0:Y=0:IT%=0 +720 X2=0:Y2=0 +730 XY=X*Y +740 X=X2-Y2+X0 +750 Y=2*XY+Y0 +760 IT%=IT%+1 +770 X2=X*X:Y2=Y*Y +780 IF (X2+Y2 <= 4) AND (IT% < MI%) THEN GOTO 730 +790 PSET XX,YY,MI%-IT% +800 NEXT XX +810 GOSUB2000 +820 NEXT YY +1000 GOTO 1000 +2000 REM OUTPUT TIME SPENT +2010 PRINT CHR$(19)SPC(33)TI$:RETURN diff --git a/examples/cx16/mandelbrot-gfx.p8 b/examples/cx16/mandelbrot-gfx.p8 index eaa63a1da..2c8ff99b4 100644 --- a/examples/cx16/mandelbrot-gfx.p8 +++ b/examples/cx16/mandelbrot-gfx.p8 @@ -5,7 +5,7 @@ main { const uword width = 256 const uword height = 200 - const ubyte max_iter = 32 + const ubyte max_iter = 16 ; 32 looks pretty nice sub start() { initialize() @@ -16,18 +16,24 @@ main { } sub mandel() { + const float XL=-2.000 + const float XU=0.500 + const float YL=-1.100 + const float YU=1.100 + float dx = (XU-XL)/width + float dy = (YU-YL)/height ubyte pixelx ubyte pixely for pixely in 0 to height-1 { - float yy = (pixely as float)/0.35/height - 1.35 + float yy = YL+dy*pixely cx16.r0 = 0 cx16.r1 = pixely cx16.FB_cursor_position() for pixelx in 0 to width-1 { - float xx = (pixelx as float)/0.3/width - 2.2 + float xx = XL+dx*pixelx float xsquared = 0.0 float ysquared = 0.0 @@ -61,7 +67,8 @@ main { txt.plot(32, 9) txt.print("floats") txt.plot(32, 10) - txt.print("32 iter") + txt.print_b(max_iter) + txt.print(" iter") cx16.r0 = 0 cx16.r1 = 0