]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_in.h
wwww
[16.git] / src / lib / 16_in.h
1 /* Catacomb Apocalypse Source Code\r
2  * Copyright (C) 1993-2014 Flat Rock Software\r
3  *\r
4  * This program is free software; you can redistribute it and/or modify\r
5  * it under the terms of the GNU General Public License as published by\r
6  * the Free Software Foundation; either version 2 of the License, or\r
7  * (at your option) any later version.\r
8  *\r
9  * This program is distributed in the hope that it will be useful,\r
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12  * GNU General Public License for more details.\r
13  *\r
14  * You should have received a copy of the GNU General Public License along\r
15  * with this program; if not, write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
17  */\r
18 \r
19 //\r
20 //      ID Engine\r
21 //      ID_IN.h - Header file for Input Manager\r
22 //      v1.0d1w\r
23 //      By Jason Blochowiak
24 //      Open Watcom port by sparky4\r
25 //\r
26 \r
27 #ifndef __16_IN__\r
28 #define __16_IN__\r
29
30 #include <string.h>\r
31 #include "src/lib/lib_head.h"\r
32 \r
33 //++++#ifdef    __DEBUG__\r
34 #define __DEBUG_InputMgr__\r
35 //++++#endif\r
36 \r
37 #define TESTKEYIN
38 #define TESTCONTROLNOISY\r
39 \r
40 #define KeyInt  9       // The keyboard ISR number\r
41 \r
42 // Stuff for the joystick\r
43 #define JoyScaleMax             32768\r
44 #define JoyScaleShift   8\r
45 #define MaxJoyValue             5000\r
46 \r
47 #define MaxPlayers      4\r
48 #define MaxKbds         2\r
49 #define MaxJoys         2\r
50 #define NumCodes        128\r
51 \r
52 typedef byte            ScanCode;\r
53 #define sc_None                 0\r
54 #define sc_Bad                  0xff\r
55 #define sc_Return               0x1c\r
56 #define sc_Enter                sc_Return\r
57 #define sc_Escape               0x01\r
58 #define sc_Space                0x39\r
59 #define sc_BackSpace    0x0e\r
60 #define sc_Tab                  0x0f\r
61 #define sc_Alt                  0x38\r
62 #define sc_Control              0x1d\r
63 #define sc_CapsLock             0x3a\r
64 #define sc_LShift               0x2a\r
65 #define sc_RShift               0x36\r
66 #define sc_UpArrow              0x48\r
67 #define sc_DownArrow    0x50\r
68 #define sc_LeftArrow    0x4b\r
69 #define sc_RightArrow   0x4d\r
70 #define sc_Insert               0x52\r
71 #define sc_Delete               0x53\r
72 #define sc_Home                 0x47\r
73 #define sc_End                  0x4f\r
74 #define sc_PgUp                 0x49\r
75 #define sc_PgDn                 0x51\r
76 #define sc_F1                   0x3b\r
77 #define sc_F2                   0x3c\r
78 #define sc_F3                   0x3d\r
79 #define sc_F4                   0x3e\r
80 #define sc_F5                   0x3f\r
81 #define sc_F6                   0x40\r
82 #define sc_F7                   0x41\r
83 #define sc_F8                   0x42\r
84 #define sc_F9                   0x43\r
85 #define sc_F10                  0x44\r
86 #define sc_F11                  0x57\r
87 #define sc_F12                  0x59\r
88 \r
89 #define sc_1                    0x02\r
90 #define sc_2                    0x03\r
91 #define sc_3                    0x04\r
92 #define sc_4                    0x05\r
93 #define sc_5                    0x06\r
94 #define sc_6                    0x07\r
95 #define sc_7                    0x08\r
96 #define sc_8                    0x09\r
97 #define sc_9                    0x0a\r
98 #define sc_0                    0x0b\r
99 \r
100 #define sc_A                    0x1e\r
101 #define sc_B                    0x30\r
102 #define sc_C                    0x2e\r
103 #define sc_D                    0x20\r
104 #define sc_E                    0x12\r
105 #define sc_F                    0x21\r
106 #define sc_G                    0x22\r
107 #define sc_H                    0x23\r
108 #define sc_I                    0x17\r
109 #define sc_J                    0x24\r
110 #define sc_K                    0x25\r
111 #define sc_L                    0x26\r
112 #define sc_M                    0x32\r
113 #define sc_N                    0x31\r
114 #define sc_O                    0x18\r
115 #define sc_P                    0x19\r
116 #define sc_Q                    0x10\r
117 #define sc_R                    0x13\r
118 #define sc_S                    0x1f\r
119 #define sc_T                    0x14\r
120 #define sc_U                    0x16\r
121 #define sc_V                    0x2f\r
122 #define sc_W                    0x11\r
123 #define sc_X                    0x2d\r
124 #define sc_Y                    0x15\r
125 #define sc_Z                    0x2c\r
126 \r
127 #define key_None                0\r
128 #define key_Return              0x0d\r
129 #define key_Enter               key_Return\r
130 #define key_Escape              0x1b\r
131 #define key_Space               0x20\r
132 #define key_BackSpace   0x08\r
133 #define key_Tab                 0x09\r
134 #define key_Delete              0x7f\r
135
136 #define key_LSuper                      0x5b
137 #define key_RSuper                      0x5c
138 #define key_Menu                        0x5d
139 \r
140 //      Stuff for the mouse\r
141 #define MReset          0\r
142 #define MButtons        3\r
143 #define MDelta          11\r
144 \r
145 #define MouseInt        0x33\r
146 #ifdef DEMO0\r
147 typedef enum            {\r
148                                                 demo_Off,demo_Record,demo_Playback,demo_PlayDone\r
149                                         } Demo;\r
150 #endif\r
151 typedef enum            {\r
152                                                 //ctrl_None,                            // MDM (GAMERS EDGE) - added\r
153                                                 ctrl_Keyboard,\r
154                                                         ctrl_Keyboard1 = ctrl_Keyboard,ctrl_Keyboard2,\r
155                                                 ctrl_Joystick,\r
156                                                         ctrl_Joystick1 = ctrl_Joystick,ctrl_Joystick2,\r
157                                                 ctrl_Mouse,
158                                                 ctrl_Joypad,
159                                                         ctrl_Joypad1 = ctrl_Joypad,ctrl_Joypad2\r
160                                         } ControlType;\r
161 typedef enum            {\r
162                                                 motion_Left = -1,motion_Up = -1,\r
163                                                 motion_None = 0,\r
164                                                 motion_Right = 1,motion_Down = 1\r
165                                         } Motion;\r
166 typedef enum            {\r
167                                                 dir_North,//dir_NorthEast,\r
168                                                 dir_East,//dir_SouthEast,\r
169                                                 dir_South,//dir_SouthWest,\r
170                                                 dir_West,//dir_NorthWest,\r
171                                                 dir_None\r
172                                         } Direction;\r
173 typedef struct          {\r
174                                                 boolean         button0,button1,button2,button3;\r
175                                                 int                     x,y;\r
176                                                 Motion          xaxis,yaxis;\r
177                                                 Direction       dir;\r
178                                         } CursorInfo;\r
179 \r
180 typedef struct          {\r
181                                                 ScanCode        button0,button1,\r
182                                                                         //upleft,\r
183                                                                         up,\r
184                                                                         //upright,\r
185                                                                         left,                           right,\r
186                                                                         //downleft,\r
187                                                                         down\r
188                                                                         //,downright\r
189                                                                         ;\r
190                                         } KeyboardDef;\r
191 typedef struct          {\r
192                                                 word            joyMinX,joyMinY,\r
193                                                                         threshMinX,threshMinY,\r
194                                                                         threshMaxX,threshMaxY,\r
195                                                                         joyMaxX,joyMaxY,\r
196                                                                         joyMultXL,joyMultYL,\r
197                                                                         joyMultXH,joyMultYH;\r
198                                         } JoystickDef;
199
200 /*typedef       struct
201 {
202         CursorInfo;
203 }       ControlInfo;*/\r
204 /*\r
205 =============================================================================\r
206 \r
207                                         GLOBAL VARIABLES\r
208 \r
209 =============================================================================\r
210 */\r
211 \r
212 //\r
213 // configuration variables\r
214 //\r
215 static boolean                  MousePresent;\r
216 static boolean                  JoysPresent[MaxJoys];\r
217 static boolean                  JoyPadPresent;\r
218 \r
219 //      Global variables\r
220 //              extern boolean JoystickCalibrated;              // MDM (GAMERS EDGE) - added\r
221 //              extern ControlType ControlTypeUsed;                             // MDM (GAMERS EDGE) - added\r
222 \r
223                 extern boolean          Keyboard[NumCodes];\r
224                 extern boolean          Paused;\r
225                 extern char             LastASCII;\r
226                 extern ScanCode LastScan;\r
227 \r
228                 //extern KeyboardDef    KbdDefs[];
229                 static KeyboardDef      KbdDefs[MaxKbds] = {0x1d,0x38,0x47,0x48,0x49,0x4b,0x4d,0x4f,0x50,0x51};\r
230                 extern JoystickDef      JoyDefs[MaxJoys];\r
231                 extern ControlType      Controls[MaxPlayers];\r
232 \r
233                 extern dword    MouseDownCount;\r
234 \r
235 #ifdef DEMO0\r
236                 static Demo             DemoMode = demo_Off;\r
237                 static byte /*_seg*/    *DemoBuffer;\r
238                 static word             DemoOffset,DemoSize;\r
239 #endif\r
240 \r
241 extern dword far* clockdw;\r
242 \r
243 /*\r
244 =============================================================================\r
245 \r
246                                         LOCAL VARIABLES\r
247 \r
248 =============================================================================\r
249 */\r
250 static  byte        far ASCIINames[] =          // Unshifted ASCII for scan codes\r
251                                         {\r
252 //       0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F\r
253         0  ,27 ,'1','2','3','4','5','6','7','8','9','0','-','=',8  ,9  ,        // 0\r
254         'q','w','e','r','t','y','u','i','o','p','[',']',13 ,0  ,'a','s',        // 1\r
255         'd','f','g','h','j','k','l',';',39 ,'`',0  ,92 ,'z','x','c','v',        // 2\r
256         'b','n','m',',','.','/',0  ,'*',0  ,' ',0  ,0  ,0  ,0  ,0  ,0  ,        // 3\r
257         0  ,0  ,0  ,0  ,0  ,0  ,0  ,'7','8','9','-','4','5','6','+','1',        // 4\r
258         '2','3','0',127,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 5\r
259         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 6\r
260         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0           // 7\r
261                                         },\r
262                                         far ShiftNames[] =              // Shifted ASCII for scan codes\r
263                                         {\r
264 //       0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F\r
265         0  ,27 ,'!','@','#','$','%','^','&','*','(',')','_','+',8  ,9  ,        // 0\r
266         'Q','W','E','R','T','Y','U','I','O','P','{','}',13 ,0  ,'A','S',        // 1\r
267         'D','F','G','H','J','K','L',':',34 ,'~',0  ,'|','Z','X','C','V',        // 2\r
268         'B','N','M','<','>','?',0  ,'*',0  ,' ',0  ,0  ,0  ,0  ,0  ,0  ,        // 3\r
269         0  ,0  ,0  ,0  ,0  ,0  ,0  ,'7','8','9','-','4','5','6','+','1',        // 4\r
270         '2','3','0',127,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 5\r
271         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 6\r
272         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0           // 7\r
273                                         },\r
274                                         far SpecialNames[] =    // ASCII for 0xe0 prefixed codes\r
275                                         {\r
276 //       0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F\r
277         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 0\r
278         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,13 ,0  ,0  ,0  ,        // 1\r
279         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 2\r
280         0  ,0  ,0  ,0  ,0  ,'/',0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 3\r
281         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 4\r
282         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 5\r
283         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,        // 6\r
284         0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0  ,0           // 7\r
285                                         },\r
286                                         *ScanNames[] =          // Scan code names with single chars\r
287                                         {\r
288         "?","?","1","2","3","4","5","6","7","8","9","0","-","+","?","?",\r
289         "Q","W","E","R","T","Y","U","I","O","P","[","]","|","?","A","S",\r
290         "D","F","G","H","J","K","L",";","\"","?","?","?","Z","X","C","V",\r
291         "B","N","M",",",".","/","?","?","?","?","?","?","?","?","?","?",\r
292         "?","?","?","?","?","?","?","?","\xf","?","-","\x15","5","\x11","+","?",\r
293         "\x13","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",\r
294         "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?",\r
295         "?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"\r
296                                         },      // DEBUG - consolidate these\r
297                                         far ExtScanCodes[] =    // Scan codes with >1 char names\r
298                                         {\r
299         1,0xe,0xf,0x1d,0x2a,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,\r
300         0x3f,0x40,0x41,0x42,0x43,0x44,0x57,0x59,0x46,0x1c,0x36,\r
301         0x37,0x38,0x47,0x49,0x4f,0x51,0x52,0x53,0x45,0x48,\r
302         0x50,0x4b,0x4d,0x00\r
303                                         },\r
304                                         *ExtScanNames[] =       // Names corresponding to ExtScanCodes\r
305                                         {\r
306         "Esc","BkSp","Tab","Ctrl","LShft","Space","CapsLk","F1","F2","F3","F4",\r
307         "F5","F6","F7","F8","F9","F10","F11","F12","ScrlLk","Enter","RShft",\r
308         "PrtSc","Alt","Home","PgUp","End","PgDn","Ins","Del","NumLk","Up",\r
309         "Down","Left","Right",""\r
310                                         };
311 \r
312 static  boolean         IN_Started;\r
313 static  boolean         CapsLock;\r
314 static  ScanCode        CurCode,LastCode;\r
315 \r
316 static  Direction       DirTable[] =            // Quick lookup for total direction\r
317                                         {\r
318                                                 //dir_NorthWest,\r
319                                                 dir_North,\r
320                                                 //dir_NorthEast,\r
321                                                 dir_West,               dir_None,       dir_East,\r
322                                                 //dir_SouthWest,\r
323                                                 dir_South//,dir_SouthEast\r
324                                         };\r
325 \r
326 static  void                    (*INL_KeyHook)(void);\r
327 static  void interrupt  (*OldKeyVect)(void);\r
328 \r
329 static  char                    *ParmStringsIN[] = {"nojoys","nomouse",nil};\r
330 \r
331 // Function prototypes\r
332 #define IN_KeyDown(code)        (Keyboard[(code)])\r
333 #define IN_ClearKey(code)       {Keyboard[code] = false; if (code == LastScan) LastScan = sc_None;}\r
334
335 //      Internal routines
336 void interrupt INL_KeyService(void);
337 void Mouse(int x);
338 //static void INL_GetMouseDelta(int *x,int *y);
339 //static word INL_GetMouseButtons(void);
340 void IN_GetJoyAbs(word joy,word *xp,word *yp);
341 //static void INL_GetJoyDelta(word joy,int *dx,int *dy,boolean adaptive);
342 //static word INL_GetJoyButtons(word joy);
343 word IN_GetJoyButtonsDB(word joy);
344 //static void INL_StartKbd(void);
345 //static void INL_ShutKbd(void);
346 //static boolean INL_StartMouse(void);
347 //static void INL_ShutMouse(void);
348 //static void INL_SetJoyScale(word joy);
349 void IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy);
350 //static boolean INL_StartJoy(word joy);
351 //static void INL_ShutJoy(word joy);
352 void IN_Startup(void);
353 void IN_Default(boolean gotit,ControlType in);
354 void IN_Shutdown(void);
355 void IN_SetKeyHook(void (*hook)());
356 void IN_ClearKeysDown(void);
357 //static void INL_AdjustCursor(CursorInfo *info,word buttons,int dx,int dy);
358 void IN_ReadCursor(CursorInfo *info);
359 void IN_ReadControl(int player,CursorInfo *info);
360 void IN_SetControlType(int player,ControlType type);
361 #if DEMO0
362 boolean IN_StartDemoRecord(word bufsize);
363 void IN_StartDemoPlayback(byte /*__segment*/ *buffer,word bufsize);
364 void IN_StopDemo(void);
365 void IN_FreeDemoBuffer(void);
366 #endif
367 byte *IN_GetScanName(ScanCode scan);
368 ScanCode IN_WaitForKey(void);
369 char IN_WaitForASCII(void);
370 void IN_AckBack(void);
371 void IN_Ack(void);
372 boolean IN_IsUserInput(void);
373 boolean IN_UserInput(dword delay,boolean clear);
374
375 \r
376 /*extern        void            IN_Startup(void),IN_Shutdown(void),\r
377                                         IN_Default(boolean gotit,ControlType in),\r
378                                         IN_SetKeyHook(void (*)()),\r
379                                         IN_ClearKeysDown(void),\r
380                                         IN_ReadCursor(CursorInfo *),\r
381                                         IN_ReadControl(int,ControlInfo *),\r
382                                         IN_SetControlType(int,ControlType),\r
383                                         IN_GetJoyAbs(word joy,word *xp,word *yp),\r
384                                         IN_SetupJoy(word joy,word minx,word maxx,\r
385                                                                 word miny,word maxy),\r
386                                         Mouse(int x),\r
387 #ifdef DEMO0\r
388                                         IN_StartDemoPlayback(byte __segment *buffer,word bufsize),\r
389                                         IN_StopDemo(void),IN_FreeDemoBuffer(void),\r
390 #endif\r
391                                         IN_Ack(void),IN_AckBack(void);\r
392 extern  boolean         IN_UserInput(dword delay,boolean clear),\r
393                                         IN_IsUserInput(void)\r
394 #ifdef DEMO0\r
395                                         , IN_StartDemoRecord(word bufsize)\r
396 #endif\r
397 ;\r
398 extern  byte            *IN_GetScanName(ScanCode);\r
399 extern  char            IN_WaitForASCII(void);\r
400 extern  ScanCode        IN_WaitForKey(void);\r
401 extern  word            IN_GetJoyButtonsDB(word joy);*/\r
402 \r
403 \r
404 void interrupt INL_KeyService(void);\r
405 boolean IN_qb(byte kee);\r
406 #endif\r