-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
preloader.asm
147 lines (143 loc) · 3.1 KB
/
preloader.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
; starting game!
start_game:
lda <KONAMI_CODE_STATE
cmp konami_code_length
beq .start_sound_alt
.if ENABLE_SOUND!=0
jsr start_sound
.endif
jmp .start_sound_end
.start_sound_alt:
jsr start_sound_alt
.start_sound_end:
jsr dim_base_palette_out
; disable PPU
lda #%00000000
sta PPUCTRL
lda #%00000000
sta PPUMASK
; wait for v-blank
jsr waitblank_simple
.if SECRETS>=3
; check for konami code
lda <KONAMI_CODE_STATE
cmp konami_code_length
bne .no_konami_code
lda #LOW(GAMES_COUNT)
clc
adc #2
sta <SELECTED_GAME
lda #HIGH(GAMES_COUNT)
adc #0
sta <SELECTED_GAME+1
.no_konami_code:
.endif
lda SELECTED_GAME+1
jsr select_prg_bank
ldx SELECTED_GAME
lda loader_data_game_flags, x
and CONSOLE_TYPE
beq compatible_console
; not compatible console!
; error sound
jsr error_sound
; save state, without game save
lda #0
sta <LAST_STARTED_SAVE
jsr save_state
; print error message
jsr clear_screen
jsr load_text_attributes
lda #$21
sta PPUADDR
lda #$A0
sta PPUADDR
lda #LOW(string_incompatible_console)
sta <COPY_SOURCE_ADDR
lda #HIGH(string_incompatible_console)
sta <COPY_SOURCE_ADDR+1
jsr print_text
lda #%00001000
sta PPUCTRL
lda #%00001010
sta PPUMASK
; disable scrolling
inc SCROLL_LOCK
; dim-in
jsr dim_base_palette_in
; wait until all buttons released
.incompatible_print_wait_no_button:
jsr read_controller
lda <BUTTONS
bne .incompatible_print_wait_no_button
; tiny delay
ldx #15
.incompatible_wait:
jsr waitblank_simple
dex
bne .incompatible_wait
; wait until any button pressed
.incompatible_print_wait_button:
jsr read_controller
lda <BUTTONS
beq .incompatible_print_wait_button
jsr dim_base_palette_out
jmp Start
compatible_console:
; clear NTRAM
jsr enable_chr_write
jsr enable_four_screen
jsr clear_screen
; clear nametables
jsr disable_four_screen
jsr clear_screen
jsr disable_chr_write
; clear sprite data
jsr clear_sprites
; load this empty data
jsr sprite_dma_copy
; loading game settings
ldx <SELECTED_GAME
lda loader_data_reg_0, x
sta <LOADER_REG_0
lda loader_data_reg_1, x
sta <LOADER_REG_1
lda loader_data_reg_2, x
sta <LOADER_REG_2
lda loader_data_reg_3, x
sta <LOADER_REG_3
lda loader_data_reg_4, x
sta <LOADER_REG_4
lda loader_data_reg_5, x
sta <LOADER_REG_5
lda loader_data_reg_6, x
sta <LOADER_REG_6
lda loader_data_reg_7, x
sta <LOADER_REG_7
lda loader_data_chr_start_bank_h, x
sta <LOADER_CHR_START_H
lda loader_data_chr_start_bank_l, x
sta <LOADER_CHR_START_L
lda loader_data_chr_start_bank_s, x
sta <LOADER_CHR_START_S
lda loader_data_chr_count, x
sta <LOADER_CHR_LEFT
lda loader_data_game_save, x
sta <LOADER_GAME_SAVE
sta <LAST_STARTED_SAVE ; save ID of save
lda #2
sta <LOADER_GAME_SAVE_BANK
; loading battery backed save if need
jsr load_save
; saving state
jsr save_state
; first PRG bank
lda #0
jsr select_prg_bank
; loading tiles
jsr load_all_chr_banks
; wait for sound end and reset sound registers
jsr wait_sound_end
jsr reset_sound
; start loader stored into RAM
jmp loader