]> git.sur5r.net Git - cc65/blobdiff - testcode/lib/conio.c
fixup conio.c some more. also includes merge of upstream/master because git is retarded.
[cc65] / testcode / lib / conio.c
index bdee122625fd2ef12c5f6c7fb8af6bae0241b546..fe977ec08ca2d11f45a7a32deb6e2359959732b7 100644 (file)
 #include <stdlib.h>
 #include <joystick.h>
 
+#if defined(__GAMATE__)
+/* there is not enough screen space to show all 256 characters at the bottom */
+#define NUMCHARS        128
+#define NUMCOLS           4
+#else
+#define NUMCHARS        256
+#define NUMCOLS          16
+#endif
+
 static char grid[5][5] = {
     { CH_ULCORNER, CH_HLINE, CH_TTEE, CH_HLINE, CH_URCORNER },
     { CH_VLINE, ' ', CH_VLINE, ' ', CH_VLINE },
@@ -27,10 +36,15 @@ void main(void)
 {
         int i, j, n;
         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);
-        cputs("cc65 conio test\n\rInput: [        ]");
+        cputs("cc65 conio test\n\r");
+        cputs("Input:[        ]");
 
         cputsxy(0, 2, "Colors:" );
         tcol = textcolor(0); /* remember original textcolor */
@@ -39,14 +53,14 @@ void main(void)
         bgcolor(bgcol);bordercolor(bcol);
         for (i = 0; i < 3; ++i) {
                 gotoxy(i,3 + i);
-                for (j = 0; j < 16; ++j) {
+                for (j = 0; j < NUMCOLS; ++j) {
                         textcolor(j);
                         cputc('X');
                 }
         }
         textcolor(tcol);
 
-        cprintf("\n\n\r Screensize is: %dx%d", xsize, ysize);
+        cprintf("\n\n\r Screensize: %dx%d", xsize, ysize );
 
         chlinexy(0,6,xsize);
         cvlinexy(0,6,3);
@@ -64,13 +78,13 @@ void main(void)
                 }
         }
 
-        gotoxy(0,ysize - 2 - ((256 + xsize) / xsize));
+        gotoxy(0,ysize - 2 - ((NUMCHARS + xsize) / xsize));
         revers(1);
         for (i = 0; i < xsize; ++i) {
                 cputc('0' + i % 10);
         }
         revers(0);
-        for (i = 0; i < 256; ++i) {
+        for (i = 0; i < NUMCHARS; ++i) {
             if ((i != '\n') && (i != '\r')) {
                     cputc(i);
             } else {
@@ -89,23 +103,27 @@ void main(void)
         cursor(1);
         for (;;) {
 
+                /* do the "rvs" blinking */
+                i = textcolor(COLOR_BLACK);
                 gotoxy(8, 2);
-                j = n & 1;
+                j = n >> 4 & 1;
                 revers(j);
                 cputc(j ? 'R' : ' ');
                 revers(j ^ 1);
-                cputs(" revers");
+                cputs(" rvs");
                 revers(0);
+                textcolor(i);
 
-#if defined(__NES__) || defined(__PCE__)
-
-                joy_install(joy_static_stddrv);
-                while (!joy_read(JOY_1)) ;
-                joy_uninstall();
+                gotoxy(7 + inpos,1);
 
+#if defined(__NES__) || defined(__PCE__) || defined(__GAMATE__)
+                /* not all targets have waitvblank */
+                waitvblank();
+                /* for targets that do not have a keyboard, read the first
+                   joystick */
+                joy = joy_read(JOY_1);
+                cprintf("%02x", joy);
 #else
-
-                gotoxy(8 + inpos,1);
                 i = cgetc();
                 if ((i >= '0') && (i<='9')) {
                     textcolor(i - '0');
@@ -129,9 +147,7 @@ void main(void)
                     cputc(i);
                     inpos = (inpos + 1) & 7;
                 }
-
 #endif
-
                 ++n;
         }
 }