This repository has been archived by the owner on Apr 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoystick.pas
106 lines (78 loc) · 1.79 KB
/
joystick.pas
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
unit Joystick;
interface
type
JoyRec =
record
present : Boolean;
x, y : Word;
button1,
button2,
button3,
button4 : Boolean;
end;
var
gSticks : array [1..2] of JoyRec;
procedure PollSticks;
procedure InitSticks;
implementation
const
cVGAPort = $03DA;
cStickPort = $0201;
procedure HSync;
begin
while Port[ cVGAPort] and 1 = 0 do;
while Port[ cVGAPort] and 1 <> 0 do;
end;
procedure PollSticks;
var b : Byte;
mask : Byte;
laps : Word;
begin
mask := 0;
if gSticks[1].present then
mask := 3;
if gSticks[2].present then
mask := mask or 12;
FillChar( gSticks, SizeOf( gSticks), 0);
laps := 0;
asm cli end;
{HSync;}
Port[ cStickPort] := $FF; { Write anything to trigger countdown }
repeat
{HSync;}
b := Port[ cStickPort];
if b and 1 <> 0 then
Inc( gSticks[1].x);
if b and 2 <> 0 then
Inc( gSticks[1].y);
if b and 4 <> 0 then
Inc( gSticks[2].x);
if b and 8 <> 0 then
Inc( gSticks[2].y);
Inc( laps);
until (b and mask = 0) or (laps > 60000);
asm sti end;
gSticks[1].present := b and 3 = 0;
gSticks[2].present := b and 12 = 0;
if gSticks[1].present then
begin
gSticks[1].button1 := b and 16 = 0;
gSticks[1].button2 := b and 32 = 0;
gSticks[1].button3 := b and 64 = 0;
gSticks[1].button4 := b and 128 = 0;
end;
if gSticks[2].present then
begin
gSticks[2].button1 := b and 64 = 0;
gSticks[2].button2 := b and 128 = 0;
gSticks[2].button3 := b and 16 = 0;
gSticks[2].button4 := b and 32 = 0;
end;
end;
procedure InitSticks;
begin
gSticks[1].present := True;
gSticks[2].present := True;
PollSticks;
end;
end.