8 #include <tgi/tgi-kernel.h>
16 #define COLOR_BACK TGI_COLOR_BLACK
17 #define COLOR_FORE TGI_COLOR_WHITE
20 /*****************************************************************************/
22 /*****************************************************************************/
29 static unsigned AspectRatio;
33 /*****************************************************************************/
35 /*****************************************************************************/
39 static void CheckError (const char* S)
41 unsigned char Error = tgi_geterror ();
42 if (Error != TGI_ERR_OK) {
43 printf ("%s: %d\n", S, Error);
50 static void DoWarning (void)
51 /* Warn the user that the TGI driver is needed for this program */
53 printf ("Warning: This program needs the TGI\n"
54 "driver on disk! Press 'y' if you have\n"
55 "it - any other key exits.\n");
56 if (tolower (cgetc ()) != 'y') {
59 printf ("Ok. Please wait patiently...\n");
64 static void DoCircles (void)
66 static const unsigned char Palette[2] = { TGI_COLOR_WHITE, TGI_COLOR_ORANGE };
68 unsigned char Color = COLOR_FORE;
69 unsigned X = MaxX / 2;
70 unsigned Y = MaxY / 2;
72 tgi_setpalette (Palette);
74 tgi_setcolor (COLOR_FORE);
75 tgi_line (0, 0, MaxX, MaxY);
76 tgi_line (0, MaxY, MaxX, 0);
78 for (I = 10; I < 240; I += 10) {
79 tgi_ellipse (X, Y, I, tgi_imulround (I, AspectRatio));
81 Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
90 static void DoCheckerboard (void)
92 static const unsigned char Palette[2] = { TGI_COLOR_WHITE, TGI_COLOR_BLACK };
96 tgi_setpalette (Palette);
99 for (Y = 0; Y <= MaxY; Y += 10) {
100 for (X = 0; X <= MaxX; X += 10) {
101 tgi_setcolor (Color);
102 tgi_bar (X, Y, X+9, Y+9);
103 Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
110 Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
112 Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE;
118 static void DoDiagram (void)
120 static const unsigned char Palette[2] = { TGI_COLOR_WHITE, TGI_COLOR_BLACK };
121 int XOrigin, YOrigin;
126 tgi_setpalette (Palette);
127 tgi_setcolor (COLOR_FORE);
129 /* Determine zero and aplitude */
132 Amp = (MaxY - 19) / 2;
135 tgi_line (XOrigin, 10, XOrigin, MaxY-10);
136 tgi_line (XOrigin-2, 12, XOrigin, 10);
137 tgi_lineto (XOrigin+2, 12);
140 tgi_line (XOrigin, YOrigin, MaxX-10, YOrigin);
141 tgi_line (MaxX-12, YOrigin-2, MaxX-10, YOrigin);
142 tgi_lineto (MaxX-12, YOrigin+2);
145 tgi_gotoxy (XOrigin, YOrigin);
146 for (I = 0; I <= 360; I += 5) {
148 /* Calculate the next points */
149 X = (int) (((long) (MaxX - 19) * I) / 360);
150 Y = (int) (((long) Amp * -cc65_sin (I)) / 256);
153 tgi_lineto (XOrigin + X, YOrigin + Y);
162 static void DoLines (void)
164 static const unsigned char Palette[2] = { TGI_COLOR_WHITE, TGI_COLOR_BLACK };
167 tgi_setpalette (Palette);
168 tgi_setcolor (COLOR_FORE);
170 for (X = 0; X <= MaxY; X += 10) {
171 tgi_line (0, 0, MaxY, X);
172 tgi_line (0, 0, X, MaxY);
173 tgi_line (MaxY, MaxY, 0, MaxY-X);
174 tgi_line (MaxY, MaxY, MaxY-X, 0);
185 unsigned char Border;
188 /* Warn the user that the tgi driver is needed */
191 /* Load and initialize the driver */
192 tgi_load_driver (tgi_stddrv);
193 CheckError ("tgi_load_driver");
195 /* Install the driver */
196 tgi_install (tgi_static_stddrv);
197 CheckError ("tgi_install");
201 CheckError ("tgi_init");
204 /* Get stuff from the driver */
205 MaxX = tgi_getmaxx ();
206 MaxY = tgi_getmaxy ();
207 AspectRatio = tgi_getaspectratio ();
209 /* Set the palette, set the border color */
210 Border = bordercolor (COLOR_BLACK);
212 /* Do graphics stuff */
219 /* Unload the driver */
222 /* Uninstall the driver */
226 /* Reset the border */
227 (void) bordercolor (Border);