-
Notifications
You must be signed in to change notification settings - Fork 1
/
JOY.C
122 lines (109 loc) · 2.38 KB
/
JOY.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include "joy.h"
extern char far a_1;
extern char far a_2;
extern char far b_1;
extern char far b_2;
extern int far xa;
extern int far ya;
extern int far xb;
extern int far yb;
extern void far jstat(void);
static JS_UPROC jsu_func = NULL;
static char js_enabled = 0;
static char js_devices = 0;
/* ¯®à®£¨ çã¢á⢨⥫ì®á⨠*/
unsigned int fleft, fright, fup, fdown;
void js_stub(unsigned short butt) {
}
void js_init(void) {
if (!jsu_func) {
jsu_func = js_stub;
}
jstat();
js_devices = 0;
js_enabled = 0;
js_devices |= (xa || ya) ? 1 : 0;
js_devices |= (xb || yb) ? 2 : 0;
}
int js_state(void) {
return(js_devices);
}
void js_on(void) {
js_enabled = js_devices ? 1 : 0;
}
void js_off(void) {
js_enabled = 0;
}
void js_set(JS_UPROC funcaddr) {
disable(); /* cli */
jsu_func = funcaddr;
enable(); /* sti */
}
void js_read(void) {
unsigned short butt;
/* joystick enabled */
if (js_enabled) {
jstat();
butt = 0;
/* joystick 1 */
if (js_devices & 1) {
butt |= (xa < fleft) ? JOY1_L : 0;
butt |= (xa > fright) ? JOY1_R : 0;
butt |= (ya < fup) ? JOY1_U : 0;
butt |= (ya > fdown) ? JOY1_D : 0;
/* button state inverse in DOS */
butt |= a_1 ? 0 : JOY1_A;
butt |= a_2 ? 0 : JOY1_B;
}
if (js_devices & 2) {
/* joystick 2 */
butt |= (xb < fleft) ? JOY2_L : 0;
butt |= (xb > fright) ? JOY2_R : 0;
butt |= (yb < fup) ? JOY2_U : 0;
butt |= (yb > fdown) ? JOY2_D : 0;
/* button state inverse in DOS */
butt |= b_1 ? 0 : JOY2_A;
butt |= b_2 ? 0 : JOY2_B;
}
/* call user defined function */
jsu_func(butt);
}
}
/* áâனª ¤¦®©á⨪ */
void js_test(void) {
unsigned int mleft, mright, mup, mdown, x, y; /* ¬ å § 票ï */
/* àãçª ¢ æ¥âॠ*/
do {
jstat();
} while (a_1 && a_2);
x = xa;
y = ya;
do {
jstat();
} while ((!a_1) || (!a_2));
/* àãçª ¢ «¥¢®¬ ¢¥å¥¬ 㣫ã */
do {
jstat();
} while (a_1 && a_2);
mleft = xa;
mup = ya;
do {
jstat();
} while ((!a_1) || (!a_2));
/* àãçª ¢ ¯à ¢®¬ ¨¦¥¬ 㣫ã */
do {
jstat();
} while (a_1 && a_2);
mright = xa;
mdown = ya;
do {
jstat();
} while ((!a_1) || (!a_2));
fleft = mleft + ((x - mleft) / 2);
fright = mright - ((mright - x) / 2);
fup = mup + ((y - mup) / 2);
fdown = mdown - ((mdown - y) / 2);
}