-
Notifications
You must be signed in to change notification settings - Fork 1
/
spmgr.c
391 lines (340 loc) · 10.1 KB
/
spmgr.c
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
#include "spmgr.h"
#include "types.h"
#include "params.h"
#include "board.h"
#include "colors.h"
#include "level.h"
#include "print_tile.h"
#define SPR_PAT_SRC_SNK_MASK 64
#define SPR_PAT_SRC_1 65
#define SPR_PAT_SRC_4 66
#define SPR_PAT_SNK_1 67
#define SPR_PAT_SNK_4 68
#define SPR_PAT_TLMARK 69
#define SPR_PAT_CURSOR 70
#define SPR_PAT_HAND 71
#define SPR_PAT_TALLY 72
#define SPR_PAT_PAINT 73
#define SPR_PAT_CHECK 77
#define SPR_PAT_SRC_9 81
#define SPR_PAT_SNK_9 82
ubyte spmgr_curr_idx = 0;
ubyte spmgr_notfix_idx = 0;
ubyte spmgr_cursor_idx = 0;
ubyte spmgr_marker_idx = 0;
ubyte spmgr_fakcur_idx = 0;
__asm
EXTERN clear_sprites
EXTERN init_cursor_sprite
EXTERN init_2x2_quad_sprite
EXTERN update_2x2_quad_sprite_palettes
EXTERN update_2x2_quad_sprite_hide
EXTERN update_2x2_quad_sprite_show
EXTERN update_2x2_quad_sprite_pos
EXTERN update_cursor_sprite
EXTERN setup_scale2x_sprite
EXTERN setup_2x2_sprite
EXTERN update_2x2_sprite_palette
__endasm;
void spmgr_init()
{
param0b = 0;
__asm__("CALL clear_sprites");
spmgr_curr_idx = 0;
}
///////////////////////////////////////////////////////////////////////////////
void spmgr_setup_cursor()
{
spmgr_cursor_idx = spmgr_curr_idx;
spmgr_cursor_set_arrow();
spmgr_curr_idx += 1;
}
sbyte spmgr_cursor_dx = 0;
void spmgr_cursor_set_arrow()
{
param0b = spmgr_cursor_idx; // sprite
param1b = SPR_PAT_CURSOR; // pattern
__asm__("CALL init_cursor_sprite");
spmgr_cursor_dx = 0;
}
void spmgr_cursor_set_hand()
{
param0b = spmgr_cursor_idx; // sprite
param1b = SPR_PAT_HAND; // pattern
__asm__("CALL init_cursor_sprite");
spmgr_cursor_dx = -8;
}
void spmgr_update_cursor(uword x, ubyte y)
{
param0b = spmgr_cursor_idx;
param0w = x + spmgr_cursor_dx;
param1b = y;
__asm__("CALL update_cursor_sprite");
}
///////////////////////////////////////////////////////////////////////////////
void spmgr_setup_fake_cursor()
{
spmgr_fakcur_idx = spmgr_curr_idx;
param0b = spmgr_fakcur_idx; // sprite
param1b = SPR_PAT_HAND; // pattern
__asm__("CALL init_cursor_sprite");
spmgr_curr_idx += 1;
}
void spmgr_update_fake_cursor(uword x, ubyte y)
{
param0b = spmgr_fakcur_idx;
param0w = x - 8;
param1b = y;
__asm__("CALL update_cursor_sprite");
}
///////////////////////////////////////////////////////////////////////////////
void spmgr_setup_tally(uword x, ubyte y, ubyte attr)
{
param0b = spmgr_curr_idx; // sprite
param1b = SPR_PAT_TALLY; // pattern
__asm__("CALL init_cursor_sprite");
param0w = x;
param1b = y;
param2b = attr;
__asm__("CALL update_cursor_sprite_ex");
spmgr_curr_idx += 1;
}
void spmgr_hide_tally(ubyte spridx)
{
param0b = spridx; // sprite
param1b = SPR_PAT_TALLY; // pattern
__asm__("CALL hide_cursor_sprite");
}
void spmgr_show_tally(ubyte spridx)
{
param0b = spridx; // sprite
param1b = SPR_PAT_TALLY; // pattern
__asm__("CALL show_cursor_sprite");
}
///////////////////////////////////////////////////////////////////////////////
void spmgr_setup_marker()
{
spmgr_marker_idx = spmgr_curr_idx;
param0b = spmgr_marker_idx; // sprite
param1b = SPR_PAT_TLMARK; // pattern
param2b = 8; // (BOARD_X + 4*i) * 0; // x
param3b = 24; // (BOARD_Y + 4*j) * 0; // y
__asm__("CALL init_2x2_quad_sprite");
param4b = param5b = param6b = param7b = 0;
__asm__("CALL update_2x2_quad_sprite_palettes");
spmgr_curr_idx += 4;
}
void spmgr_hide_marker()
{
param0b = spmgr_marker_idx; // sprite
param1b = SPR_PAT_TLMARK; // pattern
__asm__("CALL update_2x2_quad_sprite_hide");
}
void spmgr_show_marker()
{
param0b = spmgr_marker_idx; // sprite
param1b = SPR_PAT_TLMARK; // pattern
__asm__("CALL update_2x2_quad_sprite_show");
}
void spmgr_pos_marker(ubyte x, ubyte y)
{
param0b = spmgr_marker_idx; // sprite
param2b = x;
param3b = y;
__asm__("CALL update_2x2_quad_sprite_pos");
}
///////////////////////////////////////////////////////////////////////////////
void spmgr_end_fixed_sprites()
{
spmgr_notfix_idx = spmgr_curr_idx;
}
///////////////////////////////////////////////////////////////////////////////
void spmgr_clear_level()
{
param0b = spmgr_notfix_idx;
__asm__("CALL clear_sprites");
spmgr_curr_idx = spmgr_notfix_idx;
}
///////////////////////////////////////////////////////////////////////////////
void spmgr_put_snk_src_mask(ubyte i, ubyte j)
{
param0b = spmgr_curr_idx; // sprite
param1b = 64; // pattern
param2b = (BOARD_X + 4*i) * 8; // x
param3b = (BOARD_Y + 4*j) * 8; // y
__asm__("CALL setup_scale2x_sprite");
spmgr_curr_idx += 1;
}
void spmgr_put_src(ubyte i, ubyte j, ubyte colcnt)
{
if (colcnt <= 4) {
param0b = spmgr_curr_idx; // sprite
param1b = SPR_PAT_SRC_1; // pattern
if (colcnt > 1)
param1b = SPR_PAT_SRC_4;
param2b = (BOARD_X + 4*i) * 8; // x
param3b = (BOARD_Y + 4*j) * 8; // y
__asm__("CALL init_2x2_quad_sprite");
spmgr_curr_idx += 4;
}
else {
ubyte x0 = 5 + (BOARD_X + 4*i) * 8; // x
ubyte y0 = 5 + (BOARD_Y + 4*j) * 8; // y
for (ubyte j = 0; j < 3; j++) {
for (ubyte i = 0; i < 3; i++) {
param0b = spmgr_curr_idx++;
param1b = SPR_PAT_SRC_9;
param2b = x0 + 7*i;
param3b = y0 + 7*j;
__asm__("CALL init_src9snk_sprite");
}
}
}
}
void spmgr_put_snk(ubyte i, ubyte j, ubyte colcnt)
{
if (colcnt <= 4) {
param0b = spmgr_curr_idx; // sprite
param1b = SPR_PAT_SNK_1; // pattern
if (colcnt > 1)
param1b = SPR_PAT_SNK_4;
param2b = (BOARD_X + 4*i) * 8; // x
param3b = (BOARD_Y + 4*j) * 8; // y
__asm__("CALL init_2x2_quad_sprite");
spmgr_curr_idx += 4;
}
else {
ubyte x0 = 5 + (BOARD_X + 4*i) * 8; // x
ubyte y0 = 5 + (BOARD_Y + 4*j) * 8; // y
for (ubyte j = 0; j < 3; j++) {
for (ubyte i = 0; i < 3; i++) {
param0b = spmgr_curr_idx++;
param1b = SPR_PAT_SNK_9;
param2b = x0 + 7*i;
param3b = y0 + 7*j;
__asm__("CALL init_src9snk_sprite");
}
}
}
}
void spmgr_update_srcsnk(ubyte spridx, ubyte colidx, ubyte colcnt)
{
if (colcnt <= 4) {
param0b = spridx; // sprite
if (colcnt == 1) {
ubyte color = lev_colors[colidx];
param4b = color;
param5b = color;
param6b = color;
param7b = color;
}
else {
param4b = lev_colors[colidx];
param5b = lev_colors[colidx+1];
param6b = COLOR_BLK;
param7b = COLOR_BLK;
if (colcnt > 2) param6b = lev_colors[colidx+2];
if (colcnt > 3) param7b = lev_colors[colidx+3];
}
__asm__("CALL update_2x2_quad_sprite_palettes");
}
else {
for (ubyte i = 0; i < 9; i++) {
param0b = spridx++;
if (i < colcnt)
param4b = lev_colors[colidx + i];
else
param4b = COLOR_BLK;
__asm__("CALL update_src9snk_sprite_color");
}
}
}
void spmgr_put_src_1(ubyte i, ubyte j, ubyte color)
{
param0b = spmgr_curr_idx; // sprite
param1b = 65; // pattern
param2b = (BOARD_X + 4*i) * 8; // x
param3b = (BOARD_Y + 4*j) * 8; // y
param4b = color;
param5b = color;
param6b = color;
param7b = color;
__asm__("CALL init_2x2_quad_sprite");
__asm__("CALL update_2x2_quad_sprite_palettes");
spmgr_curr_idx += 4;
}
void spmgr_put_snk_1(ubyte i, ubyte j, ubyte color)
{
param0b = spmgr_curr_idx; // sprite
param1b = 67; // pattern
param2b = (BOARD_X + 4*i) * 8; // x
param3b = (BOARD_Y + 4*j) * 8; // y
param4b = color;
param5b = color;
param6b = color;
param7b = color;
__asm__("CALL init_2x2_quad_sprite");
__asm__("CALL update_2x2_quad_sprite_palettes");
spmgr_curr_idx += 4;
}
void spmgr_put_pnt(ubyte i, ubyte j, ubyte colidx)
{
param0b = spmgr_curr_idx; // sprite
param1b = SPR_PAT_PAINT; // pattern
param2b = (BOARD_X + 4*i) * 8; // x
param3b = (BOARD_Y + 4*j) * 8; // y
__asm__("CALL setup_2x2_sprite");
spmgr_curr_idx += 4;
// using text colors
param4b = 8 + lev_colors[colidx];
__asm__("CALL update_2x2_sprite_palette");
}
void spmgr_put_check(ubyte i, ubyte j)
{
param0b = spmgr_curr_idx; // sprite
param1b = SPR_PAT_CHECK; // pattern
param2b = (BOARD_X + 4*i) * 8; // x
param3b = (BOARD_Y + 4*j) * 8; // y
__asm__("CALL setup_2x2_sprite");
spmgr_curr_idx += 4;
}
void spmgr_set_check_color(ubyte spridx, ubyte color)
{
param0b = spridx; // sprite
param4b = color;
__asm__("CALL update_2x2_sprite_palette");
}
void spmgr_hide_check(ubyte spridx)
{
param0b = spridx; // sprite
param1b = SPR_PAT_TLMARK; // pattern
__asm__("CALL update_2x2_quad_sprite_hide");
}
void spmgr_show_check(ubyte spridx)
{
param0b = spridx; // sprite
param1b = SPR_PAT_CHECK; // pattern
__asm__("CALL update_2x2_quad_sprite_show");
}
///////////////////////////////////////////////////////////////////////////////
void spmgr_print_debug()
{
#define spmgr_print_debug_ENABLED
ubyte x = 30;
ubyte y = 2;
print_set_color(CTEXT_WHI);
print_set_pos(x, y);
print_str("SPRITE MGR");
#ifndef spmgr_print_debug_ENABLED
print_set_pos(x, ++y);
print_str("DISABLED");
#else
y += 2;
x++;
print_set_pos(x, y++); print_str("CURSOR "); print_hex_byte(spmgr_cursor_idx);
print_set_pos(x, y++); print_str("MARKER "); print_hex_byte(spmgr_marker_idx);
print_set_pos(x, y++); print_str("NOTFIX "); print_hex_byte(spmgr_notfix_idx);
y++;
print_set_pos(x, y++); print_str("CURRNT "); print_hex_byte(spmgr_curr_idx);
#endif
}