|
|
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:
20: int HasJoy0 = 0, HasJoy1 = 0;
21: int minx0, maxx0, miny0, maxy0;
22: int minx1, maxx1, miny1, maxy1;
23:
24: void read_joystick(int nr, unsigned int *dir, int *button) {
25: int *minx, *maxx, *miny, *maxy;
26: int left = 0, right = 0, top = 0, bot = 0;
27: char JoyPort;
28: int laps, JoyX, JoyY, XCenter, YCenter, XDelta, YDelta;
29:
30: *dir = 0;
31: *button = 0;
32: if (((nr == 0) && (HasJoy0 == 0)) || ((nr == 1) && (HasJoy1 == 0)))
33: return;
34:
35: JoyX = 0;
36: JoyY = 0;
37: laps = 0;
38: outportb(0x201, 0xff);
39: if (nr == 0) {
40: disable();
41: do {
42: JoyPort = inportb(0x201);
43: if (JoyPort & 1)
44: JoyX++;
45: if (JoyPort & 2)
46: JoyY++;
47: laps++;
48: } while(((JoyPort & 3) != 0) && (laps != 65535));
49: enable();
50: if (laps == 65535) {
51: HasJoy0 = 0;
52: return;
53: }
54: minx = &minx0;
55: maxx = &maxx0;
56: miny = &miny0;
57: maxy = &maxy0;
58: } else {
59: disable();
60: do {
61: JoyPort = inportb(0x201);
62: if (JoyPort & 4)
63: JoyX++;
64: if (JoyPort & 8)
65: JoyY++;
66: laps++;
67: } while(((JoyPort & 12) != 0) && (laps != 65535));
68: enable();
69: if (laps == 65535) {
70: HasJoy1 = 0;
71: return;
72: }
73: minx = &minx1;
74: maxx = &maxx1;
75: miny = &miny1;
76: maxy = &maxy1;
77: }
78:
79: if (JoyX < (*minx)) *minx = JoyX;
80: if (JoyY < (*miny)) *miny = JoyY;
81: if (JoyX > (*maxx)) *maxx = JoyX;
82: if (JoyY > (*maxy)) *maxy = JoyY;
83:
84: XCenter = ((*maxx)+(*minx))/2;
85: YCenter = ((*maxy)+(*miny))/2;
86: XDelta = ((*maxx)-(*minx))/3;
87: YDelta = ((*maxy)-(*miny))/3;
88:
89: if (JoyX < (XCenter-XDelta))
90: left = 1;
91: if (JoyX > (XCenter+XDelta))
92: right = 1;
93:
94: if (JoyY < (YCenter-YDelta))
95: top = 1;
96: if (JoyY > (YCenter+YDelta))
97: bot = 1;
98:
99: if (left) top = !top;
100: if (right) bot = !bot;
101: *dir = bot | (right << 1) | (top << 8) | (left << 9);
102:
103: JoyPort = ~JoyPort;
104: if (nr == 0) {
105: if (JoyPort & 16) *button += 1;
106: if (JoyPort & 32) *button += 2;
107: } else {
108: if (JoyPort & 64) *button += 1;
109: if (JoyPort & 128) *button += 2;
110: }
111: if ((*button) == 3) *button = 4;
112: }
113:
114: void init_joystick(void) {
115: int laps, JoyX, JoyY;
116: char JoyPort;
117:
118: JoyX = 0;
119: JoyY = 0;
120: laps = 0;
121: disable();
122: outportb(0x201, 0xff);
123: do {
124: JoyPort = inportb(0x201);
125: if (JoyPort & 1)
126: JoyX++;
127: if (JoyPort & 2)
128: JoyY++;
129: laps++;
130: } while(((JoyPort & 3) != 0) && (laps != 65535));
131: enable();
132: if (laps != 65535) {
133: HasJoy0 = 1;
134: minx0 = JoyX - 2*JoyX/3;
135: maxx0 = JoyX + 2*JoyX/3;
136: miny0 = JoyY - 2*JoyY/3;
137: maxy0 = JoyY + 2*JoyY/3;
138: }
139:
140: JoyX = 0;
141: JoyY = 0;
142: laps = 0;
143: disable();
144: outportb(0x201, 0xff);
145: do {
146: JoyPort = inportb(0x201);
147: if (JoyPort & 4)
148: JoyX++;
149: if (JoyPort & 8)
150: JoyY++;
151: laps++;
152: } while(((JoyPort & 12) != 0) && (laps != 65535));
153: enable();
154: if (laps != 65535) {
155: HasJoy1 = 1;
156: minx1 = JoyX - 2*JoyX/3;
157: maxx1 = JoyX + 2*JoyX/3;
158: miny1 = JoyY - 2*JoyY/3;
159: maxy1 = JoyY + 2*JoyY/3;
160: }
161: }
162:
163: void close_joystick(void) {
164: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.