1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 1996, 2003 - 3D Realms Entertainment
4 
5 This file is NOT part of Duke Nukem 3D version 1.5 - Atomic Edition
6 However, it is either an older version of a file that is, or is
7 some test code written during the development of Duke Nukem 3D.
8 This file is provided purely for educational interest.
9 
10 Duke Nukem 3D is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 See the GNU General Public License for more details.
20 
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24 
25 Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
26 */
27 //-------------------------------------------------------------------------
28 
29 //****************************************************************************
30 //
31 // Private header for CONTROL.C
32 //
33 //****************************************************************************
34 
35 #ifndef _control_private
36 #define _control_private
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 //****************************************************************************
42 //
43 // DEFINES
44 //
45 //****************************************************************************
46 
47 #define BUTTON0_SCAN_1   sc_Space
48 #define BUTTON0_SCAN_2   sc_Enter
49 #define BUTTON0_SCAN_3   sc_kpad_Enter
50 #define BUTTON1_SCAN     sc_Escape
51 
52 #define AXISUNDEFINED   0x7f
53 #define BUTTONUNDEFINED 0x7f
54 #define KEYUNDEFINED    0x7f
55 
56 #define SENSITIVE        0x400
57 //#define MINSENSITIVE     0x30
58 
59 #define THRESHOLD        30
60 #define MINTHRESHOLD     10
61 
62 #define USERINPUTDELAY   200
63 
64 #define ResetMouse       0
65 #define GetMouseButtons  3
66 #define GetMouseDelta    11
67 
68 #define MouseInt         0x33
69 #define JoyMax           0xa00
70 #define MaxJoyValue      5000
71 #define MINIMUMMOUSESENSITIVITY 0x1000
72 #define DEFAULTMOUSESENSITIVITY 0x7000+MINIMUMMOUSESENSITIVITY
73 
74 #define CONTROL_NUM_FLAGS   64
75 #define INSTANT_ONOFF       0
76 #define TOGGLE_ONOFF        1
77 
78 #define MAXCONTROLVALUE  0x7fff
79 
80 // Maximum number of buttons for any controller
81 #define MAXBUTTONS 32
82 
83 // Number of Mouse buttons
84 
85 #define MAXMOUSEBUTTONS 6
86 
87 // Number of Mouse Axes
88 
89 #define MAXMOUSEAXES 2
90 
91 // Number of JOY buttons
92 
93 #define MAXJOYBUTTONS 32
94 
95 // Number of JOY axes
96 
97 #define MAXJOYAXES 12
98 
99 // Number of GamePad axes
100 
101 #define MAXGAMEPADAXES 2
102 
103 // Number of axes
104 
105 #define MAXAXES 6
106 
107 // NORMAL axis scale
108 
109 #define NORMALAXISSCALE (65536)
110 
111 #define BUTTONSET(x,value) \
112     (\
113     ((x)>31) ?\
114     (CONTROL_ButtonState2 |= (value<<((x)-32)))  :\
115     (CONTROL_ButtonState1 |= (value<<(x)))\
116     )
117 
118 #define BUTTONCLEAR(x) \
119     (\
120     ((x)>31) ?\
121     (CONTROL_ButtonState2 &= (~(1<<((x)-32)))) :\
122     (CONTROL_ButtonState1 &= (~(1<<(x))))\
123     )
124 
125 #define BUTTONHELDSET(x,value)\
126     (\
127     ((x)>31) ?\
128     (CONTROL_ButtonHeldState2 |= value<<((x)-32)) :\
129     (CONTROL_ButtonHeldState1 |= value<<(x))\
130     )
131 
132 #define LIMITCONTROL(x)\
133     {\
134     if ((*x)>MAXCONTROLVALUE) \
135        {\
136        (*x) = MAXCONTROLVALUE;\
137        }\
138     if ((*x)<-MAXCONTROLVALUE) \
139        {\
140        (*x) = -MAXCONTROLVALUE;\
141        }\
142     }
143 #define SGN(x) \
144     ( ( (x) > 0 ) ? 1 : ( (x) < 0 ) ? -1 : 0 )
145 
146 //****************************************************************************
147 //
148 // TYPEDEFS
149 //
150 //****************************************************************************
151 
152 typedef enum
153    {
154    motion_Left  = -1,
155    motion_Up    = -1,
156    motion_None  = 0,
157    motion_Right = 1,
158    motion_Down  = 1
159    } motion;
160 
161 
162 typedef struct
163    {
164    int32 joyMinX;
165    int32 joyMinY;
166    int32 threshMinX;
167    int32 threshMinY;
168    int32 threshMaxX;
169    int32 threshMaxY;
170    int32 joyMaxX;
171    int32 joyMaxY;
172    int32 joyMultXL;
173    int32 joyMultYL;
174    int32 joyMultXH;
175    int32 joyMultYH;
176    } JoystickDef;
177 
178 //   int32 ThrottleMin;
179 //   int32 RudderMin;
180 //   int32 ThrottlethreshMin;
181 //   int32 RudderthreshMin;
182 //   int32 ThrottlethreshMax;
183 //   int32 RudderthreshMax;
184 //   int32 ThrottleMax;
185 //   int32 RudderMax;
186 //   int32 ThrottleMultL;
187 //   int32 RudderMultL;
188 //   int32 ThrottleMultH;
189 //   int32 RudderMultH;
190 
191 /*
192 typedef struct
193    {
194    byte active     : 1;
195    byte used       : 1;
196    byte toggle     : 1;
197    byte buttonheld : 1;
198    byte cleared    : 1;
199    } controlflags;
200 typedef struct
201    {
202    volatile byte active     : 1;
203    volatile byte used       : 1;
204    volatile byte toggle     : 1;
205    volatile byte buttonheld : 1;
206    volatile byte cleared    : 1;
207    } controlflags;
208 */
209 typedef struct
210    {
211    byte active     ;
212    byte used       ;
213    byte toggle     ;
214    byte buttonheld ;
215    int32 cleared    ;
216    } controlflags;
217 
218 typedef struct
219    {
220    kb_scancode key1;
221    kb_scancode key2;
222    } controlkeymaptype;
223 
224 typedef struct
225    {
226    byte singleclicked;
227    byte doubleclicked;
228    word extra;
229    } controlbuttontype;
230 
231 typedef struct
232    {
233    byte analogmap;
234    byte minmap;
235    byte maxmap;
236    byte extra;
237    } controlaxismaptype;
238 
239 typedef struct
240    {
241    int32 analog;
242    int32 digital;
243    } controlaxistype;
244 
245 
246 //***************************************************************************
247 //
248 // PROTOTYPES
249 //
250 //***************************************************************************
251 
252 void    CONTROL_GetMouseDelta( void );
253 byte    CONTROL_GetMouseButtons( void );
254 boolean CONTROL_StartMouse( void );
255 void    CONTROL_GetJoyAbs( void );
256 void    CONTROL_GetJoyDelta( void );
257 void    CONTROL_SetJoyScale( void );
258 boolean CONTROL_StartJoy( int32 joy );
259 void    CONTROL_ShutJoy( int32 joy );
260 void    CONTROL_SetFlag( int32 which, boolean active );
261 void    CONTROL_ButtonFunctionState( boolean * state );
262 boolean CONTROL_KeyboardFunctionPressed( int32 whichfunction );
263 boolean CONTROL_CheckRange( int32 which );
264 int32   CONTROL_GetTime( void );
265 void    CONTROL_AxisFunctionState( boolean * state );
266 void    CONTROL_GetJoyMovement( ControlInfo * info );
267 
268 #ifdef __cplusplus
269 };
270 #endif
271 #endif
272