Annotation of hatari/src/joy.c, revision 1.1.1.15

1.1       root        1: /*
1.1.1.4   root        2:   Hatari - joy.c
1.1       root        3: 
1.1.1.14  root        4:   This file is distributed under the GNU General Public License, version 2
                      5:   or at your option any later version. Read the file gpl.txt for details.
1.1.1.4   root        6: 
                      7:   Joystick routines.
1.1       root        8: 
1.1.1.6   root        9:   NOTE: The ST uses the joystick port 1 as the default controller.
1.1       root       10: */
1.1.1.10  root       11: const char Joy_fileid[] = "Hatari joy.c : " __DATE__ " " __TIME__;
1.1       root       12: 
                     13: #include <SDL.h>
                     14: 
                     15: #include "main.h"
                     16: #include "configuration.h"
1.1.1.6   root       17: #include "ioMem.h"
1.1       root       18: #include "joy.h"
1.1.1.5   root       19: #include "log.h"
1.1.1.12  root       20: #include "screen.h"
1.1.1.2   root       21: #include "video.h"
1.1.1.15! root       22: #include "statusbar.h"
1.1       root       23: 
1.1.1.2   root       24: #define JOY_BUTTON1  1
                     25: #define JOY_BUTTON2  2
1.1       root       26: 
1.1.1.14  root       27: typedef struct
                     28: {
                     29:        int XPos,YPos;                /* the actually read axis values in range of -32768...0...32767 */
                     30:        int XAxisID,YAxisID;          /* the IDs of the physical PC joystick's axis to be used to gain ST joystick axis input */
                     31:        int Buttons;                  /* JOY_BUTTON1 */
                     32: } JOYREADING;
                     33: 
                     34: typedef struct
                     35: {
                     36:     const char *SDLJoystickName;
                     37:     int XAxisID,YAxisID;           /* the IDs associated with a certain SDL joystick */
                     38: } JOYAXISMAPPING;
1.1.1.2   root       39: 
1.1.1.13  root       40: static SDL_Joystick *sdlJoystick[ JOYSTICK_COUNT ] =           /* SDL's joystick structures */
1.1.1.6   root       41: {
                     42:        NULL, NULL, NULL, NULL, NULL, NULL
                     43: };
1.1.1.7   root       44: 
1.1.1.13  root       45: /* Further explanation see JoyInit() */
1.1.1.14  root       46: static JOYAXISMAPPING const *sdlJoystickMapping[ JOYSTICK_COUNT ] =    /* references which axis are actually in use by the selected SDL joystick */
1.1.1.13  root       47: {
                     48:        NULL, NULL, NULL, NULL, NULL, NULL
                     49: };
                     50: 
                     51: static bool bJoystickWorking[ JOYSTICK_COUNT ] =               /* Is joystick plugged in and working? */
1.1.1.6   root       52: {
1.1.1.11  root       53:        false, false, false, false, false, false
1.1.1.13  root       54: };
1.1.1.6   root       55: 
1.1.1.11  root       56: int JoystickSpaceBar = false;           /* State of space-bar on joystick button 2 */
1.1.1.13  root       57: static Uint8 nJoyKeyEmu[ JOYSTICK_COUNT ];
1.1.1.7   root       58: static Uint16 nSteJoySelect;
1.1       root       59: 
                     60: 
                     61: /*-----------------------------------------------------------------------*/
1.1.1.8   root       62: /**
                     63:  * This function initialises the (real) joysticks.
                     64:  */
1.1       root       65: void Joy_Init(void)
                     66: {
1.1.1.13  root       67:        /* Joystick axis mapping table                          */
                     68:        /* Matthias Arndt <[email protected]>               */
                     69:        /* Somehow, not all SDL joysticks are created equal.    */
                     70:        /* Not all pads or sticks use axis 0 for x and axis 1   */
                     71:        /* for y information.                                   */
                     72:        /* This table allows to remap the axis to used.         */
                     73:        /* A joystick is identified by its SDL name and         */
                     74:        /* followed by the X axis to use and the Y axis.        */
                     75:        /* Find out the axis number with the tool jstest.       */
                     76: 
                     77:        /* FIXME: Read those settings from a configuration file and make them tunable from the GUI. */
1.1.1.14  root       78:        static const JOYAXISMAPPING AxisMappingTable [] =
1.1.1.13  root       79:        {
1.1.1.15! root       80:                /* Example entry for mapping joystick axis for a certain device: */
        !            81:                /* USB game pad with ID ID 0079:0011, sold by Speedlink with axis 3 and 4 used */
        !            82:                /*{"USB Gamepad" , 3, 4}, */
1.1.1.14  root       83:                /* Default entry used if no other SDL joystick name does match (should be last of this list) */
1.1.1.13  root       84:                {"*DEFAULT*" , 0, 1},
                     85:        };
                     86: 
1.1.1.14  root       87:        int i, j, nPadsConnected;
1.1.1.13  root       88: 
1.1.1.6   root       89:        /* Initialise SDL's joystick subsystem: */
                     90:        if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0)
                     91:        {
                     92:                Log_Printf(LOG_ERROR, "Could not init joysticks: %s\n", SDL_GetError());
                     93:                return;
                     94:        }
                     95: 
                     96:        /* Scan joystick connection array for working joysticks */
                     97:        nPadsConnected = SDL_NumJoysticks();
1.1.1.13  root       98:        for (i = 0; i < nPadsConnected && i < JOYSTICK_COUNT ; i++)
1.1.1.6   root       99:        {
                    100:                /* Open the joystick for use */
                    101:                sdlJoystick[i] = SDL_JoystickOpen(i);
                    102:                /* Is joystick ok? */
                    103:                if (sdlJoystick[i] != NULL)
                    104:                {
                    105:                        /* Set as working */
1.1.1.11  root      106:                        bJoystickWorking[i] = true;
1.1.1.6   root      107:                        Log_Printf(LOG_DEBUG, "Joystick %i: %s\n", i, SDL_JoystickName(i));
1.1.1.14  root      108:                        /* determine joystick axis mapping for given SDL joystick name, last is default: */
                    109:                        for (j = 0; j < ARRAYSIZE(AxisMappingTable)-1; j++) {
1.1.1.13  root      110:                                /* check if ID string matches the one reported by SDL: */
1.1.1.14  root      111:                                if(strncmp(AxisMappingTable[j].SDLJoystickName, SDL_JoystickName(i), strlen(AxisMappingTable[j].SDLJoystickName)) == 0)
1.1.1.13  root      112:                                        break;
                    113:                        }
                    114: 
1.1.1.14  root      115:                        sdlJoystickMapping[i] = &(AxisMappingTable[j]);
                    116:                        Log_Printf(LOG_DEBUG, "Joystick %i maps axis %d and %d (%s)\n", i, sdlJoystickMapping[i]->XAxisID, sdlJoystickMapping[i]->YAxisID,
                    117:                                        sdlJoystickMapping[i]->SDLJoystickName );
1.1.1.6   root      118:                }
                    119:        }
                    120: 
1.1.1.11  root      121:        JoystickSpaceBar = false;
1.1       root      122: }
                    123: 
                    124: 
1.1.1.2   root      125: /*-----------------------------------------------------------------------*/
1.1.1.8   root      126: /**
                    127:  * Close the (real) joysticks.
                    128:  */
1.1.1.7   root      129: void Joy_UnInit(void)
                    130: {
                    131:        int i, nPadsConnected;
                    132: 
                    133:        nPadsConnected = SDL_NumJoysticks();
                    134: 
1.1.1.13  root      135:        for (i = 0; i < nPadsConnected && i < JOYSTICK_COUNT ; i++)
1.1.1.7   root      136:        {
1.1.1.11  root      137:                if (bJoystickWorking[i] == true)
1.1.1.7   root      138:                {
                    139:                        SDL_JoystickClose(sdlJoystick[i]);
                    140:                }
                    141:        }
                    142: }
                    143: 
                    144: 
                    145: /*-----------------------------------------------------------------------*/
1.1.1.8   root      146: /**
                    147:  * Read details from joystick using SDL calls
                    148:  * NOTE ID is that of SDL
                    149:  */
1.1.1.9   root      150: static bool Joy_ReadJoystick(int nSdlJoyID, JOYREADING *pJoyReading)
1.1.1.6   root      151: {
1.1.1.12  root      152:        /* Joystick is OK, read position from the configured joystick axis */
                    153:        pJoyReading->XPos = SDL_JoystickGetAxis(sdlJoystick[nSdlJoyID], pJoyReading->XAxisID);
                    154:        pJoyReading->YPos = SDL_JoystickGetAxis(sdlJoystick[nSdlJoyID], pJoyReading->YAxisID);
1.1.1.6   root      155:        /* Sets bit #0 if button #1 is pressed: */
                    156:        pJoyReading->Buttons = SDL_JoystickGetButton(sdlJoystick[nSdlJoyID], 0);
                    157:        /* Sets bit #1 if button #2 is pressed: */
                    158:        if (SDL_JoystickGetButton(sdlJoystick[nSdlJoyID], 1))
                    159:                pJoyReading->Buttons |= JOY_BUTTON2;
                    160: 
1.1.1.11  root      161:        return true;
1.1       root      162: }
                    163: 
1.1.1.2   root      164: 
                    165: /*-----------------------------------------------------------------------*/
1.1.1.8   root      166: /**
                    167:  * Read PC joystick and return ST format byte, i.e. lower 4 bits direction
                    168:  * and top bit fire.
                    169:  * NOTE : ID 0 is Joystick 0/Mouse and ID 1 is Joystick 1 (default),
                    170:  *        ID 2 and 3 are STE joypads and ID 4 and 5 are parport joysticks.
                    171:  */
1.1.1.6   root      172: Uint8 Joy_GetStickData(int nStJoyId)
1.1       root      173: {
1.1.1.6   root      174:        Uint8 nData = 0;
                    175:        JOYREADING JoyReading;
                    176:        int nSdlJoyId;
1.1.1.12  root      177:        int nAxes; /* how many joystick axes are on the current selected SDL joystick? */
1.1.1.6   root      178: 
                    179:        nSdlJoyId = ConfigureParams.Joysticks.Joy[nStJoyId].nJoyId;
1.1.1.12  root      180:        nAxes = SDL_JoystickNumAxes(sdlJoystick[nSdlJoyId]);
1.1.1.6   root      181: 
                    182:        /* Are we emulating the joystick via the keyboard? */
                    183:        if (ConfigureParams.Joysticks.Joy[nStJoyId].nJoystickMode == JOYSTICK_KEYBOARD)
                    184:        {
                    185:                /* If holding 'SHIFT' we actually want cursor key movement, so ignore any of this */
                    186:                if ( !(SDL_GetModState()&(KMOD_LSHIFT|KMOD_RSHIFT)) )
                    187:                {
                    188:                        nData = nJoyKeyEmu[nStJoyId];
                    189:                }
                    190:        }
                    191:        else if (ConfigureParams.Joysticks.Joy[nStJoyId].nJoystickMode == JOYSTICK_REALSTICK
                    192:                 && bJoystickWorking[nSdlJoyId])
                    193:        {
1.1.1.12  root      194:                /* get joystick axis from configuration settings and make them plausible */
1.1.1.13  root      195:                JoyReading.XAxisID = sdlJoystickMapping[nSdlJoyId]->XAxisID;
                    196:                JoyReading.YAxisID = sdlJoystickMapping[nSdlJoyId]->YAxisID;
                    197: 
1.1.1.12  root      198:                /* make selected axis IDs plausible */
                    199:                if(  (JoyReading.XAxisID == JoyReading.YAxisID) /* same joystick axis for two directions? */
                    200:                   ||(JoyReading.XAxisID > nAxes)               /* ID for x axis beyond nr of existing axes? */
                    201:                   ||(JoyReading.YAxisID > nAxes)               /* ID for y axis beyond nr of existing axes? */
                    202:                  )
                    203:                {
                    204:                        /* define sane SDL joystick axis defaults and prepare them for saving back to the config file: */
                    205:                        JoyReading.XAxisID = 0;
                    206:                        JoyReading.YAxisID = 1;
                    207:                }
1.1.1.13  root      208: 
1.1.1.12  root      209:                /* Read real joystick and map to emulated ST joystick for emulation */
1.1.1.6   root      210:                if (!Joy_ReadJoystick(nSdlJoyId, &JoyReading))
                    211:                {
1.1.1.12  root      212:                        /* Something is wrong, we cannot read the joystick from SDL */
1.1.1.11  root      213:                        bJoystickWorking[nSdlJoyId] = false;
1.1.1.6   root      214:                        return 0;
                    215:                }
                    216: 
                    217:                /* Directions */
                    218:                if (JoyReading.YPos <= JOYRANGE_UP_VALUE)
1.1.1.11  root      219:                        nData |= ATARIJOY_BITMASK_UP;
1.1.1.6   root      220:                else if (JoyReading.YPos >= JOYRANGE_DOWN_VALUE)
1.1.1.11  root      221:                        nData |= ATARIJOY_BITMASK_DOWN;
1.1.1.6   root      222:                if (JoyReading.XPos <= JOYRANGE_LEFT_VALUE)
1.1.1.11  root      223:                        nData |= ATARIJOY_BITMASK_LEFT;
1.1.1.6   root      224:                else if (JoyReading.XPos >= JOYRANGE_RIGHT_VALUE)
1.1.1.11  root      225:                        nData |= ATARIJOY_BITMASK_RIGHT;
1.1.1.6   root      226: 
                    227:                /* PC Joystick button 1 is set as ST joystick button */
                    228:                if (JoyReading.Buttons & JOY_BUTTON1)
1.1.1.11  root      229:                        nData |= ATARIJOY_BITMASK_FIRE;
1.1.1.6   root      230: 
                    231:                /* Enable PC Joystick button 2 to mimick space bar (For XenonII, Flying Shark etc...) */
                    232:                if (nStJoyId == JOYID_JOYSTICK1 && (JoyReading.Buttons & JOY_BUTTON2))
                    233:                {
1.1.1.11  root      234:                        if (ConfigureParams.Joysticks.Joy[nStJoyId].bEnableJumpOnFire2)
1.1.1.6   root      235:                        {
1.1.1.11  root      236:                                /* If "Jump on Button 2" is enabled, PC Joystick button 2 acts as "ST Joystick up" */
                    237:                                nData |= ATARIJOY_BITMASK_UP;
                    238:                        } else {
                    239:                                /* If "Jump on Button 2" is not enabled, PC Joystick button 2 acts as pressing SPACE on the ST keyboard */
                    240:                                /* Only press 'space bar' if not in NULL state */
                    241:                                if (!JoystickSpaceBar)
                    242:                                {
                    243:                                        /* Press, ikbd will send packets and de-press */
                    244:                                        JoystickSpaceBar = JOYSTICK_SPACE_DOWN;
                    245:                                }
1.1.1.6   root      246:                        }
                    247:                }
                    248:        }
                    249: 
                    250:        /* Ignore fire button every 8 frames if enabled autofire (for both cursor emulation and joystick) */
                    251:        if (ConfigureParams.Joysticks.Joy[nStJoyId].bEnableAutoFire)
                    252:        {
                    253:                if ((nVBLs&0x7)<4)
1.1.1.11  root      254:                        nData &= ~ATARIJOY_BITMASK_FIRE;          /* Remove top bit! */
1.1.1.6   root      255:        }
                    256: 
                    257:        return nData;
1.1       root      258: }
                    259: 
1.1.1.2   root      260: 
                    261: /*-----------------------------------------------------------------------*/
1.1.1.8   root      262: /**
                    263:  * Get the fire button states.
                    264:  * Note: More than one fire buttons are only supported for real joystick,
                    265:  * not for keyboard emulation!
                    266:  */
1.1.1.6   root      267: static int Joy_GetFireButtons(int nStJoyId)
                    268: {
                    269:        int nButtons = 0;
                    270:        int nSdlJoyId;
                    271:        int i, nMaxButtons;
                    272: 
                    273:        nSdlJoyId = ConfigureParams.Joysticks.Joy[nStJoyId].nJoyId;
                    274: 
                    275:        /* Are we emulating the joystick via the keyboard? */
                    276:        if (ConfigureParams.Joysticks.Joy[nStJoyId].nJoystickMode == JOYSTICK_KEYBOARD)
                    277:        {
                    278:                if (nJoyKeyEmu[nStJoyId] & 0x80)
                    279:                {
                    280:                        nButtons |= 1;
                    281:                }
                    282:        }
                    283:        else if (ConfigureParams.Joysticks.Joy[nStJoyId].nJoystickMode == JOYSTICK_REALSTICK
                    284:                 && bJoystickWorking[nSdlJoyId])
                    285:        {
                    286:                nMaxButtons = SDL_JoystickNumButtons(sdlJoystick[nSdlJoyId]);
                    287:                if (nMaxButtons > 17)
                    288:                        nMaxButtons = 17;
                    289:                /* Now read all fire buttons and set a bit for each pressed button: */
                    290:                for (i = 0; i < nMaxButtons; i++)
                    291:                {
                    292:                        if (SDL_JoystickGetButton(sdlJoystick[nSdlJoyId], i))
                    293:                        {
                    294:                                nButtons |= (1 << i);
                    295:                        }
                    296:                }
                    297:        }
1.1.1.2   root      298: 
1.1.1.6   root      299:        return nButtons;
1.1       root      300: }
                    301: 
1.1.1.2   root      302: 
                    303: /*-----------------------------------------------------------------------*/
1.1.1.8   root      304: /**
                    305:  * Set joystick cursor emulation for given port.  This assumes that
                    306:  * if the same keys have been defined for "cursor key emulation" in
                    307:  * other ports, the emulation for them has been switched off. Returns
                    308:  * 1 if the port number was OK, zero for error.
                    309:  */
1.1.1.9   root      310: bool Joy_SetCursorEmulation(int port)
1.1.1.7   root      311: {
                    312:        if (port < 0 || port >= JOYSTICK_COUNT) {
                    313:                return 0;
                    314:        }
                    315:        ConfigureParams.Joysticks.Joy[port].nJoystickMode = JOYSTICK_KEYBOARD;
                    316:        return 1;
                    317: }
                    318: 
                    319: 
                    320: /*-----------------------------------------------------------------------*/
1.1.1.8   root      321: /**
                    322:  * Toggle joystick cursor emulation between port 0, port 1 and being off
                    323:  * from them. When it's turned off from them, the port's previous state
                    324:  * is restored
                    325:  */
1.1       root      326: void Joy_ToggleCursorEmulation(void)
                    327: {
1.1.1.11  root      328:        static JOYSTICKMODE saved[2] = { JOYSTICK_DISABLED, JOYSTICK_DISABLED };
                    329:        JOYSTICKMODE state;
                    330:        int i, port = 2;
1.1.1.7   root      331:        for (i = 0; i < 2; i++) {
                    332:                state = ConfigureParams.Joysticks.Joy[i].nJoystickMode;
                    333:                if (state == JOYSTICK_KEYBOARD) {
                    334:                        port = i;
                    335:                } else {
                    336:                        saved[i] = state;
                    337:                }
                    338:        }
                    339:        switch (port) {
                    340:        case 0:  /* (only) in port 0, disable cursor emu */
                    341:                ConfigureParams.Joysticks.Joy[0].nJoystickMode = saved[0];
                    342:                break;
                    343:        case 1:  /* (at least) in port 1, switch cursor emu to port 0 */
                    344:                ConfigureParams.Joysticks.Joy[1].nJoystickMode = saved[1];
                    345:                ConfigureParams.Joysticks.Joy[0].nJoystickMode = JOYSTICK_KEYBOARD;
                    346:                break;
                    347:        default:  /* neither in port 0 or 1, enable cursor emu to port 1 */
                    348:                ConfigureParams.Joysticks.Joy[1].nJoystickMode = JOYSTICK_KEYBOARD;
1.1.1.6   root      349:        }
1.1.1.15! root      350:        Statusbar_UpdateInfo();
1.1.1.6   root      351: }
                    352: 
                    353: 
                    354: /*-----------------------------------------------------------------------*/
1.1.1.8   root      355: /**
                    356:  * A key has been pressed down, check if we use it for joystick emulation
                    357:  * via keyboard.
                    358:  */
1.1.1.9   root      359: bool Joy_KeyDown(int symkey, int modkey)
1.1.1.6   root      360: {
                    361:        int i;
                    362: 
1.1.1.7   root      363:        for (i = 0; i < JOYSTICK_COUNT; i++)
1.1.1.6   root      364:        {
                    365:                if (ConfigureParams.Joysticks.Joy[i].nJoystickMode == JOYSTICK_KEYBOARD
                    366:                    && !(modkey & KMOD_SHIFT))
                    367:                {
                    368:                        if (symkey == ConfigureParams.Joysticks.Joy[i].nKeyCodeUp)
                    369:                        {
1.1.1.11  root      370:                                nJoyKeyEmu[i] &= ~ATARIJOY_BITMASK_DOWN;   /* Disable down */
                    371:                                nJoyKeyEmu[i] |= ATARIJOY_BITMASK_UP;    /* Enable up */
                    372:                                return true;
1.1.1.6   root      373:                        }
                    374:                        else if (symkey == ConfigureParams.Joysticks.Joy[i].nKeyCodeDown)
                    375:                        {
1.1.1.11  root      376:                                nJoyKeyEmu[i] &= ~ATARIJOY_BITMASK_UP;   /* Disable up */
                    377:                                nJoyKeyEmu[i] |= ATARIJOY_BITMASK_DOWN;    /* Enable down */
                    378:                                return true;
1.1.1.6   root      379:                        }
                    380:                        else if (symkey == ConfigureParams.Joysticks.Joy[i].nKeyCodeLeft)
                    381:                        {
1.1.1.11  root      382:                                nJoyKeyEmu[i] &= ~ATARIJOY_BITMASK_RIGHT;   /* Disable right */
                    383:                                nJoyKeyEmu[i] |= ATARIJOY_BITMASK_LEFT;    /* Enable left */
                    384:                                return true;
1.1.1.6   root      385:                        }
                    386:                        else if (symkey == ConfigureParams.Joysticks.Joy[i].nKeyCodeRight)
                    387:                        {
1.1.1.11  root      388:                                nJoyKeyEmu[i] &= ~ATARIJOY_BITMASK_LEFT;   /* Disable left */
                    389:                                nJoyKeyEmu[i] |= ATARIJOY_BITMASK_RIGHT;    /* Enable right */
                    390:                                return true;
1.1.1.6   root      391:                        }
                    392:                        else if (symkey == ConfigureParams.Joysticks.Joy[i].nKeyCodeFire)
                    393:                        {
1.1.1.11  root      394:                                nJoyKeyEmu[i] |= ATARIJOY_BITMASK_FIRE;
                    395:                                return true;
1.1.1.6   root      396:                        }
                    397:                }
                    398:        }
                    399: 
1.1.1.11  root      400:        return false;
1.1.1.6   root      401: }
                    402: 
                    403: 
                    404: /*-----------------------------------------------------------------------*/
1.1.1.8   root      405: /**
                    406:  * A key has been released, check if we use it for joystick emulation
                    407:  * via keyboard.
                    408:  */
1.1.1.9   root      409: bool Joy_KeyUp(int symkey, int modkey)
1.1.1.6   root      410: {
                    411:        int i;
                    412: 
1.1.1.7   root      413:        for (i = 0; i < JOYSTICK_COUNT; i++)
1.1.1.6   root      414:        {
                    415:                if (ConfigureParams.Joysticks.Joy[i].nJoystickMode == JOYSTICK_KEYBOARD
                    416:                    && !(modkey & KMOD_SHIFT))
                    417:                {
                    418:                        if (symkey == ConfigureParams.Joysticks.Joy[i].nKeyCodeUp)
                    419:                        {
1.1.1.11  root      420:                                nJoyKeyEmu[i] &= ~ATARIJOY_BITMASK_UP;
                    421:                                return true;
1.1.1.6   root      422:                        }
                    423:                        else if (symkey == ConfigureParams.Joysticks.Joy[i].nKeyCodeDown)
                    424:                        {
1.1.1.11  root      425:                                nJoyKeyEmu[i] &= ~ATARIJOY_BITMASK_DOWN;
                    426:                                return true;
1.1.1.6   root      427:                        }
                    428:                        else if (symkey == ConfigureParams.Joysticks.Joy[i].nKeyCodeLeft)
                    429:                        {
1.1.1.11  root      430:                                nJoyKeyEmu[i] &= ~ATARIJOY_BITMASK_LEFT;
                    431:                                return true;
1.1.1.6   root      432:                        }
                    433:                        else if (symkey == ConfigureParams.Joysticks.Joy[i].nKeyCodeRight)
                    434:                        {
1.1.1.11  root      435:                                nJoyKeyEmu[i] &= ~ATARIJOY_BITMASK_RIGHT;
                    436:                                return true;
1.1.1.6   root      437:                        }
                    438:                        else if (symkey == ConfigureParams.Joysticks.Joy[i].nKeyCodeFire)
                    439:                        {
1.1.1.11  root      440:                                nJoyKeyEmu[i] &= ~ATARIJOY_BITMASK_FIRE;
                    441:                                return true;
1.1.1.6   root      442:                        }
                    443:                }
                    444:        }
                    445: 
1.1.1.11  root      446:        return false;
1.1.1.6   root      447: }
                    448: 
                    449: 
                    450: /*-----------------------------------------------------------------------*/
1.1.1.8   root      451: /**
                    452:  * Read from STE joypad buttons register (0xff9200)
                    453:  */
1.1.1.6   root      454: void Joy_StePadButtons_ReadWord(void)
                    455: {
                    456:        Uint16 nData = 0xffff;
                    457: 
                    458:        if (ConfigureParams.Joysticks.Joy[JOYID_STEPADA].nJoystickMode != JOYSTICK_DISABLED
                    459:            && (nSteJoySelect & 0x0f) != 0x0f)
                    460:        {
                    461:                int nButtons = Joy_GetFireButtons(JOYID_STEPADA);
                    462:                if (!(nSteJoySelect & 0x1))
                    463:                {
                    464:                        if (nButtons & 0x01)  /* Fire button A pressed? */
                    465:                                nData &= ~2;
                    466:                        if (nButtons & 0x10)  /* Fire button PAUSE pressed? */
                    467:                                nData &= ~1;
                    468:                }
                    469:                else if (!(nSteJoySelect & 0x2))
                    470:                {
                    471:                        if (nButtons & 0x02)  /* Fire button B pressed? */
                    472:                                nData &= ~2;
                    473:                }
                    474:                else if (!(nSteJoySelect & 0x4))
                    475:                {
                    476:                        if (nButtons & 0x04)  /* Fire button C pressed? */
                    477:                                nData &= ~2;
                    478:                }
                    479:                else if (!(nSteJoySelect & 0x8))
                    480:                {
                    481:                        if (nButtons & 0x01)  /* Fire button OPTION pressed? */
                    482:                                nData &= ~2;
                    483:                }
                    484:        }
                    485: 
                    486:        if (ConfigureParams.Joysticks.Joy[JOYID_STEPADB].nJoystickMode != JOYSTICK_DISABLED
                    487:            && (nSteJoySelect & 0xf0) != 0xf0)
                    488:        {
                    489:                int nButtons = Joy_GetFireButtons(JOYID_STEPADB);
                    490:                if (!(nSteJoySelect & 0x10))
                    491:                {
                    492:                        if (nButtons & 0x01)  /* Fire button A pressed? */
                    493:                                nData &= ~8;
                    494:                        if (nButtons & 0x10)  /* Fire button PAUSE pressed? */
                    495:                                nData &= ~4;
                    496:                }
                    497:                else if (!(nSteJoySelect & 0x20))
                    498:                {
                    499:                        if (nButtons & 0x02)  /* Fire button B pressed? */
                    500:                                nData &= ~8;
                    501:                }
                    502:                else if (!(nSteJoySelect & 0x40))
                    503:                {
                    504:                        if (nButtons & 0x04)  /* Fire button C pressed? */
                    505:                                nData &= ~8;
                    506:                }
                    507:                else if (!(nSteJoySelect & 0x80))
                    508:                {
                    509:                        if (nButtons & 0x08)  /* Fire button OPTION pressed? */
                    510:                                nData &= ~8;
                    511:                }
                    512:        }
                    513: 
                    514:        IoMem_WriteWord(0xff9200, nData);
1.1       root      515: }
1.1.1.2   root      516: 
1.1.1.6   root      517: 
                    518: /*-----------------------------------------------------------------------*/
1.1.1.8   root      519: /**
                    520:  * Read from STE joypad direction/buttons register (0xff9202)
                    521:  */
1.1.1.6   root      522: void Joy_StePadMulti_ReadWord(void)
                    523: {
                    524:        Uint8 nData = 0xff;
                    525: 
                    526:        if (ConfigureParams.Joysticks.Joy[JOYID_STEPADA].nJoystickMode != JOYSTICK_DISABLED
                    527:            && (nSteJoySelect & 0x0f) != 0x0f)
                    528:        {
                    529:                nData &= 0xf0;
                    530:                if (!(nSteJoySelect & 0x1))
                    531:                {
                    532:                        nData |= ~Joy_GetStickData(JOYID_STEPADA) & 0x0f;
                    533:                }
                    534:                else if (!(nSteJoySelect & 0x2))
                    535:                {
                    536:                        nData |= ~(Joy_GetFireButtons(JOYID_STEPADA) >> 13) & 0x0f;
                    537:                }
                    538:                else if (!(nSteJoySelect & 0x4))
                    539:                {
                    540:                        nData |= ~(Joy_GetFireButtons(JOYID_STEPADA) >> 9) & 0x0f;
                    541:                }
                    542:                else if (!(nSteJoySelect & 0x8))
                    543:                {
                    544:                        nData |= ~(Joy_GetFireButtons(JOYID_STEPADA) >> 5) & 0x0f;
                    545:                }
                    546:        }
                    547: 
                    548:        if (ConfigureParams.Joysticks.Joy[JOYID_STEPADB].nJoystickMode != JOYSTICK_DISABLED
                    549:            && (nSteJoySelect & 0xf0) != 0xf0)
                    550:        {
                    551:                nData &= 0x0f;
                    552:                if (!(nSteJoySelect & 0x10))
                    553:                {
                    554:                        nData |= ~Joy_GetStickData(JOYID_STEPADB) << 4;
                    555:                }
                    556:                else if (!(nSteJoySelect & 0x20))
                    557:                {
                    558:                        nData |= ~(Joy_GetFireButtons(JOYID_STEPADB) >> 13) & 0x0f;
                    559:                }
                    560:                else if (!(nSteJoySelect & 0x40))
                    561:                {
                    562:                        nData |= ~(Joy_GetFireButtons(JOYID_STEPADB) >> 9) & 0x0f;
                    563:                }
                    564:                else if (!(nSteJoySelect & 0x80))
                    565:                {
                    566:                        nData |= ~(Joy_GetFireButtons(JOYID_STEPADB) >> 5) & 0x0f;
                    567:                }
                    568:        }
                    569: 
                    570:        IoMem_WriteWord(0xff9202, (nData << 8) | 0x0ff);
                    571: }
                    572: 
                    573: 
                    574: /*-----------------------------------------------------------------------*/
1.1.1.8   root      575: /**
                    576:  * Write to STE joypad selection register (0xff9202)
                    577:  */
1.1.1.6   root      578: void Joy_StePadMulti_WriteWord(void)
                    579: {
                    580:        nSteJoySelect = IoMem_ReadWord(0xff9202);
                    581: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.