source: abuse/branches/pd/imlib/port/dos4gw/joystick.c @ 528

Last change on this file since 528 was 49, checked in by Sam Hocevar, 15 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1#include "joy.hpp"
2#include <stdio.h>
3#include <string.h>
4#include <dos.h>
5#include <stdlib.h>
6
7
8int use_joy=1,joy_centx=50,joy_centy=50;    // which joystick do you want to use?
9               
10int joy_init(int argc, char **argv)
11{
12  int i; 
13  for (i=1;i<argc;i++)
14    if (!strcmp(argv[i],"-joy"))
15      use_joy=1;
16    else if (!strcmp(argv[i],"-joy2"))
17      use_joy=2;
18    else if (!strcmp(argv[i],"-nojoy"))
19      use_joy=0;
20
21  return use_joy;
22}             
23
24void joy_status(int &b1, int &b2, int &b3, int &xv, int &yv)
25{
26  if (use_joy)   // make sure that we detected one before
27  {
28    union REGS inregs,outregs;
29    inregs.w.ax=0x8400;
30    inregs.w.dx=0;
31    int386(0x15,&inregs,&outregs);
32
33    int b;
34    if (use_joy==1)   
35      b=((0xff^outregs.w.ax)&0x30)>>4;
36    else
37      b=((0xff^outregs.w.ax)&0xc0)>>4;
38    b1=b&1;
39    b2=b&2;     
40    b3=0;
41
42
43    inregs.w.ax=0x8400;
44    inregs.w.dx=1;
45    int386(0x15,&inregs,&outregs);   // now read the movement
46
47    if (use_joy==1)
48    {
49      xv=((int)inregs.w.ax-(int)joy_centx)*2/joy_centx;
50      yv=((int)inregs.w.bx-(int)joy_centy)*2/joy_centy;
51    } else
52    {
53      xv=((int)inregs.w.cx-(int)joy_centx)*2/joy_centx;
54      yv=((int)inregs.w.dx-(int)joy_centy)*2/joy_centy;
55    }   
56  }
57  else xv=yv=b1=b2=b3=0;
58}
59
60
61void joy_calibrate()
62{
63  if (use_joy)
64  {
65    union REGPACK regs;
66    regs.w.ax=0x8400;
67    regs.w.dx=0x0001;
68    intr(0x15,&regs);   // now read the movement
69
70    if (use_joy==1)
71    {
72      joy_centx=(int)regs.w.ax;
73      joy_centy=(int)regs.w.bx;
74    } else
75    {
76      joy_centx=(int)regs.w.cx;
77      joy_centy=(int)regs.w.dx;
78    }   
79  }
80}
81
82
83
84
85
Note: See TracBrowser for help on using the repository browser.