]> git.sur5r.net Git - cc65/blob - testcode/lib/conio.c
update conio test
[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
17 static char grid[5][5] = {
18     { CH_ULCORNER, CH_HLINE, CH_TTEE, CH_HLINE, CH_URCORNER },
19     { CH_VLINE, ' ', CH_VLINE, ' ', CH_VLINE },
20     { CH_LTEE, CH_HLINE, CH_CROSS, CH_HLINE, CH_RTEE },
21     { CH_VLINE, ' ', CH_VLINE, ' ', CH_VLINE },
22     { CH_LLCORNER, CH_HLINE, CH_BTEE, CH_HLINE, CH_LRCORNER },
23 };
24
25 void main(void)
26 {
27         int i, j, n;
28         unsigned char xsize, ysize, tcol, bgcol, bcol, inpos = 0;
29
30         clrscr();
31         screensize(&xsize, &ysize);
32         cputs("cc65 conio test\n\rInput: [        ]");
33
34         cputsxy(0, 2, "Colors:" );
35         tcol = textcolor(0); /* remember original textcolor */
36         bgcol = bgcolor(0); /* remember original background color */
37         bcol = bordercolor(0); /* remember original border color */
38         for (i = 0; i < 3; ++i) {
39                 gotoxy(i,3 + i);
40                 for (j = 0; j < 16; ++j) {
41                         textcolor(j);
42                         cputc('X');
43                 }
44         }
45         textcolor(tcol);
46         bgcolor(bgcol);
47
48         cprintf("\n\n\r Screensize is: %dx%d", xsize, ysize );
49
50         chlinexy(0,6,xsize);
51         cvlinexy(0,6,3);
52         chlinexy(0,8,xsize);
53         cvlinexy(xsize-1,6,3);
54         cputcxy(0,6,CH_ULCORNER);
55         cputcxy(xsize-1,6,CH_URCORNER);
56         cputcxy(0,8,CH_LLCORNER);
57         cputcxy(xsize-1,8,CH_LRCORNER);
58
59         for (i = 0; i < 5; ++i) {
60                 gotoxy(xsize - 5,i);
61                 for (j = 0; j < 5; ++j) {
62                         cputc(grid[i][j]);
63                 }
64         }
65
66         gotoxy(0,ysize - 2 - ((256 + xsize) / xsize));
67         revers(1);
68         for (i = 0; i < xsize; ++i) {
69                 cputc('0' + i % 10);
70         }
71         revers(0);
72         for (i = 0; i < 256; ++i) {
73             if ((i != '\n') && (i != '\r')) {
74                     cputc(i);
75             } else {
76                     cputc(' ');
77             }
78         }
79         while(wherex() > 0) {
80                 cputc('#');
81         }
82         revers(1);
83         for (i = 0; i < xsize; ++i) {
84                 cputc('0' + i % 10);
85         }
86         revers(0);
87
88         cursor(1);
89         for(;;) {
90
91                 gotoxy(8, 2);
92                 j = n & 1;
93                 revers(j);
94                 cputc(j ? 'R' : ' ');
95                 revers(j ^ 1);
96                 cputs(" revers");
97                 revers(0);
98
99                 gotoxy(8 + inpos,1);
100                 i = cgetc();
101                 if ((i >= '0') && (i<='9')) {
102                     textcolor(i - '0');
103                 } else if (i == CH_CURS_LEFT) {
104                     inpos = (inpos - 1) & 7;
105                 } else if (i == CH_CURS_RIGHT) {
106                     inpos = (inpos + 1) & 7;
107                 } else if (i == CH_F5) {
108                     bgcol = (bgcol + 1) & 0x0f;
109                     bordercolor(bgcol);
110                 } else if (i == CH_F6) {
111                     bgcol = (bgcol - 1) & 0x0f;
112                     bordercolor(bgcol);
113                 } else if (i == CH_F7) {
114                     bgcol = (bgcol + 1) & 0x0f;
115                     bgcolor(bgcol);
116                 } else if (i == CH_F8) {
117                     bgcol = (bgcol - 1) & 0x0f;
118                     bgcolor(bgcol);
119                 } else {
120                     cputc(i);
121                     inpos = (inpos + 1) & 7;
122                 }
123
124                 ++n;
125         }
126
127         for(;;);
128 }