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