]> git.sur5r.net Git - cc65/blob - testcode/lib/conio.c
Added C64 Chameleon accelerator code and documentation.
[cc65] / testcode / lib / conio.c
1 /*
2  * conio api test program
3  *
4  * keys:
5  *
6  * 1...0        change text color
7  * F5/F6        change border color
8  * F7/F8        change background color
9  *
10  */
11
12
13 #include <conio.h>
14 #include <string.h>
15 #include <stdlib.h>
16 #include <joystick.h>
17
18 #if defined(__GAMATE__)
19 /* there is not enough screen space to show all 256 characters at the bottom */
20 #define NUMCHARS        128
21 #define NUMCOLS           4
22 #else
23 #define NUMCHARS        256
24 #define NUMCOLS          16
25 #endif
26
27 static char grid[5][5] = {
28     { CH_ULCORNER, CH_HLINE, CH_TTEE, CH_HLINE, CH_URCORNER },
29     { CH_VLINE, ' ', CH_VLINE, ' ', CH_VLINE },
30     { CH_LTEE, CH_HLINE, CH_CROSS, CH_HLINE, CH_RTEE },
31     { CH_VLINE, ' ', CH_VLINE, ' ', CH_VLINE },
32     { CH_LLCORNER, CH_HLINE, CH_BTEE, CH_HLINE, CH_LRCORNER },
33 };
34
35 void main(void)
36 {
37         int i, j, n;
38         unsigned char xsize, ysize, tcol, bgcol, bcol, inpos = 0;
39 #if defined(__NES__) || defined(__PCE__) || defined(__GAMATE__)
40         unsigned char joy;
41
42         joy_install(joy_static_stddrv);
43 #endif
44         clrscr();
45         screensize(&xsize, &ysize);
46         cputs("cc65 conio test\n\r");
47         cputs("Input:[        ]");
48
49         cputsxy(0, 2, "Colors:" );
50         tcol = textcolor(0); /* remember original textcolor */
51         bgcol = bgcolor(0); /* remember original background color */
52         bcol = bordercolor(0); /* remember original border color */
53         bgcolor(bgcol);bordercolor(bcol);
54         for (i = 0; i < 3; ++i) {
55                 gotoxy(i,3 + i);
56                 for (j = 0; j < NUMCOLS; ++j) {
57                         textcolor(j);
58                         cputc('X');
59                 }
60         }
61         textcolor(tcol);
62
63         cprintf("\n\n\r Screensize: %dx%d", xsize, ysize );
64
65         chlinexy(0,6,xsize);
66         cvlinexy(0,6,3);
67         chlinexy(0,8,xsize);
68         cvlinexy(xsize-1,6,3);
69         cputcxy(0,6,CH_ULCORNER);
70         cputcxy(xsize-1,6,CH_URCORNER);
71         cputcxy(0,8,CH_LLCORNER);
72         cputcxy(xsize-1,8,CH_LRCORNER);
73
74         for (i = 0; i < 5; ++i) {
75                 gotoxy(xsize - 5,i);
76                 for (j = 0; j < 5; ++j) {
77                         cputc(grid[i][j]);
78                 }
79         }
80
81         gotoxy(0,ysize - 2 - ((NUMCHARS + xsize) / xsize));
82         revers(1);
83         for (i = 0; i < xsize; ++i) {
84                 cputc('0' + i % 10);
85         }
86         revers(0);
87         for (i = 0; i < NUMCHARS; ++i) {
88             if ((i != '\n') && (i != '\r')) {
89                     cputc(i);
90             } else {
91                     cputc(' ');
92             }
93         }
94         while(wherex() > 0) {
95                 cputc('#');
96         }
97         revers(1);
98         for (i = 0; i < xsize; ++i) {
99                 cputc('0' + i % 10);
100         }
101         revers(0);
102
103         cursor(1);
104         for (;;) {
105
106                 /* do the "rvs" blinking */
107                 i = textcolor(COLOR_BLACK);
108                 gotoxy(8, 2);
109                 j = n >> 4 & 1;
110                 revers(j);
111                 cputc(j ? 'R' : ' ');
112                 revers(j ^ 1);
113                 cputs(" rvs");
114                 revers(0);
115                 textcolor(i);
116
117                 gotoxy(7 + inpos,1);
118
119 #if defined(__NES__) || defined(__PCE__) || defined(__GAMATE__)
120                 /* not all targets have waitvsync */
121                 waitvsync();
122                 /* for targets that do not have a keyboard, read the first
123                    joystick */
124                 joy = joy_read(JOY_1);
125                 cprintf("%02x", joy);
126 #else
127                 i = cgetc();
128                 if ((i >= '0') && (i<='9')) {
129                     textcolor(i - '0');
130                 } else if (i == CH_CURS_LEFT) {
131                     inpos = (inpos - 1) & 7;
132                 } else if (i == CH_CURS_RIGHT) {
133                     inpos = (inpos + 1) & 7;
134                 } else if (i == CH_F5) {
135                     bgcol = (bgcol + 1) & 0x0f;
136                     bordercolor(bgcol);
137                 } else if (i == CH_F6) {
138                     bgcol = (bgcol - 1) & 0x0f;
139                     bordercolor(bgcol);
140                 } else if (i == CH_F7) {
141                     bgcol = (bgcol + 1) & 0x0f;
142                     bgcolor(bgcol);
143                 } else if (i == CH_F8) {
144                     bgcol = (bgcol - 1) & 0x0f;
145                     bgcolor(bgcol);
146                 } else {
147                     cputc(i);
148                     inpos = (inpos + 1) & 7;
149                 }
150 #endif
151                 ++n;
152         }
153 }