]> git.sur5r.net Git - cc65/blob - testcode/lib/conio.c
print a space for 0x0a and 0x0d in the char matrix
[cc65] / testcode / lib / conio.c
1
2 #include <conio.h>
3 #include <string.h>
4 #include <stdlib.h>
5
6 static char grid[5][5] = {
7     { CH_ULCORNER, CH_HLINE, CH_TTEE, CH_HLINE, CH_URCORNER },
8     { CH_VLINE, ' ', CH_VLINE, ' ', CH_VLINE },
9     { CH_LTEE, CH_HLINE, CH_CROSS, CH_HLINE, CH_RTEE },
10     { CH_VLINE, ' ', CH_VLINE, ' ', CH_VLINE },
11     { CH_LLCORNER, CH_HLINE, CH_BTEE, CH_HLINE, CH_LRCORNER },
12 };
13
14 void main(void)
15 {
16         int i, j, n;
17         unsigned char xsize, ysize, tcol, inpos = 0;
18
19         clrscr();
20         screensize(&xsize, &ysize);
21         cputs("cc65 conio test\n\rInput: [        ]");
22
23         cputsxy(0, 2, "Colors:" );
24         tcol = textcolor(0); /* remember original textcolor */
25         for (i = 0; i < 3; ++i) {
26                 gotoxy(i,3 + i);
27                 for (j = 0; j < 16; ++j) {
28                         textcolor(j);
29                         cputc('X');
30                 }
31         }
32         textcolor(tcol);
33
34         cprintf("\n\n\r Screensize is: %dx%d", xsize, ysize );
35
36         chlinexy(0,6,xsize);
37         cvlinexy(0,6,3);
38         chlinexy(0,8,xsize);
39         cvlinexy(xsize-1,6,3);
40         cputcxy(0,6,CH_ULCORNER);
41         cputcxy(xsize-1,6,CH_URCORNER);
42         cputcxy(0,8,CH_LLCORNER);
43         cputcxy(xsize-1,8,CH_LRCORNER);
44
45         for (i = 0; i < 5; ++i) {
46                 gotoxy(xsize - 5,i);
47                 for (j = 0; j < 5; ++j) {
48                         cputc(grid[i][j]);
49                 }
50         }
51
52         gotoxy(0,ysize - 2 - ((256 + xsize) / xsize));
53         revers(1);
54         for (i = 0; i < xsize; ++i) {
55                 cputc('0' + i % 10);
56         }
57         revers(0);
58         for (i = 0; i < 256; ++i) {
59             if ((i != '\n') && (i != '\r')) {
60                     cputc(i);
61             } else {
62                     cputc(' ');
63             }
64         }
65         while(wherex() > 0) {
66                 cputc('#');
67         }
68         revers(1);
69         for (i = 0; i < xsize; ++i) {
70                 cputc('0' + i % 10);
71         }
72         revers(0);
73
74         cursor(1);
75         for(;;) {
76
77                 gotoxy(8, 2);
78                 j = n & 1;
79                 revers(j);
80                 cputc(j ? 'R' : ' ');
81                 revers(j ^ 1);
82                 cputs(" revers");
83                 revers(0);
84
85                 gotoxy(8 + inpos,1);
86                 i = cgetc();
87                 if ((i >= '0') && (i<='9')) {
88                     textcolor(i - '0');
89                 } else if (i == CH_CURS_LEFT) {
90                     inpos = (inpos - 1) & 7;
91                 } else if (i == CH_CURS_RIGHT) {
92                     inpos = (inpos + 1) & 7;
93                 } else {
94                     cputc(i);
95                     inpos = (inpos + 1) & 7;
96                 }
97
98                 ++n;
99         }
100
101         for(;;);
102 }