-
Notifications
You must be signed in to change notification settings - Fork 1
/
keyboard.c
189 lines (161 loc) · 4.44 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* keyboard.c */
/* Copyright Hugh Robinson 2006-2008.
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 3 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, see <http://www.gnu.org/licenses/>. */
#include "asylum.h"
extern asylum_options options;
static char keyboard[512];
static int keybuf;
static int mouse;
void init_keyboard()
{
for (int i = 0; i < 512; i++) keyboard[i] = 0;
}
/*
void swi_removecursors()
{
;
}
*/
int swi_readescapestate()
{
return keyboard[SDL_SCANCODE_ESCAPE];
}
int readmousestate()
{
return mouse;
}
int osbyte_79()
{
update_keyboard();
int key = keybuf;
keybuf = -1;
return key;
//for (int i=0;i<512;i++) if (keyboard[i]) {/*printf("Returning %i\n",i);*/ return i;}
return -1;
}
int osbyte_7a()
{
update_keyboard(); for (int i = 0; i < 512; i++) if (keyboard[i]) return i;return -1;
}
void osbyte_7c()
{
keyboard[SDL_SCANCODE_ESCAPE] = 0;
}
int osbyte_81(int c)
{
if (c >= 0) return osbyte_79();
update_keyboard();
return keyboard[-c];
}
char swi_oscrc()
{
return 0xff;
}
void update_keyboard()
{
SDL_Event e;
SDL_KeyboardEvent* ke;
SDL_MouseButtonEvent* me;
while (SDL_PollEvent(&e))
{
// why not SDL_PeepEvents(&e, 1, SDL_GETEVENT, SDL_KEYDOWNMASK|SDL_KEYUPMASK)>0)?
switch (e.type)
{
case SDL_KEYDOWN:
ke = (SDL_KeyboardEvent*)&e;
if (ke->keysym.scancode <= 512) {
keyboard[ke->keysym.scancode] = 0xff;
keybuf = ke->keysym.scancode;
}
break;
case SDL_KEYUP:
ke = (SDL_KeyboardEvent*)&e;
if (ke->keysym.scancode <= 512)
keyboard[ke->keysym.scancode] = 0;
break;
case SDL_MOUSEBUTTONDOWN:
me = (SDL_MouseButtonEvent*)&e;
switch (me->button)
{
case SDL_BUTTON_LEFT: mouse |= 4; break;
case SDL_BUTTON_MIDDLE: mouse |= 2; break;
case SDL_BUTTON_RIGHT: mouse |= 1; break;
}
break;
case SDL_MOUSEBUTTONUP:
me = (SDL_MouseButtonEvent*)&e;
switch (me->button)
{
case SDL_BUTTON_LEFT: mouse &= ~4; break;
case SDL_BUTTON_MIDDLE: mouse &= ~2; break;
case SDL_BUTTON_RIGHT: mouse &= ~1; break;
}
break;
case SDL_QUIT:
exithandler();
break;
}
}
}
void cheatread()
{
int key = osbyte_79();
if (key == -1)
return;
switch (key) {
case SDL_SCANCODE_F1:
getmpmg();
break;
case SDL_SCANCODE_F2:
getrocket();
break;
case SDL_SCANCODE_F3:
prepstrength();
break;
case SDL_SCANCODE_F4:
maxlives(); // Originally screensave();
break;
default:
if (key >= SDL_SCANCODE_1 && key <= SDL_SCANCODE_9)
{
change_zone(key - SDL_SCANCODE_1);
}
break;
}
}
void keyread(key_state* ks)
{
int r4 = -1;
//nojoystick:
if ((osbyte_81(options.leftkey) == 0xff) || !(r4&1))
{ if (++ks->leftpress == 0) ks->leftpress = 0xff;}
else ks->leftpress = 0;
if ((osbyte_81(options.rightkey) == 0xff) || !(r4&2))
{ if (++ks->rightpress == 0) ks->rightpress = 0xff;}
else ks->rightpress = 0;
if ((osbyte_81(options.upkey) == 0xff) || !(r4&4))
{ if (++ks->uppress == 0) ks->uppress = 0xff; }
else ks->uppress = 0;
if ((osbyte_81(options.downkey) == 0xff) || !(r4&8))
{ if (++ks->downpress == 0) ks->downpress = 0xff; }
else ks->downpress = 0;
if ((osbyte_81(options.firekey) == 0xff) || !(r4&16))
{ if (++ks->fire == 0) ks->fire = 0xff; }
else ks->fire = 0;
if (ks->leftpress || ks->rightpress
|| ks->uppress || ks->downpress || ks->fire)
ks->keypressed = 1;
}
int need_redraw()
{
return 0;
}