OpenCores
URL https://opencores.org/ocsvn/t6507lp/t6507lp/trunk

Subversion Repositories t6507lp

[/] [t6507lp/] [trunk/] [rtl/] [verilog/] [vga_controller.v] - Blame information for rev 221

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 221 creep
////////////////////////////////////////////////////////////////////////////
2
////                                                                    ////
3
//// t2600 IP Core                                                      ////
4
////                                                                    ////
5
//// This file is part of the t2600 project                             ////
6
//// http://www.opencores.org/cores/t2600/                              ////
7
////                                                                    ////
8
//// Description                                                        ////
9
//// VGA controller                                                     ////
10
////                                                                    ////
11
//// TODO:                                                              ////
12
//// - Feed the controller with data                                    ////
13
////                                                                    ////
14
//// Author(s):                                                         ////
15
//// - Gabriel Oshiro Zardo, gabrieloshiro@gmail.com                    ////
16
//// - Samuel Nascimento Pagliarini (creep), snpagliarini@gmail.com     ////
17
////                                                                    ////
18
////////////////////////////////////////////////////////////////////////////
19
////                                                                    ////
20
//// Copyright (C) 2001 Authors and OPENCORES.ORG                       ////
21
////                                                                    ////
22
//// This source file may be used and distributed without               ////
23
//// restriction provided that this copyright statement is not          ////
24
//// removed from the file and that any derivative work contains        ////
25
//// the original copyright notice and the associated disclaimer.       ////
26
////                                                                    ////
27
//// This source file is free software; you can redistribute it         ////
28
//// and/or modify it under the terms of the GNU Lesser General         ////
29
//// Public License as published by the Free Software Foundation;       ////
30
//// either version 2.1 of the License, or (at your option) any         ////
31
//// later version.                                                     ////
32
////                                                                    ////
33
//// This source is distributed in the hope that it will be             ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied         ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR            ////
36
//// PURPOSE. See the GNU Lesser General Public License for more        ////
37
//// details.                                                           ////
38
////                                                                    ////
39
//// You should have received a copy of the GNU Lesser General          ////
40
//// Public License along with this source; if not, download it         ////
41
//// from http://www.opencores.org/lgpl.shtml                           ////
42
////                                                                    ////
43
////////////////////////////////////////////////////////////////////////////
44
 
45
`include "timescale.v"
46
 
47
module vga_controller (
48
        input reset,
49
        input clk_50,
50
        input [8:0] SW,
51
        output reg [3:0] VGA_R,
52
        output reg [3:0] VGA_G,
53
        output reg [3:0] VGA_B,
54
        output [9:0] LEDR,
55
        output reg VGA_VS,
56
        output reg VGA_HS
57
);
58
 
59
reg clk_25;
60
reg [9:0] hc;
61
reg [9:0] vc;
62
reg vsenable;
63
wire vidon;
64
 
65
assign LEDR = SW;
66
 
67
always @ (posedge clk_50 or negedge reset)
68
begin
69
        if (!reset) begin
70
                clk_25 <= 0;
71
        end
72
        else begin
73
                clk_25 <= !clk_25;
74
        end
75
end
76
 
77
always @ (posedge clk_25 or negedge reset)
78
begin
79
        if (!reset) begin
80
                hc <= 0;
81
                VGA_HS <= 1;
82
                vsenable <= 0;
83
        end
84
        else if (hc < 640) begin
85
                hc <= hc + 1;
86
                vsenable <= 0;
87
                VGA_HS <= 1;
88
        end
89
        else if (hc < 640 + 16) begin
90
                VGA_HS <= 1;
91
                hc <= hc + 1;
92
                vsenable <= 0;
93
        end
94
        else if (hc < 640 + 16 + 96) begin
95
                VGA_HS <= 0;
96
                hc <= hc + 1;
97
                vsenable <= 0;
98
        end
99
        else if (hc < 640 + 16 + 96 + 48) begin
100
                VGA_HS <= 1;
101
                hc <= hc + 1;
102
                vsenable <= 0;
103
        end
104
        else begin
105
                VGA_HS <= 1;
106
                hc <= 0;
107
                vsenable <= 1;
108
        end
109
end
110
 
111
always @ (posedge clk_25 or negedge reset)
112
begin
113
        if (!reset) begin
114
                vc <= 0;
115
                VGA_VS <= 1;
116
        end
117
        else begin
118
                if (vsenable == 1) begin
119
                        vc <= vc + 1;
120
                end
121
                if (vc < 480) begin
122
                        VGA_VS <= 1;
123
                end
124
                else if (vc < 480 + 11) begin
125
                        VGA_VS <= 1;
126
                end
127
                else if (vc < 480 + 11 + 2) begin
128
                        VGA_VS <= 0;
129
                end
130
                else if (vc < 480 + 11 + 2 + 31) begin
131
                        VGA_VS <= 1;
132
                end
133
                else begin
134
                        vc <= 0;
135
                        VGA_VS <= 1;
136
                end
137
        end
138
end
139
 
140
always @ (posedge clk_25)
141
begin
142
        if (vidon == 1) begin
143
                if (hc < 320) begin
144
                        if (vc < 240) begin
145
                                VGA_R[0] <= 1;
146
                                VGA_G[0] <= 1;
147
                                VGA_B[0] <= 1;
148
                                VGA_R[1] <= 1;
149
                                VGA_G[1] <= 1;
150
                                VGA_B[1] <= 1;
151
                                VGA_R[2] <= 1;
152
                                VGA_G[2] <= 1;
153
                                VGA_B[2] <= 1;
154
                                VGA_R[3] <= 1;
155
                                VGA_G[3] <= 1;
156
                                VGA_B[3] <= 1;
157
                        end
158
                        else begin
159
                                VGA_R[0] <= 0;
160
                                VGA_G[0] <= 0;
161
                                VGA_B[0] <= 1;
162
                                VGA_R[1] <= 0;
163
                                VGA_G[1] <= 0;
164
                                VGA_B[1] <= 1;
165
                                VGA_R[2] <= 0;
166
                                VGA_G[2] <= 0;
167
                                VGA_B[2] <= 1;
168
                                VGA_R[3] <= 0;
169
                                VGA_G[3] <= 0;
170
                                VGA_B[3] <= 1;
171
                        end
172
                end
173
                else begin
174
                        if (vc < 240) begin
175
                                VGA_R[0] <= 1;
176
                                VGA_G[0] <= 0;
177
                                VGA_B[0] <= 0;
178
                                VGA_R[1] <= 1;
179
                                VGA_G[1] <= 0;
180
                                VGA_B[1] <= 0;
181
                                VGA_R[2] <= 1;
182
                                VGA_G[2] <= 0;
183
                                VGA_B[2] <= 0;
184
                                VGA_R[3] <= 1;
185
                                VGA_G[3] <= 0;
186
                                VGA_B[3] <= 0;
187
                        end
188
                        else begin
189
                                VGA_R[0] <= 0;
190
                                VGA_G[0] <= 1;
191
                                VGA_B[0] <= 0;
192
                                VGA_R[1] <= 0;
193
                                VGA_G[1] <= 1;
194
                                VGA_B[1] <= 0;
195
                                VGA_R[2] <= 0;
196
                                VGA_G[2] <= 1;
197
                                VGA_B[2] <= 0;
198
                                VGA_R[3] <= 0;
199
                                VGA_G[3] <= 1;
200
                                VGA_B[3] <= 0;
201
                        end
202
                end
203
        end
204
        else begin
205
                VGA_R[0] <= 0;
206
                VGA_G[0] <= 0;
207
                VGA_B[0] <= 0;
208
                VGA_R[1] <= 0;
209
                VGA_G[1] <= 0;
210
                VGA_B[1] <= 0;
211
                VGA_R[2] <= 0;
212
                VGA_G[2] <= 0;
213
                VGA_B[2] <= 0;
214
                VGA_R[3] <= 0;
215
                VGA_G[3] <= 0;
216
                VGA_B[3] <= 0;
217
        end
218
end
219
 
220
assign vidon = (hc < 640 && vc < 480) ? 1 : 0;
221
 
222
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.