-
Notifications
You must be signed in to change notification settings - Fork 2
/
test-02.asm
168 lines (141 loc) · 4.32 KB
/
test-02.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
;==============================================================================
; Test 2
; Gradient Background
;
; Copyright 2017 James O'Reilly
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;==============================================================================
processor 6502
include vcs.h ; this lib is included with DASM
;==============================================================================
; CONSTANTS
;
BLACK = $00
FIRST_COLOR = $7F ; First color at the top of the Background
COLOR_STEPS = 15 ; Number of colors after the first
;==============================================================================
; VARIBLES
;
SEG.U Variables
ORG $80
currBgColor ds 1 ; Current BG Color for loop interations
stopBgColor ds 1 ; When we reach this value, stop decrementing
SEG
;==============================================================================
; START
;
ORG $F000 ; Starting location of ROM
Start SEI ; Disable any interrupts
;==============================================================================
; RESET
;
Reset CLD ; Clear BCD math bit
LDX #$FF
TXS ; Set stack to beginning
LDA #0 ; Loop backwards from $FF to $00
.ClearLoop STA $00,X ; and clear each memory location
DEX
BNE .ClearLoop
;==============================================================================
; INIT
;
Initialize LDA #BLACK
STA COLUBK
LDA #FIRST_COLOR
STA currBgColor
SBC #COLOR_STEPS
STA stopBgColor
;==============================================================================
; MAIN LOOP
;
MainLoop JSR VerticalSync
JSR VerticalBlank
JSR Scanline
JSR OverScan
JMP MainLoop
;==============================================================================
; V-SYNC (3 Scanlines)
;
; Reset TV Signal to indicate new frame
; D1 but must be enabled here which is 00000010 (e.g 2 in dec.)
;
VerticalSync LDA #0
STA VBLANK
LDA #2
STA VSYNC ; Begin VSYNC period
STA WSYNC ; Halt 6502 until end of scanline 1
STA WSYNC ; Halt 6502 until end of scanline 2
RTS
;==============================================================================
; V-BLANK (37 Scanlines)
;
; Start a timer for enough cycles to approximate 36 scanlines
; Ideally, we're putting logic here instead.
; At 228 clock counts per scan line, we get 36 * 228 = 8208
; therefore 6502 instruction count would be 8208 / 3 = 2736
; 42 * 64 = 2688 (close enough, we'll fix it on the last line)
;
VerticalBlank LDA #42
STA TIM64T ; Start the timer with 42 ticks
LDA #0
STA WSYNC ; Halt 6502 until end of scanline 3
STA VSYNC ; End VSYNC period
RTS
;==============================================================================
; SCANLINE (192 Scanlines)
;
Scanline LDA INTIM ; Loop until the V-Blank timer finishes
BNE Scanline
LDA #0 ; End V-BLANK period with 0
STA WSYNC ; Halt 6502 until end of scanline
STA VBLANK ; Begin drawing to screen again
LDA #FIRST_COLOR
STA currBgColor
.SLLoop STA COLUBK ; Set the current color as background color
LDA #2
STA WSYNC ; 12 scanlines of the same color
STA WSYNC
STA WSYNC
STA WSYNC
STA WSYNC
STA WSYNC
STA WSYNC
STA WSYNC
STA WSYNC
STA WSYNC
STA WSYNC
STA WSYNC
DEC currBgColor ; Step down to next color
LDA currBgColor
CMP stopBgColor ; Check to see if we are on the last color
BNE .SLLoop ; And do it again if we aren't
LDA #2
STA VBLANK ; Suppress drawing to screen
RTS
;==============================================================================
; OVERSCAN (30 Scanlines)
;
OverScan LDX #30 ; x = 30;
LDA #2
.OSLoop STA WSYNC ; Halt 6502 until end of scanline
DEX ; x--
BNE .OSLoop ; if x !== 0 goto .OSLoop
RTS
;==============================================================================
; INTERRUPT VECTORS
;
org $FFFC ; 6502 looks here to start execution
.word Start ; NMI
.word Start ; Reset
.word Start ; IRQ