-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticles.asm
254 lines (239 loc) · 13.6 KB
/
Particles.asm
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
;****************************************************************************************************************
;
; This file contains particle related routines
;
; genPrtcl
; fndInctvPrtcl
; updtPrtcls
;
;****************************************************************************************************************
;****************************************************************************************************************
; CONSTANTS
;****************************************************************************************************************
PRTCLLFSPN equ 30 ; Lifespan of each particle in 1/50th second
;****************************************************************************************************************
; Generate three particles at the location provided in BC
;
; Entry Registers:
; BC = Pixel address, B = X, C = Y
; Registers Used:
; A, B, C, D, E, H, L
; Returned Registers:
; NONE
;****************************************************************************************************************
genPrtcl
inc b ; Move to the center of the block
inc b
inc b
inc b
; Generate particle RIGHT
push bc
call fndInctvPrtcl
pop bc
or a ; Check if A is zero...
ret z ; ...and return if it is
ld a, PRTCLLFSPN ; Set lifespan of particle
ld (hl), a ; save it
inc l ; Move HL to...
inc l ; ...the XVector
ld a, (rndmNmbr1)
ld (hl), a ; Load 0 into the XVector
inc l ; Move HL to...
ld (hl), 0x00 ; Load 0 into the XVector
inc l ; ...the Xpos
ld (hl), 0 ; Set the low byte to 0
inc l ; Move to high byte
ld (hl), b ; Set high byte to B
inc l ; Move to the YVector
ld a, 0x00
ld (hl), a ; Load YVextor low byte
inc l ; Move HL to...
ld (hl), 0xfe ; Load YVextor high byte
inc l ; ...the ypos
ld (hl), 0 ; Set the low byte to 0
inc l ; Move to high byte
ld (hl), c ; Set high byte to C
; Generate particle LEFT
push bc
call fndInctvPrtcl
pop bc
or a ; Check if A is zero...
ret z ; ...and return if it is
ld a, PRTCLLFSPN ; Set lifespan of particle
ld (hl), a ; save it
inc l ; Move HL to...
inc l ; ...the XVector
ld a, (rndmNmbr2)
ld (hl), a
inc l
ld (hl), 0xff
inc l
ld (hl), 0
inc l
ld (hl), b
inc l
ld a, 00
ld (hl), a
inc l
ld (hl), 0xfe
inc l
ld (hl), 0
inc l
ld (hl), c
; Generate particle MIDDLE
push bc
call fndInctvPrtcl
pop bc
or a ; Check if A is zero...
ret z ; ...and return if it is
ld a, PRTCLLFSPN ; Set lifespan of particle
ld (hl), a ; save it
inc l ; Move HL to...
inc l ; ...the XVector
ld a, 0x0a
ld (hl), 0
inc l
ld (hl), 0
inc l
ld (hl), 0
inc l
ld (hl), b
inc l
ld a, 00
ld (hl), a
inc l
ld (hl), 0xfe
inc l
ld (hl), 0
inc l
ld (hl), c
ret
;****************************************************************************************************************
; Find the address of a particle that is not currently active
;
; Entry Registers:
; NONE
; Registers Used:
; A, B, D, E, H, L
; Returned Registers:
; A = > 0 means a particle was found
; HL = Address of available score sprite
;****************************************************************************************************************
fndInctvPrtcl
ld b, NUMPRTCLS ; Load B with the total number of available particles
ld hl, objctPrtcls + 1 ; Load HL with the address of the first particles timer value
_chkNxtPrtcl
ld a, (hl) ; Load A with the time value from the particle
or a ; If its zero...
jr z, _foundPrtcl ; ...then its available and we can finish...
ld de, PRTCLSZ ; ...otherwise we load DE with the size of a particle...
add hl, de ; ... and increment HL to get to the next particle
djnz _chkNxtPrtcl ; Loop if necessary
xor a ; Getting here means no available particles, so reset A
ret ; Return
_foundPrtcl
inc a ; We found a particle so increment the timer to mark is used
ld (hl), a
dec l ; Move to the start of the particle struct
ret
;****************************************************************************************************************
; Updates active particles by adjusting their current position using their current vector. A particle is active
; if it has a timer value > 0
;
; Entry Registers:
; NONE
; Registers Used:
; A, B, D, E, H, L
; Returned Registers:
; NONE
;****************************************************************************************************************
updtPrtcls
ld b, NUMPRTCLS ; Load B with the total number of particles available
ld hl, objctPrtcls ; Point HL at the particle objects object pool
_nxtPrtcl
ld c, (hl) ; Save lifespan
inc l ; Move to timer
ld a, (hl) ; Load timer
or a ; Is timer > 0
jp nz, _updtPrtcl ; Yes then update
ld de, PRTCLSZ - 1 ; Move to next particle
add hl, de ; Increase HL
djnz _nxtPrtcl ; Loop
ret
_updtPrtcl
inc a ; Increment timer
cp c ; Compare with lifespan
jp z, _rstPrtclTmr ; If 0 then reset the timer
push bc
push hl
ld (hl), a ; Save new timer value
inc l ; Move to the x vector address
; Update X Position with XVector
ld c, (hl) ; Load the low byte of the xVector into C
inc l ; Move to the hight byte
ld b, (hl) ; Load the hight byte of the xVector into B
inc l
ld e, (hl) ; Load low byte of xpos into E
inc l ; Move to the high byte
ld d, (hl) ; Load the high byte of xpos into D
ex de, hl ; Exchange DE and HL
add hl, bc ; Add the xvector to the xpos
ex de, hl ; Exchange DE and HL again to get the particle address back into HL
ld a, d ; Check to see if the X location
cp SCRNLFT ; ...has passed the left edge of the screen area
jr nc, _chkRght ; If not then check the right screen edge
ld d, SCRNLFT ; otherwise set the balls X pos to the screens edge
_chkRght
cp SCRNRGHT - BLLPXLWIDTH ; Check to see if the X location has passed the right screen edge
jp c, _sveXPos ; If not then save the current X pos
ld d, 256 - 16 - 6 ; ...otherwise set the X pos to be the right screen edge
_sveXPos
ld (hl), d ; Save high byte of xpos
dec l ; Move to the low byte
ld (hl), e ; Save the low byte of xpos
inc l ; Move to the YVector
inc l ; ...which is a word away
; Apply gravity to YVector
ld c, (hl) ; Load the low byte of the xVector into C
inc l ; Move to the hight byte
ld b, (hl) ; Load the hight byte of the xVector into B
ld a, (grvty)
ld e, a
ld a, (grvty + 1)
ld d, a
ex de, hl
add hl, bc
ex de, hl
; Update Y Position using YVector
ld c, e
ld b, d
dec l
ld (hl), e
inc l
ld (hl), d
inc l
ld e, (hl) ; Load low byte of xpos into E
inc l ; Move to the high byte
ld d, (hl) ; Load the high byte of xpos into D
ex de, hl ; Exchange DE and HL
add hl, bc ; Add the xvector to the xpos
ex de, hl ; Exchange DE and HL again to get the particle address back into HL
ld (hl), d ; Save high byte of xpos
dec l ; Move to the low byte
ld (hl), e ; Save the low byte of xpos
inc l ; Move to the YVector
inc l ; ...which is a word away
; Move to the next particle
pop hl ; Resotore HL before we started moving around
pop bc ; Restore our particle counter in B
ld de, PRTCLSZ - 1 ; Load DE with the size of a particle struct - 1
add hl, de ; Move HL to the next particle address
djnz _nxtPrtcl ; Loop
ret
_rstPrtclTmr ; Reset the timer for the current particle as its not dead
xor a ; Clear A
ld (hl), a ; Save A to the timer basically resetting it
ld de, PRTCLSZ - 1 ; Load DE with the size of a particle struct - 1
add hl, de ; Move HL to the next particle address
djnz _nxtPrtcl ; Loop
ret