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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
Display_Entities:
LD HL, $mem_entities_list
CALL =Display_Entity
CALL =Display_Entity
CALL =Display_Entity
CALL =Display_Entity
CALL =Display_Entity
CALL =Display_Entity
CALL =Display_Entity
CALL =Display_Entity
CALL =Display_Entity
CALL =Display_Entity
CALL =Display_Entity
CALL =Display_Entity
CALL =Display_Entity
CALL =Display_Entity
CALL =Display_Entity
CALL =Display_Entity
LD BC, $00a0
LD HL, $mem_oam_buffer
LD A, $mem_oam_buffer_low
ADD L
LD L, A
LD A, $mem_oam_buffer_low
XOR $ff
INC A
ADD C
LD C, A
CALL =bzero
RET
Display_Entity:
LD A, (HL+)
LD E, A
CP $00
JP Z, =.skip
LD A, (HL+)
ADD $80
LD D, A
LD A, $mem_viewport_x
LD B, A
SUB $82
CP D
JP NC, =.skip
ADD $0e
CP D
JP C, =.skip
LD A, D
SUB $80
SUB B
AND $0f
SWAP A
LD B, A
LD A, (HL+)
ADD $80
LD D, A
LD A, $mem_viewport_y
LD C, A
SUB $82
CP D
JP NC, =.skip
ADD $0d
CP D
JP C, =.skip
LD A, D
SUB $80
SUB C
AND $0f
SWAP A
ADD $06
LD C, A
.Check_Window_Overlap:
LD A, $mem_display_flag
BIT 3, A
JR Z, =.Check_Window_Overlap.end
LD A, $6f
CP B
JR NC, =.Check_Window_Overlap.end
LD A, $55
CP C
JP C, =.skip
.Check_Window_Overlap.end:
.ADD_MOVING_ANIMATION_OFFSET
LD A, (HL+)
BIT 3, A
LD D, A
.Moving_Animation:
JR Z, =.Moving_Animation.end
LD A, $mem_moving_animation_step
.ADD_A_TO_DIRECTION_BC
.Moving_Animation.end:
.Blinking_Animation:
LD A, L
AND $f0
OR $07
LD L, A
BIT 3, (HL)
JR Z, =.Blinking_Animation.end
LD A, $mem_blinking_animation_counter
AND $02
CP $02
JP Z, =.skip
.Blinking_Animation.end:
.Action_Animation:
LD A, L
AND $f0
OR $0a
LD L, A
LD A, $01
CP (HL)
JR NZ, =.Action_Animation.end
LD A, $mem_moving_animation_step
CP $04
JR C, =.Action_Animation.Step1
CP $0c
JR C, =.Action_Animation.Step2
JR =.Action_Animation.end
.Action_Animation.Step1:
SLA A
SLA A
JR =.Action_Animation.Apply
.Action_Animation.Step2:
SUB $04
SLA A
XOR $ff
INC A
ADD $10
.Action_Animation.Apply:
.ADD_A_TO_DIRECTION_BC
.Action_Animation.end:
.SuperJump_Animation:
LD A, L
AND $f0
OR $0a
LD L, A
LD A, $03
CP (HL)
JR NZ, =.SuperJump_Animation.end
LD A, $mem_moving_animation_step
CP $00
JR Z, =.SuperJump_Animation.end
.ADD_A_TO_DIRECTION_BC
LD A, $mem_moving_animation_step
SUB $08
.ABS
SLA A
CPL
INC A
ADD $10
CPL
INC A
ADD C
LD C, A
.SuperJump_Animation.end:
.Shaking_Animation:
LD A, L
AND $f0
OR $0a
LD L, A
LD A, $04
CP (HL)
JR NZ, =.Shaking_Animation.end
LD A, $mem_moving_animation_step
CP $00
JR Z, =.Shaking_Animation.end
LD A, $mem_moving_animation_step
SRA A
AND $03
BIT 1, A
RES 1, A
JR NZ, =.Shaking_Animation.skip_invert
CPL
INC A
.Shaking_Animation.skip_invert:
ADD B
LD B, A
.Shaking_Animation.end:
.Moving_2x:
LD A, L
AND $f0
OR $0a
LD L, A
LD A, $05
CP (HL)
JR NZ, =.Moving_2x.end
LD A, $mem_moving_animation_step
CP $00
JR Z, =.Moving_2x.end
SLA A
AND $0f
PUSH BC
LD B, A
LD A, $mem_moving_animation_step
CPL
INC A
ADD B
POP BC
.ADD_A_TO_DIRECTION_BC
LD A, $mem_moving_animation_step
SUB $08
.ABS
SUB $04
.ABS
CPL
INC A
ADD $04
CPL
INC A
ADD C
LD C, A
.Moving_2x.end:
.Moving_Hops:
BIT 3, D
JR Z, =.Moving_Hops.end
LD A, L
AND $f0
OR $0a
LD L, A
LD A, (HL)
LD A, $00
CP (HL)
JR NZ, =.Moving_Hops.end
LD A, $mem_moving_animation_step
SUB $08
.ABS
SUB $04
.ABS
CPL
INC A
ADD $04
CPL
INC A
ADD C
LD C, A
.Moving_Hops.end:
LD A, D
SWAP A
AND $07
CP $enum_direction_left
JR Z, =.Left_Direction_sprite
CP $enum_direction_right
JR Z, =.Right_Direction_sprite
CP $enum_direction_up
JR Z, =.Up_Direction_sprite
JP =.Down_Direction_sprite
.Left_Direction_sprite:
CALL =Flags_From_Animation ; Uses and changes HL
LD D, A
JP =.Write_OBJ
.Right_Direction_sprite:
LD A, $02
ADD E
LD E, A
CALL =Flags_From_Animation ; Uses and changes HL
OR $20
LD D, A
JP =.Write_OBJ
.Up_Direction_sprite:
LD A, $04
ADD E
LD E, A
CALL =Flags_From_Animation ; Uses and changes HL
LD D, A
JP =.Write_OBJ
.Down_Direction_sprite:
LD A, $08
ADD E
LD E, A
CALL =Flags_From_Animation ; Uses and changes HL
LD D, A
JP =.Write_OBJ
.Write_OBJ:
PUSH HL
; First OBJ (left)
LD HL, $mem_oam_buffer
LD A, $mem_oam_buffer_low
LD L, A
LD A, C
LD (HL+), A
LD A, B
LD (HL+), A
LD A, E
INC A
LD (HL+), A
LD A, D
LD (HL+), A
; Second OBJ
LD A, B
ADD $08
LD B, A
LD A, C
LD (HL+), A
LD A, B
LD (HL+), A
LD A, E
XOR $02
INC A
LD (HL+), A
LD A, D
LD (HL+), A
LD A, L
LD $mem_oam_buffer_low, A
POP HL
.skip:
LD A, L
AND $f0
ADD $10
LD L, A
RET
Flags_From_Animation: ; Expect entity in HL (offset doesn't matter) + breaks D (but result in A)
LD A, L
AND $f0
OR $0a
LD L, A
LD A, $02
CP (HL)
LD D, $00
JR NZ, =Flags_From_Animation.Shadow_Palette
LD D, $40
Flags_From_Animation.Shadow_Palette:
LD A, L
AND $f0
OR $07
LD L, A
BIT 1, (HL)
LD A, D
RET Z
OR $10
RET
|