| 1 | /* $Id: joyos2.cpp,v 1.5 2003-04-02 12:59:23 sandervl Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * OS/2 Joystick apis
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright 1999 Przemysaw Dobrowolski <dobrawka@asua.org.pl>
|
|---|
| 6 | *
|
|---|
| 7 | *
|
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 9 | *
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | /****************************************************************************
|
|---|
| 14 | * Includes *
|
|---|
| 15 | ****************************************************************************/
|
|---|
| 16 |
|
|---|
| 17 | #define INCL_BASE
|
|---|
| 18 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
|---|
| 19 | #include <misc.h>
|
|---|
| 20 | #include "joyos2.h"
|
|---|
| 21 |
|
|---|
| 22 | #define DBG_LOCALLOG DBG_joyos2
|
|---|
| 23 | #include "dbglocal.h"
|
|---|
| 24 |
|
|---|
| 25 | #define GAMEPDDNAME "GAME$"
|
|---|
| 26 |
|
|---|
| 27 | #define IOCTL_JOYSTICK 0x80 // IOCTL's
|
|---|
| 28 |
|
|---|
| 29 | // IOCTL wraper functions
|
|---|
| 30 | #define GAME_GET_PARMS 0x02
|
|---|
| 31 | #define GAME_GET_CALIB 0x04
|
|---|
| 32 | #define GAME_SET_CALIB 0x05
|
|---|
| 33 | #define GAME_GET_STATUS 0x10
|
|---|
| 34 |
|
|---|
| 35 | #define MAXJOYDRIVERS 2 // GAME$ knows only 2 joysticks
|
|---|
| 36 |
|
|---|
| 37 | //******************************************************************************
|
|---|
| 38 | //******************************************************************************
|
|---|
| 39 | LONG JoyOpen(HANDLE *phGame)
|
|---|
| 40 | {
|
|---|
| 41 | ULONG action;
|
|---|
| 42 | APIRET rc;
|
|---|
| 43 |
|
|---|
| 44 | if (phGame==NULL)
|
|---|
| 45 | return -1;
|
|---|
| 46 |
|
|---|
| 47 | rc = DosOpen( GAMEPDDNAME,
|
|---|
| 48 | phGame,
|
|---|
| 49 | &action,
|
|---|
| 50 | 0,
|
|---|
| 51 | FILE_READONLY,
|
|---|
| 52 | FILE_OPEN,
|
|---|
| 53 | OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE,
|
|---|
| 54 | NULL );
|
|---|
| 55 |
|
|---|
| 56 | return (rc);
|
|---|
| 57 | }
|
|---|
| 58 | //******************************************************************************
|
|---|
| 59 | //******************************************************************************
|
|---|
| 60 | LONG JoyGetParams(HANDLE hGame, GAME_PARM_STRUCT *pGameParams)
|
|---|
| 61 | {
|
|---|
| 62 | ULONG dataLen;
|
|---|
| 63 | APIRET rc;
|
|---|
| 64 |
|
|---|
| 65 | dataLen = sizeof( *pGameParams );
|
|---|
| 66 | rc = DosDevIOCtl( hGame,
|
|---|
| 67 | IOCTL_JOYSTICK,
|
|---|
| 68 | GAME_GET_PARMS, // 0x80, 0x02
|
|---|
| 69 | NULL,
|
|---|
| 70 | 0,
|
|---|
| 71 | NULL,
|
|---|
| 72 | pGameParams,
|
|---|
| 73 | dataLen,
|
|---|
| 74 | &dataLen);
|
|---|
| 75 | return (rc);
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | //******************************************************************************
|
|---|
| 79 | //******************************************************************************
|
|---|
| 80 | // For each stick:
|
|---|
| 81 | // tell user to centre joystick and press button
|
|---|
| 82 | // call get status with wait
|
|---|
| 83 | // tell user to move to upper left and press button
|
|---|
| 84 | // call get status with wait
|
|---|
| 85 | // tell user to move to lower right and press button
|
|---|
| 86 | // call get status with wait
|
|---|
| 87 | // Then call set calibration IOCTL with these values
|
|---|
| 88 | LONG JoyCalibrate(HANDLE hGame, GAME_CALIB_STRUCT gameCalib)
|
|---|
| 89 | {
|
|---|
| 90 | ULONG parmLen;
|
|---|
| 91 | APIRET rc;
|
|---|
| 92 |
|
|---|
| 93 | parmLen = sizeof( gameCalib );
|
|---|
| 94 | rc = DosDevIOCtl( hGame,
|
|---|
| 95 | IOCTL_JOYSTICK,
|
|---|
| 96 | GAME_SET_CALIB, // 0x80, 0x05
|
|---|
| 97 | &gameCalib,
|
|---|
| 98 | parmLen,
|
|---|
| 99 | &parmLen,
|
|---|
| 100 | NULL,
|
|---|
| 101 | 0,
|
|---|
| 102 | NULL );
|
|---|
| 103 | return (rc);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | //******************************************************************************
|
|---|
| 107 | //******************************************************************************
|
|---|
| 108 | LONG JoyGetStatus( HANDLE hGame, GAME_STATUS_STRUCT *pGameStatus )
|
|---|
| 109 | {
|
|---|
| 110 | ULONG dataLen;
|
|---|
| 111 | APIRET rc;
|
|---|
| 112 |
|
|---|
| 113 | dataLen = sizeof( *pGameStatus );
|
|---|
| 114 | rc = DosDevIOCtl( hGame,
|
|---|
| 115 | IOCTL_JOYSTICK,
|
|---|
| 116 | GAME_GET_STATUS, // 0x80, 0x10
|
|---|
| 117 | NULL,
|
|---|
| 118 | 0,
|
|---|
| 119 | NULL,
|
|---|
| 120 | pGameStatus,
|
|---|
| 121 | dataLen,
|
|---|
| 122 | &dataLen );
|
|---|
| 123 | return (rc);
|
|---|
| 124 | }
|
|---|
| 125 | //******************************************************************************
|
|---|
| 126 | //******************************************************************************
|
|---|
| 127 | LONG JoyClose( HANDLE hGame )
|
|---|
| 128 | {
|
|---|
| 129 | APIRET rc;
|
|---|
| 130 |
|
|---|
| 131 | rc = DosClose( hGame );
|
|---|
| 132 |
|
|---|
| 133 | return (rc);
|
|---|
| 134 | }
|
|---|
| 135 | //******************************************************************************
|
|---|
| 136 | //******************************************************************************
|
|---|
| 137 | LONG JoyGetCalValues( HANDLE hGame, GAME_CALIB_STRUCT *pGameCalib )
|
|---|
| 138 | {
|
|---|
| 139 | ULONG dataLen;
|
|---|
| 140 | APIRET rc;
|
|---|
| 141 |
|
|---|
| 142 | dataLen = sizeof( *pGameCalib );
|
|---|
| 143 | rc = DosDevIOCtl( hGame,
|
|---|
| 144 | IOCTL_JOYSTICK,
|
|---|
| 145 | GAME_GET_CALIB, // 0x80, 0x04
|
|---|
| 146 | NULL,
|
|---|
| 147 | 0,
|
|---|
| 148 | NULL,
|
|---|
| 149 | pGameCalib,
|
|---|
| 150 | dataLen,
|
|---|
| 151 | &dataLen);
|
|---|
| 152 |
|
|---|
| 153 | return (rc);
|
|---|
| 154 | }
|
|---|
| 155 | //******************************************************************************
|
|---|
| 156 | //******************************************************************************
|
|---|
| 157 | LONG JoyInstalled(USHORT wID)
|
|---|
| 158 | {
|
|---|
| 159 | BOOL flReturn=1; // MMSYSERR_NODRIVER
|
|---|
| 160 | HANDLE hJoy;
|
|---|
| 161 | APIRET rc;
|
|---|
| 162 | GAME_PARM_STRUCT GameParams;
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 | rc=JoyOpen(&hJoy);
|
|---|
| 166 | if ( rc==0 )
|
|---|
| 167 | {
|
|---|
| 168 | JoyGetParams(hJoy,&GameParams);
|
|---|
| 169 | JoyClose(hJoy);
|
|---|
| 170 |
|
|---|
| 171 | if (( wID == 0 ) && (GameParams.useA > 0))
|
|---|
| 172 | flReturn=0; //
|
|---|
| 173 | else
|
|---|
| 174 | if (( wID == 1 ) && (GameParams.useB > 0))
|
|---|
| 175 | flReturn=0;
|
|---|
| 176 | else
|
|---|
| 177 | flReturn=167; // JOYERR_UNPLUGGED
|
|---|
| 178 | }
|
|---|
| 179 | return (flReturn);
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|