-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard.c
143 lines (119 loc) · 3.12 KB
/
keyboard.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (C) 1995 Ronny Wester
Copyright (C) 2003 Jeremy Chin
Copyright (C) 2003-2007 Lucas Martin-King
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-------------------------------------------------------------------------------
keyboard.c - keyboard stuff... just think what was once here... (DOS interrupt
handlers... *shudder*
Author: $Author: lmartinking $
Rev: $Revision: 250 $
URL: $HeadURL: svn://svn.icculus.org/cdogs-sdl/trunk/src/keyboard.c $
ID: $Id: keyboard.c 250 2007-07-06 16:38:43Z lmartinking $
*/
#include <string.h>
#include "SDL.h"
#include "keyboard.h"
#ifdef SYS_NDS
#include <nds.h>
#endif
#ifdef SYS_PSP
#include <pspctrl.h>
#endif
void InitKeyboard(void)
{
return;
}
char KeyDown(int key)
{
#ifdef SYS_NDS
scanKeys();
if (keysHeld() & KEY_X)
return keyEsc;
return 0;
#endif
#ifdef SYS_PSP
SceCtrlData pad;
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
sceCtrlPeekBufferPositive(&pad, 1);
if (pad.Buttons & PSP_CTRL_TRIANGLE)
return keyEsc;
return 0;
#else
char *tmp;
SDL_PumpEvents();
tmp = SDL_GetKeyState(NULL);
return tmp[key];
#endif
}
#ifdef SYS_NDS
int GetKeyDown(void)
{
scanKeys();
if (keysHeld() & KEY_X)
return keyEsc;
if (keysHeld() > 0)
return keysHeld;
return 0;
}
#endif
#ifdef SYS_PSP
int GetKeyDown(void)
{
SceCtrlData pad;
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
sceCtrlPeekBufferPositive(&pad, 1);
if (pad.Buttons & PSP_CTRL_TRIANGLE)
return keyEsc;
if (pad.Buttons > 0)
return pad.Buttons;
return 0;
}
#endif
#if (!defined SYS_PSP) && !defined SYS_NDS
int GetKeyDown(void)
{
int i;
int nr_keys;
Uint8 *keystate;
SDL_PumpEvents();
keystate = SDL_GetKeyState(&nr_keys);
/* We force these to be ignored, because they are often turned on,
they are toggle keys, and we don't actually need to check for them,
and it fixes a bug of the game "hanging" waiting for key release,
because Windows often has NumLock on by default! */
keystate[SDLK_NUMLOCK] = 0;
keystate[SDLK_CAPSLOCK] = 0;
keystate[SDLK_SCROLLOCK] = 0;
/* Okay, this isn't particularly smart, as it returns only the first
key it finds. */
for (i = 0; i < nr_keys; i++) {
if (keystate[i] == 1) {
return i;
}
}
return 0;
}
#endif
int AnyKeyDown(void)
{
return (GetKeyDown() > 0);
}
void ClearKeys(void)
{
// memset(&uKeys, 0, sizeof(uKeys));
}