aboutsummaryrefslogtreecommitdiff
path: root/game/entities.asm
blob: fa9d8fdd4803e65b5413d0f0d20964504368e904 (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
;
; Simple array based entity system
;

.equ ET_NONE    0
.equ ET_PLAYER  1
.equ ET_ENEMY   2
.equ ET_END     0xff

.equ ET_BG      0xa000

entities_erase:
    ; bg is stored in ET_BG addr
    ld b, >ET_BG
    push b

    ld x, <entities
    ld a, >entities

entities_erase_next:
    ld y, [a : x]
    cmp y, ET_END
    bz
    jmp entities_erase_done

    ; write, no transparent
    ld y, 1
    push y

    ; dst: x
    inc x
    bo
    inc a
    ld y, [a : x]
    push y

    ; dst: y
    inc x
    bo
    inc a
    ld y, [a : x]
    push y

    ; src: saved bg
    ld y, [sp + 3]
    push y
    ld y, 0
    push y

    call entities_blt

    pop y
    pop y
    pop y
    pop y
    pop y

    ; next entity
    add x, 5
    bo
    inc a

    pop b
    inc b
    push b

    jmp entities_erase_next

entities_erase_done:
    pop a
    ret

entities_update:
    ld x, <entities
    ld a, >entities

entities_update_next:
    ld y, [a : x]
    cmp y, ET_END
    bz
    ret

    push a
    push x

    add x, 5
    bo
    inc a

    ld y, [a : x]
    inc x
    bo
    inc a
    ld b, [a : x]
    inc x
    bo
    inc a

    ld x, [sp + 0]
    ld a, [sp + 1]

    ; entity update
    push a
    push x
    call [b : y]
    pop x
    pop x

    pop x
    pop a

    add x, 7
    bo
    inc a

    jmp entities_update_next

entities_draw:
    ; bg is stored in ET_BG addr
    ld b, >ET_BG
    push b

    ld x, <entities
    ld a, >entities

entities_draw_next:
    ld y, [a : x]
    cmp y, ET_END
    bz
    jmp entities_draw_done

    inc x
    bo
    inc a
    ; save x addr for later
    push a
    push x

    ; save bg

    ; read, no transparent
    ld y, 4
    push y

    ; dst: x
    ld y, [a : x]
    push y

    ; dst: y
    inc x
    bo
    inc a
    ld y, [a : x]
    push y

    ; dst: save bg
    ld y, [sp + 5]
    push y
    ld y, 0
    push y

    call entities_blt

    pop y
    pop y
    pop y
    pop y
    pop y

    ; draw sprite

    ; x addr
    pop x
    pop a

    ; write, transparent
    ld y, 3
    push y

    ; dst: x
    ld y, [a : x]
    push y

    ; dst: y
    inc x
    bo
    inc a
    ld y, [a : x]
    push y

    ; src: the sprite
    inc x
    bo
    inc a
    ld y, [a : x]
    inc x
    bo
    inc a
    ld b, [a : x]
    push b
    push y

    call entities_blt

    pop y
    pop y
    pop y
    pop y
    pop y

    ; next entity
    add x, 3
    bo
    inc a

    pop b
    inc b
    push b

    jmp entities_draw_next

entities_draw_done:
    pop a
    ret

; sp: write mode
;     y coord
;     x coord
;     addr
entities_blt:
    ; settings mode
    ld y, 128
    ld b, 0xb0
    port b, y

    ; setup
    inc b

    ; addr
    ld y, [sp + 2]
    port b, y
    ld y, [sp + 3]
    port b, y

    ; x
    ld y, [sp + 5]
    port b, y
    ; y
    ld y, [sp + 4]
    port b, y

    ; 16x16
    ld y, 16
    port b, y
    port b, y

    ; blit
    dec b
    ; write mode
    ld y, [sp + 6]
    port b, y
    ret