-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprite.asm
131 lines (113 loc) · 3.15 KB
/
sprite.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
.include "settings.inc"
.include "constants.inc"
.bank 0, 16, $c000, "NES_PRG0"
.segment "Code"
.org $C000
.function irq_handler
RTI
.endfunction
.function nmi_handler
LDA #$00
STA OAMADDR
LDA #$02
STA OAMDMA
RTI
.endfunction
.function reset_handler
;SEI
CLD
LDX #$00
STX PPUCTRL
STX PPUMASK
vblankwait:
BIT PPUSTATUS
BPL vblankwait
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 ;move all sprites off screen
INX
BNE clrmem
vblankwait2: ; Second wait for vblank, PPU is ready after this
BIT PPUSTATUS
BPL vblankwait2
JMP main
.endfunction
.function main
LDX PPUSTATUS ; Reset PPUADDR
LDX #$3f ; Write to PPUADDR
STX PPUADDR
LDX #$00
STX PPUADDR
LoadPalettesLoop:
LDA palette, x ;load palette byte
STA PPUDATA ;write to PPU
INX ;set index to next byte
CPX #$20
BNE LoadPalettesLoop ;if x = $20, 32 bytes copied, all done
; Segment 0
LDA #$70 ; y-coord of sprite
STA $0200
LDA #$05 ; index of sprite
STA $0201
LDA #$00 ; sprite attributes
STA $0202
LDA #$80 ; x-coord of sprite
STA $0203
; Segment 1
LDA #$70 ; y-coord of sprite
STA $0204
LDA #$06 ; index of sprite
STA $0205
LDA #$00 ; sprite attributes
STA $0206
LDA #$88 ; x-coord of sprite
STA $0207
; Segment 2
LDA #$78 ; y-coord of sprite
STA $0208
LDA #$07 ; index of sprite
STA $0209
LDA #$00 ; sprite attributes
STA $020A
LDA #$80 ; x-coord of sprite
STA $020B
; Segment 3
LDA #$78 ; y-coord of sprite
STA $020C
LDA #$08 ; index of sprite
STA $020D
LDA #$00 ; sprite attributes
STA $020E
LDA #$88 ; x-coord of sprite
STA $020F
LDA #%10010000
STA PPUCTRL
LDA #%00011110
STA PPUMASK
forever:
JMP forever
.endfunction
.segment "Palette"
.org $E000
palette:
.byte $0F,$31,$32,$33,$0F,$35,$36,$37,$0F,$39,$3A,$3B,$0F,$3D,$3E,$0F
.byte $0F,$1C,$15,$14,$0F,$02,$38,$3C,$0F,$1C,$15,$14,$0F,$02,$38,$3C
.segment "Vectors"
.org $FFFA ;first of the three vectors starts here
.word nmi_handler ;when an NMI happens (once per frame if enabled) the
;processor will jump to the label NMI:
.word reset_handler ;when the processor first turns on or is reset, it will jump
;to the label RESET:
.word irq_handler ;external interrupt IRQ is not used in this tutorial
.bank 1, 8, $0000, "NES_CHR0"
.segment "Chr"
.org $0000
.incbin "graphics.chr"