]> git.sur5r.net Git - cc65/commitdiff
Added tgidemo
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 3 Oct 2002 17:36:18 +0000 (17:36 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 3 Oct 2002 17:36:18 +0000 (17:36 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1433 b7a2c559-68d2-44c3-8de9-860c34a00d81

samples/.cvsignore
samples/Makefile
samples/README
samples/tgidemo.c [new file with mode: 0644]

index 37eecc22a8f4e1e2b2e5155cfbc02762cb6aa66c..82c14e1ff71eab1dde022494240e401de5c1ca2d 100644 (file)
@@ -3,7 +3,9 @@ mousedemo
 nachtm
 plasma
 sieve
+tgidemo
 *.map
 *.d64
 *.s
 *.lbl
+*.tgi       
index de4814dc2ade6912a7f2aa52ffa0e63d400fea60..40f0fa2e045c0e6b4317c4dddf9202611f60a453 100644 (file)
@@ -32,26 +32,29 @@ C1541       = c1541
 # --------------------------------------------------------------------------
 # Rules how to make each one of the binaries
 
-EXELIST=hello mousedemo nachtm plasma sieve
+EXELIST=hello mousedemo nachtm plasma sieve tgidemo
 
 .PHONY:        all
 all:           $(EXELIST)
 
-hello:         $(CRT0) hello.o $(CLIB)
+hello:                 $(CRT0) hello.o $(CLIB)
        @$(LD) -t $(SYS) -m hello.map -Ln hello.lbl -o $@ $^
 
 mousedemo:             $(CRT0) mousedemo.o $(CLIB)
        @$(LD) -t $(SYS) -m mousedemo.map -Ln mousedemo.lbl -o $@ $^
 
-nachtm:        $(CRT0) nachtm.o $(CLIB)
-       @$(LD) -t $(SYS) -m nachtm.map -Ln nachtm.lbl -o $@ $^
+nachtm:                $(CRT0) nachtm.o $(CLIB)
+       @$(LD) -t $(SYS) -vm -m nachtm.map -Ln nachtm.lbl -o $@ $^
 
-plasma:        $(CRT0) plasma.o $(CLIB)
-       @$(LD) -t $(SYS) -m nachtm.map -Ln nachtm.lbl -o $@ $^
+plasma:                $(CRT0) plasma.o $(CLIB)
+       @$(LD) -t $(SYS) -m plasma.map -Ln nachtm.lbl -o $@ $^
 
-sieve:         $(CRT0) sieve.o $(CLIB)
+sieve:                 $(CRT0) sieve.o $(CLIB)
        @$(LD) -t $(SYS) -m sieve.map -Ln sieve.lbl -o $@ $^
 
+tgidemo:       $(CRT0) tgidemo.o $(CLIB)
+       @$(LD) -t $(SYS) -m tgidemo.map -Ln tgidemo.lbl -o $@ $^
+
 
 # --------------------------------------------------------------------------
 # Rule to make a disk with all samples. Needs the c1541 program that comes
index cb7002dc062f16ff5574da152e09a7fcd77d53ef..1611d4aa91567ad96768a0ea23c84157b7505d18 100644 (file)
@@ -51,5 +51,10 @@ Description: Implements the "Sieve of Eratosthenes" as a way to find all
                a benchmark program.
 Platforms:     All systems with conio and clock support:
                Atari, C64, C128, CBM510, CBM610, PET, Plus/4
-
+-----------------------------------------------------------------------------
+Name:           tgidemo
+Description:   Shows some of the graphics capabilities of the "tiny graphics
+               interface".
+Platforms:     Runs on all platforms that have TGI support:
+               C64
 
diff --git a/samples/tgidemo.c b/samples/tgidemo.c
new file mode 100644 (file)
index 0000000..e0e83f9
--- /dev/null
@@ -0,0 +1,197 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <conio.h>
+#include <modload.h>
+#include <tgi.h>
+
+
+
+
+
+/*****************************************************************************/
+/*                                          Data                                    */
+/*****************************************************************************/
+
+
+
+static const unsigned char SinusTable[] = {
+    0x64,0x63,0x61,0x5F,0x5D,0x5B,0x59,0x57,0x55,0x54,
+    0x52,0x50,0x4E,0x4C,0x4A,0x49,0x47,0x45,0x43,0x42,
+    0x40,0x3E,0x3C,0x3B,0x39,0x38,0x36,0x34,0x33,0x31,
+    0x30,0x2E,0x2D,0x2B,0x2A,0x28,0x27,0x26,0x24,0x23,
+    0x22,0x20,0x1F,0x1E,0x1D,0x1C,0x1B,0x1A,0x19,0x18,
+    0x17,0x16,0x15,0x14,0x13,0x12,0x12,0x11,0x10,0x10,
+    0x0F,0x0E,0x0E,0x0D,0x0D,0x0C,0x0C,0x0C,0x0B,0x0B,
+    0x0B,0x0B,0x0B,0x0B,0x0B,0x0A,0x0B,0x0B,0x0B,0x0B,
+    0x0B,0x0B,0x0B,0x0C,0x0C,0x0C,0x0D,0x0D,0x0E,0x0E,
+    0x0F,0x10,0x10,0x11,0x12,0x12,0x13,0x14,0x15,0x16,
+    0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,
+    0x22,0x23,0x24,0x26,0x27,0x28,0x2A,0x2B,0x2D,0x2E,
+    0x30,0x31,0x33,0x34,0x36,0x38,0x39,0x3B,0x3C,0x3E,
+    0x40,0x42,0x43,0x45,0x47,0x49,0x4A,0x4C,0x4E,0x50,
+    0x52,0x54,0x55,0x57,0x59,0x5B,0x5D,0x5F,0x61,0x63,
+    0x64,0x65,0x67,0x69,0x6B,0x6D,0x6F,0x71,0x73,0x74,
+    0x76,0x78,0x7A,0x7C,0x7E,0x7F,0x81,0x83,0x85,0x86,
+    0x88,0x8A,0x8C,0x8D,0x8F,0x91,0x92,0x94,0x95,0x97,
+    0x98,0x9A,0x9B,0x9D,0x9E,0xA0,0xA1,0xA2,0xA4,0xA5,
+    0xA6,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,
+    0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB6,0xB7,0xB8,0xB8,
+    0xB9,0xBA,0xBA,0xBB,0xBB,0xBC,0xBC,0xBC,0xBD,0xBD,
+    0xBD,0xBD,0xBD,0xBD,0xBD,0xBE,0xBD,0xBD,0xBD,0xBD,
+    0xBD,0xBD,0xBD,0xBC,0xBC,0xBC,0xBB,0xBB,0xBA,0xBA,
+    0xB9,0xB8,0xB8,0xB7,0xB6,0xB6,0xB5,0xB4,0xB3,0xB2,
+    0xB1,0xB0,0xAF,0xAE,0xAD,0xAC,0xAB,0xAA,0xA9,0xA8,
+    0xA6,0xA5,0xA4,0xA2,0xA1,0xA0,0x9E,0x9D,0x9B,0x9A,
+    0x98,0x97,0x95,0x94,0x92,0x91,0x8F,0x8D,0x8C,0x8A,
+    0x88,0x86,0x85,0x83,0x81,0x7F,0x7E,0x7C,0x7A,0x78,
+    0x76,0x74,0x73,0x71,0x6F,0x6D,0x6B,0x69,0x67,0x65
+};
+
+
+
+/* Driver stuff */
+static unsigned XRes;
+static unsigned YRes;
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+static void CheckError (const char* S)
+{
+    unsigned char Error = tgi_geterror ();
+    if (Error != TGI_ERR_OK) {
+        printf ("%s: %d\n", S, Error);
+        exit (EXIT_FAILURE);
+    }
+}
+
+
+void DoWarning (void)
+/* Warn the user that the TGI driver is needed for this program */
+{
+    printf ("Warning: This program needs the TGI\n"
+            "driver on disk! Press 'y' if you have\n"
+            "it - any other key exits.\n");
+    if (cgetc () != 'y') {
+        exit (EXIT_SUCCESS);
+    }
+    printf ("Ok. Please wait patiently...\n");
+}
+
+
+
+static void DoCircles (void)
+{
+    static const unsigned char Palette[2] = { COLOR_WHITE, COLOR_LIGHTRED };
+    unsigned char I;
+    unsigned char Color = 1;
+
+    tgi_setpalette (Palette);
+    while (!kbhit ()) {
+        tgi_setcolor (1);
+        tgi_line (0, 0, 319, 199);
+        tgi_line (0, 199, 319, 0);
+        tgi_setcolor (Color);
+        for (I = 10; I < 240; I += 10) {
+            tgi_circle (160, 100, I);
+        }
+        Color ^= 0x01;
+    }
+
+    cgetc ();
+    tgi_clear ();
+}
+
+
+
+static void DoCheckerboard (void)
+{
+    static const unsigned char Palette[2] = { COLOR_WHITE, COLOR_BLACK };
+    unsigned X, Y;
+    unsigned char Color;
+
+    tgi_setpalette (Palette);
+    Color = 0;
+    while (1) {
+        for (Y = 0; Y < YRes; Y += 10) {
+            for (X = 0; X < XRes; X += 10) {
+                tgi_setcolor (Color);
+                tgi_bar (X, Y, X+9, Y+9);
+                Color ^= 0x01;
+                if (kbhit ()) {
+                    cgetc ();
+                    tgi_clear ();
+                    return;
+                }
+            }
+            Color ^= 0x01;
+        }
+        Color ^= 0x01;
+    }
+}
+
+
+
+static void DoDiagram (void)
+{
+    static const unsigned char Palette[2] = { COLOR_WHITE, COLOR_BLACK };
+    unsigned X;
+
+    tgi_setpalette (Palette);
+    tgi_setcolor (1);  
+    tgi_line (10, 10, 10, 190);
+    tgi_lineto (310, 190);
+    tgi_line (8, 12, 10, 10);
+    tgi_lineto (12, 12);
+    tgi_line (308, 188, 310, 190);
+    tgi_lineto (308, 192);
+    for (X = 0; X < sizeof (SinusTable); ++X) {
+        tgi_setpixel (X+10, SinusTable[X]);
+    }
+
+    cgetc ();
+    tgi_clear ();
+}
+
+
+
+int main (void)
+{
+    unsigned char Border;
+
+    /* Warn the user that the tgi driver is needed */
+    DoWarning ();
+
+    /* Load and initialize the driver */
+    tgi_load (TGI_MODE_320_200_2);
+    CheckError ("tgi_load");
+    tgi_init (TGI_MODE_320_200_2);
+    CheckError ("tgi_init");
+
+    /* Get stuff from the driver */
+    XRes = tgi_getxres ();
+    YRes = tgi_getyres ();
+
+    /* Set the palette, set the border color */
+    Border = bordercolor (COLOR_BLACK);
+
+    /* Do graphics stuff */
+    DoCircles ();
+    DoCheckerboard ();
+    DoDiagram ();
+
+    /* Unload the driver */
+    tgi_unload ();
+
+    /* Reset the border */
+    bordercolor (Border);
+
+    /* Done */
+    printf ("Done\n");
+    return EXIT_SUCCESS;
+}