-
Notifications
You must be signed in to change notification settings - Fork 0
/
flagdemo.s
282 lines (196 loc) · 3.57 KB
/
flagdemo.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
277
278
279
280
281
282
;; KES - 5/13/2009
;; ****** constants ******
MainScanLineCount = 192
StripeCount = 13
;; ****** parameters ******
clRed = $44
clWhite = $0e
clBlue = $84
clStar = clWhite
clBkg = $00
;StripeHeight = 5
StripeHeight = 9
FlagTopY = 30
ScanLinesLeftAtBottom = MainScanLineCount - FlagTopY - StripeCount * StripeHeight
; ****** variables ******
.bss
StripeIndex: .res 1
CurrentStripeColor: .res 1
CurrentLeftColor: .res 1
SaveStripeY: .res 1
CurrentX0: .res 1
CurrentX: .res 1
ScanLineVector: .res 2
WaveLineOffset: .res 1
VWaveDT: .res 1
VWaveT: .res 1
.segment "VECTORS"
.word Reset ; NMI
.word Reset ; RESET
.word Reset ; IRQ
.code
;; ******** register *******
VSYNC = $00 ; 0000 00x0 Vertical Sync Set-Clear
VBLANK = $01 ; xx00 00x0 Vertical Blank Set-Clear
WSYNC = $02 ; ---- ---- Wait for Horizontal Blank
COLUBK = $09 ; xxxx xxx0 Color-Luminance Background
.proc Reset
sei
ldx #0
txs
pha
txa
Clear:
dex
bne Clear
lda #0
sta WaveLineOffset
sta VWaveT
lda #$77
sta VWaveDT
.endproc
StartOfFrame :
; Start of vertical blank processing
lda #0
sta VBLANK
lda #2
sta VSYNC
; 3 scanlines of VSYNCH signal...
sta WSYNC
sta WSYNC
sta WSYNC
lda #0
sta VSYNC
; 37 scanlines of vertical blank...
ldy #37
:
sta WSYNC
dey
bne :-
jsr MainPic
lda #%01000010
sta VBLANK ; end of screen - enter blanking
; 30 scanlines of overscan...
; .REPEAT 30
; sta WSYNC
; .ENDREPEAT
inc CurrentX0
jmp StartOfFrame
.code
.macro LeftSide ofs0, ofs1
lda VStripLeft + 2 * ofs0 + ofs1, y
sta COLUBK
.endmacro
.macro RightSide ofs0, ofs1
lda VStripRight + 2 * ofs0 + ofs1, y
sta COLUBK
.endmacro
.macro MakeScanLine ofs0, ofs1, ofs2, ofs3, ofs4, ofs5
lda #clBkg
sta COLUBK
nop
nop
LeftSide ofs0, 0
LeftSide ofs1, 1
RightSide ofs2, 1
RightSide ofs3, 0
RightSide ofs4, 0
; RightSide ofs5, 0
iny ; need the 2 cycles
lda #clBkg
sta COLUBK
.endmacro
.proc MainPic
ldx WaveLineOffset
lda WaveLineLookupLo, x
sta ScanLineVector
lda WaveLineLookupHi, x
sta ScanLineVector + 1
ldy VWaveDT
lda VWaveSpeed, y
clc
adc VWaveT
sta VWaveT
bcc SkipVWave
inx
cpx #5
bne :+
ldx #0
:
stx WaveLineOffset
SkipVWave:
iny
sty VWaveDT
ldx #clBkg
stx COLUBK
ldy #FlagTopY
:
sta WSYNC
dey
bne :-
; 192 scanlines of picture...
ldx #StripeHeight * 14
ldy #0
sta WSYNC
ScanLine:
txa
lsr a
bcc :+
nop
:
jmp (ScanLineVector)
EndOfLine:
sta WSYNC
dex
bne ScanLine
rts
.endproc
WaveLine0:
MakeScanLine 0, 0, 1, 2, 3, 2
jmp MainPic::EndOfLine
WaveLine1:
MakeScanLine 0, 1, 2, 3, 2, 0
jmp MainPic::EndOfLine
WaveLine2:
MakeScanLine 1, 2, 3, 2, 0, 0
jmp MainPic::EndOfLine
WaveLine3:
MakeScanLine 2, 3, 2, 0, 0, 1
jmp MainPic::EndOfLine
WaveLine4:
MakeScanLine 3, 2, 0, 0, 1, 2
jmp MainPic::EndOfLine
WaveLine5:
MakeScanLine 2, 0, 0, 1, 2, 3
jmp MainPic::EndOfLine
.rodata
.align $100
VStripLeft:
.res StripeHeight, clBkg
.repeat 7
.res StripeHeight, clBlue
.endrepeat
.repeat 3
.res StripeHeight, clWhite
.res StripeHeight, clRed
.endrepeat
VStripRight:
.res StripeHeight, clBkg ; shared between left and right
.repeat 6
.res StripeHeight, clRed
.res StripeHeight, clWhite
.endrepeat
.res StripeHeight, clRed
.res StripeHeight, clBkg
.define WaveLineList WaveLine0, WaveLine1, WaveLine2, WaveLine3, WaveLine4, WaveLine5
WaveLineLookupLo:
.lobytes WaveLineList
WaveLineLookupHi:
.hibytes WaveLineList
VWaveSpeed:
.repeat $40, I
.byte $35+I, $35+I
.endrepeat
.repeat $40, I
.byte $75-I, $75-I
.endrepeat