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