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