-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaivLogo.S
276 lines (228 loc) · 5.38 KB
/
aivLogo.S
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
.db "NES", $1A, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
.org $8000
.define PPUCTRL $2000
.define PPUMASK $2001
.define OAMADDR $2003
.define OAMDATA $2004
.define PPUSCROLL $2005
.define PPUADDR $2006
.define PPUDATA $2007
.define JOYPAD1 $4016
.define scrollx $01
.define buttons $02
.define currentlinefirstbyte $03
.define currentlinelastbyte $04
.define spriteposY $05
; PPUCTRL:
; 7 bit 0
; ---- ----
; VPHB SINN
; |||| ||||
; |||| ||++- Base nametable address
; |||| || (0 = $2000; 1 = $2400; 2 = $2800; 3 = $2C00)
; |||| |+--- VRAM address increment per CPU read/write of PPUDATA
; |||| | (0: add 1, going across; 1: add 32, going down)
; |||| +---- Sprite pattern table address for 8x8 sprites
; |||| (0: $0000; 1: $1000; ignored in 8x16 mode)
; |||+------ Background pattern table address (0: $0000; 1: $1000)
; ||+------- Sprite size (0: 8x8 pixels; 1: 8x16 pixels – see PPU OAM#Byte 1)
; |+-------- PPU master/slave select
; | (0: read backdrop from EXT pins; 1: output color on EXT pins)
; +--------- Generate an NMI at the start of the
; vertical blanking interval (0: off; 1: on)
; PPUMASK
; 7 bit 0
; ---- ----
; BGRs bMmG
; |||| ||||
; |||| |||+- Greyscale (0: normal color, 1: produce a greyscale display)
; |||| ||+-- 1: Show background in leftmost 8 pixels of screen, 0: Hide
; |||| |+--- 1: Show sprites in leftmost 8 pixels of screen, 0: Hide
; |||| +---- 1: Show background
; |||+------ 1: Show sprites
; ||+------- Emphasize red (green on PAL/Dendy)
; |+-------- Emphasize green (red on PAL/Dendy)
; +--------- Emphasize blue
start:
LDA #%10000000
STA PPUCTRL
LDA #%00011110
STA PPUMASK
LDA #$3F
STA PPUADDR
LDA #0
STA PPUADDR
; color pallette
LDA #$0F
STA PPUDATA
LDA #$0
STA PPUDATA
LDA #$28
STA PPUDATA
LDA #$20
STA PPUDATA
; sprite color pallette
LDA #$3F
STA PPUADDR
LDA #$14
STA PPUADDR
LDA #$21
STA PPUDATA
LDA #$22
STA PPUDATA
LDA #$23
STA PPUDATA
LDA #$24
STA PPUDATA
LDA #$20
STA PPUADDR
LDA #$00
STA PPUADDR
LDX #1
; set current line at 0
LDA #$00
STA currentlinelastbyte
LDA #$20
STA currentlinefirstbyte
JSR draw_image
LDX #1
LDA #$00
STA currentlinelastbyte
LDA #$24
STA currentlinefirstbyte
JSR draw_image
LDA #0
STA OAMADDR
LDA #$22 ;posy
STA OAMDATA
LDA #$66 ;tile index
STA OAMDATA
LDA #%00000001 ;attributes
STA OAMDATA
LDA #$22 ;posx
STA OAMDATA
LDA #77
STA spriteposY
loop:
JMP loop
draw_image:
DEX
STX PPUDATA
INX
TXA
; 00000110
AND #%00001111 ; == #$0F
BEQ new_line
continue:
INX
BNE draw_image
RTS
new_line:
; 2110
LDA currentlinelastbyte
CLC
ADC #$20
STA currentlinelastbyte
BEQ incfirstbyte
afterincfirstbyte:
LDA currentlinefirstbyte
STA PPUADDR
LDA currentlinelastbyte
STA PPUADDR
JMP continue
incfirstbyte:
LDY currentlinefirstbyte
INY
STY currentlinefirstbyte
JMP afterincfirstbyte
; At the same time that we strobe bit 0, we initialize the ring counter
; so we're hitting two birds with one stone here
readjoy:
lda #$01
; While the strobe bit is set, buttons will be continuously reloaded.
; This means that reading from JOYPAD1 will only return the state of the
; first button: button A.
sta JOYPAD1
sta buttons
lsr a ; now A is 0
; By storing 0 into JOYPAD1, the strobe bit is cleared and the reloading stops.
; This allows all 8 buttons (newly reloaded) to be read from JOYPAD1.
sta JOYPAD1
joyloop:
lda JOYPAD1
lsr a ; bit 0 -> Carry
rol buttons ; Carry -> bit 0; bit 7 -> Carry
bcc joyloop
rts
nmi:
PHA
JSR readjoy
PLA
JSR readxinput
RTI
readxinput:
LDA buttons
AND #%00001111
BEQ skipscroll
LDA buttons
AND #%00001101
BEQ decresescrollx
LDA buttons
AND #%00001110
BEQ incresescrollx
LDA buttons
AND #%00000111
BEQ movespriteUP
LDA buttons
AND #%00001011
BEQ movespriteDown
skipscroll:
JSR movesprite
LDA scrollx
STA PPUSCROLL
LDA #$00
STA PPUSCROLL
RTS
incresescrollx:
LDA scrollx
CMP #$FF
BEQ skipscroll
INC scrollx
JMP skipscroll
decresescrollx:
LDA scrollx
AND #$FF
BEQ skipscroll
DEC scrollx
JMP skipscroll
movesprite:
LDA #0
STA OAMADDR
LDA spriteposY ;posy
STA OAMDATA
LDA #$66 ;tile index
STA OAMDATA
LDA #%00000001 ;attributes
STA OAMDATA
LDA scrollx ;posx
STA OAMDATA
RTS
movespriteUP:
LDA spriteposY
CMP #$00
BEQ skipscroll
DEC spriteposY
JMP skipscroll
movespriteDown:
LDA spriteposY
CMP #$FF
BEQ skipscroll
INC spriteposY
JMP skipscroll
irq:
RTI
.goto $FFFA
.dw nmi
.dw start
.dw irq
.incbin "aiv256.chr"