-
Notifications
You must be signed in to change notification settings - Fork 1
/
reset512k.asm
450 lines (381 loc) · 5.21 KB
/
reset512k.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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
;---------------------------------------------------------------
.MACRO setdmapos _x,_y
_scnadd = SCREEN+(_y*$20)+_x
lda #>_scnadd
sta $2006
lda #<_scnadd
sta $2006
.ENDMACRO
;---------------------------------------------------------------
; CODE
;---------------------------------------------------------------
RESET: sei
ldx #$FF
txs ; set the stack pointer
stx $8000 ; reset the mapper
lda #%00010000 ;WRAM bank 0?
sta $Bfff
lsr a
sta $Bfff
lsr a
sta $Bfff
lsr a
sta $Bfff
lsr a
sta $Bfff
RESET2: lda #$00
sta PPU0
sta PPU1
;clear RAM
lda #$FF
ldx #$00
@a: sta $0000,x
sta $0100,x
sta $0200,x
sta $0300,x
sta $0400,x
sta $0500,x
sta $0600,x
sta $0700,x
inx
bne @a
;ldx #$FF ;reset stack pointer
;txs
;stx screenNumberOld
;jsr resetMMC1
lda #%00001100 ;Set bank layout, H&V mirror, 16kb ROM at $C000. 8KB CHR
jsr setMMC1r0
lda #$00
jsr setPRGBank
lda #%00010000 ;WRAM bank 0?
jsr setMMC1r1
jsr readPad1
lda PAD1_sel
beq @noClear
.IF 1=1
lda #%00010000 ;WRAM bank 0?
jsr setMMC1r1
lda #$FF
jsr clearWRAM
lda #%00010100 ;WRAM bank 1?
jsr setMMC1r1
lda #$01
jsr clearWRAM
lda #%00011000 ;WRAM bank 2?
jsr setMMC1r1
lda #$02
jsr clearWRAM
lda #%00011100 ;WRAM bank 3?
jsr setMMC1r1
lda #$03
jsr clearWRAM
lda #%00010000 ;WRAM bank 0?
jsr setMMC1r1
.ENDIF
jsr initPulsarData
@noClear:
jsr initGraphics
jsr clearSprites
;lda #$01
;jsr setPRGBank
;jsr initPulsar
;lda #$00
;jsr setPRGBank
lda #%10001000
sta PPU0
lda #%00011010
sta PPU1
mainLoop:
lda #$00
jsr setPRGBank
jsr initEditor
jmp editorLoop
jmp mainLoop
delay01:
ldx #$04
ldy #$00
@a: dey
bne @a
dex
bne @a
rts
whiteBar:
lda #%11111111
sta PPU1
jsr pulsarRefresh
lda #%00011110
sta PPU1
rts
NMI: pha
txa
pha
tya
pha
bit PPU_STATUS
lda currentBank
pha
lda #$03
jsr setPRGBank
jsr debugNumbers
jsr dmaPrimary
jsr dmaSecondary
lda #$FD ;use X scroll to move screen to left by 8 pixels
sta $2005
lda #$00
sta $2005
lda #$00
sta $2006
sta $2006
jsr spriteDMA
inc vblankFlag
.IF 0=1
lda #BANK_ENGINE
jsr setPRGBank
jsr whiteBar
jsr delay01
jsr whiteBar
jsr delay01
jsr whiteBar
jsr delay01
jsr whiteBar
jsr delay01
jsr processController ;***TEMP***for audio
.ENDIF
pla
jsr setPRGBank
;jsr readPad1
pla
tay
pla
tax
pla
IRQ: rti
vblankWait:
lda $2002
bpl vblankWait
rts
.include "debug.asm"
debugPhex:pha
lsr a
lsr a
lsr a
lsr a
sta $2007
pla
and #$0F
sta $2007
rts
phexWindow:
pha
lsr a
lsr a
lsr a
lsr a
sta windowBuffer,x
inx
pla
and #$0F
sta windowBuffer,x
inx
rts
phexRow: pha
lsr a
lsr a
lsr a
lsr a
sta rowBuffer,x
inx
pla
and #$0F
sta rowBuffer,x
inx
rts
phexTitle:
pha
lsr a
lsr a
lsr a
lsr a
sta titleBuffer,x
inx
pla
and #$0F
sta titleBuffer,x
rts
initGraphics:
;CHR Font
lda #<font
sta tmp0
lda #>font
sta tmp1
lda #BANK_FONT
jsr setPRGBank
lda #>CHR_RAM_0
sta $2006
lda #<CHR_RAM_0
sta $2006
jsr writeFont
;SPR Font
lda #<spr
sta tmp0
lda #>spr
sta tmp1
lda #>CHR_RAM_1
sta $2006
lda #<CHR_RAM_1
sta $2006
jsr writeFont
lda #<layout
sta tmp0
lda #>layout
sta tmp1
lda #>SCREEN
sta $2006
lda #<SCREEN
sta $2006
ldy #$00
ldx #$04
@c: lda (tmp0),y
sta $2007
iny
bne @c
inc tmp1
dex
bne @c
lda #BANK_FIXED
jsr setPRGBank
lda #$3f
ldx #$00
sta $2006
stx $2006
@a: lda palette,x
sta $2007
inx
cpx #$20
bne @a
rts
attributeTable:
.BYTE $55,$55,$55,$55,$55,$55,$55,$55
.BYTE $00,$00,$11,$00,$00,$00,$00,$00
.BYTE $00,$00,$11,$00,$00,$00,$00,$00
.BYTE $00,$00,$11,$00,$00,$00,$00,$00
.BYTE $00,$00,$11,$00,$00,$00,$00,$00
.BYTE $AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA
;%0101-0101
;.BYTE $FA,$FA,$FA,$FA,$FA,$FA,$BA,$EA
.BYTE $FA,$FA,$FA,$FA,$FA,$FA,$BA,$EA
.BYTE $5F,$5F,$4F,$0F,$4F,$0F,$4B,$0E
writeFont: ldx #$10
ldy #$00
@writeFont: lda (tmp0),y
sta $2007
iny
bne @writeFont
inc tmp1
dex
bne @writeFont
rts
palette: .incbin "set.dat"
spriteDMA:
lda #$00
sta $2003
lda #>sprBuf
sta $4014
;Flash palette
lda #>$3F13
sta $2006
lda #<$3F13
sta $2006
lda cursorFlashColour
sta $2007
lda #$00
sta $2006
sta $2006
rts
clearSprites:
ldx #$00
@a: lda #240
sta SPR_Y,x
lda #$C0
sta SPR_CHAR,x
lda #$00
sta SPR_ATTR,x
lda #$00
sta SPR_X,x
inx
inx
inx
inx
bne @a
rts
;---------------------------------------------------------------
; ENGINE CODE
;---------------------------------------------------------------
.include "joypad.asm"
;---------------------------------------------------------------
; MMC1 CODE
;---------------------------------------------------------------
clearWRAM:
ldx #<SRAM
stx tmp0
ldx #>SRAM
stx tmp1
ldx #$20
ldy #$00
@clearWram:
sta (tmp0),y
iny
bne @clearWram
inc tmp1
dex
bne @clearWram
rts
resetMMC1:
ldx #$80
stx $8000
rts
setPRGBank:
sta currentBank
sta $E000
lsr a
sta $E000
lsr a
sta $E000
lsr a
sta $E000
lsr a
sta $E000
rts
setMMC1r0:
sta $9fff
lsr a
sta $9fff
lsr a
sta $9fff
lsr a
sta $9fff
lsr a
sta $9fff
rts
setMMC1r1:
sta $Bfff
lsr a
sta $Bfff
lsr a
sta $Bfff
lsr a
sta $Bfff
lsr a
sta $Bfff
rts
setMMC1r2:
sta $Dfff
lsr a
sta $Dfff
lsr a
sta $Dfff
lsr a
sta $Dfff
lsr a
sta $Dfff
rts