-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo-16-sprites.wnf
278 lines (203 loc) · 5.68 KB
/
demo-16-sprites.wnf
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
program demo16sp
lomem=$4000,runad
// --- GTIA ---
byte array HPOSP[4]=@
byte array HPOSM[4]=@
byte array SIZEP[4]=@ // 53256
byte PAL=@ // 1=PAL, $E=NTSC
byte array COLPM[4]=@ // 53266
byte array COLPF[4]=@ // 53270
byte COLBK=@ // 53274
byte array PCOLR[4]=@ // shadow from 53266-9
byte array COLOR[5]=708 // shadow from 53270-4
byte GRACTL=@ // 53277 // 2:Player an 1: Missiles an
byte HITCLR=@ // 53278 // delete the collision registers
// --- POKEY ---
byte RANDOM=@ // 53770 // $d20a
// --- ANTIC ---
byte DMACTL=@ // 54272
byte SDMCTL=@ // 559 // shadow from 54272 DMACTL
byte CHACTL=@ // 54273
byte CHACT=@
word DLIST=@ // 54274
byte PMBASE=@ // 54279 // 2kb range ($800)
byte CHBASE=@ // 54281
byte CHBAS=@ // shadow from 54281 (Font) 1k range ($400)
byte WSYNC=@ // Write value will stop CPU
byte VCOUNT=@ // vertical screen (line / 2) in PAL 0-155 in NTSC 0-131
byte GPRIOR=@
word SDLSTL=@
const pm_addr = $B000
procedure initPlayerMissile()
begin
PCOLR[0]:=$02 // 704
PCOLR[1]:=$04
PCOLR[2]:=$06
PCOLR[3]:=$08
COLOR[2]:=2
COLOR[3]:=$FF
GPRIOR := $10+ // The 4 missiles are combined to a 5th player
$1 // Prioity player, screen, background
SDMCTL:= $20+ // DMA for Display List
$10+ // one line PM resolution
$08+ // DMA player
$04+ // DMA missiles
$02 // normal screen width (40bytes)
GRACTL:=3
PMBASE:=HI:pm_addr
end
byte array sprite_x[MAX_SPRITES] = @sprite_x
byte array sprite_y[MAX_SPRITES] = @sprite_y
byte array sprite_shape[MAX_SPRITES] = @sprite_shape
byte array sprite_color[MAX_SPRITES] = @sprite_color
// The sprites must be written only when the electron beam is below the lowest sprite to be displayed.
procedure wait_and_show_all_sprites()
begin
// @waitline(111)
// @backcolorline($88) // only to show where we are (light blue line)
@show_sprites() // This function MUST call each 1/50s frame
end
byte x_,y_
byte xmin,xmax,ymin,ymax
byte array x[MAX_SPRITES]
byte array y[MAX_SPRITES]
byte array xstep[MAX_SPRITES]
byte array ystep[MAX_SPRITES]
byte array colors[MAX_SPRITES]
byte i=203,j
// tape measure on the right, we use missiles PMG for that
//
// See the DLIs, each produce a gray line.
// the meter value in the @reset_meter function in file: multi-sprite-dli.INC must set
// to the tape measure displayed value under first occurance of such gray line or you get wrong
// sprite data.
procedure init_tape_measure()
begin
i := 48 + 160 - 2 // horizontal position of the tape measure
hposm[0] := i
hposm[1] := i-2
hposm[2] := i-4
hposm[3] := i-6
@move(adr:@tape_measure, pm_addr + $300, 248) // copy the array content to the missile data (pm_addr + $300)
end
const PM_X_OFFSET = 48
const PM_Y_OFFSET = 32
procedure init_sprite_start_position_and_colors()
begin
for i:=0 to MAX_SPRITES-1 do
begin
y[i] := PM_Y_OFFSET + i * 8
x[i] := PM_X_OFFSET + i * 9
xstep[i] := 1
ystep[i] := 1
colors[i] := $0a + i * 16
sprite_shape[i] := i & 15
end
end
procedure position_sprites()
local i
begin
for i:=0 to MAX_SPRITES-1 do
begin
x_ := x[i]
y_ := y[i]
y_ := y_ + ystep[i] // simple positioning of sprites
x_ := x_ + xstep[i]
if x_ >= xmax or x_ < xmin then
begin
xstep[i] := -xstep[i]
end
if y_ >= ymax or y_ < ymin then
begin
ystep[i] := -ystep[i]
end
// set a sprite (x, y, color, data)
sprite_color[i] := colors[i]
sprite_x[i] := x_
sprite_y[i] := y_
sprite_shape[i] := sprite_shape[i] + 1
// reset animation pointer
if sprite_shape[i] > 15 then sprite_shape[i] := 0
x[i] := x_
y[i] := y_
end
end
// MAIN Routine
word count
procedure increment()
begin
count := count + 1
end
byte animate
begin
@init_vbi()
@sleep(1)
@start_displaylist_interrupts()
initPlayerMissile()
@init_sprites()
init_tape_measure()
init_sprite_start_position_and_colors()
// frame, in which the sprites are moved
xmax := PM_X_OFFSET + 160 - 8
xmin := PM_X_OFFSET
ymax := PM_Y_OFFSET + 192 - 16
ymin := PM_Y_OFFSET
@printf("\nSimple Demonstration of %d sprites", MAX_SPRITES)
// Demonstration loop
@init_fastscreen($bc40)
@init_set_bytes_per_line(40)
position_sprites() // ; 3380 cycles
animate := 10
for j:=1 to 60 do // loop for 60s
begin
for i:=1 to 50 do // loop for 1s
begin
if animate != 0 then
begin
animate := animate - 1
end
else
begin
animate := 1 // 25 pictures per sec
// animate := 2 // 16.6 pics per sec
// animate := 3 // 12.5 pics per sec
position_sprites() // ; 3380 cycles
end
count := 0
// try to do something and count it how often it occurs
while vcount >= 112 do
begin
increment()
end
while vcount < 112 do
begin
increment()
end
@backcolorline($88) // only to show where we are (light blue line)
// show how often we could count something
@fast_gotoxy(2,0)
@printff("%d ", count)
wait_and_show_all_sprites()
end
end
@stop_displaylist_interrupts()
@deinit_vbi()
hposm[0] := 0
hposm[1] := 0
hposm[2] := 0
hposm[3] := 0
@exit(0)
end
include "FAST_SCREEN_OUTPUT.INC"
include "SCREEN_OUTPUT.INC"
include "PRINTF.INC"
include "FILLBYTE.INC"
include "BASIC.INC"
include "BACKCOLORLINE.INC"
include "BREAKKEY.INC"
include "displaylist.INC"
include "dli.INC"
include "multi-sprite-dli.INC"
include "multi-sprite-multiplexer.INC"
include "SPRITES.INC"
include "SPRTDATA.INC"