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

1.1     ! root        1:  /* 
        !             2:   * UAE - The Un*x Amiga Emulator
        !             3:   * 
        !             4:   * Joystick emulation for Linux
        !             5:   * 
        !             6:   * Copyright 1997 Bernd Schmidt
        !             7:   */
        !             8: 
        !             9: #include "sysconfig.h"
        !            10: #include "sysdeps.h"
        !            11: 
        !            12: #include "config.h"
        !            13: #include "options.h"
        !            14: #include "memory.h"
        !            15: #include "custom.h"
        !            16: #include "joystick.h"
        !            17: 
        !            18: int nr_joysticks;
        !            19: 
        !            20: static int js0, js1;
        !            21: 
        !            22: /* There are too many different versions of <linux/joystick.h>.  Rather
        !            23:  * than trying to work correctly with all of them, we duplicate the
        !            24:  * necessary definitions here.  */
        !            25: struct JS_DATA_TYPE
        !            26: {
        !            27:     int buttons;
        !            28:     int x;
        !            29:     int y;
        !            30: };
        !            31: 
        !            32: static struct JS_DATA_TYPE jscal;
        !            33: 
        !            34: void read_joystick(int nr, unsigned int *dir, int *button)
        !            35: {
        !            36:     static int minx = MAXINT, maxx = MININT,
        !            37:                miny = MAXINT, maxy = MININT;
        !            38:     int left = 0, right = 0, top = 0, bot = 0;
        !            39:     struct JS_DATA_TYPE buffer;
        !            40:     int len;
        !            41:     int fd = nr == 0 ? js0 : js1;
        !            42: 
        !            43:     *dir = 0;
        !            44:     *button = 0;
        !            45:     if (nr >= nr_joysticks)
        !            46:        return;
        !            47:     
        !            48:     len = read(fd, &buffer, sizeof(buffer));
        !            49:     if (len != sizeof(buffer)) 
        !            50:        return;
        !            51:     
        !            52:     if (buffer.x < minx) minx = buffer.x;
        !            53:     if (buffer.y < miny) miny = buffer.y;
        !            54:     if (buffer.x > maxx) maxx = buffer.x;
        !            55:     if (buffer.y > maxy) maxy = buffer.y;
        !            56:     
        !            57:     if (buffer.x < (minx + (maxx-minx)/3))
        !            58:        left = 1;
        !            59:     else if (buffer.x > (minx + 2*(maxx-minx)/3))
        !            60:        right = 1;
        !            61: 
        !            62:     if (buffer.y < (miny + (maxy-miny)/3))
        !            63:        top = 1;
        !            64:     else if (buffer.y > (miny + 2*(maxy-miny)/3))
        !            65:        bot = 1;
        !            66:        
        !            67:     if (left) top = !top;
        !            68:     if (right) bot = !bot;
        !            69:     *dir = bot | (right << 1) | (top << 8) | (left << 9);
        !            70:     *button = buffer.buttons & 3;
        !            71: }
        !            72: 
        !            73: void init_joystick(void)
        !            74: {
        !            75:     nr_joysticks = 0;
        !            76:     js0 = -1; js1 = -1;
        !            77:     js0 = open("/dev/js0", O_RDONLY);
        !            78:     if (js0 < 0) {
        !            79:        write_log ("No joysticks found\n");
        !            80:        return;
        !            81:     }
        !            82:     nr_joysticks = 1;
        !            83:     js1 = open("/dev/js1", O_RDONLY);
        !            84:     if (js1 < 0) {
        !            85:        write_log ("Found one joystick\n");
        !            86:        return;
        !            87:     }
        !            88:     write_log ("Found two joysticks\n");
        !            89:     nr_joysticks = 2;
        !            90: }
        !            91: 
        !            92: void close_joystick(void)
        !            93: {
        !            94:     if (js0 >= 0)
        !            95:        close(js0);
        !            96:     if (js1 >= 0)
        !            97:        close(js1);
        !            98: }

unix.superglobalmegacorp.com

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