-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink_master.asm
281 lines (263 loc) · 4.7 KB
/
link_master.asm
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
;Airaki! - FSE 2014
;Released under the GPL V3, see LICENSE.TXT
link_comm:
ld a,(LINK_ISMASTER)
or a
jr z,+
;Master communication
ld a,(LINK_FIELD)
ld hl,linkcomm_m_jt
rst $30
ret
+:
;Slave communication
call linkerror ;Timeout reset by slave serial interrupt, keep here
ret
linkcomm_m_jt:
.dw linkcm_0
.dw linkcm_1
.dw linkcm_2
.dw linkcm_3
.dw linkcm_4
.dw linkcm_5
linkcm_0:
;Send 0F, get 13
ld a,$0F
ldh ($01),a
ld a,$81
ldh ($02),a
ret
linkcm_1:
;Send HP MSB, get HP MSB
ld a,(ENEMY_HP)
swap a
and $F
or $20
ldh ($01),a
ld a,$81
ldh ($02),a
ret
linkcm_2:
;Send HP LSB, get HP LSB
ld a,(ENEMY_HP)
and $F
or $40
ldh ($01),a
ld a,$81
ldh ($02),a
ret
linkcm_3:
;Send shield, receive shield
ld a,(SHIELD_UP)
or a
jr z,+
ld a,(PLAYER_SH1)
and $F
+:
or $60
ldh ($01),a
ld a,$81
ldh ($02),a
ret
linkcm_4:
;Send attack, get attack
ld a,(PLAYERATK_TOSEND)
ld b,a
ld a,(LINK_SENDBOMB)
sla a
sla a
or b
and $F
or $80
ldh ($01),a
ld a,$81
ldh ($02),a
xor a
ld (PLAYERATK_TOSEND),a
ld (LINK_SENDBOMB),a
ret
linkcm_5:
;Send status, get status
ld a,(PLAYER_USEPOTION)
and 1
swap a
srl a
ld b,a
ld a,(PAUSE_FLAG)
and 1
sla a
sla a
or b
ld b,a
ld a,(PLAYER_DIZZY)
or a
ld a,b
jr z,+
or 2
+:
ld b,a
ld a,(LINK_SENDDEAD) ;Player died
or b
and $F
or $A0
ldh ($01),a
ld a,$81
ldh ($02),a
xor a
ld (PLAYER_USEPOTION),a
ld (LINK_SENDDEAD),a
ret
linkh_master:
ld a,(LINK_RX)
swap a
and $F
srl a
cp 6
jr c,+
ld a,(LINK_FIELD) ;Rewind one step, let's do this over again...
or a
jr z,+++
dec a
jr ++
+++:
ld a,5
++:
ld (LINK_FIELD),a
jp linkerror
+:
ld hl,linkser_m_jt
rst $30
xor a
ld (LINK_TIMEOUT),a
ret
linkser_m_jt:
.dw linksm_0
.dw linksm_1
.dw linksm_2
.dw linksm_3
.dw linksm_4
.dw linksm_5
linksm_0:
ld a,(LINK_RX) ;Presence check
cp $13
jp nz,linkerror
jp link_nextfield
linksm_1:
ld a,(LINK_RX) ;Slave HP MSB
and $F0
cp $30
jp nz,linkerror
ld a,(LINK_RX)
and $F
swap a
ld (LINK_HPBUFFER),a
jp link_nextfield
linksm_2:
ld a,(LINK_RX) ;Slave HP LSB
and $F0
cp $50
jp nz,linkerror
ld a,(PLAYER_USEPOTION) ;Dirty kludge to avoid bouncy HP bar after health potion
or a
jr nz,+
ld a,(LINK_RX)
and $F
ld b,a
ld a,(PLAYER_HP)
ld c,a
ld a,(LINK_HPBUFFER)
or b
cp c
jr z,+
ld (PLAYER_HP),a
ld hl,HPBAR_REFRESH
set 1,(hl)
+:
jp link_nextfield
linksm_3:
ld a,(LINK_RX) ;Slave shield
and $F0
cp $70
jp nz,linkerror
ld a,(LINK_RX)
and $F
ld (ENEMY_SH),a
jp link_nextfield
linksm_4:
ld a,(LINK_RX) ;Slave attack
and $F0
cp $90
jp nz,linkerror
ld a,(LINK_RX)
bit 2,a
jr z,+
push af
ld a,DAMAGE_BOMB
ld (PLAYERATK_FORCE),a
ld a,BLINK_TIME
ld (PLAYER_BLINK),a
call setdamage
pop af
and 3
+:
and $F
or a
jr z,link_nextfield
dec a
jr nz,+
call attackplayer ;Regular attack (slash animation)
jr link_nextfield
+:
ld de,aap_beer
call aa_init_enemy ;Beer special attack
jr link_nextfield
linksm_5:
ld a,(LINK_RX) ;Slave status
and $F0
cp $B0
jp nz,linkerror
ld a,(LINK_RX)
bit 0,a
jp nz,p2pdeath ;Player died
bit 3,a
call nz,got2ppotion
ld a,(LINK_RX)
ld b,a
ld hl,LINK_IGNOREPAUSE
ld a,(LINK_IGNOREPAUSE)
res 0,(hl)
or a
jr nz,++
ld a,b
srl a
srl a
and 1
xor 1
ld c,a
ld a,(PAUSE_FLAG)
or c
jr nz,+
call enterpause
jr ++
+:
ld a,(PAUSE_FLAG)
and c
jr z,++
call exitpause
++:
ld a,b
srl a
and 1
ld (ENEMY_DIZZY),a
jr link_nextfield
link_nextfield:
xor a
ld (LINK_TIMEOUT),a
ld a,(LINK_FIELD)
inc a
cp 6
jr nz,+
xor a
+:
ld (LINK_FIELD),a
ret