8 #include <tgi/tgi-kernel.h>
12 #define COLOR_BACK TGI_COLOR_BLACK
13 #define COLOR_FORE TGI_COLOR_WHITE
16 /*****************************************************************************/
18 /*****************************************************************************/
25 static unsigned AspectRatio;
29 /*****************************************************************************/
31 /*****************************************************************************/
35 static void CheckError (const char* S)
37 unsigned char Error = tgi_geterror ();
38 if (Error != TGI_ERR_OK) {
39 printf ("%s: %d\n", S, Error);
46 static void DoWarning (void)
47 /* Warn the user that the TGI driver is needed for this program */
49 printf ("Warning: This program needs the TGI\n"
50 "driver on disk! Press 'y' if you have\n"
51 "it - any other key exits.\n");
52 if (tolower (cgetc ()) != 'y') {
55 printf ("Ok. Please wait patiently...\n");
60 static void DoCircles (void)
62 static const unsigned char Palette[2] = { TGI_COLOR_WHITE, TGI_COLOR_ORANGE };
64 unsigned char Color = COLOR_FORE;
65 unsigned X = MaxX / 2;
66 unsigned Y = MaxY / 2;
68 tgi_setpalette (Palette);
70 tgi_setcolor (COLOR_FORE);
71 tgi_line (0, 0, MaxX, MaxY);
72 tgi_line (0, MaxY, MaxX, 0);
74 for (I = 10; I < 240; I += 10) {
75 tgi_ellipse (X, Y, I, tgi_imulround (I, AspectRatio));
77 Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
86 static void DoCheckerboard (void)
88 static const unsigned char Palette[2] = { TGI_COLOR_WHITE, TGI_COLOR_BLACK };
92 tgi_setpalette (Palette);
95 for (Y = 0; Y <= MaxY; Y += 10) {
96 for (X = 0; X <= MaxX; X += 10) {
98 tgi_bar (X, Y, X+9, Y+9);
99 Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
106 Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
108 Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
114 static void DoDiagram (void)
116 static const unsigned char Palette[2] = { TGI_COLOR_WHITE, TGI_COLOR_BLACK };
117 int XOrigin, YOrigin;
122 tgi_setpalette (Palette);
123 tgi_setcolor (COLOR_FORE);
125 /* Determine zero and aplitude */
128 Amp = (MaxY - 19) / 2;
131 tgi_line (XOrigin, 10, XOrigin, MaxY-10);
132 tgi_line (XOrigin-2, 12, XOrigin, 10);
133 tgi_lineto (XOrigin+2, 12);
136 tgi_line (XOrigin, YOrigin, MaxX-10, YOrigin);
137 tgi_line (MaxX-12, YOrigin-2, MaxX-10, YOrigin);
138 tgi_lineto (MaxX-12, YOrigin+2);
141 tgi_gotoxy (XOrigin, YOrigin);
142 for (I = 0; I <= 360; I += 5) {
144 /* Calculate the next points */
145 X = (int) (((long) (MaxX - 19) * I) / 360);
146 Y = (int) (((long) Amp * -cc65_sin (I)) / 256);
149 tgi_lineto (XOrigin + X, YOrigin + Y);
158 static void DoLines (void)
160 static const unsigned char Palette[2] = { TGI_COLOR_WHITE, TGI_COLOR_BLACK };
163 tgi_setpalette (Palette);
164 tgi_setcolor (COLOR_FORE);
166 for (X = 0; X <= MaxY; X += 10) {
167 tgi_line (0, 0, MaxY, X);
168 tgi_line (0, 0, X, MaxY);
169 tgi_line (MaxY, MaxY, 0, MaxY-X);
170 tgi_line (MaxY, MaxY, MaxY-X, 0);
181 unsigned char Border;
183 /* Warn the user that the tgi driver is needed */
186 /* Load and initialize the driver */
187 tgi_load_driver (tgi_stddrv);
188 CheckError ("tgi_load_driver");
190 CheckError ("tgi_init");
193 /* Get stuff from the driver */
194 MaxX = tgi_getmaxx ();
195 MaxY = tgi_getmaxy ();
196 AspectRatio = tgi_getaspectratio ();
198 /* Set the palette, set the border color */
199 Border = bordercolor (COLOR_BLACK);
201 /* Do graphics stuff */
207 /* Unload the driver */
210 /* Reset the border */
211 (void) bordercolor (Border);