1 /* Catacomb Apocalypse Source Code
\r
2 * Copyright (C) 1993-2014 Flat Rock Software
\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
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
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
21 // ID_IN.h - Header file for Input Manager
\r
23 // By Jason Blochowiak
24 // Open Watcom port by sparky4
\r
31 #include "src/lib/lib_head.h"
\r
33 //++++#ifdef __DEBUG__
\r
34 #define __DEBUG_InputMgr__
\r
38 #define TESTCONTROLNOISY
\r
40 #define KeyInt 9 // The keyboard ISR number
\r
42 // Stuff for the joystick
\r
43 #define JoyScaleMax 32768
\r
44 #define JoyScaleShift 8
\r
45 #define MaxJoyValue 5000
\r
47 #define MaxPlayers 4
\r
50 #define NumCodes 128
\r
52 typedef byte ScanCode;
\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
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
74 #define sc_PgUp 0x49
\r
75 #define sc_PgDn 0x51
\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
136 #define key_LSuper 0x5b
137 #define key_RSuper 0x5c
138 #define key_Menu 0x5d
140 // Stuff for the mouse
\r
145 #define MouseInt 0x33
\r
148 demo_Off,demo_Record,demo_Playback,demo_PlayDone
\r
152 //ctrl_None, // MDM (GAMERS EDGE) - added
\r
154 ctrl_Keyboard1 = ctrl_Keyboard,ctrl_Keyboard2,
\r
156 ctrl_Joystick1 = ctrl_Joystick,ctrl_Joystick2,
\r
159 ctrl_Joypad1 = ctrl_Joypad,ctrl_Joypad2
\r
162 motion_Left = -1,motion_Up = -1,
\r
164 motion_Right = 1,motion_Down = 1
\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
174 boolean button0,button1,button2,button3;
\r
176 Motion xaxis,yaxis;
\r
181 ScanCode button0,button1,
\r
192 word joyMinX,joyMinY,
\r
193 threshMinX,threshMinY,
\r
194 threshMaxX,threshMaxY,
\r
196 joyMultXL,joyMultYL,
\r
197 joyMultXH,joyMultYH;
\r
205 =============================================================================
\r
209 =============================================================================
\r
213 // configuration variables
\r
215 static boolean MousePresent;
\r
216 static boolean JoysPresent[MaxJoys];
\r
217 static boolean JoyPadPresent;
\r
219 // Global variables
\r
220 // extern boolean JoystickCalibrated; // MDM (GAMERS EDGE) - added
\r
221 // extern ControlType ControlTypeUsed; // MDM (GAMERS EDGE) - added
\r
223 extern boolean Keyboard[NumCodes];
\r
224 extern boolean Paused;
\r
225 extern char LastASCII;
\r
226 extern ScanCode LastScan;
\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
233 extern dword MouseDownCount;
\r
236 static Demo DemoMode = demo_Off;
\r
237 static byte /*_seg*/ *DemoBuffer;
\r
238 static word DemoOffset,DemoSize;
\r
241 extern dword far* clockdw;
\r
244 =============================================================================
\r
248 =============================================================================
\r
250 static byte far ASCIINames[] = // Unshifted ASCII for scan codes
\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
262 far ShiftNames[] = // Shifted ASCII for scan codes
\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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?","?","?","?","?","\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
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
304 *ExtScanNames[] = // Names corresponding to ExtScanCodes
\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
312 static boolean IN_Started;
\r
313 static boolean CapsLock;
\r
314 static ScanCode CurCode,LastCode;
\r
316 static Direction DirTable[] = // Quick lookup for total direction
\r
321 dir_West, dir_None, dir_East,
\r
323 dir_South//,dir_SouthEast
\r
326 static void (*INL_KeyHook)(void);
\r
327 static void interrupt (*OldKeyVect)(void);
\r
329 static char *ParmStringsIN[] = {"nojoys","nomouse",nil};
\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
336 void interrupt INL_KeyService(void);
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);
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);
367 byte *IN_GetScanName(ScanCode scan);
368 ScanCode IN_WaitForKey(void);
369 char IN_WaitForASCII(void);
370 void IN_AckBack(void);
372 boolean IN_IsUserInput(void);
373 boolean IN_UserInput(dword delay,boolean clear);
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
388 IN_StartDemoPlayback(byte __segment *buffer,word bufsize),
\r
389 IN_StopDemo(void),IN_FreeDemoBuffer(void),
\r
391 IN_Ack(void),IN_AckBack(void);
\r
392 extern boolean IN_UserInput(dword delay,boolean clear),
\r
393 IN_IsUserInput(void)
\r
395 , IN_StartDemoRecord(word bufsize)
\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
404 void interrupt INL_KeyService(void);
\r
405 boolean IN_qb(byte kee);
\r