-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.pas
187 lines (110 loc) · 2.55 KB
/
control.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
unit control;
interface
type
TMagnet = record
y, old: byte;
end;
const
left_magnet_px = 5;
right_magnet_px = 25;
empty_tile = 0;
py_limit = 22;
delay_value = 6;
var
fireBtn, keyboard, esc: Boolean;
joy, joyDelay: byte;
l_magnet, r_magnet: TMagnet;
function anyKey: Boolean; assembler;
procedure JoyScan;
implementation
uses keycode, joystick, atari;
(*-----------------------------------------------------------*)
function allow(m: byte; dy: byte): Boolean;
var p: PByte register;
begin
asm
fxs FX_MEMS #$00
end;
Result := false;
if m = 0 then begin
if l_magnet.y > py_limit then exit;
p:=pointer(dpeek(88) + byte(l_magnet.y + dy)*40 + left_magnet_px);
Result:= (p[0] = empty_tile);
end else begin
if r_magnet.y > py_limit then exit;
p:=pointer(dpeek(88) + byte(r_magnet.y + dy)*40 + right_magnet_px + 1);
Result:= (p[0] = empty_tile);
end;
end;
(*-----------------------------------------------------------*)
function anyKey: Boolean; assembler;
asm
lda:cmp:req 20
lda #1
sta Result
lda $d20f
and #4
bne skp
beq stop
skp lda trig0
bne @exit
stop sta Result
end;
(*-----------------------------------------------------------*)
Procedure JoyScan;
var onKey: byte = $80;
a: byte;
procedure get_key; assembler;
asm
lda $d20f
and #4
bne @exit
lda $d209
cmp onKey_: #0
bne skp
ldy delay: #delay_value
dey
sty delay
bne @exit
skp
sta onKey
sta onKey_
mva #delay_value delay
end;
BEGIN
fireBtn:= Boolean(trig0);
get_key;
a:=porta and $0f;//joy_1;
//onKey:=onKey and %00111111;
if keyboard then fireBtn:=false;
if a = joy then begin
if joyDelay >= 1 then begin dec(joyDelay) ; exit end;
joy:=$ff;
end else begin
joyDelay:=delay_value;
joy:=a;
//if a <> joy_none then keyboard:=false;
end;
if onKey < 128 then begin
fireBtn:=true;
case onKey of
KEY_ESC: esc:=true;
KEY_Q: begin a:=joy_up; keyboard:=false end;
KEY_A: begin a:=joy_down; keyboard:=false end;
KEY_P: begin fireBtn:=false; a:=joy_up; keyboard:=true end;
KEY_L: begin fireBtn:=false; a:=joy_down; keyboard:=true end;
end;
onKey:=$80;
end;
if fireBtn then begin {left magnet}
case a of
joy_up: if allow(0, -1) then begin dec(l_magnet.y, 3) end; {up}
joy_down: if allow(0, 2) then begin inc(l_magnet.y, 3); end; {down}
end;
end else {right magnet}
case a of
joy_up: if allow(1, -1) then dec(r_magnet.y, 3); {up}
joy_down: if allow(1, 2) then inc(r_magnet.y, 3); {down}
end;
end;
end.