aboutsummaryrefslogtreecommitdiff
path: root/entity/display.gbasm
blob: 80c11402394bbc2f036a9b4f5a17c075f5eb9a2a (plain)
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
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, =Display_Entity.skip

	LD A, (HL+)
	ADD $80
	LD D, A
	LD A, $mem_viewport_x
	LD B, A
	SUB $82
	CP D
	JP NC, =Display_Entity.skip
	ADD $0e
	CP D
	JP C, =Display_Entity.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, =Display_Entity.skip
	ADD $0d
	CP D
	JP C, =Display_Entity.skip
	LD A, D
	SUB $80
	SUB C
	AND $0f
	SWAP A
	ADD $06
	LD C, A

	.ADD_MOVING_ANIMATION_OFFSET

	LD A, (HL+)
	BIT 3, A
	LD D, A
	Display_Entity.Moving_Animation:
		JR Z, =Display_Entity.Moving_Animation.end

		LD A, $mem_moving_animation_step
		.ADD_A_TO_DIRECTION_BC
	Display_Entity.Moving_Animation.end:

	Display_Entity.Action_Animation:
		LD A, D
		AND $f0
		CP $10
		JR NZ, =Display_Entity.Action_Animation.end

		LD A, $mem_moving_animation_step
		CP $04
		JR C, =Display_Entity.Action_Animation.Step1
		CP $0c
		JR C, =Display_Entity.Action_Animation.Step2
		JR =Display_Entity.Action_Animation.end

		Display_Entity.Action_Animation.Step1:
			SLA A
			SLA A
			JR =Display_Entity.Action_Animation.Apply

		Display_Entity.Action_Animation.Step2:
			SUB $04
			SLA A
			XOR $ff
			INC A
			ADD $10

		Display_Entity.Action_Animation.Apply:
			.ADD_A_TO_DIRECTION_BC
	Display_Entity.Action_Animation.end:

	Display_Entity.SuperJump_Animation:
		LD A, D
		AND $f0
		CP $30
		JR NZ, =Display_Entity.SuperJump_Animation.end

		LD A, $mem_moving_animation_step
		CP $00
		JR Z, =Display_Entity.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
	Display_Entity.SuperJump_Animation.end:

	Display_Entity.Shaking_Animation:
		LD A, D
		AND $f0
		CP $40
		JR NZ, =Display_Entity.Shaking_Animation.end

		LD A, $mem_moving_animation_step
		CP $00
		JR Z, =Display_Entity.Shaking_Animation.end
		LD A, $mem_moving_animation_step
		SRA A
		AND $03
		BIT 1, A
		RES 1, A
		JR NZ, =Display_Entity.Shaking_Animation.skip_invert
		CPL
		INC A
		Display_Entity.Shaking_Animation.skip_invert:
		ADD B
		LD B, A
	Display_Entity.Shaking_Animation.end:

	Display_Entity.Moving_Hops:
		LD A, D
		AND $f8
		CP $08
		JR NZ, =Display_Entity.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
	Display_Entity.Moving_Hops.end:

	LD A, D
	AND $07

	CP $enum_direction_left
	JR Z, =Display_Entity.Left_Direction_sprite
	CP $enum_direction_right
	JR Z, =Display_Entity.Right_Direction_sprite
	CP $enum_direction_up
	JR Z, =Display_Entity.Up_Direction_sprite
	JP =Display_Entity.Down_Direction_sprite

	Display_Entity.Left_Direction_sprite:
		CALL =Flags_From_Animation
		LD D, A
		JP =Display_Entity.Write_OBJ

	Display_Entity.Right_Direction_sprite:
		LD A, $02
		ADD E
		LD E, A
		CALL =Flags_From_Animation
		OR $20
		LD D, A
		JP =Display_Entity.Write_OBJ

	Display_Entity.Up_Direction_sprite:
		LD A, $04
		ADD E
		LD E, A
		CALL =Flags_From_Animation
		LD D, A
		JP =Display_Entity.Write_OBJ

	Display_Entity.Down_Direction_sprite:
		LD A, $08
		ADD E
		LD E, A
		CALL =Flags_From_Animation
		LD D, A
		JP =Display_Entity.Write_OBJ

	Display_Entity.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

	Display_Entity.skip:
	LD A, L
	AND $f0
	ADD $10
	LD L, A
	RET

Flags_From_Animation:
	LD A, D
	AND $f0
	CP $20
	LD A, $00
	RET NZ
	LD A, $40
	RET