-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_current.asm
376 lines (321 loc) · 8.05 KB
/
test_current.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
.inesprg 1 ; 1x 16KB PRG code
.ineschr 1 ; 1x 8KB CHR data
.inesmap 0 ; mapper 0 = NROM, no bank swapping
.inesmir 1 ; background mirroring
;;
;; VARS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.rsset $0000 ;;vars at RAM x0000
framecount .rs 1 ;frame counter
seconds .rs 1
button1 .rs 1
button2 .rs 1
player1x .rs 1
player1y .rs 1
;;
;; CONSTANTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
P1STARTX = $70
P1STARTY = $A0
FPS = $3C
;;memory bank 1; executable code
.bank 0
.org $C000
RESET: ;;when reset or powered on
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:
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
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 ; start out at 0
LoadPalettesLoop:
LDA palette, x ; load data from address (palette + the value in x)
; 1st time through loop it will load palette+0
; 2nd time through loop it will load palette+1
; 3rd time through loop it will load palette+2
; etc
STA $2007 ; write to PPU
INX ; X = X + 1
CPX #$20 ; Compare X to hex $10, decimal 16 - copying 16 bytes = 4 sprites
BNE LoadPalettesLoop ; Branch to LoadPalettesLoop if compare was Not Equal to zero
; if compare was equal to 32, keep going down
;;;;;;;;;;;;;;;;;
;; INIT VARS
LDA #P1STARTX
STA player1x
LDA #P1STARTY
STA player1y
LDA #$00
STA framecount
STA seconds
LoadSprites:
LDX #$00 ; start at 0
LoadSpritesLoop:
LDA player1, x ; load data from address (player1 + x)
STA $0200, x ; store into RAM address ($0200 + x)
INX ; X = X + 1
CPX #$20 ; Compare X to hex $10, decimal 16
BNE LoadSpritesLoop ; Branch to LoadSpritesLoop if compare was Not Equal to zero
; if compare was equal to 16, keep going down
LoadBackground:
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$20
STA $2006 ; write the high byte of $2000 address
LDA #$00
STA $2006 ; write the low byte of $2000 address
LDX #$00 ; start out at 0
.WriteSky: ;;write the top 20 rows of 32 tiles as empty ($24 in mario)
LDA #$24
STA $2007 ; write to PPU
LDA #$24
STA $2007
LDA #$24
STA $2007
LDA #$24
STA $2007
LDA #$24
STA $2007
INX
CPX #$80 ;;32*20=640=5 sets of $80
BNE .WriteSky
LDX #$00
.WriteGround:
LDA #$25
STA $2007 ; write to PPU
LDA #$25
STA $2007
LDA #$25
STA $2007
LDA #$25
STA $2007
LDA #$25
STA $2007
INX
CPX #$40 ;;32*10=640=5 sets of $40
BNE .WriteGround
.BGExit:
LoadAttribute:
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$23
STA $2006 ; write the high byte of $23C0 address
LDA #$C0
STA $2006 ; write the low byte of $23C0 address
LDX #$00 ; start out at 0
LoadAttributeLoop:
LDA attribute, x ; load data from address (attribute + the value in x)
STA $2007 ; write to PPU
INX ; X = X + 1
CPX #$08 ; Compare X to hex $08, decimal 8 - copying 8 bytes
BNE LoadAttributeLoop ; Branch to LoadAttributeLoop if compare was Not Equal to zero
; if compare was equal to 128, keep going down
LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
STA $2000 ;; PPU CONTROL
LDA #%00011110 ; enable sprites, enable background, no clipping on left side
STA $2001
Forever:
JMP Forever ;jump back to aForever, infinite loop
NMI:
LDA #$00
STA $2003 ; set the low byte (00) of the RAM address
LDA #$02
STA $4014 ; set the high byte (02) of the RAM address, start the transfer
;
; CONTROLLERS
;
JSR ReadControllers
JSR Movement
JSR TestBank1
JSR FrameCount
RTI ;return from interrupt
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;
;; subroutines
;;
;; CONTROLLER BITS: Bx-A-B-SEL-ST-U-D-L-R
ReadControllers: ;;latch buttons on controller 1 and 2
LDA #$01
STA $4016
LDA #$00
STA $4016
LDX #$08
.ReadController1Loop:
LDA $4016
LSR A
ROL button1
DEX
BNE .ReadController1Loop
LDX #$08
.ReadController2Loop:
LDA $4017
LSR A ; bit0 -> Carry
ROL button2 ; bit0 <- Carry
DEX
BNE .ReadController2Loop
RTS
Movement: ;;input->sprite movement
;;p1
;;--right component
LDA button1
AND #%00000001
BEQ .ReadRDone
LDA player1x
CMP #$F0
BEQ .ReadRDone
CLC
ADC #$01
STA player1x
.ReadRDone:
;;--left component
LDA button1
AND #%00000010
BEQ .ReadLDone
LDA player1x
CMP #$00
BEQ .ReadLDone
SEC
SBC #$01
STA player1x
.ReadLDone:
;;--down
LDA button1
AND #%00000100
BEQ .ReadDDone
LDA player1y
CMP #$C6
BEQ .ReadDDone
CLC
ADC #$01
STA player1y
.ReadDDone:
;;--up
LDA button1
AND #%00001000
BEQ .ReadUDone
LDA player1y
CMP #$90
BEQ .ReadUDone
SEC
SBC #$01
STA player1y
.ReadUDone:
.MoveSprites: ;;8 tile player sprite
CLC
LDA player1y
;;top
STA $0200
STA $0204
;;midtop
ADC #$08
STA $0208
STA $020C
;;midbot
ADC #$08
STA $0210
STA $0214
;;lowbot
ADC #$08
STA $0218
STA $021C
CLC
LDA player1x
;;left
STA $0203
STA $020B
STA $0213
STA $021B
ADC #$08
;;right
STA $0207
STA $020F
STA $0217
STA $021F
RTS ;;END Movement sr
FrameCount:
LDA framecount
CLC
ADC #$01
STA framecount
CMP #FPS
BNE .EndCount
LDA seconds
CLC
ADC #$01
STA seconds
LDA #$00
STA framecount
.EndCount:
RTS
;;
;;;;;;;;;;;;;;;-END BANK0
;;;;;;;;;;;;;;;-BANK1
;;
.bank 1
.org $E000
palette: ;$3F00-$3F0F =bg, $3F10-$3F1F=sprite
.db $22,$29,$1A,$0F, $22,$36,$17,$0F, $22,$30,$21,$0F, $22,$27,$17,$0F ;;background palette
.db $22,$37,$01,$18, $22,$37,$30,$0F, $22,$37,$0C,$0F, $21,$25,$38,$04 ;;sprite palette
TestBank1:
LDA #$DE
STA $10
LDA #$AD
STA $11
RTS
player1:
;vert tile attr horiz
.db $70, $00, $00, $80 ;sprite 0
.db $70, $01, $00, $88 ;sprite 1
.db $78, $02, $01, $80 ;sprite 2
.db $78, $03, $01, $88 ;sprite 3
.db $80, $04, $02, $80 ;sprite 2
.db $80, $05, $02, $88 ;sprite 3
.db $88, $06, $02, $80 ;sprite 2
.db $88, $07, $02, $88 ;sprite 3
;;BOTTOM:10
.db $0C,$08,$09,$0A,$09,$0C,$08,$09,$0A,$09,$0C,$08,$09,$0A,$09,$0C
.db $08,$09,$0A,$09,$0C,$08,$09,$0A,$09,$0C,$08,$09,$0A,$09,$0C,$08
.db $09,$0A,$09,$0C,$08,$09,$0A,$09,$0C,$08,$09,$0A,$09,$0C,$08,$09
.db $0A,$09,$0C,$08,$09,$0A,$09,$0C,$08,$09,$0A,$09,$0C,$08,$09,$0A
attribute:
.db %00100000, %01010000, %01000001, %01010000, %00010000, %01010000, %00010000, %01010000
.org $FFFA ;first of the three vectors starts here
.dw NMI ;when an NMI happens (once per frame if enabled) the
;processor will jump to the label NMI:
.dw RESET ;when the processor first turns on or is reset, it will jump
;to the label RESET:
.dw 0 ;external interrupt IRQ is not used
;;;;;;;;;;;;;;
.bank 2
.org $0000
.incbin "mariohack.chr" ;includes 8KB graphics file from SMB1