Skip to content

Commit 65eeeba

Browse files
committed
Implemented 8-bit driver; complete display driver refactor
1 parent fad54c6 commit 65eeeba

File tree

1 file changed

+68
-82
lines changed

1 file changed

+68
-82
lines changed

Dev/Game/Software/vga_display.spin

+68-82
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ vga
5454

5555
' Setup and start video generator
5656
or dira, vgapin ' Set video generator output pins
57-
or outa, vgapin ' Drive VGA pins low for blanking
57+
andn outa, vgapin ' Drive VGA pins low for blanking
5858
or dira, vspin ' Set VSync signal output pin
5959
or dira, sigpin ' Set data ready signal output pin
6060
or dira, syncpin ' Set sync output pins
@@ -65,143 +65,129 @@ vga
6565
shr cnt, #10 ' Set-up ~1ms wait
6666
add cnt, cnt ' Add 1ms wait
6767
waitcnt cnt, #0 ' Allow PLL to settle
68-
mov vcfg, VidCfg ' Configure and start video generator
68+
mov vcfg, SyncCfg ' Configure and start video generator
6969

70-
' Display vertical sync area
70+
' Display video
7171
video or outa, vspin ' Drive vertical sync signal pin high
7272
mov vptr, numFP ' Initialize vertical sync pointer
73-
:fporch mov vscl, BVidScl ' Set video scale for blank active video area
74-
andn outa, vspin ' Drive vertical sync signal pin low
75-
waitvid sColor, cPixel ' Display blank active video line
7673

74+
' Display vertical sync area
75+
:fporch mov vscl, blkScale ' Set video scale for blank active video area
76+
andn outa, vspin ' Drive vertical sync signal pin low
77+
waitvid sColor, pixel3 ' Display blank active video line
7778
mov vscl, fphScale ' Set video generator scale to half front porch
78-
waitvid sColor, cPixel ' Display first half of front porch
79-
or outa, syncpin
79+
waitvid sColor, pixel0 ' Display first half of front porch
80+
or outa, syncpin ' Take control of sync pins from video generator
8081
mov vcfg, SyncCfg ' Set video configuration to control sync pins
81-
waitvid sColor, pPixel ' Display second half of front porch
82+
waitvid sColor, pixel3 ' Display second half of front porch
8283
andn outa, syncpin ' Hand sync pin control to video generator
8384
mov vscl, hsScale ' Set video generator scale to horizontal sync
84-
waitvid sColor, hsPixel ' Display horizontal sync
85-
mov vscl, bphScale ' Set video generator scale to half back porch
86-
waitvid sColor, pPixel ' Display first half of back porch
87-
cmp vptr, #1 wz
88-
if_nz or outa, syncpin ' Take sync pin control back from video generator
89-
if_nz waitvid sColor, cPixel ' Display second half of back porch
90-
if_nz mov vcfg, VidCfg ' Set video configuration to control color pins
91-
if_z waitvid sColor, pPixel
92-
85+
waitvid sColor, pixel2 ' Display horizontal sync
86+
mov vscl, bphScale ' Set video generator scale to half back porch
87+
waitvid sColor, pixel3 ' Display first half of back porch
88+
or outa, syncpin ' Take sync pin control back from video generator
89+
waitvid sColor, pixel0 ' Display second half of back porch
90+
mov vcfg, ColCfg ' Set video configuration to control color pins
9391
djnz vptr, #:fporch ' Display front porch lines
92+
mov vcfg, SyncCfg ' Set video generator control to sync pins
9493
mov vptr, numVS ' Initialize vertical sync pointer
95-
:vsync
96-
mov vscl, BVidScl ' Set video scale for blank active video area
97-
waitvid sColor, vPixel ' Display blank active VSync video line
94+
:vsync mov vscl, blkScale ' Set video scale for blank active video area
95+
waitvid sColor, pixel1 ' Display blank active VSync video line
96+
andn outa, syncpin ' Hand sync pin control to video generator
9897
mov vscl, fphScale ' Set video generator scale to half front porch
99-
waitvid sColor, vPixel ' Display first half of front porch
100-
waitvid sColor, vPixel ' Display second half of front porch
98+
waitvid sColor, pixel1 ' Display first half of front porch
99+
waitvid sColor, pixel1 ' Display second half of front porch
101100
mov vscl, hsScale ' Set video generator scale to horizontal sync
102-
waitvid sColor, cPixel ' Display horizontal sync
101+
waitvid sColor, pixel0 ' Display horizontal sync
103102
mov vscl, bphScale ' Set video generator scale to half back porch
104-
waitvid sColor, vPixel ' Display first half of back porch
105-
waitvid sColor, vPixel ' Display second half of back porch
106-
103+
waitvid sColor, pixel1 ' Display first half of back porch
104+
waitvid sColor, pixel1 ' Display second half of back porch
107105
djnz vptr, #:vsync ' Display vertical sync lines
108106
mov vptr, numBP ' Initialize vertical sync pointer
109-
:bporch mov vscl, BVidScl ' Set video scale for blank active video area
110-
waitvid sColor, pPixel ' Display blank active video line
111-
112-
107+
:bporch mov vscl, blkScale ' Set video scale for blank active video area
108+
waitvid sColor, pixel3 ' Display blank active video line
113109
mov vscl, fphScale ' Set video generator scale to half front porch
114-
waitvid sColor, pPixel ' Display first half of front porch
115-
waitvid sColor, pPixel ' Display second half of front porch
110+
waitvid sColor, pixel3 ' Display first half of front porch
111+
waitvid sColor, pixel3 ' Display second half of front porch
116112
mov vscl, hsScale ' Set video generator scale to horizontal sync
117-
waitvid sColor, hsPixel ' Display horizontal sync
113+
waitvid sColor, pixel2 ' Display horizontal sync
118114
mov vscl, bphScale ' Set video generator scale to half back porch
119-
waitvid sColor, pPixel ' Display first half of back porch
120-
cmp vptr, #1 wz
121-
if_z or outa, syncpin
122-
if_z waitvid sColor, cPixel ' Display second half of back porch
123-
if_z mov vcfg, VidCfg
124-
if_nz waitvid sColor, pPixel
125-
126-
115+
waitvid sColor, pixel3 ' Display first half of back porch
116+
cmp vptr, #1 wz ' Check if last back porch line
117+
if_z or outa, syncpin ' Take control of sync pins from video generator
118+
if_z waitvid sColor, pixel0 ' Display second half of back porch
119+
if_z mov vcfg, ColCfg ' Set video configuration to control color pins
120+
if_nz waitvid sColor, pixel3 ' Display second half of back porch
127121
cmp vptr, dataSig wz ' Check if graphics data ready
128122
if_z or outa, sigpin ' Signal data ready
129123
djnz vptr, #:bporch ' Display back porch lines
130124
andn outa, sigpin ' Disable data ready signal
131125

132126
' Display active video
133127
nextsl add cursl, #1 ' Increment current scanline
134-
active mov vscl, VVidScl ' Set video scale for visible video
128+
active mov vscl, visScale ' Set video scale for visible video
135129
jmp #scancode ' Display line
136130
scanret djnz lptr, #active ' Display same line twice
137-
mov lptr, #2 ' Reset line pointer
138131
cmp cursl, numLines wz ' Check if at bottom of screen
139-
if_z mov cursl, #0 ' Reset current scanline
132+
if_z mov cursl, #0 ' Reset current scanline
140133
wrlong cursl, clptr ' Set current scanline in Main RAM
134+
mov lptr, #2 ' Reset line pointer
141135
if_nz jmp #nextsl ' Continue displaying remaining scanlines
142136
jmp #video ' Return to start of display
143137

144-
' Scancode buffer
138+
' Scancode resources
145139
scancode long 0[80*2] ' Buffer containing display scancode
146140
mov vscl, fphScale ' Set video generator scale to half front porch
147-
waitvid sColor, cPixel ' Display first half of front porch
148-
or outa, syncpin
141+
waitvid sColor, pixel0 ' Display first half of front porch
142+
or outa, syncpin ' Take control of sync pins from video generator
149143
mov vcfg, SyncCfg ' Set video configuration to control sync pins
150-
waitvid sColor, pPixel ' Display second half of front porch
144+
waitvid sColor, pixel3 ' Display second half of front porch
151145
andn outa, syncpin ' Hand sync pin control to video generator
152146
mov vscl, hsScale ' Set video generator scale to horizontal sync
153-
waitvid sColor, hsPixel ' Display horizontal sync
154-
mov vscl, bphScale ' Set video generator scale to half back porch
155-
waitvid sColor, pPixel ' Display first half of back porch
156-
or outa, syncpin ' Take sync pin control back from video generator
157-
waitvid sColor, cPixel ' Display second half of back porch
158-
mov vcfg, VidCfg ' Set video configuration to control color pins
147+
waitvid sColor, pixel2 ' Display horizontal sync
148+
mov vscl, bphScale ' Set video generator scale to half back porch
149+
waitvid sColor, pixel3 ' Display first half of back porch
150+
or outa, syncpin ' Take sync pin control back from video generator
151+
waitvid sColor, pixel0 ' Display second half of back porch
152+
mov vcfg, ColCfg ' Set video configuration to control color pins
159153
jmp #scanret ' Return to rest of display
154+
iR rdlong pixels, vbptrs+0 ' Load next pixels
155+
iW waitvid pixels, #%%3210 ' Display pixels
160156

161157
' Config values
162158
vgapin long |< 16 | |< 17 | |< 18 | |< 19 | |< 20 | |< 21 | |< 22 | |< 23 ' VGA output pins
159+
syncpin long |< 24 | |< 25 ' Sync pins
163160
sigpin long |< 26 ' Data ready signal pin
164161
vspin long |< 27 ' VSync signal output pin
165162
pllfreq long 259917792 ' Counter A frequency
166163
CtrCfg long %0_00001_101_00000000_000000_000_000000 ' Counter A configuration
167-
VidCfg long %0_01_1_0_0_000_00000000000_010_0_11111111 ' Video generator configuration
168-
VVidScl long %000000000000_00000010_000000001000 ' Video generator visible video scale register
169-
HVidScl long %000000000000_00010000_000010100000 ' Video generator horizontal sync scale register
170-
BVidScl long %000000000000_00000000_001010000000 ' Video generator blank line scale register
164+
ColCfg long %0_01_1_0_0_000_00000000000_010_0_11111111 ' Video generator color pins configuration
165+
SyncCfg long %0_01_1_0_0_000_00000000000_011_0_11111111 ' Video generator sync pins configuration
171166

172-
' Video Generator inputs
173-
' ??????????????????????
167+
' Video generator resources
168+
visScale long %000000000000_00000010_000000001000 ' Video generator visible video scale register
169+
blkScale long %000000000000_00000000_001010000000 ' Video generator blank line scale register
170+
fphScale long %000000000000_00000000_000000001000 ' Video generator scale for half of front porch
171+
hsScale long %000000000000_00000000_000001100000 ' Video generator scale for horizontal sync
172+
bphScale long %000000000000_00000000_000000011000 ' Video generator scale for horizontal sync
173+
sColor long %00000011_00000001_00000010_00000000 ' Sync colors (porch_HSync_VSync_HVSync)
174+
pixel0 long %%0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0 ' Porch color blank pixels
175+
pixel1 long %%1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1 ' VSync pixels
176+
pixel2 long %%2_2_2_2_2_2_2_2_2_2_2_2_2_2_2_2 ' HSync sync blank pixels
177+
pixel3 long %%3_3_3_3_3_3_3_3_3_3_3_3_3_3_3_3 ' Porch sync blank pixels
174178

175-
' Video attributes
179+
' Video frame attributes
176180
numFP long 10 ' Number of vertical front porch lines
177181
numVS long 2 ' Number of vertical sync lines
178182
numBP long 33 ' Number of vertical back porch lines
179183
numLines long 240 ' Number of rendered lines
180184
numSegs long 80 ' Number of scanline segments
181-
dataSig long 15 ' Back porch scanline to signal render cogs
182-
183-
' TESTING
184-
sColor long %00000011_00000001_00000010_00000000 ' Sync colors (porch_HSync_VSync_HVSync)
185-
cPixel long %%0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0 ' Porch color blank pixels
186-
vPixel long %%1_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1 ' VSync pixels
187-
hsPixel long %%2_2_2_2_2_2_2_2_2_2_2_2_2_2_2_2 ' HSync sync blank pixels
188-
pPixel long %%3_3_3_3_3_3_3_3_3_3_3_3_3_3_3_3 ' Porch sync blank pixels
189-
fphScale long %000000000000_00000000_000000001000 ' Video generator scale for half of front porch
190-
hsScale long %000000000000_00000000_000001100000 ' Video generator scale for horizontal sync
191-
bphScale long %000000000000_00000000_000000011000 ' Video generator scale for horizontal sync
192-
bpScale long %000000000000_00000000_000000110000 ' Video generator scale for horizontal sync
193-
SyncCfg long %0_01_1_0_0_000_00000000000_011_0_11111111 ' Video generator sync pins configuration
194-
syncpin long |< 24 | |< 25 ' Sync pins
195-
196-
' Instructions used to generate scancode
197-
iR rdlong pixels, vbptrs+0 ' Load next pixels
198-
iW waitvid pixels, #%%3210 ' Display pixels
199185

200186
' Other values
201187
d0s0 long 1 << 9 + 1 ' Value to increment source and destination registers
202188
d0 long 1 << 9 ' Value to increment destination register
203189
d1 long 1 << 10 ' Value to incrememnt destination register by 2
204-
190+
dataSig long 15 ' Back porch scanline to signal render cogs
205191
vbptrs long 0[80] ' Buffer containing Main RAM video buffer memory locations
206192

207193
' Frame pointers
@@ -214,4 +200,4 @@ clptr res 1 ' Pointer to location of current scanline in Mai
214200
cursl res 1 ' Container for current scanline
215201
pixels res 1 ' Container for currently rendering pixels
216202

217-
fit
203+
fit

0 commit comments

Comments
 (0)