⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 joystick.txt

📁 二~六键游戏操纵杆(gamepad)控制程序
💻 TXT
字号:
-----BEGIN PGP SIGNED MESSAGE-----

                         Joystick Library for Dos v 1.1

                         by Simone Zanella Productions

Disclaimer
- ----------

This is freeware: use it as you like, but ALWAYS include the original
author's name in the docs of your program. I don't claim that this
program is useful, I don't warrant anything: use it at your own risk.
You can freely copy and distribute these files, as long as you don't
remove my name from them.


Description
- -----------

This small package is aimed at those programmers who would like to add
joystick support to some of their programs, but don't want to waste
too much time over this feature. With just two functions, you can test
the status of both joysticks, including fire buttons.

IF YOU ARE NOT A PROGRAMMER, you could take a look at JoyEmu by the same
author; this keyboard emulator has a full featured control panel, let you 
add joystick support to existing programs without modifying the code and 
is Dos and Windows 95 compatible.

The code for these routines is taken from JoyEmu's source code.

Together with this file you should have received also:

JOYSTICK.C    Joystick routines
JOYSTICK.H    Header file for using routines in your program
JTEST.C       Sample program that shows the status of both joysticks
JTEST.MAK     Make file for JTEST.C (Borland C)
MAKEFILE      Make file for JTEST.C (DJGPP)
JTEST.EXE     Compiled version of JTEST

These files contain the source code for a simple joystick routine
that can be used to add joystick support to any program.

The code compiles without errors under:

  Borland C (version 3.1 tested)
  DJGPP (version 2.7.2.1 tested)

but should be fairly portable to other Dos C compilers.


How to add joystick support
- ---------------------------

The usage is very simple:

- - include "joystick.h" at the beginning of your program and
  compile and link the module "joystick.c"

- - at program startup, use:

  unsigned char j, mode, skipjoy;

  // Set mode to the kind of joystick requested:
  // JOY_2BUTTONS    standard 2-buttons joysticks
  // JOY_4BUTTONS    4-buttons joysticks (fire 3 and 4 are other joystick's
  //                 fire buttons)
  // JOY_6BUTTONS    6-buttons joystick (fire 3 & 4 as above, fire 5 and 6
  //                 connected to joystick #2 directions)
  //
  // Set skipjoy to:
  // JOY_NONE    if all joysticks connected should be detected and calibrated;
  // JOY_SECOND  if only first joystick is used and thus should be calibrated.
  //
  // Set calibfile to the name of a file to be used for saving/reloading
  // calibration (NULL to force re-calibration at each run).

  j = InstallJoystick(mode, skipjoy, calibfile);

- - use the value j to determine number of joysticks connected:

  j & JOY_FIRST    first joystick is present
  j & JOY_SECOND   second joystick is present
  j & JOY_BOTH     both joysticks present (or one 6-buttons joystick)

- - when you want to read the joystick(s), use:

  unsigned int fj, sj;

  ReadJoystick(&fj, &sj);

  Then, you can determine if a direction is activated by:

  fj & JOY_xx

  where "xx" can be: UP, DN (down), LT (left), RT (right)

  You can test the fire buttons in a similar way:

  fj & JOY_AF    first button
  fj & JOY_BF    second button
  fj & JOY_CF    third button (only when mode = JOY_4BUTTONS)
  fj & JOY_DF    fourth button (only when mode = JOY_4BUTTONS)
  fj & JOY_EF    fifth button (only joystick 1, when mode = JOY_6BUTTONS)
  fj & JOY_FF    sixth button (only joystick 1, when mode = JOY_6BUTTONS)

  Of course, replace "fj" above with "sj" to test second joystick.

If you want to poll joystick at regular intervals, you can chain the
system timer (int 8).

The calibration configuration is saved and reloaded automatically when
you specify 'calibfile' in InstallJoystick; user is not warned, however,
when configuration cannot be saved successfully. Joystick mode is saved
in the configuration; if specified mode or the mode saved is JOY_6BUTTONS
and the two modes don't match, the routine re-calibrate the joystick;
the same happens if a new joystick is found, or if incorrect calibration
is detected (this is tricky: it is possible that different joysticks have
similar but not identical calibration, that is not detected by this routine).
If you want to re-calibrate the joystick(s), just delete the configuration
file. If your program needs more than two fire buttons, be sure to leave
an option for those with 2-buttons joysticks, so that they can use the
keyboard for the missing buttons. If your program uses just one joystick,
use JOY_SECOND as the value for parameter skipjoy.

- ---

(C) 1997 Simone Zanella Productions.

E-mail: szanella@dsi.unive.it
        zanella@prometeo.it

Web:    http://www.dsi.unive.it/~szanella/index.htm
        http://members.tripod.com/~szanella/index.htm

Last modified: June 15th, 1997

Changes from version 1.0:

- - changed calibration to manual, to avoid incompatibilities and
  to get a faster reading;
- - added support for 4 and 6 buttons joysticks;
- - added parameter mode to function InstallJoystick, to set
  the number of buttons for joysticks;
- - added parameter skipjoy to function InstallJoystick, to skip
  installation/calibration of one joystick;
- - added parameter calibfile to function InstallJoystick, to
  allow calibration saving/reloading;
- - changed to integer parameters 'first' and 'second' in function
  ReadJoystick, to keep flags for fire buttons 5 and 6;
- - removed tolerances from function InstallJoystick.


- -----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.2i

mQCNAzARNUQAAAEEAMTn+IgTuJ5Ei99lzFa6D6GCDYPUimdSQ2I2keFCVG2sCVfB
uejwgdPp+u/mlwJDE2wZpAUfgHe8E3N/vmfO6bl0RxOc1Hkl0mc/np5/F4wZoeOB
GcaEpwJLkKlFoE93p8Bh/UwUNo9UaKjfwx0mqP9G+XgiVowo7NEsAHa/+Bl9AAUR
tCpTaW1vbmUgWmFuZWxsYSA8c3phbmVsbGFAbW9vLmRzaS51bml2ZS5pdD6JAJUD
BRAwETVz0SwAdr/4GX0BAXjLA/9IZD5mT/BHdRfDvH6AnFwaxqAuluhCcycchW0A
/SOUJPsmFnFjGUoCFrur603rEUJpR/JsZpVOXaQHcNSuitB2msDu8YZyrVPgcV86
vGptHkX31GrfIK8RR4hHRtt0suUBWZBDJRfLNbq7KMKxfNF3h4wRjC1NBzzU0orM
mj9d2A==
=HOga
- -----END PGP PUBLIC KEY BLOCK-----


-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: cp850

iQCVAwUBM6bJudEsAHa/+Bl9AQHMQAQAruEzCndGuXhEu3sEgkjDJAERpaF+Um96
Fo79ViL3LUiR3pinxYXaCn0WchMZl2Si6WCoeScOZM1r/R8H9jhT/1D1xs26Awxt
W8XnJOdqPBsdYNciZm7ZBW8cnx6l6Om4BNbvYUv8Qz8+epnIjiwdj7otl5cikaNG
qwHjIKZFsA4=
=tTkz
-----END PGP SIGNATURE-----

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -