-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstates.asm
349 lines (275 loc) · 6.5 KB
/
states.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
;
; Gamestate management
;
; ---------------------------
; Gamestate change dispatch
; subroutine
; ---------------------------
UpdateGameState:
inc SkipNMI
lda #0
sta GSUpdateNeeded
jsr ClearSprites
lda GameState ; load gamestate
asl a ; multiply by two
tax ; use it as an index
; low byte first
lda GameState_Table+1, x
pha
; then high byte
lda GameState_Table, x
pha
; Jump to sub-subroutine
rts
; -------------------------
; Load Title gamestate
; -------------------------
gsTitle:
lda #0
sta TitleSelected
;lda #0
;sta $2000
ldx #0
@loop:
lda PaletteData, x
sta PaletteRAM, x
inx
cpx #$20
bne @loop
lda BGData_Lookup
sta bgPointer
lda BGData_Lookup+1
sta bgPointer+1
lda #$FF
sta bgUpdateFlags
jsr UpdateBackground
; Load sprites
ldx #$00
titleSpriteLoop:
lda titleSpriteData, X
sta $0200, x
inx
cpx #$04 ; one sprite, four bytes per sprite
bne titleSpriteLoop
; Turn PPU back on
lda #PPU_ON
sta $2001
;lda FrameUpdates
;ora #%11000000
;sta FrameUpdates
;lda #%10010000
;sta $2000 ; enable NMI, sprites from pattern table 0
dec SkipNMI
rts
; -------------------------
; Load Gameplay gamestate
; -------------------------
gsGame:
; General INIT stuff
lda #$00
sta p1Score
sta p2Score
;sta $2000
jsr ResetBall
lda BGData_Lookup+2
sta bgPointer
lda BGData_Lookup+3
sta bgPointer+1
lda #$FF
sta bgUpdateFlags
jsr UpdateBackground
; Load sprites
ldx #$00
SpriteLoop:
lda SpriteData, X
sta $0200, x
inx
cpx #36 ; one sprite, four bytes per sprite
bne SpriteLoop
; Turn PPU back on
lda #PPU_ON
sta $2001
lda #$01
sta start_ticks
;lda #%10010000
;sta $2000 ; enable NMI, sprites from pattern table 0
dec SkipNMI
rts
; -------------------------
; Load Game Over gamestate
; -------------------------
gsDed:
; 2 - deterimine winner
; 3 - write winner to screen
; Player One
; Player Two
; Computer Player
; "Wins"
lda p1Score
cmp p2Score
bcc p2Won
; P1 Won
lda DedBG_Table
sta bgPointer
lda DedBG_Table+1
sta bgPointer+1
jmp gsDedEnd
p2Won:
lda TitleSelected
beq compWon
lda DedBG_Table+2
sta bgPointer
lda DedBG_Table+3
sta bgPointer+1
jmp gsDedEnd
compWon:
lda DedBG_Table+4
sta bgPointer
lda DedBG_Table+5
sta bgPointer+1
gsDedEnd:
lda #$FF
sta bgUpdateFlags
jsr UpdateBackground
dec SkipNMI
rts
ClearSprites:
ldx #$00
ClearSpriteLoop:
lda #$00
sta $0200, x
inx
cpx #$00 ; one sprite, four bytes per sprite
bne ClearSpriteLoop
rts
BGData_Lookup:
.word TitleBGData
.word GameBGData
GameState_Table:
.word gsDed-1
.word gsGame-1
.word gsTitle-1
TitleBGData:
; Flag byte
; %1000 0000 RLE
; %0100 0000 Skip PPU Address
; blank background to start of box
.byte $AA, $80, $20, $00, $01
; box top
.byte $01, $40, $06 ; left corner
.byte $0B, $C0, $02 ; top line
.byte $01, $40, $07 ; right corner
.byte $14, $C0, $01 ; blank until start of logo
; logo top row
.byte $0B, $40, $A0, $A1, $A2, $A3, $A4
.byte $A5, $A6, $A7, $A8, $A9, $AA
.byte $15, $C0, $01 ; black until 2nd row of logo
; logo bottom row
.byte $0B, $40, $B0, $B1, $B2, $B3, $B4
.byte $B5, $B6, $B7, $B8, $B9, $BA
.byte $14, $C0, $01 ; blank until start of bottom box
.byte $01, $40, $08 ; left corner
.byte $0B, $C0, $03 ; bottom line
.byte $01, $40, $09 ; right corner
; blank until menu start
.byte $F6, $C0, $01
;.byte $17, $C0, $01
.byte $07, $40
.byte "VS COMP"
.byte $39, $C0, $01
.byte $08, $40
.byte "2 PLAYER"
.byte $38, $C0, $01
.byte $0A, $40
.byte "SOUND TEST"
.byte $FF, $C0, $01
.byte $2A, $C0, $01
; attribute data
.byte $20, $C0, $55
.byte $20, $C0, $AA
.byte $00
titleSpriteData:
.byte $7F, $05, $00, $5E
GameBGData:
.byte $64, $80, $20, $00, $00
.byte $02, $C0, '0' ; should be at $2064
.byte $14, $C0, $00
.byte $02, $C0, '0' ; should be at $207A
.byte $FF, $C0, $00
.byte $FF, $C0, $00
.byte $FF, $C0, $00
.byte $47, $C0, $00
; attribute data
.byte $08, $C0, $0F
.byte $30, $C0, $00
.byte $08, $C0, $0F
; 2nd nametable - Game Over
.byte $FF, $80, $24, $00, $01
.byte $0A, $C0, $01
; 8 tiles in
.byte $0B, $40 ; address $2509
.byte $C0, $C1, $C2, $C3, $C4, $C5, $C6, $C7
.byte $C8, $C9, $CA
.byte $15, $C0, $01
.byte $0B, $40 ; address $2529
.byte $D0, $D1, $D2, $D3, $D4, $D5, $D6, $D7
.byte $D8, $D9, $DA
.byte $18, $C0, $01
.byte $0B, $40 ; address $254C
.byte $E0, $E1, $E2, $E3, $E4, $E5, $E6, $E7
.byte $E8, $E9, $EA
.byte $15, $C0, $01
.byte $0B, $00, $25, $6C
.byte $F0, $F1, $F2, $F3, $F4, $F5, $F6, $F7
.byte $F8, $F9, $FA
.byte $FF, $80, $25, $77, $01
.byte $FF, $C0, $01
.byte $4B, $C0, $01
; attribute data
.byte $18, $80, $27, $C0, $55
.byte $28, $C0, $AA
.byte $00
SpriteData:
; Sprite Attribute Stuff
; %1000 0000 Flip horizontally
; %0100 0000 Flip vertically
; %0010 0000 Priority (0 front of BG; 1 behind BG)
; %0000 1100 Ignored
; %0000 0011 Palette
; Y, Idx, Attr, X
.byte $80, $01, %00000000, $80 ; Ball
; Player 1
.byte $80, $02, %00000000, $08 ; Paddle top
.byte $88, $04, %00000000, $08 ; Paddle middle A
.byte $8F, $04, %00000000, $08 ; Paddle middle A
.byte $94, $03, %00000000, $08 ; Paddle bottom
; Player 2
.byte $80, $02, %00000000, $F0 ; Paddle top
.byte $88, $04, %00000000, $F0 ; Paddle middle A
.byte $8F, $04, %00000000, $F0 ; Paddle middle A
.byte $94, $03, %00000000, $F0 ; Paddle bottom
DedBG_Table:
.word DedBGOne
.word DedBGTwo
.word DedBGComp
; player 1
DedBGOne:
.byte $0A, $00, $25, $CB
.byte "PLAYER ONE"
.byte $04, $00, $25, $ED
.byte "WINS"
.byte $00
; player 2
DedBGTwo:
.byte $0A, $00, $25, $CB
.byte "PLAYER TWO"
.byte $04, $00, $25, $ED
.byte "WINS"
.byte $00
; computer player
DedBGComp:
.byte $0F, $00, $25, $C9
.byte "COMPUTER PLAYER"
.byte $04, $00, $25, $ED
.byte "WINS"
.byte $00