2
Copyright (C) 1994-1995 Apogee Software, Ltd.
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
See the GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
//****************************************************************************
24
// SWIFT services module - for CYBERMAN use in ROTT.
26
//****************************************************************************
47
//****************************************************************************
49
// SWIFT_Initialize ()
51
// Test for presence of SWIFT extensions and SWIFT device.
52
// Returns 1 (TRUE) if SWIFT features are available, 0 otherwise.
53
// Remember to call SWIFT_Terminate() if SWIFT_Initialize succeeds!
55
//****************************************************************************
57
int SWIFT_Initialize (void)
59
SWIFT_StaticData sdBuf;
62
if (fActive) // SWIFT extensions already active
65
SoftError( "SWIFT_Initialize: Already active.\n");
66
SoftError( "SWIFT_Initialize: returns TRUE\n");
71
nAttached = SWIFT_DEV_NONE;
74
if (_dos_getvect(0x33) == NULL) // No mouse driver loaded
77
SoftError( "SWIFT_Initialize: No mouse driver loaded.\n");
78
SoftError( "SWIFT_Initialize: returns FALSE\n");
84
// Reset the mouse and driver
86
int386( 0x33, ®s, ®s);
91
SoftError( "SWIFT_Initialize: No pointing device attached.\n");
92
SoftError( "SWIFT_Initialize: returns FALSE\n");
98
AX (regs) = 36; // Get Mouse Information
102
int386 (0x33, ®s, ®s);
103
SoftError( "SWIFT_Initialize: driver version %d.%02d\n", regs.h.bh, regs.h.bl);
104
SoftError( "SWIFT_Initialize: %s mouse using IRQ %d\n",
105
(regs.h.ch==1) ? "bus" :
106
(regs.h.ch==2) ? "serial" :
107
(regs.h.ch==3) ? "inport" :
108
(regs.h.ch==4) ? "PS/2" :
109
"unknown", regs.h.cl);
113
// allocate a DOS real-mode buffer
114
pdosmem = allocDOS(DOSMEMSIZE, &segment, &selector);
118
SoftError( "SWIFT_Initialize: DOS Alloc failed!\n");
119
SoftError( "SWIFT_Initialize: returns FALSE\n");
125
// SWIFT device supported and attached
127
if (SWIFT_GetStaticDeviceInfo (&sdBuf))
132
{ // SWIFT functions not present
134
SoftError( "SWIFT_Initialize: no SWIFT support in mouse driver.\n");
138
if (sdBuf.deviceType == SWIFT_DEV_NONE)
141
SoftError( "SWIFT_Initialize: no SWIFT device connected.\n");
146
nAttached = sdBuf.deviceType;
148
SoftError( "SWIFT_Initialize: ");
152
case SWIFT_DEV_CYBERMAN:
153
SoftError( "CyberMan %d.%02d connected.\n",
154
sdBuf.majorVersion, sdBuf.minorVersion);
158
SoftError( "Unknown SWIFT device (type %d) connected.\n",
167
{ // activation of SWIFT module failed for some reason
169
{ // if DOS buffer was allocated, free it
176
SoftError( "SWIFT_Initialize: returns %s.\n", (fActive ? "TRUE" : "FALSE"));
183
//****************************************************************************
185
// SWIFT_Terminate ()
187
// Free resources required for SWIFT support. If SWIFT_Initialize has
188
// not been called, or returned FALSE, this function does nothing.
189
// SWIFT_Terminate should always be called at some time after a call to
190
// SWIFT_Initialize has returned TRUE.
192
//****************************************************************************
194
void SWIFT_Terminate (void)
197
SoftError( "SWIFT_Terminate called.\n");
214
//****************************************************************************
216
// SWIFT_GetAttachedDevice ()
218
// Returns the device-type code for the attached SWIFT device, if any.
220
//****************************************************************************
222
int SWIFT_GetAttachedDevice (void)
229
//****************************************************************************
231
// SWIFT_GetStaticDeviceInfo ()
233
// Reads static device data.
235
//****************************************************************************
237
int SWIFT_GetStaticDeviceInfo (SWIFT_StaticData far *psd)
239
memset (&RMI, 0, sizeof (RMI));
240
RMI.ax = 0x53C1; // SWIFT: Get Static Device Data
241
RMI.es = segment; // DOS buffer real-mode segment
242
RMI.dx = 0; // " " " " offset
243
MouseInt (&RMI); // get data into DOS buffer
245
*psd = *(SWIFT_StaticData *)pdosmem; // then copy into caller's buffer
246
return (RMI.ax == 1); // return success
251
//****************************************************************************
253
// SWIFT_Get3DStatus ()
255
// Read the current input state of the device.
257
//****************************************************************************
260
void SWIFT_Get3DStatus (SWIFT_3DStatus far *pstat)
265
SoftError( "SWIFT_Get3DStatus: SWIFT module not active!\n");
269
memset (&RMI, 0, sizeof (RMI));
274
*pstat = *(SWIFT_3DStatus *)pdosmem;
280
//****************************************************************************
282
// SWIFT_TactileFeedback ()
284
// Generates tactile feedback to user.
285
// d = duration of tactile burst, in milliseconds.
286
// on = motor on-time per cycle, in milliseconds.
287
// off = motor off-time per cycle, in milliseconds.
289
//****************************************************************************
291
void SWIFT_TactileFeedback (int d, int on, int off)
293
// Use DPMI call 300h to issue mouse interrupt
294
memset (&RMI, 0, sizeof(RMI));
295
RMI.ax = 0x5330; // SWIFT: Get Position & Buttons
296
RMI.bx = (on / 5) << 8 + (off / 5);
301
SoftError( "SWIFT_TactileFeedback (dur=%d ms, on=%d ms, off=%d ms)\n",
302
d / 40 * 40, on/5*5, off/5*5);
308
//****************************************************************************
310
// SWIFT_GetDynamicDeviceData ()
312
// Returns Dynamic Device Data word - see SDD_* above
314
//****************************************************************************
316
unsigned SWIFT_GetDynamicDeviceData (void)
318
memset (&RMI, 0, sizeof(RMI));
319
RMI.ax = 0x53C2; // SWIFT: Get Dynamic Device Data
321
return ((unsigned)RMI.ax);
325
//****************************************************************************
329
// Generate a call to the mouse driver (interrupt 33h) in real mode,
330
// using the DPMI function 'Simulate Real-Mode Interrupt'.
332
//****************************************************************************
334
void MouseInt (struct rminfo *prmi)
336
memset (&sregs, 0, sizeof (sregs));
337
AX (regs) = 0x0300; // DPMI: simulate interrupt
338
BX (regs) = MOUSE_INT;
340
DI (regs) = FP_OFF (prmi);
341
sregs.es = FP_SEG (prmi);
342
int386x( DPMI_INT, ®s, ®s, &sregs );
346
//****************************************************************************
350
// Release real-mode DOS memory block via DPMI
352
//****************************************************************************
354
void freeDOS (short sel)
356
AX(regs) = 0x0101; // DPMI free DOS memory
359
int386( DPMI_INT, ®s, ®s);
363
//****************************************************************************
367
// Allocate a real-mode DOS memory block via DPMI
369
//****************************************************************************
371
void far *allocDOS (unsigned nbytes, short *pseg, short *psel)
373
unsigned npara = (nbytes + 15) / 16;
376
*pseg = 0; // assume will fail
379
// DPMI call 100h allocates DOS memory
381
AX (regs) = 0x0100; // DPMI: Allocate DOS Memory
382
BX (regs) = npara; // number of paragraphs to alloc
383
int386( DPMI_INT, ®s, ®s);
385
if (regs.w.cflag == 0)
387
*pseg = AX (regs); // the real-mode segment
388
*psel = DX (regs); // equivalent protected-mode selector
389
// pprot is the protected mode address of the same allocated block.
390
// The Rational extender maps the 1 MB physical DOS memory into
391
// the bottom of our virtual address space.
392
pprot = (void far *) ((unsigned)*pseg << 4);
399
/* This isn't of much use in Linux. */
401
int SWIFT_Initialize (void)
408
void SWIFT_Terminate (void)
413
void SWIFT_Get3DStatus (SWIFT_3DStatus far *pstat)
418
void SWIFT_TactileFeedback (int d, int on, int off)
423
unsigned SWIFT_GetDynamicDeviceData (void)