Annotation of uae/src/sdl-joystick.c, revision 1.1

1.1     ! root        1:  /* 
        !             2:   * UAE - The Un*x Amiga Emulator
        !             3:   * 
        !             4:   * Joystick emulation for Linux and BSD. They share too much code to
        !             5:   * split this file.
        !             6:   * 
        !             7:   * Copyright 1997 Bernd Schmidt
        !             8:   * Copyright 1998 Krister Walfridsson
        !             9:   */
        !            10: 
        !            11: #include "sysconfig.h"
        !            12: #include "sysdeps.h"
        !            13: 
        !            14: #include "config.h"
        !            15: #include "options.h"
        !            16: #include "memory.h"
        !            17: #include "custom.h"
        !            18: #include "joystick.h"
        !            19: #include "SDL.h"
        !            20: 
        !            21: int nr_joysticks;
        !            22: 
        !            23: static SDL_Joystick *joy0, *joy1;
        !            24: 
        !            25: struct joy_range
        !            26: {
        !            27:     int minx, maxx, miny, maxy;
        !            28: } range0, range1;
        !            29: 
        !            30: void read_joystick(int nr, unsigned int *dir, int *button)
        !            31: {
        !            32:     int x_axis, y_axis;
        !            33:     int left = 0, right = 0, top = 0, bot = 0;
        !            34:     int len, i, num;
        !            35:     SDL_Joystick *joy = nr == 0 ? joy0 : joy1;
        !            36:     struct joy_range *r = nr == 0 ? &range0 : &range1;
        !            37: 
        !            38:     *dir = 0;
        !            39:     *button = 0;
        !            40:     if (nr >= nr_joysticks)
        !            41:        return;
        !            42: 
        !            43:     SDL_JoystickUpdate ();
        !            44: 
        !            45:     x_axis = SDL_JoystickGetAxis (joy, 0);
        !            46:     y_axis = SDL_JoystickGetAxis (joy, 1);
        !            47: 
        !            48:     if (x_axis < r->minx) r->minx = x_axis;
        !            49:     if (y_axis < r->miny) r->miny = y_axis;
        !            50:     if (x_axis > r->maxx) r->maxx = x_axis;
        !            51:     if (y_axis > r->maxy) r->maxy = y_axis;
        !            52:     
        !            53:     if (x_axis < (r->minx + (r->maxx - r->minx)/3))
        !            54:        left = 1;
        !            55:     else if (x_axis > (r->minx + 2*(r->maxx - r->minx)/3))
        !            56:        right = 1;
        !            57: 
        !            58:     if (y_axis < (r->miny + (r->maxy - r->miny)/3))
        !            59:        top = 1;
        !            60:     else if (y_axis > (r->miny + 2*(r->maxy - r->miny)/3))
        !            61:        bot = 1;
        !            62: 
        !            63:     if (left) top = !top;
        !            64:     if (right) bot = !bot;
        !            65:     *dir = bot | (right << 1) | (top << 8) | (left << 9);
        !            66:     num = SDL_JoystickNumButtons (joy);
        !            67:     if (num > 16)
        !            68:        num = 16;
        !            69:     for (i = 0; i < num; i++)
        !            70:        *button |= (SDL_JoystickGetButton (joy, i) & 1) << i;
        !            71: }
        !            72: 
        !            73: void init_joystick(void)
        !            74: {
        !            75:     int i;
        !            76:     nr_joysticks = SDL_NumJoysticks ();
        !            77:     if (nr_joysticks > 0)
        !            78:        joy0 = SDL_JoystickOpen (0);
        !            79:     if (nr_joysticks > 1)
        !            80:        joy1 = SDL_JoystickOpen (1);
        !            81:     range0.minx = INT_MAX;
        !            82:     range0.maxx = INT_MIN;
        !            83:     range0.miny = INT_MAX;
        !            84:     range0.maxy = INT_MIN;
        !            85:     range1.minx = INT_MAX;
        !            86:     range1.maxx = INT_MIN;
        !            87:     range1.miny = INT_MAX;
        !            88:     range1.maxy = INT_MIN;
        !            89: }
        !            90: 
        !            91: void close_joystick(void)
        !            92: {
        !            93:     if (nr_joysticks > 0)
        !            94:        SDL_JoystickClose (joy0);
        !            95:     if (nr_joysticks > 1)
        !            96:        SDL_JoystickClose (joy1);
        !            97: }

unix.superglobalmegacorp.com

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