Say hello to D-Pad Hero 2 repository
[dpadhero2.git] / gameinfo.asm
blob936ff1d71ac072e2343dc060e9ea4a14fe6e602c
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/fade.h"
19 .include "common/joypad.h"
20 .include "common/ldc.h"
21 .include "common/palette.h"
22 .include "common/ppu.h"
23 .include "common/ppubuffer.h"
24 .include "common/sprite.h"
25 .include "common/timer.h"
26 .include "sound/mixer.h"
27 .include "sound/sound.h"
28 .include "sound/sfx.h"
29 .include "player.h"
31 .ifdef MMC
32 .if MMC == 3
33 .include "mmc/mmc3.h"
34 .endif
35 .endif
37 .dataseg
39 ; Bitmask of players who have confirmed their readiness
40 players_ready .db
42 .codeseg
44 .public gameinfo_init
45 .public gameinfo_main
47 .public pulse_buttons
49 .extrn wipeout:proc
50 .extrn is_clip_play:proc
51 .extrn main_cycle:byte
52 .extrn frame_count:byte
53 .extrn game_type:byte
55 .proc gameinfo_init
56 jsr wipeout
58 .ifdef MMC
59 .if MMC == 3
60 lda #28 : sta chr_banks[0]
61 lda #30 : sta chr_banks[1]
62 lda #20 : sta chr_banks[2]
63 lda #21 : sta chr_banks[3]
64 lda #22 : sta chr_banks[4]
65 lda #23 : sta chr_banks[5]
66 .endif
67 .endif
69 ldcay @@bg_data
70 jsr write_ppu_data_at
72 jsr set_black_palette
73 ldcay @@palette
74 jsr load_palette
76 lda #0 : ldy #31
77 jsr set_fade_range
78 lda #6
79 jsr set_fade_delay
80 jsr start_fade_from_black
82 lda #0
83 sta players_ready
85 lda #0
86 jsr start_song
88 inc main_cycle
90 jsr screen_on
91 jsr nmi_on
92 rts
94 @@palette:
95 .db $0f,$20,$20,$20
96 .db $0f,$20,$20,$20
97 .db $0f,$20,$20,$20
98 .db $0f,$06,$18,$38 ; button
99 .db $0f,$02,$22,$30 ; target - blue
100 .db $0f,$06,$16,$30 ; target - red
101 .db $0f,$08,$28,$30 ; target - yellow
102 .db $0f,$0A,$2A,$20 ; target - green
104 @@bg_data:
105 .charmap "font.tbl"
106 .db $20,$8A,10 : .char "PLAYER 1 ="
107 .db $20,$EA,10 : .char "PLAYER 2 ="
108 .db $21,$49,11 : .char "AUTO-SWAP ="
110 .db $22,$68,17 : .char "IN `YOUR` LANE(S)"
112 .db $23,$2B,4 : .char "PUSH"
113 ; B + A
114 .db $23,$10,2,$AA,$AB
115 .db $23,$30,2,$BA,$BB
116 .db $23,$12,2,$AE,$AF
117 .db $23,$32,2,$BE,$BF
118 .db $23,$14,2,$AC,$AD
119 .db $23,$34,2,$BC,$BD
121 ; attributes
122 .db $23,$F4,$42,$FF
123 .db 0
124 .endp
126 ; Y = 0 ==> player 1, 1 ==> player 2, 2 ==> switch
127 .proc draw_orb
128 ; calculate orb frame (0..7)
130 asl : asl : asl
131 adc frame_count
133 asl : asl : asl
135 and #$1C
136 ora #1
137 bcc +
138 eor #$1C
139 + pha
140 ; left half
141 jsr next_sprite_index
145 sta sprites.tile,x
147 sta sprites.attr,x
148 lda @@orb_y_offset,y
149 clc : adc #26
150 sta sprites._y,x
151 lda #168
152 sta sprites._x,x
153 ; right half
154 jsr next_sprite_index
157 ora #2
158 sta sprites.tile,x
160 sta sprites.attr,x
161 lda @@orb_y_offset,y
162 clc : adc #26
163 sta sprites._y,x
164 lda #168+8
165 sta sprites._x,x
167 @@orb_y_offset:
168 .db 0,24,48
169 .endp
171 .proc draw_orbs
172 ldy #0
173 jsr draw_orb ; player 1
174 ldy #1
175 jsr draw_orb ; player 2
176 ldy #2
177 jmp draw_orb ; switch
178 .endp
180 ; POW, star, clock
181 .proc draw_power_ups
182 ldy #0
183 - jsr next_sprite_index
185 lda @@tile_indexes,y
186 sta sprites.tile,x
187 lda @@tile_attribs,y
188 sta sprites.attr,x
189 lda @@x_offsets,y
190 clc : adc #96
191 sta sprites._x,x
192 lda #128
193 sta sprites._y,x
195 cpy #6
196 bne -
198 @@x_offsets:
199 .db 0,8,24,32,48,56
200 @@tile_indexes:
201 .db $5D,$5F,$7D,$7F,$9D,$9F
202 @@tile_attribs:
203 .db 1,1,2,2,0,0
204 .endp
206 ; Letter, fake skull
207 .proc draw_special_items
208 lda game_type
209 cmp #2
210 bne +
211 ; items not available in versus mode
213 + jsr is_clip_play
214 beq +
215 ; items not available in clip play mode
217 + ldy #0
218 - jsr next_sprite_index
220 lda @@tile_indexes,y
221 sta sprites.tile,x
222 lda @@tile_attribs,y
223 sta sprites.attr,x
224 lda @@x_offsets,y
225 clc : adc #108
226 sta sprites._x,x
227 lda #104
228 sta sprites._y,x
230 cpy #4
231 bne -
233 @@x_offsets:
234 .db 0,8,24,32
235 @@tile_indexes:
236 .db $3D,$3F,$1D,$1F
237 @@tile_attribs:
238 .db $80|0,$80|0,3,3
239 .endp
241 .proc pulse_buttons
242 jsr palette_fade_in_progress
243 beq +
245 + lda frame_count
246 and #7
247 beq +
249 + ldy #$3F : lda #$0D : ldx #1
250 jsr begin_ppu_string
251 lda frame_count
252 lsr : lsr : lsr
253 and #7
255 lda @@color_table,y
256 jsr put_ppu_string_byte
257 jmp end_ppu_string
258 @@color_table:
259 .db $06,$16,$26,$20,$26,$16,$06,$06
260 .endp
262 .proc gameinfo_main
263 jsr reset_sprites
264 jsr draw_orbs
265 jsr draw_power_ups
266 jsr draw_special_items
267 jsr pulse_buttons
268 jsr check_input
269 jmp check_if_all_ready
270 .endp
272 .proc check_input
273 jsr palette_fade_in_progress
274 beq +
276 + lda players_ready
278 bcs +
279 ; player 1 ready?
280 lda joypad0
281 and #(JOYPAD_BUTTON_B | JOYPAD_BUTTON_A)
282 cmp #(JOYPAD_BUTTON_B | JOYPAD_BUTTON_A)
283 bne +
284 ; ready!
285 lda players_ready
286 ora #1
287 sta players_ready
288 ldcay @@player_1_ready_data
289 jsr copy_string_to_ppu_buffer
290 lda #6 : ldx #4
291 jsr start_sfx
292 + lda players_ready
293 and #2
294 bne +
295 ; player 2 ready?
296 lda joypad1
297 and #(JOYPAD_BUTTON_B | JOYPAD_BUTTON_A)
298 cmp #(JOYPAD_BUTTON_B | JOYPAD_BUTTON_A)
299 bne +
300 ; ready!
301 lda players_ready
302 ora #2
303 sta players_ready
304 ldcay @@player_2_ready_data
305 jsr copy_string_to_ppu_buffer
306 lda #6 : ldx #4
307 jsr start_sfx
308 + rts
310 .charmap "font.tbl"
311 @@player_1_ready_data:
312 .db $20,$98,3 : .char "OK!"
313 .db 0
314 @@player_2_ready_data:
315 .db $20,$F8,3 : .char "OK!"
316 .db 0
317 .endp
319 .proc check_if_all_ready
320 lda players_ready
321 cmp #3
322 beq +
325 .if 1;ndef NO_TRANSITIONS
326 lda #0
327 sta main_cycle
329 lda #3 : ldy #6
330 jsr start_timer
331 ldcay @@fade_out
332 jmp set_timer_callback
334 @@fade_out:
335 lda #10 : ldy #6
336 jsr start_timer
337 ldcay @@really_go
338 jsr set_timer_callback
339 jmp start_fade_to_black
341 @@really_go:
342 .endif
343 lda #7
344 sta main_cycle
346 .endp
348 .end