Annotation of uae/src/od-dos/joystick.c, revision 1.1.1.2

1.1       root        1:  /*
                      2:   * UAE - The Un*x Amiga Emulator
                      3:   *
                      4:   * Joystick emulation for DOS
                      5:   *
                      6:   * Copyright 1996, 1997 Gustavo Goedert
                      7:   */
                      8: 
                      9: #include "sysconfig.h"
                     10: #include "sysdeps.h"
                     11: 
                     12: #include <dos.h>
                     13: 
                     14: #include "config.h"
                     15: #include "options.h"
                     16: #include "memory.h"
                     17: #include "custom.h"
                     18: #include "joystick.h"
                     19: 
1.1.1.2 ! root       20: int nr_joysticks;
1.1       root       21: int HasJoy0 = 0, HasJoy1 = 0;
                     22: int minx0, maxx0, miny0, maxy0;
                     23: int minx1, maxx1, miny1, maxy1;
                     24: 
                     25: void read_joystick(int nr, unsigned int *dir, int *button) {
                     26:     int *minx, *maxx, *miny, *maxy;
                     27:     int left = 0, right = 0, top = 0, bot = 0;
                     28:     char JoyPort;
                     29:     int laps, JoyX, JoyY, XCenter, YCenter, XDelta, YDelta;
                     30: 
                     31:     *dir = 0;
                     32:     *button = 0;
                     33:     if (((nr == 0) && (HasJoy0 == 0)) || ((nr == 1) && (HasJoy1 == 0)))
                     34:        return;
                     35: 
                     36:     JoyX = 0;
                     37:     JoyY = 0;
                     38:     laps = 0;
                     39:     outportb(0x201, 0xff);
                     40:     if (nr == 0) {
                     41:        disable();
                     42:        do {
                     43:            JoyPort = inportb(0x201);
                     44:            if (JoyPort & 1)
                     45:                JoyX++;
                     46:            if (JoyPort & 2)
                     47:                JoyY++;
                     48:            laps++;
                     49:        } while(((JoyPort & 3) != 0) && (laps != 65535));
                     50:        enable();
                     51:        if (laps == 65535) {
                     52:            HasJoy0 = 0;
                     53:            return;
                     54:        }
                     55:        minx = &minx0;
                     56:        maxx = &maxx0;
                     57:        miny = &miny0;
                     58:        maxy = &maxy0;
                     59:     } else {
                     60:        disable();
                     61:        do {
                     62:            JoyPort = inportb(0x201);
                     63:            if (JoyPort & 4)
                     64:                JoyX++;
                     65:            if (JoyPort & 8)
                     66:                JoyY++;
                     67:            laps++;
                     68:        } while(((JoyPort & 12) != 0) && (laps != 65535));
                     69:        enable();
                     70:        if (laps == 65535) {
                     71:            HasJoy1 = 0;
                     72:            return;
                     73:        }
                     74:        minx = &minx1;
                     75:        maxx = &maxx1;
                     76:        miny = &miny1;
                     77:        maxy = &maxy1;
                     78:     }
                     79: 
                     80:     if (JoyX < (*minx)) *minx = JoyX;
                     81:     if (JoyY < (*miny)) *miny = JoyY;
                     82:     if (JoyX > (*maxx)) *maxx = JoyX;
                     83:     if (JoyY > (*maxy)) *maxy = JoyY;
                     84: 
                     85:     XCenter = ((*maxx)+(*minx))/2;
                     86:     YCenter = ((*maxy)+(*miny))/2;
                     87:     XDelta = ((*maxx)-(*minx))/3;
                     88:     YDelta = ((*maxy)-(*miny))/3;
                     89: 
                     90:     if (JoyX < (XCenter-XDelta))
                     91:        left = 1;
                     92:     if (JoyX > (XCenter+XDelta))
                     93:        right = 1;
                     94: 
                     95:     if (JoyY < (YCenter-YDelta))
                     96:        top = 1;
                     97:     if (JoyY > (YCenter+YDelta))
                     98:        bot = 1;
                     99: 
                    100:     if (left) top = !top;
                    101:     if (right) bot = !bot;
                    102:     *dir = bot | (right << 1) | (top << 8) | (left << 9);
                    103: 
                    104:     JoyPort = ~JoyPort;
                    105:     if (nr == 0) {
                    106:        if (JoyPort & 16) *button += 1;
                    107:        if (JoyPort & 32) *button += 2;
                    108:     } else {
                    109:        if (JoyPort & 64) *button += 1;
                    110:        if (JoyPort & 128) *button += 2;
                    111:     }
                    112:     if ((*button) == 3) *button = 4;
                    113: }
                    114: 
                    115: void init_joystick(void) {
                    116:     int laps, JoyX, JoyY;
                    117:     char JoyPort;
                    118: 
                    119:     JoyX = 0;
                    120:     JoyY = 0;
                    121:     laps = 0;
                    122:     disable();
                    123:     outportb(0x201, 0xff);
                    124:     do {
                    125:        JoyPort = inportb(0x201);
                    126:        if (JoyPort & 1)
                    127:            JoyX++;
                    128:        if (JoyPort & 2)
                    129:            JoyY++;
                    130:        laps++;
                    131:     } while(((JoyPort & 3) != 0) && (laps != 65535));
                    132:     enable();
                    133:     if (laps != 65535) {
                    134:        HasJoy0 = 1;
                    135:        minx0 = JoyX - 2*JoyX/3;
                    136:        maxx0 = JoyX + 2*JoyX/3;
                    137:        miny0 = JoyY - 2*JoyY/3;
                    138:        maxy0 = JoyY + 2*JoyY/3;
                    139:     }
                    140: 
                    141:     JoyX = 0;
                    142:     JoyY = 0;
                    143:     laps = 0;
                    144:     disable();
                    145:     outportb(0x201, 0xff);
                    146:     do {
                    147:        JoyPort = inportb(0x201);
                    148:        if (JoyPort & 4)
                    149:            JoyX++;
                    150:        if (JoyPort & 8)
                    151:            JoyY++;
                    152:        laps++;
                    153:     } while(((JoyPort & 12) != 0) && (laps != 65535));
                    154:     enable();
                    155:     if (laps != 65535) {
                    156:        HasJoy1 = 1;
                    157:        minx1 = JoyX - 2*JoyX/3;
                    158:        maxx1 = JoyX + 2*JoyX/3;
                    159:        miny1 = JoyY - 2*JoyY/3;
                    160:        maxy1 = JoyY + 2*JoyY/3;
                    161:     }
1.1.1.2 ! root      162: 
        !           163:     nr_joysticks = HasJoy0 + HasJoy1;
1.1       root      164: }
                    165: 
                    166: void close_joystick(void) {
                    167: }

unix.superglobalmegacorp.com

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