]> git.sur5r.net Git - cc65/blob - testcode/lib/joy-test.c
fix last change
[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 #ifdef __ATARI5200__
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 #ifdef __ATARI5200__
59             cprintf ("%1d:%-3s%-3s%-3s%-3s%-3s%-3s",
60                      i,
61                      (j & joy_masks[JOY_UP])?    " U " : " u ",
62                      (j & joy_masks[JOY_DOWN])?  " D " : " d ",
63                      (j & joy_masks[JOY_LEFT])?  " L " : " l ",
64                      (j & joy_masks[JOY_RIGHT])? " R " : " r ",
65                      (j & joy_masks[JOY_FIRE])?  " 1 " : "   ",
66                      (j & joy_masks[JOY_FIRE2])? " 2 " : "   ");
67 #else
68             cprintf ("%2d: %-6s%-6s%-6s%-6s%-6s%-6s",
69                      i,
70                      (j & joy_masks[JOY_UP])?    "  up  " : " ---- ",
71                      (j & joy_masks[JOY_DOWN])?  " down " : " ---- ",
72                      (j & joy_masks[JOY_LEFT])?  " left " : " ---- ",
73                      (j & joy_masks[JOY_RIGHT])? "right " : " ---- ",
74                      (j & joy_masks[JOY_FIRE])?  " fire " : " ---- ",
75                      (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- ");
76 #endif
77         }
78     }
79     return 0;
80 }