2 * Acess2 GUI (AxWin) Version 3
3 * - By John Hodge (thePowersGang)
12 // TODO: Move out to a common header
18 #define JOY_IOCTL_GETSETAXISLIMIT 6
19 #define JOY_IOCTL_GETSETAXISPOSITION 7
22 extern void Video_SetCursorPos(short X, short Y);
23 const char *gsMouseDevice;
24 extern int giTerminalFD;
25 extern int giScreenWidth;
26 extern int giScreenHeight;
30 int giInput_MouseButtonState;
31 int giInput_MouseX, giInput_MouseY;
39 giMouseFD = open(gsMouseDevice, 3);
42 // TODO: Update these if the screen resolution changes
43 num_value.Num = 0; num_value.Value = giScreenWidth;
44 ioctl(giMouseFD, JOY_IOCTL_GETSETAXISLIMIT, &num_value);
45 num_value.Value = giScreenWidth/2;
46 giInput_MouseX = giScreenWidth/2;
47 ioctl(giMouseFD, JOY_IOCTL_GETSETAXISPOSITION, &num_value);
49 num_value.Num = 1; num_value.Value = giScreenHeight;
50 ioctl(giMouseFD, JOY_IOCTL_GETSETAXISLIMIT, &num_value);
51 num_value.Value = giScreenHeight/2;
52 giInput_MouseY = giScreenHeight/2;
53 ioctl(giMouseFD, JOY_IOCTL_GETSETAXISPOSITION, &num_value);
58 void Input_FillSelect(int *nfds, fd_set *set)
60 if(*nfds < giTerminalFD) *nfds = giTerminalFD;
61 if(*nfds < giMouseFD) *nfds = giMouseFD;
62 FD_SET(giTerminalFD, set);
63 FD_SET(giMouseFD, set);
66 void Input_HandleSelect(fd_set *set)
68 if(FD_ISSET(giTerminalFD, set))
71 static uint32_t scancode;
72 #define KEY_CODEPOINT_MASK 0x3FFFFFFF
74 if( read(giTerminalFD, &codepoint, sizeof(codepoint)) != sizeof(codepoint) )
77 _SysDebug("Terminal read failed?");
80 // _SysDebug("Keypress 0x%x", codepoint);
82 switch(codepoint & 0xC0000000)
84 case 0x00000000: // Key pressed
85 WM_Input_KeyDown(codepoint & KEY_CODEPOINT_MASK, scancode);
86 case 0x80000000: // Key release
87 WM_Input_KeyFire(codepoint & KEY_CODEPOINT_MASK, scancode);
90 case 0x40000000: // Key refire
91 WM_Input_KeyUp(codepoint & KEY_CODEPOINT_MASK, scancode);
94 case 0xC0000000: // Raw scancode
95 scancode = codepoint & KEY_CODEPOINT_MASK;
100 if(FD_ISSET(giMouseFD, set))
102 const int c_n_axies = 4;
103 const int c_n_buttons = 5;
116 char data[sizeof(*mouseinfo) + sizeof(*axies)*c_n_axies + c_n_buttons];
118 mouseinfo = (void*)data;
120 seek(giMouseFD, 0, SEEK_SET);
121 i = read(giMouseFD, data, sizeof(data));
122 i -= sizeof(*mouseinfo);
124 _SysDebug("Mouse data undersized (no header)");
127 if( mouseinfo->NAxies > c_n_axies || mouseinfo->NButtons > c_n_buttons ) {
128 _SysDebug("%i axies, %i buttons above prealloc counts (%i, %i)",
129 mouseinfo->NAxies, mouseinfo->NButtons, c_n_axies, c_n_buttons
133 if( i < sizeof(*axies)*mouseinfo->NAxies + mouseinfo->NButtons ) {
134 _SysDebug("Mouse data undersized (body doesn't fit %i < %i)",
135 i, sizeof(*axies)*mouseinfo->NAxies + mouseinfo->NButtons
141 if( mouseinfo->NAxies < 2 )
144 axies = (void*)( mouseinfo + 1 );
145 buttons = (void*)( axies + mouseinfo->NAxies );
148 Video_SetCursorPos( axies[0].CursorPos, axies[1].CursorPos );
150 // _SysDebug("Mouse to %i,%i", axies[0].CursorPos, axies[1].CursorPos);
153 giInput_MouseX, giInput_MouseY,
154 axies[0].CursorPos, axies[1].CursorPos
156 giInput_MouseX = axies[0].CursorPos;
157 giInput_MouseY = axies[1].CursorPos;
159 for( i = 0; i < mouseinfo->NButtons; i ++ )
162 int cur = buttons[i] > 128;
164 if( !!(giInput_MouseButtonState & bit) != cur )
166 WM_Input_MouseButton(giInput_MouseX, giInput_MouseY, i, cur);
168 giInput_MouseButtonState ^= bit;