remove obsolete comment
[AROS.git] / test / joystick.c
blob1529d70cd05e97d2289cffc12ebedc93dc369337
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/exec.h>
7 #include <proto/dos.h>
8 #include <proto/lowlevel.h>
9 #include <libraries/lowlevel_ext.h>
11 #include <stdio.h>
12 #include <stdlib.h>
15 struct Library *LowLevelBase;
17 static void printbuttons(ULONG val)
19 if (val & JPF_BUTTON_PLAY) printf("[PLAY/MMB]");
20 if (val & JPF_BUTTON_REVERSE) printf("[REVERSE]");
21 if (val & JPF_BUTTON_FORWARD) printf("[FORWARD]");
22 if (val & JPF_BUTTON_GREEN) printf("[SHUFFLE]");
23 if (val & JPF_BUTTON_RED) printf("[SELECT/LMB/FIRE]");
24 if (val & JPF_BUTTON_BLUE) printf("[STOP/RMB]");
27 static void printmousedirections(ULONG val)
29 printf("[%d,%d]", (int)(val & JP_MHORZ_MASK), (int)(val & JP_MVERT_MASK) >> 8);
32 static void printajoydirections(ULONG val)
34 printf("[%d, %d]", (int)(val & JP_XAXIS_MASK), (int)(val & JP_YAXIS_MASK) >> 8);
36 static void printjoydirections(ULONG val)
38 if (val & JPF_JOY_UP) printf("[UP]");
39 if (val & JPF_JOY_DOWN) printf("[DOWN]");
40 if (val & JPF_JOY_LEFT) printf("[LEFT]");
41 if (val & JPF_JOY_RIGHT) printf("[RIGHT]");
44 static void printjoyport(ULONG val)
46 int i;
48 for(i = 31; i >= 0; i--)
50 printf("%d", (val & (1 << i)) ? 1 : 0);
53 printf(" - ");
55 if ((val & JP_TYPE_MASK) == JP_TYPE_NOTAVAIL) printf("NOT AVAILABLE");
56 if ((val & JP_TYPE_MASK) == JP_TYPE_UNKNOWN) printf("UNKNOWN");
58 if ((val & JP_TYPE_MASK) == JP_TYPE_JOYSTK)
60 printf("JOYSTICK - ");
61 printjoydirections(val);
62 printbuttons(val);
65 if ((val & JP_TYPE_MASK) == JP_TYPE_GAMECTLR)
67 printf("GAME CONTROLLER - ");
68 printjoydirections(val);
69 printbuttons(val);
72 if ((val & JP_TYPE_MASK) == JP_TYPE_MOUSE)
74 printf("MOUSE - ");
75 printmousedirections(val);
76 printbuttons(val);
79 if ((val & JP_TYPE_MASK) == JP_TYPE_ANALOGUE)
81 printf("JOYSTICK[ANALOGUE] - ");
82 printajoydirections(val);
83 printbuttons(val);
86 printf("\n");
89 int main(int argc, char **argv)
91 int unit = 1;
93 if (argc == 2) unit = atoi(argv[1]);
95 LowLevelBase = OpenLibrary("lowlevel.library", 0);
97 if (LowLevelBase)
99 ULONG old = 0;
101 while(!CheckSignal(SIGBREAKF_CTRL_C))
103 ULONG new;
105 new = ReadJoyPort(unit);
106 if (new != old)
108 old = new;
109 printjoyport(new);
112 Delay(1);
114 CloseLibrary(LowLevelBase);
117 return 0;