-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ded.asm
273 lines (219 loc) · 4.13 KB
/
ded.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
; asmsyntax=ca65
DedInit:
jsr MMC1_Setup_Vert
lda #$FF
sta game_paused ; to stop the skyline scroll
lda #1
sta Ded_Fading
lda #0
sta Ded_Pal
lda #DED_FADESPEED
sta Ded_FadeNext
jsr bufferScroll
jsr BufferSkylineScroll
lda #<Ded_Frame
sta DoFramePointer
lda #>Ded_Frame
sta DoFramePointer+1
lda #<Ded_NMI
sta DoNMIPointer
lda #>Ded_NMI
sta DoNMIPointer+1
jsr WriteSkylineScroll
jsr Scores_CheckIfNew
bne :+
rts
: jmp Scores_InsertNewScore
;rts
Ded_NMI:
jsr WritePalettes
jsr WriteSprites
lda Ded_Fading
beq @noscroll
; only update the scroll (for the status bar thing) if fading
jsr WriteSkylineScroll
jmp @end
@noscroll:
bit $2002
lda #0
sta $2005
lda #16
sta $2005
lda #PPU_CTRL_TITLE
sta $2000
@end:
jmp NMI_Finished
Ded_Frame:
lda Ded_Fading
beq @fadeDone
dec Ded_FadeNext
beq @doFade
jmp WaitSpriteZero
@doFade:
lda #DED_FADESPEED
sta Ded_FadeNext
lda Ded_Pal
cmp #4
bcc @notDone
lda #0
sta Ded_Fading
jmp WaitSpriteZero
@notDone:
asl a
asl a
tax
ldy #31
@fadeLoop:
lda PaletteRAM, y
sec
sbc #$10
bpl @notBlack
lda #$0D
@notBlack:
sta PaletteRAM, y
inx
dey
bpl @fadeLoop ; Fade all eight palettes
inc Ded_Pal
jmp WaitSpriteZero
@fadeDone:
lda #PPU_CTRL_TITLE
sta $2000
inc SkipNMI
lda #PPU_MASK_OFF
sta $2001
; Update a single palette. We don't care about the others.
lda #<DedSolidPalette
sta TmpAddr
lda #>DedSolidPalette
sta TmpAddr+1
jsr LoadPaletteBG0
jsr ClearAttrTable0
; Clear out the tile column draw buffer
ldx #15
lda #0
@loop:
sta tile_column_buffer, x
dex
bpl @loop
jsr ClearNametable0
jsr ClearNametable1
jsr ClearAttrTable0
jsr ClearAttrTable1
jsr ClearSprites
; Draw "Game Over"
lda #$21
sta $2006
lda #$8C
sta $2006
ldx #$C2
ldy #($CA - $C2)
jsr DrawSequential
; Draw "Press Start"
lda #$22
sta $2006
lda #$0B
sta $2006
ldx #$D0
ldy #($DA - $D0)
jsr DrawSequential
; Draw "Select to Restart"
lda #$22
sta $2006
lda #$8A
sta $2006
ldx #$E0
ldy #12
jsr DrawSequential
@startEnd:
; attributes for "Press Start"
lda #$23
sta $2006
lda #$E2
sta $2006
lda #$55
sta $2007
sta $2007
sta $2007
sta $2007
; reset the frame pointer to avoid fading again
lda #<GameOverWait
sta DoFramePointer
lda #>GameOverWait
sta DoFramePointer+1
lda DedStartPal
sta DED_START_PAL
lda #3
.ifdef NTSC
ldx #0
.else
ldx #1
.endif
jsr snd_LOAD
lda #0
sta TmpX ; current color index
lda #2
sta TmpY ; countdown to next switch
lda #0
sta SkipNMI
GameOverWait:
lda #$0F
sta PaletteRAM+28
sta PaletteRAM+20
sta PaletteRAM+3
sta PaletteRAM+7
sta PaletteRAM+11
sta PaletteRAM+15
sta PaletteRAM+19
sta PaletteRAM+23
sta PaletteRAM+27
sta PaletteRAM+31
; "press start" fade thing
dec TmpY
bne @noColor
lda #8
sta TmpY
ldx TmpX
lda DedStartPal, x
sta DED_START_PAL ; Palette 01, first non-BG color
inx
cpx #6
bne @noWrap
ldx #0
@noWrap:
stx TmpX
@noColor:
lda #BUTTON_SELECT
jsr ButtonPressedP1
beq @checkStart
jmp ReplayLastMap
@checkStart:
lda #BUTTON_START
jsr ButtonPressedP1
bne @gotoTitle
jmp WaitFrame
@gotoTitle:
; save the last working seed
lda working_seed
sta rng_seed
lda working_seed+1
sta rng_seed+1
lda #STATES::GS_TITLE
sta current_gamestate
inc gamestate_changed
jmp WaitFrame
ReplayLastMap:
; Do not save last working seed. Jump right to a new game.
lda #STATES::GS_GAME
sta current_gamestate
inc gamestate_changed
dec GameFullInit
jmp WaitFrame
DedText:
.byte "Game Over!", $00
DedStart:
.byte "Press Start", $00
DedSolidPalette:
.byte $0F,$30,$00,$30
DedStartPal:
.byte $2D,$00,$10,$20,$10,$00