Welcome to mirror list, hosted at ThFree Co, Russian Federation.

menu.asm - github.com/coolgirl-multicart/coolgirl-multirom-builder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 819d1e9d63edb4993c3007873be5822dd34f6e2f (plain)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
; INES header stuff
  .inesprg 128 * 1024   ; 8 banks of PRG = 128kB
  .ineschr 0   ; no CHR, RAM only
  .inesmir 0   ; horizontal mirroring
  .inesmap 2   ; UxROM

  ; default settings
  ; enable main sounds
  .ifndef ENABLE_SOUND
ENABLE_SOUND .equ 1
  .endif
  ; number of stars
  .ifndef STARS
STARS .equ 30
  .endif
  ; stars direction (0 - down to up, 1 - up to down)
  .ifndef STARS_DIRECTION
STARS_DIRECTION .equ 1
  .endif
  ; star spawn interval
  .ifndef STAR_SPAWN_INTERVAL
STAR_SPAWN_INTERVAL .equ 90
  .endif
  ; remember last started game
  .ifndef ENABLE_LAST_GAME_SAVING
ENABLE_LAST_GAME_SAVING .equ 1
  .endif
  ; show right cursor
  .ifndef ENABLE_RIGHT_CURSOR
ENABLE_RIGHT_CURSOR .equ 1
  .endif
  ; game names offset from the left
  .ifndef GAME_NAMES_OFFSET
GAME_NAMES_OFFSET .equ 1
  .endif
  ; time before button autorepeat
  .ifndef BUTTON_REPEAT_FRAMES
BUTTON_REPEAT_FRAMES .equ 30
  .endif
  ; minimum number of games for screen wrap feature
  .ifndef WRAP_GAMES
WRAP_GAMES .equ 30
  .endif
  ; enable dim-in (on startup, etc)
  .ifndef ENABLE_DIM_IN
ENABLE_DIM_IN .equ 1
  .endif
  ; dim-in speed (more - slower)
  .ifndef DIM_IN_DELAY
DIM_IN_DELAY .equ 5
  .endif
  ; enable dim-out (before game launch, etc)
  .ifndef ENABLE_DIM_OUT
ENABLE_DIM_OUT .equ 1
  .endif
  ; dim-out speed (more - slower)
  .ifndef DIM_OUT_DELAY
DIM_OUT_DELAY .equ 1
  .endif
  ; save cursor position immediately
  .ifndef INSTANT_STATE_SAVE
INSTANT_STATE_SAVE .equ 1
  .endif

  .ifndef GAMES_DB
GAMES_DB                        .sequ "games.asm"
  .endif
  .ifndef MENU_HEADER_PATTERN_TABLE_BIN
MENU_HEADER_PATTERN_TABLE_BIN   .sequ "menu_header_pattern_table.bin"
  .endif
  .ifndef MENU_HEADER_NAME_TABLE_BIN
MENU_HEADER_NAME_TABLE_BIN      .sequ "menu_header_name_table.bin"
  .endif
  .ifndef MENU_HEADER_ATTRIBUTE_TABLE_BIN
MENU_HEADER_ATTRIBUTE_TABLE_BIN .sequ "menu_header_attribute_table.bin"
  .endif
  .ifndef MENU_HEADER_BG_PALETTE_0
MENU_HEADER_BG_PALETTE_0        .sequ "bg_palette0.bin"
  .endif
  .ifndef MENU_HEADER_BG_PALETTE_1
MENU_HEADER_BG_PALETTE_1        .sequ "bg_palette1.bin"
  .endif
  .ifndef MENU_HEADER_BG_PALETTE_2
MENU_HEADER_BG_PALETTE_2        .sequ "bg_palette2.bin"
  .endif
  
  ; games settings
  .include GAMES_DB

  ; sprites data
  .rsset $0400
SPRITES .rs 256

  ; non-volatile PRG-RAM
  .rsset $6000
SRAM_SIGNATURE .rs 8
SRAM_LAST_STARTED_GAME .rs 2
SRAM_LAST_STARTED_LINE .rs 2
SRAM_LAST_STARTED_SAVE .rs 1

  .rsset $0000
  ; zero page variables
  ; some common variables
COPY_SOURCE_ADDR .rs 2
COPY_DEST_ADDR .rs 2
TMP .rs 2
  ; selected game
SELECTED_GAME .rs 2

  .bank 15   ; last bank
  .org $FFFA ; vectors
  .dw NMI    ; NMI vector
  .dw Start  ; reset vector
  .dw IRQ    ; interrupts

  .org $FFE0
unrom_bank_data:
  ; for compatibility with UNROM and UNROM's bus conflicts
  .db $00, $01, $02, $03, $04, $05, $06, $07, $08, $09, $0A, $0B, $0C, $0D, $0E, $0F

  .org $E000
Start:
  sei ; no interrupts

  ; reset stack
  ldx #$ff
  txs

  ; disable and reset sound
  jsr reset_sound

  ; disable PPU
  lda #%00000000
  sta PPUCTRL
  sta PPUMASK
  ; warm-up
  jsr waitblank_simple
  jsr waitblank_simple
  ; load black screen
  jsr load_black

  ; clean memory
  lda #$00
  sta <COPY_SOURCE_ADDR
  sta <COPY_SOURCE_ADDR+1
  ldy #$02
  ldx #$08
.loop:
  sta [COPY_SOURCE_ADDR], y
  iny
  bne .loop
  inc COPY_SOURCE_ADDR+1
  dex
  bne .loop

  ; loading loader and other RAM routines
  ldx #$00
.load_ram_routines:
  lda ram_routines+$C000, x
  sta ram_routines, x
  lda ram_routines+$C100, x
  sta ram_routines+$100, x
  lda ram_routines+$C200, x
  sta ram_routines+$200, x
  inx
  bne .load_ram_routines

  ; init banks and other cart stuff
  jsr banking_init
  ; detect console type
  jsr console_detect
  ; clean nametables
  jsr clear_screen
  ; load CHR data
  jsr load_base_chr
  ; clear all sprites data
  jsr clear_sprites
  ; load this empty sprites data
  jsr sprite_dma_copy
  ; read buttons
  jsr read_controller 
  ; loading saved cursor position and other data
  jsr load_state
  ; saving last started game to flash (if any)
  jsr save_all_saves
  ; skip separator if any
  jsr check_separator_down

  ; init variables
  lda <SCROLL_LINES_TARGET
  sta <SCROLL_LINES
  sta <LAST_LINE_GAME
  sta <TMP
  lda <SCROLL_LINES_TARGET+1
  sta <SCROLL_LINES+1
  sta <LAST_LINE_GAME+1
  sta <TMP+1

  ; calculate modulo
.init_modulo:
  lda <TMP+1
  bne .do_init_modulo
  lda <TMP
  cmp #LINES_PER_SCREEN * 2
  bcs .do_init_modulo
  jmp .init_modulo_end
.do_init_modulo:
  lda <TMP
  sec
  sbc #LINES_PER_SCREEN * 2
  sta <TMP
  lda <TMP+1
  sbc #0
  sta <TMP+1
  jmp .init_modulo
.init_modulo_end:
  lda <TMP
  sta <SCROLL_LINES_MODULO
  sta <LAST_LINE_MODULO

  jsr set_scroll_targets

  ; sprites init
  lda <SPRITE_0_X_TARGET
  sta SPRITE_0_X
  lda <SPRITE_1_X_TARGET
  sta SPRITE_1_X
  lda <SPRITE_Y_TARGET
  sta SPRITE_0_Y
  .if ENABLE_RIGHT_CURSOR=0
  lda #$FF
  .endif
  sta SPRITE_1_Y ;hide right cursor
  lda #$00
  sta SPRITE_0_TILE
  sta SPRITE_1_TILE
  lda #%00000000
  sta SPRITE_0_ATTR
  lda #%01000000
  sta SPRITE_1_ATTR

  ; prevent first attributes load skip
  lda #1
  sta LAST_ATTRIBUTE_ADDRESS

  ; init random number generator
  jsr random_init

  lda #%00000100
  cmp <BUTTONS
  bne .skip_build_info
  ; build and hardware info
  jmp show_build_info
.skip_build_info:
  ldx #GAMES_COUNT & $FF
  dex
  bne .not_single_game
  ldx #(GAMES_COUNT >> 8) & $FF
  bne .not_single_game
  stx <SELECTED_GAME
  stx <SELECTED_GAME+1
  jmp start_game
.not_single_game:
  .if SECRETS>=1
  lda #%00010011
  cmp <BUTTONS
  bne .not_hidden_rom_1
  lda #GAMES_COUNT & $FF
  sta <SELECTED_GAME
  lda #(GAMES_COUNT >> 8) & $FF
  sta <SELECTED_GAME+1
  jmp start_game
.not_hidden_rom_1:
  .endif
  .if SECRETS>=2
  lda #%00100011
  cmp <BUTTONS
  bne .not_hidden_rom_2
  lda #GAMES_COUNT & $FF
  clc
  adc #1
  sta <SELECTED_GAME
  lda #(GAMES_COUNT >> 8) & $FF
  adc #0
  sta <SELECTED_GAME+1
  jmp start_game
.not_hidden_rom_2:
  .endif
  lda #%00000111
  cmp <BUTTONS
  bne .not_tests
  jmp do_tests
.not_tests:

  ; printing game names
  ldx #LINES_PER_SCREEN
  jsr print_last_name
.print_next_game_at_start:
  inc <LAST_LINE_GAME
  lda <LAST_LINE_GAME
  bne .last_line_ok
  inc <LAST_LINE_GAME+1
.last_line_ok:
  inc <LAST_LINE_MODULO
  lda <LAST_LINE_MODULO
  cmp #LINES_PER_SCREEN * 2
  bne .modulo_ok
  lda #0
  sta <LAST_LINE_MODULO
.modulo_ok:
  jsr print_last_name
  dex
  bne .print_next_game_at_start

  ; enable PPU
  lda #%00001000 ; first nametable
  sta PPUCTRL
  lda #%00011110 ; enable sprites
  sta PPUMASK

  ; start dimming
  jsr dim_base_palette_in

  ; do not hold buttons!
  jsr wait_buttons_really_not_pressed

  ; main loop
infin:
  jsr waitblank
  jsr buttons_check
  jmp infin

NMI: ; not used
  rti

IRQ: ; not used
  rti

  .include "misc.asm"
  .include "buttons.asm"
  .include "video.asm"
  .include "sounds.asm"
  .include "tests.asm"
  .include "buildinfo.asm"
  .include "saves.asm"
  .include "preloader.asm"

  ; patterns
  .bank 12
  .org $8000
chr_data:
  .incbin MENU_HEADER_PATTERN_TABLE_BIN
  .org $8000 + 224 * 16
  .incbin "footer.pt"
  .org $8800
  .incbin "menu_symbols.bin"
  .org $9000
  .incbin "menu_sprites.bin"

  .bank 13
  .org $A000
  ; background
nametable_header:
  .incbin MENU_HEADER_NAME_TABLE_BIN
nametable_footer:
  .incbin "footer.nt"
tilepal:
  ; palette for background
  .incbin MENU_HEADER_BG_PALETTE_0
  .incbin MENU_HEADER_BG_PALETTE_1
  .incbin MENU_HEADER_BG_PALETTE_2
  .incbin "bg_palette3.bin"
  .org tilepal+$0F ; footer color
  .db $21
  .incbin "sprites_palette.bin" ; palette for sprites
  .org tilepal+$14 ; custom palette for stars
  .db $00, $22, $00, $00
  .db $00, $14, $00, $00
  .db $00, $05, $00, $00

header_attribute_table:
  .incbin MENU_HEADER_ATTRIBUTE_TABLE_BIN

  ; routines to be executed from RAM
  .bank 14
  .org $0500 ; actually it's $C500 in cartridge memory
ram_routines:
  .include "banking.asm"
  .include "flash.asm"
  .include "loader.asm"