-
Notifications
You must be signed in to change notification settings - Fork 2
/
title.asm
320 lines (250 loc) · 4.58 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
; asmsyntax=ca65
.importzp main_NUMBER_OF_MAPS
TITLE_SpriteTop = 79 ; topmost Y coordinate of cursor
TitleCursorTile = $1D
Title_TextChrIdStart = $20
Title_TextChrAddrStart = Title_TextChrIdStart * 16
Title_TextLength = 12
Title_TextRowCount = 2
Init_Title:
.NMI_Disable
.Disable_Drawing
; Load up a palette
.repeat 8, i
lda Pal_Tv+i
sta PaletteBuffer+i
sta PaletteBufferSprites+i
.endrepeat
;lda #$0
;sta txt_NoClear
; Unused palettes. Make them red.
; lda #$16
;.repeat 4, i
; sta PaletteBuffer+8+i
; sta PaletteBufferSprites+8+i
;.endrepeat
jsr ClearRam
jsr ClearSprites
lda #$0F
sta CurrentBoard
lda #ChrData::Title
jsr LoadChrData
jsr WriteBlankTile
;lda #7
;jsr LoadChrData
jsr ClearAttrTable0
;lda #$0F
;jsr FillNametable0
jsr WriteTvAttr
lda #ScreenIDs::Tv
ldx #$20
jsr LoadScreen
; Draw a menu
lda #$21
sta AddressPointer0+1
lda #$4A
sta AddressPointer0+0
ldx LastSpriteOffset
lda #79
sta Sprites, x
lda #70
sta Sprites+3, x
lda #TitleCursorTile ; tile
sta Sprites+1, x
lda #$00 ; attr
sta Sprites+2, x
; Draw two rows for the menu text.
ldy #Title_TextChrIdStart
ldx #0
stx TmpX ; rows
@textTileLoop:
; CHR start address for the text
lda AddressPointer0+1
sta $2006
lda AddressPointer0+0
sta $2006
; Calculate the next start address
clc
adc #64
sta AddressPointer0+0
lda AddressPointer0+1
adc #0
sta AddressPointer0+1
ldx #0 ; colums
:
sty $2007
iny
inx
cpx #Title_TextLength
bne :-
inc TmpX
lda TmpX
cmp #Title_TextRowCount
bne @textTileLoop
ldx #0
ldy #0
sty TmpX
@menuLoop:
txa
pha
jsr title_DrawText
pla
tax
inc TmpX
; Read the init index
iny
lda data_TitleMenu, y
sta title_MenuItems, x
inx
stx title_MenuLength
; Check for next item
iny
lda data_TitleMenu, y
beq @menuDone
jmp @menuLoop
@menuDone:
jsr WaitForNMI
lda #0
sta $2005
sta $2005
sta ls_PrevTraceCount
; Currently selected item
sta IdxA
lda #$0F
sta menu_PrevLevel
lda #3
sta LivesCount
jsr ReadControllers
.NMI_Set NMI_Title
Frame_Title:
jsr ReadControllers
lda #BUTTON_START
jsr ButtonPressedP1
beq :+
jmp title_SelectMenuOption
jmp @button_done
: lda #BUTTON_A
jsr ButtonPressedP1
beq :+
jmp title_SelectMenuOption
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 IdxA
asl a
asl a
asl a
asl a
clc
adc #TITLE_SpriteTop
ldx LastSpriteOffset
sta Sprites+0, x
jsr WaitForNMI
jmp Frame_Title
; Move selection up
t_sel_up:
dec IdxA
bpl :+
; Wrap around to end
lda title_MenuLength
sec
sbc #1
sta IdxA
: rts
; Move selection down
t_sel_down:
inc IdxA
lda IdxA
cmp title_MenuLength
bcc :+
; wrap the index around to zero
lda #0
sta IdxA
: rts
NMI_Title:
; Select first nametable
jsr WritePalettes
jsr WriteSprites
lda #%10000000
sta $2000
lda #%00011110
sta $2001
.SetScroll $00
dec Sleeping
rti
; Null terminated string in AddressPointer0, PPU
; address should already be set.
title_DrawText:
jsr TextClearStringBuffer
ldx #0
lda #0
:
sta TextBuffer, x
inx
cpx #12
bne :-
;ldy #0
ldx #0
:
lda data_TitleMenu, y
beq :+
sta TextBuffer, x
inx
iny
jmp :-
:
tya
pha
jsr TextPrepare
lda TmpX
beq @firstRow
; Second row
lda #$C0
sta AddressPointer0+0
lda #$02
sta AddressPointer0+1
jmp @end
@firstRow:
lda #$00
sta AddressPointer0+0
lda #$02
sta AddressPointer0+1
@end:
;pla ; number of tiles to write
lda #12
jsr WriteTextBuffer
pla
tay
rts
title_SelectMenuOption:
lda CurrentBoard
sta menu_PrevLevel
.NMI_Disable
jsr WaitForNMI
ldx IdxA
lda title_MenuItems, x
jmp JumpToInit
; Text is null terminated
data_TitleMenu:
.byte "Level Select", $00, InitIDs::LevelSelect
.byte "Credits", $00, InitIDs::Credits
.byte $00
title_PalBackground:
.byte $0F, $11, $14, $1B
nop
nop