Add tools/ and manual/, move sources to src/
[dpadhero2.git] / src / gameselect.asm
blob1218935f6d442b76d29af89e91a5084ef78a3884
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 ; 0
40 ; 0 new game
41 ; 1 setup
42 ; 1 new game
43 ; 0 1 player
44 ; 1 2 players
45 ; 2 difficulty (1 player)
46 ; 0 easy
47 ; 1 normal
48 ; 2 hard
49 ; 3 2 players
50 ; 0 co-op
51 ; 1 versus
52 ; 4 difficulty (2 players)
53 ; 0 easy
54 ; 1 normal
55 ; 2 hard
56 ; 5 setup
57 ; 0 controller 1
58 ; 1 controller 2
59 current_menu .db
60 current_menu_item .db
61 ; 0 = erase, 1 = draw, 1 = accepting input
62 menu_state .db
63 selected_controller .db
65 ; 0 = 1 player, 1 = 2 player co-op, 2 = 2 player vs
66 game_type .db
67 .public game_type
69 .codeseg
71 .public gameselect_init
72 .public gameselect_main
74 .public brick_menu_bg_data
76 .extrn wipeout:proc
77 .extrn main_cycle:byte
78 .extrn frame_count:byte
80 .proc gameselect_init
81 jsr wipeout
83 .ifdef MMC
84 .if MMC == 3
85 lda #24 : sta chr_banks[0]
86 lda #26 : sta chr_banks[1]
87 lda #12 : sta chr_banks[2]
88 lda #13 : sta chr_banks[3]
89 lda #14 : sta chr_banks[4]
90 lda #15 : sta chr_banks[5]
91 .endif
92 .endif
94 ldcay brick_menu_bg_data : jsr write_ppu_data_at
95 ldcay @@bg_data : jsr write_ppu_data_at
97 jsr set_black_palette
98 ldcay @@palette
99 jsr load_palette
101 lda #0 : ldy #31
102 jsr set_fade_range
103 lda #6
104 jsr set_fade_delay
105 jsr start_fade_from_black
107 lda #0 ; main
108 jsr load_menu
110 lda #6 : jsr start_song
112 inc main_cycle
114 jsr screen_on
115 jsr nmi_on
118 @@bg_data:
119 .charmap "font.tbl"
120 .db $22,$E6,$06 : .char "B-BACK"
121 .db $22,$F6,$04 : .char "A-OK"
122 .db 0
124 @@palette:
125 .db $0f,$06,$16,$37 ; bricks and frame
126 .db $0f,$20,$20,$20 ; white text
127 .db $0f,$00,$00,$00 ; gray text
128 .db $0f,$00,$10,$20
129 .db $0f,$06,$16,$20
130 .db $0f,$0A,$1A,$20
131 .db $0f,$00,$10,$20
132 .db $0f,$00,$10,$20
133 .endp
135 brick_menu_bg_data:
136 .incbin "graphics/gameselect-bg.dat"
137 ; attributes
138 .db $23,$DA,$44,$55
139 .db $23,$E2,$44,$55
140 .db 0
142 .proc gameselect_main
143 jsr reset_sprites
144 jsr update_menu
146 .endp
148 ; A = menu to load
149 .proc load_menu
150 sta current_menu
151 lda #0
152 sta current_menu_item
153 sta menu_state
155 .endp
157 .proc update_menu
158 lda menu_state
159 beq @@erase
160 cmp #1
161 beq @@draw
162 ; accepting input
163 jsr draw_selection
164 jsr check_input
167 @@erase:
168 ldy #$21 : lda #$AC : ldx #$4C : jsr begin_ppu_string : lda #0 : jsr put_ppu_string_byte : jsr end_ppu_string
169 ldy #$21 : lda #$EC : ldx #$4C : jsr begin_ppu_string : lda #0 : jsr put_ppu_string_byte : jsr end_ppu_string
170 ldy #$22 : lda #$2C : ldx #$4C : jsr begin_ppu_string : lda #0 : jsr put_ppu_string_byte : jsr end_ppu_string
171 inc menu_state ; draw
174 @@draw:
175 lda current_menu
176 asl : asl : asl : tay
177 lda menu_data_table+4,y ; PPU data size
179 lda menu_data_table+2,y ; PPU data lo
181 lda menu_data_table+3,y ; PPU data hi
184 jsr copy_bytes_to_ppu_buffer
185 inc menu_state ; accepting input
187 .endp
189 menu_data_table:
190 ; parent menu, number of items, PPU data ptr, PPU data size, selected callback, padding
191 ;.db -1, 2 : .dw main_menu_data : .db main_menu_data_end-main_menu_data : .dw main_menu_item_selected : .db 0
192 .db -1, 2 : .dw new_game_menu_data : .db new_game_menu_data_end-new_game_menu_data : .dw new_game_menu_item_selected : .db 0
193 .db 0, 3 : .dw difficulty_menu_data : .db difficulty_menu_data_end-difficulty_menu_data : .dw difficulty_menu_item_selected : .db 0
194 .db 0, 2 : .dw two_player_menu_data : .db two_player_menu_data_end-two_player_menu_data : .dw two_player_menu_item_selected : .db 0
195 .db 2, 3 : .dw difficulty_menu_data : .db difficulty_menu_data_end-difficulty_menu_data : .dw difficulty_menu_item_selected : .db 0
196 .if 0
197 .db 0, 2 : .dw setup_menu_data : .db setup_menu_data_end-setup_menu_data : .dw setup_menu_item_selected : .db 0
198 .db 5, 2 : .dw controller_menu_data : .db controller_menu_data_end-controller_menu_data : .dw controller_menu_item_selected : .db 0
199 .db 6, 2 : .dw map_buttons_menu_data : .db map_buttons_menu_data_end-map_buttons_menu_data : .dw map_buttons_menu_item_selected : .db 0
200 .db 7, 2 : .dw defaults_menu_data : .db defaults_menu_data_end-defaults_menu_data : .dw defaults_menu_item_selected : .db 0
201 .endif
203 .charmap "font.tbl"
204 .if 0
205 main_menu_data:
206 .db $21,$AC,8 : .char "NEW GAME"
207 .db $21,$EC,5 : .char "SETUP"
208 main_menu_data_end:
209 .endif
211 new_game_menu_data:
212 .db $21,$AC,8 : .char "1 PLAYER"
213 .db $21,$EC,9 : .char "2 PLAYERS"
214 new_game_menu_data_end:
216 difficulty_menu_data:
217 .db $21,$AC,8 : .char "BEGINNER" ; "easy"
218 .db $21,$EC,6 : .char "NORMAL"
219 .db $22,$2C,6 : .char "EXPERT" ; "hard"
220 difficulty_menu_data_end:
222 two_player_menu_data:
223 .db $21,$AC,5 : .char "CO-OP"
224 .db $21,$EC,6 : .char "VERSUS"
225 two_player_menu_data_end:
227 .if 0
228 setup_menu_data:
229 .db $21,$AC,12 : .char "CONTROLLER 1"
230 .db $21,$EC,12 : .char "CONTROLLER 2"
231 setup_menu_data_end:
233 controller_menu_data:
234 .db $21,$AC,4 : .char "TEST"
235 .db $21,$EC,11 : .char "MAP BUTTONS"
236 controller_menu_data_end:
238 map_buttons_menu_data:
239 .db $21,$AC,8 : .char "DEFAULTS"
240 .db $21,$EC,6 : .char "CUSTOM"
241 map_buttons_menu_data_end:
243 defaults_menu_data:
244 .db $21,$AC,7 : .char "NES PAD"
245 .db $21,$EC,8 : .char "KEYBOARD"
246 defaults_menu_data_end:
247 .endif
249 .proc draw_selection
250 jsr next_sprite_index
252 lda #$11
253 sta sprites.tile,x
254 lda current_menu_item
255 asl : asl : asl : asl
256 adc #103
257 sta sprites._y,x
258 lda #84
259 sta sprites._x,x
260 lda #0
261 sta sprites.attr,x
263 .endp
265 .proc play_cursor_sfx
266 lda #0 : ldx #4
267 jmp start_sfx
268 .endp
270 .proc play_select_sfx
271 lda #6 : ldx #4
272 jmp start_sfx
273 .endp
275 .proc play_back_sfx
276 lda #8 : ldx #4
277 jmp start_sfx
278 .endp
280 .proc previous_menu
281 lda current_menu
282 asl : asl : asl : tay
283 lda menu_data_table,y
284 bmi +
285 jsr load_menu
286 + jmp play_back_sfx
287 .endp
289 .proc previous_menu_item
290 dec current_menu_item
291 bpl +
292 lda current_menu
293 asl : asl : asl : tay
294 lda menu_data_table+1,y ; number of items
295 sta current_menu_item
296 dec current_menu_item
297 + jmp play_cursor_sfx
298 .endp
300 .proc next_menu_item
301 lda current_menu
302 asl : asl : asl : tay
303 inc current_menu_item
304 lda current_menu_item
305 cmp menu_data_table+1,y ; number of items
306 bcc +
307 lda #0
308 sta current_menu_item
309 + jmp play_cursor_sfx
310 .endp
312 .proc select_menu_item
313 jsr play_select_sfx
314 lda current_menu
315 asl : asl : asl : tay
316 lda menu_data_table+5,y ; function ptr lo
318 lda menu_data_table+6,y ; function ptr hi
321 jmp call_fptr
322 .endp
324 .if 0
325 .proc main_menu_item_selected
326 lda current_menu_item
327 beq @@new_game_selected
328 ; setup selected
329 lda #5
330 jmp load_menu
331 @@new_game_selected:
332 lda #1 ; new game
333 jmp load_menu
334 .endp
335 .endif
337 .proc new_game_menu_item_selected
338 lda current_menu_item
339 beq @@one_player_selected
340 ; two players selected
341 lda #2
342 jmp load_menu
343 @@one_player_selected:
344 lda #0
345 sta game_type
346 lda #1 ; difficulty
347 jsr load_menu
348 lda #1
349 sta current_menu_item ; normal is default
351 .endp
353 .proc difficulty_menu_item_selected
354 lda current_menu_item
355 sta player.difficulty
356 jmp start_game
357 .endp
359 .proc two_player_menu_item_selected
360 lda current_menu_item
361 sta game_type
362 inc game_type
363 lda #3 ; difficulty
364 jsr load_menu
365 lda #1
366 sta current_menu_item ; normal is default
368 .endp
370 .if 0
371 .proc setup_menu_item_selected
372 lda current_menu_item
373 sta selected_controller
374 lda #6
375 jmp load_menu
376 .endp
378 .proc controller_menu_item_selected
379 lda current_menu_item
380 beq @@test_selected
381 ; map buttons selected
382 lda #7
383 jmp load_menu
384 @@test_selected:
386 .endp
388 .proc map_buttons_menu_item_selected
389 lda current_menu_item
390 beq @@defaults_selected
391 ; map buttons selected
393 @@defaults_selected:
394 lda #8
395 jmp load_menu
396 .endp
398 .proc defaults_menu_item_selected
399 ldx #4
400 lda selected_controller
401 beq +
402 ldx #9
403 + lda current_menu_item
404 beq @@nes_pad_selected
405 ; keyboard selected
406 jsr set_emu_button_mapping
407 jmp +
408 @@nes_pad_selected:
409 jsr set_default_button_mapping
410 ; back to controller menu
411 + lda #6
412 jmp load_menu
413 .endp
414 .endif
416 .proc start_game
417 .ifndef NO_TRANSITIONS
418 lda #1 : ldx #4
419 jsr start_sfx
421 lda #0
422 sta main_cycle
424 lda #13 : ldy #6
425 jsr start_timer
426 ldcay @@really_start
427 jsr set_timer_callback
428 jsr start_audio_fade_out
429 jmp start_fade_to_black
431 @@really_start:
432 .endif
433 ldy #0 ; default: no songs unlocked
434 lda game_type
435 cmp #2 ; versus?
436 bne +
437 ldy #$3F ; in versus mode, all songs are unlocked
438 + sty player.unlocked_songs
440 .ifdef LIFE_SUPPORT
441 lda #2
442 sta player.life_count
443 .endif
444 lda #0
445 sta player.completed_challenges+0
446 sta player.completed_challenges+1
447 sta player.completed_challenges+2
448 sta player.completed_challenges+3
449 sta player.completed_challenges+4
450 sta player.completed_challenges+5
451 sta player.acquired_pad_pieces
452 sta player.beat_game
453 ldy player.difficulty
454 lda @@initial_credit,y
455 sta player.credit
457 lda #5 ; song select
458 sta main_cycle
461 @@initial_credit:
462 .db 8 ; easy
463 .db 4 ; normal
464 .db 2 ; hard
465 .endp
467 .proc check_input
468 jsr palette_fade_in_progress
469 beq +
471 + lda joypad0_posedge
472 and #(JOYPAD_BUTTON_START | JOYPAD_BUTTON_A)
473 bne @@select
474 lda joypad0_posedge
475 and #JOYPAD_BUTTON_UP
476 bne @@up
477 lda joypad0_posedge
478 and #(JOYPAD_BUTTON_DOWN | JOYPAD_BUTTON_SELECT)
479 bne @@down
480 lda joypad0_posedge
481 and #JOYPAD_BUTTON_B
482 bne @@back
485 @@back:
486 jmp previous_menu
487 @@up:
488 jmp previous_menu_item
489 @@down:
490 jmp next_menu_item
491 @@select:
492 jmp select_menu_item
493 .endp
495 .end