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