Say hello to D-Pad Hero 2 repository
[dpadhero2.git] / challenges.asm
blob9b9d4ed69b5c7b9c7f56919c04cd94fc3c234737
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 challenge_timer .db
40 challenge_count .db
42 .codeseg
44 .public challenges_init
45 .public challenges_main
47 .public challengestats_init
48 .public challengestats_main
50 .public brick_menu_bg
52 .extrn wipeout:proc
53 .extrn print_value:proc
54 .extrn count_bits:proc
55 .extrn main_cycle:byte
56 .extrn player:player_state
57 .extrn selected_song:byte
58 .extrn bitmasktable:byte
59 .extrn game_type:byte
60 .extrn rock_score_table:dword
61 .extrn AC0:byte
62 .extrn AC1:byte
63 .extrn AC2:byte
65 brick_menu_bg:
66 .incbin "graphics/challenges-bg.dat"
67 ; attributes
68 .db $23,$C9,$46,$05
69 .db $23,$D1,$46,$50
70 .db $23,$D9,$46,$55
71 .db $23,$E1,$46,$55
72 .db $23,$E9,$46,$55
73 .db $23,$F1,$46,$05
74 .db 0
76 .proc challenges_init_common
77 jsr wipeout
79 .ifdef MMC
80 .if MMC == 3
81 lda #28 : sta chr_banks[0]
82 lda #30 : sta chr_banks[1]
83 lda #20 : sta chr_banks[2]
84 lda #21 : sta chr_banks[3]
85 lda #22 : sta chr_banks[4]
86 lda #23 : sta chr_banks[5]
87 .endif
88 .endif
90 lda #0
91 jsr start_song
93 ldcay brick_menu_bg
94 jsr write_ppu_data_at
95 ldcay @@bg_data
96 jsr write_ppu_data_at
98 jsr print_rock_score
100 jsr dim_completed_challenges
102 ldcay @@palette
103 jsr load_palette
104 lda #0 : ldy #31
105 jsr set_fade_range
106 lda #6
107 jmp set_fade_delay
109 @@bg_data:
110 .charmap "font.tbl"
111 .db $20,$8B,$0A : .char "CHALLENGES"
112 .db $21,$47,$12 : .char "MAKE IT TO THE END"
113 .db $21,$87,$0A : .char "SCORE OVER"
114 .db $21,$C7,$0F : .char "STREAK OVER 100"
115 .db $22,$07,$10 : .char "SPELL D-PAD HERO"
116 .db $22,$47,$12 : .char "FIND 3 FAKE SKULLS"
117 .db $22,$87,$10 : .char "BLOW UP ALL POWS"
118 .db $22,$C7,$13 : .char "DON'T USE ANY ITEMS"
119 .db $23,$07,$13 : .char "END WITH MAX HEALTH"
120 .db 0
122 @@palette:
123 .db $0f,$06,$16,$37 ; bricks and frame
124 .db $0f,$20,$20,$20 ; white text
125 .db $0f,$00,$00,$00 ; gray text
126 .db $0f,$00,$10,$20
127 .db $0f,$06,$16,$20
128 .db $0f,$0A,$1A,$20
129 .db $0f,$00,$10,$20
130 .db $0f,$00,$10,$20
131 .endp
133 ; Prints the score that much be reached to complete
134 ; the score challenge on the selected song.
135 .proc print_rock_score
136 lda player.difficulty
137 asl : asl : asl : asl : asl ; 8*4=32 bytes per difficulty
138 adc selected_song ; four
139 adc selected_song ; bytes
140 adc selected_song ; per
141 adc selected_song ; score
143 lda rock_score_table+0,y : sta AC0
144 lda rock_score_table+1,y : sta AC1
145 lda rock_score_table+2,y : sta AC2
146 ldx #5 : lda #$21 : ldy #$92
147 jmp print_value
148 .endp
150 .proc challenges_init
151 jsr challenges_init_common
153 ldcay @@bg_data
154 jsr write_ppu_data_at
156 inc main_cycle
158 jsr screen_on
159 jsr nmi_on
160 jmp start_fade_from_black
162 @@bg_data:
163 .charmap "font.tbl"
164 ; B - BACK
165 .db $23,$64,$06 : .char "B-BACK"
166 ; A - PLAY
167 .db $23,$76,$06 : .char "A-PLAY"
168 .db 0
169 .endp
171 .proc dim_completed_challenges
172 ldy selected_song
173 lda player.completed_challenges,y
175 bcc +
176 ; dim 1st row
178 ldy #$23 : lda #$D1 : ldx #$46
179 jsr begin_ppu_string
180 lda #$A0
181 jsr @@finish_ppu_string
183 + pha
184 and #3
185 beq +
186 ; dim 2nd and/or 3rd row
188 lda @@attrib_data,y
190 ldy #$23 : lda #$D9 : ldx #$46
191 jsr begin_ppu_string
193 jsr @@finish_ppu_string
194 + pla
195 lsr : lsr
197 and #3
198 beq +
199 ; dim 4th and/or 5th row
201 lda @@attrib_data,y
203 ldy #$23 : lda #$E1 : ldx #$46
204 jsr begin_ppu_string
206 jsr @@finish_ppu_string
207 + pla
208 lsr : lsr
210 and #3
211 beq +
212 ; dim 6th and/or 7th row
214 lda @@attrib_data,y
216 ldy #$23 : lda #$E9 : ldx #$46
217 jsr begin_ppu_string
219 jsr @@finish_ppu_string
220 + pla
221 lsr : lsr : lsr
222 bcc +
223 ; dim 8th row
224 ldy #$23 : lda #$F1 : ldx #$46
225 jsr begin_ppu_string
226 lda #$0A
227 jsr @@finish_ppu_string
228 + jmp flush_ppu_buffer
230 @@finish_ppu_string:
231 jsr put_ppu_string_byte
232 jmp end_ppu_string
234 @@attrib_data:
235 .db $55,$5A,$A5,$AA
236 .endp
238 .proc check_input
239 jsr palette_fade_in_progress
240 beq +
242 + lda joypad0_posedge
243 and #(JOYPAD_BUTTON_START | JOYPAD_BUTTON_A)
244 bne @@play
245 lda joypad0_posedge
246 and #JOYPAD_BUTTON_B
247 bne @@go_back
250 @@play:
251 .ifndef NO_TRANSITIONS
252 lda #0
253 sta main_cycle
255 lda #6 : ldx #4
256 jsr start_sfx
258 lda #8 : ldy #6
259 jsr start_timer
260 ldcay @@really_play
261 jsr set_timer_callback
262 jmp start_fade_to_black
264 @@really_play:
265 .endif
266 lda game_type
267 beq + ; normal
268 lda #26 ; game info
269 sta main_cycle
271 + lda #7 ; game start
272 sta main_cycle
275 @@go_back:
276 .ifndef NO_TRANSITIONS
277 lda #0
278 sta main_cycle
280 lda #8 : ldy #6
281 jsr start_timer
282 ldcay @@really_go_back
283 jsr set_timer_callback
284 jmp start_fade_to_black
286 @@really_go_back:
287 .endif
288 lda #5
289 sta main_cycle
291 .endp
293 .proc challenges_main
294 jsr reset_sprites
295 jmp check_input
296 .endp
298 .proc challengestats_init
299 .if 0
300 lda #$FF
301 sta player.last_completed_challenges
302 sta player.new_completed_challenges
303 lda #8
304 sta player.won_credit
305 .endif
306 jsr challenges_init_common
308 lda #0
309 sta challenge_count
310 lda #48
311 sta challenge_timer
313 inc main_cycle
315 jsr screen_on
316 jsr nmi_on
317 jmp start_fade_from_black
318 .endp
320 .proc draw_challenge_status_sprites
321 lda #0 ; challenge index
322 - cmp challenge_count
323 bne +
325 + pha
327 lda bitmasktable,y ; mask for challenge
328 ldy selected_song
329 and player.completed_challenges,y ; previously completed?
330 bne ++
331 ; left side
332 jsr next_sprite_index
334 lda #$11
335 sta sprites.tile,x
336 lda #35
337 sta sprites._x,x
340 asl : asl : asl : asl ; challenge index * 16
341 adc #74
342 sta sprites._y,x
346 lda bitmasktable,y ; mask for challenge
347 ldy selected_song
348 and player.new_completed_challenges ; completed just now?
349 beq +
350 lda #1 ; palette for "completed"
351 + sta sprites.attr,x
353 ; right side
354 jsr next_sprite_index
356 lda #$13
357 sta sprites.tile,x
358 lda #35+8
359 sta sprites._x,x
362 asl : asl : asl : asl ; challenge index * 16
363 adc #74
364 sta sprites._y,x
368 lda bitmasktable,y ; mask for challenge
369 ldy selected_song
370 and player.new_completed_challenges ; completed just now?
371 beq +
372 lda #1 ; palette for "completed"
373 + sta sprites.attr,x
374 ++ pla
376 adc #1
377 bne -
378 .endp
380 .proc process_next_challenge
381 dec challenge_timer
382 beq +
384 + ldy selected_song
385 lda player.completed_challenges,y
386 ldy challenge_count
387 inc challenge_count
388 and bitmasktable,y ; challenge previously completed?
389 beq +
390 inc challenge_timer
392 + lda player.new_completed_challenges
393 and bitmasktable,y ; challenge completed now?
395 ldx #4
396 lda #0 ; "bad" sfx
398 beq +
399 lda #6 ; "good" sfx
400 + jsr start_sfx
401 lda #32
402 sta challenge_timer
404 .endp
406 .proc challengestats_main
407 jsr reset_sprites
408 jsr draw_challenge_status_sprites
409 lda challenge_count
410 cmp #8
411 beq @@check_input
412 jmp process_next_challenge
414 @@check_input:
415 lda joypad0_posedge
416 and #(JOYPAD_BUTTON_START | JOYPAD_BUTTON_A)
417 bne @@go
420 @@go:
421 .ifndef NO_TRANSITIONS
422 lda #0
423 sta main_cycle
425 lda #8 : ldy #6
426 jsr start_timer
427 ldcay @@really_go
428 jsr set_timer_callback
429 jmp start_fade_to_black
431 @@really_go:
432 .endif
433 .if 0
434 ; remember current score (restored upon continue)
435 lda player.score+0
436 sta player.checkpoint_score+0
437 lda player.score+1
438 sta player.checkpoint_score+1
439 lda player.score+2
440 sta player.checkpoint_score+2
441 .endif
443 ; add the completed challenges for song
444 ldy selected_song
445 lda player.completed_challenges,y
446 ora player.new_completed_challenges
447 sta player.completed_challenges,y
449 lda player.new_completed_challenges
450 bne +
451 lda #5 ; song select
452 sta main_cycle
454 + lda #30 ; credit win
455 sta main_cycle
457 .endp
459 .end