]> git.sur5r.net Git - cc65/blob - testcode/lib/joytest.c
Added joy_stddrv modules
[cc65] / testcode / lib / joytest.c
1 /*
2  * simple joystick test program
3  * CPG 2000
4  */
5
6 #include <stdio.h>
7 #include <conio.h>
8 #include <joystick.h>
9
10 /*#define printf_to_use xxprintf*/
11 #define printf_to_use cprintf
12
13 void xxprintf(char *string)
14 {
15     char i=0;
16
17     while (*(string + i)) cputc(*(string + i++));
18 }
19
20 int main(void)
21 {
22     char c,j;
23     int s;
24
25     clrscr();
26     printf_to_use("Enter joystick # (0-3): ");
27     do {
28         c = cgetc();
29     } while (c < '0' && c > '3');
30     printf("%c\n",c);
31     j = c - '0';
32     printf("using joystick #%d, 'q' to quit\n",j);
33
34     while(1) {
35         if (kbhit()) {
36             c = cgetc();
37             if (c == 'q' || c == 'Q')
38                 return(0);
39         }
40         s = readjoy(j);
41         gotoxy(1,5);
42         if (s & JOY_UP) {
43             printf_to_use("UP ");
44         }
45         else {
46             printf_to_use("   ");
47         }
48         if (s & JOY_DOWN) {
49             printf_to_use("DOWN ");
50         }
51         else {
52             printf_to_use("     ");
53         }
54         if (s & JOY_LEFT) {
55             printf_to_use("LEFT ");
56         }
57         else {
58             printf_to_use("     ");
59         }
60         if (s & JOY_RIGHT) {
61             printf_to_use("RIGHT ");
62         }
63         else {
64             printf_to_use("      ");
65         }
66         if (s & JOY_FIRE) {
67             revers(1);
68             printf_to_use(" FIRE ");
69             revers(0);
70         }
71         else {
72             printf_to_use("      ");
73         }
74     }
75 }