]> git.sur5r.net Git - cc65/blobdiff - samples/tgidemo.c
Removed a "cc65_" prefix.
[cc65] / samples / tgidemo.c
index ccefdb5c14259ba44107833a155040ea172fc5eb..1d76fee2e3974d6815e6f2fb60542127d6e7bef2 100644 (file)
@@ -5,16 +5,19 @@
 #include <ctype.h>
 #include <modload.h>
 #include <tgi.h>
-#include <tgi/tgi-kernel.h>
 
 
 
-#define COLOR_BACK     TGI_COLOR_BLACK
-#define COLOR_FORE     TGI_COLOR_WHITE
+#ifndef DYN_DRV
+#  define DYN_DRV       1
+#endif
+
+#define COLOR_BACK      TGI_COLOR_BLACK
+#define COLOR_FORE      TGI_COLOR_WHITE
 
 
 /*****************************************************************************/
-/*                                          Data                                    */
+/*                                   Data                                    */
 /*****************************************************************************/
 
 
@@ -27,7 +30,7 @@ static unsigned AspectRatio;
 
 
 /*****************************************************************************/
-/*                                          Code                                    */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
@@ -37,14 +40,18 @@ static void CheckError (const char* S)
     unsigned char Error = tgi_geterror ();
     if (Error != TGI_ERR_OK) {
         printf ("%s: %d\n", S, Error);
+        if (doesclrscrafterexit ()) {
+            cgetc ();
+        }
         exit (EXIT_FAILURE);
     }
 }
 
 
 
+#if DYN_DRV
 static void DoWarning (void)
-/* Warn the user that the TGI driver is needed for this program */
+/* Warn the user that the dynamic TGI driver is needed for this program */
 {
     printf ("Warning: This program needs the TGI\n"
             "driver on disk! Press 'y' if you have\n"
@@ -52,8 +59,9 @@ static void DoWarning (void)
     if (tolower (cgetc ()) != 'y') {
         exit (EXIT_SUCCESS);
     }
-    printf ("Ok. Please wait patiently...\n");
+    printf ("OK. Please wait patiently...\n");
 }
+#endif
 
 
 
@@ -74,7 +82,7 @@ static void DoCircles (void)
         for (I = 10; I < 240; I += 10) {
             tgi_ellipse (X, Y, I, tgi_imulround (I, AspectRatio));
         }
-       Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
+        Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
     }
 
     cgetc ();
@@ -96,16 +104,16 @@ static void DoCheckerboard (void)
             for (X = 0; X <= MaxX; X += 10) {
                 tgi_setcolor (Color);
                 tgi_bar (X, Y, X+9, Y+9);
-               Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
+                Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
                 if (kbhit ()) {
                     cgetc ();
                     tgi_clear ();
                     return;
                 }
             }
-           Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
+            Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
         }
-       Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
+        Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
     }
 }
 
@@ -143,7 +151,7 @@ static void DoDiagram (void)
 
         /* Calculate the next points */
         X = (int) (((long) (MaxX - 19) * I) / 360);
-        Y = (int) (((long) Amp * -cc65_sin (I)) / 256);
+        Y = (int) (((long) Amp * -sin (I)) / 256);
 
         /* Draw the line */
         tgi_lineto (XOrigin + X, YOrigin + Y);
@@ -163,11 +171,11 @@ static void DoLines (void)
     tgi_setpalette (Palette);
     tgi_setcolor (COLOR_FORE);
 
-    for        (X = 0; X <= MaxY; X += 10) {
-       tgi_line (0, 0, MaxY, X);
-       tgi_line (0, 0, X, MaxY);
-       tgi_line (MaxY, MaxY, 0, MaxY-X);
-       tgi_line (MaxY, MaxY, MaxY-X, 0);
+    for (X = 0; X <= MaxY; X += 10) {
+        tgi_line (0, 0, MaxY, X);
+        tgi_line (0, 0, X, MaxY);
+        tgi_line (MaxY, MaxY, 0, MaxY-X);
+        tgi_line (MaxY, MaxY, MaxY-X, 0);
     }
 
     cgetc ();
@@ -180,12 +188,19 @@ int main (void)
 {
     unsigned char Border;
 
+#if DYN_DRV
     /* Warn the user that the tgi driver is needed */
     DoWarning ();
 
     /* Load and initialize the driver */
     tgi_load_driver (tgi_stddrv);
     CheckError ("tgi_load_driver");
+#else
+    /* Install the driver */
+    tgi_install (tgi_static_stddrv);
+    CheckError ("tgi_install");
+#endif
+
     tgi_init ();
     CheckError ("tgi_init");
     tgi_clear ();
@@ -204,8 +219,13 @@ int main (void)
     DoDiagram ();
     DoLines ();
 
+#if DYN_DRV
     /* Unload the driver */
     tgi_unload ();
+#else
+    /* Uninstall the driver */
+    tgi_uninstall ();
+#endif
 
     /* Reset the border */
     (void) bordercolor (Border);