This repository has been archived by the owner on Feb 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
i_cyber.c
281 lines (245 loc) · 6.43 KB
/
i_cyber.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
//
// Copyright (C) 1993-1996 Id Software, Inc.
// Copyright (C) 1993-2008 Raven Software
// Copyright (C) 2016-2017 Alexey Khokholov (Nuke.YKT)
//
// 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.
//
// DESCRIPTION:
// CyberMan
//
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "i_system.h"
//
// Doom control structure
//
// The keybaord and joystick will add to the values set by the cyberman,
// to a maximum of 0x19000 for forwardmove and sidemove. Angleturn is
// not bounded at all.
//
// parm normal fast
// ----- ------ ----
// forwardmove 0xc800 0x19000
// sidemove 0xc000 0x14000
// angleturn 0x2800000 0x5000000
//
// The keyboard and joystick have a 1/3 second slow turn of 0x1400000 under
// normal speed to help aiming.
//
#define BT_ATTACK 1
#define BT_USE 2
#define BT_CHANGE 4 // if true, the next 3 bits hold weapon num
#define BT_WEAPONMASK (8+16+32)
#define BT_WEAPONSHIFT 3
//
// CyberMan detection and usage info
//
#define DPMI_INT 0x31
#define MOUSE_INT 0x33
#define DOSMEMSIZE 64 // enough for any SWIFT structure
typedef struct {
short x;
short y;
short z;
short pitch;
short roll;
short yaw;
short buttons;
} SWIFT_3DStatus;
// DPMI real mode interrupt structure
static struct rminfo {
long EDI;
long ESI;
long EBP;
long reserved_by_system;
long EBX;
long EDX;
long ECX;
long EAX;
short flags;
short ES,DS,FS,GS,IP,CS,SP,SS;
} RMI;
typedef struct {
unsigned char deviceType;
unsigned char majorVersion;
unsigned char minorVersion;
unsigned char absRelFlags;
unsigned char centeringFlags;
unsigned char reserved[5];
} StaticDeviceData;
// values for deviceType:
#define DEVTYPE_CYBERMAN 1
short selector;
unsigned short segment; // segment of DOS memory block
SWIFT_3DStatus *cyberstat;
int isCyberPresent; // is CyberMan present?
static union REGS regs;
static struct SREGS sregs;
extern int mousepresent;
//
// I_StartupCyberMan
// If a cyberman is present, init it and set isCyberPresent to 1
//
void I_StartupCyberMan(void)
{
StaticDeviceData *pbuf;
int success = 0;
isCyberPresent = 0;
cyberstat = (SWIFT_3DStatus *)I_AllocLow(DOSMEMSIZE);
segment = (int)cyberstat >> 4;
pbuf = (StaticDeviceData *)cyberstat;
memset(pbuf, 0, sizeof(StaticDeviceData));
// Use DPMI call 300h to issue mouse interrupt
memset(&RMI, 0, sizeof(RMI));
RMI.EAX = 0x53C1; // SWIFT: Get Static Device Data
RMI.ES = segment;
RMI.EDX = 0;
memset(&sregs, 0, sizeof(sregs));
regs.w.ax = 0x0300; // DPMI: simulate interrupt
regs.w.bx = MOUSE_INT;
regs.w.cx = 0;
regs.x.edi = FP_OFF(&RMI);
sregs.es = FP_SEG(&RMI);
int386x(DPMI_INT, ®s, ®s, &sregs);
if ((short)RMI.EAX != 1)
{
// SWIFT functions not present
printf("CyberMan: Wrong mouse driver - no SWIFT support (AX=%04x).\n",
(unsigned)(short)RMI.EAX);
}
else
{
if (pbuf->deviceType != DEVTYPE_CYBERMAN)
{
// no SWIFT device, or not CyberMan
if (pbuf->deviceType == 0)
{
printf("CyberMan: no SWIFT device connected.\n");
}
else
{
printf("CyberMan: SWIFT device is not a CyberMan! (type=%d)\n",
pbuf->deviceType);
}
}
else
{
printf("CyberMan: CyberMan %d.%02d connected.\n",
pbuf->majorVersion, pbuf->minorVersion);
isCyberPresent = 1;
mousepresent = 0;
}
}
}
//
// I_ReadCyberCmds
//
int oldpos;
void I_ReadCyberCmd(ticcmd_t *cmd)
{
int delta;
// Use DPMI call 300h to issue mouse interrupt
memset(&RMI, 0, sizeof(RMI));
RMI.EAX = 0x5301; // SWIFT: Get Position and Buttons
RMI.ES = segment;
RMI.EDX = 0;
memset(&sregs, 0, sizeof(sregs));
regs.w.ax = 0x0300; // DPMI: simulate interrupt
regs.w.bx = MOUSE_INT;
regs.w.cx = 0;
regs.x.edi = FP_OFF(&RMI);
sregs.es = FP_SEG(&RMI);
int386x(DPMI_INT, ®s, ®s, &sregs);
if (cyberstat->y < -7900)
{
cmd->forwardmove = 0xc800 / 2048;
}
else if (cyberstat->y > 7900)
{
cmd->forwardmove = -0xc800 / 2048;
}
if (cyberstat->buttons & 4)
{
cmd->buttons |= BT_ATTACK;
}
if (cyberstat->buttons & 2)
{
cmd->buttons |= BT_USE;
}
delta = cyberstat->x - oldpos;
oldpos = cyberstat->x;
if (cyberstat->buttons & 1) // strafe
{
if (cyberstat->x < -7900)
{
cmd->sidemove = -0xc800 / 2048;
}
else if (cyberstat->x > 7900)
{
cmd->sidemove = 0xc800 / 2048;
}
else
{
cmd->sidemove = delta * 40 / 2048;
}
}
else
{
if (cyberstat->x < -7900)
{
cmd->angleturn = 0x280;
}
else if (cyberstat->x > 7900)
{
cmd->angleturn = -0x280;
}
else
{
cmd->angleturn = -delta * 0xa / 16;
}
}
}
void I_Tactile(int on, int off, int total)
{
if (!isCyberPresent)
{
return;
}
on /= 5;
off /= 5;
total /= 40;
if (on > 255)
{
on = 255;
}
if (off > 255)
{
off = 255;
}
if (total > 255)
{
total = 255;
}
memset(&RMI, 0, sizeof(RMI));
RMI.EAX = 0x5330; // SWIFT: Get Position and Buttons
RMI.EBX = on * 256 + off;
RMI.ECX = total;
memset(&sregs, 0, sizeof(sregs));
regs.w.ax = 0x0300; // DPMI: simulate interrupt
regs.w.bx = MOUSE_INT;
regs.w.cx = 0;
regs.x.edi = FP_OFF(&RMI);
sregs.es = FP_SEG(&RMI);
int386x(DPMI_INT, ®s, ®s, &sregs);
}