From e61818f194038791c41975333499b266c1d10a11 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 30 Aug 2020 19:31:20 +0200 Subject: [PATCH] tweak cx16 mandelbrots --- compiler/res/prog8lib/c64graphics.p8 | 4 +-- compiler/res/prog8lib/c64textio.p8 | 12 +++++-- compiler/res/prog8lib/cx16textio.p8 | 19 ++++++++-- examples/cx16/mandelbrot-gfx.p8 | 54 ++++++++++++++++++++++++---- examples/cx16/mandelbrot.p8 | 4 +-- examples/line-circle-txt.p8 | 6 ++-- 6 files changed, 82 insertions(+), 17 deletions(-) diff --git a/compiler/res/prog8lib/c64graphics.p8 b/compiler/res/prog8lib/c64graphics.p8 index 4c478a012..8b9497673 100644 --- a/compiler/res/prog8lib/c64graphics.p8 +++ b/compiler/res/prog8lib/c64graphics.p8 @@ -16,7 +16,7 @@ graphics { sub clear_screen(ubyte pixelcolor, ubyte bgcolor) { memset(bitmap_address, 320*200/8, 0) - txt.clear_screen(pixelcolor << 4 | bgcolor, 0) + txt.fill_screen(pixelcolor << 4 | bgcolor, 0) } sub line(uword @zp x1, ubyte @zp y1, uword @zp x2, ubyte @zp y2) { @@ -218,7 +218,7 @@ _ormask .byte 128, 64, 32, 16, 8, 4, 2, 1 ; note: this can be even faster if we also have a 256 byte x-lookup table, but hey. ; see http://codebase64.org/doku.php?id=base:various_techniques_to_calculate_adresses_fast_common_screen_formats_for_pixel_graphics ; the y lookup tables encodes this formula: bitmap_address + 320*(py>>3) + (py & 7) (y from 0..199) -; TODO can we use an assembly function for this to calc this? +; TODO can we use an assembler function for this to calc this at assembly-time? _y_lookup_hi .byte $20, $20, $20, $20, $20, $20, $20, $20, $21, $21, $21, $21, $21, $21, $21, $21 .byte $22, $22, $22, $22, $22, $22, $22, $22, $23, $23, $23, $23, $23, $23, $23, $23 diff --git a/compiler/res/prog8lib/c64textio.p8 b/compiler/res/prog8lib/c64textio.p8 index a8fb1fb31..0170c40c9 100644 --- a/compiler/res/prog8lib/c64textio.p8 +++ b/compiler/res/prog8lib/c64textio.p8 @@ -11,8 +11,16 @@ txt { -asmsub clear_screen (ubyte char @ A, ubyte charcolor @ Y) clobbers(A) { - ; ---- clear the character screen with the given fill character and character color. +asmsub clear_screen() { + %asm {{ + lda #' ' + jmp clear_screenchars + }} +} + + +asmsub fill_screen (ubyte char @ A, ubyte charcolor @ Y) clobbers(A) { + ; ---- fill the character screen with the given fill character and character color. ; (assumes screen and color matrix are at their default addresses) %asm {{ diff --git a/compiler/res/prog8lib/cx16textio.p8 b/compiler/res/prog8lib/cx16textio.p8 index a161dec8e..e20813128 100644 --- a/compiler/res/prog8lib/cx16textio.p8 +++ b/compiler/res/prog8lib/cx16textio.p8 @@ -11,11 +11,26 @@ txt { -asmsub clear_screen (ubyte char @ A, ubyte txtcolor @ Y) clobbers(A) { +sub clear_screen() { + c64.CHROUT(147) ; clear screen (spaces) +} + + +asmsub fill_screen (ubyte char @ A, ubyte txtcolor @ Y) clobbers(A) { ; ---- clear the character screen with the given fill character and character color. %asm {{ - brk ; TODO + pha + tya + and #$0f + lda txt.color_to_charcode,y + jsr c64.CHROUT + pla + cmp #' ' + bne + + lda #147 ; clear screen + jmp c64.CHROUT ++ brk ; TODO fill screen with another character than space.... }} } diff --git a/examples/cx16/mandelbrot-gfx.p8 b/examples/cx16/mandelbrot-gfx.p8 index 851758eee..eaa63a1da 100644 --- a/examples/cx16/mandelbrot-gfx.p8 +++ b/examples/cx16/mandelbrot-gfx.p8 @@ -1,22 +1,26 @@ +%import cx16textio %import cx16flt %zeropage basicsafe main { const uword width = 256 const uword height = 200 - const ubyte max_iter = 16 + const ubyte max_iter = 32 sub start() { + initialize() + mandel() + repeat { + ; do nothing + } + } - void cx16.screen_set_mode($80) - cx16.r0=0 - cx16.FB_init() - + sub mandel() { ubyte pixelx ubyte pixely for pixely in 0 to height-1 { - float yy = (pixely as float)/0.4/height - 1.0 + float yy = (pixely as float)/0.35/height - 1.35 cx16.r0 = 0 cx16.r1 = pixely @@ -40,6 +44,44 @@ main { } cx16.FB_set_pixel(max_iter-iter) } + + print_time() } } + + sub initialize() { + void cx16.screen_set_mode($80) + + txt.plot(32, 5) + txt.print("256*200") + txt.plot(32, 6) + txt.print("mandel-") + txt.plot(33, 7) + txt.print("brot") + txt.plot(32, 9) + txt.print("floats") + txt.plot(32, 10) + txt.print("32 iter") + + cx16.r0 = 0 + cx16.r1 = 0 + cx16.r2 = 0 + cx16.r3 = 0 + cx16.clock_set_date_time() + + cx16.r0=0 + cx16.FB_init() + } + + sub print_time() { + cx16.clock_get_date_time() + txt.plot(33, 12) + if lsb(cx16.r2) < 10 + c64.CHROUT('0') + txt.print_ub(lsb(cx16.r2)) + c64.CHROUT(':') + if msb(cx16.r2) < 10 + c64.CHROUT('0') + txt.print_ub(msb(cx16.r2)) + } } diff --git a/examples/cx16/mandelbrot.p8 b/examples/cx16/mandelbrot.p8 index 487b03f0f..d918936c5 100644 --- a/examples/cx16/mandelbrot.p8 +++ b/examples/cx16/mandelbrot.p8 @@ -14,10 +14,10 @@ main { ubyte pixely for pixely in 0 to height-1 { - float yy = (pixely as float)/0.4/height - 1.0 + float yy = (pixely as float)/0.40/height - 1.3 for pixelx in 0 to width-1 { - float xx = (pixelx as float)/0.3/width - 2.2 + float xx = (pixelx as float)/0.32/width - 2.2 float xsquared = 0.0 float ysquared = 0.0 diff --git a/examples/line-circle-txt.p8 b/examples/line-circle-txt.p8 index 44fc7b773..4d9acff7e 100644 --- a/examples/line-circle-txt.p8 +++ b/examples/line-circle-txt.p8 @@ -16,13 +16,13 @@ main { txt.print("enter for disc:") void c64.CHRIN() c64.CHROUT('\n') - txt.clear_screen(' ', 1) + txt.clear_screen() disc(20, 12, 12) txt.print("enter for lines:") void c64.CHRIN() c64.CHROUT('\n') - txt.clear_screen(' ', 1) + txt.clear_screen() line(1, 10, 38, 24) line(1, 20, 38, 2) @@ -32,7 +32,7 @@ main { txt.print("enter for rectangles:") void c64.CHRIN() c64.CHROUT('\n') - txt.clear_screen(' ', 1) + txt.clear_screen() rect(4, 8, 37, 23, false) rect(20, 12, 30, 20, true)