~ubuntu-branches/ubuntu/karmic/rott/karmic-proposed

« back to all changes in this revision

Viewing changes to rott/rt_swift.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabian Greffrath
  • Date: 2008-01-27 20:00:00 UTC
  • mfrom: (1.1.1 upstream) (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080127200000-myle9y0099o45sfv
Tags: 1.0+dfsg-2
* debian/patches/01-custom-datapath.dpatch,
  debian/patches/13-improve-makefile.dpatch:
  + Changed DATADIR back to "/usr/share/games/rott/".

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Copyright (C) 1994-1995 Apogee Software, Ltd.
3
 
 
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.
8
 
 
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.
12
 
 
13
 
See the GNU General Public License for more details.
14
 
 
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.
18
 
 
19
 
*/
20
 
//****************************************************************************
21
 
//
22
 
// RT_SWIFT.C
23
 
//
24
 
// SWIFT services module - for CYBERMAN use in ROTT.
25
 
//
26
 
//****************************************************************************
27
 
 
28
 
 
29
 
#include <stddef.h>
30
 
#include <stdio.h>
31
 
#include <stdlib.h>
32
 
#include <string.h>
33
 
 
34
 
#ifdef DOS
35
 
#include <dos.h>
36
 
#endif
37
 
 
38
 
#include "rt_def.h"
39
 
#include "rt_swift.h"
40
 
#include "_rt_swft.h"
41
 
//MED
42
 
#include "memcheck.h"
43
 
 
44
 
 
45
 
#ifdef DOS
46
 
 
47
 
//****************************************************************************
48
 
//
49
 
// SWIFT_Initialize ()
50
 
//
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!
54
 
//
55
 
//****************************************************************************
56
 
 
57
 
int SWIFT_Initialize (void)
58
 
{
59
 
   SWIFT_StaticData sdBuf;
60
 
   int fSwift = 0;
61
 
 
62
 
   if (fActive)                     // SWIFT extensions already active
63
 
   {
64
 
#ifdef DEGUB
65
 
      SoftError( "SWIFT_Initialize: Already active.\n");
66
 
      SoftError( "SWIFT_Initialize: returns TRUE\n");
67
 
#endif
68
 
      return (1);
69
 
   }
70
 
 
71
 
   nAttached = SWIFT_DEV_NONE;
72
 
 
73
 
 
74
 
   if (_dos_getvect(0x33) == NULL)  // No mouse driver loaded
75
 
   {
76
 
#ifdef DBUG
77
 
      SoftError( "SWIFT_Initialize: No mouse driver loaded.\n");
78
 
      SoftError( "SWIFT_Initialize: returns FALSE\n");
79
 
#endif
80
 
      return (0);
81
 
   }
82
 
 
83
 
 
84
 
   // Reset the mouse and driver
85
 
   AX (regs) = 0;
86
 
   int386( 0x33, &regs, &regs);
87
 
 
88
 
   if (AX (regs) == 0)
89
 
   {                                // no mouse
90
 
#ifdef DBUG
91
 
      SoftError( "SWIFT_Initialize: No pointing device attached.\n");
92
 
      SoftError( "SWIFT_Initialize: returns FALSE\n");
93
 
#endif
94
 
      return (0);
95
 
   }
96
 
 
97
 
#ifdef DBUG
98
 
   AX (regs) = 36;   // Get Mouse Information
99
 
   BX (regs) = 0xffff;
100
 
   CX (regs) = 0xffff;
101
 
   DX (regs) = 0xffff;
102
 
   int386 (0x33, &regs, &regs);
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);
110
 
#endif
111
 
 
112
 
 
113
 
   // allocate a DOS real-mode buffer
114
 
   pdosmem = allocDOS(DOSMEMSIZE, &segment, &selector);
115
 
   if (!pdosmem)
116
 
   {
117
 
#ifdef DBUG
118
 
      SoftError( "SWIFT_Initialize: DOS Alloc failed!\n");
119
 
      SoftError( "SWIFT_Initialize: returns FALSE\n");
120
 
#endif
121
 
      return (0);
122
 
   }
123
 
 
124
 
//
125
 
// SWIFT device supported and attached
126
 
//
127
 
   if (SWIFT_GetStaticDeviceInfo (&sdBuf))
128
 
      fSwift = 1;
129
 
 
130
 
 
131
 
   if (!fSwift)
132
 
   {  // SWIFT functions not present
133
 
#ifdef DBUG
134
 
      SoftError( "SWIFT_Initialize: no SWIFT support in mouse driver.\n");
135
 
#endif
136
 
   }
137
 
   else
138
 
      if (sdBuf.deviceType == SWIFT_DEV_NONE)
139
 
      {
140
 
#ifdef DBUG
141
 
         SoftError( "SWIFT_Initialize: no SWIFT device connected.\n");
142
 
#endif
143
 
      }
144
 
      else
145
 
      {
146
 
         nAttached = sdBuf.deviceType;
147
 
#ifdef DBUG
148
 
         SoftError( "SWIFT_Initialize: ");
149
 
 
150
 
         switch (nAttached)
151
 
         {
152
 
            case SWIFT_DEV_CYBERMAN:
153
 
               SoftError( "CyberMan %d.%02d connected.\n",
154
 
                                sdBuf.majorVersion, sdBuf.minorVersion);
155
 
            break;
156
 
 
157
 
            default:
158
 
               SoftError( "Unknown SWIFT device (type %d) connected.\n",
159
 
                                nAttached);
160
 
            break;
161
 
         }
162
 
#endif
163
 
      fActive = 1;
164
 
   }
165
 
 
166
 
   if (!fActive)
167
 
   {                    // activation of SWIFT module failed for some reason
168
 
      if (pdosmem)
169
 
      {                 // if DOS buffer was allocated, free it
170
 
         freeDOS(selector);
171
 
         pdosmem = 0;
172
 
      }
173
 
   }
174
 
 
175
 
#ifdef DBUG
176
 
   SoftError( "SWIFT_Initialize: returns %s.\n", (fActive ? "TRUE" : "FALSE"));
177
 
#endif
178
 
   return fActive;
179
 
}
180
 
 
181
 
 
182
 
 
183
 
//****************************************************************************
184
 
//
185
 
// SWIFT_Terminate ()
186
 
//
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.
191
 
//
192
 
//****************************************************************************
193
 
 
194
 
void SWIFT_Terminate (void)
195
 
{
196
 
#ifdef DBUG
197
 
   SoftError( "SWIFT_Terminate called.\n");
198
 
#endif
199
 
 
200
 
   if (fActive)
201
 
   {
202
 
     // free DOS buffer
203
 
      if (pdosmem)
204
 
      {
205
 
         freeDOS(selector);
206
 
         pdosmem = 0;
207
 
      }
208
 
 
209
 
      fActive = 0;
210
 
   }
211
 
}
212
 
 
213
 
 
214
 
//****************************************************************************
215
 
//
216
 
// SWIFT_GetAttachedDevice ()
217
 
//
218
 
// Returns the device-type code for the attached SWIFT device, if any.
219
 
//
220
 
//****************************************************************************
221
 
 
222
 
int SWIFT_GetAttachedDevice (void)
223
 
{
224
 
   return (nAttached);
225
 
}
226
 
 
227
 
 
228
 
 
229
 
//****************************************************************************
230
 
//
231
 
// SWIFT_GetStaticDeviceInfo ()
232
 
//
233
 
// Reads static device data.
234
 
//
235
 
//****************************************************************************
236
 
 
237
 
int SWIFT_GetStaticDeviceInfo (SWIFT_StaticData far *psd)
238
 
{
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
244
 
 
245
 
   *psd = *(SWIFT_StaticData *)pdosmem;   // then copy into caller's buffer
246
 
   return (RMI.ax == 1);                  // return success
247
 
}
248
 
 
249
 
 
250
 
 
251
 
//****************************************************************************
252
 
//
253
 
// SWIFT_Get3DStatus ()
254
 
//
255
 
// Read the current input state of the device.
256
 
//
257
 
//****************************************************************************
258
 
 
259
 
 
260
 
void SWIFT_Get3DStatus (SWIFT_3DStatus far *pstat)
261
 
{
262
 
#ifdef DBUG
263
 
   if (!fActive)
264
 
   {
265
 
      SoftError( "SWIFT_Get3DStatus: SWIFT module not active!\n");
266
 
   }
267
 
#endif
268
 
 
269
 
   memset (&RMI, 0, sizeof (RMI));
270
 
   RMI.ax = 0x5301;
271
 
   RMI.es = segment;
272
 
   RMI.dx = 0;
273
 
   MouseInt(&RMI);
274
 
   *pstat = *(SWIFT_3DStatus *)pdosmem;
275
 
}
276
 
 
277
 
 
278
 
 
279
 
 
280
 
//****************************************************************************
281
 
//
282
 
// SWIFT_TactileFeedback ()
283
 
//
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.
288
 
//
289
 
//****************************************************************************
290
 
 
291
 
void SWIFT_TactileFeedback (int d, int on, int off)
292
 
{
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);
297
 
   RMI.cx = d / 40;
298
 
   MouseInt (&RMI);
299
 
 
300
 
#ifdef DBUG
301
 
   SoftError( "SWIFT_TactileFeedback (dur=%d ms, on=%d ms, off=%d ms)\n",
302
 
                   d / 40 * 40, on/5*5, off/5*5);
303
 
#endif
304
 
}
305
 
 
306
 
 
307
 
 
308
 
//****************************************************************************
309
 
//
310
 
// SWIFT_GetDynamicDeviceData ()
311
 
//
312
 
// Returns Dynamic Device Data word - see SDD_* above
313
 
//
314
 
//****************************************************************************
315
 
 
316
 
unsigned SWIFT_GetDynamicDeviceData (void)
317
 
{
318
 
   memset (&RMI, 0, sizeof(RMI));
319
 
   RMI.ax = 0x53C2;                       // SWIFT: Get Dynamic Device Data
320
 
   MouseInt (&RMI);
321
 
   return ((unsigned)RMI.ax);
322
 
}
323
 
 
324
 
 
325
 
//****************************************************************************
326
 
//
327
 
// MouseInt ()
328
 
//
329
 
// Generate a call to the mouse driver (interrupt 33h) in real mode,
330
 
// using the DPMI function 'Simulate Real-Mode Interrupt'.
331
 
//
332
 
//****************************************************************************
333
 
 
334
 
void MouseInt (struct rminfo *prmi)
335
 
{
336
 
   memset (&sregs, 0, sizeof (sregs));
337
 
   AX (regs) = 0x0300;                    // DPMI: simulate interrupt
338
 
   BX (regs) = MOUSE_INT;
339
 
   CX (regs) = 0;
340
 
   DI (regs) = FP_OFF (prmi);
341
 
   sregs.es = FP_SEG (prmi);
342
 
   int386x( DPMI_INT, &regs, &regs, &sregs );
343
 
}
344
 
 
345
 
 
346
 
//****************************************************************************
347
 
//
348
 
// freeDOS ()
349
 
//
350
 
// Release real-mode DOS memory block via DPMI
351
 
//
352
 
//****************************************************************************
353
 
 
354
 
void freeDOS (short sel)
355
 
{
356
 
   AX(regs) = 0x0101;      // DPMI free DOS memory
357
 
   DX(regs) = sel;
358
 
 
359
 
   int386( DPMI_INT, &regs, &regs);
360
 
}
361
 
 
362
 
 
363
 
//****************************************************************************
364
 
//
365
 
// allocDOS ()
366
 
//
367
 
// Allocate a real-mode DOS memory block via DPMI
368
 
//
369
 
//****************************************************************************
370
 
 
371
 
void far *allocDOS (unsigned nbytes, short *pseg, short *psel)
372
 
{
373
 
   unsigned npara = (nbytes + 15) / 16;
374
 
   void far *pprot;
375
 
   pprot = NULL;
376
 
   *pseg = 0;        // assume will fail
377
 
   *psel = 0;
378
 
 
379
 
   // DPMI call 100h allocates DOS memory
380
 
   segread (&sregs);
381
 
   AX (regs) = 0x0100;        // DPMI: Allocate DOS Memory
382
 
   BX (regs) = npara;         // number of paragraphs to alloc
383
 
   int386( DPMI_INT, &regs, &regs);
384
 
 
385
 
   if (regs.w.cflag == 0)
386
 
   {
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);
393
 
   }
394
 
   return pprot;
395
 
}
396
 
 
397
 
#else
398
 
 
399
 
/* This isn't of much use in Linux. */
400
 
 
401
 
int SWIFT_Initialize (void)
402
 
{
403
 
        STUB_FUNCTION;
404
 
        
405
 
        return 0;
406
 
}
407
 
 
408
 
void SWIFT_Terminate (void)
409
 
{
410
 
        STUB_FUNCTION;
411
 
}
412
 
 
413
 
void SWIFT_Get3DStatus (SWIFT_3DStatus far *pstat)
414
 
{
415
 
        STUB_FUNCTION;
416
 
}
417
 
 
418
 
void SWIFT_TactileFeedback (int d, int on, int off)
419
 
{
420
 
        STUB_FUNCTION;
421
 
}
422
 
 
423
 
unsigned SWIFT_GetDynamicDeviceData (void)
424
 
{
425
 
        STUB_FUNCTION;
426
 
        
427
 
        return 0;
428
 
}
429
 
 
430
 
#endif