-
Notifications
You must be signed in to change notification settings - Fork 1
/
naveZika.asm
310 lines (263 loc) · 6.48 KB
/
naveZika.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
.inesprg 1 ; Defines the number of 16kb PRG banks
.ineschr 1 ; Defines the number of 8kb CHR banks
.inesmap 0 ; Defines the NES mapper
.inesmir 1 ; Defines VRAM mirroring of banks
.rsset $0000 ; Defines where in memory the two variables bellow will be located
; These two variable will be used to loop through all the data
pointerBackgroundLowByte .rs 1
pointerBackgroundHighByte .rs 1
shotPlayer1Exists .rs 1
shotPlayer2Exists .rs 1
shotspeed .rs 1
lifeCounterP1 .rs 3
lifeCounterP2 .rs 3
leftShotHitP1 .rs 1
rightShotHitP1 .rs 1
leftShotHitP2 .rs 1
rightShotHitP2 .rs 1
gameOverLock .rs 1
leftShotPlayer1Y = $0318
leftShotPlayer1Tile = $0319
leftShotPlayer1Color = $031A
leftShotPlayer1X = $031B
rightShotPlayer1Y = $031C
rightShotPlayer1Tile = $031D
rightShotPlayer1Color = $031E
rightShotPlayer1X = $031F
heart0ColorP1 = $0322
heart1ColorP1 = $0326
heart2ColorP1 = $032A
heart3ColorP1 = $032E
heart4ColorP1 = $0332
heart0ColorP2 = $0336
heart1ColorP2 = $033A
heart2ColorP2 = $033E
heart3ColorP2 = $0342
heart4ColorP2 = $0346
; These variables represent the vertical and horizontal positions of spaceship 1 sprites;
ship1Tile1Y = $0300
ship1Tile2Y = $0304
ship1Tile3Y = $0308
ship1Tile4Y = $030C
ship1Tile5Y = $0310
ship1Tile6Y = $0314
ship1Tile1X = $0303
ship1Tile2X = $0307
ship1Tile3X = $030B
ship1Tile4X = $030F
ship1Tile5X = $0313
ship1Tile6X = $0317
ship2Tile1Y = $0348
ship2Tile2Y = $034C
ship2Tile3Y = $0350
ship2Tile4Y = $0354
ship2Tile5Y = $0358
ship2Tile6Y = $035C
ship2Tile1X = $034B
ship2Tile2X = $034F
ship2Tile3X = $0353
ship2Tile4X = $0357
ship2Tile5X = $035B
ship2Tile6X = $035F
leftShotPlayer2Y = $0360
leftShotPlayer2Tile = $0361
leftShotPlayer2Color = $0362
leftShotPlayer2X = $0363
rightShotPlayer2Y = $0364
rightShotPlayer2Tile = $0365
rightShotPlayer2Color = $0366
rightShotPlayer2X = $0367
GspriteY = $0368
GspriteColor = $036A
AspriteY = $036C
AspriteColor = $036E
MspriteY = $0370
MspriteColor = $0372
EspriteY = $0374
EspriteColor = $0376
OspriteY = $0378
OspriteColor = $037A
VspriteY = $037C
VspriteColor = $037E
EEspriteY = $0380
EEspriteColor = $0382
RspriteY = $0384
RspriteColor = $0386
.bank 0 ; Defines bank of memory
.org $C000 ; Defines where in the CPU’s address space it is located
;initial state and graphics
RESET:
SEI ; disable IRQs
CLD ; disable decimal mode
LDX #$40
STX $4017 ; disable APU frame IRQ
LDX #$FF
TXS ; Set up stack
INX ; now X = 0
STX $2000 ; disable NMI
STX $2001 ; disable rendering
STX $4010 ; disable DMC IRQs
vblankwait1: ; First wait for vblank to make sure PPU is ready
BIT $2002
BPL vblankwait1
clrmem: ; clear memory
LDA #$00
STA $0000, x
STA $0100, x
STA $0300, x
STA $0400, x
STA $0500, x
STA $0600, x
STA $0700, x
LDA #$FE
STA $0200, x
INX
BNE clrmem
vblankwait2: ; Second wait for vblank, PPU is ready after this
BIT $2002
BPL vblankwait2
JSR LoadBackground
JSR LoadPalettes
JSR LoadAttributes
JSR LoadSprites
JSR SetShotSpeed
JSR SetLifeCounters
JSR SetShotsHit
JSR SetGameOverTiles
LDA #%10000000 ; Enable NMI, sprites and background on table 0
STA $2000
LDA #%00011110 ; Enable sprites, enable backgrounds
STA $2001
LDA #$00 ; No background scrolling
STA $2006
STA $2006
STA $2005
STA $2005
InfiniteLoop:
JMP InfiniteLoop
LoadBackground:
LDA $2002
LDA #$20
STA $2006
LDA #$00
STA $2006
LDA #LOW(background)
STA pointerBackgroundLowByte
LDA #HIGH(background)
STA pointerBackgroundHighByte
LDX #$00
LDY #$00
.Loop:
LDA [pointerBackgroundLowByte], y
STA $2007
INY
CPY #$00
BNE .Loop
INC pointerBackgroundHighByte
INX
CPX #$04
BNE .Loop
RTS
LoadPalettes:
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$3F
STA $2006 ; write the high byte of $3F00 address
LDA #$00
STA $2006 ; write the low byte of $3F00 address
LDX #$00
.Loop:
LDA palettes, x ;load palette byte
STA $2007 ;write to PPU
INX ;set index to next byte
CPX #$20
BNE .Loop ;if x = $20, 32 bytes copied, all done
RTS
LoadAttributes:
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$23
STA $2006 ; write the high byte of $3F00 address
LDA #$C0
STA $2006 ; write the low byte of $3F00 address
LDX #$00
.Loop:
LDA attributes, x
STA $2007
INX
CPX #$40 ;if x = $40, 64 bytes copied, all done
BNE .Loop
RTS
LoadSprites:
LDX #$00
.Loop:
LDA spritePlayer1, x ;load palette byte
STA $0300, x ;write to PPU
INX ;set index to next byte
CPX #$A0
BNE .Loop ;if x = $80, 128 in decimal, all done
RTS
SetShotSpeed:
LDA #$04
STA shotspeed
RTS
SetLifeCounters:
LDA #$05
STA lifeCounterP1
STA lifeCounterP2
RTS
SetGameOverLock:
LDA #$00
STA gameOverLock
SetShotsHit:
LDA #$00
STA leftShotHitP1
STA rightShotHitP1
STA leftShotHitP2
STA rightShotHitP2
RTS
SetGameOverTiles:
LDA #$03
STA GspriteColor
STA AspriteColor
STA MspriteColor
STA EspriteColor
STA OspriteColor
STA VspriteColor
STA EEspriteColor
STA RspriteColor
RTS
NMI:
LDA #$00
STA $2003 ; set the low byte (00) of the RAM address
LDA #$03
STA $4014 ; set the high byte (02) of the RAM address, start the transfer
JSR ReadPlayerOneControls ; read the player 1 input
JSR ReadPlayerTwoControls ; read the player 2 input
JSR movePlayer1ShotIfExistis
JSR movePlayer2ShotIfExistis
JSR checkShotCollisionP1
JSR checkShotCollisionP2
RTI ; return from interrupt
.bank 1
.org $E000
.include "decreaseLife.asm"
.include "movements/player1Movements.asm"
.include "movements/player2Movements.asm"
.include "shots/player1Shot.asm"
.include "shots/player2Shot.asm"
.include "sound/beep.asm"
.include "shotCollisions.asm"
background:
.include "graphics/background.asm"
palettes:
.include "graphics/palettes.asm"
attributes:
.include "graphics/attributes.asm"
sprites:
.include "graphics/sprites.asm"
.org $FFFA
.dw NMI
.dw RESET
.dw 0
.bank 2
.org $0000
.incbin "graphics/graphics.chr"