This repository has been archived by the owner on Aug 25, 2022. It is now read-only.
forked from neilsf/xcb-ext-sprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xcb-ext-sprite.bas
364 lines (327 loc) · 7.23 KB
/
xcb-ext-sprite.bas
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
rem **************************************
rem * XC=BASIC Sprite extension
rem *
rem * by Csaba Fekete
rem *
rem * Namespace: spr_
rem **************************************
const SPR_ENABLE = $d015
const SPR_X_COORD0 = $d000
const SPR_Y_COORD0 = $d001
const SPR_X_COORD1 = $d002
const SPR_Y_COORD1 = $d003
const SPR_X_COORD2 = $d004
const SPR_Y_COORD2 = $d005
const SPR_X_COORD3 = $d006
const SPR_Y_COORD3 = $d007
const SPR_X_COORD4 = $d008
const SPR_Y_COORD4 = $d009
const SPR_X_COORD5 = $d00a
const SPR_Y_COORD5 = $d00b
const SPR_X_COORD6 = $d00c
const SPR_Y_COORD6 = $d00d
const SPR_X_COORD7 = $d00e
const SPR_Y_COORD7 = $d00f
const SPR_X_COORD_MSB = $d010
const SPR_MULTICOLOR = $d01c
const SPR_MCOLOR1 = $d025
const SPR_MCOLOR2 = $d026
const SPR_EXP_X = $d01d
const SPR_EXP_Y = $d017
const SPR_DATA_PRIO = $d01b
const SPR_SPR_COLL = $d01e
const SPR_DATA_COLL = $d01f
const SPR_COLOR0 = $d027
const SPR_COLOR1 = $d028
const SPR_COLOR2 = $d029
const SPR_COLOR3 = $d02a
const SPR_COLOR4 = $d02b
const SPR_COLOR5 = $d02c
const SPR_COLOR6 = $d02d
const SPR_COLOR7 = $d02e
rem !! change this when VIC bank switching is supported !!
const SPR_PTR = $07f8
data spr_enable_bits![] = %00000001, %00000010, %00000100, %00001000, %00010000, %00100000, %01000000, %10000000
data spr_disable_bits![] = %11111110, %11111101, %11111011, %11110111, %11101111, %11011111, %10111111, %01111111
dim spr_multicolor1! @ SPR_MCOLOR1
dim spr_multicolor2! @ SPR_MCOLOR2
rem ******************************
rem * Command
rem * spr_enable
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem ******************************
proc spr_enable(spr_no!)
asm "
ldx {self}.spr_no
lda _SPR_ENABLE
ora.wx _spr_enable_bits
sta _SPR_ENABLE
"
endproc
rem ******************************
rem * Command
rem * spr_disable
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem ******************************
proc spr_disable(spr_no!)
asm "
ldx {self}.spr_no
lda _SPR_ENABLE
and.wx _spr_disable_bits
sta _SPR_ENABLE
"
endproc
rem ******************************
rem * Command
rem * spr_setposy
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem * Y! - Y coordinate
rem ******************************
proc spr_setposy(spr_no!, y!)
asm "
asl {self}.spr_no
ldx {self}.spr_no
lda {self}.y
sta.wx _SPR_Y_COORD0
"
endproc
rem ******************************
rem * Command
rem * spr_setposx
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem * x - X coordinate
rem ******************************
proc spr_setposx(spr_no!, x)
asm "
lda {self}.spr_no
asl
tax
lda {self}.x
sta.wx _SPR_X_COORD0
txa
lsr
tax
lda {self}.x + 1
beq .off
.on
lda _SPR_X_COORD_MSB
ora.wx _spr_enable_bits
jmp .quit
.off
lda _SPR_X_COORD_MSB
and.wx _spr_disable_bits
.quit
sta _SPR_X_COORD_MSB
"
endproc
rem ******************************
rem * Command
rem * spr_setpos
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem * x - X coordinate
rem * y! - Y coordinate
rem ******************************
proc spr_setpos(spr_no!, x, y!)
spr_setposx spr_no!, x
spr_setposy spr_no!, y!
endproc
rem ******************************
rem * Command
rem * spr_setshape
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem * shape! - Shape location in RAM
rem ******************************
proc spr_setshape(spr_no!, shape!)
asm "
lda {self}.shape
ldx {self}.spr_no
sta.wx _SPR_PTR
"
endproc
rem ******************************
rem * Command
rem * spr_setmulti
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem ******************************
proc spr_setmulti(spr_no!)
asm "
ldx {self}.spr_no
lda _SPR_MULTICOLOR
ora.wx _spr_enable_bits
sta _SPR_MULTICOLOR
"
endproc
rem ******************************
rem * Command
rem * spr_sethires
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem ******************************
proc spr_sethires(spr_no!)
asm "
ldx {self}.spr_no
lda _SPR_MULTICOLOR
and.wx _spr_disable_bits
sta _SPR_MULTICOLOR
"
endproc
rem ******************************
rem * Command
rem * spr_setcolor
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem * color! - Color
rem ******************************
proc spr_setcolor(spr_no!, color!)
asm "
lda {self}.color
ldx {self}.spr_no
sta.wx _SPR_COLOR0
"
endproc
rem ******************************
rem * Command
rem * spr_setdblwidth
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem ******************************
proc spr_setdblwidth(spr_no!)
asm "
ldx {self}.spr_no
lda _SPR_EXP_X
ora.wx _spr_enable_bits
sta _SPR_EXP_X
"
endproc
rem ******************************
rem * Command
rem * spr_cleardblwidth
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem ******************************
proc spr_cleardblwidth(spr_no!)
asm "
ldx {self}.spr_no
lda _SPR_EXP_X
and.wx _spr_disable_bits
sta _SPR_EXP_X
"
endproc
rem ******************************
rem * Command
rem * spr_setdblheight
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem ******************************
proc spr_setdblheight(spr_no!)
asm "
ldx {self}.spr_no
lda _SPR_EXP_Y
ora.wx _spr_enable_bits
sta _SPR_EXP_Y
"
endproc
rem ******************************
rem * Command
rem * spr_cleardblheight
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem ******************************
proc spr_cleardblheight(spr_no!)
asm "
ldx {self}.spr_no
lda _SPR_EXP_Y
and.wx _spr_disable_bits
sta _SPR_EXP_Y
"
endproc
rem ******************************
rem * Command
rem * spr_behindbg
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem ******************************
proc spr_behindbg(spr_no!)
asm "
ldx {self}.spr_no
lda _SPR_DATA_PRIO
ora.wx _spr_enable_bits
sta _SPR_DATA_PRIO
"
endproc
rem ******************************
rem * Command
rem * overbg
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem ******************************
proc spr_overbg(spr_no!)
asm "
ldx {self}.spr_no
lda _SPR_DATA_PRIO
and.wx _spr_disable_bits
sta _SPR_DATA_PRIO
"
endproc
rem ******************************
rem * Function
rem * spr_spr_collision
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem ******************************
fun spr_spr_collision!(spr_no!)
result! = 0
asm "
lda _SPR_SPR_COLL
ldx {self}.spr_no
and.wx _spr_enable_bits
beq .1
lda #$01
sta {self}.result
.1
"
return result!
endfun
rem ******************************
rem * Function
rem * spr_data_collision
rem *
rem * Arguments:
rem * spr_no! - No of sprite
rem ******************************
fun spr_data_collision!(spr_no!)
result! = 0
asm "
lda _SPR_DATA_COLL
ldx {self}.spr_no
and.wx _spr_enable_bits
beq .1
lda #$01
sta {self}.result
.1
"
return result!
endfun