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