From 3403d6730fb120fe0adb52ed29582954f4e5fd93 Mon Sep 17 00:00:00 2001 From: cuz Date: Fri, 8 Oct 2004 20:10:58 +0000 Subject: [PATCH] Added the new mandelbrot sample git-svn-id: svn://svn.cc65.org/cc65/trunk@3228 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- samples/.cvsignore | 1 + samples/Makefile | 5 +- samples/README | 8 +++ samples/mandelbrot.c | 131 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 samples/mandelbrot.c diff --git a/samples/.cvsignore b/samples/.cvsignore index 3746fbe0b..cbeb999b9 100644 --- a/samples/.cvsignore +++ b/samples/.cvsignore @@ -2,6 +2,7 @@ ascii fire gunzip65 hello +mandelbrot mousedemo nachtm plasma diff --git a/samples/Makefile b/samples/Makefile index f8fc0ffe7..7ab37976c 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -49,11 +49,14 @@ gunzip65: $(CRT0) gunzip65.o $(CLIB) hello: $(CRT0) hello.o $(CLIB) @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^ +mandelbrot: $(CRT0) mandelbrot.o $(CLIB) + @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^ + mousedemo: $(CRT0) mousedemo.o $(CLIB) @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^ nachtm: $(CRT0) nachtm.o $(CLIB) - @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^ + @$(LD) -t $(SYS) -m $(basename $@).map -Ln $(basename $@).lbl -o $@ $^ plasma: $(CRT0) plasma.o $(CLIB) @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^ diff --git a/samples/README b/samples/README index caa4645a7..3a1c150b3 100644 --- a/samples/README +++ b/samples/README @@ -46,6 +46,14 @@ Description: A nice "Hello world" type program that uses the conio Platforms: Runs on all platforms that support conio, which means: Apple ][, Atari, C16, C64, C128, CBM510, CBM610, PET, Plus/4 +----------------------------------------------------------------------------- +Name: mandelbrot +Description: A mandelbrot demo using integer arithmetic. The demo was + written by groepaz/hitmen and converted to cc65 using TGI + graphics by Stephan Haubenthal. +Platforms: All systems with TGI support. You may have to change the + driver/resolution definition in the source. + ----------------------------------------------------------------------------- Name: mousedemo Description: Shows how to use the mouse. diff --git a/samples/mandelbrot.c b/samples/mandelbrot.c new file mode 100644 index 000000000..056f37223 --- /dev/null +++ b/samples/mandelbrot.c @@ -0,0 +1,131 @@ +/***************************************************************************** + * mandelbrot sample program for cc65. * + * * + * (w)2002 by groepaz/hitmen, TGI support by Stefan Haubenthal * + *****************************************************************************/ + + + +#include +#include +#include +#include + + + +/* Graphics definitions */ +#define GRAPHMODE TGI_MODE_320_200_2 +#define SCREEN_X (tgi_getmaxx()+1) +#define SCREEN_Y (tgi_getmaxy()+1) +#define MAXCOL (tgi_getmaxcolor()+1) + +#define maxiterations 32 +#define fpshift (10) +#define tofp(_x) ((_x)<>fpshift) +#define fpabs(_x) (abs(_x)) + +#define mulfp(_a,_b) ((((signed long)_a)*(_b))>>fpshift) +#define divfp(_a,_b) ((((signed long)_a)<> (fpshift - 1)) + yy; + r = r1; + } + if (count == maxiterations) { + tgi_setcolor (0); + } else { + if (MAXCOL == 2) + tgi_setcolor (1); + else + tgi_setcolor (count % MAXCOL); + } + /* set pixel */ + tgi_setpixel (x, y); + } + } +} + +int main (void) +{ + clock_t t; + unsigned long sec; + unsigned sec10; + unsigned char err; + + clrscr (); + + /* Load the graphics driver */ + cprintf ("initializing... mompls\r\n"); + tgi_load (GRAPHMODE); + err = tgi_geterror (); + if (err != TGI_ERR_OK) { + cprintf ("Error #%d initializing graphics.\r\n%s\r\n", + err, tgi_geterrormsg (err)); + exit (EXIT_FAILURE); + }; + cprintf ("ok.\n\r"); + + /* Initialize graphics */ + tgi_init (); + tgi_clear (); + + t = clock (); + + /* calc mandelbrot set */ + mandelbrot (tofp (-2), tofp (-2), tofp (2), tofp (2)); + + t = clock () - t; + + /* Fetch the character from the keyboard buffer and discard it */ + (void) cgetc (); + + /* shut down gfx mode and return to textmode */ + tgi_done (); + + /* Calculate stats */ + sec = (t * 10) / CLK_TCK; + sec10 = sec % 10; + sec /= 10; + + /* Output stats */ + cprintf ("time : %lu.%us\n\r", sec, sec10); + + /* Wait for a key, then end */ + cputs ("Press any key when done...\n\r"); + (void) cgetc (); + + /* Done */ + return EXIT_SUCCESS; + +} -- 2.39.5