]> git.sur5r.net Git - cc65/blob - testcode/lib/joy-test.c
Merge remote-tracking branch 'irgendwer/AtariOS_Structure' into master
[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     unsigned char ch, kb;
47
48     clrscr ();
49
50 #if DYN_DRV
51     Res = joy_load_driver (joy_stddrv);
52 #elif defined(JOYSTICK_DRIVER)
53     Res = joy_install (&JOYSTICK_DRIVER);
54 #else
55     Res = joy_install (&joy_static_stddrv);
56 #endif
57
58     if (Res != JOY_ERR_OK) {
59         cprintf ("Error in joy_load_driver: %u\r\n", Res);
60 #if DYN_DRV
61         cprintf ("os: %u, %s\r\n", _oserror, _stroserror (_oserror));
62 #endif
63         exit (EXIT_FAILURE);
64     }
65
66     count = joy_count ();
67 #if defined(__ATARI5200__) || defined(__CREATIVISION__)
68     cprintf ("JOYSTICKS: %d", count);
69 #else
70     cprintf ("Driver supports %d joystick(s)", count);
71 #endif
72     while (1) {
73         for (i = 0; i < count; ++i) {
74             gotoxy (0, i+1);
75             j = joy_read (i);
76 #if defined(__ATARI5200__) || defined(__CREATIVISION__)
77             cprintf ("%1d:%-3s%-3s%-3s%-3s%-3s %02x",
78                      i,
79                      JOY_UP(j)?    " U " : " - ",
80                      JOY_DOWN(j)?  " D " : " - ",
81                      JOY_LEFT(j)?  " L " : " - ",
82                      JOY_RIGHT(j)? " R " : " - ",
83                      JOY_BTN_1(j)? " 1 " : " - ", j);
84 #else
85             cprintf ("%2d: %-6s%-6s%-6s%-6s%-6s %02x",
86                      i,
87                      JOY_UP(j)?    "  up  " : " ---- ",
88                      JOY_DOWN(j)?  " down " : " ---- ",
89                      JOY_LEFT(j)?  " left " : " ---- ",
90                      JOY_RIGHT(j)? "right " : " ---- ",
91                      JOY_BTN_1(j)? "button" : " ---- ", j);
92 #endif
93         }
94
95         /* show pressed key, so we can verify keyboard is working */
96         kb = kbhit ();
97         ch = kb ? cgetc () : ' ';
98         gotoxy (1, i+2);
99         revers (kb);
100         cprintf ("kbd: %c", ch);
101         revers (0);
102     }
103     return 0;
104 }