Add tools/ and manual/, move sources to src/
[dpadhero2.git] / src / parallax.asm
blobbee4c5c58a24773529770fc9d79d00e2fd853230
2 ; Copyright (C) 2010 Kent Hansen.
4 ; This program is free software; you can redistribute it and/or modify
5 ; it under the terms of the GNU General Public License as published by
6 ; the Free Software Foundation; either version 3 of the License, or
7 ; (at your option) any later version.
9 ; This program is distributed in the hope that it will be useful,
10 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ; GNU General Public License for more details.
14 ; You should have received a copy of the GNU General Public License
15 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
18 .include "common/sprite.h"
19 .include "player.h"
20 .include "target.h"
22 .dataseg
24 ; 0 = vertical, 1 = horizontal
25 orbientation .db
27 spawn_orb_timer .db
28 spawn_orb_index .db
29 prev .db
31 .codeseg
33 .extrn frame_count:byte
35 .public initialize_orb_parallax
36 .public update_orb_parallax
38 ; A = orbientation (0 = vertical, 1 = horizontal)
39 .proc initialize_orb_parallax
40 sta orbientation
41 jsr initialize_target_lists
42 lda #16
43 sta spawn_orb_timer
44 lda #0
45 sta spawn_orb_index
46 rts
47 .endp
49 .proc get_winning_player
50 lda player.energy_level+1
51 beq + ; player 1 won
52 lda #1 ; player 2 won
53 + rts
54 .endp
56 .proc draw_orb
57 ; left half
58 jsr next_sprite_index
59 tax
60 lda targets_1.state,y
61 and #7 ; size
62 asl : asl
63 ora #1
64 sta sprites.tile,x
65 lda targets_1.state,y
66 pha
67 and #7 ; size
68 cmp #3
69 pla
70 ror : lsr : lsr
71 eor #$20
72 and #$23 ; sprite priority + palette
73 pha
74 sta sprites.attr,x
75 lda targets_1.pos_y.int,y
76 sta sprites._y,x
77 lda targets_1.pos_x.int,y
78 sta sprites._x,x
79 ; right half
80 jsr next_sprite_index
81 tax
82 lda targets_1.state,y
83 and #7 ; size
84 asl : asl
85 ora #3
86 sta sprites.tile,x
87 pla
88 sta sprites.attr,x
89 lda targets_1.pos_y.int,y
90 sta sprites._y,x
91 lda targets_1.pos_x.int,y
92 clc : adc #8
93 sta sprites._x,x
94 rts
95 .endp
97 .proc process_orbs
98 lda #$FF
99 sta prev
100 ldy active_targets_head
102 @@loop:
103 cpy #$FF ; end of list?
104 bne @@do_target
107 @@do_target:
108 jsr move_target
109 jsr draw_orb
111 lda orbientation
112 beq +
113 ; horizontal
114 lda targets_1.pos_x.int,y
115 cmp #4
116 bcc @@went_offscreen
117 bcs @@next
118 ; vertical
119 + lda targets_1.pos_y.int,y
120 cmp #$F8
121 bcs @@went_offscreen
123 @@next:
124 lda targets_2.next,y
125 sty prev
127 jmp @@loop
129 @@went_offscreen:
130 lda targets_2.next,y
132 ; put on free list
133 lda free_targets_list
134 sta targets_2.next,y
135 sty free_targets_list
137 ; remove from active targets list
138 cpy active_targets_tail
139 bne +
140 sta active_targets_tail
141 + tay
142 ldx prev
143 cpx #$FF
144 bne +
145 sty active_targets_head
146 jmp @@loop
147 + sta targets_2.next,x
148 jmp @@loop
149 .endp
151 .proc maybe_spawn_orb
152 dec spawn_orb_timer
153 beq +
155 + lda #8
156 ldy orbientation
157 beq +
158 lda #12
159 + sta spawn_orb_timer
160 ; grab target from free list
161 ldx free_targets_list
162 cpx #$FF
163 bne +
164 ; don't spawn, no free targets now
166 + lda targets_2.next,x
167 sta free_targets_list
168 ; initialize
169 lda #0
170 sta targets_1.pos_y.frac,x
171 sta targets_1.pos_x.frac,x
172 lda #240
173 ldy orbientation
174 bne +
175 sta targets_1.pos_y.int,x
176 jmp ++
177 + sta targets_1.pos_x.int,x
178 ++ lda spawn_orb_index
179 inc spawn_orb_index
181 ldy orbientation
182 beq +
183 and #7
185 lda @@pos_y_hi,y
186 jmp ++
187 + asl : asl : asl : asl : asl ; * 32
188 adc #8
189 ++ ldy orbientation
190 beq +
191 sta targets_1.pos_y.int,x
192 jmp ++
193 + sta targets_1.pos_x.int,x
194 ++ pla
195 and #7
197 lda @@size_table,y
198 sta targets_1.state,x
200 lda orbientation
201 beq +
202 ; horizontal
203 lda @@size_speed_lo,y
204 sta targets_2.speed_x.frac,x
205 lda @@size_speed_hi,y
206 sta targets_2.speed_x.int,x
207 lda #0
208 sta targets_2.speed_y.frac,x
209 sta targets_2.speed_y.int,x
210 jmp ++
211 ; vertical
212 + lda @@size_speed_lo,y
213 sta targets_2.speed_y.frac,x
214 lda @@size_speed_hi,y
215 sta targets_2.speed_y.int,x
216 lda #0
217 sta targets_2.speed_x.frac,x
218 sta targets_2.speed_x.int,x
219 ++ lda orbientation
220 beq +
221 lda frame_count
222 clc : adc spawn_orb_index
223 and #$18
224 bpl ++
225 + jsr get_winning_player
226 and #3 ; use as palette
227 asl : asl : asl
228 ++ ora targets_1.state,x
229 sta targets_1.state,x
230 jmp add_to_active_targets_list
231 @@size_table:
232 .db 2,4,0,7,1,6,3,5
233 @@size_speed_lo:
234 .db $40,$00,$C0,$80,$40,$00,$C0,$80
235 @@size_speed_hi:
236 .db $FF,$FF,$FE,$FE,$FE,$FE,$FD,$FD
237 @@pos_y_hi:
238 .db 8,24,40,56,120,168,184,208
239 .endp
241 .proc update_orb_parallax
242 jsr process_orbs
243 jmp maybe_spawn_orb
244 .endp
246 .end