8 #include <tgi/tgi-kernel.h>
12 #define COLOR_BACK TGI_COLOR_BLACK
13 #define COLOR_FORE TGI_COLOR_WHITE
16 /*****************************************************************************/
18 /*****************************************************************************/
28 /*****************************************************************************/
30 /*****************************************************************************/
34 static void CheckError (const char* S)
36 unsigned char Error = tgi_geterror ();
37 if (Error != TGI_ERR_OK) {
38 printf ("%s: %d\n", S, Error);
45 static void DoWarning (void)
46 /* Warn the user that the TGI driver is needed for this program */
48 printf ("Warning: This program needs the TGI\n"
49 "driver on disk! Press 'y' if you have\n"
50 "it - any other key exits.\n");
51 if (tolower (cgetc ()) != 'y') {
54 printf ("Ok. Please wait patiently...\n");
59 static void DoCircles (void)
61 static const unsigned char Palette[2] = { TGI_COLOR_WHITE, TGI_COLOR_ORANGE };
63 unsigned char Color = COLOR_FORE;
64 unsigned X = MaxX / 2;
65 unsigned Y = MaxY / 2;
67 tgi_setpalette (Palette);
69 tgi_setcolor (COLOR_FORE);
70 tgi_line (0, 0, MaxX, MaxY);
71 tgi_line (0, MaxY, MaxX, 0);
73 for (I = 10; I < 240; I += 10) {
74 tgi_ellipse (X, Y, I, tgi_imulround (I, tgi_aspectratio));
76 Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
85 static void DoCheckerboard (void)
87 static const unsigned char Palette[2] = { TGI_COLOR_WHITE, TGI_COLOR_BLACK };
91 tgi_setpalette (Palette);
94 for (Y = 0; Y <= MaxY; Y += 10) {
95 for (X = 0; X <= MaxX; X += 10) {
97 tgi_bar (X, Y, X+9, Y+9);
98 Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
105 Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
107 Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
113 static void DoDiagram (void)
115 static const unsigned char Palette[2] = { TGI_COLOR_WHITE, TGI_COLOR_BLACK };
116 int XOrigin, YOrigin;
121 tgi_setpalette (Palette);
122 tgi_setcolor (COLOR_FORE);
124 /* Determine zero and aplitude */
127 Amp = (MaxY - 19) / 2;
130 tgi_line (XOrigin, 10, XOrigin, MaxY-10);
131 tgi_line (XOrigin-2, 12, XOrigin, 10);
132 tgi_lineto (XOrigin+2, 12);
135 tgi_line (XOrigin, YOrigin, MaxX-10, YOrigin);
136 tgi_line (MaxX-12, YOrigin-2, MaxX-10, YOrigin);
137 tgi_lineto (MaxX-12, YOrigin+2);
140 tgi_gotoxy (XOrigin, YOrigin);
141 for (I = 0; I <= 360; I += 5) {
143 /* Calculate the next points */
144 X = (int) (((long) (MaxX - 19) * I) / 360);
145 Y = (int) (((long) Amp * -cc65_sin (I)) / 256);
148 tgi_lineto (XOrigin + X, YOrigin + Y);
157 static void DoLines (void)
159 static const unsigned char Palette[2] = { TGI_COLOR_WHITE, TGI_COLOR_BLACK };
162 tgi_setpalette (Palette);
163 tgi_setcolor (COLOR_FORE);
165 for (X = 0; X <= MaxY; X += 10) {
166 tgi_line (0, 0, MaxY, X);
167 tgi_line (0, 0, X, MaxY);
168 tgi_line (MaxY, MaxY, 0, MaxY-X);
169 tgi_line (MaxY, MaxY, MaxY-X, 0);
180 unsigned char Border;
182 /* Warn the user that the tgi driver is needed */
185 /* Load and initialize the driver */
186 tgi_load_driver (tgi_stddrv);
187 CheckError ("tgi_load_driver");
189 CheckError ("tgi_init");
192 /* Get stuff from the driver */
193 MaxX = tgi_getmaxx ();
194 MaxY = tgi_getmaxy ();
196 /* Set the palette, set the border color */
197 Border = bordercolor (COLOR_BLACK);
199 /* Do graphics stuff */
205 /* Unload the driver */
208 /* Reset the border */
209 (void) bordercolor (Border);