]> git.sur5r.net Git - cc65/blob - testcode/lib/atari5200/hello.c
atari5200: get rid of conio_colors table
[cc65] / testcode / lib / atari5200 / hello.c
1 /*
2 ** Fancy hello world program using cc65.
3 **
4 ** Ullrich von Bassewitz (ullrich@von-bassewitz.de)
5 **
6 ** TEST version for atari5200 conio, using all four colors
7 */
8
9
10
11 #include <stdlib.h>
12 #include <string.h>
13 #include <conio.h>
14 #include <joystick.h>
15
16
17
18 /*****************************************************************************/
19 /*                                   Data                                    */
20 /*****************************************************************************/
21
22
23
24 static const char Text [] = "Hello world!";
25 static unsigned char colors[] = { COLOR_WHITE, COLOR_LIGHTGREEN, COLOR_LIGHTRED, COLOR_BLACK };
26
27
28
29 /*****************************************************************************/
30 /*                                   Code                                    */
31 /*****************************************************************************/
32
33
34
35 int main (void)
36 {
37     unsigned char XSize, YSize;
38     unsigned char PosY;
39     unsigned char i = 0;
40
41     /* Set screen colors */
42     (void) textcolor (COLOR_WHITE);
43     (void) bordercolor (COLOR_BLACK);
44     (void) bgcolor (COLOR_BLACK);
45
46     /* Clear the screen, put cursor in upper left corner */
47     clrscr ();
48
49     /* Ask for the screen size */
50     screensize (&XSize, &YSize);
51
52     /* Install joystick driver */
53     joy_install (joy_static_stddrv);
54
55     while (1) {
56         /* Draw a border around the screen */
57
58         /* Top line */
59         cputc (CH_ULCORNER);
60         chline (XSize - 2);
61         cputc (CH_URCORNER);
62
63         /* Vertical line, left side */
64         cvlinexy (0, 1, YSize - 2);
65
66         /* Bottom line */
67         cputc (CH_LLCORNER);
68         chline (XSize - 2);
69         cputc (CH_LRCORNER);
70
71         /* Vertical line, right side */
72         cvlinexy (XSize - 1, 1, YSize - 2);
73
74         /* Write the greeting in the mid of the screen */
75         gotoxy ((XSize - strlen (Text)) / 2, YSize / 2);
76         cprintf ("%s", Text);
77
78         PosY = wherey ();
79         textcolor (colors[i]); /* switch to color #0 */
80         cputsxy(3, ++PosY, "COLOR 0");
81         textcolor ((colors[i] + 1) & 3); /* switch to color #1 */
82         cputsxy(3, ++PosY, "COLOR 1");
83         textcolor ((colors[i] + 2) & 3); /* switch to color #2 */
84         cputsxy(3, ++PosY, "COLOR 2");
85         textcolor ((colors[i] + 3) & 3); /* switch to color #3 */ /* color #3 is the background color. So written text isn't visible. */
86         cputsxy(3, ++PosY, "COLOR 3");
87
88         /* Wait for the user to press and release a button */
89         while (!joy_read (JOY_1))
90             ;
91         while (joy_read (JOY_1))
92             ;
93
94         i = (i + 1) & 3;
95
96         /* Change colors */
97         textcolor (colors[i]);
98         bgcolor ((colors[i] + 3) & 3);
99
100         /* Clear the screen again */
101         clrscr ();
102     }
103     /* not reached */
104
105     joy_uninstall ();
106
107     /* Done */
108     return EXIT_SUCCESS;
109 }