backport
[AROS.git] / test / joystick.c
blobe229aaaba45b87ab69d350666be2aee35c0245b5
1 #include <proto/exec.h>
2 #include <proto/dos.h>
3 #include <proto/lowlevel.h>
4 #include <libraries/lowlevel_ext.h>
6 #include <stdio.h>
7 #include <stdlib.h>
10 struct Library *LowLevelBase;
12 static void printbuttons(ULONG val)
14 if (val & JPF_BUTTON_PLAY) printf("[PLAY/MMB]");
15 if (val & JPF_BUTTON_REVERSE) printf("[REVERSE]");
16 if (val & JPF_BUTTON_FORWARD) printf("[FORWARD]");
17 if (val & JPF_BUTTON_GREEN) printf("[SHUFFLE]");
18 if (val & JPF_BUTTON_RED) printf("[SELECT/LMB/FIRE]");
19 if (val & JPF_BUTTON_BLUE) printf("[STOP/RMB]");
22 static void printmousedirections(ULONG val)
24 printf("[%d,%d]", (int)(val & JP_MHORZ_MASK), (int)(val & JP_MVERT_MASK) >> 8);
27 static void printajoydirections(ULONG val)
29 printf("[%d, %d]", (int)(val & JP_XAXIS_MASK), (int)(val & JP_YAXIS_MASK) >> 8);
31 static void printjoydirections(ULONG val)
33 if (val & JPF_JOY_UP) printf("[UP]");
34 if (val & JPF_JOY_DOWN) printf("[DOWN]");
35 if (val & JPF_JOY_LEFT) printf("[LEFT]");
36 if (val & JPF_JOY_RIGHT) printf("[RIGHT]");
39 static void printjoyport(ULONG val)
41 int i;
43 for(i = 31; i >= 0; i--)
45 printf("%d", (val & (1 << i)) ? 1 : 0);
48 printf(" - ");
50 if ((val & JP_TYPE_MASK) == JP_TYPE_NOTAVAIL) printf("NOT AVAILABLE");
51 if ((val & JP_TYPE_MASK) == JP_TYPE_UNKNOWN) printf("UNKNOWN");
53 if ((val & JP_TYPE_MASK) == JP_TYPE_JOYSTK)
55 printf("JOYSTICK - ");
56 printjoydirections(val);
57 printbuttons(val);
60 if ((val & JP_TYPE_MASK) == JP_TYPE_GAMECTLR)
62 printf("GAME CONTROLLER - ");
63 printjoydirections(val);
64 printbuttons(val);
67 if ((val & JP_TYPE_MASK) == JP_TYPE_MOUSE)
69 printf("MOUSE - ");
70 printmousedirections(val);
71 printbuttons(val);
74 if ((val & JP_TYPE_MASK) == JP_TYPE_ANALOGUE)
76 printf("JOYSTICK[ANALOGUE] - ");
77 printajoydirections(val);
78 printbuttons(val);
81 printf("\n");
84 int main(int argc, char **argv)
86 int unit = 1;
88 if (argc == 2) unit = atoi(argv[1]);
90 LowLevelBase = OpenLibrary("lowlevel.library", 0);
92 if (LowLevelBase)
94 ULONG old = 0;
96 while(!CheckSignal(SIGBREAKF_CTRL_C))
98 ULONG new;
100 new = ReadJoyPort(unit);
101 if (new != old)
103 old = new;
104 printjoyport(new);
107 Delay(1);
109 CloseLibrary(LowLevelBase);
112 return 0;