]> git.sur5r.net Git - cc65/blob - testcode/lib/joy-test.c
Removed joy_masks array.
[cc65] / testcode / lib / joy-test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5 #include <conio.h>
6 #include <joystick.h>
7
8
9 #ifdef JOYSTICK_DRIVER
10
11 /* A statically linked driver was named on the compiler's command line.
12 ** Make sure that it is used instead of a dynamic one.
13 */
14 #  undef DYN_DRV
15 #  define DYN_DRV       0
16 #else
17
18 /* Use a dynamically loaded driver, by default. */
19 #  ifndef DYN_DRV
20 #    define DYN_DRV     1
21 #  endif
22 #endif
23
24
25 int main (void)
26 {
27     unsigned char j;
28     unsigned char count;
29     unsigned char i;
30
31 #if DYN_DRV
32     unsigned char Res = joy_load_driver (joy_stddrv);
33 #elif defined(JOYSTICK_DRIVER)
34     unsigned char Res = joy_install (&JOYSTICK_DRIVER);
35 #else
36     unsigned char Res = joy_install (&joy_static_stddrv);
37 #endif
38
39     if (Res != JOY_ERR_OK) {
40         cprintf ("Error in joy_load_driver: %u\r\n", Res);
41 #if DYN_DRV
42         cprintf ("os: %u, %s\r\n", _oserror, _stroserror (_oserror));
43 #endif
44         exit (EXIT_FAILURE);
45     }
46
47     clrscr ();
48     count = joy_count ();
49 #if defined(__ATARI5200__) || defined(__CREATIVISION__)
50     cprintf ("JOYSTICKS: %d", count);
51 #else
52     cprintf ("Driver supports %d joystick(s)", count);
53 #endif
54     while (1) {
55         for (i = 0; i < count; ++i) {
56             gotoxy (0, i+1);
57             j = joy_read (i);
58 #if defined(__ATARI5200__) || defined(__CREATIVISION__)
59             cprintf ("%1d:%-3s%-3s%-3s%-3s%-3s%-3s",
60                      i,
61                      JOY_UP(j)?    " U " : " - ",
62                      JOY_DOWN(j)?  " D " : " - ",
63                      JOY_LEFT(j)?  " L " : " - ",
64                      JOY_RIGHT(j)? " R " : " - ",
65                      JOY_BTN_1(j)? " 1 " : " - ");
66 #else
67             cprintf ("%2d: %-6s%-6s%-6s%-6s%-6s%-6s",
68                      i,
69                      JOY_UP(j)?    "  up  " : " ---- ",
70                      JOY_DOWN(j)?  " down " : " ---- ",
71                      JOY_LEFT(j)?  " left " : " ---- ",
72                      JOY_RIGHT(j)? "right " : " ---- ",
73                      JOY_BTN_1(j)? "button" : " ---- ");
74 #endif
75         }
76     }
77     return 0;
78 }