-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtitle.asm
440 lines (359 loc) · 6.33 KB
/
title.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
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
; asmsyntax=ca65
TITLE_SPTOP = $48
InitTitle:
; Ignore input the next five frames (that it is checked)
lda #5
sta IgnoreInput
; set the draw orientation
lda #PPU_CTRL_TITLE
sta $2000
lda #PPU_MASK_OFF
sta $2001
inc SkipNMI
jsr ClearSprites
lda #0
.ifdef NTSC
ldx #0
.else
ldx #1
.endif
jsr snd_LOAD
bit $2002
lda #$3F
sta $2006
lda #$00
sta $2006
lda #$0F
sta $2007
lda #$21
sta $2006
lda #$80
sta $2006
lda #$00
ldx #18
:
.repeat 32
sta $2007
.endrepeat
dex
bne :-
; Load the title palette's ROM addr
lda #<TitlePalette
sta PaletteAddr
lda #>TitlePalette
sta PaletteAddr+1
; Then load ROM -> RAM
jsr LoadPalettes
;jsr WritePalettes
lda #0
sta TitleIndex
jsr ClearSprites
jsr ClearAttrTable0
jsr ClearAttrTable2
; Draw the visible Skyline
lda #BackgroundThemes::City
sta BGTheme
lda #$28
sta BGNametable
lda #$00
sta BGYStart
jsr DrawBackground
; Draw the offscreen skyline
lda #$20
sta BGNametable
lda #$00
sta BGYStart
jsr DrawBackground
; Attributes for skyline
lda #$23
sta $2006
lda #$D8
sta $2006
lda #$55
.repeat 32
sta $2007
.endrepeat
; Init the cursor sprite
; Y coord
lda #TITLE_SPTOP
sta SP_TITLEY0
sta SP_TITLEY1
; X coord
lda #$4E
sta SP_TITLEX0
lda #$56
sta SP_TITLEX1
; no attributes
lda #$00
sta SP_TITLEATTR0
sta SP_TITLEATTR1
; '->'
lda #$01 ; '-'
sta SP_TITLETILE0
lda #$02 ; '>'
sta SP_TITLETILE1
; Sprite Zero
lda #$88
sta SPZ_Y
lda #$F8
sta SPZ_X
lda #3
sta SPZ_IDX
lda #3
sta SPZ_ATT
; RAINBOW start
lda #$11
sta TitleColor
lda #$1C
sta TitleColor2
; /RAINBOW
; Draw Title
lda #$22
sta $2006
lda #$28
sta $2006
; Top row of title
ldx #$90
:
stx $2007
inx
cpx #$A0
bne :-
; Bottom row of title
lda #$22
sta $2006
lda #$48
sta $2006
ldx #$A0
:
stx $2007
inx
cpx #$B0
bne :-
lda #$22
sta TmpAddr
lda #$AD
sta TmpAddr+1
; Draw menu items
ldx #0
ldy #0
@menuLoopTop:
lda TmpAddr
sta $2006
lda TmpAddr+1
sta $2006
lda TitleData, x
beq @menuDone ; null terminated table (in the index column)
sta TmpX ; start tile index
inx
lda TitleData, x
sta TmpY
inx
lda TitleData, x
sta TitleGameStates, y
inx
iny
; next letter
@menuLoopText:
lda TmpX
sta $2007
inc TmpX
dec TmpY
bne @menuLoopText
;jmp @menuLoopTop
@textDone:
; go to the next line of text on screen
lda TmpAddr+1
clc
adc #64
sta TmpAddr+1
lda TmpAddr
adc #0
sta TmpAddr
jmp @menuLoopTop
@menuDone:
tya
sta TitleLength
; Tile for sprite zero hit
lda #$23
sta $2006
lda #$BF
sta $2006
lda #$0F
;lda #$20
sta $2007
lda #$29
sta $2006
lda #$80
sta $2006
lda #$00
ldx #18
:
.repeat 32
sta $2007
.endrepeat
dex
bne :-
lda #<Frame_Title
sta DoFramePointer
lda #>Frame_Title
sta DoFramePointer+1
lda #<NMI_Title
sta DoNMIPointer
lda #>NMI_Title
sta DoNMIPointer+1
; reset scroll
bit $2002
lda #$00
sta $2005
lda #95
sta $2005
rts
NMI_Title:
jsr WritePalettes
jsr WriteSprites
; Scroll half way down the screen
bit $2002
lda #0
sta $2005
lda #95
sta $2005
lda #PPU_CTRL_HORIZ
sta $2000
jmp NMI_Finished
title_Colors:
; only update colors every other frame
lda frame_odd
beq @t_nocolorwrap
inc TitleColor
dec TitleColor2
lda TitleColor
cmp #$1D
bne @t_nocolorwrap
lda #$11
sta TitleColor
lda #$1C
sta TitleColor2
@t_nocolorwrap:
; load palette into ram
lda TitleColor
sta PaletteRAM+26
;lda #$0F
;sta PaletteRAM+31
lda TitleColor2
sta PaletteRAM+14
lda frame_odd
bne @tf_setev
lda #1
sta frame_odd
jmp @tf_wot
@tf_setev:
lda #0
sta frame_odd
@tf_wot:
rts
; Move selection up
t_sel_up:
dec TitleIndex
bpl :+
; Wrap around to end
lda TitleLength
sec
sbc #1
sta TitleIndex
: rts
; Move selection down
t_sel_down:
inc TitleIndex
lda TitleIndex
cmp TitleLength
bcc :+
; wrap the index around to zero
lda #0
sta TitleIndex
: rts
t_sel_go:
ldx TitleIndex
lda TitleGameStates, x
sta current_gamestate
cmp #STATES::GS_GAME
beq @trans
inc gamestate_changed
rts
@trans:
jmp Title_GameTrans
; This is the default frame
Frame_Title:
jsr title_Colors
lda #BUTTON_START
jsr ButtonPressedP1
beq :+
jsr t_sel_go
jmp @button_done
: lda #BUTTON_A
jsr ButtonPressedP1
beq :+
jsr t_sel_go
jmp @button_done
: lda #BUTTON_UP
jsr ButtonPressedP1
beq :+
jsr t_sel_up
jmp @button_done
: lda #BUTTON_DOWN
jsr ButtonPressedP1
beq :+
jsr t_sel_down
jmp @button_done
: lda #BUTTON_SELECT
jsr ButtonPressedP1
beq :+
jsr t_sel_down
:
@button_done:
; calculate Y for cursor
lda TitleIndex
asl a
asl a
asl a
asl a
clc
adc #TITLE_SPTOP
sta SP_TITLEY0
sta SP_TITLEY1
jmp WaitFrame
TitleText:
.byte '"', "runner", '"', $00
TitleSeedText:
.byte "Current seed: ", $00
TitleData:
; Start tile id, length, game state
.byte $7F, 9, STATES::GS_GAME ; Start Game
.byte $70, 9, STATES::GS_SEED
.byte $67, 9, STATES::GS_HIGHSCORE
.byte $79, 6, STATES::GS_CREDITS
.byte $00
Title_BG1:
.byte $D0, $D4, $D0, $D4, $D0, $D4
Title_BG2:
.byte $DF, $D1, $D5, $D1, $D5, $D1, $D5
Title_BG3:
.byte $D7, $D6, $DA, $D6, $DA, $D6, $DA, $D6, $DA
Title_BG4:
.byte $DD, $DB, $D8, $D9, $D8, $D9, $D8, $D9, $03
Title_BG5:
.byte $D2, $D0, $D4, $D0, $D4, $D0, $D4, $D0, $D4
Title_BG6:
.byte $D3, $D1, $D5, $D1, $D5, $D1, $D5, $D1, $D5
TitlePalette:
; Background
.byte $0F,$0F,$0F,$0F
.byte $0F,$17,$24,$14
.byte $0F,$0F,$0F,$0F
.byte $0F,$0F,$0F,$0F
; Sprites
.byte $0F,$10,$00,$30
.byte $0F,$0F,$0F,$0F
.byte $0F,$0F,$0F,$0F
.byte $0F,$0F,$0F,$0F
.byte $EA, $EA