]> git.sur5r.net Git - cc65/blobdiff - samples/mandelbrot.c
Fixed _textcolor definition.
[cc65] / samples / mandelbrot.c
index 0ba4ebd2cc1cee76bd9e31ab9c9ca7dcef07ea7e..d7291c5b5701f78fb0d4f18be03571991aa5d159 100644 (file)
@@ -1,8 +1,8 @@
-/*****************************************************************************
- * mandelbrot sample program for cc65.                                       *
- *                                                                           *
- * (w)2002 by groepaz/hitmen, TGI support by Stefan Haubenthal               *
- *****************************************************************************/
+/*****************************************************************************\
+** mandelbrot sample program for cc65.                                       **
+**                                                                           **
+** (w) 2002 by groepaz/hitmen, TGI support by Stefan Haubenthal              **
+\*****************************************************************************/
 
 
 
@@ -10,6 +10,7 @@
 #include <time.h>
 #include <conio.h>
 #include <tgi.h>
+#include <cc65.h>
 
 
 
@@ -51,7 +52,7 @@ void mandelbrot (signed short x1, signed short y1, signed short x2,
     register signed short xs, ys, xx, yy;
     register signed short x, y;
 
-    /* calc stepwidth */
+    /* Calc stepwidth */
     xs = ((x2 - x1) / (SCREEN_X));
     ys = ((y2 - y1) / (SCREEN_Y));
 
@@ -61,7 +62,7 @@ void mandelbrot (signed short x1, signed short y1, signed short x2,
         xx = x1;
         for (x = 0; x < (SCREEN_X); x++) {
             xx += xs;
-            /* do iterations */
+            /* Do iterations */
             r = 0;
             i = 0;
             for (count = 0; (count < maxiterations) &&
@@ -75,12 +76,13 @@ void mandelbrot (signed short x1, signed short y1, signed short x2,
             if (count == maxiterations) {
                 tgi_setcolor (0);
             } else {
-                if (MAXCOL == 2)
+                if (MAXCOL == 2) {
                     tgi_setcolor (1);
-                else
+                } else {
                     tgi_setcolor (count % MAXCOL);
+                }
             }
-            /* set pixel */
+            /* Set pixel */
             tgi_setpixel (x, y);
         }
     }
@@ -107,6 +109,9 @@ int main (void)
     if (err  != TGI_ERR_OK) {
         cprintf ("Error #%d initializing graphics.\r\n%s\r\n",
                  err, tgi_geterrormsg (err));
+        if (doesclrscrafterexit ()) {
+            cgetc ();
+        }
         exit (EXIT_FAILURE);
     };
     cprintf ("ok.\n\r");
@@ -117,15 +122,15 @@ int main (void)
 
     t = clock ();
 
-    /* calc mandelbrot set */
+    /* 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 ();
+    cgetc ();
 
-    /* shut down gfx mode and return to textmode */
+    /* Shut down gfx mode and return to textmode */
     tgi_done ();
 
     /* Calculate stats */
@@ -136,9 +141,11 @@ int main (void)
     /* 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 ();
+    if (doesclrscrafterexit ()) {
+        /* Wait for a key, then end */
+        cputs ("Press any key when done...\n\r");
+        cgetc ();
+    }
 
     /* Done */
     return EXIT_SUCCESS;