Say hello to D-Pad Hero 2 repository
[dpadhero2.git] / difficultyselect.asm
blobc5ca6a3aa817034a861d3dd106ac06d4db386a13
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 .codeseg
39 .public difficultyselect_init
40 .public difficultyselect_main
42 .extrn wipeout:proc
43 .extrn main_cycle:byte
44 .extrn frame_count:byte
46 .proc difficultyselect_init
47 jsr wipeout
49 .ifdef MMC
50 .if MMC == 3
51 lda #24 : sta chr_banks[0]
52 lda #26 : sta chr_banks[1]
53 lda #0 : sta chr_banks[2]
54 lda #0 : sta chr_banks[3]
55 lda #0 : sta chr_banks[4]
56 lda #0 : sta chr_banks[5]
57 .endif
58 .endif
60 ldcay @@bg_data
61 jsr write_ppu_data_at
63 jsr set_black_palette
64 ldcay @@palette
65 jsr load_palette
67 lda #0
68 ldy #31
69 jsr set_fade_range
70 lda #7
71 jsr set_fade_delay
72 jsr start_fade_from_black
74 lda #6
75 jsr start_song
77 lda #1
78 sta player.difficulty ; normal is default
80 inc main_cycle
82 jsr screen_on
83 jsr nmi_on
84 rts
86 @@palette:
87 .db $0f,$06,$16,$27,$0f,$27,$00,$20,$0f,$06,$00,$10,$0f,$00,$10,$20
88 .db $0f,$0C,$00,$20,$0f,$20,$20,$20,$0f,$20,$20,$20,$0f,$20,$20,$20
90 @@bg_data:
91 .incbin "graphics/difficultyselect-bg.dat"
92 ; attribute table
93 .db $23,$C1,$43,$55
94 .db $23,$C9,$43,$55
95 .db $23,$D1,$43,$55
96 .db $23,$D9,$43,$55
97 .db $23,$E1,$43,$55
98 .db $23,$E9,$43,$55
99 .db $23,$F1,$43,$55
100 .db 0
101 .endp
103 .proc difficultyselect_main
104 jsr reset_sprites
105 lda frame_count
106 lsr : lsr : lsr : lsr
107 jsr draw_selection
108 jsr check_input
110 .endp
112 ; CF: 0 = normal, 1 = other
113 .proc draw_selection
114 ; To highlight the selection, we flip the palette of the current row.
115 ; Each row is 6 tiles tall.
117 ; upper tiles
118 ldy player.difficulty
119 lda @@attrib_length,y
121 lda @@attrib_addr_lo,y
122 ldy #$23
123 jsr begin_ppu_string
124 ldy player.difficulty
125 lda @@attrib_data_1st,y
129 bcs +
130 ldy #0
131 + tya
132 jsr put_ppu_string_byte
133 jsr end_ppu_string
134 ; lower tiles
135 ldy player.difficulty
136 lda @@attrib_length,y
138 lda @@attrib_addr_lo,y
140 adc #8
141 ldy #$23
142 jsr begin_ppu_string
143 ldy player.difficulty
144 lda @@attrib_data_2nd,y
147 bcs +
148 ldy #0
149 + tya
150 jsr put_ppu_string_byte
151 jsr end_ppu_string
153 @@attrib_length:
154 .db $42,$43,$42
155 @@attrib_addr_lo:
156 .db $CC,$DC,$DC+16
157 @@attrib_data_1st:
158 .db $FF,$FF,$F0
159 @@attrib_data_2nd:
160 .db $FF,$0F,$FF
161 .endp
163 .proc play_cursor_sfx
164 lda #0
165 ldx #4
166 jmp start_sfx
167 .endp
169 .proc check_input
170 lda joypad0_posedge
171 and #(JOYPAD_BUTTON_START | JOYPAD_BUTTON_A)
172 bne @@select_difficulty
173 lda joypad0_posedge
174 and #JOYPAD_BUTTON_UP
175 bne @@up
176 lda joypad0_posedge
177 and #(JOYPAD_BUTTON_DOWN | JOYPAD_BUTTON_SELECT)
178 bne @@down
179 .if 0
180 lda joypad0_posedge
181 bne @@next_speed_level
182 .endif
185 .if 0
186 @@next_speed_level:
187 inc player.speed_level
188 lda player.speed_level
189 cmp #8
190 bne +
191 lda #0
192 sta player.speed_level
193 + jmp play_cursor_sfx
194 .endif
196 @@up:
198 jsr draw_selection ; make sure old selection is disabled
199 dec player.difficulty
200 bpl +
201 lda #2
202 sta player.difficulty
203 + jmp play_cursor_sfx
205 @@down:
207 jsr draw_selection ; make sure old selection is disabled
208 inc player.difficulty
209 lda player.difficulty
210 cmp #3
211 bne +
212 lda #0
213 sta player.difficulty
214 + jmp play_cursor_sfx
216 @@select_difficulty:
218 jsr draw_selection ; make sure it's drawn selected
220 .ifndef NO_TRANSITIONS
221 lda #1
222 ldx #4
223 jsr start_sfx
225 ; start fading out music
227 lda #0
228 sta main_cycle
230 @@start_fade_out_music_timer:
231 lda #3
232 ldy #3
233 jsr start_timer
234 lda #<@@fade_out_music
235 ldy #>@@fade_out_music
236 jmp set_timer_callback
238 @@fade_out_music:
239 jsr mixer_get_master_vol
241 sbc #$10
242 bcc +
243 jsr mixer_set_master_vol
244 jmp @@start_fade_out_music_timer
245 + ; done fading out music
246 lda #0
247 jsr start_song ; mute
248 lda #6
249 ldy #6
250 jsr start_timer
251 lda #<@@really_select
252 ldy #>@@really_select
253 jsr set_timer_callback
254 jmp start_fade_to_black
256 @@really_select:
257 .endif
258 ; song select screen
259 lda #5
260 sta main_cycle
262 .endp
264 .end