1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-11 05:29:33 +00:00
cc65/testcode/lib/conio.c

166 lines
4.7 KiB
C
Raw Normal View History

2015-10-14 15:24:42 +00:00
/*
* conio api test program
*
* keys:
*
* 1...0 change text color
* F5/F6 change border color
* F7/F8 change background color
*
*/
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <joystick.h>
2015-11-29 00:14:59 +00:00
#if defined(__GAMATE__)
/* there is not enough screen space to show all 256 characters at the bottom */
2015-11-29 00:14:59 +00:00
#define NUMCHARS 128
#define NUMCOLS 4
#else
#define NUMCHARS 256
#define NUMCOLS 16
#endif
2015-09-28 13:29:14 +00:00
static char grid[5][5] = {
{CH_ULCORNER, CH_HLINE, CH_TTEE, CH_HLINE, CH_URCORNER},
{CH_VLINE, ' ', CH_VLINE, ' ', CH_VLINE },
{CH_LTEE, CH_HLINE, CH_CROSS, CH_HLINE, CH_RTEE },
{CH_VLINE, ' ', CH_VLINE, ' ', CH_VLINE },
{CH_LLCORNER, CH_HLINE, CH_BTEE, CH_HLINE, CH_LRCORNER}
2015-09-28 13:29:14 +00:00
};
void main(void)
{
int i, j, n;
2015-10-14 15:24:42 +00:00
unsigned char xsize, ysize, tcol, bgcol, bcol, inpos = 0;
#if defined(__NES__) || defined(__PCE__) || defined(__GAMATE__)
unsigned char joy;
joy_install(joy_static_stddrv);
#endif
clrscr();
screensize(&xsize, &ysize);
2015-11-29 00:14:59 +00:00
cputs("cc65 conio test\n\r");
cputs("Input:[ ]");
2015-09-28 13:29:14 +00:00
cputsxy(0, 2, "Colors:" );
tcol = textcolor(0); /* remember original textcolor */
2015-10-13 02:14:23 +00:00
bgcol = bgcolor(0); /* remember original background color */
2015-10-14 15:24:42 +00:00
bcol = bordercolor(0); /* remember original border color */
(void)bgcolor(bgcol);
(void)bordercolor(bcol);
2015-09-28 13:29:14 +00:00
for (i = 0; i < 3; ++i) {
gotoxy(i, 3 + i);
2015-11-29 00:14:59 +00:00
for (j = 0; j < NUMCOLS; ++j) {
(void)textcolor(j);
cputc('X');
}
}
(void)textcolor(tcol);
cprintf("\n\n\r Screensize: %dx%d", xsize, ysize);
2015-09-28 13:29:14 +00:00
chlinexy(0, 6, xsize);
cvlinexy(0, 6, 3);
chlinexy(0, 8, xsize);
cvlinexy(xsize - 1, 6, 3);
cputcxy(0, 6, CH_ULCORNER);
cputcxy(xsize - 1, 6, CH_URCORNER);
cputcxy(0, 8, CH_LLCORNER);
cputcxy(xsize - 1, 8, CH_LRCORNER);
2015-09-28 13:29:14 +00:00
for (i = 0; i < 5; ++i) {
gotoxy(xsize - 5, i);
2015-09-28 13:29:14 +00:00
for (j = 0; j < 5; ++j) {
cputc(grid[i][j]);
}
}
gotoxy(0, ysize - 2 - ((NUMCHARS + xsize) / xsize));
2015-09-28 13:29:14 +00:00
revers(1);
for (i = 0; i < xsize; ++i) {
cputc('0' + i % 10);
}
2015-09-28 13:29:14 +00:00
revers(0);
2015-11-29 00:14:59 +00:00
for (i = 0; i < NUMCHARS; ++i) {
if ((i != '\n') && (i != '\r')) {
cputc(i);
} else {
cputc(' ');
}
}
while(wherex() > 0) {
cputc('#');
}
2015-09-28 13:29:14 +00:00
revers(1);
for (i = 0; i < xsize; ++i) {
cputc('0' + i % 10);
}
2015-09-28 13:29:14 +00:00
revers(0);
2015-09-28 15:12:33 +00:00
cursor(1);
for (;;) {
/* do the "rvs" blinking */
i = textcolor(COLOR_BLACK);
2015-09-28 13:29:14 +00:00
gotoxy(8, 2);
2015-11-29 00:14:59 +00:00
j = n >> 4 & 1;
revers(j);
cputc(j ? 'R' : ' ');
2015-09-28 15:12:33 +00:00
revers(j ^ 1);
2015-11-29 00:14:59 +00:00
cputs(" rvs");
revers(0);
(void)textcolor(i);
gotoxy(7 + inpos, 1);
#if defined(__NES__) || defined(__PCE__) || defined(__GAMATE__)
2017-07-17 21:15:05 +00:00
/* not all targets have waitvsync */
waitvsync();
/* for targets that do not have a keyboard, read the first
joystick */
joy = joy_read(JOY_1);
cprintf("%02x", joy);
#else
2015-10-09 21:39:55 +00:00
i = cgetc();
if ((i >= '0') && (i <= '9')) {
(void)textcolor(i - '0');
} else if (i == CH_ENTER) {
clrscr();
return;
2015-10-09 21:39:55 +00:00
} else if (i == CH_CURS_LEFT) {
inpos = (inpos - 1) & 7;
} else if (i == CH_CURS_RIGHT) {
inpos = (inpos + 1) & 7;
#ifdef CH_F5
2015-10-14 15:24:42 +00:00
} else if (i == CH_F5) {
bgcol = (bgcol + 1) & 0x0f;
(void)bordercolor(bgcol);
#endif
#ifdef CH_F6
2015-10-14 15:24:42 +00:00
} else if (i == CH_F6) {
bgcol = (bgcol - 1) & 0x0f;
(void)bordercolor(bgcol);
#endif
#ifdef CH_F7
2015-10-13 02:14:23 +00:00
} else if (i == CH_F7) {
bgcol = (bgcol + 1) & 0x0f;
(void)bgcolor(bgcol);
#endif
#ifdef CH_F8
2015-10-13 02:14:23 +00:00
} else if (i == CH_F8) {
bgcol = (bgcol - 1) & 0x0f;
(void)bgcolor(bgcol);
#endif
2015-10-09 21:39:55 +00:00
} else {
cputc(i);
inpos = (inpos + 1) & 7;
}
2015-11-29 00:14:59 +00:00
#endif
++n;
}
}