]> git.sur5r.net Git - cc65/blobdiff - samples/mandelbrot.c
Dropped VER_PATCH (and VER_RC) and added build date.
[cc65] / samples / mandelbrot.c
index 507eb99dcded9df8d14315af2ddd83b7a52eaed8..0ba4ebd2cc1cee76bd9e31ab9c9ca7dcef07ea7e 100644 (file)
 
 
 /* Graphics definitions */
-#if defined(__APPLE2__) || defined(__APPLE2ENH__)
-#  define GRAPHMODE    TGI_MODE_280_192_6
-#else
-#  define GRAPHMODE    TGI_MODE_320_200_2
-#endif
-#define SCREEN_X        (tgi_getmaxx()+1)
-#define SCREEN_Y        (tgi_getmaxy()+1)
-#define MAXCOL          (tgi_getmaxcolor()+1)
+#define SCREEN_X        (tgi_getxres())
+#define SCREEN_Y        (tgi_getyres())
+#define MAXCOL          (tgi_getcolorcount())
 
 #define maxiterations   32
 #define fpshift         (10)
 #define divfp(_a,_b)    ((((signed long)_a)<<fpshift)/(_b))
 
 /* Workaround missing clock stuff */
-#if defined(__APPLE2__) || defined(__APPLE2ENH__)
-#  define clock()      0
-#  define CLK_TCK      1
+#ifdef __APPLE2__
+#  define clock()       0
+#  define CLK_TCK       1
+#endif
+
+/* Use dynamically loaded driver by default */
+#ifndef DYN_DRV
+#  define DYN_DRV       1
 #endif
 
 /* Use static local variables for speed */
-#pragma staticlocals (1);
+#pragma static-locals (1);
 
 
 
 void mandelbrot (signed short x1, signed short y1, signed short x2,
-                signed short y2)
+                 signed short y2)
 {
     register unsigned char count;
     register signed short r, r1, i;
@@ -57,32 +57,32 @@ void mandelbrot (signed short x1, signed short y1, signed short x2,
 
     yy = y1;
     for (y = 0; y < (SCREEN_Y); y++) {
-       yy += ys;
-       xx = x1;
-       for (x = 0; x < (SCREEN_X); x++) {
-           xx += xs;
-           /* do iterations */
-           r = 0;
-           i = 0;
-           for (count = 0; (count < maxiterations) &&
-                (fpabs (r) < tofp (2)) && (fpabs (i) < tofp (2));
-                ++count) {
-               r1 = (mulfp (r, r) - mulfp (i, i)) + xx;
-               /* i = (mulfp(mulfp(r,i),tofp(2)))+yy; */
-               i = (((signed long) r * i) >> (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);
-       }
+        yy += ys;
+        xx = x1;
+        for (x = 0; x < (SCREEN_X); x++) {
+            xx += xs;
+            /* do iterations */
+            r = 0;
+            i = 0;
+            for (count = 0; (count < maxiterations) &&
+                 (fpabs (r) < tofp (2)) && (fpabs (i) < tofp (2));
+                 ++count) {
+                r1 = (mulfp (r, r) - mulfp (i, i)) + xx;
+                /* i = (mulfp(mulfp(r,i),tofp(2)))+yy; */
+                i = (((signed long) r * i) >> (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);
+        }
     }
 }
 
@@ -95,14 +95,19 @@ int main (void)
 
     clrscr ();
 
-    /* Load the graphics driver */                       
+#if DYN_DRV
+    /* Load the graphics driver */
     cprintf ("initializing... mompls\r\n");
-    tgi_load (GRAPHMODE);
+    tgi_load_driver (tgi_stddrv);
+#else
+    /* Install the graphics driver */
+    tgi_install (tgi_static_stddrv);
+#endif
     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 ("Error #%d initializing graphics.\r\n%s\r\n",
+                 err, tgi_geterrormsg (err));
+        exit (EXIT_FAILURE);
     };
     cprintf ("ok.\n\r");
 
@@ -137,5 +142,4 @@ int main (void)
 
     /* Done */
     return EXIT_SUCCESS;
-
 }