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