]> git.sur5r.net Git - cc65/blob - testcode/lib/joy-test.c
add comment on linking, tweak a bit for easier debugging
[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 JOYSTICK_DRIVER
9
10 /* A statically linked driver was named on the compiler's command line.
11 ** Make sure that it is used instead of a dynamic one.
12 */
13 #  undef DYN_DRV
14 #  define DYN_DRV       0
15
16 /*
17  * link existing drivers like this:
18  *
19  * cl65 -DJOYSTICK_DRIVER=c64_hitjoy_joy -o joy-test.prg joy-test.c
20  *
21  * for testing a new driver you will have to uncomment the define below, and
22  * link your driver like this:
23  *
24  * co65 ../../target/c64/drv/joy/c64-hitjoy.joy -o hitjoy.s --code-label _hitjoy
25  * cl65 -DJOYSTICK_DRIVER=hitjoy -o joy-test.prg joy-test.c hitjoy.s
26  *
27 */
28
29 /* extern char JOYSTICK_DRIVER; */
30
31 #else
32
33 /* Use a dynamically loaded driver, by default. */
34 #  ifndef DYN_DRV
35 #    define DYN_DRV     1
36 #  endif
37 #endif
38
39
40 int main (void)
41 {
42     unsigned char j;
43     unsigned char count;
44     unsigned char i;
45     unsigned char Res;
46
47     clrscr ();
48
49 #if DYN_DRV
50     Res = joy_load_driver (joy_stddrv);
51 #elif defined(JOYSTICK_DRIVER)
52     Res = joy_install (&JOYSTICK_DRIVER);
53 #else
54     Res = joy_install (&joy_static_stddrv);
55 #endif
56
57     if (Res != JOY_ERR_OK) {
58         cprintf ("Error in joy_load_driver: %u\r\n", Res);
59 #if DYN_DRV
60         cprintf ("os: %u, %s\r\n", _oserror, _stroserror (_oserror));
61 #endif
62         exit (EXIT_FAILURE);
63     }
64
65     count = joy_count ();
66 #if defined(__ATARI5200__) || defined(__CREATIVISION__)
67     cprintf ("JOYSTICKS: %d", count);
68 #else
69     cprintf ("Driver supports %d joystick(s)", count);
70 #endif
71     while (1) {
72         for (i = 0; i < count; ++i) {
73             gotoxy (0, i+1);
74             j = joy_read (i);
75 #if defined(__ATARI5200__) || defined(__CREATIVISION__)
76             cprintf ("%1d:%-3s%-3s%-3s%-3s%-3s %02x",
77                      i,
78                      JOY_UP(j)?    " U " : " - ",
79                      JOY_DOWN(j)?  " D " : " - ",
80                      JOY_LEFT(j)?  " L " : " - ",
81                      JOY_RIGHT(j)? " R " : " - ",
82                      JOY_BTN_1(j)? " 1 " : " - ", j);
83 #else
84             cprintf ("%2d: %-6s%-6s%-6s%-6s%-6s %02x",
85                      i,
86                      JOY_UP(j)?    "  up  " : " ---- ",
87                      JOY_DOWN(j)?  " down " : " ---- ",
88                      JOY_LEFT(j)?  " left " : " ---- ",
89                      JOY_RIGHT(j)? "right " : " ---- ",
90                      JOY_BTN_1(j)? "button" : " ---- ", j);
91 #endif
92         }
93     }
94     return 0;
95 }